Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

dynamic source code generation

Former Member
0 Likes
499

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

3 REPLIES 3
Read only

former_member222860
Active Contributor
0 Likes
413

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

Read only

0 Likes
413

Thanks Mahesh but i have already seen this code on SDN. It wasn't helpful so i posted my query.

Thanks,

Ibrahim

Read only

0 Likes
413

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