Application Development and Automation 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: 
Read only

Need help SELECT wiht INNER JOIN

Former Member
0 Likes
1,678

Hi,

I need the the entire record of the MVKE with the same vkorg as in the table YMMARKET. Why has the bellow Join syntex error. Thank you

SELECT *

FROM MVKE

INNER JOIN YMMARKET_CODE ON mvkevkorg = ymmarket_codevkorg

WHERE matnr = p_matnr.

ENDSELECT.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,656

Hello,

revise your code like this:

SELECT *

FROM MVKE

INNER JOIN YMMARKET_CODE ON mvkevkorg = ymmarket_codevkorg

WHERE mvke~matnr = p_matnr.

ENDSELECT.

I hope help you

David

Do I really need the i_tab ?

And how should I define the itab when I need all fields of the entire record of the table mara for example?

Regards

15 REPLIES 15
Read only

Former Member
0 Likes
1,656

Hello,

Do this:


DATA:
  lt_mvke TYPE STANDARD TABLE OF MVKE.

SELECT <field1> <field2>
INTO TABLE lt_mvke
FROM MVKE AS M INNER JOIN YMMARKET_CODE AS Y ON m~vkorg = y~vkorg
WHERE matnr = p_matnr.

When using inner join you need to specify the fields.

I suggest you the following:


SELECT * FROM MVKE INTO TABLE lt_mvke
  FOR ALL ENTRIES IN YMMARKET_CODE
  WHERE matnr = p_matnr 
       AND vkorg = ymmarket_code-vkorg.

Regards,

Read only

0 Likes
1,656

It returns an syntax error with "You can not use an internal table as a work area"

Read only

0 Likes
1,656

Hello,

Try this:


DATA:
  lt_mvke TYPE TABLE OF mvke,
  ls_mvke LIKE LINE OF lt_mvke,
  lt_ymmarket TYPE TABLE OF ymmarket_code-vkorg.

SELECT * FROM MVKE INTO TABLE lt_mvke WHERE matnr = p_matnr.
IF NOT lt_mvke IS INITIAL.
  SELECT vkorg FROM YMMARKET_CODE INTO TABLE lt_ymmarket
    FOR ALL ENTRIES IN lt_mvke WHERE vkorg = lt_mvke-vkorg.

  LOOP AT lt_mvke INTO ls_mvke.
    READ TABLE lt_ymmarket WITH KEY vkorg = ls_mvke-vkorg TRANSPORTING NO FIELDS.
    IF SY-SUBRC NE 0.
      DELETE LT_MVKE.
    ENDIF.
  ENDLOOP.
ENDIF.

Regards,

Read only

Former Member
0 Likes
1,656

whenever u join two table using joins u should use alias names

ex:

parameter:p_matnr type mara-matnr.

select a~matnr 
          a~mbrsh
          a~mbrsh
          b~maktx
into table itab
where mara as a inner join makt as b on a~matnr eq b~matnr
                                           and a~matnr eq p_matnr.

Read only

0 Likes
1,656

Do I really need the i_tab ?

And how should I define the itab when I need all fields of the entire record of the table mara for example?

Regards

Read only

0 Likes
1,656

Hello,

Using this method that I described you get a better performance than using INNER JOINS.

To define tables with all fields of a structure/transparent table defined in the DDIC just do the following:


  DATA lt_itab TYPE TABLE OF <structure/transparent table>.

Regards,

Read only

0 Likes
1,656

Thank you very much for your respond. However I couldn't understand your coding much. Instead would you please look to my without the Join

  • Read the Sales data for Material

SELECT *

FROM MVKE INTO TABLE i_mvke

WHERE matnr = p_matnr.

LOOP AT i_mvke INTO i_mvke.

SELECT SINGLE vkorg

FROM YMMARKET_CODE

INTO YMMARKET_CODE-vkorg

WHERE vkorg = i_mvke.

IF sy-subrc = 0.

exit.

ENDIF.

ENDLOOP.

I just want to take the record of the MVKE which has the same "vkorg" in the table YMMARKET_CODE

Thanks

Read only

0 Likes
1,656

Why did u dropped your join idea ?

anyways, for thsi code,

after looping you need to delete those entries, which dont have a hit from YMMARKET_CODE, right ?

SELECT *

FROM MVKE INTO TABLE i_mvke

WHERE matnr = p_matnr.

LOOP AT i_mvke . "INTO i_mvke.

SELECT SINGLE vkorg

FROM YMMARKET_CODE

INTO YMMARKET_CODE-vkorg

WHERE vkorg = i_mvke-vkorg.

IF sy-subrc ne 0.

delete i_mvke.

continue.

ENDIF.

ENDLOOP.

now at the end of this loop, i_mvke, will have all those entries, which have a corresponding hit in

YMMARKET_CODE, for the VKORG.

Read only

0 Likes
1,656

It didn't work with the Join and I had not much time left to spend on this, but you are right, with the i_mvke-vkorg. I just copied it before writing this to end. But from the performance point of view which solution is better. Join or select with loop? Sorry that I keep asking you

/Thanks

Read only

Former Member
0 Likes
1,656

select vkorg into table i_vkorg from ymmarket.

select * from mvke for all entries in i_vkorg where vkorg = i_vkorg-vkorg

Read only

Former Member
0 Likes
1,657

Hello,

revise your code like this:

SELECT *

FROM MVKE

INNER JOIN YMMARKET_CODE ON mvkevkorg = ymmarket_codevkorg

WHERE mvke~matnr = p_matnr.

ENDSELECT.

I hope help you

David

Read only

0 Likes
1,656

The INTO is missing

Read only

0 Likes
1,656

you need create a internal table with the all fields the both tables, similar this code:

SELECT

ANEK~BUKRS

ANEK~ANLN1

ANEK~ANLN2

ANEK~GJAHR

ANEK~LNRAN

ANEK~BUDAT

ANEP~AFABE

ANEP~BWASL

ANEP~ANBTR

ANEP~NAFAB

ANEP~SAFAB

ANEP~ZINSB

INTO CORRESPONDING FIELDS OF TABLE IT_ANEK_P

FROM ( ANEK INNER JOIN ANEP

ON ANEPBUKRS = ANEKBUKRS

AND ANEPANLN1 = ANEKANLN1

AND ANEPANLN2 = ANEKANLN2

AND ANEPGJAHR = ANEKGJAHR

AND ANEPLNRAN = ANEKLNRAN )

WHERE ANEK~BUKRS = <IT_SOC>-BUKRS

AND ANEK~ANLN1 IN S_ANLN1

AND ANEK~GJAHR = v_ANO

AND ANEK~BUDAT IN RDATE

AND ANEP~AFABE <> '15'

AND ( ( ANEP~BWASL IN RALTAS ) OR

( ANEP~BWASL IN RBAJAS ) OR

( ANEP~BWASL IN RTRASL ) ).

Read only

0 Likes
1,656

data : t_mvke type standard table of mvke.

SELECT *

FROM MVKE

INNER JOIN YMMARKET_CODE ON mvkevkorg = ymmarket_codevkorg

into corresponding fields of table t_mvke

WHERE mvke~matnr = p_matnr.

Read only

0 Likes
1,656

Thanks it works now how it should.