cancel
Showing results for 
Search instead for 
Did you mean: 

UDF help

Former Member
0 Kudos

Hi ,

I need to write a UDF for the following requirement.

I'm getting a input string of 0-52 characters. but my target filed in IDoc  has 13 character limit.If i get 52 characters then i need to divide the text into 4 lines and duplicate the segements 4 times and map.

Can some one help me in writing the UDF for this ?

Thanks.

Accepted Solutions (0)

Answers (3)

Answers (3)

baskar_gopalakrishnan2
Active Contributor
0 Kudos

You can do simple udf for adding empty as Raja pointed and rest you can handle using standard substring function. Create duplicate elements on the target structure.

Example:

UDF for filling remaining spaces to the length upto 52 chars ...

Mapping example for four segments. Assume your source field is remarks and target also remarks

Like that you do for the remaining two segments   using substring function

substring for the third ( 26 ,39) start position 26 character count 13

substring for the fourth ( 39, 52) start position 39 character count 13

baskar_gopalakrishnan2
Active Contributor
0 Kudos

You are right using UDF is the better solution.

>i may get 0-52 characters like 10,14,22 random numbers,and duplicate segments based on the length

This part is not clear. If you get 22 ,how many duplicate segments you will make 2 or 3? How you can duplicate the segment numbers dynamically? This is not possible.

Solution: You can use duplicate subtree in the target segment only if you know the number of segments in advance. You can always create 4 segments using duplicate subtree in the mapping and send the values accordingly like if you get 52 characters fill all the 4 segments. if the length is less than 52 chars then fill only the required and remaining blank.

Hope this helps.

Former Member
0 Kudos

I duplicated the segment thrice so i have 4 segments now in the Idoc structure.I have to map the text in that segments based on the input length.

first 13 characters into first segment, next 13 characters into second segment  like that.

I can't use substring because i'm not sure how many characters i get.

zameerf
Contributor
0 Kudos

May be first you can just do a check for length not less than 13 and if so substring first 13 characters and map to first segment.

For 2nd segment, check if length greater than 13 and not less than 27, then do a substring to get next 13 char.

Similarly you can try for remaining 2 segments.

rajasekhar_reddy14
Active Contributor
0 Kudos

use my udf , it will add empty missing  spaces then use substring.

       StringBuffer s= new StringBuffer(var1);

       int len=s.length();

       int spaces=52-len;

       for (int i=0;i<spaces;i++)

               s.append(" ");

       var1 = s.toString();

     

      return var1;

Former Member
0 Kudos

I wrote UDF for this.

String[] lines =  input.split("(?<=\\G.{13})") ;

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

{

result.addValue(lines[i]);

}

thanks everyone for your helpful answers.

rajasekhar_reddy14
Active Contributor
0 Kudos

You dont need any UDF for this

1)Use lenght standard function to indetify the length of input,if lenghth less then 52 then using substring function map maccoprdingly.

2)Duplice target field 4 times but lengh 52 then only map.(write a logic using standard function.

Former Member
0 Kudos

i may get 0-52 characters like 10,14,22 random numbers,and duplicate segments based on the length. achieving this through standard functions looks tedious so thought of writing UDF for this requirement.

zameerf
Contributor
0 Kudos

Hi,

I guess your requirement can be handled with XSLT mapping, so that you can create number of required segments at runtime.

Former Member
0 Kudos

U can use split function in UDF and split it based on chunk size....

Search on Google u will get the sample code...

Thanks

Chirag

rajasekhar_reddy14
Active Contributor
0 Kudos

First you have to duplicate target field 4 times,duplicating strcuture dynamically not possible.

Then you can try using standard function,i dont think it is going to be tedious.

Try below approach,if input length less then 52 then add empty spaces to make the lenghth 52 then use substring