any questions!. agenda fun with functions externally described files condition names iteration...

34
Any Questions!

Upload: horace-nicholson

Post on 18-Jan-2018

222 views

Category:

Documents


0 download

DESCRIPTION

Fun with Functions ILEFUNCT

TRANSCRIPT

Page 1: Any Questions!. Agenda Fun with Functions Externally Described Files Condition Names Iteration Logical Files Random Reads

Any Questions!

Page 2: Any Questions!. Agenda Fun with Functions Externally Described Files Condition Names Iteration Logical Files Random Reads

Agenda

• Fun with Functions • Externally Described Files• Condition Names• Iteration• Logical Files• Random Reads

Page 3: Any Questions!. Agenda Fun with Functions Externally Described Files Condition Names Iteration Logical Files Random Reads

Fun with Functions

ILEFUNCT

Page 4: Any Questions!. Agenda Fun with Functions Externally Described Files Condition Names Iteration Logical Files Random Reads

Condition Names

• Used with Code Fields– Eg. ARE-THERE-MORE-RECORDS– Eg. FINAL-GRADE– Eg. Indicators

Page 5: Any Questions!. Agenda Fun with Functions Externally Described Files Condition Names Iteration Logical Files Random Reads

Condition Names01 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.

Page 6: Any Questions!. Agenda Fun with Functions Externally Described Files Condition Names Iteration Logical Files Random Reads

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.

Page 7: Any Questions!. Agenda Fun with Functions Externally Described Files Condition Names Iteration Logical Files Random Reads

Conditions Cont’d01 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’.

Page 8: Any Questions!. Agenda Fun with Functions Externally Described Files Condition Names Iteration Logical Files Random Reads

Conditions Cont’d01 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.

Page 9: Any Questions!. Agenda Fun with Functions Externally Described Files Condition Names Iteration Logical Files Random Reads

Option Indicators and Conditions01 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

Page 10: Any Questions!. Agenda Fun with Functions Externally Described Files Condition Names Iteration Logical Files Random Reads

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

Page 11: Any Questions!. Agenda Fun with Functions Externally Described Files Condition Names Iteration Logical Files Random Reads

Iteration

Looping

Page 12: Any Questions!. Agenda Fun with Functions Externally Described Files Condition Names Iteration Logical Files Random Reads

BASIC Perform Statement

PERFORM (paragraph-name)

Page 13: Any Questions!. Agenda Fun with Functions Externally Described Files Condition Names Iteration Logical Files Random Reads

Basic PERFORM

READ Emp-FilePERFORM DSP-RtnSTOP RUN

DSP-RTNmove emp-in to emp-out.

write dsp-record format is ‘SCREEN’. read dsp-file record.

Page 14: Any Questions!. Agenda Fun with Functions Externally Described Files Condition Names Iteration Logical Files Random Reads

PERFORM Until

PERFORM paragraph-nameUNTIL Condition

Page 15: Any Questions!. Agenda Fun with Functions Externally Described Files Condition Names Iteration Logical Files Random Reads

PERFORM Until

ConditionMet?

Execute Program

Statements

NO

YES

Page 16: Any Questions!. Agenda Fun with Functions Externally Described Files Condition Names Iteration Logical Files Random Reads

PERFORM Until

READ Emp-File AT END Move ‘YES’ TO EOF.

PERFORM Dsp-Rtn UNTIL EOF = ‘Y’

STOP RUN

DSP-RTNmove emp-in to emp-out.write dsp-record

format is ‘SCREEN’. read dsp-file RECORD. read emp-file

at endmove ‘YES’ to EOF.

Page 17: Any Questions!. Agenda Fun with Functions Externally Described Files Condition Names Iteration Logical Files Random Reads

PERFORM X Times

PERFORM (paragraph-name) THROUGH/THRU (paragraph-name)(integer/variable) TIMES

Page 18: Any Questions!. Agenda Fun with Functions Externally Described Files Condition Names Iteration Logical Files Random Reads

PERFORM X Times

Number ofTimes Met?

Execute Program

Statements

NO

YES

Page 19: Any Questions!. Agenda Fun with Functions Externally Described Files Condition Names Iteration Logical Files Random Reads

PERFORM X Times

READ Emp-File AT END Move ‘YES’ TO EOF.

PERFORM Dsp-Rtn 5 TIMES

STOP RUN

DSP-RTNmove emp-in to emp-out.write dsp-record

format is ‘SCREEN’.

read dsp-file record.

Page 20: Any Questions!. Agenda Fun with Functions Externally Described Files Condition Names Iteration Logical Files Random Reads

PERFORM With Test After

PERFORM (paragraph-name) THROUGH/THRU (paragraph-name)WITH TEST AFTERUNTIL Condition

Page 21: Any Questions!. Agenda Fun with Functions Externally Described Files Condition Names Iteration Logical Files Random Reads

PERFORM With Test After

Condition Met?

Execute Program

Statements

NO

YES

Page 22: Any Questions!. Agenda Fun with Functions Externally Described Files Condition Names Iteration Logical Files Random Reads

PERFORM With Test After

READ Emp-File AT END Move ‘YES’ TO EOF.

PERFORM Dsp-Rtn WITH TEST AFTERUNTIL EOF = ‘Y’

STOP RUN

DSP-RTNmove emp-in to emp-out.

write dsp-record format is ‘SCREEN’. read dsp-file record. read emp-file

AT ENDMOVE ‘YES’ TO

EOF.

Page 23: Any Questions!. Agenda Fun with Functions Externally Described Files Condition Names Iteration Logical Files Random Reads

PERFORMs within PERFORMs

READ Emp-File AT END Move ‘YES’ TO EOF.

PERFORM DSP-Rtn UNTIL 5 TIMES

STOP RUN

DSP-RTNMOVE EMP-IN TO EMP-OUT.PERFORM Write-Rtn

Page 24: Any Questions!. Agenda Fun with Functions Externally Described Files Condition Names Iteration Logical Files Random Reads

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

Page 25: Any Questions!. Agenda Fun with Functions Externally Described Files Condition Names Iteration Logical Files Random Reads

Iteration Statement to Use?

• Perform X Times– Use this when you know the number of times

the paragraph(s) are to be executed.

Page 26: Any Questions!. Agenda Fun with Functions Externally Described Files Condition Names Iteration Logical Files Random Reads

Sorting Data

Using Access Paths

Page 27: Any Questions!. Agenda Fun with Functions Externally Described Files Condition Names Iteration Logical Files Random Reads

Physical Files vs Logical Files

EMPLOYEEPF *FILE

EMPLOYEE *FILE

Physical Files or Logical Files?

Page 28: Any Questions!. Agenda Fun with Functions Externally Described Files Condition Names Iteration Logical Files Random Reads

Externally Described Files

• Select Statement when physical/logical file has a key.

SELECT Cobol-file-nameASSIGN TO database-actual-file-name[ORGANIZATION IS INDEXED][ACCESS MODE IS SEQUENTIAL] RECORD KEY is data-element.(data-element could be EXTERNaLLY-DESCRIBED-KEY)

Page 29: Any Questions!. Agenda Fun with Functions Externally Described Files Condition Names Iteration Logical Files Random Reads

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)

Page 30: Any Questions!. Agenda Fun with Functions Externally Described Files Condition Names Iteration Logical Files Random Reads

Handy Physical File Commands

DSPPFM – Display Physical File MemberDisplays the contents of a Physical File in arrival sequence.

DSPFD – Display File DescriptionInformation about the file – eg access path.

DSPFFD – Display File Field DescriptionDisplays the fields in the file.

Page 31: Any Questions!. Agenda Fun with Functions Externally Described Files Condition Names Iteration Logical Files Random Reads

Random Reads

• Used to retrieve a record based on the value of a key field

• Need an access path sorted by the key field needed

• Select statement changes

Page 32: Any Questions!. Agenda Fun with Functions Externally Described Files Condition Names Iteration Logical Files Random Reads

Defining a Random Access File

SELECT Employee-FileASSIGN to DATABASE-EMPPFORGANIZATION is INDEXEDACCESS MODE is RANDOMRECORD KEY is

EXTERNALLY-DESCRIBED-KEY(with duplicates).

Page 33: Any Questions!. Agenda Fun with Functions Externally Described Files Condition Names Iteration Logical Files Random Reads

Random Reads• If the key field to EMPPF is the Employee-

Number then:Move 1 to Employee-Number.Read Employee-File

Invalid KeyMove ‘Error’ to Employee-Name-Out

Not invalid key Move Employee-Name to Employee-Name-

outEnd-Read.

Page 34: Any Questions!. Agenda Fun with Functions Externally Described Files Condition Names Iteration Logical Files Random Reads

Validating the Province Code

Database object: PROVINCES