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

DEBUG... some mistake in coding joins

Former Member
0 Likes
1,483

REPORT YSDFHSH .

tables : marc,

makt,

mara.

data : begin of t_marc occurs 0,

matnr like marc-matnr,

werks like marc-werks,

maktx like makt-maktx,

zeinr like mara-zeinr,

aeszn like mara-aeszn,

end of t_marc.

select-options : s_matnr for marc-matnr,

s_werks for marc-werks,

sa_lvor for mara-lvorm.

parameters : p_spras like makt-spras.

SELECT cMATNR cWERKS tMAKTX aZEINR a~AESZN

INTO TABLE t_marc

FROM ( marc as c

INNER JOIN MAKT as t ON cMATNR = tMATNR )

INNER JOIN MARA as a ON cMATNR = aMATNR

WHERE c~MATNR IN S_MATNR

AND c~WERKS IN S_WERKS

AND a~LVORM IN Sa_LVOR

AND t~SPRAS = P_SPRAS.

if sy-subrc ne 0.

message 'What hppened' type 'S'.

endif.

loop at t_marc.

write : / t_marc-matnr,

t_marc-werks,

t_marc-maktx,

t_marc-zeinr,

t_marc-aeszn.

endloop.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
983

What is the issue?

6 REPLIES 6
Read only

Former Member
0 Likes
984

What is the issue?

Read only

0 Likes
983

Also, you may want to swap the MARA and MAKT join since your WHERE clause dicates that C comes first, then A, then T.



report ysdfhsh .

tables : marc, makt, mara.

data : begin of t_marc occurs 0,
       matnr like marc-matnr,
       werks like marc-werks,
       maktx like makt-maktx,
       zeinr like mara-zeinr,
       aeszn like mara-aeszn,
       end of t_marc.

select-options : s_matnr for marc-matnr,
                 s_werks for marc-werks,
                 sa_lvor for mara-lvorm.
parameters : p_spras like makt-spras default 'EN'.


select c~matnr c~werks t~maktx a~zeinr a~aeszn
        into table t_marc
           from marc as c
<b>                    inner join mara as a
                       on c~matnr = a~matnr
                    inner join makt as t
                       on c~matnr = t~matnr</b>
                          where c~matnr in s_matnr
                            and c~werks in s_werks
                            and a~lvorm in sa_lvor
                            and t~spras = p_spras.

if sy-subrc ne 0.
*  message  'What hppened' type 'S'.
endif.

loop at t_marc.
  write : / t_marc-matnr,
  t_marc-werks,
  t_marc-maktx,
  t_marc-zeinr,
  t_marc-aeszn.
endloop.

Regards,

Rich Heilman

Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
983

Works ok, in my system. Were you forgetting to fill the language code on the selection screen.



report ysdfhsh .

tables : marc,
makt,
mara.

data : begin of t_marc occurs 0,
matnr like marc-matnr,
werks like marc-werks,
maktx like makt-maktx,
zeinr like mara-zeinr,
aeszn like mara-aeszn,
end of t_marc.

select-options : s_matnr for marc-matnr,
s_werks for marc-werks,
sa_lvor for mara-lvorm.
<b>parameters : p_spras like makt-spras default 'EN'.</b>

select c~matnr c~werks t~maktx a~zeinr a~aeszn
into table t_marc
from ( marc as c
inner join makt as t on c~matnr = t~matnr )
inner join mara as a on c~matnr = a~matnr
where c~matnr in s_matnr
and c~werks in s_werks
and a~lvorm in sa_lvor
and t~spras = p_spras.

if sy-subrc ne 0.
*  message  'What hppened' type 'S'.
endif.

loop at t_marc.
  write : / t_marc-matnr,
  t_marc-werks,
  t_marc-maktx,
  t_marc-zeinr,
  t_marc-aeszn.
endloop.

Regards,

Rich Heilman

Read only

Former Member
0 Likes
983

when i execute the selection screen (without entering values), no data is displayed. Could you please explain why?

Read only

0 Likes
983

Rich gave you the answer then. You have a '=' comparison in your WHERE clause and for it to work, you need a value for language that is maintained for the material.

Message was edited by: Srinivas Adavi

Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
983

If you don't want to take into account the lauguage key, remove it from the selection screen and just change the WHERE clause like this.






select c~matnr c~werks t~maktx a~zeinr a~aeszn
        into table t_marc
           from marc as c
                    inner join mara as a
                       on c~matnr = a~matnr
                    inner join makt as t
                       on c~matnr = t~matnr
                          where c~matnr in s_matnr
                            and c~werks in s_werks
                            and a~lvorm in sa_lvor
<b>                            and t~spras = sy-langu.</b>



Regards,

Rich Heilman