‎2006 Oct 05 11:23 AM
Hi experts.
how can i read a string at a specified character.
For ex: i have astring like this.
str = 'YUGFHKGHKHDKHHHGJK8HJBFXJKKFKJFJKFHJH'.
so i have to read n.of charecters from starting of the string to charecter 8.
Not with search option.
Regards
‎2006 Oct 05 11:24 AM
sorry:
do tis way:
split str at '8' into V_one v_two.
v_two would have the string you need.
Regards,
ravi
Message was edited by: Ravi Kanth Talagana
‎2006 Oct 05 11:24 AM
sorry:
do tis way:
split str at '8' into V_one v_two.
v_two would have the string you need.
Regards,
ravi
Message was edited by: Ravi Kanth Talagana
‎2006 Oct 05 1:33 PM
Hi,
Thank you all.
I know all these but in my program it is not workig..Don't know why...
either split or search.Pls see the below sample code.
DATA : i_files like spflist occurs 0 with header line,
DATA: w_files LIKE LINE OF i_files.
data: str1(200) type c,
str2(200) type c.
LOOP AT i_files INTO w_files.
str = w_files-line.
lin1 = STRLEN( str ).
lin1 = lin1 - 1.(this is because there is one more '#' at the end of string)
str = str+0(lin1).
lin2 = STRLEN( str ).
search str for '#'.
split str at '#' into str1 atr2.
w_files-line = str.
MODIFY i_files FROM w_files.
CLEAR lin1.
ENDLOOP.
Suppose here str contains:
str = '00000003379#212RegVNegNoticeHLA.aspx.xml'.
So i am getting sy-subrc = 4 after search.
and after split there are no values in str2..and str1 contains full string..
Can any body tell me what may be the problem..?
Regards
‎2006 Oct 05 1:43 PM
Hi Ravi,
Your code works perfectly in my system,
chk yhis
REPORT YCHATEST.
DATA : I_FILES LIKE SPFLIST OCCURS 0 WITH HEADER LINE.
DATA: W_FILES LIKE LINE OF I_FILES.
DATA: STR1(200) TYPE C,
STR2(200) TYPE C,
STR(200),
LIN1 TYPE I,
LIN2 TYPE I.
I_FILES-LINE = '00000003379#212RegVNegNoticeHLA.aspx.xml#'.
APPEND I_FILES.
CLEAR I_FILES.
LOOP AT I_FILES INTO W_FILES.
STR = W_FILES-LINE.
LIN1 = STRLEN( STR ).
LIN1 = LIN1 - 1.
STR = STR+0(LIN1).
LIN2 = STRLEN( STR ).
SEARCH STR FOR '#'.
SPLIT STR AT '#' INTO STR1 STR2.
W_FILES-LINE = STR2.
MODIFY I_FILES FROM W_FILES.
CLEAR LIN1.
* WRITE : / W_FILES-LINE.
ENDLOOP.
‎2006 Oct 05 1:48 PM
Hi
Though in debugging, some characters resemble '#', in real they might not be. For these cases, searching or splitting with '#' will not work. Kindly check the source of the data to recognize the same.
Kind Regards
Eswar
‎2006 Oct 05 2:17 PM
Since the search results in subrc = 4. It means that it is not # but some other character. Can you check it with
CL_ABAP_CHAR_UTILITIES=>CR_LF
‎2006 Oct 05 11:27 AM
Hi
data str(100).
str = 'YUGFHKGHKHDKHHHGJK8HJBFXJKKFKJFJKFHJH'.
search str for '8'. write sy-fdpos.
Max
‎2006 Oct 05 11:28 AM
Hi,
Fidn the String lenght first,
DATA: Len type i.
String: STR.
str = 'YUGFHKGHKHDKHHHGJK8HJBFXJKKFKJFJKFHJH'.
Len = STRLEN(STR).
in the LEN will have the total lenght, now using the offset you can read as you want ..
Hope you understand
Regards
Sudheer
‎2006 Oct 05 11:29 AM
SPLIT str AT '8' into str1 str2.
str1 has the string from start to 8
and str2 from 8 to end.
If you can have more 8 in the strings than you need to include more variables.
OR
If str CS '8'.
lpos = sy-fdpos - 1.
write str(lpos) to str1.
endif.
Message was edited by: Anurag Bankley
‎2006 Oct 05 11:34 AM
Hi Ravi,
You can use the offset technique to get certain part of a string
str = 'YUGFHKGHKHDKHHHGJK8HJBFXJKKFKJFJKFHJH'.
v_temp = str+0(8).where 0 is the starting position and 8 is the length of the string
so now v_temp will contain YUGFHKGH