Application Development and Automation 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: 
Read only

Function module that accepts a SQL query

Former Member
0 Likes
3,591

HI all,

I would like to know if there is a FM to which I can pass a query string which it can execute and show the results.

The requirement is that I need to execute queries on a set of tables such as KNA1, ARDC, etc (depending on the user's choice and hence is decided at runtime) and extract values based on the join conditions. So is there a module to which I can pass the query string? if not, has anyone written a similar ABAP program which does the same? Can you please share the code if possible?

Also, which T code can i use to perform joins on tables and view data(to verify the result of the code)?

1 ACCEPTED SOLUTION
Read only

Sm1tje
Active Contributor
0 Likes
1,989

Function module: RFC_READ_TABLE

Transaction SQVi (query viewer to create joins).

5 REPLIES 5
Read only

Sm1tje
Active Contributor
0 Likes
1,991

Function module: RFC_READ_TABLE

Transaction SQVi (query viewer to create joins).

Read only

Former Member
0 Likes
1,989

Micky,

Thanks for the pointer wrt SQVi. However, i also need an RFC that can accept entire query as an input. Since RFC_READ_TABLE works on only one table, this will not help me. I need to perform joins on many tables, depending on the users input. Is there an RFC which can do this?

Read only

Former Member
0 Likes
1,989

Hi Monica,

Check the follwing FM:-

TH_SERVER_LIST u2013 List of RFC servers

CAT_CHECK_RFC_DESTINATION u2013 Checks the RFC destinations and connections

CAT_PING u2013 Checks RFC system and configuration

Regards,

Kanika

Read only

Former Member
0 Likes
1,989

Kanika,

Perhaps i used the wrong term . what i wnat is an ABAP progam or a BAPI that accepts a SQL query (that works on table )as an input and returns the result. Is this available?

Read only

Former Member
0 Likes
1,989

Just copy this program check the working through debuging and you will be able to resolve your problem.

DATA:v_fieldname

TYPE fieldname,

l_PROG TYPE string,

v_mess TYPE string,

l_sid TYPE string,

wa_ddfields TYPE dntab.

DATA i_tab TYPE STANDARD TABLE OF string.

DATA:l_str TYPE string,

l_str1 TYPE string.

PARAMETERS matnr type marc-matnr.

end-of-SELECTION.

*build the subroutine pool

APPEND 'PROGRAM subpool.' TO i_tab.

APPEND `LOAD-OF-PROGRAM.` TO i_tab.

APPEND `DATA i_tab1 TYPE TABLE OF vbak.` TO i_tab.

APPEND `DATA l_rows TYPE i.` TO i_tab.

APPEND `select * into table i_tab1 from vbak.` To i_tab.

append 'DESCRIBE TABLE i_tab1 LINES l_rows.' to i_tab.

append 'Write : l_rows .' to i_tab.

GENERATE SUBROUTINE POOL i_tab NAME l_PROG

MESSAGE v_mess

SHORTDUMP-ID l_sid.

IF sy-subrc = 0.

PERFORM ('LOOP_AT_TAB') IN PROGRAM (l_PROG) IF FOUND.

ELSEIF sy-subrc = 4.

MESSAGE v_mess TYPE 'I'.

ELSEIF sy-subrc = 8.

MESSAGE l_sid TYPE 'I'.

ENDIF.

I guess this will resolve your question.if you want more help i will be there