I have the xml in following structure:
<GM xmlns="xyz">
<H>
<E1>aaaa</E1>
<E2>bbbbb</E2>
</H>
<I>
<E1>ccc</E1>
<E2>ddd</E2>
<E3>eeeee</E3>
</I>
<B>
<E1>ff</E1>
<E2>gg</E2>
<E3>hhhh</E3>
</B>
<B>
<E1>ii</E1>
<E2>COIL</E2>
<E3><Rp><e1>ar</e1><e2>pa</e2><e3>n</e3><s><es1>jh</es1><es2>il</es2><es3>ke</es3><es4>ps</es4></s><s><es1>it</es1><es2>am</es2><es3>eg</es3><es4>ha</es4></s><s><es1>li</es1><es2>na</es2> <es3>uv</es3><es4>wx</es4></s></Rp></E3>
</B>
<B>
<E1>jj</E1>
<E2>kk</E2>
<E3>llll</E3>
</B>
</GM>
And I have the following CCB structure,
01 DATA
03 A.
05 A1 PIC X(10).
05 A2 PIC X(5).
05 A3 PIC X(5).
05 A4 PIC X(5).
05 A5 PIC X(5).
05 A6 OCCURS 3.
07 B1 PIC X(4).
07 B2 PIC X(4).
07 B3 OCCURS 3.
09 C1 PIC X(2).
09 C2 PIC X(2).
09 C3 PIC X(2).
09 C4 PIC X(2).
To transform from this xml to CCB I've written the following esql code in IBM ACE tool:
CREATE COMPUTE MODULE POC_LOGIC_Mapping
CREATE FUNCTION Main() RETURNS BOOLEAN
BEGIN
CALL CopyMessageHeaders();
-- CALL CopyEntireMessage();
SET OutputRoot.MQMD.CodedCharSetId = 1140;
SET OutputRoot.MQMD.Encoding = 785;
SET OutputRoot.Properties.MessageSet = 'K9IDEGS002001';
SET OutputRoot.Properties.MessageType = 'msg_DATA';
SET OutputRoot.Properties.MessageFormat = 'Binary1';
DECLARE ns1 NAMESPACE 'xyz';
DECLARE i INTEGER 1;
DECLARE ms BLOB;
SET OutputRoot.MRM.A.A1 = coalesce(InputRoot.XMLNSC.ns1:GM.ns1:H.ns1:E1, '');
SET OutputRoot.MRM.A.A2 = coalesce(InputRoot.XMLNSC.ns1:GM.ns1:H.ns1:E2, '');
SET OutputRoot.MRM.A.A3 = coalesce(InputRoot.XMLNSC.ns1:GM.ns1:I.ns1:E1, '');
SET OutputRoot.MRM.A.A4 = coalesce(InputRoot.XMLNSC.ns1:GM.ns1:I.ns1:E2, '');
SET OutputRoot.MRM.A.A5 = coalesce(InputRoot.XMLNSC.ns1:GM.ns1:I.ns1:E3, '');
DECLARE obj1 REFERENCE TO InputRoot.XMLNSC.ns1:GM.ns1:B;
X1: WHILE LASTMOVE(obj1) DO
IF (obj1.ns1:E2 = 'COIL') THEN
SET ms = CAST(obj1.ns1:E3 AS BLOB CCSID InputRoot.Properties.CodedCharSetId);
LEAVE X1;
ELSE
MOVE obj1 NEXTSIBLING;
END IF;
END WHILE;
DECLARE blobXML REFERENCE TO InputRoot.XMLNSC;
CREATE LASTCHILD OF blobXML PARSE(ms, InputRoot.Properties.Encoding, InputRoot.Properties.CodedCharSetId);
DECLARE sRef REFERENCE TO blobXML.Rp.s;
DECLARE j INTEGER;
FOR obj2 AS InputRoot.XMLNSC.ns1:GM.ns1:B[] DO
SET OutputRoot.MRM.A.A6[i].B1 = coalesce(obj2.ns1:E1, '');
SET OutputRoot.MRM.A.A6[i].B2 = coalesce(obj2.ns1:E2, '');
SET j = 1;
WHILE LASTMOVE(sRef) DO
SET OutputRoot.MRM.A.A6[i].B3[j].C1 = coalesce(CAST(sRef.es1 AS CHARACTER), '');
SET OutputRoot.MRM.A.A6[i].B3[j].C2 = coalesce(CAST(sRef.es2 AS CHARACTER), '');
SET OutputRoot.MRM.A.A6[i].B3[j].C3 = coalesce(CAST(sRef.es3 AS CHARACTER), '');
SET OutputRoot.MRM.A.A6[i].B3[j].C4 = coalesce(CAST(sRef.es4 AS CHARACTER), '');
SET j = j + 1;
MOVE sRef NEXTSIBLING;
END WHILE;
SET i = i + 1;
END FOR;
RETURN TRUE;
END;
END MODULE;
This providing error: "there is a mismatch between the logical definition and the message tree. Message: msg_DATA Element: C1" Now I am stuck. After setting the xml which is in lt-gt format inside element where equals to 'COIL', I need to populate B3 segements according to the occurance of segments. And C1 will be mapped to s.es1, C2 will be mapped to s.es2, C3 will be mapped to s.es3 and C4 will be mapped to s.es4.
You can't change the InputRoot, so this line won't work:
You can store the parsed E3 field in a ROW variable, like this: