Show TOC

Syntax documentation*SUB( ) / *ENDSUB Locate this document in the navigation structure

A SUB structure allows the user to define reusable logic sections anywhere in the body of the logic to make the logic easier to read and maintain.

A *SUB( ) structure is declared like a multi-line *FUNCTION( ) structure, with the following syntax:

*SUB {SubName}({Param1,[,{Param2}…])

{body text}

{body text}

{body text}

[…]

*ENDSUB

When a SUB is then used somewhere else in the logic, its body lines are inserted in the logic with all the values passed to its parameters appropriately replaced.

A SUB behaves similarly to included files, to which any number of parameters can be passed. When the logic is validated, the subs are inserted in the body of the logic as if they were included with an *INCLUDE instruction. However, to use a SUB structure, no special keyword is required. A SUB is called by inserting a line with the name of the SUB, followed by the values assigned to its parameter enclosed in brackets. The other important difference from included files is that a SUB does not need to be written in a file of its own, but can be written in any part of the logic, more similarly to a FUNCTION.

Example Example

Here the sub is defined:

*SUB MYSUB(Param1,Param2,Param3,Param4)

[%ACCOUNT_DIM%].[#Param1]=[%ACCOUNT_DIM%].[Param2]+[%ACCOUNT_DIM%].[Param3]

[%ACCOUNT_DIM%].[#Param4]=[%ACCOUNT_DIM%].[#Param1]*[%ACCOUNT_DIM%].[Factor_Param4]

*ENDSUB

Here the sub is used:

MySub(A1,B1,C1,D1)

MySub(A2,B2,C2,D2)

MySub(A3,B3,C3,D3)

End of the example.

Similarly to a FUNCTION, a SUB is not position sensitive, and can be defined anywhere in a logic, as well as, if so desired, stored in separate library files that must then be merged with the logic using an INCLUDE instruction.

A SUB can be used in any commit section of the logic without the need to be redefined in each section. However, if a SUB is redefined in a logic file, its new definition applies to all lines following the redefinition.

A SUB without parameters is supported, but they must always be followed by brackets.

Any software coding and/or code lines / strings ("Code") included in this documentation are only examples and are not intended to be used in a productive system environment. The Code is only intended to better explain and visualize the syntax and phrasing rules of certain coding. SAP does not warrant the correctness and completeness of the Code given herein, and SAP shall not be liable for errors or damages caused by the usage of the Code, except if such damages were caused by SAP intentionally or by its gross negligence.