Working with Binary Fields

Hi,

I work with Cobol routine that return a Binary return code.
How can I convert to decimal?
Is there a sample code that shows converting B/D/A?
How to use INIt/CONST with Binary fileds?

Binary fields in Natural are basically numeric for lengths one to four. Hence:

DEFINE DATA LOCAL
1 #B (B4) INIT <123>
1 #N (N8)
END-DEFINE
MOVE #B TO #N
WRITE #B #N
END

Note, if you try to have #B (B5) you will get an error message re the INIT. This is because B5 and above are basically alpha fields, and the INIT would have to be in apostrophes. (of course MOVE #B TO #N will then get an error message)

steve

1 Like
  1. But when using : call ‘cobol’ #rc (b02), I need to convert #rc to decimal.
  2. Using Init/Const : I mean to init variable with bin/hex value/

Hezi

Conversion is simply a matter of moving the source field to a target field of the correct type, e.g.:

DEFINE DATA LOCAL        
1 #RC (B02) INIT<H>
1 #RC_PACKED (P05)       
END-DEFINE               
*                        
* CALL 'COBOL' #RC       
*                        
MOVE #RC TO #RC_PACKED   
*                        
WRITE #RC #RC_PACKED     
*                        
END

Which will give you

MORE       
Page      1
           
0004      4