Skip to Content
avatar image
Former Member

Can we use inner join and For all entries together?

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.

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

6 Answers

  • Best Answer
    avatar image
    Former Member
    Sep 04, 2008 at 08: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

    Add comment
    10|10000 characters needed characters exceeded

  • Sep 04, 2008 at 06:42 PM

    Yes, you can combine.

    Regards,

    Naimesh Patel

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Sep 04, 2008 at 06: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

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Sep 04, 2008 at 06:43 PM

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

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Sep 04, 2008 at 06:47 PM

    SORT t_sodata by vbeln posnr.

    DELETE ADJACENT DUPLICATES COMPARING VBELN POSNR.

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Sep 04, 2008 at 08: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

    Add comment
    10|10000 characters needed characters exceeded