SAP ABAP。取一个透明表数据放到另外一个透明表。并保持数据同步

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了SAP ABAP。取一个透明表数据放到另外一个透明表。并保持数据同步相关的知识,希望对你有一定的参考价值。

请定义一个内表,来存放从透明表A取出的数据;然后把内表的数据Modify到透明表B。这个问题就解决了。追问

如果取2个透明表 数据放到 1个呢?

追答

也可以的。只要你定义一个合适的内表,然后把两个透明表的数据都放到这个内表中,然后再更新至某个透明表中即可。
我觉得这是挺简单的问题啊。

参考技术A SE38:写一个同步数据的程序;
SM37:排一个JOB跑这个程序。
参考技术B 可以设置一个field-symbol,把这2个表同时指向这个fs

通过ABAP程序创建透明表

       最近在解决用户账号问题的时候,需要通过ABAP程序创建透明表,查询了相关资料,总结如下。

       通过ABAP程序创建透明表,主要利用了4个函数:

       DDIF_TABL_ACTIVATE: 激活透明表

       GOX_GEN_TABLE_STD: 生成透明表

       DDIF_TABL_PUT: 设置表的相关信息

       DDIF_TABL_GET: 获得表的相关信息

     参数说明
     Import:
  NAME: 数据库表的名字
  STATE: 状态
                      STATE = ‘A’ (read the active version)
                      STATE = ‘M’ (read the latest version)
       LANGU: 语言设定, 默认sy-langu
     Export: 
       GOTSTATE: 状态信息
       DD02V_WA: 表头
       DD09L_WA: 表表的技术信息
     Tables: 
        DD03P_TAB: 表的字段列表
        DD05M_TAB: 表的外键字段
        DD08V_TAB: 表的外键
        DD12V_TAB: 表索引
        DD17V_TAB: 表的索引字段
        DD35V_TAB: 检索help相关
        DD36M_TAB: 检索help相关

      代码:

REPORT z_create_table.

PARAMETERS: tabname TYPE char32 OBLIGATORY.
DATA: lt_new_object         TYPE comt_gox_def_header,
      lt_old_object         LIKE lt_new_object,
      lv_dbtab1_name        TYPE char32,
      ls_new_object         LIKE LINE OF lt_new_object,
      ls_new_object_details TYPE LINE OF comt_gox_table_entry_fields,
      lt_returntab          TYPE bapirettab,
      ls_return             LIKE LINE OF lt_returntab.

ls_new_object-object_type = \'TABLE\'.
ls_new_object-object_name = tabname.

TRY.
    data(lv_guid) = cl_system_uuid=>if_system_uuid_static~create_uuid_c32( ).
  CATCH cx_uuid_error .
ENDTRY.

* technical setting
ls_new_object-key_guid = lv_guid.
data(lv_parent_guid) = ls_new_object-key_guid.
ls_new_object_details-fieldname = \'TABCLASS\'.
ls_new_object_details-fieldvalue = \'TRANSP\'.
APPEND ls_new_object_details TO ls_new_object-details.
CLEAR ls_new_object_details.
ls_new_object_details-fieldname = \'TABKAT\'.
ls_new_object_details-fieldvalue = \'0\'.
APPEND ls_new_object_details TO ls_new_object-details.
CLEAR ls_new_object_details.
ls_new_object_details-fieldname = \'TABART\'.
ls_new_object_details-fieldvalue = \'APPL2\'.
APPEND ls_new_object_details TO ls_new_object-details.
CLEAR ls_new_object_details.
ls_new_object_details-fieldname = \'PUFFERUNG\'.
ls_new_object_details-fieldvalue = \'X\'.
APPEND ls_new_object_details TO ls_new_object-details.
CLEAR ls_new_object_details.
ls_new_object_details-fieldname = \'CONTFLAG\'.
ls_new_object_details-fieldvalue = \'S\'.
APPEND ls_new_object_details TO ls_new_object-details.
CLEAR ls_new_object_details.
ls_new_object_details-fieldname = \'MAINFLAG\'.
ls_new_object_details-fieldvalue = \'X\'.
APPEND ls_new_object_details TO ls_new_object-details.
CLEAR ls_new_object_details.
ls_new_object_details-fieldname = \'BUFFALLOW\'.
ls_new_object_details-fieldvalue = \'X\'.
APPEND ls_new_object_details TO ls_new_object-details.
CLEAR ls_new_object_details.
ls_new_object_details-fieldname = \'SCHFELDANZ\'.
ls_new_object_details-fieldvalue = \'0\'.
APPEND ls_new_object_details TO ls_new_object-details.
CLEAR ls_new_object_details.
APPEND ls_new_object TO lt_new_object.
CLEAR ls_new_object.

ls_new_object-object_type = \'TABLE_FIELD\'.
TRY.
    lv_guid = cl_system_uuid=>if_system_uuid_static~create_uuid_c32( ).
  CATCH cx_uuid_error .
ENDTRY.
ls_new_object-key_guid = lv_guid.
ls_new_object-parent_key = lv_parent_guid.
lv_parent_guid = lv_guid.
ls_new_object-object_name = \'CODE_VALUE\'. "field name
ls_new_object_details-fieldname = \'POSITION\'.
ls_new_object_details-fieldvalue = \'1\'.
APPEND ls_new_object_details TO ls_new_object-details.
CLEAR ls_new_object_details.
ls_new_object_details-fieldname = \'KEYFLAG\'. "Key
ls_new_object_details-fieldvalue = \'X\'.
APPEND ls_new_object_details TO ls_new_object-details.
CLEAR ls_new_object_details.
ls_new_object_details-fieldname = \'NOTNULL\'. "initial
ls_new_object_details-fieldvalue = \'X\'.
APPEND ls_new_object_details TO ls_new_object-details.
CLEAR ls_new_object_details.
ls_new_object_details-fieldname = \'ROLLNAME\'.
ls_new_object_details-fieldvalue = \'COMT_PRODUCT_ID\'. "data element
APPEND ls_new_object_details TO ls_new_object-details.
CLEAR ls_new_object_details.
APPEND ls_new_object TO lt_new_object.
CLEAR ls_new_object.
REFRESH lt_returntab.
CLEAR lv_parent_guid.

lv_dbtab1_name = tabname.
CALL FUNCTION \'GOX_GEN_TABLE_STD\'
  EXPORTING
    iv_object_name = lv_dbtab1_name
    it_object_new  = lt_new_object
    it_object_old  = lt_old_object
    iv_devclass    = \'$TMP\'  "local
  IMPORTING
    et_bapireturn  = lt_returntab.

CHECK lt_returntab IS INITIAL.

DATA: lv_ddobjname TYPE ddobjname,
      ls_dd02v     TYPE dd02v.

lv_ddobjname = lv_dbtab1_name.
CALL FUNCTION \'DDIF_TABL_GET\'
  EXPORTING
    name          = lv_ddobjname
    state         = \'A\'
    langu         = sy-langu
  IMPORTING
    dd02v_wa      = ls_dd02v
  EXCEPTIONS
    illegal_input = 1
    OTHERS        = 2.
IF sy-subrc <> 0.
  RETURN.
ENDIF.

ls_dd02v-mainflag = \'X\'.
CALL FUNCTION \'DDIF_TABL_PUT\'
  EXPORTING
    name              = lv_ddobjname
    dd02v_wa          = ls_dd02v
  EXCEPTIONS
    tabl_not_found    = 1
    name_inconsistent = 2
    tabl_inconsistent = 3
    put_failure       = 4
    put_refused       = 5
    OTHERS            = 6.
IF sy-subrc <> 0.
  RETURN.
ENDIF.

* active table
CALL FUNCTION \'DDIF_TABL_ACTIVATE\'
  EXPORTING
    name     = lv_ddobjname
    auth_chk = \' \'.

CHECK sy-subrc = 0.

WRITE:/ \'Table: \', lv_ddobjname, \' generated successfully\'.

      输入透明表名运行,即可创建成功。

       

       

      进入SE11查看结果:

       

       

 

以上是关于SAP ABAP。取一个透明表数据放到另外一个透明表。并保持数据同步的主要内容,如果未能解决你的问题,请参考以下文章

SAP 透明表之间的关联字段

ABAP文本表查找

通过ABAP程序创建透明表

SAP ABAP BDC录屏工具使用

SAP-WM和MM模块是啥

[求助]关于ABAP中找生产订单状态的问题