Page 1 of 1

Change the layout of the report in COBOL

PostPosted: Thu Dec 27, 2012 9:28 am
by Nazziman
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

Re: Change the layout of the report in COBOL

PostPosted: Thu Dec 27, 2012 12:20 pm
by chandurokzz
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

Re: Change the layout of the report in COBOL

PostPosted: Thu Dec 27, 2012 8:42 pm
by dick scherrer
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.

Re: Change the layout of the report in COBOL

PostPosted: Thu Dec 27, 2012 9:49 pm
by c62ap90
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).