The FOR statement iterates through a list (for example, a message array).
For each iteration, the FOR statement makes the correlation variable (correlation_name in the syntax diagram) equal to the current member of the list (field_reference) and then executes the block of statements. The advantage of the FOR statement is that it iterates through a list without your having to write any sort of loop construct (and eliminates the possibility of infinite loops).
SET OutputRoot.MQMD=InputRoot.MQMD; SET Environment.SourceData.Folder[1].Field1 = 'Field11Value'; SET Environment.SourceData.Folder[1].Field2 = 'Field12Value'; SET Environment.SourceData.Folder[2].Field1 = 'Field21Value'; SET Environment.SourceData.Folder[2].Field2 = 'Field22Value'; DECLARE i INTEGER 1; FOR source AS Environment.SourceData.Folder[] DO CREATE LASTCHILD OF OutputRoot.XML.Data.ResultData.MessageArrayTest.Folder[i] NAME 'FieldA' VALUE '\' || source.Field1 || '\' || CAST(i AS CHAR); CREATE LASTCHILD OF OutputRoot.XML.Data.ResultData.MessageArrayTest.Folder[i] NAME 'FieldB' VALUE '\' || source.Field2 || '\' || CAST(i AS CHAR); SET i = i + 1; END FOR;generates the output message:
<Data> <ResultData> <MessageArrayTest> <Folder> <FieldA>Field11Value1</FieldA> <FieldB>Field12Value1</FieldB> </Folder> <Folder> <FieldA>Field21Value2</FieldA> <FieldB>Field22Value2</FieldB> </Folder> </MessageArrayTest> </ResultData> </Data>
Notices |
Trademarks |
Downloads |
Library |
Support |
Feedback
![]() ![]() |
ak05030_ |