Skip to Content

Linked From Document: http://scn.sap.com/docs/DOC-41921

This first example demonstrates how to use the GOS class from within regular SAP GUI applications such as report programs.

Listing Attachments

report  zget_file_list_using_class.

data: lta_sood type standard table of sood, lwa_sood type sood.
data: str_write type string.
data: ls_lporb type sibflporb.

*Specify Business Object Type and Key (BUS1065 = Employees)
parameters: p_key type swo_typeid obligatory default ‘00000111’,
                    p_type type swo_objtyp obligatory default ‘BUS1065’.

start-of-selection.

  data: lt_bapirettab type bapirettab.

  ls_lporb-typeid = p_type.
  ls_lporb-instid = p_key.

  call method zcl_oh_my_gos_new=>gos_get_file_list
    exporting
      is_lporb      = ls_lporb
    importing
      t_attachments = lta_sood
      rt_messages   = lt_bapirettab.

  if lt_bapirettab[] is initial.
    data dec_kb type p.

    loop at lta_sood into lwa_sood.

      dec_kb = lwa_sood-objlen / 1024.
      if dec_kb < 1.
        dec_kb = 1.
      endif.
      write: / lwa_sood-objdes, dec_kb, ‘KB’, ‘ ‘, lwa_sood-acnam.
    endloop.
  endif.

Uploading Attachments

report  zfile_upload_using_class.

*Specify Business Object Type and Key (BUS1065 = Employees))
parameters: p_key type swo_typeid obligatory default ‘00000111’,
            p_type type swo_objtyp obligatory default ‘BUS1065’,
            p_file type rlgrap-filename obligatory.

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.

  data: g_filename type string.
  data: g_attsize type wsrm_error-wsrm_direction.
  data: it_content like standard table of soli.
  data: ta_srgbtbrel type standard table of srgbtbrel, wa_srgbtbrel type srgbtbrel.
  data: lta_sood type standard table of sood, lwa_sood type sood.
  data: dec_kb type p.
  data: ls_lporb type sibflporb.
  data: lv_objtyp type so_obj_tp.
  data: lt_bapirettab type bapirettab.

  lv_objtyp = ‘EXT’.
  ls_lporb-instid = p_key.
  ls_lporb-typeid = p_type.

  move  p_file to g_filename.

  call function ‘GUI_UPLOAD’
    exporting
      filename   = g_filename
      filetype   = ‘BIN’
    importing
      filelength = g_attsize
    tables
      data_tab   = it_content.

  if sy-subrc eq 0.
    call method zcl_oh_my_gos_new=>gos_attach_file_solitab
      exporting
        iv_name            = g_filename
        iv_content_solitab = it_content
        is_lporb           = ls_lporb
        iv_objtp           = lv_objtyp
        iv_filelength      = g_attsize
      receiving
        rt_messages        = lt_bapirettab.
  endif.

  call method zcl_oh_my_gos_new=>gos_get_file_list
    exporting
      is_lporb      = ls_lporb
    importing
      t_attachments = lta_sood
      rt_messages   = lt_bapirettab.

  if lt_bapirettab[] is initial.
    write: /.
    loop at lta_sood into lwa_sood.
      dec_kb = lwa_sood-objlen / 1024.
      if dec_kb < 1.
        dec_kb = 1.
      endif.

      write: / lwa_sood-objdes, dec_kb, ‘KB’, ‘ ‘, lwa_sood-acnam.
    endloop.
  endif.

Downloading Attachments

report  zfile_download_using_class.

data: ta_srgbtbrel type standard table of srgbtbrel, wa_srgbtbrel type srgbtbrel.
data: lta_sood type standard table of sood, lwa_sood type sood.
data: dec_kb type p.
data: ls_lporb type sibflporb.
data: lt_bapirettab type bapirettab.

*Specify Business Object Type and Key (BUS1065 = Employees)
parameters: p_key type swo_typeid obligatory default ‘00000111’,
            p_type type swo_objtyp obligatory default ‘BUS1065’.

start-of-selection.

  ls_lporb-typeid = p_type.
  ls_lporb-instid = p_key.

  call method zcl_oh_my_gos_new=>gos_get_file_list
    exporting
      is_lporb      = ls_lporb
    importing
      t_attachments = lta_sood
      rt_messages   = lt_bapirettab.

  if lt_bapirettab[] is initial.
    loop at lta_sood into lwa_sood.
      call method zcl_oh_my_gos_new=>gos_download_file_to_gui
        exporting
          file_path  = ‘C:\TEMP\TTT’
          attachment = lwa_sood
        importing
          rt_messages = lt_bapirettab.
      if lt_bapirettab[] is initial.
        dec_kb = lwa_sood-objlen / 1024.
        if dec_kb < 1.
          dec_kb = 1.
        endif.

        write: / lwa_sood-objdes, dec_kb, ‘KB’, ‘ ‘, lwa_sood-acnam.
      endif.
    endloop.
  endif.

Emailing Attachments

report  zfile_email_using_class.

data: ta_srgbtbrel type standard table of srgbtbrel, wa_srgbtbrel type srgbtbrel.
data: lta_sood type standard table of sood, lwa_sood type sood.
data: t_receivers type somlreci1 occurs 0 with header line.

*Specify Business Object Type and Key (BUS1065 = Employees)
parameters: p_key type swo_typeid obligatory default ‘00000111’,
            p_type type swo_objtyp obligatory default ‘BUS1065’,
            p_recevr type so_recname obligatory default ‘elvis@presley.com’.

start-of-selection.

  data: t_st_return type zvnt_st_return.
  data: ls_lporb type sibflporb.
  data: lt_bapirettab type bapirettab.

  ls_lporb-typeid = p_type.
  ls_lporb-instid = p_key.

  call method zcl_oh_my_gos_new=>gos_get_file_list
    exporting
      is_lporb      = ls_lporb
    importing
      t_attachments = lta_sood
      rt_messages   = lt_bapirettab.

  if lt_bapirettab[] is initial.
    data dec_kb type p.

    loop at lta_sood into lwa_sood.
      dec_kb = lwa_sood-objlen / 1024.
      if dec_kb < 1.
        dec_kb = 1.
      endif.
      write: / lwa_sood-objdes, dec_kb, ‘KB’, ‘ ‘, lwa_sood-acnam.

      clear t_receivers.
      t_receivers-receiver = p_recevr.
      t_receivers-rec_type = ‘U’.
      append t_receivers.

      call method zcl_oh_my_gos_new=>gos_email_attached_file
        exporting
          folder_region = ‘B’
          doctp         = lwa_sood-objtp
          docyr         = lwa_sood-objyr
          docno         = lwa_sood-objno
          t_receivers   = t_receivers[]
        importing
          rt_messages   = lt_bapirettab.
      if lt_bapirettab[] is initial.
        write: ‘(Attachment Has Been Sent)’.
      endif.
    endloop.
  endif.

To report this post you need to login first.

7 Comments

You must be Logged on to comment or reply to a post.

  1. Kesavadas Thekkillath

    Attaching GOS file for a single business object key at a time is easy compared to attaching the same file for multiple keys at a time. (for ex: attach the same file for multiple records ). It can done like mentioned here Bulk upload in Services for Object.

    Also,Thanks for combining everything into single document http://scn.sap.com/docs/DOC-41921. If the part which i mentioned was included, its neatly completed and search stress for a solution will be minimized 😉

    (0) 

Leave a Reply