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

combined select query

Hi experts,

I have 4 select queries like this:

SELECT * FROM t009

INTO TABLE it_t009

FOR ALL ENTRIES IN lt_bukrs

WHERE periv = lt_bukrs-periv.

LOOP AT lt_bukrs INTO ls_bukrs.

READ TABLE it_t009 WITH KEY periv = ls_bukrs-periv.

IF sy-subrc NE 0.

it_incon-orgunit = 'b'.

it_incon-value = ls_bukrs-bukrs.

append it_incon.

delete table lt_bukrs from ls_bukrs.

endif.

ENDLOOP.

***************************************************************************

SELECT * FROM t009

INTO TABLE it_t009

FOR ALL ENTRIES IN lt_kokrs

WHERE periv = lt_kokrs-lmona.

LOOP AT lt_kokrs INTO ls_kokrs.

READ TABLE it_t009 WITH KEY periv = ls_kokrs-lmona.

IF sy-subrc NE 0.

it_incon-orgunit = 'k'.

it_incon-value = ls_kokrs-kokrs.

append it_incon.

delete table lt_kokrs from ls_kokrs.

endif.

ENDLOOP.

****************************************************************************

SELECT * FROM t009

INTO TABLE it_t009

FOR ALL ENTRIES IN lt_erkrs

WHERE periv = lt_erkrs-periv.

LOOP AT lt_erkrs INTO ls_erkrs.

READ TABLE it_t009 WITH KEY periv = ls_erkrs-periv.

IF sy-subrc NE 0.

it_incon-orgunit = 'e'.

it_incon-value = ls_erkrs-erkrs.

append it_incon.

delete table lt_erkrs from ls_erkrs.

endif.

ENDLOOP.

**************************************************************************************************************

SELECT * FROM t009

INTO TABLE it_t009

FOR ALL ENTRIES IN lt_verso

WHERE periv = lt_verso-periv.

LOOP AT lt_verso INTO ls_verso.

READ TABLE it_t009 WITH KEY periv = ls_verso-periv.

IF sy-subrc NE 0.

it_incon-orgunit = 'v'.

it_incon-value = ls_verso-verso.

append it_incon.

delete table lt_verso from ls_verso.

endif.

ENDLOOP.

******************************************************************************************************************

Now If I need to combine these select queries and append the internal table it_incon, how can I go about the same? What would be the code for that?

Thanks,

Ajay.

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

1 Answer

  • Best Answer
    Posted on Jan 19, 2009 at 07:57 AM

    Hi,

    loop at all 4 tables (lt_bukrs, lt_kokrs, lt_verso) separately and append the PERIV values to a single internal table e.g. I_PERIV_TMP

    Then,

    sort I_PERIV_TMP by PERIV.

    delete adjacent duplicates from I_PERIV_TMP comparing PERIV.

    SELECT * FROM t009

    INTO TABLE it_t009

    FOR ALL ENTRIES INI_PERIV_TMP

    WHERE periv = I_PERIV_TMP-PERIV.

    if sy-subrc = 0.

    -


    > then do your 4 seperate loops.

    endif.

    Regards,

    Dev.

    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.