‎2007 Jan 03 10:33 AM
Hello,
I am building a filed catalog for generating a dynamic table. For this purpose I am using this form.
FORM get_structure .
DATA : idetails TYPE abap_compdescr_tab,
xdetails TYPE abap_compdescr.
DATA : ref_table_des TYPE REF TO cl_abap_structdescr.
Get the structure of the table.
ref_table_des ?=
cl_abap_typedescr=>describe_by_name( pa_tab ).
idetails[] = ref_table_des->components[].
LOOP AT idetails INTO xdetails.
CLEAR xfc.
xfc-fieldname = xdetails-name .
xfc-datatype = xdetails-type_kind.
xfc-inttype = xdetails-type_kind.
xfc-intlen = xdetails-length.
xfc-decimals = xdetails-decimals.
APPEND xfc TO ifc.
ENDLOOP.
ENDFORM. " get_structure
The problem is that idetails has different structure than desired. The field names are OK but data type and lenght of fields are returned in the internal format ( P instead of CURR , S instead of INT2 ). How can I obtain dynamically a table with a identical structure as pa_tab?
Thank you!
‎2007 Jan 03 3:56 PM
Hi George,
I have a simple program where, it reads the table name and its structure...
Please go through, it may help you.. ,
If i am not wrong, i understood that, you have to careate a dynamic structure by reading the table form the user.
I think you can make use of some of the function Modules in the below program
*********************************************
Sample Code:
*******************************************
&----
*& Report ZSNI_TEST002 *
*& *
&----
*& *
*& *
&----
REPORT zsni_test002 .
DATA: d_ref TYPE REF TO data,
d_ref2 TYPE REF TO data ,
i_alv_cat TYPE TABLE OF lvc_s_fcat,
ls_alv_cat LIKE LINE OF i_alv_cat.
TYPES tabname LIKE dcobjdef-name .
PARAMETER: p_tablen TYPE tabname .
*DATA: BEGIN OF itab OCCURS 0.
INCLUDE STRUCTURE dntab.
*DATA: END OF itab.
DATA: BEGIN OF itab OCCURS 0.
INCLUDE STRUCTURE dfies. "X031L.
DATA: END OF itab.
FIELD-SYMBOLS : <f_fs> TYPE table,
<f_fs1> TYPE table,
<f_fs2> TYPE ANY,
<f_fs3> TYPE table.
REFRESH itab.
*CALL FUNCTION 'NAMETAB_GET'
EXPORTING
langu = sy-langu
tabname = p_tablen
TABLES
nametab = itab
EXCEPTIONS
no_texts_found = 1.
*CALL FUNCTION 'DDIF_NAMETAB_GET'
EXPORTING
tabname = p_tablen
ALL_TYPES = ' '
LFIELDNAME = ' '
GROUP_NAMES = ' '
UCLEN =
IMPORTING
X030L_WA =
DTELINFO_WA =
TTYPINFO_WA =
DDOBJTYPE =
DFIES_WA =
LINES_DESCR =
TABLES
X031L_TAB = itab
DFIES_TAB =
EXCEPTIONS
NOT_FOUND = 1
OTHERS = 2
.
*IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
*ENDIF.
*CALL FUNCTION 'DDIF_FIELDINFO_GET'
EXPORTING
tabname = p_tablen
FIELDNAME = ' '
LANGU = SY-LANGU
LFIELDNAME = ' '
ALL_TYPES = ' '
GROUP_NAMES = ' '
UCLEN =
IMPORTING
X030L_WA =
DDOBJTYPE =
DFIES_WA =
LINES_DESCR =
TABLES
DFIES_TAB = itab
FIXED_VALUES =
EXCEPTIONS
NOT_FOUND = 1
INTERNAL_ERROR = 2
OTHERS = 3
.
*IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
*ENDIF.
*
*LOOP AT itab .
ls_alv_cat-fieldname = itab-fieldname.
ls_alv_cat-ref_table = p_tablen.
ls_alv_cat-ref_field = itab-fieldname.
APPEND ls_alv_cat TO i_alv_cat.
*ENDLOOP.
DATA : PQ(3) TYPE N.
DO 100 TIMES.
PQ = SY-INDEX.
CONCATENATE 'D' PQ INTO ls_alv_cat-fieldname.
ls_alv_cat-ref_table = 'MAKT'.
ls_alv_cat-ref_field = 'MAKTX'.
APPEND ls_alv_cat TO i_alv_cat.
ENDDO.
internal table build
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = i_alv_cat
IMPORTING
ep_table = d_ref.
ASSIGN d_ref->* TO <f_fs>.
SELECT * FROM (p_tablen) INTO CORRESPONDING FIELDS OF TABLE <f_fs>.
LOOP AT <f_fs> ASSIGNING <f_fs2>.
*your code goes here.
ENDLOOP.
Regards,
Manjunatha