创建表

作者: 阿努比斯1117 | 来源:发表于2018-08-23 09:26 被阅读0次

    REPORT ZTEXT_XK1.

    DATA: tabname TYPE tabname VALUE 'ZZTEST', "表名
    wa_02v TYPE dd02v ,
    wa_09l TYPE dd09v ,
    subrc TYPE sy-subrc ,
    INDEX TYPE I .
    DATA: it_flds TYPE TABLE OF dd03p WITH HEADER LINE .

    START-OF-SELECTION.
    wa_02v-tabname = tabname.
    wa_02v-ddtext = '测试程序创建表'.
    wa_02v-ddlanguage = sy-langu.
    wa_02v-tabclass = 'TRANSP'.
    wa_02v-as4user = sy-uname.
    wa_02v-contflag = 'C'.
    wa_02v-mainflag = 'X'.

    wa_09l-tabname = tabname.
    wa_09l-tabart = 'USER'.
    wa_09l-tabkat = 1.

    CLEAR it_flds.
    INDEX = INDEX + 1.
    it_flds-tabname = tabname.
    it_flds-ddlanguage = 'ZH'.
    it_flds-POSITION = INDEX.
    it_flds-fieldname = 'MANDT'.
    it_flds-rollname = 'MANDT'.
    it_flds-notnull = 'X'.
    it_flds-keyflag = 'X'.
    APPEND it_flds.
    CLEAR it_flds.
    INDEX = INDEX + 1.
    it_flds-tabname = tabname.
    it_flds-ddlanguage = sy-langu.
    it_flds-POSITION = INDEX.
    it_flds-fieldname = 'MATNR'.
    it_flds-rollname = 'MATNR'.
    it_flds-notnull = 'X'.
    it_flds-keyflag = 'X'.
    APPEND it_flds.
    CLEAR it_flds.
    INDEX = INDEX + 1.
    it_flds-tabname = tabname.
    it_flds-ddlanguage = sy-langu.
    it_flds-POSITION = INDEX.
    it_flds-fieldname = 'MENGE'.
    it_flds-rollname = 'MENGE_D'.
    it_flds-reftable = tabname.
    it_flds-reffield = 'MEINS'.
    APPEND it_flds.
    CLEAR it_flds.
    INDEX = INDEX + 1.
    it_flds-tabname = tabname.
    it_flds-ddlanguage = sy-langu.
    it_flds-POSITION = INDEX.
    it_flds-fieldname = 'MEINS'.
    it_flds-rollname = 'MEINS'.
    APPEND it_flds.

    CALL FUNCTION 'DDIF_TABL_PUT'
    EXPORTING
    name = tabname
    dd02v_wa = wa_02v
    dd09l_wa = wa_09l
    TABLES
    dd03p_tab = it_flds
    EXCEPTIONS
    tabl_not_found = 1
    name_inconsistent = 2
    tabl_inconsistent = 3
    put_failure = 4
    put_refused = 5
    OTHERS = 6.
    IF sy-subrc = 0.
    WRITE / '创建成功'.

    CALL FUNCTION 'DDIF_TABL_ACTIVATE'
    EXPORTING
    name = tabname
    IMPORTING
    rc = subrc
    EXCEPTIONS
    not_found = 1
    put_failure = 2
    OTHERS = 3.
    IF sy-subrc <> 0 OR ( subrc <> 0 AND subrc <> 4 ).
    WRITE / '激活失败'.
    ELSE.
    WRITE / '激活成功'.
    ENDIF.
    ELSE.
    WRITE / '创建失败'.
    ENDIF.

    相关文章

      网友评论

          本文标题:创建表

          本文链接:https://www.haomeiwen.com/subject/vpcpiftx.html