Show TOC

include StatementLocate this document in the navigation structure

Use

Purpose

Includes code from other HTML templates in the current HTML template.

Syntax

include([[~service=]expression,] [[~theme=]expression,] [[~language=]expression,] [~name=]expression)

Parameters

Parameter

Meaning

~service

Service name.

If omitted, the current service is used.

~theme

Theme.

If omitted, the current theme (defined in the .srvc file) is used. To omit the theme part of the URL path, specify ~theme="".

~language

Language.

If omitted, no language is used. If you want to use the current language, specify ~language=~language. This behavior contrasts with the ~language parameter of the mimeURL statement.

~name

File name.

The file to be included is taken from a path constructed as follows:

<itsRootDir>\<virtual ITS>\templates\<~service>\<~theme>\ <filename(~name)>[_<~language>].<extension(~name)>|html)

Description

The include statement allows you to include code from other HTML templates in the current HTML template.

Advantages

The include statement has the following advantages:

  • Consistency of style for Internet applications.

    Many Internet applications use a shared set of style elements such as title bars or copyright footers. You can store these elements in a single file and include it in all the relevant HTML templates. This approach allows for centralized updating.

  • Reuse of common code

    You can reuse Java or Visual Basic scripts in multiple templates. This is useful for implementing commonly used routines such as validity checking of user input.

  • Reuse of function declarations

    Included files can also contain function interface declarations. This is especially useful for external function libraries, because you can declare all library functions in one file, and include the file in each template that uses the library.

Named Parameters or Positional Parameters

You can use either named parameters or positional parameters.

If you use positional parameters (for example, omit ~language= before you specify the language value), the following order is assumed:

  • ~name is the first unnamed parameter from the right

  • ~service is the first unnamed parameter from the left

  • ~theme is the second unnamed parameter from the left

  • ~language is the third unnamed parameter from the left

    Example

    To include code from the same location as the including template:

    `include ("purchasing_titlebar")`

    To include code from the global template directory (using the same theme):

    `include ("global", "purchasing_titlebar")`

    To include code used for external function declarations:

    `include ("system", "", "sapxjstring.html")`

Compile Time Evaluation and Runtime Evaluation

The Internet Transaction Server (ITS) resolves include statements at compile time or at runtime.

If the parameters evaluate to constants, or are implicitly defined by the current context, the ITS can resolve them at compile time. Since there are performance advantages to compile time evaluation, you should prefer this option whenever possible.

  • Examples of include statements resolved at compile time are:

    • `include ("purchasing_titlebar.html")`

      Here, the service, theme and language are defined by the including template itself.

    • `include ("purchasing"&"_titlebar"&".html")`

      Here, the service, theme and language are implicitly defined, and the expression "purchasing"&"_titlebar"&".html" evaluates to a constant.

    • `include ("system", "", "sapxjstring.html")`

      Here, all parameters get constant values explicitly assigned.

  • Examples of include statements that can only be resolved at runtime are:

    • `include ("purchasing" & screen_element & ".html")`

      Here, screen_element is a non-constant that can only be defined at runtime.

    • `include (~service=~service, "purchasing_titlebar.html")`

      When evaluating expressions, the HTMLBusiness interpreter does not differentiate between variables defined at compile time and variables defined at runtime. For this reason, ~service is not considered a constant expression. However, if you omit the ~service parameter completely, it is handled as a constant and implicitly defined.

Including Language Resources With Included Templates

If you include a template from a different service in your current service, any language resources associated with the included template are also taken into account.

  • If an included template references a language resource file called <resource file>_<language>.htrc, the HTMLBusiness interpreter attempts to resolve the name from within the included template.

  • If an included template references a language resource file called <resource file>_<language>.htrc, and the name cannot be resolved from within the included template, the HTMLBusiness interpreter must attempt to resolve the name from within the including template.

Example

Suppose the template templateA_html of service A includes the template templateB_html of service B:

If the template templateB_html of service B references a language resource file called resource1_en.htrc, the HTMLBusiness interpreter should resolve the name from within the template templateB.html of service B.

If the name of the language resource file cannot be resolved from within the included template templateB.html, it must be resolved from within the including templateA.html of service A.

A compile time include example could be written as:

`include(~service="paw1",~theme="99", ~name="sapmpw01_100")`
         

Suppose templateA.html of service A includes templateB.html of service B and templateC.html of service C.

templateA.html contains the following HTMLBusiness code:

`write (#resource1)`
`include(~service="ServiceB", ~theme="99", ~name= "B" )`
`include (~service="ServiceC", ~theme="99",~name="C")`
         

templateB.html contains the following HTMLBusiness code:

`write (#resource1)`
`write (#resource2)`

         

templateC.html contains the following HTMLBusiness code:

`write (#resource1)`
`write (#resource2)`
         

The contents of the respective language resource files are as follows:

Resource File

Variable

Value

templateA_en.htrc

#resource1

A1

#resource2

A2

templateB_en.htrc

#resource1

B1

templateC_en.htrc

#resource1

C1

If the logon language is English ( en), and you execute templateA.html, you get the following output :

A1

B1

A2

C1

A2

A runtime include example could be written as:

mytheme=99`
`include(~service="paw1",~theme=mytheme,~name="sapmpw01_100")`
         

Suppose templateA.html of service A includes templateB.html of service B, and templateB.html of service B includes templateC.html of service C.

templateA.html contains the following HTMLBusiness code:

`write (#resource1)`
`mytheme=99`
`include (~service="ServiceB", ~theme=mytheme,~name="B" )`
         

templateB.html contains the following HTMLBusiness code:

`mytheme=99`
`include (~service="ServiceC", ~theme=mytheme, ~name="C")`
`write (#resource1)`
`write (#resource2)`
         

templateC.html contains the following HTMLBusiness code:

`write (#resource1)`
`write (#resource2)`
         

The contents of the respective language resource files are again as follows:

Resource File

Variable

Value

templateA_en.htrc

#resource1

A1

#resource2

A2

templateB_en.htrc

#resource1

B1

templateC_en.htrc

#resource1

C1

If the logon language is English ( en), and you execute templateA.html, you get the following output:

A1

C1

A2

B1

A2

Restrictions

  • You cannot use the include statement in a language resource file.

  • The file name you include must have the extension .html.