F4076CalculateAlgebraicExpresn

F4076 Calculate Algebraic Expression

Minor Business Rule

Object Name: B4500130

Parent DLL: CDIST

Location: Client/Server

Language: C




Functional Description


Purpose


This business function calculates the algebraic expression in an alphanumeric string and returns a 

mathnumeric value, otherwise return error message ID.


Setup Notes and Prerequisites


The Input  string format:

• May or may not contain parentheses to establish precedence.
• May or may not contain blank(s)
• May interpret to a character string value or to numeric value. 
• All arithmetic function characters must be in upper case, 
The input string is a 160-upper-case-character string.
• May or may not contain variables

Here are some examples of valid input text strings:

((2+3)-4))*(5/6)  ;   &VAR1*5  ;  ((1.4 * 10)-1500) %EA

((2500 * 1.15)-(?SDUORG*10))  !USD  ; (((99 * 88) + 77) %TN) + 15000

10*5/2500  ;  ?SDAEXP*?SDUORG/&VAR2

Is very important to consider that exist 4 different types of variables, these variables are always 

defined with a special character in the first position of the variable. The special characters are into 

the file F4009 and these can  be changed, alphabetic, numeric, and mathematical function (for 

example, A,1,(,+,-,*,/) values are not valid in this field. The second character of the variable must be in 

the range A to Z or 0-9.


When you are using variables type Unit of Measure and Currency Code, always you must put a specific 

mathematical operator, example:


• Unit of Measure  %EA = " /  1.1111", the Division sign must precede each variable of Unit of  
Measure defined , if you enter this expression  "+ %EA" , the result will be wrong because the 

interpretation will be " + / 1.1111".

• Currency Code  !USD = " *  1.1111", the Multiplication sign must precede each variable of Currency 
Code defined , if you enter this expression  "+ !USD" , the result will be wrong because the 

interpretation will be " + * 1.1111".



Special Logic


A.Operators:


The following operators are prioritized as:

1)')'Right parentheses
2)'/'Division

3)'*'Multiplication

4)'-'Minus

5)'+'Addition

6)'('Left parentheses


Technical Specification



Related Tables 


Table Table Description

F4075Price Variable Table


Related Business Functions


Source NameFunction Name


X0005GetUDC

B0000033GetExchRate

B1100001IsColInCurrencyCodeTable

B0000500AlgebraicExpressionCalculate

B400520GetItemUoMConversionFactor

B0000500AlgebraicExpressionCalculate




Processing 


Retrieve CPCP02, CPCP03, CPCP04, and CPCP05 from F4009.


List A


CPCP02Symbol to identify Variable table

CPCP03Symbol to identify Unit of Measure

CPCP04Symbol to identify Currency

CPCP05Symbol to identify Database Fields


List B


CPCP02Symbol to identify Variable table

CPCP03Symbol to identify Unit of Measure

CPCP04Symbol to identify Currency

CPCP05Symbol to identify Database Fields

')'Right parentheses

'/'Division

'*'Multiplication

'-'Minus

'+'Addition

'('Left parentheses

' 'Blank character


Compare each character in the string one at a time against the four symbols retrieved from F4009 

(List A).


If you encounter any character between A-Z and a-z or any special characters that is not proceeded by 

one of the four symbols, then issue the error code.


There should not be any character or string other than function names that defined in section 1.2.


If there is any invalid character or string, skip all steps below and return Error Code.

Take the first character of the input string and validate
Detach the special character of the variable and take rest of the variable until find character blank 

or mathematical function, defined section 1.3 



If DS CP02 was found into the string

If the variable = blanks

return Error Code, assign DS Error ID '3958'
else

If variable is greater that ten characters
return Error Code, assign DS Error ID '3958'
else
Retrieve record from the file F4075 with the fields DS DTEJ and Variable Name
If unsuccessful fetch

return Error Code, assign DS Error ID '3958'
else
If  DS Mode Call = 1
change the variable string for value "1"
else
Use field UOM from F4075 for calculate conversion factor if UOMs are different
If DS UOM is not equal to F4075-UOM

Retrieve UOM conversion factor with the Business Function B40000520 
DS MCU->MCU

F4075-UOM->UOM

DS UOM->UOM

"1"->QTY

DS IVI->IVI

DS ITM->ITM

DS TFLA->TFLA

Work Field<-CONV

F4075-UPRC= F4075-UPRC / Work Filed (Conversion Factor) 

Endif
Use field CRCD from F4075 for calculate conversion factor if CRCDs are different

If F4075-CRCD is not equal to DS CRCD

Retrieve the exchange rate using Business Function B0000033
F4075-CRCD->CRCD

DS CRCD->CRDC

DS AN8->AN8

DS DTEJ->EFT

Work field<-CRR

F4075-UPRC=F4075-UPRC * Work Field (Currency conversion factor )

Endif
Change the variable string for the field F4075-UPRC into the formula

Endif
Endif
Endif
Endif

else

If DS CP03 was found

If variable is greater that two characters
return Error Code, assign DS Error ID '4335'
else
Verify if the variable exist into the file F0005 with the Business Function X0005
"UOM"->DTAI
"00"->SY

"UM"->RT

Variable name ->KY

"2"->AS

If  Error message ID DTAI in not blank
return Error Code, assign DS Error ID '4335'
else
 If  Mode Call = 1
edit this filed, the Division sign must precede this value, example: "/ 1"
else
If variable is not equal to DS UOM
Retrieve record from the file F4211 with the fields DS DOCO ,DCTO ,LNID  ,SFXO  , MCU
Keep the fields SDITM,SDMCU to be used in the business function B400520

Retrieve record from the file F4101 with the key SDITM and keep the field IMTFLA to be 

used in the business function B400520

Retrieve record from the file F40205 with the key DS LNID and keep the field LFIVI to 

be used in the business function B400520

Retrieve UOM conversion factor with the Business Function B400520 

SDMCU->MCU

DS UOM->UOM

Variable Name->UOM

"1"->QTY

LFIVI->IVI

SDITM->ITM

IMTFLA->TFLA

Work Field<-CONV

change the variable string for the value of the work field returned

edit this field,  the Division sign must precede the numeric value, example:

If the return value was 99.9999 you must put this character "/"before the field , and 

the result is  "/ 99.9999".

else
change the variable string for value "1"
edit this filed, the Division sign must precede this value, example: " / 1"

Endif
Endif
Endif
Endif
else

If DS CP04 was found

If DS CRYR = "N"
return Error Code, assign DS Error ID '4336'
else
If the variable = Blanks
return Error Code, assign DS Error ID '2110'
else
If variable is greater that three characters
return Error Code, assign DS Error ID '2110'
else
Validate the variable Currency Code with the Business Function B1100001
EV01<-bhvrerrid

DS Variable->CRCD

If EV01 is not blank

return Error Code, assign DS Error ID '2110'
else
If  Mode Call = 1
edit this filed, the Multiplication sign must precede this value, example: "* 1"
else
If Variable Currency Code is not equal to DS CRCD
If DS CR CDCR = Blanks
return Error Code, assign DS Error ID '4338'
else
Retrieve the exchange rate using Business Function B0000033
DS CRCD->CRCD

Variable name->CRDC

DS AN8->AN8

DS DTEJ->EFT

Work field<-CRR

change the variable string for the value of the work field returned

edit this field,  the Multiplication sign must precede the numeric value, 

example:

If the return value was 99.9999 you must put this character "*"before the 

field , and the result is  "* 99.9999".

Endif
else
edit this filed, the Multiplication sign must precede this value, example: " * 
1"

Endif
 Endif

Endif
Endif
Endif
Endif
else

If DS CP05 was found

If the variable does not a name of the fields of file F4211 
return Error Code, assign DS Error ID '4337'
else
If  DS Mode Call = 1
change the variable string for value "1"
else
Retrieve record from the file F4211 with the fields DS DOCO,DCTO,LNID,SFXO,MCU
change the variable string for the value of the name of variable, example:

SDUPRC, is the name of the variable 
F4211, field SDUPRC has value 999.9999

change SDUPRC for 999.9999 into the formula

Endif 
Endif
else

If the 

Data Structure

D4500130 - F4076 Calculate Algebraic Expression



Special Input Expected


Parameters for B4500130 business function:


Data Item Data Structure DescriptionI/ORequiredNotes

EV01      Mode Call                   I   Y      Call = '1', called

                                                            only for testing

                                                            process Call = '2',

                                                            called for return

                                                            result numeric

FML      Calculation Formula       I   Y      160 upper-case-

                                                            character input

                                                            string.

DTEJ      Pricing Date             I   Y      Required only if Mode

                                                            = 2, use for  Pricing

                                                            Date.

CRYR      Currency Conversion       I   Y      A code that specifies

                                                            whether to use multi-

                                                            currency accounting,

                                                            must be Y or Z when is

                                                            active

CRCD      Currency Code             I    Y      Use if multi-currency

                                                            is active, all amounts

                                                            will be converted to

                                                            this common currency

                                                            code.

UOM      Unit of Measure             I   Y      Use for convert all

                                                            amounts to this common

                                                            unit of measure.

KCOO      Order Number Document Company  I   Y      Sales Order Required

                                                            only if Mode = 2

GENLNG Pointer to Order Detail (F4211)I   N      Required only if Mode

                                                            = 2

TFLA      Standard UOM Conversion       I   Y      Required only if Mode

                                                            = 2, use in UOM

                                                            conversion item

                                                            specific UOM

                                                            conversion, from

                                                            F4101.

EV02      Suppress Error Messages       I   N      1 = Suppress,

                                                            0 = Not suppress



Special Output Returned


Parameters for B4500130 business function:


Data Item Data Structure DescriptionI/ORequiredNotes


MATH01Numeric Return Value       O   N      Math Numeric Result

EV01      Error Code                   O      1 = Error found,

                                                            0 = Error not found

DTAI      Error Message ID             O   N




^

Parameter NameData ItemData TypeReq/OptI/O/Both
cCallingModeMODEcharNONENONE

The processing mode used in Purchase Order Consolidator to signify when specific orders are being processed.

szCalculationFormulaFMLcharNONENONE

An algebraic expression the system uses to calculate the adjustment to which the formula is attached. When you define formulas, use 
standard arithmetic symbols to indicate addition (+), subtraction (-), multiplication (*), and division (/). In the formula you can also include units of 
measure and currency codes, and references to fields in the Sales Order Detail table (F4211) and to variable tables. You identify each of these 
with a symbol. You define these symbols in the pricing constants, which you access from the branch/plant constants. The following is an 
example of a pricing formula that refers to a variable table. (.90 * &PROPANE) + 2  The ampersand identifies PROPANE as a variable table.

mnNumericReturnValueMATH01MATH_NUMERICNONENONE

- - - Good Performance Low Value. 

jdPricingDateDTEJJDEDATENONENONE

The Julian Date

szCurrencyCodeCRCDcharNONENONE

A code that identifies the currency of a transaction. 

szUomUOMcharNONENONE

A user defined code (00/UM) that indicates the quantity in which to express an inventory item, for example, CS (case) or BX (box).

idF4211PointerGENLNGIDNONENONE


^

szStandardUOMConvTFLAcharNONENONE


^

cErrorCodeEV01charNONENONE




   1 = Error found

   0 = Error not found



^

cSuppressErrorMsgEV02charNONENONE




   1 = Suppress

   0 = Not suppress



^

szErrorMsgIdDTAIcharNONENONE

A code that identifies and defines a unit of information. It is an alphanumeric code up to 8 characters long that does not allow blanks or 
special characters such as %, &, or +. You create new data items using system codes 55-59. You cannot change the alias.

szUnitOfMeasureVariableUOM4charNONENONE

A user defined code (00/UM) that indicates the unit of measure in which you usually price the item.

Related Functions

B0000033 Get Exchange Rate
B0000500 Algebraic Expression Calculate
B1100001 Is Column In Currency Code Table
B4000260 Line Type - Activity Rules
B4000520 Get Item UoM Conversion Factor
B4500040 F4075GetPriceVariableTableRow
X0005 Get User Defined Codes

Related Tables

F4075 Price Variable Table
F4211 Sales Order Detail File