上传PDF、DOC文件到SAP HCM系统中案例

背景:公司最近在上电子签系统,以实现劳动合同、保密协议等文件的去纸质化,保存为电子档文件,而企业的信息化的中心是SAP ERP,于是领导要求将签好的电子文件存储到HCM中。

题主写了如下代码实现需求:

FUNCTION ZHR_SAVE_FILE.
*"----------------------------------------------------------------------
*"*"局部接口:
*"  IMPORTING
*"     VALUE(FILE) TYPE  STRING OPTIONAL
*"     VALUE(USRTY) TYPE  CHAR4 OPTIONAL
*"     VALUE(USRID) TYPE  CHAR30 OPTIONAL
*"     VALUE(FILETYPE) TYPE  CHAR10 OPTIONAL
*"  EXPORTING
*"     VALUE(ZTYPE) TYPE  TEXT1
*"     VALUE(MESSAGE) TYPE  CHAR200
*"----------------------------------------------------------------------

  DATA: access_info   LIKE  scms_acinf   OCCURS 1 WITH HEADER LINE,
        content_txt   LIKE  sdokcntasc   OCCURS 1,
        content_bin   LIKE  sdokcntbin   OCCURS 1.
  DATA: ls_content_bin LIKE LINE OF content_bin.
  DATA: l_string TYPE string.
  DATA: l_xstring TYPE xstring.
  DATA: doc_id_out TYPE char40.
*  DATA: ADOKID     TYPE SAPB-SAPADOKID.
*  DATA: lt_ztb_icnum LIKE TABLE OF ztb_icnum,
*        ls_ztb_icnum LIKE LINE OF lt_ztb_icnum.
  access_info-comp_id    = 'data'.

  IF FILETYPE is INITIAL or FILETYPE = '' .
    ztype = 'E'.
    message = '请输入文件类型!' .
    return.
  ENDIF.

  IF USRID is INITIAL or USRID = ''.
    ztype = 'E'.
    message = '请输入人员工号!' .
    return.
  ENDIF.

  IF usrty IS NOT INITIAL AND usrid IS NOT INITIAL AND file IS NOT INITIAL .
*    ls_ztb_icnum-ictyp = usrty.                               "通过证件号码获取人员编号
*    ls_ztb_icnum-icnum = usrid.
*    APPEND ls_ztb_icnum TO lt_ztb_icnum.CLEAR ls_ztb_icnum.
*
*
*    IF lt_ztb_icnum[] IS NOT INITIAL.
*
*      CALL FUNCTION 'Z_IF_HR_PA_CHECK'
*        TABLES
*          tb_hr_icnum = lt_ztb_icnum.
*
*    ENDIF.
*
*    READ TABLE lt_ztb_icnum INTO ls_ztb_icnum INDEX 1.
*
*    IF ls_ztb_icnum-pernr IS NOT INITIAL.                         "判断是否能找到SAP对应的人员编号

      CALL FUNCTION 'SCMS_BASE64_DECODE_STR'
        EXPORTING
          input    = file
*     unescape = 'X'
        IMPORTING
          output   = l_xstring
        EXCEPTIONS
          failed   = 1
          OTHERS   = 2.
      IF sy-subrc <> 0.
* Implement suitable error handling here
      ENDIF.

      CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
        EXPORTING
          buffer                = l_xstring
*     APPEND_TO_TABLE       = ' '
*   IMPORTING
*     OUTPUT_LENGTH         =
        TABLES
          binary_tab            = content_bin
                .

      DATA: lv_nu TYPE i.
      CLEAR l_string.
      CLEAR access_info-comp_size.
      LOOP AT content_bin INTO ls_content_bin.
        l_string = ls_content_bin-line.
        access_info-comp_size = STRLEN( l_string ) + access_info-comp_size.
      ENDLOOP.
      access_info-mimetype   = 'application/*'.
      access_info-binary_flg = 'X'.
      access_info-first_line = 1.
      access_info-last_line = LINES( content_bin ).
      APPEND access_info.

      CALL FUNCTION 'SCMS_R3DB_EXPORT'
        EXPORTING
          mandt             = sy-mandt
          crep_id           = 'A2'
          doc_id            = ''
          doc_prot          = 'rud'
          overwrite         = '-'
          vscan_profile     = '/SCMS/KPRO_CREATE'
        IMPORTING
          doc_id_out        = doc_id_out
        TABLES
          access_info       = access_info
          content_txt       = content_txt
          content_bin       = content_bin
        EXCEPTIONS
          error_export      = 1
          error_import      = 2
          error_parameter   = 3
          blocked_by_policy = 4
          OTHERS            = 5.
      IF sy-subrc <> 0.
*    case sy-subrc.
*      when 1.      sys_message_raising error_export.
*      when 2.      sys_message_raising error_export.
*      when 3.      sys_message_raising error_parameter.
*      when 4.      sys_message_raising blocked_by_policy.
*      when others. sys_message_raising error_export.
*    endcase.
      ELSE.
        DATA: BEGIN OF i_toaom OCCURS 1.
                INCLUDE STRUCTURE toaom.
        DATA: END OF i_toaom.
        DATA: BEGIN OF i_toav0 OCCURS 1.
                INCLUDE STRUCTURE toav0.
        DATA: END OF i_toav0.

        REFRESH i_toaom.
        i_toav0-mandt       = sy-mandt.
        i_toav0-sap_object  = 'PREL'.
        i_toav0-archiv_id  = 'A2'.
        i_toav0-object_id  = usrid. "pernr-pernr
        i_toav0-ar_object   = 'HRICONTRAC'.
        i_toav0-ar_date     = sy-datum.
*  I_TOAV0-DEL_DATE    = SY-DATUM.
        i_toav0-reserve     = filetype.
        i_toav0-arc_doc_id  = doc_id_out.
        APPEND i_toav0.
        CALL FUNCTION 'ARCHIV_CONNECTIONTABLE_INSERT'
          TABLES
            entrys_connectiontable = i_toav0
          EXCEPTIONS
            no_entry_possible      = 1
            OTHERS                 = 2.
        CASE sy-subrc.
          WHEN 1.
            MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
              WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4
              RAISING no_entry_possible.
          WHEN 2.
            MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
              WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4
              RAISING others.
          WHEN OTHERS.
            ztype = 'S'.
            message = '上传成功'.
        ENDCASE.
      ENDIF.
*    ELSE.
*      ztype = 'E'.
*      CONCATENATE '无法在SAP系统中找到证件号码为:' ls_ztb_icnum-icnum ',的人员!' INTO message .
    ENDIF.
*  ELSE.
*    ztype = 'E'.
*    message = '请输入所有必输项!'.
*  ENDIF.

ENDFUNCTION.

效果图如下:

相关推荐
LostSpeed4 小时前
在福昕(pdf)阅读器中导航到上次阅读页面的方法
pdf
旭久4 小时前
SpringBoot的Thymeleaf做一个可自定义合并td的pdf表格
pdf·html·springboot
雕刻刀10 小时前
Latex 转换为 Word(使用GrindEQ )(英文转中文,毕业论文)
word
觅远21 小时前
python实现word转html
python·html·word
养个小橘猫21 小时前
Word使用分隔符实现页面部分分栏
word
神色自若1 天前
Net9为PDF文字替换,使用Spire.PDF版本10.12.4.1360
pdf
机器懒得学习1 天前
解析交通事故报告:利用 PDF、AI 与数据标准化技术构建智能分析系统
pdf
SEO-狼术1 天前
Document Solutions for Word CRACK
word
合合技术团队2 天前
高效准确的PDF解析工具,赋能企业非结构化数据治理
人工智能·科技·pdf·aigc·文档