02-23-2022 12:25 AM
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
02-23-2022 12:26 AM
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
02-23-2022 6:28 AM
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 ...
02-23-2022 11:19 AM
02-23-2022 11:33 AM
02-23-2022 7:20 AM
Please paste code as text instead of image, so that people can copy it, test, and paste fixed code in the answer.
02-23-2022 8:53 AM
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.
02-23-2022 10:46 AM
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.