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

String India

Former Member
0 Likes
964

Hi,

Plz tell me how to write the program

1. Accept the String INDIA and Split as I

I N

I N D

I N D I

I N D I A

2. Accept the string and search character and display the number of occurances of that search character in that string.

Thanks

1 ACCEPTED SOLUTION
Read only

varma_narayana
Active Contributor
0 Likes
924

Hi...

<b>1. Accept the String INDIA and Split as I

I N

I N D

I N D I

I N D I A</b>

<b>Check the Soution</b>

PARAMETERS: PSTR(10) DEFAULT 'INDIA'.

DATA : V_POS TYPE I VALUE 0,

V_LEN TYPE I.

V_LEN = STRLEN( PSTR ).

DO V_LEN TIMES.

WRITE:/ PSTR+V_POS(SY-INDEX).

ENDDO.

<b>2. Accept the string and search character and display the number of occurances of that search character in that string.</b>

Solution:

PARAMETERS: PSTR(10) DEFAULT 'INDIA',

PCHR DEFAULT 'I'.

DATA : V_POS TYPE I VALUE 0,

V_LEN TYPE I,

V_COUNT TYPE I.

V_LEN = STRLEN( PSTR ).

DO V_LEN TIMES.

IF PSTR+V_POS(1) = PCHR.

ADD 1 TO V_COUNT.

ENDIF.

ADD 1 TO V_POS.

ENDDO.

Write:/ 'No of occurrences', V_COUNT.

<b>Reward if Helpful</b>

<b></b>

7 REPLIES 7
Read only

Former Member
0 Likes
924

Hi ,

try this

REPORT yyyvenkateshtesting .

DATA: c(5) TYPE c VALUE 'INDIA'.

DATA: a TYPE i.

DATA: b TYPE i.

a = 0.

b = 0.

DO 5 TIMES.

b = b + 1.

DO b TIMES.

WRITE:/ c+a(b).

exit.

ENDDO.

ENDDO.

reward points if helpful,

thanks & regards,

venkatesh.

Read only

Former Member
0 Likes
924

Hi rams,

You can search for using the string operators like CA, CO etc.

This will return the position found in system variable sy-fdpos.

Using that position you can split the string and manipulate as you wish.

Regards,

Yogesh

Read only

varma_narayana
Active Contributor
0 Likes
925

Hi...

<b>1. Accept the String INDIA and Split as I

I N

I N D

I N D I

I N D I A</b>

<b>Check the Soution</b>

PARAMETERS: PSTR(10) DEFAULT 'INDIA'.

DATA : V_POS TYPE I VALUE 0,

V_LEN TYPE I.

V_LEN = STRLEN( PSTR ).

DO V_LEN TIMES.

WRITE:/ PSTR+V_POS(SY-INDEX).

ENDDO.

<b>2. Accept the string and search character and display the number of occurances of that search character in that string.</b>

Solution:

PARAMETERS: PSTR(10) DEFAULT 'INDIA',

PCHR DEFAULT 'I'.

DATA : V_POS TYPE I VALUE 0,

V_LEN TYPE I,

V_COUNT TYPE I.

V_LEN = STRLEN( PSTR ).

DO V_LEN TIMES.

IF PSTR+V_POS(1) = PCHR.

ADD 1 TO V_COUNT.

ENDIF.

ADD 1 TO V_POS.

ENDDO.

Write:/ 'No of occurrences', V_COUNT.

<b>Reward if Helpful</b>

<b></b>

Read only

Former Member
0 Likes
924

hi,

REPORT ZNAZSPLIT .

data : lv_i(5) type c value 'INDIA',

lv type c value 'I'.

data: lv_len type i,

i type i,

j type i,

k type i.

lv_len = strlen( lv_i ).

i = 1.

k = 0.

j = 0.

do lv_len times.

write : / lv_i+0(i).

i = i + 1.

if lv_i+k(1) = lv.

j = j + 1.

endif.

k = K + 1.

enddo.

write : / 'I occurs ' , j , 'times'.

copy and paste the program above.. your result occurs

rewards if useful,

regards,

Nazeer shaik

Read only

Former Member
0 Likes
924

Hi Ram,

<b>1. Accept the String INDIA and Split as </b>

PARAMETERS: S_NAME TYPE STRING.

DATA V_LENGTH TYPE I.

DATA V_INDEX TYPE SY-INDEX.

V_LENGTH = STRLEN( S_NAME ).

DO V_LENGTH TIMES.

V_INDEX = SY-INDEX.

DO V_INDEX TIMES.

V_POS = V_INDEX - 1.

WRITE: S_NAME+V_POS(1).

ENDDO.

ENDDO.

<b>2. Accept the string and search character and display the number of occurances of that search character in that string

</b>

PARAMETERS: P_NAME TYPE STRING.

PARAMETERS: P_SC.

DATA V_LENGTH TYPE I.

DATA V_COUNT TYPE I.

V_LENGTH = STRLEN( P_NAME ).

DO V_LENGTH TIMES.

V_INDEX = SY-INDEX - 1.

IF P_NAME+V_INDEX(1) = P_SC.

V_COUNT = V_COUNT + 1.

ENDIF.

ENDDO.

IF V_COUNT IS NOT INITIAL.

WRITE:/ 'The search character found ', V_COUNT, 'times'.

ELSE.

WRITE:/ 'Search character doest not find in the String'.

ENDIF.

Thanks,

Vinay

Read only

Former Member
0 Likes
924

Hi Rams,

PARAMETERS: STRING(5) DEFAULT 'INDIA'.

DATA : V_LEN TYPE I,

VAR TYPE I VALUE1.

V_LEN = STRLEN( STRING ).

DO V_LEN TIMES.

IF VAR < V_LEN.

WRITE:/ STRING + 0 ( VAR ).

NEW-LINE.

ENDIF.

VAR = VAR + 1.

ENDDO.

Reward points for all helpful answers,

kiran.M

Read only

satykumar
Product and Topic Expert
Product and Topic Expert
0 Likes
924

try this to split any string

DATA length TYPE i.

PARAMETERS name TYPE string.

length = STRLEN( name ).

DO.

DATA : v_str TYPE string,

v_substr TYPE string,

v_position TYPE i.

v_str = name.

v_position = v_position + 1.

v_substr = v_str+0(v_position).

WRITE 😕 v_substr.

IF v_position = length.

EXIT.

ENDIF.

regards,

Satyendra