on 10-02-2009 9:36 AM
Hello,
because we are not really able to write Java-Code we have a question for support to the community!
We have a mapping were we get some strings. These strings containing data which we have to map to certain fields in target structure.
Example:
001GIE;002090429;0030853;005D ;007TCT ;010TTNU9457423 ;01140;01296;013SCI01;019
4N ;02145G1;027E;0300;033V;03508388;03604508;03703880;039003054 ;040003054
The requirement is that we have to identify the fields to map by it's number, like "001GIE" means 001 field in target structure.
So how to do an UDF? We need to parse the string and put the found strings into right position in an array e.g. But how to get this result to the single target-fields in target structure?!
And another problem in example: how to get data if the identifier (019) and the data (4N) is divided by an end of line (see example)?!
Do you have some ideas?! We highly appreciate your help!
br
Hi Fritz,
Few questions
1. The numbers 001 002 etc will be always three characters long? what will happen after 999. Or you will not have such long values
2. what about the missing numbers 006, 008, 009 etc. will the target have empty field for these?
3. How your target looks like ? Can you provide the structure
4. Are you reading this file into one xml node. That is how does your source structure looks like
-<root>
--<Value>001GIE;002090429;0030853;005D ;007TCT ;010TTNU9457423 ;01140;01296;013SCI01;019
4N ;02145G1;027E;0300;033V;03508388;03604508;03703880;039003054 ;040003054</Value>
-<root>
Regards
Suraj
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Suraj!!!
1. The numbers 001 002 etc will be always three characters long? what will happen after 999. Or you will not have such long values
always three characters, up to 111
2. what about the missing numbers 006, 008, 009 etc. will the target have empty field for these?
target has empty fields, yes, 008 can also be empty
3. How your target looks like ? Can you provide the structure
Target looks like:
<Bewsatz>
<B001>
<B002>
<B003>
<B004>
<B005>
<...>
<B111>
</Bewsatz>
There is also a header but here is no problem to map!
4. Are you reading this file into one xml node. That is how does your source structure looks like
Source:
<?xml version="1.0" encoding="UTF-8"?>
<ns0:MT_CT01_READ_DATA xmlns:ns0="http://xyz.com/pi/osy/ct01">
<Bewsatz1>
<F1/>
<F2/>
<F3/>
<F4/>
<F5/>
<F6/>
<F7/>
<F8/>
<F9/>
<F10/>
<F11/>
</Bewsatz1>
<Bewsatz2>
<F1/>
<F2/>
<F3/>
<F4/>
<F5/>
<F6/>
<F7/>
<F8/>
<F9/>
<F10/>
<F11/>
</Bewsatz2>
<Bewsatz3>
<F1/>
<F2/>
<F3/>
<F4/>
<F5/>
<F6/>
<F7/>
<F8/>
<F9/>
<F10/>
<F11/>
</Bewsatz3>
<Bewsatz4>
<F1/>
<F2/>
<F3/>
<F4/>
<F5/>
<F6/>
<F7/>
<F8/>
<F9/>
<F10/>
<F11/>
</Bewsatz4>
</ns0:MT_CT01_READ_DATA>
Thanks Fitz!
Hi Fritz,
Let us address the problem one by one.
1. You might need to change the source structure to :
-root 1..1
--Value 1..unbounded
Please note root and Value are the names given by me you can use any names as per your wish. But we cannot have the source as you specified, will this source be ok for you?
2. Give File content conversion parameter
recordset name = Vale
Value.endSeparator 'nl'
By doing this there will be a Value node created when the source file has a newline character
3. In message mapping create two UDF
*UDF1 (Simple ?UDF with input field named *input )
for (int i=0;i<input.length;i++)
output += input<i>;
return output
*UDF2 (Simple UDF with input field named input)*
int i = 1;
String [] value = new String[112];
while (input.indexOf(";") != -1)
{
String counter = "";
Integer i_int = new Integer (i);
if (i<10)
counter = "00"+ i_int.toString();
else if (i>9 && i<100)
counter = "0"+ i_int.toString();
else counter = i_int.toString();
if (input.startsWith(counter)) {
value<i> = input.substring(3, input.indexOf(";"));
if (input.indexOf(";") != -1 )
input = input.substring(input.indexOf(";")+1);
}
else
value <i> = "";
i++;
}
int j;
GlobalContainer globalContainer = container.getGlobalContainer();
globalContainer.setParameter("Output", value);
Now do a mapping like this
Value (context root)--> UDF1 > UDF2> target root node (ie Bewsatz)
By this step you set all the values in global container named Output
3. Now for each target field call this UDF
*UDF3 (Simple UDF with input field named pos)*
GlobalContainer globalContainer = container.getGlobalContainer();
String[] Value = (String[] )globalContainer.getParameter("Output");;
String outvalue;
if (Value != null) {
outvalue = Value(pos) ;
}
return outvalue;
Call this UDF for each output field with positions like 1, 2, 3, ...111
Please try this
Regards
Suraj
Hi Suraj,
I tried your approach but i have some problems..
You gave info that i might change the structure too:
-root 1..1
--Value 1..unbounded
I have no chance to change the structure.
Source is as follows (now also with header):
<Header>
<HKZ/>
<HTC/>
</Header>
<Bewsatz1>
<F1/>
<F2/>
<F3/>
<F4/>
<F5/>
<F6/>
<F7/>
<F8/>
<F9/>
<F10/>
<F11/>
</Bewsatz1>
<Bewsatz2>
<F1/>
<F2/>
<F3/>
<F4/>
<F5/>
<F6/>
<F7/>
<F8/>
<F9/>
<F10/>
<F11/>
</Bewsatz2>
<Bewsatz3>
<F1/>
<F2/>
<F3/>
<F4/>
<F5/>
<F6/>
<F7/>
<F8/>
<F9/>
<F10/>
<F11/>
</Bewsatz3>
<Bewsatz4>
<F1/>
<F2/>
<F3/>
<F4/>
<F5/>
<F6/>
<F7/>
<F8/>
<F9/>
<F10/>
<F11/>
</Bewsatz4>
Target is:
<Header>
<HKZ/>
<HTC/>
</Header>
<Bewsatz>
<F1/>
<F2/>
<F3/>
<F4/>
<F5/>
<F6/>
<F7/>
<F8/>
<F9/>
<F10/>
<F11/>
</Bewsatz>
Is there a chance to change the coding to this requirements?!
br
Hi Fritz,
The problem is I cannot distribute the file value to different fields like F1, F2 etc of source. Thats why I read it and distributed it in different fields of target
>>I have no chance to change the structure.
But why :(:(
Since this was the source structure I thought it will be easy for you to adjust !!!! Are you getting this structure from some external definition?
Regards
Suraj
Hi i checked you idea from previous steps.
Your idea is:
-<root>
--<Value>001GIE;002090429;0030853;005D ;007TCT ;010TTNU9457423 ;01140;01296;013SCI01;019
4N ;02145G1;027E;0300;033V;03508388;03604508;03703880;039003054 ;040003054</Value>
-<root>
This is nearly the structure we have but we have to read in like this:
-<root>
--<Value>001GIE;002090429;0030853;005D ;007TCT ;010TTNU9457423 ;01140;01296;013SCI01;019
4N ;02145G1;027E;0300;033V;03508388;03604508;03703880;039003054 ;040003054</Value>
--<Value1>001GIE;002090429;0030853;005D ;007TCT ;010TTNU9457423 ;01140;01296;013SCI01;019
4N ;02145G1;027E;0300;033V;03508388;03604508;03703880;039003054 ;040003054</Value1>
--<Value2>001GIE;002090429;0030853;005D ;007TCT ;010TTNU9457423 ;01140;01296;013SCI01;019
4N ;02145G1;027E;0300;033V;03508388;03604508;03703880;039003054 ;040003054</Value2>
-<root>
Cool thing is that this value rows will appear 3-5 times. so i have also the nice problem on how to make sure to get the structure from file
Can you adopt this?!
br - done a great job so far!
Hi Fritz,
Still didnt get that
Will this be the content of your input file
001GIE;002090429;0030853;005D ;007TCT ;010TTNU9457423 ;01140;01296;013SCI01;019
4N ;02145G1;027E;0300;033V;03508388;03604508;03703880;039003054 ;040003054
001GIE;002090429;0030853;005D ;007TCT ;010TTNU9457423 ;01140;01296;013SCI01;019
4N ;02145G1;027E;0300;033V;03508388;03604508;03703880;039003054 ;040003054
001GIE;002090429;0030853;005D ;007TCT ;010TTNU9457423 ;01140;01296;013SCI01;019
4N ;02145G1;027E;0300;033V;03508388;03604508;03703880;039003054 ;040003054
001GIE;002090429;0030853;005D ;007TCT ;010TTNU9457423 ;01140;01296;013SCI01;019
4N ;02145G1;027E;0300;033V;03508388;03604508;03703880;039003054 ;040003054
....
or
you want one value
001GIE;002090429;0030853;005D ;007TCT ;010TTNU9457423 ;01140;01296;013SCI01;019
4N ;02145G1;027E;0300;033V;03508388;03604508;03703880;039003054 ;040003054
duplicated in different source element Value, Value1 etc...
If it is the first case then the method i suggested will work and your input will look like
-root
--Value 001GIE;002090429;0030853;005D ;007TCT ;010TTNU9457423 ;01140;01296;013SCI01;019
--Value 4N ;02145G1;027E;0300;033V;03508388;03604508;03703880;039003054 ;040003054
--Value 001GIE;002090429;0030853;005D ;007TCT ;010TTNU9457423 ;01140;01296;013SCI01;019
--Value 4N ;02145G1;027E;0300;033V;03508388;03604508;03703880;039003054 ;040003054
--Value 001GIE;002090429;0030853;005D ;007TCT ;010TTNU9457423 ;01140;01296;013SCI01;019
--Value 4N ;02145G1;027E;0300;033V;03508388;03604508;03703880;039003054 ;040003054
Here you need to note two things
1) The node name will always be Value and not Value1, 2, 3 etc
2) Each newline value in input record will create a new Value node
And if your approach is second one then!!!! I dont have any idea on how to replicate same value across different node (Value1, Value2, Value3)
Regards
Suraj
User | Count |
---|---|
84 | |
10 | |
10 | |
10 | |
7 | |
6 | |
6 | |
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.