Any Questions!. Agenda Fun with Functions –how to get the system date Condition Names INDARA and...
-
Upload
spencer-ferguson -
Category
Documents
-
view
215 -
download
0
Transcript of Any Questions!. Agenda Fun with Functions –how to get the system date Condition Names INDARA and...
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 LibraryCOBOL
reference linksIBM Boulder, Colorado library
http://publib.boulder.ibm.com/infocenter/iseries/v5r4/index.jsp
COBOL Programmers Manual
http://publib.boulder.ibm.com/iseries/v5r2/ic2924/books/c0925393.pdf
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-FILE VALUE ‘NO’.
IF THERE-ARE-MORE-RECORDSREAD EMPLOYEE-FILE.
IF END-OF-FILEPERFORM 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-FILE VALUE ‘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 NOVEMBER VALUE ‘NOV’.88 DECEMBER VALUE ‘DEC’.
IF OCTOBERDISPLAY ‘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
0000.30 A DSPSIZ(24 80 *DS3)
0000.40 A INDARA In file area (GLOBAL)
0000.50 A CA03(03 'Function Key 03 =
0000.60 A CA12(12 'Function Key 12 =
0000.70 A R SCREEN1
0000.80 A 1 9'ENTER' in RECORD area (LOCAL)
0000.90 A 1 26'PAYROLL DEPARTMENT'
0001.00 A 1 59'C1401.1'
0001.10 A 3 2'Type choice, press Enter.'
0001.20 A 5 4'Employee number . .'
0001.30 A EEMPNO 5D 0I 5 24ALIAS(SCR1_EMPLOYEE_NUMBER)
0001.40 A 99 ERRMSG('Employee number not
0001.50 A Re-enter valid number.' 99
0001.60 A 23 2'F3=Exit'
SI special indicators - send to the screen for screen behavior / actionControl-area - keyed response received form the “screen”
0018.00 FILE-CONTROL.
0019.00 SELECT DISPLAY-FILE
0020.00 ASSIGN TO WORKSTATION-HM100DSP-SI
0021.00 ORGANIZATION IS TRANSACTION
0022.00 CONTROL-AREA IS WS-CONTROL.
0030.00 DATA DIVISION.
0032.00 FILE SECTION.
0033.00
0034.00 *File Definition for a Program Described File
0036.00 FD DISPLAY-FILE.
0038.00 01 DISPLAY-RECORD.
0039.00 COPY DD-ALL-FORMATS OF HM100DSP.
0045.00
0046.00 WORKING-STORAGE SECTION.
indicatorsRESPONSE and RESULTING
0078.00 01 WS-CONTROL.
0079.00 05 WS-FUNCTION-KEY PIC X(2).
0080.00 88 WS-FUNCTION-KEY-03 VALUE '03'.
0083.00 88 NO-FUNCTION-KEY-WAS-PRESSED VALUE '00'.
0084.00 05 WS-DEVICE-NAME PIC X(10).
0085.00 05 WS-RECORD-FORMAT PIC X(10).
0087.00 01 WS-INDICATOR-LIST.
0088.00 05 IN99 INDICATOR 99 PIC 1 VALUE B'0'.
0089.00 88 INCORRECT-ACTION-CODE VALUE B'1'.
0090.00 88 CORRECT-ACTION-CODE VALUE B'0'.
0091.00 05 IN98 INDICATOR 98 PIC 1 VALUE B'0'.
0092.00 88 INVALID-HORSE VALUE B'1'.
0093.00 88 VALID-HORSE VALUE B'0'.
0094.00 05 IN97 INDICATOR 97 PIC 1 VALUE B'0'.
0095.00 88 REPORT-PRINTED VALUE B'1'.
0096.00 88 REPORT-NOT-PRINTED VALUE B'0'.
•
Program check and response logic
0216.00 EVALUATE TRUE screen variable
0217.00 WHEN SCR1-ACTION-CODE OF PROMPT-I = 'P'
0218.00 PERFORM 210-print-rtn
0224.00 WHEN OTHER
0225.00 SET INCORRECT-ACTION-CODE TO TRUE
0227.00 END-EVALUATE.
0249.01
0249.02 if not ws-function-key-03
0249.03 move save-action to scr1-action-code of prompt-o
0249.04 move save-horse to scr1-horse-code of prompt-o
0249.05 * Write the prompt screen to the screen
0249.06 WRITE DISPLAY-RECORD
0249.07 FORMAT IS 'PROMPT '
0249.08 INDICATORS ARE WS-INDICATOR-LIST
0249.09 end-write
0249.11 * Wait for input
0249.12 READ DISPLAY FILE RECORD
Option Indicators and Conditions
01 WS-indicators. 05 IN90 INDICATOR 90 PIC 1.
88 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-messageIf don’t-display-messageIf 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 F3If 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
ConditionMet?
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 ofTimes 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
Start Verb
Used only with Sequentially defined files.
Initialize the record key
START file-nameKey ConditionINVALID KEY
Perform Invalid-LogicNOT INVALID KEY
Perform valid-logicEND-START.