‎2007 Jul 24 1:04 PM
Hi,
How is a work area defined runtime from a structure? I would like to read the name of the structure from db table. Then use that structure to define a work area.
I have tried the following.
data:
struc_name type abap_typename,
structure_name(25) type c.
structure_name = 'ZDKD0001INSTALMENTS'.
move structure_name to struc_name.
data:
wa_structure type struc_name.
Hope anyone can help.
Regards,
Morten
‎2007 Jul 24 1:43 PM
Hi morten,
1.
For this purpose,
in my program,
there is an INDEPENDENT FORM
whose inputs are
TABLE NAME / STRUCTURE NAME
and from those, it consructs dynamic table.
2. Here is the program.
the dynamic table name will be
<DYNTABLE>.
3. U can use this program (FORM in this program)
to generate any kind of internal table
by specifying TABLE NAME .
4.
REPORT abc.
*----
COMPULSORY
FIELD-SYMBOLS: <dyntable> TYPE ANY TABLE.
FIELD-SYMBOLS: <dynline> TYPE ANY.
DATA: lt TYPE lvc_t_fcat.
DATA: ls TYPE lvc_s_fcat.
FIELD-SYMBOLS: <fld> TYPE ANY.
DATA : fldname(50) TYPE c.
*----
parameters : iname LIKE dd02l-tabname.
*----
START-OF-SELECTION.
*----
PERFORM
PERFORM mydyntable USING lt.
BREAK-POINT.
*----
INDEPENDENT FORM
*----
FORM mydyntable USING ptabname.
*----
Create Dyn Table From FC
FIELD-SYMBOLS: <fs_data> TYPE REF TO data.
FIELD-SYMBOLS: <fs_1>.
FIELD-SYMBOLS: <fs_2> TYPE ANY TABLE.
DATA: lt_data TYPE REF TO data.
data : lt TYPE lvc_t_fcat .
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.
ASSIGN lt_data TO <fs_data>.
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = lt
IMPORTING
ep_table = <fs_data>
EXCEPTIONS
generate_subpool_dir_full = 1
OTHERS = 2.
IF sy-subrc <> 0.
ENDIF.
*----
Assign Dyn Table To Field Sumbol
ASSIGN <fs_data>->* TO <fs_1>.
ASSIGN <fs_1> TO <fs_2>.
ASSIGN <fs_1> TO <dyntable>.
ENDFORM. "MYDYNTABLE
regards,
amit m.
‎2007 Jul 24 1:09 PM
as u are hard coding your structure name the runtime concept never comes in to picture here
‎2007 Jul 24 1:12 PM
Hi,
Just click on the below link.
Here you can see the complete details of HOW TO CREATE DYANMIC INTERNAL TABLE( Defining structure at runtime ). It is Crystal Clear.
" http://www.saptechnical.com/Tutorials/ABAP/DynamicInternaltable/DynamicInternalTable.htm "
Regards
‎2007 Jul 24 1:43 PM
Hi morten,
1.
For this purpose,
in my program,
there is an INDEPENDENT FORM
whose inputs are
TABLE NAME / STRUCTURE NAME
and from those, it consructs dynamic table.
2. Here is the program.
the dynamic table name will be
<DYNTABLE>.
3. U can use this program (FORM in this program)
to generate any kind of internal table
by specifying TABLE NAME .
4.
REPORT abc.
*----
COMPULSORY
FIELD-SYMBOLS: <dyntable> TYPE ANY TABLE.
FIELD-SYMBOLS: <dynline> TYPE ANY.
DATA: lt TYPE lvc_t_fcat.
DATA: ls TYPE lvc_s_fcat.
FIELD-SYMBOLS: <fld> TYPE ANY.
DATA : fldname(50) TYPE c.
*----
parameters : iname LIKE dd02l-tabname.
*----
START-OF-SELECTION.
*----
PERFORM
PERFORM mydyntable USING lt.
BREAK-POINT.
*----
INDEPENDENT FORM
*----
FORM mydyntable USING ptabname.
*----
Create Dyn Table From FC
FIELD-SYMBOLS: <fs_data> TYPE REF TO data.
FIELD-SYMBOLS: <fs_1>.
FIELD-SYMBOLS: <fs_2> TYPE ANY TABLE.
DATA: lt_data TYPE REF TO data.
data : lt TYPE lvc_t_fcat .
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.
ASSIGN lt_data TO <fs_data>.
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = lt
IMPORTING
ep_table = <fs_data>
EXCEPTIONS
generate_subpool_dir_full = 1
OTHERS = 2.
IF sy-subrc <> 0.
ENDIF.
*----
Assign Dyn Table To Field Sumbol
ASSIGN <fs_data>->* TO <fs_1>.
ASSIGN <fs_1> TO <fs_2>.
ASSIGN <fs_1> TO <dyntable>.
ENDFORM. "MYDYNTABLE
regards,
amit m.
‎2007 Jul 24 1:47 PM
Hi,
Try way.
<b>TYPE-POOLS ABAP.
DATA: STRUC_NAME TYPE ABAP_TYPENAME.
DATA: TABLEMARA TYPE TABLE OF MARA.
FIELD-SYMBOLS <FS_WA> TYPE ANY.
START-OF-SELECTION.
STRUC_NAME = 'TABLEMARA'.
ASSIGN (STRUC_NAME) TO <FS_WA>.
....
</b>
or.
<b>DATA: DATA_OBJ TYPE REF TO DATA.
FIELD-SYMBOLS <FS_WA> TYPE ANY.
START-OF-SELECTION.
CREATE DATA DATA_OBJ TYPE MARA.
ASSIGN DATA_OBJ->* TO <FS_WA>.</b>
Regards.
Marcelo Ramos
‎2007 Jul 24 1:49 PM
data: wa_ref type ref to data.
field-symbols : <wa_fs> type any.
during run time call..
<b>CREATE DATA wa_ref TYPE (MARA). </b> " To create wa like data dictionary table or structure
<b>CREATE DATA wa_ref LIKE LINE OF itab. </b>" To create wa type of some internal table.
then
use..
<b>ASSIGN wa_ref->* TO <wa_fs>.
</b>
then u can use <wa_fs> as work area for internal table or some type..
Reward if useful
Regards
Prax