2005 Sep 16 12:36 PM
hii,
i have fm in which i have the code like this
my ztab contains 4 columns field1 field2 field3 field4.
call function 'ZUPDATE'.
importing
tabname = 'ZTAB'
value = '2,3,4,5' .
now in <b>zupdate</b> function i have written code like this
data wa like ztab.
split value at ','
into wa-field1 wa-field2 wa-field3 wa-field4 .
modify (tabname) from wa .
but want to make this zupdate function as dynaminc so that it can be run for any z-table
i have tried using field symbols but not able to succeed.
the parameter i shud pass to zupdat fm will be any table name and its corressponding values saparated by ','.
help.
abhishek suppal
2005 Sep 16 12:54 PM
Hi
you can try so:
DATA: WA TYPE REF TO DATA.
DATA: T_VALUES(100) OCCURS 0 WITH HEADER LINE.
FIELD-SYMBOLS: <WA> TYPE ANY,
<VALUE> TYPE ANY.
Work area:
CREATE DATA WA TYPE (TABNAME).
ASSIGN WA->* TO <WA>.
REFRESH T_VALUE.
SPLIT VALUE AT ',' INTO TABLE T_VALUE.
LOOP AT T_VALUE.
ASSIGN COMPONENT SY-TABIX OF STRUCTURE <WA> TO <VALUE>.
MOVE T_VALUE TO <VALUE>.
ENDLOOP.
CHECK SY-SUBRC = 0.
MODIFY (TABNAME) FROM <WA>.
Max
2005 Sep 16 12:57 PM
Is it working ??
It is surprising that your function 'ZUPDATE' has the visiblity on the table declared in your first function ??
I would have expected some kind of Field-Symbol in order to address that particular table. Something like :
DATA : w_extern_tab(30) TYPE c VALUE '(ZFIRST_FUNCTION)ZTAB'
ASSIGN (w_extern_tab) TO <F>.
MODIIFY <F> FROM wa.
well, sort of.
Apart from this, I think you should use ASSIGN COMPONENT OF STRUCTURE ... to do this
2005 Sep 16 3:00 PM
I am not sure that it is a good idea to pass the values in a string. I would expect problems with packed formats or conversion exists.
Christian
2005 Sep 16 3:54 PM
2005 Sep 16 4:44 PM
hi, though max's code can compile successfully.
I think there are some problems in it.
First, 'ZUPDATE' maybe a customize table or a internal table.
For CREATE DATA WA TYPE (TABNAME).
if TABNAME is a DDIC type, it is ok, if a internal table name, it will be fail. because CREATE DATA need a 'Absolute Type Names', not a internal name. So if ZUPDATE is a internal table, you can do like following:
data: cl_typ type ref to CL_ABAP_TYPEDESCR.
cl_typ = CL_ABAP_TYPEDESCR=>DESCRIBE_BY_DATA( ZTAB ).
CALL FUNCTION 'ZUPDATE'
EXPORTING
TABNAME = cl_typ->ABSOLUTE_NAME
.........
Second, the problem is still have. even CREATE DATA can create a correct type table, but it is initial. And can its update be transfered out of the function? ZTAB is a table out of the FM.
In my opinion, if you want to achieve it in a clear and easy way, just reference how ALV function do.
transfer ANY table into FM, and using Field Symbol.
Just a table name is not enough.
hope it will be helpful
thanks