Skip to Content

Removing a row from a context

Hi Experts,

I have a issue here and need your suggestion.

My scenario is, i have a source file like following

<source_msg>

     <record>

          a

          b

          c

     </record>

     <record>

          1

          2

          3

     </record>

     <record>

          4

          5

          6

     </record>

     <record>

          7

          8

          9

     </record>

     <record>

          11

          12

          13

     </record>

.

.

.

.

</source_msg>

Now what the output should be, 1st there should be a new idoc (context change) for every 2 records, and the first record, containing alphabets, should not be created.

I created following udf to handle context change but couldn't remove the first context

int j=0;

for(int i=0; i<record.length; i++

{

result.addValue(record[i]);

if (j==2)

{

result.addContextChange();

j=0;

}

j++

}

Thanks for your reply...

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

4 Answers

  • Best Answer
    avatar image
    Former Member
    Jul 07, 2015 at 12:31 PM

    Hi Debtirtha,

    Please use the below udf code for splitting per 2 records.

    int a =0, b=0;

    a = (record.length)/(Integer.parseInt(num[0]));

    b = (record.length)%(Integer.parseInt(num[0]));

    if(b>0)

          a = a+1;

    for(;a>0;a--)

            result.addValue("");

    This is generic udf to split the messages as per num number, in your case 2.

    Map the output of this udf to the target IDOC node, which would solve your requirement of creating IDOC's per 2 records.

    Regarding your another query of suppressing the records having alphabets, can you be more specific by exactly what you mean by alphabets.

    Regards

    Vishnu

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Jul 07, 2015 at 09:17 AM

    Hi Debtirtha,

    try below code.

    int j = 0;

    for (int i=1, i<record.length; i++)

    {

         if (j==1)

         {

            result.addContextChange();

            j = 0;

         }

        

         result.addValue(record[i])

         j ++

    }

    Regards,

    SAnthi

    Add comment
    10|10000 characters needed characters exceeded

  • Jul 07, 2015 at 12:41 PM

    Hi Santhi and Vishnu,

    Thanks for your quick reply. It has been resolved now, i used following code

    int j=0;

    int k=0;

    for (int i=0; i<=record.length-1;i++)

    {

    k++;

    if (k==1)

    {

    result.addValue(ResultList.SUPPRESS);

    }

    else

      result.addValue(record[i]);

      if (j==2)

      {

      result.addContextChange();

    j=0;

      }

      j++;

    }

    to create the idoc i used a different udf connected to idoc node.

    thanks for your reply guys. really appreciate.

    regards,

    Debtirtha

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Jul 07, 2015 at 12:49 PM

    Debritha,

    Can you please reward points to the helpful replies.. 🤪

    Regards

    Vishnu

    Add comment
    10|10000 characters needed characters exceeded