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

Default values in tables for function module

Former Member
0 Likes
3,411

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
Read only

Former Member
0 Likes
1,866

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
Read only

Former Member
0 Likes
1,867

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.

Read only

0 Likes
1,866

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.

Read only

0 Likes
1,866

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

Read only

0 Likes
1,866

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

Thanks again.

Read only

0 Likes
1,866

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.

Read only

0 Likes
1,866

Hi Rous,

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

Regards,

Hendy.

Read only

Former Member
0 Likes
1,866

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

Read only

Former Member
0 Likes
1,866

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