cancel
Showing results for 
Search instead for 
Did you mean: 

PI mapping : Context change for text lines

Former Member
0 Kudos

Hi experts

I have an idoc with E1EDKT1 node having many E1EDKT2 nodes under it (these are text lines).

I have written a UDF to conatenate all the TDLINE fields in E1EDKT2 nodes into a single target field which is working fine.

I need to conditionally send the E1EDKT1 => E1EDKT2 node contents to target field.

However the E1EDKT2 node has 2 fields as below

TDLINE     always present, populated with text lines

TDFORMAT present only on some nodes and populated with /

What I need to do is in the target field insert a new-line character before the TDLINE (text line) wherever there is \ in the TDFORMAT field.

Please can you suggest appropriate mapping since I am struggling with unequal contexts and hence not getting the desired results.

I am struggling with context mappings since I am new to PI

Idoc example

E1EDKT1     ABCD                                 Send to destination target field.

E1EDKT2     TDLINE                              TDFORMAT

E1EDKT2      This is the first line of text     /

E1EDKT2      This is the second line     

E1EDKT2      This is the third line               /

E1EDKT2      This is the fourth line

The desired result i want is : \nThis is the first line of textThis is the second line\nThis is the third lineThis is the fourth line

Accepted Solutions (0)

Answers (3)

Answers (3)

Former Member
0 Kudos
markangelo_dihiansan
Active Contributor
0 Kudos

Hello,

You can use this mapping:

TDFORMAT -----------------------> concat: -> replaceString -> UDF -> Target

TDLINE -> mapWithDefault -> /       Constant: /   -> /

                                                             Constant: \n -> /

Hope this helps,
Mark

Former Member
0 Kudos

Hi

Check this UDF:


var1 and var2 will be inputs
execution type: all values of a context

String out ="";
for(int i=0;i<var2.length;i++)
{
if(var1[i].equals("/"))
{
out = out+ "\n" + var2[i];
}
else
{
out =out+var2[i];
}
}
result.addValue(out);

Change the context of TDLINE to E1EDXT2


Thanks
Amit Srivastava

Former Member
0 Kudos

Hi Amit

I am getting closer to what I want as the output so thanks for that. However I have one question. I changed the mapping given by you as below

I want to send the output only if E1EDKT1-TDID (parent node value = ZABC). So I have introduced the useOneAsMany and put an if condition to check this.

But the problem is though Displayqueue shows all text lines coming out from if node, the formatByExample context comes out empty. Due to this I get the below error

Runtime exception when processing target-field mapping /ns0:XX_XXXXXXXX_XXXXXXX_XXXXXXX/Header/dbTableName/access/XXXXXX; root message: Exception:[com.sap.aii.mappingtool.tf7.FunctionException: Function formatByExample: Queues do not have the same number of values] in class com.sap.aii.mappingtool.flib7.NodeFunctions method formatByExample[[Ljava.lang.String;@723a25f4, [Ljava.lang.String;@4791f0c2, com.sap.aii.mappingtool.tf7.rt.ResultListImpl@3e557543, com.sap.aii.mappingtool.tf7.rt.Context@5c85a1ad]

How can I acheive this?

Former Member
0 Kudos

Hi,

Check this:

input will be var1, var2, var3

String out ="";

if(var3[0].equals("ABC"))

{

for(int i=0;i<var1.length;i++)

{

if(var1[i].equals("/"))

{

out = out+ "\n" + var2[i];

}

else

{

out =out+var2[i];

}

}

result.addValue(out);

}

else

{

result.addSuppress();

}

Mapping:

Thanks

Amit Srivastava