cancel
Showing results for 
Search instead for 
Did you mean: 

Regarding udf

Former Member
0 Kudos

Hi All,

Can any body give me the code for below logic.

Logic is From the source field Plant i am getting two characters for which we have to add

two more characters(i.e contry code) and send it to target field.But this country code

is available in the filename.

USPCSSC20090609122334 is the filename.

US is the countrycode for which we have to capture and add it to the plant field and send it to the target field.

So we have capture the countrycode dynamically so that this interface works fine for all countrys.

Good points will be given.

Thanks

Accepted Solutions (0)

Answers (9)

Answers (9)

Former Member
0 Kudos

Hi suraj,

yes there are two other udfs used in MM.

former_member187339
Active Contributor
0 Kudos

Hi,

Either paste the code here or see whether the { (Brackets) are matched }

Regards

Suraj

Former Member
0 Kudos

hi suraj,

Tried both returns but showing same errors while activating the MM

former_member187339
Active Contributor
0 Kudos

Hi,

Is there any other udf used? Make sure you have all other udfs (such as init, cleanUp etc) as blank in the Function tab of Message Mapping

Don't try test it in the test tab of Message Mapping , as the value FileName will be available only at runtime

Regards

Suraj

Former Member
0 Kudos

hi suraj,

public String DynamicFileName(String plant, Container container) throws StreamTransformationException{

DynamicConfiguration conf = (DynamicConfiguration) container

.getTransformationParameters().get(StreamTransformationConstants.DYNAMIC_CONFIGURATION);

DynamicConfigurationKey key = DynamicConfigurationKey.create("http://sap.com/xi/XI/System/File","FileName");

String filename = conf.get(key);

return filename.substring(0,1)+plant;

}

this is the code used in udf

former_member187339
Active Contributor
0 Kudos

Hi,

Try this


public String DynamicFileName(String plant, Container container) throws StreamTransformationException{

DynamicConfiguration conf = (DynamicConfiguration) container
.getTransformationParameters().get(StreamTransformationConstants.DYNAMIC_CONFIGURATION);

DynamicConfigurationKey key = DynamicConfigurationKey.create("http://sap.com/xi/XI/System/File","FileName");
String filename = conf.get(key);
*return (filename.substring(0,1)+plant);*
}

Change return (filename.substring(0,1)+plant);

or better use return ((filename.substring(0,1)).concat(plant));

Regards

Suraj

Edited by: S.R.Suraj on Sep 16, 2009 6:28 AM

Former Member
0 Kudos

hi

I am getting these errors in mapping when i tried to activate the mapping

Function init, Line 1:

'class' or 'interface' expected public void init(GlobalContainer container) throws StreamTransformationException{ ^

com/sap/xi/tf/_InventoryData_To_ZINV_SYNC_MM_.java[207] 'class' or 'interface' expected public static void main(String[] args) throws Exception{/!_$ClNRep_/_InventoryData_To_ZINV_SYNC_MM_ st = new /!_$ClNRep_/_InventoryData_To_ZINV_SYNC_MM_(); st.testExecute(); } ^

com/sap/xi/tf/_InventoryData_To_ZINV_SYNC_MM_.java[208] 'class' or 'interface' expected } ^

com/sap/xi/tf/_InventoryData_To_ZINV_SYNC_MM_.java[209] 'class' or 'interface' expected ^ 4 errors

former_member187339
Active Contributor
0 Kudos

Hi,

Can you paste here the complete code of UDF which you are using. I think some { (brackets) are missing

Regards

Suraj

Former Member
0 Kudos

return filename.substring(0,1)+plant;

change the above code as follows


return filename.substring(0,2)+plant;

public String substring(int beginIndex,

int endIndex)


Returns a new string that is a substring of this string. The substring begins at the specified beginIndex and extends to the character at index endIndex - 1. Thus the length of the substring is endIndex-beginIndex. 

Example:

"USPCSSC20090609122334".substring(0, 2) returns "US"

Former Member
0 Kudos

Thanks suraj,

So i will create udf with one argument i.e plant so code will be

public String DynamicFileName(String plant, Container container) throws StreamTransformationException{

DynamicConfiguration conf = (DynamicConfiguration) container

.getTransformationParameters().get(StreamTransformationConstants.DYNAMIC_CONFIGURATION);

DynamicConfigurationKey key = DynamicConfigurationKey.create("http://sap.com/xi/XI/System/File","FileName");

String filename = conf.get(key);

return filename.substring(0,1)+plant;

}

IN MM

Plant -> DynamicfileName->Target file

Is this right

former_member187339
Active Contributor
0 Kudos

Hi,

suppose your plant = "PLANT"

>>return filename.substring(0,1)+plant;

will give an output like USPLANT

>>return (filename.substring(0,1)+plant.substring(0,1));

will give output like USPL

Which one you want?

>>IN MM Plant -> DynamicfileName->Target file

This is correct

Regards

Suraj

Former Member
0 Kudos

create a UDF with one argument plant


DynamicConfiguration conf = (DynamicConfiguration) container
    .getTransformationParameters().get(StreamTransformationConstants.DYNAMIC_CONFIGURATION);
 
DynamicConfigurationKey key = DynamicConfigurationKey.create("http://sap.com/xi/XI/System/File","FileName");
String filename = conf.get(key);
return filename.substring(0,2)+plant;
}

plant(SourceField)--->UDF---->Target field

select use adapter specific identifiers in the sender communication channel and select filename

Former Member
0 Kudos

Thanks suraj

I will try with this code.But countrycode should be added before the plantfield two characters.

rajasekhar_reddy14
Active Contributor
0 Kudos

Try this code, i hope it will work,if little modification required to accordigly,

Take first argument plant,that is your source filed from source message,then get the file name using Dynamic configuration,then use substing function to get the first two values from Filaname,

finally append the Ccode with Plat,

retrunt this one ,

String Ccode;

public String DynamicFileName(Container container) throws StreamTransformationEx {

DynamicConfiguration conf = (DynamicConfiguration) container

.getTransformationParameters().get(StreamTransformationConstants.DYNAMIC_CONFIGURATION);

DynamicConfigurationKey key = DynamicConfigurationKey.create("http://sap.com/xi/XI/System/File","FileName");

String valueOld = conf.get(key);

Ccode=valueold.substring(2);

Result = Ccode + Plant;

return Result;

}

I have complied the code,but this logic work fine..

Cheers,

Raj

former_member187339
Active Contributor
0 Kudos

Hi,

Then your mapping will be

FileName UDF take its Substring (0,2) and concat with Plant Field Substring (0,2)

Regards

Suraj

former_member187339
Active Contributor
0 Kudos

Hi,

Get the file name using this UDF


public String DynamicFileName(Container container) throws StreamTransformationEx {
DynamicConfiguration conf = (DynamicConfiguration) container
    .getTransformationParameters().get(StreamTransformationConstants.DYNAMIC_CONFIGURATION);

DynamicConfigurationKey key = DynamicConfigurationKey.create("http://sap.com/xi/XI/System/File","FileName");
String valueOld = conf.get(key);
return valueOld;
}

Do a sub string to get first two characters and append with source field

Make sure use set the use adapter specific identifiers in the sender communication channel and select filename

Hope this helps

Regards

Suraj