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: 7315

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: 1232
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: 8120
Location: East Dubuque, Illinois, USA

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 Convert CLIST to REXX cvnlynn CLIST & REXX 12 Tue Jun 27, 2017 2:06 am
No new posts Convert current to hex value gopurs DFSORT/ICETOOL 4 Wed Feb 15, 2017 5:40 am
No new posts Joinkeys with decimal scdinesh DFSORT/ICETOOL 3 Fri Feb 10, 2017 4:46 am
No new posts Converting decimal to numeric using I... Balaryan DFSORT/ICETOOL 4 Thu Feb 02, 2017 11:27 pm
No new posts How to convert the VBM file to VB or... Sulabh Agrawal JCL & VSAM 4 Fri Nov 18, 2016 1:04 pm


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