View previous topic :: View next topic
|
Author |
Message |
himanshupant
New User
Joined: 21 Mar 2007 Posts: 46 Location: India
|
|
|
|
Hi
I have a VSAM KSDS file with a packed hexadecimal three digit number as a part of its key like
012
01B
I wish to carry out basic addition on this so that I can get the value like
012
01C
012
01D
and so on and so forth..
Any idea how this can be done in COBOL ?? |
|
Back to top |
|
|
Douglas Wilder
Active User
Joined: 28 Nov 2006 Posts: 305 Location: Deerfield IL
|
|
|
|
Packed number are defined as comp-3.
For Example:
Code: |
10 PACK-NUM1 PIC S9(03) COMP-3 VALUE ZERO. |
Then do your math:
Code: |
COMPUTE PACK-NUM1 = PACK-NUM + 1. |
COBOL knows how to handle the math and signs in packed numbers. |
|
Back to top |
|
|
himanshupant
New User
Joined: 21 Mar 2007 Posts: 46 Location: India
|
|
|
|
Its not a packed COMP number .. Its a hexadecimal number like say
x'00112A'
and when I repeatedly add x'000001' to it
I want
x'00112B'
x'00112C'
.
.
.
.
x'00112F'
x'001130'
etc |
|
Back to top |
|
|
CICS Guy
Senior Member
Joined: 18 Jul 2007 Posts: 2146 Location: At my coffee table
|
|
|
|
Code: |
10 PACK-NUM1 PIC S9(06) COMP VALUE ZERO. |
Then do your math:
Code: |
COMPUTE PACK-NUM1 = PACK-NUM + 1. |
|
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19243 Location: Inside the Matrix
|
|
|
|
Hello,
Quote: |
I have a VSAM KSDS file with a packed hexadecimal three digit number as a part of its key like |
Quote: |
Its not a packed COMP number .. Its a hexadecimal number like say
|
Your terminology is completely confusing - because you are not using standard terms. You need to learn the proper names for things. . .
For starters - every byte on the mainframe is a hexadecimal value - x'00' thru x'FF'. Every byte is also a binary value - b'0000 0000' thru b'1111 1111'.
What it the picture of the 3-byte field in the vsam file?
One way to do what you say you want is to define an s9(8) comp field, redefine it as a 1 byte filler and a 3-byte pic xxx field. To increase the value by one, simply add 1 to the s9(8) comp field and move the pic xxx fiedl to whereever you want it. |
|
Back to top |
|
|
himanshupant
New User
Joined: 21 Mar 2007 Posts: 46 Location: India
|
|
|
|
sorry about the inadvertent confusion..
the three byte field`s PIC clause is XXX.
So if I add a simple 1 to the XXX will I get the desired result ?? |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19243 Location: Inside the Matrix
|
|
|
|
Hello,
No.
You should do as suggested and define an s9(8) comp field and redefine it. As your data of interest is 3 bytes, make the first byte of the redefinition a filler and bytes 2-4 your 3-byte value. Add to the comp field to increment the xxx value. |
|
Back to top |
|
|
mmwife
Super Moderator
Joined: 30 May 2003 Posts: 1592
|
|
|
|
If you're confined to a 3 byte field because the file is already in use with that configuration, you can move the 3 bytes to a four byte COMP field (redefine the COMP field to PIC X(4), VALUE the COMP field to zeros and use ref/mod to move the 3 byte VSAM key field to it [e.g. move 3-BYTES to PIC-X-4-BYTES(2:3) ].
After the math, ref/mod move the the PIC4 field back to the VSAM key field. |
|
Back to top |
|
|
himanshupant
New User
Joined: 21 Mar 2007 Posts: 46 Location: India
|
|
|
|
I am using something like the below
03 WS-HEX-NUMBER-NUM PIC S9(8) COMP VALUE X'00110A'.
03 WS-HEX-NUMBER REDEFINES WS-HEX-NUMBER-NUM.
05 FILLER PIC X.
05 WS-HEX-CHAR PIC XXX.
.
.
.
.
.
PROCEDURE DIVISON
.
.
.
.
.
ADD 1 TO WS-HEX-NUMBER-NUM
DISPLAY ' HEX 2 = ' WS-HEX-CHAR
I am getting a compilation error as below
IGYGR1080-S A "VALUE" clause literal was not compatible with the data category of subject data item. The "VALUE" clause was discarded.
|
|
Back to top |
|
|
CICS Guy
Senior Member
Joined: 18 Jul 2007 Posts: 2146 Location: At my coffee table
|
|
|
|
Try:
Code: |
03 WS-HEX-NUMBER-NUM PIC S9(8) COMP VALUE 4362.
03 WS-HEX-NUMBER REDEFINES WS-HEX-NUMBER-NUM.
05 FILLER PIC X.
05 WS-HEX-CHAR PIC XXX. |
Or:
Code: |
03 WS-HEX-CHARACTER PIC X(4) VALUE X'00110A'.
03 WS-HEX-NUMBER-NUM REDEFINES WS-HEX-CHARACTER
PIC S9(8) COMP.
03 WS-HEX-NUMBER REDEFINES WS-HEX-NUMBER-NUM.
05 FILLER PIC X.
05 WS-HEX-CHAR PIC XXX. |
|
|
Back to top |
|
|
himanshupant
New User
Joined: 21 Mar 2007 Posts: 46 Location: India
|
|
|
|
thanks... seems to work..
One more question , any way I can see the number in SYSOUT of the job
for example if I add 1 to 00110A and I get 0011OB , can I see this value in SYSOUT ?
I am not able to see it if I am doing a display like
DISPLAY WS-HEX-CHAR |
|
Back to top |
|
|
CICS Guy
Senior Member
Joined: 18 Jul 2007 Posts: 2146 Location: At my coffee table
|
|
|
|
Since a binary X'00110A' is a decimal '4362', which are you trying to 'see'?
If WS-HEX-CHAR is comp, COBOL will display the latter, if WS-HEX-CHAR is character, COBOL will display the three bytes but you will need HEX ON to see it.
There have been several good snipits of COBOL code given to display hex character strings as display, ie., X'00110A' displayed as X'F0F0F1F1F0C1'. |
|
Back to top |
|
|
himanshupant
New User
Joined: 21 Mar 2007 Posts: 46 Location: India
|
|
|
|
I am trying to see X'00110A ' as character 00110A
WS-HEX-CHAR is comp but what I am seeing on adding 1 to it in hex format is x'110A41' ... this is pretty strange ..
could it be that the string has encountered some conversion like into 2s complement form or something like that ?? |
|
Back to top |
|
|
CICS Guy
Senior Member
Joined: 18 Jul 2007 Posts: 2146 Location: At my coffee table
|
|
|
|
As far as the x'110A41' goes, I'd guess that you used the second example and did not correct my error:
03 WS-HEX-CHARACTER PIC X(4) VALUE X'00110A'.
should be:
03 WS-HEX-CHARACTER PIC X(4) VALUE X'0000110A'.
And again I repeat:
Quote: |
There have been several good snipits of COBOL code given to display hex character strings as display, ie., X'00110A' displayed as X'F0F0F1F1F0C1'. |
|
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8700 Location: Dubuque, Iowa, USA
|
|
|
|
Quote: |
I am trying to see X'00110A ' as character 00110A
WS-HEX-CHAR is comp but what I am seeing on adding 1 to it in hex format is x'110A41' ... this is pretty strange ..
could it be that the string has encountered some conversion like into 2s complement form or something like that ?? |
Actually, COBOL did exactly what you told it to do. PIC X(04) field with value X'00110A' has the value left-justified blank filled, so the actual value in the field is X'00110A40'. Add 1 to that and you get X'00110A41'. |
|
Back to top |
|
|
|