cancel
Showing results for 
Search instead for 
Did you mean: 

Spliting TDLINE to max 70 characters

Former Member
0 Kudos

Hi,

I have a requirement where TDLINE will carry some characters which is not fixed.It can be 70 ot 280.

My Requiremnt:-I want to split the string into 70 characters only.So,if we are getting 280 character in string ,I want to divide it into 4 line(70 each )

Suppose,if we have 150 character than we will divide it into 70,70 and 10 character.

Please suggest your view.

Accepted Solutions (0)

Answers (2)

Answers (2)

vinaymittal
Contributor
0 Kudos

i used this UDF in one project exactly similar situation but the length was 255 anyways i added a variable you can decide the length yourself

i used this as input

aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa

code is

//start

int i=0;
int len = Integer.parseInt(field_length[0]);


String str= Customer_notes[0];


double line= Math.ceil(Customer_notes[0].length() / (float)len );
int lines =  (int)line;

int traversed = 0;
for(i=0; i <lines; i++)
{
  

      String current_str = "";
   
      if( str.length() >= len && len > 0) 
      {
          
          current_str = str.substring(0,len);
          TDLINE.addValue( current_str );

      }
      else
      {
          current_str = str;
          TDLINE.addValue(current_str);
      }

        traversed = traversed + current_str.length();

       str = Customer_notes[0].substring(traversed, Customer_notes[0].length());

}


//end

it never gave me a problem .

Cheers

Vinay

former_member192343
Active Contributor
0 Kudos

Hi Ravi,

please check this thread  http://scn.sap.com/message/14883112#14883112

you can add third and fourth items as in my example or use UDF

Regards, Mikhail