Skip to Content
0
Former Member
Mar 13, 2007 at 06:12 AM

to add number of senders mail addresses

11 Views

in the following code how there is one sender address how do i make it to 3 senders i mean add the number of senders

REPORT ZSPOOL5 NO STANDARD PAGE HEADING.

PARAMETER: P_EMAIL1 LIKE SOMLRECI1-RECEIVER,

P_SENDER LIKE SOMLRECI1-RECEIVER,

P_DELSPL AS CHECKBOX.

*ranges:

*DATA DECLARATION

DATA: GD_RECSIZE TYPE I.

  • Spool IDs

TYPES: BEGIN OF T_TBTCP.

INCLUDE STRUCTURE TBTCP.

TYPES: END OF T_TBTCP.

DATA: IT_TBTCP TYPE STANDARD TABLE OF T_TBTCP INITIAL SIZE 0,

WA_TBTCP TYPE T_TBTCP.

  • Job Runtime Parameters

DATA: GD_EVENTID LIKE TBTCM-EVENTID,

GD_EVENTPARM LIKE TBTCM-EVENTPARM,

GD_EXTERNAL_PROGRAM_ACTIVE LIKE TBTCM-XPGACTIVE,

GD_JOBCOUNT LIKE TBTCM-JOBCOUNT,

GD_JOBNAME LIKE TBTCM-JOBNAME,

GD_STEPCOUNT LIKE TBTCM-STEPCOUNT,

GD_ERROR TYPE SY-SUBRC,

GD_RECIEVER TYPE SY-SUBRC.

DATA: W_RECSIZE TYPE I.

DATA: GD_SUBJECT LIKE SODOCCHGI1-OBJ_DESCR,

IT_MESS_BOD LIKE SOLISTI1 OCCURS 0 WITH HEADER LINE,

IT_MESS_ATT LIKE SOLISTI1 OCCURS 0 WITH HEADER LINE,

GD_SENDER_TYPE LIKE SOEXTRECI1-ADR_TYP,

GD_ATTACHMENT_DESC TYPE SO_OBJ_NAM,

GD_ATTACHMENT_NAME TYPE SO_OBJ_DES.

  • Spool to PDF conversions

DATA: GD_SPOOL_NR LIKE TSP01-RQIDENT,

GD_DESTINATION LIKE RLGRAP-FILENAME,

GD_BYTECOUNT LIKE TST01-DSIZE,

GD_BUFFER TYPE STRING.

  • Binary store for PDF

DATA: BEGIN OF IT_PDF_OUTPUT OCCURS 0.

INCLUDE STRUCTURE TLINE.

DATA: END OF IT_PDF_OUTPUT.

CONSTANTS:C_DEV LIKE SY-SYSID VALUE 'DEV',

C_NO(1) TYPE C VALUE ' ',

C_DEVICE(4) TYPE C VALUE 'LOCL'.

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

*START-OF-SELECTION.

START-OF-SELECTION.

  • Write statement to represent report output. Spool request is created

  • if write statement is executed in background. This could also be an

  • ALV grid which would be converted to PDF without any extra effort

WRITE 'Hello World'.

NEW-PAGE.

COMMIT WORK.

  • NEW-PAGE PRINT OFF.

IF SY-BATCH EQ 'X'.

PERFORM GET_JOB_DETAILS.

PERFORM OBTAIN_SPOOL_ID.

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

  • Alternative way could be to submit another program and store spool

  • id into memory.

*submit ZSPOOLTOPDF2

  • to sap-spool

  • spool parameters %_print

  • archive parameters %_print

  • without spool dynpro

  • and return.

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

  • Get spool id from program called above

  • IMPORT w_spool_nr FROM MEMORY ID 'SPOOLTOPDF'.

PERFORM CONVERT_SPOOL_TO_PDF.

PERFORM PROCESS_EMAIL.

IF P_DELSPL EQ 'X'.

PERFORM DELETE_SPOOL.

ENDIF.

IF SY-SYSID = C_DEV.

WAIT UP TO 5 SECONDS.

SUBMIT RSCONN01 WITH MODE = 'INT'

WITH OUTPUT = 'X'

AND RETURN.

ENDIF.

ELSE.

SKIP.

WRITE:/ 'Program must be executed in background in-order for spool',

'request to be created.'.

ENDIF.

----


  • FORM obtain_spool_id *

----


FORM OBTAIN_SPOOL_ID.

CHECK NOT ( GD_JOBNAME IS INITIAL ).

CHECK NOT ( GD_JOBCOUNT IS INITIAL ).

SELECT * FROM TBTCP

INTO TABLE IT_TBTCP

WHERE JOBNAME = GD_JOBNAME

AND JOBCOUNT = GD_JOBCOUNT

AND STEPCOUNT = GD_STEPCOUNT

AND LISTIDENT <> '0000000000'

ORDER BY JOBNAME

JOBCOUNT

STEPCOUNT.

READ TABLE IT_TBTCP INTO WA_TBTCP INDEX 1.

IF SY-SUBRC = 0.

  • MESSAGE S004(ZDD) WITH GD_SPOOL_NR.

GD_SPOOL_NR = WA_TBTCP-LISTIDENT.

  • MESSAGE S004(ZDD) WITH GD_SPOOL_NR.

ELSE.

MESSAGE S005(ZDD).

ENDIF.

ENDFORM. "obtain_spool_id

----


  • FORM get_job_details *

----


FORM GET_JOB_DETAILS.

  • Get current job details

CALL FUNCTION 'GET_JOB_RUNTIME_INFO'

IMPORTING

EVENTID = GD_EVENTID

EVENTPARM = GD_EVENTPARM

EXTERNAL_PROGRAM_ACTIVE = GD_EXTERNAL_PROGRAM_ACTIVE

JOBCOUNT = GD_JOBCOUNT

JOBNAME = GD_JOBNAME

STEPCOUNT = GD_STEPCOUNT

EXCEPTIONS

NO_RUNTIME_INFO = 1

OTHERS = 2.

ENDFORM. "get_job_details

----


  • FORM convert_spool_to_pdf *

----


FORM CONVERT_SPOOL_TO_PDF.

CALL FUNCTION 'CONVERT_ABAPSPOOLJOB_2_PDF'

EXPORTING

SRC_SPOOLID = GD_SPOOL_NR

NO_DIALOG = C_NO

DST_DEVICE = C_DEVICE

IMPORTING

PDF_BYTECOUNT = GD_BYTECOUNT

TABLES

PDF = IT_PDF_OUTPUT

EXCEPTIONS

ERR_NO_ABAP_SPOOLJOB = 1

ERR_NO_SPOOLJOB = 2

ERR_NO_PERMISSION = 3

ERR_CONV_NOT_POSSIBLE = 4

ERR_BAD_DESTDEVICE = 5

USER_CANCELLED = 6

ERR_SPOOLERROR = 7

ERR_TEMSEERROR = 8

ERR_BTCJOB_OPEN_FAILED = 9

ERR_BTCJOB_SUBMIT_FAILED = 10

ERR_BTCJOB_CLOSE_FAILED = 11

OTHERS = 12.

CHECK SY-SUBRC = 0.

  • Transfer the 132-long strings to 255-long strings

LOOP AT IT_PDF_OUTPUT.

TRANSLATE IT_PDF_OUTPUT USING ' ~'.

CONCATENATE GD_BUFFER IT_PDF_OUTPUT INTO GD_BUFFER.

ENDLOOP.

TRANSLATE GD_BUFFER USING '~ '.

DO.

IT_MESS_ATT = GD_BUFFER.

APPEND IT_MESS_ATT.

SHIFT GD_BUFFER LEFT BY 255 PLACES.

IF GD_BUFFER IS INITIAL.

EXIT.

ENDIF.

ENDDO.

ENDFORM. "convert_spool_to_pdf

----


  • FORM process_email *

----


FORM PROCESS_EMAIL.

DESCRIBE TABLE IT_MESS_ATT LINES GD_RECSIZE.

CHECK GD_RECSIZE > 0.

PERFORM SEND_EMAIL USING P_EMAIL1.

  • perform send_email using p_email2.

ENDFORM. "process_email

----


  • FORM send_email *

----


  • --> p_email *

----


FORM SEND_EMAIL USING P_EMAIL.

CHECK NOT ( P_EMAIL IS INITIAL ).

REFRESH IT_MESS_BOD.

  • Default subject matter

GD_SUBJECT = 'Subject'.

GD_ATTACHMENT_DESC = 'Attachname'.

  • CONCATENATE 'attach_name' ' ' INTO gd_attachment_name.

IT_MESS_BOD = 'Message Body text, line 1'.

APPEND IT_MESS_BOD.

IT_MESS_BOD = 'Message Body text, line 2...'.

APPEND IT_MESS_BOD.

  • If no sender specified - default blank

IF P_SENDER EQ SPACE.

GD_SENDER_TYPE = SPACE.

ELSE.

GD_SENDER_TYPE = 'INT'.

ENDIF.

  • Send file by email as .xls speadsheet

PERFORM SEND_FILE_AS_EMAIL_ATTACHMENT

TABLES IT_MESS_BOD

IT_MESS_ATT

USING P_EMAIL

'Example .xls documnet attachment'

'PDF'

GD_ATTACHMENT_NAME

GD_ATTACHMENT_DESC

P_SENDER

GD_SENDER_TYPE

CHANGING GD_ERROR

GD_RECIEVER.

ENDFORM. "send_email

----


  • FORM delete_spool *

----


FORM DELETE_SPOOL.

DATA: LD_SPOOL_NR TYPE TSP01_SP0R-RQID_CHAR.

LD_SPOOL_NR = GD_SPOOL_NR.

CHECK P_DELSPL <> C_NO.

CALL FUNCTION 'RSPO_R_RDELETE_SPOOLREQ'

EXPORTING

SPOOLID = LD_SPOOL_NR.

ENDFORM. "delete_spool

&----


*& Form SEND_FILE_AS_EMAIL_ATTACHMENT

&----


  • Send email

----


FORM SEND_FILE_AS_EMAIL_ATTACHMENT TABLES IT_MESSAGE

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

DATA: T_PACKING_LIST LIKE SOPCKLSTI1 OCCURS 0 WITH HEADER LINE,

T_CONTENTS LIKE SOLISTI1 OCCURS 0 WITH HEADER LINE,

T_RECEIVERS LIKE SOMLRECI1 OCCURS 0 WITH HEADER LINE,

T_ATTACHMENT LIKE SOLISTI1 OCCURS 0 WITH HEADER LINE,

T_OBJECT_HEADER LIKE SOLISTI1 OCCURS 0 WITH HEADER LINE,

W_CNT TYPE I,

W_SENT_ALL(1) TYPE C,

W_DOC_DATA LIKE SODOCCHGI1.

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[] = IT_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.

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-OBJ_DESCR = LD_ATTDESCRIPTION.

T_PACKING_LIST-OBJ_NAME = LD_ATTFILENAME.

T_PACKING_LIST-DOC_SIZE = T_PACKING_LIST-BODY_NUM * 255.

APPEND T_PACKING_LIST.

  • Add the recipients email address

CLEAR T_RECEIVERS.

REFRESH T_RECEIVERS.

T_RECEIVERS-RECEIVER = LD_EMAIL.

T_RECEIVERS-REC_TYPE = 'U'.

T_RECEIVERS-COM_TYPE = 'INT'.

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.

  • Populate zerror return code

LD_ERROR = SY-SUBRC.

  • Populate zreceiver return code

LOOP AT T_RECEIVERS.

LD_RECEIVER = T_RECEIVERS-RETRN_CODE.

ENDLOOP.

ENDFORM. "send_file_as_email_attachment