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
 

 

Converting hex values stored in x(4) to 9(8).

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

New User


Joined: 20 Dec 2006
Posts: 55
Location: noida

PostPosted: Mon Dec 09, 2013 10:06 am    Post subject: Converting hex values stored in x(4) to 9(8).
Reply with quote

Hi,
I have an existing file which has a x(4) field which contains date in hex format.
Sample values -
Code:

2102
0373

I want to to move this x(4) value into 9(8). For example, for the above sample the final expected value is 20130723.

I tried moving this value to s9(4) comp-3 but the value which moved was 0373.

Request you to please provide me some inputs to resolve this.

Thanks.
Back to top
View user's profile Send private message

Anuj Dhawan

Senior Member


Joined: 22 Apr 2006
Posts: 6258
Location: Mumbai, India

PostPosted: Mon Dec 09, 2013 11:50 am    Post subject:
Reply with quote

I'm on a toss but do you really mean what you say?

Edit: After a second thought, these topics should help you:

http://ibmmainframes.com/about51027.html
http://ibmmainframes.com/about48534.html
http://www-01.ibm.com/support/docview.wss?uid=swg21177358
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 7913
Location: Bellevue, IA

PostPosted: Mon Dec 09, 2013 5:30 pm    Post subject:
Reply with quote

You cannot do this with a MOVE statement -- you MUST write code to convert the hexadecimal values to decimal digits. Your code will take each hex character (the X'20', X'13', X'07' and X'23' in your example) and convert to decimal, accumulating the results as you go. The conversion can be done by a table or by EVALUATE or by arithmetic -- your choice -- but you will be converting base 16 values to base 10 values.
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: Mon Dec 09, 2013 7:25 pm    Post subject: Reply to: Converting hex values stored in x(4) to 9(8).
Reply with quote

Although I'm repeating what Anuj has posted, perhaps this is somewhat clearer -

Code:

     *                                                                 
     *     NOTE: ALL NUMERIC FIELDS MUST BE UNSIGNED                   
     *                                                                 
           03  WS-PACKED           PIC  9(09)      PACKED-DECIMAL.     
           03  WS-PACKED-V9        REDEFINES WS-PACKED                 
                                   PIC  9(08)V9    PACKED-DECIMAL.     
           03  WS-PACKED-X         REDEFINES WS-PACKED                 
                                   PIC  X(05).                         
           03  WS-DISPLAY          PIC  9(09).                         
           03  WS-DISPLAY-V9       REDEFINES WS-DISPLAY                 
                                   PIC  9(08)V9.                       
           03  WS-DISPLAY-X        REDEFINES WS-DISPLAY                 
                                   PIC  X(09).                         
      *                                                                 
           MOVE X'20130723'            TO WS-PACKED-X (1:4).           
           MOVE X'0F'                  TO WS-PACKED-X (5:).             
           MOVE WS-PACKED-V9           TO WS-DISPLAY-V9.               
      *                                                                 
           INSPECT WS-DISPLAY-X        CONVERTING X'FAFBFCFDFEFF'       
                                       TO 'ABCDEF'.                     
      *                                                                 
      *    WS-DISPLAY-X CONTAINS C'201307230'                           
      *                                                                 
           DISPLAY 'WS-DISPLAY-X = ', WS-DISPLAY-X.                     

Leave the INSPECT, in case there's another value you need to convert from HEX to CHARACTER, that may contain 4-Bit nibbles of "A" through "F", which you currently don't have in your example.

If your HEX value (for example) were X'20BF72A' then the INSPECT would be necessary to convert the unpacked nibbles of X'FB', X'FF' and X'FA, to 'B', 'F' and 'A', respectively.
Back to top
View user's profile Send private message
ApexNC

New User


Joined: 10 Feb 2006
Posts: 12
Location: USA

PostPosted: Wed Jan 08, 2014 5:36 am    Post subject: Reply to: Converting hex values stored in x(4) to 9(8).
Reply with quote

Based on the sample value given, I'd wager this is actually a YYYYMMDD field in Binary Coded Decimal format. In which case, the conversion to decimal is actually quite simple:

Code:

01  FILLER.                                       
    05 PIC-X-4 PIC X(4) VALUE X'20130723'.         
    05 PIC-9-8 PIC 9(8).                           
LINKAGE SECTION.                                   
01  BCD-CONV PIC 9(8)V9 COMP-3.                   
PROCEDURE DIVISION.                               
    SET ADDRESS OF BCD-CONV TO ADDRESS OF PIC-X-4 
    MOVE BCD-CONV TO PIC-9-8                       


If you don't mind RC=4 and a redefines length warning (IGYDS1154-W) on the compile, it can be made even simpler:

Code:

01  FILLER.                                         
    05 PIC-X-4 PIC X(4) VALUE X'20130723'.         
    05 BCD-CONV REDEFINES PIC-X-4 PIC 9(8)V9 COMP-3.
    05 PIC-9-8 PIC 9(8).                           
PROCEDURE DIVISION.                                 
    MOVE BCD-CONV TO PIC-9-8                                         


Putting BCD-CONV in LINKAGE and using SET ADDRESS gives RC=0 on the compile and avoids the redefines length warning.
Back to top
View user's profile Send private message
Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7228

PostPosted: Wed Jan 08, 2014 6:38 am    Post subject: Reply to: Converting hex values stored in x(4) to 9(8).
Reply with quote

Requires documenting if used.

The definition overlaps the first byte of the following field, However, it doesn't matter, because nothing from that final byte is used.

The MOVE is to an integer, so the decimal part (V9), which is only there to allow the field to be defined as COMP-3/PACKED-DECIMAL, is not used.

The receiving field is unsigned, so the compiler will not use the sign from the source field, it will simply make the sign-nybble in the receiving field F.

So, it works.

However,

Code:
01  FILLER.
    05  BCD-VALUE-PLUS-ONE-BYTE.                                       
        10 PIC-X-4 PIC X(4) VALUE X'20130723'
        10 FILLER PIC 9 COMP-3 VALUE ZERO.         
    05 BCD-CONV REDEFINES BCD-VALUE-PLUS-ONE-BYTE PIC 9(8)V9 COMP-3.
    05 PIC-9-8 PIC 9(8).                           
PROCEDURE DIVISION.                                 
    MOVE BCD-CONV TO PIC-9-8


No messages, no wondering, no change of behaviour with a signed final receiver.
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 Is the 'prompt' data for the DSLIST p... Willy Jensen TSO/ISPF 2 Tue Dec 06, 2016 4:38 am
No new posts Overlaying one set of charater values... Kevin Lindsley SYNCSORT 7 Sat Nov 05, 2016 3:21 am
No new posts Regarding COBOL Stored Procedure opti... selvamsrinivasan85 DB2 4 Fri Nov 04, 2016 8:57 pm
No new posts Access SQLCA fields inside a stored p... gangapd DB2 4 Thu Oct 27, 2016 10:20 am
No new posts Low values Results from VARCHAR FORMAT balaji81_k DB2 10 Thu Oct 20, 2016 1:18 am


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