Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

String manipulation

Former Member
0 Likes
715

Hi experts,

I am obtaining a string from the database. I just wanna split that string into every 60 characters.I have to append it to the internal table.For every 60 characters i have to give the row value as 1 and it should increment depending upon the number of splits made.

Kindly help me in resolving this.Thanx in advance.

1 ACCEPTED SOLUTION
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
683

You might try something like this.



report zrich_0001.

data: begin of itab occurs 0,
      index type i,
      value(60) type c,
      end of itab.
data: offset type i.
data: len type i.
data: string type string.
data: substring type i.

string = 'This is the string that we need to break up into 60 ' &
         'characters per line and place the values in an internal' &
         ' table with a index value for each row that we add'.

len = strlen( string ).


do.

  if len < 0.
    exit.
  endif.

  if len < 60.
    substring = len.
    itab-index = sy-index.
    itab-value = string+offset(substring).
  else.
    itab-index = sy-index.
    itab-value = string+offset(60).
  endif.

  append itab.

  len = len - 60.
  offset = offset + 60.

enddo.

loop at itab.
  write:/ itab-index,  itab-value.
endloop.


Regards,

Rich Heilman

5 REPLIES 5
Read only

Former Member
0 Likes
683

Use the FM RKD_WORD_WRAP, Pass the string in the TEXTLINE and OUTPUTLEN = 60. You will get the splitted lines in the table OUT_LINES.

Sample Code:

TYPES: BEGIN OF ty_desc,

desc TYPE char50,

END OF ty_desc.

DATA: li_desc TYPE STANDARD TABLE OF ty_desc,

lwa_desc TYPE ty_desc,

ws_data type char100.

ws_data = 'sjkdc jsfjsfshf fjsfhjsd fjksd'.

CALL FUNCTION 'RKD_WORD_WRAP'

EXPORTING

textline = ws_data

outputlen = 50

TABLES

out_lines = li_desc

EXCEPTIONS

outputlen_too_large = 1

OTHERS = 2.

IF sy-subrc <> 0.

ENDIF.

Regards,

Prakash.

Read only

Former Member
0 Likes
683

put like this

l = strlen(itab-text).

do 1 times.

n = n + 1.

if n = 60.

here create a new line.

endif.

enddo.

this is sample code only,but u can achive this one.

Regards

Prabhu

Read only

uwe_schieferstein
Active Contributor
0 Likes
683

Hello Satheesh

A possible solution looks like that:

TYPES: begin of ty_s_entry.
TYPES: row  TYPE i.
TYPES: text TYPE char60.
TYPES: end of ty_s_entry.
data:
  ls_entry  TYPE ty_s_entry.


  DO.
    ls_entry-row  = syst-tabix.
    ls_entry-text = ld_string+0(60).

    IF ( ls_entry-text IS INITIAL ).
      EXIT.
    ENDIF.
    
    APPEND ls_entry TO lt_itab.
  ENDDO.

I do not exactly know how you recognise the end of your string. Probably you have to define another condition.

Regards

Uwe

Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
684

You might try something like this.



report zrich_0001.

data: begin of itab occurs 0,
      index type i,
      value(60) type c,
      end of itab.
data: offset type i.
data: len type i.
data: string type string.
data: substring type i.

string = 'This is the string that we need to break up into 60 ' &
         'characters per line and place the values in an internal' &
         ' table with a index value for each row that we add'.

len = strlen( string ).


do.

  if len < 0.
    exit.
  endif.

  if len < 60.
    substring = len.
    itab-index = sy-index.
    itab-value = string+offset(substring).
  else.
    itab-index = sy-index.
    itab-value = string+offset(60).
  endif.

  append itab.

  len = len - 60.
  offset = offset + 60.

enddo.

loop at itab.
  write:/ itab-index,  itab-value.
endloop.


Regards,

Rich Heilman

Read only

Former Member
0 Likes
683

U can try the below code.

lstr is the string having the data.

lrecord = lstr.

Do 100 Times.

clear itab-record.

itab-serial = sy-index.

itab-record = lrecord(60).

shift lrecord by 60 places.

if lrecord ne space.

append itab-record.

else.

exit.

endif.

enddo.

Regards

Anurag

Message was edited by: Anurag Bankley