|
Simon,
Thanks very much for your help. I was able to get it working - an RPG dspf
pgm where all the db i/o is in an SQLC module.
Phil
>
> Hello Phil,
>
> Since no-one else has been able to properly assist you I decided to take a
> look at this. There are a number of things wrong with your code:
>
> 1/ The SQL precompiler does not understand typedefs and that is
> why the structure is flagged as unusable. If you look closely at the SQL
> compiler listing you'll see:
>
> Data Names Define Reference
> hostDS **** 31
>
> the **** indicate the data name has NOT been defined.
>
> 2/ You are attempting a multi-row fetch so you should tell the
> compiler. Specify FOR 10 ROWS on the FETCH since your structure has room
> for 10 rows.
>
> 3/ I also wouldn't use the word CURSOR for the cursor name since
> CURSOR is an SQL reserved word.
>
> 4/ Although not required, host variables should be defined within
> BEGIN DECLARE and END DECLARE blocks to indicate they are used by SQL.
>
> 5/ The example you show as being from the SQL Host Programming
> manual, isn't as it is in the manual. In my version the example on page
> 26 is a single record fetch and it does not use a typedef for the
> structure. The multi record fetch example is on page 30 and although
> incomplete does show the "FOR n ROWS" clause and the use of a struct
> rather than a typedef. The example is incomplete so I have completed it
> and altered it to work with your supplied EMPLOYEE file.
>
> EXEC SQL BEGIN DECLARE SECTION;
> _Packed struct {char first_initial;
> char middle_initial;
> _Packed struct {short lastname_len;
> char lastname_data[15];
> } lastname;
> double total_salary;
> } employee_rec[10];
> struct { short inds[4];
> } employee_inds[10];
> EXEC SQL include SQLCA;
> EXEC SQL END DECLARE SECTION;
> int main() {
> EXEC SQL DECLARE C1 CURSOR FOR
> SELECT SUBSTR(FIRSTNAME,1,1), MIDINIT, LASTNAME,
> SALARY+BONUS+COMM
> FROM CORPDATA.EMPLOYEE;
> EXEC SQL OPEN C1;
> EXEC SQL FETCH C1 FOR 10 ROWS INTO :employee_rec:employee_inds;
> }
>
> Regards,
> Simon Coulter.
> --------------------------------------------------------------------
> FlyByNight Software AS/400 Technical Specialists
> http://www.flybynight.com.au/
>
> Phone: +61 3 9419 0175 Mobile: +61 0411 091 400 /"\
> Fax: +61 3 9419 0175 mailto: shc@flybynight.com.au \ /
> X
> ASCII Ribbon campaign against HTML E-Mail / \
> --------------------------------------------------------------------
As an Amazon Associate we earn from qualifying purchases.
This mailing list archive is Copyright 1997-2025 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].
Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.