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

How to split this select query

Former Member
0 Likes
1,234

Hi all,

Can any one help me to split this single select query into 9 select query.

select KNA1STCEG VBRKBUKRS VBRKVKORG VBRKVBELN VBRKFKDAT VBRKFKART VBRKVBTYP VBRKVBUND VBRKKUNAG VBRKKUNRG VBRK~NETWR

VBRKWAERK VBRKFKSTO VBRKSFAKN VBRKLAND1 T001WKUNNR VBRPPOSNR VBRPWERKS VBRPFKIMG VBRPVRKME VBRPPRSDT

VBRPNETWR VBRPVGBEL VBRPVGPOS VBRPMATNR VBRPPRCTR VBRPCHARG VBRPAUBEL VBRPAUPOS VBRPVBELN T001WAERS T001~BUKRS

MBEWSTPRS MBEWPEINH MBEWMATNR MBEWBWKEY LIKPLFART LIKPWERKS LIKPVBELN MBEW_RECVSTPRS MBEW_RECV~PEINH

MBEW_RECVBWKEY MBEW_RECVMATNR CKMLCRBDATJ CKMLCRPOPER CKMLCRSTPRS CKMLCRWAERS CKMLCRPEINH CKMLCRCURTP

CKMLCRKALNR CKMLCR_RECVSTPRS CKMLCR_RECVWAERS CKMLCR_RECVPEINH CKMLCR_RECVCURTP CKMLCR_RECVBDATJ CKMLCR_RECV~POPER

CKMLCR_RECV~KALNR

from ( KNA1

left outer join VBRK

on VBRKKUNRG = KNA1KUNNR

inner join T001W

on T001WKUNNR = VBRKKUNAG

inner join VBRP

on VBRPVBELN = VBRKVBELN

inner join T001

on T001BUKRS = VBRKBUKRS

left outer join MBEW

on MBEWMATNR = VBRPMATNR

and MBEWBWKEY = VBRPWERKS

left outer join LIKP

on LIKPVBELN = VBRPVGBEL

inner join MBEW as MBEW_RECV

on MBEW_RECVBWKEY = T001WBWKEY

and MBEW_RECVMATNR = VBRPMATNR

inner join CKMLCR

on CKMLCRKALNR = MBEWKALN1

inner join CKMLCR as CKMLCR_RECV

on CKMLCR_RECVKALNR = MBEW_RECVKALN1 )

where VBRP~WERKS in SP$00005

and VBRP~MATNR in SP$00008

and VBRP~CHARG in SP$00009

and VBRP~AUBEL in SP$00017

and CKMLCR~CURTP in SP$00015

and CKMLCR~BDATJ in SP$00013

and CKMLCR~POPER in SP$00014

and CKMLCR_RECV~CURTP in SP$00019

and CKMLCR_RECV~BDATJ in SP$00020

and CKMLCR_RECV~POPER in SP$00018 .

4 REPLIES 4
Read only

nikhil_chitre
Active Participant
0 Likes
1,009

hello,

In your select quesry you have used inner join....this will affect the performance of you code.

instead use select with addition FOR ALL ENTRIES.

for more details refer to the SAP help and build up your select queries.

Regards,

Nikhil

Read only

Former Member
0 Likes
1,009

split the selects at each join and make different select queries with using FOR ALL ENTRIES.

and select from header tables first and then select from lines item tables

Read only

Former Member
0 Likes
1,009

Just split your query as 9 different select queries on the 9 tables you have used in the join. Connect each select query with the ON condition in the join query as the where condition with FOR ALL ENTRIES.

This is the least you can expect. Hope you are not expecting someone to send a code with 9 different select queries. That would be against forum rules.

Regards,

Vikranth

Read only

Former Member
0 Likes
1,009

Hi, it is not good for your performance to split into 9 selects but the select you are now using is also not so good. Start with VBRP instead of KNA1.

You can do it in the following way. For example:

DATA tb_kna1 TYPE STANDARD TABLE OF kna1.

DATA tb_vbrk TYPE STANDARD TABLE OF vrbk.

DATA tb_vrbp TYPE STANDARD TABLE OF vrbp.

.

  • Start with VRBP for a better performance

.

SELECT * FROM vrbp

INTO CORRESPONDING FIELDS OF TABLE tb_vbrp

WHERE werks IN .... etc.

SELECT * FROM vbrk

INTO CORRESPONDING FIELDS OF TABLE tb_vbrk

FOR ALL ENTRIES IN tb_vrbp

WHERE vbeln = tb_vrbp-vbeln.

SELECT * FROM kna1

INTO CORRESPONDING FIELDS OF TABLE tb_kna1

FOR ALL ENTRIES IN tb_vrbk

WHERE kunnr = tb_vrbk-kunnr.

Success.