‎2009 Mar 25 7:56 AM
Hi guys,
I would like to declare TYPES with five fields dynamically in my program and then use the same type in program later on. For that i have written the following code.
it_code-line = 'TYPES : BEGIN OF TY_TABLE,'.
APPEND it_code. CLEAR it_code.
CONCATENATE f1 'TYPE' f1 ',' INTO it_code separated by space.
APPEND it_code. CLEAR it_code.
CONCATENATE f2 'TYPE' f2 ',' INTO it_code separated by space.
APPEND it_code. CLEAR it_code.
CONCATENATE f3 'TYPE' f3 ',' INTO it_code separated by space.
APPEND it_code. CLEAR it_code.
CONCATENATE f4 'TYPE' f4 ',' INTO it_code separated by space.
APPEND it_code. CLEAR it_code.
CONCATENATE f5 'TYPE' f5 ',' INTO it_code separated by space.
APPEND it_code. CLEAR it_code.
it_code-line = 'END OF TY_TABLE.'.
APPEND it_code. CLEAR it_code.
INSERT REPORT 'ZIBM_DYN_INCLUDE' FROM it_code.
But i am getting syntax error ' Type TY_TABLE is unknown'. How to rectify this error.
Your help will be deeply appreciated.
Thanks,
Ibrahim
‎2009 Mar 25 8:27 AM
Here's the sample program for Dynamic source code generation.
data: begin of itab occurs 0,
line(150),
end of itab.
data: v_name like sy-repid.
parameters: p_table like dd02l-tabname.
itab-line = 'Report sy-repid.'.
append itab. clear itab.
itab-line = 'tables:'.
append itab. clear itab.
concatenate p_table '.' into itab.
itab-line = 'data: begin of itab occurs 0.'.
append itab. clear itab.
concatenate 'include structure' p_table '.' into itab separated by space.
itab-line = 'data:end of itab.'.
append itab. clear itab.
itab-line = 'form f_select.'.
append itab. clear itab.
itab-line = 'select * into table itab'.
append itab. clear itab.
concatenate 'FROM' p_table '.' INTO itab separated by space.
itab-line = 'endform.'.
append itab. clear itab.
generate subroutine pool itab name v_name.
perform f_select in program (v_name).Mahesh
‎2009 Mar 25 8:35 AM
Thanks Mahesh but i have already seen this code on SDN. It wasn't helpful so i posted my query.
Thanks,
Ibrahim
‎2009 Mar 25 8:50 AM
why don't you use form fields for dynamic table generation ??
in https://www.sdn.sap.com/irj/scn/wiki?path=/display/abap/individualcellcoloringindynamic+alv
I have made an example where you add the fields to the fieldcat. you generate the dynamic table and line.
in this report I create fields (employeenumbers) depending on the selection on the selection screen.
so if someone selects company A on the selection screen the programm creates a table with all the employees from company a where the employeenumber is the fieldname.
further on you can also declare static fields as well to this structure.
so perhaps I misunderstood you're requirement but dynamic generation is normally done with form fields
you can also search for the method that creates the 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