Let's understand Mainframe
Home Tutorials Interview Q&A Quiz Mainframe Memes Contact us About us

Module 17 : COBOL Performance Tuning tips

COBOL Performance Tuning tips

  • You must follow your company/project guidelines/standards.
  • Understand business requirements clearly before jumping into writing a code. Once requirement is clearly understood, prepare list of functions that your program will perform. Based on requirement decide whether all functionality can be coded into single program or multiple programs. In case, if some functionality is common across multiple places then create a single COBOL sub-program and makes use of it in multiple places. Similarly for common codes, variable declaration make use of COPYBOOKS. This helps in avoiding code redundancy and also enables easier code maintenance.
  • Estimate the rough count of number of records that your functionality needs to handle. This will give you rough idea of number of I/O that your COBOL program is expected to perform. Based on all these details you can decide what type of storage technology (i.e flat files, VSAM, DB2 tables) will be needed for data storage.
  • Make use of structure programming statements so that program is readable and the optimizer can operate on larger region of program that enables more efficient code. Avoid use of ALTER, Un-controlled GOTO, backward branches.
  • Avoid use of 66 levels declaration. Instead use structuring breakage by level numbers.
  • Avoid use of 77 levels declaration. Instead group all such items into categories and declare them under 01 level.
  • It is suggested to use 88 level declaration for switches/condition names. This promotes code readability.
  • During data item (variable) declaration, increment the level numbers by keeping some gap in-between. This is to enable simple insertion of extra levels during later modification. This will help a lot as you do not need to renumber whole hierarchy later. (You can initially code like 01, 05, 10, 15…)
  • When performing arithmetic, should use signed numeric fields. COBOL performs faster with signed fields than unsigned fields
  • If you are performing SEARCH in COBOL and if your data is in sorted order, you should use SEARCH ALL (binary search). Binary search(SEARCH ALL) is faster than linear search (SEARCH)
  • When writing to variable length blocked sequential files, use the APPLY WRITE-ONLY clause for the file or use the AWO compiler option. This can reduce the number of calls to Data Management Services to handle the I/Os.
  • Using indexes to address a table is more efficient than using subscripts since the index already contains the displacement from the start of the table and does not have to be calculated at run-time.
  • Prefer use of external sort/merge (through JCL) over COBOL SORT/MERGE.
  • Structured programming statement GOTO should be avoided. However, it is okay to use controlled GOTO statements (meaning GOTO transferring control to end of paragraph being performed)
  • Try to use EVALUATE instead of nested IF statement. Execution of IF-ELSE statement consumes more CPU as compare to execution of EVALUATE.
  • It is good practice to code ON OVERFLOW with STRING/UNSTRING statements. Otherwise, you will remain unaware of incomplete operation.
  • INITIALIZE all variables in beginning of program only. Try to avoid use of INITIALIZE in middle of programs and also remember that it is inefficient to initialize an entire group unless you really need all items in group to be initialized to different value. You can use MOVE spaces/zeroes statement to initialize variables, if needed. (MOVE is faster than INITIALIZE)
  • When converting data to upper or lower case, it is suggested to use INSPECT CONVERTING instead of the intrinsic functions UPPER-CASE or LOWER-CASE. It is more efficient to use INSPECT CONVERTING.

© copyright mainframebug.com
Privacy Policy