Re: What is wrong?



Saml wrote:
It's been a long day, so take this with a grain of salt...

Don't you want to use parameter markers on the cursor?
C/EXEC SQL
C+ DECLARE CTLWO CURSOR FOR
C+ select cjshid
C+ from edcjlf02
C+ where cjonbr = ? -- <<<<<------------
c+ fetch first row only
C/END-EXEC

I think you cannot use a parameter marker in a statically declared cursor like that. Parameter markers are used in dynamically constructed cursor definitions that you then PREPARE into a SQL variable; the SQL variable is then referenced in the DECLARE statement:

/free
rpg_var = 'select col_a from table_1 where col_b = ?';
/end-free
c/exec sql
c+ prepare sql_var from :rpg_var
c/end-exec
c/exec sql
c+ declare my_cursor for sql_var
c/end-exec
c/exec sql
c+ open my_cursor using :wo#
c/end-exec



Of course, if you are only reading on row, you probably don't need a cursor at all.

Exactly right:


C/EXEC SQL
C+ select cjshid
C+ into :ctl#
C+ from edcjlf02
C+ where cjonbr = :wo#
c+ fetch first row only
C/END-EXEC


<qgenesist@xxxxxxxxxxx> wrote in message news:bc9140d2-b9d9-4eed-9770-72c38177125d@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
This program locks and doesnt debug at begin of proc. what I am trying
to do is send in a workorder 112272 and retrieve the controlling work
order (lets call it 112100) and return that number. As you might be
able to tell, my procedure making skills are non-existant, I will
eventually do this and some other procs and make a service program.

call rtvctl# '112272'




H*NOMAIN
H DEBUG
H DFTACTGRP(*NO) ACTGRP(*CALLER)
H OPTION(*SRCSTMT:*NODEBUGIO)

D DS_EDCJPF E DS EXTNAME(edcjpf)

/copy proto,rtvctl#
here it is:
D*RTVCTL# PR 6S 0 EXTPROC ('RTVCTL#')
D RTVCTL# PR 6S 0
D WO# 6S 0
CONST

P RTVCTL# B
D PI 6S 0
D WO# 6S 0 const
D CTL# S 6S 0

C/EXEC SQL
C+ Set Option commit= *none
C/END-EXEC
C/EXEC SQL
C+ Set Option closqlcsr= *endmod
C/END-EXEC

c #main tag
c exsr $dclcsr
c exsr $opncsr
c exsr $rtvctl
C dump
c exsr $rtvstt
c exsr $clscsr

C #end TAG
c eval *inlr = *on
C #rtx TAG
c return ctl#
c $dclcsr begsr
********************************************************
* Declare Cursor with Selection Criteria
********************************************************
C/EXEC SQL
C+ DECLARE CTLWO CURSOR FOR
C+ select cjshid
C+ from edcjlf02
C+ where cjonbr = :wo#
c+ fetch first row only
C/END-EXEC
c #dclcsr tag
c endsr
********************************************************
* Open Cursor
********************************************************
c $opncsr begsr
C/EXEC SQL
C+ OPEN CTLWO USING :wo#
C/END-EXEC
c #opncsr tag
c endsr
*********************************
* Retrieve Controlling Workorder
*********************************
c $rtvctl begsr
C/EXEC SQL
C+ FETCH CTLWO INTO :ctl#
C/END-EXEC
c #rtvctl# tag
c endsr
*********************************
* Retrieve SQL State
*************************************
c $rtvstt begsr
c #rtvstt tag
c endsr
*************************************
* Close Cursor
*************************************
c $clscsr begsr
C/EXEC SQL
C+ CLOSE CTLWO
C/END-EXEC
c #clscsr tag
c endsr

P RTVCTL# E



.



Relevant Pages

  • Re: Dynamic cursor not working in external stored procedure
    ... creates is dynamic in that the files and libraries are changed. ... first time I call this sp, ... C/EXEC SQL ... Declare the Cursor ...
    (comp.sys.ibm.as400.misc)
  • Re: A problem in compiling sqlrpg source
    ... It looks as if you have a space in the wrong place in the "DECLARE C1 CURSOR ... This might make the compiler think that you were trying to open the cursor ... source file is "sqlrpg". ... C/EXEC SQL WHENEVER NOT FOUND GO TO DONE1 ...
    (comp.sys.ibm.as400.misc)
  • Re: What is wrong?
    ... Don't you want to use parameter markers on the cursor? ... C/EXEC SQL ... c $dclcsr begsr ... c #dclcsr tag ...
    (comp.sys.ibm.as400.misc)
  • Dynamic cursor not working in external stored procedure
    ... I have a stored procedure calling an external program. ... creates is dynamic in that the files and libraries are changed. ... creation of the cursor. ... C/EXEC SQL ...
    (comp.sys.ibm.as400.misc)
  • Re: RPG SQL Question
    ... my RPG program that I want to change it so their more dynamic. ... C/EXEC SQL Declare C1 Cursor For ... C* Close the cursor ...
    (comp.sys.ibm.as400.misc)