12-15-2022 10:09 AM
Hi experts,
I have the data in my field symbol, I arranged it into fields, now I want to display count of each fields in o/p.
loop at dtab assigning <fs_dtab>.
Case sy-tabix.
When 1.
<fs_final>-bukrs = <fs_dtab>.
When 2.
<fs_final>-doknr = <fs_dtab>.
endcase.
Endloop.
this is final part of my code.
Now, for example
let say <fs_final>-bukrs field has 5 values ,
Then I want to display 'count of bukrs = 5'
Thanks in advance..
12-15-2022 10:38 AM
<fs_final>-bukrs field has 5 values - do you mean, it is line of a table with 5 distinct BUKRS values?
12-15-2022 11:29 AM
Hello,
You can use "strlen" syntax for string.
DATA:lv_length TYPE I.
lv_length = STRLEN( <fs_final>-bukrs ).
IF lv_length = 5.
Write: / 'Then I want to display count of bukrs = 5'.
ENDIF.
12-15-2022 2:23 PM
Thanks for help, my requirement is to get count of records,
Strlen gives me the length of single record
Length of single record doesn't matters, but I want just the count of all records present in <fs_final>-bukrs.
for example: if <fs_final>-bukrs has data's as below;
EUR10
EUR20
EUR30
EUR40
EUR50
O/P should be: no of bukrs = 5.
12-15-2022 2:13 PM
Yes , there was 5 bukrs values
Then I need to display its count of records in o/p.
Thanks.
12-15-2022 2:15 PM
To count the number of distinct BUKRS values:
12-15-2022 3:05 PM
How could you have 5 values of BUKRS, as you specify in your code BUKRS is the value of line 1 of the table DBTAB ?
You have 1 value of BUKRS
12-16-2022 8:45 AM
hello,
when you assign to bukrs then you can count to bukrs.
data:lv_count_bukrs type i.
loop at dtab assigning <fs_dtab>.
Case sy-tabix.
When 1.
<fs_final>-bukrs = <fs_dtab>.
lv_count_bukrs = lv_count_bukrs + 1.
When 2.
<fs_final>-doknr = <fs_dtab>.
endcase.
Endloop.
12-17-2022 3:50 PM
12-17-2022 7:10 PM
sun_light I don't see how the proposed answer can work. It returns lv_count_bukrs = 1, and you said you expect 5.
12-19-2022 8:08 AM
Hello Raja,
You can use SPLIT and LINES function to get the result.
DATA : lt_split TYPE STANDARD TABLE OF bukrs.
LOOP AT dtab ASSIGNING <fs_dtab>.
CASE sy-tabix.
WHEN 1.
<fs_final>-bukrs = <fs_dtab>.
SPLIT <fs_final>-bukrs AT space INTO TABLE lt_split.
DATA(lv_bukrs_cnt) = lines( lt_split ).
WHEN 2.
<fs_final>-doknr = <fs_dtab>.
ENDCASE.
ENDLOOP.