cancel
Showing results for 
Search instead for 
Did you mean: 

Mapping query

Former Member
0 Kudos

Hi all, I have 2 queries. I have an IDOC to file scenario where the IDOC structure looks as shown below. At the target side there are 4 nodes.

IDOC

       +EDIDC40

       +E1LTO

           +E1LO

                 +Z1

                 +ZE1

                 +ZE2

Q 1) The 3 rd node of the target structure should repeat itself as many number of times as the fields are under the segment ZE2 (30 fields). And each value of the field under ZE2 must be sent to "Value" element of the 3rd node everytime it is repeated. i.e.; 30 repeation of node 3 with "Value" containing the data from each field of ZE2.

Q 2) Also in the first node of the target one element "N" should have total count of the no. of fields under the segment ZE2. As the idoc structure may chnage in future i want to keep the count as dynamic rather than a constant.

Can anyone please help? I am a newbie in PI.

Thanks.

Accepted Solutions (1)

Accepted Solutions (1)

former_member184789
Active Contributor
0 Kudos

Hi,

And as far as the logic for the target field is concerned, as your logic is to populate the single target field with the 30 source fields one by one i.e. in first occurrence of target segment it should take the first field, in second occurrence the second field & so on..Just have another UDF for this..For this UDF also, you will give input a the 30 fields concatenated with pipe separator just like you did for populating the segment 30 times..You must have a split by value ( Each value) after this..

String[] resu = var1[0].split("\\|");

int temp = resu.length;

    for(int b=0;b<temp;b++){

        result.addValue(resu[b]);

}

Execution Type: All Values of context.

Look how this worked for me...

Answers (1)

Answers (1)

former_member184789
Active Contributor
0 Kudos

Hi,

1. It may not be very straightforward. Do one thing, concat all the source fields with a pipe separator as shown below. Here I have done for two fields only. You have to concatenete all so that you pass the 30 fields separated with pipe separator eg:

Field1 | Field2 | Field3 .....Field30.

You will pas this to the below UDF which will calculate the no. of fields stored with the pipe separator:

String[] res = var1[0].split("\\|");

int tem = res.length;

result.addValue(tem);

Execution Type: All values of context.

2. Now you have to populate as many segments of 3rd node as per the no. of count of fields stored in the variable, which you can do by the below UDF:

for(int a=0;a<inp1.length;a++){

    for(int b=0;b<inp1[0];b++){

        result.addValue("");

}

}

Execution TYpe: All values of context

Input: inp1 (int)

For populating the no of fields in source, you are getting this no. immediately after the output of the first UDF as shown above. You can map that to the Value field.

You may try to replace two UDF's by a sinlge UDF..

PS: Since I have concateneted only two fields, you will have to concatenete all the fields together with a pipe seperator as :

Field1

          Concataente ( |)  -> 

Field2                                       -> Concatenete( |) ....& so on...

                                    Field3

Hope this helps..

former_member184789
Active Contributor
0 Kudos

Hi,

instead of having two udf's use the below udf:

String[] resu = var1[0].split("\\|");

int temp = resu.length;

    for(int b=0;b<temp;b++){

        result.addValue("");

}

All values of context. Map the output to the 3rd node which u want to repeat as per the no of fields..

Former Member
0 Kudos

Thanks Adarsh,

I tried your method but it is repeating the ID at under one occurrence of target node EmpRec.

I need the EmpRec to repeat 2 times (in your exapmle) with the ID having EmpID value at the first repetition of node EmpRec and EmpAddres at the second repetition of the node. Likewise i need to repeat EmpRec 30 times.

Also, how to concatenate 30 fields of segment ZE2?

former_member184789
Active Contributor
0 Kudos

Hi,

I only wanted to show you how the multiple nodes will be generated. As you want the segment corresponding to EmpRecord to occur multiple times, then you can simply map the segment with the output of the above UDF instead of the field EmpID. Thus you will be having multiple occurrences of the target segment.

For concateneting the fields, you cannot do it at once, since concat function works for only two fields at a time. You have to do it as concat field 1 & 2 with pipe separator & then the output of this will be concatenated with the third field, the output of this will concatenated with fourth & so on..

Eg, I want to concat four fields as shown below, first I concat first & second & the concatenated output of this will be concatenated to third & so on. You have to do it for 30 fields..