Chapter 2: Getting Started with PL/I Programming

This chapter will guide you through setting up a PL/I environment, writing your first PL/I program, and exploring the language's syntax and structure. With a solid understanding of these foundations, you’ll be prepared to tackle more complex programming tasks in PL/I.

Key Topics Covered

Setting up the PL/I Environment

To start programming in PL/I, you’ll need an environment that supports it, which typically means an IBM mainframe or a compatible emulator. Begin by installing the necessary PL/I compiler (e.g., IBM Enterprise PL/I) and any required libraries.

Access to the mainframe, if used, may require setting up an emulator (such as Hercules for personal systems) or accessing an IBM mainframe environment provided by your organization. Familiarize yourself with the command line or interactive development environments like IBM Developer for z/OS, as these tools streamline development and debugging processes.

Recommended tools for development include:

  • IBM Developer for z/OS – an IDE for mainframe development.
  • ISPF – a standard IBM interface for editing and navigating mainframe files.
  • Enterprise PL/I compiler – for compiling PL/I code on mainframes.

Once your environment is configured, ensure access to any relevant documentation or online resources to help resolve potential setup issues.

First Program: Hello World

Writing a simple “Hello World” program is a good starting point for understanding PL/I’s syntax and structure. Here’s a basic example:

/* Hello World program in PL/I */
HELLO: PROC OPTIONS(MAIN);
  PUT SKIP LIST('Hello, World!');
END HELLO;

In this program:

  • HELLO: The program name, defined before the `PROC` keyword.
  • PROC OPTIONS(MAIN): Indicates this is the main entry procedure of the program.
  • PUT SKIP LIST: Outputs “Hello, World!” to the console with a line break (`SKIP`).
  • END HELLO; Closes the procedure named HELLO.

This simple example introduces key elements of PL/I, including basic syntax and output commands. From here, you can expand to include variables, data types, and more complex procedures.

Syntax and Structure of a PL/I Program

PL/I syntax is built to handle both scientific and business logic, which makes it versatile. A PL/I program typically includes three main parts: declarations, program logic, and an ending statement. Here are some important syntax details:

Data Types and Declarations

PL/I supports various data types that make it highly flexible. Common types include:

  • CHARACTER: For string data, defined as `CHARACTER(n)` where `n` is the length.
  • FIXED: For fixed-point numeric data, often used in business applications.
  • FLOAT: For floating-point data, useful in scientific calculations.

Declarations are made at the start of the procedure, specifying data types and initializing values where needed.

Control Structures

PL/I includes control structures like `DO`, `IF`, `SELECT`, and looping constructs, making it powerful for handling complex logical operations.

DO I = 1 TO 10;
  PUT SKIP LIST('Iteration:', I);
END;

This loop iterates from 1 to 10, outputting each iteration. Control structures in PL/I are intuitive and designed for high readability.

Error Handling

One of PL/I's unique features is its advanced error handling with the `ON` condition. You can use it to define specific responses to errors directly within the program.

ON ERROR;
  PUT SKIP LIST('An error occurred.');
END;

This block will execute if an error is encountered, providing a custom message and potentially allowing recovery or graceful exit strategies.