We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you two Citrix podcasts. Learn about 2020 trends and get answers to your biggest Citrix questions!Listen Now

x

# Convert binary to numeric dynamically

on
Medium Priority
611 Views
I have a program which recieves a variable of type 9B.  The underlying variable can be of any numeric precision and scale e.g. (8,0 or 5,3, etc...). How can I convert this value into a character array?

If i use %editc(variable, 'X') I do not get the right value.

Any help would be greatly appreciated!
Comment
Watch Question

## View Solution Only

Commented:
I should note that I can make this work for non packed numerics, but I don't know how to make it work for packed numerics.

Thanks.

Commented:
hi try somehing like

** working storage for packed field
D Pak1            ds
D  Val                          15p 0 Inz
** resulting numeri
D Zone            s             30S15 Inz
** offset to calulate length
D GblpOset        s             10i 0
** packed field length (no bytes)
DGblPLen          s             10i 0
DBufferOffSet     s             10i 0 Inz(20)

DPackDecPos       s             10i 0 Inz(%DecPos(MyPackField))
DPackFieldLen     s             10I 0 Inz(7)
** packed field in alpha format
D Buf             ds           100
D  MypackField                   7p 2 Inz(52.51) Overlay(Buf:20)
** ws to calculated
D Div             s             10i 0
D
/Free
*inlr = *on ;
//  set  packed length
gblPLen = (PackFieldLen + 1 ) / 2 ;

// set offset to ds
gblpOset = 9 - GblPLen ;

// map character to pack ds
%subst(Pak1    : GblpOset    : GblPLen)  =
%subst(Buf     : BufferOffSet: GblPlen) ;

// set percision
Div = 10 ** PackDecPos ;

// create zoned numeric
Zone = Val / xx ;
/End-Free

dave

Commented:
I think I'd just convert immediately to a 9P0 (packed decimal with the same number of digits). Once there, conversion to any other numeric form (including scale) is simply a matter of dividing by the appropriate power of 10 with an EVAL. But even that might not be necessary.

A B-type field is allowed to have decimal fractions. As such, I would hope that the compiler would generate the correct packed intermediate field during the division anyway.

It should be easy to code a test program and run in debug a few times. Set the 9B0 field value to different amounts and see how various calcs result.

Tom

Not the solution you were looking for? Getting a personalized solution is easy.

Commented:
What version of the operating system are you on? V5R2/V5R3/V5R4? You can use the %CHAR BIF to create a character field.
##### Thanks for using Experts Exchange.

• View three pieces of content (articles, solutions, posts, and videos)
• Ask the experts questions (counted toward content limit)
• Customize your dashboard and profile