👁 0
Q: What is the difference between COMP and COMP-3 in COBOL?
Answer:
COMP (COMPUTATIONAL) - Pure binary format
- Stored in binary (base-2)
- Used for subscripts and counts
- Efficient for arithmetic operations
- PIC S9(4) COMP = 2 bytes
- PIC S9(9) COMP = 4 bytes
COMP-3 (PACKED DECIMAL)
- Each digit takes 4 bits (nibble)
- Last nibble holds sign
- Used for business calculations
- PIC S9(5) COMP-3 = 3 bytes
- Formula: (n+1)/2 rounded up
When to use:
- COMP - Array subscripts, counters, loops
- COMP-3 - Money, quantities, business data
👁 0
Q: How do I fix S0C7 Data Exception ABEND?
Answer:
S0C7 occurs when the program tries to perform arithmetic on non-numeric data.
Common Causes:
- Uninitialized numeric fields (contains spaces/garbage)
- Moving alphanumeric data to numeric field
- Reading file with wrong record layout
- Array subscript accessing wrong memory
How to Fix:
- Initialize all numeric fields to ZEROS
- Validate input before arithmetic
- Check file layouts match
- Use DISPLAY to debug field contents
* Always initialize
INITIALIZE WS-RECORD.
MOVE ZEROS TO WS-AMOUNT.
* Validate before use
IF WS-INPUT IS NUMERIC
COMPUTE WS-RESULT = WS-INPUT * 2
END-IF.
👁 0
Q: What is the difference between COMP and COMP-3?
Answer:
COMP (Binary) stores data in binary format, taking 2, 4, or 8 bytes. COMP-3 (Packed Decimal) stores two digits per byte with the sign in the last nibble, more efficient for decimal arithmetic. COMP is faster for calculations while COMP-3 saves space for large decimal numbers.
👁 0
Q: What is USAGE clause?
Answer:
USAGE specifies internal data representation. DISPLAY (default)=character, COMP/BINARY=binary, COMP-3/PACKED-DECIMAL=packed, COMP-1=single float, COMP-2=double float. Affects storage size and arithmetic performance.
👁 0
Q: Explain NULL handling in DB2
Answer:
NULL means unknown/missing value. NULL != NULL returns unknown. Use IS NULL, IS NOT NULL. COALESCE(col, default) substitutes. NULL in arithmetic yields NULL. Indicator variables detect NULL in COBOL. NVL function alternative.
👁 0
Q: How to handle date arithmetic?
Answer:
DATE + n DAYS adds days. DATE - n MONTHS subtracts months. DAYS(date2) - DAYS(date1) gives day count. DATEDIFF function available. TIMESTAMPDIFF for time differences. DATE/TIME functions for extraction.
👁 0
Q: What is CORRESPONDING in COBOL?
Answer:
CORRESPONDING (CORR) operates on fields with matching names. MOVE CORRESPONDING record-1 TO record-2 moves all matching fields. ADD CORRESPONDING does arithmetic. Reduces code but requires careful naming. Not recommended for performance-critical code.
👁 0
Q: Explain COMPUTE statement
Answer:
COMPUTE performs arithmetic with expression syntax. COMPUTE RESULT = (A + B) * C / D. Supports + - * / ** operators. ROUNDED option rounds result. ON SIZE ERROR handles overflow. Clearer than separate ADD/SUBTRACT/MULTIPLY/DIVIDE for complex formulas.
👁 0
Q: What is ON SIZE ERROR?
Answer:
ON SIZE ERROR traps arithmetic overflow. COMPUTE X = A + B ON SIZE ERROR PERFORM error-handler END-COMPUTE. Also NOT ON SIZE ERROR for success. Must be enabled (TRUNC option). Prevents abends from overflow conditions.
👁 0
Q: How to use SUBTRACT CORRESPONDING?
Answer:
SUBTRACT CORRESPONDING subtracts matching fields. SUBTRACT CORR group-1 FROM group-2. Each matching numeric field in group-2 decreased by corresponding group-1 value. Use ROUNDED and SIZE ERROR options. Limited to numeric fields.