Schultz’s PowerBuilder Notes

Stored Procedures


Stored Procedures as External Function

Declare a Local External Function in n_tr_lm object.  (In this  example, SQLCA is  declared to be of type n_tr_lm, a descendant of n_tr)

FUNCTION long get_next_id(string TABLE, string COLUMN, long INCREMENT) &
   RPCFUNC ALIAS FOR “QUAD0076.dbo.sp_qg_get_next_id”

Powerbuilder script to call stored proc:

ll_next_job = SQLCA.get_next_id(“JOB_QUEUE”, “JOB_ID”, 1)

Calling a stored procedure using a local function which is not an external function

Example:

DECLARE redo_list PROCEDURE FOR
    @li_rc = QUAD0035.dbo.ml_create_cm_redo_list
    @CmEvent = :al_cm_id,
    @Output_List_id = :ll_output_id OUT
USING SQLCA;

EXECUTE redo_list;

IF SQLCA.SQLCode = -1 THEN
   ls_msg = SQLCA.SQLErrText
   MessageBox("of_redo_stored_Proc", ls_msg)
ELSE
   // Put the return value into the var and close the declaration.
   FETCH redo_list INTO :li_rc, :ll_output_id;
   CLOSE redo_list;
END IF

Calling a stored procedure with an output argument

In our Sybase environment, I found that the “dbo” was required in the stored procedure name

DECLARE redo_list PROCEDURE FOR
   @li_rc = QUAD0035.dbo.ml_create_cm_redo_list
   @CmEvent = :al_cm_id,
   @Output_List_id = :ll_output_id OUT
USING SQLCA;

EXECUTE redo_list;

IF SQLCA.SQLCode = -1 THEN
   ls_msg = SQLCA.SQLErrText
   MessageBox("of_redo_stored_Proc", ls_msg)
ELSE
   // Put the return value into the var and close the declaration.
   FETCH redo_list INTO :li_rc, :ll_output_id;
   CLOSE redo_list;
END IF

April 21, 2008 - Posted by | Database, Powerscript | , , , , , , , , , , , ,

5 Comments »

  1. DECLARE sp_name PROCEDURE FOR dbo.sp_example
    @path = :txtpath ;
    EXECUTE sp_blob;
    commit USING SQLCA;

    If sqlca.sqlcode 0 then
    is_msg =sqlca.sqlerrtext
    Messagebox(“Message”, is_msg, StopSign! )
    return
    Else
    Messagebox(“Message”,”Successfull” )
    end if

    Comment by Nilesh Umaretiya | March 28, 2013 | Reply

  2. Hello,

    May I just ask if you could help me somehow.
    I wanted to know the values of the passed arguments from( stored procedure by which it is the datasource of the datawindow) and put it in a messagebox.

    I had hard time tracing the error of an existing powerbuilder software.
    Please share some ideas. Thanks

    Comment by Marj | November 5, 2015 | Reply

  3. what about to read a entire result set?

    Comment by Respawn | June 19, 2017 | Reply

  4. Using this form, does not work for me:
    ll_next_job = SQLCA.get_next_id(“JOB_QUEUE”, “JOB_ID”, 1)

    Ive declared the external global reference of the function, but, how do i reference it in SQLCA or in another transaction? when i run it, it always says its a ‘unkown function’, what is the code? i use two two (sqlca and another one) and in both cases it does not work, i think i have to asociate it to them, but, how do i do that?

    Also, what does text mean? what is n_tr_lm ? and n_tr ? how are they declared?
    (In this example, SQLCA is declared to be of type n_tr_lm, a descendant of n_tr)

    thanks

    Comment by Billy | November 11, 2020 | Reply

    • n_tr is part of the PFC
      n_tr_lm is a descendant of n_tr
      The external function get_next_id(string, string, long) exists only in n_tr_lm

      When you declare SQLCA, it must be of type n_tr_lm. If it is of type n_tr or Transaction, you are unable to use the get_next_id(string, string, long) function as it does not exist on these ancestors.

      Comment by rick130 | March 26, 2021 | Reply


Leave a comment