While this is very simple if all the Date components are stored in one column it can tricky if date components are stored in different coloumns, like e.g. the year and period in the MBEWH in SAP.
So if you wanted to use Select Options for Year(S_MBHYEA) and Months(S_MBHMON) you cannot just mix them in one select, because when you select 2010 - 2014 and April to June, you would only get the months april to june of every year, but what you really want is april 2010 to june 2014.
A way to to deal with this is to use a cursor getting all years selected and the comparing the months of the first and last year selected to the actual wanted months.
"Cursor
OPEN CURSOR CP_CURSOR FOR
SELECT *
FROM MBEWH
WHERE
BWKEY IN S_MBHBKY AND
LFGJA IN S_MBHYEA.
"Get next cursor
DO.
FETCH NEXT CURSOR CP_CURSOR
INTO CORRESPONDING FIELDS OF L_WA_MBEWH.
IF SY-SUBRC <> 0.
CLOSE CURSOR CP_CURSOR.
EXIT.
ENDIF.
"Filter everything below lower year and lower months
IF S_MBHMON-LOW IS NOT INITIAL AND
L_WA_MBEWH-LFGJA = S_MBHYEA-LOW AND
L_WA_MBEWH-LFMON < S_MBHMON-LOW.
CONTINUE.
ENDIF.
"Filter everything above high year and high month.
IF S_MBHMON-HIGH IS NOT INITIAL AND
L_WA_MBEWH-LFGJA = S_MBHYEA-HIGH AND
L_WA_MBEWH-LFMON > S_MBHMON-HIGH.
CONTINUE.
ENDIF.
Thanks for sharing this Information. SAP Training in Gurgaon
ReplyDelete