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

Inner Join Problem

Former Member
0 Likes
574

Hi,

I am having some problem with my inner join, trying to link two tables MSEG and MKPF.

The problem is that I don't know what to link the Tables with,

please help me.

DATA:

t_Sloc TYPE MSEG-LGORT,

t_MvT TYPE MSEG-BWART,

t_MatD TYPE MKPF-MBLNR,

t_Item TYPE MSEG-ZEILE,

t_Post TYPE MKPF-BUDAT,

t_Q TYPE MSEG-MENGE,

t_Bun TYPE MSEG-MEINS,

TotalQ TYPE i.

START-OF-SELECTION.

SELECT MSEGLGORT MSEGBWART MSEGZEILE MSEGMENGE MSEG~MEINS

FROM MSEG

INNER JOIN MKPF ON MSEGBWART = MKPFBUDAT

INTO (t_Sloc, t_MvT, t_Item, t_Q, t_Bun)

WHERE MSEG~MATNR = INPUT.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
557

Hi John,

See this below:

select smblnr smjahr sbwart smatnr swerks smenge

appending corresponding fields of table t_mseg

from mseg as s inner join mkpf as k

on smblnr = kmblnr and

smjahr = kmjahr

where s~matnr in s_matnr

and s~werks in s_werks_full

and ( sbwart eq lit_101 or sbwart eq lit_102 )

and k~budat between s_budat-low and s_budat-high

and s~bukrs = p_bukrs.

or u can also use view WB2_V_MKPF_MSEG2 .

Sri

4 REPLIES 4
Read only

Former Member
0 Likes
558

Hi John,

See this below:

select smblnr smjahr sbwart smatnr swerks smenge

appending corresponding fields of table t_mseg

from mseg as s inner join mkpf as k

on smblnr = kmblnr and

smjahr = kmjahr

where s~matnr in s_matnr

and s~werks in s_werks_full

and ( sbwart eq lit_101 or sbwart eq lit_102 )

and k~budat between s_budat-low and s_budat-high

and s~bukrs = p_bukrs.

or u can also use view WB2_V_MKPF_MSEG2 .

Sri

Read only

0 Likes
557

Thank you so much I can now join MSEG and MKPF you made my day/night

But Sri,

what does this do in you answer:

and s~werks in s_werks_full

and ( sbwart eq lit_101 or sbwart eq lit_102 )

and k~budat between s_budat-low and s_budat-high

and s~bukrs = p_bukrs.

Read only

Former Member
0 Likes
557

hi

good

you can use tha MBLNR as the key field to join both the table,bcz this is the key field which i present in both the table.

thanks

mrutyun^

Read only

Former Member
0 Likes
557

hi john,

It is better change ur code as following .. it works

TYPES: BEGIN OF ty_itab,

lgort TYPE lgort_d,

bwart TYPE bwart,

mblnr TYPE mblnr,

zeile TYPE mblpo,

budat TYPE budat,

menge TYPE menge_d,

meins TYPE meins,

totalq TYPE i,

END OF ty_itab.

DATA: wa_itab TYPE ty_itab,

it_itab TYPE STANDARD TABLE OF ty_itab.

START-OF-SELECTION.

SELECT mseglgort msegbwart msegzeile msegmenge mseg~meins

FROM mseg

INNER JOIN mkpf ON msegbwart = mkpfbudat

INTO CORRESPONDING FIELDS OF TABLE IT_ITAB.

WHERE mseg~matnr = input.

rewards if useful

regards

sree