‎2006 Nov 20 8:43 AM
Hi,
How to create dynamic internal table using oops concept ..and is it possible to create dynamic internal table without using objects(oops concept)..
awaiting for your replies....
Regards,
Ravi
‎2006 Nov 20 8:45 AM
‎2006 Nov 20 8:45 AM
‎2006 Nov 20 8:46 AM
Hi ravi,
1.
For this purpose,
in my program,
<b> there is an INDEPENDENT FORM</b>
whose inputs are
<b> LIST OF FIELDS, (just as u require)</b>
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 list of fields.
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.
DATA : ddfields LIKE ddfield OCCURS 0 WITH HEADER LINE.
*----
START-OF-SELECTION.
*----
field list
ddfields-fieldname = 'BUKRS'.
APPEND DDFIELDS.
ddfields-fieldname = 'MATNR'.
APPEND DDFIELDS.
*----
PERFORM mydyntable .
*----
see <DYNTABLE> in debug mode.
BREAK-POINT.
*----
INDEPENDENT FORM
*----
FORM mydyntable .
*----
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 .
*----
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.
‎2006 Nov 20 8:46 AM
Hi Ravi,
Check out the links
http://searchsap.techtarget.com/tip/1,289483,sid21_gci912390,00.html
http://www.sap-img.com/ab030.htm
This links has examples also.
here is a small example
REPORT zricha001.
PARAMETERS: comp(50).
DATA: dref TYPE REF TO data.
FIELD-SYMBOLS: <dyn_table> TYPE STANDARD TABLE.
CREATE DATA dref TYPE TABLE OF (comp).
ASSIGN dref->* TO <dyn_table>.
SELECT * FROM (comp)
INTO TABLE <dyn_table>.
BREAK-POINT.
Hope this helps.
Regards,
Richa
‎2006 Nov 20 8:47 AM
u can create dynamic internal tables....u have to write code in routinues which when executed automatically creates dynamic internal tables..
Check this link....http://www.sap-img.com/ab030.htm
This has various examples which shows how to create dynamic internal tables...
‎2006 Nov 20 8:48 AM
hi,
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.
regards,
keerthi
‎2006 Nov 20 8:49 AM
Hi Ravi,
Depends on how you want to create the internal table and the release you're on. Take a look at the CREATE DATA statement - you can, for example, create an internal table dynamically only knowing the type of the row. No knowledge of ABAP Objects required.
MJ
‎2006 Nov 20 12:15 PM
Hi Ravi ,
To create an internal table dynamically using OOPS concept use the class
<b>cl_alv_table_create</b>. Use the method <b>CREATE_DYNAMIC_TABLE</b>
Reagrds ,
Arun
Message was edited by:
Arun Ramachandran