Skip to Content
author's profile photo Former Member
Former Member

Executing stored function using Native SQL

In SAP documentation, I can see how to execute an Oracle stored procedure in an external database using:

EXEC SQL.

EXECUTE PROCEDURE procname

ENDEXEC.

I want to execute a stored FUNCTION within a package. I have tried executing it using the syntax for PROCEDURE above and get a "ORA-06550 wrong type or number of arguments" error. Since the function has one argument in and one argument out, I think I am counting the number of arguments correctly. Has anyone executed from within ABAP an Oracle function stored in an external database?

Thanks

Janice Ishee

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

3 Answers

  • author's profile photo Former Member
    Former Member
    Posted on Nov 23, 2005 at 03:49 PM

    Hi Janice,

    Here is an example that can help you:

    EXEC SQL PERFORMING get_ora.

    SELECT ora_field1, ora_field2, ora_field3,

    INTO :gs_data-field1,

    :gs_data-field12,

    :gs_data-field13,

    FROM oraserv.sv_abcde@xyz

    WHERE ora_field1 = :G_FIELD1

    ENDEXEC.

    Note the use of colon (😊 and the comma after each field.

    If this helps, please remember to award points and close the post.

    Cheers,

    Bhanu

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Nov 23, 2005 at 04:26 PM

    Janice - from help.sap.com:

    Stored Procedures

    The command EXECUTE PROCEDURE proc allows you to call a procedure stored in the database. When you call it, you can pass a list of host variables as parameters. When yuo call a procedure, you must specify for each parameter whether it is an input parameter ( IN), output parameter (OUT) or changing parameter (INOUT).

    Example

    Calling a Procedure:

    DATA Y TYPE I VALUE 300. 
    
    DATA Z TYPE I.
    
    EXEC SQL.
    INSERT INTO AVERI_CLNT (CLIENT, ARG1, ARG2, ARG3)
    VALUES ('000', 9, 2, 47)
    ENDEXEC.
    
    EXEC SQL.
    CREATE OR REPLACE PROCEDURE PROC1 (X IN NUMBER) IS
    BEGIN
    UPDATE AVERI_CLNT SET ARG3 = ARG3 + X;
    END;
    ENDEXEC.
    EXEC SQL.
    CREATE OR REPLACE PROCEDURE PROC2 (X IN NUMBER, Y OUT NUMBER) IS
    BEGIN
    SELECT ARG3 INTO Y
    FROM AVERI_CLNT
    WHERE CLIENT = '000' AND ARG1 = 9 AND ARG2 = 2;
    UPDATE AVERI_CLNT SET ARG3 = ARG3 - X;
    END;
    ENDEXEC.
    EXEC SQL.
    EXECUTE PROCEDURE PROC1 ( IN :Y )
    ENDEXEC.
    EXEC SQL.
    EXECUTE PROCEDURE PROC2 ( IN :Y, OUT :Z )
    ENDEXEC.
    IF SY-SUBRC <> 0 OR Z <> 347.
    WRITE: / 'Wrong result for EXECUTE PROCEDURE:', Z.
    ENDIF.
    EXEC SQL.
    DROP PROCEDURE PROC1
    ENDEXEC.
    EXEC SQL.
    DROP PROCEDURE PROC2
    ENDEXEC.

    Rob

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Nov 23, 2005 at 05:17 PM

    Thanks. I have seen and tried this syntax. I am thinking my problem is that, within the external Oracle database, I am trying to execute a function rather than a procedure. As you describe, the procedure syntax is

    EXECUTE PROCEDURE procname ( IN in_param, OUT out_param ).

    Using this syntax I am getting a wrong number or type of parameters error. I am thinking it might be the syntax of calling a function would be more like:

    out_param = funcname ( in_param ).

    I am not defining my function within ABAP but it exists in the Oracle database. Have you had any success executing a function?

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.