‎2010 Jul 14 11:09 AM
Dear all:
Please help.
If i will be create 25 add on tables, each table include the same fields for user id, create date, create time and terminal id. Each add on table will be create table maintenance. For set these four fields value, my original as below, but it's will be a long statement. I want to know that have function or other statement to do this. Thanks a lot!!
CASE p_dynnr.
WHEN '0001'. "for add on table ZZRDF001
zzrdf001-usnam = sy-uname. "user id
zzrdf001-datum = sy-datum. "create/change date
zzrdf001-uzeit = sy-uzeit. "create/change time
zzrdf001-term = p_term. "terminal id
WHEN '0002'. "for add on table ZZRDF01
zzrdf01-usnam = sy-uname. "user id
zzrdf01-datum = sy-datum. "create/change date
zzrdf01-uzeit = sy-uzeit. "create/change time
zzrdf01-term = p_term. "terminal id
WHEN '0003'."for add on table ZZRDF02
zzrdf02-usnam = sy-uname. "user id
zzrdf02-datum = sy-datum. "create/change date
zzrdf02-uzeit = sy-uzeit. "create/change time
zzrdf02-term = p_term. "terminal id
WHEN '0005'. "for add on table ZZRDF04
zzrdf04-usnam = sy-uname. "user id
zzrdf04-datum = sy-datum. "create/change date
zzrdf04-uzeit = sy-uzeit. "create/change time
zzrdf04-term = p_term. "terminal id
ENDCASE.
Moderator message: please use more descriptive subject lines from now on.
Edited by: Thomas Zloch on Jul 14, 2010 12:54 PM
‎2010 Jul 15 1:55 PM
data:begin of wa_s,
name type sy-uname,
date type sy-datum,
time type sy-uzeit,
end of wa_s.
field-symbols:<fs> type any.
wa_s-name = sy-uname.
wa_s-date = sy-datum.
wa_s-time = sy-uzeit.
CASE p_dynnr.
WHEN '0001'. "for add on table ZZRDF001
assign <fs> to zzrdf001.
WHEN '0002'. "for add on table ZZRDF01
assign <fs> to zzrdf01.
WHEN '0003'."for add on table ZZRDF02
assign <fs> to zzrdf02.
WHEN '0005'. "for add on table ZZRDF04
assign <fs> to zzrdf04.
ENDCASE.
move-corresponding wa_s to <fs>.
Will this do ?
Hi,
why are using screen number, your are selecting the table name through select query right ?
Edited by: Keshav.T on Jul 15, 2010 6:39 PM
‎2010 Jul 14 11:38 AM
Hi try the following code to reduce the size and improve the readability
DATA : BEGIN OF y_struc,
usnam LIKE zzrdf001-usnam,
datum LIKE zzrdf001-datum,
uzeit LIKE zzrdf001-uzeit,
term LIKE zzrdf001-term,
END OF y_struc.
MOVE : sy-uname TO y_struc-usnam
, sy-datum TO y_struc-datum
, sy-uzeit TO y_struc-uzeit
, p_term TO y_struc-term
.
CASE p_dynnr.
WHEN '0001'. "for add on table ZZRDF001
MOVE-CORRESPONDING y_struc TO zzrdf001.
WHEN '0002'. "for add on table ZZRDF01
MOVE-CORRESPONDING y_struc TO zzrdf01.
WHEN '0003'."for add on table ZZRDF02
MOVE-CORRESPONDING y_struc TO zzrdf02.
WHEN '0005'. "for add on table ZZRDF04
MOVE-CORRESPONDING y_struc TO zzrdf04.
ENDCASE.
or you can use teh MACROS for eliminating MOVE CORRESPONDENCE statement to improve the performance
DATA : BEGIN OF y_struc,
usnam LIKE zzrdf001-usnam,
datum LIKE zzrdf001-datum,
uzeit LIKE zzrdf001-uzeit,
term LIKE zzrdf001-term,
END OF y_struc.
MOVE : sy-uname TO y_struc-usnam
, sy-datum TO y_struc-datum
, sy-uzeit TO y_struc-uzeit
, p_term TO y_struc-term
.
CASE p_dynnr.
WHEN '0001'. "for add on table ZZRDF001
M_FILL_TABLE y_struc zzrdf001.
WHEN '0002'. "for add on table ZZRDF01
M_FILL_TABLE y_struc zzrdf01.
WHEN '0003'."for add on table ZZRDF02
M_FILL_TABLE y_struc zzrdf02.
WHEN '0005'. "for add on table ZZRDF04
M_FILL_TABLE y_struc zzrdf04.
ENDCASE.
DEFINE M_FILL_TABLE.
MOVE : &1-usnam to &2-usnam
, &1-datum to &2-usnam
, &1-uzeit to &2-uzeit
, &1-term to &2-term
.
END-OF-DEFINITION.Edited by: Senthil Kumar on Jul 14, 2010 4:09 PM
‎2010 Jul 14 11:49 AM
‎2010 Jul 14 12:27 PM
I have used stored table names (in a char30 if I remember correctly). Then one merely references the variable holding the table name or, as already noted, one could use field-symbols.
‎2010 Jul 14 3:02 PM
I would use a data reference for that but before doing so, since it seems that you have a1-to-1 relationship between screens and tables and all tables are typed the same, any approach you use would be much slicker if you named your tables consistently with your screens, e.g., table ZBB0001 for screen '0001'. A data reference works like this (assuming you follow my suggestion and you have a base structure or table that all others follow):
DATA: gr_dref TYPE REF TO data.
DATA: gv_tablename TYPE tablename.
FIELD-SYMBOLS: <fs> TYPE zbb0000.
CONCATENATE 'ZBB' sy-dynnr INTO gv_tablename.
TRY.
CREATE DATA gr_dref TYPE (gv_tablename).
ASSIGN gr_dref->* TO <fs>.
CATCH cx_sy_create_data_error.
* Do something
ENDTRY.
<fs>-field1 = '1'.
<fs>-field2 = '2'.
<fs>-field3 = '3'.
‎2010 Jul 15 8:31 AM
Thanks for your replied.But still have problem. I'm just not familiar 'field symbol'.
My statement as below
SELECT * INTO lw_tvdir "This is get my table name by input screen no.
FROM tvdir
UP TO 1 ROWS
WHERE area = 'ZRD01'
AND devclass = 'ZRD01'
AND ( liste = p_dynnr
OR detail = p_dynnr ).
ENDSELECT.
now, i want to combine the table name and field name(UNAME, datum, uzeit, term) to set each table fields value.
example: after selected tvdir the tablename is 'ZZRDF001'.
ZZRDF001-UNAME = SY-UNAME.
ZZRDF001-DATUM = SY-DATUM.
ZZRDF001-UZEIT = SY-UZEIT.
ZZRDF001-TERM = P_TERM.
and these fields will be update the real data. How can i do?
‎2010 Jul 15 1:42 PM
The example I gave you still applies, especially since you are using TVDIR to determine the table name. You can use one of the tables (since they are all typed the same) to declare the field symbol type in order to reference the field names directly in the program. Otherwise, you'll need to use a run time type identification class (or function) to get the index of each field in the structure and access them dynamically in a DO loop with the field symbol. You need to spend some time reading the help files and applying the example though - don't just say you're not familiar with field symbols. I wasn't either until I read about them and tried them out many years ago .
‎2010 Jul 15 1:55 PM
data:begin of wa_s,
name type sy-uname,
date type sy-datum,
time type sy-uzeit,
end of wa_s.
field-symbols:<fs> type any.
wa_s-name = sy-uname.
wa_s-date = sy-datum.
wa_s-time = sy-uzeit.
CASE p_dynnr.
WHEN '0001'. "for add on table ZZRDF001
assign <fs> to zzrdf001.
WHEN '0002'. "for add on table ZZRDF01
assign <fs> to zzrdf01.
WHEN '0003'."for add on table ZZRDF02
assign <fs> to zzrdf02.
WHEN '0005'. "for add on table ZZRDF04
assign <fs> to zzrdf04.
ENDCASE.
move-corresponding wa_s to <fs>.
Will this do ?
Hi,
why are using screen number, your are selecting the table name through select query right ?
Edited by: Keshav.T on Jul 15, 2010 6:39 PM
‎2010 Jul 15 2:36 PM
You would do that for 25 tables all typed the exact same? True, it's a bad design to start with, but what if they add 25 more tables? You're going to have to change the code every single time and then you wind up with a 50 level CASE statement. Why not make it dynamic and hands-off (no more development required, no matter how many tables they add)?
‎2010 Jul 15 2:42 PM
Hi Brad,
You are correct, i didnt know that he is selecting the table name from the DDIC table.
If so then it can be assigned once.
‎2010 Jul 15 5:49 PM
Thanks for you these reply and suggestion. Actually my English not pretty good, maybe the words fail to express what is meant. But it's OK. I will try by best to understand what you-all said.
I agree some opinion, because my problem and these situation that it's too difficult explain in English for me.
And my job situation It's a long story. I don't want to explain too much. Because it's like a pretext.
Anyway, thanks a lot and nice to meet you-all.
Best Regards,
Nicole Chen
‎2010 Jul 15 6:44 PM
Well, your english is better than most non-primary speakers. I'm still not exactly sure what your design is or what you're trying to accomplish but since you are making an effort, here is a snippet of code that might help (some obvious declarations/checks/handling left out):
DATA: gr_dref TYPE REF TO data.
DATA: gv_tablename TYPE vim_name.
FIELD-SYMBOLS: <fs> TYPE zzrdf001. "Assumes all table typed the same - may need to cast if not
SELECT SINGLE tabname FROM tvdir INTO gv_tablename "This is get my table name by input screen no.
WHERE area EQ 'ZRD01'
AND devclass EQ 'ZRD01'
AND ( liste EQ p_dynnr OR
detail EQ p_dynnr ).
CHECK sy-subrc EQ 0.
TRY.
CREATE DATA gr_dref TYPE (gv_tablename).
ASSIGN gr_dref->* TO <fs>.
CATCH cx_sy_create_data_error.
* Do something
ENDTRY.
<fs>-uname = sy-uname. "Assumes UNAME is the key
<fs>-datum = sy-datum.
<fs>-uzeit = sy-uzeit.
<fs>-term = p_term.
MODIFY (gv_tablename) FROM <fs>.
COMMIT WORK.
‎2010 Jul 21 2:25 AM
Dear Brad:
Thank you very much. Thanks a lot for your help. It's look like work. For some situation still wrong, but it's OK to me.
Thank you to offer an opinion and the example.
Best Regards,
Nicole Chen