Application Development 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: 

Counting number of characters.

Former Member
0 Kudos

Hello Experts,

Please let me know on this.

Here is the source file :

72/070414/114147/11973//100-//EA/00000000///04198//RRT0/RC23///////353825001511172/72/070414/123620/11973//1000//EA/00000000///04198//RRT0/RC23///////354762008125236/72/070414/125411/13814//1000//EA/00000000///04198//INV/ID06///////90000000002697/72/070414/140820/11973//1000//EA/00000000///04198//RRT0/RC23///////353057002479718/72/070414/145438/13814//1000//EA/00000000///04198//INV/ID06///////90000000002739/72/070414/145438/11973//1000-//EA/00000000///04198//INV/ID06///////353057002479718/72/070414/150008/13814//1000-//EA/00000000///04198//INV/ID06///////90000000002739/72/070414/150008/11973//1000//EA/00000000///04198//INV/ID06///////353057002479718/72/070414/150611/13814//1000//EA/00000000///04198//INV/ID06///////90000000002744/72/070414/150611/11973//1000-//EA/00000000///04198//INV/ID06///////354762008125236/72/070414/153158/13814//1000-//EA/00000000///04198//INV/ID06///////90000000002744/72/070414/153158/11973//1000//EA/00000000///04198//INV/ID06///////354762008125236/72/070414/154629/13814//1000//EA/00000000///04198//INV/ID06///////90000000002759/72/070414/154629/11973//1000-//EA/00000000///04198//INV/ID06///////353057002479718/72/070414/154904/13814//1000-//EA/00000000///04198//INV/ID06///////90000000002759/72/070414/154904/11973//1000//EA/00000000///04198//INV/ID06///////353057002479718/72/070414/171923/13814//1000//EA/00000000///04198//INV/ID06///////90000000002779/72/070414/171924/11973//1000-//EA/00000000///04198//INV/ID06///////353825001511172/72/070414/183753/13814//1000//EA/00000000///04198//INV/ID06///////90000000002784/1559\

  • The followoing are my requirements : *

1) I want to count the number of characters in this source file. This source file is stored in a structure ITAB.

2) Also I want to count the number of '/' slash in this source file.

3) I want to compare the number of characters in the source file till the last '/' to that of the number before '\' i.e., 1559, which is the cheksum number.

Please let me know on this ASAP. Points to be awarded to precise answers for all 3 questions. Thanks in advance.

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hello Debaprasad Narendra,

I guess the easiest way is to first convert the ITAB to a string.

DATA:

zlv_string TYPE string.

LOOP AT itab.

CONCATENATE zlv_string itab INTO zlv_string.

ENDLOOP.

Then you can use the FIND statement to answer your questions.

Regards,

John.

9 REPLIES 9

Former Member
0 Kudos

Hello Debaprasad Narendra,

I guess the easiest way is to first convert the ITAB to a string.

DATA:

zlv_string TYPE string.

LOOP AT itab.

CONCATENATE zlv_string itab INTO zlv_string.

ENDLOOP.

Then you can use the FIND statement to answer your questions.

Regards,

John.

0 Kudos

Hi,,

have a look at this code.

data:

w_char(256) type c value 'i love india'.

data:

w_temp like sy-index,

w_index type i.

data:

w_letter type c valu 'i'.

do.

search w_char for w_letter .

if sy-subrc eq 0.

w_temp = w_temp + 1.

w_index = sy-fdpos + 1.

w_char = w_char+w_index.

else.

exit.

endif.

enddo.

i think this code will help u to solve u r problem plzz reward if it is usefull

Former Member
0 Kudos

Debaprasad,

what are the fields in itab? As per your quey i think you have one field.

If yes..

DATA : v_num TYPE i,

v_count TYPE I value 1,

v_char_cnt TYPE i,

v_slah_cnt TYPE i..

v_num = strlen( itab-field ).

do v_num TIMES.

IF itab-field+0(v_count) CA SY-ABCDE.

v_char_cnt = v_char_cnt + 1.

v_count = v_count + 1.

ELSEIF itab-field+0(v_count) CO '/'.

v_slah_cnt = v_slah_cnt + 1.

ENDDO.

Don't forget to reward if useful......

Former Member
0 Kudos

Hi,

initially

loop at itab

split itab at '/' into string.
if sy-subrc eq 0.
w_num = w_num + 1.
endif.

w_int = strlen( string ).

w_sum = w_int + w_sum+1.
endloop.
here u will get w_num is number of slashes
w_int = lettercount before /
w_sum eq number of letters in the file.

Plzz reward points if it helps.

Former Member
0 Kudos

Hello

Please check the code as below

1) I want to count the number of characters in this source file. This source file is stored in a structure ITAB.

-


data cnt type i.

Loop at itab.

cnt = cnt + strlen( itab-data ).

endloop.

-


Now the variable cnt will have the total number of characters in the file.

2) Also I want to count the number of '/' slash in this source file.

-


data : cnt_slash type i.

data : cnt_line type i.

loop at itab.

cnt_line = strlen( itab-data ).

do cnt_line times.

if itab-data+sy-index( 1 ) = '/'.

cnt_slash = cnt_slash + 1.

endif.

enddo.

endloop.

Now cnt_slash will contain the number of '/'s in the ITAB.

-


3) I want to compare the number of characters in the source file till the last '/' to that of the number before '\' i.e., 1559, which is the cheksum number.

-


data : slash_pos type i.

data check_sum type i.

data : cnt_line type i.

data : cnt_chars type i.

loop at itab.

cnt_line = strlen( itab-data ).

do cnt_line times.

if itab-data+sy-index( 1 ) = '/'.

slash_pos = sy-index + 1.

cnt_char = cnt_char + 1.

endif.

if itab-data+sy-index( 1 ) = '\'.

check_sum = itab-data+slash_pos( sy-index ).

slash_pos = sy-index + 1.

else.

cnt_char = cnt_char + 1.

endif.

enddo.

endloop.

Now cnt_char will have total character - check sum characters. Check_sum will have the number between '/' and '\'.

-


Regards

Ranganath

Former Member
0 Kudos

Answers

-


1) I want to count the number of characters in this source file. This source file is stored in a structure ITAB.

loop the itab

concatenate all the fields into a TEMP string

use DESCRIBE FIELD temp length len

where len a variable of type i

use an accumalator to store this len value as

total_size = total_size + len

Use this code for the following 2 questions

DATA: RESULT_TAB TYPE MATCH_RESULT_TAB.

FIELD-SYMBOLS <MATCH> LIKE LINE OF RESULT_TAB.

FIND ALL OCCURRENCES OF '\' IN INFILE RESULTS RESULT_TAB.

LOOP AT RESULT_TAB ASSIGNING <MATCH>.

AT LAST.

LV_POS = <MATCH>-OFFSET.

ENDAT.

ENDLOOP.

award points

2) Also I want to count the number of '/' slash in this source file.

3) I want to compare the number of characters in the source file till the last '/' to that of the number before '\' i.e., 1559, which is the cheksum number.

Former Member
0 Kudos

DATA : char_count TYPE i.
DATA : slash_count TYPE i.
DATA : pos TYPE i VALUE 1.
DATA: l_str TYPE string VALUE '-//EA/00000000///04198//INV/ID06/////////1000//EA/00000000///04198//INV/ID06///////90000000002784/1559\'.
DATA: result_tab TYPE match_result_tab.

"Assign itab-value to l_str.

***1) I want to count the number of characters in this source file. This source file is stored in a structure ITAB.
char_count = STRLEN( l_str ).
WRITE 😕 char_count.

***2) Also I want to count the number of '/' slash in this source file.
FIND ALL OCCURRENCES OF REGEX '/'
     IN l_str
     RESULTS result_tab.
DESCRIBE TABLE result_tab LINES slash_count.
WRITE 😕 slash_count.

*3) I want to compare the number of characters in the source file till the last '/' to that of the number before '\' i.e., 1559, which is the cheksum number
????????

Former Member
0 Kudos

Thanks. The second part of my question was answered. Please let me know about the first and the last part.

Former Member
0 Kudos

1) What i meant by the third question is:

The number of chracters(say i_count) until the last '/' (forward slash) should be equal to the number before the '\' (backward slash) i.e., 1559(say w_count). Now that this number(w_count) is in a structure, how do i check that the (i_count = w_count).

2) Also how do I delete the last record of an internal table. ??