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: 

check unsaved data exist before leave in dynpro

jasonwangcn
Participant
0 Kudos

Hi All expert,

i created an own dynpro program with table control and tabstrips. User could save the data during operation.

Then go on do some changed. Then leave the transaction.Before the user leave the transaction, I need check is there any thing chaned but unsaved.

What is the best approach to check is there any data change after last save?

1 ACCEPTED SOLUTION

michael_piesche
Active Contributor

1) SY-DATAR

If it applies for your scenario, the ABAP System Field SY-DATAR is set to 'X', after the PAI event, if at least one input field on a screen was changed by a user or by other data being passed, otherwise it stays initial. If it is changed to X, you have to store this as a global/session flag, because it will be reset to initial, for the next PAI event when there is no additional change. When it comes to leaving the application, you can check for sy-datar or your flag being not initial (CHECK sy-datar = abap_true OR gv_datar = abap_true), and throwing the message that data has changed and if this should be saved before leaving.

2) ALV-Grid

If you happen to use the ALV-Grid, you can use the method CHECK_CHANGED_DATA of CL_GUI_ALV_GRID.

3) Y- and X-Data

In SAP standard you will find this 'problem' also solved by Y-DATA and X-DATA logic. Y-DATA being your old original data (read from DB or last save) and X-DATA being your new, current ongoing changes that have not been saved yet.

For any object, table, structure variable that you want to compare against any changes, you will therefore need to create a Y- and a X-data object. Currently you most likely only have one, a corresponding X-data and you are missing the Y-data for comparison.

In cases where only one db-record needs to be checked for changes, you will have Y- and X-data based on a structure (identical or similar to the db-structure). In cases where you have multiple db-records, you will have Y- and X-data based on a table (also identical or similar to the db-structure).

The reason why your underlying structures of Y- and X-data might differ from your db-table structure, depends on your scenario: you might want to compare only against relevant attributes that the user can change, and want to omit internal/system attributes, or you want to add further technical attributes, such as a CRUD-flag (create/read/update/delete) to clearly distinguish the current stage or also have separate data to check the overall change-status in case several db-tables have to be updated at once with a save.

For practical examples, look for the following:

  • search for YVBAK and XVBAK in programm SAPMV45A
  • or any other Y- and X-data such as Y-/XFPLA, Y-/XFPLT, Y-/XFPLTC

4) any other standard or custom logic?

I would be interested to know if you can think of any other general or specific, standard, out of the box or custom logic. Especially from other people in the community who have come across this topic?

2 REPLIES 2

michael_piesche
Active Contributor

1) SY-DATAR

If it applies for your scenario, the ABAP System Field SY-DATAR is set to 'X', after the PAI event, if at least one input field on a screen was changed by a user or by other data being passed, otherwise it stays initial. If it is changed to X, you have to store this as a global/session flag, because it will be reset to initial, for the next PAI event when there is no additional change. When it comes to leaving the application, you can check for sy-datar or your flag being not initial (CHECK sy-datar = abap_true OR gv_datar = abap_true), and throwing the message that data has changed and if this should be saved before leaving.

2) ALV-Grid

If you happen to use the ALV-Grid, you can use the method CHECK_CHANGED_DATA of CL_GUI_ALV_GRID.

3) Y- and X-Data

In SAP standard you will find this 'problem' also solved by Y-DATA and X-DATA logic. Y-DATA being your old original data (read from DB or last save) and X-DATA being your new, current ongoing changes that have not been saved yet.

For any object, table, structure variable that you want to compare against any changes, you will therefore need to create a Y- and a X-data object. Currently you most likely only have one, a corresponding X-data and you are missing the Y-data for comparison.

In cases where only one db-record needs to be checked for changes, you will have Y- and X-data based on a structure (identical or similar to the db-structure). In cases where you have multiple db-records, you will have Y- and X-data based on a table (also identical or similar to the db-structure).

The reason why your underlying structures of Y- and X-data might differ from your db-table structure, depends on your scenario: you might want to compare only against relevant attributes that the user can change, and want to omit internal/system attributes, or you want to add further technical attributes, such as a CRUD-flag (create/read/update/delete) to clearly distinguish the current stage or also have separate data to check the overall change-status in case several db-tables have to be updated at once with a save.

For practical examples, look for the following:

  • search for YVBAK and XVBAK in programm SAPMV45A
  • or any other Y- and X-data such as Y-/XFPLA, Y-/XFPLT, Y-/XFPLTC

4) any other standard or custom logic?

I would be interested to know if you can think of any other general or specific, standard, out of the box or custom logic. Especially from other people in the community who have come across this topic?

Sandra_Rossi
Active Contributor
0 Kudos
IF field1 <> saved_field1
  OR field2 <> saved_field2
  OR ...
  " Something has been changed
ENDIF.