PL/I Interview Questions (31 - 40)
31. How do you declare a structure in PL/I?
A structure is like a group of related variables. For example -
DCL 1 EMPLOYEE,
2 ID FIXED BIN,
2 NAME CHAR(20),
2 SALARY FIXED DEC(7,2);
You can now refer to fields like EMPLOYEE.ID or EMPLOYEE.SALARY.
32. What is the purpose of the PICTURE attribute in PL/I?
PICTURE is used for formatted numeric data, especially when dealing with reports or input/output. For example -
DCL PRICE PICTURE 'ZZZ.99';
This formats a number with 3 digits before and 2 digits after the decimal. It helps you control the appearance of numbers.
33. How do you perform bit manipulation in PL/I?
Use bit variables and bit operations like AND, OR, XOR. For example -
DCL A BIT(8) INIT('10101010'B);
DCL B BIT(8) INIT('11001100'B);
C = A & B; /* AND operation */
You can define BIT variables with BIT(n) where n is the number of bits.
34. What is the use of the UNION attribute in PL/I?
The UNION attribute allows multiple fields to share the same memory space. You can interpret the same data in different ways. For example -
DCL 1 DATA UNION,
2 A FIXED BIN,
2 B CHAR(4);
Here, A and B use the same storage — useful for low-level data manipulation or conversions.
35. How do you implement conditional compilation in PL/I?
Use %IF, %THEN, %ELSE for compile-time decisions.
%IF DEBUG %THEN
PUT SKIP LIST('Debugging info');
%ELSE
PUT SKIP LIST('Production mode');
You can control what parts of the program get compiled, depending on conditions like a DEBUG flag.
36. What are the different types of loops available in PL/I?
PL/I supports these types of loops:
- DO UNTIL: Loop runs first, then checks the condition.
- DO WHILE: Loop checks the condition first, then runs.
- DO n TO m: Repeats a fixed number of times.
37. How do you declare and use constants in PL/I?
Use the DEFINE statement to create constants:
%DECLARE PI CONSTANT FIXED DEC(5,4) VALUE(3.1416);
CONSTANT tells PL/I this value doesn't change. You can also use % constants for compile-time constants.
38. What is the difference between ALIGNED and UNALIGNED in PL/I?
- ALIGNED: Data is stored at memory boundaries that the system prefers. This is usually faster.
- UNALIGNED: Data can be stored anywhere in memory — more flexible, but sometimes slower.
DCL A FIXED BIN(31) ALIGNED;
DCL B FIXED BIN(31) UNALIGNED;
Use UNALIGNED if you’re reading binary data from files or hardware.
39. How do you perform recursion in PL/I?
To use recursion, declare the procedure as RECURSIVE.
RECURSIVE FACTORIAL(N)
RETURNS(FIXED BIN(31)) =
IF N <= 1 THEN RETURN(1);
ELSE RETURN(N * FACTORIAL(N - 1));
Recursion is when a function calls itself to solve a smaller part of the problem.
40. What is the purpose of the REVERT statement in PL/I?
ON ERROR BEGIN;
PUT SKIP LIST('An error occurred.');
END;
REVERT ERROR; /* Turns off the ON ERROR handler */
Useful when you only want to handle an error for a limited section of code.