Quantcast
Channel: SCN : All Content - ABAP Development
Viewing all articles
Browse latest Browse all 8332

Join help

$
0
0

I am relatively new to ABAP and am needing help with a join statement as it contains multiple tables.  I am trying to just simply display certain fields across MARA, MARC, MVKE, and MAKT based on their material numbers.  I have the ACCOUNT ASSIGNMENT GROUP field displayed and would like to list its description along with it.  I know that this is in table TVKMT and have tried to figure out a solution to get the correct amount of rows.  I currently have a working version that joins MARA, MVKE, MARC, and MAKT and then just loops through to get the AAG description as seen here:

 

<code>

*Put data into internal table

   SELECT marc~werks mvke~matnr mara~mtart makt~maktx marc~beskz mvke~vkorg mvke~vtweg mara~spart mvke~ktgrm

     FROM ( mvke

          INNER JOIN mara

          ON mara~matnr = mvke~matnr

          INNER JOIN marc

          ON marc~matnr = mara~matnr

          INNER JOIN makt

          ON makt~matnr = marc~matnr )

     INTO CORRESPONDING FIELDS OF TABLE dt_materials

       WHERE makt~spras IN spras

       AND marc~werks IN werks

       AND mvke~ktgrm IN ktgrm

       AND mvke~matnr IN matnr

       AND mvke~vkorg IN vkorg

       AND mvke~vtweg IN vtweg.

 

* Gets Account Assignment Group Description

   LOOP AT dt_materials INTO ds_materials.

     tab_index = sy-tabix.

     SELECT SINGLE tvkmt~vtext

       INTO ds_materials-vtext

       FROM tvkmt

       WHERE tvkmt~ktgrm = ds_materials-ktgrm

       and tvkmt~spras in spras.

     IF sy-subrc EQ 0.

       MODIFY dt_materials FROM ds_materials INDEX tab_index TRANSPORTING vtext.

     ENDIF.

   ENDLOOP.

</code>


I tried doing another join like this:

<code>

SELECT marc~werks mvke~matnr mara~mtart makt~maktx marc~beskz mvke~vkorg mvke~vtweg mara~spart mvke~ktgrm tvkmt~vtext

     FROM ( mara

          INNER JOIN marc

          ON marc~matnr = mara~matnr

          INNER JOIN makt

          ON makt~matnr = marc~matnr

          INNER JOIN mvke

          ON mvke~matnr = makt~matnr

          JOIN tvkmt

          ON tvkmt~ktgrm = mvke~ktgrm )

     INTO CORRESPONDING FIELDS OF TABLE dt_materials

       WHERE makt~spras IN spras

       AND tvkmt~spras IN spras

       AND marc~werks IN werks

       AND mvke~ktgrm IN ktgrm

       AND mvke~matnr IN matnr

       AND mvke~vkorg IN vkorg

       AND mvke~vtweg IN vtweg.


</code>


I've played around with different types of joins for the last one and can't seem to get the correct output as the above code.  I don't know if this is an overkill explanation for such a simple solution, but anyway...help would be appreciated. Thanks in advance!


Viewing all articles
Browse latest Browse all 8332

Trending Articles