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: 

AT...ENDAT vs ON CHANGE OF

Former Member
0 Kudos
111

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.

1 ACCEPTED SOLUTION

Former Member
0 Kudos
70

i think there is something wrong with the code

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.

i dont exactly see anything wrong with the AT...ENDAT statement, but dont understand why this code is not giving the same result as ON CHANGE OF!!

1 REPLY 1

Former Member
0 Kudos
71

i think there is something wrong with the code

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.

i dont exactly see anything wrong with the AT...ENDAT statement, but dont understand why this code is not giving the same result as ON CHANGE OF!!