09-04-2008 7:40 PM
Hello Experts,
I am using "For All entries" clause as below. I want to fetch data (some fields) from VBAK and VBAP based on all entries in table fp_ft_itm.
Please advice if I can combine the select using inner join.
Thanks,
Anand
The code:-
DATA: BEGIN OF wa_sodata,
vbeln TYPE vbak-vbeln,
posnr TYPE vbap-posnr,
mvgr5 TYPE vbap-mvgr5,
vgbel TYPE vbap-vgbel,
auart TYPE vbak-auart,
vbtyp TYPE vbak-vbtyp,
END OF wa_sodata.
DATA: t_sodata LIKE STANDARD TABLE OF wa_sodata.
IF NOT fp_ft_itm[] IS INITIAL.
SELECT vbeln posnr mvgr5 vgbel FROM vbap
INTO TABLE t_sodata
FOR ALL ENTRIES IN fp_ft_itm
WHERE
vbeln = fp_ft_itm-aubel AND
posnr = fp_ft_itm-aupos.
ENDIF.
*
CLEAR wa_sodata.
LOOP AT t_sodata INTO wa_sodata.
SELECT SINGLE auart vbtyp FROM vbak
INTO (wa_sodata-auart, wa_sodata-vbtyp)
WHERE
vbeln = wa_sodata-vbeln.
MODIFY t_sodata FROM wa_sodata.
ENDLOOP.
SORT t_sodata BY vbeln auart.
09-04-2008 9:41 PM
Hi,
Modified your code..
DATA: BEGIN OF wa_sodata,
vbeln TYPE vbak-vbeln,
posnr TYPE vbap-posnr,
mvgr5 TYPE vbap-mvgr5,
vgbel TYPE vbap-vgbel,
auart TYPE vbak-auart,
vbtyp TYPE vbak-vbtyp,
END OF wa_sodata.
DATA: t_sodata LIKE STANDARD TABLE OF wa_sodata.
IF NOT fp_ft_itm[] IS INITIAL.
SELECT A~vbeln A~posnr A~mvgr5 A~vgbel
b~auart b~vbtyp
INTO TABLE t_sodata
FROM vbap AS A INNER JOIN vbak as B
ON A~vbeln = b~vbeln
FOR ALL ENTRIES IN fp_ft_itm
WHERE
a~vbeln = fp_ft_itm-aubel AND
a~posnr = fp_ft_itm-aupos.
ENDIF.
*
SORT t_sodata BY vbeln auart.
Thanks
Naren
09-04-2008 7:42 PM
09-04-2008 7:43 PM
Thumb rule before using FOR ALL ENTRIES you need to sort the ITAB and delet adjacent duplicates you have not done that.
09-04-2008 7:47 PM
SORT t_sodata by vbeln posnr.
DELETE ADJACENT DUPLICATES COMPARING VBELN POSNR.
09-04-2008 7:50 PM
Your subject and Message are different . Any how i m answering both
Previous replies for your message content .
Can we use inner join and For all entries together?
Yes you can
09-04-2008 9:37 PM
Hello,
Sorry, my question was not correct:
How to combine inner join and For all entries together instead of writing 2 separate select statements for VBAP and VBAK tables?
Thanks and regards,
Anand
09-04-2008 9:41 PM
Hi,
Modified your code..
DATA: BEGIN OF wa_sodata,
vbeln TYPE vbak-vbeln,
posnr TYPE vbap-posnr,
mvgr5 TYPE vbap-mvgr5,
vgbel TYPE vbap-vgbel,
auart TYPE vbak-auart,
vbtyp TYPE vbak-vbtyp,
END OF wa_sodata.
DATA: t_sodata LIKE STANDARD TABLE OF wa_sodata.
IF NOT fp_ft_itm[] IS INITIAL.
SELECT A~vbeln A~posnr A~mvgr5 A~vgbel
b~auart b~vbtyp
INTO TABLE t_sodata
FROM vbap AS A INNER JOIN vbak as B
ON A~vbeln = b~vbeln
FOR ALL ENTRIES IN fp_ft_itm
WHERE
a~vbeln = fp_ft_itm-aubel AND
a~posnr = fp_ft_itm-aupos.
ENDIF.
*
SORT t_sodata BY vbeln auart.
Thanks
Naren