How to declare and use out parameter in Powerbuilder with ASA database

5.4k Views Asked by At

I have a stored procedure named sp_getnextautono(as_sequenceid Char(20), as_sequenceno double output)

In Powerbuilder I have scripted as follows:

//Declaration
Declare proc_autono Procedure for sp_setnextautono 
@as_sequenceid = :ls_input, 
@as_sequenceno = :ld_sequenceno;

//Execution
Execute proc_autono;

If Sqlca.Sqlcode <> 0 Then
   ls_errormsg = Sqlca.SQLErrText
   Rollback Using Sqlca;
   MessageBox( 'Error', 'Error: ' + Sqlca.SqlErrText , Stopsign! )
   Return FAILURE 
End If

// Fetch
Fetch proc_autono Into :ld_sequenceno;

If Sqlca.Sqlcode <> 0 Then
   ls_errormsg = Sqlca.SQLErrText
   Rollback Using Sqlca;
   MessageBox( 'Error', 'Error: ' + Sqlca.SqlErrText , Stopsign! )
   Return FAILURE 
End If

There is no error but I am unable to fetch the sequenceno.

The variable ld_sequenceno returns 0.

Can anyone advise me how to solve the above issue?

1

There are 1 best solutions below

0
On

This is your code (wich is almost fine):

//Declaration
Declare proc_autono Procedure for sp_setnextautono
    @as_sequenceid = :ls_input,
    @as_sequenceno = :ld_sequenceno;

You are only missing to indicate that :ld_sequenceno is an OUTPUT variable. Try the next and everything should be ok:

//Declaration
Declare proc_autono Procedure for sp_setnextautono
    @as_sequenceid = :ls_input,
    @as_sequenceno = :ld_sequenceno **OUTPUT**;