Formulas used must be written in AdvPL syntax for the system to interpret them.
Procedures
Creating formulas:
Indication of a field from another file
SE1->E1_Valor = value of currency 1 from SE1 - Bills Receivable File.
Operation between fields or fixed parts (alphanumeric)
Used to set data by gathering information that is in different fields or with a part considered fixed. Its complement is referenced by the name of a field.
LEDGER ACCOUNT = SA1->A1_CONTA + SE1-> E1_NATUREZ
HISTORY = “Concerning a trade note payment” + SE1->E1_NUM
Mathematical operations with or without condition are used to obtain a value represented in several fields, as well as some information whose mathematical formulas must be applied to a certain field.
SALES PRICE =
IIF(DAY(Dbase)=15,B1_PRV2*0,10,B1_PRV1)
TOTAL OF COMMISSION PAID TO A BILL =
(SE1->E1_COMIS1+SE1->E1_COMIS2+SE1->E1_COMIS3+ SE1->E1_COMIS4 + SE1->COMIS5)
Operation with UserFunction and system fields.
Practical Application
Use of the field Term Formula of product register to create a UserFunction.
1. Create a userfunction to calculate the delivery term. Example:
UserFunction FORMPRZ()
Return
2. In Formula Register, a userfunction must be associated with a formula to calculate the delivery term:
Code | 001 |
Description | Delivery Term Formula |
Formula | EXECBLOCK("FORMPRZ",.F.,.F.) |
At this moment, the userfunction is run for test (validation). If there is any inconsistency, the formula cannot be saved.
3. After registering the formula, the userfunction must be changed to define how the delivery term is calculated. Example:
UserFunction FORMPRZ()
// The minimum delivery term for every 100 units is the period entered in
// Delivery field
Return Max((QUANTITY/100)*SB1->B1_PE,SB1->B1_PE)
4. In the Delivery Term field, enter the code of the formula registered, in this case 001.
5. The QUANTITY variable used in the example of UserFunction FORMPRZ() is in the execution of the function created and associated with the term formula.