IBM MAINFRAMES COBOL Training Class9 Usage Clause The
IBM MAINFRAMES COBOL Training Class-9
Usage Clause § The data can be stored in different format’s by using USAGE CLAUSE the programmer can defined the data storage and format of a particular field at the time of declaration. § Possible values for USAGE CLAUSE § Display (default) Character format. § Computation / COMP § COMP-1 § COMP-2 § COMP-3 (OR) Packed Decimal
Refreshing Basics § § § Nibble: 4 Bits Is One Nibble. Byte: 8 Bits Is One Byte. Half Word: 16 Bits Or 2 Bytes Is Half Word. Full Word: 32 Bits Or 4 Bytes Is Full Word. Double Word: 64 Bits Or 8 Bytes Is Double Word. § When we use display usage clause each character will store in a one byte
Computation COMP § In COMP data items the data stored is represented in Binary format. § PIC clause can contain S and 9 only. (V NOT ALLOWED) 01 WS-DATAITEM PIC § § S 9(10) COMP. The memory allocation will be as follows § S 9(01) – S 9(04) Half word Binary. § S 9(05) – S 9(09) Full word Binary. § S 9(10) - S 9(18) Double word Binary. Most significant bit is ON if the number is negative.
Computation COMP-1 and COMP-2 § COMP-1 is used for Single word floating point item. This will occupy 4 bytes § COMP-2 is used for declaring Double word floating-point item. This will occupy 8 bytes § PIC Clause should not be specified for both COMP-1 and COMP-2.
Computation COMP-3 § COMP-3 is used to store the data in Packed Decimal/ hexadecimal representation. § § § In this Two digits are stored in each byte. § Memory calculation is done with the Formula PIC clause can contain S, V and 9. Last nibble is for sign. (F for unsigned positive, C for signed positive and D for signed negative) , Least significant bit is ON if the number is negative § S 9(N) COMP-3 § For Even number (N/2) + 1 FOR ODD number (N+1)/2.
Difference between COMP & COMP-3 1. Comp is a binary usage, while comp-3 indicates packed decimal. 2. In comp only S and 9 are allowed, while in COMP-3 S , 9 and V are allowed 3. For higher boundaries comp is better where as comp-3 for lower boundaries 4. For comp the maximum bytes can be 8 bytes, where as for comp-3 it would be __ bytes? 5. For comp the sign bit is stored at Most Significant Bit where as for comp-3 the sign is stored at Least Significant Bit.
Sync Clause & Slack Byte § SYNC clause is specified with COMP, COMP-1 and COMP-2 items. These items are expected to start at half/full/double word boundaries for faster address resolution. SYNC clause does this but it may introduce slack bytes (unused bytes) before the binary item. 01 WS-TEST. 10 WS-VAR 1 PIC X(02). 10 WS-VAR 2 PIC S 9(6) COMP SYNC.
Thank You Polsani Anil Kumar
- Slides: 9