Change the layout of the report in COBOL



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

Change the layout of the report in COBOL

Postby Nazziman » Thu Dec 27, 2012 9:28 am

I have a task to produce a report based on the data from DB2 table. Currently, I want to have a different layout which the account number did not repeatedly appear. For example, current output:

 ---------------------------------------
   ACCOUNT NO.   CERT AMOUNT   
   ---------------------------------------
    111111111           100.00         
    111111111        5,000.00         
    222222222           100.00         
    222222222        5,000.00         
    333333333           100.00         
    333333333        5,000.00         
         TOTAL       15,300.00

My desired output is this:

------------------------------------------
   ACCOUNT NO.   CERT AMOUNT
   ----------------------------------------
    111111111          5,100.00     
    222222222          5,100.00     
    333333333          5,100.00     
           TOTAL       15,300.00


How to compute the subtotal for each account?

Currently, I'm using this coding to add summation of all amount which produce the TOTAL:

           ADD W-CERT-AMOUNT1 TO W-TOTAL-TEMP1.                                 
           MOVE W-TOTAL-TEMP1       TO W-RPT-CERT-TOTAL.   


Since I'm currently new in COBOL programming (about 1 month), I have still difficulties in doing this task.
Also, how can I automatically add the account number without the duplication? Do I need to set it manually? For example, MOVE '111111111' to W-RPT-ACC-NO.
Thank you in advance for your help.

Code'd
Nazziman
 
Posts: 3
Joined: Thu Dec 27, 2012 8:24 am
Has thanked: 0 time
Been thanked: 0 time

Re: Change the layout of the report in COBOL

Postby chandurokzz » Thu Dec 27, 2012 12:20 pm

Hi Nazziman,

You may consider writing a query,

Select  Account No,                     
          SUM(Cert Amount)     
INTO  :host-Account-no
        , :host-total-amount               
  FROM   <table.name>                 
  GROUP BY Account No


Thanks,
Chandu
chandurokzz
 
Posts: 10
Joined: Wed Apr 11, 2012 12:49 pm
Has thanked: 1 time
Been thanked: 0 time

Re: Change the layout of the report in COBOL

Postby dick scherrer » Thu Dec 27, 2012 8:42 pm

Hello and welcome to the forum,

How you implement a solution would depend on the instructions given to the class. Using a query like the one posted will get the answer, but if the goal of the exercise is to accumulate the totals in the COBOL code, this will not meet the requirement.

Before submitting a "non-cobol" solution, suggest you confirm that either method is acceptable.
Hope this helps,
d.sch.
User avatar
dick scherrer
Global moderator
 
Posts: 6268
Joined: Sat Jun 09, 2007 8:58 am
Has thanked: 3 times
Been thanked: 93 times

Re: Change the layout of the report in COBOL

Postby c62ap90 » Thu Dec 27, 2012 9:49 pm

You look like you are on the correct path Nazziman by using WORKING-STORAGE to hold your Account and Amount.
This looks like a typical COBOL control-break program.

Basically (pseudo code)…
Read Input
at end
move WS-Account-No to <print line>
move WS-Cert-Amount to <print line>
write <print line>
move WS-Cert-Amount-Grand-Total to <print line>
write <print line>
End-Read

If Input-Account-No not equal WS-Account-No
move WS-Account-No to <print line>
move WS-Cert-Amount to <print line>
write <print line>
move zero to WS-Cert-Amount
End-if

Move Input-Account-No to WS-Account-No.
Add Input-Cert-Amount to WS-Cert-Amount
WS-Cert-Amount-Grand-Total.

Go back and read another record…

Also, the Input-Account-No should be in sorted order before COBOL program executes.
You will also have to tinker with the first record storing Account and Amount in Working Storage. You'll figure it out.
Have fun!

FD ACCOUNT-FILE
BLOCK CONTAINS 0 RECORDS
RECORDING MODE F
RECORD CONTAINS 80 CHARACTERS
LABEL RECORDS ARE STANDARD.
01 ACCOUNT-REC.
05 AR-ACCOUNT-NO PIC 9(09).
05 AR-CERT-AMOUNT PIC 9(05)V99.
05 FILLER PIC X(64).
c62ap90
 
Posts: 125
Joined: Thu Oct 11, 2012 10:24 pm
Has thanked: 1 time
Been thanked: 7 times


Return to IBM Cobol

 


  • Related topics
    Replies
    Views
    Last post