Previous Topic: General PrinciplesNext Topic: Field Names in CL Programs


Coding Standards for CL Programs

All programs should follow the standard layout. For example:

Indent the program source to follow the logical structure of structured program constructs, such as IF, ELSE, and DO. For example:

All programs should use ‘H*:‘ source directives to document the main processing stages. These will then automatically appear in the summary documentation and provide a program synopsis.

For more information on documentation and the CA 2E Toolkit utilities Document Program (YDOCPGM) command, refer to the Toolkit Concepts Guide.

Declare entry parameters before all other parameters, and in the order that they appear in the PGM statement. Include a text description of the variable against each DCL statement. Where a field is a data structure, show declarations of sub-fields, indented, below that of the major field. If the parameter is an aggregate data structure, for instance a list parameter passed by a command, document the structure as part of the comment:

Place general error handling at the end of the program. The standard error handling should trap and resend any exception message.

This can be done as follows:

V2R2 of OS/400 has new message APIs that allow you to handle messages more efficiently. You should use them once they are available. The following code carries out the same standard exception handling as shown above.