0

I have created database table ZSP_EMP_DET inside which I am performing CRUD operations by providing values through screen .

So I have tried to find if record is already present in table or not and if found update values through screen but values are not getting modified inside DB table.

    DATA zsp_emp_det TYPE zsp_emp_det.
    DATA gwa_emp type table of zsp_emp_det.

    gwa_emp-empid = zsp_emp_det-empid.     "it is a name given to input fields on screen

    SELECT * from ZSP_EMP_DET
        where empid = gwa_emp-empid.

    IF sy-subrc = 0.
        gwa_emp-fname = zsp_emp_det-fname.
        gwa_emp-lname = zsp_emp_det-lname.
        gwa_emp-loc = zsp_emp_det-loc.
        gwa_emp-designation = zsp_emp_det-designation.
        gwa_emp-bdate = zsp_emp_det-bdate.
        gwa_emp-doj = zsp_emp_det-doj.
    
        MODIFY zsp_emp_det FROM gwa_emp.
    
    
        MESSAGE 'Data Modified Successfully' TYPE 'S'.
    
    ELSE.
        MESSAGE 'Data is not Modified' TYPE 'E'.
    ENDIF.
Sandra Rossi
  • 11,934
  • 5
  • 22
  • 48
sumedh patil
  • 59
  • 3
  • 8
  • 1
    Your program doesn't compile, please post a [minimal reproducible example](https://stackoverflow.com/help/minimal-reproducible-example). What is the primary key of your table? For information, you must test `SY-SUBRC` after MODIFY to know if it's successful and use `COMMIT WORK` to validate your changes. – Sandra Rossi Nov 17 '21 at 18:30
  • Does this answer your question? [Best way to modify a DB Table from a work area in ABAP](https://stackoverflow.com/questions/31609258/best-way-to-modify-a-db-table-from-a-work-area-in-abap) – Suncatcher Nov 18 '21 at 16:03

1 Answers1

2

You need to fill primary fields in your structure. I am not sure table structure. You can use move corresponding for filling your structure or you can select into structure like below.

 SELECT * 
   FROM ZSP_EMP_DET
   INTO gwa_emp
        where empid = gwa_emp-empid.
mkysoft
  • 5,392
  • 1
  • 21
  • 30
  • Thank you it worked . and also now that i trying modifying specific field ,if i dont enter data in other fields on screen ,they are getting modified as blank . can you please tell me how can i modify specific field without changing others in DB? – sumedh patil Nov 18 '21 at 03:36
  • 1
    If you are sure someone cannot update other fields in same time, you can read all fields and update new ones from screen and run MODIFY command. Otherwise you need to use UPDATE command for specific fields. – mkysoft Nov 18 '21 at 08:24
  • From ABAP release 7.55 you can declare an indicator structures along with the statement TYPES. This way you can specify specific field as update-relevant. – peterulb Nov 19 '21 at 21:19