Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Unpacking decimals

Status
Not open for further replies.

couchman02

Programmer
May 29, 2001
7
US
Hello guys and girls, I searched the archives and didn't see what I was looking for but I know someone has had this question before. I also wanted someone to check out my code on how I'm doing it and maybe suggest a better way.
Does it seem like I'm on the right path to converting a packed-decimal file to displayable fields in working storage that I can turn around and write out to a new file that's non-packed?

FD FILE

01 RECORD
03 BANK PIC S999 COMP-3.
03 APPLICATION PIC S9 COMP-3.
03 ACCOUNT PIC S9(8) COMP-3.


WORKING-STORAGE.

01 CONVERSION-FIELDS.
05 WS-BANK PIC S999 COMP-3.
05 WS-BANK-R REDEFINES WS-BANK PIC XX.
05 WS-APPL PIC S9 COMP-3.
05 WS-APPL-R REDEFINES WS-APPL PIC X.
05 WS-ACCT PIC S9(8) COMP-3.
05 WS-ACCT-R REDEFINES WS-ACCT PIC X(8).

01 DISPLAY-FIELDS.
05 WS-DISPLAY-BANK PIC 999.
05 WS-DISPLAY-APPL PIC 99.
05 WS-DISPLAY-ACCT PIC 9(16).

PROCEDURE-DIVISION.
PERFORM 0150-CONVERSION-RTN

0150-CONVERSION-RTN.

MOVE BANK TO WS-BANK-R
MOVE WS-BANK TO WS-DISPLAY-BANK

MOVE APPLICATION TO WS-APPL-R
MOVE WS-APPL TO WS-DISPLAY-APPL

MOVE ACCOUNT TO WS-ACCT-R
MOVE WS-ACCT TO WS-DISPLAY-ACCT

DISPLAY 'WS-DISPLAY-BANK = ' WS-DISPLAY-BANK
DISPLAY 'WS-DISPLAY-APPL = ' WS-DISPLAY-APPL
DISPLAY 'WS-DISPLAY-ACCT = ' WS-DISPLAY-ACCT

I ran this and I'm not getting what I hoped to see, It's not blowing up either so I guess thats good. Any responses is very much appreciated. Oh yeah, I'm using Cobol OS/390 on the mainframe.

Thanks again,
Rookie Progammer
-Couch
 
Couch,

you are doing stuff you don't need to do. if all you need to do is turn your packed decimals into display numerics, try the following example:

01 PACKED-FIELDS.
03 PF-BANK PIC S999 COMP-3.
03 PF-APPLICATION PIC S9 COMP-3.
03 PF-ACCOUNT PIC S9(8) COMP-3.

01 DISPLAY-FIELDS.
03 DF-BANK PIC 999.
03 DF-APPLICATION PIC 9.
03 DF-ACCOUNT PIC 9(8).

MOVE CORRESPONDING PACKED-FIELDS TO DISPLAY-FIELDS.
DISPLAY 'BANK' ... etc.

a simple numeric move is all you need.

i hope this is what you were looking for.
 
Aw geez, talking about not seeing the forest cause of the trees. I'll try it first thing Wednsday and let you know.

Thanks for quick reply Winzip.


-Couch
 
Data names must be EXACTLY the same in order to use MOVE CORRESPONDING.

01 PACKED-FIELDS.
03 BANK PIC S999 COMP-3.
03 APPLICATION PIC S9 COMP-3.
03 ACCOUNT PIC S9(8) COMP-3.

01 DISPLAY-FIELDS.
03 BANK PIC 999.
03 APPLICATION PIC 9.
03 ACCOUNT PIC 9(8).

MOVE CORRESPONDING PACKED-FIELDS TO DISPLAY-FIELDS.
DISPLAY 'Bank ' BANK IN DISPLAY-FIELDS ... etc.

HOWEVER, if you are going to use DISPLAY, you don't even have to convert. The compiler will do it for you.
DISPLAY BANK OF PACKED-FIELDS will show the unpacked number, except negative numbers will have an overpunch on the last character. (Some compilers may not overpunch.)

Stephen J Spiro
ANSI COBOL Standards Committee
 
Thanks for reply Stephen, I've tried to mark your and winzip posts as helpful but I keep getting error message. It could be where using I'm using IE 4 here at work. I'll try again when I get home.


-Couch
 
01 INPUT-REC.
05 NUMBER-P PIC 9(05) COMP-3.

01 OUTPUT-REC.
05 NUMBER-9 PIC 9(05).

MOVE NUMBER-P TO NUMBER-9.

This works for me. I suppose you could go crazy with corresponding if you wanted to. If you do not like my post feel free to point out your opinion or my errors.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top