How do we define data structures? Why do we use it and what are the different types of data structures in AS400?
How do I define different data structures in the RPG program and use them? Provide a sample code for defining, initializing, and using various data structures in the RPG program.
The
data structure
is a structure of different data types. The user defines the storage region for the data structure, which is called the Subfields in the fields of the structure. The data structure can be used to subdivide and group the fields. There are various types of data structures in AS400, which are as follows:In RPG, we can declare the data structure as follows:
Fixed format declaration of data structure
In Fixed format RPG, you can declare the data structure by putting DS in D specs (Definition Specifications) positions 24 through 25.
DDS1 DS
RPG Fully free declaration of data structure
In a fully free RPG, you can declare a data structure by supplying the DCL-DS, which the name and keywords of the data structure should follow.
DCL-DS DS1;
SUBFIELD1 CHAR(1);
END-DS;
The data structure can be defined the same as other data structures using the LIKEDS keyword in the RPG program.