Split a Line
Part of the Tables and Text section of Coddy's COBOL Programming journey. Lesson 16 of 19.
Challenge
EasyThe program reads transaction lines like DEP,120.50 until END. In DO-LINE, split LINE-IN at the comma into TX-TYPE and AMT-X, convert AMT-X into TX-AMT, and display the type and AMT-OUT: DEP 120.50.
Example input, one line per ACCEPT: DEP,120.50, WDR,40, DEP,50, FEE,2.5, 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.
*> Split LINE-IN, convert AMT-X and
*> display the type and amount here