Ok, I'm attempting to write my first ABAP report. I am trying to write a report that allows a user to input a unit of measure and a material group. Then it will look at every material in that group. If a material's base unit of measure or alternate unit of measure(s) do not equal the user-supplied unit then that material will be written to the screen. Otherwise nothing will happen. Here is what I have so far:
REPORT ZBASE_UNIT_SELECT.
PARAMETERS: PA_MATKL TYPE MARA-MATKL, PA_UNIT TYPE MARA-MEINS.
DATA: IT_MARA TYPE TABLE OF MARA,
WA_MARA LIKE LINE OF IT_MARA.
DATA: IT_MARM TYPE TABLE OF MARM,
WA_MARM LIKE LINE OF IT_MARM.
START-OF-SELECTION.
SELECT * FROM MARA INTO TABLE IT_MARA WHERE MATKL = PA_MATKL.
LOOP AT IT_MARA INTO WA_MARA.
if wa_mara-meins = pa_unit.
This is where I get stuck. I need to determine of the base unit of measure (MARA-MEINS) equals the supplied unit (PA_UNIT) and if it does then I need to move on to the next one. If it doesn't match then I need to compare the alternate unit of measures (MARM-MEINH) to the supplied unit (PA_UNIT). How can I do this comparison using two different tables?
Any help is more than appreciated!
Thanks,
Aaron
hi
try this
1.select the field (MARM-MEINH) into one internal table itab1 supp.
2.then
LOOP AT IT_MARA INTO WA_MARA.
if wa_mara-meins EQ pa_unit.
continue.
else.
read itab1 into wa_itab1
compare the alternate unit of measures (MARM-MEINH) to the supplied unit (PA_UNIT).
endif.
endloop.
reward if useful
Message was edited by:
neha gupta
Hi Aaron,
You need to use IF..ELSEIF statements for your requirement.
IF <condtion1>.
statements(1).
ELSEIF <condtion2>.
statements(2).
ENDIF.
If <condtion1> is true then statements(1) are executed,if not it will check whether <condtion1> is true.If it is true then statements(2) are executed.
LOOP AT IT_MARA INTO WA_MARA.
if wa_mara-meins = pa_unit.
>>Do as per ur requirement(1)
elseif wa_mara-meins = pa_unit.
>>Do as per ur requirement(2)
endif.
ENDLOOP.
Thanks,
Vinay
Hello Aaron
You could simplify your task using two simple SELECT statements:
DATA: gt_mara_ok TYPE STANDARD TABLE OF mara, gt_mara_nok TYPE STANDARD TABLE OF mara. SELECT * FROM mara INTO TABLE gt_mara_ok WHERE matkl = pa_matkl AND ( meins = pa_unit OR meinh = pa_unit ). SELECT * FROM mara INTO TABLE gt_mara_nok WHERE matkl = pa_matkl AND ( meins <> pa_unit AND meinh <> pa_unit ).
Regards
Uwe
REPORT ZBASE_UNIT_SELECT.
PARAMETERS: PA_MATKL TYPE MARA-MATKL, PA_UNIT TYPE MARA-MEINS.
DATA: IT_MARA TYPE TABLE OF MARA,
WA_MARA LIKE LINE OF IT_MARA.
DATA: IT_MARM TYPE TABLE OF MARM,
WA_MARM LIKE LINE OF IT_MARM.
START-OF-SELECTION.
SELECT * FROM MARA INTO TABLE IT_MARA WHERE MATKL = PA_MATKL.
select * from marm into table it_marm where ( ur condition).
or..
select * into corresponding fields of table it_marm from marm for all entries in it_mara where matnr = it_mara-matnr.
LOOP AT IT_MARA INTO WA_MARA.
if wa_mara-meins = pa_unit.
ur requirement.
else.
read table it_marm with key meinh = pa_unit.
if sy-subrc = 0.
ur requirement.
endif.
endif.
hope this helps..
Regards
CNU
If you don't mind, look at the following:
DATA: BEGIN OF T_TABLE OCCURS 0,
MATNR,
MEINS
MEINH
END OF TABLE.
SELECT AMATNR AMEINS B~MEINH INTO TABLE T_TABLE
FROM MARA AS A INNER JOIN MARM AS B
ON AMATNR = BMATNR
WHERE AMEINS <> PA_UNIT AND BMEINH <> PA_UNIT.
My guess is this will fill table T_TABLE with materials where the base unit of measure (MEINS) and alternate unit of measure (MEINH) do not equal the supplied unit (PA_UNIT). Is this correct?
DATA:
gt_mara_ok TYPE STANDARD TABLE OF mara,
gt_mara_nok TYPE STANDARD TABLE OF mara.
SELECT * FROM mara INTO TABLE gt_mara_ok
WHERE matkl = pa_matkl
AND ( meins = pa_unit OR
meinh = pa_unit ).
SELECT * FROM mara INTO TABLE gt_mara_nok
WHERE matkl = pa_matkl
AND ( meins <> pa_unit AND
meinh <> pa_unit ).
Here is what I have now (thanks to your wonderful help)
PARAMETERS: PA_MATKL TYPE MARA-MATKL, PA_UNIT TYPE MARA-MEINS. DATA: BEGIN OF T_TABLE OCCURS 0, MATNR TYPE MARA-MATNR, MEINS TYPE MARA-MEINS, MEINH TYPE MARM-MEINH, END OF T_TABLE. SELECT A~MATNR A~MEINS B~MEINH INTO TABLE T_TABLE FROM MARA AS A INNER JOIN MARM AS B ON A~MATNR = B~MATNR WHERE A~MEINS <> PA_UNIT AND B~MEINH <> PA_UNIT and A~MATKL = PA_MATKL. if sy-subrc = 4. write: / 'No records found'. endif. LOOP AT T_TABLE. IF T_TABLE-MEINS = PA_UNIT OR T_TABLE-MEINH = PA_UNIT. DELETE T_TABLE WHERE MATNR = T_TABLE-MATNR. ENDIF. ENDLOOP. LOOP AT T_TABLE. WRITE: / T_TABLE-MATNR. ENDLOOP.
However, no records are found EVER. I guess there is something wrong with the select statement but I'm not sure what.
This reply goes to everybody. I am so sorry I didn't realize that I was looking at the tables in our production box but I was developing in our dev box. It seems like I have my code working now but I won't know until I transport it to our test box and test it out. I appreciate all of the help I received so far. I'm keeping my fingers crossed! If my solution works I will change the question to answered and award points accordingly Thanks again!
Aaron
Add a comment