Skip to Content
author's profile photo Former Member
Former Member

sending the mail with PDF attachment

hi all,

can anyone tell me how to achieve sending mail with PDF attachment from the ALV report?

if any information about how to send from spool to mail with PDF, that would also be useful.

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

2 Answers

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Dec 10, 2005 at 10:40 AM

    Hi

    see here perhaps it's helpfull for you:

    http://www.sapdevelopment.co.uk/reporting/rep_spooltopdf.htm

    Max

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Dec 10, 2005 at 10:50 AM
    REPORT ZMAILOUTPUT
        MESSAGE-ID ZZ.
    
    *----------------------------------------------------------------------*
    *  CONSTANTS                                                           *
    *----------------------------------------------------------------------*
    
    CONSTANTS : C_X(1)      TYPE C VALUE 'X',      " For constant value
                C_OTF(3)    TYPE C VALUE 'OTF',    " For format
                C_U(1)      TYPE C VALUE 'U'.      " Mail Option
    
    *----------------------------------------------------------------------*
    *  VARIABLES                                                           *
    *----------------------------------------------------------------------*
    
    DATA : V_RQIDENT  TYPE TSP01-RQIDENT,  " For Spool Number
           V_RQCLIENT TYPE TSP01-RQCLIENT, " For Client
           V_RQO1NAME TYPE TSP01-RQO1NAME, " For Object name
           V_SPOOL    TYPE TSP01-RQIDENT,  " For Spool Number
           V_SPOOL1   TYPE TSP01-RQIDENT.  " For Spool Number
    
    *----------------------------------------------------------------------*
    *  FLAGS                                                               *
    *----------------------------------------------------------------------*
    
    DATA : F_SPOOL TYPE C.
    
    *----------------------------------------------------------------------*
    *   INTERNAL TABLES                                                    *
    *----------------------------------------------------------------------*
    
    * Internal table for sending mails
    DATA: IT_PDF          LIKE TLINE      OCCURS 10 WITH HEADER LINE,
          IT_XI_PDF       LIKE TLINE      OCCURS 0  WITH HEADER LINE,
          IT_HTML         LIKE SOLISTI1   OCCURS 0  WITH HEADER LINE,
          IT_XI_TEMP      LIKE BAPIQCMIME OCCURS 0  WITH HEADER LINE,
          IT_XI_MIME(255) TYPE C          OCCURS 0  WITH HEADER LINE.
    
    * For sending mail
    DATA: IT_OBJPACK LIKE SOPCKLSTI1 OCCURS 2 WITH HEADER LINE.
    
    * Internal table for Single List with Column Length 255
    DATA : IT_OBJBIN LIKE SOLISTI1 OCCURS 10 WITH HEADER LINE.
    
    * Internal table for Single List with Column Length 255
    DATA : IT_OBJTXT LIKE SOLISTI1 OCCURS 10 WITH HEADER LINE.
    
    * Internal table for Structure of the API Recipient List
    DATA : IT_RECLIST LIKE SOMLRECI1 OCCURS 5 WITH HEADER LINE.
    
    * Structure of the API Recipient List
    DATA: X_DOC_CHNG LIKE SODOCCHGI1.
    
    * Internal table for storing the variants
    DATA : BEGIN OF IT_VARIANT1 OCCURS 0,
            VARIANT LIKE VARID-VARIANT,
           END   OF IT_VARIANT1.
    
    * Internal table to store variants for the programs
    DATA: IT_VARIANT2 LIKE IT_VARIANT1 OCCURS 0 WITH HEADER LINE.
    
    * Internal table for storing the selected values
    DATA IT_RETURN TYPE DDSHRETVAL OCCURS 0 WITH HEADER LINE.
    
    * Internal table for storing the mail-ids
    DATA : BEGIN OF IT_MAILID OCCURS 0,
            KOKRS LIKE CSKS-KOKRS,
            KOSTL LIKE CSKS-KOSTL,
            DATBI LIKE CSKS-DATBI,
            TELX1 LIKE CSKS-TELX1,
           END   OF IT_MAILID.
    
    * Internal table for storing the mail-ids
    DATA : IT_MAILID1 LIKE IT_MAILID OCCURS 0 WITH HEADER LINE.
    
    *----------------------------------------------------------------------*
    *   SELECTION SCREEN                                                   *
    *----------------------------------------------------------------------*
    DATA : V_CHAR TYPE CHAR50.
    
    SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001.
    SELECT-OPTIONS: S_EMAIL FOR V_CHAR  NO INTERVALS
                    LOWER CASE
                    NO-DISPLAY.
    SELECT-OPTIONS: S_EMAIL1 FOR V_CHAR  NO INTERVALS
                    LOWER CASE
                    NO-DISPLAY.
    SELECTION-SCREEN END OF BLOCK B1.
    
    SELECTION-SCREEN BEGIN OF BLOCK A1 WITH FRAME TITLE TEXT-028.
    
    SELECTION-SCREEN BEGIN OF LINE.
    PARAMETERS : P_C1 AS CHECKBOX.
    SELECTION-SCREEN COMMENT 3(66) TEXT-026 FOR FIELD P_C1.
    SELECTION-SCREEN END OF LINE.
    PARAMETERS : P_SET LIKE TSP1D-PAPART MATCHCODE OBJECT ZH_TSP1D.
    SELECTION-SCREEN SKIP 1.
    
    PARAMETERS : P_VARA1 TYPE RS38M-SELSET.
    SELECTION-SCREEN END OF BLOCK A1.
    
    SELECTION-SCREEN BEGIN OF BLOCK A2 WITH FRAME TITLE TEXT-029.
    
    SELECTION-SCREEN BEGIN OF LINE.
    PARAMETERS : P_C2 AS CHECKBOX.
    SELECTION-SCREEN COMMENT 3(56) TEXT-027 FOR FIELD P_C1.
    SELECTION-SCREEN END OF LINE.
    PARAMETERS : P_SET1 LIKE TSP1D-PAPART MATCHCODE OBJECT ZH_TSP1D.
    SELECTION-SCREEN SKIP 1.
    
    PARAMETERS : P_VARA2 TYPE RS38M-SELSET.
    SELECTION-SCREEN END OF BLOCK A2.
    
    *---------------------------------------------------------------------*
    * AT SELECTION SCREEN ON VALUE REQUEST
    *---------------------------------------------------------------------*
    AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_VARA1.
    
    * For fetching the variants available for the program
      PERFORM FETCH_VARIANTS.
    
    AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_VARA2.
    
    * For fetching the variants available for the program
      PERFORM FETCH_VARIANTS1.
    
    *---------------------------------------------------------------------*
    * AT SELECTION SCREEN
    *---------------------------------------------------------------------*
    AT SELECTION-SCREEN.
    
    * For Validation
      PERFORM VALIDATION.
    
    *----------------------------------------------------------------------*
    *  START OF SELECTION                                                  *
    *----------------------------------------------------------------------*
    START-OF-SELECTION.
    
    * To get the output data and mail
      PERFORM FETCH_DATA.
    
    *----------------------------------------------------------------------*
    *  END OF SELECTION                                                    *
    *----------------------------------------------------------------------*
    END-OF-SELECTION.
    
      IF F_SPOOL = C_X.
        MESSAGE E000 WITH 'Spool Not Generated'(060).
      ENDIF.
    
    *&---------------------------------------------------------------------*
    *&      Form  fetch_data
    *&---------------------------------------------------------------------*
    *       To get the output data and mail
    *----------------------------------------------------------------------*
    FORM FETCH_DATA .
    
    * To send the output to spool
      PERFORM GENERATE_SPOOL.
    
    ENDFORM.                    " fetch_data
    
    *&---------------------------------------------------------------------*
    *&      Form  generate_spool
    *&---------------------------------------------------------------------*
    *       To send the output to spool
    *----------------------------------------------------------------------*
    FORM GENERATE_SPOOL .
    
      DATA: L_PARAMS LIKE PRI_PARAMS,
            L_DAYS(1)  TYPE N VALUE 2,
            L_COUNT(3) TYPE N VALUE 1,
            L_VALID    TYPE C,
            L_VALID1   TYPE C,
            L_PARAMS1  LIKE PRI_PARAMS.
    
      DATA: L_DEVICE TYPE USR01-SPLD.
    
    *Get the printer name for the user
      SELECT SINGLE SPLD INTO L_DEVICE FROM USR01 WHERE BNAME = SY-UNAME.
      IF L_DEVICE IS INITIAL.
        L_DEVICE = 'LOCL'.
      ENDIF.
    
    * For report-1
      IF P_C1 = 'X'.
    
    * Setting the print parameters
    
        CALL FUNCTION 'GET_PRINT_PARAMETERS'
          EXPORTING
            DESTINATION    = L_DEVICE
            COPIES         = L_COUNT
            LIST_NAME      = SY-UNAME
            LIST_TEXT      = 'SUBMIT ... TO SAP-SPOOL'(008)
            RELEASE        = C_X
            NEW_LIST_ID    = C_X
            EXPIRATION     = L_DAYS
    *        LINE_SIZE      = 255
    *        LINE_COUNT     = 65
            LAYOUT         = p_set
            SAP_COVER_PAGE = SPACE
            COVER_PAGE     = SPACE
            RECEIVER       = 'SAP*'(010)
            DEPARTMENT     = 'System'(011)
            NO_DIALOG      = C_X
          IMPORTING
            OUT_PARAMETERS = L_PARAMS
            VALID          = L_VALID.
    
        IF L_VALID <> SPACE.
    
          CLEAR V_SPOOL.
    * Fetch the spool number b4 submit
          PERFORM FETCH_RECENT_SPOOL USING V_SPOOL.
    
    * Submitting the program to spool
          SUBMIT RKAEP000 TO SAP-SPOOL
            USING SELECTION-SET P_VARA1
            SPOOL PARAMETERS L_PARAMS
            WITHOUT SPOOL DYNPRO
            AND RETURN.
    
          CLEAR V_SPOOL1.
    * Fetch the spool number after submit
          PERFORM FETCH_RECENT_SPOOL USING V_SPOOL1.
    
          IF V_SPOOL = V_SPOOL1.
            F_SPOOL = C_X.
            IF P_C2 IS INITIAL.
              STOP.
            ENDIF.
          ELSE.
    * Checking the format ( ABAP/OTF)
            PERFORM FORMAT_CHECK TABLES S_EMAIL.
          ENDIF.
    
    
        ELSE.
          MESSAGE E000 WITH 'Problem in print settings'(003).
          STOP.
        ENDIF.
      ENDIF.
    
    * For Report-2
      IF P_C2 = 'X'.
    
    * Setting the print parameters
    
        CALL FUNCTION 'GET_PRINT_PARAMETERS'
          EXPORTING
            DESTINATION    = L_DEVICE
            COPIES         = L_COUNT
            LIST_NAME      = SY-UNAME
            LIST_TEXT      = 'SUBMIT ... TO SAP-SPOOL'(008)
            RELEASE        = C_X
            NEW_LIST_ID    = C_X
            EXPIRATION     = L_DAYS
    *        LINE_SIZE      = 200
    *        LINE_COUNT     = 65
            LAYOUT         = p_set1
            SAP_COVER_PAGE = SPACE
            COVER_PAGE     = SPACE
            RECEIVER       = 'SAP*'(010)
            DEPARTMENT     = 'System'(011)
            NO_DIALOG      = C_X
          IMPORTING
            OUT_PARAMETERS = L_PARAMS1
            VALID          = L_VALID1.
    
        IF L_VALID1 <> SPACE.
    
          CLEAR V_SPOOL.
    * Fetch the spool number b4 submit
          PERFORM FETCH_RECENT_SPOOL USING V_SPOOL.
    
    * Submitting the program to spool
          SUBMIT GP3DIEHXY88SNFJ0391V7KF9EK7050 TO SAP-SPOOL
            USING SELECTION-SET P_VARA2
            SPOOL PARAMETERS L_PARAMS1
            WITHOUT SPOOL DYNPRO
            AND RETURN.
    
          CLEAR V_SPOOL1.
    * Fetch the spool number after submit
          PERFORM FETCH_RECENT_SPOOL USING V_SPOOL1.
    
          IF V_SPOOL = V_SPOOL1.
            MESSAGE E000 WITH 'Spool Not Generated'(060).
            STOP.
          ENDIF.
    
    * Checking the format ( ABAP/OTF)
          PERFORM FORMAT_CHECK TABLES S_EMAIL1.
    
        ELSE.
          MESSAGE E000 WITH 'Problem in print settings'(003).
          STOP.
        ENDIF.
      ENDIF.
    
    ENDFORM.                    " generate_spool
    *&---------------------------------------------------------------------*
    *&      Form  fetch_recent_spool
    *&---------------------------------------------------------------------*
    *       Fetch the recent spool number generated
    *----------------------------------------------------------------------*
    FORM FETCH_RECENT_SPOOL USING P_V_SPOOL TYPE TSP01-RQIDENT .
    
      DATA:  L_USER LIKE TSP01-RQ2NAME.
    
      CLEAR : V_RQIDENT,
              V_RQCLIENT,
              V_RQO1NAME.
    
      L_USER = SY-UNAME.
    
    * Get latest Spool No
      SELECT SINGLE RQIDENT
                    RQCLIENT
                    RQO1NAME
             INTO (V_RQIDENT , V_RQCLIENT , V_RQO1NAME)
        FROM TSP01
       WHERE RQCRETIME =   ( SELECT MAX( RQCRETIME )
                                    FROM TSP01
                                   WHERE RQ2NAME EQ L_USER
                                     AND RQFINAL EQ '.' ).
    
      IF SY-SUBRC = 0 .
        P_V_SPOOL = V_RQIDENT.
      ENDIF.
    
    
    ENDFORM.                    " fetch_recent_spool
    
    *&---------------------------------------------------------------------*
    *&      Form  format_check
    *&---------------------------------------------------------------------*
    *       Checking the format ( ABAP/OTF)
    *----------------------------------------------------------------------*
    FORM FORMAT_CHECK TABLES P_S_EMAIL STRUCTURE S_EMAIL.
    
      DATA : L_OBJTYPE    LIKE RSTSTYPE-TYPE.
    
      CALL FUNCTION 'RSTS_GET_ATTRIBUTES'
        EXPORTING
          AUTHORITY     = 'SP01'(019)
          CLIENT        = V_RQCLIENT
          NAME          = V_RQO1NAME
          PART          = 1
        IMPORTING
          OBJTYPE       = L_OBJTYPE
        EXCEPTIONS
          FB_ERROR      = 1
          FB_RSTS_OTHER = 2
          NO_OBJECT     = 3
          NO_PERMISSION = 4.
    
      IF SY-SUBRC <> 0.
        MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
                WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.
    
      IF L_OBJTYPE(3) = C_OTF.
    * Convert OTF Spool to PDF
        PERFORM CONVERT_OTF2PDF TABLES P_S_EMAIL.
      ELSE.
    * Convert ABAP Spool to PDF
        PERFORM CONVERT_ABAP2PDF TABLES P_S_EMAIL.
      ENDIF.
    
    ENDFORM.                    " format_check
    
    *&---------------------------------------------------------------------*
    *&      Form  convert_otf2pdf
    *&---------------------------------------------------------------------*
    *       Convert OTF Spool to PDF
    *----------------------------------------------------------------------*
    FORM CONVERT_OTF2PDF TABLES P_P_S_EMAIL STRUCTURE S_EMAIL .
    
      CLEAR   IT_PDF.
      REFRESH IT_PDF.
    
      DATA : L_BYTECOUNT  TYPE I.
    
    * Fn. to get the PDF format
      CALL FUNCTION 'CONVERT_OTFSPOOLJOB_2_PDF'
        EXPORTING
          SRC_SPOOLID              = V_RQIDENT
          NO_DIALOG                = 'X'
        IMPORTING
          PDF_BYTECOUNT            = L_BYTECOUNT
        TABLES
          PDF                      = IT_PDF
        EXCEPTIONS
          ERR_NO_OTF_SPOOLJOB      = 1
          ERR_NO_SPOOLJOB          = 2
          ERR_NO_PERMISSION        = 3
          ERR_CONV_NOT_POSSIBLE    = 4
          ERR_BAD_DSTDEVICE        = 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.
    
      IF SY-SUBRC = 0.
    * For page format
        PERFORM PAGE_FORMAT TABLES P_P_S_EMAIL.
      ELSE.
        MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
                WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.
    
    ENDFORM.                    " convert_otf2pdf
    
    *&---------------------------------------------------------------------*
    *&      Form  convert_abap2pdf
    *&---------------------------------------------------------------------*
    *        Convert ABAP Spool to PDF
    *----------------------------------------------------------------------*
    FORM CONVERT_ABAP2PDF TABLES P_P_S_EMAIL STRUCTURE S_EMAIL.
    
      CLEAR   IT_PDF.
      REFRESH IT_PDF.
    
      DATA : L_BYTECOUNT  TYPE I.
    
    * Fn. to convert to PDF format
      CALL FUNCTION 'CONVERT_ABAPSPOOLJOB_2_PDF'
        EXPORTING
          SRC_SPOOLID              = V_RQIDENT
          NO_DIALOG                = 'X'
        IMPORTING
          PDF_BYTECOUNT            = L_BYTECOUNT
        TABLES
          PDF                      = IT_PDF
        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.
    
      IF SY-SUBRC = 0.
    * For page formatting
        PERFORM PAGE_FORMAT TABLES P_P_S_EMAIL.
      ELSE.
        MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
                WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.
    
    ENDFORM.                    " convert_abap2pdf
    
    *&---------------------------------------------------------------------*
    *&      Form  send_mail
    *&---------------------------------------------------------------------*
    *       For sending mail
    *----------------------------------------------------------------------*
    FORM SEND_MAIL TABLES MAIL STRUCTURE S_EMAIL .
    
    * Structures and internal tables for the send data
      DATA: OBJPACK LIKE SOPCKLSTI1 OCCURS 2  WITH HEADER LINE,
            OBJHEAD LIKE SOLISTI1   OCCURS 1  WITH HEADER LINE,
            OBJBIN  LIKE SOLISTI1   OCCURS 0  WITH HEADER LINE,
            OBJTXT  LIKE SOLISTI1   OCCURS 10 WITH HEADER LINE,
            RECLIST LIKE SOMLRECI1  OCCURS 5  WITH HEADER LINE.
    
      DATA: DOC_CHNG LIKE SODOCCHGI1,
            TAB_LINES LIKE SY-TABIX.
    
    * Data for the status output after sending
      DATA: SENT_TO_ALL LIKE SONV-FLAG.
    
      CLEAR: IT_RECLIST, IT_RECLIST[],
             IT_OBJTXT , IT_OBJTXT[],
             IT_OBJPACK, IT_OBJPACK[],
             IT_OBJBIN , IT_OBJBIN[],X_DOC_CHNG.
    
      LOOP AT IT_HTML.
        OBJBIN-LINE = IT_HTML-LINE.
        APPEND OBJBIN.
        CLEAR OBJBIN.
      ENDLOOP.
    
    
    * Create the document which is to be sent
      DOC_CHNG-OBJ_NAME  = 'List'(012).
      DOC_CHNG-OBJ_DESCR = 'Mail'(013).
    
    * Heading
      OBJTXT-LINE = 'Mail with pdf attachment'(014).
      APPEND OBJTXT.
      CLEAR OBJTXT.
    
    * Size
      DESCRIBE TABLE OBJTXT LINES TAB_LINES.
      READ TABLE OBJTXT INDEX TAB_LINES.
      DOC_CHNG-DOC_SIZE = ( TAB_LINES - 1 ) * 255 + STRLEN( OBJTXT ).
    
    * Fill the fields of the packing_list for the main document:
      CLEAR OBJPACK-TRANSF_BIN.
    
    * The document needs no header (head_num = 0)
      OBJPACK-HEAD_START = 1.
      OBJPACK-HEAD_NUM = 0.
    
    * Body
      OBJPACK-BODY_START = 1.
      OBJPACK-BODY_NUM = TAB_LINES.
      OBJPACK-DOC_TYPE = 'RAW'(015).
      APPEND OBJPACK.
    
    * Create the attachment (the list itself)
      DESCRIBE TABLE OBJBIN LINES TAB_LINES.
    
    * Fill the fields of the packing_list for the attachment:
      OBJPACK-TRANSF_BIN = 'X'.
    
    * Header
      OBJPACK-HEAD_START = 1.
      OBJPACK-HEAD_NUM = 0.
    
    * Body
      OBJPACK-BODY_START = 1.
      OBJPACK-BODY_NUM = TAB_LINES.
      OBJPACK-DOC_TYPE = 'PDF'(016).
      OBJPACK-OBJ_NAME = 'Attachment'(017).
      OBJPACK-OBJ_DESCR = 'Mail with pdf Attachment'(018).
      OBJPACK-DOC_SIZE = TAB_LINES * 255.
      APPEND OBJPACK.
    
    *-Fill the mail recipient list
      LOOP AT MAIL.
        RECLIST-RECEIVER = MAIL-LOW.
        RECLIST-REC_TYPE = C_U.
        APPEND RECLIST.
        CLEAR: RECLIST,
               MAIL.
      ENDLOOP.
    
    *-Send the document by calling the SAPoffice API1 module for sending
    *-documents with attachments
    
      CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
        EXPORTING
          DOCUMENT_DATA              = DOC_CHNG
          PUT_IN_OUTBOX              = C_X
          COMMIT_WORK                = C_X
        IMPORTING
          SENT_TO_ALL                = SENT_TO_ALL
        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.
          MESSAGE I000 WITH 'Mail has been sent successfully'(006).
        WHEN OTHERS.
          MESSAGE E000 WITH 'Problem in sending the mail'(023).
      ENDCASE.
    
    ENDFORM.                    " send_mail
    *&---------------------------------------------------------------------*
    *&      Form  page_format
    *&---------------------------------------------------------------------*
    *        For page foramtting
    *----------------------------------------------------------------------*
    FORM PAGE_FORMAT TABLES EMAIL STRUCTURE S_EMAIL .
    
      DATA : L_LINES       TYPE I,
             L_TEMP(500)   TYPE C,
             L_OFFSET      TYPE P,
             L_LINESLEN(2) TYPE P,
             L_MIMELEN(2)  TYPE P,
             L_TABIX       LIKE SY-TABIX.
    
      CLEAR : IT_XI_PDF,
              IT_XI_TEMP.
    
      REFRESH : IT_XI_PDF,
                IT_XI_TEMP.
    
      IT_XI_PDF[] = IT_PDF[].
    
    * Reformat the line to 255 characters wide (--code from SAP--)
      CLEAR: L_TEMP, L_OFFSET, IT_XI_TEMP.
      DESCRIBE TABLE IT_XI_PDF   LINES  L_LINES.
      DESCRIBE FIELD IT_XI_PDF   LENGTH L_LINESLEN IN CHARACTER MODE.
      DESCRIBE FIELD IT_XI_TEMP  LENGTH L_MIMELEN IN CHARACTER MODE.
    
      LOOP AT IT_XI_PDF.
        L_TABIX = SY-TABIX.
        MOVE IT_XI_PDF TO L_TEMP+L_OFFSET.
        IF L_TABIX = L_LINES.
          L_LINESLEN = STRLEN( IT_XI_PDF ).
        ENDIF.
        L_OFFSET = L_OFFSET + L_LINESLEN.
        IF L_OFFSET GE L_MIMELEN.
          CLEAR IT_XI_TEMP.
          IT_XI_TEMP = L_TEMP(L_MIMELEN).
          APPEND IT_XI_TEMP.
          SHIFT L_TEMP BY L_MIMELEN PLACES.
          L_OFFSET = L_OFFSET - L_MIMELEN.
        ENDIF.
        IF L_TABIX = L_LINES.
          IF L_OFFSET GT 0.
            CLEAR IT_XI_TEMP.
            IT_XI_TEMP = L_TEMP(L_OFFSET).
            APPEND IT_XI_TEMP.
          ENDIF.
        ENDIF.
      ENDLOOP.
    
      CLEAR : IT_XI_MIME,
              IT_XI_MIME[].
    
      LOOP AT IT_XI_TEMP.
        IT_XI_MIME(255) = IT_XI_TEMP-LINE.
        APPEND IT_XI_MIME.
        CLEAR  IT_XI_MIME.
      ENDLOOP.
    
    * Final Data
      CLEAR : IT_HTML,
              IT_HTML[].
    
      IT_HTML[] = IT_XI_MIME[].
    
    * For sending mail
      PERFORM SEND_MAIL TABLES EMAIL.
    
    ENDFORM.                    " page_format
    *&---------------------------------------------------------------------*
    *&      Form  fetch_variants
    *&---------------------------------------------------------------------*
    *       For fetching the variants available for the program
    *----------------------------------------------------------------------*
    FORM FETCH_VARIANTS .
    
      DATA : L_PROGRAM LIKE RS38M-PROGRAMM VALUE 'RKAEP000',
             L_VARA1 TYPE DFIES-FIELDNAME VALUE 'P_VARA1'.
    
      CLEAR : IT_VARIANT1,
              IT_VARIANT1[].
    
    * Get variants
      PERFORM GET_VARIANTS TABLES IT_VARIANT1
                           USING L_PROGRAM.
    
    * F4 Help
      IF NOT IT_VARIANT1[] IS INITIAL.
        PERFORM GET_F4_HELP TABLES IT_VARIANT1
                             USING L_VARA1
                            CHANGING P_VARA1.
      ELSE.
        MESSAGE E000 WITH 'No variants available for report1'(054).
      ENDIF.
    
    ENDFORM.                    " fetch_variants
    
    *&---------------------------------------------------------------------*
    *&      Form  validation
    *&---------------------------------------------------------------------*
    *       For Validation
    *----------------------------------------------------------------------*
    FORM VALIDATION .
    
      DATA : L_PRO1 LIKE RS38M-PROGRAMM VALUE 'RKAEP000',
             L_PRO2 LIKE RS38M-PROGRAMM VALUE 'GP3DIEHXY88SNFJ0391V7KF9EK7050',
             L_C1,
             L_C2.
    
    * If both check-box are unchecked
      IF P_C1 IS INITIAL
     AND P_C2 IS INITIAL.
        MESSAGE E000 WITH 'Check any one check-box'(049).
      ENDIF.
    
    * If checked without varaint
      IF NOT P_C1 IS INITIAL AND P_VARA1 IS INITIAL.
        MESSAGE E000 WITH 'Please give any one of the variant for report1'(055).
      ENDIF.
    
    * If checked without varaint
      IF NOT P_C2 IS INITIAL AND P_VARA2 IS INITIAL.
        MESSAGE E000 WITH 'Please give any one of the variant for report2'(061).
      ENDIF.
    
    * Reading the variant and fetching the mail-ids
      IF P_C1 = C_X.
    
        L_C1 = '1'.
        CLEAR : S_EMAIL,
                S_EMAIL[].
    
        PERFORM READ_VARIANTS TABLES IT_MAILID
                                     S_EMAIL
                               USING P_VARA1
                                     L_PRO1
                                     L_C1.
        IF S_EMAIL[] IS INITIAL.
          MESSAGE E000 WITH 'No Id available for given Cost report1'(066).
        ELSE.
          SORT S_EMAIL BY LOW.
          DELETE ADJACENT DUPLICATES FROM S_EMAIL COMPARING LOW.
        ENDIF.
    
      ENDIF.
    
    * Reading the variant and fetching the mail-ids
      IF P_C2 = C_X.
    
        CLEAR : S_EMAIL1,
                S_EMAIL1[].
    
        L_C2 = '2'.
        PERFORM READ_VARIANTS TABLES IT_MAILID1
                                     S_EMAIL1
                               USING P_VARA2
                                     L_PRO2
                                     L_C2.
    
        IF S_EMAIL1[] IS INITIAL.
          MESSAGE E000 WITH 'No Id available for given Cost report2'(067).
        ELSE.
          SORT S_EMAIL1 BY LOW.
          DELETE ADJACENT DUPLICATES FROM S_EMAIL1 COMPARING LOW.
        ENDIF.
    
      ENDIF.
    
    ENDFORM.                    " validation
    
    *&---------------------------------------------------------------------*
    *&      Form  GET_VARIANTS
    *&---------------------------------------------------------------------*
    *       Fetching Variants
    *----------------------------------------------------------------------*
    FORM GET_VARIANTS  TABLES   P_IT_VARIANT STRUCTURE IT_VARIANT1
                       USING    P_V_PROGRAM  TYPE RS38M-PROGRAMM.
    
      SELECT VARIANT
             FROM VARID
             INTO TABLE P_IT_VARIANT
             WHERE REPORT = P_V_PROGRAM.
    
    ENDFORM.                    " GET_VARIANTS
    *&---------------------------------------------------------------------*
    *&      Form  GET_F4_HELP
    *&---------------------------------------------------------------------*
    *       text
    *----------------------------------------------------------------------*
    FORM GET_F4_HELP  TABLES   P_IT_VARIANT1 STRUCTURE IT_VARIANT1
                       USING   P_L_VARA1 LIKE DFIES-FIELDNAME
                      CHANGING P_P_VARA LIKE P_VARA1.
    
    
    * Fn. for Pop-Up
      CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
        EXPORTING
          RETFIELD        = P_L_VARA1
          VALUE_ORG       = 'S'
          DISPLAY         = ' '
        TABLES
          VALUE_TAB       = P_IT_VARIANT1
          RETURN_TAB      = IT_RETURN
        EXCEPTIONS
          PARAMETER_ERROR = 1
          NO_VALUES_FOUND = 2
          OTHERS          = 3.
      IF SY-SUBRC = 0.
        P_P_VARA = IT_RETURN-FIELDVAL.
      ELSE.
        MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
                WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.
    
    ENDFORM.                    " GET_F4_HELP
    *&---------------------------------------------------------------------*
    *&      Form  FETCH_VARIANTS1
    *&---------------------------------------------------------------------*
    *       text
    *----------------------------------------------------------------------*
    FORM FETCH_VARIANTS1 .
    
      DATA : V_PROGRAM1 LIKE RS38M-PROGRAMM VALUE 'GP3DIEHXY88SNFJ0391V7KF9EK7050',
             L_VARA2  TYPE DFIES-FIELDNAME VALUE 'P_VARA2'.
    
      CLEAR : IT_VARIANT2,
              IT_VARIANT2[].
    
    * Get Variants
      PERFORM GET_VARIANTS TABLES IT_VARIANT2
                           USING V_PROGRAM1.
    
    * F4 Help
      IF NOT IT_VARIANT2[] IS INITIAL.
        PERFORM GET_F4_HELP TABLES IT_VARIANT2
                            USING  L_VARA2
                          CHANGING P_VARA2.
      ELSE.
        MESSAGE E000 WITH 'No variants available for report2'(050).
      ENDIF.
    
    ENDFORM.                    " FETCH_VARIANTS1
    
    *&---------------------------------------------------------------------*
    *&      Form  read_variants
    *&---------------------------------------------------------------------*
    *        Reading the variant and fetching the mail-ids
    *----------------------------------------------------------------------*
    FORM READ_VARIANTS TABLES P_IT_MAILID STRUCTURE IT_MAILID
                              P_S_EMAIL   STRUCTURE S_EMAIL
                       USING  P_P_VARA1   LIKE P_VARA1
                              P_L_PRO1    LIKE RS38M-PROGRAMM
                              P_L_C1      TYPE C.
    
      DATA : L_TEMP(44),
             IT_VALUTAB LIKE RSPARAMS OCCURS 0 WITH HEADER LINE.
    
      RANGES : R_COCEN FOR CSKS-KOSTL.
    
    * Function Module to get the variant contents
      CALL FUNCTION 'RS_VARIANT_CONTENTS'
        EXPORTING
          REPORT               = P_L_PRO1
          VARIANT              = P_P_VARA1
        TABLES
          VALUTAB              = IT_VALUTAB
        EXCEPTIONS
          VARIANT_NON_EXISTENT = 1
          VARIANT_OBSOLETE     = 2
          OTHERS               = 3.
    
      IF SY-SUBRC <> 0.
        MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
                WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.
    
      CLEAR : R_COCEN,
              R_COCEN[].
    
      LOOP AT IT_VALUTAB WHERE SELNAME = 'KOSTL'
                            OR SELNAME = '_C-CCTR'.
    
    * Getting the range of cost centers
        IF IT_VALUTAB-OPTION = 'BT'.
          R_COCEN-LOW    = IT_VALUTAB-LOW.
    * For Conversion Routine
          PERFORM CONVERSION USING R_COCEN-LOW.
          R_COCEN-HIGH   = IT_VALUTAB-HIGH.
    * For Conversion Routine
          PERFORM CONVERSION USING R_COCEN-HIGH.
          R_COCEN-OPTION = 'BT'.
          R_COCEN-SIGN   = 'I'.
          APPEND R_COCEN.
          CLEAR  R_COCEN.
        ENDIF.
    
    * Getting the single cost centers
        IF IT_VALUTAB-OPTION = 'EQ'.
          R_COCEN-LOW    = IT_VALUTAB-LOW.
    * For Conversion Routine
          PERFORM CONVERSION USING R_COCEN-LOW.
          R_COCEN-OPTION = 'EQ'.
          R_COCEN-SIGN   = 'I'.
          APPEND R_COCEN.
          CLEAR  R_COCEN.
        ENDIF.
    
      ENDLOOP.
    
    * If no cost centers
      IF NOT R_COCEN[] IS INITIAL.
        SELECT KOKRS
               KOSTL
               DATBI
               TELX1
          FROM CSKS
               INTO TABLE P_IT_MAILID
         WHERE KOSTL IN R_COCEN.
    
        IF P_IT_MAILID[] IS INITIAL.
          IF P_L_C1 = '1'.
            MESSAGE E000 WITH 'No IDs available for report1'(059).
          ELSEIF P_L_C1 = '2'.
            MESSAGE E000 WITH 'No IDs available for report2'(062).
          ENDIF.
    
        ENDIF.
    
    * Deleting the blank entries
        DELETE P_IT_MAILID WHERE TELX1 = SPACE.
    
        CLEAR L_TEMP.
        READ TABLE P_IT_MAILID INDEX 1.
        L_TEMP = P_IT_MAILID-TELX1.
    
        DATA : L_CHECK.
    
        LOOP AT P_IT_MAILID WHERE TELX1 <> L_TEMP.
          L_CHECK = C_X.
        ENDLOOP.
    
    * For checking the unique ids
        IF L_CHECK = C_X.
          IF P_L_C1 = '1'.
            MESSAGE E000 WITH 'No unique mail-ids for  report1'(058).
          ELSEIF P_L_C1 = '2'.
            MESSAGE E000 WITH 'No unique mail-ids for  report2'(065).
          ENDIF.
        ENDIF.
    
    * Populating the IDs for the cost centers
        LOOP AT P_IT_MAILID.
          SET LOCALE LANGUAGE SY-LANGU.
          TRANSLATE P_IT_MAILID-TELX1 TO LOWER CASE.
          SET LOCALE LANGUAGE SPACE .
          CONCATENATE P_IT_MAILID-TELX1 '@allergan.com' INTO L_TEMP.
          P_S_EMAIL-LOW = L_TEMP.
          P_S_EMAIL-SIGN = 'I'.
          P_S_EMAIL-OPTION = 'EQ'.
          APPEND P_S_EMAIL.
          CLEAR  P_S_EMAIL.
        ENDLOOP.
    
      ELSE.
        IF P_L_C1 = '1'.
          MESSAGE E000 WITH 'No Cost Center Available for report1'(057).
        ELSEIF P_L_C1 = '2'.
          MESSAGE E000 WITH 'No Cost Center Available for report2'(063).
        ENDIF.
      ENDIF.
    
    ENDFORM.                    " read_variants
    *&---------------------------------------------------------------------*
    *&      Form  CONVERSION
    *&---------------------------------------------------------------------*
    *       For Conversion Routine
    *----------------------------------------------------------------------*
    FORM CONVERSION  USING    P_IT_VALUTAB_LOW TYPE C.
    
      CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
        EXPORTING
          INPUT  = P_IT_VALUTAB_LOW
        IMPORTING
          OUTPUT = P_IT_VALUTAB_LOW.
    
    ENDFORM.                    " CONVERSION
    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.