Wednesday, November 01, 2006

This is for my Mom

*This program is intended to collect savings account data
*and store it into a text file.

IDENTIFICATION DIVISION.
PROGRAM-ID. SAVINGSDATA.
AUTHOR. IRENE HELDER.
DATE-WRITTEN. OCTOBER 25, 2006.

*Maintenance Log
*Name Date Explanation
*--------------------------------------

ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT PRINT-FILE ASSIGN TO 'A:\SAVINGS.DAT'
ORGANIZATION IS LINE SEQUENTIAL.

DATA DIVISION.
FILE SECTION.
FD PRINT-FILE
RECORD CONTAINS 36 CHARACTERS.
01 PRINT-LINE PIC X(36).

WORKING-STORAGE SECTION.
*All the variables needed for storing the data.
01 WS-SCREEN-SAVINGS.
05 WS-ACCOUNTNUM.
10 WS-ACCFIRST PIC 9(5) VALUE 0.
10 WS-ACCHYPHEN PIC X VALUE "-".
10 WS-ACCLAST PIC 99 VALUE 0.
05 WS-NAME PIC X(17) VALUE SPACES.
05 WS-AMOUNT PIC ZZZZZZ9.99 VALUE SPACES.
05 WS-TERM PIC 99 VALUE 0.

*Other variables needed for running the program.
01 WS-OTHER-VARIABLES.
05 WS-COUNTER PIC 99 VALUE 0.
05 WS-MORERECORDS PIC X VALUE 'Y'.

*Variables for printing data to the file.
01 WS-PRINTLINE.
05 PR-ACCOUNTNUM PIC X(8).
05 PR-NAME PIC X(17).
05 PR-AMOUNT PIC 9(7)V99.
05 PR-TERM PIC 99.

*Control variables.
01 WS-CONTROLS.
05 WS-SAVE PIC X VALUE SPACES.
88 SAVE-DATA VALUE 'Y','y'.

*Details how the screen will display.
SCREEN SECTION.
01 GET-ACCOUNT-NUM.
05 VALUE "PLEASE ENTER THE ACCOUNT NUMBER:"
LINE 2 COLUMN 2.
05 PIC 9(5) USING WS-ACCFIRST LINE 2 COLUMN 34 REVERSE-VIDEO.
05 VALUE "-" LINE 2 COLUMN 39.
05 PIC 99 USING WS-ACCLAST LINE 2 COLUMN 40 REVERSE-VIDEO.

01 GET-ACCTNAME.
05 VALUE "PLEASE ENTER THE NAME:" LINE 4 COLUMN 2.
05 PIC X(17) USING WS-NAME LINE 4 COLUMN 24 REVERSE-VIDEO.

01 GET-ACCTAMOUNT.
05 VALUE "PLEASE ENTER THE AMOUNT:" LINE 6 COLUMN 2.
05 PIC ZZZZZZ9.99 USING WS-AMOUNT
LINE 6 COLUMN 25 REVERSE-VIDEO.

01 GET-ACCTTERM.
05 VALUE "PLEASE ENTER THE TERM:" LINE 8 COLUMN 2.
05 PIC 99 USING WS-TERM LINE 8 COLUMN 24 REVERSE-VIDEO.

01 SAVE-RECORD.
10 VALUE "WOULD YOU LIKE TO SAVE THIS RECORD?"
LINE 10 COLUMN 2.
10 PIC X USING WS-SAVE LINE 10 COLUMN 37.

01 MORE-RECORDS.
10 VALUE "WOULD YOU LIKE TO ADD ANOTHER RECORD?" LINE 12
COLUMN 2.
10 PIC X USING WS-MORERECORDS LINE 12 COLUMN 39.

01 ERROR-MESSAGES.
05 SCR-FIRSTERROR.
10 VALUE "PLEASE ENTER 5 NUMBERS BEFORE THE HYPHEN"
LINE 3 COLUMN 2.
05 SCR-SECONDERROR.
10 VALUE "PLEASE ENTER 2 NUMBERS AFTER THE HYPHEN"
LINE 3 COLUMN 2.

01 CLEAR-SCREEN.
05 LINE 2 BLANK LINE.
05 LINE 3 BLANK LINE.
05 LINE 4 BLANK LINE.
05 LINE 5 BLANK LINE.
05 LINE 6 BLANK LINE.
05 LINE 7 BLANK LINE.
05 LINE 8 BLANK LINE.
05 LINE 9 BLANK LINE.
05 LINE 10 BLANK LINE.
05 LINE 11 BLANK LINE.
05 LINE 12 BLANK LINE.

PROCEDURE DIVISION.

CREATESAVINGSACCOUNTFILE.
PERFORM A100-STARTUP.
PERFORM A200-PROCESSRECORDS
UNTIL WS-MORERECORDS = "N" or "n".
PERFORM A300-FINALIZE.

STOP RUN.

A100-STARTUP.
OPEN EXTEND PRINT-FILE.

A200-PROCESSRECORDS.
* DISPLAY 'ENTERED A200 PARAGRAPH'.
DISPLAY CLEAR-SCREEN.
INITIALIZE WS-SCREEN-SAVINGS.

PERFORM B100-GETDATA.
PERFORM B200-SAVERECORDS.
PERFORM B300-MORERECORDS.

A300-FINALIZE.
* DISPLAY 'ENTERED A300 PARAGRAPH'.
CLOSE PRINT-FILE.

*I left the code in but commented it out because I can't get it to
*work properly.
B100-GETDATA.
DISPLAY GET-ACCOUNT-NUM.

* PERFORM WITH TEST AFTER UNTIL WS-COUNTER = 5
ACCEPT GET-ACCOUNT-NUM.
* INITIALIZE WS-COUNTER
* INSPECT WS-ACCFIRST TALLYING WS-COUNTER FOR CHARACTERS
* BEFORE '-'
* IF WS-COUNTER <> 5
* DISPLAY SCR-FIRSTERROR
* END-IF
* END-PERFORM.

* PERFORM WITH TEST AFTER UNTIL WS-COUNTER = 2
* INITIALIZE WS-COUNTER
* INSPECT WS-ACCLAST TALLYING WS-COUNTER FOR CHARACTERS
* BEFORE '-'
* IF WS-COUNTER <> 2
* DISPLAY SCR-SECONDERROR
* END-IF
* END-PERFORM.

* DISPLAY CLEAR-MSGS.
DISPLAY GET-ACCTNAME.
ACCEPT GET-ACCTNAME.

DISPLAY GET-ACCTAMOUNT.
ACCEPT GET-ACCTAMOUNT.

DISPLAY GET-ACCTTERM.
ACCEPT GET-ACCTTERM.

B200-SAVERECORDS.
DISPLAY SAVE-RECORD.
ACCEPT SAVE-RECORD.
IF SAVE-DATA PERFORM C100-PRINTVALUES.

B300-MORERECORDS.
DISPLAY MORE-RECORDS.
ACCEPT MORE-RECORDS.

C100-PRINTVALUES.
* DISPLAY 'ENTERED C100'.
MOVE WS-ACCOUNTNUM TO PR-ACCOUNTNUM.
MOVE WS-NAME TO PR-NAME.
MOVE WS-AMOUNT TO PR-AMOUNT.
MOVE WS-TERM TO PR-TERM.
MOVE WS-PRINTLINE TO PRINT-LINE.
WRITE PRINT-LINE AFTER ADVANCING 1 LINE.

No comments: