09-19-2008 8:23 AM
Hello,everybody!
I'm creating a fuction modul or a class's method. But met a problem.I want to change the exporting parameter's type dynamically.
Here is what I want to do.
import data:
stru_name (structure name) dictionary table
indata (input data) string
output
outdata (output data)
The output data will be divided according to the structure of stru_name.
For example:
structure(a(3),b(3),c(3))
indata(123456789)
u2192outdata(123,456,789)
structure(a(2),b(3),c(4))
indata(123456789)
u2192outdata(12,345,6789)
Can anybody give me some advices?
I will appreciate your help.
Thanks.
Chen.
09-22-2008 11:01 PM
Make the parameter type ANY. Then you can pass data of any structure.
09-23-2008 4:08 AM
Hello Junhua,
Don give any type for the parameters in the function module to make it generic.
Regards
Farzan
09-24-2008 1:29 AM
Hello Sourav,Farzan
Thanks for your reply.
I have give any type for the output parameter .
But at the end of my source ,how I move the data to the output parameter.
Here is my source.
FUNCTION z_divide_data_by_stru.
*"----
""ローカルインタフェース:
*" IMPORTING
*" REFERENCE(STRU_NAME) TYPE STRUNAME
*" REFERENCE(I_DATA) TYPE STRING
*" EXPORTING
*" REFERENCE(O_DATA) TYPE ANY
*" EXCEPTIONS
*" LENGTH_ERROR
*" OTHER_ERROR
*"----
DATA:
dy_stru TYPE REF TO data,
res_dfies TYPE ddfields,
res_header TYPE x030l,
wl_dfies TYPE dfies.
DATA:
wa_offset TYPE doffset,
wa_length TYPE ddleng.
FIELD-SYMBOLS:
<dyn_stru>,
<dyn_field>.
CREATE DATA dy_stru TYPE (stru_name).
ASSIGN dy_stru->* TO <dyn_stru>.
CALL FUNCTION 'TR_NAMETAB_GET'
EXPORTING
iv_tabname = stru_name
iv_get_lengths_in_charmode = 'X'
IV_GET_TEXTS = ' '
IMPORTING
et_dfies = res_dfies
es_header = res_header
EXCEPTIONS
not_found = 1
OTHERS = 2.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
DO.
ASSIGN COMPONENT sy-index
OF STRUCTURE <dyn_stru> TO <dyn_field>.
READ TABLE res_dfies INTO wl_dfies INDEX sy-index.
wa_offset = wl_dfies-offset.
wa_length = wl_dfies-leng.
<dyn_field> = i_data+wa_offset(wa_length).
IF sy-subrc <> 0.
EXIT.
ENDIF.
ENDDO.
WRITE <dyn_stru> TO o_data. -
>Here is my problem....
ENDFUNCTION.
Can you give me some other advice?