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

combined select query

Former Member
0 Likes
579

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.

1 ACCEPTED SOLUTION
Read only

dev_parbutteea
Active Contributor
0 Likes
544

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.

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.

2 REPLIES 2
Read only

dev_parbutteea
Active Contributor
0 Likes
545

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.

Read only

0 Likes
544

Hello,

Any other ideas?

Thanks,

Ajay.