I want to use SQL to query a file and summurize data, using multiple scalars( min, max, sum) and display the results on a workstation screen. Can i use one select statement in RPG iseries or should I create a stored procedure? Any code samples,etc would be greatly appreciated.
Software/Hardware used:
i series- RPG
ASKED:
September 27, 2011 4:31 PM
UPDATED:
March 31, 2012 1:08 AM
Here is code in program. it blows up on the FROM statement in the SQL line.
Wow, thanks for your fast reply.
**File List
FREPFILW IF E K DISK
FREP025D CF E WORKSTN
** Data Structure for build
DHOSTVARS DS
D HVTOTORD 5S 0
D HVTOTBKS 7S 0
D HVTOT$AMT 9S 2
D HVRSLMIN 3S 0
D HVRLSMAX 3S 0
D HVRLSAV 3S 0
D HVSHPMIN 3S 0
D HVSHPMAX 3S 0
D HVSHPAV 3S 0
D HVTOTBKS 7S 0
D HVTOT$AMT 9S 2
D HVRSLMIN 3S 0
D HVRLSMAX 3S 0
D HVRLSAV 3S 0
D HVSHPMIN 3S 0
D HVSHPMAX 3S 0
D HVSHPAV 3S 0
C/EXEC SQL
C+ SELECT COUNT(INV1), SUM(TOT$), SUM(QTYBKS), MIN(DAYS1), MAX(DAYS1),
C+ AVG(DAYS1), MIN(DAYS2), MAX(DAYS), AVG(DAYS2) INTO : HOSTVARS
C+ FROM WFILES.REPFILW
C/END-EXEC
/End-Free
C DOW *IN03 <> ’1′
C EVAL #TOTORD = HVTOTORD
C EVAL #TOTBKS = HVTOTBKS
C EVAL #TOTAMT = HVTOT$AMT
C EVAL #RLSMIN = HVRSLMIN
C EVAL #RLSMAX = HVRLSMAX
C EVAL #RLSAV = HVRLSAV
C EVAL #SHPMIN = HVSHPMIN
C EVAL #SHPMAX = HVSHPMAX
C EVAL #SHPAV = HVSHPAV
C Exfmt SCR1
C ENDDO
C Seton LR
Here is a trivial example:
H Debug DHOSTVARS ds D iCnt 5 0 D iTot 5 0 D minFile 10 D maxFile 10 /free exec sql SELECT COUNT(*), SUM(APNKYF), MIN(APFILE), MAX(APFILE) INTO :HOSTVARS FROM mylib/ACCPTH ; dump ; return ; /end-freeUse DSPFD with TYPE(*ACCPTH) and OUTPUT(*OUTFILE) to generate a test file in library {mylib}. Use the example to investigate.
I don’t see that you have {/free} in your example source although you do have {/end-free}. Also, your HOSTVARS data structure doesn’t match up with you column list in your SELECT statement at all.
There are other possible problems, but I can’t tell if there should be more to your example program or not. Maybe that’s why {/free} is missing and why you have a F-spec for REPFILW that isn’t used. Also, you are using SQL naming in your FROM clause, but that might be specified on your compile.
Tom
your HOSTVARS data structure must match field for field (sequence and type) with the select statement.
I was able to get the program to compile and display the results. I had a “.” in the FROM, should have been “/”, took out the end free, matched the HOSTVAR to SQL. Pretty simple to do, without much code involved at all.
Thanks for all your help.