cancel
Showing results for 
Search instead for 
Did you mean: 

novice in PI

Former Member
0 Kudos

Hi Everyone,

I am learning PI and currently working on UDF.

I am interface Z RFC to update the data from external system.

When the data is staged at XI i need to concatenate two fields and store into third in message mapping.

I am writing an UDF for this.

For example :

source structure.

emp_id

emp_name

emp_sal

date_time

first_name

last_name

gender

dept_id

target strucutre( strucutre in sap)

ZEMPID

ZEMPNAME

ZEMPSAL

ZDEPTID

ZDATE

ZTIME

I need the steps (including execution type ) to concatenate fields first_name and last_name into zempname in UDF only.

Can you pls give me the steps and code.

Regards,

Vinay

Accepted Solutions (0)

Answers (4)

Answers (4)

former_member183816
Active Participant
0 Kudos

Go through this u will fulfill ur requirement easily.

(Graphical mapping all functions)==>

http://help.sap.com/saphelp_nw04/helpdata/en/43/c4cdfc334824478090739c04c4a249/content.htm

Some more helpful links are....

Like where u can use UDF

User Defined Function==>

http://help.sap.com/saphelp_nwpi71/helpdata/EN/22/e127f28b572243b4324879c6bf05a0/content.htm

former_member189420
Active Participant
0 Kudos

Hello Vinay,

I believe this is for your understanding purpose as to how UDF works.

1. Create UDF with two input parameters of type string.

2. Type of the UDF be single value function.

3. Inside the UDF, you can use Java function concat with the input parameters and place the resultant into a String variable

4. Using the return statement return the resultant String variable.

After creating the UDF. The UDF appears along with the standard functions in the graphical editor.

Coming to the graphical mapping:

Use the source nodes first_name and last_name as input parameters for your UDF and the output of the UDF into the target field ZEMPNAME.

Prerequisite: You should know Java coding.

Hope it is clear.

Regards,

Anand Patil

Former Member
0 Kudos

Hi Anand,

The code is what i require..since i am new to java as well.

Regards,

Vinay

former_member518917
Participant
0 Kudos

Hey Vinay,

step 1: Create a UDF (concatString) with two input parameters (str1, str2) of type string.

step2: Inside the UDF, write code to concate the strings , and return the value.

Here, in this case, you just need to write a single line of code in udf. assuming two strings are separated by space " ".

public String concatString(String str1, String str2, Container container) throws StreamTransformationException

return str1+" " +str2;

Hope this help

Edited by: Ritu Sinha on Jan 6, 2011 5:16 PM

Former Member
0 Kudos

Hi,

Why to go for a UDF if u have standard function available??

But still if u want to use UDF:

Input will be var1 , var2...Execution type all values of a comtext.

String a =u201Du201D;

a= var1.concat (var2);

return a;

Thanks

Amit

Former Member
0 Kudos

Hi Amit,

I used the execution type as "All values of a Context"

my UDF method is as follows

public void jncalculate(String[] var1, String[] var2, ResultList result, Container container) throws StreamTransformationException{

String res="";

res = var1.concat(var2);

return res;

}

system throws the following error.

cannot find symbol symbol : method concat(java.lang.String[]) location: class java.lang.String[] res = var1.concat(var2); ^

Function jncalculate, Line 4:

cannot return a value from method whose result type is void return res; ^ Note: /usr/sap/DX1/DVEBMGS00/j2ee/cluster/server0/./temp/classpath_resolver/Map64de0d15198b11e0a6f80000003b5cae/source/com/sap/xi/tf/_MM_VK_EMP_RFC_IB_.java uses or overrides a deprecated API. Note: Recompile with -Xlint:deprecation for details. Note: /usr/sap/DX1/DVEBMGS00/j2ee/cluster/server0/./temp/classpath_resolver/Map64de0d15198b11e0a6f80000003b5cae/source/com/sap/xi/tf/_MM_VK_EMP_RFC_IB_.java uses unchecked or unsafe operations. Note: Recompile with -Xlint:unchecked for details. 2 errors

Regards,

Vinay

Former Member
0 Kudos

Correction...

Select Execution type as a "Single Value"...

By mistake i have mentioned it as "all values of a context".

Thanks

Amit

Former Member
0 Kudos

Its working... thanks..

By the way... can you give me in 2-3 sentences and examples about the various Execution type like single values...

etc.

I need to understand what this means.. so that i can use them in different scenarios.

Regards,

Vinay

Former Member
0 Kudos

Hi,

Chk this:

/people/rohit.kalugade/blog/2009/02/09/context-and-queue-in-message-mapping-udf-150-part2

http://wiki.sdn.sap.com/wiki/display/XI/UDFExecutionType-ContextandQueue.

Basically when u choose context and queues as execution type then u have play with more than one value for a filed.

Thanks

Amit

baskar_gopalakrishnan2
Active Contributor
0 Kudos

>>> need the steps (including execution type ) to concatenate fields first_name and last_name into zempname in UDF only.

This is pretty simple. Don't need UDF. Just use concat standard function

use first_name and last_name as input of concat and map the output to the zempname

MichalKrawczyk
Active Contributor
0 Kudos

Hi,

why an UDF ? use concat function from standard functions (text)

Regards,

Michal Krawczyk