Question
· Oct 22

Help in Creating Index in DTL based of a variable value

Hello. I need to transform a message

FROM:

MSH|^~\&|
SCH||61490||
PID|1||
RGS|1||1
AIS|1||
AIS|2||
AIS|3||
AIL|1||
AIP|1||

TO:

MSH|^~\&|
SCH||61490||
PID|1||
RGS|1||1
AIS|1||
AIL|1||
AIP|1||
RGS|1||1
AIS|2||
AIL|1||
AIP|1||
RGS|1||1
AIS|3||
AIL|1||
AIP|1||

The RGS, AIS, AIL and AIP are all under the RGS group. The one RGS segment that comes in will be copied across the group. If 3 AIS segments come in then I need 3 RGS groups, if 2 I need 2 RGS groups etc.

In my DTL (screenshot below) I have currently hardcoded the RGS index (1,2,3) but this will not be sufficient incase 4 AIS segments are sent in. I need this index to be variable based off the number of AIS segments that are sent in. 

I have seen posts about using "increment and a while" and I did try that but it didn't work. In the DTL above instead of setting the index to 1, 2, 3 I had set it to "trgs". tais is the count of the AIS sent in. 

Schema:

<?xml version="1.0"?> <Category name="TEST_Schema_2.3.1" 
          description="Orders scheduling." 
          base="2.3.1">     <MessageType name="SIU_S12" structure="SIU_ALL" returntype="base:ACK_S12"/>
    <MessageType name="SIU_S13" structure="SIU_ALL" returntype="base:ACK_S13"/>
    <MessageType name="SIU_S14" structure="SIU_ALL" returntype="base:ACK_S14"/>
    <MessageType name="SIU_S15" structure="SIU_ALL" returntype="base:ACK_S15"/>     <MessageStructure name="SIU_ALL" 
          definition="base:MSH~base:SCH~base:PID~{~base:RGS~base:AIS~base:AIL~base:AIP~}" 
          description="Custom structure with repeating RGS group"/>
</Category>

 

Any leads please?

Product version: IRIS 2021.1
Discussion (5)3
Log in or sign up to continue

To create an index in DTL based on a variable value, you can utilize looping capabilities in DTL to dynamically handle variable counts and indexes. Here are some potential approaches to achieve this:

  1. Using a foreach Loop: This DTL element is specifically designed for iterating over repeating source segments. Inside a foreach, you can dynamically set the index based on the current iteration. Take advantage of the foreach loop to iterate through the AIS segments and assign dynamic indexes to the RGS elements accordingly. This technique would replace the hardcoded indexes with variable-driven ones [1].

  2. Using Code Blocks: Code blocks in DTL allow embedded ObjectScript to execute custom transformations. You can add a code block inside your DTL and use a counter to keep track of the current index. This counter can drive the dynamic allocation of index values for the RGS segments [2].

  3. Utilizing XML Structure: The DTL XML allows you to include actions like assignment and iteration. For example, you can define DTL elements to loop through the source AIS segments and assign values using target.{RGS} with an incremented index [1][2].

By combining variable-driven iterations like foreach or custom code blocks for the dynamic logic, you can dynamically set the RGS index based on AIS segments received in the message. References for specific DTL functionality are found in [1][2].

Sources:

A foreach (possibly multiple foreaches) is what you need. Getting the iterators right is the issue. You're iterating over the AISgrp in the first RGSgrp of the source message and placing them in target RGSGroups with the same iteration count of the source AISgrp. Here's an example based on the 2.3.1:SIU_S12 schema structure that should do what you want, and also handles repetitions of the AIL, AIP and AIG groups: