prashant_cobol 400

44
Objective: To provide information that an application programmer needs to write, compile, debug and run COBOL/400 programs on IBM Application System/400 (AS/400) system.

Upload: saiprasad

Post on 11-Jan-2016

217 views

Category:

Documents


0 download

DESCRIPTION

hello

TRANSCRIPT

Page 1: Prashant_COBOL 400

Objective: To provide information that an application programmer needs to write, compile, debug and run COBOL/400 programs on IBM Application System/400 (AS/400) system.

Page 2: Prashant_COBOL 400

Features available with COBOL/400

TRANSACTION I/O: you can send or receive records from a work station.

COPY: You can use externally described files.

DATABASE I/O: You can use standard COBOL Environment and Data Division entries to specify file identification, field definitions and data structures. Clauses have been added to the READ, WRITE, REWRITE, DELETE and START verbs to support the AS/400 database.

LIKE clause: you can define the characteristics of a data name by copying them from a previously-defined data name.

Page 3: Prashant_COBOL 400

Steps or phases to build your COBOL/400 program

Entering your COBOL Program (SEU) provides a special display to help you enter an accurate COBOL

source program into the system. The SEU also provides a COBOL syntax checker that checks each line for errors as you enter or change them.

Compiling Your COBOL Program Create COBOL Program using CRTCBLPGM command Using the PROCESS Statement to Specify Compiler Options Understanding the compiler listing output and resolving the errors

Debugging Your COBOL Program Using Start interactive source debugger (STRISDB) OR Start Debug

(STRDBG) command and setting up breakpoints

Running Your COBOL Program Using a Control Language (CL) CALL command Using the COBOL CALL statement Using a menu-driven application program Calling from the Command Line

Page 4: Prashant_COBOL 400

Structure of a COBOL/400 Program

IDENTIFICATION DIVISION. PROGRAM-ID. XYZ. AUTHOR. ABC. DATE-WRITTEN. 24 September, 2008. DATE-COMPILED. 25 September, 2008.

ENVIRONMENT DIVISION. CONFIGURATION SECTION. SOURCE-COMPUTER. IBM-AS400. OBJECT-COMPUTER. IBM-AS400. SPECIAL-NAMES.

LOCAL DATA IS LDA-AREA. Contd….

Page 5: Prashant_COBOL 400

Structure of a COBOL/400 Program

INPUT-OUTPUT SECTION.FILE-CONTROL.

SELECT FILE-NAME ASSIGN TO DATABASE-DB-FILE NAME ORGANIZATION IS INDEXED ACCESS IS DYNAMIC RECORD KEY IS EXTERNALLY-DESCRIBED-

KEY FILE STATUS IS FILE-STATUS.

Page 6: Prashant_COBOL 400

Assign The following device files can be used with the

Assign Clause:

DATABASE – For Physical and Logical files WORKSTATION – For Display file

Page 7: Prashant_COBOL 400

System Indicator - SI SELECT DISPFILE

ASSIGN TO WORKSTATION-DSPFIL-SI

INDARA – This file level keyword is specified in the Display File to assign a separate Indicator Area. If specified, the Input and the Output Buffer of

the indicator is handled by the system. There’s no

need to clear the buffer before using the Indicator

value.

Page 8: Prashant_COBOL 400

Organization Type of logical structure (organization) of the file: SEQUENTIAL – the records are accessed sequentially,

the order in which they are entered.

INDEXED – the position of each logical record in the file is determined by the key sequence access path

created with the file and maintained by system.

RELATIVE - the position of each record in the file is determined by its relative record number within the arrival sequence path.

TRANSACTION – signifies interaction between a COBOL program and a workstation user.

Page 9: Prashant_COBOL 400

Access Mode Following are the types of Access Modes: Sequential – Allows reading and writing of a file in a

serial manner - can be specified for sequential, indexed or relative Files.

Random – Allows reading and writing records in a programmer-specified manner

Dynamic – Records may be processed sequentially or randomly

Page 10: Prashant_COBOL 400

Advantages and Disadvantages Sequential Files

Advantages:Simple organization, Recovers space from deleted records.

Disadvantages: Slow, Complicated to change (insert, delete,

amend)

Page 11: Prashant_COBOL 400

Advantages and Disadvantages Contd…. Relative Files

Advantages:Fastest Direct Access organization, Very

little storage overhead. Disadvantages: Can not recover space from deleted records,

Only a single numeric key allowed.

Page 12: Prashant_COBOL 400

Advantages and Disadvantages Contd…. Indexed Files

Advantages: Can use multiple, alphanumeric keys, Can

be read sequentially on any of its keys. Disadvantages: Slow when adding or deleting records.

Page 13: Prashant_COBOL 400

Key Record Key – The file key is specified. Relative Key – The RELATIVE KEY clause specifies the relative record

number for a specific record in a subfile. The field specified as the relative key needs to declared in the Working Storage Section.

RELATIVE KEY IS WB-RRN………WORKING-STORAGE-SECTION.

01 WB-RRN PIC 9(5) Value 0

Page 14: Prashant_COBOL 400

File Status Clause This clause is used to monitor the processing of each I/O

request for the file. When specified system moves a value (which indicates

the status of execution of the statement) into the data item after each input output

that implicitly orexplicitly refers to the file.

Used to monitor for errors and exceptional conditions.

FILE STATUS IS WB-FILE-STATUS………WORKING-STORAGE-SECTION.

01 WB-FILE-STATUS PIC X(2).

Page 15: Prashant_COBOL 400

File Status Examples 00 – Successful Completion 22 – Duplicate Key 23 – Record Not Found 9D – Record is Locked

Page 16: Prashant_COBOL 400

Structure of a COBOL/400 Program Contd….DATA DIVISION. FILE SECTION.

FD DB-FILE LABEL RECORDS ARE STANDARD.

01 DB-REC. COPY DDS-ALL-FORMATS OF DB FILE NAME.

WORKING-STORAGE SECTION. 01 FLD-REC. 05 FLD1 PIC S9(005) VALUE 0. 05 FLD2 PIC X(005) VALUE “Y”.

LINKAGE SECTION.

01 LINKAGE-AREA.

05 LS-PARM1 PIC X(002). 05 LA-PARM2 PIC X(002).

Page 17: Prashant_COBOL 400

Label RecordsFollowing are the types of Label Records: Standard Omitted – Used for Display Files

Standard – If specified, the AS/400 system would consider the first record as a Label Record and the file would be hence read from the second record.

Omitted – If specified, the AS/400 system would not consider the first record as a Label Record.

Page 18: Prashant_COBOL 400

Working Storage Section Level 66 - Identifies items that must contain a RENAMES clause Level 77 - Identifies data item description entries — independent Working- Storage or Linkage Section items that are not subdivisions of other items, and are not subdivided themselves. Level 88 - Identifies any condition-name entry that

is associated with a particular value of a conditional variable.

Page 19: Prashant_COBOL 400

Declaring IndicatorsWORKING-STORAGE SECTION.

01 INDIC-AREA. 05 INDIC-TABLE OCCURS 99 PIC 1 INDICATOR 1. 88 IND-OFF VALUE B"0". 88 IND-ON VALUE B"1".

01 WS-INDICATORS. 05 IND-HELP PIC 9(02) VALUE 01. 05 IND-KEY2 PIC 9(02) VALUE 02. 05 IND-EXIT PIC 9(02) VALUE 03. 05 IND-CANCEL PIC 9(02) VALUE 12. 05 IND-SFLNXTCHG PIC 9(02) VALUE 30. 05 IND-SFLDSP PIC 9(02) VALUE 31. 05 IND-SFLDSPCTL PIC 9(02) VALUE 32. 05 IND-SFLCLEAR PIC 9(02) VALUE 33. 05 IND-SFLEND PIC 9(02) VALUE 34.

Page 20: Prashant_COBOL 400

Screen CF12(12 'Cancel / Previous

Screen') CF03(03 'Exit Screen') R IUW0034S05N32 SFLDSPN31 SFLDSPCTL 31 SFLCLR 90 SFLEND(*MORE)

Page 21: Prashant_COBOL 400

Redefines Clause Redefines - The REDEFINES clause allows you to use

different data description entries to describe the same computer storage area.

For example:05 A PIC X(6).05 B REDEFINES A. 10 B-1 PIC X(2). 10 B-2 PIC 9(4).05 C PIC 99V99.

Page 22: Prashant_COBOL 400

Rename ClauseRename – The RENAME clause allows alternative grouping of Data Items.

For Example:01 RECORD-1.

05 FLD-1 PIC X(10). 05 FLD-2 PIC X(05).

05 FLD-3 PIC X(05).

66 FLD-4 RENAMES FLD-1 THROUGH FLD2

Page 23: Prashant_COBOL 400

Linkage Section This section is used to specify the linkage parameters.

LINKAGE SECTION.

01 LINKAGE-AREA.

05 LS-PARM1 PIC X(002). 05 LA-PARM2 PIC X(002).

Calling Program – CALL “PGM1” USING WS-PARM1 WS-PARM2

Called Program – It will contain the Linkage section and the Procedure Division would be written as:

PROCEDURE DIVISION USING LINKAGE-AREA.

Page 24: Prashant_COBOL 400

Structure of a COBOL/400 Program Contd….

PROCEDURE DIVISION USING LINKAGE-AREA.0000-MAIN-PARA. PERFORM 0100-INITIALIZE-PROGRAM THRU 0100-EXIT.

0100-INITIALIZE-PROGRAM.

ACCEPT LOCAL-DATA-AREA FROM LDA-AREA.

OPEN INPUT FILE1 I-O FILE2 .

0100-EXIT. EXIT.

Page 25: Prashant_COBOL 400

Controls Next Sentence – Specified to Transfer Control to the

next executable line. Continue – Specified to indicate that no executable

instruction is present. Go Back – Specified to Transfer Control from the Called

Program to the Calling Program.

Stop Run – Specified to terminate the execution of a Program.

The execution of the run-unit is terminated.

Page 26: Prashant_COBOL 400

Controls Contd….. Exit program – The EXIT PROGRAM statement specifies the end of a called program and returns control to the calling program.

Go To - The GO TO statement transfers control from one part of the Procedure Division to another

Page 27: Prashant_COBOL 400

Controls Contd….. Perform - The PERFORM statement transfers control explicitly to one or more procedures and implicitly returns control to the next executable statement after execution of the specified procedure(s) or imperative statements is completed.

Page 28: Prashant_COBOL 400

Types of PERFORM An out-of-line PERFORM statement:

PERFORM 1000-OPEN-PARA.

1000-OPEN-PARA. *=============== OPEN I-O ACCOUNTS

DISPFILE OUTPUT REPORTFILE.

An in-line PERFORM statement:PERFORM

MOVE “A” TO FLD-AMOVE “B” TO FLD-B

END-PERFORM

Page 29: Prashant_COBOL 400

PERFORM Statement Formats There are four PERFORM statement formats:

Basic PERFORM

PERFORM 1000-OPEN-PARA.

TIMES phrase PERFORM PERFORM 1000-OPEN-PARA 5 TIMES.

UNTIL phrase PERFORM PERFORM 1000-OPEN-PARA UNTIL WS-EOF NOT = “Y”

VARYING phrase PERFORM

PERFORM 1000-OPEN-PARA VARYING WS-I FROM 1 BY 1 UNTIL WS-EOF = “Y”

Page 30: Prashant_COBOL 400

Handling Indicators Change the Value of an Indicator:

MOVE B"0" TO INDIC-TABLE(IND-SFLEND)

Check the Value of an Indicator:

IF IND-ON(IND-EXIT) MOVE 99 TO WS-RECNOEND-IF.

Page 31: Prashant_COBOL 400

Procedure Division Keywords String – STRING WS-RESERVE-TYPE(1) ")" DELIMITED BY SPACES INTO WS-RESERVE-TYP-C(1)

END-STRING

Unstring – UNSTRING WS-SUB-GRP(WS-F) DELIMITED BY ',' INTO WS-VALID-RESV-CODES(WS-F, 1) WS-VALID-RESV-CODES(WS-F, 2) END-UNSTRING Add Compute Move

Page 32: Prashant_COBOL 400

EvaluateEvaluate

EVALUATE WS-IND1 WHEN "01" ADD 1 TO WS-RESV1-CNT ADD WS-CRS-RES-AMT(WS-H) TO WS-RESV1-TOTAL-AMT WHEN "02" ADD 1 TO WS-RESV2-CNT ADD WS-CRS-RES-AMT(WS-H) TO WS-RESV2-TOTAL-AMT END-EVALUATE

Page 33: Prashant_COBOL 400

File Handling in Cobol Open a File:

Start a File: Move values to the key START CLAIMRES KEY NOT < CRS-KEY

INVALID KEY MOVE "Y" TO WS-EOF-CLAIMRES END-START.

Read a FileMove values to the keyREAD CLAIMRES NEXT

AT END MOVE "Y" TO WS-EOF-CLAIMRES NOT AT END MOVE "N" TO WS-EOF-CLAIMRES END-READ.

Page 34: Prashant_COBOL 400

File Handling Contd… Write a Record in the File

Move Values to the fieldsWRITE ITMCLRS06P-REC.

Re-write a Record in the FileMove Values to the fieldsRE-WRITE ITMCLRS06P-REC.

Delete a File Move Values to the fields DELETE FILE-NAME

Page 35: Prashant_COBOL 400

Reports INPUT-OUTPUT SECTION. FILE-CONTROL. SELECT PRINTFILE ASSIGN TO PRINTER-QPRINTS.

DATA DIVISION. FILE SECTION.

FD PRINTFILE LABEL RECORDS ARE OMITTED LINAGE IS 66 LINES LINES AT TOP 1. 01 PRINT-REC PIC X(198).

Page 36: Prashant_COBOL 400

Reports Contd…..WORKING-STORAGE SECTION.

01 RPT-MAIN-HEADING-01. 05 FILLER PIC X(03) VALUE SPACES. 05 RPT-HDG PIC X(13) VALUE SPACES. 05 FILLER PIC X(182) VALUE SPACES.

PROCEDURE DIVISION.

MOVE "Overall Total" TO RPT-HDGWRITE PRINT-REC FROM RPT-MAIN-HEADING-03.

Page 37: Prashant_COBOL 400

Reports Contd…..To Write in the Next Page:

IF LINAGE-COUNTER OF PRINTFILE > 62 ADD 1 TO WS-PAGE-NO

MOVE "Overall Total" TO RPT-HDG WRITE PRINT-REC FROM RPT-MAIN-HEADING-01 AFTER

PAGEEND-IF

Page 38: Prashant_COBOL 400

Subfiles – Screen DesignR IUW0034S04 SFL

30 SFLNXTCHG DFSELOPT 1A B 6 DFCODE 2A O 6 7 DFDESC 40A O 6 20 R IUW0034S05 SFLCTL(IUW0034S04) SFLSIZ(0100) SFLPAG(0010) 31 SFLDSP 32 SFLDSPCTL 33 SFLCLR 34 SFLEND

Page 39: Prashant_COBOL 400

Steps For Handling Subfiles Initialize the Function Keys Clear The Subfile Load the Subfile Display the Subfile

Page 40: Prashant_COBOL 400

Initialize the Function KeysMOVE B"0" TO INDIC-TABLE(IND-SFLEND) INDIC-TABLE(IND-SFLDSP) INDIC-TABLE(IND-SFLDSPCTL) INDIC-TABLE(IND-SFLNXTCHG)

Page 41: Prashant_COBOL 400

Clear The SubfileMOVE B"1" TO INDIC-TABLE(IND-SFLCLEAR)

Page 42: Prashant_COBOL 400

Load the Subfile

READ ACCOUNTS NEXT RECORD PERFORM 3300-READ-ACCNTS UNTIL WS-EOF-ACCNTS = "Y“

3300-READ-ACCNTS.*=================== ADD 1 TO WS-COUNT READ ACCOUNTS NEXT RECORD AT END MOVE "Y" TO WS-EOF-ACCNTS END-READ

MOVE AC-MAIN TO ACMAIN OF SUBFIL-O MOVE AC-SUB TO ACSUB OF SUBFIL-O MOVE AC-GST-REGD TO GSTRGD OF SUBFIL-O MOVE AC-GST-REG-NO TO GSTRGDNO OF SUBFIL-O MOVE AC-GST-BILL TO GSTBILL OF SUBFIL-O WRITE SUBFILE DISP-REC FORMAT IS "SUBFIL" INDICATORS ARE INDIC-TABLE.

Page 43: Prashant_COBOL 400

Display the SubfileMOVE B"1" TO INDIC-TABLE(IND-SFLDSP) INDIC-TABLE(IND-SFLDSPCTL) INDIC-TABLE(IND-SFLEND)

WRITE DISP-REC FORMAT IS "SUBFILCTL" INDICATORS ARE INDIC-TABLEEND-WRITE

READ DISPFILE FORMAT IS "SUBFILCTL" INDICATORS ARE INDIC-TABLEEND-READ

Page 44: Prashant_COBOL 400

ArraysDeclaring:05 WS-VALID-RESV-CDES OCCURS 5 TIMES INDEXED BY WS-SUB2. 10 WS-VALID-RESV-CODES PIC X(04).Searching:PERFORM VARYING WS-SUB1 FROM 1 BY 1 UNTIL WS-SUB1 > OR WS-RESV-FOUND = "Y" SET WS-SUB2 TO 1 SEARCH WS-VALID-RESV-CDES WHEN WS-VALID-RESV-CDES(WS-SUB1, WS-SUB2) = WS-CRS-RES-CODE(WS-H) SET WS-IND1 TO WS-SUB1 SET WS-IND2 TO WS-SUB2 MOVE "Y" TO WS-RESV-FOUND PERFORM 2065-ADD-TO-RESV-PARA THRU 2065-ADD-TO-RESV-PARA-EXIT END-SEARCHEND-PERFORM