Formula scripts for data collection use interpreted JavaScript as the scripting language.
Note
Scripting is disabled for security reasons by default. For more information, see SAP ME Security Guide
at .
SAP ME supports the following methods in DC formulas:
callEJB()
executeQuery()
exit()
findSingleParameter()
getEJBProperties()
print()
printAll()
This method calls Enterprise JavaBeans (EJB).
call(EJBname, EJBmethod, argument, …)
EJBname
is the name of the EBJ such as ItemBO
orSFCBO
.
EJBmethod
is the method to call such as start or complete.
argument
- one or more arguments to pass to the method.
Example
props = callEJB("SFCBO", "getProperties", SFC_BO, "PRIORITY");
priority = props.get("PRIORITY");
exit(priority);
This method executes an SQL query on the SAP ME WIP database. It returns a data object containing the results of the query. May be null.
The SQL must be valid for the database server used by SAP ME for the WIP database.
Example
queryStr = "select PRIORITY from SFC where HANDLE=\'";
queryStr = queryStr + SFC_BO+"\'";
result = executeQuery(queryStr);
priority = result.get("PRIORITY");
exit(priority);
This method stops the script execution.
Example
exit(A)
Finishes the script execution and returns the value of script variable A
as the result of the formula calculation. This is the value that will be used for the data collection parameter to which the formula belongs.
You can use the findSingleParameter
method with arguments as defined below:
findSingleParameter("parameter_name", "this" | "subassy", "item_name", "item_revision", "operation_name", "operation_revision", "resource_name", "last")
Note that you must enclose each argument in either double or single quotation marks.
Argument | Description |
---|---|
| The name of the parameter as it appears in the |
| Use one of these literals: |
| The name of the material associated with the SFC number |
| The version of the material associated with the SFC number |
| The name of the operation where data was collected for the SFC number |
| The version of the operation where data was collected for the SFC number |
| The name of the resource where data was collected for the SFC number |
| Required literal to end the argument |
Note that you cannot use mathematical symbols (+
, -
, *
, /
) in parameter names that are used in calculations.
Example
The DC group DC1/A
has one parameter, P1
, of the Numeric
type. DC1/A
is attached to the operation OP1
.
The DC group DC2/A
has three parameters defined as follows:
Parameter Name | Type |
---|---|
|
|
|
|
|
|
DC2/A
is attached to the operation OP2
.
The operator collects data at OP1
through the DC Entry
plug-in. Using the following formula for PFORM
, when the operator at OP2
enters data for P2
and P3
, and saves the entries, the DC Entry
plug-in calculates the sum of these two values plus the saved value entered for P1
at OP1
. The calculated value is saved for the parameter PFORM
.
a=P2+P3;
b=findSingleParameter("P1", "this", "MAT1", "*", "OP1", "A", "RES1", "last");
c=a+b;
exit(c);
Example
value = findSingleParameter("PARAM1", "this", "M1", "A", "O1", "A", "DEFAULT", "last");
exit(value);
Caution
When creating formulas, make sure that user input does not cause divide-by-zero errors.
This method retrieves one or more properties from Enterprise JavaBeans (EJB).
call(EJBname, objectHandle, property, …)
EJBname
is the name of the EBJ such as ItemBO
orSFCBO
.
objectHandle
is the reference to the EJB to get the properties.
properties
- one or more properties to retrieve.
Example
props = getEJBProperties("SFCBO", SFC_BO, "Priority");
priority = props.get("PRIORITY");
exit(priority);
The print(value,…)
method prints the string value of one or more variables. This method should be used for only debugging and testing purposes.
The printAll()
method prints the string values of each of the variables available to the script. This method should be used for only debugging and testing purposes.
Example
print(SFC_BO);
printAll();
exit(1);
You can view results of the print()
and printAll()
methods in Log Viewer (Developer Traces
view) in SAP NetWeaver Administrator.
To do that, configure Tracing as follows:
In SAP NetWeaver Administrator, choose Log Configuration
.
On the Log Configuration: Java
screen, select Tracing Locations
in the Show
field, enter com.sap.me.script.ScriptBOBean in the Location
field and choose Go
to find the location
Change Severity
from Error
to Debug
.
On the SAP Manufacturing Execution Logging Configuration
screen ( ), verify that the Debugging Information
checkbox is selected.