Product Lifecycle Management Blogs by SAP
Dive into product lifecycle management news, learn about digitalizing PLM for the digital supply chain, and stay informed with product updates from SAP.
cancel
Showing results for 
Search instead for 
Did you mean: 
subrahmanyam2023
Employee
Employee
Objective: Showcasing Looping Functionality in the Production Process

Hello everyone,

In this blog, I will demonstrate how to achieve looping functionality in the DMC Production Process. Sometimes, there is a need to iteratively call public APIs or external services, but currently, there is no direct looping action available. Therefore, I will present a workaround to achieve the desired looping functionality.

I will begin by providing an explanation on how to create a loop in the production process, followed by a simple example.

Let's get started...

step 1: Create process variables for looping condition.
Process variable:
variableName: P_IterationLength
type: integer
value: 5

variableName: P_Index
type: integer
value: 0

 


 

Step 2: Drag and drop the condition block and script block onto the canvas. Set the looping condition as shown in the image below.
'P_Index' < 'P_IterationLength'


 

step 3:Create input and output variables in the script block. Assign the process variable P_Index to both input and output variables. Here, assigning 'P_Index' to the input variable serves as the actual assignment, while binding it to the output variable ensures that any updates made in the output variable within the script will also update the associated process variable.
Input:
current_index (Integer), value: 'P_Index'

Output:
nextIndex (Integer), value: 'P_Index'

 


 


 

step 4: Write the update logic in the script.
$output.nextIndex = $input.current_index+1


step 5: Connect the output of the script back to the condition block, and attach the else condition to the end action. In this case, the loop will run five times.


 

By following the above steps, we have successfully achieved looping in the production process. Now, let's explore a simple example.

Example:Obtaining the list of first operations for all SFCs.

To achieve this logic, we need to iteratively retrieve details for each SFC. In this scenario, we must make iterative calls to the Retrieve_SFC API and extract first operation from it.

Let's build the logic for this.

step 1: Within the same production process, create a String array of SFCs.
P_Sfcs (StringArray)
value: ["SO0123_009","SO0123_010"]


 

Step 2:Add a Script action to dynamically get the length of the SFCs array and assign it to the P_IterationLength variable.


 



 

Step 3: Add the Retrieve_SFC Service inside the loop, as shown in the image below.


Step 4: To pass the SFC, we need to get the SFC from the P_Sfcs array based on the index. However, it is not directly possible to pass the index while assigning it to the SFC property in the service.

 
The following expression is not valid:
'P_Sfcs['P_index']'

Therefore, we need an intermediate script to extract the SFC number from the array using the index.

Create a script with the following configurations:
Input:
variableName: index
type: integer
value: 'P_Index'

variableName: sfcs
type: stringArray
value: 'P_Sfcs'


Output:
variableName: sfc
type:string
value:


Script:
$output.sfc = $input.sfcs[$input.index]

 


Step 5: Pass the SFC number from the script output to the Retrieve_SFC service


 

Step 6:Add one more script after the Retrieve_SFC service call to get the first operation.

Create another process variable, P_Operations, with the following configurations
process Variable:
variableName: P_Operations
tye: stringArray
value: []



Input: 
variableName: index
type: integer
value: 'P_index'

variableName: operations
type: stringArray
value: 'P_Operations'

variableName: steps
type: structureArray
schema: sfcstep--00004
value: 'Retrieve_SFC#steps'

Output:
variableName: operations
type: stringArray
value: 'P_Operations'

Script:
var operation = $input.steps[0].operation.operation;
$input.operations.push(operation);
$output.operations = $input.operations;

Now save and deploy the production process to test it.

Summary:

In this blog, we explored the looping functionality in the DMC Production Process. We learned how to create a loop using condition blocks and script blocks, and demonstrated a use case for retrieving active operations of SFCs. By following the step-by-step process, we were able to achieve looping within the production process.

Looping functionality is crucial when it comes to repetitive tasks and iterative calls in the production process. With the workaround explained in this blog, you can now incorporate loops effectively into your DMC workflow.

Please share your implementation of looping in the production process in the comments section below. Also, make sure to follow the digital manufacturing tag to stay updated with more blogs related to SAP DMC.