1 / 58

Any Questions?

Learn the basics of COBOL programming, including how to create a program, define files, and process data. Understand the different parts of a COBOL program and the key COBOL verbs. This lecture will also cover how a COBOL compiler works.

tpalmer
Download Presentation

Any Questions?

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Any Questions?

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

  3. Agenda • How does a compiler work? • Creating a COBOL Program • Parts of a COBOL Program • The Perform Statement • Defining Files • Defining Variables • COBOL Verbs

  4. Compilers • Translate programs written by humans into Machine Language Code.

  5. COBOL Compiler on the iSeries Compiled Listing (PGM1) Source Code QCBLLESRC (PGM1) COBOL Compiler Program Object (PGM1)

  6. Steps to Create a COBOL Program 1. Create a Source Physical File - QCBLLESRC 2. Create a Source Member in the Source Physical file with the type CBLLE 3. Type in the COBOL code using SEU 4. Exit & Save 5. Compile

  7. What is COBOL? • Designed by the US defense department • Meant to be English like for ease of maintenance COmmon Business Oriented Language

  8. Parts of a COBOL Program • Identification Division • Environment Division • Data Division • Procedure Division (See Page 51 of your text)

  9. Identification Division

  10. Identification Division(Syntax) IDENTIFICATION DIVISION. PROGRAM-ID. program-name. [AUTHOR. [comment-entry] … ] [INSTALLATION. [comment-entry] …] [DATE-WRITTEN. [comment-entry] …] [DATE-COMPILED. [comment-entry] …] [SECURITY. [comment-entry] …]

  11. Identification Division • Required • Name of the Program in the Program-ID paragraph. • Optional • Author • Installation • Date-Written • etc.

  12. Environment Division

  13. Environment Division(Syntax) [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.]

  14. Environment Division • 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

  15. Select for a Database File Select Product-File Assign to disk-PRODPF. Select Product-file Assign to database-PRODPF Access is Sequential.

  16. Select Statement for a Display-File Select Display-File assign to workstation-PRDSPF organization is transaction. Select Display-File assign to workstation-PRDSPF-SI organization is transaction.

  17. Select Statement for a Spooled File Select Product-Report assign to printer-qprint. Select Product-Report assign to printer-qsysprt.

  18. Select Statement for an Externally Described Printer File Select Product-Report assign to formatfile-qsysprt.

  19. Data Division

  20. File Section • Define the files used in the program • File Description • Record Description • Program Described vs Externally Described.

  21. File Section - FD • Label Clause • Not used often • Transmitting Data • Block Clause • Optional • I’ve never seen it used

  22. File Section - FD • Records Clause • Optional • Used to double check that the record format

  23. File Section - Record Description • Details the fields in each record

  24. Working Storage Section • Variables need by the program that are not described in the files and not parameters • Value clause used to initialize variables.

  25. Linkage Section • Define Parameters

  26. Data Division(Syntax) [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).]

  27. Defining Variables • Zoned Decimals (or signed integers) • Packed Decimal • Alphabetic • Alphanumeric • Boolean • Dates • Time • TimeStamp

  28. Variable Data vs Constant Data • Variable Data Changes • Constant Data doesn’t • Figurative Constants • ZERO, ZEROS, ZEROES • SPACES

  29. Variable Names • 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

  30. Variable Name Examples

  31. PICture Clauses(Elementary Items) • 9 - Number • X – Alphanumeric • A - Alphabetic • V - Decimal Point PACKED-DECIMAL = COMP-3

  32. PIC Clauses

  33. Date, Time, & TimeStamp fields 01 Todays-date format of date. 01 Todays-time format of time. 01 Todays-timestamp format of timestamp.

  34. Boolean Variables 01 IN99 pic 1.

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

  36. PIC Clauses(Group Item – Example) 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).

  37. Procedure Division

  38. Procedure Division(Syntax) PROCEDURE DIVISION. paragraph-name. statements.

  39. Procedure Division • 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.

  40. Perform Statement • 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.

  41. Coding a COBOL Program • Column based • 3 parts to a COBOL source line • Continuation (-) • Area A • Area B

  42. Continuation (-) • * to start a comment line

  43. Area A • Division Names • Section Names • Paragraph Names

  44. Area B • Everything else

  45. Frequently Used COBOL Verbs

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

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

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

  49. Display File Read • 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.

  50. 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)

More Related