通过SAP函数组GOX_OBJECTS_GENERATE中的函数创建数据对象(域,数据元素,表)

 

*&---------------------------------------------------------------------*
*& Report ZRCP10
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT zrcp10.

*PARAMETERS :DEVCLASS TYPE DEVCLASS DEFAULT '$TMP',
*      IV_REQUEST_WB TYPE  TRKORR,
*      DOMANAME TYPE DOMNAME OBLIGATORY,
*      DDLANGUAGE TYPE DDLANGUAGE,

CLASS:zcl_dynamic_operate DEFINITION.
  PUBLIC SECTION.
*  TABLES DD07V.
    CLASS-METHODS:
    "DD07V
      create_domain IMPORTING
                              REFERENCE(devclass)      TYPE  devclass DEFAULT '$TMP'   "包
                              REFERENCE(iv_request_wb) TYPE  trkorr OPTIONAL         "请求号
                              REFERENCE(domaname)      TYPE  domname                    "域名
                              REFERENCE(description)   TYPE  comt_gox_fieldvalue     "域描述
                              REFERENCE(ddlanguage)    TYPE  ddlanguage DEFAULT sy-langu      "语言
                              REFERENCE(datatype)      TYPE  datatype_d                 "基本类型
                              REFERENCE(leng)          TYPE  leng                       "长度
                              REFERENCE(outlen)        TYPE  outputlen OPTIONAL       "输出长度
                              REFERENCE(decimals)      TYPE  decimals OPTIONAL        "精度
                              REFERENCE(lowercase)     TYPE  lowercase OPTIONAL       "是否考虑大小写
                              REFERENCE(signflag)      TYPE  signflag OPTIONAL        "数值域的符号标志 作为域输出属性一部分的加/减号
                              REFERENCE(valexi)        TYPE  valexi OPTIONAL          "是否存在固定值
                              REFERENCE(convexit)      TYPE  convexit OPTIONAL         "转换例程
                              REFERENCE(it_dd07v)      TYPE    dd07vtab  " DD07T         "固定值表
                    RETURNING VALUE(return)            TYPE  mewi_t_return," BAPIRETURN. "返回消息
      "dd04v
      create_element IMPORTING
                               REFERENCE(rollname)    TYPE  rollname
                               REFERENCE(description) TYPE  as4text
                               REFERENCE(ddlanguage)  TYPE  ddlanguage DEFAULT sy-langu
                               REFERENCE(domname)     TYPE  domname OPTIONAL
                               REFERENCE(routputlen)  TYPE  ddleng OPTIONAL
                               REFERENCE(memoryid)    TYPE  memoryid OPTIONAL
                               VALUE(reptext)         TYPE  reptext OPTIONAL
                               VALUE(scrtext_s)       TYPE  scrtext_s OPTIONAL
                               VALUE(scrtext_m)       TYPE  scrtext_m OPTIONAL
                               VALUE(scrtext_l)       TYPE  scrtext_l OPTIONAL
                               REFERENCE(devclass)    TYPE  devclass DEFAULT '$TMP'
                               REFERENCE(request_wb)  TYPE  trkorr OPTIONAL
                     RETURNING VALUE(return)          TYPE  mewi_t_return,
      "DD02V
      create_table   IMPORTING
                               REFERENCE(tabname)    TYPE  char32
                               REFERENCE(tabclass)   TYPE  tabclass DEFAULT 'TRANSP'
                               REFERENCE(tabkat)     TYPE  tabkat DEFAULT '0'
                               REFERENCE(tabart)     TYPE  tabart DEFAULT 'APPL0'
                               REFERENCE(pufferung)  TYPE  pufferung DEFAULT ''
                               REFERENCE(contflag)   TYPE  contflag DEFAULT 'A'
                               REFERENCE(mainflag)   TYPE  maintflag DEFAULT ''
                               REFERENCE(buffallow)  TYPE  bufallow DEFAULT 'N'
                               REFERENCE(schfeldanz) TYPE  schfeldanz DEFAULT 0
                               REFERENCE(devclass)   TYPE  devclass DEFAULT '$TMP'
                               REFERENCE(request_wb) TYPE  trkorr OPTIONAL
                               REFERENCE(it_dd03l)   TYPE fins_cfiny_dd03l  " DD07T         "固定值表
                     RETURNING VALUE(return)         TYPE  mewi_t_return.



ENDCLASS.

*&---------------------------------------------------------------------*
*& Class (Implementation) zcl_dynamic_operate
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
CLASS zcl_dynamic_operate IMPLEMENTATION.
  METHOD create_domain.
    DATA: lt_new_object         TYPE comt_gox_def_header,
          lw_onject_text        TYPE coms_gox_def_text,
          lt_old_object         LIKE lt_new_object,
          lv_doma_name          TYPE char32,
          lv_devclass           TYPE devclass,
          lv_request_wb         TYPE trkorr,
          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,
          lw_dd07v              LIKE LINE OF it_dd07v,
          ew_return             LIKE LINE OF return.

    IF domaname IS INITIAL OR ( domaname(1) <> 'Z' AND domaname(1) <> 'Y' ).
      ew_return-type = 'E'.
      ew_return-message = '不能创建域名' && domaname.
      RETURN.
    ENDIF.
    lv_doma_name  = domaname.
    lv_request_wb = iv_request_wb.
    MOVE devclass TO lv_devclass.

    CLEAR ls_new_object.
    ls_new_object-object_type = 'DOMA'.
    ls_new_object-object_name = domaname.

    "域描述
    CLEAR lw_onject_text.
    lw_onject_text-language = ddlanguage.
    lw_onject_text-description = description.
    APPEND lw_onject_text TO ls_new_object-object_text.

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

    MOVE lv_guid                     TO ls_new_object-key_guid          .
    DATA(lv_parent_guid)             =  ls_new_object-key_guid.

    CLEAR ls_new_object_details.
    ls_new_object_details-fieldname = 'DDLANGUAGE'."语言
    ls_new_object_details-fieldvalue = ddlanguage  .
    APPEND ls_new_object_details TO ls_new_object-details.

    CLEAR ls_new_object_details.
    ls_new_object_details-fieldname  = 'DATATYPE'."数据类型
    ls_new_object_details-fieldvalue = datatype.
    APPEND ls_new_object_details TO ls_new_object-details.

    CLEAR ls_new_object_details.
    ls_new_object_details-fieldname = 'LENG'."类型长度
    ls_new_object_details-fieldvalue = leng.
    CONDENSE ls_new_object_details-fieldvalue.
    APPEND ls_new_object_details TO ls_new_object-details.

    CLEAR ls_new_object_details.
    IF outlen IS NOT INITIAL .
      ls_new_object_details-fieldname = 'OUTPUTLEN'."输出长度 默认和类型长度一致
      ls_new_object_details-fieldvalue = outlen.
      CONDENSE ls_new_object_details-fieldvalue.
      APPEND ls_new_object_details TO ls_new_object-details.
    ENDIF.

    CLEAR ls_new_object_details.
    ls_new_object_details-fieldname = 'DECIMALS'."小数位
    ls_new_object_details-fieldvalue = decimals.
    APPEND ls_new_object_details TO ls_new_object-details.

    CLEAR ls_new_object_details.
    ls_new_object_details-fieldname = 'LOWERCASE'."是否区分大小写
    ls_new_object_details-fieldvalue = lowercase.
    APPEND ls_new_object_details TO ls_new_object-details.

    CLEAR ls_new_object_details.
    ls_new_object_details-fieldname = 'SIGNFLAG'."符号
    ls_new_object_details-fieldvalue = signflag.
    APPEND ls_new_object_details TO ls_new_object-details.

    CLEAR ls_new_object_details.
    ls_new_object_details-fieldname = 'VALEXI'."是否存在固定值
    ls_new_object_details-fieldvalue = valexi.
    APPEND ls_new_object_details TO ls_new_object-details.

*CLEAR LS_NEW_OBJECT_DETAILS.
*LS_NEW_OBJECT_DETAILS-FIELDNAME = 'CONVEXIT'."转换历程
*LS_NEW_OBJECT_DETAILS-FIELDVALUE = 'X'.
*APPEND LS_NEW_OBJECT_DETAILS TO LS_NEW_OBJECT-DETAILS.

    APPEND ls_new_object TO lt_new_object.

    IF it_dd07v IS NOT INITIAL .
      LOOP AT it_dd07v ASSIGNING FIELD-SYMBOL().
        ls_new_object-object_type = 'DOMA_SET'.
        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.
        "域值

        CLEAR ls_new_object_details.
        ls_new_object_details-fieldname = 'VALPOS'."值关键字
        ls_new_object_details-fieldvalue = -valpos.
        APPEND ls_new_object_details TO ls_new_object-details.
        IF -ddtext IS NOT INITIAL .
          CLEAR ls_new_object_details.
          ls_new_object_details-fieldname = 'DDTEXT'."简短描述
          ls_new_object_details-fieldvalue = -ddtext.
          APPEND ls_new_object_details TO ls_new_object-details.
        ENDIF.

        IF -domvalue_l IS NOT INITIAL .
          CLEAR ls_new_object_details.
          ls_new_object_details-fieldname = 'DOMVALUE_L'."下限值
          ls_new_object_details-fieldvalue = -domvalue_l.
          APPEND ls_new_object_details TO ls_new_object-details.
        ENDIF.
        IF -domvalue_h IS NOT INITIAL .
          CLEAR ls_new_object_details.
          ls_new_object_details-fieldname = 'DOMVALUE_H'."DOMVALUE_H
          ls_new_object_details-fieldvalue = -domvalue_h.
          APPEND ls_new_object_details TO ls_new_object-details.
        ENDIF.

        APPEND ls_new_object TO lt_new_object.
        CLEAR ls_new_object.

      ENDLOOP.
    ENDIF.

    DATA et_bapireturn  TYPE bapirettab.
    DATA et_transport   TYPE comt_gox_trans_object.

    CALL FUNCTION 'GOX_GEN_DOMA_STD'
      EXPORTING
        iv_object_name = lv_doma_name
        it_object_new  = lt_new_object
        it_object_old  = lt_old_object
        iv_devclass    = lv_devclass
        iv_request_wb  = lv_request_wb
      IMPORTING
        et_bapireturn  = et_bapireturn
        et_transport   = et_transport.


    APPEND LINES OF et_bapireturn TO return.

*CHECK ET_BAPIRETURN IS INITIAL.

    DATA: lv_ddobjname TYPE ddobjname,
          ls_dd02v     TYPE dd02v.

    lv_ddobjname = lv_doma_name.
    DATA name      TYPE ddobjname.
    DATA state     TYPE ddobjstate.
    DATA langu     TYPE sy-langu.
    DATA gotstate  TYPE ddgotstate.
    DATA dd01v_wa  TYPE dd01v.
    DATA dd07v_tab TYPE STANDARD TABLE OF dd07v.

    CALL FUNCTION 'DDIF_DOMA_GET'
      EXPORTING
        name          = lv_ddobjname
        state         = 'A'
        langu         = sy-langu
      IMPORTING
        gotstate      = gotstate
        dd01v_wa      = dd01v_wa
      TABLES
        dd07v_tab     = dd07v_tab
      EXCEPTIONS
        illegal_input = 1.

*DATA NAME      TYPE DDOBJNAME.
*DATA DD01V_WA  TYPE DD01V.
*DATA DD07V_TAB TYPE STANDARD TABLE OF DD07V.
*
    CALL FUNCTION 'DDIF_DOMA_PUT'
      EXPORTING
        name              = lv_ddobjname
        dd01v_wa          = dd01v_wa
      TABLES
        dd07v_tab         = dd07v_tab
      EXCEPTIONS
        doma_not_found    = 1
        name_inconsistent = 2
        doma_inconsistent = 3
        put_failure       = 4
        put_refused       = 5.
    IF sy-subrc NE 0.
      RETURN.
    ENDIF.

* ACTIVE TABLE
    CALL FUNCTION 'DDIF_DOMA_ACTIVATE'
      EXPORTING
        name     = lv_ddobjname
        auth_chk = ' '.

    CHECK sy-subrc = 0.

  ENDMETHOD.

  METHOD create_element.
    DATA: lt_new_object         TYPE comt_gox_def_header,
          lt_old_object         LIKE lt_new_object,
          lw_onject_text        TYPE coms_gox_def_text,
          lv_element_name       TYPE char32,
          lv_devclass           TYPE devclass,
          lv_request_wb         TYPE trkorr,
          ls_new_object         LIKE LINE OF lt_new_object,
          ls_new_object_details TYPE LINE OF comt_gox_table_entry_fields,
          et_bapireturn         TYPE bapirettab,
          et_transport          TYPE comt_gox_trans_object.
    lv_element_name  = rollname.
    lv_request_wb    = request_wb.
    lv_devclass = devclass.

    IF reptext IS INITIAL.
      reptext = description.
    ENDIF.

    IF scrtext_s IS INITIAL.
      scrtext_s = description.
    ENDIF.

    IF scrtext_m IS INITIAL.
      scrtext_m = description.
    ENDIF.

    IF scrtext_l IS INITIAL.
      scrtext_l = description.
    ENDIF.

    CLEAR ls_new_object.

    ls_new_object-object_type = 'ELEMENT'.
    ls_new_object-object_name = rollname .

    "数据元素描述
    CLEAR lw_onject_text.
    lw_onject_text-language = ddlanguage.
    lw_onject_text-description = description.
    APPEND lw_onject_text TO ls_new_object-object_text.

    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.

    CLEAR    ls_new_object_details.
    ls_new_object_details-fieldname  = 'DDTEXT'."标题描述
    ls_new_object_details-fieldvalue =  ddlanguage.
    APPEND   ls_new_object_details   TO ls_new_object-details.

    CLEAR    ls_new_object_details.
    ls_new_object_details-fieldname  =  'DOMNAME'."域名
    ls_new_object_details-fieldvalue =  domname.
    APPEND   ls_new_object_details   TO ls_new_object-details.

    CLEAR    ls_new_object_details.
    ls_new_object_details-fieldname = 'DDLANGUAGE'. "语言
    ls_new_object_details-fieldvalue = ddlanguage.
    APPEND   ls_new_object_details   TO ls_new_object-details.

    CLEAR    ls_new_object_details.
    ls_new_object_details-fieldname = 'ROUTPUTLEN'. "长度(字符数)
    ls_new_object_details-fieldvalue = routputlen.
    APPEND   ls_new_object_details   TO ls_new_object-details.

    CLEAR    ls_new_object_details.
    ls_new_object_details-fieldname = 'MEMORYID'.  "设置/获取参数标识
    ls_new_object_details-fieldvalue = memoryid.
    APPEND   ls_new_object_details   TO ls_new_object-details.

    CLEAR    ls_new_object_details.
    ls_new_object_details-fieldname = 'REPTEXT'. "长标题
    ls_new_object_details-fieldvalue = reptext.
    APPEND   ls_new_object_details   TO ls_new_object-details.

    CLEAR    ls_new_object_details.
    ls_new_object_details-fieldname = 'HEADLEN'.  "长标题长度
    ls_new_object_details-fieldvalue = strlen( reptext ).
    APPEND   ls_new_object_details   TO ls_new_object-details.

    CLEAR    ls_new_object_details.
    ls_new_object_details-fieldname = 'SCRTEXT_S'. "短标题
    ls_new_object_details-fieldvalue = scrtext_s.
    APPEND   ls_new_object_details   TO ls_new_object-details.

    CLEAR    ls_new_object_details.
    ls_new_object_details-fieldname = 'SCRLEN1'.   "短标题长度
    ls_new_object_details-fieldvalue = strlen( scrtext_s ).
    APPEND   ls_new_object_details   TO ls_new_object-details.

    CLEAR    ls_new_object_details.
    ls_new_object_details-fieldname = 'SCRTEXT_M'. "中标题
    ls_new_object_details-fieldvalue = scrtext_m.
    APPEND   ls_new_object_details   TO ls_new_object-details.

    CLEAR    ls_new_object_details.
    ls_new_object_details-fieldname = 'SCRLEN2'. "中标题长度
    ls_new_object_details-fieldvalue = strlen( scrtext_m ).
    APPEND   ls_new_object_details   TO ls_new_object-details.

    CLEAR    ls_new_object_details.
    ls_new_object_details-fieldname = 'SCRTEXT_L'. "长标题
    ls_new_object_details-fieldvalue = scrtext_l.
    APPEND   ls_new_object_details   TO ls_new_object-details.

    CLEAR    ls_new_object_details.
    ls_new_object_details-fieldname = 'SCRLEN3'.  "长标题长度
    ls_new_object_details-fieldvalue = strlen( scrtext_l ).
    APPEND   ls_new_object_details   TO ls_new_object-details.

    APPEND ls_new_object TO lt_new_object.

    CALL FUNCTION 'GOX_GEN_DTEL_STD'
      EXPORTING
        iv_object_name = lv_element_name
        it_object_new  = lt_new_object
        it_object_old  = lt_old_object
        iv_devclass    = lv_devclass
        iv_request_wb  = lv_request_wb
      IMPORTING
        et_bapireturn  = et_bapireturn
        et_transport   = et_transport.

    APPEND LINES OF et_bapireturn TO return.

    DATA: lv_ddobjname TYPE ddobjname,
          ls_dd02v     TYPE dd02v.
    lv_ddobjname = lv_element_name.
    DATA gotstate  TYPE ddgotstate.
    DATA dd04v_wa  TYPE dd04v.
    DATA tpara_wa  TYPE tpara.
    CALL FUNCTION 'DDIF_DTEL_GET'
      EXPORTING
        name          = lv_ddobjname
        state         = 'A'
        langu         = sy-langu
      IMPORTING
        gotstate      = gotstate
        dd04v_wa      = dd04v_wa
        tpara_wa      = tpara_wa
      EXCEPTIONS
        illegal_input = 1.
    CALL FUNCTION 'DDIF_DTEL_PUT'
      EXPORTING
        name              = lv_ddobjname
        dd04v_wa          = dd04v_wa
      EXCEPTIONS
        dtel_not_found    = 1
        name_inconsistent = 2
        dtel_inconsistent = 3
        put_failure       = 4
        put_refused       = 5.
    IF sy-subrc NE 0.
      RETURN.
    ENDIF.
* ACTIVE TABLE
    CALL FUNCTION 'DDIF_DTEL_ACTIVATE'
      EXPORTING
        name     = lv_ddobjname
        auth_chk = ' '.
    CHECK sy-subrc = 0.
  ENDMETHOD.

  METHOD create_table.
    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.
    DATA iv_request_wb  TYPE trkorr.
    DATA et_bapireturn  TYPE bapirettab.
    DATA et_transport   TYPE comt_gox_trans_object.

    CLEAR ls_new_object.
    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.

    CLEAR ls_new_object_details.
    ls_new_object_details-fieldname = 'TABCLASS'. "表类别
    ls_new_object_details-fieldvalue = tabclass.
    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 = tabkat.
    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 = tabart.
    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 = pufferung.
    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 = contflag.
    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 = mainflag.
    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 = buffallow.
    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 = schfeldanz.
    APPEND ls_new_object_details TO ls_new_object-details.

    APPEND ls_new_object TO lt_new_object.

    LOOP AT it_dd03l ASSIGNING FIELD-SYMBOL().
      DATA(l_tabix) = sy-tabix.
      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        = -fieldname. "FIELD NAME
      ls_new_object-position           = l_tabix. "SY-TABIX
      ls_new_object_details-fieldname  = 'FIELDNAME'.
      ls_new_object_details-fieldvalue = -fieldname.
      APPEND ls_new_object_details  TO ls_new_object-details.
      ls_new_object_details-fieldname  = 'AS4LOCAL'.
      ls_new_object_details-fieldvalue = 'A'."-AS4LOCAL.
      SHIFT ls_new_object_details-fieldvalue LEFT DELETING LEADING space.
      APPEND ls_new_object_details  TO ls_new_object-details.

      ls_new_object_details-fieldname  = 'POSITION'.
      ls_new_object_details-fieldvalue = l_tabix.
      SHIFT ls_new_object_details-fieldvalue LEFT DELETING LEADING space.
      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 = -keyflag.
      APPEND ls_new_object_details  TO ls_new_object-details.
      CLEAR ls_new_object_details.
      ls_new_object_details-fieldname  = 'NOTNULL'. "NOTNULL
      ls_new_object_details-fieldvalue = -notnull.
      APPEND ls_new_object_details  TO ls_new_object-details.

      CLEAR ls_new_object_details.
      ls_new_object_details-fieldname  = 'ROLLNAME'. "NOTNULL
      ls_new_object_details-fieldvalue = -rollname.
      APPEND ls_new_object_details  TO ls_new_object-details.
      CLEAR ls_new_object_details.
      ls_new_object_details-fieldname  = 'COMPTYPE'. "NOTNULL
      ls_new_object_details-fieldvalue = 'E'."-COMPTYPE.
      APPEND ls_new_object_details  TO ls_new_object-details.
      "使用内置类型创建字段
*  CLEAR LS_NEW_OBJECT_DETAILS.
*  LS_NEW_OBJECT_DETAILS-FIELDNAME  = 'DATATYPE'. "KEY
*  LS_NEW_OBJECT_DETAILS-FIELDVALUE = -DATATYPE.
*  APPEND LS_NEW_OBJECT_DETAILS  TO LS_NEW_OBJECT-DETAILS.
*
*  CLEAR LS_NEW_OBJECT_DETAILS.
*  LS_NEW_OBJECT_DETAILS-FIELDNAME  = 'LENG'. "KEY
*  LS_NEW_OBJECT_DETAILS-FIELDVALUE = -LENG.
*  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.
    ENDLOOP.


    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    = devclass  "LOCAL
        iv_request_wb  = request_wb
      IMPORTING
        et_bapireturn  = et_bapireturn
        et_transport   = et_transport.
    APPEND LINES OF et_bapireturn TO return.
    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.
  ENDMETHOD.
ENDCLASS.

START-OF-SELECTION.

*  "测试
*  DATA(return) = zcl_dynamic_operate=>create_domain(
*    domaname      = 'ZDC'
*    description = '测试'
*    datatype      = 'CHAR'
*    leng          = '10'
*    it_dd07v      = VALUE #( ( domname = 'ZD1' valpos = '0001' ddlanguage = '1' ddtext = '空' )
*                            ( domname = 'ZD2' valpos = '0002' ddlanguage = '1' domvalue_l = 'X' ddtext = '是' ) )
*    ).
*
*  IF return IS NOT INITIAL.
*    cl_demo_output=>display( return ).
*    EXIT.
*  ENDIF.
*
*  return = zcl_dynamic_operate=>create_element(
*  rollname    = 'ZE_DC'
*  description = '数据元素'
*  domname     = 'ZDC'
**           routputlen  =
**           memoryid    =
**           reptext     =
**           scrtext_s   =
**           scrtext_m   =
**           scrtext_l   =
**           devclass    = '$TMP'
**           request_wb  =
*  ).
*  IF return IS NOT INITIAL.
*    cl_demo_output=>display( return ).
*    EXIT.
*  ENDIF.

*"测试
*DATA(RETURN) = zcl_dynamic_operate=>create_domain(
*      domaname      = 'ZDC'
*      description = '测试'
*      datatype      = 'CHAR'
*      leng          = '10'
*      it_dd07v      = VALUE #( ( domname = 'ZD1' valpos = '0001' ddlanguage = '1' ddtext = '空' )
*      ( domname = 'ZD2' valpos = '0002' ddlanguage = '1' domvalue_l = 'X' ddtext = '是' ) )
*      ).
*
*IF RETURN IS NOT INITIAL.
*  cl_demo_output=>display( RETURN ).
*  EXIT.
*ENDIF.


  DATA(return) = zcl_dynamic_operate=>create_element(
  rollname    = 'ZE_MAILBOX'
  description = '人事专员邮箱'
  domname     = 'CHAR30'
*           routputlen  =
*           memoryid    =
*           reptext     =
*           scrtext_s   =
*           scrtext_m   =
*           scrtext_l   =
             devclass    = 'Z001'
             request_wb  = 'ED1K900601'
  ).
  IF return IS NOT INITIAL.
    cl_demo_output=>display( return ).
    EXIT.
  ENDIF.

"创建表
*DATA(RETURN) = zcl_dynamic_operate=>create_table(
*      tabname    = 'ZTDC'
*it_dd03l   = VALUE #( ( fieldname = 'MANDT' POSITION = 'X' keyflag = 'X' rollname = 'MANDT' )
*                     ( fieldname = 'MATNR' POSITION = 'X' keyflag = 'X' rollname = 'MATNR' ) )
*      ).
*(
*      tabname    = ''
*      tabclass   = 'TRANSP'
*      tabkat     = 0
*      tabart     = 'APPL0'
**      pufferung  = ''
*      contflag   =
*      mainflag   =
*      buffallow  =
*      schfeldanz =
**                 devclass   = '$TMP'
**                 request_wb =
*      it_dd03l   =
*      )

*TABCLASS
*TRANSP  透明表格
*INTTAB  结构
*CLUSTER  簇表
*POOL  共享表格
*VIEW  生成的视图结构
*APPEND  附加结构
*
*TABKAT  0  大小范畴
*0  表 < 500K         0                    0 到            810
*1  表 < 1.5 MB         1                  810 到          3,200
*2  表 < 6.5 MB         2                3,200 到         13,000
*3  表 < 25 MB        3               13,000 到         52,000
*4  表 > 160 MB         4               52,000 到        210,000
*5  值无法手动编辑(早期预警值)     5              210,000 到        420,000
*6  值无法手动编辑(早期预警值)     6              420,000 到        840,000
*7  值无法手动编辑(早期预警值)     7              840,000 到      1,600,000
*8  值无法手动编辑(早期预警值)     8            1,600,000 到      3,300,000
*9  值无法手动编辑(早期预警值)     9            3,300,000 到    130,000,000
*10  值无法手动编辑(早期预警值)
*11  值无法手动编辑(早期预警值)
*12  值无法手动编辑(早期预警值)
*13  值无法手动编辑(早期预警值)
*14  值无法手动编辑(早期预警值)
*
*TABART CHAR  5 0 技术设置的数据类
*APPL0     主数据,透明表
*APPL1     事务数据,透明表
*APPL2     组织和定制
*DDIM      业务仓库中的维度表
*DFACT     业务仓库中的事实表
*DODS      业务仓库中的操作型数据存储表
*USER      客户数据类
*USER1     客户数据类
*
*CONTFLAG 1 类型  CONTFLAG  CHAR  1 0 提交类
*A  应用表 (主数据和业务数据)
*C  定制表, 仅由客户维护, 非SAP输入
*L  存储当前数据表,传送空闲
*G  定制表, 不受 SAP 更新影响, 只 INS 全部
*E  控制表,SAP和用户有分开的关键字范围
*S  系统表, 只被SAP维护, 修改=调整
*W  系统表,内容可通过单独的传输请求对象传输
*
*PUFFERUNG  1 类型  PUFFERUNG CHAR  1 0 缓冲类型指示器
*无缓冲
*P  已缓冲单个表格条目
*G  按通用键值指定进行完全缓冲
*X  整个表传递至缓冲区
*
*SCHFELDANZ SCHFELDANZ  NUMC  3 0 普通缓冲区的关键区域号
*
*
*BUFALLOW 1 类型  BUFALLOW  CHAR  1 0 允许/不允许缓冲的指示器
*N  不允许缓存
*X  缓存已打开
*A  允许缓冲,但已关闭
*
*LANGDEP  1 类型  LANGDEP CHAR  1 0 语言相关性 ,具有INCLUDES表标记
*表不可包括INCLUDE对于其他表
*X  表包含
*
*SQLTAB 1 类型  SQLAPPDTAB  CHAR  30  0 SQL 表或附加的表的名称
*
*
*EXCLASS  NUMC  1 ABAP 字典:include 语句和子类型扩展等级
*0  未分类
*1  无法增强
*2  可以增强(字符型)
*3  可以增强(字符或数字型)
*4  可以增强(深度)

*mainflag
*允许显示/维护,但存在限制
*X  允许显示/维护
*N  不允许显示/维护

 

你可能感兴趣的:(SAP,动态创建SAP数据对象)