‎2013 Jul 01 11:03 PM
Hi good day everybody, i have issue with function module, i need to create a function module with many parameters, the records to retrieve must be according the input users, so if the user does not type any parameter then the function module must retrieve all records.
I have done it with report abap using select option, but now i need to create the same behaviour with FM.
How can do it?
than you for all your advices.
‎2013 Jul 02 7:04 AM
Hi Saul,
have a look to the statement : RANGES
it's like SELECT-OPTIONS but without selection screen.
if you debug your program you will see the structure of any SELECT-OPTIONS is :
SIGN
OPTION
LOW
HIGH
for example, a simple value look like :
SIGN : I
OPTION : EQ
LOW : /the_value/
HIGH:
I means Include, you could find E for Exclude.
EQ means Equal, you could find BT : Between ....
the limit is 3000 entries .. after you could have a short dump
and the RANGES could be used like SELECT-OPTIONS using the IN option in the SELECT .. WHERE statement.
I hope it's clear.
regards
Fred
‎2013 Jul 02 6:38 PM
Hi Frédéric Good day, thank you sr. so could you give me an example to undestand it clearly
Best Regards.
‎2013 Jul 03 7:57 AM
Saul, you have a lot of example inside SAP, each function modules that used the structure RSPARAMS
for exampe RSAQ_QUERY_CALL (for SELECTION_TABLES)
Regards
Fred
‎2013 Jul 02 6:05 PM
Hi Saul,
I assume in your case user wants a parameter to enter if they does not enter then only u have to fetch all the records.
So declare the parameters as optional in Import section of your FM.
Inside FM declare a range of the desired field type.
If Import parameter is passed with value (If not initial) pass it to Low Field of the range.
Use the range declared in your select query.
This may help you.
Regards,
Vinay Mutt
‎2013 Jul 02 6:41 PM
Hi Vinay thank you for your advice, so could you give me an example to undestand it clearly.
Best Regards.
‎2013 Jul 02 7:12 PM
Hi Saul,
I cannot understand your query completely but as sugg. by Vinay have an optional importing parameter and it should do the trick for you.
BR.
‎2013 Jul 02 8:10 PM
Hi Ankit good day, this is my requirement, I need the function module do this:
1.- ask parameter search
1.1 fmbdt~rfikrs
1.2 fmbdt~rmeasure
1.3 fmbdt~rfundsctr
1.4 fmbdt~rfund
1.5 fmbdt~BUDGET_PD_9
2.- Based on the parameters values, it need to add the amounts
from fmbdt-tsl01 to fmbdt-tsl04.
Note: the result set must meet according parameters values, otherwise if anyone
is empty must retrive all records from that parmeter field, or if all paramters is empty, must retrieve all recors from all paramter fields .
the query is:
select tsl01 tsl02 tsl03 tsl04
INTO CORRESPONDING FIELDS OF TABLE it_fmbdt
from fmbdt
where fmbdt~rfikrs in prfikrs
and fmbdt~rmeasure in prmeasur
and fmbdt~rfundsctr in prfundsc
and fmbdt~rfund in prfund
and fmbdt~BUDGET_PD_9 in pbudget.
‎2013 Jul 03 3:51 AM
Hi Saul,
Good day to you too .
Assuming you have multiple parameters instead of multiple select options, please follow below steps :
1) Create 5 optional importing parameters.
2) Modify your Select query as,
select rfikrs rmeasure rfundsctr rfund budget_pd_9 tsl01 tsl02 tsl03 tsl04
INTO CORRESPONDING FIELDS OF TABLE it_fmbdt
from fmbdt
where fmbdt~rfikrs = prfikrs
or fmbdt~rmeasure = prmeasur
or fmbdt~rfundsctr = prfundsc
or fmbdt~rfund = prfund
or fmbdt~BUDGET_PD_9 = pbudget.
This query will give a super set of all the results.
3) Loop at it_fmbdt into ls_fmbdt.
*-- Now check the fields individually and apply your summation logic, eg:-
if ls_fmbdt-rfikrs is not initial.
*-- Sum the required fields.
endif.
Endloop.
Please ask in case i missed anything or something is unclear.
BR.
‎2013 Jul 03 6:22 AM
Hi Saul,
I have created a test program for your requirement.
I am using table FAGLFLEXA and will fetch data w.r.t parameters entries and will add HSL & KSL fields. You change the code w.r.t your requirement.
In Function module I have declared five table parameter as optional for parameters from report program.
I have not declared associated type for table parameters so it will take dynamically.
From Report call FM
SELECT-OPTIONS: SO_P1 FOR FAGLFLEXA-RYEAR,
SO_P2 FOR FAGLFLEXA-DOCNR,
SO_P3 FOR FAGLFLEXA-RLDNR,
SO_P4 FOR FAGLFLEXA-RBUKRS,
SO_P5 FOR FAGLFLEXA-HSL.
CALL FUNCTION 'Y_TEST_FM'
TABLES
PT_1 = SO_P1
PT_2 = SO_P2
PT_3 = SO_P3
PT_4 = SO_P4
PT_5 = SO_P5.
In FM used the below code:
TYPES: BEGIN OF TY_FAG,
RYEAR TYPE FAGLFLEXA-RYEAR,
DOCNR TYPE FAGLFLEXA-DOCNR,
RLDNR TYPE FAGLFLEXA-RLDNR,
RBUKRS TYPE FAGLFLEXA-RBUKRS,
HSL TYPE FAGLFLEXA-HSL,
KSL TYPE FAGLFLEXA-KSL,
ADDITION TYPE FAGLFLEXA-KSL,
END OF TY_FAG.
DATA: IT_FAG TYPE TABLE OF TY_FAG.
FIELD-SYMBOLS: <FS_FAG> TYPE TY_FAG.
*Fetch data, iam using FAGLFLEXA table to add HSL & KSL. If all the parameter is initial then it will fetch all the data and if any parameter value exist then only those data will be fetched.
SELECT RYEAR
DOCNR
RLDNR
RBUKRS
HSL
KSL
FROM FAGLFLEXA
INTO TABLE IT_FAG
WHERE RYEAR IN PT_1
AND DOCNR IN PT_2
AND RLDNR IN PT_3
AND RBUKRS IN PT_4
AND HSL IN PT_5.
* To check the Select Query
IF SY-SUBRC = 0.
* using field symbol
LOOP AT IT_FAG ASSIGNING <FS_FAG>.
* Put your condition to check whether the data is present
IF <FS_FAG>-DOCNR IS NOT INITIAL.
<FS_FAG>-ADDITION = <FS_FAG>-HSL
+ <FS_FAG>-KSL.
ENDIF.
ENDLOOP.
ENDIF.
If you need to export the table after calculation, declare another table parameter 'IT_FAG'.
Hope this might help your requirement. For any clarification do let me know.
Regards
M Nair
‎2013 Jul 03 5:19 PM
Hi good day Ankit tan you for your advice, according with your advice, when the parameters are declared in tab import as optional and are placed in the query where, it Works fine when has values, but what happen when the user does not type anything, the result set would be empty, so i would like to retrieve all records when the parameters are blank.
best regards.
‎2013 Jul 04 5:23 AM
Hi Saul,
Put break point on select query of function module and pass empty parameters to FM and check the select query behavior in debugger mode.
If the parameters are blank then it will fetch all entries from table.
Regards,
M Nair
‎2013 Jul 04 5:37 AM
Hi Saul,
Have a good day
As i posted earlier Create Optional import parameters in the Function Module.I hope you have done that already.
After that do the following.
Create ranges as shown below.
Ranges: r_rfikrs for fmbdt~rfikrs
r_rmeasure for fmbdt~rmeasure
r_rfundsctr for fmbdt~rfundsctr. Similraly create for other fields.
If NOT p_rfikrs (This is the Import Parameter you declared) IS INITIAL.
r_rfikrs-sign = 'I',
r_rfikrs-option = 'EQ'.
r_rfikrs-low = p_rfikrs.
append r_rfikrs.
endif.
Similarly code for other fields.
Use the range fields in your select query using IN Option.
Hopethis will help you in solving your problem.
Regards,
Vinay Mutt
‎2013 Jul 04 11:52 AM
Hi Saul,
I did not read your entire question, my bad. Since you want all entries if the parameter is empty you need to go for SELECT OPTION and not PARAMETER.This means you need to define the parameters in TABLES tab.
Seems Manik's solution will work.
Please try and revert.
BR.
‎2013 Jul 03 8:40 AM
Hi,
Create 5 IMPORT parameters of type RSPARAMS_TT.
RSPARAMS_TT is Table type of RSPARAMS which is same as SELECT PARAMETER.
You need to fill RSPARAMS_TT type structures with your selection values and pass it to FM.
Thanks,
Murtuza