Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Native Sql - Result of stored procedure in query

Former Member
0 Kudos

Hi experts,

I am calling a stored procedure in native sql, I would like to get the results of the query into my internal table. How do I do that?

Warm Regards,

Abdullah

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi,

To use a Native SQL statement, it must be preceded by an EXEC SQL statement and concluded by an ENDEXEC statement.

An ABAP/4 program with Native SQL statements does not generally run with different databases.

Regards,

Phani.

7 REPLIES 7

former_member222860
Active Contributor
0 Kudos

Hi,

Declare the variable or itab for the result of the stored procedure

DATA: A  TYPE I VALUE 100.

EXEC SQL. 
  EXECUTE PROCEDURE PROC1 ( IN :A ) 
ENDEXEC.

WRITE:/ A.

Former Member
0 Kudos

Hi,

To use a Native SQL statement, it must be preceded by an EXEC SQL statement and concluded by an ENDEXEC statement.

An ABAP/4 program with Native SQL statements does not generally run with different databases.

Regards,

Phani.

0 Kudos

Following is my code, the output of the query, i need in my internal table.


EXEC SQL.
  EXECUTE PROCEDURE d01.Z_PRICINGREPORT ( IN :i_mandt,
                                          IN :i_kschl,
                                          IN :i_vkorg,
                                          IN :i_vtweg,
                                          IN :i_matkll,
                                          IN :i_matklh,
                                          IN :i_matnrl,
                                          IN :i_matnrh,
                                          IN :i_inco1,
                                          IN :i_inco2,
                                          IN :i_zsalel,
                                          IN :i_zsaleh,
                                          IN :i_kunnrl,
                                          IN :i_kunnrh,
                                          IN :i_chargl,
                                          IN :i_chargh,
                                          IN :i_vkburl,
                                          IN :i_vkburh,
                                          IN :i_vkgrpl,
                                          IN :i_vkgrph,
                                          IN :i_wrkstl,
                                          IN :i_wrksth,
                                          IN :i_mtf,
                                          IN :i_mtt,
                                          IN :i_datbi,
                                          IN :i_werks,
                                          IN :i_stock,
  )

ENDEXEC.

0 Kudos

there is a resultset of the above query. How can I get it into my internal table on the abap side?

0 Kudos

Hi,

I got your question, you want to store resultset of stored procedure and not the output parameter.

I have no idea whether cursor can be used in this case but you can try this option as well.

Below is the simple code of cursor in native sql from abap help. Instead of select statement you call

your stored procedure and see if it works or not.

I doubt if we could open the cursor for stored procedure instead of select statement but inside stored proc there is select statement so let's give it a try .

DATA: F1(3), F2(3), F3(3). 
F3 = ' 1 '. 
EXEC SQL. 
  OPEN C FOR 
    SELECT CLIENT, ARG1 FROM AVERI_CLNT 
        WHERE ARG2 = :F3 
ENDEXEC. 
DO. 
  EXEC SQL. 
    FETCH NEXT C INTO :F1, :F2 
  ENDEXEC. 
  IF SY-SUBRC <> 0. 
    EXIT. 
  ENDIF. 
  WRITE: / F1, F2. 
ENDDO. 
EXEC SQL. 
  CLOSE C 
ENDEXEC.

Regards,

Vishal

0 Kudos

I too solved it in the way you mentioned. execute procedure is a native sql statement. you can write it inside the open cursor.

0 Kudos

Just to save your time, posting the code - making it is easier for someone like me:

DATA l_type LIKE parameter1 .

l_type = 'EMP'.

EXEC SQL.

OPEN C FOR

execute <stored procedure name> @parameter1 = :l_type

ENDEXEC.

DO.

EXEC SQL.

Fetch next C into :ls_data-col1,

:ls_data-col2

ENDEXEC.

IF sy-subrc <> 0.

EXIT.

ENDIF.

APPEND ls_data TO lt_data.

ENDDO.

EXEC SQL.

CLOSE C

ENDEXEC.