Quantcast
Channel: SCN : Document List - ABAP Development
Viewing all articles
Browse latest Browse all 935

Using the GOS (Generic Object Services) Class within ITS programs

$
0
0

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

 

This last example demonstrates how to use the GOS class from within ITS applications.

 

Basic Setup

 

Create a program with one screen and a transaction.

 

Insert this code into the top include:

 

include avwrtcxm.

data: objtype type swo_objtyp.
data: objkey type swo_typeid.
data: g_dwnl_objtp like sood-objtp.
data: g_dwnl_objyr like sood-objyr.
data: g_dwnl_objno like sood-objno.
data: okcode like sy-ucomm.
data: save_ok_code like sy-ucomm.
data: dec_kb type p.
data: g_counter like sy-index.
data: g_lines like sy-tabix.
data: filelength type i.
data: it_content like standard table of soli.
data: mime_info like savwmpmime occurs 0 with header line.
data: lta_sood type standard table of sood.
data: lwa_sood type sood.
data: ls_lporb type sibflporb.
data: lt_bapirettab type bapirettab.
data: lv_objtyp type so_obj_tp.
data: l_file_name_with_path type avwctxcont.
data: mimetype type w3conttype.
data: g_filename type string.
data: g_download_content type soli_tab.
data: size type i.
data: t_receivers type somlreci1 occurs 0 with header line.

 

Screen 0100 Attributes:

 

p.jpg

 

Listing Attachments

 

module status_0100 output.

  objtype = 'BUS1065'.
  objkey = '00000111'.

  ls_lporb-typeid = objtype.
  ls_lporb-instid = objkey.

  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.
    g_counter = 1.
    describe table lta_sood lines g_lines.
    field-set 'TOTAL_ATTACHMENTS' g_counter g_lines.
    field-transport.

    g_counter = 1.
    loop at lta_sood into lwa_sood.
      dec_kb = lwa_sood-objlen / 1024.
      if dec_kb < 1.
        dec_kb = 1.
      endif.

      field-set 'ATTACHMENTS_COL1' g_counter lwa_sood-objdes.
      field-set 'ATTACHMENTS_COL2' g_counter dec_kb.
      if lwa_sood-acnam <> ''.
        field-set 'ATTACHMENTS_COL3' g_counter lwa_sood-acnam.
      else.
        field-set 'ATTACHMENTS_COL3' g_counter lwa_sood-file_ext.
      endif.
      field-set 'ATTACHMENTS_objtp' g_counter lwa_sood-objtp.
      field-set 'ATTACHMENTS_objyr' g_counter lwa_sood-objyr.
      field-set 'ATTACHMENTS_objno' g_counter lwa_sood-objno.
      g_counter = g_counter + 1.
    endloop.
    field-transport.
  endif.

endmodule.                 " STATUS_0100  OUTPUT

 

Uploading Attachments, Downloading Attachments, Emailing Attachments

 

module user_command_0100 input.

  save_ok_code = sy-ucomm.

  lv_objtyp = 'EXT'.
  ls_lporb-typeid = objtype.
  ls_lporb-instid = objkey.

  case save_ok_code.
    when 'FIUP'.
      clear mime_info.

      mime-info mime_info.
      loop at mime_info.
        mime-upload sy-tabix it_content filelength.
      endloop.

      move mime_info-contfname to l_file_name_with_path.
      move mime_info-contfname to g_filename.

      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      = filelength
        receiving
          rt_messages        = lt_bapirettab.

      if lt_bapirettab[] is initial.
        leave to transaction 'ZGOS_NEW'.
      endif.
    when 'DOWN'.
      "note: This code should really be put in the PBO of a new screen since the mime-download
      "is the only processing completed.
      if not ( g_dwnl_objtp is initial ) and
         not ( g_dwnl_objyr is initial ) and
         not ( g_dwnl_objno is initial ).
        call method zcl_oh_my_gos_new=>gos_get_file_solitab
          exporting
            folder_region     = 'B'
            doctp             = g_dwnl_objtp
            docyr             = g_dwnl_objyr
            docno             = g_dwnl_objno
          importing
            o_content_solitab = g_download_content
            o_mimetype        = mimetype
            o_filelength      = size
            rt_messages       = lt_bapirettab.

        if lt_bapirettab[] is initial.
          mime-download g_download_content size mimetype.
        endif.
      endif.
    when 'EMAIL'.
      if not ( g_dwnl_objtp is initial ) and
         not ( g_dwnl_objyr is initial ) and
         not ( g_dwnl_objno is initial ).
        clear t_receivers.
        t_receivers-receiver = 'elvis@presley.com'.
        t_receivers-rec_type = 'U'.
        append t_receivers.

        call method zcl_oh_my_gos_new=>gos_email_attached_file
          exporting
            folder_region = 'B'
            doctp         = g_dwnl_objtp
            docyr         = g_dwnl_objyr
            docno         = g_dwnl_objno
            t_receivers   = t_receivers[]
          importing
            rt_messages   = lt_bapirettab.
      endif.
  endcase.

endmodule.                 " USER_COMMAND_0100  INPUT

 

ITS HTML

 

<html>
<head>
  <title>`~windowtitle`</title>
</head>
<body>
  `~messageline`

  <!--BEGIN UPLOAD FILE PROCESSING-->
  <form method="post" enctype="multipart/form-data" action="`WGateURL()`">
  <p><CENTER><INPUT TYPE="FILE" size="50" NAME="LOCALFILE1"></CENTER></p>
  <p><CENTER><INPUT TYPE="SUBMIT" NAME="~OkCode(FIUP)" VALUE="Upload File"></CENTER></p>
  </form>
  <!--END UPLOAD FILE PROCESSING-->


  <!--BEGIN DOWNLOAD FILE PROCESSING-->
  `if (TOTAL_ATTACHMENTS > 0)`
      <CENTER>
      <TABLE border=1>
      <TH colspan=3>
        <font face="arial, helvetica" class="style5" size="2">Attached Documents</font>
      </TH>
      <TR><TD></TD></TR>
  `end`
  `repeat with j from 1 to TOTAL_ATTACHMENTS`
      <FORM NAME="`ATTACHMENTS_DOWN_objno[j]`"
       ACTION = "`wgateURL(~OKCode="DOWN")`&g_dwnl_objtp=`ATTACHMENTS_objtp[j]`&g_dwnl_objyr=`ATTACHMENTS_objyr[j]`&g_dwnl_objno=`ATTACHMENTS_objno[j]`"
       METHOD="post">
      <TR>
          <TD>
                <font face="arial, helvetica" class="style5" size="2">
                  <INPUT TYPE="submit" name="" value="Download File">
                </font>
          </TD>
          <TD>
              <font face="arial, helvetica" class="style5" size="2">
                `ATTACHMENTS_COL1[j]` (`ATTACHMENTS_COL2[j]`KB )
              </font>
          </TD>
          <TD align=center>
              <font face="arial, helvetica" class="style5" size="2">
                &nbsp&nbsp`ATTACHMENTS_COL3[j]`&nbsp&nbsp
              </font>
          </TD>
      </TR>
      </FORM>
  `end`
  `if (TOTAL_ATTACHMENTS > 0)`
      </TABLE>
      </CENTER>
  `end`
  <!--END DOWNLOAD FILE PROCESSING-->

  <p><p>

  <!--BEGIN EMAIL FILE PROCESSING-->
  `if (TOTAL_ATTACHMENTS > 0)`
      <CENTER>
      <TABLE border=1>
      <TH colspan=3>
              <font face="arial, helvetica" class="style5" size="2">Attached Documents</font>
      </TH>
      <TR><TD></TD></TR>
  `end`
  `repeat with j from 1 to TOTAL_ATTACHMENTS`
      <FORM NAME="`ATTACHMENTS_EMAIL_objno[j]`"
       ACTION = "`wgateURL(~OKCode="EMAIL")`&g_dwnl_objtp=`ATTACHMENTS_objtp[j]`&g_dwnl_objyr=`ATTACHMENTS_objyr[j]`&g_dwnl_objno=`ATTACHMENTS_objno[j]`"
       METHOD="post">
      <TR>
          <TD>
                <font face="arial, helvetica" class="style5" size="2">
                  <INPUT TYPE="submit" name="" value="Email File">
                </font>
          </TD>
          <TD>
              <font face="arial, helvetica" class="style5" size="2">
                `ATTACHMENTS_COL1[j]` (`ATTACHMENTS_COL2[j]`KB )
              </font>
          </TD>
          <TD align=center>
              <font face="arial, helvetica" class="style5" size="2">
                &nbsp&nbsp`ATTACHMENTS_COL3[j]`&nbsp&nbsp
              </font>
          </TD>
      </TR>
      </FORM>
  `end`
  `if (TOTAL_ATTACHMENTS > 0)`
      </TABLE>
      </CENTER>
  `end`
  <!--END EMAIL FILE PROCESSING-->

</body>
</html>

 

RESULT

 

p.jpg


Viewing all articles
Browse latest Browse all 935

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>