cancel
Showing results for 
Search instead for 
Did you mean: 

UDF to create (or not) nodes

Former Member
0 Kudos

HI,

my target is to create a node for every item(wich belongs to the right header-ordernumber) in my source mapping. But sometimes there is no <pos> for a specific header(i.e. ordernumber 222)

Sourcemessage-Structure: (RFC CONTROL_RECIPE_DOWNLOAD)

<head>

<Ordernumber>111

<Ordernumber>222

</head>

<pos>

<ordernumber_pos>111

<ordernumberpos>10

<posdata>xxx

</pos>

<pos>

<ordernumber_pos>111

<ordernumberpos>20

<posdata>yyy

</pos>

1. Do you have an UDF example to reach this ?

I think i have to loop over all <pos> to find the right one(maybe concat ordernumber an pos) .

2. Which returnvalue is used to avoid creating a node ?

Thx,

Gordon

Edited by: Gordon Breuer on Apr 13, 2011 2:01 PM

Accepted Solutions (0)

Answers (3)

Answers (3)

Former Member
0 Kudos

As you said for each pos you need to create one target node, so in this case there will be 2 nodes..can you give one example where your scenario is failing.. also let me know if source message can come as mentioned below.. the last pos 555 is not present under header-->Ordernumber. If this is not the case then you will not require any udf hopefully.

<head>

<Ordernumber>111

<Ordernumber>222

</head>

<pos>

<ordernumber_pos>111

<ordernumberpos>10

<posdata>xxx

</pos>

<pos>

<ordernumber_pos>111

<ordernumberpos>20

<posdata>yyy

</pos>

<pos>

<ordernumber_pos>555

<ordernumberpos>10

<posdata>zzz

</pos>

Former Member
0 Kudos

Ups,

that was a typo error.

I need a node for every

ideas ?

Former Member
0 Kudos

I got your point, just one calrification to know if below mentioned message can heppen and then you don't need to create any node??

<head>

<Ordernumber>111

<Ordernumber>222

</head>

<pos>

<ordernumber_pos>555

<ordernumberpos>10

<posdata>zzz

</pos>

Former Member
0 Kudos

No, there are only <pos> for existing ordernumbers.

thx,

Gordon

Former Member
0 Kudos

Then I don't think you need any UDF for this.. it is just you need to set the context coreclty that's it.

Provide an example with source and desired output where your mapping is not giving expected results.

Former Member
0 Kudos

Do you have an example for the graphical mapping (with the correct context) ?

Former Member
0 Kudos

You can go thorugh this blog for to understanding the context handeling concept (look into sap help to read more) but setting the desired context depends on case to case that's why I asked you to provide an example.

/people/riyaz.sayyad/blog/2006/04/23/introduction-to-context-handling-in-message-mapping

Former Member
0 Kudos

Hi Gordon,

This is achievable. Please do the following:

Create an UDF of type All values of Queue.

Have three arguements, first Ordernumber, second ordernumber_pos, third removeContext(count(Ordernumber))

In the UDF,

int counter = var3.length;

for(int i =0; i<counter ;i++)

{

for (int j = 0; j < counter; j++)

{

if (var1<i> == var2[j])

{

result.addValue(" ");

result.addContextChange(); // - check if this line is required during testing, if context required keep it, else remove this line

}

}

}

Change the i & j start and end conditions based on your understanding

>> Which returnvalue is used to avoid creating a node ?

Just use return statement if u dont wish to create a node. Or if inside a for loop, use continue statement to skip adding result.addValue() step. It will go the next value of the loop.

Cheers,

Souvik

Edited by: Souvik Chatterjee on Apr 13, 2011 6:14 PM

Former Member
0 Kudos

Hi,

You can create a UDF with 2 input fields for orderNumber and orderNumber_pos. For the orderNumber_pos, use a mapWithDefault so that you get the missing nodes in your UDF.

Then in the code, use a for loop to iterate through the two input arrays to create the ouput. Create the UDF as a queue function.

Regards

Former Member
0 Kudos

you´re right but in case there is no what value is transported to the resultvalue ?

any value = node will be created!