‎2007 Aug 08 7:22 AM
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
‎2007 Aug 08 7:33 AM
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>
‎2007 Aug 08 7:32 AM
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.
‎2007 Aug 08 7:33 AM
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
‎2007 Aug 08 7:33 AM
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>
‎2007 Aug 08 7:34 AM
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
‎2007 Aug 08 7:36 AM
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
‎2007 Aug 08 7:38 AM
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
‎2007 Aug 08 7:47 AM
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