Improving your programming productivity can be as valuable to your installation's resource management as coding effective and efficient programs. The following techniques can help reduce some tedious and time-consuming coding tasks and allow you more effective use of your time and system resources.

Using these suggestions may not always be possible or practical. Refer to your organization's guidelines and requirements prior to using the following techniques.

Finding Coding Errors

Errors fall into two broad classes: those that the compiler can identify when it examines your source program and those that surface later when you execute the program. The second type of error—the run-time error-is often harder to track down.

Check for Errors, Using NOCOMPILE

After you have completed your design reviews and desk-checked your coding, you can check your program for syntax errors with the NOCOMPILE option. If you are a TSO user compiling in the foreground, you can send the messages to your screen by defining your data set as the SYSTERM data set and using the TERM option when you compile your program.

Errors the Compiler Can Identify

The compiler detects errors that are not dependent on run-time logic. While it can correct some of the errors it finds, the compiler cannot correct all of them. If your compilation fails, you need to fix the source program and compile it again. Common coding mistakes include:

  • Misspellings
  • Faulty punctuation (especially missing, extra, or misplaced periods)
  • Not observing COBOL formatting rules (Area A and Area B)
  • Incorrect or incomplete syntax
  • Using reserved words in data-definitions or paragraph headers

Sometimes mistakes go unnoticed at compile time because the statement makes sense to the compiler, even though it is not what you intended. These errors surface at run time. Errors the Compiler Cannot Identify

Check for these mistakes in your program logic:

  • Failing to match the record description in your source program with the record format on the file to be read. For example, a numeric field that should contain zero (numeric) actually contains blanks (alphanumeric).
  • Trying to perform calculations on invalid data.
  • Moving data into an item that is too small for it.
  • Moving a group item to another group item when the subordinate data descriptions are incompatible.
  • Specifying a USAGE clause for a redefining data item that is different from the USAGE specified for the item redefined, and not keeping track of the changed USAGE.
  • Specifying subscript values that are not within the bounds of the table. (You can use the SSRANGE compiler option to check for this type of error.)
  • Attempting an illogical I/O operation, such as reading a file that is opened OUTPUT or closing a file that is not opened. (Test the file status code after each input/output.)
  • Not defining a sign field for items that may hold negative values. (The sign is lost and what should have been a negative number becomes a positive number.)
  • Not initializing the items in the Working-Storage Section with a value before using them.
  • Not initializing counters and indexes.
  • In a called program, incorrectly matching the data descriptions in the Linkage Section with those of the calling program.
  • In the calling program, incorrectly identifying the data to be passed.
  • Combining RES and NORES.

Using the COPY Facility

If your program contains frequently used code sequences (such as blocks of common data items, input/output routines or error routines), write the code sequences once, place them in a library, and then retrieve them for your program with the COPY statement.

  • The VS COBOL II COPY facility can help you in two ways:
  • It saves time and labor by eliminating repetitive coding.

It helps to ensure accuracy by eliminating new coding mistakes. When your program is compiled, the compiler expands the copybook to the actual code. The COPY statement you entered will appear on the source listing. You can use the COPY statement in any division. To use the COPY statement does the following steps:

  • Use System Services to allocate copy libraries. Allocate the library (partitioned data set) that will contain your copy members.
  • Add the members to the partitioned data set. Use utility statements to enter source statements into a library copy member.
  • Put COPY statements into your source program. At the point in your source program where you want the contents of the member to be inserted, code a COPY statement that includes the name of the member, as you defined it in step two.
  • Identify the copy library when you compile your program. At compile time, you need to tell the compiler which partitioned data sets contain your copy members. To do this, identify that data set (or data sets) in the SYSLIB DD statement. Programs must be compiled with the LIB option.

Copying an Entire Source Program

You can put frequently used source programs, such as a payroll program, into the copy library. If you want to use a source program that has been put in the copy library, use the BASIS statement in your source program. Also, you may want to copy an entire source program, but with some alterations. You can do this by using the BASIS statement combined with INSERT and DELETE statements.

Using the REPLACE Statement

The REPLACE statement provides a way to apply a change to sections of COBOL source programs without your having to manually find all places that need to be changed. It is an easy method of doing simple string substitutions. It is similar to the COPY statement, except that it acts on the entire source program, not just on the text in COPY libraries.

You can use the REPLACE statement to resolve any conflict between new reserved COBOL words and names you have used in your program. For example, if you have used the name DAY-OF-WEEK for a data item in your program, you will need to change all the occurrences of that name. To do this, insert the following REPLACE statement before the first line of your program:

This will replace all occurrences of DAY-OF-WEEK in your program with the new name WEEKDAY. Because REPLACE statements are processed after any COPY statements are processed, it will also change any occurrences of DAY-OF-WEEK that were included in text from COPY libraries.

The rules for using the REPLACE statement are:

  • The LIB compiler option must be specified.
  • REPLACE statements cannot introduce COPY statements (although COPY statements can introduce REPLACE statements).
  • REPLACE statements cannot not modify or introduce other REPLACE statements.
  • Any REPLACE statement is in effect from the point at which it is specified until:
  • It is explicitly turned off
  • The occurrence of another REPLACE statement
  • The end of the compiled program is reached.

Controlling the Output Listing

The "CONTROL (*CBL) statement is an output listing control statement. With the SOURCE, MAP, and LIST compiler options, this statement selectively suppresses or allows production of output. The names "CONTROL and "CBL are synonymous; wherever one appears in the explanation that follows, the other can be substituted.

The characters "CONTROL or *CBL can start in any column, beginning with column 7. followed by at least one space or comma and one or more option key words. The optional keywords must be separated by one or more spaces or commas. The "CONTROL statement must be the only statement on the line and may be terminated with a period. Continuation is not allowed.

"CONTROL does not turn options on and off. It only allows listing control for those listing options in effect for the compilation. The keywords that can appear are: SOURCE and NOSOURCE, MAP and NOMAP, LIST and NOLIST. The source line containing the "CONTROL statement does not appear in the source listing.

Your installation may set certain options to have fixed values that cannot be overridden for individual applications. These fixed options take precedence over options specified via:

  • PARM statement in JCL
  • PROCESS card (synonym: CBL)
  • "CONTROL (*CBL).

The requested options are handled in the following manner:

  • If an option or its negation appears more than once in a "CONTROL statement, the last occurrence of the option keyword is used.
  • If the corresponding option has been requested as a parameter to the compiler, then a "CONTROL statement with the negation of the option keyword must precede the portions of the source program for which listing output is to be inhibited. Listing output then resumes when a "CONTROL statement with the affirmative option keyword is encountered.
  • If the negation of the corresponding option has been requested as a parameter to the compiler, the output of that type is always inhibited.

Selective Source Listing

Production or suppression of a listing of the input source program lines is controlled by the "CONTROL SOURCE and "CONTROL NOSOURCE statements (or "CBL SOURCE and "CBL NOSOURCE). If any "CONTROL NOSOURCE or "CBL NOSOURCE statement is encountered and SOURCE has been requested as a parameter to the compiler, the following informational (l-level) message is issued: Printing of the source code has been suppressed.

The source program text is displayed as follows

  • If NUM is not requested, the sequence field is printed to the left of the listing.
  • If NUM is requested, the sequence field is blank, unless sequence is violated (in which case the sequence field appears to the left of the listing).

The entire line is displayed in the body of the listing.

Storage Mapping in the Data Division

Parts of the MAP listing and embedded MAP summary can be selected or inhibited by use of "CONTROL MAP or "CONTROL NOMAP statements ("CBL MAP or "CBL NOMAP statements) interspersed throughout the source

Object Code in the Procedure Division

You can control the selective listing of generated object code with the "CONTROL LIST and "CONTROL NOLIST statements (*CBL LIST and *CBL NOLIST). User-defined names are displayed. The sequence field and COBOL statement are placed on a separate line to make room for the user-defined names. Internal clauses of COBOL statements are displayed in the statement line format.

All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd Protection Status

IBM Mainframe Topics