Using host structure arrays in PL/I applications that use SQL

In PL/I programs, you can define a host structure array.

In these examples, the following are true:

  • B_ARRAY is the name of a host structure array that contains the items C1_VAR and C2_VAR.
  • B_ARRAY cannot be qualified.
  • B_ARRAY can only be used with the blocked forms of the FETCH and INSERT statements.
  • All items in B_ARRAY must be valid host variables.
  • C1_VAR and C2_VAR are not valid host variables in any SQL statement. A structure cannot contain an intermediate level structure. A_STRUCT cannot contain the dimension attribute.
DCL 1 A_STRUCT,
      2 B_ARRAY(10),
        3 C1_VAR CHAR(20),
        3 C2_FIXED BIN(15) UNALIGNED;
 

To retrieve 10 rows from the CORPDATA.DEPARTMENT table, do the following:

 
DCL 1 DEPT(10),
      5 DEPTPNO CHAR(3),
      5 DEPTNAME CHAR(29) VAR,
      5 MGRNO CHAR(6),
      5 ADMRDEPT CHAR (3);
DCL 1 IND_ARRAY(10),
      5 INDS(4) FIXED BIN(15);
EXEC SQL
  DECLARE C1 CURSOR FOR
     SELECT *
       FROM CORPDATA.DEPARTMENT;
 
EXEC SQL
  FETCH C1 FOR 10 ROWS INTO :DEPT :IND_ARRAY;