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: 

Convert output display to Excel file and Email to a set of users

Former Member
0 Kudos

Hello All,

I have a rquirement that the report output display has to be Emailed to the users as an Excel attachment.

If anybody has done this or has any suggestions on how to do this, Please let me know.

Thanks and Regards,

Vanitha

3 REPLIES 3

Former Member
0 Kudos

hi,

check this code...

this V_LINE is the record i am sending it to email.

V_LINE(800) TYPE C.

CONCATENATE X_LIKP-VBELN

V_BSTKD

X_LIKP-KUNNR

X_ADDR-STRAS

X_ADDR-NAME1

X_ADDR-NAME2

X_ADDR-NAME3

X_LIPS-EMPST

X_ADDR-TELF1

X_ADDR-REGIO

X_ADDR-PSTLZ

X_LIKP-WADAT

X_LIKP-LFDAT

V_DELV_TIME

V_WT_CHAR INTO V_LINE

SEPARATED BY ','.

*--here i am concatenating all the values to V_LINE with comma separated .

then calling the below form to send it to email receipients.

FORM F_SEND_MAIL .

DATA : L_TABLE_LINES LIKE SY-TABIX, " table index

  • L_TAB TYPE X VALUE 9, " TAB value

L_MANDT TYPE SY-MANDT. " Client

DATA: X_DOC_CHNG LIKE SODOCCHGI1, " document attributes

IT_OBJPACK LIKE SOPCKLSTI1 OCCURS 0 WITH HEADER LINE,

" attachment table

IT_OBJHEAD LIKE SOLISTI1 OCCURS 0 WITH HEADER LINE,

" object header table

IT_OBJBIN LIKE SOLISTI1 OCCURS 0 WITH HEADER LINE,

" binary table

IT_OBJTXT LIKE SOLISTI1 OCCURS 0 WITH HEADER LINE,

IT_RECLIST LIKE SOMLRECI1 OCCURS 0 WITH HEADER LINE.

CLEAR IT_RECLIST.

REFRESH IT_RECLIST.

*-popualate email ids

IT_RECLIST-RECEIVER = 'srikanthm@intelligroup.com'.

IT_RECLIST-REC_TYPE = 'U'.

*-append receiver table

APPEND IT_RECLIST.

CLEAR IT_RECLIST.

*-popualate email ids

IT_RECLIST-RECEIVER = <another email id>.

IT_RECLIST-REC_TYPE = 'U'.

*-append receiver table

APPEND IT_RECLIST.

CLEAR IT_RECLIST.

*--populate document attributes

CLEAR: X_DOC_CHNG.

X_DOC_CHNG-OBJ_NAME = 'HEADING'.

CONCATENATE 'Japan BOL details for the delivery#'

V_VBELN

INTO X_DOC_CHNG-OBJ_DESCR SEPARATED BY SPACE.

*-populate body text

CONCATENATE 'Japan BOL details for the Delivery#'

V_VBELN

',is attached'

INTO it_objtxt SEPARATED BY SPACE.

APPEND IT_OBJTXT.

*-document size

CLEAR : L_TABLE_LINES.

DESCRIBE TABLE IT_OBJTXT LINES L_TABLE_LINES.

READ TABLE IT_OBJTXT INDEX L_TABLE_LINES.

x_doc_chng-doc_size =

( l_table_lines - 1 ) * 255 + STRLEN( it_objtxt ).

*-populate packing list for body text

CLEAR IT_OBJPACK-TRANSF_BIN.

IT_OBJPACK-HEAD_START = 1.

IT_OBJPACK-HEAD_NUM = 0.

IT_OBJPACK-BODY_START = 1.

IT_OBJPACK-BODY_NUM = l_table_lines.

IT_OBJPACK-DOC_TYPE = 'RAW'.

APPEND IT_OBJPACK.

CLEAR IT_OBJPACK.

*-populate object header

  • IT_OBJHEAD = 'Japan BOL'.

CONCATENATE 'Japan BOL-'

SY-DATUM

'-'

SY-UZEIT

'.CSV'

INTO

IT_OBJHEAD.

APPEND IT_OBJHEAD.

CLEAR IT_OBJHEAD.

*--for attachment

*-populate object bin table for attachment

*-column header

  • CONCATENATE 'Document No.'

  • 'Year'

    • 'Item'

    • 'Material No.'

  • 'Error Text'

  • INTO IT_OBJBIN SEPARATED BY ','.

APPEND IT_OBJBIN.

CLEAR IT_OBJBIN.

*--add Internal table lines here, as attachment.

it_objbin = V_LINE.

APPEND IT_OBJBIN.

CLEAR IT_OBJBIN.

*-get total no.of lines of Object table(attachment)

CLEAR : L_TABLE_LINES.

DESCRIBE TABLE IT_OBJBIN LINES L_TABLE_LINES.

*

*-populate object header

IT_OBJHEAD = 'Report'.

APPEND IT_OBJHEAD.

CLEAR IT_OBJHEAD.

*-packing list for attachment

IT_OBJPACK-TRANSF_BIN = 'X'.

IT_OBJPACK-HEAD_START = 1.

IT_OBJPACK-HEAD_NUM = 1.

IT_OBJPACK-BODY_START = 1.

IT_OBJPACK-BODY_NUM = L_TABLE_LINES .

IT_OBJPACK-DOC_TYPE = 'RAW' .

IT_OBJPACK-OBJ_NAME = 'ABCD'.

IT_OBJPACK-OBJ_DESCR = 'ERROR REPORT'.

IT_OBJPACK-DOC_SIZE = L_TABLE_LINES * 255.

APPEND IT_OBJPACK.

CLEAR IT_OBJPACK.

*-Sending the document

CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'

EXPORTING

DOCUMENT_DATA = X_DOC_CHNG

PUT_IN_OUTBOX = 'X'

  • IMPORTING

  • SENT_TO_ALL =

  • NEW_OBJECT_ID =

TABLES

PACKING_LIST = IT_OBJPACK

OBJECT_HEADER = IT_OBJHEAD

CONTENTS_BIN = IT_OBJBIN

CONTENTS_TXT = IT_OBJTXT

  • CONTENTS_HEX =

  • OBJECT_PARA =

  • OBJECT_PARB =

RECEIVERS = IT_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.

Message was edited by: Srikanth Kidambi Maruthi

Former Member
0 Kudos

Hi Vanitha,

go through this code ...it will be useful

REPORT ZSENDEXTERNAL.

DATA: OBJPACK LIKE SOPCKLSTI1 OCCURS 2 WITH HEADER LINE.

DATA: OBJHEAD LIKE SOLISTI1 OCCURS 1 WITH HEADER LINE.

DATA: OBJBIN LIKE SOLISTI1 OCCURS 10 WITH HEADER LINE.

DATA: OBJTXT LIKE SOLISTI1 OCCURS 10 WITH HEADER LINE.

DATA: RECLIST LIKE SOMLRECI1 OCCURS 5 WITH HEADER LINE.

DATA: DOC_CHNG LIKE SODOCCHGI1.

DATA: TAB_LINES LIKE SY-TABIX.

  • Creation of the document to be sent

  • File Name

DOC_CHNG-OBJ_NAME = 'SENDFILE'.

  • Mail Subject

DOC_CHNG-OBJ_DESCR = 'This is Sudheer sending to Sanjeeva'.

  • Mail Contents

OBJTXT = 'Minimum bid : $250000'.

APPEND OBJTXT.

OBJTXT = 'A representation of the pictures up for auction'.

APPEND OBJTXT.

OBJTXT = 'was included as attachment.'.

APPEND OBJTXT.

DESCRIBE TABLE OBJTXT LINES TAB_LINES.

READ TABLE OBJTXT INDEX TAB_LINES.

DOC_CHNG-DOC_SIZE = ( TAB_LINES - 1 ) * 255 + STRLEN( OBJTXT ).

  • Creation of 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.

  • Creation of the document attachment

  • (Assume that the data in OBJBIN is in BMP format)

*OBJBIN = ' \O/ '. APPEND OBJBIN.

*OBJBIN = ' | '. APPEND OBJBIN.

*OBJBIN = ' / \ '. APPEND OBJBIN.

*DESCRIBE TABLE OBJBIN LINES TAB_LINES.

*OBJHEAD = 'PICTURE.BMP'.

*APPEND OBJHEAD.

*

    • Creation of 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 = 'BMP'.

*OBJPACK-OBJ_NAME = 'PICTURE'.

*OBJPACK-OBJ_DESCR = 'Representation of object 138'.

*OBJPACK-DOC_SIZE = TAB_LINES * 255.

*APPEND OBJPACK.

  • Completing the recipient list

RECLIST-RECEIVER = 'sanjeeva.rao@ge.com'.

RECLIST-REC_TYPE = 'U'.

APPEND RECLIST.

*RECLIST-RECEIVER = 'SAPUSERNAME'.

*RECLIST-REC_TYPE = 'P'.

*APPEND RECLIST.

  • Sending the document

CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'

EXPORTING

DOCUMENT_DATA = DOC_CHNG

PUT_IN_OUTBOX = '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 'The document was sent'.

ELSE.

WRITE 'The document could not be sent'.

ENDIF.

ENDLOOP.

WHEN 1.

WRITE: / 'No authorization for sending to the specified number',

'of recipients'.

WHEN 2.

WRITE: / 'Document could not be sent to any recipient'.

WHEN 4.

WRITE: / 'No send authorization'.

WHEN OTHERS.

WRITE: / 'Error occurred while sending'.

try to understand and come up with questions ..

vengal

Former Member
0 Kudos

hi,

is your problem solved or not ???

regards

srikanth