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

Dynamic update

Former Member
0 Likes
1,047

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!

1 ACCEPTED SOLUTION
Read only

former_member186741
Active Contributor
0 Likes
1,018

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

9 REPLIES 9
Read only

ferry_lianto
Active Contributor
0 Likes
1,018

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

Read only

Former Member
0 Likes
1,018

Hi

You can use the Dynamic internal tables for the same,

Weblogs

/people/rich.heilman2/blog/2005/07/27/dynamic-internal-tables-and-structures--abap

/people/subramanian.venkateswaran2/blog/2004/11/19/dynamic-internal-table

Regards

Kathirvel

Read only

former_member186741
Active Contributor
0 Likes
1,019

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

Read only

0 Likes
1,018

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.

Read only

0 Likes
1,018

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.

Read only

0 Likes
1,018

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.

Read only

0 Likes
1,018

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.

https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/library/abap/how%20to%20im...

Regards

Ravi

Note - Please mark all the helpful answers

Read only

0 Likes
1,018

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!

Read only

0 Likes
1,018

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