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

Dynamic join table

Hi expert. i wish to create a program that can join 2 dynamic table, some of the point i cant figure out the solution, so wish the expert here can help me.

Like the code below:

table_1 and table_2 is the parameters.

field2 is the primary key of table_1 and table_2

where_tab is the dynamic SQL condition.

DATA: pre_itab1 TYPE REF TO data.

FIELD-SYMBOLS: <fs_itab1> TYPE STANDARD TABLE.

DATA: pre_itab2 TYPE REF TO data.

FIELD-SYMBOLS: <fs_itab2> TYPE STANDARD TABLE.

CREATE DATA pre_itab1 TYPE STANDARD TABLE OF (table_1).

ASSIGN pre_itab1->* TO <fs_itab1>.

CREATE DATA pre_itab2 TYPE STANDARD TABLE OF (table_2).

ASSIGN pre_itab1->* TO <fs_itab2>.

ASSIGN pre_itab2->* TO <fs_itab2>.

IF table_1 NE '' AND table_2 NE ''.

SELECT *

FROM (table_1)

INNER JOIN (table_2) on (table_1)(field2) = (table_2)(field2)

INTO table <fs_itab2>

WHERE (where_tab).

ELSEIF table_1 NE ''.

SELECT *

FROM (table_1)

INTO table <fs_itab1>

where (where_tab).

ENDIF.

there had 2 problem or more that i even didnt realise.

1. the inner join part

2. the table size that create on field-symbols for <fs_itab2>.

Please give advice for how to solve it.

i'll appreciate for ur reply.

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

2 Answers

  • author's profile photo Former Member
    Former Member
    Posted on Jan 13, 2009 at 02:52 AM

    Thanks max for fast respond.

    ur sample were help me to solve my inner join problem.

    thanks.

    but i still cant solve the 2nd problem which is the table size of the join table,

    the problem i cant solve bcoz 2 of the input is dynamic tables, (like mara join marc)

    means that i must have a dynamic table structure which consist of all the dynamic field

    of mara and marc that allow me to store 2 of the dynamic input tables.

    abit messy, hope u can understand what i need.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jan 12, 2009 at 10:46 AM

    Hi

    I hope this sample can help you:

    DATA: POSNR TYPE VBAP-POSNR.
    DATA: FROM_TABLE(100).
    DATA: FIELD_TABLE(10) TYPE C OCCURS 0 WITH HEADER LINE.
    
    FROM_TABLE = 'VBAK INNER JOIN VBAP ON VBAK~VBELN = VBAP~VBELN'.
    
    FIELD_TABLE = 'POSNR'.
    APPEND FIELD_TABLE.
    
    
    SELECT (FIELD_TABLE) INTO POSNR FROM (FROM_TABLE)..
      WRITE / POSNR.
      if sy-dbcnt > 10. exit. endif.
    ENDSELECT.

    Max

    Edited by: max bianchi on Jan 12, 2009 11:50 AM

    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.