Aggregation Block

Sepasoft MES Module Suite

Description

The Aggregation Block appends iteratively-collected data values, one per pass, into any eligible user-created Chart Parameter. This Block requires that an Iteration Block be placed in the same chart to index one row of data per iteration loop.

Connections

Two connections are required:

Input — (input) A signal to receive execution control from the previous Block in the sequence. Unlimited input connections are allowed (spread across up to three available edges).

Output — (output) A signal to pass execution control to the next Block in the sequence.

Properties

The optional Name and Description fields are included on most Blocks for clarity and documentation benefit.

Source

The Source Items tree will be pre-populated with all available schemas (filtered properties from any Action Block in the current chart). Click on an entry in the tree and then click the Select button to populate the selection in the Source field. Refer to the section Allowed Schemas and Data Types below for allowed achemas and data types.

Destination

The Destination drop-down will be pre-populated with all available Chart Parameters (created in the Start Block). Select the one you created for data aggregation (collecting rows of data to be saved as MES Objects later by a Save MES Object Block).


Allowed Schemas and Data Types

The items selected for Source and Destination must match in type or schema.

Valid aggregation combinations:

  • Action Block B2MML-to-B2MML Parameters
  • B2MML Parameter to other B2MML Parameter
  • Complex Parameter to another identical Complex Parameter

Combinations not valid / not supported:

  • Aggregating from Action Block's XML response (XMLOUT)
  • Aggregating between non-equivalent schemas
  • Aggregating between mismatched data types

The Aggregation Block will retrieve data from the source using the source path and append all returned items to the destination parameter data. Some data has to exist at the source path otherwise an error will be thrown.

To aggregate, the source and destination schemas must be equivalent. The only allowed difference is the number of occurrences. The source node can be a single node (max occurrence = 1). The destination node has to be a repeating node (max occurrence > 1 or unbound). Otherwise, their names, structures, child names, and child structures have to be the same. The path selected for the source schema should also exist in the destination schema, with the exception that the root portion may be named differently (e.g. @Param1/Param1Root/Node1/Node2 is equivalent to @Param2/Param2Root/Node1/Node2).

If the selected path matches an array path of a preceding iterator block then it will be replaced with the iterator path. An iterator path will have a [n] (array path has brackets but no index) next to the iterated node to indicate to the chart that this 'n' should be replaced with an appropriate index on execution. This functionality allows filtering. Users can iterate over a list of materials, have some decision logic before reaching the Aggregation Block and then the Aggregation Block will append the current array item of the iteration.

To use the Aggregation Block, first create a Chart Parameter with an allowed schema or data type in the Start Block of your chart, to use for data aggregation (in the example below, it is B2MML Schema with object type Material):

Usage

Connecting the Script Block

  1. Drag an Aggregation Block onto the Design Grid (position to be the next block in the chart sequence).
  2. Click on the previous Block in the sequence and draw a Connector to the Aggregation Block (any available edge). This becomes the Input connection. Repeat for any additional input Blocks, if applicable (unlimited connections are allowed on up to three edges).
  3. Click on the Aggregation Block and draw a Connector (from any available edge) to the next Block in the sequence. This becomes the Output connection.

Configuring the Properties

  1. Create a destination schema for use in aggregating in the Start Block of the chart.
  2. Select the source schema for aggregating rows from the Source Items tree and click the Select button to populate it in the Source field.
  3. Select the destination schema (created for data aggregation in the Start Block) from the Destination drop-down. If the schemas match, a green check mark will appear with the note "Source and destination are correctly set".

Example

Iteratively Create Material Definitions

This example chart collects a list of Material Definitions from an SAP database and creates an MES Material Definition object for each.




Start Block

A Chart Parameter called maxRows is used to limit the number of SAP entries to fetch from the SAP database. The number will be input into the chart during the chart execution function executeChart(chartPath, chartParameters, returnChartParameters).


Sample SettingDescription
maxRowsInteger. Used to pass in to the chart the number of rows to fetch from the database.
b2mml_materialsB2MML array. Used to hold the entries aggregated by the Aggregation Block (one row per loop).
rows_aggregatedInteger. Used to return the count of how many rows were aggregated by the Aggregation Block.
rows_verify_noInteger. Used to return the count of how many rows failed the Verify MES Object Block (row data was not a proper MES Object).
rows_decision_noInteger. Used to return the count of how many rows failed the Decision Block (equation was False, so decision is "No").







SAP BAPI Action Block - Properties

This block fetches the Material Definitions from the specified SAP database. It is configured as follows:

A Destination called My SAP Server was previously configured in the Interface for SAP ERP section of the Global area in Designer:






The Remote Function Call section is configured to filter down to just the BAPI_MATERIAL_GETLIST module where the Material Definitions are stored:

PropertySample SettingDescription
NameGet MaterialsName of the Block (available, if needed, for local use within the chart by other Blocks).
DestinationMy SAP ServerSelected SAP Connector Destination (created in the Interface for SAP section of the Global area in Designer).
SAP BAPI Options
(Hierarchical/Alphabetical)
(tree of available BAPI options)
Alphabetical checkbox and
Material/BAPI_MATERIAL_GETLIST
The two checkboxes decide how the tree of available SAP BAPI options below is sorted. Alphabetical is usually chosen if you know the name of the BAPI you want, else drill down to find it in Hierarchical mode.
Selected BAPI(shows the selected BAPI)Display only. Shows (and remembers) the selected BAPI after the Select button is pushed.
RFC TypesRFCSynchronous Remote Function Call (expects an immediate answer from the receiving system, else an error will be reported).
Queue NameN/A


SAP BAPI Action Block - Mapping

The Input tab of the SAP BAPI Action Block includes mapping for the Chart Parameter maxRows to be passed into the BAPI function call that the block makes to the SQL database (limits the number of entries fetched). There is also a requirement that MATNRSELECTION in BAPI_MATERIAL_GETLIST be restricted to positive integer values only.


The Output tab of the SAP BAPI Action Block includes mapping for MATERIAL → ID and MATL_DESC → Description. Note that it must first include a mapping connector at the parent level, to provide the block with a means of knowing the array sizes on both sides so it can map the connections properly. Each member of the BAPI_MATERIAL_GETLIST will be mapped into a B2MML array that includes Material Definition properties of ID and Description. These are collected, one at a time by the Aggregation Block in the iteration loop (into the Chart Parameter b2mml_materials), and then turned into MES Material Definition objects by the SAVE MES Object Block.



Iteration Block

This block increments a pointer to one row of data at a time in the data array selected in the Array Path field. For each row pointed to, control passes to the Block connected to its Next output. It accepts a return trigger input (Next Trigger) to increment the pointer to the next row. When there are no more rows in the selected data array, it will pass control to the Block connected to its Done output.

In this example, the path is to MaterialDefinition in the B2MML array, MATERIAL, which contains the ID and Description properties that the Aggregation Block will append, one row at a time, to Chart Parameter b2mml_materials (which the Save MES Object Block will later use to create the MES Material Definition Objects).

On each loop through the Iteration Block, the row pointer is incremented and control passes to the Decision Block that is connected to its Next output Connector.

Once all rows have been iterated through, control passes to the Save MES Object Block connected to its Done output.






Decision Block

In this example, the expression used to arrive at a 'True' decision is simply whether the last character in the ID property in the row currently being pointed to (by the Iteration Block) is equal to "8" (the asterisk is a wildcard that ignores all the preceding characters). If the ID ends in "8", control passes to the Verify MES Object Block connected to its True output. Otherwise, control passes to the Script Block connected to its False output.






Verify MES Object Block

This Block is used to test whether an array of data (or a row of data pointed to by an Iteration Block) contains appropriate information to successfully create an MES Object. It does not create the object. 

In this example, if the row contains appropriate information required to successfully create an MES Object, control passes to the Aggregation Block connected to its Yes output, to be appended to the end of the current b2mml_materials array. If not, then control is passes to the Script Block connected to its No output.




Aggregation Block

This Block appends iteratively-collected data values, one per pass, into a user-created Chart Parameter. 

In this example, b2mml_materials was created in the Start Block to hold the aggregated data. Chart execution control only passes into the Aggregation Block after it has successfully passed through the Decision Block (ID property ends in "8") and the Verify MES Object Block (data is determined to be sufficient to successfully create an MES Object).

After the row has been 'aggregated' (appended to the end of b2mml_materials), control passes back to the Iteration Block and the loop  repeats with the next row.






Script Block - Connected to Decision Block

This script increments the Chart Parameter rows_decision_no any time the expression in the Decision Block resolves to False (which passes control to this Script Block).






Script Block - Connected to Verify MES Object Block

This script increments the Chart Parameter rows_verify_no any time the Verify MES Object Block resolves to No (which passes control to this Script Block).






Script Block - Connected to Aggregation Block

This script increments the Chart Parameter rows_aggregated immediately after the Aggregation Block completes its task (appending a row to b2mml_materials).






Script Block - Connected Last in the Iteration Loop

This Block has no scripting inside except for the pass instruction (which is a non-operation), so it does absolutely nothing! It is placed in the chart at its current position simply to make the Connectors exiting the three other Script Blocks flow nicely. Otherwise, they end up auto-routing strangely, making the chart more difficult to understand. Feel free to sprinkle empty Script Blocks as needed to keep your 'wiring' neat and self-explanatory.






Save MES Object Block

This block creates an MES Object for each entry in the selected RFM (the drop-down list Target will list all of the Action Blocks in the chart. The filtered RFM in the selected Action Block will be used to create the list of MES Objects). For this example, one MES Material Definition object will be created for each entry in the RFM selected in the "Get Materials" SAP RFM Action Block (up to the limit defined by the Chart Parameter maxRows).




PropertySample SettingDescription
TargetGet Materials

"Get Materials" is the data source selected from the drop-down list of blocks with available data (it's the only choice in this example).




Executing the Chart

This example chart is being executed from a script within a Button component on an Ignition Designer window:


If "10" is entered into the Rows to Fetch text field, then when the Button is pressed:

  • The number in the text field is loaded into numRows.
  • The chart is executed, passing in numRows to the Chart Parameter maxRows in the Start Block, and listing three Chart parameters to include in the resulting object when chart execution concludes. Unlike the other two variants of .executeChart, the function will wait for chart execution to conclude so it can return a Python dictionary containing the Chart Parameters specified (in this example: rows_aggregated, rows_verify_no and rows_decision_no).
  • The various counts are retrieved from the returned chart parameter object and printed to the Output Console.


The result of the chart execution is that ten rows are fetched from BAPI_MATERIAL_GETLIST in the SAP database and six MES Material Definition objects are created (those that have an ID that ends with "8", per the Decision Block expression):




Sepasoft MES Module Suite