Microsoft KB Archive/58828

How to Modify CENTER.COB Program to Make a Subprogram

PSS ID Number: Q58828 Article last modified on 03-06-1990

2.00 2.10 2.20 3.00 3.00a MS-DOS

Summary: Microsoft COBOL Compiler Versions 2.00, 2.10, and 2.20 come with a program called CENTER.COB, which centers, right aligns, or left aligns text within an 80-character field. This program can be made into a subprogram to be called by other programs. The following changes need to be made to this program for it to work as a subprogram: 1. Move the block storage called PARAMETER-AREA into the LINKAGE SECTION. 2. Add the clause “USING PARAMETER-AREA” to the PROCEDURE DIVISION header. 3. Replace STOP RUN with EXIT PROGRAM. 4. Delete the DISPLAY and ACCEPT statements. If you want to center text in a field other than 80 characters in length, change the PA-BUFFER-LEN, PA-IN-TITLE, and PA-OUT-TITLE variables in the PARAMETER-AREA. This information applies to Microsoft COBOL Compiler Versions 2.00, 2.10, 2.20, 3.00, and 3.00a.

More Information: In the program CENTER.COB, the code will be changed to resemble the following structure: DATA DIVISION. WORKING-STORAGE SECTION. 01 WORK-FIELDS. . . . LINKAGE SECTION. 01 PARAMETER-AREA. 05 PA-OPTION PIC X VALUE SPACE. 88 CENTER-OPTION VALUE ‘C’, ‘c’. . . . PROCEDURE DIVISION USING PARAMETER-AREA. . . EXIT PROGRAM. In the calling program, add the PARAMETER-AREA to the WORKING-STORAGE SECTION, MOVE the data to be centered and CALL “CENTER” USING PARAMETER-AREA. The code will resemble the following structure: WORKING-STORAGE SECTION. 01 PARAMETER-AREA. 05 PA-OPTION PIC X VALUE SPACE. 88 CENTER-OPTION VALUE ‘C’, ‘c’. . . . 01 WS-VARIABLES. 05 WS-STUFF-TO-CENTER PIC X(80). 05 WS-CENTERED-STUFF PIC X(80). PROCEDURE DIVISION. . . MOVE WS-STUFF-TO-CENTER TO PA-IN-TITLE. CALL “CENTER” USING PARAMETER-AREA. MOVE PA-OUT-TITLE TO WS-CENTERED-STUFF. ..

Code Example
The complete code for defining the subprogram CENTER.COB is as follows: IDENTIFICATION DIVISION. PROGRAM-ID. CENTER. SECURITY. THIS PROGRAM CENTERS, RIGHT ALIGNS, OR RIGHT ALIGNS A HEADING WITHIN AN 80 CHARACTER FIELD. IT CAN BE MADE INTO A GENERAL-PURPOSE SUBPROGRAM BY MOVING THE BLOCK OF STORAGE CALLED PARAMETER-AREA INTO THE LINKAGE SECTION, ADDING THE CLAUSE, “USING PARAMETER-AREA” TO THE PROCEDURE DIVISION HEADER, REPLACING “STOP RUN” WITH “EXIT PROGRAM”, AND DELETING THE DISPLAY AND ACCEPT STATEMENTS. THE PARAMETER-AREA VARIABLES WOULD THEN BE SET UP IN THE CALLING PROGRAM. * ENVIRONMENT DIVISION. DATA DIVISION. WORKING-STORAGE SECTION. 01 WORK-FIELDS. 05 IIX PIC S9(5) VALUE 0 COMP-0. 05 WS-IN-START PIC S9(5) VALUE 0 COMP-0. 05 WS-IN-END PIC S9(5) VALUE 0 COMP-0. 05 WS-IN-LEN PIC S9(5) VALUE 0 COMP-0. 05 WS-OUT-INDEX PIC S9(5) VALUE 0 COMP-0. 05 TEN-SPACES PIC X(10) VALUE SPACES. 01 SWITCHES. 05 ON-VALUE PIC X VALUE ‘Y’. 05 OFF-VALUE PIC X VALUE ‘N’. 05 FINISHED-SW PIC X VALUE ‘N’. 88 FINISHED VALUE ‘Y’. LINKAGE SECTION. 01 PARAMETER-AREA. 05 PA-OPTION PIC X VALUE SPACE. 88 CENTER-OPTION VALUE ‘C’, ‘c’. 88 LEFT-ALIGN-OPTION VALUE ‘L’, ‘l’. 88 RIGHT-ALIGN-OPTION VALUE ‘R’, ‘r’. 88 VALID-OPTION VALUE ‘C’, ‘c’, ‘L’, ‘l’, ‘R’, ‘r’. 88 END-OPTION VALUE ‘E’, ‘e’. 05 PA-BUFFER-LEN PIC S9(5) VALUE 80 COMP-0. 05 PA-IN-TITLE PIC X(80) VALUE SPACES. 05 FILLER REDEFINES PA-IN-TITLE. 10 PA-IN-TITLE-CHAR OCCURS 80 TIMES PIC X. 05 PA-OUT-TITLE PIC X(80) VALUE SPACES. 05 FILLER REDEFINES PA-OUT-TITLE. 10 PA-OUT-TITLE-CHAR OCCURS 80 TIMES PIC X. PROCEDURE DIVISION USING PARAMETER-AREA. P000-MAIN-LINE. IF END-OPTION MOVE ON-VALUE TO FINISHED-SW EXIT PROGRAM ELSE IF VALID-OPTION PERFORM P020-GET-TITLE. EXIT PROGRAM. P020-GET-TITLE. MOVE SPACES TO PA-OUT-TITLE. IF PA-IN-TITLE NOT = SPACES PERFORM P030-ADJUST. EXIT PROGRAM. P030-ADJUST. PERFORM P035-NOTHING VARYING WS-IN-START FROM 1 BY 1 UNTIL PA-IN-TITLE-CHAR (WS-IN-START) NOT = SPACE OR WS-IN-START > PA-BUFFER-LEN. PERFORM P035-NOTHING VARYING WS-IN-END FROM PA-BUFFER-LEN BY -1 UNTIL PA-IN-TITLE-CHAR (WS-IN-END) NOT = SPACE OR WS-IN-END NOT > 1. COMPUTE WS-OUT-INDEX = 1 + ((PA-BUFFER-LEN - WS-IN-LEN) / 2). PERFORM P040-MOVE-TITLE VARYING IIX FROM WS-IN-START BY 1 UNTIL IIX > WS-IN-END. P035-NOTHING. EXIT. P040-MOVE-TITLE. MOVE PA-IN-TITLE-CHAR (IIX) TO PA-OUT-TITLE-CHAR (WS-OUT-INDEX). ADD 1 TO WS-OUT-INDEX.

Copyright Microsoft Corporation 1990.