👁 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: 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: How does SEARCH ALL differ from SEARCH?
Answer:
SEARCH performs a sequential/linear search from the current index position. SEARCH ALL performs a binary search requiring the table to be sorted (ASCENDING/DESCENDING KEY clause) and indexed. SEARCH ALL is faster for large tables but requires sorted data.
👁 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: How to handle binary data?
Answer:
COMP/BINARY stores binary. PIC S9(4) COMP is halfword (2 bytes). PIC S9(9) COMP is fullword (4 bytes). PIC S9(18) COMP is doubleword (8 bytes). SYNC aligns for performance. Value range limited by bytes, not picture.
👁 0
Q: What is ERASE on DELETE?
Answer:
ERASE overwrites data with binary zeros. Physical erase before space release. Security requirement for sensitive data. Takes time. Without ERASE, data remains until overwritten.
👁 0
Q: What is FILEDATA parameter?
Answer:
FILEDATA specifies DCB for NFS/USS. FILEDATA=TEXT or BINARY. TEXT handles line endings. BINARY transfers unchanged. On PATH DD statements. Affects how data converted between systems.
👁 0
Q: What is SYNCHRONIZED clause?
Answer:
SYNCHRONIZED aligns binary items on natural boundaries for efficient access. 01 WS-GROUP. 05 WS-CHAR PIC X. 05 WS-BINARY PIC S9(8) COMP SYNC. Adds slack bytes as needed. Can waste space but improves performance. RIGHT/LEFT options available.
👁 0
Q: What is NATIVE-BCD?
Answer:
NATIVE-BCD is native binary-coded decimal, digits stored one per byte. Less efficient than COMP-3 but simpler to inspect in dumps. Some shops prefer for debugging. Available through compiler options or USAGE clause variations.
👁 0
Q: How to define table with KEY?
Answer:
For binary search, tables need KEY: 05 WS-TABLE OCCURS 100 ASCENDING KEY WS-CODE INDEXED BY WS-IDX. 10 WS-CODE PIC X(5). 10 WS-DESC PIC X(20). SEARCH ALL requires sorted data per KEY. Multiple keys for complex sorts.