Functionality This function module is used to instantiate templates. A program isgenerated from the template rows contained in the template. Thisprocess is carried out for any given meta-object, and is controlled bymeta-statements in the template. Meta-statements control, for example, whether a template row isreplaced conditionally, or several times (by various different values). To check and instantiate the template, it is dismantled in the meta-statements (rows that start with '*@') and in the template rows (allthe other rows). Valid ABAP/4-statements are permitted as meta-statements. The followingrestrictions apply: Only those statements that can be used in a FORM routine are permitted(for example, no PROGRAM-statements, no FORM-statements). The variables I_META_OBJECT and I_TEMPLATE are predefined, and must notbe declared a second time. The template rows can contain parameters. Parameters are enclosed inbackslashes, and can be valid actual parameters in a meta-program (forexample, \sy-datum\, \sy-repid+5(3)\). The function module RSS_TEMPLATE_INSTANTIATE is called to generate theprogram. The name of the template, the name of the program that isgoing to be generated, and the meta-object, are transferred to themodule. The meta-object is transferred untyped, and can be a simplename, or a complex data structure. You access the meta-object using theformal parameter I_META_OBJECT in the meta-program of the template. Themeta-object also controls the replacement of the template rows. NEW-PAGE Example The following example demonstrates how a primitive table display isgenerated from a template (stored as a program-include with the namename TMPLSE16): Template TMPLSE16> *@*-------------------------------------------------------------------* *@* data declaration *@*-------------------------------------------------------------------* *@ *@data: tabname like dfies-tabname, *@ x_init, *@ max_columns type i, *@ total_width type i, *@ ft like dfies occurs 0 with header line. *@ *@*-------------------------------------------------------------------* *@* prepare meta data for generation *@*-------------------------------------------------------------------* *@ *@tabname = i_meta_object. *@call function 'GET_FIELDTAB' *@ exporting *@ only = 'X' *@ tabname = tabname *@ withtext = ' ' *@ tables *@ fieldtab = ft *@ exceptions *@ internal_error = 1 *@ no_texts_found = 2 *@ table_has_no_fields = 3 *@ table_not_activ = 4 *@ others = 5. *@total_width = 1. *@loop at ft. *@ total_width = total_width + ft-outputlen + 1. *@ if total_width > 255. exit. endif. *@ max_columns = sy-tabix. *@endloop. *@ *@*-------------------------------------------------------------------* *@* instantiate model lines *@*-------------------------------------------------------------------* *@ report zz\tabname\ line-size \total_width\. *---------------------------------------------------------------------- * template....: \i_template\ * generated at: \sy-datum\ \sy-uzeit\ * generated by: \sy-uname\ *---------------------------------------------------------------------- tables \tabname\. *@loop at ft where keyflag = 'X'. select-options \ft-fieldname(8)\ for \tabname\-\ft-fieldname\. *@endloop. uline /(\total_width\). new-line. write sy-vline no-gap. *@loop at ft to max_columns. write (\ft-outputlen\) '\ft-fieldname\' color col_heading no-gap. write sy-vline no-gap. *@endloop. uline /(\total_width\). select * from \tabname\ *@clear x_init. *@loop at ft where keyflag = 'X'. *@ if x_init is initial. where \ft-fieldname\ in \ft-fieldname(8)\ *@ x_init = 'X'. *@ else. and \ft-fieldname\ in \ft-fieldname(8)\ *@ endif. *@endloop. . new-line. write sy-vline no-gap. *@loop at ft to max_columns. *@ if not ft-keyflag is initial. write \tabname\-\ft-fieldname\ color col_key no-gap. *@ else. write \tabname\-\ft-fieldname\ color col_normal no-gap. *@ endif. write sy-vline no-gap. *@endloop. endselect. uline /(\total_width\). NEW-PAGE The Generation Process> The function module RSS_TEMPLATE_INSTANTIATE is called. The followinginformation has to be transferred to the module: The name of the template.................: 'TMPLSE16', the name of the program you want to generate: 'ZZTRDIR', and the name of the table as a meta-object...: 'TRDIR'. call function 'RSS_TEMPLATE_INSTANTIATE' exporting i_template = 'TMPLSE16' i_program = 'ZZTRDIR' i_meta_object = 'TRDIR' exceptions template_not_found = 1 template_syntax_error = 2 internal_error = 3. NEW-PAGE The Generated Program> The template described above generates the program ZZTRDIR for themeta- object TRDIR: report zztrdir line-size 206. *---------------------------------------------------------------------- * template....: TMPLSE16 * generated at: 04.03.1997 14:17:00 * generated by: SAPUSER *---------------------------------------------------------------------- tables trdir. select-options name for trdir-name. uline /(206). new-line. write sy-vline no-gap. write (000040) 'NAME' color col_heading no-gap. write sy-vline no-gap. write (000001) 'SQLX' color col_heading no-gap. write sy-vline no-gap. ... write (000020) 'LDBNAME' color col_heading no-gap. write sy-vline no-gap. uline /(206). select * from trdir where name in name . new-line. write sy-vline no-gap. write trdir-name color col_key no-gap. write sy-vline no-gap. write trdir-sqlx color col_normal no-gap. write sy-vline no-gap. ... write trdir-ldbname color col_normal no-gap. write sy-vline no-gap. endselect. uline /(206). |