• How I built large systems on small machines.

    From Richard@riplin@azonic.co.nz to comp.lang.cobol on Tue Oct 2 13:09:31 2018
    From Newsgroup: comp.lang.cobol


    Mayer Goldberg wanted to know how CALL/CANCEL was used to build large systems from lots of independent programs. This working demo system should show how it was done on CP/M, MS-DOS, and similar back in the late 70s through to the 90s.

    It is in COBOL85 and tested with GNUCOBOL.

    mainprog.cbl ---------------------------------------
    IDENTIFICATION DIVISION.
    PROGRAM-ID. mainprog.
    ENVIRONMENT DIVISION.
    DATA DIVISION.
    WORKING-STORAGE SECTION.
    01 XXX PIC X.
    COPY "interface.ws".
    PROCEDURE DIVISION.
    MAINLINE.
    MOVE "menuprog" TO Next-Program
    Menu-Program
    PERFORM
    UNTIL Next-Program = "FINISH"
    MOVE Next-Program TO Call-Program
    MOVE Menu-Program TO Next-Program
    CALL Call-Program
    USING Interface-Data
    ON EXCEPTION
    DISPLAY "PROGRAM FAILED: " Call-Program
    DISPLAY "Press enter"
    ACCEPT XXX
    MOVE Menu-Program TO Next-Program
    END-CALL
    CANCEL Call-Program
    END-PERFORM
    STOP RUN
    .
    END PROGRAM mainprog.
    interface.ws ----------------------------------------------
    01 Interface-Data.
    03 Next-Program PIC X(8).
    03 Call-Program PIC X(8).
    03 Menu-Program PIC X(8).
    03 Login-Data.
    05 Login-Name PIC X(12).
    05 Login-Level PIC X.

    * add all sorts of 'global' data here
    * change the filler to keep the same size
    * when adding data items.

    03 FILLER PIC X(1000).

    * end ------------------------------------

    menuprog.cbl ------------------------------------
    IDENTIFICATION DIVISION.
    PROGRAM-ID. menuprog.
    ENVIRONMENT DIVISION.
    INPUT-OUTPUT SECTION.
    FILE-CONTROL.
    SELECT OPTIONAL MenuData
    ASSIGN "MENUDATA"
    ORGANIZATION LINE SEQUENTIAL
    FILE STATUS File-Status
    .
    DATA DIVISION.
    FILE SECTION.
    FD MenuData.
    01 MD-Record.
    03 MD-Selection PIC X(4).
    03 MD-Description PIC X(32).
    03 MD-Program PIC X(8).
    WORKING-STORAGE SECTION.
    01 File-Status.
    03 FS1 PIC X.
    03 FS2 PIC X.
    01 XXX PIC XXX.
    01 MPrompt PIC X(18)
    VALUE "Enter selection: ".
    01 MEnter PIC X(4).
    01 MIndex PIC S9(4) COMP.
    01 MLimit PIC S9(4) COMP.
    01 Menu-Table.
    03 Menu-Item OCCURS 100.
    05 MSelection PIC X(4).
    05 MProgram PIC X(8).
    LINKAGE SECTION.
    COPY "interface.ws".
    PROCEDURE DIVISION
    USING Interface-Data.
    MAINLINE.
    DISPLAY "This is the menu"
    OPEN INPUT MenuData
    MOVE SPACES TO MD-Record
    MOVE ZERO TO MLimit
    PERFORM
    UNTIL MD-Selection = "****"
    READ MenuData
    AT END
    MOVE "****" TO MD-Selection
    NOT AT END
    DISPLAY MD-Selection SPACE MD-Description
    ADD 1 TO MLimit
    MOVE MD-Selection TO MSelection(MLimit)
    MOVE MD-Program TO MProgram (MLimit)
    END-READ
    END-PERFORM
    MOVE SPACES TO Next-Program
    PERFORM UNTIL Next-Program NOT = SPACES
    DISPLAY MPrompt
    ACCEPT MEnter
    PERFORM
    VARYING MIndex FROM 1 BY 1
    UNTIL MIndex > MLimit
    IF ( MEnter = MSelection(MIndex) )
    MOVE MProgram(MIndex) TO Next-Program
    DISPLAY "Next program: " Next-Program
    END-IF
    END-PERFORM
    END-PERFORM
    EXIT PROGRAM
    .
    END PROGRAM menuprog.

    MENUDATA ---------------------------------------
    A Maintain Product File prodmant
    B Maintain Customer File custmant
    C Order Entry orderent
    X Closedown program FINISH
    ****
    comments may appear here.

    prodmant.cbl -----------------------------------
    IDENTIFICATION DIVISION.
    PROGRAM-ID. prodmant.
    ENVIRONMENT DIVISION.
    DATA DIVISION.
    WORKING-STORAGE SECTION.
    01 XXX PIC XXX.
    LINKAGE SECTION.
    COPY "interface.ws".
    PROCEDURE DIVISION
    USING Interface-Data.
    MAINLINE.
    DISPLAY "This is product maintenance"
    ACCEPT XXX
    EXIT PROGRAM
    .
    END PROGRAM prodmant.

    orderent.cbl -----------------------------------
    IDENTIFICATION DIVISION.
    PROGRAM-ID. orderent.
    ENVIRONMENT DIVISION.
    DATA DIVISION.
    WORKING-STORAGE SECTION.
    01 XXX PIC XXX.
    LINKAGE SECTION.
    COPY "interface.ws".
    PROCEDURE DIVISION
    USING Interface-Data.
    MAINLINE.
    DISPLAY "This is order entry"
    ACCEPT XXX
    DISPLAY "Now to print order"
    MOVE "orderprt" TO Next-Program
    EXIT PROGRAM
    .
    END PROGRAM orderent.

    orderprt.cbl -------------------------------------
    IDENTIFICATION DIVISION.
    PROGRAM-ID. orderprt.
    ENVIRONMENT DIVISION.
    DATA DIVISION.
    WORKING-STORAGE SECTION.
    01 XXX PIC X.
    LINKAGE SECTION.
    COPY "interface.ws".
    PROCEDURE DIVISION
    USING Interface-Data.
    MAINLINE.
    DISPLAY "This is order print"
    ACCEPT XXX
    EXIT PROGRAM
    .
    END PROGRAM orderprt.

    doit.sh -----------------------------

    #!/bin/sh

    LD_LIBRARY_PATH=/usr/local/lib:${LD_LIBRARY_PATH}
    export LD_LIBRARY_PATH

    /usr/local/bin/cobc -version
    /usr/local/bin/cobc -x mainprog.cbl -o mainprog
    /usr/local/bin/cobc menuprog.cbl -o menuprog
    /usr/local/bin/cobc prodmant.cbl -o prodmant
    /usr/local/bin/cobc orderent.cbl -o orderent
    /usr/local/bin/cobc orderprt.cbl -o orderprt

    ./mainprog

    end --------------------------------------------



    --- Synchronet 3.20a-Linux NewsLink 1.114