COBOL Realtime (Scenario based) Interview Questions (21 - 30)

21. Can we declare a variable with 05 level number without having 01 declared before?

A 05 level variable cannot exist independently; it must always be inside an 01 level structure.

01 WS-GROUP.
   05 WS-NAME PIC X(10).

22. What is the difference between 01 and 49 level number?

FeatureLevel 01Level 49
PurposeDefines a new or a standalone variable.Used to define a individual variable that can't be divided further.
GroupingCan contain subfields (05, 10, etc.). Cannot have subordinate levels.
Requires Parent?No, 01 can exist independently.Yes, 49 must be inside an 01 group and redefine an item.
Example
01 WS-DATA. 
	05 WS-NAME PIC X(10).
01 WS-DATA. 
	...
	49 WS-ORIG PIC X(10).

23. Which variables do not have PICTURE clause?

  • Index variables
  • RENAMES clause
  • Internal floating-point variables
  • 88-level number
  • COMP-1 and COMP-2 variables

24. What is the maximum length of alphabetic or aplha-numeric data type?

Alphabetic (A) data type maximum length: PIC A(255) (255 characters). Alphanumeric (X) max length = 32,767 characters (system-dependent).

25. What is the maximum length of numeric data type?

Maximum length: 18 digits (i.e., PIC 9(18)).

26. What is the length of variable declared as S9(08)?

S → Sign (optional, does not add to length). 9(08) → 8 digits (numeric). Total length = 8 bytes for display format (PIC S9(08)).

27. What is the length of variable declared as S9(08) SIGN IS LEADING SEPARATE CHARACTER?

SIGN IS LEADING SEPARATE CHARACTER → Sign is stored as an extra separate character (1 byte). So, it has a total length of 9 bytes (8 bytes for numeric digits + 1 extra byte for the sign).

28. What is the length of variable declared as 9(04).9(02)?

A variable declared as 9(04).9(02) has a total length of 6 digits, with the first part representing 4 digits and the second part representing 2 digits.

  • 9(04): This specifies a numeric field with 4 digits.
  • .: The period separates the whole and fractional parts of the number.
  • 9(02): This specifies a numeric field with 2 digits.

Therefore, the total length is 4 (from 9(04)) + 2 (from 9(02)) = 6 digits.

29. What is the length of variable declared as 9(04)V9(02)?

A variable declared as 9(04)v9(02) represents a numeric field with a total of 6 digits, 4 before the decimal point and 2 after, making the total length 6 digits.

  • 9(04): This specifies a numeric field with 4 digits.
  • v: Indicates the position of the decimal point (implied decimal).
  • 9(02): This specifies a numeric field with 2 digits.

30. Suppose, I have declared a variable as 9(04). What is the computation applied to by default?

By default, 9(04) is stored in DISPLAY format. DISPLAY is the default computation applied on the variable if no computation is coded.