cancel
Showing results for 
Search instead for 
Did you mean: 

Need User Defined Function sample

Former Member
0 Kudos

Hi -

I have the following question - here is the mapping of an unbounded tag <Line> in the source and a segment TDLINE in the idoc as follows.

Line 1 .. unbounded ( source )

E1EDKT2 0 .. 99999999999

Segment required

TDLINE 0 ..1

TDFORMAT 0 ..1

My problem is I need for each Line tag to write out to a new TDLINE - but as I duplicate the E1EDKT2 to the max of 4 - I get the first <Line> text in each of the TDLINE

Here is a sample of the input and output ...

INPUT

<Message><OrderItemId>27036336</OrderItemId><To>A</To><From>B</From><Line>This is a test message. It should be split up into multiple </Line><Line>lines with a length less than 200 characters. -- Thank you</Line></Message></Messages></OrderHeader>

OUTPUT

<E1EDKT1 SEGMENT="1"><TDID>ZGCD</TDID><TSSPRAS>EN</TSSPRAS><E1EDKT2 SEGMENT=""><TDLINE> </TDLINE><TDFORMAT>*</TDFORMAT></E1EDKT2><E1EDKT2 SEGMENT=""><TDLINE>A</TDLINE><TDFORMAT>/=</TDFORMAT></E1EDKT2><E1EDKT2 SEGMENT=""><TDLINE>B</TDLINE><TDFORMAT>/=</TDFORMAT></E1EDKT2><E1EDKT2 SEGMENT=""><TDLINE>This is a test message. It should be split up into multiple </TDLINE><TDFORMAT>/=</TDFORMAT></E1EDKT2><E1EDKT2 SEGMENT=""><TDLINE>This is a test postcard message. It should be split up into multiple </TDLINE><TDFORMAT>/=</TDFORMAT></E1EDKT2></E1EDKT1>

Any help would be greatly appreciated!

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos
Former Member
0 Kudos

Ok thanks - mine looks exactly that way, however when I run a check on my map I still am getting the following error. What should the two UDF's look like are my earlier posts correct for those? Do I need to do anything to identify the global variable? The error message says something about a class or interface ...

Check Result for Object MM_xxxxxx_order_XX Source code has syntax error: /usr/sap/xxx/DVEBMGS00/j2ee/cluster/server0/./temp/classpath_resolver/Mapec19bd704c6511dcc364001125c52e50/source/com/sap/xi/tf/_MM_xxxxxx_order_XX_.java:1066: 'class' or 'interface' expected public String UDFRetrieveText$(Container container){ ^ /usr/sap/xxx/DVEBMGS00/j2ee/cluster/server0/./temp/classpath_resolver/Mapec19bd704c6511dcc364001125c52e50/source/com/sap/xi/tf/_MM_xxxxxx_order_XX_.java:1070: 'class' or 'interface' expected } ^ /usr/sap/xxx/DVEBMGS00/j2ee/cluster/server0/./temp/classpath_resolver/Mapec19bd704c6511dcc364001125c52e50/source/com/sap/xi/tf/_MM_xxxxxx_order_XX_.java:1090: 'class' or 'interface' expected ^ 3 errors

Former Member
0 Kudos

Thanks! It worked. I had an extra ending } ( forgot that XI assigns the beginning and ending {}

Answers (8)

Answers (8)

Former Member
0 Kudos

copy and paste the code of the function UDFRetrieveText. That's an odd error, I think it would have something to do with the syntax of your UDF.

Former Member
0 Kudos

Store UDF

Public string UDFStoreText(String a,Container container){

storeText = a;

return a;

}

Retrieve UDF

Public string UDFRetrieveText(Container container){

return storeText;

}

Former Member
0 Kudos

You mentioned a "global Variable" how do I define this - maybe that's the problem?

Former Member
0 Kudos

definately the problem,

right under the design tab in mapping, theres a edit java sections button, in there you can define global variables

Also, if my solution does not work, I would like other people to give you possible solutions. I figured out a way to handle this, but it's a little tedious, and I believe there might be a better solution, but if no one can help you, I'll guide you through it.

Former Member
0 Kudos

Ok I defined the global varialbe in the java section as

String storeText = null;

But I am still getting the following error ...

Source code has syntax error: /usr/sap/xxx/DVEBMGS00/j2ee/cluster/server0/./temp/classpath_resolver/Map56034bb04c3011dc91a4001125c52e50/source/com/sap/xi/tf/_MM_order_FC_.java:1065: 'class' or 'interface' expected public String UDFRetrieveText$(Container container){ ^ /usr/sap/xxx/DVEBMGS00/j2ee/cluster/server0/./temp/classpath_resolver/Map56034bb04c3011dc91a4001125c52e50/source/com/sap/xi/tf/_MM_order_FC_.java:1069: 'class' or 'interface' expected } ^ /usr/sap/xxx/DVEBMGS00/j2ee/cluster/server0/./temp/classpath_resolver/Map56034bb04c3011dc91a4001125c52e50/source/com/sap/xi/tf/_MM_order_FC_.java:1089: 'class' or 'interface' expected ^ 3 errors

Former Member
0 Kudos

In the global variables part of the definitions you will need to write it as String storText; you shouldn't define what variables are in the global variables part.

If you want, in the initialization window, you can also put storeText = null; but this is not needed.

Former Member
0 Kudos

It even worked for the mapping issue you had?

Former Member
0 Kudos

Yes! Like a charm.

Thanks!

Former Member
0 Kudos

You might be able to make my above code work by applying the UseOneAsMany function on the rest of the entries, but I'm not sure.

Former Member
0 Kudos

Looking at the example you have above for code makes this more complicated than I thought, that code I provided above may or may not work. This is an interesting problem though, I want to look into it more.

Former Member
0 Kudos

Easy solution:

Create global variable: String storeZ;

Create UDFStoreZ with code

public String UDFStoreZ(String a, Container...){

storeZ = a;

return a;

}

Create UDFRetreiveZ with no inputs and code

public String UDFRetreiveZ(Container...){

return storeZ;

}

Map:

line -


> UDFStoreZ -


>E1EDKT2

UDFRetreiveZ---->Segment

UDFRetreiveZ---->TDLINE

points if it works thanks

Former Member
0 Kudos

Hi Thanks- I am trying this but seems I am getting a syntax error. Any suggestions - here is the error.

Source code has syntax error: /usr/sap/xxx/DVEBMGS00/j2ee/cluster/server0/./temp/classpath_resolver/Map74067fd04c0611dc8609001125c52e50/source/com/sap/xi/tf/_MM_xxxxx_order_FC_.java:1064: 'class' or 'interface' expected public String UDFRetrieveText$(Container container){ ^ /usr/sap/xxx/DVEBMGS00/j2ee/cluster/server0/./temp/classpath_resolver/Map74067fd04c0611dc8609001125c52e50/source/com/sap/xi/tf/_MM_xxxxx_order_FC_.java:1068: 'class' or 'interface' expected } ^ /usr/sap/xxx/DVEBMGS00/j2ee/cluster/server0/./temp/classpath_resolver/Map74067fd04c0611dc8609001125c52e50/source/com/sap/xi/tf/_MM_xxxxx_order_FC_.java:1088: 'class' or 'interface' expected ^ 3 errors

Message was edited by:

SA

Former Member
0 Kudos

I think that the problem why this solution will not work is because of the structure - I have to deal with sort of a flat strucure where the number of Line tags is multiple but the Messages is only one. See below :

<OrderHeader>

<OrderID>orderid</OrderID>

<StoreID>storeid</StoreID>

<CustomerID>customreabc</CustomerID>

<Currency>USD</Currency>

<OrderCharges>

<TotalProductPrice currency="USD">675.00000</TotalProductPrice>

<TotalAdjustment currency="USD">0.00000</TotalAdjustment>

<TotalShippingCharge currency="USD">14.95000</TotalShippingCharge>

<TotalSalesTax currency="USD">56.36000</TotalSalesTax>

<TotalShippingTax currency="USD">0.00000</TotalShippingTax>

</OrderCharges>

<BillingAddressInfo>

<AddressLine1>3966 Davila Dr</AddressLine1>

<AddressLine2 xsi:nil="true" />

<AddressLine3 xsi:nil="true" />

<City>Dallas</City>

<StateOrProvinceName>SD</StateOrProvinceName>

<Country>United States</Country>

<PostalCode>77777</PostalCode>

<Telephone>9899899898</Telephone>

<Email>email@emai..com</Email>

<LastName>doe</LastName>

<FirstName>joe</FirstName>

</BillingAddressInfo>

<PlacedDate>2007-03-12</PlacedDate>

<PlacedDateTime>2007-03-12 10:31:57.378</PlacedDateTime>

<Messages>

<Message>

<To>A</To>

<From>B</From>

<Line>this is a string of text that</Line> <Line>must be continued on the next line</Line> <Line> and must write out to the appropriate segments</Line>

</Message>

</Messages>

</OrderHeader>

justin_santhanam
Active Contributor
0 Kudos

SA,

Could you tell us from the source u need only <Line> elements or <To> /<From> elements also?

Best regards,

raj.

Former Member
0 Kudos

Hi thanks to both but I have already tried both of these things. I have duplicated subtree 4 times on my segment containing TDLINE - and I have tried the split by value function between <Line> and TDLINE It continues to only capture the first <Line> Any other suggestions?

justin_santhanam
Active Contributor
0 Kudos

Hey,

I'm sure it will work. Did u changed the context to higher level.

Best regards,

raj.

justin_santhanam
Active Contributor
0 Kudos

Hello,

Can u confirm whether the structure and results are as u expected.

http://www.flickr.com/photo_zoom.gne?id=1130020000&size=o

Best regards,

raj.

justin_santhanam
Active Contributor
0 Kudos

Hey,

UDF not needed.

Line 1(Change Context to higher level)--> SplitByValue(Each Value)--> TDLINE

Try this and let us know.

Best regards,

raj.

Former Member
0 Kudos

hi

If i am notg worng what you want is to map the line to TDLINE.

fo this you will have to replicate the segment E1EDKT2 number of times the line element appears .

so you will map line to E1EDKT2 and also to TDLINE

Hope this helps

Nikhil