简体   繁体   English

使用生成的“表单”将记录添加到 SAP 数据库

[英]Add record to SAP database with generated 'form'

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).我已经创建了一个屏幕,并在布局画家中创建了一个基于表格的“表单”(使用按 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!我是 ABAP 的初学者,我在这方面遇到了一些麻烦..谢谢!

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.我也在尝试更新数据库中的一行,但是使用此代码,数据库中的每一行都被删除,而不仅仅是具有指定 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.如果您使用了表定义中的向导,则输入字段可能已经是 Txxxx-v1 和 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. 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM