ABAPEXEC_PROCEDURE - EXEC PROCEDURE

BAL_S_LOG - Application Log: Log header data   RFUMSV00 - Advance Return for Tax on Sales/Purchases  
This documentation is copyright by SAP AG.

EXEC SQL - EXECUTE

Syntax

EXEC SQL.
  EXECUTE PROCEDURE proc ( IN    p_in1    IN    p_in2 ...,
                          OUT   p_out1   OUT   p_out2 ...,
                          INOUT p_inout1 INOUT p_inout2 ... )
ENDEXEC.

Effect

In database systems, you can define procedures as so-called stored procedures. Since the syntax for calling such procedures and the pertinent parameter transfer for various database systems can vary widely, a uniform command exists inNative SQL.

The statement EXECUTE PROCEDURE calls a procedure proc stored in the database. For allformal parameters of the procedure, you must specify the actual parameters, separated by commas. Youmust specify IN, OUT, or INOUT before every actual parameter, in order to indicate whether the parameter is an input, output, or input/output parameter. For actual parameters, you can use literals orhost variables identified by a colon(:), which could also be internal tables in this case. When internal tables are used they must be standard tables withoutsecondary table keys.

Example

Definition of a procedure incprice using database-specific SQL statements (Oracle) and callingthe procedure with the SAP specific Native SQL statement EXECUTE PROCEDURE. The execution of the program section raises the price of every flight for the client "000" in the table SFLIGHT by a specific amount.

PARAMETERS incprice TYPE sflight-price.

EXEC SQL.
  CREATE OR REPLACE PROCEDURE increase_price (x IN NUMBER) IS
  BEGIN
    UPDATE sflight SET price = price + x
           WHERE mandt = '000';
  END;
ENDEXEC.

EXEC SQL.
  EXECUTE PROCEDURE increase_price ( IN :incprice )
ENDEXEC.

Example

This example defines a selfunc procedure using database-specific SQL statements (Informix). Italso calls the procedure using the SAP-specific Native SQL statement EXECUTE PROCEDURE in a LOOP loop by means of aselectiontable, and deletes the procedure using an SQL statement. In the case shown here, the procedure is a function whose return value output in EXECUTE PROCEDURE is copied to the host variable name.

DATA scarr_carrid TYPE scarr-carrid.
SELECT-OPTIONS s_carrid FOR scarr_carrid NO INTERVALS.
DATA s_carrid_wa LIKE LINE OF s_carrid.

DATA name TYPE c LENGTH 20.

TRY.
    EXEC SQL.
      CREATE FUNCTION selfunc( input CHAR(3) )
        RETURNING char(20);
        DEFINE output char(20);
        SELECT carrname
               INTO output
               FROM scarr
               WHERE mandt  = '000' AND
                     carrid = input;
        RETURN output;
        END FUNCTION;
    ENDEXEC.
    LOOP AT s_carrid INTO s_carrid_wa
                    WHERE sign = 'I' AND option = 'EQ'.
      TRY.
         EXEC SQL.
            EXECUTE PROCEDURE selfunc( IN  :s_carrid_wa-low,
                                      OUT :name )
          ENDEXEC.
          WRITE: / s_carrid_wa-low, name.
        CATCH cx_sy_native_sql_error.
          MESSAGE `Error in procedure execution` TYPE 'I'.
      ENDTRY.
    ENDLOOP.
    EXEC SQL.
      DROP FUNCTION selfunc;
    ENDEXEC.
  CATCH cx_sy_native_sql_error.
    MESSAGE `Error in procedure handling` TYPE 'I'.
ENDTRY.




General Data in Customer Master   Fill RESBD Structure from EBP Component Structure  
This documentation is copyright by SAP AG.


Length: 6183 Date: 20120522 Time: 053531     triton ( 147 ms )