Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups 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: 30
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: 7228

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: 30
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: 7228

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: 2502
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 File Aid to File Manager conversion murali3955 IBM Tools 4 Thu Nov 24, 2016 3:41 pm
No new posts Match or compare two files in VB Format anatol DFSORT/ICETOOL 14 Thu Nov 03, 2016 7:41 pm
No new posts Conversion of a VB file to FB. isssal DFSORT/ICETOOL 1 Mon Oct 31, 2016 10:23 pm
No new posts Low values Results from VARCHAR FORMAT balaji81_k DB2 10 Thu Oct 20, 2016 1:18 am
No new posts output data in CSV Format janmejay COBOL Programming 8 Sat Oct 15, 2016 2:20 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us