欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

SAP PLM获取DMS文档原件示例

程序员文章站 2022-05-18 14:15:58
...

获取SAP PLM DMS原件,便于其他系统访问

示例代码:

DATA: LV_HOSTIP      TYPE TDWD-NTADR,
      LV_RFCHOST     TYPE RFCHOST_EXT,
      LV_RFCIP       TYPE RFCDISPLAY-RFCHOST.

DATA: DOKAR TYPE  DRAW-DOKAR,
      DOKNR TYPE  DRAW-DOKNR,
      DOKVR TYPE  DRAW-DOKVR,
      DOKTL TYPE  DRAW-DOKTL.

DATA: GT_FILES TYPE TABLE OF CVAPI_DOC_FILE WITH HEADER LINE,
      GT_DRAT TYPE TABLE OF DRAT WITH HEADER LINE.

DATA: LT_URL TYPE DMS_URL.

*数据传入传出
DATA: EV_OURL TYPE string,
      IV_FILENAME TYPE FILEP.

DOKAR = 'DWG'.
DOKNR = 'DWG-00000002'.
DOKVR = '00'.
DOKTL = '000'.
IV_FILENAME = 'EXPORT.XLSX'.


*第一步获取RFC IP地址
  LV_RFCHOST = SY-HOST.
  CALL FUNCTION 'RFC_HOST_TO_IP'
    EXPORTING
      RFCHOST                     = LV_RFCHOST
    IMPORTING
      RFCIP                       = LV_RFCIP
    EXCEPTIONS
      HOST_TO_IP_CONVERSION_ERROR = 1
      OTHERS                      = 2.
  IF SY-SUBRC <> 0.
    LV_HOSTIP = '10.18.11.12' .         "系统取不到则用定值
  ELSE .
    LV_HOSTIP = LV_RFCIP.
  ENDIF.

*第二步读取原文件清单
  CALL FUNCTION 'CVAPI_DOC_GETDETAIL'
    EXPORTING
      PF_BATCHMODE    = 'X'
      PF_DOKAR        = DOKAR
      PF_DOKNR        = DOKNR
      PF_DOKVR        = DOKVR
      PF_DOKTL        = DOKTL
      PF_READ_DRAD    = ' '
      PF_READ_DRAP    = ' '
      PF_ACTIVE_FILES = ' '
      PF_READ_COMP    = ' '
      PF_READ_KPRO    = 'X'
      PF_READ_DRAT    = 'X'
      PF_BAPI_CALL    = ' '
    TABLES
      PT_FILES        = GT_FILES
      PT_DRAT         = GT_DRAT
    EXCEPTIONS
      NOT_FOUND       = 1
      NO_AUTH         = 2
      ERROR           = 3
      OTHERS          = 4.
  IF SY-SUBRC <> 0.
    RETURN .
  ENDIF.

*第三步获取原文件URL

LOOP AT GT_FILES.
  DATA: lv_string1 TYPE string,
        lv_string2 TYPE string.

  lv_string1 = GT_FILES-FILENAME.
  lv_string2 = IV_FILENAME.

  TRANSLATE lv_string1 TO UPPER CASE.
  TRANSLATE lv_string2 TO UPPER CASE.

  IF lv_string1 = lv_string2.
    CALL FUNCTION 'CVAPI_DOC_VIEW'
      EXPORTING
        PF_DOKAR      = DOKAR
        PF_DOKNR      = DOKNR
        PF_DOKVR      = DOKVR
        PF_DOKTL      = DOKTL
        PF_HOSTNAME   = LV_HOSTIP
        PF_APPL_START = ' '
        PF_GET_URL    = 'X'
        PF_APPTP      = '1'

        PS_FILE       = GT_FILES
      IMPORTING
        PFX_URL       = LT_URL
      EXCEPTIONS
        ERROR         = 1
        NOT_FOUND     = 2
        NO_AUTH       = 3
        NO_ORIGINAL   = 4
        OTHERS        = 5.
    IF SY-SUBRC =  0.
      MOVE LT_URL TO EV_OURL.
    ENDIF.
    ENDIF.
ENDLOOP.

原件文件名存储位置:

Table:DMS_PHF_CD1