cancel
Showing results for 
Search instead for 
Did you mean: 

Dynamically count the field

Former Member
0 Kudos
68

I have a scenario where the target field of one idoc segment should get populated ie. field should count how many other different segments are generated in the target.for example

segment A comes to 2 times then say field of segment C should be 2 in the target

Accepted Solutions (0)

Answers (4)

Answers (4)

Former Member
0 Kudos

Hi Guys thanks for the answers.

Former Member
0 Kudos

You can use the following UDF's for increment and initialisation of the counter

Increment the Global Variable Counter

public String incrementCounter(String a,Container container){

//write your code here

if(a.equals(" "))

{

Object o = container.getGlobalContainer().getParameter("CNTR");

Integer ii;

if( o == null ) ii = new Integer(0);

else ii = (Integer)o;

ii = new Integer( ii.intValue() + 1);

container.getGlobalContainer().setParameter("CNTR", ii);

String temp = ii.toString();

return temp;

}

else return " ";

<b>Intialise the Counter</b>

Object o = container.getGlobalContainer().getParameter("CNTR");

Integer ii = new Integer(0);;

container.getGlobalContainer().setParameter("CNTR", ii);

return "1";

Former Member
0 Kudos

Arijit,

You can use the function "Count" here....assign "A" as input to function count..it will return you number of "A" segments in payload.

Nilesh

justin_santhanam
Active Contributor
0 Kudos

Guha,

Could you give the sample input/output payload? It could be easy for us to suggest.

Best regards,

raj.

Former Member
0 Kudos

I am giving an example:

the input file contains: The target field

E1EDK01 GLN : 2

PARTNER_ID

E1EDK01

PARTNER_ID

ie based on how many that particular segment is present in the payload the target field should count the value.For this case the E1EDK01 segment is present two times.

Former Member
0 Kudos

Could you please explain a bit more in detail. Or answer the following question.

1. Is IDOC sender or receiver.

2. What is the field that requiers the counting. Based on what it should count. like as you explained if a segment repeats twice you want to get 2 as output?

Former Member
0 Kudos

Hi,

Map your E1EDK01 segment with "Count" node function and to the target side field you want to catch value.

Don't forget to set Context of E1EdK01 to IDOC.

Regards,

Akshay.

    • Also dont forget to give points