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

help me

Former Member
0 Likes
848

Hi,

I have 2 tables in my report ( mseg & mkpf ) and I would like to output [ mkpf-xblnr, mkpf-mblnr, mseg-wempf and mseg-menge]. Can you please help in solving my problem.

I wort this code but it is not working:

**************************************************************

Start-Of-Selection.

  • MSEG TABLE

select matnr mblnr lgort ablad wempf menge from mseg into

corresponding fields of table t_mseg where

werks = '5900' and

( bwart = '101' or

bwart = '102' ) and

wempf = pa_wempf.

LOOP AT t_mseg INTO wa_mseg.

write wa_mseg-wempf .

  • MKPF TABLE

select budat mblnr xblnr from mkpf into corresponding

fields of table t_mkpf for all entries in t_mseg

where mblnr = t_mseg-mblnr and

budat ge pa_sdate and

budat le pa_edate.

write wa_mkpf-xblnr.

write wa_mkpf-mblnr.

endloop.

8 REPLIES 8
Read only

Former Member
0 Likes
825

Hello,

Start-Of-Selection.

  • MSEG TABLE

select matnr mblnr lgort ablad wempf menge from mseg into

corresponding fields of table t_mseg where

werks = '5900' and

( bwart = '101' or

bwart = '102' ) and

wempf = pa_wempf.

write wa_mseg-wempf .

  • MKPF TABLE

select budat mblnr xblnr from mkpf into corresponding

fields of table t_mkpf for all entries in t_mseg

where mblnr = t_mseg-mblnr and

budat ge pa_sdate and

budat le pa_edate.

LOOP AT t_mkpf INTO wa_mkpf.

write wa_mkpf-xblnr.

write wa_mkpf-mblnr.

ENDLOOP.

Neeraj.

Read only

Former Member
0 Likes
825

Hi Shaheen,

Please write both the select statements under START-OF-SELECTION.

and then when you are looping at t_mseg (LOOP AT t_mseg INTO wa_mseg). Read the other table i.e, t_mkpf with all the relevant fields and use write statement to display the output.

Reward points if helpful.

Thanks,

Asha

Read only

Former Member
0 Likes
825

Try this..

data: begin of itab occurs 0,

xblnr like mkpf-xblnr,

mblnr like mkpf-mblnr,

wempf like mkpf-wempf,

menge like mseg-menge,

end of itab.

select mkpfxblnr mkpfmblnr msegwempf msegmenge into corresponding fields of table itab from mkpf inner join mseg on ( mkpfmblnr = msegmblnr and mkpfmjahr = msegmjahr ) where mkpfbudat ge pa_sdate and mkpfbudat le paedate and msegwerks = '5900' and msegbwart in ('101','102') and msegwempf = pa_wempf.

reward if useful

Regards

Sugumar G

Read only

Former Member
0 Likes
825

use for all entries

first select data from one table and then again write another select statement for another table using for all entries of the above table

not u output the data.

or u can use inner join to join two tables and display them

reward if helpful

raam

Read only

dhruv_shah3
Active Contributor
0 Likes
825

Hi,

Write as this:

select matnr mblnr lgort ablad wempf menge from mseg into

corresponding fields of table t_mseg where

werks = '5900' and

bwart IN ('101','102' ) and

wempf = pa_wempf.

select budat mblnr xblnr from mkpf into corresponding

fields of table t_mkpf for all entries in t_mseg

where mblnr = t_mseg-mblnr and

budat between pa_sdate and pa_edate.

LOOP AT t_mseg INTO wa_mseg.

write wa_mseg-wempf .

write wa_mkpf-xblnr.

write wa_mkpf-mblnr.

endloop.

HTH

Regards,

Dhruv Shah

Read only

0 Likes
825

Thanks but i still not getting the required output

Read only

Former Member
0 Likes
825

Hi shaheen khan,

what i understud from yourproblem is you want to selected fields from both tables. i think you should join two tables ,

with where condition and can try somthing like this,

select axblnr amblnr bwempf bmenge into

CORRESPONDING FIELDS OF TABLE t_mseg

from mseg as a join mkpf as b

on (write the conditions what you need).

but remember in condition if you are using table fields then dont forget to prefix the table name as "a" or "b".

and create a work area with the fields you needed , and using that work area you can do it, i have some different example similar to that, hope it may help full to you,

Example:

REPORT ZSKASSIGNMENT1.

PARAMETERS : idno1 type i,idno2 type i.

data : BEGIN OF wa,

name type zname1,

idno type i,

sex type zname1,

course type zname1,

address(20),

END OF wa.

data : itab like STANDARD TABLE OF wa.

select aname aidno bsex acourse b~address into

CORRESPONDING FIELDS OF TABLE itab

from zskassignmentta1 as a join zskassignmentta2 as b

on aidno = bidno where a~idno between idno1 and idno2.

loop at itab into wa.

WRITE 😕 wa-idno ,wa-name,wa-sex,wa-course,wa-address.

ENDLOOP.

Regards:

syed khutubuddin.

Read only

Former Member
0 Likes
825

Hi,

Please refer the below code..

declare pa_wempf,pa_sdate,pa_edate.

data:t_mseg type TABLE OF mseg,

wa_mseg type mseg.

data:t_mkpf type TABLE OF mkpf,

wa_mkpf type mkpf.

Start-Of-Selection.

  • MSEG TABLE

select matnr mblnr lgort ablad wempf menge from mseg into

corresponding fields of table t_mseg where

werks = '5900' and

( bwart = '101' or

bwart = '102' ) and

wempf = pa_wempf.

write wa_mseg-wempf .

    • MKPF TABLE

select budat mblnr xblnr from mkpf into corresponding

fields of table t_mkpf for all entries in t_mseg

where mblnr = t_mseg-mblnr and

budat ge pa_sdate and

budat le pa_edate.

LOOP AT t_mkpf INTO wa_mkpf.

write wa_mkpf-xblnr.

write wa_mkpf-mblnr.

ENDLOOP.

Reward if it is useful

Regards,

Vijay