cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Join 3 tables

Abapper0114
Explorer
0 Likes
570

Hello experts,

Can you help me join these 3 tables?

  SELECT ebeln
         bsart
    FROM ekko
    INTO TABLE it_ekko
   WHERE bsart = 'ZLSR'.

  IF it_ekko IS NOT INITIAL.
    SELECT ebeln,
           ebelp,
           matnr,
           werks,
           menge,
           bwtty,
           bwtar
      FROM ekpo
       FOR ALL ENTRIES IN @IT_ekko
     WHERE ebeln = @IT_ekko-ebeln
      INTO TABLE @IT_ekpo.

    IF it_ekpo IS NOT INITIAL.
      SELECT stprs,
             matnr,
             bwkey,
             bwtar,
             bwtty
        FROM mbew
         FOR ALL ENTRIES IN @IT_ekpo
       WHERE matnr = @IT_ekpo-matnr
         AND bwkey = @IT_ekpo-werks
        INTO TABLE @IT_mbew.

        IF sy-subrc = 0.
        ENDIF.
    ENDIF.
  ENDIF.

I've already tried this and it's not getting the right record. 

SELECT c~stprs,
       c~matnr,
       c~bwkey,
       c~bwtar,
       c~bwtty
  FROM ekko AS A
    INNER JOIN ekpo AS b
          ON a~ebeln = b~ebeln
    INNER JOIN mbew AS c
          ON c~matnr = b~matnr
         AND c~bwkey = b~werks
  WHERE a~bsart = 'ZLSR'
  INTO TABLE @DATA(it_temp).

 With using the first code sample IT_MBEW gets 41 records while using the 2nd code sample, IT_TEMP gets 112 records. 

Accepted Solutions (0)

Answers (1)

Answers (1)

RaymondGiuseppi
Active Contributor
0 Likes

You can add T001W so that your code will also other options of Customizing (as suggested by @KjetilKilhavn.

But also check for MM Customizing : Split Valuation, you can get multiple valuation per plant (e.g. new/used and a total record) and you don't provide enough fields in the join.

  • I ususally add a "bwtty = space OR bwtar <> space" clause to remove duplicates in some MM reports.
  • Note that BWTAR and BWTTY are also in table EKPO but you don't use them
  • Use STPRS when VPRSV is 'S' and VERPR when 'V' 

What exactly are you looking for in MBEW?