You are on page 1of 22

Preparing Program Logic

1. Hierarchy Chart can be drawn when a program contains multiple modules or paragraphs. It shows the relationship of the paragraphs in the PROCEDURE DIVISION. Each rectangle
represents one paragraph in the program

100-MAIN-RTN

200-INITIAL-RTN

500-PROCESS-RTN

900-CLOSE-RTN

600-HEADING-RTN
COBOL21: A Complete COBOL Program

700-WRITE-RTN

Preparing Program Logic


2. Pseudocode preferred by many programmers in planning program logic. It should be comprehensive enough to use as a guide as you write the COBOL code.
Example: Initialize variables Display summary lines Access the system date Close files Open input file Terminate program Read a record Do-while not end of file Display headings as needed move input fields to output fields display a detail line Increment counters Hold the screen as needed Read next record End-do COBOL21: A Complete COBOL Program

Preparing Program Logic


3. Flowcharts can be used for both planning and documentation. It shows the step-by-step logic flow within the program. START 100-MAIN-RTN 200-INITIAL-RTN 500-PROCESS-RTN 900-INITIAL-RTN STOP
COBOL21: A Complete COBOL Program

Until EOFSW = 1

IDENTIFICATION DIVISION
IDENTIFICATION DIVISION. PROGRAM-ID. Object program name. (max of 8 chars) [AUTHOR.] programmers name. [INSTALLATION.] clients name or company name. [DATE-WRITTEN.] installation date. [DATE-COMPILED.] [SECURITY.] name of person who have access to the output of the program.

4
COBOL21: A Complete COBOL Program

ENVIRONMENT DIVISION
ENVIRONMENT DIVISION. [CONFIGURATION SECTION.] used when a program must access special hardware-related items. [SOURCE-COMPUTER.]platform used in developing the program. [OBJECT-COMPUTER.]platform used in executing the program.

5
COBOL21: A Complete COBOL Program

ENVIRONMENT DIVISION
Division header section header paragraph header

ENVIRONMENT DIVISION. INPUT-OUTPUT SECTION. FILE-CONTROL.

Input file

SELECT file-name ASSIGN TO path ORGANIZATION IS LINE SEQUENTIAL. SELECT file-name ASSIGN TO path.
Output file COBOL21: A Complete COBOL Program

DATA DIVISION
DATA DIVISION. FILE SECTION.
Describes the content and organization of the files to be processed within the program. The only fields described are those found in the records of the input or output files.

WORKING-STORAGE SECTION.
Describes fields that are not part of the files, such as switches, accumulators, counters, work area fields, and output record layouts.

7
COBOL21: A Complete COBOL Program

DATA DIVISION
DATA DIVISION. FILE SECTION. FD file-name [RECORD CONTAINS integer CHARACTERS] [LABEL RECORD IS STANDARD] [ RECORDS ARE OMITTED ] [DATA RECORD IS data-name1 ] [ RECORDS ARE ] record-description-entry ... 8
COBOL21: A Complete COBOL Program

DATA DIVISION
FILE SECTION. FD --> File description is used for each file to be processed by the
program. The file name following FD must be the same userdefined name following the word SELECT in the FILECONTROL paragraph. RECORD CONTAINS --> can be used to document the the logical record length for the file being defined. LABEL RECORD --> required in COBOL74, used to specify the presence or absence of a header label on files. STANDARD --> used in the LABEL RECORD entry for disk files and tape files. OMITTED --> applies only to some tape files and to unit record input or output devices such as scanners, card readers, and printers. DATA RECORD --> used to specify the name of the records within the file, for documentation purposes only.
COBOL21: A Complete COBOL Program

DATA DIVISION
record-description-entry ...
Very important part of the program, it creates a temporary storage area, or buffer, for input and output records. Example.
01 INVENTORY-RECORD. 02 IR-STATUS PIC X. 88 AVAILABLE VALUE A. 88 OUT-OF-STOCK VALUE O. 02 IR-NUMBER PIC X(11). 02 IR-ITEM-NAME PIC X(20). 02 IR-QUANTITY-ON-HAND PIC 9(5). 02 IR-QUANTITY-ORDERED PIC 9(5). 02 IR-LAST-SHIPMENT. 03 IR-DATE-LAST-RECEIVED PIC 9(8). 03 IR-QUANTITY-LAST-RECEIVED PIC 9(5).

10
COBOL21: A Complete COBOL Program

DATA DIVISION
Level Number
Used to show how data items or fields are related to each other. It shows the hierarchy of data. It can range from 01 to 49 and special level number 77 and 88. Used to define switches, accumulators, and counters, and to define output record layouts for reports.

Level 01 (used in defining record-name)


used to specify an individual record or group of related fields.

Level 02-49 (used in defining field-name)


used to specify an individual record or group of related fields.

11
COBOL21: A Complete COBOL Program

DATA DIVISION
Two types of Item/Field
1. Group item These items can be divided into subordinate data items with other level numbers. It has no picture clause. Example: Employee-Name, Employee-Address 2. Elementary Item A field that is part of some larger field or record. A name that is not divided into subordinate data items and has a picture clause. Example: Last-Name, First-Name, MI, Street, City, Province

12
COBOL21: A Complete COBOL Program

DATA DIVISION
PICTURE or PIC Clause It specifies a detailed description of an elementary item. It indicates the number of characters in the data item and the type of data: letters only (alphabetic), PIC A; numbers only (numeric), PIC S9V99; or letters, numbers, and special characters (alphanumeric), PIC X.
Example: 02 EMPLOYEE-NAME. 03 LAST-NAME 03 FIRST-NAME 03 MI PIC X(15). PIC X(15). PIC X.

13
COBOL21: A Complete COBOL Program

DATA DIVISION
Five basic data categories
1. Alphabetic An item that may contain only letters of the alphabet or spaces. The character A is used to represent alphabetic items. 2. Alphanumeric An item that may contain letters, numbers, spaces, and special characters. The character X is used to represent alphanumeric items. 3. Numeric An item that may contain numbers 0 to 9. The character 9 is used to define numeric fields. An S at the beginning of the picture of a numeric field indicates the fields is a signed numeric field, either positive or negative. Without an S, a numeric field is unsigned and can never contain a negative value.
COBOL21: A Complete COBOL Program

14

DATA DIVISION
Five basic data categories
3. Numeric (continuation) Implied decimal position --> The use of a V in a numeric picture identifies the implied decimal position. No decimal point actually is stored in the field, but whenever numeric processing occurs, the field will be treated as though the decimal point is in the designated position. USAGE --> indicates how the numeric field is stored in memory or auxiliary storage. The default USAGE for a field is DISPLAY. It means that each character or digit in the field requires one byte of storage. Ex. 02 UNIT-COST PIC 9(5)V99. <-- default 02 UNIT-COST PIC 9(5)V99 DISPLAY.

15
COBOL21: A Complete COBOL Program

DATA DIVISION
Five basic data categories
3. Numeric (continuation) BINARY/COMP --> provides an efficient way for the computer to work with and manipulate numeric data. Ex. 02 UNIT-COST PIC 9(5)V99 BINARY. 02 UNIT-COST PIC 9(5)V99 COMPUTATIONAL. 02 UNIT-COST PIC 9(5)V99 COMP. PACKED-DECIMAL --> causes data to be stored in a format that is efficient for the computer's numeric operations. The data are stored as a base 10 number with two digits per byte. Ex. 02 UNIT-COST PIC 9(5)V99 PACKED-DECIMAL. 02 UNIT-COST PIC 9(5)V99 COMPUTATIONAL-3. 02 UNIT-COST PIC 9(5)V99 COMP-3.
COBOL21: A Complete COBOL Program

16

DATA DIVISION
Five basic data categories
3. Numeric (continuation) INDEX --> special fields reserved to store values used in conjunction with arrays and tables. Ex. 02 EMPLOYEE-IDX PIC 9(5) INDEX. 4. Alphanumeric edited Allows an alphanumeric field to be edited or formatted for output. It fills the destination item from left to right. The edit patterns are blank (B), zero (0), and slash (/) insertion characters. This can be used in both numeric and alphanumeric fields. Ex. 02 F PIC XBXBXBX/XXBXBXBX VALUE EAST ASIA. Output: E A S T/ A S I A

17
COBOL21: A Complete COBOL Program

DATA DIVISION
Five basic data categories
5. Numeric edited (Edit Patterns) Z --> Zero Suppression * --> Zero Suppression with asterisks (check protection symbol) P --> Scaling Symbol Accounting Applications CR --> Credit Symbol DB --> Debit Symbol

Insertion Characters $ --> Dollar Sign , --> Comma . --> Decimal Period

Signed Numeric Fields + --> Plus Sign - --> Minus Sign

18
COBOL21: A Complete COBOL Program

DATA DIVISION
DATA DIVISION. FILE SECTION. . . . WORKING-STORAGE SECTION.
Contains fields that are not part of any record layout, but are necessary to accomplish the task of the program. Switches --> are used in the decision-making logic of a program. Ex. 02 EOFSW PIC X VALUE Y. Accumulators or Counters--> are used in arithmetic and contains sums. Ex. 02 ACC-SALES-AMOUNT PIC 9(9)V99 VALUE ZEROES. 02 EMPLOYEE-CTR PIC 9(3) VALUE ZEROES.

19
COBOL21: A Complete COBOL Program

DATA DIVISION
Work Area fields --> are miscellaneous fields needed for processing but not falling under the other special categories used. Ex. 02 WS-SYSTEM-DATE. 03 WS-YY PIC 99. 03 WS-MM PIC 99. 03 WS-DD PIC 99. Output record layouts --> define the formats for the heading lines, detail lines, and summary lines. Ex. 01 REPORT-HEADING. 02 HEADING-LINE1. 03 F PIC X(18) VALUE SPACES. 03 F PIC X(62) VALUE EAST ASIA COLLEGE OF INFORMATION TECHNOLOGY. 02 HEADING-LINE2. 20 . . .
COBOL21: A Complete COBOL Program

DATA DIVISION
FILLER --> a reserved word used when a name is not given to a field. Only fields that will be referenced later in the program need user-defined names. A filler entry is not directly referenced anywhere in the program and, therefore, needs no name. Ex. 02 FILLER PIC X(09) VALUE EAST ASIA. SPACES/SPACE --> is a reserved word called a figurative constant. It is a nonnumeric literal filled with blanks, such as . Ex. 02 FILLER PIC X(05) VALUE SPACES. ZEROES/ZEROS --> is another figurative constant. It represents the numeric value 0. Ex. 02 CTR PIC 9(05) VALUE ZEROES.

21
COBOL21: A Complete COBOL Program

DATA DIVISION
ALL --> is another figurative constant used to fill a field with the character in the non-numeric literal. Ex. 02 FILLER PIC X(05) VALUE ALL -. or Ex. 02 FILLER PIC X(05) VALUE -----. HIGH-VALUES/HIGH-VALUE --> is another figurative constant that represents the greatest value in a computers collating sequence. It means that no other field will have a value greater than HIGH-VALUES. Ex. 02 CTR PIC 9(05) VALUE HIGH-VALUES. LOW-VALUES/LOW-VALUE --> is another figurative constant that represents the lowest value in a computers collating sequence. It means that no other fields will have a value less than LOW-VALUES. Ex. 02 CTR PIC 9(05) VALUE LOW-VALUES.

22
COBOL21: A Complete COBOL Program

You might also like