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

How to store a Packed value in a Variable of PIC clause X?


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
dates

New User


Joined: 11 Mar 2008
Posts: 9
Location: LA,USA

PostPosted: Mon May 03, 2010 3:22 pm
Reply with quote

I have Packed value of type S9(7) COMP-3 .

Now i need to store this value in a pre-defined field of type X(20). Is there a way i can do this ?
Back to top
View user's profile Send private message
Anuj Dhawan

Superior Member


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

PostPosted: Mon May 03, 2010 3:39 pm
Reply with quote

COBOL MOVE verb? icon_confused.gif icon_neutral.gif
Back to top
View user's profile Send private message
dates

New User


Joined: 11 Mar 2008
Posts: 9
Location: LA,USA

PostPosted: Mon May 03, 2010 3:55 pm
Reply with quote

MOVE will unpack the value and store it in X(20),

I want the packed value to be stored as it is in PACKED format in the X(20) field.
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: Mon May 03, 2010 3:56 pm
Reply with quote

Redefining the COMP-3 field as PIC X will allow you to do this -

Code:

03  WS-PACKED-VALUE PIC S9(07) COMP-3.
03  WS-PACKED-VALUE-X REDEFINES WS-PACKED-VALUE PIC  X(04).
03  WS-TWENTY-BYTES PIC  X(20) VALUE HIGH-VALUES.
03  WS-POS PIC  9(08) BINARY.
*
* LEFT-JUSTIFIED WITH LOW-ORDER HIGH-VALUES
*
MOVE WS-PACKED-VALUE-X TO WS-TWENTY-BYTES (1:LENGTH OF WS-PACKED-VALUE-X).
*
* RIGHT-JUSTIFIED WITH HIGH-ORDER HIGH-VALUES
*
COMPUTE WS-POS = (LENGTH OF WS-TWENTY-BYTES - LENGTH OF WS-PACKED-VALUE-X) + 1.
MOVE WS-PACKED-VALUE-X TO WS-TWENTY-BYTES (WS-POS:).

HIGH-VALUES are used as a placeholder for determining the length of the COMP-3 data. You can use an INSPECT to find this placeholder.

Bill
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: Mon May 03, 2010 7:51 pm
Reply with quote

Hello,

Quote:
I want the packed value to be stored as it is in PACKED format in the X(20) field.

What should happen to the "other" bytes in the 20-byte field? Should they be unchanged or set to spaces or?
Back to top
View user's profile Send private message
Kjeld

Active User


Joined: 15 Dec 2009
Posts: 365
Location: Denmark

PostPosted: Tue May 04, 2010 5:46 am
Reply with quote

Using a group move will move the bytes as is:
Code:

01 PACKED-GROUP.
  05 FILLER                   PIC X(16) VALUE 'EYECATCHER16: '.
  05 YOUR-PACKED-FIELD        PIC S9(7) COMP-3.
01 OUTPUT-DATA.
  05 RECEIVING-FIELD          PIC X(20).
.....
PROCEDURE DIVISION.
     MOVE +1234567 to YOUR-PACKED-FIELD
     MOVE PACKED-GROUP to RECEIVING_FIELD
     ....
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 Store the data for fixed length COBOL Programming 1
No new posts Extracting Variable decimal numbers f... DFSORT/ICETOOL 17
No new posts PD not working for unsigned packed JO... DFSORT/ICETOOL 5
No new posts Def PD not working for unsigned packe... JCL & VSAM 3
No new posts Variable Output file name DFSORT/ICETOOL 8
Search our Forums:

Back to Top