IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Packing string in cobol


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
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
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

Superior Member


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

PostPosted: Wed Dec 10, 2008 3:36 pm
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
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
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: 2501
Location: Atlanta, Georgia, USA

PostPosted: Wed Dec 10, 2008 5:01 pm
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: 2481
Location: @my desk

PostPosted: Wed Dec 10, 2008 5:06 pm
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
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: 2481
Location: @my desk

PostPosted: Wed Dec 10, 2008 6:22 pm
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

Moderator Emeritus


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

PostPosted: Thu Dec 11, 2008 1:26 am
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
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
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: 2501
Location: Atlanta, Georgia, USA

PostPosted: Thu Dec 11, 2008 6:44 pm
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: 1249
Location: Richfield, MN, USA

PostPosted: Thu Dec 11, 2008 8:58 pm
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 View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts Replace each space in cobol string wi... COBOL Programming 3
No new posts PARSE Syntax for not fix length word ... JCL & VSAM 7
No new posts COBOL -Linkage Section-Case Sensitive COBOL Programming 1
No new posts COBOL ZOS Web Enablement Toolkit HTTP... COBOL Programming 0
No new posts Sortjoin and Search for a String and ... DFSORT/ICETOOL 1
Search our Forums:

Back to Top