Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Column figures and not adding up

Status
Not open for further replies.

chris22232

Technical User
Sep 11, 2002
1
US
My column totals are not adding up after doing a move, add, and print-record.
Does anyone know the correct steps to getting columns to total up and give you a result in the bottom?
 
Chris,
Please explain more, listing programs, data etc., without which we are not going to be able to help.
Marc
 
I'm using Microfocus V.2 on Win98
I'm not able to print totals and most recently my error is: the program is doing a loop on 300-PROCESS-PAST ACCOUNTS. Any help would be greatly appreciated.


IDENTIFICATION DIVISION.
PROGRAM-ID.
*AUTHOR.
*DATE.

****************************************************************
* This program reads in customer name and prints amount owed *
* by each customer. Discounts will be given to customers when *
* certain day requirements are met. Totals will be printed for *
* each column. *
****************************************************************

ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.

SELECT DEL-FILE ASSIGN TO "A:\DEL.TXT"
ORGANIZATION IS LINE SEQUENTIAL.

SELECT PRINT-FILE ASSIGN TO "A:\DEL2.TXT"
ORGANIZATION IS LINE SEQUENTIAL.


*_______________________________________________________

DATA DIVISION.
FILE SECTION.
FD DEL-FILE.
01 DELINQUENT-RECORD.
05 DR-NAME PIC X(15).
05 DR-ACCOUNT-NO PIC X(6).
05 DR-AMOUNT-DUE PIC 9(5).
05 DR-DAYS-OVERDUE PIC X(3).
05 DR-DISCOUNT-RATE PIC 99.

FD PRINT-FILE.
01 PRINT-RECORD PIC X(133).

WORKING-STORAGE SECTION.

01 MORE-RECORDS PIC X VALUE "Y".

01 WS-DISCOUNT-AMOUNT PIC 9(4)999 VALUE ZERO.

01 WS-DISCOUNT-RATE PIC 9 VALUE ZERO.

01 WS-NET-AMOUNT PIC 9(4)999 VALUE ZERO.

01 DR-AMOUNT-TOTAL PIC 9(4)99 VALUE ZERO.

01 WS-DISCOUNT-TOTAL PIC 9(4)999 VALUE ZERO.

01 WS-NET-TOTAL PIC 9(4)999 VALUE ZERO.


01 HEADING-ONE.
05 PIC X(33) VALUE SPACES.
05 PIC X(24)
VALUE "LONGISTICS NETWORKS".

01 HEADING-TWO.
05 PIC X(30) VALUE SPACES.
05 PIC X(26)
VALUE "DELINQUENT ACCOUNTS REPORT".

*01 HEADING-THREE.
* 05 RUN-YEAR PIC 99.
* 05 RUN-MONTH PIC 99.
* 05 RUN-DAY PIC 99.


01 HEADING-THREE.
05 DATE-OF-RUN.
10 MO-OUT PIC 99.
10 PIC X VALUE "/".
10 DAY-OUT PIC 99.
10 PIC X VALUE "/".
10 YEAR-OUT PIC 99.
05 PIC X(65) VALUE SPACES.
05 PIC X(6)
VALUE "PAGE 1".

01 HEADING-FOUR.
05 PIC X(3) VALUE SPACES.
05 PIC X(7) VALUE "ACCOUNT".
05 PIC X(21) VALUE SPACES.
05 PIC X(7) VALUE "AMOUNT".
05 PIC X(5) VALUE SPACES.
05 PIC X(4) VALUE "DAYS".
05 PIC X(5) VALUE SPACES.
05 PIC X(8) VALUE "DISCOUNT".
05 PIC X(4) VALUE SPACES.
05 PIC X(8) VALUE "DISCOUNT".
05 PIC X(7) VALUE SPACES.
05 PIC X(3) VALUE "NET".

01 HEADING-FIVE.
05 PIC X(6) VALUE "NUMBER".
05 PIC X(2) VALUE SPACES.
05 PIC X(4) VALUE "NAME".
05 PIC X(20) VALUE SPACES.
05 PIC X(3) VALUE "DUE".
05 PIC X(6) VALUE SPACES.
05 PIC X(7) VALUE "OVERDUE".
05 PIC X(6) VALUE SPACES.
05 PIC X(4) VALUE "RATE".
05 PIC X(7) VALUE SPACES.
05 PIC X(6) VALUE "AMOUNT".
05 PIC X(6) VALUE SPACES.
05 PIC X(6) VALUE "AMOUNT".

01 DETAIL-LINE.
05 DR-ACCOUNT-NO-OUT PIC X(6).
05 PIC X(2) VALUE SPACES.
05 DR-NAME-OUT PIC X(15).
05 PIC X(7) VALUE SPACES.
05 DET-AMOUNT-TOTAL PIC $$$,999.
05 PIC X(7) VALUE SPACES.
05 DR-DAYS-OVERDUE-OUT PIC X(2).
05 PIC X(9) VALUE SPACES.
05 WS-DISCOUNT-RATE-OUT PIC 9.
05 PIC X VALUE "%".
05 PIC X(8) VALUE SPACES.
05 DET-DISCOUNT-TOTAL PIC $$,$$9.
05 PIC X(5) VALUE SPACES.
05 DET-NET-TOTAL PIC $$$$,$99.

01 DASH-LINE.
05 PIC X(30) VALUE SPACES.
05 PIC X(54) VALUE
"______________________________________________________".



01 TOTALS-LINE.
05 PIC X(10) VALUE SPACES.
05 PIC X(6) VALUE "TOTALS".
05 PIC X(14) VALUE SPACES.
05 FINAL-AMOUNT PIC $$$,999.
05 PIC X(28).
05 FINAL-DISCOUNT PIC $$,$$9.
05 PIC X(6).
05 FINAL-NET PIC $$$,999.


PROCEDURE DIVISION.
000-MAIN-MODULE.
PERFORM 100-INITIALIZE-DELINQUENT-FILE.
PERFORM 700-READ-DELINQUENT-FILES.
PERFORM 800-WRITE-REPORT-HEADINGS.
* PERFORM 820-WRITE-DETAIL-LINE.
PERFORM 300-PROCESS-PAST-ACCOUNTS
UNTIL MORE-RECORDS = "N".
PERFORM 810-INCREMENT-OVERDUE-TOTALS.
PERFORM 820-WRITE-DETAIL-LINE.
PERFORM 900-WRITE-DELINQUENT-TOTALS.
PERFORM 690-FINISH-DELINQUENT-REPORT.

100-INITIALIZE-DELINQUENT-FILE.
OPEN INPUT DEL-FILE
OUTPUT PRINT-FILE.

300-PROCESS-PAST-ACCOUNTS.
IF DR-AMOUNT-DUE >= 25000
OR DR-DAYS-OVERDUE > 25
PERFORM 410-SET-DISCOUNT-RATE
ELSE
PERFORM 700-READ-DELINQUENT-FILES
END-IF.
410-SET-DISCOUNT-RATE.
IF DR-DAYS-OVERDUE <= 25
MOVE 4 TO WS-DISCOUNT-RATE
END-IF.

IF DR-DAYS-OVERDUE >= 26 AND <= 40
MOVE 3 TO WS-DISCOUNT-RATE
END-IF.

IF DR-DAYS-OVERDUE >= 41 AND <= 55
MOVE 2 TO WS-DISCOUNT-RATE
END-IF.

IF DR-DAYS-OVERDUE > 55
MOVE 1 TO WS-DISCOUNT-RATE
END-IF.

PERFORM 420-COMPUTE-DISCOUNT-AMOUNT.

420-COMPUTE-DISCOUNT-AMOUNT.
COMPUTE WS-DISCOUNT-AMOUNT = DR-AMOUNT-DUE *
(WS-DISCOUNT-RATE * .01).

PERFORM 430-COMPUTE-NET-AMOUNT.

430-COMPUTE-NET-AMOUNT.
COMPUTE WS-NET-AMOUNT = DR-AMOUNT-DUE -
WS-DISCOUNT-AMOUNT.

690-FINISH-DELINQUENT-REPORT.
CLOSE DEL-FILE
PRINT-FILE.
STOP RUN.

700-READ-DELINQUENT-FILES.
READ DEL-FILE
AT END MOVE &quot;N&quot; TO MORE-RECORDS.

800-WRITE-REPORT-HEADINGS.
WRITE PRINT-RECORD FROM HEADING-ONE
AFTER ADVANCING 1 LINE.
WRITE PRINT-RECORD FROM HEADING-TWO
AFTER ADVANCING 1 LINE.
WRITE PRINT-RECORD FROM HEADING-THREE
AFTER ADVANCING 1 LINE.
WRITE PRINT-RECORD FROM HEADING-FOUR
AFTER ADVANCING 2 LINES.
WRITE PRINT-RECORD FROM HEADING-FIVE
AFTER ADVANCING 1 LINES.
MOVE SPACES TO PRINT-RECORD.
WRITE PRINT-RECORD.

810-INCREMENT-OVERDUE-TOTALS.
ADD DR-AMOUNT-DUE TO DR-AMOUNT-TOTAL.
ADD WS-DISCOUNT-AMOUNT TO WS-DISCOUNT-TOTAL.
ADD WS-NET-AMOUNT TO WS-NET-TOTAL.


820-WRITE-DETAIL-LINE.
* ACCEPT HEADING-THREE FROM DATE


MOVE DR-NAME TO DR-NAME-OUT.
MOVE DR-ACCOUNT-NO TO DR-ACCOUNT-NO-OUT.
MOVE DR-AMOUNT-DUE TO DET-AMOUNT-TOTAL.
MOVE DR-DAYS-OVERDUE TO DR-DAYS-OVERDUE-OUT.
MOVE WS-DISCOUNT-RATE TO WS-DISCOUNT-RATE-OUT.
MOVE WS-DISCOUNT-AMOUNT TO DET-DISCOUNT-TOTAL.
MOVE WS-NET-AMOUNT TO DET-NET-TOTAL.

WRITE PRINT-RECORD FROM DETAIL-LINE
AFTER ADVANCING 1 LINE.

900-WRITE-DELINQUENT-TOTALS.
WRITE PRINT-RECORD FROM DASH-LINE
AFTER ADVANCING 1 LINE.

MOVE DR-AMOUNT-TOTAL TO FINAL-AMOUNT.
MOVE WS-DISCOUNT-TOTAL TO FINAL-DISCOUNT.
MOVE WS-NET-TOTAL TO FINAL-NET.

WRITE PRINT-RECORD FROM TOTALS-LINE
AFTER ADVANCING 1 LINE.

PERFORM 690-FINISH-DELINQUENT-REPORT.
 
Printing totals prob,

You coded:
PERFORM 300-PROCESS-PAST-ACCOUNTS
UNTIL MORE-RECORDS = &quot;N&quot;.

The only way the loop will be broken is when MORE-RECORDS = &quot;N&quot;. This will happen only when 700-READ-DELINQUENT-FILES is executed. But, the IF statement, as coded, will never execute 700-READ-DELINQUENT-FILES, as soon as the highlighted condition becomes true.

300-PROCESS-PAST-ACCOUNTS.
IF DR-AMOUNT-DUE >= 25000
OR DR-DAYS-OVERDUE > 25

PERFORM 410-SET-DISCOUNT-RATE
ELSE
PERFORM 700-READ-DELINQUENT-FILES
END-IF.


I think what you are trying to do is read DEL-FILE, and, depending on the values, set discount rates, until EOF on DEL-FILE. If so, you could recode 300-PROCESS-PAST-ACCOUNTS this way:

300-PROCESS-PAST-ACCOUNTS.
PERFORM 700-READ-DELINQUENT-FILES
IF MORE-RECORDS = &quot;Y&quot;
IF (DR-AMOUNT-DUE >= 25000)
OR (DR-DAYS-OVERDUE > 25)
PERFORM 410-SET-DISCOUNT-RATE
END-IF
END-IF
.

Dimandja
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top