Automailer Program For Sending Output of SAP TCodes in Background
Automailer Program For Sending Output of SAP TCodes in Background
TCodes in Background
There has been requirement from users to get output of some report(s), mailed to them in excel
format(so that they can adjust/formulate the data as they want). And mostly such reports have fixed
periodicity, such as weekly, fortnight or monthly.
The following program performs similar functionality by taking following steps of exection:
1. It takes Transaction code and its variant as input. Also the recipients can be added on the input
screen.
2. Collect the data, export it to excel format, zipped and send to the specified recipients.
The user just need to schedule this program in background, such that it can be scheduled for auto-
mailing.
Note: The following code provide the basic layout of the program, it need to be adjusted/modified as
per your need.
*&---------------------------------------------------------------------*
*& Report ZSD_AUTOMAIL
*&
*&---------------------------------------------------------------------*
*&
*& PURPOSE - TO SEND AUTOMAIL TO DEFINED RECEIPENTS
*&---------------------------------------------------------------------*
REPORT ZSD_AUTOMAIL.
TABLES: ADR6.
** Variables
DATA : GV_FIELDCNT TYPE I,
GV_STR TYPE STRING,
GV_STRMSG TYPE STRING,
GV_XSTRMSG TYPE XSTRING.
** CONSTANTS
CONSTANTS:
CO_TAB TYPE C VALUE CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB,
CO_CRET TYPE C VALUE CL_ABAP_CHAR_UTILITIES=>CR_LF.
** Selection screen
SELECTION-SCREEN : BEGIN OF BLOCK B WITH FRAME TITLE TEXT-001.
*** Initialization
INITIALIZATION.
SELECT SINGLE PGMNA INTO L_PRGNM FROM TSTC WHERE TCODE = P_TCODE.
IF SY-SUBRC <> ''.
MESSAGE 'Please provide correct Transaction Code.' TYPE 'E'.
ENDIF.
PERFORM GET_REPORT_OUTPUT.
PERFORM EXCEL_ZIP_SEND.
*----------------------------------------------------------------------*
***INCLUDE ZSD_SALES_REGISTER_ROUTINES .
*----------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*& Form GET_REPORT_OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM GET_REPORT_OUTPUT .
IF WA_TEXT-LINE NP '-*'.
REPLACE ALL OCCURRENCES OF '|' IN WA_TEXT WITH CO_SEPARATER.
CONCATENATE GV_STRMSG WA_TEXT CO_NEWLINE INTO GV_STRMSG.
ENDIF.
ENDLOOP.
REFRESH IT_TEXT.
REFRESH IT_BIN_CON.
CLEAR : LV_BDYMSG .
CONCATENATE 'Billing Information From' L_PDATE 'To' L_CDATE INTO L_BODY SEPARATED
BY ' '.
LV_BDYMSG = L_BODY.
CONCATENATE 'Cheque Details From' L_PDATE 'To' L_CDATE INTO L_BODY SEPARATED BY '
'.
LV_BDYMSG = L_BODY.
ENDIF.
TRY.
"
CLEAR SEND_REQUEST .
SEND_REQUEST = CL_BCS=>CREATE_PERSISTENT( ).
LOOP AT SO_RECP.
"convert receipient to internet format and then add
RECIPIENT = CL_CAM_ADDRESS_BCS=>CREATE_INTERNET_ADDRESS( SO_RECP-LOW ).
CALL METHOD SEND_REQUEST->ADD_RECIPIENT
EXPORTING
I_RECIPIENT = RECIPIENT
I_EXPRESS = 'X'.
ENDLOOP.