‎2008 Jun 03 1:14 PM
Hi,I need to create an internal table depending on no.of records I found in a standard table.In my dynamic internal table I have first 4 columns fixed and next columns should be genreted dynamically at run time.I searched the forum,every example I found was with using classes,as I dont have any Idea of classes I couldnot understand those programs.PLZ If anyone can provide an example exactly on my requirement without any classes used or with CLEAR explanation.Thanks in advance.
Points will be rewarded for every helpful answer.
‎2008 Jun 03 1:17 PM
Hi
You can use:
1) Class Method:
CALL METHOD cl_alv_table_create=>create_dynamic_table
2) Look at CLASS CL_ABAP_TABLEDESCR (If you have SAP version higher then 4.7 ) in this class you can crate internal table dynamically.
Best Regards.
‎2008 Jun 03 1:23 PM
Hi,thanks for u r feedback,but as I said I dont have any Idea of using classes,I need an example without classes and give me example similar to my requirement like this :
Fixed1 Fixed2 Fixed3 Fixed4 Dynamic1 Dynamic2..........
‎2008 Jun 03 1:27 PM
use Function Module:
call function 'LVC_TABLE_CREATE'.
fill it_fieldcatalog like for usual ALV report. and all.
‎2008 Jun 03 1:25 PM
Try this example: This is the smallest program to create dynamic internal table. You have no way to escape from learning Class concepts.
DATA: struct_type TYPE REF TO cl_abap_structdescr,
comp_tab TYPE cl_abap_structdescr=>component_table,
comp LIKE LINE OF comp_tab,
dref TYPE REF TO data.
FIELD-SYMBOLS: <struc> TYPE ANY,
<comp> TYPE ANY.
comp-name = 'column1'.
comp-type = cl_abap_elemdescr=>get_c( 40 ).
APPEND comp TO comp_tab.
comp-name = 'column2'.
comp-type = cl_abap_elemdescr=>get_i( ).
APPEND comp TO comp_tab.
struct_type = cl_abap_structdescr=>create( comp_tab ).
CREATE DATA dref TYPE HANDLE struct_type.
ASSIGN dref->* TO <struc>.
ASSIGN COMPONENT 'COLUMN1' OF STRUCTURE <struc> TO <comp>.
<comp> = 'Amount'.
ASSIGN dref->* TO <struc>.
ASSIGN COMPONENT 'COLUMN2' OF STRUCTURE <struc> TO <comp>.
<comp> = 11.
‎2008 Jun 03 1:32 PM
On what basis the example program is creating Dynamic IT? or if u can create one program as my requirement is,I will change it as I want.Thanks.
‎2008 Jun 04 9:06 AM
I have just made a program like you're requirements
DATA: ta_output TYPE REF TO data.
DATA: new_table TYPE REF TO data,
new_line TYPE REF TO data,
is_lvc_cat TYPE lvc_s_fcat,
it_lvc_cat TYPE lvc_t_fcat.
FIELD-SYMBOLS: <ta_output> TYPE table,
<ta_color> TYPE table,
<l_line> TYPE ANY,
<l_field> TYPE ANY,
<fs> TYPE ty_pernrs.
.
SELECT pernr ename FROM pa0001
INTO CORRESPONDING FIELDS OF TABLE ta_pernrs
WHERE pernr IN so_pernr
AND werks IN so_werks
AND begda <= '99991231'
AND endda > h_begin.
*build fields for dynamic table
* static fields
is_lvc_cat-fieldname = 'VALIDITYDATE'.
is_lvc_cat-ref_field = 'VALIDITYDATE'.
is_lvc_cat-ref_table = 'BAPI7013_1'.
is_lvc_cat-scrtext_s = is_lvc_cat-scrtext_m =
is_lvc_cat-scrtext_l = 'Datum'.
APPEND is_lvc_cat TO it_lvc_cat.
is_lvc_cat-fieldname = 'DAY_STRING'.
is_lvc_cat-ref_field = 'DAY_STRING'.
is_lvc_cat-ref_table = 'CASDAYATTR'.
is_lvc_cat-scrtext_s = is_lvc_cat-scrtext_m =
is_lvc_cat-scrtext_l = 'Datum'.
APPEND is_lvc_cat TO it_lvc_cat.
* dynamic fields
LOOP AT ta_pernrs INTO wa_pernrs.
FREE it_0002.
WRITE wa_pernrs-pernr TO h_ri_pernr.
is_lvc_cat-fieldname = wa_pernrs-pernr.
is_lvc_cat-ref_field = 'massn'.
is_lvc_cat-ref_table = 'PERNR'.
is_lvc_cat-just = 'C'.
is_lvc_cat-scrtext_s = is_lvc_cat-scrtext_m = is_lvc_cat-scrtext_l = wa_persnrs-pernr.
APPEND is_lvc_cat TO it_lvc_cat.
endloop.
* create table
* Create a new Table
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = it_lvc_cat
IMPORTING
ep_table = ta_output.
* Create a new Line with the same structure of the table.
ASSIGN ta_output->* TO <ta_output>.
CREATE DATA new_line LIKE LINE OF <ta_output>.
ASSIGN new_line->* TO <l_line>.
kind regards
arthur
Edited by: A. de Smidt on Jun 4, 2008 10:08 AM
Edited by: A. de Smidt on Jun 4, 2008 10:09 AM