This example shows the use of built-in functions.
Assume that you want to calculate a mathematical function that is the sine of the Fldm field in FILEA. First create a file (assume it is called FILEAA) with a record format containing the following fields:
|
OVRDBF FILE(FILEAA) TOFILE(FILEA) SHARE(*YES) OPNQRYF FILE(FILEA) FORMAT(FILEAA) + MAPFLD((SINM '%SIN(FLDM)')) CALL PGM(PGMF) /* Created using file FILEAA as input */ CLOF OPNID(FILEA) DLTOVR FILE(FILEAA)
The built-in function %SIN calculates the sine of the field specified as its argument. Because the Sinm field is defined in the format specified on the FORMAT parameter, the Open Query File (OPNQRYF) command converts its internal definition of the sine value (in floating point) to the definition of the Sinm field. This technique can be used to avoid certain high-level language restrictions regarding the use of floating-point fields. For example, if you defined the Sinm field as a packed decimal field, PGMF can be written using any high-level language, even though the value was built using a floating-point field.
There are many other functions besides sine that can be used. See the OPNQRYF command in the Control language (CL) topic for a complete list of built-in functions.