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
 

 

Packed Hexadecimal addition

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
View previous topic :: :: View next topic  
Author Message
himanshupant

New User


Joined: 21 Mar 2007
Posts: 46
Location: India

PostPosted: Mon Apr 06, 2009 11:09 pm    Post subject: Packed Hexadecimal addition
Reply with quote

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
View user's profile Send private message

Douglas Wilder

Active User


Joined: 28 Nov 2006
Posts: 305
Location: Deerfield IL

PostPosted: Mon Apr 06, 2009 11:28 pm    Post subject:
Reply with quote

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
View user's profile Send private message
himanshupant

New User


Joined: 21 Mar 2007
Posts: 46
Location: India

PostPosted: Mon Apr 06, 2009 11:34 pm    Post subject:
Reply with quote

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
View user's profile Send private message
CICS Guy

Senior Member


Joined: 18 Jul 2007
Posts: 2150
Location: At my coffee table

PostPosted: Mon Apr 06, 2009 11:44 pm    Post subject:
Reply with quote

Code:
    10  PACK-NUM1      PIC S9(06) COMP VALUE ZERO.

Then do your math:
Code:
        COMPUTE PACK-NUM1 = PACK-NUM + 1.
Back to top
View user's profile Send private message
dick scherrer

Site Director


Joined: 23 Nov 2006
Posts: 19270
Location: Inside the Matrix

PostPosted: Mon Apr 06, 2009 11:48 pm    Post subject:
Reply with quote

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
View user's profile Send private message
himanshupant

New User


Joined: 21 Mar 2007
Posts: 46
Location: India

PostPosted: Mon Apr 06, 2009 11:51 pm    Post subject:
Reply with quote

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
View user's profile Send private message
dick scherrer

Site Director


Joined: 23 Nov 2006
Posts: 19270
Location: Inside the Matrix

PostPosted: Mon Apr 06, 2009 11:55 pm    Post subject:
Reply with quote

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
View user's profile Send private message
mmwife

Super Moderator


Joined: 30 May 2003
Posts: 1592

PostPosted: Tue Apr 07, 2009 4:05 am    Post subject:
Reply with quote

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
View user's profile Send private message
himanshupant

New User


Joined: 21 Mar 2007
Posts: 46
Location: India

PostPosted: Tue Apr 07, 2009 10:42 am    Post subject:
Reply with quote

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.

icon_sad.gif
Back to top
View user's profile Send private message
CICS Guy

Senior Member


Joined: 18 Jul 2007
Posts: 2150
Location: At my coffee table

PostPosted: Tue Apr 07, 2009 11:08 am    Post subject:
Reply with quote

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
View user's profile Send private message
himanshupant

New User


Joined: 21 Mar 2007
Posts: 46
Location: India

PostPosted: Tue Apr 07, 2009 11:28 am    Post subject:
Reply with quote

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
View user's profile Send private message
CICS Guy

Senior Member


Joined: 18 Jul 2007
Posts: 2150
Location: At my coffee table

PostPosted: Tue Apr 07, 2009 11:39 am    Post subject:
Reply with quote

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
View user's profile Send private message
himanshupant

New User


Joined: 21 Mar 2007
Posts: 46
Location: India

PostPosted: Tue Apr 07, 2009 11:53 am    Post subject:
Reply with 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 ??
Back to top
View user's profile Send private message
CICS Guy

Senior Member


Joined: 18 Jul 2007
Posts: 2150
Location: At my coffee table

PostPosted: Tue Apr 07, 2009 12:05 pm    Post subject:
Reply with quote

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'.
icon_redface.gif
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
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 7913
Location: Bellevue, IA

PostPosted: Tue Apr 07, 2009 4:44 pm    Post subject:
Reply with quote

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
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 Decimal to hexadecimal Steve Ironmonger DFSORT/ICETOOL 5 Fri May 27, 2016 4:19 pm
No new posts Performing addition using JCL sort card Shaheen Shaik DFSORT/ICETOOL 14 Fri May 06, 2016 12:25 pm
No new posts Need help on comparing hexadecimal va... ashok_uddaraju DFSORT/ICETOOL 4 Thu Apr 28, 2016 2:08 am
No new posts conversion from char to packed decimal Musab Ahmed DFSORT/ICETOOL 7 Fri Apr 08, 2016 1:12 pm
No new posts NDM Packed Data file from Mainframes ... santhosh5983 IBM Tools 2 Wed Mar 30, 2016 2:36 am


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