IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Conversion of BCD format to Hexadecimal format


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
dharmaraok

New User


Joined: 10 Mar 2011
Posts: 45
Location: india

PostPosted: Wed Sep 24, 2014 10:27 am
Reply with quote

I am having a field of type X(2).

input file:

02
06

I need to convert this field into equailavent hexa decimal value.

output file

01
0A

Could you please let me know how can we achieve this.

I tried by moving X(2) to comp-3 field but it is not getting desired value.
Back to top
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Wed Sep 24, 2014 10:41 am
Reply with quote

This will add the sign-byte to your BCD, but not use anything except the sign from the value due to the V9 part of it.

Code:
01  W-CONVERTED-TO-PACKED COMP-3 PIC 9(4)V9 VALUE ZERO.
01  FILLER REDEFINES W-CONVERTED-TO-PACKED.
    05  W-BCD-VALUE PIC XX.
    05  W-SIGN-WAITING-FROM-ABOVE PIC X.

MOVE your-source-BCD TO W-BCD-VALUE
MOVE W-CONVERTED-TO-PACKED TO your-target-binary
Back to top
View user's profile Send private message
dharmaraok

New User


Joined: 10 Mar 2011
Posts: 45
Location: india

PostPosted: Wed Sep 24, 2014 10:49 am
Reply with quote

Thanks Bill,

how to declare your-target-binary field in working storage section.
Back to top
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Wed Sep 24, 2014 11:43 am
Reply with quote

Just like any other:

01 target-binary COMP (or COMP-4 or BINARY) PIC 9(4).

If you need that somewhere where only a two-byte PIC X is, then REDEFINES this as PIC XX.
Back to top
View user's profile Send private message
Bill O'Boyle

CICS Moderator


Joined: 14 Jan 2008
Posts: 2501
Location: Atlanta, Georgia, USA

PostPosted: Wed Sep 24, 2014 9:36 pm
Reply with quote

Code:

           03  WS-BCD              PIC  X(02)      VALUE X'0026'.   
           03  WS-HEX              PIC  X(02).   
           03  WS-PACKED-V9        PIC  9(04)V9    PACKED-DECIMAL.     
           03  WS-PACKED-X         REDEFINES WS-PACKED-V9               
                                   PIC  X(03).                         
           03  WS-HWORD            PIC  9(04)      BINARY.             
           03  WS-HWORD-X          REDEFINES WS-HWORD                   
                                   PIC  X(02).                         
      *   
           MOVE WS-BCD                 TO WS-PACKED-X (1:LENGTH OF WS-PACKED-X - 1)           
           MOVE X'0F'                  TO WS-PACKED-X (LENGTH OF WS-PACKED-X:).             
           MOVE WS-PACKED-V9           TO WS-HWORD.
           MOVE WS-HWORD-X             TO WS-HEX.

*
* AT THIS POINT, WS-HEX = X'001A'
*
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts Populate last day of the Month in MMD... SYNCSORT 2
No new posts Modifying Date Format Using DFSORT DFSORT/ICETOOL 9
No new posts 10 byte RBA conversion DB2 2
No new posts 10 byte RBA conversion -non applicati... JCL & VSAM 1
No new posts Need to convert date format DFSORT/ICETOOL 20
Search our Forums:

Back to Top