Application Development 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: 

How to pass variable number of parameters to a FORM.

Former Member
0 Kudos

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

1 ACCEPTED SOLUTION

Former Member
0 Kudos

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.

5 REPLIES 5

Former Member
0 Kudos

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

0 Kudos

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.

Former Member
0 Kudos

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.

0 Kudos

Thanks Charles.

I'll try your approach.

Sorry I posted my reply before reading yours.

Regards,

Sheetal

Former Member
0 Kudos

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.