通过不使用结构作为数据持有者将单个插入 DB table

Insert single into DB table by not using structure as data holder

有没有办法在 db table 中插入单个记录而不使用结构作为数据持有者。

我在想

INSERT INTO table(filed1, field2) VALUES (value1, value2).

abap 中可以实现这样的功能吗?谢谢

不,这是不可能的,因为您不能使用 OpenSQL INSERT statements. You might be able to work around the need for a temporary structure on the right-hand side by using a VALUE type( ... ) 运算符指定单个目标字段,但我还没有尝试过。

您应该尝试动态创建结构。

使用 CL_ABAP_STRUCTDESCR=>CREATE,指定组件列表(列列表)及其类型,您将动态获得可用于创建数据引用的结构描述。

快速伪代码:

DATA coldescr TYPE REF TO cl_abap_structdescr.
DATA cols TYPE REF TO data.
FIELD-SYMBOLS <cols> TYPE any.

coldescr = cl_abap_structdescr=>create(  ).

CREATE DATA cols TYPE HANDLE coldescr.

ASSIGN cols->* TO <cols>.

您可以在插入 select stmt 时使用 <cols>