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
 

 

Convert value Pic X to Decimal

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
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    Post subject: Convert value Pic X to Decimal
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

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7254

PostPosted: Thu Aug 30, 2012 6:55 pm    Post subject: Reply to: Convert value Pic X to Decimal
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: 1224
Location: Israel

PostPosted: Thu Aug 30, 2012 7:01 pm    Post subject: Reply to: Convert value Pic X to Decimal
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    Post subject:
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: 7932
Location: Bellevue, IA

PostPosted: Thu Aug 30, 2012 7:13 pm    Post subject:
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    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 How to convert the VBM file to VB or... Sulabh Agrawal JCL & VSAM 4 Fri Nov 18, 2016 1:04 pm
No new posts Convert +9999999999999.99 to S9(12)V9(3) vnktrrd DFSORT/ICETOOL 8 Thu Nov 17, 2016 8:15 pm
This topic is locked: you cannot edit posts or make replies. Db2 SQL query to convert rows into co... subratarec DB2 5 Thu Nov 17, 2016 4:51 pm
No new posts convert PD to ZD ram_vizag DFSORT/ICETOOL 5 Sat Nov 05, 2016 3:06 am
No new posts Comparing Decimal and CHAR columns rakesh17684 DB2 7 Thu Oct 20, 2016 2:33 am


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