Skip to Content
0
Former Member
Jul 24, 2007 at 12:20 AM

AT...ENDAT vs ON CHANGE OF

40 Views

Hi

I am trying to do an excercise to display a list of values from a table which has year, category, person, movie , award received.

Say the data is like this

2004 BACTRS AAAA movie1

2004 BACTRS AAAAA movie2

2004 BACTR BBB movie3

2004 BACTR BBBB movie4

2004 BPIC movie5

etc...

I have used the following query using ON CHANGE OF to display data group by year and category

SELECT * FROM znm_movie order by awdyear category.
    ON CHANGE OF znm_movie-awdyear or znm_movie-category.
      lncolor = lncolor + 1.
      FORMAT COLOR = lncolor.
      WRITE :/ lncolor.
    ENDON.

    WRITE :/ znm_movie-awdyear, znm_movie-category, znm_movie-person, znm_movie-movie, znm_movie-received.
ENDSELECT.

To get the same result using AT...ENDAT I have tried the following code

SELECT * FROM znm_movie INTO CORRESPONDING FIELDS OF TABLE it_movie_tab.

IF sy-subrc <> 0.
  WRITE : / 'No Records Found'.
ENDIF.

sort it_movie_tab BY awdyear ASCENDING category ASCENDING. "person ASCENDING movie ASCENDING.

LOOP AT it_movie_tab INTO it_movie_wa.

  AT FIRST.
    FORMAT COLOR = lncolor.
    WRITE : 'Year', 10 'Category', 20 'Person', 50 'Movie' , 80 'Received'.
    lncolor = lncolor + 1.
  ENDAT.

  AT NEW awdyear.
    ULINE. WRITE it_movie_wa-awdyear.
  ENDAT.

  WRITE :/10 it_movie_wa-category, 20 it_movie_wa-person, 50 it_movie_wa-movie, 80 it_movie_wa-received.

  AT END OF category.
      lncolor = lncolor + 1.
      FORMAT COLOR = lncolor.
      WRITE :/ lncolor.
  ENDAT.

ENDLOOP.

********************

But the results are different between the two programs. The excercise I was doing is expecting same results using AT...ENDAT and ON CHANGE OF.

Pls. Help.