‎2007 Nov 20 4:48 AM
hi friends,
how we can use the dynamic internal tables and colors.plz help me as soon as possible.
‎2007 Nov 20 4:51 AM
Hi,
See this code for a dynamic table
data : lv_dbtab1 like dd02l-tabname.
lv_dbtab1 = 'MARA'.
data : dref type ref to data.
field-symbols: <itab> type any table, " used to store dynamic tables
<wa> type any, " used to store record data
<wa1> type any . " used to store field data
* LV_DETAIL contains values of a single field
* LV_DATA1 contains an entire record
* we do not know the sized of the table that must be generated beforehand
* hence we use field symbols to dynamically generate the internal table
create data dref type standard table of (lv_dbtab1)
with non-unique default key.
assign dref->* to <itab> .
* selects all data
select * from (lv_dbtab1) into table <itab> .
loop at <itab> assigning <wa>.
do.
assign component sy-index
of structure <wa> to <wa1>.
if sy-subrc <> 0.
exit.
endif.
if sy-subrc = 1.
write :/ .
endif.
move <wa1> to lv_detail.
concatenate lv_data1 lv_detail comma into lv_data1.
enddo.
* display
new-line.
write lv_data1.
endloop.
‎2007 Nov 20 4:51 AM
Hi,
See this code for a dynamic table
data : lv_dbtab1 like dd02l-tabname.
lv_dbtab1 = 'MARA'.
data : dref type ref to data.
field-symbols: <itab> type any table, " used to store dynamic tables
<wa> type any, " used to store record data
<wa1> type any . " used to store field data
* LV_DETAIL contains values of a single field
* LV_DATA1 contains an entire record
* we do not know the sized of the table that must be generated beforehand
* hence we use field symbols to dynamically generate the internal table
create data dref type standard table of (lv_dbtab1)
with non-unique default key.
assign dref->* to <itab> .
* selects all data
select * from (lv_dbtab1) into table <itab> .
loop at <itab> assigning <wa>.
do.
assign component sy-index
of structure <wa> to <wa1>.
if sy-subrc <> 0.
exit.
endif.
if sy-subrc = 1.
write :/ .
endif.
move <wa1> to lv_detail.
concatenate lv_data1 lv_detail comma into lv_data1.
enddo.
* display
new-line.
write lv_data1.
endloop.
‎2007 Nov 20 4:53 AM
Can you please specify what you want in colors - column headings, alv etc
‎2007 Nov 20 4:57 AM
hi
you will get clear idea on dynamic internal table if you go through the following thread
/people/subramanian.venkateswaran2/blog/2004/11/19/dynamic-internal-table
Reward Points if useful
regards,
Pavan
‎2007 Nov 20 5:02 AM
HI
Dynamic Internal Tables are tables created at RUN TIME Using Field Symbols.
It's useful in creating a program where you don't know name of table till run time. In other words it's very useful in creating Dynamic Programs.
we use Dynamic internal tables when we use ABAP oops
we create them by using Field symbols
There are a few declarations to make:
field-symbols: <table> type any.
types: fieldref type ref to data.
data: dyn_table type fieldref.
As for the actual code to generate the table:
create data dyn_table type (SAP Table).
assign dyn_table->* to table.
The table is now a field symbol which can be referenced in the normal way.
check out this prg
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.
-
or Just try out this simpler dynamic internal tables
DATA: itab TYPE STANDARD TABLE OF spfli,
wa LIKE LINE OF itab.
DATA: line(72) TYPE c,
list LIKE TABLE OF line(72).
START-OF-SELECTION.
*line = ' CITYFROM CITYTO '.
line = ' AIRPTO '.
APPEND line TO list.
SELECT DISTINCT (list)
INTO CORRESPONDING FIELDS OF TABLE itab
FROM spfli.
IF sy-subrc EQ 0.
LOOP AT itab INTO wa.
WRITE: / wa-cityfrom, wa-cityto.
WRITE 😕 wa-airpto.
ENDLOOP.
ENDIF.
for more info visit
http://www.sap-img.com/ab030.htm
<b>Reward if usefull</b>