Application Development 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: 

Can we use inner join and For all entries together?

Former Member
0 Kudos

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.

1 ACCEPTED SOLUTION

Former Member

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

6 REPLIES 6

naimesh_patel
Active Contributor

Yes, you can combine.

Regards,

Naimesh Patel

Former Member
0 Kudos

Thumb rule before using FOR ALL ENTRIES you need to sort the ITAB and delet adjacent duplicates you have not done that.

Former Member
0 Kudos

SORT t_sodata by vbeln posnr.

DELETE ADJACENT DUPLICATES COMPARING VBELN POSNR.

Former Member
0 Kudos

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

Former Member
0 Kudos

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

Former Member

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