View previous topic :: View next topic
|
Author |
Message |
umanaga
New User
Joined: 09 Apr 2007 Posts: 33 Location: India
|
|
|
|
hello, i am confused how to do this.
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 |
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
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 |
|
|
Marso
REXX Moderator
Joined: 13 Mar 2006 Posts: 1353 Location: Israel
|
|
|
|
- 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. |
You have to initialize the whole area
Code: |
MOVE 0 TO WS-A-COMP |
Then you can move the X'1A' to the PIC X field (and not to the COMP field).
Finally, you can use WS-A-COMP which will contain the 26 you seek. |
|
Back to top |
|
|
umanaga
New User
Joined: 09 Apr 2007 Posts: 33 Location: India
|
|
|
|
thanks guys.. will giv a try |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8700 Location: Dubuque, Iowa, USA
|
|
|
|
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 |
|
|
|