Application Development and Automation 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: 
Read only

on change event

Former Member
0 Likes
1,944

Hi experts,

Iam trying to display the data using itab(t_det) and it is having REVNR filed like this.


AUFNR  RSNUM      REVNR 
4006149|0043996297|11ATS9-8|
4006150|0043996338|11ATS9-8|
4006161|0043996297|11ATS9-9|
4006162|0043996338|11ATS9-10|

If REVNR changes i want to display the data in new page like this.

<b>11ATS9-8

-


</b>

4006149

4006150

<b>11ATS9-9

-


</b>

4006161

<b>11ATS9-10

-


</b>

4006162

I have written following code.Just i want to know is it correct approach...



  LOOP AT T_DET.

<b>    ON CHANGE OF T_DET-REVNR.
      NEW-PAGE.</b>

      WRITE:/1(10) T_DET-AUFNR,
             14(20) T_DET-EQKTX,
             36(4) T_DET-VKBUR,
             43(12) T_DET-ERNAM,
             54(10) T_DET-BUDAT,
             66(5) T_DET-MENGE,
             75(3) T_DET-MEINS.
    <b>ENDON.</b>

  ENDLOOP.

reward guaranteed

thanks

kaki

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,902

Yes as amit said the fields which we need to look up for onchange/internal table events we have to place the fields as first in the sequence of sort in the internal table .

16 REPLIES 16
Read only

Former Member
0 Likes
1,902

Hi kaki,

1. If REVNR changes

If u want that,

then take this field as FIRST field in the

internal table.

Then SORT It.

Then use loop.

2. BCOS,

If its third field,

then apbap will consider

THE COMBINATINO OF 1, 2 AND THIRD FIELD.

iF THE COMBINATION CHAGNES,

THEN ALSO THE EVENT WILL GET TRIGGERED.

regards,

amit m.

Read only

Former Member
0 Likes
1,902

It looks fine - are you having any issues when executing the report?

Sudha

Read only

Former Member
0 Likes
1,902

Hi kaki

there is small change

<b>LOOP AT T_DET.

ON CHANGE OF T_DET-REVNR.

if sy-index ne 0.

NEW-PAGE.

endif.

write: t_det-revnr.

ENDON.

WRITE:/1(10) T_DET-AUFNR,

14(20) T_DET-EQKTX,

36(4) T_DET-VKBUR,

43(12) T_DET-ERNAM,

54(10) T_DET-BUDAT,

66(5) T_DET-MENGE,

75(3) T_DET-MEINS.

ENDLOOP.</b>

<b>HI kaki

SORT t_DET on refnr.

will do</b>

regards

kishore

try this. it works

Message was edited by: Harikishore Sreenivasulu

Message was edited by: Harikishore Sreenivasulu

Read only

Former Member
0 Likes
1,903

Yes as amit said the fields which we need to look up for onchange/internal table events we have to place the fields as first in the sequence of sort in the internal table .

Read only

0 Likes
1,902

So if i change the itab structure, it is enough right??


DATA: BEGIN OF T_DET OCCURS 0,
        REVNR LIKE AFIH-REVNR,
        AUFNR LIKE AUFK-AUFNR,
        RSNUM LIKE AFKO-RSNUM,
      END OF T_DET.

Read only

0 Likes
1,902

Hi again,

1. Thats perfectly right !

2. One more thing, which ideally should be done is :

The other fields,

should be written after ENDON.

Bcos, when the event is triggered

, the other fields will have * as value.

(in some events, it has *, probably

in change, it has the value of the first

combination row).

However, its advisable to use

the other fields for displaying,

after ENDON.

*----


3. ALSO DON'T FORGET TO

SORT THE ITAB ON THAT FIELD.

(VERY VERY IMPORTANT)

regards,

amit m.

Message was edited by: Amit Mittal

Read only

0 Likes
1,902

Hi amit,

You mean wright statment should be like this??


  SORT T_DET BY REVNR.

  LOOP AT T_DET.

    ON CHANGE OF T_DET-REVNR.
      NEW-PAGE.
    ENDON.
      WRITE:/1(10) T_DET-AUFNR,
             14(20) T_DET-EQKTX,
             36(4) T_DET-VKBUR,
             43(12) T_DET-ERNAM,
             54(10) T_DET-BUDAT,
             66(5) T_DET-MENGE,
             75(3) T_DET-MEINS.
  ENDLOOP.

Read only

0 Likes
1,902

Hi again,

1. Almost like this :

2. However, u need to write REVNR in

ON CHANGE OF T_DET-REVNR.

NEW-PAGE.

write 😕 REVNR. (<------ here)

ENDON.

regards,

amit m.

Read only

0 Likes
1,902

Iam using something like this...


  LOOP AT T_DET.

    ON CHANGE OF T_DET-REVNR.
      NEW-PAGE.

      WRITE:/1(10) T_DET-AUFNR,
             14(20) T_DET-EQKTX,
             36(4) T_DET-VKBUR,
             43(12) T_DET-ERNAM,
             54(10) T_DET-BUDAT,
             66(5) T_DET-MENGE,
             75(3) T_DET-MEINS.
    ENDON.
ENDLOOP.

TOP-OF-PAGE.
  WRITE:/ 'Revision', 20 ':',SPACE, T_DET-REVNR.

Read only

0 Likes
1,902

Hi Kaki,

there is no difference between on change and at new .

if you see my code in the above post.

replace at new with on change,

and endat with endon. the code work very well.

both are same.

Regards

vijay

Read only

0 Likes
1,902

Hi again,

1. It should be like this:

LOOP AT T_DET.

ON CHANGE OF T_DET-REVNR.

NEW-PAGE.

WRITE <------- if u want to write something else also

<b>ENDON.</b>

WRITE:/1(10) T_DET-AUFNR,

14(20) T_DET-EQKTX,

36(4) T_DET-VKBUR,

43(12) T_DET-ERNAM,

54(10) T_DET-BUDAT,

66(5) T_DET-MENGE,

75(3) T_DET-MEINS.

ENDLOOP.

TOP-OF-PAGE.

WRITE:/ 'Revision', 20 ':',SPACE, T_DET-REVNR.

[/CODE]

regards,

amit m.

Read only

0 Likes
1,902

Hello Amit,

As per your reply, the 'AT NEW' event makes the other field value of the internal table to ''.So I am tempted to ask you the reason why the others fields of the internal table are marked with ''.

Could you please clarify me , eventhough this is out of the scope of this question?.

Regards,

Partha

Read only

0 Likes
1,902

Hi parthasarthy,

1. The reason is :

At this point of time,

(when the AT NEW event fires

because of new field combination)

, then what should be value

of other fields ?

ITS NOT WELL DEFINED !

2. One may say that the values

in other fields, should be

having those values of the 1st record

at which the BREAK/NEW occurs !

3. Also u will agree that,

when we use GROUP BY in a normal sql in oracle,

the other fields we cannot write

in select query.

select bukrs , BUTXT

from t001

group by bukrs

(HERE BUTXT will not be allowed,

becuase group by is only on BUKRS,

so at that point of time, BUTXT is not defined

properly )

4. However, ON CHANGE OF

does not have this problem.

It contains the value of the corresponding

record in the loop.

regards,

amit m.

Read only

Former Member
0 Likes
1,902

Hi Kaki,

Here is another way..

REPORT  ZTEST_CODE  NO STANDARD PAGE HEADING .


DATA: BEGIN OF ITAB OCCURS 0,
       REVNR TYPE REVNR,
       AUFNR TYPE AUFNR,
       RSNUM TYPE RSNUM,
      END OF ITAB.

ITAB-REVNR = 'test123'.
ITAB-AUFNR = 'abcdef'.
ITAB-RSNUM = 'user12'.

APPEND ITAB.
CLEAR ITAB.

ITAB-REVNR = 'test123'.
ITAB-AUFNR = 'abcdef1'.
ITAB-RSNUM = 'user12'.

APPEND ITAB.
CLEAR ITAB.

ITAB-REVNR = 'test123'.
ITAB-AUFNR = 'abcd12'.
ITAB-RSNUM = 'user12'.

APPEND ITAB.
CLEAR ITAB.

ITAB-REVNR = 'test123'.
ITAB-AUFNR = 'abcdef34'.
ITAB-RSNUM = 'user12'.

APPEND ITAB.
CLEAR ITAB.

ITAB-REVNR = 'test123'.
ITAB-AUFNR = 'abcdef'.
ITAB-RSNUM = 'user12'.

APPEND ITAB.
CLEAR ITAB.

ITAB-REVNR = 'testabc'.
ITAB-AUFNR = 'abcdef1'.
ITAB-RSNUM = 'user12'.

APPEND ITAB.
CLEAR ITAB.

ITAB-REVNR = 'testabc'.
ITAB-AUFNR = 'abcd12'.
ITAB-RSNUM = 'user12'.

APPEND ITAB.
CLEAR ITAB.

ITAB-REVNR = 'testabc'.
ITAB-AUFNR = 'abcdef34'.
ITAB-RSNUM = 'user12'.

APPEND ITAB.
CLEAR ITAB.

TOP-OF-PAGE.
  WRITE:/ '_________________________________________'.
  WRITE:/ 'This is for heading'.

END-OF-SELECTION.
  SORT ITAB BY REVNR.

  LOOP AT ITAB.

    AT NEW REVNR.
      WRITE:/ 'REVNR:' , ITAB-REVNR.
      WRITE:/ '_________________________________________'.
      WRITE:/ 'AUFNR' ,
              'RSNUM' .

    ENDAT.

    WRITE:/ ITAB-AUFNR,
            ITAB-RSNUM.
    AT END OF ABLAD.
      NEW-PAGE.
    ENDAT.
  ENDLOOP.

Regards

Vijay

Read only

Former Member
0 Likes
1,902

Hi,

1. DIFFERENCE between

AT NEW and ON CHANGE OF.

( * and field-value)

2. Just copy paste this code in new program.

3.

REPORT abc.

DATA : t001 LIKE TABLE OF t001 WITH HEADER LINE.

SELECT * FROM t001 INTO TABLE t001.

LOOP AT t001.

AT NEW bukrs.

WRITE 😕 'AT NEW : ' , t001-bukrs , t001-butxt.

ENDAT.

ON CHANGE OF t001-bukrs.

WRITE 😕 'ON CHANGE OF : ' , t001-bukrs , t001-butxt.

ENDON.

WRITE 😕 .

ENDLOOP.

regards,

amit m.

Read only

Former Member
0 Likes
1,902

Thanks Amit .