cancel
Showing results for 
Search instead for 
Did you mean: 

Mapping text in IDOC to IDOC scenario

former_member58757
Participant
0 Kudos

Hi,

I have to map the source tdline field of IDOC segment E1EDPT1 to target IDOC Tdline field. Currently few tdline brings more than 31 chars but target should have only 31 and if it's more than 31 should roll over to next line.

I can able to truncate 31 chars using substring and if coneditions, but chars from 31 to rest couldnt be mapped, I tried a duplicate subtree in target and didnt work, used global variables to store the remainins but still didnt work.

Any suggestion would be greatly appreciated.

Thanks,

Menaga

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Menaga,

Create a Context user defined function AddNode. Have one argument input. Add this code:

String str=input[0];

while(str.length()>31)

{

result.addValue(str.substring(0,31));

str=str.substring(31,str.length());

}

result.addValue(str);

So map tdline source --> udf(Addnode) --> tdline target

Regards,

---Satish

former_member58757
Participant
0 Kudos

Thanks every one , below is my UDF

String str="";

str=var1[0];

while(str.length() >31);{

result.addValue(str.substring(0,30));

str=str.substring(30);

}

result.addValue(str);

mapping

Source tdline -> remove context->udf->target tdline

I get this below exception

untime exception when processing target-field mapping /ORDERSEX/IDOC/E1EDKT1/E1EDKT2/TDLINE; root message: Exception:[java.lang.StringIndexOutOfBoundsException: String index out of range: 30] in class com.sap.xi.tf._MM_ACSI_ORDER_ method Tdlinesplit[[Ljava.lang.String;@2a96d411, com.sap.aii.mappingtool.tf7.rt.ResultListImpl@143cbdef,

Thanks,

Menaga

Former Member
0 Kudos

Hi Menaga,

Make sure that the scope of your UDF is "value" not "context" either "queue".

Thanks

Ivan

former_member58757
Participant
0 Kudos

Hi Ivan,

The execution type in UDF is all values for context , should that be for single value?

Thanks,

Menaga

Former Member
0 Kudos

Hi Menaga,

Your udf should be context only because we are passing as an array in the line String str=input[0];.

Also please dont the substring number. I see you changed from 31 to 30. It should be the same as I have given. I just tested and it is working for me.

If you want to change to 30 change everywhere to 30 in the udf.

Regards,

---Satish

former_member58757
Participant
0 Kudos

Hi Sathish,

Thanks for your response, I found and did the change already but now the problem is it just only picks up the first line and doest loop through the rest.

How the mapping should be?

I have it as

E1EDPT1(source) - UDF - E1EDPT1(target_

Tdline(Source)

Thanks,

Menaga

former_member58757
Participant
0 Kudos

Hi Sathish,

Thanks for your response, I found and did the change already and UDF is working what I want but now the problem is it just only picks up the first line in the context / array and doest loop through the rest.

How the mapping should be?

I have it as

E1EDPT1(source) - UDF - E1EDPT1(target)

Tdline(Source) - Remove context - UDF -Split by value change - tdline target.

Thanks,

Menaga

Former Member
0 Kudos

Menaga,

Try changing the context level to one level up or to the root and see.

Also remove split by value change and see.

Regards,

---Satish

former_member58757
Participant
0 Kudos

Hi Sathish,

I am not sure what you mean by move a level in context, I do see the substring extracts only 31 chars and doest put the rest in the next segment all it does is just gets only one segment.

I am thiking some thing is missing in map that loops through the segment.

Thanks,

Menaga

Former Member
0 Kudos

Menaga,

Did you try removing remove context and splitbyvalue (changed)? What are you getting? Also please provide a sample xml file.

Regards,

---Satish

former_member181962
Active Contributor
0 Kudos

Hi Menaga,

Ignore my last post.

Try this:

String str=a[0];
for(int i =0;i<str.length()-31;i+=31)
{
result.addValue(str.substring(i,i+31);
}
result.addValue(str.substring(i));

where a is the input.

Regards,

Ravi

former_member58757
Participant
0 Kudos

Hi Sathish,

Yes I tried but still it doesn't bring all the lines. Always brings up only 1 segments though source has 6/7 lines .

Thanks,

Menaga

former_member58757
Participant
0 Kudos

Hi Ravi,

I dont think problem with UDF..it does splits the string in to 2 but the problem is the target is not getting generated for all the line.

Thanks,

Menaga

Former Member
0 Kudos

>>target is not getting generated for all the line

It could be because the occurcen of TDLINE is 0-1

Can you please use the same UDF to map to EIEDKT2,i just want to see if it generates multiple E1EDKT2

thanks

Aamir

former_member58757
Participant
0 Kudos

Hi Amir,

Tdline is 0-1 , I have tried my mapping like this

TDLINE- UDF - E1EDKT2

TDLINE - UDF - TDLINE

it results with 2 E1EDKT2 segment in the target with one first 31 chars string in tdline nad second one blank, in the queue I could able to see 2 lines of text , first one with 31 and next one with the remaining

all other lines where truncated in the target ...

I tried

E1EDKT2 - UDF E1EDKT2

TDLINE - UDF - TDLINE

E1EDKT2 source has 6 lines with few lines more than 31 chars

target provides 2 E1EDKT2 segment with one segment TDLINE present and next one doesnt have.

Thanks

Menaga

Former Member
0 Kudos

TDLINE- UDF - E1EDKT2
TDLINE - UDF - TDLINE

This is correct,now can you please paste the UDF you are using for TDLINE-UDF-TDLINE

also the cache for UDF,is it Value,Context or Queue?

Thanks

Aamir

Edited by: Aamir Suhail on Jul 9, 2009 10:36 AM

former_member58757
Participant
0 Kudos

Hi Amir,

UDF for string manipulateion

String str="";

str=var1[0];

while(str.length() >31){

result.addValue(str.substring(0,31));

str=str.substring(31, str.length());

}

result.addValue(str);

I have 6 lines of E1EDKT2 with soem more than 31 mapping to target E1EDKT2.

input value as argument and using Execution type "All values of context".

Thanks,

Menaga

Former Member
0 Kudos

Menaga,

You should map like this:

For the segment E1EDPT2:

TDLINE(change the context to E1EDP01) ---> udf --> E1EDPT2

For TDLINE:

TDLINE --> removecontext --> udf --> splitbyvalue --> TDLINE.

Menaga, you should observe one thing. You started your question or thread with E1EDPT2 and now you are using E1EDKT2. These are two different segments. One is in header and one is detail. So please make sure you are doing what you want. I am giving my logic for Item level.

Regards,

---Satish

former_member58757
Participant
0 Kudos

Hi Sathish,

I am mapping Item to Header mark for , for some reason our customer send PO with text in first item and we need to map that to header mark for in target.

E1EDPT2 to E!EDKT2

Thanks,

Menaga

former_member58757
Participant
0 Kudos

Hi Sathish,

I don't know why you want to change the context to E1EDP01 , if I do so it does bring only the first line and E1EDP01 segment in target was not displayed.

Thanks,

Menaga

former_member58757
Participant
0 Kudos

I got E1EDP01 , my mistake.

Still I didnt get multiple target lines.

Thanks,

Menaga

Former Member
0 Kudos

Menaga,

Create a udf with name addnode and Queue as cache. Have one parameter as input:

Imports: java.;*

Add this code:

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

{

String str=input<i>;

while(str.length()>31)

{

result.addValue(str.substring(0,31));

str=str.substring(31,str.length());

}

result.addValue(str);

}

Now map like this:

For e1edkt2:

tdline(change context to idoc) --> addnode udf --> e1edkt2

For tdline:

tdline --> removecontext --> addnode --> splitbyvalue --> tdline

Regards,

---Satish

Former Member
0 Kudos

Menaga,

In the above after the for statement the code should be String str=input[i

];

I dont know why when I am trying to edit it is not showing the i in the brackets. So please put this i as an array for the input in the line

Regards,

---Satish

former_member58757
Participant
0 Kudos

Hi Sathish,

It worked. Thanks for your assistance.

Thanks,

Menaga

Answers (5)

Answers (5)

Former Member
0 Kudos

Hi Menaga,

fF the field does not support a length greater than 31, you can duplicate the segment(not the element) the times you need to send all the source content, but for that you need to talk to the responsible persons at the backend side.

Other solution, Is truncates it using substring standard function.

I hope this helps you.

Thanks

Ivan

former_member181962
Active Contributor
0 Kudos

YOu can use a Java UDF (Chose Context radio button while creating the UDF)

The logic should be something like

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

{

if ( i%31 == 0)

{

v_str = str+i(31);

addResult(v_str);

}

}

Regards,

Ravi

former_member181962
Active Contributor
0 Kudos

Hi Menaga,

Try this code:

String str=input[0];
String v_str="";

for(int i =0;i<str.length();i++)
{
if ( i%31 == 0)
{
if i (< str.length()-31)
{
v_str = str.substring(i,i+31);
result.addValue(v_str);
}
}
}
v_str = str.substring(i);
result.addValue(v_str);

Regards,

Ravi

Former Member
0 Kudos

Hi ,

According to my understanding , if the text is more than 31 char it should display in 2 lines right ! ..

So try using UDF , and you can solve it .

Regards,

B.Jude

Former Member
0 Kudos

Hey

In a standard IDOC,TDLINE occurs 0-1 so you cant put your logic just there,did you write a UDF to create multiple E1EDPT2 and then populate TDLINE?

Thanks

Aamir

Edited by: Aamir Suhail on Jul 8, 2009 9:38 AM

Former Member
0 Kudos

Hi ,

You can Go with a Simple mapping logic..

Use if then ESLE Function:

If Length is greater than 31 Then tdline--> Substring of (0 to 31) and to target

Else Directly map tdline to Target

Regards,

Sainath

former_member58757
Participant
0 Kudos

Hi Sainath,

simple mapping will discard and will not roll over to next line.

Thanks,

Menaga