| Contents |
|
|
|
- We are a cosmopolitan community of 400 members, from around the globe. - Working on writing and publishing articles on CICS. - Special article on "How do I learn Mainframe Programming" |
| Contents |
| Contents |
| Q. What are some of the common COBOL Errors, a beginner could make? |
| Here are the top 10 Mistakes in COBOL, you should watch out for, when you start-out to write COBOL-Programs. 1. Period was Required Often, you forget to put periods after divisions, sections or para's, and that’s when you get a "A Period was Required" Message. See what happens when you forget to put a period after IDENTIFICATION DIVISION. 2. Forgetting a Dash You will get strange error-Messages when you forget to put a dash in paragraph names that have multiple words. For example, if you forget to code a dash in the OPEN-FILE-ROUTINE, you get the following error Message. 3. XXX should not begin in Area-A I have coded PERFORM Instruction by error in Col 11. Coding a COBOL-statement in Area-A, when it should begin in Area-B, will issue an error like ... should not begin in Area-A, it was processed as if in Area-B. 4. YYY should begin in Area-A. I have coded the OPEN-FILE-ROUTINE by mistake in Area B. Coding a para, section or division entry in Area-B, when it should begin in Area-A, will issue an error like ...should begin in Area-A, it was processed as if in Area-A. 5. XXX was not defined as a data-name. I have declared the Variable WS-EMPLOYEE-SALARY in the Working Storage Section. But in the PROCEDURE DIVISION, while using it, I did a Typo-error, and spelled it as WS-EMPLOYEE-SALRY(forgot the 'A'). COBOL Compiler does not recognize the Data-name WS-EMPLOYEE-SALRY(the one without the 'A'), and complains about it. 6. The XXX Statement was Invalid. Expected ..., but found something else. I must have committed a Syntax-error. Out here, I’ve forgotten to put a closing single-quote on the Literal String 'QUASAR'. Here’s what the Compiler complains. 7. Putting PICTURE Clause on a Group Data-Item. Many beginners write the PICTURE Clause on the Group Level Data-Item. In COBOL, you break down Group Data-items further in smaller Storage Areas. So, you always specify the PICTURE Clause for the Lowest-Level Data-Items. By error, I have coded PICTURE Clause on WS-EMPLOYEE-RECORD, when it should be specified only for the EMPLOYEE-NAME, EMPLOYEE-SALARY and EMPLOYEE-JDATE Fields. 8. Neither an FD nor SD was found in the Program for the File XXX. I have done a typo-error in the FD Para, so the COBOL Internal file-name specified in the SELECT Clause does not match the FD Descriptor. 9. No Matching Scope-Terminator Found. When you code IFs, EVALUATEs, loops using Inline PERFORMs be sure to supply the Scope Terminator END-IF, END-EVALUATE, END-PERFORM correctly. The Compiler Software recognizes the statements inside an PERFORM..END-PERFORM as one block. I've forgotten to code an END-PERFORM, and the compiler complains about it– it doesn't know where the PERFORM Block ends. |
| Q. What are some COBOL Coding Standards one should follow? |
| Program Header : Every COBOL Module should begin with a Program-Header, that specifies the Program Name, system, description, File Access, DB2 Tables Access, Sub-programs called etc. Here's how I have coded the Program-Header for my COBOL-Program PROG05. IDENTIFICATION DIVISION : The PROGRAM-ID should be 7 OR 8 chars and must be the same as Member-name. Most projects or Production Environments specify a naming-convention for the PROGRAM-ID. At my work-place it goes like this - PROGRAM-ID. XXXYZAnn. The first 3 characters XXX should be the name of the Sub-system. Say for example, our Mainframe sub-system is GEMINI, so we use the three letter prefix GEM for all our programs. It is followed by B, if it’s a Batch Program, C if its an Online Program. Our programs are mostly Batch, so we'd put a B. We also use a single letter code - I for Inserts, U for Updates, D for Deletes, S for Selects. Say, that my Program does Inserts, so I use the code I. We also code D for DB2, or I for IMS. My Program uses DB2 for storing Data. Hence, my program-id would be GEMBIDnn. So, in my project, all our Programs are like GEMBID01, GEMBID27, GEMBID58, GEMBID59, GEMBID60, GEMBID2A so on and so forth. ENVIRONMENT DIVISION : For readability, you should write each SELECT Statement on a new line, and the ASSIGN TO Clause, ORGANIZATION IS, ACCESS MODE IS, FILE STATUS IS, and the RECORD KEY IS Clauses should be indented thereafter on successive lines. DATA DIVISION : It's a good practice to organize the Working-Storage Variables in the COBOL-Program, so its very easy to FIND Variables. For example, all the Storage Areas used for Input-Output go together. All the Print-Formats such as Header-Lines, Separator Lines should be grouped. Then follows the DB2-I/O Areas which contain 'EXEC SQL – END-EXEC' Blocks. These are Storage Areas in COBOL that will receive the data fetched from DB2 Tables, or send data-output to be stored in DB2 Tables. Likewise, Flags-and-Switches which help detect special conditions, Literals and Constants(Values that don’t change) and Counters which help keep track how many times you do a thing;are stored together under the Working Storage Section. Level-Numbers and Picture Clause – Get into the habit of inserting Blank Empty-Lines, lavishly. Don't hesitate to use them. Level-Numbers indicate Break-up or Structure. User Non-contiguous Level-Numbers like 01, 05, 10, 15 and so on. Indent each higher Level-Number 3 columns to the right. See how I have indented 01, 05 and 88-Levels. Code the Picture Clause preferably on Position 45. For Numeric-Edited variables like WS-CONTRACT-FACE-AMT, write the entire PIC Clause –ZZZ,ZZZ,ZZZ,ZZZ,ZZZ.99 instead of writing –Z(3),Z(3),Z(3),Z(3),Z(3).9(2). |
| Q. I want a comprehensive list of all the possible COBOL Errors, that the COBOL Compiler complains about? |
| To generate a complete Listing of all possible errors in COBOL, along with the Errors-Codes and their Description, I'd call for ERRMSG. Write a COBOL Program, with the PROGRAM-ID ERRMSG. and that does the trick. I've coded the ERRMSG COBOL Program. This magic trick works, COBOL-Compiler Software recognizes the special-program ERRMSG, and it produces an entire list of Error-codes and Descriptions in the Compiler-Listing. Here's an extract of what you'll get as output in the Compile-Listing. It’s a huge List. Get the Complete Error-Listing here. |
| Q. What does COBOL stand for? |
| COBOL stands for Common Business Oriented Language. COBOL Programs are used to process. Business-Data. COBOL Programs are easy to code and analyse, because it is an English-like language. Writing a COBOL program is just like writing a passage in English. |
| Q. Are COBOL Programs English-like? |
| Just as text in English is organised into sections and para’s, COBOL Programs can also be broken down into divisions, divisions further into sections, and sections into paragraphs. Each paragraph contain sentences, or COBOL Statements. Like the English language, sentences(statements) in COBOL should end with a period(full-stop). When you start new paragraphs in COBOL, you need to indent them, just as in English you follow indentation rules. COBOL then is whole-lot English like. Even instructions in COBOL, are words borrowed from English, ADD, SUBTRACT, MULTIPLY, DIVIDE etc. |
| Q. What’s the basic skeleton of a COBOL Program |
| The basic skeleton of a COBOL Program is as follows : A COBOL Program can be divided or broken down into 4 parts – IDENTIFICATION DIVISION, ENVIRONMENT DIVISION, DATA DIVISION and PROCEDURE DIVISION. The PROCEDURE DIVISION contains the instructions to be executed(performed), one after the other, step-by-step till you reach the end of the Program and stop running it(STOP RUN). Under a division, you may have several sections as well, and sections in turn can have several paragraphs. Divisions, sections and paragraphs help make the COBOL Program more structured, and the flow of the COBOL Program is easy to grasp. |
| Q. What are the Alignment(Indentation rules) in COBOL? |
| The lines in a COBOL Program are indented or aligned, as its done in English. When you write COBOL Program on the Mainframe terminal, you have 80 columns on a line to code on. The area spanning from columns 8-11 is called Area A. The area spanning from columns 12-72 is called Area B. In COBOL, division names, sections and paragraphs begin in Area A. See below, how I’ve coded IDENTIFICATION DIVISION, ENVIRONMENT DIVISION,.. etc. starting on Column 8 - You code COBOL Instructions, COBOL Statements in Area B(that’s anywhere between Column 12 – 72). So, all your COBOL Instructions in the PROCEDURE DIVISION like ADD, SUBTRACT, MOVE should begin on or after Column 12. Look below, how I’ve coded COBOL Instructions in Area B. An interesting bit of trivia, back in the early days, COBOL Programs were coded on a COBOL Coding-Sheet, before punching the Instructions onto a Punched-Card. Here's a picture of, how a Coding-Sheet. looked like. |
| Q. What is the IDENTIFICATION DIVISION used for? |
| The IDENTIFICATION DIVISION is used to identify the COBOL Program to the system. Under the IDENTIFICATION DIVISION, you can code several para-entries like PROGRAM-ID, AUTHOR etc. which supply extra-descriptive information about the COBOL Program. The PROGRAM-ID para assigns a unique-name to the COBOL-Program. You simply write the name of your COBOL Program after the PROGRAM-ID Para. Here’s how you code it - |
| Q. How do you document a COBOL Program? |
| A well-documented COBOL Program is easy to analyse. You can quickly understand the functionality of the COBOL Program, if it contains comments. In COBOL, you code comments by putting an asterisk * in Column 7. |
| Q. What is PROCEDURE DIVISION? |
| The PROCEDURE DIVISION is the starting-point of the COBOL-Program. This is where the Mainframe begins to run(execute the COBOL instructions). Hence, all your instructions/programming logic must be written inside this PROCEDURE DIVISION. Under the PROCEDURE DIVISION, you can write Instructions one-after-the other. The Mainframe executes, runs the instruction in the PROCEDURE DIVISION, one-by-one, step-by-step sequentially, till you say, STOP RUNning the Program. To stop running the COBOL Program, the last-instruction you code must be STOP RUN. PROCEDURE DIVISION. |
| Q. How do you display text on the Screen in COBOL? |
| To Display data on the Screen, in COBOL you code the DISPLAY Instruction. You code DISPLAY followed by the text that want to print on the Screen, enclosed in Single Quotes. Say for example, if I want to display Hello World on the Screen, I would write - |
| Q. How do I setup Compile-Link Job? |
| To run and process data using a Program, you need to first Compile-Link a COBOL Program. The Free COBOL-Compiler Software on Mainframes is IGYCRCTL. The Compiler-Software works like a Translator, translates the Program from COBOL to Binary Language. Like any other Program on Mainframes, the free Compiler IGYCRCTL also expects you to supply some Input-Output Files. To run the Compiler-Software IGYCRCTL, I set-up a job like this – I’ve set //SYSIN DD Input-File to point to my COBOL Source Program which resides at SYSADM.DEMO.SRCLIB(PROG04). //SYSLIN DD Output-File, where the compiler stores Binary Object code points to a Temporary-File LOADSET. The //SYSPRINT DD File is set to point to the Spool SYSOUT=*. This contains the Compile-Listing. I look at the Compile-Listing, and know if my program successfully compiled, or the compiler complained about my Program(its faulty, has syntax errors). //SYSUT1 to //SYSUT7 are temporary-work-Files. The Output Binary-Object-Code generated by the Compiler-Software IGYCRCTL, cannot run on its own, standalone. To get it running, it needs other Helper Programs. The Linker-Software packs and bundles together my Binary-Program along-with any other Helper-Programs, it may need into one composite Load-Module. My Program is all set to go! The Free COBOL-Linker Software on Mainframes is HEWL. It expects the following files - To run the Linker Software HEWL, I added a LKED Step to my job. I have set the //SYSLIN DD Input-File to point to Binary Object-Code stored at the Temporary-Dataset LOADSET created in the COMPILE Step. Bundled-up Output Load Module of the Linker HEWL is stored in //SYSLMOD File. I have made the //SYSLMOD DD File point to the dataset SYSADM.DEMO.LOADLIB(PROG04). The Load-Module PROG04 would be stored in my personal Load-Library SYSADM.DEMO.LOADLIB. |
| Q. I’ve hit SUB on the Compile-Link Job. What next? |
| Hit SUBmit on the Compile-Link job after you’ve set it up. Start SDSF to see the Output of the Compile-Link Job in the Spool, and check Compile SYSPRINT-Listing for any errors. Here’s how, the Compile-Listing looks. It shows that I running Enterprise COBOL Version. The SSRANGE, XREF, LIST, MAP, OFFSET Compiler options have been turned ON. The Compiler Software IGYCRCTL leaves behind signature, a Two-Digit Return-Code as a signal, to indicate if the COBOL-Program compiled successfully, or it contained errors. Check the Return-Code set by the Compiler, by scrolling to the bottom of the Compile-Listing. The Return-Code set by the Compiler is RC=04. A Zero RC suggests, the COBOL Program is correct, an RC=04 denotes Warnings(W). This is acceptable. When the Compiler sets the RC=08, the COBOL Program contains Errors(E), and an RC=12 says the COBOL Program has Severe-Errors(S). When the Compiler complains with Errors(E) and Severe Messages(S), you need to go back and correct your COBOL Program. |
| Q. How do I run my Program? |
| To run your program , you need to write a Job. I’d run my Program, by setting up a job like this - I need to run the Program PROG04, so I write EXEC PGM=PROG04. The Mainframe Computer should pickup this Load Module from my Personal Load Library SYSADM.DEMO.LOADLIB, so I added a //JOBLIB DD Statement pointing to my Load-Library. When I SUBmit this Job, the Output Listing in the Spool, shows up as - |
|
|
| Subscribe to Mainframes 360 |
| Visit this group |