cancel
Showing results for 
Search instead for 
Did you mean: 

Need help with user defined function

Former Member
0 Kudos

Hello SDN,

I need some help with a user-defined function. My source message contains multiple

generic records (1000 char string), and my target message is 1 header record,

then multiple generic records. See description of source and target messages below:

Source:

GenericRecordTable 1..unbounded

Row (1000 char string)

Target:

Field1 (char5)

Field2 (char5)

Field3 (char5)

IT_Data

GenericRecordTable 1..unbounded

Row (1000 char string)

Basically, what I need to do in my user defined funtion is to map the first record

in my source record to the 3 header fields, then map all of the rest of the records

(starting from line 2) into the GenericRecordTable.

Can someone please help me with the code for the user defined function(s) for this

mapping?

Thank you.

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi,

If i have understood your question correctly then it can by achieved by using the substring function.

I mean take the required value from your Record (1000 char) by using substring and map it to your field1, field2 & field3. Like this for example.

Row (1000 char) -


> Substring (0, 5) -


> Field1.

Row (1000 char) -


> Substring (6, 11) -


> Field1.

Row (1000 char) -


> Substring (12, 17) -


> Field1.

IT_Data

GenericRecordTable 1..unbounded

Row (1000 char) -


> Substring (18, 1000) -


> Row (1000 char)

Please correct me if I have understood it wrong.

Regards,

Sarvesh

Former Member
0 Kudos

Hello, I don't think you understand how my source data looks like. See below.

aaaaabbbbbccccc

this is generic record line number 1

this is generic record line number 2

this is generic record line number 3

...

I am new to Java, so I need help with the coding of the UDF to read the first line in my source message and map it to the header fields in my target message. Then I think I will need a second UDF to read the other records starting from second line in my source message and map them to the table in my target message.

If you can help, I would really appreciate it.

Thank you.

Former Member
0 Kudos

Hello,

After working on this on my own for a while, I now have this solved.

Thanks,

Rhonda

Former Member
0 Kudos

hi,

Activities

1. To create a new user-defined function, in the data-flow editor, choose Create New Function (This

graphic is explained in the accompanying text), which is located on the lower left-hand side of the

screen. In the menu, choose Simple Function or Advanced Function.

2. In the window that appears, specify the attributes of the new function:

Name

Technical name of the function. The name is displayed in the function chooser and on the data-flow

object.

Description

Description of how the function is used.

Cache

Function type (see above)

Argument Count

In this table, you specify the number of input values the function can process, and name them. All

functions are of type String.

3. In the window that appears, you can create Java source code:

...

a. You can import Java packages to your methods from the Imports input field, by specifying them

separated by a comma or semi-colon:

You do not need to import the packages java.lang., java.util., java.io., and java.lang.reflect. since

all message mappings require these packages and therefore import them. You should be able to

access standard JDK and J2EE packages of the SAP Web Application Server by simply specifying the

package under Import. In other words, you do not have to import it as an archive into the Integration

Repository. You can also access classes of the SAP XML Toolkit, the SAP Java Connector, and the

SAP Logging Service (see also: Runtime Environment (Java-Mappings)).

In addition to the standard packages, you can also specify Java packages that you have imported as

archives and that are located in the same, or in an underlying software component version as the

message mapping.

b. Create your Java source text in the editor window or copy source text from another editor.

4. Confirm with Save and Close.

5. User-defined functions are limited to the message mapping in which you created the function. To

save the new function, save the message mapping.

6. To test the function, use the test environment.

The new function is now visible in the User-Defined function category. When you select this category,

a corresponding button is displayed in the function chooser pushbutton bar. To edit, delete, or add the

function to the data-flow editor, choose the arrow next to the button and select from the list box

displayed.

http://help.sap.com/saphelp_nw04/helpdata/en/d9/718e40496f6f1de10000000a1550b0/content.htm

http://java.sun.com/j2se/1.5.0/docs/api/

/people/krishna.moorthyp/blog/2006/07/29/documentation-html-editor-in-xi

/people/sap.user72/blog/2006/02/06/xi-mapping-tool-exports

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

UDF -

http://help.sap.com/saphelp_nw04/helpdata/en/22/e127f28b572243b4324879c6bf05a0/content.htm

Regards

Former Member
0 Kudos

Thanks, but I really need help with the coding inside the function.