cancel
Showing results for 
Search instead for 
Did you mean: 

ON change does not detect my first record.

aris_hidalgo
Contributor
0 Kudos

Hello experts,

I have added a code that every time it detects a change on field ls_lines it would do the functions below. But my problem is that when I run my sapscript form the first record does not display. I have posted below my code which is inside a form that is inside a loop..Any alternatives here guys?thanks a lot!

ON CHANGE OF MKPF-MBLNR OR MSEG-EBELN OR MSEG-BWART OR MSEG-WERKS.

CLEAR XKOPFDR.

ENDON.

ON change of ls_lines.

CLEAR XKOPFDR.

NEW_PAGE = X.

endon.

IF XKOPFDR IS INITIAL.

XKOPFDR = X.

IF NEW_PAGE = X.

clear new_page.

CALL FUNCTION 'CONTROL_FORM'

EXPORTING COMMAND = 'NEW-PAGE'.

ENDIF.

CALL FUNCTION 'WRITE_FORM'

EXPORTING ELEMENT = 'KOPF'

WINDOW = 'KOPF'.

NEW_PAGE = X.

CALL FUNCTION 'WRITE_FORM'

EXPORTING ELEMENT = 'POS_ZEILE'

WINDOW = 'MAIN'.

LOOP AT SERIAL_TAB.

IF SY-TABIX EQ L_LINES.

V_FINISH = 'Y'.

ENDIF.

CALL FUNCTION 'WRITE_FORM'

EXPORTING ELEMENT = 'SERNUM'

WINDOW = 'MAIN'.

V_FIRST_NUM = 'N'.

ENDLOOP.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

HI viray,

just store the ls_lines into a tmp variable and check it every time..

when not equal .. means a change..


if tmp_ls_line NE ls_lines.
CLEAR XKOPFDR.
NEW_PAGE = X.
endif.

tmp_ls_lines  = ls_lines.

this will work for all records...

regards

satesh

Answers (6)

Answers (6)

Former Member
0 Kudos

Hello Viraylab,

As u have said within loop u r executing a perform and within this u are checking for on change. This field ls_lines is field in internal table traptab?

if yes then the code should be

on change traptab-ls-lines.

clear ...

endon.

Former Member
0 Kudos

Hi,

You should sort on the fields which you are using in ON CHANGE OF.

If it still does not work,

try replacing ON CHANGE by AT NEW.

Regards,

Shashank

aris_hidalgo
Contributor
0 Kudos

The problem is, ls_lines is not part of the itab that i'm looping. Also, I didn't use a where conditon in loop. just:

loop at traptab.

...

...

PERFORM get_serial_nos. "here is where it gets new ls_lines

PERFORM wa03_ausgabe. "the code earlier...

...

endloop.

Former Member
0 Kudos

Hi,

ON CHANGE will work only when you are looping in the same table. It is a control break statement which has to be used in loop.

Regards,

Shashank

Former Member
0 Kudos

Hi Viraylab,

use 'AT NEW F'

Former Member
0 Kudos

Hello,

If you have not done so already, please read the F1 documentation for ON CHANGE OF.

The following conditions are necessary -

1. This statement is to be used within a LOOP...ENDLOOP.

2. The Table should be sorted by the fileds which are being used in ON CHANGE OF.

3. You should not use LOOP AT WHERE.

Regards,

Anand Mandalika.

Former Member
0 Kudos

Hi Viray,

Try to use At new followed by ENDAT instead of On Change.

It is always suggested to use At New control statemnet for the reqmt. ur looking for.

You can check for more help on AT new , bu preesing F1 on the same.

Cheers

Sunny

Rewrd points, if found helpful

Former Member
0 Kudos

are u using LOOP AT WHERE or only LOOP bcoz control breaks will not work in LOOP AT WHERE condition