Any Questions!
Agenda Fun with Functions –how to get the system date Condition Names INDARA and SI Iteration Logical Files Positioning the file pointer
IBM Library COBOL reference links IBM Boulder, Colorado library COBOL Programmers Manual
Fun with Functions Refer to COBOL Intrinsic functions handout Move FUNCTION CURRENT DATE (1:8) to …
Condition Names Used with Code Fields –Eg. ARE-THERE-MORE-RECORDS –Eg. FINAL-GRADE –Eg. Indicators
Condition Names 01 ARE-THERE-MORE-RECORDS PIC X(3) VALUE ‘YES’. 88 THERE-ARE-MORE-RECORDS VALUE ‘YES’. 88 END-OF-FILEVALUE ‘NO’. IF THERE-ARE-MORE-RECORDS READ EMPLOYEE-FILE. IF END-OF-FILE PERFORM TERMINATION-RTN.
Set Verb Used to initialize fields to a Condition- Name. 01 ARE-THERE-MORE-RECORDS PIC X(3). 88 THERE-ARE-MORE-RECORDS VALUE ‘YES’. 88 END-OF-FILEVALUE ‘NO’. SET END-OF-FILE TO TRUE.
Conditions Cont’d 01 WORK-DAYS PIC X(3). 88 MONDAY VALUE ‘MON’. 88 TUESDAY VALUE ‘TUE’. 88 WEDNESDAY VALUE ‘WED’. 88 THURSDAY VALUE ‘THU’ 88 FRIDAY VALUE ‘FRI’. SET MONDAY TO TRUE. IF FRIDAY DISPLAY ‘GO HOME EARLY’.
Conditions Cont’d 01 FALL-MONTHS PIC X(3). 88 SEPTEMBER VALUE ‘SEP’. 88 OCTOBER VALUE ‘OCT’. 88 NOVEMBERVALUE ‘NOV’. 88 DECEMBER VALUE ‘DEC’. IF OCTOBER DISPLAY ‘HAPPY HALLOWEEN!!’ SET DECEMBER TO TRUE.
INDARA and SI The relation ship between the externally declared (DDS) interactive screen file and the COBOL internally declared indicator usage area
As externally defined and created in DDS A DSPSIZ(24 80 *DS3) A INDARA In file area (GLOBAL) A CA03(03 'Function Key 03 = A CA12(12 'Function Key 12 = A R SCREEN A 1 9'ENTER' in RECORD area (LOCAL) A 1 26'PAYROLL DEPARTMENT' A 1 59'C1401.1' A 3 2'Type choice, press Enter.' A 5 4'Employee number..' A EEMPNO 5D 0I 5 24ALIAS(SCR1_EMPLOYEE_NUMBER) A 99 ERRMSG('Employee number not A Re-enter valid number.' A 23 2'F3=Exit'
SI special indicators - send to the screen for screen behavior / action Control-area - keyed response received form the “screen” FILE-CONTROL SELECT DISPLAY-FILE ASSIGN TO WORKSTATION-HM100DSP-SI ORGANIZATION IS TRANSACTION CONTROL-AREA IS WS-CONTROL DATA DIVISION FILE SECTION *File Definition for a Program Described File FD DISPLAY-FILE DISPLAY-RECORD COPY DD-ALL-FORMATS OF HM100DSP WORKING-STORAGE SECTION.
indicators RESPONSE and RESULTING WS-CONTROL WS-FUNCTION-KEY PIC X(2) WS-FUNCTION-KEY-03 VALUE '03' NO-FUNCTION-KEY-WAS-PRESSED VALUE '00' WS-DEVICE-NAME PIC X(10) WS-RECORD-FORMAT PIC X(10) WS-INDICATOR-LIST IN99 INDICATOR 99 PIC 1 VALUE B'0' INCORRECT-ACTION-CODE VALUE B'1' CORRECT-ACTION-CODE VALUE B'0' IN98 INDICATOR 98 PIC 1 VALUE B'0' INVALID-HORSE VALUE B'1' VALID-HORSE VALUE B'0' IN97 INDICATOR 97 PIC 1 VALUE B'0' REPORT-PRINTED VALUE B'1' REPORT-NOT-PRINTED VALUE B'0'.
Program check and response logic EVALUATE TRUE screen variable WHEN SCR1-ACTION-CODE OF PROMPT-I = 'P' PERFORM 210-print-rtn WHEN OTHER SET INCORRECT-ACTION-CODE TO TRUE END-EVALUATE if not ws-function-key move save-action to scr1-action-code of prompt-o move save-horse to scr1-horse-code of prompt-o * Write the prompt screen to the screen WRITE DISPLAY-RECORD FORMAT IS 'PROMPT ' INDICATORS ARE WS-INDICATOR-LIST end-write * Wait for input READ DISPLAY FILE RECORD
Option Indicators and Conditions 01 WS-indicators. 05 IN90 INDICATOR 90 PIC display-message value B’1’. 88 dont-display-message value B’0’. Set display-message to true. Set dont-display-message to true. If display-message If don’t-display-message If not display-message
Response Indicators and Conditions 01 WS-Control. 05 ws-function-key pic x(2). 88 F3 value ’03’ 88 F12 value ’12’. 88 Enter value ’00’ 05 ws-device-name pic x(10). 05 ws-record-format pic x(10). If F3 If not F3
Iteration Looping
BASIC Perform Statement PERFORM (paragraph-name)
Basic PERFORM READ Emp-File PERFORM DSP-Rtn STOP RUN DSP-RTN move emp-in to emp- out. write dsp-record format is ‘SCREEN’. read dsp-file record.
PERFORM Until PERFORM paragraph-name UNTIL Condition
PERFORM Until Condition Met? Execute Program Statements NO YES
PERFORM Until READ Emp-File AT END Move ‘YES’ TO EOF. PERFORM Dsp-Rtn UNTIL EOF = ‘Y’ STOP RUN DSP-RTN move emp-in to emp-out. write dsp-record format is ‘SCREEN’. read dsp-file RECORD. read emp-file at end move ‘YES’ to EOF.
PERFORM X Times PERFORM (paragraph-name) THROUGH/THRU (paragraph-name) (integer/variable) TIMES
PERFORM X Times Number of Times Met? Execute Program Statements NO YES
PERFORM X Times READ Emp-File AT END Move ‘YES’ TO EOF. PERFORM Dsp-Rtn 5 TIMES STOP RUN DSP-RTN move emp-in to emp- out. write dsp-record format is ‘SCREEN’. read dsp-file record.
PERFORM With Test After PERFORM (paragraph-name) THROUGH/THRU (paragraph-name) WITH TEST AFTER UNTIL Condition
PERFORM With Test After Condition Met? Execute Program Statements NO YES
PERFORM With Test After READ Emp-File AT END Move ‘YES’ TO EOF. PERFORM Dsp-Rtn WITH TEST AFTER UNTIL EOF = ‘Y’ STOP RUN DSP-RTN move emp-in to emp-out. write dsp-record format is ‘SCREEN’. read dsp-file record. read emp-file AT END MOVE ‘YES’ TO EOF.
PERFORMs within PERFORMs READ Emp-File AT END Move ‘YES’ TO EOF. PERFORM DSP-Rtn UNTIL 5 TIMES STOP RUN DSP-RTN MOVE EMP-IN TO EMP-OUT. PERFORM Write-Rtn
Iteration Statement to Use? Perform Until –Tests for the condition first –Statements are executed only if the condition is true Perform With Test After –tests for the condition last –Statements are always executed at least once
Iteration Statement to Use? Perform X Times –Use this when you know the number of times the paragraph(s) are to be executed.
Sorting Data Using Access Paths
Physical Files vs Logical Files EMPLOYEEPF *FILE EMPLOYEE *FILE Physical Files or Logical Files?
Externally Described Files Select Statement when physical/logical file has a key. SELECT Cobol-file-name ASSIGN TO database-actual-file-name [ORGANIZATION IS INDEXED] [ACCESS MODE IS SEQUENTIAL] RECORD KEY is data-element. (data-element could be EXTERNaLLY-DESCRIBED-KEY)
Externally Described Files Copying the record layout. FD Cobol-file-name. 01 Cobol-Record-Name. COPY DD-actualrecordname OF actualfilename. (DD can be replaced by DDS if you require the 10 char field names instead of the aliases)
Handy Physical File Commands DSPPFM – Display Physical File Member Displays the contents of a Physical File in arrival sequence. DSPFD – Display File Description Information about the file – eg access path. DSPFFD – Display File Field Description Displays the fields in the file.
Positioning the File Pointer Start Verb
Used only with Sequentially defined files. Initialize the record key START file-name Key Condition INVALID KEY Perform Invalid-Logic NOT INVALID KEY Perform valid-logic END-START.