Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

How to send an ALV Grid Report to SAP user mail in excel format attched wit

Hi ,this is some urgent requirement,

Can anybody tell me How to send an ALV Grid Report to SAP inbox in excel format which should be attached with the mail.

Tags:
Former Member
Former Member replied

See the following ex:

***Sending mail to the receipients

if not it_final[] is initial.

PERFORM SUB_GET_MAIL_ADDR.

  • Populate table with detaisl to be entered into .xls file

PERFORM BUILD_XLS_DATA_TABLE.

PERFORM POPULATE_EMAIL_MESSAGE_BODY.

      • Send file by email as .xls speadsheet

PERFORM SEND_FILE_AS_EMAIL_ATTACHMENT

TABLES IT_MESSAGE

IT_ATTACH

USING P_EMAIL

'Sales Register Report - Set Top Box / Accessories'

'XLS'

'SSTB'

' '

' '

' '

CHANGING GD_ERROR

GD_RECIEVER.

  • Instructs mail send program for SAPCONNECT to send email(rsconn01)

PERFORM INITIATE_MAIL_EXECUTE_PROGRAM.

&----


*& Form BUILD_XLS_DATA_TABLE

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM BUILD_XLS_DATA_TABLE .

data: wa_itab like it_final.

CONSTANTS:

CON_TAB TYPE C VALUE CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB,

CON_CRET TYPE C VALUE CL_ABAP_CHAR_UTILITIES=>CR_LF.

CONCATENATE 'Business Place' 'Region Code' 'Region' 'Branch Code'

'Branch' 'Material Desc' 'Area off Code'

'Area Name' 'Zone code' 'Zone Name' 'Cust No' 'Cust Name'

'Bill Doc No' 'Bill Date' 'Base Val' 'Total Val' 'Quantity'

INTO IT_ATTACH SEPARATED BY CON_TAB.

CONCATENATE CON_CRET IT_ATTACH INTO IT_ATTACH.

APPEND IT_ATTACH.

LOOP AT IT_FINAL INTO WA_ITAB.

CONCATENATE WA_ITAB-BUSINESS_PLACE

WA_ITAB-KVGR1

WA_ITAB-REGION

WA_ITAB-VKBUR

WA_ITAB-SALES_OFF

WA_ITAB-ARKTX

WA_ITAB-vkgrp

WA_ITAB-sales_grp

WA_ITAB-bzirk

WA_ITAB-zone

WA_ITAB-kunnr

WA_ITAB-name

WA_ITAB-vbeln

WA_ITAB-fkdat

WA_ITAB-base_value

WA_ITAB-total_value

WA_ITAB-fkimg

INTO IT_ATTACH SEPARATED BY CON_TAB.

CONCATENATE CON_CRET IT_ATTACH INTO IT_ATTACH.

APPEND IT_ATTACH.

ENDLOOP.

ENDFORM. " BUILD_XLS_DATA_TABLE

&----


*& Form POPULATE_EMAIL_MESSAGE_BODY

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM POPULATE_EMAIL_MESSAGE_BODY .

REFRESH IT_MESSAGE.

CONCATENATE SY-DATUM6(2) '/' SY-DATUM4(2) '/' SY-DATUM+0(4) INTO G_DATE.

IT_MESSAGE = 'Please find attached excel sheet.'.

APPEND IT_MESSAGE.

ENDFORM. " POPULATE_EMAIL_MESSAGE_BODY

&----


*& Form SEND_FILE_AS_EMAIL_ATTACHMENT

&----


  • Send email

----


FORM SEND_FILE_AS_EMAIL_ATTACHMENT TABLES PIT_MESSAGE

PIT_ATTACH

USING P_EMAIL

P_MTITLE

P_FORMAT

P_FILENAME

P_ATTDESCRIPTION

P_SENDER_ADDRESS

P_SENDER_ADDRES_TYPE

CHANGING P_ERROR

P_RECIEVER.

DATA: LD_ERROR TYPE SY-SUBRC,

LD_RECIEVER TYPE SY-SUBRC,

LD_MTITLE LIKE SODOCCHGI1-OBJ_DESCR,

LD_EMAIL LIKE SOMLRECI1-RECEIVER,

LD_FORMAT TYPE SO_OBJ_TP ,

LD_ATTDESCRIPTION TYPE SO_OBJ_NAM ,

LD_ATTFILENAME TYPE SO_OBJ_DES ,

LD_SENDER_ADDRESS LIKE SOEXTRECI1-RECEIVER,

LD_SENDER_ADDRESS_TYPE LIKE SOEXTRECI1-ADR_TYP,

LD_RECEIVER LIKE SY-SUBRC.

LD_EMAIL = P_EMAIL.

LD_MTITLE = P_MTITLE.

LD_FORMAT = P_FORMAT.

LD_ATTDESCRIPTION = P_ATTDESCRIPTION.

LD_ATTFILENAME = P_FILENAME.

LD_SENDER_ADDRESS = P_SENDER_ADDRESS.

LD_SENDER_ADDRESS_TYPE = P_SENDER_ADDRES_TYPE.

  • Fill the document data.

W_DOC_DATA-DOC_SIZE = 1.

  • Populate the subject/generic message attributes

W_DOC_DATA-OBJ_LANGU = SY-LANGU.

W_DOC_DATA-OBJ_NAME = 'SAPRPT'.

W_DOC_DATA-OBJ_DESCR = LD_MTITLE .

W_DOC_DATA-SENSITIVTY = 'F'.

  • Fill the document data and get size of attachment

CLEAR W_DOC_DATA.

READ TABLE IT_ATTACH INDEX W_CNT.

W_DOC_DATA-DOC_SIZE =

( W_CNT - 1 ) * 255 + STRLEN( IT_ATTACH ).

W_DOC_DATA-OBJ_LANGU = SY-LANGU.

W_DOC_DATA-OBJ_NAME = 'SAPRPT'.

W_DOC_DATA-OBJ_DESCR = LD_MTITLE.

W_DOC_DATA-SENSITIVTY = 'F'.

CLEAR T_ATTACHMENT.

REFRESH T_ATTACHMENT.

T_ATTACHMENT[] = PIT_ATTACH[].

  • Describe the body of the message

CLEAR T_PACKING_LIST.

REFRESH T_PACKING_LIST.

T_PACKING_LIST-TRANSF_BIN = SPACE.

T_PACKING_LIST-HEAD_START = 1.

T_PACKING_LIST-HEAD_NUM = 0.

T_PACKING_LIST-BODY_START = 1.

T_PACKING_LIST-OBJ_NAME = 'stb'.

DESCRIBE TABLE IT_MESSAGE LINES T_PACKING_LIST-BODY_NUM.

T_PACKING_LIST-DOC_TYPE = 'RAW'.

APPEND T_PACKING_LIST.

  • Create attachment notification

T_PACKING_LIST-TRANSF_BIN = 'X'.

T_PACKING_LIST-HEAD_START = 1.

T_PACKING_LIST-HEAD_NUM = 1.

T_PACKING_LIST-BODY_START = 1.

DESCRIBE TABLE T_ATTACHMENT LINES T_PACKING_LIST-BODY_NUM.

  • T_PACKING_LIST-DOC_TYPE = LD_FORMAT.

T_PACKING_LIST-DOC_TYPE = 'XLS'.

  • T_PACKING_LIST-OBJ_DESCR = LD_ATTDESCRIPTION.

T_PACKING_LIST-OBJ_DESCR = 'Sales_STB'.

  • T_PACKING_LIST-OBJ_NAME = LD_ATTFILENAME.

T_PACKING_LIST-OBJ_NAME = 'stb'.

T_PACKING_LIST-DOC_SIZE = T_PACKING_LIST-BODY_NUM * 255.

APPEND T_PACKING_LIST.

T_RECEIVERS-RECEIVER = g_user. "User name.

T_RECEIVERS-REC_TYPE = 'U'.

  • T_RECEIVERS-COM_TYPE = 'INT'.

  • T_RECEIVERS-COPY = 'X'.

  • T_RECEIVERS-NOTIF_DEL = 'X'.

  • T_RECEIVERS-NOTIF_NDEL = 'X'.

APPEND T_RECEIVERS.

CALL FUNCTION 'SO_DOCUMENT_SEND_API1'

EXPORTING

DOCUMENT_DATA = W_DOC_DATA

PUT_IN_OUTBOX = 'X'

SENDER_ADDRESS = LD_SENDER_ADDRESS

SENDER_ADDRESS_TYPE = LD_SENDER_ADDRESS_TYPE

COMMIT_WORK = 'X'

IMPORTING

SENT_TO_ALL = W_SENT_ALL

TABLES

PACKING_LIST = T_PACKING_LIST

CONTENTS_BIN = T_ATTACHMENT

CONTENTS_TXT = IT_MESSAGE

RECEIVERS = T_RECEIVERS

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.

0 View this answer in context
Not what you were looking for? View more on this topic or Ask a question