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

Pass parameters of user defined type to function module

Former Member
0 Likes
4,584

Hi,

Is it possible to pass a table parameter of user defined type, from the calling program, to a user defined function module? If yes then how to do it? If no then is there a work around for this?

Thanks in advance!!!!

Regards,

Sriram.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
2,152

Hi,

You may define an importing/exporting/changing paramer from type STANDARD TABLE. Of course, to access the table's data in the MF's body, you'll certaily have to make use of data refenreces or instructions like ASSIGN COMPONENT to dynamically acces the table's fields.

Regards

Hi,

Is it possible to pass a table parameter of user defined type, from the calling program, to a user defined function module? If yes then how to do it? If no then is there a work around for this?

Thanks in advance!!!!

Regards,

Sriram.

6 REPLIES 6
Read only

Former Member
0 Likes
2,153

Hi,

You may define an importing/exporting/changing paramer from type STANDARD TABLE. Of course, to access the table's data in the MF's body, you'll certaily have to make use of data refenreces or instructions like ASSIGN COMPONENT to dynamically acces the table's fields.

Regards

Read only

0 Likes
2,152

Hi,

Thanks for your reply but I didn';t get you. In the calling program I have defined type

TYPES BEGIN OF ty_bkpf.

INCLUDE STRUCTURE bkpf.

TYPES flag TYPE c.

TYPES END OF ty_bkpf.

Then I'm creating internal table as below.

DATA it_bkpf TYPE STANDARD TABLE OF ty_bkpf.

Now I'm creating a FM where I want to pass it_bkpf. In tables parameters of the FM how to pass it_bkpf? if I define it_bkpf LIKE bkpf then i cannot straight away pass it_bkpf as parameter from calling program.

Regards,

Sriram

Read only

0 Likes
2,152

Hi Sriram,

Create a structure in SE11, having all fields of table BKPF and additional field 'flag' TYPE c. Use this structure to define the internal table it_bkpf in TABLES of FM.

Thanks & Regards

Radhika

Read only

0 Likes
2,152

Thanks Radhika! Is this the only way to do it?

Regards,

Sriram

Read only

matt
Active Contributor
0 Likes
2,152

A type defined in your program is only visible within your program. It is unknown to your function module. Function module parameters must either have a generic definition (Blank = ANY, STANDARD TABLE, C, CLIKE etc.) a basic type (T, I etc.) or be defined in the data dictionary.

One possible workaround - depending on what you're trying to achieve - is to define the type in the function module and the calling program, then pass the reference from the program to the FM.

e.g.

Calling program

TYPES my_table_type ...

DATA: my_table TYPE my_table_type,
     r_data TYPE REF TO DATA.
...
* populate my_table

GET REFERENCE OF my_table INTO r_data.
CALL FUNCTION MODULE 'Z_MYFM' EXPORTING ir_data = r_data. 

FM

TYPES my_table_type ...

FIELD-SYMBOLS: <my_table> TYPE my_table_type.
ASSIGN ir_data->* TO <my_table>.

Read only

Clemenss
Active Contributor
0 Likes
2,152

Hi Sriram_14880,

you can always declare the function module import or tables parameters as TYPE ANY or TYPE STANDARD TABLE.

But then you can bot access the fields of the line structure directly but only by assignment.

I guess you are better of by creating structures and/or data elements and related table types in Data Dictionary because then you can use the fields not only in programs but anywhere, screens, functions etc.

Regards,

Clemens