cancel
Showing results for 
Search instead for 
Did you mean: 

Function Module: Optional importing parameters with default value as * (all values)

e_giunta
Participant
0 Kudos

Hello experts,

I have a function module with 7 input parameters, 4 of these are mandatory but 3 are optional. In WHERE of select statement i need a condition like:

SELECT *

FROM knvh

WHERE vkorg = in_vkorg AND vtweg = in_vtweg AND spart = in_spart AND hkunnr eq IN_hkunnr AND name1 = in_name1 AND ort01 = in_ort01 AND kunnr = in_kunnr.

* name1, ort01 and kunnr are optional

It works if user insert all import parameters. But If user doesnt insert optional parameters the function module return an empty table. I need something where if user dont insert optional parameters the funct module return a table with every possible value of name1, ort01 and kunnr.

It's possible to achieve this setting * (all values) in default values of optional parameters? Or via abap? If via abap how i can change the WHERE clause?

Thanks!

Accepted Solutions (0)

Answers (2)

Answers (2)

Patrick_vN
Active Contributor

What Nic said. Though you could define some ranges for the fields name1, ort01 and kunnr and fill these prior to the execution of the SQL statement (depending of course whether the parameters are supplied or not).

NTeunckens
Active Contributor
0 Kudos

Hello Eugenio

You could use a "Dynamic Where Clause" for that, adding Syntax to your Where-Clause depending on which Parameters are filled ...

For an Example see this link ...

"Create a String-Table LT_WHERE_CLAUSE
"Add the SQL-Syntax whenever data from Parameters is provided
SELECT *
  FROM knvh
  WHERE vkorg = in_vkorg 
    AND vtweg = in_vtweg 
    AND spart = in_spart 
    AND hkunnr = in_hkunnr 
    AND ( lt_where_clause ).


See some examples on the Web for this to get an idea on how you can make this work ...

Hope this helps.

Nic T.