‎2006 Sep 06 1:51 PM
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.
‎2006 Sep 06 2:08 PM
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
‎2006 Sep 06 1:57 PM
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.
‎2006 Sep 06 1:58 PM
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
‎2006 Sep 06 2:01 PM
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
‎2006 Sep 06 2:08 PM
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
‎2006 Sep 06 2:11 PM
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