Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

problem in Function Module

Former Member
0 Likes
1,576

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.

11 REPLIES 11
Read only

GauthamV
Active Contributor
0 Likes
1,240

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.

Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
1,240

Hello Deep,

SELECT * FROM <table> INTO TABLE <int. table> WHERE field = param

When 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

Read only

Former Member
0 Likes
1,240

yes i agree with that.... but how can i fix that.... is there any way that it takes blank as 'ALL"

Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
1,240

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

Read only

0 Likes
1,240

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

Read only

former_member194797
Active Contributor
0 Likes
1,240

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.

Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
1,240

Hello Henri,

Why do we need the condition, can you please explain?

BR,

Suhas

Read only

former_member194797
Active Contributor
0 Likes
1,240

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.

Read only

venkat_o
Active Contributor
0 Likes
1,240

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.

REPORT 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.
Thanks Venkat.O

Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
1,240

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

Read only

former_member194797
Active Contributor
0 Likes
1,240

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.