Using database field validations in your LANSA functions

Date:Archived
Product/Release:LANSA - All Platforms
Abstract:Existing database field validations can be used in a LANSA function without having to add lots of checks to individual functions.
Submitted By:LANSA Technical Support

In many batch and/or print functions, a selection screen is displayed where certain details can be selected.

Function A, for example, is used to print a list of all the orders for a given customer and a given period. The user can choose a customer and a start and end date. The function checks that the customer number exists and that the date fields are valid dates.

Function B is used to print a list of all invoices for a selected customer for a given period. This function performs the same validations as function A.

These validations can be centralised in the data dictionary instead of being executed in each function by defining a dummy file in LANSA. This file can contain all the possible selection fields and their validations defined with the option ADDUSE (LANSA will only perform the validation when the field is included in the GROUP_BY).

Example of a validation:

Example of Validation

All validations in the function can now be replaced by ONE command:

INSERT(selection fields) TO_FILE(selection file) CHECK_ONLY(*YES)

Example RDML of a function:

* Define screen 
GROUP_BY NAME(#GB_SEL) FIELDS((#SELNUM) (#SELDATF)(#SELDATT))
FUNCTION OPTIONS(*DIRECT *NOMESSAGES)
BEGIN_LOOP
* Initialise screen fields
CHANGE FIELD(#GB_SEL) TO(*DEFAULT)

* Request selection details
REQUEST FIELDS((#GB_SEL))

* Validate selection fields
INSERT FIELDS((#GB_SEL)) TO_FILE(ASPSEL) 
CHECK_ONLY(*YES)

* Call print function
SUBMIT PROCESS(ASPTEST) FUNCTION(ASPT002) 
EXCHANGE(#GB_SEL) JOB(PRTSKIL) OUTQ(*USRPRF)
END_LOOP

If there are too many selection fields, it is possible to define a dummy file per application.