Back to: ILE RPG in Easy Bytes

Unit 3 demonstrates how to define the files and data items (work variables, data structures, and constants) your program might need to perform its tasks. You also learn how to identify the database files and device files your program uses, and how to use them. ILE RPG supports a rich set of data types, so this unit explains which ones are appropriate for most business programming. It also examines how to set the initial value for a data item and how to distinguish among program variables, literals, and constants.
This course is a unit of the ILE RPG in Easy Bytes series, a complete introductory ILE RPG programming self-guided tutorial.
- Before starting this course you must complete the required prerequisite course: 2. Database Concepts – ILE RPG in Easy Bytes
One-Time Payment
Members Only
Instead of paying for each unit individually, you may purchase a membership which will automatically enroll you at a discount in the entire “ILE RPG in Easy Bytes” series.
Using Declarations
You must name all the files and instruct the compiler how the program is to use them. In addition, you must name all the other data items and specify their attributes. The declarations section must appear in your source code, following control options (if present), before any processing takes place.
The general format of the Dcl-f instruction is as follows: Dcl-f file-name {device} {optional-keywords}; When a program declares a file, all the record formats and fields in that file become available to the program. No further declarations are necessary for the program to use those items.
A literal is a means of noting a fixed value (e.g., a number, a character string, or a date).
They stand alone in the program, without depending upon any other kind of data item. A typical use for a standalone variable might be as a counter to count the number of transactions being processed, as an intermediate variable to temporarily hold a value for later processing, as an accumulator to keep running track of year-to-date sales amounts, or as an indicator to represent whether a condition is true. Unlike a named constant, the value stored in a standalone variable might change often while the program is running.
Data structures can provide flexibility in your handling of data by letting you group variables into a logical structure, subdivide variables into subfields, and redefine variables with different data types or names. An RPG program can process the entire data structure as a unit or its subfields individually. RPG uses three instructions to declare data structures:
RPG uses the Like, Likeds, and Likerec keywords to define a new data item like an already defined parent data item. LIKE The Like keyword defines a standalone variable or data structure subfield that adopts the length and the data type of another data item. When you define a data item with the Like keyword, the data type, decimal positions, and, usually, the length are left blank because the compiler retrieves those attributes from the referenced parent.
2, the task of declaring files and other data items fell to two fixed-format specifications: File specifications (F-specs) Definition specifications (D-specs) Previous lessons introduced these specifications. Now, we summarize the possible entries.
- Before starting this course you must complete the required prerequisite course: 2. Database Concepts – ILE RPG in Easy Bytes