View previous topic :: View next topic
|
Author |
Message |
shahin
New User
Joined: 24 Feb 2006 Posts: 15 Location: calicut
|
|
|
|
Hi
I need the string "AEFB" be packed in a variable of PIC X(2). Can anyone help me please... |
|
Back to top |
|
|
Anuj Dhawan
Superior Member
Joined: 22 Apr 2006 Posts: 6248 Location: Mumbai, India
|
|
|
|
Hi,
Packed ? what does that mean in this context ? Please clarify. |
|
Back to top |
|
|
shahin
New User
Joined: 24 Feb 2006 Posts: 15 Location: calicut
|
|
|
|
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 |
|
|
shahin
New User
Joined: 24 Feb 2006 Posts: 15 Location: calicut
|
|
|
|
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 |
|
|
Bill O'Boyle
CICS Moderator
Joined: 14 Jan 2008 Posts: 2501 Location: Atlanta, Georgia, USA
|
|
|
|
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 |
|
|
Arun Raj
Moderator
Joined: 17 Oct 2006 Posts: 2481 Location: @my desk
|
|
|
|
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 |
|
|
shahin
New User
Joined: 24 Feb 2006 Posts: 15 Location: calicut
|
|
|
|
Thansk a lot Bill and Arun,
Arun,
Can we use this method when we move variable content? |
|
Back to top |
|
|
Arun Raj
Moderator
Joined: 17 Oct 2006 Posts: 2481 Location: @my desk
|
|
|
|
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 |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19243 Location: Inside the Matrix
|
|
|
|
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 |
|
|
shahin
New User
Joined: 24 Feb 2006 Posts: 15 Location: calicut
|
|
|
|
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 |
|
|
shahin
New User
Joined: 24 Feb 2006 Posts: 15 Location: calicut
|
|
|
|
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 |
|
|
Bill O'Boyle
CICS Moderator
Joined: 14 Jan 2008 Posts: 2501 Location: Atlanta, Georgia, USA
|
|
|
|
Oops! 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 |
|
|
Terry Heinze
JCL Moderator
Joined: 14 Jul 2008 Posts: 1248 Location: Richfield, MN, USA
|
|
|
|
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 |
|
|
|