GOS会计凭证上传附件

1、GOS介绍

GOS是一个连接文档和SAP内各种对象的工具,在SAP的一些凭证中,可以通过GOS进行附件的上传、查看和删除等功能,例如采购订单、会计凭证等。

如果没有这个按钮,可以将当前登录用户的类型设置为对话即可。

 2、前台附件上传

点击创建附件,选择需要上传的附件即可

 点击附件清单,即可查看上传的附件

 并且可以对当前上传的附件进行删除操作

 3、代码实现

 源代码

"--------------------@斌将军--------------------
REPORT zgos.

TYPE-POOLS: slis,abap,truxs.
INCLUDE <cntn01>.

*----------------------------------------------------------------------*
*   屏幕定义
*----------------------------------------------------------------------*
SELECTION-SCREEN BEGIN OF BLOCK blk1 WITH FRAME TITLE TEXT-002.
  PARAMETERS:p_file  TYPE rlgrap-filename MEMORY ID p, "上载模版路径
             p_belnr TYPE bkpf-belnr OBLIGATORY,
             p_gjahr TYPE bkpf-gjahr OBLIGATORY,
             p_bukrs TYPE bkpf-bukrs OBLIGATORY.
SELECTION-SCREEN END OF BLOCK blk1.

*----------------------------------------------------------------------*
* AT SELECTION-SCREEN  on HELP-REQUEST|VALUE-REQUEST                   *
*----------------------------------------------------------------------*
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
  "选择路径
  PERFORM frm_choose_file.

*----------------------------------------------------------------------*
* START-OF-SELECTION                                                   *
*----------------------------------------------------------------------*
START-OF-SELECTION.
  "上传附件
  PERFORM frm_upload_file.

*&---------------------------------------------------------------------*
*&      Form  FRM_CHOOSE_FILE
*&---------------------------------------------------------------------*
*       选择文件
*----------------------------------------------------------------------*
FORM frm_choose_file.
  "F4 选择文件
  CALL FUNCTION 'F4_FILENAME'
    IMPORTING
      file_name = p_file.

  IF sy-subrc <> 0.
  ENDIF.
ENDFORM. "FRM_CHOOSE_FILE

*&---------------------------------------------------------------------*
*&      Form  FRM_UPLOAD_FILE
*&---------------------------------------------------------------------*
*       上传附件
*----------------------------------------------------------------------*
FORM frm_upload_file.

  DATA:lt_swcont        TYPE TABLE OF swcont WITH HEADER LINE,
       lt_binrel_attrib TYPE TABLE OF brelattr,
       lt_bin           TYPE TABLE OF solix.

  DATA:lv_filename       TYPE string,
       lv_long_filename  TYPE dbmsgora-filename,
       lv_pure_filename  TYPE sdbah-actid,
       lv_pure_extension TYPE sdbad-funct,
       ls_obja           TYPE borident,
       ls_roleb          TYPE borident,
       ls_binrel         TYPE gbinrel,
       ls_attsize        TYPE int4,
       lo_swc_obj        TYPE swc_object.

  "上传文件
  CLEAR:lv_filename.
  lv_filename = p_file.
  CALL FUNCTION 'GUI_UPLOAD'
    EXPORTING
      filename                = lv_filename
      filetype                = 'BIN'
    IMPORTING
      filelength              = ls_attsize
    TABLES
      data_tab                = lt_bin
    EXCEPTIONS
      file_open_error         = 1
      file_read_error         = 2
      no_batch                = 3
      gui_refuse_filetransfer = 4
      invalid_type            = 5
      no_authority            = 6
      unknown_error           = 7
      bad_data_format         = 8
      header_not_allowed      = 9
      separator_not_allowed   = 10
      header_too_long         = 11
      unknown_dp_error        = 12
      access_denied           = 13
      dp_out_of_memory        = 14
      disk_full               = 15
      dp_timeout              = 16
      OTHERS                  = 17.
  IF sy-subrc <> 0.
    MESSAGE '文件上传失败' TYPE 'S' DISPLAY LIKE 'E'.
    STOP.
  ELSE.

    CLEAR:lv_long_filename.
    lv_long_filename = lv_filename.
    "截取文件名称和后缀
    CALL FUNCTION 'SPLIT_FILENAME'
      EXPORTING
        long_filename  = lv_long_filename
      IMPORTING
        pure_filename  = lv_pure_filename
        pure_extension = lv_pure_extension.

    "转换文件
    swc_create_object  lo_swc_obj 'MESSAGE' ''.
    swc_set_element    lt_swcont 'NO_DIALOG' 'X'.
    swc_set_element    lt_swcont 'DOCUMENTTITLE' lv_pure_filename."文件名
    swc_set_table      lt_swcont 'Content_Hex'   lt_bin."文件内容
    swc_set_element    lt_swcont 'DOCUMENTTYPE'  lv_pure_extension."文件格式
    swc_set_element    lt_swcont 'DOCUMENTSIZE'  ls_attsize."文件大小
    swc_refresh_object lo_swc_obj.
    swc_call_method    lo_swc_obj  'CREATE' lt_swcont.
    swc_get_object_key lo_swc_obj  ls_roleb-objkey.

    ls_roleb-objtype = 'MESSAGE'.   "
    ls_obja-objtype = 'BKPF'.      "
    ls_obja-objkey = p_bukrs && p_belnr && p_gjahr."拼接会计公司、会计凭证、会计年度

    "上传附件
    CALL FUNCTION 'BINARY_RELATION_CREATE_COMMIT'
      EXPORTING
        obj_rolea      = ls_obja
        obj_roleb      = ls_roleb
        relationtype   = 'ATTA'
      IMPORTING
        binrel         = ls_binrel
      TABLES
        binrel_attrib  = lt_binrel_attrib
      EXCEPTIONS
        no_model       = 1
        internal_error = 2
        unknown        = 3
        OTHERS         = 4.
    IF sy-subrc EQ 0.
      MESSAGE s043(sgos_msg)."已成功创建附件
    ENDIF.
  ENDIF.

ENDFORM.
"--------------------@斌将军--------------------

定期更文,欢迎关注

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值