If i have a pf (pf1)
R Rec
account 10p00
name 10a
dept 1a
salary 5p00
k account
After Updating, I given dept- A, S, D different account, different salary.
NOW I AM TRYING TO ADD SALARY ON DEPT WISE
{FOR EXAMPLE- IN SQL, SELECT SUM(SALARY) FROM PF1 WHERE DEPT='A'}
BUT I AM TRYING IN RPGLE .. IT IS POSSIBLE TO ADD SALARY ON DEPT BASIS ?
HOW ?
Software/Hardware used:
SOFTWARE
ASKED:
August 21, 2012 4:54 PM
If you create a logical file on DEPT and use that in your program, then this sould be rather simple.
As CharlieBrowne said, you can use pretty much the same SQL in RPG. Here’s a trivial example:
H Debug
D mySUM s 10 2
/free
exec sql SELECT SUM(SALARY)
INTO :mySUM
FROM PF1 WHERE DEPT=’A';
dump ;
return ;
/end-free
The DEBUG keyword is just for testing, and the DUMP statement is also for testing.
Or are you needing to know how it would be done using native I/O? If so, please post the code you’ve been trying to create.
Tom
Sorry about the code formatting. I’m not sure why the {code} function is included with the editor since it doesn’t do anything useful.
Tom
and this is homework.
*************** Beginning of data *********************************************** flab25 if e k disk c dow *in03=’0′ c read rec 03 c move *blanks dept1 1 0 c z-add 0 sala2 6 0 c/exec sql c+ SELECT dept, sum(salary) into :dept1, :sala2 FROM lab22 GROUP BY dept c/end-exec c dept1 dsply c sala2 dsply c enddo c seton lr ******************************************************************************************* its giving me error that- SQL Pre-compiler failed….
giving me error
You need to show us the error. “SQL Pre-compiler failed” is not the error; it’s only a message telling that the pre-compiler couldn’t finish. You need to look at the pre-compiler output to see the error (and show it to us).
Tom