SAP R/3 форум ABAP консультантов
Russian ABAP Developer's Club

Home - FAQ - Search - Memberlist - Usergroups - Profile - Log in to check your private messages - Register - Log in - English
Blogs - Weblogs News

Sending Excel at attachments



 
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> Programming Techniques | Приемы программирования -> Mail
View previous topic :: View next topic  
Author Message
admin
Администратор
Администратор



Joined: 01 Sep 2007
Posts: 1639

PostPosted: Fri Nov 07, 2008 6:18 pm    Post subject: Sending Excel at attachments Reply with quote

Code:
REPORT  zpsendmailexternal .

*This table requires information about how the data in the
*tables OBJECT_HEADER, CONTENTS_BIN and CONTENTS_TXT are
*to be distributed to the documents and its attachments.

DATA: objpack LIKE sopcklsti1 OCCURS 2 WITH HEADER LINE.

*This table must contain the summarized data dependent on each object
*type.
*SAPscript objects store information here about forms and styles,
*for example. Excel list viewer objects store the number of rows and
*columns
*amongst other things and PC objects store their original file name.


DATA: objhead LIKE solisti1 OCCURS 1 WITH HEADER LINE.
*CREATION OF INTERNAL TABLE
DATA : BEGIN OF itobjbin OCCURS 10 ,
vbeln TYPE vbrp-vbeln,
matnr TYPE vbrp-matnr,
werks TYPE vbrp-werks,
fktyp LIKE vbrk-fktyp,
END OF itobjbin .


*This table must contain the summarized content of the objects
*identified as binary objects.

*DATA: OBJBIN LIKE SOLISTI1 OCCURS 10 WITH HEADER LINE.
DATA: objbin TYPE STANDARD TABLE OF solisti1 INITIAL SIZE 0
WITH HEADER LINE.

DATA: wa_itobjbin LIKE itobjbin .

*This table must contain the summarized content of the objects
*identified as ASCII objects.

DATA: objtxt LIKE solisti1 OCCURS 10 WITH HEADER LINE.

*This table must contain the document recipients.
DATA: reclist LIKE somlreci1 OCCURS 5 WITH HEADER LINE.

*This structure must contain the attributes of the document to be sent.
DATA: doc_chng LIKE sodocchgi1.
DATA: tab_lines LIKE sy-tabix.
DATA : v_fktyp LIKE vbrk-fktyp.

*Creating the document to be sent
doc_chng-obj_name = 'OFFER'. " input contains the attributes of the
*document to be sent

doc_chng-obj_descr = 'EMAIL WITH EXCEL DOWNLOAD'. "input contains
*title/subject of the document

*BODY OF THE MAIL
objtxt = 'Hi'.
APPEND objtxt .
objtxt = 'Test for excel download'.
APPEND objtxt.
objtxt = 'Below is the attachment with Billing Document Details'.
APPEND objtxt.
objtxt = 'Regards'.
APPEND objtxt.

DESCRIBE TABLE objtxt LINES tab_lines.

READ TABLE objtxt INDEX tab_lines.

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

*Creating the entry for the compressed document
CLEAR objpack-transf_bin.
objpack-head_start = 1.
objpack-head_num = 0.
objpack-body_start = 1.
objpack-body_num = tab_lines.
objpack-doc_type = 'RAW'.
APPEND objpack.

*Creating the document attachment
*(Assume the data in OBJBIN are given in BMP format)

SELECT vbeln matnr werks
FROM vbrp INTO TABLE itobjbin
UP TO 10 ROWS
WHERE werks GE '1000'.

LOOP AT itobjbin.
SELECT SINGLE fktyp INTO v_fktyp FROM vbrk WHERE vbeln = itobjbin-vbeln.
  MOVE v_fktyp TO itobjbin-fktyp.
  MODIFY itobjbin.
ENDLOOP.

PERFORM build_xls_data_table .

DESCRIBE TABLE objbin LINES tab_lines.

objhead = 'ABC.XLS'. APPEND objhead.

*Creating the entry for the compressed attachment

objpack-transf_bin = 'X'.

objpack-head_start = 1.

objpack-head_num = 1.

objpack-body_start = 1.

objpack-body_num = tab_lines.

objpack-doc_type = 'XLS'.

objpack-obj_name = 'ATTACHMENT'.

objpack-obj_descr = 'XLS'.

objpack-doc_size = tab_lines * 255.

APPEND objpack..


*Entering names in the distribution list


reclist-receiver = 'dev02'.

reclist-rec_type = 'b'.

APPEND reclist.


*Sending the document


CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
     EXPORTING
          document_data              = doc_chng
          put_in_outbox              = 'X'
          commit_work                = 'X'
     TABLES
          packing_list               = objpack
          object_header              = objhead
          contents_bin               = objbin
          contents_txt               = objtxt
          receivers                  = reclist
     EXCEPTIONS
          too_many_receivers         = 1
          document_not_sent          = 2
          operation_no_authorization = 4
          OTHERS                     = 99.

CASE sy-subrc.

  WHEN 0.

    WRITE: / 'Result of the send process:'.

    LOOP AT reclist.

      WRITE: / reclist-receiver(48), ':'.

      IF reclist-retrn_code = 0.

        WRITE 'sent successfully'.

      ELSE.

        WRITE 'not sent'.

      ENDIF.

    ENDLOOP.

  WHEN 1.

    WRITE: / 'no authorization to send to the specified number of',
    'recipients!'.

  WHEN 2.

    WRITE: / 'document could not be sent to any of the recipients!'.

  WHEN 4.

    WRITE: / 'no authorization to send !'.

  WHEN OTHERS.

    WRITE: / 'error occurred during sending !'.

ENDCASE.

**---------------------------------------------------------------------
** Form build_xls_data_table
**---------------------------------------------------------------------
*text
*----------------------------------------------------------------------
*
*--> p1 text
*<-- p2 text
*----------------------------------------------------------------------
FORM build_xls_data_table .

  DATA: con_cret LIKE cl_abap_char_utilities=>cr_lf. "OK for non Unicode
*con_tab TYPE C VALUE '09'. "OK for non Unicode
  DATA:con_tab LIKE cl_abap_char_utilities=>newline.

CONCATENATE 'Billing Document' 'Material Number' 'Plant' 'Billing
category' ' ' INTO objbin SEPARATED BY con_tab.

  CONCATENATE con_cret objbin INTO objbin.
  APPEND objbin.

  LOOP AT itobjbin .
CONCATENATE itobjbin-vbeln itobjbin-matnr itobjbin-werks itobjbin-fktyp
    INTO objbin SEPARATED BY con_tab.
    CONCATENATE con_cret objbin INTO objbin.
    APPEND objbin.
  ENDLOOP.
ENDFORM.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> Programming Techniques | Приемы программирования -> Mail All times are GMT + 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


All product names are trademarks of their respective companies. SAPNET.RU websites are in no way affiliated with SAP AG.
SAP, SAP R/3, R/3 software, mySAP, ABAP, BAPI, xApps, SAP NetWeaver and any other are registered trademarks of SAP AG.
Every effort is made to ensure content integrity. Use information on this site at your own risk.