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
 

 

Packing string in cobol

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

New User


Joined: 24 Feb 2006
Posts: 15
Location: calicut

PostPosted: Wed Dec 10, 2008 3:31 pm    Post subject: Packing string in cobol
Reply with quote

Hi

I need the string "AEFB" be packed in a variable of PIC X(2). Can anyone help me please...
Back to top
View user's profile Send private message

Anuj Dhawan

Senior Member


Joined: 22 Apr 2006
Posts: 6258
Location: Mumbai, India

PostPosted: Wed Dec 10, 2008 3:36 pm    Post subject:
Reply with quote

Hi,

Packed ? what does that mean in this context ? Please clarify.
Back to top
View user's profile Send private message
shahin

New User


Joined: 24 Feb 2006
Posts: 15
Location: calicut

PostPosted: Wed Dec 10, 2008 3:41 pm    Post subject:
Reply with quote

I mean i want the string AEFB be packed in a variable of PIC X(02) in cobol. ie the first nibble contains A, the second nibble E like that.
Back to top
View user's profile Send private message
shahin

New User


Joined: 24 Feb 2006
Posts: 15
Location: calicut

PostPosted: Wed Dec 10, 2008 4:55 pm    Post subject:
Reply with quote

To make it more clear, when i do HEX ON i need to see the letter A in first nibble, E in second nibble like that..
Back to top
View user's profile Send private message
Bill O'Boyle

CICS Moderator


Joined: 14 Jan 2008
Posts: 2502
Location: Atlanta, Georgia, USA

PostPosted: Wed Dec 10, 2008 5:01 pm    Post subject: Re: Packing string in cobol
Reply with quote

Note that the following technique (for obvious reasons) will work only for letters "A" through "F".

Code:

03  WS-AEFB-CHAR PIC X(04) VALUE 'AEFB'.
03  WS-AEFB-PACKED PIC  X(02).
03  WS-PACKED PIC 9(03) COMP-3.
03  WS-PACKED-V9 REDEFINES WS-PACKED PIC 9(02)V9 COMP-3.
03  WS-PACKED-X REDEFINES WS-PACKED PIC X(03).
03  WS-DISPLAY PIC 9(05).
03  WS-DISPLAY-V9 REDEFINES WS-DISPLAY PIC 9(04)V9.
03  WS-DISPLAY-X REDEFINES WS-DISPLAY PIC X(05).

MOVE WS-AEFB-CHAR TO WS-DISPLAY-X.
MOVE ZERO TO WS-DISPLAY-X (5:).

INSPECT WS-DISPLAY-X CONVERTING 'ABCDEF' TO X'FAFBFCFDFEFF'.

MOVE WS-DISPLAY-V9 TO WS-PACKED-V9.
MOVE WS-PACKED-X TO WS-AEFB-PACKED.

Regards,

Bill
Back to top
View user's profile Send private message
Arun Raj

Moderator


Joined: 17 Oct 2006
Posts: 2181
Location: @my desk

PostPosted: Wed Dec 10, 2008 5:06 pm    Post subject:
Reply with quote

shahin,

You can do something like this.
Code:
05 PACK-CHAR PIC X(2)

MOVE X'AEFB' TO PACK-CHAR
DISPLAY 'PACK-CHAR:' PACK-CHAR

Output
Code:
PACK-CHAR:ÞÛ   
DCCD6CCCD7AF444
713203819AEB000
Back to top
View user's profile Send private message
shahin

New User


Joined: 24 Feb 2006
Posts: 15
Location: calicut

PostPosted: Wed Dec 10, 2008 6:12 pm    Post subject:
Reply with quote

Thansk a lot Bill and Arun,

Arun,

Can we use this method when we move variable content?
Back to top
View user's profile Send private message
Arun Raj

Moderator


Joined: 17 Oct 2006
Posts: 2181
Location: @my desk

PostPosted: Wed Dec 10, 2008 6:22 pm    Post subject:
Reply with quote

Quote:
Can we use this method when we move variable content?
What is your source variable definition? Where do you get this data from?
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: Thu Dec 11, 2008 1:26 am    Post subject:
Reply with quote

Hello,

Quote:
I need the string "AEFB" be packed in a variable of PIC X(2).
What should happen if the "input" contains "ASDF" or "AVLE"? Is there some default replacement value for values other than 0-9,A-F?

To clarify, "A3FE" would be valid, correct?
Back to top
View user's profile Send private message
shahin

New User


Joined: 24 Feb 2006
Posts: 15
Location: calicut

PostPosted: Thu Dec 11, 2008 11:06 am    Post subject:
Reply with quote

Arun,

The variable source is an input file. For example i need INFILE-REC(1:4) be packed to a variable of PIC X(02).

d.sch,

The input will always contain 0-9,A-F only.
Back to top
View user's profile Send private message
shahin

New User


Joined: 24 Feb 2006
Posts: 15
Location: calicut

PostPosted: Thu Dec 11, 2008 6:04 pm    Post subject:
Reply with quote

Bill,

I tried the code and I am not getting the values properly packed. When i tried packing "AEFB" and written into a file the output i got in HEX ON is like:

Code:



000001 Û .{                                                                   
       F04C00000000000000000000000000000000000000000000000000000000000000000000
       BFB000000000000000000000000000000000000000000000000000000000000000000000


The file defenition was like this:

Code:


01  TD-SUBFLE-OUT-REC.             
    05 PACKED-FLD        PIC X(2). 
    05 FILLER            PIC X(78).



Please help
Back to top
View user's profile Send private message
Bill O'Boyle

CICS Moderator


Joined: 14 Jan 2008
Posts: 2502
Location: Atlanta, Georgia, USA

PostPosted: Thu Dec 11, 2008 6:44 pm    Post subject:
Reply with quote

Oops! icon_redface.gif I mistyped the definitions for the following fields -

03 WS-PACKED PIC 9(05) COMP-3.
03 WS-PACKED-V9 REDEFINES WS-PACKED PIC 9(04)V9 COMP-3.

The definition of WS-PACKED-X is correct (3-Bytes).

This should work for you now, with WS-PACKED-X = X'AEFB0F', but all you need is the first two bytes.

Regards,

Bill
Back to top
View user's profile Send private message
Terry Heinze

JCL Moderator


Joined: 14 Jul 2008
Posts: 1239
Location: Richfield, MN, USA

PostPosted: Thu Dec 11, 2008 8:58 pm    Post subject:
Reply with quote

If the 4 half nibbles of your data will always be hex (0-F), you could move 44795 to a PIC S9(9) COMP field, redefine it as a PIC X(4) field, and reference the last 2 bytes of it. (Untested).
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
This topic is locked: you cannot edit posts or make replies. Full Time COBOL Software Development ... shally Mainframe Jobs 0 Fri Jan 20, 2017 5:24 am
This topic is locked: you cannot edit posts or make replies. COBOL Software Development Lead at Fi... shally Mainframe Jobs 0 Fri Jan 20, 2017 5:21 am
No new posts Executing OO COBOL program invoking J... Virendra Shambharkar COBOL Programming 2 Tue Jan 10, 2017 6:37 pm
No new posts OO COBOL compile error Virendra Shambharkar COBOL Programming 3 Tue Jan 10, 2017 6:05 pm
No new posts Need Suggestion on COBOL program vickey_dw COBOL Programming 5 Thu Jan 05, 2017 10:55 pm


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