Mapping XML in lt-gt format to CCB in ESQL

72 views Asked by At

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>&lt;Rp&gt;&lt;e1&gt;ar&lt;/e1&gt;&lt;e2&gt;pa&lt;/e2&gt;&lt;e3&gt;n&lt;/e3&gt;&lt;s&gt;&lt;es1&gt;jh&lt;/es1&gt;&lt;es2&gt;il&lt;/es2&gt;&lt;es3&gt;ke&lt;/es3&gt;&lt;es4&gt;ps&lt;/es4&gt;&lt;/s&gt;&lt;s&gt;&lt;es1&gt;it&lt;/es1&gt;&lt;es2&gt;am&lt;/es2&gt;&lt;es3&gt;eg&lt;/es3&gt;&lt;es4&gt;ha&lt;/es4&gt;&lt;/s&gt;&lt;s&gt;&lt;es1&gt;li&lt;/es1&gt;&lt;es2&gt;na&lt;/es2&gt; &lt;es3&gt;uv&lt;/es3&gt;&lt;es4&gt;wx&lt;/es4&gt;&lt;/s&gt;&lt;/Rp&gt;</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.

1

There are 1 answers

0
Attila Repasi On BEST ANSWER

You can't change the InputRoot, so this line won't work:

CREATE LASTCHILD OF blobXML PARSE(ms, InputRoot.Properties.Encoding, InputRoot.Properties.CodedCharSetId);

You can store the parsed E3 field in a ROW variable, like this:

DECLARE ns1 NAMESPACE 'xyz';
    
DECLARE e3Blob BLOB CAST(FIELDVALUE(InputRoot.XMLNSC.ns1:GM.ns1:B[2].ns1:E3) AS BLOB CCSID InputRoot.Properties.CodedCharSetId);
DECLARE temp ROW;
CREATE LASTCHILD OF temp DOMAIN('XMLNSC')
    PARSE(
        e3Blob,
        InputRoot.Properties.Encoding,
        InputRoot.Properties.CodedCharSetId
    );
    
CALL CopyMessageHeaders();
SET OutputRoot.XMLNSC.out.Rp = temp.XMLNSC.Rp;