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: 

How to implement Select option and parameter from multiple table in ABAP Report

0 Kudos

Hi folks,

I'm New to SAP ABAP, need your help.

I'm creating an alv report which displays data from multiple tables: mara, marc, one custom table, makt, mlgn.

On the selection screen, there are fields from each of these tables. It also has 2 parameters from different tables.
How do I implement select option and parameter, the only common field between these field is matnr,

I know how to do it for select option from single table by using

.

but this is just for first table in second table

doing this doesn't help as gt_marc would still have entries where s_meins doesn't match.

This is what I'm using for output

Please let me know if any more info is needed to resolve this.

Also, if you could share a demo program where this has been implemented that might help too

7 REPLIES 7

jerryjanda
Community Manager
Community Manager
0 Kudos

Thank you for visiting SAP Community to get answers to your questions. Since you're asking a question here for the first time, I recommend that you familiarize yourself with https://community.sap.com/resources/questions-and-answers, as it provides tips for preparing questions that draw responses from our members. Feel free to take our Q&A tutorial at https://developers.sap.com/tutorials/community-qa.html as well, as that will help you when submitting questions to the community.

I also recommend that you include a profile picture. By personalizing your profile, you encourage readers to respond: https://developers.sap.com/tutorials/community-profile.html.

Kind regards,

--Jerry

Moderation Lead

Make sure to subscribe to What's New!

FredericGirod
Active Contributor

You could do it with a FOR ALL ENTRIES, but you have to check if the table is not empty (otherwise you will have the full table as result).

Or you could do INNER JOIN. It is how to make one SELECT statement and access to several table. For this you need to know the link between the tables. For MARA & MARC it is just the MATNR field.

SELECT ....
INTO ...
FROM MARA
INNER JOIN MARC
on MARA~MATNR = MARC~MATNR
WHERE MARA~MATNR IN S_MATNR
AND MARC~WERKS IN S_WERKS ...

matt
Active Contributor

And, generally, JOINS are more efficient that FOR ALL ENTRIES:

0 Kudos

matthew.billingham, this is your favorite discussion 🙂

Sandra_Rossi
Active Contributor

Please paste code as text instead of image, so that people can copy it, test, and paste fixed code in the answer.

LaurensDeprost
Contributor
0 Kudos

Look up some online resources on the basics of relational databases/SQL if you're not familiar with databases yet. Some context on stuff like (primary and foreign) keys, relationships, and join conditions will help you a lot.

former_member9115
Participant
0 Kudos

Hi, check if following helpful.

SELECT MARC~MATNR ,
MARC~WERKS,
MARC~QZGTP,
MARC~MAXLZ,
MARC~MABST,
MARC~MINBE,
MARA~MEINS,
MARA~MATKL,
MARA~MFRNR
FROM MARC
Inner join MARA On MARC~MATNR = MARA~MATNR
WHERE werks in @s_werks
and MARC~matnr in @s_matnr
and MARC~qzgtp in @s_qzgtp
and MARC~maxlz in @s_mabst
and MARC~minbe in @s_minbe
INTO table @data(IT_LOC).

SORT IT_LOC BY MATNR.



IF IT_LOC IS NOT INITIAL.
CL_SALV_TABLE=>FACTORY( IMPORTING R_SALV_TABLE = DATA(LO_ALV)
CHANGING T_TABLE = IT_LOC ).
IF LO_ALV IS BOUND.
DATA(LO_FUNCTIONS) = LO_ALV->GET_FUNCTIONS( ).
LO_FUNCTIONS->SET_ALL( 'X' ).
LO_ALV->DISPLAY( ).
ENDIF.
ELSE.
MESSAGE 'NO DATA FOUND' TYPE 'E'.
ENDIF.