MVSFORUMS.com Forum Index MVSFORUMS.com
A Community of and for MVS Professionals
 
 FAQFAQ   SearchSearch   Quick Manuals   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

COBOL Packed to display numeric data conversion

 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Application Programming
View previous topic :: View next topic  
Author Message
Srishti Rawat
Beginner


Joined: 03 Nov 2021
Posts: 20
Topics: 6

PostPosted: Fri Mar 24, 2023 6:25 am    Post subject: COBOL Packed to display numeric data conversion Reply with quote

Hi Team,

I need to convert packed decimal to signed numeric decimal number in my COBOL program.
I am receiving the amount field from input file as packed decimal s9(13)v9(2) which gets displayed in my output file like below:
00000000005907P
But I want this to display in my output file like
-590.77.

I tried moving it to zoned decimal and than to numeric edit but still the sign is missing.
Can anyone please help me with the COBOL code to convert it so that it should get displayed properly in my output file.

Thanks,
Srishti
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12367
Topics: 75
Location: San Jose

PostPosted: Fri Mar 24, 2023 12:00 pm    Post subject: Reply with quote

Srishti Rawat,

Try this
Code:

01 WS-PACKIN   PIC S9(13)V9(2) COMP-3.
01 WS-DISPOUT  PIC +++++++++++++.99.   

MOVE WS-PACKIN           TO WS-DISPOUT   
DISPLAY WS-DISPOUT                       

_________________
Kolusu - DFSORT Development Team (IBM)
DFSORT is on the Web at:
www.ibm.com/storage/dfsort

www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Srishti Rawat
Beginner


Joined: 03 Nov 2021
Posts: 20
Topics: 6

PostPosted: Sat Mar 25, 2023 10:47 am    Post subject: Reply with quote

Hi Kolusu,

Thanks for the reply. I tried it, but the decimal places are varying. Also for the negative number this is showing positive sign.
For ex, for 00000000005907P,
output : +59077.00
expected result: -590.77

Please suggest.
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12367
Topics: 75
Location: San Jose

PostPosted: Sat Mar 25, 2023 5:37 pm    Post subject: Reply with quote

Srishti Rawat wrote:
I need to convert packed decimal to signed numeric decimal number in my COBOL program.
I am receiving the amount field from input file as packed decimal s9(13)v9(2) which gets displayed in my output file like below:
00000000005907P


Srishti Rawat,

Looking at the data you are showing it is not COMP-3 aka Packed decimal. For comp-3 a negative number will have D or B an lower nibble of the data and positive data will have C or F as the sign

You sample data of 00000000005907P meant it is ZONED decimal data. here is a representation of the zoned decimal data.

Code:

ABCDEFGHI}JKLMNOPQR
CCCCCCCCCCDDDDDDDDDD
01234567890123456789


Hex C0 thru C9 are positive numbers and D0 thru D9 are negative numbers. So -7 would look as 00000000000000P and so a -590.77 would look as 00000000005907P. The same number in packed decimal format would like as X'000000000059077D'

So understand the difference between the numeric items and then post it properly.

Still the code is the same

Code:

01 WS-ZONEDN   PIC S9(13)V9(2).
01 WS-DISPOUT  PIC +++++++++++++.99. 

MOVE WS-ZONEDN           TO WS-DISPOUT
DISPLAY WS-DISPOUT                     

_________________
Kolusu - DFSORT Development Team (IBM)
DFSORT is on the Web at:
www.ibm.com/storage/dfsort

www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Srishti Rawat
Beginner


Joined: 03 Nov 2021
Posts: 20
Topics: 6

PostPosted: Sun Mar 26, 2023 10:30 am    Post subject: Reply with quote

Hi Kolusu,

I appreciate the explanation. I tried this with both packed and zoned decimal. Before posting this query in this forum, I already tried moving the variable to PIC -------------.99. which didnt work, was having the same issue.
For both of them(packed/zoned decimal) the results are as below:
Code:
01 WS-AMTPK     PIC S9(13)V9(2) COMP-3.
01 WS-AMTZN     PIC S9(13)V9(2).
01 WS-DISPOUT  PIC +++++++++++++.99.


Code:
MOVE WS-AMT  TO WS-AMTPK.
MOVE WS-AMTPK  TO WS-DISPOUT.
DISPLAY WS-DISPOUT.


Result: +59077.00

Code:
MOVE WS-AMT  TO WS-AMTZN.
MOVE WS-AMTZN  TO WS-DISPOUT.
DISPLAY WS-DISPOUT.


Result: +59077.00

Here, WS-AMT is variable from input file copybook where it is defined as X(15). This file is an output from another program where WS-AMT is defined as s9(13)v9(2). In the input file this amount field comes in zoned decimal 00000000005907P.

Also when I tried to display WS-AMTZN, it showed value 00000000590770{, not sure why it is adding last two zeroes.

I hope I am able to explain the scenario well.
[/code]
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12367
Topics: 75
Location: San Jose

PostPosted: Sun Mar 26, 2023 11:44 am    Post subject: Reply with quote

Srishti Rawat wrote:

Here, WS-AMT is variable from input file copybook where it is defined as X(15). This file is an output from another program where WS-AMT is defined as s9(13)v9(2). In the input file this amount field comes in zoned decimal 00000000005907P.


Srishti Rawat,

What version of COBOL are you running? If you are running 6.xx and higher what is the setting for ZONEDATA ?

Try this sample code and tell me what it produces.

Code:

01 WS-CHAR     PIC X(15).                       
01 WS-ZONEDN   REDEFINES WS-CHAR PIC S9(13)V9(2).
01 WS-DISPOUT  PIC +++++++++++++.99.             


     MOVE '00000000005907P'   TO WS-CHAR         
     MOVE WS-ZONEDN           TO WS-DISPOUT     
     DISPLAY WS-DISPOUT                         

_________________
Kolusu - DFSORT Development Team (IBM)
DFSORT is on the Web at:
www.ibm.com/storage/dfsort

www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Application Programming All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


MVSFORUMS
Powered by phpBB © 2001, 2005 phpBB Group