04-12-2005 8:24 PM
Hi,
What is the correct syntax to pass variable number of parameters to a subroutine?
PERFORM TEST TABLES BRETURN USING TEST_NAME CHANGING MY_OUTPUT.
FORM TEST TABLES RETURN STRUCTURE BAPIRET2
ITAB STRUCTURE ITABLE_LINE OPTIONAL
USING VALUE(NAME) TYPE STRING
CHANGING VALUE(OUTPUT) TYPE STRING.
The above code does not work. How can we specify an optional parameter?
Thanks and Regards,
Sheetal
Message was edited by: Sheetal Pisolkar
04-12-2005 10:20 PM
Srinivas is correct. There are no optional parameters in subroutines like there are in function modules.
If you want the second table ITAB to be optional, you will have to pass an empty table, and add a USING parameter, let's call it FLAG, with a 'Yes' or 'No' value indicating whether or not you want the table to be used. Then your FORM code can interrogate the FLAG and do whatever you need to do.
Optional parameters in function modules get initial value when NOT passed so maybe just getting an empty table is all your subroutine needs to know.
You could also build a function module instead of a subroutine and then you can have optional parameters.
In case you are not aware, internal tables can be passed to subroutines via the USING and CHANGING lists so the TABLES feature is now considered obsolete.
04-12-2005 8:39 PM
Hi Sheetal,
You cannot pass variable number of parameters to a subroutine. If you let the forum know, why you need that, may be someone can help.
Srinivas
04-12-2005 10:24 PM
Hi,
I am trying to use a subroutine instead of function.A FUNCTION understands optional keyword.
How can this work for a FORM?
CALL FUNCTION 'TEST'
EXPORTING
MY_OUTPUT = 'output'
IMPORTING
TEST_NAME = 'mytest'.
FUNCTION TEST
* EXPORTING
* VALUE(OUTPUT) TYPE STRING
* IMPORTING
* VALUE(NAME) TYPE STRING
* TABLES
* RETURN STRUCTURE BAPIRET2 OPTIONAL
* ITAB STRUCTURE ITABLE_LINE OPTIONAL
...
ENDFUNCTION.
PERFORM TEST USING TEST_NAME CHANGING MY_OUTPUT.
FORM TEST TABLES RETURN STRUCTURE BAPIRET2 OPTIONAL
ITAB STRUCTURE ITABLE_LINE OPTIONAL
USING VALUE(NAME) TYPE STRING
CHANGING VALUE(OUTPUT) TYPE STRING.
ENDFORM.
Is this be possible?
Thanks
Sheetal.
04-12-2005 10:20 PM
Srinivas is correct. There are no optional parameters in subroutines like there are in function modules.
If you want the second table ITAB to be optional, you will have to pass an empty table, and add a USING parameter, let's call it FLAG, with a 'Yes' or 'No' value indicating whether or not you want the table to be used. Then your FORM code can interrogate the FLAG and do whatever you need to do.
Optional parameters in function modules get initial value when NOT passed so maybe just getting an empty table is all your subroutine needs to know.
You could also build a function module instead of a subroutine and then you can have optional parameters.
In case you are not aware, internal tables can be passed to subroutines via the USING and CHANGING lists so the TABLES feature is now considered obsolete.
04-12-2005 10:35 PM
Thanks Charles.
I'll try your approach.
Sorry I posted my reply before reading yours.
Regards,
Sheetal
04-12-2005 10:21 PM
You might want to change your posting to a question so that you can reward points as you deem appropriate.
Let us know how it goes.