on 04-08-2015 5:20 AM
hi all,
i've a source structure and target structure which looks like this below
<L_PO1>
<S_PO1>
<D_330>30</D_330>
<D_355>BD</D_355>
<D_235>BP</D_235>
<D_234>MAT1</D_234>
</S_PO1>
<L_PID>
<S_PID>
<D_349>F</D_349>
<D_352>description which can have length 140 characters max</D_352>
</S_PID>
</L_PID>
<L_PID>
<S_PID>
<D_349>F</D_349>
<D_352>another description for the same MAT1 which also can have max 140 char</D_352>
</S_PID>
</L_PID>
</L_PO1>
The target structure is a IDOC orders and it should look like this below after the mapping of item level segment
<E1EDP01 SEGMENT="1">
<MENGE>30</MENGE>
<MENEE>BD</MENEE>
<E1EDP19 SEGMENT="1">
<QUALF>001</QUALF>
<IDTNR>MAT1</IDTNR>
</E1EDP19>
<E1EDPT1 SEGMENT="1">
<TDID>Z001</TDID>
<TSSPRAS>E</TSSPRAS>
<E1EDPT2 SEGMENT="1">
<TDLINE>take first 70 characters of the description</TDLINE> "if the description is greater than 70 characters
<TDFORMAT>/</TDFORMAT>
</E1EDPT2>
<E1EDPT2 SEGMENT="1">
<TDLINE>remaining 70 characters or less from the description</TDLINE> "create a new TDLINE with a new context of E1EDPT2.
<TDFORMAT>/</TDFORMAT>
</E1EDPT2>
<E1EDPT2 SEGMENT="1">
<TDLINE>this description is not greater than 70 characters</TDLINE> " no need to split because it's not more than 70 characters.
<TDFORMAT>/</TDFORMAT>
</E1EDPT2>
</E1EDPT1>
</E1EDP01>
so, basically, I have to split description into 70 characters if its more than 70 characters and assign to a new TDLINE field.
howz it doable?
thx
mike
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Harish,
I am not really looking for splitting. Splitting can be done using standard function Node pool fragment single value but once split I am not sure now to assign the values to E1EDPT2 and TDLINE to repeat for each and every value and thats where I need help to be precise Should have made my ask clear before.
thx
mike
Edit: Swapped E1EDPT1 and E1EDPT2 mapping
Hi Michael
Try the following UDF of type All Values of Queue. It has two output fields.
public void genText(String[] a, ResultList parent, ResultList line, Container container) throws StreamTransformationException {
int limit = 70;
for(int i = 0; i < a.length; i++) {
if(a[i].equals(ResultList.CC)) {
line.addContextChange();
parent.addContextChange();
} else {
String text = a[i];
while(!text.isEmpty()) {
parent.addValue("");
if(text.length() > limit) {
line.addValue(text.substring(0, limit));
line.addContextChange();
text = text.substring(limit);
} else {
line.addValue(text);
break;
}
}
}
}
}
Following is the mapping logic for the E1EDPT1 E1EDPT2 and TDLINE fields.
Sample output (I've not included the other ORDERS05 fields)
Rgds
Eng Swee
Message was edited by: Eng Swee Yeoh
Hi Eng,
thanks a lot for the reply. But this is not exactly I want. I want all the description for the same item under one E1EDP01 node. With your UDF, it is adding context for each and every E1EDPT2 value which is not what I want. For the above example, I want all the description to come under same E1EDP01 node under multiple E1EDPT2 /TDLINE under a single E1EDPT1 node. Makes sense?
thx
mike
hi Harish,
The udf is written to add parent context (E1EDPT2) and if we remove the context for E1EDPT2, then it won't work properly because E1EDPT2 if it is assigned 2 null values for example before CC, it will repeat only 2 times instead of 3 times if the description is 2 and one of them is more than 70 characters. makes sense? And if we pass all the descriptin to E1EDPT2 without any context change, it will repeat more than 3 times when it was supposed to repeat only 3 times. This will create erroneous result.
thx
mike
Ok this should be it, hopefully (crossing fingers!)
Change the execution type to "All Values of a Context"
int limit = 70;
for(int i = 0; i < a.length; i++) {
String text = a[i];
while(!text.isEmpty()) {
parent.addValue("");
if(text.length() > limit) {
line.addValue(text.substring(0, limit));
text = text.substring(limit);
} else {
line.addValue(text);
break;
}
}
}
Slight changes to the mapping flow
- Change context of D_352 to L_PO1
- Add SplitByValue to second output of UDF before TDLINE
I've tested with two occurrences of L_PO1 and it should work fine.
substring(0,70) will get 70 characters. It will take from beginIndex to (endIndex - 1), refer to the following JavaDoc description of substring function.
User | Count |
---|---|
87 | |
10 | |
10 | |
10 | |
7 | |
6 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.