Dear SAP Community Member,
In order to fully benefit from what the SAP Community has to offer, please register at:
Thank you,
The SAP Community team.
The SAP Community wiki will be closed to new content submissions from December 7 6:00 p.m. CET to December 11 6:00 p.m. CET.
All content created during this period will not be available/restorable after December 11.
We apologize for the inconvenience, but we need to take this action to improve and maintain the SAP Community wiki performance.
Please plan your tasks accordingly.
Skip to end of metadata
Go to start of metadata


Unknown macro: { font-family}


Unknown macro: { font-style}


Unknown macro: { color}


Unknown macro: { color}


Unknown macro: { color}

*&this program will attach documents to SAP documents.

report  zgos_attachment.
include <cntn01>.
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 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 <parameters>                                 *
at selection-screen on p_file.
  if p_file is initial.
    message e999(yfimc01) with 'Please select the file path'. "#EC NOTEXT
at selection-screen  on value-request for p_file.
  call function 'F4_FILENAME'
      program_name  = syst-cprog
      dynpro_number = syst-dynnr
      field_name    = 'P_FILE'
      file_name     = p_file.

* 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'
      filename                = g_filename
      filetype                = 'BIN'
      filelength              = g_attsize
      data_tab                = gt_bin
      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.
*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

        obj_rolea      = gs_obja
        obj_roleb      = gs_objb
        relationtype   = 'ATTA'
        binrel         = gs_binrel
        binrel_attrib  = gt_binatt
        no_model       = 1
        internal_error = 2
        unknown        = 3
        others         = 4.
    if sy-subrc eq 0.
      message s043(sgos_msg).

  • No labels