cancel
Showing results for 
Search instead for 
Did you mean: 

create dynamically a type containing an include type

marco_sposa
Participant
0 Kudos

Hello Expert,

i've generated a class with the scdo transaction insert changes in z tables in CDHR/POS.

looking into that class the write method, one of the paramter type is 

  types:
     BEGIN OF TY_ZTEST_123 .
      INCLUDE TYPE ZTEST_ABC.
      INCLUDE TYPE IF_CHDO_OBJECT_TOOLS_REL=>TY_ICDIND.
 TYPES END OF TY_ZTEST_123 .

Since they are many tables to manage, and the class name, class method generated by the system has exactly the same parameters ( on the name of the parameters changes but not the type : 

allways the table structure +  include type if+chdo_object_tools_rel=>ty_icdind.

i wanted to create a function module to class the appropriate method by passing the table name, the internal table for the class to recieve.

how should i build the internal class dynamically to have this kind of type?

 

  types:
     BEGIN OF TY_ZTEST_123 .
      INCLUDE TYPE ZTEST_ABC.
      INCLUDE TYPE IF_CHDO_OBJECT_TOOLS_REL=>TY_ICDIND.
 TYPES END OF TY_ZTEST_123 .

 

 

i try by creating a dynamic table like this

 

 

  CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
    EXPORTING
      i_structure_name       = p_name
    CHANGING
      ct_fieldcat            = p_fieldcat
    EXCEPTIONS
      inconsistent_interface = 1
      program_error          = 2
      OTHERS                 = 3.
  IF sy-subrc <> 0.
* Implement suitable error handling here
  ENDIF.

  CLEAR ls_fieldcat.
  ls_fieldcat-fieldname = 'kz'.
  ls_fieldcat-datatype  = 'CHAR'.
  ls_fieldcat-intlen    = '1'.
  ls_fieldcat-domname   = 'CDCHNGIND'.
  ls_fieldcat-ref_table = 'ICDIND'.
  APPEND ls_fieldcat TO p_fieldcat.

 

 

and

 

 

* Create dynamic internal table and assign to FS
  CALL METHOD cl_alv_table_create=>create_dynamic_table
    EXPORTING
      it_fieldcatalog  = lt_fieldcat
      i_length_in_byte = 'X'
    IMPORTING
      ep_table         = dy_table_new.

  ASSIGN dy_table_new->* TO <dyn_table_updt_new>.

 

 

but when i call the method dynamically the  the method i have an illegal cx_sy_dyn_call_error for the <dyn_table_updt_new> as the method parameter expected a table of tt_ztest123 defined as table of ty_ztest_123 . 

How could i solve this?

Thank you in advance

 

 

Sandra_Rossi
Active Contributor
Dynamic creation (means creation at runtime) of data type and dynamic calling are two completely different things. If I understand well your main question, you want to pass any type to a parameter of a method, so you should type it ANY. Please edit your question to clarify it.
Sandra_Rossi
Active Contributor
0 Kudos

For information, if you need to create a data type dynamically (not sure if it's really what you need), DON'T use the old method cl_alv_table_create=>create_dynamic_table. Instead, use the official and much more powerful RTTS (cl_abap_typedescr, etc.) The forum is full of examples. Reason to NOT use: Alternative to CL_ALV_TABLE_CREATE=>CREATE_DYNAMIC... - SAP Community.

marco_sposa
Participant
0 Kudos
Hello Sandra, thanks for your comment, i've edited the post and yes i'm willing to create dynamically a type. i will definitively read the link you kindly provide.

Accepted Solutions (1)

Accepted Solutions (1)

thomas_mller13
Participant
0 Kudos

./.

marco_sposa
Participant
0 Kudos
The fact is the type will always have the same structure: include type( a table) and include type if_chdo_object_tools_rel=>ty_icind.
marco_sposa
Participant
0 Kudos
the RTTI helped. thank you you all
Sandra_Rossi
Active Contributor
0 Kudos
@marco_sposa Please, don't mislead future visitors by marking this answer as the solution which says don't use RTTI and your solution is to use RTTI, post your own detailed answer and mark it as the solution.

Answers (3)

Answers (3)

thomas_mller13
Participant
0 Kudos

./.

thomas_mller13
Participant
0 Kudos

./.

Sandra_Rossi
Active Contributor
0 Kudos
Please use the buttons "..." and "</>" to make the code easy to read.
thomas_mller13
Participant
0 Kudos

./.

marco_sposa
Participant
0 Kudos
i guess i'm not clear: i have table 1 and a table 2. i need to create dynamically a type1 like types:ty1: include type table1.include type IF_CHDO_OBJECT_TOOLS_REL=>TY_ICDIND. types end of ty1. and for the second: types:ty2: include type table2.include type IF_CHDO_OBJECT_TOOLS_REL=>TY_ICDIND. types end of ty2. since i have 20 tables, i want to create dynamically the type. ho i'm clearer
marco_sposa
Participant
0 Kudos

Hello Sandra and thanks for your reply, i'm trying to create a type table dynamically i will definitively read the link you gave me.

Thanks