PL/I Interview Questions (41 - 50)
41. How do you implement multitasking or parallel processing in PL/I?
PL/I supports multitasking through tasking features, such as:
- CALL TASK – Starts a new task (like a thread).
- WAIT – Waits for a task to finish.
- TASK RETURNS – Used to get results from the task.
CALL TASK TASK1;
WAIT(TASK1);
Used in advanced systems for concurrent processing.
42. What is the use of the ENTRY attribute in procedures?
ENTRY is used to declare a procedure pointer (like a function reference). You can call different procedures using the same pointer.
DCL PROC_PTR ENTRY(FIXED) RETURNS(FIXED);
PROC_PTR = ADD_PROC;
X = PROC_PTR(10);
43. How do you handle date and time values in PL/I?
Use the built-in DATE and TIME functions:
DCL TODAY CHAR(10);
TODAY = DATE('YYYYMMDD');
DCL NOW CHAR(8);
NOW = TIME('HHMISS');
DATE() gives the current date. TIME() gives the current time. You can use formats like 'YYYYMMDD', 'MMDDYY', 'HHMISS', etc.
44. What are the differences between FIXED and FLOAT data types in PL/I?
Attribute | FIXED (Decimal/Integer) | FLOAT (Floating Point) |
---|---|---|
Precision | Exact | Approximate |
Range | Limited | Very large range |
Usage | Money, counters | Scientific, engineering |
DCL A FIXED DEC(5,2); /* 5 digits, 2 after decimal */
DCL B FLOAT BIN(21); /* Floating point binary */
45. How do you perform dynamic memory allocation in PL/I?
Use the ALLOCATE and FREE statements:
DCL PTR POINTER;
DCL DATA CHAR(100) BASED(PTR);
ALLOCATE DATA SET(PTR);
FREE DATA;
ALLOCATE reserves memory at runtime. FREE releases it when you're done.
46. What is the significance of the ORDER attribute in PL/I?
The ORDER attribute controls the order in which items in a structure are stored in memory. By using ORDER, you tell the compiler to keep the fields in the exact order you wrote them.
DCL 1 MYSTRUCT ORDER,
2 ID FIXED,
2 NAME CHAR(20);
Use ORDER when field layout matters, like when working with external files or binary data.
47. How do you implement a linked list in PL/I?
A linked list is a collection of items where each item points to the next one using a pointer. The steps are -
- Define a structure with data and a pointer to the next node.
- Allocate memory for each node.
- Link nodes using the pointer.
48. What are the uses of the OVERLAY attribute in PL/I?
OVERLAY allows multiple variables to share the same memory location. It is useful when you want to reuse storage or interpret data differently.
DCL 1 COMMON_AREA,
2 X FIXED,
2 Y CHAR(4) OVERLAY(X);
Here, X and Y use the same memory. Writing to one affects the other.
49. How do you perform file buffering in PL/I?
File buffering means reading or writing multiple records at once using memory, which improves speed. In PL/I, file buffering is automatic, but you can control it using:
- ENVIRONMENT(BUFFERED) – tells PL/I to use buffering.
- ENVIRONMENT(UNBUFFERED) – for real-time (immediate) read/write.
50. What is the role of the ENVIRONMENT attribute in PL/I?
The ENVIRONMENT attribute is used in file declarations to specify how the file should behave. Examples of its uses:
- ENVIRONMENT(F): F-style files (default)
- ENVIRONMENT(BUFFERED): Use file buffering
- ENVIRONMENT(UNBUFFERED): Write data immediately
- ENVIRONMENT(RECORD): Process the file as records
- ENVIRONMENT(PRINT): Format output for printing