Search on this Website

Friday, June 8, 2007

Example of Dynamic Internal table

see the example program :

REPORT abc.

*------------- COMPULSORY
FIELD-SYMBOLS: TYPE ANY TABLE.
FIELD-SYMBOLS: TYPE ANY.
DATA: lt TYPE lvc_t_fcat.
DATA: ls TYPE lvc_s_fcat.
FIELD-SYMBOLS: TYPE ANY.
DATA : fldname(50) TYPE c.



*--------------------
PARAMETERS : infty(4) TYPE c OBLIGATORY.
DATA : iname LIKE dd02l-tabname.

START-OF-SELECTION.
*------------------- GET INFO
CONCATENATE 'P' infty INTO iname.
DATA : ddfields LIKE ddfield OCCURS 0 WITH HEADER LINE.
CALL FUNCTION 'DD_NAMETAB_TO_DDFIELDS'
EXPORTING
tabname = iname
TABLES
ddfields = ddfields.
.

*------------- CONSTRUCT FIELD LIST

LOOP AT ddfields.
ls-fieldname = ddfields-fieldname.
APPEND ls TO lt.
ENDLOOP.

*-------------- PERFORM

PERFORM mydyntable USING lt.

BREAK-POINT.


*---------------------------------------------------------------
* INDEPENDENT FORM
*---------------------------------------------------------------

FORM mydyntable USING lt TYPE lvc_t_fcat .


*-------------- Create Dyn Table From FC

FIELD-SYMBOLS: TYPE REF TO data.
FIELD-SYMBOLS: .
FIELD-SYMBOLS: TYPE ANY TABLE.
DATA: lt_data TYPE REF TO data.


ASSIGN lt_data TO .

CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = lt
IMPORTING
ep_table =
EXCEPTIONS
generate_subpool_dir_full = 1
OTHERS = 2.
IF sy-subrc <> 0.
ENDIF.


*------------- Assign Dyn Table To Field Sumbol

ASSIGN ->* TO .
ASSIGN TO .
ASSIGN TO .

ENDFORM. "MYDYNTABLE

No comments: