0

I've created a screen, and inside the layout painter I created a 'form' based on the table (using the wizard that appears when you hit F6). So now I have all the fields to create the row, and I've created a 'save' button to, but obviously nothing happens yet.

Could anyone link me to some kind of guid on how to make this functional? I'm a beginner at ABAP and I'm having quite some trouble with this.. Thanks!

edit

I'm also trying to update a row in the database, but using this code, every row in the database get's deleted, not only the one with the specified ID. Does anyone know what I'm doing wrong?

  UPDATE zmotoren_jat SET:
  prijs = zmotoren_jat-prijs,
  naam = zmotoren_jat-naam
  WHERE motorid = zmotoren_jat-motorid. "this line doesn't seem to work!
Sandra Rossi
  • 11,934
  • 5
  • 22
  • 48
  • 2
    Yeah, generally I hate telling people to read a book, but your question is so broad that you need some basic reading first. You need to link your button to UCOMM, check for the UCOMM in the PAI through a module, you have to think about enqueue/dequeue for locks, check for uniqueness, think about number ranges ( dont do your own ), and I am probably still forgetting much.. – tomdemuyt May 19 '11 at 19:21
  • Also: If you are trying to update one of SAP's provided tables a direct table update is the very last thing you want to do. SAP provides a number of ways to update their database tables via BAPIs; BDCs IDOCs etc. Upating via SAP provided functions ensures that the referencial integrity of the database remains. It looks like you're just playing around with your own tables... but I thought I'd just put this out there. – Esti May 19 '11 at 20:32

1 Answers1

1

short answer : you put the field content into a variable having the correct table structure, and insert this variable into the table (or update if you whish to modify an existing value)

DATA line LIKE Txxxx.   'Txxxx is the table you want to insert into
line-v1 = inputfield1.  'inputfield1 is your first inputfield
line-v2 = inputfiled2.  'inputfield1 is your second inputfield

INSERT Txxxx FROM line.
if sy-subrc ne 0.
* an error has occured...
endif.

if you used the wizard from the table definition, then the inputfields can already be something like Txxxx-v1 and Txxxx-v2. In this can its even simpler as you can just do the following :

INSERT Txxxx.

Please note that this is just some very quik and dirty answer to your question. You will probably have to check if the values have any sense, and at least if they do not already exist in the table.

Regards

Edit : about your update... the comma is separating the update in two. you should remove it.

Also, you should use a work area : a variable of the same structure that you fill. Then you use it to Create/Read/Update/delate in your table... This would simplify code reading.

Something like :

* define the working area
data wa_zmotoren_jat like zmotoren_jat.  " wa_ stand for "working area"
* modifiy the variable
wa_zmotoren_jat-motorid = ....
wa_zmotoren_jat-prijs = ...
wa_zmotoren_jat-naam = ...
* use it to update...
UPDATE zmotoren_jat SET:
  prijs = wa_zmotoren_jat-prijs,
  naam = wa_zmotoren_jat-naam
  WHERE motorid = wa_zmotoren_jat-motorid. 
PATRY Guillaume
  • 4,287
  • 1
  • 32
  • 41
  • This worked, thank you! I have one more problem: I'm also trying to update a row, but when I do so, all the rows in the table get updated, and not only the one in the 'where' clause. I've updated my post, can you take a look? thanks! –  May 31 '11 at 02:19
  • I'll try it with a work area, the comma was indeed the problem. Thanks! –  May 31 '11 at 18:46