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

problem with inner join

Former Member
0 Likes
2,144
select
        mara~matnr
        mara~mtart
        mara~matkl
        mara~bmatn
        mara~bismt
        mara~meins
        mara~mfrpn
        mara~mfrnr
        makt~maktx
        lfa1~lifnr
        lfa1~name1
   into table lt_output
        from mara
   inner join makt on mara~matnr = makt~matnr
   inner join lfa1 on mara~mfrnr = lfa1~lifnr
   where
        mara~matnr in s_matnr and
        mtart in s_mtart and
        matkl in s_matkl and
        bmatn in s_bmatn and
        bismt in s_bismt and
        meins in s_meins and
        mfrpn in s_mfrpn and
        mfrnr in s_mfrnr.

when I inner join these three tables am getting 34 records in the output table but when I enter material number matnr and check it, no records was showing up....I think inner join was failed can any one help me

Edited by: Thomas Zloch on Apr 14, 2010 4:21 PM - tags added

18 REPLIES 18
Read only

Former Member
0 Likes
1,796

Did you intend to omit the table names in this part of WHERE?

mtart in s_mtart and
        matkl in s_matkl and
        bmatn in s_bmatn and
        bismt in s_bismt and
        meins in s_meins and
        mfrpn in s_mfrpn and
        mfrnr in s_mfrnr. 

I've never tried without supplying the mara~, etc.

Trying deconstructing...see if you get values in SE11 from MARA only , with the where clause (that applies to MARA), then LFA1, etc.

Read only

Former Member
0 Likes
1,796

>

>

select
>         mara~matnr
>         mara~mtart
>         mara~matkl
>         mara~bmatn
>         mara~bismt
>         mara~meins
>         mara~mfrpn
>         mara~mfrnr
>         makt~maktx
>         lfa1~lifnr
>         lfa1~name1
>    into table lt_output
>         from mara
>    inner join makt on mara~matnr = makt~matnr
>    inner join lfa1 on mara~mfrnr = lfa1~lifnr
>    where
>         mara~matnr in s_matnr and
>         mtart in s_mtart and
>         matkl in s_matkl and
>         bmatn in s_bmatn and
>         bismt in s_bismt and
>         meins in s_meins and
>         mfrpn in s_mfrpn and
>         mfrnr in s_mfrnr.

> when I inner join these three tables am getting 34 records in the output table but when I enter material number matnr and check it, no records was showing up....I think inner join was failed can any one help me

>

> Edited by: Thomas Zloch on Apr 14, 2010 4:21 PM - tags added

Hi,

Please change your WHERE condition like this,(Give the Table Alias along with field name )

where

> mara~matnr in s_matnr and

> mara~mtart in s_mtart and

> mara~matkl in s_matkl and

> mara~bmatn in s_bmatn and

> mara~bismt in s_bismt and

> mara~meins in s_meins and

> mara~mfrpn in s_mfrpn and

> mara~mfrnr in s_mfrn

Read only

Former Member
0 Likes
1,796

I've tried with thata too same answer...if I give material no no record is printing

Read only

0 Likes
1,796

Hi

I think you are not giving valid material so u r not getting the result.

Try with the Valid material range becaus eu r using all AND condtion .

Fot that particualer material what u have given in where condtions it should also satisfy.

Check wheather in where condtion it is AND or OR.

Ask for the valid Test data to functional consultant.

Regards,

Pravin

Read only

0 Likes
1,796

Let's first of all get rid of the myth that the table names are required in the join when specifying field names: This is only necessary, when the given field/column appears in more than one of the join's database tables. In certain cases it is still good practice though, because if for some strange reason one of the tables would be changed and now you'd actually have duplicate field names across tables, the SQL statement would no longer be syntactically correct.

Now to your problem, which I'm not sure I understand, so let me rephrase. When you run the join without any restrictions you get 34 records, but when entering a condition on material number you get 0 records. If that's the case then most likely your problem is that you used the wrong reference for defining your select-option <em>s_matnr</em>, which has to be of type <em>matnr</em> (or similar) to ensure that the correct conversion exit <em>matn1</em> gets applied.

Otherwise if your system is configured to store material numbers with leading zeros, you won't get any match if you search for material number 1, when you actually should have looked for 000000000001. By using the right type you ensure that this conversion happens as it should.

You can also quickly check this in SE16 or SE16N, just make sure to switch off the conversion exits in the settings for the transaction (that way you see the non-numeric data as it is stored on the database rather than how it's displayed for the user).

And as Nehruu mentioned, either select the language or add a condition on language. Otherwise you'll end up with duplicate records if your system stores material descriptions in more than one language.

Read only

Former Member
0 Likes
1,796

Hi

You have to pass the logon Language Key to MAKT~SPRAS = sy-langu you can get correct output.

Regards

Nehruu

Read only

Former Member
0 Likes
1,796

This is the complete code I've used to print this report....I tried tomake changes suggested by you guys but the same reply

Moderator message - Please respect the 2,500 character maximum when posting. Post only the relevant portions of code

Edited by: Rob Burbank on Apr 15, 2010 2:54 PM

Read only

0 Likes
1,796

Moderator message - Please respect the 2,500 character maximum when posting. Post only the relevant portions of code

Edited by: Rob Burbank on Apr 15, 2010 2:57 PM

Read only

0 Likes
1,796

Moderator message - Please respect the 2,500 character maximum when posting. Post only the relevant portions of code

Edited by: Rob Burbank on Apr 15, 2010 2:56 PM

Read only

0 Likes
1,796

Moderator message - Please respect the 2,500 character maximum when posting. Post only the relevant portions of code

Edited by: Rob Burbank on Apr 15, 2010 2:57 PM

Read only

0 Likes
1,796

Moderator message - Please respect the 2,500 character maximum when posting. Post only the relevant portions of code

Edited by: Rob Burbank on Apr 15, 2010 2:57 PM

Read only

0 Likes
1,796

Moderator message - Please respect the 2,500 character maximum when posting. Post only the relevant portions of code

Edited by: Rob Burbank on Apr 15, 2010 2:58 PM

Read only

0 Likes
1,796

Moderator message - Please respect the 2,500 character maximum when posting. Post only the relevant portions of code

Edited by: Rob Burbank on Apr 15, 2010 2:58 PM

Read only

0 Likes
1,796

i AM REALLY SORRY GUYS I HAVE POSTED SO MANYMESSAGES....THAT IS THE CODE I USED TO PRINT THE OUTPUT. I HAVE ALSO TRIED UR SUGGESSIONS. PLEASE LET ME KNOW IF IHAVE TO MAKE ANY MODIFICATIONS.

Moderator message - Please do not try to get around the limit by making multiple posts. Much of what you posted was code that was commented out. Please alo do not use all caps. Rob

Edited by: Rob Burbank on Apr 15, 2010 2:59 PM

Read only

Former Member
0 Likes
1,796

Hi I think you need a slight modification to your code.

select

mara~matnr

mara~mtart

mara~matkl

mara~bmatn

mara~bismt

mara~meins

mara~mfrpn

mara~mfrnr

makt~maktx

lfa1~lifnr

lfa1~name1

into table lt_output

from mara

inner join makt on maramatnr = maktmatnr

inner join lfa1 on maramfrnr = lfa1lifnr

where

maramatnr = maktmatnr and

maramfrnr = lfa1lifnr and

mara~matnr in s_matnr and

mtart in s_mtart and

matkl in s_matkl and

bmatn in s_bmatn and

bismt in s_bismt and

meins in s_meins and

mfrpn in s_mfrpn and

mfrnr in s_mfrnr.

I hope this will solve your problem..

Please revert back in case of any issues..

Read only

Former Member
0 Likes
1,796

Try with JOIN instead of INNER JOIN.

And you must check MAKT-SPRAS value. Remember there is a description for every language that you've been installed. Maybe the output will result on several records of the same material.

Read only

Yasin
Active Participant
0 Likes
1,796

Try to run your SQL statement without joining the lfa1 table and check the output.

Yasin.

Read only

Former Member
0 Likes
1,796

I have tried to remove join for lfa1 and retrived the data from different sql statement...same result.....and where should i pass the spars language key