External file description considerations for host structure arrays in RPG/400 applications that use SQL

Field definitions for externally described files, including renaming of fields, are recognized by the SQL precompiler.

The external definition form of the data structure can be used to obtain a copy of the column names to be used as host variables.

In the following example, the DEPARTMENT table is included in the RPG/400® program and is used to declare a host structure array. A multiple-row FETCH statement is then used to retrieve 10 rows into the host structure array.

 
*...1....+....2....+....3....+....4....+....5....+....6....*
ITDEPT     E DSDEPARTMENT               10
I              DEPARTMENT                      DEPTN
I              ADMRDEPT                        ADMRD
 
…
 
C/EXEC SQL
C+   DECLARE C1 CURSOR FOR
C+      SELECT *
C+        FROM CORPDATA.DEPARTMENT
C/END-EXEC
 
…
 
C/EXEC SQL
C+ FETCH C1 FOR 10 ROWS INTO :TDEPT
C/END-EXEC