420 pts.
 AS400
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

Answer Wiki:
You can use the same SQL statement in your RPG program.
Last Wiki Answer Submitted:  August 21, 2012  8:07 pm  by  CharlieBrowne   32,835 pts.
All Answer Wiki Contributors:  CharlieBrowne   32,835 pts.
To see all answers submitted to the Answer Wiki: View Answer History.


Discuss This Question:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _


 

If you create a logical file on DEPT and use that in your program, then this sould be rather simple.

 44,150 pts.

 

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

 108,055 pts.

 

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

 108,055 pts.

 

and this is homework.

 44,150 pts.

 

*************** 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….                              

 420 pts.

 

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

 108,055 pts.