开发者

Add record to SAP database with generated 'form'

开发者 https://www.devze.com 2023-03-06 19:31 出处:网络
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

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开发者_如何学C 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!


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. 
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号