2008 May 15 5:06 PM
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.
2008 May 15 7:09 PM
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
2008 May 15 5:12 PM
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,
2008 May 15 5:23 PM
It returns an syntax error with "You can not use an internal table as a work area"
2008 May 15 5:29 PM
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,
2008 May 15 5:18 PM
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.
2008 May 15 5:58 PM
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
2008 May 15 6:18 PM
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,
2008 May 15 6:33 PM
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
2008 May 15 6:47 PM
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.
2008 May 15 7:03 PM
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
2008 May 15 5:22 PM
select vkorg into table i_vkorg from ymmarket.
select * from mvke for all entries in i_vkorg where vkorg = i_vkorg-vkorg
2008 May 15 7:09 PM
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
2008 May 15 7:20 PM
2008 May 15 7:26 PM
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 ) ).
2008 May 15 7:28 PM
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.
2008 May 15 8:03 PM
| User | Count |
|---|---|
| 3 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |