Handling X12 Interchanges
As X12 documents are sent within Interchanges you need to choose how Ensemble should handle incoming documents. Especially if you need to access documents at the Group or Transaction Set level. This chapter describes different scenarios for handling X12 Interchanges
X12 Batch Handling
Batch Handling settings determine how Ensemble sends and receives documents. The choices you make here affect how your Business Processes should be configured.
Receiving Batch Documents
X12 business services have the Batch Handling configuration setting, which determines how to process incoming batch documents. The options are:
-
Whole Batch — Do not process child documents individually; accumulate and send the whole batch as one composite document.
-
Single-Session Batch — Forward all documents in the Interchange as part of a single session, including final parent document objects containing batch and group header and trailer segments.
-
Multi-Session Batch — Forward each document in the Interchange in its own session, followed by final parent document objects containing the batch and group header and trailer segments.
-
Individual — Forward each child document in the batch in its own session; do not forward parent batch document objects.
If you select Whole Batch any transformations of individual Transaction Sets will have to account for the Interchange and Group levels. See Configuring Business Processes for Whole Batch below.
Sending Batch Documents
On the outgoing side, X12 File and FTP business operations have the Auto Batch Parent Segs configuration setting. When Auto Batch Parent Segs is False (the default) the business operation outputs child documents, but does not output the batch headers and trailers. When Auto Batch Parent Segs is True, while outputting a message that has a batch parent, the business operation outputs the batch headers first, then the child documents, then follows up with the batch trailers when triggered by the final batch header message or by a file name change.
Batch Modes
The combination of Batch Handling and Auto Batch Parent Segs enables the following modes of operation for X12 batch documents:
Batch Handling | Auto Batch Parent Segs | Results |
---|---|---|
Whole Batch | (any) | Business service sends only the parent document; all child documents are referenced to it but not sent individually. Operation outputs entire batch at one time when it receives the parent document. |
Single-Session or Multi-Session |
True | Service sends each child document as it receives and parses it, followed by the parent document when all children have been sent. The business operation outputs parent headers when it receives the first child document, then finishes up with trailers when it receives the parent document object. Trailer segments automatically contain the correct child count values. |
Single-Session or Multi-Session |
False | This results in double output: the business operation sends out each child document individually, followed by the parent document containing each child document (again). |
Individual | False | Business service forwards each child document in the batch in its own session and does not forward objects representing the batch headers and trailers. On the outgoing side, the business operation does the same. |
Configuring Business Processes for Whole Batch
If you choose to have the business service process incoming X12 documents in Whole Batch mode you will need to configure the business process accordingly.
For examples of X12 Productions that use the Whole Batch setting please view the Demo.X12.SorterDTL.ByGroup.Production and Demo.X12SorterDTL.ByInterchange.Production demo productions. To view them, ensure that you are within the ENSDEMO namespace and navigate to the Production List page. Select the production you wish to view and click open. These demos incorporate all of the configuration settings listed below.
Routing Rules for Whole Batch
To properly route documents in Whole Batch mode, set the routing rule to accept Interchanges. Send to the relevant data transformation if necessary.
Create a new routing rule
-
Ensure you are in the proper namespace and navigate to the Ensemble Rule Editor page.
-
Click New.
-
Follow the instructions in Adding an X12 Routing Rule.
Edit the constraint
-
Double click on the constraint rule item.
-
Set the Source to your business service.
-
Set the Message Class to EnsLib.EDI.X12.Document.
-
Set the Schema Category as appropriate for your production.
-
Choose Interchange from the Document Name selection.
For more information, see Using the Rule Constraint Editor.
Define the condition
Choose any conditional statement relevant to your production. If you always want the action to be applied, click on the condition rule item and type “1”.
Add a Send action.
-
Click on the when rule item.
-
Click Send to add a send action.
-
Double click on the transform rule item and select the appropriate data transformation.
-
Double click on the target rule item and select the appropriate business operation from your production.
For more information, see Selecting the Transformation and Target of a Send Action.
Data Transformations for Whole Batch
To transform whole batch documents at the Group or Transaction Set level, you must iterate through each group and each transaction set within each group. To do so, follow the steps below.
Create a new Data Transformation
-
Create a new set action by clicking Add Action and selecting set.
-
Input a variable name into the Property field, such as ArrayOfGroups.
-
Input ##class(%Library.VariableName).%New() into the Value field, where VariableName is the value you provided in the Property field.
-
Input "" into the Key field.
Create an Array of Groups
-
Create a new set action by clicking Add Action and selecting set.
-
Input a variable name into the Property field, such as ArrayOfGroups.
-
Input ##class(%Library.VariableName).%New() into the Value field, where VariableName is the value you provided in the Property field.
-
Input "" into the Key field.
Loop over the Groups in each Interchange
-
Create a new for each action by clicking Add Action and selecting for each.
-
Input source.{GroupDocsRef} into the Property field.
-
Input Group into the Key field.
Loop over the Transaction Sets in each Group
-
Create a new for each action by clicking Add Action and selecting for each.
-
Be sure the for each is between the for each and endeach blocks of the previous action.
-
Input Group.{TransactionSetDocsRef} into the Property field.
-
Input TSIn into the Key field.
Add any additional actions necessary. For more information, see Developing DTL Transformations.
Configuring Business Processes for Other Batch Settings
If you choose to have the business service process incoming X12 documents in Whole Batch mode you will need to configure the business process accordingly.
For an example of an X12 production that use Single Batch Setting please view the Demo.X12.SorterProcess demo production. To view it, ensure that you are within the ENSDEMO namespace and navigate to the Production List page. Select the production you wish to view and click open. This demo incorporates all of the configuration settings listed below.
Routing Rules for Other Batch Settings
To properly route documents in Single Session, Multi Session, or Individual mode, create a routing rule set with a unique routing rule for each type of X12 document the production will encounter.
To create new rules within the rule set:
-
Click on ruleSet
-
Click rule to add a rule
-
Follow the instructions set in Routing Rules for Whole Batch
-
When editing the constraint, be sure to set the Document Name to the appropriate X12 document type.
-
When adding a data transformation, be sure to use a transformation written for the appropriate X12 document type.
Data Transformations for Other Batch Settings
To transform X12 documents within productions with Single Session, Multi Session, or Individual mode you must create a separate data transformation for each type of X12 document the production will encounter. For more information, see Developing DTL Transformations.