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

regarding string

Former Member
0 Likes
1,045

Hi frnds,

I have a requirement where i have to find the position numbers of '#' in the complet string.

can anyone help me how to approach.

<code>

REPORT ZTEST_POSITIONFINDER.

data : var1 type string .

var1 = '210651#WHA-588QV#11/26/2007 10:58#527.02#526.99#526.99#17640207#ALLEN K WITHRAW J#1000#CVGOGG20071118NL02#Approved on link to booking.#'.

</code>

help me frnds

regards,

satish

10 REPLIES 10
Read only

Former Member
0 Likes
1,021

search var1 for '.#.'.

this will get you the position of the first # in your string in variable sy-fdpos.

now use search var1 for '.#.' starting at sy-fdpos.

Read only

0 Likes
1,021

Hi Florian,

i tried the below way but actually First '#' is at

7th position but its showing 6th.Then how to get the next '#'.

<code>

REPORT ZTEST_POSITIONFINDER.

data : var1 type string ,

pos type i.

var1 = '210651#WHA-588QV#11/26/2007 10:58#527.02#526.99#526.99#17640207#ALLEN K WITHRAW J#1000#CVGOGG20071118NL02#Approved on link to booking.#'.

search var1 for '#'.

if sy-subrc eq 0.

write : / sy-fdpos.

endif.

</code>

regards,

satish

Read only

0 Likes
1,021

REPORT ZTEST_POSITIONFINDER.

data : var1 type string ,

pos type i,

slen type i.

var1 = '210651#WHA-588QV#11/26/2007 10:58#527.02#526.99#526.99#17640207#ALLEN K WITHRAW J#1000#CVGOGG20071118NL02#Approved on link to booking.#'.

pos = 0.

slen = strlen( var1 ).

do slen times.

if var1+pos(1) = '#'.

pos = pos + 1.

write pos.

else.

pos = pos + 1.

endif.

enddo.

Read only

Former Member
0 Likes
1,021

Use the Key word 'SEARCH FOR'.

Thanks,

Read only

Former Member
0 Likes
1,021

Hi,

You can use SPLIT command for separating the data.

Ex:

v_char = '210651#WHA-588QV#Test'.

SPLIT v_char AT '#' INTO v1

v2

v3.

Now, v1 will have 210651 and

similarly v2 = WHA-588QV,

v3 = Test

Now using STRLEN command, you can get the length of the individual fields data like

v_count = STRLEN( v1 ).

Then increment v_count by 1 and you will get the position of the '#'.

If you want any more help, get back to me.

Thanks & Regards,

Jalendhar

Read only

Former Member
0 Likes
1,021

Hi,

DATA : v_cnt TYPE I,

v_num TYPE I,

v_num1 TYPE I,

v_pos(100).

var1 = '210651#WHA-588QV#11/26/2007 10:58#527.02#526.99#526.99#17640207#ALLEN K WITHRAW J#1000#CVGOGG20071118NL02#Approved on link to booking.#'.

v_cnt = strlen( var1 ).

DO v_cnt TIMES.

v_count = v_count + 1.

IF var1+v_num1(v_count) EQ '#' .

concatenate v_count ',' INTO v_pos.

ENDIF.

ENDDO.

Write : v_pos.

Here you can see the # position numbers seperated by coma(,).

Read only

Former Member
0 Likes
1,021

Satish,

I forgot to add one more line in my earlier mail.Check now this.

DATA : v_cnt TYPE I,

v_num TYPE I,

v_num1 TYPE I,

v_pos(100).

var1 = '210651#WHA-588QV#11/26/2007 10:58#527.02#526.99#526.99#17640207#ALLEN K WITHRAW J#1000#CVGOGG20071118NL02#Approved on link to booking.#'.

v_cnt = strlen( var1 ).

DO v_cnt TIMES.

v_count = v_count + 1.

IF var1+v_num1(v_count) EQ '#' .

concatenate v_count ',' INTO v_pos.

  • v_count = v_count + 1.*

ENDIF.

ENDDO.

Write : v_pos.

Here you can see the # position numbers seperated by coma(,).

Read only

0 Likes
1,021

Hi Murali,

i m getting an error at

IF var1+v_num1(v_count) EQ '#' .

Relational operator '+' is not supported.

so can u suggest whts the problem.

regards,

satish

Read only

0 Likes
1,021

REPORT ZTEST_POSITIONFINDER.

data : var1 type string ,

pos type i,

slen type i,

schar type c.

var1 = '210651#WHA-588QV#11/26/2007 10:58#527.02#526.99#526.99#17640207#ALLEN K WITHRAW J#1000#CVGOGG20071118NL02#Approved on link to booking.#'.

pos = 0.

slen = strlen( var1 ).

do slen times.

schar = var1+pos(1).

if schar eq '#'.

pos = pos + 1.

write pos.

else.

pos = pos + 1.

endif.

enddo.

Read only

Former Member
0 Likes
1,021

Try this...


DATA : var1 TYPE string,
       w_lines TYPE i.

TYPES: BEGIN OF ty_table,
       line(200) TYPE c,
       END OF ty_table.

DATA: t_table TYPE STANDARD TABLE OF ty_table.

var1 = '210651#WHA-588QV#11/26/2007 10:58#527.02#526.99#526.
99#17640207#allen k withraw j#1000#cvgogg20071118nl02#approved on link
to booking.#'.

SPLIT var1 AT '#'
INTO TABLE t_table.

DESCRIBE TABLE t_table LINES w_lines.

WRITE:/ w_lines.

It will give you 11, which is the number of # symbols in your text...

Greetings,

Blag.