Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref
IBM Mainframe Forum Index
 
Register
 
IBM Mainframe Forum 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: 39
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: 7312

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: 39
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: 7312

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 Parsing single liner XML into readabl... rohanthengal COBOL Programming 1 Fri Oct 18, 2019 8:41 pm
No new posts String to ASCII conversion JPLMARTINS COBOL Programming 4 Sun Sep 29, 2019 12:00 am
No new posts Convert string to packed format ajaydwivedi4u COBOL Programming 6 Sat Sep 21, 2019 5:01 pm
No new posts Pack to Unpack conversion for sending... A_programmers COBOL Programming 13 Wed Sep 11, 2019 10:46 pm
No new posts Converting a copybook value into Json... srikant314 COBOL Programming 1 Mon Jun 03, 2019 11:17 am

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