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

Want to create dynamic SQL with table join

Former Member
0 Likes
1,055

I want to create a dynamic SQL query so that the user can enter any two table names on the selection screen and two field names that he wants to join. After which i should be able to dynamically generate the SQL (native or open) and show the result as report. I have already read the forum threads and know how to create dynamic SQL for single table, what i m struggling with is how to do inner join. I know i can use nested select but that will make the query very slow because i want to extend it to more than 2 tables later.

Will give points to useful answer for sure, thanks for reading.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
676

You should read my weblog to get an idea -:)

<a href="/people/alvaro.tejadagalindo/blog/2006/12/13/dynamic-inner-join-function-module Inner Join Function Module</a>

Greetings,

Blag.

4 REPLIES 4
Read only

Former Member
0 Likes
677

You should read my weblog to get an idea -:)

<a href="/people/alvaro.tejadagalindo/blog/2006/12/13/dynamic-inner-join-function-module Inner Join Function Module</a>

Greetings,

Blag.

Read only

0 Likes
676

Hi Alvaro,

Your function module seems really useful. But when i put in the table names as

VBAK and VBAP, filter table entries as vbeln and posnr and where_table as VBELN EQ '1500000267'.

I get a runtime error "LOAD_PROGRAM_NOT_FOUND" on line

005500 if r_oo_class is initial.

005510 perform (l_form) in program (l_name).

-


> else.

005530 perform (l_form) in program (l_name) using r_oo_class

of include LSKBHF06.

I have tried hard to figure out the problem but cant, could you please help

Read only

Former Member
0 Likes
676

Hi,

Following is a piece of code which I have used in my program.

DATA: ws_flds(72) TYPE c.

DATA: ftab LIKE TABLE OF ws_flds.

ws_flds = 'rbukrs rprctr racct ryear '.

APPEND ws_flds TO ftab.

SELECT (ftab)

INTO CORRESPONDING FIELDS OF TABLE it_grp_glpca

FROM glpca FOR ALL ENTRIES IN i_cert_item

WHERE kokrs = c_kokrs

AND rldnr = '8A'

AND rrcty IN ('0','2')

AND rvers = '000'

AND rbukrs = i_cert_item-bukrs

AND ryear = p_ryear

AND rprctr = i_cert_item-prctr

AND racct = i_cert_item-saknr

AND ( poper BETWEEN '001' AND ws_poper )

AND aufnr IN s_aufnr

AND kostl IN s_kostl

AND rfarea IN s_fkber

AND rmvct IN s_rmvct

AND sprctr IN s_sprctr

AND ( racct BETWEEN c_low AND c_high ).

You can now pass your table name as (p_table) or append fieldnames to the internal table (ftab). if it is join then you can append this table like abukrs asaknr..etc.

Regards

Subramanian

Read only

Former Member
0 Likes
676

HI

GOOD

GO THROUGH THIS LINK,i hope this ll help you to solve your problem

/people/ravishankar.rajan/blog/2006/12/21/building-dynamic-sql-statements-using-the-clrswhere-class

thanks

mrutyun^