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

reading a string.

Former Member
0 Likes
1,285

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

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,242

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

9 REPLIES 9
Read only

Former Member
0 Likes
1,243

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

Read only

0 Likes
1,242

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

Read only

0 Likes
1,242
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.
Read only

0 Likes
1,242

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

Read only

0 Likes
1,242

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

Read only

Former Member
0 Likes
1,242

Hi

data str(100).

str = 'YUGFHKGHKHDKHHHGJK8HJBFXJKKFKJFJKFHJH'.

search str for '8'. write sy-fdpos.

Max

Read only

Former Member
0 Likes
1,242

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

Read only

Former Member
0 Likes
1,242

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

Read only

Former Member
0 Likes
1,242

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