on 06-09-2013 12:23 PM
Hi,
Can you kindly help me create a UDF for the following:
Structure:
<HeaderInformationFreeText>
<Text>Sample Text </Text>
<HeaderInformationFreeText>
Occurences:
HeaderInformationFreeText: 0...unbounded
Text: can only accommodate up to 70 characters; can occur only up to 5 times per HeaderInformationFreeText (up to 350 characters)
Example:
<HeaderInformationFreeText>
<TextTypeCode>AAI</TextTypeCode>
<Text>Conditions in this PO as price, quantity and delivery information</Text>
<Text> have to be confirmed through the Supplier Portal within the next </Text>
<Text>48hrs. *** If you are not a supplier using the Supplier Portal, </Text>
<Text>please submit confirmations or changes by email to the following </Text>
<Text>email address: poc onfirmation.im@pg.com or to the Buyer?s fax number</Text>
</HeaderInformationFreeText>
<HeaderInformationFreeText>
<TextTypeCode>AAI</TextTypeCode>
<Text>text 6</Text>
<Text>text 7</Text>
<Text>text 8</Text>
</HeaderInformationFreeText>
We need to need to “re-open” the HeaderInformationFreeText to accommodate the remaining Texts greater than 350 characters.
Hello,
Check this UDF:
Execution type: all values of a context
Input of type string : var1
ResultList = result
ResultList = result1
Mapping:
/-----Text
Input ------UDF----
\------HeaderInformationFreeText
if(!var1[0].equals(""))
{
int len = var1[0].length();
int divide = len/70;
int count =0;
String out = "";
int temp = 0;
if(len%70 == 0)
{
result1.addValue("");
for(int i=0;i<divide;i++)
{
temp = 70*i;
out = var1[0].substring (0+temp,70+temp);
result.addValue(out);
count= count+1;
if(count>=5)
{
result1.addValue("");
result.addContextChange();
count=0;
}
}
}
else
{
result1.addValue("");
for(int j=0;j<divide;j++)
{
temp = 70*j;
out = var1[0].substring (0+temp,70+temp);
result.addValue(out);
count= count+1;
if(count>=5)
{
result.addContextChange();
result1.addValue("");
count=0;
}
}
result.addValue (var1[0].substring (divide*70, len));
}
}
else
result.addSuppress();
Thanks
Amit Srivastava
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
hi Rod,
Your requirement is a bit tricky. I am assuming you have a source field which may be long text (more than 350 characters).
If I assume <HeaderInformationFreeText> is at target, you need to calculate source field length first through standard length function, divide by 350-> ceil (standard function) will give you number of times you need to create <HeaderInformationFreeText>.
For field <Text>, use the UDF below. It will have 3 parameters.
parameter 1 numberOfTimes- derived from source field length, divided by 70, ceil
parameter 2 maximumLength (constant 70)
paramter 3 sourceValue (this will be the source field value passed to the UDF)
__________________________________________________________________
int len = sourceValue[0].length();
int limit = Integer.parseInt(maximumLength[0]);
for (int i = 0; i < Integer.parseInt(numberOfTimes[0]); i++)
if (!(i == Integer.parseInt(numberOfTimes[0])-1))
result.addValue(sourceValue[0].substring(limit*i,limit*i+69));
else
result.addValue(sourceValue[0].substring(limit*i,len));
__________________________________________________________________
After the UDF, do a split by value and this should suffice your requirement.
Hope it works!
Ambrish
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Rod,
When you deal with IDoc TDLine's we need to split TD Line to 70 characters i think you are working on similar requirement, so you have to substring/UDF combination here
1)Duplicate Text at target side 5 times.
2)You have to make sure that your header text length always 350 characters,if length less than that then add remaining spaces.
Use below UDF code to handle this
StringBuffer s= new StringBuffer(var1);
int len=s.length();
int spaces=350-len;
for (int i=0;i<spaces;i++)
s.append(" ");
var1 = s.toString();
return var1;
Then create one variable at Target end and map like below
Headertext------>UDF----->Variable.
3) Use substring function to split the string
Varaiable holding header test value so
Variable----->substring(0,70)------>Text.
Variable--->substring(70,140)----->Text(duplicated segment)...like that map for 3 more duplicate sgements by changing substring value.
PS:Adding additional spaces will not cause any issue.
Thank you,
Raj
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I used Single Values for the Execution Type and the error disappears. I have a concern however:
So I used the following text as input for the target Text field which has 489 characters:
<TDLINE>Conditions in this PO as price, quantity and delivery information have to be confirmed through the Supplier Portal within the next 48hrs. *** If you are not a supplier using the Supplier Portal, please submit confirmations or changes by email to the following email address: poc onfirmation.im@pg.com or to the Buyer’s fax number below within the ne xt 24 hours. *** For additional questions regarding this order, please call to the cont act you have printed in this order. PREPAID AND ADD</TDLINE>
I also created a variable named textVariable and mapped like below:
TDLINE -> addSpaces UDF -> *textVariable
Then duplicated the Text subtree 5x and also the HeaderInformationFreeText as one header text tree only allows 350 characters.
Mapped each of the Text with their substring values. The resulting XML went fine until the Text value "please"
When I added another Text field to accommodate the remaining texts, it generated an exception:
Can you kindly advise?
I assume your structure shown is sender side and the example part is target structure you want to create. One simplest approach is to use java mapping. In java mapping, read the entire text in a string and use substring method to read up to 70 chars for five times and store them in the child element. If the entire text read string has still more values then you have to construct the next parent node and pass it to it's child node. You can search scn for the java mapping basic. Here is an example below
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
84 | |
10 | |
10 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.