Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Profile Log in to check your private messages Log in
 
Conversion of BCD format to Hexadecimal format

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
View previous topic :: :: View next topic  
Author Message
dharmaraok

New User


Joined: 10 Mar 2011
Posts: 31
Location: india

PostPosted: Wed Sep 24, 2014 10:27 am    Post subject: Conversion of BCD format to Hexadecimal format
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

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7315

PostPosted: Wed Sep 24, 2014 10:41 am    Post subject: Reply to: Conversion of BCD format to Hexadecimal format
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: 31
Location: india

PostPosted: Wed Sep 24, 2014 10:49 am    Post subject:
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

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7315

PostPosted: Wed Sep 24, 2014 11:43 am    Post subject: Reply to: Conversion of BCD format to Hexadecimal format
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: 2504
Location: Atlanta, Georgia, USA

PostPosted: Wed Sep 24, 2014 9:36 pm    Post subject: Reply to: Conversion of BCD format to Hexadecimal format
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    IBMMAINFRAMES.com Support Forums -> COBOL Programming All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Mainframe Blocks to Tracks conversion upendrasri JCL & VSAM 1 Sat Nov 18, 2017 10:52 am
No new posts Format Last Record differently from r... Learncoholic DFSORT/ICETOOL 5 Tue Oct 24, 2017 12:01 pm
No new posts Format issues using XMITIP MSGDD ssdjp1 CLIST & REXX 5 Mon Oct 23, 2017 8:47 pm
No new posts Fetch Previous month & year in MM... girishb2 DFSORT/ICETOOL 3 Thu Sep 21, 2017 9:54 pm
No new posts Convert rows and column into JSON for... Dinesh Manivannan DB2 2 Sun Sep 03, 2017 6:50 pm

Facebook
Back to Top
 
Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us