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

custom Function module

Former Member
0 Likes
1,754

Hi ,

I created Custom function module importing parameter as X

and changing parameter as emp_det type ZTABLE (Transpearent table)

I used select stat which will get data from Ztable stored into internal table itab.

at the end i am assing internal table emp_det

EMP_DET = itab.

This emp_det gives final result.

Whilie checking iam getting error as

itab cannot be converted to the type of emp_det

Thanks,

Sam

1 ACCEPTED SOLUTION
Read only

nabheetscn
SAP Champion
SAP Champion
0 Likes
1,721

Just pass this in tables parameter it will work.

Nabheet

11 REPLIES 11
Read only

Former Member
0 Likes
1,721

Hi,

Please, put the your code (start of FM , call of FM, definition of variables).

Best regards,

Leandro Mengue

Read only

0 Likes
1,721

Code

FUNCTION Z_TEST_RKM.

*"----


""Local Interface:

*" IMPORTING

*" VALUE(EMPLOYEE) LIKE ZHRS_EMP

*" STRUCTURE ZHRS_EMPLOYEE_SEARCH OPTIONAL

*" CHANGING

*" REFERENCE(EMPLOYEE_DETAILS) TYPE ZHR_TABLE

*"----


types: begin of ty_str,

MANDT type MANDT,

PERNR type PERSNO,

VORNA type PAD_VORNA,

NACHN type PAD_NACHN,

end of ty_str.

data: it_employee_detail TYPE STANDARD TABLE OF ty_str,

wa_employee_info TYPE ty_str.

select * from ZHR_TABLE into table it_employee_detail.

EMPLOYEE_DETAILS = it_employee_detail.

ENDFUNCTION.

Read only

0 Likes
1,721

Hi,

Try this:

DATA: i_zhr_table LIKE  zhr_table OCCURS 0 WITH HEADER LINE.

CALL FUNCTION 'Z_TEST_RKM'
   TABLES EMPDETAIL = i_zhr_table.


FUNCTION Z_TEST_RKM.
*"--------------------------------------------------------------------
""Local Interface:
*" TABLES
*" EMPDETAIL STRUCTURE zhr_table
*"--------------------------------------------------------------------

  select * from ZHR_TABLE into table EMPDETAIL.

ENDFUNCTION.

Best regards,

Leandro Mengue

Read only

matt
Active Contributor
0 Likes
1,721

>

> FUNCTION Z_TEST_RKM.

> *"----


> ""Local Interface:

> *" IMPORTING

> *" VALUE(EMPLOYEE) LIKE ZHRS_EMP

> *" STRUCTURE ZHRS_EMPLOYEE_SEARCH OPTIONAL

> *" CHANGING

> *" REFERENCE(EMPLOYEE_DETAILS) TYPE ZHR_TABLE

> *"----


>...

>

> EMPLOYEE_DETAILS = it_employee_detail.

>

>

>

> ENDFUNCTION.

The problem occurs because you've defined EMPLOYEE_DETAILS to be a structure that is like ZHR_TABLE. Not a table. There are two ways of dealing with this.

1. Use the TABLES parameter as Leandro suggested above - although this is obsolete in later versions, it must be used for RFCs.

2. Define a table type in the data dictionary, e.g. ZHR_TABLE_T_TY, which has a line type of ZHR_TABLE. Then you can use

> *" CHANGING

> *" REFERENCE(EMPLOYEE_DETAILS) TYPE ZHR_TABLE_T_TY

3. Use

> *" CHANGING

> *" REFERENCE(EMPLOYEE_DETAILS) TYPE ANY TABLE

I recommend 1 if your function module is RFC enabled, and 2 if it isn't. 3 will work, but it's bad programming!

matt

Read only

peter_peng
Product and Topic Expert
Product and Topic Expert
0 Likes
1,721

Hi, Samprithsap,

you have to define a table type for changing parameter emp_det, or you just declare a structure emp_det because here ztable is just refered as a structure.

so, you have to go to se11 and define a table type whose line type is ztable, then use this table type to define emp_det.

in addition, I don't think it's necessary to define changing parameter. If it is, you just need define emp_det as table parameter where you can use ztable directly.

Edited by: Peter Peng on Oct 19, 2010 4:13 AM

Read only

nabheetscn
SAP Champion
SAP Champion
0 Likes
1,722

Just pass this in tables parameter it will work.

Nabheet

Read only

0 Likes
1,721

i changed changing parameter to table parameter

still same error

FUNCTION Z_TEST_RKM.

*"----


""Local Interface:

*" TABLES

*" EMPDETAIL STRUCTURE zhr_table

*"----


types: begin of ty_str,

MANDT type MANDT,

PERNR type PERSNO,

VORNA type PAD_VORNA,

NACHN type PAD_NACHN,

end of ty_str.

data: it_employee_detail TYPE STANDARD TABLE OF ty_str,

wa_employee_info TYPE ty_str.

select * from ZHR_TABLE into table it_employee_detail.

EMPDETAIL = it_employee_detail.

ENDFUNCTION.

Read only

0 Likes
1,721

Hi

Does your structure ty_Str contains all the fields of table zhr_table. the structure of ty_str and it_emp_detail is not matching i guess.

You can define your internal table of the same structure of zhr_table and try.

Regards

Sridevi S

Read only

0 Likes
1,721

If you want all data from ZHR_TABLE into EMPDETAIL parameter of FM

No need to define any structure and another internal table and then assigning

this internal table to FM parameter you can just write below query in your FM logic,

select * from ZHR_TABLE into table EMPDETAIL.

Regards,

Pawan

Read only

0 Likes
1,721

Hi,

If you already changed to table type then, must be the different structure,

Please check tht both the tables are identical.

Thanks,

Anmol.

Read only

Clemenss
Active Contributor
0 Likes
1,721

Hi,

use

EMPDETAIL[] = it_employee_detail[].

to make sure the table body is used regardless of header line presence.

Regards,

Clemens