cancel
Showing results for 
Search instead for 
Did you mean: 

Removing a row from a context

0 Kudos

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...

Accepted Solutions (1)

Accepted Solutions (1)

pvishnuvardan_reddy
Active Contributor
0 Kudos

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

Answers (3)

Answers (3)

pvishnuvardan_reddy
Active Contributor
0 Kudos

Debritha,

Can you please reward points to the helpful replies..

Regards

Vishnu

0 Kudos

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

Former Member
0 Kudos

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