Chinaunix首页 | 论坛 | 博客
  • 博客访问: 484177
  • 博文数量: 199
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 1902
  • 用 户 组: 普通用户
  • 注册时间: 2020-05-14 13:25
个人简介

代码5S

文章分类

全部博文(199)

文章存档

2021年(5)

2020年(194)

我的朋友

分类: 其他平台

2020-06-08 12:32:22

*&---------------------------------------------------------------------*
*& Report  ZGOS_ATTACHMENT
*&
*&---------------------------------------------------------------------*
*&this program will attach documents to SAP documents.
*&
*&---------------------------------------------------------------------* 


report  zgos_attachment.


*Macros.
include .
swc_container lt_message_container.
*top dec.
type-pools: slis, abap, truxs.
data: g_objid     type ydmfw_objid,
      gt_filename type standard table of dxfilep with header line,
      wa_filename type dxfilep,
      gt_bin      type solix occurs 0,
      wa_bin      type solix,
      g_filename  type string,
      l_obj       type swc_object,
      gs_obja     type borident,
      gs_objb     type borident,
      gs_binrel   type gbinrel,
      gt_binatt   type standard table of brelattr,
      g_attsize   type INT4."wsrm_error-wsrm_direction.


selection-screen begin of block b0 with frame title text-001.
parameters: p_file  type rlgrap-filename,
            p_belnr type bkpf-belnr.
selection-screen end of block b0.


*----------------------------------------------------------------------*
* AT SELECTION-SCREEN  on                                  *
*----------------------------------------------------------------------*
at selection-screen on p_file.
  if p_file is initial.
    message e999(yfimc01) with 'Please select the file path'. "#EC NOTEXT
  endif.
*----------------------------------------------------------------------*
* AT SELECTION-SCREEN  on HELP-REQUEST|VALUE-REQUEST                   *
*----------------------------------------------------------------------*
at selection-screen  on value-request for p_file.
  call function 'F4_FILENAME'
    exporting
      program_name  = syst-cprog
      dynpro_number = syst-dynnr
      field_name    = 'P_FILE'
    importing
      file_name     = p_file.


start-of-selection.
* this step can be replace to get file from app server as well.
*uploading [file: EXT is TXT].
  move  p_file to g_filename.
  call function 'GUI_UPLOAD'
    exporting
      filename                = g_filename
      filetype                = 'BIN'
    importing
      filelength              = g_attsize
    tables
      data_tab                = gt_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.
  else.
*file Uploaded successfully.
*convert uploaded file contents into BIN format.
    data: l_seq type i.
    swc_container      l_cont.
    swc_create_object  l_obj  'MESSAGE'       ''.
    swc_set_element    l_cont 'NO_DIALOG'     'X'.
    swc_set_element    l_cont 'DOCUMENTTITLE' g_filename.
    swc_set_table      l_cont 'Content_Hex'   gt_bin.
    swc_set_element    l_cont 'DOCUMENTTYPE'  'TXT'.
    swc_set_element    l_cont 'DOCUMENTSIZE'  g_attsize.
    swc_refresh_object l_obj.
    swc_call_method    l_obj  'CREATE'        l_cont.
    swc_get_object_key l_obj  gs_objb-objkey.


    gs_objb-objtype = 'MESSAGE'.   "type of attach document
    gs_obja-objtype = 'BKPF'.      "BO of SAP Document.
    concatenate    '0001'  "company code
                   p_belnr "FI Document
                   '2009'  "fiscal year
                   into
                   gs_obja-objkey.


    call function 'BINARY_RELATION_CREATE_COMMIT'
      exporting
        obj_rolea      = gs_obja
        obj_roleb      = gs_objb
        relationtype   = 'ATTA'
      importing
        binrel         = gs_binrel
      tables
        binrel_attrib  = gt_binatt
      exceptions
        no_model       = 1
        internal_error = 2
        unknown        = 3
        others         = 4.
    if sy-subrc eq 0.
      message s043(sgos_msg).
    endif.
  endif.
————————————————
版权声明:本文为CSDN博主「u010450973」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/u010450973/java/article/details/51453588
阅读(1916) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~