cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

In Function Module, optional input function is not working ?

vinayad
Participant
0 Likes
834

Hi all,

Any help would be appreciated!

I have a request to create Function Module with all inputs are optional.

All the inputs are from same table and I need to fetch the records accordingly.

Though, I made all the import parameters are optional but if I input anyone of the field value it is not returning with empty table.

Thank you!

Sample code snippet

SELECT * FROM VBFA INTO TABLE T_VBFA
   WHERE VBELV = I_PRECEDINGDOC
     AND POSNV = I_PRECEDINGITEM
     AND VBELN = I_FOLLOWONDOC
     AND POSNN = I_SUBSEQUENTITEM
     AND VBTYP_N = I_SUBSDOCCATEG.

Accepted Solutions (1)

Accepted Solutions (1)

MateuszAdamus
Active Contributor

Hello vinayad

You've made them option, but that doesn't mean they don't have a value. They do, the value is empty. That's why your query is looking for a record which has fields with empty value.

What you can do in this case is create a range variable for each of the parameters. Then add a new record to the range with the parameter's value. Then use these ranges in the query.

Example in pseudo code below.

DATA:
  lt_vbelv_range TYPE RANGE OF vbelv.

IF i_precedingdoc IS NOT INITIAL.
  APPEND INITIAL LINE TO lt_vbelv_range REFERENCE INTO DATA(ld_vbelv).
  ld_vbelv->sign = 'I'.
  ld_vbelv->option = 'EQ'.
  ld_vbelv->low = i_precedingdoc.
ENDIF.

SELECT * FROM vbfa INto TABLE t_vbfa WHERE vbelv IN lt_vbelv_range.

" do the same for other parameters and put them in the same query
Kind regards,
Mateusz
vinayad
Participant
mateuszadamus

I really appreciate your help !

Answers (1)

Answers (1)

RaymondGiuseppi
Active Contributor
0 Likes

Convert the parameters into range, don't check value initial, for example an initial value for a flag.checkbox is a specified value and must not be ignored

Copy mateuszadamus's code and replace the IS INITIAL criteria with IS SUPPLIED.

vinayad
Participant
0 Likes
raymond.giuseppiI really appreciate your help !