Teach Yourself COBOL in 21 days, Second Edition

Previous chapterNext chapterContents


- Bonus Day 3 -
Full-Screen I/O

So far you have worked with COBOL programs that display and accept all data by scrolling up from the bottom of the screen. All activity you have encountered so far occurs one line at a time.

Several modern versions of COBOL enable a more polished method of handling user input by enabling the program to display and accept a full screen of information at a time. Full-screen I/O is not a standard part of the COBOL language, but it is so common in modern COBOL that you should have some understanding of how this works. Because full-screen I/O is not a standard part of the language, there are variations on how each version of COBOL handles this problem. There are enough similarities, however, that a general understanding of how some versions of COBOL handle full-screen I/O will be usable with almost any version of COBOL.

Today, you learn about the following topics:

What Is Full-Screen I/O?

Full-screen I/O enables you to define a complete screen (24 rows by 80 columns) containing prompts and fields to be entered. This screen can be displayed to the user, which enables the user to enter data in the fields, move the cursor around the screen to different fields, modify the fields in any order, and then complete the entry by pressing a key to indicate that all fields are complete.

Figure B3.1 is an example of what a full screen might look like. The screen is a series of prompts followed by one or more fields into which information can be typed.

Figure B3.1.
An example of full-screen I/O.

Most versions of COBOL make this feature available by providing an enhanced version of the ACCEPT and DISPLAY verbs. These enhanced features usually allow for the following:

The Keyboard

The keyboard usually behaves differently during full-screen I/O, and you will have to experiment with it once you have your first program up and running. Usually, the Tab key and arrow keys move you around the screen from field to field, and the Enter key causes the screen input to terminate and sends the data you have entered back to the program. This might cause confusion for some PC users who are used to using the Enter key to move the cursor to the next field.

Formatting Full Screens

The simplest screen to format for data entry usually is a menu screen. It has several values that are displayed onscreen, and usually only one data entry field, which is the selection by the user.

First look at the following proposed output for a full-screen menu:

OUTPUT:

                     PLEASE SELECT:

                         1. STATE CODE MAINTENANCE
                         2. VENDOR MAINTENANCE
                         3. VOUCHER PROCESSING

                         0. EXIT

YOUR SELECTION 5
INVALID SELECTION - PLEASE RE-TRY.

Now look at the code to create this screen. Listing B3.1 is bilmnu04.cbl, and is a full-screen version of the billing system menu for Micro Focus Personal or Professional COBOL, ACUCOBOL, and with slight revisions LPI COBOL.

TYPE: Listing B3.1. A full-screen menu.

000100 IDENTIFICATION DIVISION.
000200 PROGRAM-ID. BILMNU04.
000300*--------------------------------
000400* Menu for the bill payment system.
000500* Including Vouchers
000600* Using full screen IO.
000700*--------------------------------
000800 ENVIRONMENT DIVISION.
000900 INPUT-OUTPUT SECTION.
001000 FILE-CONTROL.
001100
001200 DATA DIVISION.
001300 FILE SECTION.
001400
001500 WORKING-STORAGE SECTION.
001600
001700 77  MENU-PICK                    PIC 9 VALUE 0.
001800     88  MENU-PICK-IS-VALID       VALUES 0 THRU 3.
001900
002000 77  ERROR-MESSAGE      PIC X(79).
002100
002200 SCREEN SECTION.
002300 01  MENU-SCREEN.
002400     05  BLANK SCREEN.
002500     05  LINE  6 COL 20 VALUE "PLEASE SELECT:".
002600     05  LINE  8 COL 25 VALUE "1. STATE CODE MAINTENANCE".
002700     05  LINE  9 COL 25 VALUE "2. VENDOR MAINTENANCE".
002800     05  LINE 10 COL 25 VALUE "3. VOUCHER PROCESSING".
002900     05  LINE 12 COL 25 VALUE "0. EXIT".
003000     05  LINE 20 COL  1 VALUE "YOUR SELECTION".
003100     05  LINE 20 COL 16 PIC Z USING MENU-PICK.
003200     05  LINE 24 COL  1 PIC X(79) FROM ERROR-MESSAGE.
003300
003400 PROCEDURE DIVISION.
003500 PROGRAM-BEGIN.
003600     PERFORM OPENING-PROCEDURE.
003700     PERFORM MAIN-PROCESS.
003800     PERFORM CLOSING-PROCEDURE.
003900
004000 PROGRAM-EXIT.
004100     EXIT PROGRAM.
004200
004300 PROGRAM-DONE.
004400     STOP RUN.
004500
004600 OPENING-PROCEDURE.
004700
004800 CLOSING-PROCEDURE.
004900
005000 MAIN-PROCESS.
005100     PERFORM GET-MENU-PICK.
005200     PERFORM DO-THE-PICK
005300         UNTIL MENU-PICK = 0.
005400
005500*--------------------------------
005600* MENU
005700*--------------------------------
005800 GET-MENU-PICK.
005900     PERFORM DISPLAY-MENU-SCREEN.
006000     PERFORM ACCEPT-MENU-SCREEN.
006100     PERFORM RE-ACCEPT-MENU-SCREEN
006200         UNTIL MENU-PICK-IS-VALID.
006300
006400 DISPLAY-MENU-SCREEN.
006500
006600      DISPLAY MENU-SCREEN.
006700
006800 ACCEPT-MENU-SCREEN.
006900     ACCEPT MENU-SCREEN.
007000     MOVE SPACE TO ERROR-MESSAGE.
007100
007200 RE-ACCEPT-MENU-SCREEN.
007300     MOVE "INVALID SELECTION - PLEASE RE-TRY."
007400         TO ERROR-MESSAGE.
007500     PERFORM DISPLAY-MENU-SCREEN.
007600     PERFORM ACCEPT-MENU-SCREEN.
007700
007800 DO-THE-PICK.
007900     IF MENU-PICK = 1
008000         PERFORM STATE-MAINTENANCE
008100     ELSE
008200     IF MENU-PICK = 2
008300         PERFORM VENDOR-MAINTENANCE
008400     ELSE
008500     IF MENU-PICK = 3
008600         PERFORM VOUCHER-PROCESSING.
008700
008800     PERFORM GET-MENU-PICK.
008900
009000*--------------------------------
009100* STATE
009200*--------------------------------
009300 STATE-MAINTENANCE.
009400     CALL "STCMNT04".
009500
009600*--------------------------------
009700* VENDOR
009800*--------------------------------
009900 VENDOR-MAINTENANCE.
010000     CALL "VNDMNT05".
010100
010200*--------------------------------
010300* VOUCHERS
010400*--------------------------------
010500 VOUCHER-PROCESSING.
010600     CALL "VCHMNU01".
010700

ANALYSIS: The SCREEN SECTION begins at line 002200. The screen definition for MENU-SCREEN begins at line 002200.

The first variable within MENU-SCREEN is BLANK SCREEN at line 002400. This is not really a value, but an instruction to blank the screen when DISPLAY MENU-SCREEN is executed.

Lines 002500 through 002900 define values that will be displayed onscreen. Each field is defined with a LINE (row), COL (column), and a VALUE definition of the literal.

Line 003100 defines a data entry field. This definition includes a line and column (LINE 20 COL 16), a picture (PIC Z), and a USING clause (USING MENU-PICK) that names the field to be used for receiving the entered data. When the MENU-SCREEN is processed, this definition causes various things to happen.

During DISPLAY MENU-SCREEN, the cursor is positioned at row 20 and column 16. The value in MENU-PICK is moved to the screen and displayed using zero suppression (PIC Z).

During ACCEPT MENU-PICK, the cursor is positioned at row 20 and column 16. The value entered by the user is saved. When the user presses Enter, the saved value is moved to MENU-PICK.

It is important to note that MENU-PICK is defined in WORKING-STORAGE at line 001700, and not in the SCREEN SECTION. The field that is displayed or entered is always processed by moving it to a temporary area and then displaying it, or accepting it into a temporary area and moving it back to the field. This moving back and forth is performed automatically by displaying or accepting a full screen. The field itself is not part of the screen definition, but is used by the screen definition.

The last field in MENU-SCREEN is defined at line 003200. This has a row and column position (LINE 24 COL 1), a picture (PIC X(79)), and a FROM clause (FROM ERROR-MESSAGE).

A FROM clause affects only the way DISPLAY behaves. During DISPLAY MENU-SCREEN the cursor is positioned at row 24 and column 1. The value in ERROR-MESSAGE is moved to the screen and displayed as a PIC X(79) field.

The logic of bilmnu04.cbl is similar to bilmnu03.cbl, but uses full screens instead of individual fields.

GET-MENU-PICK at line 005800 displays the menu, then accepts the user entry, and, if necessary, reaccepts entry until a valid value is entered.

The DISPLAY-MENU-SCREEN routine at line 006400 displays the whole MENU-SCREEN.

The ACCEPT-MENU-SCREEN routine at line 006800 accepts the entire MENU-SCREEN. Only one field is defined in MENU-SCREEN at line 003100; the field that will accept data into MENU-PICK. The ACCEPT of MENU-SCREEN actually causes data entry to take place only for that single field.

The routine to RE-ACCEPT-MENU-SCREEN, at line 007200, moves an error message to ERROR-MESSAGE, displays the entire MENU-SCREEN, and then accepts the MENU-SCREEN again.

One short point worth noting is that MENU-PICK must be initialized when it is defined. If it is not, the first DISPLAY MENU-SCREEN will cause an error, because MENU-PICK will contain an invalid numeric value.


TIP: Some versions of COBOL will not accept COL as an abbreviation for COLUMN in a screen definition. LPI COBOL is one that does not. If your compiler complains about the use of COL, change all of them to COLUMN and try to compile again.

Code, compile, and run bilmnu04.cbl to see the effect of full-screen I/O. It will compile and run correctly for Micro Focus Personal COBOL, ACUCOBOL, LPI COBOL by changing COL to COLUMN, and probably others. It will not work for VAX COBOL, which does not support full-screen I/O.

Try entering some valid and invalid menu choices to see how the field at the bottom of the screen is either filled with error messages or cleared, depending on the validity of the choice.

Defining a Screen to Maintain a File

In the next example, you create a full-screen version of vendor maintenance. First, you need to define the screens. A screen can be designed on printer spacing paper by using 80 columns and 24 lines of the chart. Figure B3.2 is a layout chart for the menu portion of the program.

Figure B3.2.
Screen layout for the menu.

Listing B3.2 shows the menu screen to be used in vendor maintenance. It has only one modifiable field, MENU-PICK, which must be defined in WORKING-STORAGE.

TYPE: Listing B3.2. The menu screen.

004800 01  MENU-SCREEN.
004900     05  BLANK SCREEN.
005000     05  LINE  2 COLUMN 30 VALUE "VENDOR MAINTENANCE".
005100     05  LINE  6 COLUMN 20 VALUE "PLEASE SELECT:".
005200     05  LINE  8 COLUMN 25 VALUE "1. ADD RECORDS".
005300     05  LINE  9 COLUMN 25 VALUE "2. CHANGE A RECORD".
005400     05  LINE 10 COLUMN 25 VALUE "3. LOOK UP A RECORD".
005500     05  LINE 11 COLUMN 25 VALUE "4. DELETE A RECORD".
005600     05  LINE 12 COLUMN 25 VALUE "5. LOOK UP BY NAME".
005700     05  LINE 13 COLUMN 25 VALUE "6. PRINT RECORDS".
005800     05  LINE 14 COLUMN 25 VALUE "7. PRINT IN NAME ORDER".
005900     05  LINE 15 COLUMN 25 VALUE "8. DISPLAY ALL RECORDS".
006000     05  LINE 17 COLUMN 25 VALUE "0. EXIT".
006100     05  LINE 20 COLUMN  1 VALUE "YOUR SELECTION? ".
006200     05  LINE 20 COLUMN 17 PIC Z USING MENU-PICK.
006300     05  LINE 24 COLUMN  1 PIC X(79) FROM ERROR-MESSAGE.

Figure B3.3 is a screen layout chart for the new vendor maintenance program. The layout includes prompts and entry fields for each of the fields in the vendor file. The extra field on line 12 is a 20-character field to hold the state name retrieved from the state codes file. This field cannot be modified; it is for display only.

Figure B3.3.
Screen layout chart for vendor maintenance.

The DATA DIVISION definition of the basic screen for vendor maintenance is shown in Listing B3.3. It includes modifiable entry fields for all of the fields in the vendor file.

TYPE: Listing B3.3. Basic vendor maintenance screen.

007200 01  VENDOR-SCREEN.
007300     05  BLANK SCREEN.
007400     05  LINE  4 COLUMN 20 VALUE "VENDOR NUMBER:".
007500     05  LINE  4 COLUMN 40 PIC Z(5) USING VENDOR-NUMBER.
007600     05  LINE  6 COLUMN 20 VALUE "VENDOR NAME: ".
007700     05  LINE  6 COLUMN 40 PIC X(30) USING VENDOR-NAME.
007800     05  LINE  8 COLUMN 20 VALUE "VENDOR ADDRESS:".
007900     05  LINE  8 COLUMN 40 PIC X(30) USING VENDOR-ADDRESS-1.
008000     05  LINE  9 COLUMN 40 PIC X(30) USING VENDOR-ADDRESS-2.
008100     05  LINE 10 COLUMN 20 VALUE "VENDOR CITY:".
008200     05  LINE 10 COLUMN 40 PIC X(20) USING VENDOR-CITY.
008300     05  LINE 12 COLUMN 20 VALUE "VENDOR STATE:".
008400     05  LINE 12 COLUMN 40 PIC XX USING VENDOR-STATE.
008500     05  LINE 12 COLUMN 45 PIC X(20) FROM STATE-NAME.
008600     05  LINE 14 COLUMN 20 VALUE "VENDOR ZIP:".
008700     05  LINE 14 COLUMN 40 PIC X(10) USING VENDOR-ZIP.
008800     05  LINE 16 COLUMN 20 VALUE "VENDOR CONTACT:".
008900     05  LINE 16 COLUMN 40 PIC X(30) USING VENDOR-CONTACT.
009000     05  LINE 18 COLUMN 20 VALUE "VENDOR PHONE:".
009100     05  LINE 18 COLUMN 40 PIC X(15) USING VENDOR-PHONE.
009200     05  LINE 22 COLUMN  1 PIC X(79) FROM FOOTER-FIELD.
009300     05  LINE 22 COLUMN  1 PIC X(79) FROM 2ND-FOOTER-FIELD.
009400     05  LINE 24 COLUMN  1 PIC X(79) FROM ERROR-MESSAGE.
009500

A maintenance program that uses full-screen I/O faces one problem. When a field is defined in a screen, it can be defined as a USING field, such as line 007500 in Listing B3.3. This definition will allow data entry. A field also can be defined with a FROM clause, as in line 008500 of Listing B3.3. A FROM field cannot be modified. There are times during maintenance when you want a field to be modifiable, and there are other times when you do not. How can you define a field to be both modifiable and nonmodifiable?

Some versions of COBOL allow you to change whether a field can be modified while the program is running, but some do not. The solution should take as many versions of COBOL into account as possible. One solution that works on many different versions of COBOL is to define several different screens.

You will need three screens. The first screen allows the user to enter only the values that make up the primary key to the file; in this case, the VENDOR-NUMBER. The second screen allows the user to enter all fields except the primary key fields. The third screen displays all fields, but allows none of them to be entered.

The key screen is used by all modes (add, change, inquire, and delete) to get the user entry of the vendor number to process. The change screen is used by add and change modes to enable the user to enter or update the fields in the file. The display-only screen is used by inquire and delete modes to enable the user to view or review a record before deciding to delete it.

Ignoring the user instructions and error messages, Listing B3.4 is a listing of the three screens that will be used in the program. A few more fields will be added for the actual program, but these are the basic screen definitions.

TYPE: Listing B3.4. Example of screen definitions for vendor maintenance.

006500 01  KEY-SCREEN.
006600     05  BLANK SCREEN.
006700     05  LINE  4 COLUMN 20 VALUE "VENDOR NUMBER:".
006800     05  LINE  4 COLUMN 40 PIC Z(5) USING VENDOR-NUMBER.
......
007100
007200 01  ENTRY-SCREEN.
007300     05  BLANK SCREEN.
007400     05  LINE  4 COLUMN 20 VALUE "VENDOR NUMBER:".
007500     05  LINE  4 COLUMN 40 PIC Z(5) FROM VENDOR-NUMBER.
007600     05  LINE  6 COLUMN 20 VALUE "VENDOR NAME: ".
007700     05  LINE  6 COLUMN 40 PIC X(30) USING VENDOR-NAME.
007800     05  LINE  8 COLUMN 20 VALUE "VENDOR ADDRESS:".
007900     05  LINE  8 COLUMN 40 PIC X(30) USING VENDOR-ADDRESS-1.
008000     05  LINE  9 COLUMN 40 PIC X(30) USING VENDOR-ADDRESS-2.
008100     05  LINE 10 COLUMN 20 VALUE "VENDOR CITY:".
008200     05  LINE 10 COLUMN 40 PIC X(20) USING VENDOR-CITY.
008300     05  LINE 12 COLUMN 20 VALUE "VENDOR STATE:".
008400     05  LINE 12 COLUMN 40 PIC XX USING VENDOR-STATE.
008500     05  LINE 12 COLUMN 45 PIC X(20) FROM STATE-NAME.
008600     05  LINE 14 COLUMN 20 VALUE "VENDOR ZIP:".
008700     05  LINE 14 COLUMN 40 PIC X(10) USING VENDOR-ZIP.
008800     05  LINE 16 COLUMN 20 VALUE "VENDOR CONTACT:".
008900     05  LINE 16 COLUMN 40 PIC X(30) USING VENDOR-CONTACT.
009000     05  LINE 18 COLUMN 20 VALUE "VENDOR PHONE:".
009100     05  LINE 18 COLUMN 40 PIC X(15) USING VENDOR-PHONE.
......
009600
009700 01  DISPLAY-SCREEN.
009800     05  BLANK SCREEN.
009900     05  LINE  4 COLUMN 20 VALUE "VENDOR NUMBER:".
010000     05  LINE  4 COLUMN 40 PIC Z(5) FROM VENDOR-NUMBER.
010100     05  LINE  6 COLUMN 20 VALUE "VENDOR NAME: ".
010200     05  LINE  6 COLUMN 40 PIC X(30) FROM VENDOR-NAME.
010300     05  LINE  8 COLUMN 20 VALUE "VENDOR ADDRESS:".
010400     05  LINE  8 COLUMN 40 PIC X(30) FROM VENDOR-ADDRESS-1.
010500     05  LINE  9 COLUMN 40 PIC X(30) FROM VENDOR-ADDRESS-2.
010600     05  LINE 10 COLUMN 20 VALUE "VENDOR CITY:".
010700     05  LINE 10 COLUMN 40 PIC X(20) FROM VENDOR-CITY.
010800     05  LINE 12 COLUMN 20 VALUE "VENDOR STATE:".
010900     05  LINE 12 COLUMN 40 PIC XX FROM VENDOR-STATE.
011000     05  LINE 12 COLUMN 45 PIC X(20) FROM STATE-NAME.
011100     05  LINE 14 COLUMN 20 VALUE "VENDOR ZIP:".
011200     05  LINE 14 COLUMN 40 PIC X(10) FROM VENDOR-ZIP.
011300     05  LINE 16 COLUMN 20 VALUE "VENDOR CONTACT:".
011400     05  LINE 16 COLUMN 40 PIC X(30) FROM VENDOR-CONTACT.
011500     05  LINE 18 COLUMN 20 VALUE "VENDOR PHONE:".
011600     05  LINE 18 COLUMN 40 PIC X(15) FROM VENDOR-PHONE.

ANALYSIS: The KEY-SCREEN at line 006500 contains only a prompt for the vendor number and a field for entry of the vendor number.

The ENTRY-SCREEN at line 007200 is similar to the VENDOR-SCREEN in Listing B3.3, but at line 007500, the VENDOR-NUMBER is not modifiable because it is defined with a FROM clause.

The DISPLAY-SCREEN at line 009700 is the same as ENTRY-SCREEN, except that all fields are defined with USING clauses, which makes all fields nonmodifiable.

A Maintenance Module for the File

With the screens worked out, it is possible to complete the maintenance module. Listing B3.5 contains add, change, inquire, and delete modes.

TYPE: Listing B3.5. Maintenance using full-screen I/O.

000100 IDENTIFICATION DIVISION.
000200 PROGRAM-ID. VNDMNT06.
000300*--------------------------------
000400* Add, Change, Inquire and Delete
000500* for the Vendor File.
000600* This includes Inquire by name
000700* The vendor report, and the vendor
000800* report in name order.
000900* Added Display all records.
001000* Uses full screen IO
001100*--------------------------------
001200 ENVIRONMENT DIVISION.
001300 INPUT-OUTPUT SECTION.
001400 FILE-CONTROL.
001500
001600     COPY "SLVND02.CBL".
001700
001800     COPY "SLSTATE.CBL".
001900
002000 DATA DIVISION.
002100 FILE SECTION.
002200
002300     COPY "FDVND04.CBL".
002400
002500     COPY "FDSTATE.CBL".
002600
002700 WORKING-STORAGE SECTION.
002800
002900 77  MENU-PICK                    PIC 9 VALUE ZERO.
003000     88  MENU-PICK-IS-VALID       VALUES 0 THRU 8.
003100
003200 77  VENDOR-RECORD-FOUND          PIC X.
003300 77  STATE-RECORD-FOUND           PIC X.
003400
003500 77  SCREEN-ERROR                 PIC X.
003600 77  ERROR-MESSAGE                PIC X(79) VALUE SPACE.
003700
003800 77  CONTINUE-MESSAGE             PIC X(40) VALUE SPACE.
003900 77  OK-TO-CONTINUE               PIC X.
004000
004100 01  FOOTER-FIELD.
004200     05  FOOTER-1-FIELD           PIC X(40) VALUE SPACE.
004300     05  FOOTER-2-FIELD           PIC X(39) VALUE SPACE.
004400
004500     COPY "WSCASE01.CBL".
004600
004700 SCREEN SECTION.
004800 01  MENU-SCREEN.
004900     05  BLANK SCREEN.
005000     05  LINE  2 COLUMN 30 VALUE "VENDOR MAINTENANCE".
005100     05  LINE  6 COLUMN 20 VALUE "PLEASE SELECT:".
005200     05  LINE  8 COLUMN 25 VALUE "1. ADD RECORDS".
005300     05  LINE  9 COLUMN 25 VALUE "2. CHANGE A RECORD".
005400     05  LINE 10 COLUMN 25 VALUE "3. LOOK UP A RECORD".
005500     05  LINE 11 COLUMN 25 VALUE "4. DELETE A RECORD".
005600     05  LINE 12 COLUMN 25 VALUE "5. LOOK UP BY NAME".
005700     05  LINE 13 COLUMN 25 VALUE "6. PRINT RECORDS".
005800     05  LINE 14 COLUMN 25 VALUE "7. PRINT IN NAME ORDER".
005900     05  LINE 15 COLUMN 25 VALUE "8. DISPLAY ALL RECORDS".
006000     05  LINE 17 COLUMN 25 VALUE "0. EXIT".
006100     05  LINE 20 COLUMN  1 VALUE "YOUR SELECTION? ".
006200     05  LINE 20 COLUMN 17 PIC Z USING MENU-PICK.
006300     05  LINE 24 COLUMN  1 PIC X(79) FROM ERROR-MESSAGE.
006400
006500 01  KEY-SCREEN.
006600     05  BLANK SCREEN.
006700     05  LINE  4 COLUMN 20 VALUE "VENDOR NUMBER:".
006800     05  LINE  4 COLUMN 40 PIC Z(5) USING VENDOR-NUMBER.
006900     05  LINE 22 COLUMN  1 PIC X(79) FROM FOOTER-FIELD.
007000     05  LINE 24 COLUMN  1 PIC X(79) FROM ERROR-MESSAGE.
007100
007200 01  ENTRY-SCREEN.
007300     05  BLANK SCREEN.
007400     05  LINE  4 COLUMN 20 VALUE "VENDOR NUMBER:".
007500     05  LINE  4 COLUMN 40 PIC Z(5) FROM VENDOR-NUMBER.
007600     05  LINE  6 COLUMN 20 VALUE "VENDOR NAME: ".
007700     05  LINE  6 COLUMN 40 PIC X(30) USING VENDOR-NAME.
007800     05  LINE  8 COLUMN 20 VALUE "VENDOR ADDRESS:".
007900     05  LINE  8 COLUMN 40 PIC X(30) USING VENDOR-ADDRESS-1.
008000     05  LINE  9 COLUMN 40 PIC X(30) USING VENDOR-ADDRESS-2.
008100     05  LINE 10 COLUMN 20 VALUE "VENDOR CITY:".
008200     05  LINE 10 COLUMN 40 PIC X(20) USING VENDOR-CITY.
008300     05  LINE 12 COLUMN 20 VALUE "VENDOR STATE:".
008400     05  LINE 12 COLUMN 40 PIC XX USING VENDOR-STATE.
008500     05  LINE 12 COLUMN 45 PIC X(20) FROM STATE-NAME.
008600     05  LINE 14 COLUMN 20 VALUE "VENDOR ZIP:".
008700     05  LINE 14 COLUMN 40 PIC X(10) USING VENDOR-ZIP.
008800     05  LINE 16 COLUMN 20 VALUE "VENDOR CONTACT:".
008900     05  LINE 16 COLUMN 40 PIC X(30) USING VENDOR-CONTACT.
009000     05  LINE 18 COLUMN 20 VALUE "VENDOR PHONE:".
009100     05  LINE 18 COLUMN 40 PIC X(15) USING VENDOR-PHONE.
009200     05  LINE 22 COLUMN  1 PIC X(79) FROM FOOTER-FIELD.
009300     05  LINE 23 COLUMN  1 PIC X(40) FROM CONTINUE-MESSAGE.
009400     05  LINE 23 COLUMN 41 PIC X USING OK-TO-CONTINUE.
009500     05  LINE 24 COLUMN  1 PIC X(79) FROM ERROR-MESSAGE.
009600
009700 01  DISPLAY-SCREEN.
009800     05  BLANK SCREEN.
009900     05  LINE  4 COLUMN 20 VALUE "VENDOR NUMBER:".
010000     05  LINE  4 COLUMN 40 PIC Z(5) FROM VENDOR-NUMBER.
010100     05  LINE  6 COLUMN 20 VALUE "VENDOR NAME: ".
010200     05  LINE  6 COLUMN 40 PIC X(30) FROM VENDOR-NAME.
010300     05  LINE  8 COLUMN 20 VALUE "VENDOR ADDRESS:".
010400     05  LINE  8 COLUMN 40 PIC X(30) FROM VENDOR-ADDRESS-1.
010500     05  LINE  9 COLUMN 40 PIC X(30) FROM VENDOR-ADDRESS-2.
010600     05  LINE 10 COLUMN 20 VALUE "VENDOR CITY:".
010700     05  LINE 10 COLUMN 40 PIC X(20) FROM VENDOR-CITY.
010800     05  LINE 12 COLUMN 20 VALUE "VENDOR STATE:".
010900     05  LINE 12 COLUMN 40 PIC XX FROM VENDOR-STATE.
011000     05  LINE 12 COLUMN 45 PIC X(20) FROM STATE-NAME.
011100     05  LINE 14 COLUMN 20 VALUE "VENDOR ZIP:".
011200     05  LINE 14 COLUMN 40 PIC X(10) FROM VENDOR-ZIP.
011300     05  LINE 16 COLUMN 20 VALUE "VENDOR CONTACT:".
011400     05  LINE 16 COLUMN 40 PIC X(30) FROM VENDOR-CONTACT.
011500     05  LINE 18 COLUMN 20 VALUE "VENDOR PHONE:".
011600     05  LINE 18 COLUMN 40 PIC X(15) FROM VENDOR-PHONE.
011700     05  LINE 23 COLUMN  1 PIC X(40) FROM CONTINUE-MESSAGE.
011800     05  LINE 23 COLUMN 41 PIC X USING OK-TO-CONTINUE.
011900     05  LINE 24 COLUMN  1 PIC X(79) FROM ERROR-MESSAGE.
012000
012100 PROCEDURE DIVISION.
012200 PROGRAM-BEGIN.
012300     PERFORM OPENING-PROCEDURE.
012400     PERFORM MAIN-PROCESS.
012500     PERFORM CLOSING-PROCEDURE.
012600
012700 PROGRAM-EXIT.
012800     EXIT PROGRAM.
012900
013000 PROGRAM-DONE.
013100     STOP RUN.
013200
013300 OPENING-PROCEDURE.
013400     OPEN I-O VENDOR-FILE.
013500     OPEN I-O STATE-FILE.
013600
013700 CLOSING-PROCEDURE.
013800     CLOSE VENDOR-FILE.
013900     CLOSE STATE-FILE.
014000
014100 MAIN-PROCESS.
014200     PERFORM GET-MENU-PICK.
014300     PERFORM MAINTAIN-THE-FILE
014400         UNTIL MENU-PICK = 0.
014500
014600*--------------------------------
014700* MENU
014800*--------------------------------
014900 GET-MENU-PICK.
015000     PERFORM INITIALIZE-MENU-PICK.
015100     PERFORM DISPLAY-ACCEPT-MENU.
015200     PERFORM RE-DISPLAY-ACCEPT-MENU
015300         UNTIL MENU-PICK-IS-VALID.
015400
015500 INITIALIZE-MENU-PICK.
015600     MOVE 0 TO MENU-PICK.
015700
015800 DISPLAY-ACCEPT-MENU.
015900     DISPLAY MENU-SCREEN.
016000     ACCEPT MENU-SCREEN.
016100     MOVE SPACE TO ERROR-MESSAGE.
016200
016300 RE-DISPLAY-ACCEPT-MENU.
016400     MOVE "INVALID SELECTION - PLEASE RE-TRY."
016500           TO ERROR-MESSAGE.
016600     PERFORM DISPLAY-ACCEPT-MENU.
016700
016800 MAINTAIN-THE-FILE.
016900     PERFORM DO-THE-PICK.
017000     PERFORM GET-MENU-PICK.
017100
017200 DO-THE-PICK.
017300     IF MENU-PICK = 1
017400         PERFORM ADD-MODE
017500     ELSE
017600     IF MENU-PICK = 2
017700         PERFORM CHANGE-MODE
017800     ELSE
017900     IF MENU-PICK = 3
018000         PERFORM INQUIRE-MODE
018100     ELSE
018200     IF MENU-PICK = 4
018300         PERFORM DELETE-MODE
018400     ELSE
018500     IF MENU-PICK = 5
018600         PERFORM INQUIRE-BY-NAME
018700     ELSE
018800     IF MENU-PICK = 6
018900         PERFORM PRINT-VENDOR-REPORT
019000     ELSE
019100     IF MENU-PICK = 7
019200         PERFORM PRINT-BY-NAME
019300     ELSE
019400     IF MENU-PICK = 8
019500         PERFORM DISPLAY-ALL.
019600
019700*--------------------------------
019800* ADD
019900*--------------------------------
020000 ADD-MODE.
020100     PERFORM INITIALIZE-ADD-MODE.
020200     PERFORM GET-NEW-RECORD-KEY.
020300     PERFORM ADD-RECORDS
020400        UNTIL VENDOR-NUMBER = ZEROES.
020500
020600 INITIALIZE-ADD-MODE.
020700     MOVE "ENTER THE VENDOR NUMBER TO ADD"
020800       TO FOOTER-1-FIELD.
020900
021000 GET-NEW-RECORD-KEY.
021100     PERFORM ACCEPT-NEW-RECORD-KEY.
021200     PERFORM RE-ACCEPT-NEW-RECORD-KEY
021300        UNTIL VENDOR-NUMBER = ZEROES
021400           OR VENDOR-RECORD-FOUND = "N".
021500
021600 ACCEPT-NEW-RECORD-KEY.
021700     PERFORM INITIALIZE-VENDOR-FIELDS.
021800     PERFORM ENTER-VENDOR-NUMBER.
021900     IF VENDOR-NUMBER NOT = ZEROES
022000         PERFORM READ-VENDOR-RECORD.
022100
022200 RE-ACCEPT-NEW-RECORD-KEY.
022300     MOVE "RECORD ALREADY ON FILE" TO ERROR-MESSAGE.
022400     PERFORM ACCEPT-NEW-RECORD-KEY.
022500
022600 ADD-RECORDS.
022700     PERFORM INITIALIZE-TO-ADD-FIELDS.
022800     PERFORM ENTER-REMAINING-FIELDS.
022900     IF OK-TO-CONTINUE = "Y"
023000         PERFORM WRITE-VENDOR-RECORD.
023100     PERFORM GET-NEW-RECORD-KEY.
023200
023300 INITIALIZE-TO-ADD-FIELDS.
023400     MOVE "ADD NEW FIELDS" TO FOOTER-FIELD.
023500     MOVE "CONTINUE WITH ADDITIONS (Y/N)?"
023600         TO CONTINUE-MESSAGE.
023700     MOVE "Y" TO OK-TO-CONTINUE.
023800
023900*--------------------------------
024000* CHANGE
024100*--------------------------------
024200 CHANGE-MODE.
024300     PERFORM INITIALIZE-CHANGE-MODE.
024400     PERFORM GET-EXISTING-RECORD.
024500     PERFORM CHANGE-RECORDS
024600        UNTIL VENDOR-NUMBER = ZEROES.
024700
024800 INITIALIZE-CHANGE-MODE.
024900     MOVE "ENTER THE VENDOR NUMBER TO CHANGE"
025000        TO FOOTER-1-FIELD.
025100
025200 CHANGE-RECORDS.
025300     PERFORM INITIALIZE-TO-CHANGE-FIELDS.
025400     PERFORM ENTER-REMAINING-FIELDS.
025500     IF OK-TO-CONTINUE = "Y"
025600         PERFORM REWRITE-VENDOR-RECORD.
025700     PERFORM GET-EXISTING-RECORD.
025800
025900 INITIALIZE-TO-CHANGE-FIELDS.
026000     MOVE "CHANGE FIELDS" TO FOOTER-FIELD.
026100     MOVE "CONTINUE WITH CHANGES (Y/N)?"
026200        TO CONTINUE-MESSAGE.
026300     MOVE "Y" TO OK-TO-CONTINUE.
026400
026500*--------------------------------
026600* INQUIRE
026700*--------------------------------
026800 INQUIRE-MODE.
026900     PERFORM INITIALIZE-INQUIRE-MODE.
027000     PERFORM GET-EXISTING-RECORD.
027100     PERFORM INQUIRE-RECORDS
027200        UNTIL VENDOR-NUMBER = ZEROES.
027300
027400 INITIALIZE-INQUIRE-MODE.
027500     MOVE "ENTER THE VENDOR NUMBER TO DISPLAY"
027600        TO FOOTER-1-FIELD.
027700
027800 INQUIRE-RECORDS.
027900     PERFORM INITIALIZE-TO-INQUIRE.
028000     PERFORM DISPLAY-ACCEPT-ALL-FIELDS.
028100     PERFORM GET-EXISTING-RECORD.
028200
028300 INITIALIZE-TO-INQUIRE.
028400     MOVE "PRESS ENTER TO CONTINUE" TO CONTINUE-MESSAGE.
028500     MOVE SPACE TO OK-TO-CONTINUE.
028600
028700*--------------------------------
028800* DELETE
028900*--------------------------------
029000 DELETE-MODE.
029100     PERFORM INITIALIZE-DELETE-MODE.
029200     PERFORM GET-EXISTING-RECORD.
029300     PERFORM DELETE-RECORDS
029400        UNTIL VENDOR-NUMBER = ZEROES.
029500
029600 INITIALIZE-DELETE-MODE.
029700     MOVE "ENTER THE VENDOR NUMBER TO DELETE"
029800       TO FOOTER-1-FIELD.
029900
030000 DELETE-RECORDS.
030100     PERFORM INITIALIZE-TO-DELETE-RECORD.
030200     PERFORM ASK-OK-TO-DELETE.
030300     IF OK-TO-CONTINUE = "Y"
030400         PERFORM DELETE-VENDOR-RECORD.
030500     PERFORM GET-EXISTING-RECORD.
030600
030700 INITIALIZE-TO-DELETE-RECORD.
030800     MOVE "OK TO DELETE(Y/N)?" TO CONTINUE-MESSAGE.
030900     MOVE "N" TO OK-TO-CONTINUE.
031000
031100 ASK-OK-TO-DELETE.
031200     PERFORM DISPLAY-ACCEPT-ALL-FIELDS.
031300     PERFORM RE-DISPLAY-ACCEPT-ALL-FIELDS
031400        UNTIL OK-TO-CONTINUE = "Y" OR "N".
031500
031600 RE-DISPLAY-ACCEPT-ALL-FIELDS.
031700     MOVE "YOU MUST ENTER YES OR NO"
031800         TO ERROR-MESSAGE.
031900     PERFORM DISPLAY-ACCEPT-ALL-FIELDS.
032000
032100*--------------------------------
032200* Routines shared by all modes
032300*--------------------------------
032400 INITIALIZE-VENDOR-FIELDS.
032500     MOVE SPACE TO VENDOR-RECORD.
032600     MOVE ZEROES TO VENDOR-NUMBER.
032700     MOVE SPACE TO STATE-NAME.
032800
032900 ENTER-VENDOR-NUMBER.
033000     MOVE "ENTER 0 TO QUIT" TO FOOTER-2-FIELD.
033100     DISPLAY KEY-SCREEN.
033200     ACCEPT KEY-SCREEN.
033300     MOVE SPACE TO ERROR-MESSAGE.
033400
033500*--------------------------------
033600* Routines shared Add and Change
033700*--------------------------------
033800 ENTER-REMAINING-FIELDS.
033900     PERFORM DISPLAY-ACCEPT-ENTRY-SCREEN.
034000     PERFORM DISPLAY-ACCEPT-ENTRY-SCREEN
034100         UNTIL SCREEN-ERROR = "N"
034200            OR OK-TO-CONTINUE = "N".
034300
034400 DISPLAY-ACCEPT-ENTRY-SCREEN.
034500     DISPLAY ENTRY-SCREEN.
034600     ACCEPT ENTRY-SCREEN.
034700     MOVE SPACE TO ERROR-MESSAGE.
034800
034900     INSPECT OK-TO-CONTINUE
035000      CONVERTING LOWER-ALPHA TO UPPER-ALPHA.
035100
035200     IF OK-TO-CONTINUE = "Y"
035300         PERFORM EDIT-CHECK-FIELDS.
035400
035500 EDIT-CHECK-FIELDS.
035600     MOVE "N" TO SCREEN-ERROR.
035700     PERFORM EDIT-CHECK-VENDOR-NAME.
035800     IF SCREEN-ERROR NOT = "Y"
035900         PERFORM EDIT-CHECK-VENDOR-ADDRESS-1.
036000     IF SCREEN-ERROR NOT = "Y"
036100         PERFORM EDIT-CHECK-VENDOR-ADDRESS-2.
036200     IF SCREEN-ERROR NOT = "Y"
036300         PERFORM EDIT-CHECK-VENDOR-CITY.
036400     IF SCREEN-ERROR NOT = "Y"
036500         PERFORM EDIT-CHECK-VENDOR-STATE.
036600     IF SCREEN-ERROR NOT = "Y"
036700         PERFORM EDIT-CHECK-VENDOR-ZIP.
036800     IF SCREEN-ERROR NOT = "Y"
036900         PERFORM EDIT-CHECK-VENDOR-CONTACT.
037000     IF SCREEN-ERROR NOT = "Y"
037100         PERFORM EDIT-CHECK-VENDOR-PHONE.
037200
037300 EDIT-CHECK-VENDOR-NAME.
037400     INSPECT VENDOR-NAME
037500         CONVERTING LOWER-ALPHA
037600         TO         UPPER-ALPHA.
037700
037800     IF VENDOR-NAME = SPACES
037900         MOVE "Y" TO SCREEN-ERROR
038000         MOVE "VENDOR NAME MUST BE ENTERED"
038100            TO ERROR-MESSAGE.
038200 EDIT-CHECK-VENDOR-ADDRESS-1.
038300     INSPECT VENDOR-ADDRESS-1
038400         CONVERTING LOWER-ALPHA
038500         TO         UPPER-ALPHA.
038600     IF VENDOR-ADDRESS-1 = SPACE
038700         MOVE "Y" TO SCREEN-ERROR
038800         MOVE "VENDOR ADDRESS-1 MUST BE ENTERED"
038900           TO ERROR-MESSAGE.
039000
039100 EDIT-CHECK-VENDOR-ADDRESS-2.
039200     INSPECT VENDOR-ADDRESS-2
039300         CONVERTING LOWER-ALPHA
039400         TO         UPPER-ALPHA.
039500
039600 EDIT-CHECK-VENDOR-CITY.
039700     INSPECT VENDOR-CITY
039800         CONVERTING LOWER-ALPHA
039900         TO         UPPER-ALPHA.
040000
040100     IF VENDOR-CITY = SPACE
040200         MOVE "Y" TO SCREEN-ERROR
040300         MOVE  "VENDOR CITY MUST BE ENTERED"
040400           TO ERROR-MESSAGE.
040500
040600 EDIT-CHECK-VENDOR-STATE.
040700     PERFORM EDIT-VENDOR-STATE.
040800     PERFORM CHECK-VENDOR-STATE.
040900
041000 EDIT-VENDOR-STATE.
041100     INSPECT VENDOR-STATE
041200         CONVERTING LOWER-ALPHA
041300         TO         UPPER-ALPHA.
041400
041500 CHECK-VENDOR-STATE.
041600     PERFORM VENDOR-STATE-REQUIRED.
041700     IF VENDOR-STATE NOT = SPACES
041800         PERFORM VENDOR-STATE-ON-FILE.
041900
042000 VENDOR-STATE-REQUIRED.
042100     IF VENDOR-STATE = SPACE
042200         MOVE "Y" TO SCREEN-ERROR
042300         MOVE "VENDOR STATE MUST BE ENTERED"
042400           TO ERROR-MESSAGE.
042500
042600 VENDOR-STATE-ON-FILE.
042700     MOVE VENDOR-STATE TO STATE-CODE.
042800     PERFORM READ-STATE-RECORD.
042900     IF STATE-RECORD-FOUND = "N"
043000         MOVE "Y" TO SCREEN-ERROR
043100         MOVE "STATE CODE NOT FOUND IN CODES FILE"
043200           TO ERROR-MESSAGE.
043300
043400 EDIT-CHECK-VENDOR-ZIP.
043500     INSPECT VENDOR-ZIP
043600         CONVERTING LOWER-ALPHA
043700         TO         UPPER-ALPHA.
043800     IF VENDOR-ZIP = SPACE
043900         MOVE "Y" TO SCREEN-ERROR
044000         MOVE "VENDOR ZIP MUST BE ENTERED"
044100           TO ERROR-MESSAGE.
044200
044300 EDIT-CHECK-VENDOR-CONTACT.
044400     INSPECT VENDOR-CONTACT
044500         CONVERTING LOWER-ALPHA
044600         TO         UPPER-ALPHA.
044700
044800 EDIT-CHECK-VENDOR-PHONE.
044900     INSPECT VENDOR-PHONE
045000         CONVERTING LOWER-ALPHA
045100         TO         UPPER-ALPHA.
045200     IF VENDOR-PHONE = SPACE
045300         MOVE "Y" TO SCREEN-ERROR
045400         MOVE "ENTER VENDOR PHONE"
045500            TO ERROR-MESSAGE.
045600
045700*--------------------------------
045800* Routines shared by Change,
045900* Inquire and Delete
046000*--------------------------------
046100 GET-EXISTING-RECORD.
046200     PERFORM INITIALIZE-VENDOR-FIELDS.
046300     PERFORM ACCEPT-EXISTING-KEY.
046400     PERFORM RE-ACCEPT-EXISTING-KEY
046500         UNTIL VENDOR-RECORD-FOUND = "Y" OR
046600               VENDOR-NUMBER = ZEROES.
046700
046800 ACCEPT-EXISTING-KEY.
046900     PERFORM ENTER-VENDOR-NUMBER.
047000     IF VENDOR-NUMBER NOT = ZEROES
047100         PERFORM READ-VENDOR-AND-STATE.
047200
047300 RE-ACCEPT-EXISTING-KEY.
047400     MOVE "RECORD NOT FOUND" TO ERROR-MESSAGE.
047500     PERFORM ACCEPT-EXISTING-KEY.
047600
047700*--------------------------------
047800* Routines shared by delete and inquire
047900*--------------------------------
048000 DISPLAY-ACCEPT-ALL-FIELDS.
048100     DISPLAY DISPLAY-SCREEN.
048200     ACCEPT DISPLAY-SCREEN.
048300     MOVE SPACE TO ERROR-MESSAGE.
048400     INSPECT OK-TO-CONTINUE
048500      CONVERTING LOWER-ALPHA TO UPPER-ALPHA.
048600
048700*--------------------------------
048800* File I-O Routines
048900*--------------------------------
049000 READ-VENDOR-AND-STATE.
049100     PERFORM READ-VENDOR-RECORD.
049200     IF VENDOR-RECORD-FOUND = "Y"
049300         MOVE VENDOR-STATE TO STATE-CODE
049400         PERFORM READ-STATE-RECORD
049500         IF STATE-RECORD-FOUND = "N"
049600             MOVE "*** NOT FOUND ***" TO STATE-NAME.
049700
049800 READ-VENDOR-RECORD.
049900     MOVE "Y" TO VENDOR-RECORD-FOUND.
050000     READ VENDOR-FILE RECORD
050100       INVALID KEY
050200          MOVE "N" TO VENDOR-RECORD-FOUND.
050300
050400 WRITE-VENDOR-RECORD.
050500     WRITE VENDOR-RECORD
050600         INVALID KEY
050700         DISPLAY "RECORD ALREADY ON FILE".
050800
050900 REWRITE-VENDOR-RECORD.
051000     REWRITE VENDOR-RECORD
051100         INVALID KEY
051200         DISPLAY "ERROR REWRITING VENDOR RECORD".
051300
051400 DELETE-VENDOR-RECORD.
051500     DELETE VENDOR-FILE RECORD
051600         INVALID KEY
051700         DISPLAY "ERROR DELETING VENDOR RECORD".
051800
051900 READ-STATE-RECORD.
052000     MOVE "Y" TO STATE-RECORD-FOUND.
052100     READ STATE-FILE RECORD
052200       INVALID KEY
052300          MOVE "N" TO STATE-RECORD-FOUND.
052400
052500*--------------------------------
052600* CALLS TO OTHER PROGRAMS
052700*--------------------------------
052800
052900*--------------------------------
053000* INQUIRE BY NAME
053100*--------------------------------
053200 INQUIRE-BY-NAME.
053300     PERFORM CLOSING-PROCEDURE.
053400     CALL "VNINNM03".
053500     PERFORM OPENING-PROCEDURE.
053600
053700*--------------------------------
053800* PRINT
053900*--------------------------------
054000 PRINT-VENDOR-REPORT.
054100     PERFORM CLOSING-PROCEDURE.
054200     DISPLAY "VENDOR REPORT IN PROGRESS".
054300     CALL "VNDRPT04".
054400     PERFORM OPENING-PROCEDURE.
054500
054600*--------------------------------
054700* PRINT BY NAME
054800*--------------------------------
054900 PRINT-BY-NAME.
055000     PERFORM CLOSING-PROCEDURE.
055100     DISPLAY " REPORT BY NAME IN PROGRESS".
055200     CALL "VNBYNM02".
055300     PERFORM OPENING-PROCEDURE.
055400
055500*--------------------------------
055600* DISPLAY ALL
055700*--------------------------------
055800 DISPLAY-ALL.
055900     PERFORM CLOSING-PROCEDURE.
056000     CALL "VNDDSP03".
056100     DISPLAY "DISPLAY COMPLETE".
056200     DISPLAY "PRESS ENTER TO CONTINUE".
056300     ACCEPT OK-TO-CONTINUE.
056400     PERFORM OPENING-PROCEDURE.
056500

OUTPUT:

The following output of vndmnt06.cbl illustrates some of the full screens that are created by the program:

                              VENDOR MAINTENANCE
                   PLEASE SELECT:
                        1. ADD RECORDS
                        2. CHANGE A RECORD
                        3. LOOK UP A RECORD
                        4. DELETE A RECORD
                        5. LOOK UP BY NAME
                        6. PRINT RECORDS
                        7. PRINT IN NAME ORDER
                        8. DISPLAY ALL RECORDS
                        0. EXIT
YOUR SELECTION?
-------------------------------------------------------------------------
                    VENDOR NUMBER:      _____
ENTER THE VENDOR NUMBER TO CHANGE       ENTER 0 TO QUIT
-------------------------------------------------------------------------
                    VENDOR NUMBER:      __606
ENTER THE VENDOR NUMBER TO CHANGE       ENTER 0 TO QUIT
RECORD NOT FOUND
-------------------------------------------------------------------------
                    VENDOR NUMBER:          2
                    VENDOR NAME:        ABC PRINTING_________________
                    VENDOR ADDRESS:     1624 FOOTHILL BLVD
                                        SUITE 34
                    VENDOR CITY:        LOS ANGELES
                    VENDOR STATE:       CA   CALIFORNIA
                    VENDOR ZIP:         91042
                    VENDOR CONTACT:     CHARLES JOHANSSEN
                    VENDOR PHONE:       (818) 555-4321
CHANGE FIELDS
CONTINUE WITH CHANGES (Y/N)?            Y
-------------------------------------------------------------------------
                    VENDOR NUMBER:          2
                    VENDOR NAME:        ABC PRINTING
                    VENDOR ADDRESS:     1624 FOOTHILL BLVD
                                        SUITE 34
                    VENDOR CITY:        LOS ANGELES
                    VENDOR STATE:       CA   CALIFORNIA
                    VENDOR ZIP:         91042
                    VENDOR CONTACT:     CHARLES JOHANSSEN
                    VENDOR PHONE:       (818) 555-4321
OK TO DELETE(Y/N)?                      N
------------------------------------------------------------------------

ANALYSIS: The screens are defined at lines 004800, 006500, 007200, and 009700 in the SCREEN SECTION. All of the fields used in the screen definitions are defined either in the WORKING-STORAGE SECTION or in the FILE SECTION.

At lines 003500 and 003600, fields are defined to handle error logic, a SCREEN-ERROR flag, and an ERROR-MESSAGE that will be displayed on the screens.

The user instructions fields on rows 23 and 24 are defined at lines 0003800 through 004300, which consist of a CONTINUE-MESSAGE flag, an OK-TO-CONTINUE flag, and a FOOTER-FIELD that is broken into two smaller fields, FOOTER-1-FIELD and FOOTER-2-FIELD.

When through the menu, all modes start by using the ENTER-VENDOR-NUMBER routine at line 032900. This routine is used to display and accept entry of the KEY-SCREEN.

ADD-MODE begins at line 020000. It uses INITIALIZE-ADD-MODE to set up a message in FOOTER-1-FIELD, and then performs GET-NEW-RECORD-KEY at line 021000.

The task of GET-NEW-RECORD-KEY is to get the user to enter a vendor number that is not on file or enter 0 to indicate that the user wants to exit. The GET-NEW-RECORD-KEY paragraph uses ENTER-VENDOR-NUMBER and the KEY-SCREEN to do this. After the user has entered a valid vendor number (a new number or a zero), ADD-RECORDS at line 020300 is performed until VENDOR-NUMBER = ZEROES.

ADD-RECORDS at line 022600 initializes for adding fields, and then performs ENTER-REMAINING-FIELDS. If on the return from ENTER-REMAINING-FIELDS the test for OK-TO-CONTINUE = "Y" is true, the new vendor record is written. Another new record key is asked of the user and ADD-RECORDS continues until the user enters 0.

ENTER-REMAINING-FIELDS at line 033800 is probably the largest routine in the file. Its job is to display and accept the ENTRY-SCREEN, and to edit and validate all of the entered fields. It starts by performing DISPLAY-ACCEPT-ENTRY-SCREEN and then repeating DISPLAY-ACCEPT-ENTRY-SCREEN UNTIL SCREEN-ERROR = "N" OR OK-TO-CONTINUE = "N". The OK-TO-CONTINUE flag gives the user a chance to bail out if the data entry cycle began in error.

This bail-out takes place in DISPLAY-ACCEPT-ENTRY-SCREEN, which begins at line 034400. After displaying and accepting the screens at line 034900, the OK-TO-CONTINUE flag is converted to uppercase, and if OK-TO-CONTINUE = "Y" is true, the edit-check is performed.

The edit-checks are performed on the basis that all editing and checking stops on the first field that contains an error. EDIT-CHECK-FIELDS at line 035500 performs each edit-check, field by field, as long as SCREEN-ERROR NOT = "Y" is true.

The actual checks are at lines 037300 through 045500. Each edit-check must set up two conditions if an error occurs in a field. It must MOVE "Y" TO SCREEN-ERROR and it must move an error message to ERROR-MESSAGE.

Change mode, which is similar to add mode, first locates the key of a record that does exist, and then uses ENTER-REMAINING-FIELDS to enable the user to change values. Inquire mode and delete mode are simple; they are left for you to analyze.

Code and compile vndmnt06.cbl. Print out a copy of the program and as you run it, follow where you are at each point in the maintenance program.

Boilerplate

The cobshl04.cbl program is a boilerplate, though a very simple one. The vndmnt06.cbl program can be used as a boilerplate for full-screen maintenance programs. Replace the data and statements that are specific to the vendor file with those from another file.

New Term: A boilerplate is a program that can be used as the basic starting block for other programs.

As your coding improves, you gradually will develop something that you are happy with as the basic way a file should be maintained and that will become your boilerplate. For now, you can use vndmnt06.cbl as a boilerplate and for the exercises of today's lesson.

Summary

Several modern versions of COBOL enable a more polished method of handling user input by allowing the program to display and accept a full screen of information at a time. Today, you learned these basics:

Q&A

Q Do I have to use full-screen I/O?

A No, but you probably will. After you become more familiar with COBOL, you will want to try these "slicker" screens. If you land a job working in COBOL, you will almost certainly have to code in full-screen mode.

Q Can I use a mouse with COBOL programs?

A A mouse is not supported as a standard part of the COBOL language, but several modern COBOL compilers include programs or routines that can be called upon that will return mouse positions and mouse clicks. Micro Focus Personal COBOL supports mouse commands, but this is beyond the scope of this book.

Workshop

Quiz

1. The following code is a fragment of a screen definition. Which lines create fields on the screen that cannot be modified?
008300     05  LINE 12 COLUMN 20 VALUE "VENDOR STATE:".
008400     05  LINE 12 COLUMN 40 PIC XX USING VENDOR-STATE.
008500     05  LINE 12 COLUMN 45 PIC X(20) FROM STATE-NAME.
2. Which line or lines of the code in question 1 create fields on the screen that can be modified?

Exercise

Using vndmnt06.cbl as a pattern, create stcmnt05.cbl as a full-screen maintenance module for the state codes file.


Previous chapterNext chapterContents


© Copyright, Macmillan Computer Publishing. All rights reserved.