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

Function module - input datatype Mismatch

Former Member
0 Likes
1,098

Dear All,

I have developed a function module that would convert any '#' in a supplied string to '_'. I have defined the import and export parameters as 'string'.

This function module is getting called only if we call it exporting a variable of datatype 'string' and does not get called if we export a variable whose data type is different from 'string' (say Char20).

One work around is to define another variable with data type 'string' and pass this variable to the function module (after taking the contents of the variable with a different data type into this 'string' variable). But, isn't there a better solution like the SAP standard function module 'string_length' which can be called by exporting a variable of any data type (like char20, char10, num, string etc).

I want this function module to be used in Transformation (in BI) while loading data into an InfoProvider. I may want to remove '#' in 0MATERIAL or 0CUSTOMER or ZCUSTOMER which may have different datatypes and I do not want the user to do the workaround while calling this function module (by creating a variable with 'String') each time.

Please help.

Thanks,

Bajrang

Message was edited by:

Sriram Bajrang Bulusu

1 ACCEPTED SOLUTION
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
835

Sure, all you need to do is not assign a type to the importing and/or exporting parameters, this makes them generic and they will take the type of what is being pass to it.

So here is a funcitno module, notice there is no type in the signature.



function z_test.
*"----------------------------------------------------------------------
*"*"Local interface:
*"  IMPORTING
*"     REFERENCE(I_STR)
*"  EXPORTING
*"     REFERENCE(E_STR)
*"----------------------------------------------------------------------


  e_str = i_str.

  translate e_str using '#_'.


endfunction.

So when you call this, you can pass a string, a character field, what ever.

Regards,

RIch Heilman

2 REPLIES 2
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
836

Sure, all you need to do is not assign a type to the importing and/or exporting parameters, this makes them generic and they will take the type of what is being pass to it.

So here is a funcitno module, notice there is no type in the signature.



function z_test.
*"----------------------------------------------------------------------
*"*"Local interface:
*"  IMPORTING
*"     REFERENCE(I_STR)
*"  EXPORTING
*"     REFERENCE(E_STR)
*"----------------------------------------------------------------------


  e_str = i_str.

  translate e_str using '#_'.


endfunction.

So when you call this, you can pass a string, a character field, what ever.

Regards,

RIch Heilman

Read only

0 Likes
835

So then the callling program looks like this.



report zrich_0001.

data: char20 type char20.
data: str type string.

char20 = 'aiwkdn#s;als#eoco'.


call function 'Z_TEST'
     exporting
          i_str = char20
     importing
          e_str = str.


write:/ str.

Regards,

Rich Heilman