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: 

Default values in tables for function module

Former Member
0 Kudos

Hi,

We've created a function module and it is their requirement to have a default value for the tables in the FM? How do we do this? Cause if it is just an import parameter there is a column for default values, but for tables there is none. How do we code this?

Thanks.

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi,

In the start of the function module you can check the table and set your default values.

FUNCTION ...

"Check whether the table is initial

"Do not override the value passed by the user

IF itab[] IS INITIAL.

itab-field = 'DEFAULT'. "Set your default value

APPEND itab.

ENDIF.

- - - Your functionality

...

Regards

Wenceslaus.

8 REPLIES 8

Former Member
0 Kudos

Hi,

In the start of the function module you can check the table and set your default values.

FUNCTION ...

"Check whether the table is initial

"Do not override the value passed by the user

IF itab[] IS INITIAL.

itab-field = 'DEFAULT'. "Set your default value

APPEND itab.

ENDIF.

- - - Your functionality

...

Regards

Wenceslaus.

0 Kudos

Thanks Wenceslaus.

Would your suggestion happen after the user has entered some data?

What we want to happen is when we execute the FM (like in SE37) the values will already be there by default even before the user enters some data. Is this possible?

Thanks again.

0 Kudos

Hi Rous,

That's why I had checked with IS INITIAL.

Just check the table whether it is empty or not. If it is empty set the default values.

But however this approach will not show the default values for the tables parameter. The default values are set programmatically.

Regards

Wenceslaus

Message was edited by: Wenceslaus

0 Kudos

Ok, then how are the default values set programmatically? Is there a way?

Thanks again.

0 Kudos

Hi Rous,

I don't know whether you have understood my previous posts.

See, there is no straightforward approach to set the default values for TABLES parameters.

You could only possibly check whether the parameter is empty in your FM, and if it is empty set the preferred default value in the parameter, which is illustrated in the code,

IF itab[] IS INITIAL.

itab-field = 'DEF_VALUE'.

APPEND itab.

ENDIF.

Regards

Wenceslaus.

0 Kudos

Hi Rous,

You can use 'Test Data Directoy' to save the default value for parameter and tables.

Regards,

Hendy.

Former Member
0 Kudos

Hi Rous ,

I do not feel there is a way to default data in an internal table .

At alternative is that in the FM you check if the value of the passed internal table i intial or not . If it is initial the appned your default values.

Regards

Arun

Former Member
0 Kudos

hi,

check whether the table is initial and then assign the table's field as default.

check this link.

https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/8129f164-0a01-0010-2a8e-87652872...

hope this helps!!!

Message was edited by:

Gayatri M