2009 Dec 12 9:41 AM
Dear Expert ,
I want to pass four parameter to the select queery in RFC which are optional and
i want to execute that query like we execute query in report for example
SELECT a~matnr
a~bismt
INTO CORRESPONDING FIELDS OF TABLE it_mara
FROM mara AS a INNER JOIN marc AS b ON amatnr = bmatnr
WHERE b~werks in p_werks
AND a~bismt IN p_bismt
AND a~matnr in p_matnr .
where if only p_bismt= '02470' is passed it should give result for all matnr of bismt ='02470 '
Regards
Deepak
2009 Dec 12 8:44 PM
Hi Deepak,
and what is the question?
Create an RFC-usable function module, create import parameters for the ranges (must be type table or certain tabletype) and then it's OK.
It is not nice to use a name like p_werks for a range (used with IN ).
Regards,
Clemens
2009 Dec 12 11:54 PM
The problem with the optional parameters is that if none on the parameters have values you are retrieving the whole table.
You should check that, at least, one of the four parameters are completed.
Here you have a quick solution for your problem:
ranges: r_bismt for mara-bismt.
ranges: r_matnr for mara-matnr.
ranges: r_werks for marc-werks.
if not i_bismt is initial.
move 'I' to r_bismt-sign.
move 'EQ' to r_bismt-option.
move i_bismt to r_bismt-low.
append r_bismt.
endif.
if not i_matnr is initial.
move 'I' to r_matnr-sign.
move 'EQ' to r_matnr-option.
move i_matnr to r_matnr-low.
append r_matnr.
endif.
if not i_werks is initial.
move 'I' to r_werks-sign.
move 'EQ' to r_werks-option.
move i_werks to r_werks-low.
append r_werks.
endif.
SELECT a~matnr
a~bismt
INTO CORRESPONDING FIELDS OF TABLE it_mara
FROM mara AS a INNER JOIN marc AS b ON amatnr = bmatnr
WHERE b~werks in r_werks
AND a~bismt IN r_bismt
AND a~matnr in r_matnr .
2009 Dec 14 4:24 AM
YEs
Bettina ,
Your answer is helpful, but what if all fields are passed blank
Regards
Deepak
2009 Dec 17 1:09 AM
In that case you have to decide how the FM will behave.
You can check that at least one parameter have a value, if not, you can return an error.
You can retrieve all the data (like happens with the select options). With my previous code, if all the fields are blank the select will retrieve the whole table.
Regards
Bettina
| User | Count |
|---|---|
| 4 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |