2007 Apr 18 8:47 AM
there is quite a lot dynamic internal table blogs etc. but those instrcuctions does not help me to build up really dynamic internal table. Examples always point to some structure etc.
Case is: user gives date range in selection screen. Ex. 1.1.2007-20.1.2007.
Program should create internal table with fields for number of days in between those days.
So end result should be like this:
types: begin of lt_date_tab_dynamic_range,
date_1 type syst-datum,
date_2 type syst-datum,
date_nn type syst-datum,
end of lt_date_range.
How this could do via abap?
Thanks.
2007 Apr 18 9:17 AM
sorry Sudheer but your code not solve my problem..
"parameters: p_table(30) type c default 'T001' " this one makes it <b>not</b> dynamic...
It is not dynamic if you give some structure etc to create table.
Sathis, yes i know that if i use generate program (which is only for internal use) i could do this but then hole program have to generate (because i could not import table type back from generated program).
And yes i have read those alv blogs but there is no solution for this or im stupid (which could be of course also true).
t. Reko
sorry Sudheer but your code not solve my problem..
"parameters: p_table(30) type c default 'T001' " this one makes it <b>not</b> dynamic...
It is not dynamic if you give some structure etc to create table.
Sathis, yes i know that if i use generate program (which is only for internal use) i could do this but then hole program have to generate (because i could not import table type back from generated program).
And yes i have read those alv blogs but there is no solution for this or im stupid (which could be of course also true).
t. Reko
2007 Apr 18 8:54 AM
Hi
type-pools : abap.
field-symbols: <dyn_table> type standard table,
<dyn_wa>,
<dyn_field>.
data: dy_table type ref to data,
dy_line type ref to data,
xfc type lvc_s_fcat,
ifc type lvc_t_fcat.
selection-screen begin of block b1 with frame.
parameters: p_table(30) type c default 'T001'.
selection-screen end of block b1.
start-of-selection.
perform get_structure.
perform create_dynamic_itab. **********Creates a dyanamic internal table**********
perform get_data.
perform write_out.
form get_structure.
data : idetails type abap_compdescr_tab,
xdetails type abap_compdescr.
data : ref_table_des type ref to cl_abap_structdescr.
* Get the structure of the table.
ref_table_des ?=
cl_abap_typedescr=>describe_by_name( p_table ).
idetails[] = ref_table_des->components[].
loop at idetails into xdetails.
clear xfc.
xfc-fieldname = xdetails-name .
xfc-datatype = xdetails-type_kind.
xfc-inttype = xdetails-type_kind.
xfc-intlen = xdetails-length.
xfc-decimals = xdetails-decimals.
append xfc to ifc.
endloop.
endform.
form create_dynamic_itab.
* Create dynamic internal table and assign to FS
call method cl_alv_table_create=>create_dynamic_table
exporting
it_fieldcatalog = ifc
importing
ep_table = dy_table.
assign dy_table->* to <dyn_table>.
* Create dynamic work area and assign to FS
create data dy_line like line of <dyn_table>.
assign dy_line->* to <dyn_wa>.
endform.
form get_data.
* Select Data from table.
select * into table <dyn_table>
from (p_table).
endform.
Write out data from table.
loop at <dyn_table> into <dyn_wa>.
do.
assign component sy-index
of structure <dyn_wa> to <dyn_field>.
if sy-subrc <> 0.
exit.
endif.
if sy-index = 1.
write:/ <dyn_field>.
else.
write: <dyn_field>.
endif.
enddo.
endloop.
Regards
Sudheer
2007 Apr 18 8:57 AM
Check the link below. i know u must have already visited this , but this is a good ex where in a loop dyntable is created .
/people/alvaro.tejadagalindo/blog/2006/11/27/dynamic-alv-list-display
2007 Apr 18 9:02 AM
You can do it by generation of code like below:
form gen_cal_date.
ld_source = 'form calculate_date.'.
append ld_source to p_lt_lines.
ld_source = ' DATA: BEGIN OF ls_date Occurs 0,'.
append ld_source to p_lt_lines.
loop at <itab> into <wa_itab>.
ld_counter = ld_counter + 1.
concatenate <field>_ ld_counter' type sy-datum,' into ld_source.
append ld_source to p_lt_lines.
endloop.
ld_source = ' END OF ls_date.'.
append ld_source to p_lt_lines.
ld_source = 'endform.'.
append ld_source to p_lt_lines.
endform.
Hope the above helps. If you need clarifications, do let me know.
2007 Apr 18 9:10 AM
Hi,
Try this code.....................
types: begin of lt_date_tab_dynamic_range,
date_1 type syst-datum,
date_2 type syst-datum,
date_nn type i,
end of lt_date_tab_dynamic_range.
data : itab type table of lt_date_tab_dynamic_range,
wa type lt_date_tab_dynamic_range.
select-options : pa for sy-datum.
data: temp type i.
start-of-selection.
temp = pa-high - pa-low.
wa-date_1 = pa-high.
wa-date_2 = pa-low.
wa-date_nn = temp.
append wa to itab.
loop at itab into wa.
write : wa-date_1, wa-date_2, wa-date_nn.
endloop.
Regards
Purshoth
2007 Apr 18 9:17 AM
sorry Sudheer but your code not solve my problem..
"parameters: p_table(30) type c default 'T001' " this one makes it <b>not</b> dynamic...
It is not dynamic if you give some structure etc to create table.
Sathis, yes i know that if i use generate program (which is only for internal use) i could do this but then hole program have to generate (because i could not import table type back from generated program).
And yes i have read those alv blogs but there is no solution for this or im stupid (which could be of course also true).
t. Reko
2007 Apr 18 9:28 AM
Hi Reko,
I took the code from Rich Heilmans' blog.
Actually the table is created but i didn't populate it with data.
select-options : s_1 FOR SY-DATUM.
data : lv_i(3) type c,
xfc type lvc_s_fcat,
ifc type lvc_t_fcat.
data : lv_datum(2).
data: dy_table type ref to data.
lv_i = s_1-high - s_1-low.
do lv_i times.
lv_datum = lv_datum + 1 .
perform create_fieldcat using lv_datum.
enddo.
call method cl_alv_table_create=>create_dynamic_table
exporting
it_fieldcatalog = ifc
importing
ep_table = dy_table.
*&---------------------------------------------------------------------*
*& Form create_fieldcat
*&---------------------------------------------------------------------*
form create_fieldcat using pindex.
data : lv_day(7) .
concatenate 'DATE_' pindex into lv_day.
xfc-fieldname = lv_day.
xfc-datatype = 'DATS'.
xfc-OUTPUTLEN = '10'.
append xfc to ifc.
endform. " create_fieldcat
Hope this helps
Regards.
2007 Apr 18 9:40 AM
2007 Apr 18 10:11 AM
and to put data into table:
field-symbols: <lt_destination> type standard table.
field-symbols: <fs> type any,
<ls_wa_to>,
<fs_field> type any.
data: ls_destination type ref to data.
data: lv_field type bdcdata-fnam.
assign dy_table->* to <lt_destination>.
create data ls_destination like line of <lt_destination>.
assign ls_destination->* to <ls_wa_to>.
clear lv_datum.
do lv_i times.
lv_datum = lv_datum + 1 .
concatenate '<ls_wa_to>-' 'DATE_' lv_datum into lv_field.
assign (lv_field) to <fs_field>.
some data -->
<fs_field> = sy-datum.
append <ls_wa_to> to <lt_destination>.
free <ls_wa_to>.
enddo.
| User | Count |
|---|---|
| 3 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |