使用ABAP代码创建SAP Netweaver透明表(transparent table)

Report source code could be found below:

REPORT ztable.

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.

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

  IMPORTING
    et_bapireturn  = lt_returntab.

CHECK lt_returntab IS NOT 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.

CALL FUNCTION 'DDIF_TABL_ACTIVATE'
  EXPORTING
    name     = lv_ddobjname
    auth_chk = ' '.

CHECK sy-subrc = 0.

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

specify the table name:

run the report and the table is generated successfully and could be found in SE11:

要获取更多Jerry的原创文章,请关注公众号"汪子熙":

汪子熙 CSDN认证博客专家 前端框架 Node.js SAP
Jerry Wang,2007 年从电子科技大学计算机专业硕士毕业后加入 SAP 成都研究院工作至今。Jerry 是 SAP 社区导师,SAP 中国技术大使。14 多年的 SAP 产品开发生涯,Jerry 曾经先后参与 SAP Business ByDesign,SAP CRM,SAP Cloud for Customer,SAP S/4HANA,SAP Commerce Cloud(电商云)等标准产品的研发工作。
相关推荐
©️2020 CSDN 皮肤主题: 博客之星2020 设计师:CY__ 返回首页
实付 49.90元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值