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: 

Field restarting the counter

jogeswararao_kavala
Active Contributor
0 Kudos

Dear Experts,

I have a row counting field in the report output.

The data is sorted on one field (EQUNR)

My requirement is the counter field is to restart when a new value starts for EQUNR.

I could achieve this with the following code, but  this does not work when single EQUNR value is queried.

When debugged I understand this is not the way to achieve the result.

data cnt type i.
data eqp type char18.

loop at itab into wa.
eqp = wa-equnr.

      loop at itab into wa.
          if wa-equnr = eqp.

  cnt = cnt + 1.
  wa-count = cnt .
  MODIFY TABLE ITAB FROM WA TRANSPORTING count.

  else.

    cnt = 0.
    endif.
  endloop.
  endloop.

(Screenshots attached)

Can someone help.

Regards

Jogeswara Rao

1 ACCEPTED SOLUTION

former_member585060
Active Contributor
0 Kudos

Hi,

     Use Control break events. use  AT NEW equnr to reset the counter.

Search scn with control break events, there are many posts on this topic.

http://wiki.sdn.sap.com/wiki/display/Snippets/control+break+events

Thanks & Regards

Bala Krishna

4 REPLIES 4

former_member585060
Active Contributor
0 Kudos

Hi,

     Use Control break events. use  AT NEW equnr to reset the counter.

Search scn with control break events, there are many posts on this topic.

http://wiki.sdn.sap.com/wiki/display/Snippets/control+break+events

Thanks & Regards

Bala Krishna

0 Kudos

Thank you Balakrishna.

I'll explore.

Regards

Jogeswara Rao

0 Kudos

TYPES : BEGIN OF ty_itab,

           equnr TYPE equnr,

           count TYPE i,

           num   TYPE c length 10,

           date  TYPE d,

        END OF ty_itab.

DATA : i_itab  TYPE STANDARD TABLE OF ty_itab,

       WA_itab TYPE ty_itab,

       v_num   TYPE i.

FIELD-SYMBOLS : <fs_line> TYPE ANY.

    

* Selection logic

 

...

...

 

SORT i_itab BY equnr.

LOOP AT i_itab ASSIGNING <fs_line>.

AT NEW equnr.

CLEAR : v_num.

ENDAT.

<fs_line>-count = v_num.

v_num = v_num + 1.

  

ENDLOOP.

Thanks & Regards

Bala Krishna

0 Kudos

Thank you Balakrishna.

Regards

Jogeswara Rao