Best Practices - Developing Processes

The purpose of this document is to provide best practices when developing processes.

Naming convention

When you add a process to a data class or to a representation class, Sage X3 displays the default code, which starts with the class code. It is recommended to use the default code and follow the same convention for any other process files. This makes it easier to find all processes for a particular data class or representation class.

Function and subroutine names

Make sure you use meaningful names for the subroutine and function names. Prefix them with the name of the child class they are related to.

Comments

Make sure you add comments (in English) to explain your code.

Variable definitions

Make sure you define all variables in your functions and subroutines as local. Do not define any global variable.

Error handling

Error handling must be carried out using the ASTATUS variable and the ASETERROR method.

Example:

[L]ASTATUS=Fmet ASETERROR("AMOUNT","the amount has been successfully updated", [V]CST_AINFO)
[L]ASTATUS=Fmet ASETERROR("MYPROP","The value of MYPROP is exceeding a usual value", [V]CST_AWARNING)
[L]ASTATUS=Fmet ASETERROR("","Global inconsistency for the class xxx", [V]CST_AERROR)
[L]ASTATUS=Fmet ASETERROR("","A fatal error occured", [V]CST_AFATAL)

Use constants

Use standard constants to make the code easier to read. Refer to the Constants Developer Guide.

Single Entry/Exit point for functions and subroutines

  • Make sure you have a single entry point and a single exit point for all functions and subroutines.
  • Try to avoid using "Goto" in your code.

Indent code

Make sure you indent your code to make it easier to read.