1 / 18

Chapter 1

Chapter 1. Your First COBOL program. What is COBOL?. COBOL is an acronym for Common Business Oriented Language. Programming language especially aimed at solving business problems . COBOL screens are 80 columns wide by 24 or 25 characters high and do not contain graphics. A COBOL program.

hop-moss
Download Presentation

Chapter 1

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. Chapter 1 Your First COBOL program

  2. What is COBOL? • COBOL is an acronym for Common Business Oriented Language. • Programming language especially aimed at solving business problems. • COBOL screens are 80 columns wide by 24 or 25 characters high and do not contain graphics.

  3. A COBOL program 000100 IDENTIFICATION DIVISION. 000200 PROGRAM-ID. HELLO. 000300 ENVIRONMENT DIVISION. 000400 DATA DIVISION. 000500 PROCEDURE DIVISION. 000600 000700 PROGRAM-BEGIN. 000800 DISPLAY "Hello world". 000900 001000 PROGRAM-DONE. 001100 STOP RUN.

  4. COBOL program parts -Divisions • There are four divisions in COBOL. • Identification Division • Environment Division • Data Division • Procedure Division • DON'T make typing errors. Some of the typing errors that can cause serious problems when you are compiling include misspelling the name of a DIVISION (for example, INDENTIFICATION DIVISION), adding an unnecessary hyphen (for example, DATA-DIVISION), or omitting any of the periods. Note that everything ends with a period (.)

  5. COBOL program parts -Divisions • The IDENTIFICATION DIVISION marks the beginning of a COBOL program. The name of the program, which you assign, will be entered as a statement in the IDENTIFICATION DIVISION. • This division is used to identify basic information about the program. In this example, the IDENTIFICATION DIVISION contains only the PROGRAM-ID, HELLO.

  6. COBOL program parts -Divisions • ENVIRONMENT DIVISION, which is used to identify the environment in which the program is running. Remember that COBOL is intended to run on many different types of machines, and this section is used to handle the differences between various computers. • Contains statements or commands to describe the physical environment in which the program is running. The main use of the ENVIRONMENT DIVISION is to describe the physical structure of files that will be used in the program.

  7. COBOL program parts -Divisions • The DATA DIVISION contains statements describing the data used by the program. • Contain any data that the program operates on. • All the data that the program uses will be defined in this division. • The DATA DIVISION and the PROCEDURE DIVISION are the most important divisions in a COBOL program; they do 95 percent of the work.

  8. COBOL program parts -Divisions • PROCEDURE DIVISION. This is the meat of the program--the part that does the work intended by the programmer. • The PROCEDURE DIVISION contains the COBOL statements that the program will execute after the program starts running. • The PROCEDURE DIVISION is the real workhorse of a COBOL program. • Without a PROCEDURE DIVISION, you wouldn't have a program, because all the other divisions are used to create the environment and data that are used by the PROCEDURE DIVISION to actually do something.

  9. COBOL program partsProgram ID and Stop Run • Most compilers require that only two things be present in a COBOL program--other than the four divisions--in order to compile it: • PROGRAM-ID • STOP RUN

  10. COBOL program partsProgram ID and Stop Run • The PROGRAM-ID is a paragraph that must appear in the IDENTIFICATION DIVISION and is used to give the program a name. • There must also be one paragraph in the PROCEDURE DIVISION that contains the STOP RUN statement. • Most versions of COBOL require this explicit command as a way of identifying the point in the program where the program terminates.

  11. COBOL – Sample program 000100 IDENTIFICATION DIVISION. 000200 PROGRAM-ID. SENTNCES. 000300 ENVIRONMENT DIVISION. 000400 DATA DIVISION. 000500 PROCEDURE DIVISION. 000600 000700 PROGRAM-BEGIN. 000800 DISPLAY "This program contains four DIVISIONS,". 000900 DISPLAY "three PARAGRAPHS". 001000 DISPLAY "and four SENTENCES". 001100 PROGRAM-DONE. 001200 STOP RUN.

  12. COBOL source code • A COBOL source code file has five areas, extending from left to right across the page. • The first six characters or columns of a line are called the sequence number area. • This area is not processed by the compiler, or if it is processed, it provides you only with warnings that numbers are out of sequence (if they are). .

  13. COBOL source code • Character position 7 is called the indicator area. • This seventh position is usually blank. • If an asterisk (*) is placed in this column, everything else on that line is ignored by the compiler. • This is used as a method to include comments in your source code file.

  14. COBOL source code - Area A vs Area B • The four character positions 8 through 11 are called Area A. • DIVISIONs and paragraphs (and SECTIONs) must start in Area A. • It is good coding practice to start DIVISIONs, SECTIONs, and paragraph names at column 8 rather than some random place in Area A.

  15. COBOL source code - Area A vs Area B • Character positions 12 through 72 are called Area B. • Sentences must start and end within Area B. • It is good coding practice to start sentences at column 12 rather than some random place in Area B.

  16. COBOL source code - Area A vs Area B • COBOL was designed as an 80-column language, but there is no formal definition of character positions 73 through 80. This is called the identification area (which has nothing to do with the IDENTIFICATIONDIVISION). • Some special COBOL editors place a modification code automatically in positions 73 through 80. • This method of marking lines as modified usually depends on a special editor set up for COBOL that inserts these codes automatically. • You probably will never see modification codes using COBOL on a PC.

  17. COBOL source code - Area A vs Area B 000100 IDENTIFICATION DIVISION. 000200 PROGRAM-ID. COMMENT. 000300 ENVIRONMENT DIVISION. DATA DIVISION. MB072197 000500 PROCEDURE DIVISION. 000600 000700* This is a comment. MB072197 000800* This paragraph displays information about the program. MB072197 000900 PROGRAM-BEGIN. 003700 DISPLAY "This program contains four DIVISIONS,". MB072197 003800 DISPLAY "three PARAGRAPHS". MB072197 001000 DISPLAY "and four SENTENCES". 001100 PROGRAM-DONE. 001200 STOP RUN.

  18. What is a Shell Program? • A COBOL program that contains the minimum requirements usually is called a shell program, a skeleton program, or a boilerplate program. IDENTIFICATION DIVISION. PROGRAM-ID. COBSHL01. ENVIRONMENT DIVISION. DATA DIVISION. PROCEDURE DIVISION. PROGRAM-BEGIN. PROGRAM-DONE. STOP RUN.

More Related