App Connect

App Connect

Join this online user group to communicate across IBM product users and experts by sharing advice and best practices with peers and staying up to date regarding product enhancements.


#Applicationintegration
#App Connect
#AppConnect
 View Only
  • 1.  unable to perform iteration while parsing CSV Records

    Posted Thu June 01, 2023 02:00 PM

    Hi i am sending two csv records to insert into the database through file nodes, i written the code and tried the iteration but the iteration is not working an anybody help me out with this the code is given below, we used MRM parser here

    input csv record:

    120001,venu,9000000001,test@gmail.com,ABC Street,Test Lane,Newyork,75012
    120001,gopal,9000000001,test@gmail.com,ABC Street,Test Lane,Newyork,75012

     
     
    CREATE COMPUTE MODULE CustDetails_Compute
    CREATE FUNCTION Main() RETURNS BOOLEAN
    BEGIN
    DECLARE i INTEGER 1;
    DECLARE skuNo, customerMobileNo INTEGER;
    DECLARE sqlStmt, customerName, customerEmail, addressLine1, addressLine2, city, zipcode CHAR;
     
        SET OutputRoot.Properties = InputRoot.Properties;
        
        SET OutputRoot.Properties.MessageSet = 'HDENO38002001';
    SET OutputRoot.Properties.MessageType = 'customer';
    SET OutputRoot.Properties.MessageFormat = 'Text_CSV';
    SET Environment.Variables.custRec[] = InputRoot.MRM[];
    IF EXISTS(Environment.Variables.custRec[]) THEN
    CREATE FIELD OutputRoot.XMLNSC.customerDetails;
    DECLARE outRef REFERENCE TO OutputRoot.XMLNSC.customerDetails;
    FOR src AS Environment.Variables.custRec[] DO
    SET skuNo                         = Environment.Variables.custRec[i].customerDetails.skuNo;
    SET customerName = Environment.Variables.custRec[i].customerDetails.customerName;
    SET customerMobileNo = Environment.Variables.custRec[i].customerDetails.customerMobileNo;
    SET customerEmail = Environment.Variables.custRec[i].customerDetails.customerEmail;
    SET addressLine1 = Environment.Variables.custRec[i].customerDetails.addressLine1;
    SET addressLine2 = Environment.Variables.custRec[i].customerDetails.addressLine2;
    SET city     = Environment.Variables.custRec[i].customerDetails.city;
    SET zipcode     = Environment.Variables.custRec[i].customerDetails.zipcode;
    SET sqlStmt = 'INSERT INTO VENU_SALES(SKU_NO, CUSTOMER_NAME, CUSTOMER_MOBILE_NO, CUSTOMER_EMAIL, 
    ADDRESS_LINE1, ADDRESS_LINE2, CITY, ZIPCODE) VALUES (?, ?, ?, ?, ?, ?, ?, ?);';
    SET i = i + 1;
    PASSTHRU(sqlStmt, skuNo, customerName, customerMobileNo, customerEmail, addressLine1, 
    addressLine2, city, zipcode);
    END FOR;
    END IF;
    RETURN TRUE;
    END;
    END MODULE;



    ------------------------------
    venu gopal
    ------------------------------



  • 2.  RE: unable to perform iteration while parsing CSV Records

    Posted Thu June 01, 2023 02:33 PM
    Edited by Jim Berube Fri June 02, 2023 11:58 AM

    You're code is kind of all over the place here. First, you should use DFDL, not MRM. MRM has been deprecated for a number of years now. Second, you're using a FOR Loop, so use it. You don't need to copy the message into Environment.Variables unless you need this stored there for another purpose later, You can just iterate over the actual input message. Tree copies are expensive.

    CREATE FIELD OutputRoot.XMLNSC.customerDetails;
    DECLARE outRef REFERENCE TO OutputRoot.XMLNSC.customerDetails;
    FOR src AS Environment.Variables.custRec[] DO
    	SET skuNo = src.customerDetails.skuNo;
    	SET customerName = src.customerDetails.customerName;
    	SET customerMobileNo = src.customerDetails.customerMobileNo;
    	SET customerEmail = src.customerDetails.customerEmail;
    	SET addressLine1 = src.customerDetails.addressLine1;
    	SET addressLine2 = src.customerDetails.addressLine2;
    	SET city = src.customerDetails.city;
    	SET zipcode = src.customerDetails.zipcode;
    	SET sqlStmt = 'INSERT INTO VENU_SALES(SKU_NO, CUSTOMER_NAME, CUSTOMER_MOBILE_NO, CUSTOMER_EMAIL, ADDRESS_LINE1, ADDRESS_LINE2, CITY, ZIPCODE) VALUES (?, ?, ?, ?, ?, ?, ?, ?); ';
    	PASSTHRU(sqlStmt, skuNo, customerName, customerMobileNo, customerEmail, addressLine1,	addressLine2, city, zipcode);
    END FOR;

    I don't know why you're creating a field or declaring a reference to it, because it means nothing here, unless it's being used later in that code block that you didn't include.

    In the SET statements, you should be using "src" as what you're getting the data from, not Environment.Variables.custRec[], as the FOR Loop iterates over each row of data it finds and is giving you the built-in reference for it.

    I don't know if the "customerDetails" should be in there or not, as I don't know what the tree structure looks like there.

    There's no need for the index or to have  increase it.

    Have you validated that your locally created fields even contain data?

    I would argue that you could probably condense it down to this, as long as the paths to the data elements are correct.

    IF EXISTS(Environment.Variables.custRec[]) THEN
    	SET sqlStmt = 'INSERT INTO VENU_SALES(SKU_NO, CUSTOMER_NAME, CUSTOMER_MOBILE_NO, CUSTOMER_EMAIL, ADDRESS_LINE1, ADDRESS_LINE2, CITY, ZIPCODE) VALUES (?, ?, ?, ?, ?, ?, ?, ?); ';
    	FOR src AS Environment.Variables.custRec[] DO
    		PASSTHRU(sqlStmt, src.customerDetails.skuNo, src.customerDetails.customerName, src.customerDetails.customerMobileNo, src.customerDetails.customerEmail, src.customerDetails.addressLine1, src.customerDetails.addressLine2, src.customerDetails.city, src.customerDetails.zipcode);
    	END FOR;
    END IF;



    ------------------------------
    James E. (Jim) Berube
    Technical Account Manager (TAM) - Specialist, IBM Expertise Connect, IBM Expert Labs
    IBM Software
    ------------------------------