Using keywords QUALIFIED, LIKEDS, and DIM with data structures |
Qualified Keyword
The keyword QUALIFIED tells that data structure subfields are referenced using qualified notation. We can access a data structure subfield as a Data structure name followed by a period and the subfield name i.e. DS1.subfield1 if the QUALIFIED keyword is specified for data structure DS1 having subfield subfield1.
D DS1 DS QUALIFIED D subfld1 1A D subfld2 1A
**FREE dcl-ds ds1 QUALIFIED; subfld1 char(1); subfld2 char(1); end-ds ds1;
The QUALIFIED keyword can be used with subfields too.
LIKEDS keyword
The LIKEDS keyword is used to define a data structure, its subfield, prototype return value, and prototyped parameter like another data structure.
D DS1 DS QUALIFIED D subfld1 1A D subfld2 1A * D DS2 DS LIKEDS(DS1)
**FREE dcl-ds ds1 QUALIFIED; subfld1 char(1); subfld2 char(1); end-ds ds1; dcl-ds ds2 likeds(ds1);
DIM keyword
The DIM keyword defines the number of elements in an array, table, prototype parameter, array data structure, prototype return value.
DIM(numeric)
The numeric should have zero decimal positions. It can be a literal, named constant, or bif.
Coding Data structure using keywords QUALIFIED, LIKEDS, and DIM.
RPG Code in Fixed format for Using keywords QUALIFIED, LIKEDS, and DIM with data structures in RPG AS400
D DS1 DS QUALIFIED D subfld1 10 D subfld2 5 D subfld3 5 D DS2 DS LIKEDS(DS1) D DS3 DS QUALIFIED D subfld1 5 D subfld2 LIKEDS(DS2) D DIM(2) C EVAL DS1.subfld1 = 'DS1_1' C EVAL DS1.subfld2 = 'DS1_2' C EVAL DS1.subfld3 = 'DS1_3' C DS1 DSPLY C EVAL DS2.subfld1 = 'DS2_1' C EVAL DS2.subfld2 = 'DS2_2' C EVAL DS2.subfld3 = 'DS2_3' C DS2 DSPLY C EVAL DS3.subfld1 = 'DS3_1' C EVAL DS3.subfld2(1) = 'DS3_2' C EVAL DS3.subfld2(2) = 'DS3_3' C DS3 DSPLY C SETON LR
RPG Code in /Free format for Using keywords QUALIFIED, LIKEDS, and DIM with data structures in RPG AS400
D DS1 DS QUALIFIED D subfld1 10 D subfld2 5 D subfld3 5 D DS2 DS LIKEDS(DS1) D DS3 DS QUALIFIED D subfld1 5 D subfld2 LIKEDS(DS2) D DIM(2) /Free DS1.subfld1 = 'DS1_1'; DS1.subfld2 = 'DS1_2'; DS1.subfld3 = 'DS1_3'; DSPLY DS1; DS2.subfld1 = 'DS2_1'; DS2.subfld2 = 'DS2_2'; DS2.subfld3 = 'DS2_3'; DSPLY DS2; DS3.subfld1 = 'DS3_1'; DS3.subfld2(1) = 'DS3_2'; DS3.subfld2(2) = 'DS3_3'; DSPLY DS3; *INLR = *ON; /End-Free
RPG Code in fully Free format for Using keywords QUALIFIED, LIKEDS, and DIM with data structures in RPG AS400
**FREE dcl-ds ds1 qualified; subfld1 char(10); subfld2 char(5); subfld3 char(5); end-ds; dcl-ds ds2 likeds(ds1); dcl-ds ds3 qualified; subfld1 char(5); subfld2 likeds(ds2) DIM(2); end-ds; DS1.subfld1 = 'DS1_1'; DS1.subfld2 = 'DS1_2'; DS1.subfld3 = 'DS1_3'; DSPLY DS1; DS2.subfld1 = 'DS2_1'; DS2.subfld2 = 'DS2_2'; DS2.subfld3 = 'DS2_3'; DSPLY DS2; DS3.subfld1 = 'DS3_1'; DS3.subfld2(1) = 'DS3_2'; DS3.subfld2(2) = 'DS3_3'; DSPLY DS3; *INLR = *ON;
Output
DSPLY DS1_1 DS1_2DS1_3 DSPLY DS2_1 DS2_2DS2_3 DSPLY DS3_1DS3_2 DS3_3
Related Post
Read also :
- Data Structure and Types of DS in RPG AS400
- Using a Data Structure to subdivide the field in RPG AS400
- Using a Data Structure to group fields in RPG AS400
- Externally Described Data Structure in RPG AS400
- Using EXTFLD to code Externally Described DS in RPG AS400
- Using PREFIX to rename all fields in an external data structure in RPG AS400
- Define an externally-described data structure using the LIKEREC keyword in RPG AS400
- Difference between LIKEREC and EXTNAME keyword in RPG AS400
- Multiple Occurrence Data Structure in RPG AS400
- Data Area Data Structure in RPG AS400
- *LDA Local data area data structure in RPG AS400
- File information data structures (INFDS) in RPG AS400
- Indicator data structure in RPG AS400
- Program Status Data Structure in RPG AS400
- Array Data Structures in RPG AS400
- Defining Data Structure Parameters in a Prototype or Procedure Interface