‎2006 Nov 20 9:06 PM
Hello guys,
I have to write a aprogram to update one Z table. The problem is that the program has to be used to update different Z tables, with different structures. So, I have to update a table , but I don't know the structure of the table. I only know that I fill have some pairs of fields like 1_from and 1_to , 2_from and 2_to ...., fields that need to met some logical conditions (validation). Is this possible? I was thinking to have the table name as an input parameter, then to define an internal table type ref to tabname, and then to update it, but I don't know hou do do it.
Can anyone help ?
Thank You!
‎2006 Nov 21 3:52 AM
here's a simple program to dynamicaly read and print the first 5 rows of any parameter supplied table. You can use the concepts to write an update program.
REPORT znrw_dyn_tab.
PARAMETERS: p_tab1 TYPE tabname.
DATA tabdref TYPE REF TO data.
FIELD-SYMBOLS <struc> TYPE ANY.
FIELD-SYMBOLS <tab> TYPE table.
PERFORM get_data USING tabdref p_tab1.
LOOP AT <tab> ASSIGNING <struc>.
PERFORM print USING <struc>.
ENDLOOP.
&----
*& Form get_data
&----
FORM get_data
USING us_tdref TYPE REF TO data
us_table TYPE tabname.
CREATE DATA us_tdref TYPE TABLE OF (us_table).
ASSIGN us_tdref->* TO <tab>.
SELECT * FROM (us_table) UP TO 5 ROWS INTO CORRESPONDING FIELDS OF
TABLE <tab>.
ENDFORM. "get_data
&----
*& Form print
&----
FORM print USING p_struc.
FIELD-SYMBOLS <field> TYPE ANY.
NEW-LINE.
DO.
*... work through all structure's components...
ASSIGN COMPONENT sy-index OF STRUCTURE p_struc TO <field>.
IF sy-subrc <> 0.
*... exit when reaching the end of components
EXIT.
ENDIF.
WRITE: <field>.
ENDDO.
ENDFORM. " print
‎2006 Nov 20 9:14 PM
Hi,
Please check this blog perhaps it may help.
/people/rich.heilman2/blog/2005/07/27/dynamic-internal-tables-and-structures--abap
Regards,
Ferry Lianto
‎2006 Nov 20 9:17 PM
‎2006 Nov 21 3:52 AM
here's a simple program to dynamicaly read and print the first 5 rows of any parameter supplied table. You can use the concepts to write an update program.
REPORT znrw_dyn_tab.
PARAMETERS: p_tab1 TYPE tabname.
DATA tabdref TYPE REF TO data.
FIELD-SYMBOLS <struc> TYPE ANY.
FIELD-SYMBOLS <tab> TYPE table.
PERFORM get_data USING tabdref p_tab1.
LOOP AT <tab> ASSIGNING <struc>.
PERFORM print USING <struc>.
ENDLOOP.
&----
*& Form get_data
&----
FORM get_data
USING us_tdref TYPE REF TO data
us_table TYPE tabname.
CREATE DATA us_tdref TYPE TABLE OF (us_table).
ASSIGN us_tdref->* TO <tab>.
SELECT * FROM (us_table) UP TO 5 ROWS INTO CORRESPONDING FIELDS OF
TABLE <tab>.
ENDFORM. "get_data
&----
*& Form print
&----
FORM print USING p_struc.
FIELD-SYMBOLS <field> TYPE ANY.
NEW-LINE.
DO.
*... work through all structure's components...
ASSIGN COMPONENT sy-index OF STRUCTURE p_struc TO <field>.
IF sy-subrc <> 0.
*... exit when reaching the end of components
EXIT.
ENDIF.
WRITE: <field>.
ENDDO.
ENDFORM. " print
‎2006 Nov 22 6:46 AM
Thank you all for your reply's.
Very helpful example, thank you.
Any suggestion for the update part? I don't know how to build a dynamic screen, generating fields according to my dynamic table.
‎2006 Nov 22 10:45 PM
we need to know a bit more to help you out on this.
1. do you really need to write a program? Why not use SM30? You might be trying to reinvent the wheel here.
2. do you know in advance the tables you are dealing with? If you do then you could build your screen with all the possible fields but only display the ones that relate to the entered table. Your PAI code would validate that the entered table is in the permitted set. Your PBO code would be hard-coded to hide fields not relating to the entered table.
3. if you want a slightly more generic approach you could create a control table which defines the tables allowed to be dealt with by this transaction and maybe another one defining the fields (name,type,length,Updateability etc). Your screen could have generic fields....field1,field2 etc. Your PAI code would consult the table to validate the entered table. The PBO code would use the entered table and the associated field list values to decide how many fields are displayed, what text precedes them and what format each one has.
‎2006 Nov 23 8:22 AM
Thank you for your reply.
It would be nice to do it through SM30, but I have to do lots of validation and authorisation checks, and I really don't know how to modify that transaction.
‎2006 Nov 23 8:25 AM
For validations, you can use the events that come with the table maintenance. See the document here, which explains how to deal with the events in detail.
Regards
Ravi
Note - Please mark all the helpful answers
‎2006 Nov 23 9:04 AM
Thank you very much for this tip.
Verry usefull. One more question: When I enter the events dialog, I have an information popup with "DO NOT CHANGE, SAP DATA".
Is it safe to add events there?
Thank you!
‎2006 Nov 23 9:14 AM
You will not manually add event but select which ones to be activated and then it will give a sort of include where you do your coding.
Regards,
Ravi