👁 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 are the four divisions of a COBOL program?
Answer:
- IDENTIFICATION DIVISION - Program identification (PROGRAM-ID)
- ENVIRONMENT DIVISION - Hardware/software environment, file assignments
- DATA DIVISION - Data definitions (FILE, WORKING-STORAGE, LINKAGE SECTION)
- PROCEDURE DIVISION - Executable code and business logic
Only IDENTIFICATION and PROCEDURE DIVISION are mandatory.
👁 0
Q: What is the difference between SECTION and PARAGRAPH in COBOL?
Answer:
SECTION:
- Contains one or more paragraphs
- Ends with next SECTION or end of program
- Used for logical grouping
- Can be performed as a unit
PARAGRAPH:
- Basic unit of code
- Named block of statements
- Ends at next paragraph name or SECTION
PERFORM SECTION-NAME executes all paragraphs in the section.
PERFORM PARA-NAME executes only that paragraph.
👁 0
Q: Explain REDEFINES clause with an example.
Answer:
REDEFINES allows the same storage area to be referenced by different data names with different definitions.
Rules:
- Must be at same level as item being redefined
- Cannot redefine item with OCCURS
- Redefined item must appear first
- Lengths should match or redefining should be shorter
01 WS-DATE. 05 WS-DATE-NUM PIC 9(8). 01 WS-DATE-X REDEFINES WS-DATE. 05 WS-YEAR PIC 9(4). 05 WS-MONTH PIC 9(2). 05 WS-DAY PIC 9(2).
Same 8 bytes can be accessed as single number or individual components.
👁 0
Q: What is a copybook and why is it used?
Answer:
A copybook is a reusable code file that can be included in multiple programs using the COPY statement.
Uses:
- Standard record layouts
- Common working storage definitions
- Reusable paragraphs
- Ensures consistency across programs
Syntax:
COPY EMPREC. COPY EMPREC REPLACING ==EMP== BY ==WS-EMP==.
Benefits:
- Reduces code duplication
- Easier maintenance
- Standard definitions across team
👁 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 causes S0C7 abend and how to fix it?
Answer:
S0C7 (Data Exception) occurs when non-numeric data is used in numeric operations. Common causes: uninitialized fields, incorrect data from files, wrong REDEFINES. Fix by: initializing variables, validating input data, using INSPECT/NUMVAL functions, checking file data quality.
👁 0
Q: How to handle variable length records?
Answer:
Use RECORD CONTAINS min TO max CHARACTERS clause in FD. Define RECORD-LENGTH field in the record. For VSAM, use RECORD VARYING IN SIZE. Access actual length via LENGTH OF or special register. Handle both fixed and variable portions appropriately.
👁 0
Q: Explain STRING and UNSTRING operations
Answer:
STRING concatenates multiple fields into one: STRING field-1 DELIMITED BY SPACE field-2 INTO output-field. UNSTRING splits one field into multiple: UNSTRING input-field DELIMITED BY ',' INTO field-1 field-2. Both support POINTER for position tracking and OVERFLOW handling.
👁 0
Q: How does INSPECT work?
Answer:
INSPECT examines/modifies string contents. INSPECT field TALLYING counter FOR ALL 'X'. INSPECT field REPLACING ALL 'A' BY 'B'. INSPECT field CONVERTING 'abc' TO '123'. Useful for data validation, transformation, and counting characters.
👁 0
Q: What is 88-level condition name?
Answer:
88-level defines condition names for field values. 01 WS-STATUS PIC X. 88 VALID-STATUS VALUE 'Y'. 88 INVALID-STATUS VALUE 'N'. Use in IF: IF VALID-STATUS. Set using SET VALID-STATUS TO TRUE. Makes code self-documenting.
👁 0
Q: Explain REDEFINES clause usage
Answer:
REDEFINES allows multiple data descriptions for same memory. 01 WS-DATE PIC 9(8). 01 WS-DATE-R REDEFINES WS-DATE. 05 WS-YEAR PIC 9(4). 05 WS-MONTH PIC 99. 05 WS-DAY PIC 99. Cannot redefine with larger size. Useful for different views of data.
👁 0
Q: Explain SECTION vs PARAGRAPH
Answer:
SECTION groups related paragraphs, terminated by next SECTION or end of program. PARAGRAPH is a named block of code, terminated by next paragraph/section. PERFORM SECTION executes all paragraphs within. SECTION needed for segmentation, PARAGRAPH for simple procedures.
👁 0
Q: What is RENAMES clause?
Answer:
RENAMES (66-level) creates alternative groupings of elementary items. 01 REC. 05 FIELD-A PIC X(5). 05 FIELD-B PIC X(5). 05 FIELD-C PIC X(5). 66 FIELDS-AB RENAMES FIELD-A THRU FIELD-B. Provides different data views without memory overhead.
👁 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 use CONTINUE statement?
Answer:
CONTINUE is a no-operation placeholder. Useful in EVALUATE when certain conditions need no action: WHEN 'X' CONTINUE. In IF: IF condition CONTINUE ELSE action. Maintains structure without dummy statements. Not a GOTO target.
👁 0
Q: Explain START statement for VSAM
Answer:
START positions for sequential READ. START filename KEY IS EQUAL/GREATER/NOT LESS THAN key-field. After successful START, READ NEXT retrieves records sequentially from that position. INVALID KEY handles not-found condition.
👁 0
Q: How to handle packed decimal data?
Answer:
Packed decimal (COMP-3) stores 2 digits per byte, sign in low nibble. PIC S9(5) COMP-3 uses 3 bytes. For I/O, often must convert to display. Use MOVE to display field or NUMVAL function. Handle sign separately if needed.
👁 0
Q: Explain PROCEDURE DIVISION USING
Answer:
PROCEDURE DIVISION USING defines parameters for called program. Parameters match LINKAGE SECTION definitions. Order matches calling program's USING clause. Establishes addressability to passed data. BY REFERENCE/VALUE/CONTENT options inherited from CALL.
👁 0
Q: What is GLOBAL clause?
Answer:
GLOBAL makes data available to nested programs. 01 WS-COUNTER PIC 9(5) GLOBAL. Nested programs can reference without passing as parameters. Use sparingly; explicit passing preferred. File definitions can also be GLOBAL.
👁 0
Q: What is MOVE CORRESPONDING?
Answer:
MOVE CORRESPONDING moves all fields with matching names between groups. MOVE CORR INPUT-REC TO OUTPUT-REC. Only moves if names match exactly. Moves all matches, not just first. Useful for record transformations. Debug carefully-silent partial moves.
👁 0
Q: Explain EXTERNAL clause
Answer:
EXTERNAL allows data sharing between separately compiled programs. 01 WS-SHARED PIC X(100) EXTERNAL. All programs with same EXTERNAL name share same storage. Use for global data without passing parameters. Be careful with initialization.
👁 0
Q: What is SAME RECORD AREA?
Answer:
SAME RECORD AREA clause specifies files share buffer: SAME RECORD AREA FOR FILE-1 FILE-2. Records of different files occupy same memory. Reading one file overlays other's record. Saves memory but requires careful coding.
👁 0
Q: Explain JUSTIFIED RIGHT clause
Answer:
JUSTIFIED RIGHT aligns alphanumeric receiving field contents to right. 05 WS-NAME PIC X(10) JUSTIFIED RIGHT. MOVE 'ABC' TO WS-NAME gives ' ABC'. Default is left justified. Only for alphanumeric elementary items.
👁 0
Q: What is RECORDING MODE for files?
Answer:
RECORDING MODE specifies record format: F=fixed, V=variable, U=undefined, S=spanned. RECORDING MODE IS V for variable records. Affects how records are blocked and how length is tracked. Must match JCL DCB specifications.
👁 0
Q: How to handle EBCDIC/ASCII conversion?
Answer:
COBOL on mainframe uses EBCDIC natively. For ASCII conversion: use INSPECT CONVERTING, or file translation (JCL), or LE functions. NATIONAL-OF and DISPLAY-OF for Unicode. Different collating sequences affect SORT and comparisons.
👁 0
Q: What is ORGANIZATION clause?
Answer:
ORGANIZATION specifies file structure: SEQUENTIAL (default), INDEXED (VSAM KSDS), RELATIVE (RRDS). Determines access methods available. INDEXED requires RECORD KEY. ACCESS MODE can be SEQUENTIAL, RANDOM, or DYNAMIC.
👁 0
Q: How to use EXIT PERFORM?
Answer:
EXIT PERFORM immediately exits current PERFORM loop. EXIT PERFORM CYCLE skips to next iteration. COBOL 2002+ feature. Previously used GO TO with OUT-OF-PARAGRAPH technique. Makes loop control cleaner without extra flags.
👁 0
Q: What is PIC clause editing?
Answer:
Picture editing characters: Z=zero suppress, *=check protect, +=sign, -=negative, CR/DB=credit/debit, $=currency, .=decimal, ,=comma, B=blank. Example: PIC ,ZZ9.99- displays $ 123.45-. Insertion characters add to display.
👁 0
Q: Explain EXEC SQL statements
Answer:
EXEC SQL marks embedded DB2 SQL. EXEC SQL SELECT col INTO :host-var FROM table WHERE key = :key-var END-EXEC. Colon prefix for host variables. SQLCODE in SQLCA indicates result. Precompiler converts to COBOL calls.
👁 0
Q: How to handle OCCURS INDEXED tables?
Answer:
Indexed tables use INDEXED BY: 05 TBL OCCURS 10 INDEXED BY IDX. SET IDX TO 1 initializes. SET IDX UP BY 1 increments. SEARCH uses index implicitly. More efficient than subscript-index conversion.
👁 0
Q: Explain WRITE BEFORE/AFTER ADVANCING
Answer:
ADVANCING controls line spacing for print files. WRITE rec AFTER ADVANCING 2 LINES skips 2 lines first. WRITE rec BEFORE ADVANCING PAGE starts new page after. WRITE rec AFTER PAGE goes to new page first. Controls report formatting.
👁 0
Q: What is USE BEFORE REPORTING?
Answer:
In Report Writer, USE BEFORE REPORTING procedure runs before printing. USE BEFORE REPORTING report-group-name. Allows dynamic modification of report data. Can suppress or modify lines based on runtime conditions.
👁 0
Q: How to use STRING with POINTER?
Answer:
STRING uses POINTER to track position: STRING field-1 DELIMITED SIZE INTO output WITH POINTER pos-var. Pointer shows next available position. Initialize before first STRING. Check for overflow. Continue STRING in multiple statements.
👁 0
Q: What is PERFORM recursion limit?
Answer:
COBOL doesn't traditionally support recursion; same paragraph in PERFORM stack causes error. RECURSIVE clause in PROGRAM-ID enables it. Recursive programs need local storage. Stack depth limited by system resources. Usually avoid in COBOL.
👁 0
Q: Explain DEBUGGING declarative
Answer:
USE FOR DEBUGGING enables debug procedures. Requires WITH DEBUGGING MODE. Triggers on: ALTER, PERFORM, GO TO, or reference to debug item. Displays data values and flow. Object code excluded unless compiled with DEBUG option.
👁 0
Q: Explain DE-EDIT function
Answer:
FUNCTION DE-EDIT converts edited numeric back to numeric. Original: '1,234.56-'. DE-EDIT result: -1234.56. Removes edit characters, preserves numeric value and sign. Useful when receiving edited display data needing calculation.
👁 0
Q: What is OBJECT-COMPUTER paragraph?
Answer:
OBJECT-COMPUTER describes execution machine. OBJECT-COMPUTER. IBM-3090. MEMORY SIZE clause deprecated. PROGRAM COLLATING SEQUENCE for sort order. SEGMENT-LIMIT for overlay. Mostly documentation now; compiler usually ignores.
👁 0
Q: What is READY TRACE?
Answer:
READY TRACE turns on paragraph tracing. Shows paragraph names as executed. RESET TRACE turns off. Must compile with debugging option. Output goes to SYSOUT. Replaced by better debuggers but useful for quick flow analysis.
👁 0
Q: How to use UNSTRING with TALLYING?
Answer:
UNSTRING field-1 DELIMITED BY ',' INTO field-2 field-3 TALLYING IN count-var. Count-var shows how many receiving fields got data. With COUNT IN, tracks characters per field. ALL delimiter allows multiple consecutive delimiters as one.
👁 0
Q: Explain SYMBOLIC CHARACTERS
Answer:
SPECIAL-NAMES. SYMBOLIC CHARACTERS NULL-CHAR IS 1. Assigns name to ordinal position in collating sequence. Position 1 is X'00' in EBCDIC. Use: MOVE NULL-CHAR TO field. Define non-printable characters readably.
👁 0
Q: What is ALTER statement?
Answer:
ALTER changes GO TO target dynamically. ALTER para-1 TO PROCEED TO para-2. Obsolete-causes maintenance nightmares. Makes flow unpredictable. Use EVALUATE or SET/IF instead. Some shops prohibit. Still legal but strongly discouraged.
👁 0
Q: How to use PERFORM EXIT?
Answer:
EXIT statement marks paragraph end. PERFORM PROCESS-DATA THRU PROCESS-EXIT. Process-exit paragraph contains only EXIT. Ensures consistent exit point. Can also GO TO exit paragraph. EXIT PROGRAM in subprogram returns to caller.
👁 0
Q: What is LOCAL-STORAGE SECTION?
Answer:
LOCAL-STORAGE SECTION is reinitialized each invocation. Unlike WORKING-STORAGE which retains values. Each thread gets own copy. Useful for recursive programs and threaded environments. COBOL-85+ feature. Not all compilers support equally.
👁 0
Q: Explain COPY REPLACING
Answer:
COPY copybook REPLACING ==:TAG:== BY ==WS-==. Substitutes text during copy. Pseudo-text delimiters ==. Can replace identifiers, literals, words. Multiple REPLACING clauses allowed. Useful for generic copybooks.
👁 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 EXEC CICS structure?
Answer:
EXEC CICS marks CICS commands. EXEC CICS READ FILE('name') INTO(area) RIDFLD(key) END-EXEC. Commands: READ, WRITE, SEND, RECEIVE, LINK, XCTL. RESP and RESP2 capture return codes. Translator converts to CALL.
👁 0
Q: How to use FUNCTION CURRENT-DATE?
Answer:
FUNCTION CURRENT-DATE returns 21-char timestamp. Format: YYYYMMDDHHMMSSDHHMM (D=hundredths, HH=GMT offset). MOVE FUNCTION CURRENT-DATE TO WS-TIMESTAMP. Parse components with reference modification or REDEFINES.
👁 0
Q: What is XML GENERATE?
Answer:
XML GENERATE creates XML from data. XML GENERATE output FROM data-item. Optional: COUNT IN length, WITH ENCODING, WITH XML-DECLARATION. Generates element for each field. Names from data names. COBOL 5+ feature.
👁 0
Q: How to define FILE-CONTROL?
Answer:
SELECT file-name ASSIGN TO ddname. ORGANIZATION IS INDEXED. ACCESS MODE IS DYNAMIC. RECORD KEY IS key-field. ALTERNATE RECORD KEY IS alt-key. FILE STATUS IS ws-status. Maps COBOL file to physical dataset.
👁 0
Q: Explain PERFORM VARYING with example
Answer:
PERFORM VARYING executes a paragraph while incrementing a counter. Syntax: PERFORM para-name VARYING WS-IDX FROM 1 BY 1 UNTIL WS-IDX > 10. The counter is initialized, tested, and incremented automatically. Can have nested VARYING with AFTER clause.
👁 0
Q: What is the purpose of COPY statement?
Answer:
COPY includes copybook members at compile time, promoting code reuse and standardization. Syntax: COPY copybook-name. REPLACING clause allows field substitution. Copybooks typically contain record layouts, working-storage definitions, and common routines.
👁 0
Q: What is EVALUATE statement and when to use it?
Answer:
EVALUATE is COBOL's case/switch construct. Syntax: EVALUATE TRUE WHEN condition-1 statement WHEN OTHER default END-EVALUATE. More readable than nested IF for multiple conditions. Can evaluate multiple subjects and use THRU for ranges.
👁 0
Q: What is INITIALIZE and its options?
Answer:
INITIALIZE sets fields to default values: alphabetic to spaces, numeric to zeros. Options: REPLACING NUMERIC BY value, REPLACING ALPHANUMERIC BY value. Does not initialize FILLER or REDEFINES items. Useful for clearing record areas before processing.
👁 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: How to use OCCURS DEPENDING ON?
Answer:
OCCURS DEPENDING ON creates variable-length tables. 01 WS-TABLE. 05 WS-COUNT PIC 99. 05 WS-ITEM OCCURS 1 TO 100 DEPENDING ON WS-COUNT. Only variable entries allocated based on counter. Used with variable length records.
👁 0
Q: What is FILE STATUS and common codes?
Answer:
FILE STATUS is a 2-byte field capturing I/O operation results. 00=success, 10=end-of-file, 22=duplicate key, 23=record not found, 35=file not found, 39=file attribute mismatch, 41=file already open, 47=not opened input. Essential for error handling.
👁 0
Q: How does ACCEPT and DISPLAY work?
Answer:
ACCEPT reads from console/system: ACCEPT WS-DATE FROM DATE, ACCEPT WS-INPUT FROM CONSOLE. DISPLAY writes to console: DISPLAY 'Message' WS-FIELD. UPON clause specifies destination. Limited in batch; mainly for debugging or simple interaction.
👁 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 SORT and MERGE in COBOL?
Answer:
SORT orders records: SORT SORT-FILE ON ASCENDING KEY-FIELD USING INPUT-FILE GIVING OUTPUT-FILE. INPUT/OUTPUT PROCEDURE allows processing during sort. MERGE combines pre-sorted files: MERGE SORT-FILE ON KEY USING FILE-1 FILE-2 GIVING OUTPUT-FILE.
👁 0
Q: How to define and use indexes?
Answer:
INDEX defined with OCCURS: 05 WS-TABLE OCCURS 10 INDEXED BY WS-IDX. SET WS-IDX TO 5 sets position. SET WS-IDX UP/DOWN BY 1 changes position. Use SEARCH verb with index. More efficient than subscripts for table access.
👁 0
Q: What is DECLARATIVES section?
Answer:
DECLARATIVES contains USE procedures for exception handling. USE AFTER ERROR PROCEDURE ON file-name handles file errors. USE AFTER EXCEPTION handles specific conditions. Must be first in PROCEDURE DIVISION. END DECLARATIVES marks end.
👁 0
Q: Explain CALL statement and parameters
Answer:
CALL invokes subprogram: CALL 'SUBPROG' USING param-1 param-2. BY REFERENCE (default) passes address. BY CONTENT passes copy. BY VALUE passes value (for C). ON EXCEPTION handles load failures. CANCEL releases memory.
👁 0
Q: What is LINKAGE SECTION?
Answer:
LINKAGE SECTION defines parameters received from calling program. Items here have no memory until CALL provides addresses via USING clause. Address established at runtime. Used for both passed parameters and dynamically addressed data.
👁 0
Q: What are nested programs?
Answer:
Nested programs are contained within another COBOL program. Defined between IDENTIFICATION DIVISION and END PROGRAM. Can access outer program's data with GLOBAL clause. COMMON attribute allows access from sibling programs. Promotes modular design.
👁 0
Q: What is GOBACK vs STOP RUN?
Answer:
STOP RUN terminates entire run unit (all programs). GOBACK returns to caller; if main program, acts like STOP RUN. Use GOBACK in subprograms to return control. STOP RUN from subprogram ends everything unexpectedly.
👁 0
Q: What is reference modification?
Answer:
Reference modification extracts substring: WS-FIELD(start:length). WS-NAME(1:3) gets first 3 characters. Can use in MOVE, IF, DISPLAY. Start position is 1-based. Length optional (to end). More flexible than REDEFINES for variable positions.
👁 0
Q: How to work with OCCURS indexed tables?
Answer:
Define: 01 WS-TABLE. 05 WS-ENTRY OCCURS 100 INDEXED BY WS-IDX. 10 WS-NAME PIC X(20). 10 WS-VALUE PIC 9(5). Access: MOVE WS-NAME(WS-IDX) TO output. Search: SEARCH WS-ENTRY WHEN WS-NAME(WS-IDX) = 'VALUE' perform action.
👁 0
Q: How to use intrinsic functions?
Answer:
COBOL-85 intrinsic functions: FUNCTION LENGTH(field), FUNCTION CURRENT-DATE, FUNCTION UPPER-CASE(field), FUNCTION NUMVAL(field), FUNCTION MOD(a,b), FUNCTION INTEGER-OF-DATE(date). Use in expressions or with COMPUTE. Return values only, no side effects.
👁 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: Explain ALTERNATE RECORD KEY
Answer:
ALTERNATE RECORD KEY defines secondary indexes for INDEXED files. SELECT file-name ALTERNATE RECORD KEY IS ALT-KEY WITH DUPLICATES. Allows access by multiple keys. DUPLICATES permits non-unique values. Define path in VSAM cluster.
👁 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: What is VALUE clause?
Answer:
VALUE initializes data items. 05 WS-FLAG PIC X VALUE 'Y'. 05 WS-COUNT PIC 9(3) VALUE ZEROS. 05 WS-TABLE OCCURS 5 VALUE 'INIT'. Figurative constants: SPACES, ZEROS, LOW-VALUES, HIGH-VALUES, QUOTES. Cannot use with REDEFINES target.
👁 0
Q: Explain BLANK WHEN ZERO clause
Answer:
BLANK WHEN ZERO displays spaces when numeric field contains zero. 05 WS-AMOUNT PIC Z(5)9.99 BLANK WHEN ZERO. Shows blank instead of 0.00. Only for numeric-edited or numeric display fields. Improves report readability.
👁 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.
👁 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: What is POINTER data type?
Answer:
USAGE POINTER stores memory addresses. SET ptr TO ADDRESS OF data. Used with SET ADDRESS OF linkage-item TO ptr. CALL with BY REFERENCE returns addresses. Supports dynamic memory and chained structures.
👁 0
Q: What is OPEN mode options?
Answer:
OPEN INPUT for read, OUTPUT for write (creates), I-O for read/update, EXTEND for append. Multiple files per OPEN. OPEN OUTPUT deletes existing file! EXTEND preserves and adds. File must be closed before reopening in different mode.
👁 0
Q: What is REPLACE statement?
Answer:
REPLACE substitutes text during compilation. REPLACE ==OLD-TEXT== BY ==NEW-TEXT==. Active until REPLACE OFF or next REPLACE. Useful with copybooks for site-specific modifications. Different from COPY REPLACING-more global.
👁 0
Q: How does PERFORM THRU work?
Answer:
PERFORM para-1 THRU para-2 executes from para-1 through para-2 inclusive. Paragraphs must be contiguous. Common: PERFORM 1000-INIT THRU 1000-EXIT where EXIT paragraph has only EXIT. Ensures cleanup code always runs.
👁 0
Q: What is OPTIONAL file clause?
Answer:
OPTIONAL allows missing files: SELECT OPTIONAL input-file. OPEN succeeds even if file absent. READ immediately gets end-of-file. Useful for conditional processing. FILE STATUS 35 if accessed without OPTIONAL.
👁 0
Q: Explain SPECIAL-NAMES paragraph
Answer:
SPECIAL-NAMES maps system names to COBOL names. DECIMAL-POINT IS COMMA for European notation. CURRENCY SIGN IS '$'. SYMBOLIC CHARACTERS name = value. ALPHABET for custom collating. CLASS for character groups.
👁 0
Q: Explain condition-name SET TRUE
Answer:
SET condition-name TO TRUE assigns the condition's VALUE. If 88 ACTIVE VALUE 'A', SET ACTIVE TO TRUE moves 'A' to parent. Cleaner than MOVE 'A' TO STATUS. Makes code self-documenting. Multiple values take first.
👁 0
Q: What is APPLY WRITE-ONLY?
Answer:
APPLY WRITE-ONLY FOR file-name optimizes output buffer handling. System doesn't preserve record area after WRITE. Can't re-read just-written record. Improves I/O performance. Use when write-only access pattern is guaranteed.
👁 0
Q: How to define group level items?
Answer:
Group items contain subordinate items. 01 WS-DATE. 05 WS-YEAR PIC 9(4). 05 WS-MONTH PIC 99. 05 WS-DAY PIC 99. Group is alphanumeric regardless of contents. MOVE WS-DATE moves all 8 bytes. Reference individual or group.
👁 0
Q: What is BLOCK CONTAINS clause?
Answer:
BLOCK CONTAINS defines blocking factor. BLOCK CONTAINS 10 RECORDS or BLOCK CONTAINS 800 CHARACTERS. 0 RECORDS means system-determined. Affects I/O performance-larger blocks fewer I/Os. Must match JCL/VSAM definition.
👁 0
Q: What is LABEL RECORDS clause?
Answer:
LABEL RECORDS specifies header/trailer labels. STANDARD (default) for labeled tapes. OMITTED for unlabeled or disk. Now less relevant-mostly tapes. Compiler may accept but ignore for disk files. Required in some older programs.
👁 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.
👁 0
Q: What is CLASS condition?
Answer:
CLASS tests character content. IF field IS NUMERIC/ALPHABETIC/ALPHABETIC-LOWER/ALPHABETIC-UPPER. Custom classes in SPECIAL-NAMES: CLASS VOWELS IS 'A' 'E' 'I' 'O' 'U'. Then IF char IS VOWELS. Useful for validation.
👁 0
Q: What is CURSOR IS clause?
Answer:
In Screen Section, CURSOR IS field-name positions cursor. ACCEPT screen-name WITH CURSOR. Runtime positions to specified field. Can set dynamically. Used in interactive COBOL (CICS typically handles cursor differently).
👁 0
Q: How to handle negative numbers?
Answer:
Sign stored in PIC S9. SIGN IS LEADING/TRAILING SEPARATE CHARACTER for explicit sign byte. COMP-3 sign in low nibble. Display: S9(5)- shows trailing minus. +9(5) shows sign always. DB/CR for accounting format.
👁 0
Q: Explain ENTRY statement
Answer:
ENTRY creates alternate entry point in subprogram. ENTRY 'ALTNAME' USING params. Called program appears under different name. Useful for multiple functions in one load module. Each ENTRY has own parameters. Not standard-use carefully.
👁 0
Q: What is SERVICE RELOAD?
Answer:
SERVICE RELOAD refreshes segmented program overlays. Forces segment reload from disk. Rarely needed with virtual storage. From overlay management era. May affect performance. Better to restructure program than use frequently.
👁 0
Q: What is TITLE statement?
Answer:
TITLE 'Page Header' sets listing page headers. Appears on each page of compilation listing. Useful for documentation. Multiple TITLES change as encountered. After IDENTIFICATION DIVISION start. Compiler directive, not executable.
👁 0
Q: How to define OCCURS ASCENDING?
Answer:
05 TABLE OCCURS 100 ASCENDING KEY IS CODE-FIELD INDEXED BY IDX. 10 CODE-FIELD PIC X(5). 10 DATA-FIELD PIC X(20). ASCENDING means lower values first. Required for SEARCH ALL. DESCENDING also available. Key must be within occurrence.
👁 0
Q: Explain IDENTIFICATION DIVISION
Answer:
IDENTIFICATION DIVISION identifies program. PROGRAM-ID required (up to 8 chars for compatibility). AUTHOR, DATE-WRITTEN, DATE-COMPILED, REMARKS are documentation. INSTALLATION for deployment info. Only PROGRAM-ID affects compilation.
👁 0
Q: What is WORKING-STORAGE SECTION?
Answer:
WORKING-STORAGE SECTION declares program variables. Initialized at program load. Retains values between CALL invocations unless INITIAL program. Define all work areas, flags, counters, tables here. 01-49 levels for data, 77 for independent items.
👁 0
Q: What is COLLATING SEQUENCE?
Answer:
PROGRAM COLLATING SEQUENCE IS sequence-name. Affects comparisons and SORT order. Define custom alphabet in SPECIAL-NAMES. Standard is NATIVE (EBCDIC). ASCII for ASCII order. STANDARD-1 for ASCII collating.
👁 0
Q: Explain ALPHABET clause
Answer:
ALPHABET defines custom collating sequence. ALPHABET MY-SEQ IS 'A' THRU 'Z' 'a' THRU 'z'. Or ALPHABET ASCII IS STANDARD-1. Use with COLLATING SEQUENCE. Affects string comparisons and SORT. Define in SPECIAL-NAMES.
👁 0
Q: What is TALLY special register?
Answer:
TALLY is predefined counter for EXAMINE (obsolete verb). Some code still references it. INSPECT replaced EXAMINE. Not recommended for new code. TALLY is global, can conflict. Define your own counters instead.
👁 0
Q: Explain FUNCTION LENGTH
Answer:
FUNCTION LENGTH returns byte count. FUNCTION LENGTH(field-name). For group items, includes all subordinates. For variable OCCURS, actual current length. Use in COMPUTE, MOVE, comparisons. Often used with STRING pointer initialization.
👁 0
Q: What is PROCEDURE-POINTER?
Answer:
USAGE PROCEDURE-POINTER stores program addresses. SET proc-ptr TO ENTRY 'PROGNAME'. CALL proc-ptr. Enables dynamic program selection. Similar to function pointers. Used in table-driven designs. Check ADDRESS OF for validity.
👁 0
Q: What is RETURN-CODE register?
Answer:
RETURN-CODE sets program completion status. MOVE 0 TO RETURN-CODE (success). MOVE 8 TO RETURN-CODE (warning). Passed to caller/JCL. Check RETURN-CODE after CALL. LE uses CEE3STS for detailed status.
👁 0
Q: Explain JSON GENERATE
Answer:
JSON GENERATE creates JSON from data. JSON GENERATE output FROM data-item. NAME clause for custom keys. SUPPRESS clause omits fields. COUNT IN length. COBOL V6+ feature. Generates name-value pairs from structure.