7 COBOL/MVS PROGRAMMING AND RUNNING TIPS
7.2 Program Design and Efficiency
7.4 Data Formats for Inter-Language Communication
7 COBOL/MVS PROGRAMMING AND RUNNING TIPS
In addition to the pointers given below, also consult the "Programming Techniques" section of the IBM COBOL for MVS & VM Programming Guide, SC26-4767.
· The following features of COBOL/MVS cannot be used at this facility:
· CHECKPOINT/RESTART (the RERUN clause is tolerated)
· User label handling functions are not supported. Therefore, the label handling format of USE is invalid. The data-mname option of the LABEL RECORDS clause is invalid. USER-DECLARATIVE is never invoked for labeling.
· Any COBOL/MVS instruction that causes a message to be written on the operator's console (e.g. DISPLAY ON CONSOLE or STOP literal).
· COBOL/MVSM allows the SEGMENTATION feature; you will not improve storage allocation by using it, because COBOL/MVS does not perform overlay.
· When using the SORT verb, always use DISP=SHR in the JCL rather than DISP=OLD for the data set SYS1.SORTLIB. Also, the following statement must be included for the SORT/MERGE program messages if Computer Center procedures are not being used:
· COBOL/MVS Interactive DEBUG is not available.
The hints in this section apply to all types of COBOL programs run at NIH.
· Arrange the Data Division so that the most active files are first. This is particularly important if there are more than five files being used.
· Group FDs by function and define files that are used together in sequence.
· Since core is initialized to zeroes, uninitialized variables may not cause a program to ABEND and may instead cause a program to yield incorrect results. The fact that core is initialized to zeroes should not be depended on by the programmer to initialize data items within the program. System software often modifies core for its own purpose that is later used in the program's region.
· Whenever possible, use one OPEN statement when opening multiple files. This will cause their buffers to be close together and improve locality of reference. Whenever possible, use one OPEN or CLOSE statement for all files.
· Avoid the use of SAME RECORD AREA since this causes buffers to be separated from files not using the option.
· Group references to DIRECT files because buffers for these files are separate from sequential files.
· It is a good practice to CLOSE a file after the last reference to it instead of waiting until job-end time. This will eliminate extra paging in a case where a DCB has been paged out and must be paged in when the data set is closed.
· A FILE STATUS key of 92 represents a logic error in the program processing the file: Typical logic errors include:
· attempting to read an unopened file
· attempting to read beyond end-of-file
· attempting to close a closed file
· attempting to open an opened file.
To obtain more information about the FILE STATUS key, see the IBM COBOL for MVS & VM Programming Guide, SC26-4767.
· Group items in WORKING-STORAGE according to their usage; items used together should be defined together.
· Define large tables either at the beginning or end of WORKING-STORAGE. Defining a large table in the middle results in unnecessarily separating other items by a large span of addresses.
· Use VALUE clauses for initialization of WORKING-STORAGE items whenever possible. This will provide for initialization at OBJECT time and eliminates execution time statements and potential unnecessary paging.
· Arrange the WORKING-STORAGE Section so that the most commonly used items are in the first 4096 bytes.
· Optimization and better locality of reference may be achieved by carefully selecting data types used. For example, avoid data conversion (and use of conversion subroutines) by comparing like items: COMP to COMP; COMP-3 to COMP-3.
· The generated code for conversion from external decimal (PIC 9) to binary (COMP) is particularly lengthy. Convert on a one-time basis if possible, e.g., move decimal data to a binary field and use it multiple times. External decimal data is always converted either to COMP or COMP-3 before it is used in an arithmetic operation.
· Always give COMP-3 items an uneven PICTURE length. An even PICTURE will cause an extra instruction to be generated.
· Define items used as counters as COMP, to avoid use of conversion routines.
· Use one-byte alpha-numeric data items for all switches and flags (PICTURE X).
· Avoid the use of figurative constants (SPACE OR ZERO) to initialize a multi-character data field:
77 G PIC X(3).
MOVE 'bbb' to G.
instead of:
MOVE SPACE to G.
· All arithmetic items should be signed.
· If the value of a subscript is being frequently incremented without looking up a table entry, use subscripts. If each time the subscript is incremented a value is looked up in the table, use indexing.
· Avoid numeric comparison of items of unequal number of decimal places.
· Avoid use of ON SIZE ERROR; instead, allow enough decimal places to contain the maximum field. Also avoid use of ROUNDED if possible.
· Use MULTIPLY instead of DIVIDE when possible:
MULTIPLY A BY .5 GIVING Q
instead of:
DIVIDE A BY 2 GIVING Q
· Use ADD instead of MULTIPLY.
ADD A TO A
instead of:
MULTIPLY 2 BY A
· Make all operands have the same number of decimal places for ADD and SUBTRACT statements:
77 H PIC S9(3)V99
ADD 3.50 TO H
instead of:
ADD 3.5 TO H
· Never multiply by ten or any multiple of ten; instead use a REDEFINES statement.
77 F PIC S9(5)V99.
77 F10 REDEFINES F PIC S9(6)V9.
· When using IF statements put the most likely condition first in an IF/OR and the least likely first in an IF/AND.
· Avoid the use of NEXT SENTENCE after the ELSE option of IF statements.
· Try not to use negative compound IF statements.
· Avoid the use of PERFORM statements where the PERFORMed paragraph is not close to the PERFORM statement. In-line code is better if not too large or too frequent.
· It is better to pass a single item to a subroutine (an 01 level with several elementary items) than to pass many individual items.
· Use the absolute value for subscripting whenever possible. If you want the first occurrence of TAX-REC use TAX-REC (1) instead of MOVE 1 to SUB, TAX-REC (SUB).
· Define numeric items used as subscripts as binary.
· Avoid the use of multi-level subscripted or indexed tables if at all possible.
· The WRITE BEFORE ADVANCING and WRITE AFTER ADVANCING options cause a carriage control character to be written in the first position of each record as follows:
AFTER ADVANCING |
ASA |
BEFORE ADVANCING |
machine |
If both BEFORE ADVANCING and AFTER ADVANCING are specified, machine control characters are written.
· ABENDs in Language Environment OS/390 & VM: An ABEND is still a problem of some type and the application will be notified of such a problem. There have been some changes in the way in which COBOL/MVS programs run. They now run in what is called a common execution environment, the actual name is Language Environment OS/390 & VM or LE for short. LE sets up the environment which includes acquiring memory, handling errors, and other functions. Before OS/VS COBOL did all these functions itself, and if it ran into a problem it simply gave the user a dump. With COBOL/MVS and LE you actually get more explicit information. COBOL/MVS identifies the problem even down to the statement level and notifies LE it found an application error. LE does not ABEND like OS/VS COBOL did, however it passes back to the user a return code indicating the application did not run as designed. In most cases a return code of U4038 will be issued. The U4038 means the application ended with a software raised or user raised condition of severity 2 or greater. The Computer Center has set the LE parameters to ensure a dump will be created when this happens.
· S001 ABEND - You might not see the S001 return code, however the return code will be something other than zero, probably U4038. Whether you get the original S001 error or U4038 really depends on who traps the error. If COBOL identifies the error you will get an IGZ message and a U4038 return code. If LE or maybe IMS traps the error you will probably continue to get the S001. Either way a dump will be produced.
· S0C7 ABEND - All programs which were converted from OS/VS COBOL must specify the NUMPROC(MIG) compiler option. Using this option will make the COBOL/MVS compiler generate code very similar to the old OS/VS COBOL code. Also the compiler will use numeric techniques when comparing two data items, as was the case with OS/VS COBOL. Two other options are available for sign processing, NUMPROC(PFD) and NUMPROC(NOPFD). If you use either of these two options (NUMPROC(NOPFD) is the default) with a program converted from OS/VS COBOL, some 0C7 conditions will be bypassed. Both of these options perform logical rather than numeric comparisons and both are performance enhancements, with NUMPROC(PFD) providing the greatest benefit. However it is the users responsibility to ensure valid sign positions in the data fields. Most OS/VS COBOL programs do not contain the proper numeric class test ( IF numeric ...) and depend on the S0C7 dump to catch invalid data. This is why all programs converted from OS/VS COBOL must be compiled with the NUMPROC(MIG) option to obtain the same results with COBOL/MVS.
· //SYSOUT Usage by LE - LE sends error messages and report data to the //SYSOUT DD statement. If you code a program that sends data to this same DD statement, your data and any errors detected by LE will be in the same file.
There are 2 ways to separate the LE information from your program data:
· Change the Select statement in the COBOL program to point to a different DD statement and add a new DD card to the JCL.
· LE provides users the option of changing the name changing the name of the DD statement where errors and report information will be sent. This is accomplished with the LE MSGFILE option. An example for the PROC CBL3CALL follows.
A couple of things to look out for - The "/" before the MSGFILE option indicates that all parameters after the / are for LE and not your program. You may use any DD name you want within the (), just make sure you also add the corresponding DD statement.
· In an OCCURS/DEPENDING clause, if a minimum number of occurrences is not specified, COBOL, assumes the minimum is 1. For example, consider the following statement:
05 VARLEN-FIELD OCCURS 5 TIMES DEPENDING ON OTHER-FIELD...
This would be the same as coding:
05 VARLEN-FIELD OCCURS 1 TO 5 TIMES DEPENDING ON
OTHER-FIELD ...
· DEBUG statements - If you decide to use the debug statements in your programs, simply placing the code in the program is not enough. You must also use the run-time DEBUG parameter. This is a LE parameter and not a program parameter. It is specified on the program execution JCL card as follows:
Anything before the "/" are program parameters and everything after are LE parameters.
· FILE STATUS 39 ERRORS - The ANSI 85 standards are very strict in this area. The Record Contains clause and the 01 Level Record must be the same as the LRECL in the DCB. Recording mode must also agree between the FD and the actual file. Be aware the 'ADV' compiler option will add one byte to the output file. Also if you read data from a TSO terminal you will need to put the LRECL on the ALLOCATE statement.
· Execution of COBOL/MVS programs interactively - When your program begins execution, a number of runtime modules may need to be accessed from a library called SYS1.SCEERUN. If you try to run your program interactively you will need to allocate this library. If you execute your program in the batch environment using the standard NIH procedures, you should not have a problem. The SYS1.SCEERUN library is referenced by the batch procedures.
· The SORTCNTL DD statement allows the user to modify the order and fields of an invoked sort dynamically at execution time. It can also be used to change or add SORT/MERGE control statements to programs that invoke the SORT/MERGE facility without having to recompile.
· Whenever possible, achieve maximum blocking flexibility by obtaining DCB information from the JCL or volume label rather than coding it directly in the program. The following example shows how a FD designed to define a data set with a blocking factor of 77 is modified to define a data set of any blocking factor.
specific blocksize:
FD CARD-IN
BLOCK CONTAINS 77 RECORDS
RECORD CONTAINS 80 CHARACTERS
any blocksize:
FD CARD-IN
BLOCK CONTAINS 0_/ RECORDS
The following figures show the ways data can be stored. The source language definitions for each data type are given under the COBOL, FORTRAN, and PL/I headings. For more specific information on data formats, consult the appropriate language manuals and the IBM manual ESA/390 Principles of Operation, SA22-7201.
The "MACHINE DATA FORMAT" column in the figures below shows a bit breakdown of the data type as stored internally. Bit positions are written vertically under the machine data format symbols they refer to.
CHARACTER
COBOL |
FORTRAN |
PL/I |
TYPE |
PIC X(n) DISPLAY 1<=n<=32767 |
CHARACTER*n 1<=n<=3267 |
CHAR(n) 1<=n<=32767 |
Length = n bytes |
MACHINE DATA FORMAT |
EXAMPLE | ||||
Char 1 |
Char 2 |
... |
Char n |
Value |
Internal hex representation |
0 0 - 0 7 |
0 1 - 8 5 |
ABCD |
C1C2C3C4 | ||
Figure 2. Character Formats for Inter-Language Communication
FIXED POINT
The fixed point two-word data type, which is available only in COBOL, is simulated through software and requires all data items to be aligned on a word boundary.
The "Range" given in the table indicates the minimum and maximum values numbers can have in all uses of the language. Idiosyncrasies in languages reduce the full range of numbers in some cases even though they are represented the same internally.
Assumed decimal points in COBOL and PL/I are not shown in the table. They are stored in the same way as other numbers; instructions generated by the compilers keep track of the position of the assumed decimal point.
COBOL |
FORTRAN |
PL/I |
TYPE |
PIC S9(1-4) COMP (or COMP-4) Range: -9999 to 9999 |
INTEGER*2 Range: -32768 to 32767 |
FIXED BIN (1-15,0) Range: -32768 to 32767 |
Halfword Length = 2 bytes. |
PIC S9(5-9) COMP (or COMP-4) Range: -(9)9s to +(9)9s |
INTEGER*4 Range: -2147483648 to 2147483647 |
FIXED BIN 16-31,0) Range: -2147483648 to 2147483647 |
Fullword Length =4 bytes. |
PIC S9(10-18) COMP (or COMP-4) Range: -(18)9s to +(18)9s |
----- |
----- |
Two-word Length = 8 bytes. |
Figure 3. Fixed Point Formats for Inter-Language Communication
MACHINE DATA FORMAT |
EXAMPLES | |
|
0 0 - 1 0 1 5 Halfword |
Value ----------+1234 -1234 |
Internal hex -------------------- 04D2 FB2E |
|
0 0 - 3 0 1 1 Fullword |
+1234 ---------- -1234 |
000004D2 --------------------- FFFFFB2E |
|
0 0 - 6 0 1 3 Two-word |
+1234 ---------- -1234 |
0...04D2 --------------------- F...FB2E |
"S" is a binary sign bit: 0 is positive; 1 is negative.
"I" is a 15, 31, or 63 bit integer.
Figure 4 (Continued)
FLOATING POINT
Magnitude is the range of a number expressed in powers of ten.
Although the numbers are represented the same internally, peculiarities in languages reduce the precision of numbers in some cases. The degree of precision given in the table is good in all cases. Fractional precisions occur because of the difference between the decimal representation and the machine's internal storage of numbers.
COBOL |
FORTRAN |
PL/I |
TYPE |
COMP-1 Magnitude: 10**-78 to 10**75 Precision: 7.2 digits |
REAL*4 Magnitude: 10**-78 to 10**75 Precision: 7.2 digits |
FLOAT DEC(1-6) Magnitude: 10**-78 to 10**75 Precision: 6 digits |
Short Length = 4 bytes |
COMP-2 Magnitude: 10**-78 to 10**75 Precision: 16 digits |
REAL*8 Magnitude: 10**-78 to 10**75 Precision: 16.8 digits |
FLOAT DEC(7-16) Magnitude: 10**-78 to 10**75 Precision: 16 digits |
Long Length = 8 bytes |
|
------ |
REAL*16 Magnitude: 10**-78 to 10**75 Precision: 35 digits |
FLOAT DEC(17-33) Magnitude: 10**-78 to 10**75 Precision: 33 digits |
Extended Length = 16 bytes |
Figure 4. Floating Point Formats for Inter-Language Communication
MACHINE DATA FORMAT |
EXAMPLES | |
|
0 0-0 0 - 3 0 1 7 8 1 Short |
Value ----------- +1234 ------------1234 |
Internal hex representation --------------------- 434D2000 --------------------- C34D2000 |
|
0 0-0 0 - 6 0 1 7 8 3 Long |
+1234 ----------- -1234 |
434D20...0 --------------------- C34D20...0 |
|
0 0-0 0 - 6 0 1 7 8 3 0 - 0 0 6 0 7 8 3 Extended |
+1234 ----------- -1234 |
434D20...0 --------------------- C34D20...0 |
"S" is a binary sign bit: 0 is positive; 1 is negative.
"E" is a seven bit exponent with a value between hex 16** -64 and 16** +63.
"F" is a fraction, which may be 24, 56, or 112 bits long.
Figure 4 (Continued)
ZONED DECIMAL
The "Range" given in the table indicates the minimum and maximum values numbers can have in all uses of the language. Idiosyncrasies in languages reduce the full range of numbers in some cases even though they are represented the same internally.
COBOL |
FORTRAN |
PL/I |
TYPE |
PIC 9(n) DISPLAY 1<=n<=18 Range: 0 to (18)9s |
------ |
PIC '(n)9' 1<=n<=15 Range: 0 to (15)9s |
Unsigned Length = n bytes. |
PIC S9(n) DISPLAY 1<=n<=18 Range: -(18)9s to +(18)9s |
------ |
PIC '(n-1)9T' 1<=n<=15 Range: -(15)9s to +(15)9s |
Signed Length = n bytes. |
MACHINE DATA FORMAT |
EXAMPLES | |
|
0-0 0-0 0-1 1-1 0 3 4 7 8 1 2 5 Unsigned |
Value ---------- 1234 |
Internal hex representation --------------------- F1F2F3F4 |
|
0-0 0-0 0-1 1-1 0 3 4 7 8 1 2 5 Signed |
+1234 ---------- -1234 |
F1F2F3C4 --------------------- F1F2F3D4 |
"Z" is a 4 bit zone code with a
value of hex F.
"D" is a 4 bit binary decimal
number with a value between hex 0 and 9.
"Si" is a 4 bit sign code: A, C, E, and F are positive; B and D are negative.
Figure 5. Zoned Decimal Formats for Inter-Language Communication
PACKED DECIMAL
The "Range" given in the table indicates the minimum and maximum values numbers can have in all uses of the language. Idiosyncrasies in languages reduce the full range of numbers in some cases even though they are represented the same internally.
COBOL |
FORTRAN |
PL/I |
TYPE |
COMP-3 PIC 9(n) 1<=n<=18 Range: -(18)9s to +(18)9s |
------ |
FIXED DEC(n) 1<=n<=15 Range: -(15)9s to +(15)9s |
Length in bytes = (n+1)/2 rounded up. |
MACHINE DATA FORMAT |
EXAMPLES | |
|
0-0 0-0 0 3 4 7 |
Value --------------- -1234 --------------- -1234 |
Internal hex representation --------------------- 01234C --------------------- 01234D |
"D" is a 4 bit binary
decimal number with a value hex 0 through 9.
"Si" is a 4 bit sign code: A, C, E,
and F are positive; B and D are negative.
Figure 6. Packed Decimal Formats for Inter-Language Communication