2012 Feb 27 8:39 AM
Hi Expert,
Is there any method to create transparent table on runtime instead of using SE11.
I have a program to copy data from a source table into a target table.
First, User have to enter source table and target table name.
Then program will get the structure of source table and pass the data into an internal table.
From the internal table again insert the data into the target table.
Lets say if the target table does not exist in data dictionary, I will have to create a new target transparent table based on the same structure of the source table during runtime.
Is there any way to do this?
Thank you.
2012 Feb 27 9:38 AM
Perform
- First ask database administrator for allowing user to create database tables in a productive system (...)
- Then read documentation on FM DDIF_TABL_PUT () (*)
Regards,
Raymond
(*) DDIF_TABL_GET (with from table) and DDIF_TABL_ACTIVATE can be useful too
(**) "This function module does not perform any authorization check and does not write any correction entry." but read first task
Hi Expert,
Is there any method to create transparent table on runtime instead of using SE11.
I have a program to copy data from a source table into a target table.
First, User have to enter source table and target table name.
Then program will get the structure of source table and pass the data into an internal table.
From the internal table again insert the data into the target table.
Lets say if the target table does not exist in data dictionary, I will have to create a new target transparent table based on the same structure of the source table during runtime.
Is there any way to do this?
Thank you.
2012 Feb 27 8:46 AM
You could try integrating a BDC for SE 11 and use field symbols to assign the appropriate table fields and types to the table control. Just a suggestion which i think would work.
Do let me know if u d like more info on it.
Also, post your code, i could make appropriate changes and present it to u.
Edited by: AJ Nayak on Feb 27, 2012 2:18 PM
2012 Feb 27 8:52 AM
Hi,
Can I have more info about that?
I am not only able to get the structure of the source table, but have no idea on creating the target transparent table.
Below code shows how I get the structure of the source table:
CREATE DATA testing_data TYPE STANDARD TABLE OF (source).
ASSIGN testing_data->* TO <source_table>.
2012 Feb 27 8:59 AM
Hi,
Can I have more info about that?
I am not only able to get the structure of the source table, but have no idea on creating the target transparent table.
Below code shows how I get the structure of the source table:
CREATE DATA testing_data TYPE STANDARD TABLE OF (source).
ASSIGN testing_data->* TO <source_table>.
Alright, Basically the logic would be to check if the target table already exists by checking the DD02l Table (passing your target table name. If it does exist, proceed with your process.
If it doesn't exist ( sy-subrc ne 0 ) run a BDC which creates it using the same structure as the source table assuming you already have the target structure as stated above, you can simply pass the structure values of the source to the appropriate fields in the BDC recording to create the table.
Also note that some data would have to be hardcoded, such as table description, Package to store the table, and Request number.
Edited by: AJ Nayak on Feb 27, 2012 2:35 PM
2012 Feb 27 9:13 AM
Hi,
Thanks for the info.
I will try to work on it and get back to you if encounter any issue.
Have a nice day.
2012 Feb 27 9:15 AM
Any time ! I hope it was clear enough. maybe we can wait a while and see if anyone comes up with a better idea.
2012 Feb 27 9:31 AM
Abetter way to get the field list of the source table would be the FM DDIF_FIELDINFO_GET just pass your table name to it and it will return a list of all the fields, domains etc etc in the 'DFIES_TAB' table.
2012 Feb 27 9:38 AM
Perform
- First ask database administrator for allowing user to create database tables in a productive system (...)
- Then read documentation on FM DDIF_TABL_PUT () (*)
Regards,
Raymond
(*) DDIF_TABL_GET (with from table) and DDIF_TABL_ACTIVATE can be useful too
(**) "This function module does not perform any authorization check and does not write any correction entry." but read first task
2012 Feb 27 9:49 AM
Thanks Raymond, That was an eye opener for me !
Very informative and useful !
2012 Feb 28 6:36 AM
Hi Raymond,
Is there any example program of DDIF_TABL_GET, DDIF_TABL_PUT and DDIF_TABL_ACTIVATE?
Thanks.
2012 Feb 28 7:35 AM
2012 Feb 28 10:33 AM
I hope this will help you for acheiving the requirement.
Please use the below code. i have emtnioned for creating one internal table.
DATA : i_tab TYPE TABLE OF dfies,
wa_tab TYPE dfies,
i_fc TYPE lvc_t_fcat,
w_table TYPE dfies-tabname,
wa_fc TYPE lvc_s_fcat,
w_dy_table TYPE REF TO data.
FIELD-SYMBOLS: <fs_table> TYPE STANDARD TABLE.
REFRESH : i_fc, i_tab.
CLEAR: wa_tab, w_dy_table.
w_table = Source table name from selection screen.
**get the structure details and fill the field catalogue.
CALL FUNCTION 'DDIF_FIELDINFO_GET'
EXPORTING
tabname = w_table
langu = sy-langu
TABLES
dfies_tab = i_tab
EXCEPTIONS
not_found = 1
internal_error = 2
OTHERS = 3.
LOOP AT i_tab into wa_tab.
CLEAR : wa_fc.
wa_fc-fieldname = wa_tab-fieldname.
wa_fc-datatype = wa_tab-inttype.
wa_fc-inttype = wa_tab-inttype.
wa_fc-intlen = wa_tab-outputlen.
wa_fc-decimals = wa_tab-decimals.
wa_fc-ref_table = w_table.
wa_fc-ref_field = wa_tab-fieldname.
APPEND wa_fc TO i_fc.
ENDLOOP.
CHECK i_fc[] IS NOT INITIAL.
**if field catalogue is filled, then pass it to method to create the internal table, **which then assign it to field symbol and utilize as required.
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = i_fc
IMPORTING
ep_table = w_dy_table.
TRY.
UNASSIGN: <fs_table>.
ASSIGN w_dy_table->* TO <fs_table>.
IF sy-subrc NE 0.
MESSAGE u2018Error while creating dynamic tableu2019.
ENDIF.
ENDTRY.
-
if the second table is not there, then you can use of the last try endtry with <fs_table2> and you can use further.
2012 Feb 29 2:08 AM
Hi All,
Is the below code already successfully get the structure of table SPFLI?
DATA: t_dd03p LIKE dd03p OCCURS 0 WITH HEADER LINE,
wa_dd02v LIKE dd02v,
wa_dd09l LIKE dd09l.
START-OF-SELECTION.
CALL FUNCTION 'DDIF_TABL_GET'
EXPORTING
name = 'SPFLI'
state = 'A'
IMPORTING
dd02v_wa = wa_dd02v
dd09l_wa = wa_dd09l
TABLES
dd03p_tab = t_dd03p.
Is yes, how to proceed to DDIF_TABL_PUT in order to create a new transparent table based on the structure of table SPFLI (including all the keys, fields, datatype, etc of table SPFLI)?
Thanks.
2012 Feb 29 5:54 AM
I recommend to use the code which i have given, it is working in production.
2012 Feb 29 7:12 AM
Hi Ramesh,
Yup, its working. But I am trying to use FM DDIF_TABL_GET, DDIF_TABL_PUT and DDIF_TABL_ACTIVATE to create the dynamic Z-Transparent table..
Below code is almost working, but still with some error. Do you notice any error there?
DATA: t_dd03p LIKE dd03p OCCURS 0 WITH HEADER LINE,
wa_dd02v LIKE dd02v,
wa_dd09l LIKE dd09v.
DATA: dd03p_internal TYPE STANDARD TABLE OF dd03p,
abc TYPE dd03p.
START-OF-SELECTION.
CALL FUNCTION 'DDIF_TABL_GET'
EXPORTING
name = 'SPFLI'
state = 'A'
IMPORTING
dd02v_wa = wa_dd02v
dd09l_wa = wa_dd09l
TABLES
dd03p_tab = t_dd03p
EXCEPTIONS
illegal_input = 1. " Value not Allowed for Parameter
LOOP AT t_dd03p INTO abc.
APPEND abc TO dd03p_internal.
ENDLOOP.
DELETE t_dd03p WHERE fieldname(2) NE 'VV'.
wa_dd02v-tabname = 'ZNEWTABLE' .
wa_dd02v-tabclass = 'TRANSP' .
wa_dd02v-as4user = sy-uname .
wa_dd02v-as4time = sy-uzeit .
wa_dd02v-as4date = sy-datum .
wa_dd02v-applclass = '' .
wa_dd02v-authclass = '' .
CALL FUNCTION 'DDIF_TABL_PUT'
EXPORTING
name = 'ZNEWTABLE'
dd02v_wa = wa_dd02v
dd09l_wa = wa_dd09l
TABLES
dd03p_tab = dd03p_internal.
CALL FUNCTION 'DDIF_TABL_ACTIVATE'
EXPORTING
name = 'ZNEWTABLE'
auth_chk = 'X'
EXCEPTIONS
not_found = 1 " Table not Found
put_failure = 2. " Table could not be Written
2012 Feb 29 7:39 AM
2012 Feb 29 9:31 AM
Hi Raymond and Ramesh,
Thanks for the info, its very useful to me.
It is working fine now, I can create dynamic Z-transparent table successfully.
So, i would like to share the code here in case in future anyone need this solution:
PARAMETER: source TYPE ddobjname,
target TYPE ddobjname.
DATA: l_got_state TYPE ddgotstate,
l_s_dd02v TYPE dd02v,
l_s_dd09l TYPE dd09l,
l_t_dd03p TYPE dd03p OCCURS 0,
l_key TYPE string,
l_rc TYPE sysubrc,
l_langu_space TYPE rs_bool.
FIELD-SYMBOLS:
<l_s_dd03p> TYPE dd03p.
read model table (header and technical settings)
CALL FUNCTION 'DDIF_TABL_GET'
EXPORTING
name = source
state = 'A'
langu = sy-langu
IMPORTING
gotstate = l_got_state
dd02v_wa = l_s_dd02v
dd09l_wa = l_s_dd09l
TABLES
dd03p_tab = l_t_dd03p
EXCEPTIONS
illegal_input = 1
OTHERS = 2.
IF sy-subrc <> 0
OR l_got_state <> 'A'.
EXIT.
ENDIF.
adjust header
l_s_dd02v-tabname = target.
l_s_dd02v-ddtext = target.
l_s_dd02v-as4user = sy-uname.
l_s_dd02v-as4date = sy-datum.
l_s_dd02v-as4time = sy-uzeit.
adjust technical settings
l_s_dd09l-tabname = target.
l_s_dd09l-as4user = sy-uname.
l_s_dd09l-as4date = sy-datum.
l_s_dd09l-as4time = sy-uzeit.
adjust tablnm
LOOP AT l_t_dd03p ASSIGNING <l_s_dd03p>.
<l_s_dd03p>-tabname = target.
ENDLOOP.
create table
CALL FUNCTION 'DDIF_TABL_PUT'
EXPORTING
name = target
dd02v_wa = l_s_dd02v
dd09l_wa = l_s_dd09l
TABLES
dd03p_tab = l_t_dd03p
EXCEPTIONS
tabl_not_found = 1
name_inconsistent = 2
tabl_inconsistent = 3
put_failure = 4
put_refused = 5
OTHERS = 6.
CALL FUNCTION 'DDIF_TABL_ACTIVATE'
EXPORTING
name = target
auth_chk = rs_c_false
prid = -2
IMPORTING
rc = l_rc
EXCEPTIONS
not_found = 1
put_failure = 2
OTHERS = 3.
Best Regards,
Kelvin
| User | Count |
|---|---|
| 4 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |