2006 Feb 20 12:43 PM
Hi Guys,
I have a requirement where in I need to create an internal table after user inputting.
I have a parameter where the user enters the Table Name.I need to create dynamic internal table for the table entered by the user.How can I do it??
Note: This is a requirement for 3.1I Version.
So, cl_alv_table_create=>create_dynamic_table doesn't work here.
Regards,
Vinod.
2006 Feb 20 12:47 PM
Hi,
Try this and kindly reward points by clicking the star on the left of reply,if it helps.
REPORT ZCLUST1 .
*
Example: how to create a dynamic internal table
The dynamic internal table stucture
DATA: BEGIN OF STRUCT OCCURS 10,
FILDNAME(8) TYPE C,
ABPTYPE TYPE C,
LENGTH TYPE I,
END OF STRUCT.
The dynamic program source table
DATA: BEGIN OF INCTABL OCCURS 10,
LINE(72),
END OF INCTABL.
DATA: LNG TYPE I, TYPESRTING(6).
Sample dynamic internal table stucture
STRUCT-FILDNAME = 'field1'. STRUCT-ABPTYPE = 'c'. STRUCT-LENGTH = '6'.
APPEND STRUCT. CLEAR STRUCT.
STRUCT-FILDNAME = 'field2'. STRUCT-ABPTYPE = 'd'.
APPEND STRUCT. CLEAR STRUCT.
STRUCT-FILDNAME = 'field3'. STRUCT-ABPTYPE = 'i'.
APPEND STRUCT. CLEAR STRUCT.
Create the dynamic internal table definition in the dyn. program
INCTABL-LINE = 'program zdynpro.'. APPEND INCTABL.
INCTABL-LINE = 'data: begin of dyntab occurs 10,'. APPEND INCTABL.
LOOP AT STRUCT.
INCTABL-LINE = STRUCT-FILDNAME.
LNG = STRLEN( STRUCT-FILDNAME ).
IF NOT STRUCT-LENGTH IS INITIAL .
TYPESRTING(1) = '('.
TYPESRTING+1 = STRUCT-LENGTH.
TYPESRTING+5 = ')'.
CONDENSE TYPESRTING NO-GAPS.
INCTABL-LINE+LNG = TYPESRTING.
ENDIF.
INCTABL-LINE+15 = 'type '.
INCTABL-LINE+21 = STRUCT-ABPTYPE.
INCTABL-LINE+22 = ','.
APPEND INCTABL.
ENDLOOP.
INCTABL-LINE = 'end of dyntab. '.
APPEND INCTABL.
Create the code processes the dynamic internal table
INCTABL-LINE = ' '. APPEND INCTABL.
INCTABL-LINE = 'dyntab-field1 = ''aaaaaa''.'. APPEND INCTABL.
INCTABL-LINE = 'dyntab-field1 = ''19970814''.'. APPEND INCTABL.
INCTABL-LINE = 'dyntab-field1 = 1.'. APPEND INCTABL.
INCTABL-LINE = 'append dyntab.'. APPEND INCTABL.
INCTABL-LINE = ' '. APPEND INCTABL.
INCTABL-LINE = 'loop at dyntab.'. APPEND INCTABL.
INCTABL-LINE = 'write: / dyntab.'. APPEND INCTABL.
INCTABL-LINE = 'endloop.'. APPEND INCTABL.
Create and run the dynamic program
INSERT REPORT 'zdynpro'(001) FROM INCTABL.
SUBMIT ZDYNPRO.
2006 Feb 20 12:50 PM
Hi,
you could try to make like SAP, the goal is to create a report in the memory and call this report.
In the report, you describe a table with all the field. You have to create a field-symbols to point on this table.
I'm not sure that will works in 3.1.
Most simple is to look inside the code of the OOo.
Rgd
Frédéric
2006 Feb 20 12:58 PM
Hi vinod,
1. 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 some inputs (ie. field list)
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 : 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: <fs_data> TYPE REF TO data.
FIELD-SYMBOLS: <fs_1>.
FIELD-SYMBOLS: <fs_2> TYPE ANY TABLE.
DATA: lt_data TYPE REF TO data.
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.
2006 Feb 20 1:10 PM
2006 Feb 20 1:18 PM
Hi Vinod
I'm sorry, but you can't create a dynamic internal table in your release.
Every tools to create it are available from rel. 4.6A
Max
2006 Feb 20 9:27 PM
Hi,
DATA: it_new_table TYPE REF TO data,
wa_new_table TYPE REF TO data,
it_fieldcat TYPE lvc_t_fcat.
FIELD-SYMBOLS:<it_dynamic_table> TYPE STANDARD TABLE,
<wa_dynamic_table> TYPE ANY.
Create a new Table
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = it_fieldcat
IMPORTING
ep_table = it_new_table.
Create a new Line with the same structure of the table.
ASSIGN it_new_table->* TO <it_dynamic_table>.
CREATE DATA wa_new_table LIKE LINE OF it_dynamic_table>.
ASSIGN wa_new_table->* TO <wa_dynamic_table>.
Thanks,
Pramod
| User | Count |
|---|---|
| 4 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |