Show TOC

Background documentationWriting Formula Scripts

 

Formula scripts for data collection use interpreted JavaScript as the scripting language.

Note Note

Scripting is disabled for security reasons by default. For more information, see Start of the navigation path Authorizations Next navigation step Standard Roles Next navigation step SAP NetWeaver UME Security Roles and Actions End of the navigation path in SAP ME Security Guide at Start of the navigation path http://service.sap.com/instguidesInformation published on non-SAP site Next navigation step SAP Business Suite Applications Next navigation step SAP Manufacturing Next navigation step SAP Manufacturing Execution 15.1 End of the navigation path.

End of the note.
Methods Available for Formula Scripts

SAP ME supports the following methods in DC formulas:

  • callEJB()

  • executeQuery()

  • exit()

  • findSingleParameter()

  • getEJBProperties()

  • print()

  • printAll()

callEJB()

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 Example

props = callEJB("SFCBO", "getProperties", SFC_BO, "PRIORITY");

priority = props.get("PRIORITY");

exit(priority);

End of the example.
executeQuery(<SQLstring>)

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 Example

queryStr = "select PRIORITY from SFC where HANDLE=\'";

queryStr = queryStr + SFC_BO+"\'";

result = executeQuery(queryStr);

priority = result.get("PRIORITY");

exit(priority);

End of the example.
exit ()

This method stops the script execution.

Example 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.

End of the example.
findSingleParameter ()

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

parameter_name

The name of the parameter as it appears in the Parameter Name field in Data Collection Maintenance

this | subassy

Use one of these literals: this returns the current SFC number subassy returns the SFC number of a subassembly consumed by the current SFC number

item_name

The name of the material associated with the SFC number

item_revision

The version of the material associated with the SFC number

operation_name

The name of the operation where data was collected for the SFC number

operation_revision

The version of the operation where data was collected for the SFC number

resource_name

The name of the resource where data was collected for the SFC number

last

Required literal to end the argument

Note that you cannot use mathematical symbols (+, -, *, /) in parameter names that are used in calculations.

Example 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

P2

Numeric

P3

Numeric

PFORM

Formula

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);

End of the example.

Example Example

value = findSingleParameter("PARAM1", "this", "M1", "A", "O1", "A", "DEFAULT", "last");

exit(value);

End of the example.

Caution Caution

When creating formulas, make sure that user input does not cause divide-by-zero errors.

End of the caution.
getEJBProperties()

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 Example

props = getEJBProperties("SFCBO", SFC_BO, "Priority");

priority = props.get("PRIORITY");

exit(priority);

End of the example.
print () and printAll ()

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 Example

print(SFC_BO);

printAll();

exit(1);

End of the example.
Viewing Print Results

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:

  1. In SAP NetWeaver Administrator, choose Log Configuration.

  2. 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

  3. Change Severity from Error to Debug.

  4. On the SAP Manufacturing Execution Logging Configuration screen (Start of the navigation path http://<SAP ME server>:<port>/manufacturing-adminInformation published on non-SAP site Next navigation step Logging Configuration End of the navigation path), verify that the Debugging Information checkbox is selected.