2009 Jan 27 9:16 AM
Hallo,
I want to split a string of any length in new substrings and want to save these substrings in different variables.
I tried as following:
data:
string type string value 'Hallo SAP world', "This could be any string with any lenght
offset type i value 0,
str_len type i,
new_str type string.
str_len = strlen( string ).
do 5 times.
new_str = string+offset(3).
write : new_str.
write : ' '.
offset = offset + 3.
enddo.
1_ Has anyone any idea, how to save the new substrings in different variables?
2_ Since the new substring has length 3. So how many times should the do-loop run?
Thanks
ama
2009 Jan 27 9:58 AM
Hi, Muhammed Aftab Alam
Test the following Sample code it working the same way you are requiring, I have Tested,
REPORT zfsl_sub_string.
DATA: main_string TYPE string,
len_string TYPE i,
reminder TYPE i,
string_from TYPE i.
main_string = 'Hallo SAP World'. " You can give any string here.
len_string = STRLEN( main_string ).
DO 3 TIMES.
reminder = len_string MOD 3.
IF reminder NE 0.
CONCATENATE main_string ' ' into main_string SEPARATED BY space.
len_string = strlen( main_string ).
ENDIF.
ENDDO.
len_string = len_string div 3.
string_from = 0.
DO len_string TIMES.
WRITE: / main_string+string_from(3).
ADD 3 TO : string_from.
ENDDO.Following too the same as above just add PARAMETER for input String
REPORT zfsl_sub_string.
PARAMETERS: pstring TYPE string.
DATA: "pstring TYPE string,
len_string TYPE i,
reminder TYPE i,
string_from TYPE i.
*pstring = 'Hallo SAP World'. " You can give any string here.
len_string = STRLEN( pstring ).
DO 3 TIMES.
reminder = len_string MOD 3.
IF reminder NE 0.
CONCATENATE pstring ' ' into pstring SEPARATED BY space.
len_string = strlen( pstring ).
ENDIF.
ENDDO.
len_string = len_string div 3.
string_from = 0.
DO len_string TIMES.
WRITE: / pstring+string_from(3).
ADD 3 TO : string_from.
ENDDO.Please Reply if any Problem,
Kind Regards,
Faisal
Edited by: Faisal Altaf on Jan 27, 2009 3:06 PM
2009 Jan 27 9:19 AM
Hi,
Check this FM RKD_WORD_WRAP
Function module RKD_WORD_WRAP
Import parameters Value
TEXTLINE THIS IS THE STRING
DELIMITER
OUTPUTLEN 3
Export parameters Value
OUT_LINE1 THI
OUT_LINE2 S
OUT_LINE3 IS
Tables Value
OUT_LINES 0 Entries
Result: 7 Entries
2009 Jan 27 9:55 AM
Hallo Avinash,
thanks for your suggestion.
How can I assign values to OUT_LINE?
Can this function be used for strings having more than 9 characters?
CALL FUNCTION 'RKD_WORD_WRAP'
IMPORTING
textline = string "string = 'Hallo SAP world' or any other string
* DELIMITER = ' '
OUTPUTLEN = 3
EXPORTING
OUT_LINE1 =
OUT_LINE2 =
OUT_LINE3 =
* TABLES
* OUT_LINES =
* EXCEPTIONS
OUTPUTLEN_TOO_LARGE = 1
OTHERS = 2
Many thanks
ama
2009 Jan 27 10:11 AM
Hi, Muhammed Aftab Alam
My Above code didnu2019t solve your problem? If not please tell me you else requirements.
Thanks and Kind Regards,
Faisal
2009 Jan 27 9:25 AM
2009 Jan 27 9:29 AM
Instead of saving into different variables..try using an internal table
Take one column in this table of type string.
Then use
SPLIT command into internal table.
This will split the string as you want and specifying the internal table would fetch all the split strings into an internal table.
Hope this helps
Regards,
Prashant
2009 Jan 27 9:30 AM
2009 Jan 27 9:32 AM
check these fms
STRING_SPLIT
SWA_STRING_SPLIT
TEXT_SPLIT
кu03B1ятu03B9к
2009 Jan 27 9:32 AM
Hi,
thanks for your suggestions. Since I am a newbie, it'll take some time to implement them.
Regards
ama
2009 Jan 27 9:58 AM
Hi, Muhammed Aftab Alam
Test the following Sample code it working the same way you are requiring, I have Tested,
REPORT zfsl_sub_string.
DATA: main_string TYPE string,
len_string TYPE i,
reminder TYPE i,
string_from TYPE i.
main_string = 'Hallo SAP World'. " You can give any string here.
len_string = STRLEN( main_string ).
DO 3 TIMES.
reminder = len_string MOD 3.
IF reminder NE 0.
CONCATENATE main_string ' ' into main_string SEPARATED BY space.
len_string = strlen( main_string ).
ENDIF.
ENDDO.
len_string = len_string div 3.
string_from = 0.
DO len_string TIMES.
WRITE: / main_string+string_from(3).
ADD 3 TO : string_from.
ENDDO.Following too the same as above just add PARAMETER for input String
REPORT zfsl_sub_string.
PARAMETERS: pstring TYPE string.
DATA: "pstring TYPE string,
len_string TYPE i,
reminder TYPE i,
string_from TYPE i.
*pstring = 'Hallo SAP World'. " You can give any string here.
len_string = STRLEN( pstring ).
DO 3 TIMES.
reminder = len_string MOD 3.
IF reminder NE 0.
CONCATENATE pstring ' ' into pstring SEPARATED BY space.
len_string = strlen( pstring ).
ENDIF.
ENDDO.
len_string = len_string div 3.
string_from = 0.
DO len_string TIMES.
WRITE: / pstring+string_from(3).
ADD 3 TO : string_from.
ENDDO.Please Reply if any Problem,
Kind Regards,
Faisal
Edited by: Faisal Altaf on Jan 27, 2009 3:06 PM
2009 Jan 27 10:09 AM
Hallo Faisal,
it works fine, but the substrings must be saved in different variables, i.e. var1=Hall, var2= lo (first place of var2 is space) and so on
Kind regards,
ama
2009 Jan 27 10:16 AM
Hi, Muhammed Aftab Alam
Test the following code here i am appending these sub string to an internal table.
PARAMETERS: pstring TYPE string.
TYPES: BEGIN OF t_it,
sub_string(3),
END OF t_it.
DATA: it TYPE STANDARD TABLE OF t_it WITH HEADER LINE,
len_string TYPE i,
reminder TYPE i,
string_from TYPE i.
*pstring = 'Hallo SAP World'. " You can give any string here.
len_string = STRLEN( pstring ).
DO 3 TIMES.
reminder = len_string MOD 3.
IF reminder NE 0.
CONCATENATE pstring ' ' into pstring SEPARATED BY space.
len_string = strlen( pstring ).
ENDIF.
ENDDO.
len_string = len_string div 3.
string_from = 0.
DO len_string TIMES.
it-sub_string = pstring+string_from(3).
"WRITE: / pstring+string_from(3).
ADD 3 TO : string_from.
APPEND it to it.
ENDDO.
LOOP AT it into it.
WRITE: / it.
ENDLOOP.Please Reply if any Question
Kind Regards,
Faisal
2009 Jan 27 10:29 AM
Hallo Faisal,
thanks for the rapid reply. How can i call a particular substring? Since I have to do some functions with the substrings, they must be save in different veriables. Sorry for asking samll things.
Many thanks
ama
2009 Jan 27 10:47 AM
Hi, Muhammed Aftab Alam
Suppose you give the string 'Hallo SAP World' it will divide this String to 5 sub Strings and in the other world when you talk about the Internal Table it will Append 5 Lines to table. Now you can read any line from internal table giving the specific INDEX Number. Using following READ TABLE.
READ TABLE it INTO it INDEX 4.
WRITE: / it-sub_string.The above code will Return you the 4th Sub String
Kind Regards,
Faisal
2009 Jan 27 10:53 AM