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

Comparing two structures

Former Member
0 Likes
1,510

I have an application where users enter texts which get stored in a structure. I want a funcitonaluty to tell users when they close the application to make sure that unsaved data is saved before exiting the application.

So i will take the current structure and compare it with the data from the database and then prompt them to save the data.

Is it possible to compare two structures directly without checking for each field of the structure.

Thanks for your help

Regards

Sunil

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
743

Hi!

I guess this wont be the best approach to check out whether the user has save the data or not! It may happen that user will do some changes and then have the same entries while saving.

I had a similar requirement. If you are writing dialog program, what you can do is set a flag..(say save_flag), whenever the user saves data. When user tries to exit from application, check the status of of flag. If its set, exit else pop up a message to prompt user to save it.

Please correct me if I am wrong.

PAI-->

MODULE USER_COMMAND_9009 INPUT.
 when 'BACK'.
      IF SY-TCODE = trans_chg.
        if save_flgh = 1 and save_flgi = 1.

          LEAVE Program.
          clear: save_flgh,save_flgi.
        else.
          CALL FUNCTION 'POPUP_TO_CONFIRM'
            EXPORTING
              TITLEBAR              = 'Save Changes'
              TEXT_QUESTION         = 'The data is not saved, do you wish to save it?'
              TEXT_BUTTON_1         = 'YES'(001)
              TEXT_BUTTON_2         = 'NO'(002)
            IMPORTING
              ANSWER                = answer
            EXCEPTIONS
              TEXT_NOT_FOUND        = 1
              OTHERS                = 2.
          IF SY-SUBRC <> 0.
            MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
                    WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
          ENDIF.
          if answer = 1.
            wrk_header-EMPNO = EMPNO.
            wrk_header-EMPCO = EMPCO.
            modify ZEMPHDR from wrk_header.
            if sy-subrc = 0.
              save_flgh = 1.
            endif.

while saving-->

wrk_header-EMPNO = EMPNO.
  wrk_header-EMPCO = EMPCO.
  wrk_header-EMPNAME = EMPNAME.
  modify ZEMPHDR from wrk_header.           
  if sy-subrc ne 0.
  else.
    save_flgh = 1.
    MESSAGE s000(ztest) WITH temp_empno .
  endif.

Regards,

Sumit Nene.

Edited by: Sumit Nene on Jul 31, 2009 8:05 AM

5 REPLIES 5
Read only

venkat_o
Active Contributor
0 Likes
743

Hi Sunil, Try this way.


CASE SY_UCOMM.
 WHEN 'BACK' OR 'CANCEL' OR 'EXIT'.
  IF structure_1 NE structure_2.
    MESSAGE w020(z7) WITH 'please save the data'.
  ELSE.
    LEAVE PROGRAM.
  ENDIF.
ENDCASE.
Thanks Venkat.O

Read only

Former Member
0 Likes
743

Hi,

Try this way

Data : itab type mara.

data : jtab type mara.

pass all the data to the structure jtab from the screen and earlier values will be in itab.

even pass the sy-mandt to the jtab if required.

now

if itab <> jtab.

message 'The data has been changed Please Save it'.

endif.

you can also use the FM POP_TO_CONFIRM to get a pop in the standard way

Regards

Ramchander Rao.K

Read only

Former Member
0 Likes
743

hi,

make two internal tables using the strucures...

and then compare those tables.. in th following way

IF it_tab1] = it_tab2[.

" Tables contents are the same

ELSE.

" Tables contents are different

\give message to save th data

ENDIF.

Regards

Ashu

Read only

Former Member
0 Likes
743

Hi Sunil,

Venkat has answered your question.

ShreeMohan

Read only

Former Member
0 Likes
744

Hi!

I guess this wont be the best approach to check out whether the user has save the data or not! It may happen that user will do some changes and then have the same entries while saving.

I had a similar requirement. If you are writing dialog program, what you can do is set a flag..(say save_flag), whenever the user saves data. When user tries to exit from application, check the status of of flag. If its set, exit else pop up a message to prompt user to save it.

Please correct me if I am wrong.

PAI-->

MODULE USER_COMMAND_9009 INPUT.
 when 'BACK'.
      IF SY-TCODE = trans_chg.
        if save_flgh = 1 and save_flgi = 1.

          LEAVE Program.
          clear: save_flgh,save_flgi.
        else.
          CALL FUNCTION 'POPUP_TO_CONFIRM'
            EXPORTING
              TITLEBAR              = 'Save Changes'
              TEXT_QUESTION         = 'The data is not saved, do you wish to save it?'
              TEXT_BUTTON_1         = 'YES'(001)
              TEXT_BUTTON_2         = 'NO'(002)
            IMPORTING
              ANSWER                = answer
            EXCEPTIONS
              TEXT_NOT_FOUND        = 1
              OTHERS                = 2.
          IF SY-SUBRC <> 0.
            MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
                    WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
          ENDIF.
          if answer = 1.
            wrk_header-EMPNO = EMPNO.
            wrk_header-EMPCO = EMPCO.
            modify ZEMPHDR from wrk_header.
            if sy-subrc = 0.
              save_flgh = 1.
            endif.

while saving-->

wrk_header-EMPNO = EMPNO.
  wrk_header-EMPCO = EMPCO.
  wrk_header-EMPNAME = EMPNAME.
  modify ZEMPHDR from wrk_header.           
  if sy-subrc ne 0.
  else.
    save_flgh = 1.
    MESSAGE s000(ztest) WITH temp_empno .
  endif.

Regards,

Sumit Nene.

Edited by: Sumit Nene on Jul 31, 2009 8:05 AM