Write values to dataset, that are aligned by right



Support for OS/VS COBOL, VS COBOL II, COBOL for OS/390 & VM and Enterprise COBOL for z/OS

Write values to dataset, that are aligned by right

Postby Matt99 » Thu Mar 15, 2018 2:45 am

Hi,

I was struggling with this problem:

I write report to the dataset and want the amount values to be aligned by right:

Let's say I fetch 3 rows from table

A. 200.000
B. 2000.000
C. 100473.090

I want to report look like this:

A  2009-12-29              200.000  
B  2009-12-29             2000.000
C  2009-12-29           100473.090


These are main steps of what I tried:

Variables:
01   WS-AMOUNT            PIC S9(15)V9(3) COMP-3 VALUE 0.
01   REPORT-LINE.                                      
       05 WS-DATE         PIC X(10).              
       05                       PIC X VALUE ' '.        
       05 WS-AMOUNT-R                              
                             PIC ZZZ,ZZZ,ZZZ,ZZZ,ZZ9,999.


SQL fetch:
FETCH CURR INTO  
      :WS-DATE,
      :WS--AMOUNT


Move:
MOVE WS-AMOUNT TO WS-AMOUNT-R



What i get:
2009-12-29                   0,200
2009-12-29                   2,000
2009-12-29                 100,473


this might give you some info. When i add these displays after move sentence, this what i see:
DISPLAY WS-AMOUNT
DISPLAY WS-AMOUNT-R

+000000000000200000    
                  0,200
+000000000002000000    
                  2,000
+000000000100473090    
                100,473


I also tried JUSTIFIED RIGHT, but that only seem to work for DISPLAYs and don't have any effect when I print values to dataset.
Do you have any suggestions?
Matt99
 
Posts: 3
Joined: Fri Dec 15, 2017 1:47 am
Has thanked: 1 time
Been thanked: 0 time

Re: Write values to dataset, that are aligned by right

Postby Robert Sample » Thu Mar 15, 2018 3:30 am

Try
      05 WS-AMOUNT-R                              
                             PIC ZZZ,ZZZ,ZZZ,ZZZ,ZZ9.999
COBOL is producing exactly what you said you wanted -- data without any decimal points and a zero in front of the last comma if the value is less than 1000.

These users thanked the author Robert Sample for the post:
Matt99 (Sun Mar 25, 2018 8:13 pm)
Robert Sample
Global moderator
 
Posts: 3720
Joined: Sat Dec 19, 2009 8:32 pm
Location: Dubuque, Iowa, USA
Has thanked: 1 time
Been thanked: 279 times

Re: Write values to dataset, that are aligned by right

Postby Matt99 » Thu Mar 15, 2018 11:10 am

Wow, what a dumb mistake from my part. Thanks!
Matt99
 
Posts: 3
Joined: Fri Dec 15, 2017 1:47 am
Has thanked: 1 time
Been thanked: 0 time


Return to IBM Cobol

 


  • Related topics
    Replies
    Views
    Last post