Skip to Content
0
Former Member
Dec 27, 2006 at 11:55 AM

Excel sheet attached mail when opened shows a error message

298 Views

hi all,

i have created a report for sending the output to the sap inbox as excel attachment . my problem is ;it always shows an error message when ever the attachment is opened.

I have used the function 'SO_NEW_DOCUMENT_ATT_SEND_API1' and in the table parameters, TABLES

packing_list =

passing the .XLS format and excel sheet name.

please provide me a solution to stop the display of this error message having the contents 'this file is not in a recognizable format'.

thanks and regards\

Thomas

Coding :

FORM sub_output_timeadm  USING lv_usrid TYPE gty_timhours-usrid.

  DATA : lv_emp1(10) TYPE c,
        lv_ename(40) TYPE c,
          lv_hour(10) ,
          lv_lgart(15),
          lv_scc(10),
          lv_rcc(10),
          lv_order(15),
          lv_ordtext(40),
          lv_act(10).
  DATA : lwa_content TYPE solisti1.

  DATA : lit_objpack LIKE sopcklsti1 OCCURS 2 WITH HEADER LINE,"#EC *
         lit_objbin  LIKE solisti1   OCCURS 0 WITH HEADER LINE,
         lit_objtxt  LIKE solisti1   OCCURS 2 WITH HEADER LINE,
         lit_reclist LIKE somlreci1  OCCURS 2 WITH HEADER LINE,
         lwa_docdat  LIKE sodocchgi1 OCCURS 1 WITH HEADER LINE,
         lv_tab_lines LIKE sy-tabix.

  DATA : lv_file LIKE rlgrap-filename,
         lv_line LIKE solisti1-line,
         lv_vt TYPE c VALUE cl_abap_char_utilities=>horizontal_tab.
  DATA : lwa_receivers   TYPE somlreci1 .


*Object text details
  PERFORM sub_objtxt_data TABLES lit_objtxt
                                 lit_objpack
                          USING  lv_tab_lines.
*Document data details
  PERFORM sub_document_data TABLES lwa_docdat
                                   lit_objtxt
                            USING  lv_file
                                   lv_tab_lines.

  PERFORM sub_topofpage TABLES lit_objbin
                        USING  lv_line
                               lv_vt.

  PERFORM sub_fill_columnhead TABLES lit_objbin.

  LOOP AT git_content INTO lwa_content.

    lv_emp1 = lwa_content+2(10).
    CONDENSE lv_emp1.
    lv_ename = lwa_content+15(40).
    SHIFT lv_ename LEFT.
*    CONDENSE lv_ename.

    IF lv_ename+0(7) = text-024.
      WRITE lv_ename TO lv_ename RIGHT-JUSTIFIED.
    ELSE.
      CONDENSE lv_ename.
    ENDIF.

    lv_hour = lwa_content+58(10).
    CONDENSE lv_hour.
    lv_lgart = lwa_content+70(15).
    CONDENSE lv_lgart.
    lv_scc = lwa_content+90(10).
    CONDENSE lv_scc.
    lv_rcc = lwa_content+103(10).
    CONDENSE lv_rcc.
    lv_order = lwa_content+115(15).
    CONDENSE lv_order.
    lv_ordtext = lwa_content+132(40).
    CONDENSE lv_ordtext.
    lv_act = lwa_content+174(10).
    CONDENSE lv_act.

    CONCATENATE lv_emp1
                lv_ename
                lv_hour
                lv_lgart
                lv_scc
                lv_rcc
                lv_order
                lv_ordtext
                lv_act INTO lv_line SEPARATED BY lv_vt.

    CONCATENATE gc_add lv_line lv_vt INTO lv_line.
    APPEND lv_line TO lit_objbin.
    CLEAR :lv_emp1,
               lv_ename,
               lv_hour,
               lv_lgart,
               lv_scc,
               lv_rcc,
               lv_order,
               lv_ordtext,
               lv_act ,lv_line,lwa_content.
  ENDLOOP.

  DESCRIBE TABLE lit_objbin LINES lv_tab_lines.

  lv_tab_lines = lv_tab_lines + 1.
*  Object pack details
  PERFORM sub_objpack_data TABLES lit_objbin
                                  lit_objpack
                           USING  lv_tab_lines
                                  lv_file.
*Receiver list details
  PERFORM sub_reclist_timeadm TABLES lit_reclist
                              USING lv_usrid.

  READ TABLE lit_reclist INDEX 1.
  IF sy-subrc  = 0.
    CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
      EXPORTING
        document_data              = lwa_docdat
        put_in_outbox              = gc_x
        commit_work                = gc_x
      TABLES
        packing_list               = lit_objpack
        contents_bin               = lit_objbin
        contents_txt               = lit_objtxt
        receivers                  = lit_reclist
      EXCEPTIONS
        too_many_receivers         = 1
        document_not_sent          = 2
        document_type_not_exist    = 3
        operation_no_authorization = 4
        parameter_error            = 5
        x_error                    = 6
        enqueue_error              = 7
        OTHERS                     = 8.
    CASE sy-subrc.
*    WHEN 0.
*      MESSAGE i014.
*    WHEN 1.
*      MESSAGE i016.
*    WHEN 2.
*      MESSAGE i016.
*    WHEN 4.
*      MESSAGE i015.
*    WHEN OTHERS.
*      MESSAGE i017.
    ENDCASE.
  ENDIF.
  REFRESH git_content.
  CLEAR gwa_content.

FORM sub_objtxt_data TABLES xt_objtxt STRUCTURE solisti1
                            xt_objpack STRUCTURE sopcklsti1
                     USING  xv_tab_lines .

  DATA : lv_zdat(10)  TYPE c,
         lv_zdat2(10) TYPE c.

  CONSTANTS: lc_hiphen(1) TYPE c VALUE '-'.

*  write sy-datum to lv_zdat mm/dd/yyyy.
*  concatenate text-022 lv_zdat into xt_objtxt separated by space.
*  APPEND xt_objtxt.clear xt_objtxt.
  WRITE pnpbegda TO lv_zdat  MM/DD/YYYY.
  WRITE pnpendda TO lv_zdat2 MM/DD/YYYY.
  CONCATENATE text-080
              lv_zdat
              lc_hiphen
              lv_zdat2   INTO xt_objtxt SEPARATED BY space.
  APPEND xt_objtxt.CLEAR xt_objtxt.
  xt_objtxt = text-067.
  APPEND xt_objtxt.CLEAR xt_objtxt.

  CLEAR: lv_zdat,
         lv_zdat2.

  DESCRIBE TABLE xt_objtxt LINES xv_tab_lines.
  READ TABLE xt_objtxt INDEX xv_tab_lines.
  CLEAR xt_objpack-transf_bin.
  xt_objpack-head_start = 1.
  xt_objpack-head_num   = 0.
  xt_objpack-body_start = 1.
  xt_objpack-body_num   = xv_tab_lines.
  xt_objpack-doc_type   = gc_raw.
  APPEND xt_objpack.
  CLEAR xt_objpack.

ENDFORM.                    " sub_objtxt_data

*&---------------------------------------------------------------------*
*&      Form  sub_document_data
*&---------------------------------------------------------------------*
*To fix the size of the document
*----------------------------------------------------------------------*
*      -->XT_DOCDAT
*      -->XT_OBJTXT
*      -->XV_LV_FILE
*      -->XV_TAB_LINES
*----------------------------------------------------------------------*
FORM sub_document_data TABLES xt_docdat STRUCTURE sodocchgi1
                              xt_objtxt STRUCTURE solisti1
                       USING  xv_lv_file
                              xv_tab_lines.                 "#EC *
  DATA : lv_subject     TYPE string,
         lv_open        TYPE c VALUE '(',
         lv_close       TYPE c VALUE ')',
         lv_slash       TYPE c VALUE '/'.

  xt_docdat-obj_name = xv_lv_file.
  CONCATENATE lv_open sy-sysid
              lv_slash sy-mandt lv_close INTO lv_subject.
  xt_docdat-obj_descr = lv_subject.
  xt_docdat-doc_size
      = ( xv_tab_lines - 1 ) * 255 + STRLEN( xt_objtxt ).
ENDFORM.                    " sub_document_data

*&---------------------------------------------------------------------*
*&      Form  sub_topofpage
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_LIT_OBJBIN  text
*----------------------------------------------------------------------*
FORM sub_topofpage TABLES xt_objbin STRUCTURE solisti1
                   USING  xv_lv_line
                          xv_vt.

  DATA: lwa_line TYPE slis_listheader.

  LOOP AT git_header INTO lwa_line.
    CONCATENATE lwa_line-key lwa_line-info
                INTO xv_lv_line SEPARATED BY xv_vt.
    CONCATENATE gc_add xv_lv_line xv_vt
                xv_vt     "TAB space
                xv_vt
                xv_vt
                xv_vt
                xv_vt
                xv_vt
*                xv_vt
*                xv_vt
*                xv_vt
*                xv_vt
*                xv_vt
*                xv_vt
*                xv_vt
                INTO xv_lv_line.
    APPEND xv_lv_line TO xt_objbin.
  ENDLOOP.

ENDFORM.                    " sub_topofpage

*&---------------------------------------------------------------------*
*&      Form  sub_fill_columnhead
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM sub_fill_columnhead TABLES xt_objbin STRUCTURE solisti1.

  DATA:  lv_line LIKE solisti1-line,
         lv_vt TYPE c VALUE cl_abap_char_utilities=>horizontal_tab,
         lv_zdat(10).
  DATA : lv_line1(40),
         lv_line2(10),
         lv_line3(10),
         lv_line4(3),
         lv_line5(40).

  lv_line1 = text-008.
  WRITE sy-datum TO lv_zdat MM/DD/YYYY.
  lv_line2 = lv_zdat.

  CONCATENATE lv_vt
              lv_line1
              lv_vt
              lv_vt
              lv_line2
              lv_vt
              lv_vt
              lv_vt
              lv_vt
*              lv_vt
         INTO lv_line.

  CONCATENATE gc_add lv_line lv_vt INTO lv_line.

  APPEND lv_line TO xt_objbin.
  CLEAR : lv_line, lv_line1, lv_line2, lv_zdat.

  lv_line1 = text-009.
  lv_line2 = text-010.
  WRITE pnpbegda TO lv_zdat MM/DD/YYYY.
  lv_line3 = lv_zdat.
  CLEAR lv_zdat.
  lv_line4 = ' - '.
  WRITE pnpendda TO lv_zdat MM/DD/YYYY.
  lv_line5 = lv_zdat.

  CONCATENATE lv_vt
              lv_line1
              lv_vt
              lv_vt
              lv_line2
              lv_vt
              lv_line3
              lv_line4
              lv_line5
              lv_vt
              lv_vt
              lv_vt
              lv_vt
         INTO lv_line.
  CONCATENATE gc_add lv_line lv_vt INTO lv_line.

  APPEND lv_line TO xt_objbin.
  CLEAR : lv_line, lv_line1,
          lv_line2,lv_line3,
          lv_line4, lv_line5, lv_zdat.

  CONCATENATE lv_vt
              lv_vt
              lv_vt
              lv_vt
              lv_vt
              lv_vt
              lv_vt
              lv_vt
              lv_vt
         INTO lv_line.
  CONCATENATE gc_add lv_line lv_vt INTO lv_line.

  APPEND lv_line TO xt_objbin.
  CLEAR lv_line.

  CONCATENATE text-013
              text-014
              text-015
              text-016
              text-017
              text-018
              text-019
              text-026
              text-020
         INTO lv_line
    SEPARATED BY lv_vt.

  CONCATENATE gc_add lv_line
              lv_vt         "TAB space
              INTO lv_line.
  APPEND lv_line TO xt_objbin.

ENDFORM.                    " sub_fill_columnhead

*&---------------------------------------------------------------------*
*&      Form  sub_objpack_data
*&---------------------------------------------------------------------*
*To fix the actual document size
*----------------------------------------------------------------------*
*      -->XT_OBJBIN
*      -->XT_OBJPACK
*      -->XV_TAB_LINES
*      -->XV_LV_FILE
*----------------------------------------------------------------------*
FORM sub_objpack_data  TABLES  xt_objbin STRUCTURE solisti1
                               xt_objpack STRUCTURE sopcklsti1
                        USING  xv_tab_lines
                               xv_lv_file.                  "#EC *

  DATA : lwa_objpack TYPE sopcklsti1.

  lwa_objpack-transf_bin = gc_x.
  lwa_objpack-head_start = 1.
  lwa_objpack-head_num   = 0.
  lwa_objpack-body_start = 1.
  lwa_objpack-body_num   = xv_tab_lines.
  lwa_objpack-doc_type   = gc_xls.
  lwa_objpack-obj_name   = xv_lv_file.
  lwa_objpack-obj_descr = gc_descr.
  lwa_objpack-doc_size
            = ( xv_tab_lines - 1 ) * 255 + STRLEN( xt_objbin ).
  APPEND lwa_objpack TO xt_objpack.
  CLEAR lwa_objpack.
ENDFORM.                    " sub_objpack_data

*&---------------------------------------------------------------------*
*&      Form  sub_reclist_timeadm
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_LIT_RECLIST  text
*      -->P_LV_USRID  text
*----------------------------------------------------------------------*
FORM sub_reclist_timeadm  TABLES xt_reclist STRUCTURE somlreci1
                          USING  lp_usrid TYPE gty_timhours-usrid."#EC *

*local constant
  CONSTANTS :      lc_b TYPE   c VALUE 'B'.
*local workarea.
  DATA : lwa_receivers   TYPE somlreci1 ,
         lwa_usrid       TYPE gty_usrid ,
         lwa_docdata     TYPE sodocchgi1.

  REFRESH : git_receivers.":, LIT_DOCDATA .
  CLEAR : lwa_receivers,lwa_docdata.

  IF p_timadm EQ 'X'.

    MOVE: lp_usrid TO lwa_receivers-receiver,
          text-002   TO  lwa_receivers-express,
          lc_b       TO lwa_receivers-rec_type.

    APPEND lwa_receivers TO xt_reclist.

  ELSEIF p_manger EQ 'X'.

    READ TABLE git_usrid INTO lwa_usrid WITH KEY pernr = gwa_emphours-magpernr
                                                usrty = '0001' BINARY SEARCH.

    IF sy-subrc EQ 0.

      MOVE: lwa_usrid-usrid TO lwa_receivers-receiver,
              text-002       TO  lwa_receivers-express,
              lc_b       TO lwa_receivers-rec_type.

      APPEND lwa_receivers TO xt_reclist.

    ENDIF.
    CLEAR : lwa_usrid .
  ENDIF.
  .