Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

RPG and SQL code

Status
Not open for further replies.

rforeman

Programmer
Jul 17, 2002
9
0
0
US
I am attempting to create an RPG program which has SQL updates. I am not as familiar with RPG as I am with CL. But, I am told that SQL commands can't be run in CL's.

This is my RPG code so far:

C/Exec SQL
C+Execute Immediate Update opcus1/ym867h1 set ymvmd = 589
C+Where ymvnd =588 and ymdvsn = 'PLN'
End-Exec

I am getting an error at the bottom whcih is asking for a control level indicator. But, I am going according to IBM's documentation which says to put the / in postion 7.

Any help would be appreciated.

 
I am not a SQL expert but i think if you try this
it might work

C/Exec SQL
C+ Update opcus1/ym867h1 set ymvmd = 589
C+ Where ymvnd =588 and ymdvsn = 'PLN'
C/End-Exec

indirectly you can call SQL from CL by using the IBM command
RUNSQLTM.It processes a source file of SQL commands.
So if you create a source member UPD in sourcefile QTXTSRC
and put in
Update opcus1/ym867h1 set ymvmd = 589
Where ymvnd =588 and ymdvsn = 'PLN';

save the source member

then execute the command
RUNSQLSTM SRCFILE(YOURLIB/QTXTSRC) SRCMBR(UPD) COMMIT(*NONE)

it should update your table
you can put this command into your cl pgms
-----------------------------------------------
you could also create a query management query (*QMQRY)
using CRTQMQRY command of the above source
then use STRQMQRY to execute the *QMQRY object.This will execute the SQL command.


 
I am not a SQL expert but i think if you try this
it might work

C/Exec SQL
C+ Update opcus1/ym867h1 set ymvmd = 589
C+ Where ymvnd =588 and ymdvsn = 'PLN'
C/End-Exec

indirectly you can call SQL from CL by using the IBM command
RUNSQLTM.It processes a source file of SQL commands.
So if you create a source member UPD in sourcefile QTXTSRC
and put in
Update opcus1/ym867h1 set ymvmd = 589
Where ymvnd =588 and ymdvsn = 'PLN';

save the source member

then execute the command
RUNSQLSTM SRCFILE(YOURLIB/QTXTSRC) SRCMBR(UPD) COMMIT(*NONE)

it should update your table
you can put this command into your cl pgms
-----------------------------------------------
you could also create a query management query (*QMQRY)
using CRTQMQRY command of the above source
then use STRQMQRY to execute the *QMQRY object.This will execute the SQL command.


 
It is possible to use SQL from within CL programs. Certain commands are available for the same like EXECUTE, UPDATE, DELETE etc. In your case may be you could use the command UPDATE. Your code might look like what is given below:

UPDATE SET(ymvmd '589') SQL('from opcus1/ym867h1 where ymvnd =588 and ymdvsn = "PLN"')

Hope this will work for you with some slight changes (maybe with the quotation marks). Could you just let me know if it really does..... :)

All the Best.....
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top