cancel
Showing results for 
Search instead for 
Did you mean: 

Counter in Flat file

Former Member
0 Kudos

Hi All,

In my IDOC there are three item segements E1J3AIT, E1J3AIS, E1TXTH9.They are linked to three different structures SI1, SI2, SI3. I am creating a flat file.

In the target structure there is one common field counter. Now if my first segment has 3 items, 2nd segment has two items and if my 3rd segment has 3items my counter field in my output should start from 0 and end with 8. How can I achieve this? Your help will be highly appreciated.

korobee

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi,

As shabharish said just set the context of the three segments to top most level and wirte a small udf

take the message type as the input and select the context in the UDF

write this sample code

int count=0;

for(int i=0;i<=a.length;i++)

{

count=count+1;

}

result.addValue(""+count);

And map the output of the UDF with the target.

try this

cheers

jithesh

Former Member
0 Kudos

Shabarish and Jitesh,

Also can you please tell me whether I have to import any library when I write the function?

korobee

Former Member
0 Kudos

Hi Korobee,

No need to import any libraries. It is just a simple User Defined Function

cheers,

Prashanth

Shabarish_Nair
Active Contributor
0 Kudos

no libraries needed...

can u paste the exception message here ...

Shabarish_Nair
Active Contributor
0 Kudos

Ok when u CREATE the UDF use the CONTEXT option and then proceed ....

Former Member
0 Kudos

Shabarish

<i>Ok when u CREATE the UDF use the CONTEXT option and then proceed .... </i> can you tell me what do you mean by this.

What I have done is I have created the UDF and I have the three segments as inputs and changed the context. Then I have checked for the display queue. Then I got this error?

---korobee

Former Member
0 Kudos

Shabarish

Now I got you shabarish. You mean to say that when defining a UDF I have to go for the context option. So now i have copied your code and pasted in the UDF. Now when I use the function in my mapping I am getting the total count ie., 8 but I want to have a counter like 1,2,3,4,5,6,7,8.

Can you tell me where should I change to have this output?

---korobee

Shabarish_Nair
Active Contributor
0 Kudos

that is when u create your UDF it asks for 3 radio buttons,

CACHE : Value, Context and Queue -> select Queue in this case.

Former Member
0 Kudos

Shabarish

When I done like that it gives me a total count 8 for the first item in the target and no value for the other items. I think it is giving total no. of lines in my output. Can you please help me in resolving this?

korobee

Shabarish_Nair
Active Contributor
0 Kudos

well try n use a UDF.

Remember to set the context of the input nodes to the top most parent (maybe ur message type itself)

eg code...

public void count(String[] a, String[] b, String[] c, ResultList result,Container container)

{

//write your code here

int i = 0;

int j = 0;

int k = 0;

i = a.length;

j = b.length;

k = c.length;

i = ijk;

String val = String.valueOf(i);

result.addValue(val);

}

Message was edited by: Shabarish Vijayakumar

Former Member
0 Kudos

Shabarish,

According to your reply what I have done is I have created a new user defined function count with three string arguments a, b and c.

Now I have copied your code into it. Then I have taken the function into my mapping editor area. It has one output and that I have linked it to my output field. But my function has three inputs. If I give the input as my three segements E1J3AIT, E1J3AIS and E1TXTH9 it throws me an exception.

So can you tell me what do u mean by <i>Remember to set the context of the input nodes to the top most parent (maybe ur message type itself)</i>.

Your help will be appreciated.

korobee

Shabarish_Nair
Active Contributor
0 Kudos

So can you tell me what do u mean by Remember to set the context of the input nodes to the top most parent (maybe ur message type itself). >>>

in your mapping once you map those fields to the count field using the UDF, right click the input elements and using the context chk the top most context (prefer the Message Type name itself there)

CHK>> /people/riyaz.sayyad/blog/2006/04/23/introduction-to-context-handling-in-message-mapping

/people/venkat.donela/blog/2005/06/09/introduction-to-queues-in-message-mapping

and wht is the exception you are getting ?

Former Member
0 Kudos

Shabarish

So you mean to say that to count field I have to map my three segments and I have to change the context. Now I have done like what you have told and changed the context to my IDOC and then I have got errors when I displayed the queue. The errors are:

Source code has syntax error: /usr/sap/JXD/DVEBMGS00/j2ee/cluster/server0/./temp/classpath_resolver/Map0c9da750126f11dbbfb1001125a6cdc6/source/com/sap/xi/tf/_MM_DELVRY03_to_PickTicket_.java:617: cannot resolve symbol symbol : class integer location: class com.sap.xi.tf._MM_DELVRY03_to_PickTicket_ integer counter; ^ /usr/sap/JXD/DVEBMGS00/j2ee/cluster/server0/./temp/classpath_resolver/Map0c9da750126f11dbbfb1001125a6cdc6/source/com/sap/xi/tf/_MM_DELVRY03_to_PickTicket_.java:3249: cannot resolve symbol symbol : variable length location: class java.lang.String i = a.length; ^ /usr/sap/JXD/DVEBMGS00/j2ee/cluster/server0/./temp/classpath_resolver/Map0c9da750126f11dbbfb1001125a6cdc6/source/com/sap/xi/tf/_MM_DELVRY03_to_PickTicket_.java:3250: cannot resolve symbol symbol : variable length location: class java.lang.String j = b.length; ^ /usr/sap/JXD/DVEBMGS00/j2ee/cluster/server0/./temp/classpath_resolver/Map0c9da750126f11dbbfb1001125a6cdc6/source/com/sap/xi/tf/_MM_DELVRY03_to_PickTicket_.java:3251: cannot resolve symbol symbol : variable length location: class java.lang.String k = c.length; ^ /usr/sap/JXD/DVEBMGS00/j2ee/cluster/server0/./temp/classpath_resolver/Map0c9da750126f11dbbfb1001125a6cdc6/source/com/sap/xi/tf/_MM_DELVRY03_to_PickTicket_.java:3256: cannot resolve symbol symbol : variable result location: class com.sap.xi.tf._MM_DELVRY03_to_PickTicket_ result.addValue(val); ^ 5 errors

korobee