Page 1 of 1

Write values to dataset, that are aligned by right

PostPosted: Thu Mar 15, 2018 2:45 am
by Matt99
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?

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

PostPosted: Thu Mar 15, 2018 3:30 am
by Robert Sample
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.

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

PostPosted: Thu Mar 15, 2018 11:10 am
by Matt99
Wow, what a dumb mistake from my part. Thanks!