‎2005 Mar 11 8:01 PM
Hello All,
The task was to create a internal table with dynamic columns,
Actually this is my first task in the WebAS 6.20, my program is based on input file provided by user with certain effort. this file can have different effort for a one yr to five year frame..
I needed to read the raw data from file, based on months create a internal table to hold the data, after this i need to validate the data...
I have browsed thru dynamic internal table topic, but couldn't find any dynamic appending structure, the dynamic structure would contains 12 month fileds.
can any one help me in getting my task completed..
Thanks
Kumar
‎2005 Mar 11 8:24 PM
Here is a sample program that demonstates dynamic internal tables. This will not solve your problem, but maybe give you some ideas. Good Luck
report zrich_0001
no standard page heading.
* Field symbols
field-symbols:
<dyn_table> type standard table,
<dyn_wa>.
* Selection Screen
selection-screen begin of block b1 with frame title text-001.
parameters: p_numcol type c.
selection-screen end of block b1.
perform build_dyn_itab.
perform build_report.
************************************************************************
* Build_dyn_itab - Build dynamic internal table definition
************************************************************************
form build_dyn_itab.
data: new_table type ref to data,
new_line type ref to data,
wa_it_fldcatg type lvc_s_fcat,
it_fldcatg type lvc_t_fcat.
* Build dynamic internal table field catalog
* Create fields for all dates in iDates.
do p_numcol times.
clear wa_it_fldcatg.
wa_it_fldcatg-fieldname = sy-index.
wa_it_fldcatg-datatype = 'CHAR'.
wa_it_fldcatg-intlen = 5.
append wa_it_fldcatg to it_fldcatg .
enddo.
* Create dynamic internal table and assign to FS
call method cl_alv_table_create=>create_dynamic_table
exporting
it_fieldcatalog = it_fldcatg
importing
ep_table = new_table.
* assign ref variable to a field symbol
assign new_table->* to <dyn_table>.
* Create dynamic work area and assign to FS
create data new_line like line of <dyn_table>.
assign new_line->* to <dyn_wa>.
endform.
*********************************************************************
* Form build_report - Fill dynamic internal table with data
*********************************************************************
form build_report.
data: xstring type string.
data: xint(10) type c.
* Fill the dynamic internal table
do 10 times.
clear xstring.
do p_numcol times.
xint = sy-index.
shift xint right deleting trailing space.
* now add to the front of the string.
concatenate xstring xint into xstring.
enddo.
* Now move the string into dynamic internal table work area.
<dyn_wa> = xstring.
* Append to the dynamic internal table
append <dyn_wa> to <dyn_table>.
enddo.
endform.
Regards,
Rich Heilman
‎2005 Mar 11 9:09 PM
Hi Rich,
Thanks for a quick response,
I looked into the example .. my task is to create dynamic header data so that i can populate data accordingly..
to be more clear if file has 2 month data my internal table shud have 2 fields to capture that data.. similarly if my file has 4month data than my internal table shud include 2 more month fileds to hold all 4 months data..
Hope I did not confuse .But truly appreciate your quick response..
Thanks
Kumar
‎2005 Mar 11 11:59 PM
If the only dynamic part of your data is the number of months of data, then you can define your internal table as a "deep" table, i.e. each row of your table would itself have an internal table as a component. Here is some sample code:
REPORT zcdf_dynamic_table.
* ------------------------------------------------------
* Internal table with dynamic number of months.
* Tested in 4.7/6.20
* Charles Folwell - cfolwell@csc.com - March 11, 2005
* ------------------------------------------------------
* Type definitions for building internal table. I would
* usually put these definitions in the dictionary but
* for easy posting, I have included them here.
TYPES:
BEGIN OF tys_month,
amt(12) TYPE p DECIMALS 2,
END OF tys_month.
TYPES:
tyt_month TYPE STANDARD TABLE OF tys_month WITH DEFAULT KEY.
TYPES:
BEGIN OF tys_my_data,
fixed_data(20) TYPE c,
number_months TYPE i,
t_month TYPE tyt_month,
END OF tys_my_data.
* Internal table with variable number of months.
DATA:
t_my_table TYPE STANDARD TABLE OF tys_my_data WITH DEFAULT KEY.
* Work areas for internal table and for the internal table
* inside the internal table.
DATA:
wa_my_table LIKE LINE OF t_my_table,
wa_month TYPE tys_month.
START-OF-SELECTION.
* Populate internal table from somewhere, similar to this.
* If you know where the months start, and their size, then
* a field symbol can be used to move thru the data.
CLEAR wa_my_table.
wa_my_table-fixed_data = 'Key Data1'.
wa_my_table-number_months = 3.
DO wa_my_table-number_months TIMES.
CLEAR wa_month.
wa_month-amt = sy-index.
APPEND wa_month TO wa_my_table-t_month.
ENDDO.
APPEND wa_my_table TO t_my_table.
* Read back and write your table data similar to this.
LOOP AT t_my_table INTO wa_my_table.
WRITE:/ wa_my_table-fixed_data, wa_my_table-number_months.
LOOP AT wa_my_table-t_month INTO wa_month.
WRITE:/ wa_month-amt.
ENDLOOP.
ENDLOOP.
‎2005 Mar 14 6:11 AM
This is similar to Rich Heilman's effort:
<a href="/people/subramanian.venkateswaran2/blog/2004/11/19/dynamic-internal-table Internal Table</a>
Regards,
Subramanian V.