Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Excel sheet attached mail when opened shows a error message

Former Member
0 Kudos

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.
  .


1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi Thomas,

look at my coding in the following thread. I think this might help you.

Regards,

Georg-Stefan

3 REPLIES 3

Shivaji16
Active Participant
0 Kudos

Hi Tona,

Please go through the code and cross check....

REPORT zcyborg_5 NO STANDARD PAGE HEADING.

TABLES : eket.

DATA : p_date TYPE d.

DATA : w_lines TYPE sy-tabix.

TYPES : BEGIN OF types_eket,

ebeln TYPE eket-ebeln,

ebelp TYPE eket-ebelp,

eindt TYPE eket-eindt,

END OF types_eket.

DATA : t_eket TYPE STANDARD TABLE OF types_eket.

                      • Declaration for ALV display *********************

DATA : w_grid TYPE REF TO cl_gui_alv_grid,

w_custom_container TYPE REF TO cl_gui_custom_container.

**************************************************************

RANGES : r_eindt FOR eket-eindt.

FIELD-SYMBOLS: <fs_eket> TYPE types_eket.

INITIALIZATION.

CALL FUNCTION 'CALCULATE_DATE'

EXPORTING

days = '60-'

months = '0'

start_date = sy-datum

IMPORTING

result_date = p_date.

r_eindt-low = p_date.

r_eindt-high = sy-datum.

r_eindt-sign = 'I'.

r_eindt-option = 'BT'.

APPEND r_eindt.

START-OF-SELECTION.

PERFORM get_data.

PERFORM disp_data.

PERFORM email_data.

  • perform disp_alv.

&----


*& Form get_data

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM get_data.

SELECT ebeln

ebelp

eindt

FROM eket

INTO TABLE t_eket

WHERE eindt IN r_eindt.

ENDFORM. " get_data

&----


*& Form disp_data

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM disp_data.

DESCRIBE TABLE t_eket LINES w_lines.

WRITE :/5 'No of rows : ', w_lines.

WRITE :/5 'EBELN', 30 'EBELP', 50 'EINDT'.

SORT t_eket DESCENDING BY eindt.

LOOP AT t_eket ASSIGNING <fs_eket>.

AT NEW ebeln.

ULINE.

ENDAT.

WRITE : /5 <fs_eket>-ebeln, 30 <fs_eket>-ebelp, 50 <fs_eket>-eindt.

ENDLOOP.

ENDFORM. " disp_data

************************************************************************

  • call function 'SEND_TABLE_TO_EXCEL'

  • exporting

  • structure_name = 'EKET'

  • tables

  • exceltab = t_eket

  • .

**********************************************************************

FORM email_data.

*Structures and internal table used to send data vai mail

DATA : objpack LIKE sopcklsti1 OCCURS 2 WITH HEADER LINE,

objhead LIKE solisti1 OCCURS 1 WITH HEADER LINE,

objbin LIKE solisti1 OCCURS 0 WITH HEADER LINE,

objtxt LIKE solisti1 OCCURS 10 WITH HEADER LINE,

reclist LIKE somlreci1 OCCURS 5 WITH HEADER LINE,

tab_lines LIKE sy-tabix,

doc_chng LIKE sodocchgi1.

DATA : it_attach TYPE STANDARD TABLE OF solisti1,

w_attach TYPE solisti1.

CONSTANTS : c_car TYPE x VALUE '0D',

c_tab TYPE x VALUE '09'.

CONCATENATE 'EBELN'

c_tab

'EBELP'

c_tab

'EINDT'

c_car INTO w_attach.

APPEND w_attach TO it_attach.

LOOP AT t_eket INTO <fs_eket>.

CONCATENATE <fs_eket>-ebeln

c_tab

<fs_eket>-ebelp

c_tab

<fs_eket>-eindt

c_car INTO w_attach.

APPEND w_attach TO it_attach.

ENDLOOP.

MOVE it_attach[] TO objbin[].

*assign a name to the email document

doc_chng-obj_name = 'Output'.

doc_chng-obj_descr = 'Old Scheduling lines'."gives the subject line

objtxt-line = 'Regards'.

APPEND objtxt.

objtxt-line = 'Shivaji'.

APPEND objtxt.

*determine the size of the body of the email

DESCRIBE TABLE objtxt LINES tab_lines.

READ TABLE objtxt INDEX tab_lines.

doc_chng-doc_size = ( tab_lines - 1 ) * 255 + STRLEN( objtxt ).

*fill the fields of the packing list for the body of the email

*doc needs no header

objpack-head_start = 1.

objpack-head_num = 0.

*but it has a body

objpack-body_start = 1.

objpack-body_num = tab_lines.

objpack-doc_type = 'RAW'.

APPEND objpack.

*************************************************

*************fill the fields for packing list ***

                          • for attachment ********

*************************************************

DESCRIBE TABLE objbin LINES tab_lines.

*************************************************

*************if it has no header ****************

*************************************************

objpack-transf_bin = 'X'.

objpack-head_start = 1.

objpack-head_num = 1.

*************************************************

*************if it has a body ********

*************************************************

objpack-body_start = 1.

objpack-body_num = tab_lines.

objpack-doc_type = 'XLS'.

objpack-obj_name = 'Attachement'.

objpack-obj_descr = 'file'.

objpack-doc_size = tab_lines * 255.

APPEND objpack.

*************************************************

************fill the mail recipient list*******

*************************************************

reclist-receiver = sy-uname.

**rec_type 'B' indicates sap user ,rec_type 'U' indicates internet user

reclist-rec_type = 'B'.

reclist-express = 'X'.

APPEND reclist.

********************************************************************

            • Function Module to send the data as an excel attachement ****

********************************************************************

CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'

EXPORTING

document_data = doc_chng

put_in_outbox = 'X'

  • IMPORTING

  • SENT_TO_ALL =

  • NEW_OBJECT_ID =

TABLES

packing_list = objpack

  • OBJECT_HEADER =

contents_bin = objbin

contents_txt = objtxt

  • CONTENTS_HEX =

  • OBJECT_PARA =

  • OBJECT_PARB =

receivers = 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

.

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.

Former Member
0 Kudos

Thanks SHIVAJI.

I had copy the code and executed the program. As the result the mail is generated and while opening the attached excel sheet the error message

"This file is not in a recognizable format.

>if you know the file is from another program which is incompatible with Microsoft Office Excel, click Cancel, and then open this file in its original application. If you want to open the file later in Microsoft office excel, save it in a format that is compatible, such as text format.

> If you suspect the file is damaged, click Help for more information about solving the problem.

> if you still want to see what text is contained in the file ,click OK. Then click finish in the Text Import Wizard.

“is generating.

Former Member
0 Kudos

Hi Thomas,

look at my coding in the following thread. I think this might help you.

Regards,

Georg-Stefan