‎2009 Sep 04 11:01 AM
Dear abapers
i have created a function module. it works fine when i give all the inputs. but if any of the input field ( Parameter) is left blank, rather than selecting all the data related to that field it shows zero entries. please tell what is wrong with it? and how can it be fixed??
Thanks in advance...
Luthra, Deep.
‎2009 Sep 04 11:04 AM
That is the major difference between parameters and select options.
If left blank, sy-subrc will be 4 for parameters, so no entries wil return
whereas for select options sy-subrc will be 0, it wil take all entries for that field.
In case of function modules you should always check the condition before your select statement.
If matnr is not initial.
.........
else.
.........
endif.
‎2009 Sep 04 11:05 AM
Hello Deep,
SELECT * FROM <table> INTO TABLE <int. table> WHERE field = paramWhen you use '=' operator in WHERE clause, it searches for the entires with field = space(or blank). This is why your select is failing.
Hope you understand
BR,
Suhas
‎2009 Sep 04 11:09 AM
yes i agree with that.... but how can i fix that.... is there any way that it takes blank as 'ALL"
‎2009 Sep 04 11:17 AM
Hello,
If you want it that way, then transfer the parameter to a SELECT-OPTION & proceed with SELECT.
Try like this:
DATA:
R_SELOPT TYPE STANDARD TABLE OF SELOPT,
ST_SELOPT TYPE SELOPT.
ST_SELOPT-SIGN = 'I'.
ST_SELOPT-OPTION = 'EQ'.
ST_SELOPT-LOW = PARAM. "Your Input Param
APPEND ST_SELOPT TO R_SELOPT.
CLEAR ST_SELOPT.
SELECT * FROM <TABLE> INTO TABLE <INT. TABLE>
WHERE FIELD IN R_SELOPT.This will solve your problem )
BR,
Suhas
‎2009 Sep 04 11:18 AM
Hi,
Try this way:
if para1 is initial.
para1 = '%' .
endif.
and select query in this way:
select <field> from <dbtable>
INTO TABLE <internal table>
WHERE field1 like para1.
Hope this will help you.
Regards,
Swarna Munukoti.
Edited by: Swarna Munukoti on Sep 4, 2009 12:21 PM
‎2009 Sep 04 11:21 AM
You should add a condition in the code of Suhas:
IF NOT PARAM IS INITIAL.
ST_SELOPT-SIGN = 'I'.
ST_SELOPT-OPTION = 'EQ'.
ST_SELOPT-LOW = PARAM. "Your Input Param
APPEND ST_SELOPT TO R_SELOPT.
CLEAR ST_SELOPT.
ENDIF.
When PARAM is initial, R_SELOPT must remain empty for selecting ALL.
‎2009 Sep 04 11:24 AM
Hello Henri,
Why do we need the condition, can you please explain?
BR,
Suhas
‎2009 Sep 04 11:30 AM
Without the condition, in case of empty param, you will fill the range wit 'I', 'EQ', and SPACE. The select will search for a value = SPACE and it is not what you are waiting. With an empty range, the SELECT will take all entries in the table, and that is what you ask. So, in case of PARAM = SPACE, you must let the range empty.
‎2009 Sep 04 11:34 AM
Deep,
<li> Use ranges concept in the function module. It is same as SELECT-OPTIONS.
<li> You need to build ranges table like select-options table.
Try this way.
Thanks
Venkat.OREPORT ztest_program.
DATA: BEGIN OF it_mard OCCURS 0,
matnr TYPE mard-matnr,
werks TYPE mard-werks,
lgort TYPE mard-lgort,
END OF it_mard.
RANGES: matnr FOR mard-matnr,
werks FOR mard-werks,
lgort FOR mard-lgort.
START-OF-SELECTION.
matnr-low = '0001-01-002-A'.
matnr-sign = 'I'.
matnr-option = 'EQ'.
APPEND matnr.
matnr-low = 'EEYE'.
matnr-sign = 'I'.
matnr-option = 'EQ'.
APPEND matnr.
matnr-low = 'EYE1'.
matnr-sign = 'I'.
matnr-option = 'EQ'.
APPEND matnr.
SELECT *
FROM mard
INTO CORRESPONDING FIELDS OF TABLE it_mard
WHERE matnr IN matnr
AND werks IN werks
AND lgort IN lgort.
‎2009 Sep 04 12:54 PM
Dear Venkat,
Just to let you know, SAP has decided to put RANGES in its list of Obsolete Declarations. (Further details through SAP F1)
Please refrain from using (as well as advising to use) RANGES declaration.
Cheers,
Suhas
‎2009 Sep 04 1:23 PM
F1 explains that RANGES: must be replace by DATA: ... LIKE RANGE OF ... or DATA: ... TYPE RANGE OF ... , but the solution remains the same with a different notation.