Solved

Convert binary to numeric dynamically

Posted on 2006-10-25
4
572 Views
Last Modified: 2012-05-05
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!
0
Comment
Question by:stu_pb
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 3

Author Comment

by:stu_pb
ID: 17804733
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.
0
 
LVL 14

Expert Comment

by:daveslater
ID: 17805893
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
 
0
 
LVL 27

Accepted Solution

by:
tliotta earned 500 total points
ID: 17806216
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
0
 

Expert Comment

by:techcons
ID: 17846409
What version of the operating system are you on? V5R2/V5R3/V5R4? You can use the %CHAR BIF to create a character field.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Unified and professional email signatures help maintain a consistent company brand image to the outside world. This article shows how to create an email signature in Exchange Server 2010 using a transport rule and how to overcome native limitations …
Deploying our service is a grudge match between customer benefits and customer pain. In one corner, rolling out fixes (yay!) and delivering new features (double yay!). In the other corner, training on new features (boo – sounds like work), and chan…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question