‎2007 Oct 20 12:28 PM
Hi.
I need to declare an internal table TYPE based on a dynamic table whose name at design time is unknown. I tried the following codes, but it is not working and generated an error:
***********************************************************************
DATA: TXT_FILENAME_VALUE(14) TYPE C.
FIELD-SYMBOLS: <FS_TXT_FILENAME_VALUE>.
TXT_FILENAME_VALUE = ''.
CONCATENATE 'TXT_FILENAME' TXT_FILENUMBER INTO TXT_FILENAME_VALUE.
ASSIGN (TXT_FILENAME_VALUE) TO <FS_TXT_FILENAME_VALUE>.
DATA UPLOAD_ITAB TYPE TABLE OF (<FS_TXT_FILENAME_VALUE>).
***********************************************************************
Error Generated: The type "(<FS_TXT_FILENAME_VALUE>)" is unknown.
Any help would be appreciated.
‎2007 Oct 20 2:11 PM
REPORT z_dynamic_program.
TABLES:dd02l,
vlcvehicle.
FIELD-SYMBOLS: <fs_table> TYPE STANDARD TABLE,
<fs_warea> TYPE ANY,
<fs_any> TYPE ANY.
DATA:t_anytable TYPE REF TO data,
f_warea TYPE REF TO data,
tb_condition(72) TYPE c OCCURS 0 WITH HEADER LINE.
DATA:w_dynproname TYPE sy-repid,
w_msg(70) TYPE c.
DATA:t_code(72) TYPE c OCCURS 0 WITH HEADER LINE.
PARAMETERS:pa_tnam LIKE dd02l-tabname.
SELECT-OPTIONS:so_comm FOR vlcvehicle-zz_commnos.
START-OF-SELECTION.
SELECT SINGLE * FROM dd02l WHERE tabname = pa_tnam.
IF sy-subrc NE 0.
STOP.
ENDIF.
APPEND 'Program SubPool.' TO t_code.
APPEND ' ' TO t_code.
CONCATENATE 'TYPES TY_TABLE TYPE ' pa_tnam ' OCCURS 0.'
INTO t_code SEPARATED BY space.
APPEND t_code.
CONCATENATE 'TYPES TY_WAREA TYPE ' pa_tnam '.'
INTO t_code SEPARATED BY space.
APPEND t_code.
APPEND 'Form generate_table changing p_table type ref to data '
TO t_code.
APPEND ' p_warea type ref to data.'
TO t_code.
APPEND ' create data p_table type (''TY_TABLE''). '
TO t_code.
APPEND ' create data p_warea type (''TY_WAREA''). '
TO t_code.
APPEND 'Endform. ' TO t_code.
GENERATE SUBROUTINE POOL t_code
NAME w_dynproname
MESSAGE w_msg.
IF sy-subrc NE 0.
WRITE : / w_msg.
STOP.
ENDIF.
*************
Call the subroutine to get reference to dyn table
PERFORM generate_table IN PROGRAM (w_dynproname)
CHANGING t_anytable
f_warea.
ASSIGN t_anytable->* TO <fs_table>.
ASSIGN f_warea->* TO <fs_warea>.
Fetch the data from the database based on the Commission number
and the Table name
SELECT *
INTO TABLE <fs_table>
FROM (pa_tnam)
WHERE Z_COMMNOS IN so_comm.
IF sy-subrc NE 0.
STOP.
ENDIF.
DELETE FROM (pa_tnam) WHERE Z_COMMNOS IN so_comm.
IF sy-subrc EQ 0.
WRITE:/ sy-dbcnt.
ENDIF.
END-OF-SELECTION.
You can also search the forum to see the method using OOPs concept
Reward if useful
Regards,
Aj
‎2007 Oct 20 2:48 PM
Hi Kian
Please check
<a href="/people/rich.heilman2/blog/2005/07/27/dynamic-internal-tables-and-structures--abap:///people/rich.heilman2/blog/2005/07/27/dynamic-internal-tables-and-structures--abap
Regards
Arun
‎2007 Oct 20 10:30 PM
Hello Kian,
basically you need 3 things to dynamically define the type of the table line you read within the program.
1) a field symbol which is an any type
2) a character field where you put the datatype of the table line in
3) a field which is a ref to data
You put the type of the line into the field 2) as string. you create the data object 3) with the dynamical assigned type you put in 2). last you assign the field symbol 1) to the data object 3) and cast to the type you put in 2).
here a short example which first read T000 and then T001 in the same fields.
FIELD-SYMBOLS:
<my_generic_line> TYPE ANY.
DATA:
lv_line_datatype TYPE typename,
lr_generic_data TYPE REF TO data.
lv_line_datatype = 'T000'.
CREATE DATA lr_generic_data TYPE (lv_line_datatype).
ASSIGN lr_generic_data->* TO <my_generic_line>
CASTING TYPE (lv_line_datatype).
SELECT * FROM t000
INTO
<my_generic_line>.
WRITE / <my_generic_line>.
ENDSELECT.
lv_line_datatype = 'T001'.
CREATE DATA lr_generic_data TYPE (lv_line_datatype).
ASSIGN lr_generic_data->* TO <my_generic_line>
CASTING TYPE (lv_line_datatype).
SELECT * FROM t001
INTO
<my_generic_line>.
WRITE / <my_generic_line>.
ENDSELECT.You can also read by SELECT INTO TABLE if you can dynamically determine a table type of the table line structure. Just change the field symbol from any type to any table type.
Hope tht helps a bit
Roman
‎2007 Oct 21 9:26 PM
Hello Kian
Have a look at the sample report <b>ZUS_SDN_READ_DYNAMIC_TABLE</b>.
*&---------------------------------------------------------------------*
*& Report ZUS_SDN_READ_DYNAMIC_TABLE
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT zus_sdn_read_dynamic_table.
DATA:
gdo_data TYPE REF TO data.
FIELD-SYMBOLS:
<gt_itab> TYPE table,
<gs_entry> TYPE ANY.
PARAMETERS:
p_table TYPE tabname DEFAULT 'KNA1',
p_fld TYPE fieldname DEFAULT 'KUNNR'.
START-OF-SELECTION.
CREATE DATA gdo_data TYPE TABLE OF (p_table).
ASSIGN gdo_data->* TO <gt_itab>.
SELECT * FROM (p_table) INTO TABLE <gt_itab>.
READ TABLE <gt_itab> ASSIGNING <gs_entry>
WITH KEY (p_fld) = '0000000001'.
write: / syst-subrc.
END-OF-SELECTION.Regards
Uwe