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: 

To find count of each field present in fieldsymbol

sun_light
Explorer
0 Kudos

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..

10 REPLIES 10

touzik_itc
Active Participant
0 Kudos

<fs_final>-bukrs field has 5 values - do you mean, it is line of a table with 5 distinct BUKRS values?

abityildiz
Active Participant
0 Kudos

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.

0 Kudos

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.

sun_light
Explorer
0 Kudos

Yes , there was 5 bukrs values

Then I need to display its count of records in o/p.

Thanks.

Sandra_Rossi
Active Contributor

To count the number of distinct BUKRS values:

  1. Collect the values of BUKRS of all lines into an internal table with unique values. See ABAP documentation of ABAP statements to work with internal tables.
  2. Then count the number of lines in this internal table (function LINES).

FredericGirod
Active Contributor
0 Kudos

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

abityildiz
Active Participant
0 Kudos

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.

0 Kudos

Thanks a lot, this works

0 Kudos

sun_light I don't see how the proposed answer can work. It returns lv_count_bukrs = 1, and you said you expect 5.

yashoratna
Participant
0 Kudos

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.