Presentation is loading. Please wait.

Presentation is loading. Please wait.

Week 2/3 - 2nd Lecture Intro to COBOL Programming Defining Files and Processing Data.

Similar presentations


Presentation on theme: "Week 2/3 - 2nd Lecture Intro to COBOL Programming Defining Files and Processing Data."— Presentation transcript:

1 Week 2/3 - 2nd Lecture Intro to COBOL Programming Defining Files and Processing Data

2  Creating a source Physical File  Creating a Physical/Logical File  What is PDM ?  How does a compiler work?  Creating a COBOL Program  Parts of a COBOL Program  The Perform Statement  Defining Files  Defining Variables  COBOL Verbs

3  Source Physical File is like a container that consists of Source Code called member.  You can have source code for Physical File, Logical File, Cobol, RPG or Java programs.  Command to create a source physical file is CRTSRCPF QCBLSRC

4  PDM stands for Program Development Manager  This is the environment used to develop code for the AS/400 iSeries system  The editor used in PDM is called SEU (Source Entry Utility)  To start PDM the command is STRPDM  Then take option 3 for Members and get into your QCBLSRC source file to create your programs

5  Translate programs written by humans into Machine Language Code.

6 COBOL Compiler Source Code QCBLSRC (PGM1) Compiled Listing (PGM1) in a spool file format Program Object (PGM1) as an executable

7 1. Create a Source Physical File - QCBLSRC 2. Create a Source Member in the Source Physical file with the type CBL 3. Type in the COBOL code using SEU 4. Exit & Save 5. Compile (Option 14 on the Work with members screen)

8  Designed by the US defense department  Meant to be English like for ease of maintenance COmmon Business Oriented Language

9 ColumnsUseExplanation 1-6Sequence numbers or Page and Line numbers (Optional) Are added automatically by CODE/400 when the program is being entered into the system 7Continuation, comment, or starting a new page Used to denote a line as a comment (an * in column 7), to cause the printer to skip to a new page when printing the source listing (a / in column 7), or to continue nonnumeric literals (discussed later in the book) 8-11Area ASome entries, such as DIVISION SECTION, and paragraph-names, must begin in Area A 12-72Area BMost COBOL entries, including PROCEDURE DIVISION sentences, are specified in Area B 73-80Program Identification (Optional) Used to identify the program. This entry is omitted in this book Blank LineSeparate COBOL LinesBlank lines are permitted anywhere in a COBOL program to make the program easier to read

10  Identification Division  Environment Division  Data Division  Procedure Division

11

12 IDENTIFICATION DIVISION. PROGRAM-ID. program-name. [AUTHOR. [comment-entry] … ] [INSTALLATION. [comment-entry] …] [DATE-WRITTEN. [comment-entry] …] [DATE-COMPILED. [comment-entry] …] [SECURITY. [comment-entry] …] Example: IDENTIFICATION DIVISION. PROGRAM-ID. CPCH02A.

13  Required ◦ Identifies the program to the computer system. It also provides some documentation about the program. ◦ Name of the Program in the Program-ID paragraph.  Optional ◦ Author ◦ Installation ◦ Date-Written ◦ etc.

14

15  Required ◦ Identifies the input and output files that are used by the program and assigns these files to specific devices.  Optional ◦ None

16 [ENVIRONMENT DIVISION.] [CONFIGURATION SECTION.] [SOURCE-COMPUTER. AS/400.] [OBJECT-COMPUTER. AS/400.] [INPUT-OUTPUT SECTION.] [FILE-CONTROL.] [SELECT nice-file-name ASSIGN to DISK/PRINTER/WORKSTATION- physical-file-name.]

17  INPUT-OUTPUT SECTION is only required if your program uses files. ◦ Contains the FILE-CONTROL paragraph  DISK  PRINTER  DATABASE  WORKSTATION  FORMATFILE ◦ similar to setting up file pointers

18 Select Product-File Assign to disk-PRODPF. Select Product-file Assign to database-PRODPF Access is Sequential.

19 Select Display-File assign to workstation-PRDSPF organization is transaction. Select Display-File assign to workstation-PRDSPF-SI organization is transaction.

20 Select Product-Report assign to printer-qprint. Select Product-Report assign to printer-qsysprt.

21 Select Product-Report assign to formatfile-qsysprt.

22

23  Required ◦ Describes the input and output formats to be used by the program. It also defines any constants and work areas necessary for the processing of data.  Optional ◦ NA

24 Types of COBOL EntriesMargin Rules Divisions Examples: IDENTIFICATION DIVISION. ENVIRONMENT DIVISION. DATA DIVISION. PROCEDURE DIVISION. Division and Section Names 1.Begin in Area A (Columns 8-11) 2.End with a period. 3.Must appear on a line with no other entries. Sections Examples: FILE SECTION. WORKING-STORAGE SECTION. **Above section applies here as well Paragraphs Examples: PROGRAM-ID 200-PROCESS-RECORD-RTN. Paragraph-names 1.Begin in Area A (Columns 8-11) 2.End with a period, which must always be followed by at least one space. 3.May appear on lines by themselves or with other entries. Statements (Sentences) Examples: MOVE EP-LAST-NAME TO DL-LAST-NAME. ADD AMOUNT-IN TO TOTAL. Sentences 1.Begin in Area B (Columns 8-11) 2.End with a period or scope terminator. Sentences ending with a period must always be followed by at least one space. 3.May appear on lines by themselves or with other entries. 4.A sentence consists or a statement or series of statements.

25  Define the files used in the program ◦ File Description ◦ Record Description  Program Described vs Externally Described.

26  Label Clause ◦ Not used often ◦ Transmitting Data  Block Clause ◦ Optional ◦ I’ve never seen it used

27  Records Clause ◦ Optional ◦ Used to double check that the record format

28  Details the fields in each record

29  Variables need by the program that are not described in the files and not parameters  Value clause used to initialize variables.

30  Define Parameters

31 [DATA DIVISION.] [FILE-SECTION.] [FD nice-file-name] [RECORD CONTAINS 99 CHARACTERS]. [01 record-name.] [05 field-names PIC ????.] [WORKING-STORAGE SECTION.] [01 field-name PIC X(10).]

32  Zoned Decimals (or signed integers)  Packed Decimal  Alphabetic  Alphanumeric  Boolean  Dates  Time  TimeStamp

33  Variable Data Changes  Constant Data doesn’t  Figurative Constants ◦ ZERO, ZEROS, ZEROES ◦ SPACES

34  Up to 30 Characters  Letters, numbers and hypens (-)  No blanks  At least one letter  Not a COBOL Reserved Word (see text for list of reserved words)  Meaning full names please

35

36  9 - Number  X – Alphanumeric  A - Alphabetic  V - Decimal Point PACKED-DECIMAL = COMP-3

37

38 01 Todays-date format of date. 01 Todays-time format of time. 01 Todays-timestamp format of timestamp.

39 01 IN99 pic 1.

40 PIC Clauses (Group Items) Mix of Elementary Items. Used to break a variable into smaller portions

41 01 Student-Number PIC 9(9). 01 Student-Number-Edited. 05 Student-Number-Part-1 PIC 9(3). 05 Student-Number-Part-2 PIC 9(3). 05 Student-Number-Part-3 PIC 9(3).

42

43  Required ◦ Contains the instructions necessary for reading input, processing it, and creating output.  Optional ◦ NA

44 PROCEDURE DIVISION. paragraph-name. statements.

45  Program Logic  Statements are executed in the order that they appear.  Logic can be divided into paragraphs (sub- routines)  Cindy’s advice: put a period at the end of every line.

46  COBOL’s version of the execute sub-routine command.  Works as follows: ◦ Goto the start of a paragraph. ◦ Repeat in sequence, all of the statements in the paragraph as many times as required.  UNTIL Clause ◦ Return to the calling statement.

47  Column based  3 parts to a COBOL source line ◦ Continuation (-) ◦ Area A ◦ Area B

48  * to start a comment line

49  Division Names  Section Names  Paragraph Names

50  Everything else

51

52 OPEN Statement Usually the first statement in a program Open files for processing Terminator is a period

53 Sequential READ Statement Used to Read the next Record from a File End of File Logic Not End of File Logic Terminator - END-READ.

54 Sequential READ Statement READ Employee-File AT END PERFORM 500-End-Of-File-Routine NOT AT END PERFORM 300-Process-Employee END-READ.

55  Used to read information from a screen  RECORD keyword is needed because display files usually have more than one record format. Read Display-file RECORD.

56 WRITE Statement Writes/Outputs records to a file Terminator is. Or END-WRITE. ‘Format is’ clause needed for display files Format is record format Needed because display files usually have more than one record format (screen)

57 Write display-record Format is ‘RECORD1’ end-write.

58 Write Product-record invalid key display ‘write failed’ not invalid key display ‘write ok’ End-write.

59 Write print-record-out.

60  Updates a record in a file  File must be opened as I-O instead of input  Record must be read first before rewrite REWRITE record-name (FROM variable-name) INVALID KEY perform error-rtn NOT INVALID KEY perform continue-rtn END-REWRITE.

61  COBOL assignment verb MOVE name TO first-name.

62 CLOSE Statement Closes the files used in the program Usually the second to last set of statements executed in the program Terminator is.

63 STOP RUN Statement Terminates the program The last statement executed in the program. Terminator is.

64 Device Specifications Type of DeviceImplementor-Name PrinterPRINTER DiskDISK, DATABASE Interactive input from a terminalWORKSTATION


Download ppt "Week 2/3 - 2nd Lecture Intro to COBOL Programming Defining Files and Processing Data."

Similar presentations


Ads by Google