Application Development 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: 

Logic Confusion!!!

0 Kudos

Dear all seniors,
I have a requirement to pick some fields (Matnr, Menge, Meins) from the table "MSEG" on the basis of two fields of MKPF Table, which are common in both tables (MBLNR & MJAHR) so i have used where clause there is no problem till there.
But Now i have to pick 1 field from MAKT which is MAKT-MAKTX, now i am confused in logic to pick that field from MAKT table.

Queries that i am using are,

For MKPF: SELECT SINGLE budat usnam blart FROM mkpf
INTO wa_mkpf
WHERE mblnr = mkpf-mblnr AND
mjahr = mkpf-mjahr.

For MSEG: SELECT SINGLE budat usnam blart FROM mkpf
INTO wa_mkpf
WHERE mblnr = mkpf-mblnr AND
mjahr = mkpf-mjahr.

1 ACCEPTED SOLUTION

raymond_giuseppi
Active Contributor

Do a single select with JOIN with the 3 select

select MKPF-BUDAT, MKPF-USNAM, MKPF-BLART,
       MSEG-MATNR, MSEG-MENGE, MSEG-MEINS,
       MAKT-MAKTX
from MSEG
join MKPF on MSEG-MBLNR = MKPF-MBLNR and MSEG-MJAHR = MKPF-MJAHR
left join MAKT on MAKT-MATNR = MSEG-MATNR AND MAKT-SPRAS = SY-LANGU
where MKPF-MBLNR = P_MBLNR AND MKPF-MJAHR = P_JAHR.

(add the language key to prevent duplicates)

5 REPLIES 5

yogananda
Product and Topic Expert
Product and Topic Expert

zaibshah-
You should join MAKT on MATNR field:

select MSEG-MATNR,MSEG-MENGE,MSEG-MEINS,MAKT-MAKTX 
from MSEG 
inner join MKPF on MSEG-MBLNR = MKPF-MBLNR and MSEG-MJAHR = MKPF-MJAHR
inner join MAKT on MAKT-MATNR = MSEG-MATNR 
where MKPF-MBLNR = '4500002100'

0 Kudos

Thank you soo much sir.

raymond_giuseppi
Active Contributor

Do a single select with JOIN with the 3 select

select MKPF-BUDAT, MKPF-USNAM, MKPF-BLART,
       MSEG-MATNR, MSEG-MENGE, MSEG-MEINS,
       MAKT-MAKTX
from MSEG
join MKPF on MSEG-MBLNR = MKPF-MBLNR and MSEG-MJAHR = MKPF-MJAHR
left join MAKT on MAKT-MATNR = MSEG-MATNR AND MAKT-SPRAS = SY-LANGU
where MKPF-MBLNR = P_MBLNR AND MKPF-MJAHR = P_JAHR.

(add the language key to prevent duplicates)

0 Kudos

Thank you soo much sir..

zaibshah- You have marked the other answer as accepted, so I'm not sure you understood well: better use

left join MAKT on MAKT-MATNR = MSEG-MATNR AND MAKT-SPRAS = SY-LANGU

rather than

inner join MAKT on MAKT-MATNR = MSEG-MATNR

because of language selection, and also because for texts left join is better than inner join in case there's no text provided in the database.