09-12-2007 5:30 AM
hai gurus i am writing a function module to read employee details , so i want to add selection criteria as cost center , employee group and personal area and some other , so based on these inputs i have to filter the employee details, but the problem is that the user may enter any selection critirea plus or and conditions
for example he may give condtions like
1) cost center or employee group and personal area
2)cost center and employee group or personal area
if there are no such or and conditions i would have just writen select queries for all these paramters
but the or and and conditions can come in any combination so can i manage that
in my code if yes then how if any standard report available please give me some reference
regards
afzal
09-12-2007 5:41 AM
Hi Mohammed ..
As i understand your FM has import parameters COSTCENTER ,EMPGROUP, PER_AREA. all these parameters are optional.
Then you have to write the FM source code like this.
IF COSTCENTER IS SUPPLIED
AND EMPGROUP IS SUPPLIED
AND PER_AREA IS SUPPLIED .
SELECT <FIELDS> FROM <TABLE> INTO TABLE <ITAB>
WHERE CS = COSTCENTER
AND EG = EMPGROUP
AND PA = PER_AREA .
ELSEIF COSTCENTER IS NOT SUPPLIED.
ELSEIF .
ENDIF.
reward if Helpful.
09-12-2007 6:30 AM
If you turn each of the selections criteria provided into a range table then you can achieve this with a single "select". For example, in a report this might be coded as below (but note that this may not be the most efficient for the database).
Jonathan
report zlocal_jc_parm_to_range.
*" criteria provided:
parameters:
p_kostl like csks-kostl,
p_pernr like pa0001-pernr.
start-of-selection.
perform get_data.
form get_data.
ranges:
lr_kostl for p_kostl,
lr_pernr for p_pernr.
*" Convert single criteria to range
if not p_kostl is initial.
lr_kostl-sign = 'I'. "include
lr_kostl-option = 'EQ'. "equals
lr_kostl-low = p_kostl.
append lr_kostl.
endif.
if not p_pernr is initial.
lr_pernr-sign = 'I'. "include
lr_pernr-option = 'EQ'. "equals
lr_pernr-low = p_pernr.
append lr_pernr.
endif.
select *
from zz_my_data
where kostl in lr_kostl "if empty, gets ignored
and pernr in lr_pernr. "if empty, gets ignored
endform.