cancel
Showing results for 
Search instead for 
Did you mean: 

How to COUNT all data Characters in an IDOC ?

Former Member
0 Kudos

Hi All,

I am doing an IDOC-->File scenario.

As per the Third party system requirements, I need to COUNT all the Data characters (Minus the EDIDC record) and write this value at the end of the trailer record in the file.

Example:
EDIDC--> SAPR3, LS...
E1KNA1M-->SHIRIN, UK, SW1DPL
E1KNBKM-->SHIRIN, CITIBANK

So in this example I should sum up(COUNT) all the characters(of Data) belonging to segment E1KNA1m and E1KNBKM. So here COUNT is '28'. So I need to write the value '28' at the end of the file.

I want to know, is it possible to count data in XI mapping or should this be done in R/3 itself and appended as a COUNT field to the IDOC.

Appreciate any suggestion help on this. All I want to know which is the best practise/place to count the data characters in this scenario.

Thanks

Shirin

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi,

Use String length method for Source field Write UDF and you will get the values as String Array then use String lenght method in udf.

Thanks,

RamuV

Former Member
0 Kudos

HI,

Using StringLength function, I defuinitely can get the length of the string. But since teher are multiple Strings(segments), I will need to store the previous string length somewhere and then add to it the next string length.

If I am right in above assumption, how do I do it. Is teher some global variable in XI wheer I can store the string length andkeep on adding/manipulating its value.

Regards

Shirin

Former Member
0 Kudos

Hi,

I tried a few combinations, but as mentioned earlier, I can count the characters only of one filed. How to count for all the fields of all the segments in Message mapping area.

Or any other idea is welcome.

Regards

Shirin

Former Member
0 Kudos

Hi Gurus,

I have still not been able to sort this issue out, except summing the values in SAP and then sending to XI.

I am trying to achieve this functionality in XI and not R/3.

Appreciate if you have UDF or any other method known, to count all characters in payload.

Many thanks

Shirin

Edited by: Shirin K on Jul 24, 2008 10:00 AM

santhosh_kumarv
Active Contributor
0 Kudos

Hi Shirin,

Folllow this.

1. Create a Global Variable: int len using the option Edit Java Section in Message Mapping and initialize it to 0.

2. Create a simple UDF.

public String calclen(String a,Container container)
{
len = len + a.length();
return a;
}

Map all ur source thru this UDF to the target. This UDF calculates and add the string length to the global variable.

3. Use this UDF to return the total string length in the final.

public String getlength(Container container)
{
String s = Integer.toString(len);
 return s;
}

Map this UDF to the target field.

Thanks

SaNv...

Former Member
0 Kudos

Hi,

Thanks for the reply.

Being a newbie, I have no idea where is JAVA section in MM. tried lookingh in forums, but they all talk of how to code but dont point wheer to start

And is the UDF complete( I mean cut and paste) as I do not have Java skills, I am looking for a cut and paste UDF .

Many thanks

Shirin

santhosh_kumarv
Active Contributor
0 Kudos

>>I have no idea where is JAVA section in MM

It is the last button to the right below the Design Tab

>>And is the UDF complete( I mean cut and paste) as I do not have Java skills, I am looking for a cut and paste UDF .

Add only the code i.e code with .

By Stefan grube's

Thanks

SaNv...

Former Member
0 Kudos

Hi,

Thanks for explaining.Really appreciated.

Just to confirm,

in Java edit Section I have added the following data: Please let me know if that is correct.

Imports:
Global Variables: len
Initilisation section: 0
Clean-up:

Similarly in UDF I have entered the following data:

Label/Description: Calculate length
Cache: Value(radiobutton)
Arguments: a

Next screen: 
Imports:
public String Calculate(String a, Container container)
Then entered ur code.

When I save and activate I get the following error

Starting compilation  Source code has syntax error:  D:/usr/sap/XRD/DVEBMGS02/j2ee/cluster/server0/./temp/classpath_resolver/Map2494b0c0596b11dda115001a4b52813a/source/com/sap/xi/tf/_MM_ALLOCATION_RESPONSE_.java:32: <identifier> expected public /*!_$ClNRep_*/_MM_ALLOCATION_RESPONSE_(){} ^ D:/usr/sap/XRD/DVEBMGS02/j2ee/cluster/server0/./temp/classpath_resolver/Map2494b0c0596b11dda115001a4b52813a/source/com/sap/xi/tf/_MM_ALLOCATION_RESPONSE_.java:210: ';' expected } ^ 2 errors

Appreciate if you could help.

Thanks

Shirin

santhosh_kumarv
Active Contributor

Answers (2)

Answers (2)

Former Member
0 Kudos

Thankyou.

You really have been patient and helpful.

Really appreciated.

Shirin

Former Member
0 Kudos

We can perhaps write a custom module in Java to count the number of characters for the preprocessing of the payload?