Menu
CoddyTech

Check a Line

Part of the Tables and Text section of Coddy's COBOL Programming journey. Lesson 17 of 19.

challenge icon

Challenge

Easy

Bad lines must not be added. At the start of DO-LINE, clear TX-TYPE and AMT-X. After the split, when TEST-NUMVAL of AMT-X is not 0, perform BAD-LINE, which displays Bad line: and the trimmed line; otherwise convert and display as before.

Example input, one line per ACCEPT: DEP,100, WDR,abc, FEE, XYZ,5, WDR,30.25, END.

Try it yourself

       IDENTIFICATION DIVISION.
       PROGRAM-ID. TRANS.
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01 LINE-IN PIC X(40).
       01 TX-TYPE PIC X(3).
       01 AMT-X PIC X(12).
       01 TX-AMT PIC 9(5)V99.
       01 AMT-OUT PIC Z(5)9.99.
       PROCEDURE DIVISION.
       MAIN.
           ACCEPT LINE-IN.
           PERFORM UNTIL LINE-IN = "END"
               PERFORM DO-LINE
               ACCEPT LINE-IN
           END-PERFORM.
           STOP RUN.
       DO-LINE.
           *> Clear TX-TYPE and AMT-X here
           UNSTRING LINE-IN DELIMITED BY ","
               INTO TX-TYPE AMT-X
           END-UNSTRING.
           *> Check AMT-X with TEST-NUMVAL here
           COMPUTE TX-AMT = FUNCTION NUMVAL(AMT-X).
           MOVE TX-AMT TO AMT-OUT
           DISPLAY TX-TYPE " " AMT-OUT.
       *> Write the BAD-LINE paragraph here

All lessons in Tables and Text