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 DDIC structure - work at runtime with changes

Former Member
0 Likes
1,437

Hi Experts,

I have a problem in a method of Web Dynpro Abap. Ich have a database structure /SME/DED_DYN and change its fields at runtime. I do that with the function DDIF_TABL_PUT and the activation with DDIF_TABL_ACTIVATE.

I have:


COMMIT WORK and wait.
  CALL FUNCTION 'DDIF_TABL_PUT'
     EXPORTING
         NAME = '/SME/DED_DYN'
     TABLES
         DD03P_TAB = DD03P_TAB
         DD05M_TAB = DD05M_TAB
         DD08V_TAB = DD08V_TAB
         DD35V_TAB = DD35V_TAB
         DD36M_TAB = DD36M_TAB
 
     EXCEPTIONS
         tabl_not_found          = 1
         name_inconsistent       = 2
         tabl_inconsistent       = 3
         put_failure             = 4
         put_refused             = 5
         others                  = 6.
 
  COMMIT WORK and wait.
 
  if sy-subrc = 0.
    call function 'DDIF_TABL_ACTIVATE'
      exporting
          name =  '/SME/DED_DYN'
      IMPORTING
          rc = rc    
      exceptions
            not_found   = 1
            put_failure = 2
            others      = 3.
  endif.

The fields of the DDIC structure /SME/DED_DYN are changed at runtime dynamicly. Not their value, the fields themselves with fieldname and datatype. I need to work with these NEW fields of the DDIC structure at the same runtime. But somewhere the OLD /SME/DED_DYN is buffered I think, because the method only reads this old structure although in Transaction SE11 it changes to the NEW one at runtime correctly. I have to refresh my whole Web Dynpro Application in the browser and then it works with the new structure.What buffer could this be and how can I clear it, so that my method in WebDynpro can proceed with the new DDIC structure?

I hope you understand my problem.

Thanks for your help!!

Best regards,

Ingmar

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
949

Hi,

It may help you.I have done it to concatinate the values of PK of some table. And here i hat to change the str runtime

FUNCTION ZKEY_CONCATINATE.

*"----


""Local Interface:

*" IMPORTING

*" REFERENCE(IV_NAME) TYPE DDOBJNAME

*" REFERENCE(IT_BATCH) TYPE ZCHARGTY OPTIONAL

*" TABLES

*" ET_RETURN TYPE BAPIRETTAB

*" ET_KEY STRUCTURE ZBROKEY

*"----


DATA: lt_DD03P_TAB TYPE TABLE OF DD03P.

DATA: ls_return_msg LIKE LINE OF Et_return.

DATA: dbtable TYPE REF TO data.

DATA: BEGIN OF lty_column,

FIELDNAME type FIELDNAME,

END OF lty_column.

DATA: lt_column like TABLE OF lty_column.

DATA: ls_column like LINE OF lt_column.

DATA: lv_column TYPE char50.

DATA: lv_key TYPE char50.

DATA: ls_sysubrc TYPE sy-SUBRC.

FIELD-SYMBOLS: <fs_DD03P_TAB> like LINE OF lt_DD03P_TAB,

<fs_table> TYPE ANY TABLE,

<fs_str> TYPE any,

<val>.

"Get primary keys

CALL FUNCTION 'DDIF_TABL_GET'

EXPORTING

NAME = IV_NAME

STATE = 'A'

LANGU = ' '

TABLES

DD03P_TAB = lt_DD03P_TAB

EXCEPTIONS

ILLEGAL_INPUT = 1

OTHERS = 2.

ls_sysubrc = sy-SUBRC.

case ls_sysubrc.

when 0.

****Collection of primary keys in a structure

LOOP at lt_DD03P_TAB ASSIGNING <fs_DD03P_TAB> WHERE KEYFLAG = 'X'.

CONCATENATE: '<fs_str>-'<fs_dd03p_tab>-fieldname INTO Ls_column-FIELDNAME.

APPEND ls_column to lt_column.

ENDLOOP.

TRY.

"Creation of BROKEY

CREATE DATA dbtable TYPE TABLE OF (IV_NAME).

ASSIGN dbtable->* to <fs_table>.

IF it_batch IS NOT INITIAL.

select * FROM (IV_NAME) INTO table <fs_table> FOR ALL ENTRIES IN it_batch WHERE charg = it_batch-batch.

ELSE.

select * FROM (IV_NAME) INTO table <fs_table>.

ENDIF.

CLEAR lv_key.

LOOP at <fs_table> ASSIGNING <fs_str>.

LOOP AT lt_column INTO lv_column.

ASSIGN (lv_column) to <val>.

CONCATENATE: lv_key'&'<val> INTO lv_key.

endloop.

APPEND lv_key to et_key.

CLEAR lv_key.

ENDLOOP.

catch cx_root.

"Error message when table does not exist

ls_return_msg = text-002.

APPEND ls_return_msg TO et_return.

endtry.

"Error Messages

when 1.

ls_return_msg = text-001.

APPEND ls_return_msg TO et_return.

WHEN 2.

CALL FUNCTION 'BALW_BAPIRETURN_GET2'

EXPORTING

type = sy-msgty

cl = sy-msgid

number = sy-msgno

par1 = sy-msgv1

par2 = sy-msgv2

par3 = sy-msgv3

par4 = sy-msgv4

IMPORTING

return = ls_return_msg.

APPEND ls_return_msg TO et_return.

ENDCASE.

ENDFUNCTION.

4 REPLIES 4
Read only

Former Member
0 Likes
949

I guess changing DDIC structures at runtime is problematic here. Why don´t you make use of dynamic structures beeing created at runtime using RTTI?

I think when referencing a DDIC structure during DATA declaration changing the DDIC structure at runtime won´t change the internal data objects created with reference to this DDIC structure.

Read only

0 Likes
949

Thanks for your reply!

I use another dynamic structure using RTTI at other place, but here I need a DDIC structure.

No other idea?

Read only

0 Likes
949

Hi,

I create a database table which name is ZTABL1 .

The fields of this table are MANDT and FIELDS1 .

Then i write the code below .

It changes the dbtable dynamically and the values of the fields.

I hope this help you.

DATA : DD03P_TAB LIKE DD03P OCCURS 0 WITH HEADER LINE .

DATA : DD05M_TAB LIKE DD05M OCCURS 0 WITH HEADER LINE .

DATA : DD08V_TAB LIKE DD08V OCCURS 0 WITH HEADER LINE .

DATA : DD12V_TAB LIKE DD12V OCCURS 0 WITH HEADER LINE .

DATA : DD17V_TAB LIKE DD17V OCCURS 0 WITH HEADER LINE .

DATA : DD35V_TAB LIKE DD35V OCCURS 0 WITH HEADER LINE .

DATA : DD36M_TAB LIKE DD36M OCCURS 0 WITH HEADER LINE .

DATA : lt_fcat TYPE lvc_t_fcat ,

ls_fcat TYPE lvc_s_fcat .

DATA : lt_table TYPE REF TO data.

DATA : ZTABL1 .

CALL FUNCTION 'DDIF_TABL_GET'

EXPORTING

NAME = 'ZTABL1'

TABLES

DD03P_TAB = DD03P_TAB

DD05M_TAB = DD05M_TAB

DD08V_TAB = DD08V_TAB

DD12V_TAB = DD12V_TAB

DD17V_TAB = DD17V_TAB

DD35V_TAB = DD35V_TAB

DD36M_TAB = DD36M_TAB

EXCEPTIONS

ILLEGAL_INPUT = 1

OTHERS = 2

.

LOOP AT DD05M_TAB WHERE FIELDNAME NE 'MANDT' .

DD05M_TAB-FIELDNAME = 'FIELD2' .

MODIFY DD05M_TAB .

ENDLOOP.

LOOP AT DD03P_TAB WHERE FIELDNAME NE 'MANDT'

.

DD03P_TAB-FIELDNAME = 'FIELD2' .

MODIFY DD03P_TAB .

ENDLOOP.

LOOP AT DD08V_TAB WHERE FIELDNAME NE 'MANDT' .

DD08V_TAB-FIELDNAME = 'FIELD2' .

APPEND DD08V_TAB .

ENDLOOP.

LOOP AT DD35V_TAB WHERE FIELDNAME NE 'MANDT' .

DD35V_TAB-FIELDNAME = 'FIELD2' .

MODIFY DD35V_TAB .

ENDLOOP.

LOOP AT DD36M_TAB WHERE FIELDNAME NE 'MANDT' .

DD36M_TAB-FIELDNAME = 'FIELD2' .

MODIFY DD36M_TAB .

ENDLOOP.

CALL FUNCTION 'DDIF_TABL_PUT'

EXPORTING

NAME = 'ZTABL1'

TABLES

DD03P_TAB = DD03P_TAB

DD05M_TAB = DD05M_TAB

DD08V_TAB = DD08V_TAB

DD35V_TAB = DD35V_TAB

DD36M_TAB = DD36M_TAB

EXCEPTIONS

TABL_NOT_FOUND = 1

NAME_INCONSISTENT = 2

TABL_INCONSISTENT = 3

PUT_FAILURE = 4

PUT_REFUSED = 5

OTHERS = 6

.

COMMIT WORK AND WAIT .

DATA : lv_subrc like sy-subrc .

CALL FUNCTION 'DDIF_TABL_ACTIVATE'

EXPORTING

NAME = 'ZTABL1'

AUTH_CHK = ' '

IMPORTING

RC = lv_subrc

EXCEPTIONS

NOT_FOUND = 1

PUT_FAILURE = 2

OTHERS = 3

.

COMMIT WORK AND WAIT .

clear : lt_fcat , lt_fcat[] .

LOOP AT DD03P_TAB .

MOVE-CORRESPONDING DD03P_TAB TO ls_fcat .

APPEND ls_fcat TO lt_fcat .

ENDLOOP.

PERFORM process.

&----


*& Form process

&----


form process.

FIELD-SYMBOLS : <table> TYPE table .

FIELD-SYMBOLS : <s_table> TYPE ANY .

FIELD-SYMBOLS : <f_1> TYPE ANY .

DATA : ls_ZTABL1 type ZTABL1 .

CALL METHOD cl_alv_table_create=>create_dynamic_table

EXPORTING it_fieldcatalog = lt_fcat

IMPORTING ep_table = lt_table.

ASSIGN lt_table->* TO <table>.

ASSIGN LOCAL COPY OF INITIAL LINE OF <table> TO <s_table>.

LOOP AT lt_fcat INTO ls_fcat.

IF ls_fcat-fieldname = 'FIELD2' .

ASSIGN COMPONENT ls_fcat-fieldname OF STRUCTURE <s_table> TO <f_1> .

<f_1> = 'A' .

ENDIF.

ENDLOOP.

MOVE-CORRESPONDING <s_table> TO ls_ZTABL1 .

INSERT INTO ZTABL1 values ls_ZTABL1.

endform. " process

Read only

Former Member
0 Likes
950

Hi,

It may help you.I have done it to concatinate the values of PK of some table. And here i hat to change the str runtime

FUNCTION ZKEY_CONCATINATE.

*"----


""Local Interface:

*" IMPORTING

*" REFERENCE(IV_NAME) TYPE DDOBJNAME

*" REFERENCE(IT_BATCH) TYPE ZCHARGTY OPTIONAL

*" TABLES

*" ET_RETURN TYPE BAPIRETTAB

*" ET_KEY STRUCTURE ZBROKEY

*"----


DATA: lt_DD03P_TAB TYPE TABLE OF DD03P.

DATA: ls_return_msg LIKE LINE OF Et_return.

DATA: dbtable TYPE REF TO data.

DATA: BEGIN OF lty_column,

FIELDNAME type FIELDNAME,

END OF lty_column.

DATA: lt_column like TABLE OF lty_column.

DATA: ls_column like LINE OF lt_column.

DATA: lv_column TYPE char50.

DATA: lv_key TYPE char50.

DATA: ls_sysubrc TYPE sy-SUBRC.

FIELD-SYMBOLS: <fs_DD03P_TAB> like LINE OF lt_DD03P_TAB,

<fs_table> TYPE ANY TABLE,

<fs_str> TYPE any,

<val>.

"Get primary keys

CALL FUNCTION 'DDIF_TABL_GET'

EXPORTING

NAME = IV_NAME

STATE = 'A'

LANGU = ' '

TABLES

DD03P_TAB = lt_DD03P_TAB

EXCEPTIONS

ILLEGAL_INPUT = 1

OTHERS = 2.

ls_sysubrc = sy-SUBRC.

case ls_sysubrc.

when 0.

****Collection of primary keys in a structure

LOOP at lt_DD03P_TAB ASSIGNING <fs_DD03P_TAB> WHERE KEYFLAG = 'X'.

CONCATENATE: '<fs_str>-'<fs_dd03p_tab>-fieldname INTO Ls_column-FIELDNAME.

APPEND ls_column to lt_column.

ENDLOOP.

TRY.

"Creation of BROKEY

CREATE DATA dbtable TYPE TABLE OF (IV_NAME).

ASSIGN dbtable->* to <fs_table>.

IF it_batch IS NOT INITIAL.

select * FROM (IV_NAME) INTO table <fs_table> FOR ALL ENTRIES IN it_batch WHERE charg = it_batch-batch.

ELSE.

select * FROM (IV_NAME) INTO table <fs_table>.

ENDIF.

CLEAR lv_key.

LOOP at <fs_table> ASSIGNING <fs_str>.

LOOP AT lt_column INTO lv_column.

ASSIGN (lv_column) to <val>.

CONCATENATE: lv_key'&'<val> INTO lv_key.

endloop.

APPEND lv_key to et_key.

CLEAR lv_key.

ENDLOOP.

catch cx_root.

"Error message when table does not exist

ls_return_msg = text-002.

APPEND ls_return_msg TO et_return.

endtry.

"Error Messages

when 1.

ls_return_msg = text-001.

APPEND ls_return_msg TO et_return.

WHEN 2.

CALL FUNCTION 'BALW_BAPIRETURN_GET2'

EXPORTING

type = sy-msgty

cl = sy-msgid

number = sy-msgno

par1 = sy-msgv1

par2 = sy-msgv2

par3 = sy-msgv3

par4 = sy-msgv4

IMPORTING

return = ls_return_msg.

APPEND ls_return_msg TO et_return.

ENDCASE.

ENDFUNCTION.