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

Convert value Pic X to Decimal


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

New User


Joined: 09 Apr 2007
Posts: 33
Location: India

PostPosted: Thu Aug 30, 2012 6:47 pm
Reply with quote

hello, i am confused how to do this.

Code:
 01 WS-A PIC X.

it can contain values X'01', X'02' or X'1A' etc (hex format)

i need to convert these to decimal values 01, 01, 26

tried with defining COMP variable..but failing when X'1A' is moved to COMP. This might be simple.. but i couldn't figure out icon_rolleyes.gif
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: Thu Aug 30, 2012 6:55 pm
Reply with quote

Code:
01  a-nice-name COMP-5 PIC 9(4) VALUE ZERO.
01  FILLER REDEFINES a-nice-name.
    05 FILLER PIC X.
    05  a-different-nice-name PIC X.

MOVE your-pic-x-with-a-nice-name TO a-different-nice-name
DISPLAY a-nice-name
Back to top
View user's profile Send private message
Marso

REXX Moderator


Joined: 13 Mar 2006
Posts: 1353
Location: Israel

PostPosted: Thu Aug 30, 2012 7:01 pm
Reply with quote

  1. COMP fields are at least 2 chars. You should define:
    Code:
    01  WS-A-COMP   PIC 9(4)   COMP.
    01  FILLER                 REDEFINES WS-A-COMP.
        03 FILLER   PIC X.
        03 WS-A     PIC X.

  2. You have to initialize the whole area
    Code:
        MOVE 0 TO WS-A-COMP

  3. Then you can move the X'1A' to the PIC X field (and not to the COMP field).
    Code:
        MOVE X'1A' TO WS-A

  4. Finally, you can use WS-A-COMP which will contain the 26 you seek.
Back to top
View user's profile Send private message
umanaga

New User


Joined: 09 Apr 2007
Posts: 33
Location: India

PostPosted: Thu Aug 30, 2012 7:09 pm
Reply with quote

thanks guys.. will giv a try
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8700
Location: Dubuque, Iowa, USA

PostPosted: Thu Aug 30, 2012 7:13 pm
Reply with quote

If your version of COBOL supports intrinsic functions, you could use
Code:
COMPUTE <numeric-variable> = FUNCTION ORD (WS-A) - 1
since ORD returns a value from 1 to 256 depending upon the hex value of the single byte passed to it.
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 CONVERT a given date from UTC TO BST CICS 0
No new posts small int to zoned decimal conversion DFSORT/ICETOOL 3
No new posts Extracting Variable decimal numbers f... DFSORT/ICETOOL 17
No new posts Need to convert date format DFSORT/ICETOOL 20
No new posts Keep leading zero(s) after convert fl... SYNCSORT 7
Search our Forums:

Back to Top