Skip to end of metadata
Go to start of metadata

List of all pages

Pages at first level

Author: Hardik Parikh
Submitted: 13/04/2010

Description : First We will Call Script while closing the Script form we get the Script Data in OTF Format. Our main aim is to Upload Respected Document in DMS Server.

So we have to Convert Script Generated Format to Other Binary Format way DMS Server Store it.

Error rendering macro 'code': Invalid value specified for parameter 'com.atlassian.confluence.ext.code.render.InvalidValueException'
CALL FUNCTION 'OPEN_FORM'
  EXPORTING
    device   = 'PRINTER'
    dialog   = space
    form     = 'ZSCRIPT1'
    language = sy-langu
    OPTIONS  = struct.

CALL FUNCTION 'START_FORM'
  EXPORTING
    form = 'ZSCRIPT1'.

CALL FUNCTION 'WRITE_FORM'
  EXPORTING
    element  = 'ELEM1'
    function = 'SET'
    type     = 'BODY'
    window   = 'MAIN'.

SELECT carrid connid price FROM sflight INTO TABLE itab.

LOOP AT itab.
  CALL FUNCTION 'WRITE_FORM'
    EXPORTING
      element  = 'ELEM2'
      function = 'SET'
      type     = 'BODY'
      window   = 'MAIN'.
ENDLOOP.

CALL FUNCTION 'END_FORM'.
CALL FUNCTION 'CLOSE_FORM'
  TABLES
    otfdata = datab[].

***************************ENDOFSAPSCRIPTGENERATION*******************************
DATA: lv_pdfsource TYPE xstring.
CALL FUNCTION 'CONVERT_OTF'
  EXPORTING
    format                = 'PDF'
  IMPORTING
    bin_filesize          = binfilesize
    bin_file              = lv_pdfsource
  TABLES
    otf                   = datab[]
    lines                 = pdftab[]
  EXCEPTIONS
    err_max_linewidth     = 1
    err_format            = 2
    err_conv_not_possible = 3
    err_bad_otf           = 4
    OTHERS                = 5.

*---here we will get lv_pdfsource as zstrong data now Convert XSTRING TO BInary DAta.
DATA: lt_bintab TYPE TABLE OF ls_bintab,
      wa_bintab TYPE ls_bintab.
CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
  EXPORTING
    buffer        = wa_xstring-xstring
  IMPORTING
    output_length = binlen
  TABLES
    binary_tab    = lt_bintab.

*now create dms document using given function module
documentdata-documenttype = 'DS1'.
documentdata-documentnumber = l_docname.
*DOCUMENTDATA-DOCUMENTVERSION = '01'.
documentdata-documentpart = '000'.
documentdata-username = sy-uname.
documentdata-description = l_docname.
documentdata-authoritygroup = '5000'.
documentdescriptions\-language = 'EN'.
documentdescriptions-description = l_docname.
APPEND documentdescriptions TO it_documentdescriptions.

CALL FUNCTION 'BAPI_DOCUMENT_CREATE2'
  EXPORTING
    documentdata    = documentdata
  IMPORTING
    documenttype    = attr_draw-dokar
    documentnumber  = attr_draw-doknr
    documentpart    = attr_draw-doktl
    documentversion = attr_draw-dokvr
    return          = return.


CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
  EXPORTING
    wait = 'X'.
*now after successful document creation we have to attach document to this dms document
FIELD-SYMBOLS: <fs1> TYPE ls_bintab.
LOOP AT lt_bintab ASSIGNING <fs1>.
  clearls_drao.
  ls_drao-orblk = <fs1>-line.
  ls_drao-orln = binlen.
  APPEND ls_drao TO lt_drao.
ENDLOOP.

CONCATENATE l_docname 'pdf'
INTO l_filename SEPARATED BY '.'.

ls_file-updateflag = 'I'.
ls_file-dappl = 'PDF'.
ls_file-storage_cat = 'ZDMS'.
ls_file-filename = l_filename.
ls_file-description = l_docname."file_st-cvtext."'AcrobatReader'.
ls_file-checked_in = 'X'.
APPEND ls_file TO lt_files.
ls_api_cntl-no_update_task = 'X'.

CALL FUNCTION 'CVAPI_DOC_CHECKIN'
  EXPORTING
    pf_dokar           = 'DS1'"gs_draw-dokar
    pf_doknr           = attr_draw-doknr
    pf_dokvr           = attr_draw-dokvr
    pf_doktl           = attr_draw-doktl
    pf_hostname        = 'DEFAULT'
    ps_api_control     = ls_api_cntl
    pf_replace         = 'X'
    pf_content_provide = 'TBL'
    pf_ftp_dest        = 'SAPFTPA'
    pf_http_dest       = 'SAPHTTPA'
  IMPORTING
    psx_message        = ls_msg
  TABLES
    pt_files_x         = lt_files
    pt_content         = lt_drao.

CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
  EXPORTING
    wait = 'X'.
Error rendering macro 'code': Invalid value specified for parameter 'com.atlassian.confluence.ext.code.render.InvalidValueException'
REPORT  zdms_mass_upload.
TYPE-POOLS:truxs, slis.
DATA:
     lt_documentdescriptions TYPE TABLE OF bapi_doc_drat,
     lt_characteristicvalues TYPE TABLE OF bapi_characteristic_values,
     lt_documentfiles        TYPE TABLE OF bapi_doc_files2,
     lt_drad                 TYPE TABLE OF bapi_doc_drad,
     lt_return               TYPE TABLE OF bapiret2,
     bt_return               TYPE TABLE OF bapiret2,
     ls_documentdata         TYPE bapi_doc_draw2,
     ls_drad                  TYPE bapi_doc_drad,
     ls_documentdescriptions TYPE bapi_doc_drat,
     ls_characteristicvalues TYPE bapi_characteristic_values,
     ls_documentfiles        TYPE bapi_doc_files2,
     ls_return               TYPE bapiret2,
     ss_return               TYPE bapiret2.

*Local Variable Declaration
DATA:  lv_documenttype     TYPE bapi_doc_aux-doctype,
       lv_documentnumber   TYPE bapi_doc_aux-docnumber,
       lv_documentpart     TYPE bapi_doc_aux-docpart,
       lv_documentversion  TYPE bapi_doc_aux-docversion,
       lv_msg              TYPE char255,
       tv_msg              TYPE char255.

TYPES: BEGIN OF i_out,
        index      TYPE sy-tabix,
        docnumber  TYPE bapi_doc_aux-docnumber,
        message(255)    TYPE c,
       END OF i_out.

TYPES: BEGIN OF ty_dokar,
        dokar TYPE  dokar,
       END OF ty_dokar.

*ALV data declarations
DATA: fieldcatalog TYPE slis_t_fieldcat_alv WITH HEADER LINE,
      gd_layout    TYPE slis_layout_alv,
      gd_repid     LIKE sy-repid.

DATA: it_out TYPE STANDARD TABLE OF i_out,
      wa_out TYPE i_out,
      it_success TYPE STANDARD TABLE OF i_out,
      ls_out TYPE i_out,
      w_index TYPE sy-tabix.

DATA: lt_dokar TYPE STANDARD TABLE OF ty_dokar.

DATA:  gt_file    TYPE STANDARD TABLE OF alsmex_tabline INITIAL SIZE 0.

* Access file and create XSTRING
TYPES: BEGIN OF ty_xline,
        ind(4)   TYPE c,
        doc_type(3) TYPE c,
        desc(50) TYPE c,
        filename(225) TYPE c,
        filetype(3) TYPE c,
        filepath(225) TYPE c,
        labor(3) TYPE c,
        storage(10) TYPE c,
        value1(30) TYPE c,
        value2(30) TYPE c,
        value3(30) TYPE c,
        value4(30) TYPE c,
        value5(30) TYPE c,
        value6(30) TYPE c,
        value7(30) TYPE c,
        value8(30) TYPE c,
        value9(30) TYPE c,
        value10(30) TYPE c,
        value11(30) TYPE c,
        value12(30) TYPE c,
       END OF ty_xline.

TYPES: BEGIN OF ty_errorlog,
        ind(4)       TYPE c,
        doc_type(3)  TYPE c,
        desc(50)     TYPE c,
        filename(225) TYPE c,
        filetype(3)   TYPE c,
        filepath(225) TYPE c,
        storage(10)   TYPE c,
        value1(30) TYPE c,
        value2(30) TYPE c,
        value3(30) TYPE c,
        value4(30) TYPE c,
        value5(30) TYPE c,
        value6(30) TYPE c,
        value7(30) TYPE c,
        value8(30) TYPE c,
        value9(30) TYPE c,
        value10(30) TYPE c,
        value11(30) TYPE c,
        value12(30) TYPE c,
        msg TYPE char255,
       END OF ty_errorlog.
DATA:
       lf_file        TYPE rlgrap-filename,
        " lf_file        type string,
 " LF_FILELENGTH TYPE I,
       lt_datatab    TYPE STANDARD TABLE OF ty_xline,
       lt_datatab1    TYPE STANDARD TABLE OF ty_xline,
       it_errorlog   TYPE STANDARD TABLE OF ty_errorlog,
       ls_errorlog   TYPE ty_errorlog,
       ls_datatab  TYPE ty_xline,
       ls_datatab1  TYPE ty_xline,
       req_datatab  TYPE ty_xline.

DATA: l_lines TYPE  i,
      l_lines1 TYPE  i,
      w_lines TYPE i,
      l_dokar TYPE dokar,
      w_header_txt(70) TYPE c.

DATA: ls_tdwa TYPE tdwa,
      ls_tdwo TYPE tdwo,
      ls_klah TYPE klah,
      lt_ksml TYPE STANDARD TABLE OF ksml,
      lt_tdwo TYPE STANDARD TABLE OF tdwo,
     "LS_KSML TYPE KSML,
      lt_cabn TYPE STANDARD TABLE OF cabn.

DATA: it_raw       TYPE truxs_t_text_data.
DATA: tt_return TYPE ddshretval OCCURS 0 WITH HEADER LINE.
DATA: gt_upld    TYPE STANDARD TABLE OF ty_xline INITIAL SIZE 0 ,
      gt_error   TYPE STANDARD TABLE OF ty_xline INITIAL SIZE 0 .

DATA : w_mara TYPE matnr,
       w_equi TYPE equnr.

DATA: gwa_upld    TYPE ty_xline,
      gwa_data    TYPE ty_xline,
      gwa_file    TYPE alsmex_tabline.

DATA: value(15) TYPE c,
      num(2)    TYPE c,
      w_tplnr TYPE tplnr.

DATA : w_vendorno  TYPE  bapivendor_01-vendor_no,
       w_cust  TYPE      bapicustomer_id-customer.

INITIALIZATION.
  REFRESH: lt_dokar.
  SELECT  dokar FROM tdwa INTO TABLE lt_dokar.
  SORT lt_dokar BY dokar.
************************************************************************
* Selection screen
************************************************************************
  SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-005.
  PARAMETERS: doctyp  TYPE dokar OBLIGATORY,
              file    TYPE localfile OBLIGATORY.
  SELECTION-SCREEN END OF BLOCK b1.

************************************************************************
* Events
************************************************************************
AT SELECTION-SCREEN.
  PERFORM main.
*  READ TABLE lt_dokar INTO l_dokar WITH KEY dokar = doctyp BINARY SEARCH.
*
*  SELECT SINGLE dokar FROM tdwa INTO l_dokar WHERE dokar = doctyp.
*  IF sy-subrc NE 0.
*    MESSAGE e001(zdms) WITH doctyp .
*  ENDIF.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR file.
  PERFORM file_f4.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR doctyp.
  PERFORM get_doctyp.

START-OF-SELECTION.

  PERFORM get_characteristics.
  PERFORM get_objects.
  PERFORM readdata.
  PERFORM build_fieldcatalog.
  PERFORM build_layout.
  PERFORM display_alv_report.

*&---------------------------------------------------------------------*
*&      Form  FILE_F4
*&---------------------------------------------------------------------*
FORM file_f4 .
  DATA:
     lt_filetable TYPE filetable,
     lf_rc        TYPE i.
  REFRESH: lt_filetable.
  CLEAR: lf_rc.
  CALL METHOD cl_gui_frontend_services=>file_open_dialog
    EXPORTING
      multiselection          = abap_false
    CHANGING
      file_table              = lt_filetable
      rc                      = lf_rc
    EXCEPTIONS
      file_open_dialog_failed = 1
      cntl_error              = 2
      error_no_gui            = 3
      not_supported_by_gui    = 4
      OTHERS                  = 5.

  IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE 'S' NUMBER sy-msgno
               DISPLAY LIKE 'E'
               WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
    EXIT.
  ENDIF.

* Number of selected filed must be equal to one.
  CHECK lf_rc = 1.

* Access selected file
  DATA:
    ls_file TYPE file_table.

  READ TABLE lt_filetable INTO ls_file INDEX 1.
  CHECK sy-subrc = 0.

  file = ls_file-filename.

ENDFORM.                                                    " FILE_F4
*&---------------------------------------------------------------------*
*&      Form  MAIN
*&---------------------------------------------------------------------*
FORM main .
  IF file IS INITIAL.
    MESSAGE s058(vscan) DISPLAY LIKE 'E'.
    EXIT.
  ENDIF.
  lf_file = file.
  DATA: lv_date(10)   TYPE c,
         w_truxs TYPE truxs_t_text_data.

  CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'
    EXPORTING
*   I_FIELD_SEPERATOR          =
*   I_LINE_HEADER              =
      i_tab_raw_data             =   w_truxs
      i_filename                 =   lf_file
    TABLES
      i_tab_converted_data       =  lt_datatab
    EXCEPTIONS
      CONVERSION_FAILED          = 1
      OTHERS                     = 2
            .

  MOVE lt_datatab TO lt_datatab1.

ENDFORM.                    " MAIN
*&---------------------------------------------------------------------*
*&      Form  GET_CHARACTERISTICS
*&---------------------------------------------------------------------*
FORM get_characteristics .
  CLEAR: ls_tdwa, ls_klah, l_lines.

  REFRESH:lt_ksml.
  SELECT SINGLE * FROM tdwa INTO ls_tdwa WHERE dokar = doctyp.

  SELECT SINGLE * FROM klah INTO ls_klah WHERE class = ls_tdwa-klasse
                                           AND klart = '017'.

  SELECT * FROM ksml INTO TABLE lt_ksml WHERE clint = ls_klah-clint.

  IF NOT lt_ksml IS INITIAL.
    DESCRIBE TABLE lt_ksml LINES l_lines.

    SELECT * FROM cabn INTO TABLE lt_cabn FOR ALL ENTRIES IN
      lt_ksml WHERE atinn = lt_ksml-imerk .
  ENDIF.

ENDFORM.                    " GET_CHARACTERISTICS
*&---------------------------------------------------------------------*
*&      Form  BUILD_FIELDCATALOG
*&---------------------------------------------------------------------*
FORM build_fieldcatalog .

  fieldcatalog-fieldname   = 'INDEX'.
  fieldcatalog-seltext_m   = 'Index Number'(008).
  fieldcatalog-col_pos     = 0.
  fieldcatalog-outputlen   = 25.
  fieldcatalog-emphasize   = 'X'.
  fieldcatalog-key         = 'X'.
*  fieldcatalog-do_sum      = 'X'.
*  fieldcatalog-no_zero     = 'X'.
  APPEND fieldcatalog TO fieldcatalog.
  CLEAR  fieldcatalog.

  fieldcatalog-fieldname   = 'DOCNUMBER'.
  fieldcatalog-seltext_m   = 'Document Number'(002).
  fieldcatalog-col_pos     = 0.
  fieldcatalog-outputlen   = 25.
  fieldcatalog-emphasize   = 'X'.
  fieldcatalog-key         = 'X'.
*  fieldcatalog-do_sum      = 'X'.
*  fieldcatalog-no_zero     = 'X'.
  APPEND fieldcatalog TO fieldcatalog.
  CLEAR  fieldcatalog.

  fieldcatalog-fieldname   = 'MESSAGE'.
  fieldcatalog-seltext_m   = 'Message'(003).
  fieldcatalog-outputlen   = 100.
  fieldcatalog-col_pos     = 1.
  APPEND fieldcatalog TO fieldcatalog.
  CLEAR  fieldcatalog.

ENDFORM.                    " BUILD_FIELDCATALOG
*&---------------------------------------------------------------------*
*&      Form  BUILD_LAYOUT
*&---------------------------------------------------------------------*
FORM build_layout .
  gd_layout-no_input          = 'X'.
  gd_layout-colwidth_optimize = 'X'.
  gd_layout-zebra             = 'X'.
  w_header_txt = 'Records Processed From File'(004).
  CONDENSE w_header_txt.
  gd_layout-window_titlebar       =  w_header_txt.

ENDFORM.                    " BUILD_LAYOUT
*&---------------------------------------------------------------------*
*&      Form  DISPLAY_ALV_REPORT
*&---------------------------------------------------------------------*
FORM display_alv_report .
  gd_repid = sy-repid.
  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
      i_callback_program      = gd_repid
      is_layout               = gd_layout
      it_fieldcat             = fieldcatalog[]
      i_callback_user_command = 'USER_COMMAND'
      i_save                  = 'X'
    TABLES
      t_outtab                = it_out
    EXCEPTIONS
      program_error           = 1
      OTHERS                  = 2.

ENDFORM.                    " DISPLAY_ALV_REPORT
*&---------------------------------------------------------------------*
*&      Form  user_command
*&---------------------------------------------------------------------*
FORM user_command USING r_ucomm LIKE sy-ucomm
                  rs_selfield TYPE slis_selfield.

* Check function code
  CASE r_ucomm.
    WHEN '&IC1'.
*   Check field clicked on within ALVgrid report
      IF rs_selfield-fieldname = 'DOCNUMBER'.

        CLEAR wa_out.
        READ TABLE it_out INTO wa_out INDEX rs_selfield-tabindex.
        SET PARAMETER ID 'CV1' FIELD wa_out-docnumber.
        SET PARAMETER ID 'CV2' FIELD ls_datatab-doc_type.
        SET PARAMETER ID 'CV4' FIELD '000'.
        SET PARAMETER ID 'CV3' FIELD '00'.
*     Sxecute transaction ME23N, and skip initial data entry screen
        CALL TRANSACTION 'CV03N' AND SKIP FIRST SCREEN.
      ENDIF.
  ENDCASE.
ENDFORM.                    "user_command
*&---------------------------------------------------------------------*
*&      Form  GET_DOCTYP
*&---------------------------------------------------------------------*
FORM get_doctyp .
  CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
    EXPORTING
      retfield        = 'DOKAR'
      dynpprog        = sy-repid
      dynpnr          = sy-dynnr
      value_org       = 'S'
    TABLES
      value_tab       = lt_dokar
      return_tab      = tt_return
    EXCEPTIONS
      parameter_error = 1
      no_values_found = 2
      OTHERS          = 3.
  IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
            WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ELSE.
    READ TABLE tt_return INDEX 1.
    MOVE tt_return-fieldval TO doctyp.
  ENDIF.
ENDFORM.                    " GET_DOCTYP
*&---------------------------------------------------------------------*
*&      Form  GET_OBJECTS
*&---------------------------------------------------------------------*
FORM get_objects.
  CLEAR: ls_tdwo, ls_klah, l_lines1.
  REFRESH:lt_tdwo.

  SELECT *
     FROM tdwo INTO TABLE lt_tdwo WHERE dokar = doctyp.

  IF NOT lt_tdwo IS INITIAL.
    DESCRIBE TABLE lt_tdwo LINES l_lines1.
  ENDIF.

ENDFORM.                    " GET_OBJECTS
*&---------------------------------------------------------------------*
*&      Form  READDATA
*&---------------------------------------------------------------------*
FORM readdata .
****Populate Bapi Tables
  CLEAR:     ls_documentdata,
             ls_drad,
             ls_return,
             lv_documenttype,
             lv_documentnumber,
             lv_documentpart,
             lv_documentversion.

  REFRESH: lt_documentdescriptions,
           lt_drad,
           lt_characteristicvalues,
           lt_documentfiles,
           bt_return,
           it_out.

  CLEAR: req_datatab.
  READ TABLE lt_datatab INTO req_datatab INDEX 1.
  IF sy-subrc = 0.
    DELETE lt_datatab INDEX 1.
  ENDIF.
  CLEAR: req_datatab.
  READ TABLE lt_datatab1  INTO req_datatab INDEX 1.
  IF sy-subrc = 0.
    DELETE lt_datatab1 INDEX 1.
  ENDIF.
  DESCRIBE TABLE lt_datatab LINES w_lines.
  DESCRIBE TABLE lt_datatab1 LINES w_lines.

  LOOP AT lt_datatab INTO ls_datatab.
    ON CHANGE OF ls_datatab-ind.
      REFRESH: lt_characteristicvalues.
      REFRESH lt_drad.
      REFRESH: lt_documentdescriptions.
      REFRESH lt_documentfiles.

      LOOP AT lt_datatab1 INTO ls_datatab1
       WHERE ind = ls_datatab-ind.
        w_index =   ls_datatab1-ind ."sy-tabix.
* HEADER STRUCTURE
        ls_documentdata-documenttype    = ls_datatab1-doc_type.
        ls_documentdata-documentnumber  = '*'.
        ls_documentdata-documentversion  = '00'.
        ls_documentdata-documentpart    = '000'.
        ls_documentdata-description      = ls_datatab1-desc.
        " LS_DOCUMENTDATA-STATUSEXTERN    = 'IA'.
        ls_documentdata-laboratory     = ls_datatab1-labor.
* Characteristics Table
        "  REFRESH: lt_characteristicvalues.
        CLEAR:  ls_characteristicvalues, value.
        " REFRESH lt_drad.
        CLEAR ls_drad.
        FIELD-SYMBOLS: <fs> TYPE any,
                       <req_fs> TYPE any.
        CLEAR: num.
        DO l_lines TIMES.
          num = num + 1.
          CONDENSE num.
          CONCATENATE 'VALUE' num INTO value.
          ASSIGN COMPONENT value  OF STRUCTURE ls_datatab1 TO <fs>.
          ASSIGN COMPONENT value  OF STRUCTURE req_datatab TO <req_fs>.
          ls_characteristicvalues-classtype  = '017'.
          ls_characteristicvalues-classname  = ls_tdwa-klasse.
          ls_characteristicvalues-charname  = <req_fs>.
          ls_characteristicvalues-charvalue  = <fs>.
          UNASSIGN <fs>.
          UNASSIGN <req_fs>.
          APPEND ls_characteristicvalues TO lt_characteristicvalues.
          CLEAR  ls_characteristicvalues.
        ENDDO.

        DO l_lines1 TIMES.
          num = num + 1.
          CONDENSE num.
          CONCATENATE 'VALUE' num INTO value.
          ASSIGN COMPONENT value  OF STRUCTURE ls_datatab1 TO <fs>.
          ASSIGN COMPONENT value  OF STRUCTURE req_datatab TO <req_fs>.
          ls_drad-objecttype = <req_fs>.
          IF <req_fs> = 'IFLOT' .
            SELECT tplnr FROM iflos INTO w_tplnr  WHERE strno = <fs>.
            ENDSELECT.
            ls_drad-objectkey  = w_tplnr.

          ELSEIF <req_fs> = 'EQUI'.
            ls_drad-objectkey  = <fs>.
            "            ls_drad-OBJECTDESCRIPTION =  'abc'.
            w_equi = <fs>.
            CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
              EXPORTING
                input  = w_equi
              IMPORTING
                output = w_equi.
            <fs> = w_equi.

            ls_drad-objectkey  = <fs>.
          ELSEIF <req_fs> = 'MARA'.
            ls_drad-objectkey  = <fs>.
            "            ls_drad-OBJECTDESCRIPTION =  'abc'.
            w_mara = <fs>.
            CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
              EXPORTING
                input  = w_mara
              IMPORTING
                output = w_mara.
            <fs> = w_mara.
            ls_drad-objectkey  = <fs>.

          ELSEIF <req_fs> = 'KNA1'.
            ls_drad-objectkey  = <fs>.
            "            ls_drad-OBJECTDESCRIPTION =  'abc'.
            w_cust = <fs>.
            CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
              EXPORTING
                input  = w_cust
              IMPORTING
                output = w_cust.
            <fs> = w_cust.
            ls_drad-objectkey  = <fs>.

          ELSEIF <req_fs> = 'LFA1'.
            ls_drad-objectkey  = <fs>.
            w_vendorno = <fs>.
            CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
              EXPORTING
                input  = w_vendorno
              IMPORTING
                output = w_vendorno.
            <fs> = w_vendorno.

            ls_drad-objectkey  = <fs>.
          ELSE .
            ls_drad-objectkey  = <fs>.
          ENDIF.
          UNASSIGN <fs>.
          UNASSIGN <req_fs>.
          IF ls_drad <> ''.
            APPEND ls_drad TO lt_drad.
          ENDIF.
          CLEAR ls_drad.
          CLEAR w_tplnr.
        ENDDO.
* Description Table

        CLEAR: ls_documentdescriptions.
        "  REFRESH: lt_documentdescriptions.
        ls_documentdescriptions-language     = 'EN'.
        ls_documentdescriptions-description   = ls_datatab1-desc.
        APPEND ls_documentdescriptions TO lt_documentdescriptions.
        CLEAR ls_documentdescriptions.

        " REFRESH lt_documentfiles.
        CLEAR ls_documentfiles.
        ls_documentfiles-documenttype       = ls_datatab1-doc_type..
        ls_documentfiles-documentnumber     = '*'.
        ls_documentfiles-documentpart       = '000'.
        ls_documentfiles-documentversion   = '00'.
        ls_documentfiles-sourcedatacarrier = 'PC'.
        ls_documentfiles-storagecategory   = ls_datatab1-storage.
        TRANSLATE ls_datatab1-filetype TO UPPER CASE.
        ls_documentfiles-wsapplication     = ls_datatab1-filetype.

        "    if ls_datatab1-filename <> ''.
        ls_documentfiles-description       = ls_datatab1-filename.
        ls_documentfiles-docfile           = ls_datatab1-filepath.
        ls_documentfiles-checkedin         = 'X'.
        APPEND ls_documentfiles TO lt_documentfiles.
        "     ENDIF.
        REFRESH lt_return.
        CLEAR: lv_documentnumber.
        "  CLEAR : ls_datatab1.

      ENDLOOP.
      DELETE  lt_documentfiles WHERE  docfile  = ''.
* CALL BAPI TO UPDATE DATA

      CALL FUNCTION 'BAPI_DOCUMENT_CREATE2'
        EXPORTING
          documentdata         = ls_documentdata
        IMPORTING
          documenttype         = lv_documenttype
          documentnumber       = lv_documentnumber
          documentpart         = lv_documentpart
          documentversion      = lv_documentversion
          return               = ls_return
        TABLES
          characteristicvalues = lt_characteristicvalues
          documentdescriptions = lt_documentdescriptions
          objectlinks          = lt_drad
          documentfiles        = lt_documentfiles.

      APPEND ls_return TO lt_return.
      CLEAR  ls_return.
*    APPEND ls_return TO bt_return.
      CLEAR lv_msg.
      READ TABLE lt_return INTO ls_return WITH KEY type = 'E'.
      IF sy-subrc = 0.

        CALL FUNCTION 'FORMAT_MESSAGE'
          EXPORTING
            id        = sy-msgid
            lang      = 'EN'
            no        = sy-msgno
            v1        = sy-msgv1
            v2        = sy-msgv2
            v3        = sy-msgv3
            v4        = sy-msgv4
          IMPORTING
            msg       = lv_msg
          EXCEPTIONS
            not_found = 1
            OTHERS    = 2.
        CLEAR: ls_errorlog, lv_documentnumber.
        MOVE-CORRESPONDING ls_datatab TO ls_errorlog.
        tv_msg = lv_msg.
        ls_errorlog-msg = tv_msg.

        CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'
          IMPORTING
            return = ss_return.
      ELSE.
        IF NOT lv_documentnumber IS INITIAL.
          CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT'
            EXPORTING
              input  = lv_documentnumber
            IMPORTING
              output = lv_documentnumber.

          CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
            EXPORTING
              wait = 'X'.
          lv_msg = 'Successfully Generated'(001).
          CLEAR: ls_out.
        ENDIF.
      ENDIF.
      CLEAR: ls_out.
      ls_out-index  =     w_index.
      ls_out-docnumber =  lv_documentnumber.
      ls_out-message   =  lv_msg.
      APPEND ls_out TO it_out.
    ENDON.
  ENDLOOP.
ENDFORM.                    "readdata

If we want DMS image comes in Smartforms,SE78 image Updated Needed,so try to  search many site for DMS(Data Management Systen - CV01N )

 

finally find the solution for this... Enjoy...

This Sample Program Following process done it,

1  Get DMS file Details for Specific Sale order

2 Convert JPG image to BMP image

3 Comver BMP to BDS

4 finally Save to BDS content

 

REPORT   zimage.
TYPE-POOLS: SBDST.
TABLES: STXBITMAPS.
CONSTANTS:
   C_BDS_CLASSNAME TYPE SBDST_CLASSNAME VALUE 'DEVC_STXD_BITMAP',
   C_BDS_CLASSTYPE TYPE SBDST_CLASSTYPE VALUE 'OT',          " others
   C_BDS_MIMETYPE  TYPE BDS_MIMETP      VALUE 'application/octet-stream',
   C_BDS_ORIGINAL  TYPE SBDST_DOC_VAR_TG VALUE 'OR'.
* Globals and globals for dynpro fields
DATA: G_OBJECTTYPE(20)   TYPE C,
       G_NEW_RESOLUTION   LIKE STXBITMAPS-RESOLUTION,
       G_STXBITMAPS       TYPE STXBITMAPS,
       G_STXH             TYPE STXH,
       G_TECHINFO         TYPE RSSCG,
       T_SIZE(40),
       BDS_DESCRIPTION  LIKE BAPISIGNAT-PROP_VALUE.
CONSTANTS:
       C_OBJECTTYPE_BDS      LIKE G_OBJECTTYPE VALUE 'BDS',
       C_OBJECTTYPE_STDTEXT  LIKE G_OBJECTTYPE VALUE 'OBTEXT',
       C_OBJECTTYPE_GRTEXT   LIKE G_OBJECTTYPE VALUE 'OBGRAPHICS'.
DATA: P_FILENAME       TYPE RLGRAP-FILENAME,
                P_OBJECT         TYPE STXBITMAPS-TDOBJECT,
                P_ID             TYPE STXBITMAPS-TDID,
                P_BTYPE          TYPE STXBITMAPS-TDBTYPE,
                P_FORMAT         TYPE C,
                P_TITLE          LIKE BDS_DESCRIPTION,
                P_RESIDENT       TYPE STXBITMAPS-RESIDENT,
                P_AUTOHEIGHT     TYPE STXBITMAPS-AUTOHEIGHT,
                P_BMCOMP         TYPE STXBITMAPS-BMCOMP.
DATA  L_FILE TYPE STRING..
DATA: L_FILENAME        TYPE STRING,
       L_BYTECOUNT       TYPE I,
       L_BDS_BYTECOUNT   TYPE I.
DATA: L_COLOR(1)        TYPE C,
       L_WIDTH_TW        TYPE STXBITMAPS-WIDTHTW,
       L_HEIGHT_TW       TYPE STXBITMAPS-HEIGHTTW,
       L_WIDTH_PIX       TYPE STXBITMAPS-WIDTHPIX,
       L_HEIGHT_PIX      TYPE STXBITMAPS-HEIGHTPIX.
DATA: L_BDS_OBJECT      TYPE REF TO CL_BDS_DOCUMENT_SET,
       L_BDS_CONTENT     TYPE SBDST_CONTENT,
       L_BDS_COMPONENTS  TYPE SBDST_COMPONENTS,
       WA_BDS_COMPONENTS TYPE LINE OF SBDST_COMPONENTS,
       L_BDS_SIGNATURE   TYPE SBDST_SIGNATURE,
       WA_BDS_SIGNATURE  TYPE LINE OF SBDST_SIGNATURE,
       L_BDS_PROPERTIES  TYPE SBDST_PROPERTIES,
       WA_BDS_PROPERTIES TYPE LINE OF SBDST_PROPERTIES.
DATA  WA_STXBITMAPS TYPE STXBITMAPS.
DATA: P_NAMEX    TYPE STXBITMAPS-TDNAME.

   DATA: FILELENGTH  TYPE  I.
   DATA: BEGIN OF L_BITMAP OCCURS 0,
           L(64) TYPE X,
         END OF L_BITMAP.
  TABLES: vbup,vbap,vbak,KNA1.
  DATA: l_igs_imgconv TYPE REF TO cl_igs_image_converter,
          l_img_blob    TYPE w3mimetabtype,
          l_img_size    TYPE w3param-cont_len,
          l_bmp_xstream TYPE xstring.
DATA:T_QTY TYPE C LENGTH 15,
html_control TYPE REF TO cl_gui_html_viewer,
my_container TYPE REF TO cl_gui_custom_container,
BEGIN OF objectkey,
objkey TYPE c LENGTH 16,
KDMAT TYPE VBAP-KDMAT,
  KWMENG TYPE VBAP-KWMENG,
  AUGRU TYPE  vbak-augru,
  END OF objectkey,
objtab LIKE TABLE OF objectkey WITH HEADER LINE,
   mes TYPE c LENGTH 255,

BEGIN OF imagedetail,
   "ocn TYPE c LENGTH 10,
   dokar type drad-dokar,
   doknr type drad-doknr,
   dokvr type drad-dokvr,
   DOKTL type drad-DOKTL,
   augru TYPE vbaK-augru,
   KWMENG TYPE VBAP-KWMENG,
   KDMAT TYPE vbap-KDMAT,
   objky TYPE drad-objky,
   prop01 TYPE dms_lo_cd1-prop01,
   phio_id TYPE dms_ph_cd1-phio_id,
   filename TYPE dms_phio2file-filename,
   lo_objid TYPE dms_doc2loio-lo_objid,
   END OF imagedetail,


tabimg LIKE TABLE OF imagedetail WITH HEADER LINE,
tabimg2 LIKE TABLE OF imagedetail WITH HEADER LINE,

  DOCUMENTTYPE  LIKE  BAPI_DOC_AUX-DOCTYPE,
DOCUMENTNUMBER LIKE  BAPI_DOC_AUX-DOCNUMBER,
DOCUMENTPART LIKE  BAPI_DOC_AUX-DOCPART,
DOCUMENTVERSION LIKE  BAPI_DOC_AUX-DOCVERSION,
BEGIN OF wa_vbak,
   objkey TYPE c LENGTH 16,
KDMAT TYPE VBAP-KDMAT,
   augru TYPE vbaK-augru,
   bstdk TYPE vbak-bstdk,
   bsark TYPE vbak-bsark,
   vdatu TYPE vbak-vdatu,
   name1 TYPE kna1-name1,
   butxt TYPE t001-butxt,
   vbeln TYPE vbak-vbeln,
   posnr TYPE vbap-posnr,
    FKREL TYPE vbap-FKREL,
    PSTYV TYPE vbap-PSTYV,
     MEINS TYPE VBAP-MEINS,
   KWMENG TYPE VBAP-KWMENG,
UMREN TYPE marm-UMREN,
   netpr type netpr,
   END OF wa_vbak,
   t_vbak LIKE TABLE OF wa_vbak WITH HEADER LINE,

   oref TYPE REF TO cl_dd_document,
   html TYPE w3htmltab,
   html2 TYPE w3htmltab,
   url TYPE c LENGTH 255,
   url2 TYPE c LENGTH 255,
   t_vbup TYPE TABLE OF vbup,
   i TYPE i ,"LENGTH 5,
   i2 type i." LENGTH 5.
data : tx_data  TYPE DMS_TBL_FILE ,
       Ptx_data1 TYPE DMS_REC_FILE.
FIELD-SYMBOLS: <fs> TYPE DMS_REC_PHIO.
DATA: data     TYPE STRING,
       C2       TYPE STRING,
       one      TYPE STRING,
       two      TYPE STRING,
       three    TYPE STRING,
       SIZE TYPE i,
       mimetype TYPE C,
       four(20) TYPE C.
DATA:prev TYPE drad-objky,
     next TYPE drad-objky.
"PARAMETERS ocn LIKE vbup-vbeln.
data  i_data type N LENGTH 5.
data  i_data2 type N LENGTH 5.
DATA: ptx_data  TYPE DMS_TBL_FILE .
DATA: binary_flg  type  sdok_binfl,
       data_txt    like  sdokcntasc occurs 1,
       data_bin    like  sdokcntbin occurs 1.
TYPES: zcx_root type ref to cx_root.

SELECTION-SCREEN: BEGIN OF BLOCK a WITH FRAME TITLE text-001 .


PARAMETERS: io TYpe vbup-vbeln.

SELECTION-SCREEN: END OF BLOCK a.

START-OF-SELECTION.

*  SELECT * FROM vbup WHERE vbeln IN ocn.
*    CONCATENATE vbup-vbeln vbup-posnr INTO objectkey-objkey.
*    APPEND objectkey TO objtab.
   SELECT * FROM vbak AS a
     INNER JOIN kna1 AS b ON ( a~kunnr = b~kunnr )
     INNER JOIN vbap AS c ON ( a~vbeln = c~vbeln )
     inner JOIN marm as d on ( c~matnr = d~matnr )
     INTO CORRESPONDING FIELDS OF TABLE t_vbak WHERE a~vbeln = io
   AND D~MEINH in ('PC','ST').
     .
   SORT t_vbak BY vbeln.
   LOOP AT t_vbak INTO wa_vbak.
     "ON CHANGE OF wa_vbak-KDMAT.
     CONCATENATE wa_vbak-vbeln wa_vbak-posnr INTO objectkey-objkey.
     APPEND objectkey TO objtab.
     "ENDON.
   ENDLOOP.
   LOOP AT objtab.

     SELECT * FROM drad  AS a
       INNER JOIN dms_doc2loio AS b ON ( a~doknr = b~doknr )
       INNER JOIN dms_ph_cd1 AS c ON ( c~loio_id = b~lo_objid )
       INNER JOIN dms_phio2file AS d ON ( c~prop08 = d~file_id )
       INNER JOIN dms_lo_cd1 AS e ON ( c~loio_id = e~loio_id )
       INTO CORRESPONDING FIELDS OF TABLE tabimg
       WHERE a~objky = objtab-objkey AND e~prop01 = 'JPG' .
     APPEND LINES OF tabimg TO tabimg2.
   ENDLOOP.
   PERFORM main.
            " STATUS_0100  OUTPUT

    Write: 'Check Se78 Yourself'.
*&---------------------------------------------------------------------*
*&      Form  MAIN
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM main.



LOOP AT tabimg2.

  data: ls_return type BAPIRET2.
data: lt_files2 type table of BAPI_DOC_FILES2.
data: ls_files2 type BAPI_DOC_FILES2.
data: lt_inf type table of  SCMS_ACINF.
data: ls_inf type SCMS_ACINF.
data: lt_bin type TABLE OF SDOKCNTBIN.
data: contentx type XSTRING.


  DATA: l_igs_imgconv TYPE REF TO cl_igs_image_converter,
         l_img_blob    TYPE w3mimetabtype,
         l_img_size    TYPE w3param-cont_len,
         l_bmp_xstream TYPE xstring.
   CREATE OBJECT l_igs_imgconv.


documenttype = tabimg2-dokar.
documentnumber = tabimg2-doknr.
documentpart = tabimg2-doktl.
documentversion = tabimg2-dokvr.


   CALL FUNCTION 'BAPI_DOCUMENT_GETDETAIL2'
     EXPORTING
       documenttype    = documenttype
       documentnumber  = documentnumber
       documentpart    = documentpart
       documentversion = documentversion
       getdocfiles     = 'X'
     IMPORTING
       return          = ls_return
     TABLES
       documentfiles   = lt_files2.
   IF LINES( lt_files2 ) > 1.
*   Error 'MULTIPLE_FILES'.
   ENDIF.
   READ TABLE lt_files2 INTO ls_files2 INDEX 1.
   IF sy-subrc NE 0.
*    Error 'NO_FILES'.
   ENDIF.
*
   CALL FUNCTION 'SCMS_DOC_READ'
     EXPORTING
       stor_cat    = 'ZDMS'
       doc_id      = ls_files2-file_id
     TABLES
       access_info = lt_inf
       content_bin = lt_bin.
   READ TABLE lt_inf INTO ls_inf INDEX 1.
   IF sy-subrc NE 0.
*   Error = 'NO_FILE_INFO'.
   ENDIF.
*
   " Convert XData to Xstring
   CALL FUNCTION 'SCMS_BINARY_TO_XSTRING'
     EXPORTING
       input_length = ls_inf-comp_size
     IMPORTING
       buffer       = contentx
     TABLES
       binary_tab   = lt_bin
     EXCEPTIONS
       failed       = 1
       OTHERS       = 2.
   IF sy-subrc NE 0.
*    RAISE EXCEPTION TYPE zcx_root
*    EXPORTING textid = 'BINARY_CONVERSION_ERROR'.
   ENDIF.

   l_img_size = XSTRLEN( contentx ).
   CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
     EXPORTING
       buffer     = contentx
     TABLES
       binary_tab = l_img_blob.
   CALL METHOD l_igs_imgconv->set_image
     EXPORTING
       blob      = l_img_blob
       blob_size = l_img_size.

DATA l_format TYPE string.
   l_format = 'JPG'.
   CASE l_format.
     WHEN 'TIF'.
       l_igs_imgconv->input  = 'image/tiff'.
     WHEN 'JPG'.
       l_igs_imgconv->input  = 'image/jpeg'.
     WHEN 'PNG'.
       l_igs_imgconv->input  = 'image/png'.
     WHEN 'GIF'.
       l_igs_imgconv->input  = 'image/gif'.
     WHEN OTHERS.
*      Error
   ENDCASE.

   l_igs_imgconv->output = 'image/x-ms-bmp'.
   CALL METHOD l_igs_imgconv->execute
     EXCEPTIONS
       OTHERS = 1.

   IF sy-subrc IS INITIAL.
     CALL METHOD l_igs_imgconv->get_image
       IMPORTING
         blob      = l_img_blob
         blob_size = l_img_size.


   ENDIF.

  DATA: P_DOCID          TYPE STXBITMAPS-DOCID.
   DATA: P_RESOLUTION  LIKE  STXBITMAPS-RESOLUTION.
   DATA: L_OBJECT_KEY TYPE SBDST_OBJECT_KEY.
   CALL FUNCTION 'SAPSCRIPT_CONVERT_BITMAP_BDS'
     EXPORTING
       COLOR                    = 'X'
       FORMAT                   = 'BMP'
       RESIDENT                 = P_RESIDENT
       BITMAP_BYTECOUNT         l_bytecount
      COMPRESS_BITMAP          = 'X'
     IMPORTING
       WIDTH_TW                 = L_WIDTH_TW
       HEIGHT_TW                = L_HEIGHT_TW
       WIDTH_PIX                = L_WIDTH_PIX
       HEIGHT_PIX               = L_HEIGHT_PIX
       DPI                      = P_RESOLUTION
       BDS_BYTECOUNT            = L_BDS_BYTECOUNT
     TABLES
       BITMAP_FILE              = l_img_blob
       BITMAP_FILE_BDS          = L_BDS_CONTENT
     EXCEPTIONS
       FORMAT_NOT_SUPPORTED     = 1
       NO_BMP_FILE              = 2
       BMPERR_INVALID_FORMAT    = 3
       BMPERR_NO_COLORTABLE     = 4
       BMPERR_UNSUP_COMPRESSION = 5
       BMPERR_CORRUPT_RLE_DATA  = 6
       OTHERS                   = 7.
   IF SY-SUBRC <> 0.
*???
   ENDIF.



   CREATE OBJECT L_BDS_OBJECT.
   WA_BDS_COMPONENTS-DOC_COUNT  = '1'.
   WA_BDS_COMPONENTS-COMP_COUNT = '1'.
   WA_BDS_COMPONENTS-MIMETYPE   = C_BDS_MIMETYPE."application/octet-stream
   WA_BDS_COMPONENTS-COMP_SIZE  = L_BDS_BYTECOUNT.
   APPEND WA_BDS_COMPONENTS TO L_BDS_COMPONENTS.
   WA_BDS_SIGNATURE-DOC_COUNT = '1'.
   APPEND WA_BDS_SIGNATURE TO L_BDS_SIGNATURE.
   L_OBJECT_KEY = P_NAMEX.
   CALL METHOD L_BDS_OBJECT->CREATE_WITH_TABLE
     EXPORTING
       CLASSNAME  = C_BDS_CLASSNAME "DEVC_STXD_BITMAP
       CLASSTYPE  = C_BDS_CLASSTYPE "OT
       COMPONENTS = L_BDS_COMPONENTS
       CONTENT    = L_BDS_CONTENT
     CHANGING
       SIGNATURE  = L_BDS_SIGNATURE
       OBJECT_KEY = L_OBJECT_KEY
     EXCEPTIONS
       OTHERS     = 1.
   IF SY-SUBRC = 0.
     READ TABLE L_BDS_SIGNATURE INDEX 1 INTO WA_BDS_SIGNATURE
     TRANSPORTING DOC_ID.
     IF SY-SUBRC = 0.
       P_DOCID = WA_BDS_SIGNATURE-DOC_ID.
       WA_STXBITMAPS-TDNAME     = 'TEST'.
       WA_STXBITMAPS-TDOBJECT   = 'GRAPHICS'.
       WA_STXBITMAPS-TDID       = 'BMAP'.
       WA_STXBITMAPS-TDBTYPE    = 'BCOL'.
       WA_STXBITMAPS-DOCID      = P_DOCID.
       WA_STXBITMAPS-WIDTHPIX   = L_WIDTH_PIX.
       WA_STXBITMAPS-HEIGHTPIX  = L_HEIGHT_PIX.
       WA_STXBITMAPS-WIDTHTW    = L_WIDTH_TW.
       WA_STXBITMAPS-HEIGHTTW   = L_HEIGHT_TW.
       WA_STXBITMAPS-RESOLUTION = P_RESOLUTION.
       WA_STXBITMAPS-RESIDENT   = P_RESIDENT.
       WA_STXBITMAPS-AUTOHEIGHT = P_AUTOHEIGHT.
       WA_STXBITMAPS-BMCOMP     = P_BMCOMP.
       INSERT INTO STXBITMAPS VALUES WA_STXBITMAPS.
     ENDIF.
   ENDIF.
ENDLOOP.
ENDFORM.                    "MAIN

Sending Mails - Home Page

         The input to this program is : Document number (DOKNR ) Document type (DOKAR) and Documentversion (DOKVR) and Documentpart(DOKTL).

Error rendering macro 'code': Invalid value specified for parameter 'com.atlassian.confluence.ext.code.render.InvalidValueException'
DATA  : BEGIN OF drawkey,
     dokar LIKE draw-dokar,
     doknr LIKE draw-doknr,
     dokvr LIKE draw-dokvr,
     doktl LIKE draw-doktl,
   END OF drawkey.
DATA : v_object_key(33) TYPE c.

DATA : comps TYPE STANDARD TABLE OF scms_doinf,
       wa_comps TYPE scms_doinf.

DATA : v_file_name TYPE scms_doinf-file_name.

DATA : v_docfile TYPE bapi_doc_files2-docfile.
DATA : v_zdm_file TYPE c.
DATA : v_extension(3) TYPE c.
DATA : v_filepath(255) TYPE c.
DATA : v_uname TYPE sy-uname.
DATA : v_objdes(50) TYPE c.

*-------------------------------------------------------------------------------------------
***************************************************************************************


DATA: send_request       TYPE REF TO cl_bcs.
DATA: text               TYPE bcsy_text.
DATA: binary_content     TYPE solix_tab.
DATA: document           TYPE REF TO cl_document_bcs.
DATA: sender             TYPE REF TO cl_sapuser_bcs.
DATA: recipient          TYPE REF TO if_recipient_bcs.
DATA: bcs_exception      TYPE REF TO cx_bcs.
DATA: sent_to_all        TYPE os_boolean.
DATA: path               TYPE string.
DATA: filelength         TYPE i.
DATA: i_text             TYPE soli_tab.
DATA: wa_emailbody       TYPE soli.
DATA: it_emailbody       TYPE  soli_tab.
DATA: it_text            TYPE TABLE OF soli_tab.
DATA: v_dktxt            TYPE drat-dktxt.
DATA: v_dokst            TYPE draw-dokst,
      v_zdm_doc_owner_id TYPE draw-zdm_doc_owner_id,
      v_authgroup TYPE draw-begru.
DATA : wa_text           TYPE soli.
DATA : v_ext(3)          TYPE c.
DATA : v_filename        TYPE draw-filep.
DATA : v_extension_type  TYPE soodk-objtp.
DATA : v_attachname      TYPE sood-objdes.
DATA : v_mail            TYPE adr6-smtp_addr.
DATA : it_lo_objid TYPE TABLE OF sdok_loid,
       wa_lo_objid TYPE sdok_loid.

DATA : v_phio_id TYPE sdok_phid,
       v_ph_class TYPE sdok_phcl.
DATA : it_object_id TYPE sdokobject,
       wa_object_id TYPE  sdokobject.
DATA : it_file_content_binary TYPE STANDARD TABLE OF sdokcntbin,
       wa_file_content_binary TYPE sdokcntbin.

DATA: objcont TYPE TABLE OF soli.
DATA: it_context TYPE STANDARD TABLE OF sdokpropty.

DATA: it_content_binary TYPE solix_tab,
      it_content_binary_solix TYPE solix,
      wa_content_binary TYPE solix.

DATA: count TYPE i,
      data_string TYPE xstring.

DATA : v_counter TYPE sy-tabix.

DATA : v_dappl TYPE dappl.

TRY.
*     ------- create persistent send request -----------------------
    send_request = cl_bcs=>create_persistent( ).

*     ------- create and set document with attachment --------------
*     create document from internal table with text

   concatenate 'ATTN:this is ' documentnumber into v_objdes separated by space.
    APPEND  v_objdes TO text.
    document = cl_document_bcs=>create_document(
                    i_type    = 'RAW'
                    i_text    = i_text
                    i_subject = v_objdes ).
*     add attachment to document
*     BCS expects document content here e.g. from document upload
*     binary_content = ...

* create the attachment for the mail :

    SELECT  lo_objid
             INTO TABLE it_lo_objid
             FROM dms_doc2loio
            WHERE dokar = documenttype
              AND  doknr = documentnumber
              AND dokvr  = documentversion
              AND doktl = '000'.

    v_counter = 1.

    LOOP AT it_lo_objid INTO wa_lo_objid.
      SELECT SINGLE phio_id
                    ph_class
             INTO   (wa_object_id-objid ,wa_object_id-class)
             FROM    dms_ph_cd1
             WHERE   loio_id = wa_lo_objid.

      CALL FUNCTION 'SDOK_PHIO_LOAD_CONTENT'
       EXPORTING
         object_id                 = wa_object_id
        client                    = sy-mandt
*       AS_IS_MODE                =
*       RAW_MODE                  =
*       TEXT_AS_STREAM            =
      TABLES
*       FILE_ACCESS_INFO          =
*       FILE_CONTENT_ASCII        =
        file_content_binary       =   it_file_content_binary
      EXCEPTIONS
        not_existing              = 1
        not_authorized            = 2
        no_content                = 3
        bad_storage_type          = 4
        OTHERS                    = 5
               .
      IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.

      DESCRIBE TABLE it_file_content_binary LINES count.

      count = count * 1022.

      CALL FUNCTION 'SCMS_BINARY_TO_XSTRING'
        EXPORTING
          input_length       = count
*   FIRST_LINE         = 0
*   LAST_LINE          = 0
       IMPORTING
         buffer             = data_string
        TABLES
          binary_tab         = it_file_content_binary[]
       EXCEPTIONS
         failed             = 1
         OTHERS             = 2
                .
      IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.

      CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
        EXPORTING
          buffer                = data_string
*   APPEND_TO_TABLE       = ' '
* IMPORTING
*   OUTPUT_LENGTH         =
        TABLES
          binary_tab            = it_content_binary[]
                .
*

* get the extension and the names of the files ********************

      SELECT SINGLE dappl
                    filename
        INTO (v_dappl, v_filename )

        FROM dms_doc_files
        WHERE dokar = documenttype
         AND  doknr = documentnumber
         AND dokvr = documentversion
         AND file_idx = v_counter.

      v_extension_type = v_dappl.

      v_attachname  = v_filename.

      CLEAR v_filename.
*-----------------------------------------------------------------------------
*---------------------------------------------------------------------------

      CALL METHOD document->add_attachment
        EXPORTING
          i_attachment_type    = v_extension_type
          i_attachment_subject = v_attachname
          i_att_content_hex    = it_content_binary.

*     add document to send request
      CALL METHOD send_request->set_document( document ).

      v_counter = v_counter + 1.
    ENDLOOP.

    CLEAR v_counter.
*     -------- set sender ------------------------------------------
*     note: this is necessary only if you want to set the sender
*           different from actual user (SY-UNAME). Otherwise sender is
*           set automatically with actual user.

    sender = cl_sapuser_bcs=>create( sy-uname ).
    CALL METHOD send_request->set_sender
      EXPORTING
        i_sender = sender.

*     -------- add recipient (e-mail address) ----------------------
*     create recipient - please replace e-mail address !!!

    recipient = cl_cam_address_bcs=>create_internet_address(
                                           'papiya@gmail.com' ).
*     add recipient with its respective attributes to send request
    CALL METHOD send_request->add_recipient
      EXPORTING
        i_recipient = recipient
        i_express   = 'X'.
    CLEAR v_mail.
  ENDLOOP.
*     --------- send document --------------------------------------
  CALL METHOD send_request->send(
    EXPORTING
      i_with_error_screen = 'X'
    RECEIVING
      result              = sent_to_all ).
  IF sent_to_all = 'X'.
    WRITE text-003.
  ENDIF.

  COMMIT WORK.

* -----------------------------------------------------------
* *                     exception handling
* -----------------------------------------------------------
* -----------------------------------------------------------
CATCH cx_bcs INTO bcs_exception.
  WRITE: 'This is error.'(001).
  WRITE: 'Error'(002), bcs_exception->error_type.
  EXIT.

ENDTRY.

Author: karthikeyan sukumar 

Submitted: Dec. 19, 2007

Error rendering macro 'code': Invalid value specified for parameter 'com.atlassian.confluence.ext.code.render.InvalidValueException'
REPORT  zind_mat_disp_img. 

*----------------------------------------------------------------------*
* Tables
*----------------------------------------------------------------------*

TABLES : mara, makt, drad.

*----------------------------------------------------------------------*
* internal table
*----------------------------------------------------------------------*

DATA : BEGIN OF w_material,
       matnr TYPE mara-matnr,
       prdha TYPE mara-prdha,
       maktx TYPE makt-maktx,
       img(18) TYPE c,
       END OF w_material.

DATA : i_material LIKE STANDARD TABLE OF w_material WITH HEADER LINE.

DATA : tabix TYPE i.

*----------------------------------------------------------------------*
* TYPE-POOLS AND FIELD CATALOG DECLARATION
*----------------------------------------------------------------------*

TYPE-POOLS: slis.

* To pass name of the report in function module for ALV
DATA: v_repid LIKE sy-repid .

* Internal table to display top of page and build eventcat
DATA : logoevent TYPE slis_t_event, "FOR LOGO
       t_event TYPE slis_alv_event,
       i_listheader TYPE slis_t_listheader,
       test TYPE slis_listheader.

* Table for catalog of the fields to be displayed
DATA: i_fieldcat TYPE slis_t_fieldcat_alv.
DATA : x_fieldcat TYPE slis_fieldcat_alv.

*&---------------------------------------------------------------------*
*&     Document declaration for DMS
*&---------------------------------------------------------------------*

* Document key
DATA: lf_doctype    LIKE bapi_doc_draw-documenttype,
       lf_docnumber  LIKE bapi_doc_draw-documentnumber,
       lf_docpart    LIKE bapi_doc_draw-documenttype,
       lf_docversion LIKE bapi_doc_draw-documentversion.

* Bapi-Return structure
DATA : ls_return LIKE bapiret2.

* Originals Document hierarchy
DATA: lt_files LIKE bapi_doc_files2 OCCURS 0 WITH HEADER LINE,
       ls_document LIKE bapi_doc_draw2.

*&---------------------------------------------------------------------*
*&      SELECTION-SCREEN
*&---------------------------------------------------------------------*

SELECTION-SCREEN : BEGIN OF BLOCK 001.
SELECT-OPTIONS : c_matnr FOR mara-matnr.
SELECTION-SCREEN : END OF BLOCK 001.

*&---------------------------------------------------------------------*
*&      INITIALIZATION
*&---------------------------------------------------------------------*

INITIALIZATION.

  v_repid = sy-repid.

*&---------------------------------------------------------------------*
*&      START-OF-SELECTION
*&---------------------------------------------------------------------*

START-OF-SELECTION.

  PERFORM 100_fetch_from_table.
  IF NOT i_material IS INITIAL.
    PERFORM 200_build_event USING logoevent.
    PERFORM 300_build_fieldcatalog.
    PERFORM 400_alv_grid_display.
  ENDIF.
*&---------------------------------------------------------------------*
*&      Form  100_fetch_from_table
*&---------------------------------------------------------------------*
*     Fetch datas from table into internal table
*----------------------------------------------------------------------*
FORM 100_fetch_from_table .

  SELECT a~matnr a~prdha b~maktx FROM mara AS a
            INNER JOIN makt AS b
        ON a~matnr = b~matnr INTO CORRESPONDING FIELDS OF TABLE i_material
        WHERE a~matnr IN c_matnr.
  IF sy-subrc = 0.
    SORT i_material BY matnr.
    LOOP AT i_material.
      i_material-img = 'Display_Image'.
      MODIFY i_material TRANSPORTING img.
    ENDLOOP.
  ENDIF.
ENDFORM.                    " 100_fetch_from_table

*&---------------------------------------------------------------------*
*&      Form  200_build_event
*&---------------------------------------------------------------------*
*  Build Event
*----------------------------------------------------------------------*
FORM 200_build_event USING p_logoevent TYPE slis_t_event.

  CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
*   EXPORTING
*     I_LIST_TYPE           = 0
   IMPORTING
     et_events             = p_logoevent
*   EXCEPTIONS
*     LIST_TYPE_WRONG       = 1
*     OTHERS                = 2
            .
  IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
            WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ENDIF.
  READ TABLE p_logoevent WITH KEY name = slis_ev_top_of_page INTO t_event.
  IF sy-subrc = 0.
    MOVE 'TOP_OF_PAGE' TO t_event-form.
    MODIFY p_logoevent FROM t_event INDEX sy-tabix TRANSPORTING form.
  ENDIF.

ENDFORM.                    " 150_build_event

*&---------------------------------------------------------------------*
*&      Form  300_build_fieldcatalog
*&---------------------------------------------------------------------*
*       Building field catalog for ALV display
*----------------------------------------------------------------------*
FORM 300_build_fieldcatalog .

  x_fieldcat-col_pos = 1.
  x_fieldcat-outputlen = '18'.
  x_fieldcat-fieldname = 'MATNR'.
  x_fieldcat-tabname = 'I_MATERIAL'.
  x_fieldcat-seltext_m = 'Material'.
  x_fieldcat-key = 'X'.
  x_fieldcat-key_sel = 'X'.
  x_fieldcat-hotspot = space.
  x_fieldcat-fix_column = 'X'.
  APPEND x_fieldcat TO i_fieldcat.
  CLEAR x_fieldcat.

  x_fieldcat-col_pos = 2.
  x_fieldcat-outputlen = '40'.
  x_fieldcat-fieldname = 'MAKTX'.
  x_fieldcat-tabname = 'I_MATERIAL'.
  x_fieldcat-seltext_m = 'Material_Description'.
  x_fieldcat-hotspot = space.
  APPEND x_fieldcat TO i_fieldcat.
  CLEAR x_fieldcat.

  x_fieldcat-col_pos = 3.
  x_fieldcat-outputlen = '18'.
  x_fieldcat-fieldname = 'PRDHA'.
  x_fieldcat-tabname = 'I_MATERIAL'.
  x_fieldcat-seltext_m = 'Product Hierarchy'.
  x_fieldcat-hotspot = space.
  APPEND x_fieldcat TO i_fieldcat.
  CLEAR x_fieldcat.

  x_fieldcat-col_pos = 4.
  x_fieldcat-outputlen = '18'.
  x_fieldcat-fieldname = 'IMG'.
  x_fieldcat-tabname = 'I_MATERIAL'.
  x_fieldcat-seltext_m = 'Link to Disp Image'.
  x_fieldcat-hotspot = 'X'.
  x_fieldcat-key = 'X'.
  APPEND x_fieldcat TO i_fieldcat.
  CLEAR x_fieldcat.

ENDFORM.                    " 200_build_fieldcatalog
*&---------------------------------------------------------------------*
*&      Form  400_alv_list_display
*&---------------------------------------------------------------------*
*     ALV List Display
*----------------------------------------------------------------------*

FORM 400_alv_grid_display .

  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
   EXPORTING
     i_callback_program                = v_repid
     i_callback_pf_status_set          = 'SET_PF_STATUS'
     i_callback_user_command           = 'USER_COMMAND'
     i_callback_top_of_page            = 'TOP_OF_PAGE'
     i_structure_name                  = 'I_MATERIAL'
*     IS_LAYOUT                         = struct_layout
     it_fieldcat                       = i_fieldcat
     it_events                         = logoevent
   TABLES
      t_outtab                          = i_material
   EXCEPTIONS
     program_error                     = 1
     OTHERS                            = 2
            .
  IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
            WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ENDIF.

ENDFORM.                    " 300_alv_grid_display

*---------------------------------------------------------------------*
*       FORM TOP_OF_PAGE                                              *
*---------------------------------------------------------------------*
*                                                             *
*---------------------------------------------------------------------*

FORM top_of_page.

  REFRESH i_listheader.
  DATA: t_header TYPE slis_listheader.
  DATA: v_text(50).

  WRITE sy-datum TO v_text.
  CLEAR t_header.
  t_header-typ = 'S'.
  t_header-key = 'Date'.
  t_header-info = v_text.
  APPEND t_header TO i_listheader.

  WRITE sy-repid TO v_text.
  CLEAR t_header.
  t_header-typ = 'S'.
  t_header-key = 'Program_Name'.
  t_header-info = v_text.
  APPEND t_header TO i_listheader.

  WRITE sy-uname TO v_text.
  CLEAR t_header.
  t_header-typ = 'S'.
  t_header-key = 'User'.
  t_header-info = v_text.
  APPEND t_header TO i_listheader.

  WRITE 'Materials_Display' TO v_text.
  CLEAR t_header.
  t_header-typ = 'S'.
  t_header-key = 'Details'.
  t_header-info = v_text.
  APPEND t_header TO i_listheader.

  CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
    EXPORTING
      it_list_commentary = i_listheader
      i_logo             = 'ENJOYSAP_LOGO'.

ENDFORM.                    "TOP_OF_PAGE

*&---------------------------------------------------------------------*
*& Form set_pf_status
*&---------------------------------------------------------------------*
* Form used to set the Custom pf-status of the List Display
*----------------------------------------------------------------------*

FORM set_pf_status USING i_rt_extab TYPE slis_t_extab.

  DATA : x_extab TYPE slis_extab.
  x_extab-fcode = '&LFO'.
  APPEND x_extab TO i_rt_extab.
  SET PF-STATUS 'ZSTANDARD' EXCLUDING i_rt_extab .

ENDFORM. "set_pf_status

*&---------------------------------------------------------------------*
*& Form user_command
*&---------------------------------------------------------------------*
* Form used to handle USER_COMMAND events
*----------------------------------------------------------------------*

FORM user_command USING rf_ucomm LIKE sy-ucomm
rs TYPE slis_selfield.

  tabix = rs-tabindex.
  CASE rf_ucomm.
*  when 'BACK'.
**  leave screen.
*
*  when 'EXIT'.
*  leave to screen 0.

*   Ok code for double click is &IC1 for ALV report
    WHEN '&IC1'.
      PERFORM sub_disp_img.
  ENDCASE.

ENDFORM. "user_command
*&---------------------------------------------------------------------*
*&      Form  sub_disp_img
*&---------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
FORM sub_disp_img .

  PERFORM get_document.
  IF sy-subrc = 0.
    PERFORM wa_exeute.
  ENDIF.

ENDFORM.                    " sub_disp_img
*&---------------------------------------------------------------------*
*&      Form  get_document
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM get_document.

  IF tabix NE space.
    READ TABLE i_material INDEX tabix.
    IF sy-subrc = 0.
   
*  Selecting Material path from the document  
      SELECT SINGLE * INTO drad FROM drad
               WHERE objky = i_material-matnr.
      IF sy-subrc = 0.
*      * Allocate document data
        lf_doctype    = drad-dokar.
        lf_docnumber  = drad-doknr.
        lf_docversion = drad-dokvr.
        lf_docpart    = drad-doktl.

        REFRESH lt_files.
        CLEAR lt_files.

*     Set detail information for the document
        CALL FUNCTION 'BAPI_DOCUMENT_GETDETAIL2'
              EXPORTING: documenttype      = lf_doctype
                         documentnumber    = lf_docnumber
                         documentpart      = lf_docpart
                         documentversion   = lf_docversion
                         getobjectlinks    = 'X'
                         getstatuslog      = 'X'
                         getlongtexts      = 'X'
                         getactivefiles    = 'X'
             IMPORTING:
                         documentdata      = ls_document
                         return            = ls_return
             TABLES:     documentfiles     = lt_files.

        IF ls_return-type CA 'EA'.
          MESSAGE ID '26' TYPE 'I' NUMBER '000'
                  WITH ls_return-message.
        ENDIF.
      ELSE.
        MESSAGE 'No Image Found' TYPE 'I'.
      ENDIF.
    ENDIF.
  ENDIF.
ENDFORM.                    " get_document
*&---------------------------------------------------------------------*
*&      Form  wa_exeute
*&---------------------------------------------------------------------*
*       To display image from the path.
*----------------------------------------------------------------------*
FORM wa_exeute .

  CALL FUNCTION 'WS_EXECUTE'
   EXPORTING
     inform                   = 'X'
     program                  = lt_files-docfile   "Image Path
   EXCEPTIONS
     frontend_error           = 1
     no_batch                 = 2
     prog_not_found           = 3
     illegal_option           = 4
     gui_refuse_execute       = 5
     OTHERS                   = 6
            .
  IF sy-subrc <> 0.
    MESSAGE 'Image Path Invalid' TYPE 'W'.
  ENDIF.

ENDFORM.                    " wa_exeute

  *&---------------------------------------------------------------------*
*& Report  Z_EMAIL_DMS_DOCUMENT
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT  Z_EMAIL_DMS_DOCUMENT.

TYPES :
        BEGIN OF TP_DMSFILES,
           MARK,
           LO_INDEX         TYPE DMS_DOC_INDEX,
           FILENAME(100)    TYPE C,
           FILE_TYPE        TYPE SOODK-OBJTP,
         END OF TP_DMSFILES.

"DMS document attachment to email ***************

DATA :  GSE_DRAD      TYPE DRAD,
        GSE_DRAW      TYPE DRAW.

DATA : GSE1_DRAD      TYPE DRAD,
       GSE1_DRAW      TYPE DRAW,
       GSE_FILE       TYPE DMS_REC_FILE,
       GTE_DRAT       TYPE STANDARD TABLE OF DRAT,
       GTE_DRAZ       TYPE STANDARD TABLE OF DRAZ,
       GTE_DRAD       TYPE STANDARD TABLE OF DRAD,
       GTE_DRAP       TYPE STANDARD TABLE OF DRAP,
       GTE_FILES      TYPE DMS_TBL_FILE,
       GTE_PHIOS      TYPE DMS_TBL_PHIO,
       GSE_PHIOS      TYPE DMS_REC_PHIO,
       GSE_DMSFILES   TYPE TP_DMSFILES,
       GTE_DMSFILES   TYPE STANDARD TABLE OF TP_DMSFILES.

DATA :  GSE_COUT_DEF    TYPE DMS_CHECKOUT_DEF,
        GSE_DOC_FILE    TYPE DMS_DOC_FILE,
        GSE_PHIO        TYPE DMS_PHIO,
        GVE_FILE        TYPE DRAW-FILEP.

"TO uplaod the save temp. file
 DATA : GTE_SOLIX    TYPE SOLIX_TAB,
        GSE_SOLIX    TYPE SOLIX,
        GV_FILENAME  TYPE STRING,
        GV_ATTYPE    TYPE SOODK-OBJTP,
        GV_ATSUB     TYPE SOOD-OBJDES,
        GV_ATT_DOC   TYPE FLAG,
        GV_RC        TYPE I.

data : gv_file         type string,
       gv_file1        type string,
       IV_PATH         TYPE STRING,
       EV_FILENAME     TYPE STRING,
       EV_EXTENSION    TYPE STRING,
       lv_sent_to_all  type os_boolean.

*/.. Class Declarations

DATA: go_send_request   type ref to  cl_bcs,
      go_document       type ref to  cl_document_bcs,
      lo_sender         TYPE REF TO cl_sapuser_bcs,
      lo_recipient      type ref to  if_recipient_bcs,
      lo_bcs_exception  type ref to  cx_bcs,
      GV_SUB            TYPE STRING.

DATA : IT_CONTENTS TYPE STANDARD TABLE OF solisti1,
       wa_contents TYPE solisti1.

PARAMETERS :  P_DOKNR TYPE DRAW-DOKNR.

START-OF-SELECTION.

         PERFORM SELECT_DMSDATA.

      IF NOT GTE_FILES[] IS INITIAL.
         PERFORM SEND_EMAIL.
      ELSE.
        Message I000(8I) with 'No document found in given DMS Document.'.
        set screen 0.
        leave program.
      ENDIF.

FORM SELECT_DMSDATA.

 CLEAR : GSE1_DRAW,GSE1_DRAD,GTE_FILES[],GTE_DMSFILES[].

"select the Document Info Record
SELECT SINGLE * FROM DRAW INTO CORRESPONDING FIELDS OF GSE1_DRAW WHERE DOKAR = 'MCR'
                                                                  AND DOKNR = P_DOKNR.             "GV_DOKNR.

"Document-Object Link
SELECT SINGLE * FROM DRAD INTO CORRESPONDING FIELDS OF GSE1_DRAD WHERE DOKAR = 'MCR'
                                                                   AND DOKNR = P_DOKNR.             "GV_DOKNR.

          IF NOT GSE1_DRAW-DOKNR IS INITIAL.

"call FM CV115_DOC_OPEN_DISPLAY to read the document details along with the files
"which are attach

  CALL FUNCTION 'CV115_DOC_OPEN_DISPLAY'
   EXPORTING
*     PF_API_FLAG        = ' '
     PF_DOKAR           = GSE1_DRAW-DOKAR
     PF_DOKNR           = GSE1_DRAW-DOKNR
     PF_DOKTL           = GSE1_DRAW-DOKTL
     PF_DOKVR           = GSE1_DRAW-DOKVR
     PF_READ_DRAT       = 'X'
     PF_READ_DRAD       = 'X'
     PF_READ_COMP       = 'X'
     PF_READ_KPRO       = 'X'
     PF_READ_DRAP       = 'X'
   IMPORTING
     PSX_DRAW           = GSE_DRAW
   TABLES
     PTX_DRAT           = GTE_DRAT
     PTX_DRAZ           = GTE_DRAZ
     PTX_DRAD           = GTE_DRAD
     PTX_DRAP           = GTE_DRAP
     PTX_FILES          = GTE_FILES
   EXCEPTIONS
     NOT_FOUND          = 1
     NO_AUTH            = 2
     ERROR              = 3
     OTHERS             = 4
            .
  IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.

         ENDIF.

ENDFORM.

FORM SEND_EMAIL.

     WA_CONTENTS-LINE = '<HTML> <BODY>'.
     APPEND WA_CONTENTS TO IT_CONTENTS.
     CLEAR : WA_CONTENTS.

     WA_CONTENTS-LINE = '<P><B>This program gives the Basic idea to send the DMS document as Email Attachment.</B></P>'.
     APPEND WA_CONTENTS TO IT_CONTENTS.
     CLEAR : WA_CONTENTS.

     WA_CONTENTS-LINE = '</BODY> </HTML>'.
     APPEND WA_CONTENTS TO IT_CONTENTS.
     CLEAR : WA_CONTENTS.

  TRY.
*     ------ create persistent send request ----------------------
      go_send_request = cl_bcs=>create_persistent( ).

      go_document = cl_document_bcs=>create_document(
                      i_type    = 'HTM'
                      i_text    = IT_Contents
*                      i_length  = '12'
                      i_subject  = 'DMS Document as Email Attachment' ).               "lv_sub

          PERFORM ATT_DMS_DOC.

      CALL METHOD go_send_request->set_document( go_document ).

     lo_recipient = cl_cam_address_bcs=>create_internet_address( 'xyz@compzny.com' (mailto:'xyz@compzny.com') ).

     CALL METHOD go_send_request->add_recipient
          EXPORTING
          i_recipient  = lo_recipient
          i_express = 'X'.

    CALL METHOD go_send_request->set_send_immediately
      EXPORTING
        i_send_immediately = 'X'.
*     CATCH cx_send_req_bcs .
*    ENDTRY.

      CALL METHOD go_send_request->send(
        EXPORTING
          i_with_error_screen = 'X'
        RECEIVING
          result              = lv_sent_to_all ).

      IF lv_sent_to_all = 'X'.
         Message I000(8I) with 'Email send succesfully'.
      ELSEIF lv_sent_to_all IS INITIAL.
         message i000(8i) with 'Email not send'.
      ENDIF.

      COMMIT WORK.

    CATCH cx_bcs INTO lo_bcs_exception.

  ENDTRY.

ENDFORM.

FORM ATT_DMS_DOC.

"GTE_FILES = In this we will get all the list of files which are assign to Document

 IF NOT GTE_FILES[] IS INITIAL.

"Append the files in an internal table

   LOOP AT GTE_FILES INTO GSE_FILE.
   GSE_DMSFILES-MARK        = 'X'.
   GSE_DMSFILES-LO_INDEX    = GSE_FILE-LO_INDEX.      "file no. index
   GTE_PHIOS = GSE_FILE-TBL_PHIOS.                    "file object numbers

   READ TABLE GTE_PHIOS INTO GSE_PHIOS WITH KEY LO_INDEX = GSE_FILE-LO_INDEX.
    IF SY-SUBRC = 0.
       IF GSE_PHIOS-FILENAME IS NOT INITIAL.
          CLEAR : iv_path, EV_FILENAME, EV_EXTENSION.

            IV_PATH = GSE_PHIOS-FILENAME.

        CALL FUNCTION 'CRM_EMAIL_SPLIT_FILENAME'
          EXPORTING
            iv_path            = iv_path
         IMPORTING
           EV_FILENAME         = EV_FILENAME
           EV_EXTENSION        = EV_EXTENSION
*           EV_MIMETYPE        =
                  .

         GSE_DMSFILES-FILENAME  = EV_FILENAME.
         GSE_DMSFILES-FILE_TYPE = EV_EXTENSION.
         APPEND GSE_DMSFILES TO GTE_DMSFILES.

       ENDIF.
    ENDIF.

       CLEAR : GSE_FILE,GTE_PHIOS[],GSE_DMSFILES.
   ENDLOOP.

"Call screen for selection of DMS document
      clear : GV_ATT_DOC.
      CALL SCREEN 500 STARTING AT 40 5.

          IF GV_ATT_DOC = 'X'.       "if user select Yes in screen 500 to send document in email
"loop at internal DMS document table which user have selected to send as email attachment

  LOOP AT GTE_DMSFILES INTO GSE_DMSFILES WHERE MARK = 'X'.
    CLEAR : GTE_PHIOS[].

    READ TABLE GTE_FILES INTO GSE_FILE WITH KEY LO_INDEX = GSE_DMSFILES-LO_INDEX.
          IF SY-SUBRC = 0.
          GTE_PHIOS = GSE_FILE-TBL_PHIOS.                    "file object numbers

     READ TABLE GTE_PHIOS INTO GSE_PHIOS WITH KEY LO_INDEX = GSE_FILE-LO_INDEX.
          IF SY-SUBRC = 0.

   CLEAR : GVE_FILE,GSE_PHIO,GSE_DOC_FILE,GSE_COUT_DEF.

   GSE_COUT_DEF-KPRO_USE  = 'X'.
   GSE_COUT_DEF-COMP_GET  = 'X'.

   GSE_DOC_FILE-LANGU     = 'EN'.
   GSE_DOC_FILE-DAPPL     = GSE_FILE-DAPPL.

   GSE_PHIO-LO_INDEX        = GSE_FILE-LO_INDEX.
   GSE_PHIO-LO_OBJID        = GSE_FILE-LO_OBJID.
   GSE_PHIO-PH_OBJID        = GSE_PHIOS-PH_OBJID.
   GSE_PHIO-PH_INDEX        = GSE_PHIOS-PH_INDEX.
   GSE_PHIO-LANGU           = GSE_PHIOS-LANGU.
   GSE_PHIO-STATUS_NR       = GSE_PHIOS-STATUS_NR.
   GSE_PHIO-FILENAME        = GSE_PHIOS-FILENAME.
   GSE_PHIO-ACTIVE_VERSION  = GSE_PHIOS-ACTIVE_VERSION.
   GSE_PHIO-DELETE_FLAG     = GSE_PHIOS-DELETE_FLAG.
   GSE_PHIO-PROTECTED       = GSE_PHIOS-PROTECTED.
   GSE_PHIO-DEFAULT_LANGU   = GSE_PHIOS-DEFAULT_LANGU.
   GSE_PHIO-FILE_ID         = GSE_PHIOS-FILE_ID.
   GSE_PHIO-STORAGE_CAT     = GSE_PHIOS-STORAGE_CAT.
   GSE_PHIO-CREATED_BY      = GSE_PHIOS-CREATED_BY.
   GSE_PHIO-CREATED_AT      = GSE_PHIOS-CREATED_AT.
   GSE_PHIO-CHANGED_BY      = GSE_PHIOS-CHANGED_BY.
   GSE_PHIO-CHANGED_AT      = GSE_PHIOS-CHANGED_AT.

"This FM will create a temporaray file at location GVE_FILE
  CALL FUNCTION 'CV120_DOC_CHECKOUT_VIEW'
    EXPORTING
      PS_COUT_DEF         = GSE_COUT_DEF
      PF_TCODE            = 'CV03N'
      ps_doc_file         = GSE_DOC_FILE
      ps_draw             = GSE1_DRAW
      PS_PHIO             = GSE_PHIO
*     PS_FRONTEND         =
*     PF_STD_URL          = 'X'
   IMPORTING
     PFX_FILE             = GVE_FILE
*     PFX_URL             =
*     PFX_USE_LAST        =
*   TABLES
*     PT_COMPONENTS       =
*     PT_DRAZ             =
*     PTX_CONTENT         =
   EXCEPTIONS
     ERROR               = 1
     OTHERS              = 2
            .
  IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.

  CLEAR : GTE_SOLIX[], GV_FILENAME.

  WAIT UP TO 1 SECONDS.

  IF NOT GVE_FILE IS INITIAL.

  CLEAR : GTE_SOLIX[], GV_FILENAME.
          GV_FILENAME = GVE_FILE.

"upload the temp file in internal table
CALL FUNCTION 'GUI_UPLOAD'
  EXPORTING
    filename                      = GV_FILENAME
   FILETYPE                       = 'BIN'
*   HAS_FIELD_SEPARATOR           = ' '
*   HEADER_LENGTH                 = 0
*   READ_BY_LINE                  = 'X'
*   DAT_MODE                      = ' '
*   CODEPAGE                      = ' '
*   IGNORE_CERR                   = ABAP_TRUE
*   REPLACEMENT                   = '#'
*   CHECK_BOM                     = ' '
*   VIRUS_SCAN_PROFILE            =
*   NO_AUTH_CHECK                 = ' '
* IMPORTING
*   FILELENGTH                    =
*   HEADER                        =
  tables
    data_tab                      = GTE_SOLIX
 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 ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.

  IF NOT GTE_SOLIX[] IS INITIAL.
      GV_ATTYPE   = GSE_DMSFILES-FILE_TYPE.
      GV_ATSUB    = GSE_DMSFILES-FILENAME.

 TRY.
        go_document->add_attachment(
            i_attachment_type      = GV_ATTYPE                            "'PDF'
            i_attachment_subject   = GV_ATSUB                             "lv_sub
*            i_attachment_size      = lv_len
            i_att_content_hex      = GTE_SOLIX ).

         CATCH cx_bcs INTO lo_bcs_exception.
 ENDTRY.

  ENDIF.

"Delete the temporary file

CALL METHOD cl_gui_frontend_services=>file_delete
  EXPORTING
    filename             =  GV_FILENAME
  changing
    rc                   =  GV_RC
  EXCEPTIONS
    file_delete_failed   = 1
    cntl_error           = 2
    error_no_gui         = 3
    file_not_found       = 4
    access_denied        = 5
    unknown_error        = 6
    not_supported_by_gui = 7
    wrong_parameter      = 8
    others               = 9.

IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.

  ENDIF.
          ENDIF.
          ENDIF.
       CLEAR : GSE_DMSFILES,GSE_PHIOS,GSE_DOC_FILE,GSE_FILE,GV_ATTYPE,GV_ATSUB.
  ENDLOOP.

        ENDIF. "GV_ATT_DOC

 ENDIF.

ENDFORM.

With this tutorial you'll learn how to transform a DIR content into binary Table so it can be used for download in background or send by mail .

Hope it's will be helpful.

 

*** Data Definition
DATA: v_cout         TYPE dms_checkout_def,
      v_dttrg        TYPE dttrg, "Name of data carrier
      v_docfile      TYPE dms_doc_file,
      v_dappl        TYPE dappl, "Application
      v_tabix        TYPE i ,
      v_tdwa         TYPE tdwa ,
      v_phio         TYPE dms_phio,
      v_frontend     TYPE dms_frontend_data,
      v_exception    TYPE REF TO cx_root.
*
**
*** Internal Table Definition
DATA : t_drao  TYPE STANDARD TABLE OF drao,
t_kpro  TYPE dms_tbl_file ,
t_hexa TYPE solix_tab.
**
*** Constants
CONSTANTS : c_hostname TYPE ntadr VALUE 'DEFAULT', "Hostname
c_type TYPE typdt VALUE 'PC', "Type
c_system TYPE char4 VALUE 'WN32'. "System
**
*** field-symblos
FIELD-SYMBOLS : <kpro>   TYPE LINE OF dms_tbl_file,
<phio>   TYPE LINE OF dms_tbl_phio .
CLEAR : v_tdwa .
v_frontend-frontend_type = c_type. "'PC'.
v_frontend-hostname      = c_hostname. "'DEFAULT'.
v_frontend-winsys        = c_system.                  "'WN32'.
v_frontend-platform      = 0.
v_cout-comp_get          = abap_true.
v_cout-batchmode         = abap_true.
v_cout-content_provide   = 'TBL'.
* Check if for FID Type KPRO is used
CALL FUNCTION 'CV200_DB_TDWA_SELECT'
  EXPORTING
    pf_dokar  = fid-dokar
  IMPORTING
    psx_tdwa  = v_tdwa
  EXCEPTIONS
    not_found = 1.
CHECK sy-subrc EQ 0.
v_cout-kpro_use          = v_tdwa-kpro_use.
CASE v_tdwa-kpro_use.
  WHEN abap_true.
* Kpro is used
* retrieve FID Master Data
    FREE t_kpro.
    CALL FUNCTION 'CV120_KPRO_MASTER_DATA_GET'
      EXPORTING
        pf_dokar  = fid-dokar
        pf_doknr  = fid-doknr
        pf_dokvr  = fid-dokvr
        pf_doktl  = fid-doktl
      TABLES
        ptx_data  = t_kpro
      EXCEPTIONS
        not_found = 1
        error     = 2.
    CHECK sy-subrc EQ 0.
    v_frontend-frontend_type = 'KP'.
    LOOP AT t_kpro ASSIGNING <kpro>.
      FREE t_drao.
      LOOP AT <kpro>-tbl_phios ASSIGNING <phio>.
        MOVE-CORRESPONDING <phio> TO v_phio.
        CALL FUNCTION 'CV120_DOC_CHECKOUT_VIEW'
          EXPORTING
            ps_cout_def = v_cout
            ps_doc_file = v_docfile
            ps_draw     = fid
            ps_phio     = v_phio
            ps_frontend = v_frontend
          TABLES
            ptx_content = t_drao
          EXCEPTIONS
            error       = 1.
        CHECK sy-subrc EQ 0.
        PERFORM transform_fid_to_binary 
            TABLES t_drao
                   t_hexa.
      ENDLOOP.
    ENDLOOP.
  WHEN abap_false.
    DO 2 TIMES.
      CLEAR : v_docfile .
      FREE : t_drao.
      v_tabix = sy-index.
      v_docfile-fileno = v_tabix.
      CASE v_tabix.
        WHEN 1.
          v_dappl = fid-dappl.
          v_dttrg = fid-dttrg.
        WHEN 2.
          v_dappl = fid-dappl1.
          v_dttrg = fid-dttrg1.
      ENDCASE.
      v_docfile-dappl = v_dappl.
      v_docfile-dttrg = v_dttrg.
      CALL FUNCTION 'CV120_DOC_CHECKOUT'
        EXPORTING
          ps_cout_def = v_cout
          ps_draw     = fid
          ps_doc_file = v_docfile
        TABLES
          ptx_drao    = t_drao
        EXCEPTIONS
          error       = 1
          OTHERS      = 2.
      CHECK sy-subrc EQ 0.
      CHECK sy-subrc EQ 0.
      PERFORM transform_fid_to_binary TABLES t_drao
      t_hexa.
    ENDDO.
ENDCASE.
*&---------------------------------------------------------------------*
*&      Form  transform_fid_to_binary
*&---------------------------------------------------------------------*
FORM transform_fid_to_binary TABLES drao         TYPE drao
                                    binary_table TYPE solix.
*** Field-Symbols definition
  FIELD-SYMBOLS : <drao>   TYPE drao ,
                  <source> TYPE x ,
                  <dest>   TYPE x,
                  <hexa>   TYPE solix .
** Data Definition
  DATA: v_filelong     TYPE i ,
        v_long         TYPE i,
        v_longdes      TYPE i  .
  FREE binary_table.
  CHECK drao[] IS NOT INITIAL.
* Conversion du document en binaire
  LOOP AT drao ASSIGNING <drao>.
    IF v_filelong IS INITIAL.
      v_filelong = <drao>-orln.
    ENDIF.
    ASSIGN <drao>-orblk TO <source>.
    DESCRIBE FIELD <source> LENGTH v_long IN BYTE MODE.
    CLEAR v_longdes.
    WHILE v_long GT 0.
      ASSIGN <source>+v_longdes(v_long) TO <source>.
      APPEND INITIAL LINE TO binary_table ASSIGNING <hexa>.
      ASSIGN <hexa>-line TO <dest>.
      DESCRIBE FIELD <dest> LENGTH v_longdes IN BYTE MODE.
      MOVE <source> TO <dest>.
      v_filelong = v_filelong - v_longdes.
      v_long = v_long - v_longdes.
      CHECK v_filelong LE v_longdes.
      IF v_long NE 0.
        v_long = v_filelong.
      ENDIF.
      CHECK v_long LE 0.
      v_long = 0.
    ENDWHILE.
  ENDLOOP.
ENDFORM.                    "transform_fid_to_binary
 


  • No labels