Scripts to pdf to email

REPORT Z_SCRIPT_TO_PDF_EMAIL
   NO STANDARD PAGE HEADING     "
      LINE-SIZE 80              "
      LINE-COUNT 64             "
      MESSAGE-ID XX.            "
DATA: BEGIN OF T_VBAP OCCURS 0,
        VBELN TYPE VBAP-VBELN ,
        POSNR TYPE VBAP-POSNR ,
        ARKTX TYPE VBAP-ARKTX ,
        NETPR TYPE VBAP-NETPR ,
        NETWR TYPE VBAP-NETWR ,
        GEWEI TYPE VBAP-GEWEI ,
        VOLUM TYPE VBAP-VOLUM ,
        VOLEH TYPE VBAP-VOLEH ,
        MATNR TYPE VBAP-MATNR ,
        KWMENG TYPE VBAP-KWMENG ,
        WAERK LIKE VBAP-WAERK ,
       END OF T_VBAP,
        BEGIN OF T_VBRP OCCURS 0,
         VBELN LIKE VBRP-VBELN,
         VGBEL LIKE VBRP-VGBEL,
         AUBEL LIKE VBRP-AUBEL ,
         BRGEW LIKE VBRP-BRGEW,
        END OF T_VBRP,
        BEGIN OF T_TVZBT OCCURS 0 ,
         ZTERM LIKE TVZBT-ZTERM ,
         VTEXT LIKE TVZBT-VTEXT ,
        END OF T_TVZBT ,
        BEGIN OF T_LIPS OCCURS 0 ,
         VBELN TYPE LIPS-VBELN ,
         VGBEL LIKE LIPS-VGBEL ,
         VGPOS LIKE LIPS-VGPOS ,
        END OF T_LIPS ,
        BEGIN OF  T_LIKP OCCURS 0,
         VBELN LIKE LIKP-VBELN,
         KUNNR TYPE LIKP-KUNNR ,
         BLDAT LIKE LIKP-BLDAT,
         LFDAT LIKE LIKP-LFDAT ,
        END OF T_LIKP ,
        BEGIN OF T_VBKD OCCURS 0,
         VBELN LIKE VBAP-VBELN,
         ZTERM LIKE VBKD-ZTERM,
         INCO1 LIKE VBKD-INCO1,
         INCO2 LIKE VBKD-INCO2 ,
         BSTDK LIKE VBKD-BSTDK ,
        END OF T_VBKD,
        BEGIN OF T_VBRK OCCURS 0 ,
         VBELN LIKE VBRK-VBELN ,
         WAERK LIKE VBRK-WAERK ,
        END OF T_VBRK ,
         BEGIN OF T_OUTPUT OCCURS 0 ,
          VBELN LIKE VBAP-VBELN ,
          POSNR LIKE VBAP-POSNR ,
          ARKTX LIKE VBAP-ARKTX ,
          NETPR LIKE VBAP-NETPR ,
          NETWR LIKE VBAP-NETWR ,
          GEWEI LIKE VBAP-GEWEI ,
          VOLUM LIKE VBAP-VOLUM ,
          VOLEH LIKE VBAP-VOLEH ,
          MATNR LIKE VBAP-MATNR ,
          KWMENG LIKE VBAP-KWMENG ,
          VTEXT LIKE TVZBT-VTEXT ,
          VGBEL LIKE LIPS-VGBEL,
          VGPOS LIKE LIPS-VGPOS ,
          AUBEL LIKE VBRP-AUBEL ,
          BRGEW LIKE VBRP-BRGEW,
          KUNNR LIKE LIKP-KUNNR,
          LFDAT LIKE LIKP-LFDAT ,
          BLDAT LIKE LIKP-BLDAT,
          ZTERM LIKE VBKD-ZTERM,
          INCO1 LIKE VBKD-INCO1,
          INCO2 LIKE VBKD-INCO2,
          BSTDK LIKE VBKD-BSTDK ,
          WAERK LIKE VBAP-WAERK ,
         END OF T_OUTPUT .
DATA : L_ARKTX LIKE VBAP-ARKTX  ,
       V_LEN TYPE I ,
       VAR1(10) ,
       VAR2(10) ,
       VAR3(10) .
PARAMETERS: P_VBELN LIKE VBAP-VBELN.
      SELECT  VBELN POSNR ARKTX WAERK
              NETPR NETWR GEWEI VOLUM VOLEH
              MATNR KWMENG
              FROM VBAP
              INTO  CORRESPONDING FIELDS OF  TABLE T_VBAP
              WHERE VBELN = P_VBELN .
      SELECT VBELN ZTERM INCO1
             INCO2 BSTDK
             FROM VBKD
             INTO CORRESPONDING FIELDS OF TABLE T_VBKD
             FOR ALL ENTRIES IN T_VBAP
             WHERE VBELN = T_VBAP-VBELN .
      SELECT VBELN VGBEL VGPOS
             FROM LIPS
             INTO CORRESPONDING FIELDS OF TABLE T_LIPS
             FOR ALL ENTRIES IN T_VBAP
             WHERE VGBEL = T_VBAP-VBELN .
IF NOT T_LIPS[] IS INITIAL .
      SELECT VBELN KUNNR BLDAT LFDAT
             FROM LIKP
             INTO CORRESPONDING FIELDS OF TABLE T_LIKP
             FOR ALL ENTRIES IN T_LIPS
             WHERE VBELN = T_LIPS-VBELN .
      SELECT VBELN AUBEL BRGEW VGBEL
             FROM VBRP
             INTO CORRESPONDING FIELDS OF TABLE T_VBRP
             FOR ALL ENTRIES IN T_LIPS
             WHERE VGBEL = T_LIPS-VBELN .
ENDIF  .
      SELECT VBELN WAERK
             FROM VBRK
             INTO CORRESPONDING FIELDS OF TABLE T_VBRK
             FOR ALL ENTRIES IN T_VBRP
             WHERE VBELN = T_VBRP-VBELN .
      SELECT ZTERM VTEXT
             FROM TVZBT
             INTO CORRESPONDING FIELDS OF TABLE T_TVZBT
             FOR ALL ENTRIES IN T_VBKD
             WHERE ZTERM EQ T_VBKD-ZTERM .
LOOP AT T_VBAP .
T_OUTPUT-VBELN = T_VBAP-VBELN .
T_OUTPUT-WAERK = T_VBAP-WAERK .
T_OUTPUT-POSNR = T_VBAP-POSNR .
T_OUTPUT-ARKTX = T_VBAP-ARKTX .
T_OUTPUT-NETPR = T_VBAP-NETPR .
T_OUTPUT-NETWR = T_VBAP-NETWR .
T_OUTPUT-GEWEI = T_VBAP-GEWEI .
T_OUTPUT-VOLUM = T_VBAP-VOLUM .
T_OUTPUT-VOLEH = T_VBAP-VOLEH .
T_OUTPUT-MATNR = T_VBAP-MATNR .
T_OUTPUT-KWMENG = T_VBAP-KWMENG .
L_ARKTX = T_OUTPUT-ARKTX .
*V_LEN = STRLEN( L_ARKTX ) .
SPLIT L_ARKTX AT SPACE INTO VAR1 VAR2 VAR3 .
READ TABLE T_VBKD WITH KEY VBELN = T_VBAP-VBELN .
IF SY-SUBRC = 0 .
   T_OUTPUT-ZTERM = T_VBKD-ZTERM .
   T_OUTPUT-INCO1 = T_VBKD-INCO1 .
   T_OUTPUT-INCO2 = T_VBKD-INCO2 .
   T_OUTPUT-BSTDK = T_VBKD-BSTDK .
ENDIF .
READ TABLE T_LIPS WITH KEY VGBEL = T_VBAP-VBELN .
IF SY-SUBRC = 0 .
  T_OUTPUT-VGBEL = T_LIPS-VGBEL .
ENDIF .
READ TABLE T_LIKP WITH KEY VBELN = T_LIPS-VBELN .
IF SY-SUBRC = 0 .
  T_OUTPUT-KUNNR = T_LIKP-KUNNR .
  T_OUTPUT-BLDAT = T_LIKP-BLDAT .
  T_OUTPUT-LFDAT = T_LIKP-LFDAT .
ENDIF .
READ TABLE T_VBRP WITH KEY VGBEL = T_LIPS-VBELN .
IF SY-SUBRC = 0 .
  T_OUTPUT-AUBEL = T_VBRP-AUBEL .
  T_OUTPUT-BRGEW = T_VBRP-BRGEW .
ENDIF .
READ TABLE T_VBRK WITH KEY VBELN = T_VBRP-VBELN .
IF SY-SUBRC = 0 .
  T_OUTPUT-WAERK = T_VBRK-WAERK .
ENDIF .
READ TABLE T_TVZBT WITH KEY ZTERM = T_VBKD-ZTERM .
IF SY-SUBRC = 0 .
  T_OUTPUT-VTEXT = T_TVZBT-VTEXT .
ENDIF .
APPEND T_OUTPUT .
ENDLOOP .
DATA : RECIEVER TYPE SWOTOBJID VALUE '[email protected]',
       X_OPTION LIKE ITCPO.
Internal Table Declaration
DATA : " I_PA0001 TYPE STANDARD TABLE OF TY_PA0001, "For pa0001 Details
I_OTF TYPE STANDARD TABLE OF ITCOO, "For OTF data
I_CONTENT_TXT TYPE SOLI_TAB, "Content
I_CONTENT_BIN TYPE SOLIX_TAB, "Content
I_OBJHEAD TYPE SOLI_TAB,
Work Area Declaration
*W_PA0001 TYPE TY_PA0001, "For pa0001 Details
W_RES TYPE ITCPP, "SAPscript output
"parameters
W_OTF TYPE ITCOO, "For OTF
W_PDF TYPE SOLISTI1, "For PDF
W_TRANSFER_BIN TYPE SX_BOOLEAN, "Content
W_OPTIONS TYPE ITCPO, "SAPscript output
"interface
Variable Declaration
V_LEN_IN TYPE SO_OBJ_LEN,
V_SIZE TYPE I.
Constants Declaration
CONSTANTS : C_X TYPE C VALUE 'X', "X
C_LOCL(4) TYPE C VALUE 'LOCL', "Local Printer
C_OTF TYPE SX_FORMAT VALUE 'OTF', "OTF
C_PDF TYPE SX_FORMAT VALUE 'PDF', "PDF
C_PRINTER TYPE SX_DEVTYPE VALUE 'PRINTER', "PRINTER
C_BIN TYPE CHAR10 VALUE 'BIN', "BIN
C_NAME TYPE STRING VALUE 'C:\payment.PDF',"Downloading
"File Name
C_FORM(11) TYPE C VALUE 'ZPAYMENT1'. "Form Name
START-OF-SELECTION.
Selecting the records from pa0001
*SELECT PERNR BUKRS WERKS FROM PA0001
*INTO TABLE I_PA0001 UP TO 10 ROWS.
Setting the options
W_OPTIONS-TDCOPIES = 1 ."Number of copies
W_OPTIONS-TDNOPREV = C_X."No print preview
W_OPTIONS-TDGETOTF = C_X."Return of OTF table
W_OPTIONS-TDDEST = C_LOCL."Spool: Output device
Opening the form
CALL FUNCTION 'OPEN_FORM'
EXPORTING
FORM = C_FORM
DEVICE = C_PRINTER
LANGUAGE = SY-LANGU
OPTIONS = W_OPTIONS
IMPORTING
RESULT = W_RES.
LOOP AT T_OUTPUT .
CALL FUNCTION 'WRITE_FORM'
  EXPORTING
    ELEMENT                        = 'ORD'
    WINDOW                         = 'ORDER'.
CALL FUNCTION 'WRITE_FORM'
  EXPORTING
    ELEMENT                        = 'DEL'
    WINDOW                         = 'DELIVER'.
CALL FUNCTION 'WRITE_FORM'
  EXPORTING
    ELEMENT                        = 'MAIN1'
    TYPE                           = 'BODY'
    WINDOW                         = 'MAIN'.
ENDLOOP .
CALL FUNCTION 'CLOSE_FORM'
IMPORTING
RESULT = W_RES
TABLES
OTFDATA = I_OTF
EXCEPTIONS
UNOPENED = 1
BAD_PAGEFORMAT_FOR_PRINT = 2
SEND_ERROR = 3
SPOOL_ERROR = 4
CODEPAGE = 5
OTHERS = 6.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
Converting OTF data to single line
LOOP AT I_OTF INTO W_OTF.
CONCATENATE W_OTF-TDPRINTCOM W_OTF-TDPRINTPAR
INTO W_PDF.
APPEND W_PDF TO I_CONTENT_TXT.
ENDLOOP.
Converting to PDF Format
CALL FUNCTION 'SX_OBJECT_CONVERT_OTF_PDF'
EXPORTING
FORMAT_SRC = C_OTF
FORMAT_DST = C_PDF
DEVTYPE = C_PRINTER
CHANGING
TRANSFER_BIN = W_TRANSFER_BIN
CONTENT_TXT = I_CONTENT_TXT
CONTENT_BIN = I_CONTENT_BIN
OBJHEAD = I_OBJHEAD
LEN = V_LEN_IN
EXCEPTIONS
ERR_CONV_FAILED = 1
OTHERS = 2.
V_SIZE = V_LEN_IN.
Downloading the PDF File
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
BIN_FILESIZE = V_SIZE
FILENAME = C_NAME
FILETYPE = C_BIN
TABLES
DATA_TAB = I_CONTENT_BIN.
this is the code i wrote for converting it to pdf.wat must be done futher for sending the pdf file as an attachment to the external email id.
thankiing u in anticipation.

hi sudeer,
this is my code.
REPORT Z_SCRIPT_TO_PDF_EMAIL
   NO STANDARD PAGE HEADING     "
      LINE-SIZE 80              "
      LINE-COUNT 64             "
      MESSAGE-ID XX.            "
DATA: BEGIN OF T_VBAP OCCURS 0,
        VBELN TYPE VBAP-VBELN ,
        POSNR TYPE VBAP-POSNR ,
        ARKTX TYPE VBAP-ARKTX ,
        NETPR TYPE VBAP-NETPR ,
        NETWR TYPE VBAP-NETWR ,
        GEWEI TYPE VBAP-GEWEI ,
        VOLUM TYPE VBAP-VOLUM ,
        VOLEH TYPE VBAP-VOLEH ,
        MATNR TYPE VBAP-MATNR ,
        KWMENG TYPE VBAP-KWMENG ,
        WAERK LIKE VBAP-WAERK ,
       END OF T_VBAP,
        BEGIN OF T_VBRP OCCURS 0,
         VBELN LIKE VBRP-VBELN,
         VGBEL LIKE VBRP-VGBEL,
         AUBEL LIKE VBRP-AUBEL ,
         BRGEW LIKE VBRP-BRGEW,
        END OF T_VBRP,
        BEGIN OF T_TVZBT OCCURS 0 ,
         ZTERM LIKE TVZBT-ZTERM ,
         VTEXT LIKE TVZBT-VTEXT ,
        END OF T_TVZBT ,
        BEGIN OF T_LIPS OCCURS 0 ,
         VBELN TYPE LIPS-VBELN ,
         VGBEL LIKE LIPS-VGBEL ,
         VGPOS LIKE LIPS-VGPOS ,
        END OF T_LIPS ,
        BEGIN OF  T_LIKP OCCURS 0,
         VBELN LIKE LIKP-VBELN,
         KUNNR TYPE LIKP-KUNNR ,
         BLDAT LIKE LIKP-BLDAT,
         LFDAT LIKE LIKP-LFDAT ,
        END OF T_LIKP ,
        BEGIN OF T_VBKD OCCURS 0,
         VBELN LIKE VBAP-VBELN,
         ZTERM LIKE VBKD-ZTERM,
         INCO1 LIKE VBKD-INCO1,
         INCO2 LIKE VBKD-INCO2 ,
         BSTDK LIKE VBKD-BSTDK ,
        END OF T_VBKD,
        BEGIN OF T_VBRK OCCURS 0 ,
         VBELN LIKE VBRK-VBELN ,
         WAERK LIKE VBRK-WAERK ,
        END OF T_VBRK ,
         BEGIN OF T_OUTPUT OCCURS 0 ,
          VBELN LIKE VBAP-VBELN ,
          POSNR LIKE VBAP-POSNR ,
          ARKTX LIKE VBAP-ARKTX ,
          NETPR LIKE VBAP-NETPR ,
          NETWR LIKE VBAP-NETWR ,
          GEWEI LIKE VBAP-GEWEI ,
          VOLUM LIKE VBAP-VOLUM ,
          VOLEH LIKE VBAP-VOLEH ,
          MATNR LIKE VBAP-MATNR ,
          KWMENG LIKE VBAP-KWMENG ,
          VTEXT LIKE TVZBT-VTEXT ,
          VGBEL LIKE LIPS-VGBEL,
          VGPOS LIKE LIPS-VGPOS ,
          AUBEL LIKE VBRP-AUBEL ,
          BRGEW LIKE VBRP-BRGEW,
          KUNNR LIKE LIKP-KUNNR,
          LFDAT LIKE LIKP-LFDAT ,
          BLDAT LIKE LIKP-BLDAT,
          ZTERM LIKE VBKD-ZTERM,
          INCO1 LIKE VBKD-INCO1,
          INCO2 LIKE VBKD-INCO2,
          BSTDK LIKE VBKD-BSTDK ,
          WAERK LIKE VBAP-WAERK ,
         END OF T_OUTPUT .
DATA : L_ARKTX LIKE VBAP-ARKTX  ,
       V_LEN TYPE I ,
       VAR1(10) ,
       VAR2(10) ,
       VAR3(10) .
PARAMETERS: P_VBELN LIKE VBAP-VBELN.
      SELECT  VBELN POSNR ARKTX WAERK
              NETPR NETWR GEWEI VOLUM VOLEH
              MATNR KWMENG
              FROM VBAP
              INTO  CORRESPONDING FIELDS OF  TABLE T_VBAP
              WHERE VBELN = P_VBELN .
      SELECT VBELN ZTERM INCO1
             INCO2 BSTDK
             FROM VBKD
             INTO CORRESPONDING FIELDS OF TABLE T_VBKD
             FOR ALL ENTRIES IN T_VBAP
             WHERE VBELN = T_VBAP-VBELN .
      SELECT VBELN VGBEL VGPOS
             FROM LIPS
             INTO CORRESPONDING FIELDS OF TABLE T_LIPS
             FOR ALL ENTRIES IN T_VBAP
             WHERE VGBEL = T_VBAP-VBELN .
IF NOT T_LIPS[] IS INITIAL .
      SELECT VBELN KUNNR BLDAT LFDAT
             FROM LIKP
             INTO CORRESPONDING FIELDS OF TABLE T_LIKP
             FOR ALL ENTRIES IN T_LIPS
             WHERE VBELN = T_LIPS-VBELN .
      SELECT VBELN AUBEL BRGEW VGBEL
             FROM VBRP
             INTO CORRESPONDING FIELDS OF TABLE T_VBRP
             FOR ALL ENTRIES IN T_LIPS
             WHERE VGBEL = T_LIPS-VBELN .
ENDIF  .
      SELECT VBELN WAERK
             FROM VBRK
             INTO CORRESPONDING FIELDS OF TABLE T_VBRK
             FOR ALL ENTRIES IN T_VBRP
             WHERE VBELN = T_VBRP-VBELN .
      SELECT ZTERM VTEXT
             FROM TVZBT
             INTO CORRESPONDING FIELDS OF TABLE T_TVZBT
             FOR ALL ENTRIES IN T_VBKD
             WHERE ZTERM EQ T_VBKD-ZTERM .
LOOP AT T_VBAP .
T_OUTPUT-VBELN = T_VBAP-VBELN .
T_OUTPUT-WAERK = T_VBAP-WAERK .
T_OUTPUT-POSNR = T_VBAP-POSNR .
T_OUTPUT-ARKTX = T_VBAP-ARKTX .
T_OUTPUT-NETPR = T_VBAP-NETPR .
T_OUTPUT-NETWR = T_VBAP-NETWR .
T_OUTPUT-GEWEI = T_VBAP-GEWEI .
T_OUTPUT-VOLUM = T_VBAP-VOLUM .
T_OUTPUT-VOLEH = T_VBAP-VOLEH .
T_OUTPUT-MATNR = T_VBAP-MATNR .
T_OUTPUT-KWMENG = T_VBAP-KWMENG .
L_ARKTX = T_OUTPUT-ARKTX .
*V_LEN = STRLEN( L_ARKTX ) .
SPLIT L_ARKTX AT SPACE INTO VAR1 VAR2 VAR3 .
READ TABLE T_VBKD WITH KEY VBELN = T_VBAP-VBELN .
IF SY-SUBRC = 0 .
   T_OUTPUT-ZTERM = T_VBKD-ZTERM .
   T_OUTPUT-INCO1 = T_VBKD-INCO1 .
   T_OUTPUT-INCO2 = T_VBKD-INCO2 .
   T_OUTPUT-BSTDK = T_VBKD-BSTDK .
ENDIF .
READ TABLE T_LIPS WITH KEY VGBEL = T_VBAP-VBELN .
IF SY-SUBRC = 0 .
  T_OUTPUT-VGBEL = T_LIPS-VGBEL .
ENDIF .
READ TABLE T_LIKP WITH KEY VBELN = T_LIPS-VBELN .
IF SY-SUBRC = 0 .
  T_OUTPUT-KUNNR = T_LIKP-KUNNR .
  T_OUTPUT-BLDAT = T_LIKP-BLDAT .
  T_OUTPUT-LFDAT = T_LIKP-LFDAT .
ENDIF .
READ TABLE T_VBRP WITH KEY VGBEL = T_LIPS-VBELN .
IF SY-SUBRC = 0 .
  T_OUTPUT-AUBEL = T_VBRP-AUBEL .
  T_OUTPUT-BRGEW = T_VBRP-BRGEW .
ENDIF .
READ TABLE T_VBRK WITH KEY VBELN = T_VBRP-VBELN .
IF SY-SUBRC = 0 .
  T_OUTPUT-WAERK = T_VBRK-WAERK .
ENDIF .
READ TABLE T_TVZBT WITH KEY ZTERM = T_VBKD-ZTERM .
IF SY-SUBRC = 0 .
  T_OUTPUT-VTEXT = T_TVZBT-VTEXT .
ENDIF .
APPEND T_OUTPUT .
ENDLOOP .
DATA : RECIEVER TYPE SWOTOBJID VALUE '[email protected]',
       X_OPTION LIKE ITCPO.
Internal Table Declaration
DATA : I_OTF TYPE STANDARD TABLE OF ITCOO, "For OTF data
       I_CONTENT_TXT TYPE SOLI_TAB, "Content
       I_CONTENT_BIN TYPE SOLIX_TAB, "Content
       I_OBJHEAD TYPE SOLI_TAB,
Work Area Declaration
*W_PA0001 TYPE TY_PA0001, "For pa0001 Details
W_RES TYPE ITCPP, "SAPscript output
"parameters
W_OTF TYPE ITCOO, "For OTF
W_PDF TYPE SOLISTI1, "For PDF
W_TRANSFER_BIN TYPE SX_BOOLEAN, "Content
W_OPTIONS TYPE ITCPO, "SAPscript output
"interface
Variable Declaration
V_LEN_IN TYPE SO_OBJ_LEN,
V_SIZE TYPE I.
Constants Declaration
CONSTANTS : C_X TYPE C VALUE 'X', "X
C_LOCL(4) TYPE C VALUE 'LP01', "Local Printer
C_OTF TYPE SX_FORMAT VALUE 'OTF', "OTF
C_PDF TYPE SX_FORMAT VALUE 'PDF', "PDF
C_PRINTER TYPE SX_DEVTYPE VALUE 'PRINTER', "PRINTER
C_BIN TYPE CHAR10 VALUE 'BIN', "BIN
C_NAME TYPE STRING VALUE 'C:\PAYMENT.PDF',"Downloading
"File Name
C_FORM(11) TYPE C VALUE 'ZPAYMENT1'. "Form Name
START-OF-SELECTION.
Selecting the records from pa0001
*SELECT PERNR BUKRS WERKS FROM PA0001
*INTO TABLE I_PA0001 UP TO 10 ROWS.
Setting the options
W_OPTIONS-TDCOPIES = 1 ."Number of copies
W_OPTIONS-TDNOPREV = C_X."No print preview
W_OPTIONS-TDGETOTF = C_X."Return of OTF table
W_OPTIONS-TDDEST = C_LOCL."Spool: Output device
Opening the form
CALL FUNCTION 'OPEN_FORM'
EXPORTING
FORM = C_FORM
DEVICE = C_PRINTER
LANGUAGE = SY-LANGU
OPTIONS = W_OPTIONS
IMPORTING
RESULT = W_RES.
LOOP AT T_OUTPUT .
CALL FUNCTION 'WRITE_FORM'
  EXPORTING
    ELEMENT                        = 'ORD'
    WINDOW                         = 'ORDER'.
CALL FUNCTION 'WRITE_FORM'
  EXPORTING
    ELEMENT                        = 'DEL'
    WINDOW                         = 'DELIVER'.
CALL FUNCTION 'WRITE_FORM'
  EXPORTING
    ELEMENT                        = 'MAIN1'
    TYPE                           = 'BODY'
    WINDOW                         = 'MAIN'.
ENDLOOP .
CALL FUNCTION 'CLOSE_FORM'
IMPORTING
RESULT = W_RES
TABLES
OTFDATA = I_OTF
EXCEPTIONS
UNOPENED = 1
BAD_PAGEFORMAT_FOR_PRINT = 2
SEND_ERROR = 3
SPOOL_ERROR = 4
CODEPAGE = 5
OTHERS = 6.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
Converting OTF data to single line
LOOP AT I_OTF INTO W_OTF.
CONCATENATE W_OTF-TDPRINTCOM W_OTF-TDPRINTPAR
INTO W_PDF.
APPEND W_PDF TO I_CONTENT_TXT.
ENDLOOP.
Converting to PDF Format
CALL FUNCTION 'SX_OBJECT_CONVERT_OTF_PDF'
EXPORTING
FORMAT_SRC = C_OTF
FORMAT_DST = C_PDF
DEVTYPE = C_PRINTER
CHANGING
TRANSFER_BIN = W_TRANSFER_BIN
CONTENT_TXT = I_CONTENT_TXT
CONTENT_BIN = I_CONTENT_BIN
OBJHEAD = I_OBJHEAD
LEN = V_LEN_IN
EXCEPTIONS
ERR_CONV_FAILED = 1
OTHERS = 2.
V_SIZE = V_LEN_IN.
Downloading the PDF File
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
BIN_FILESIZE = V_SIZE
FILENAME = C_NAME
FILETYPE = C_BIN
TABLES
DATA_TAB = I_CONTENT_BIN.
for pdf to email
PARAMETERS : P_SPOOL TYPE TSP01-RQIDENT OBLIGATORY .
PARAMETERS : P_MAIL  TYPE CHAR100 OBLIGATORY .
TYPES : TY_LINE TYPE STRING.
DATA: IT_ATTACHMENT TYPE SOLI OCCURS 0 WITH HEADER LINE.
DATA: IT_ATTACHMENT_LONG TYPE TY_LINE OCCURS 0 WITH HEADER LINE.
DATA: LV_PDF_SIZE        TYPE I.
DATA: LT_PDF             TYPE STANDARD TABLE OF TLINE WITH HEADER LINE.
PERFORM SEND_EMAIL USING P_SPOOL P_MAIL.
FORM send_email
-->  X_SPOOL_ID
-->  X_EMAIL
FORM SEND_EMAIL USING X_SPOOL_ID X_EMAIL.
  DATA: LT_OBJPACK LIKE SOPCKLSTI1 OCCURS 2 WITH HEADER LINE,
        LT_OBJHEAD LIKE SOLISTI1 OCCURS 1 WITH HEADER LINE,
        LT_OBJBIN LIKE SOLISTI1 OCCURS 10 WITH HEADER LINE,
        LT_OBJTXT LIKE SOLISTI1 OCCURS 10 WITH HEADER LINE,
        LT_RECLIST LIKE SOMLRECI1 OCCURS 5 WITH HEADER LINE,
        LV_DOCUMENT_DATA TYPE SODOCCHGI1.
  DATA: L_ATT_LINES TYPE I.
  DATA : LV_SPOOL_DESC(68) TYPE C.
  CHECK NOT ( X_EMAIL IS INITIAL ).
  CLEAR: LT_RECLIST, LT_RECLIST[],
  LT_OBJHEAD, LT_OBJHEAD[],
  LT_OBJTXT, LT_OBJTXT[],
  LT_OBJBIN, LT_OBJBIN[],
  LT_OBJPACK, LT_OBJPACK[].
  CLEAR LV_DOCUMENT_DATA.
Read spool and get the pdf internal table and name of spool
  PERFORM READ_SPOOL USING X_SPOOL_ID LV_SPOOL_DESC.
  CHECK NOT ( LT_PDF[] IS INITIAL ).
Convert pdf itab to 255 line itab.
  DATA :LV_COUNTER  TYPE I.
  DATA :LV_FROM     TYPE I.
  LOOP AT LT_PDF.
    TRANSLATE  LT_PDF USING ' ~' .
    CONCATENATE IT_ATTACHMENT_LONG LT_PDF INTO IT_ATTACHMENT_LONG.
  ENDLOOP.
  TRANSLATE  IT_ATTACHMENT_LONG USING '~ ' .
  APPEND IT_ATTACHMENT_LONG.
  CLEAR : LV_COUNTER.
  DO.
    LV_COUNTER = STRLEN( IT_ATTACHMENT_LONG ).
    IF LV_COUNTER GE 255.
      IT_ATTACHMENT = IT_ATTACHMENT_LONG(255).
      APPEND IT_ATTACHMENT.
      SHIFT IT_ATTACHMENT_LONG BY 255 PLACES.
    ELSE.
      IT_ATTACHMENT = IT_ATTACHMENT_LONG(LV_COUNTER).
      APPEND IT_ATTACHMENT.
      EXIT.
    ENDIF.
  ENDDO.
Body of email
  MOVE 'Email sent to you from SAP' TO LT_OBJTXT.
  APPEND LT_OBJTXT.
  LV_DOCUMENT_DATA-OBJ_NAME = 'SpoolMail'.
Title of the email as spool name
  LV_DOCUMENT_DATA-OBJ_DESCR = LV_SPOOL_DESC.
  LV_DOCUMENT_DATA-SENSITIVTY = 'O'.
  LV_DOCUMENT_DATA-EXPIRY_DAT = SY-DATUM + 15.
  LV_DOCUMENT_DATA-DOC_SIZE = STRLEN( LT_OBJTXT ).
e-mail body
  CLEAR LT_OBJPACK.
  LT_OBJPACK-HEAD_START = 1.
  LT_OBJPACK-HEAD_NUM = 0.
  LT_OBJPACK-BODY_START = 1.
  LT_OBJPACK-BODY_NUM = 1.
  LT_OBJPACK-DOC_TYPE = 'RAW'.
  LT_OBJPACK-DOC_SIZE = STRLEN( LT_OBJTXT ).
  APPEND LT_OBJPACK.
For e-mail attachment
  DESCRIBE TABLE IT_ATTACHMENT LINES L_ATT_LINES.
  READ TABLE IT_ATTACHMENT INDEX L_ATT_LINES.
  CLEAR LT_OBJPACK.
  LT_OBJPACK-TRANSF_BIN = 'X'.
  LT_OBJPACK-HEAD_START = 1.
  LT_OBJPACK-HEAD_NUM = 1.
  LT_OBJPACK-BODY_START = 1.
  LT_OBJPACK-BODY_NUM = L_ATT_LINES.
  LT_OBJPACK-DOC_TYPE = 'PDF'.
  LT_OBJPACK-OBJ_NAME = 'email'.
  LT_OBJPACK-OBJ_DESCR = LV_SPOOL_DESC.
  LT_OBJPACK-DOC_SIZE = ( 255 * ( L_ATT_LINES - 1 ) ) + STRLEN(
  IT_ATTACHMENT-LINE ).
  APPEND LT_OBJPACK.
make recipient list
  LT_RECLIST-RECEIVER = X_EMAIL.
  LT_RECLIST-REC_TYPE = 'U'. "To external email id
  APPEND LT_RECLIST.
send mail with attachment
  CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
    EXPORTING
      DOCUMENT_DATA              = LV_DOCUMENT_DATA
      PUT_IN_OUTBOX              = 'X'
    TABLES
      PACKING_LIST               = LT_OBJPACK
      OBJECT_HEADER              = LT_OBJHEAD
      CONTENTS_BIN               = IT_ATTACHMENT
      CONTENTS_TXT               = LT_OBJTXT
      RECEIVERS                  = LT_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.
    WRITE:/ 'Message sent'.
  ELSE.
    WRITE:/ 'Error encountered'.
  ENDIF.
ENDFORM. " send_email
*&      Form  read_spool
FORM READ_SPOOL USING X_SPOOL_ID Y_SPOOL_DESC.
  DATA : LV_SPOOL_TYPE TYPE TSP01-RQDOCTYPE.
  SELECT SINGLE RQDOCTYPE RQTITLE
           INTO (LV_SPOOL_TYPE, Y_SPOOL_DESC)
           FROM TSP01
          WHERE RQIDENT EQ X_SPOOL_ID.
  IF Y_SPOOL_DESC IS INITIAL.
    CONCATENATE 'Spool-' X_SPOOL_ID INTO Y_SPOOL_DESC.
  ENDIF.
  IF LV_SPOOL_TYPE EQ 'LIST'.   " If spool is  a list
    CALL FUNCTION 'CONVERT_ABAPSPOOLJOB_2_PDF'
      EXPORTING
        SRC_SPOOLID                    = X_SPOOL_ID
  NO_DIALOG                      =
  DST_DEVICE                     =
  PDF_DESTINATION                =
      IMPORTING
        PDF_BYTECOUNT                  = LV_PDF_SIZE
  PDF_SPOOLID                    =
  LIST_PAGECOUNT                 =
  BTC_JOBNAME                    =
  BTC_JOBCOUNT                   =
      TABLES
        PDF                            = LT_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
       OTHERS                         = 12
    IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
        WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
  ELSE.            " If spool is OTF
    CALL FUNCTION 'CONVERT_OTFSPOOLJOB_2_PDF'
      EXPORTING
        SRC_SPOOLID                    = X_SPOOL_ID
  NO_DIALOG                      =
  DST_DEVICE                     =
  PDF_DESTINATION                =
     IMPORTING
       PDF_BYTECOUNT                  = LV_PDF_SIZE
  PDF_SPOOLID                    =
  OTF_PAGECOUNT                  =
  BTC_JOBNAME                    =
  BTC_JOBCOUNT                   =
     TABLES
       PDF                            = LT_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
       OTHERS                         = 12
    IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
        WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
  ENDIF.
ENDFORM.                    " read_spool
for pdf to email
its going to short dump here.can u please c wats wrong with it??
  IF Y_SPOOL_DESC IS INITIAL.
    CONCATENATE 'Spool-' X_SPOOL_ID INTO Y_SPOOL_DESC.
  ENDIF.

Similar Messages

  • Script to pdf to email????

    I have to convert a script to pdf format and then download it to presentation server and then send  it as an attachment by email ( to the external mail ids).
    please help me with this.
    waiting in anitcipation.
    regards.
    suki.

    Use...HRHAP_DOC_CONVERT_SMF_TO_PDF or SX_OBJECT_CONVERT_OTF_PDF
    or CONVERT_OTF_2_PDF to convert data to PDF...
    Use the below code to send an email...
    FUNCTION Z_SEND_EMAIL.
    ""Local interface:
    *"  IMPORTING
    *"     VALUE(SENDER) LIKE  SOUD3-USRNAM
    *"     VALUE(SUBJECT) LIKE  SOOD1-OBJDES
    *"     REFERENCE(SUPPRESS_COMMIT) TYPE  CHAR01 DEFAULT ''
    *"  TABLES
    *"      RECEIVERS
    *"      EMAIL_TEXT STRUCTURE  SOLI OPTIONAL
    *"  EXCEPTIONS
    *"      ACTIVE_USER_NOT_EXIST
    *"      COMMUNICATION_FAILURE
    *"      COMPONENT_NOT_AVAILABLE
    *"      FOLDER_NOT_EXIST
    *"      FOLDER_NO_AUTHORIZATION
    *"      FORWARDER_NOT_EXIST
    *"      NOTE_NOT_EXIST
    *"      OBJECT_NOT_EXIST
    *"      OBJECT_NOT_SENT
    *"      OBJECT_NO_AUTHORIZATION
    *"      OBJECT_TYPE_NOT_EXIST
    *"      OPERATION_NO_AUTHORIZATION
    *"      OWNER_NOT_EXIST
    *"      PARAMETER_ERROR
    *"      SUBSTITUTE_NOT_ACTIVE
    *"      SUBSTITUTE_NOT_DEFINED
    *"      SYSTEM_FAILURE
    *"      TOO_MUCH_RECEIVERS
    *"      USER_NOT_EXIST
    *"      ORIGINATOR_NOT_EXIST
    *"      X_ERROR
    *"      OTHERS
    Modification Log: (Please Flag all changes with the Correction Number)
    Date(MMDDYYYY) Programmer    Corr. #       TM ID
    Description:
    3/18/04        SpechtBN      D81K900520  Updated function module call
                                             for so_object_send, exception
                                             handling and commit work.
    03/02/2005     miranddn      D81K910999  Add option to suppress
    COMMIT WORK statement. Interfering with form outputs. Entered as
    optional parameter so that objects using this function can remain
    unchanged and the function will behave normally for them.
      CLEAR:   T_OBJECT_HD_CHANGE,
               T_USER,
               T_OBJCONT,
               T_OBJHEAD,
               T_OBJPARA,
               T_OBJPARB,
               T_RECEIVERS.
      REFRESH: T_OBJCONT,
               T_OBJHEAD,
               T_OBJPARA,
               T_OBJPARB,
               T_RECEIVERS.
    determine receivers:
      LOOP AT RECEIVERS.
        T_RECEIVERS-RCDAT         = SY-DATUM.
        T_RECEIVERS-RECESC        = 'U'.
        T_RECEIVERS-RECNAM        = 'U-'.
        T_RECEIVERS-RECEXTNAM     = RECEIVERS.
        T_RECEIVERS-SNDART        = 'INT'.
        T_RECEIVERS-SNDPRI        = 1.
        T_RECEIVERS-DELIVER       = 'X'.
        T_RECEIVERS-READ          = 'X'.
        T_RECEIVERS-ADR_NAME      = RECEIVERS.
        T_RECEIVERS-SORTFIELD     = RECEIVERS.
        T_RECEIVERS-SORTCLASS     = 5.
        T_RECEIVERS-SNDCP         = ' '.   " not a copy to ...
        APPEND T_RECEIVERS.
      ENDLOOP.
    Message Header (including subject)
      T_OBJECT_HD_CHANGE-OBJLA  = SY-LANGU.
      T_OBJECT_HD_CHANGE-OBJNAM = 'MESSAGE'.
    Subject
      T_OBJECT_HD_CHANGE-OBJDES = SUBJECT.
      T_OBJECT_HD_CHANGE-OBJSNS = 'S'." sensitivity Std,Func,Priv. S,F,P
      T_OBJECT_HD_CHANGE-VMTYP  = 'R'.     "object type T = transaction
      T_OBJECT_HD_CHANGE-ACNAM  = 'U'.
    Sender
      IF SENDER = SPACE.
        T_USER-SAPNAM             = SY-UNAME.
      ELSE.
        T_USER-SAPNAM             = SENDER.
      ENDIF.
      CALL FUNCTION 'SO_NAME_CONVERT'
        EXPORTING
          NAME_IN  = T_USER
        IMPORTING
          NAME_OUT = T_USER
        EXCEPTIONS
          OTHERS   = 8.
      IF SY-SUBRC NE 0.
        T_USER-SAPNAM      = 'SPECHTBN'.
      ENDIF.
      T_OBJPARA-NAME            = 'MESSAGE'.
      T_OBJPARA-LOW             = SY-DATUM.
      APPEND T_OBJPARA.
      CALL FUNCTION 'SO_OBJECT_SEND'
        EXPORTING
      FOLDER_ID                        = ' '
      FORWARDER                        = ' '
      OBJECT_FL_CHANGE                 = ' '
        OBJECT_HD_CHANGE                 = t_object_hd_change
      OBJECT_ID                        = ' '
        OBJECT_TYPE                      = 'RAW'
      OUTBOX_FLAG                      = ' '
        OWNER                            = SENDER
      STORE_FLAG                       = ' '
      DELETE_FLAG                      = ' '
      SENDER                           = ' '
      CHECK_SEND_AUTHORITY             = ' '
      CHECK_ALREADY_SENT               = ' '
      GIVE_OBJECT_BACK                 =
      ORIGINATOR                       = ' '
      ORIGINATOR_TYPE                  = 'J'
      LINK_FOLDER_ID                   = ' '
      SEND_REQUEST_OID                 = ' '
    IMPORTING
      OBJECT_ID_NEW                    =
      SENT_TO_ALL                      =
      ALL_BINDING_DONE                 =
      OFFICE_OBJECT_KEY                =
      ORIGINATOR_ID                    =
      E_SEND_REQUEST_OID               =
        TABLES
          OBJCONT                          = email_text
          OBJHEAD                          = t_objhead
          OBJPARA                          = t_objpara
          OBJPARB                          = t_objparb
          RECEIVERS                        = t_receivers
      PACKING_LIST                     =
      ATT_CONT                         =
      ATT_HEAD                         =
      NOTE_TEXT                        =
      LINK_LIST                        =
      APPLICATION_OBJECT               =
       EXCEPTIONS
         ACTIVE_USER_NOT_EXIST            = 1
         COMMUNICATION_FAILURE            = 2
         COMPONENT_NOT_AVAILABLE          = 3
         FOLDER_NOT_EXIST                 = 4
         FOLDER_NO_AUTHORIZATION          = 5
         FORWARDER_NOT_EXIST              = 6
         NOTE_NOT_EXIST                   = 7
         OBJECT_NOT_EXIST                 = 8
         OBJECT_NOT_SENT                  = 9
         OBJECT_NO_AUTHORIZATION          = 10
         OBJECT_TYPE_NOT_EXIST            = 11
         OPERATION_NO_AUTHORIZATION       = 12
         OWNER_NOT_EXIST                  = 13
         PARAMETER_ERROR                  = 14
         SUBSTITUTE_NOT_ACTIVE            = 15
         SUBSTITUTE_NOT_DEFINED           = 16
         SYSTEM_FAILURE                   = 17
         TOO_MUCH_RECEIVERS               = 18
         USER_NOT_EXIST                   = 19
         ORIGINATOR_NOT_EXIST             = 20
         X_ERROR                          = 21
         OTHERS                           = 22
      IF SY-SUBRC <> 0.
        case sy-subrc.
          when 1.
            raise ACTIVE_USER_NOT_EXIST.
          when 2.
            raise COMMUNICATION_FAILURE.
          when 3.
            raise COMPONENT_NOT_AVAILABLE.
          when 4.
            raise FOLDER_NOT_EXIST.
          when 5.
            raise FOLDER_NO_AUTHORIZATION.
          when 6.
            raise FORWARDER_NOT_EXIST.
          when 7.
            raise NOTE_NOT_EXIST.
          when 8.
            raise OBJECT_NOT_EXIST.
          when 9.
            raise OBJECT_NOT_SENT.
          when 10.
            raise OBJECT_NO_AUTHORIZATION.
          when 11.
            raise OBJECT_TYPE_NOT_EXIST.
          when 12.
            raise OPERATION_NO_AUTHORIZATION.
          when 13.
            raise OWNER_NOT_EXIST.
          when 14.
            raise PARAMETER_ERROR.
          when 15.
            raise SUBSTITUTE_NOT_ACTIVE.
          when 16.
            raise SUBSTITUTE_NOT_DEFINED.
          when 17.
            raise SYSTEM_FAILURE.
          when 18.
            raise TOO_MUCH_RECEIVERS.
          when 19.
            raise USER_NOT_EXIST.
          when 20.
            raise ORIGINATOR_NOT_EXIST.
          when 21.
            raise X_ERROR.
          when 22.
            raise OTHERS.
        endcase.
      ENDIF.
    Begin of D81K910999
    if suppress_commit is initial.
      commit work.
    else.
    Do nothing
    endif.
    End of D81K910999
    ENDFUNCTION.

  • Convert Script to PDF using RVADOPFO, w/o using spool and send via email

    I want to convert output type script to pdf using the standard include RVADOPFO in the program. The output type is defined as medium '5' and comm starategy is also defined as INT(email) as want to send the output via email.
    Now the Include RVADOPFO contains ADDR_KEY-ADDRNUMBER & ADDR_KEY-PERSNUMBER. Where to maintain this info and how to pass in the include..below code is in the include..
    IF NOT NAST-TCODE IS INITIAL AND NAST-NACHA EQ '5'.
      ... use stratagy to get communication type
        CALL FUNCTION 'ADDR_GET_NEXT_COMM_TYPE'
             EXPORTING
                  STRATEGY           = NAST-TCODE
                ADDRESS_TYPE       =
                ADDRESS_NUMBER     = VBDKA-ADRNR
                PERSON_NUMBER      = VBDKA-ADRNP
                  ADDRESS_NUMBER     = ADDR_KEY-ADDRNUMBER
                  PERSON_NUMBER      = ADDR_KEY-PERSNUMBER
             IMPORTING
                  COMM_TYPE          = LVS_COMM_TYPE
                  COMM_VALUES        = LVS_COMM_VALUES
           TABLES
                STRATEGY_TABLE     =
             EXCEPTIONS
                  ADDRESS_NOT_EXIST  = 1
                  PERSON_NOT_EXIST   = 2
                  NO_COMM_TYPE_FOUND = 3
                  INTERNAL_ERROR     = 4
                  PARAMETER_ERROR    = 5
                  OTHERS             = 6.
    Please provide solution asap. Thanks in advance

    Hi,
    Check this links:
    Sending Mail from SAP
    https://wiki.sdn.sap.com/wiki/display/sandbox/SendMailwithPDFAttachment?showChildren=false#children
    Thanks.

  • How to convert sap script to pdf and send it as email attachment

    hi,
    my requirement is to convert a standard sales order form to pdf and send it as email attachment. get me some sample code for the same
    thanks in advance

    Hi
    See this sample code and after that use the fun module to send the mail
    SO_NEW_DOCUMENT_ATT_SEND_API1
    REPORT zzz_jaytest .
    Types Declaration
    TYPES : BEGIN OF ty_pa0001,
    pernr TYPE pa0001-pernr,
    bukrs TYPE pa0001-bukrs,
    werks TYPE pa0001-werks,
    END OF ty_pa0001.
    Internal Table Declaration
    DATA : i_pa0001 TYPE STANDARD TABLE OF ty_pa0001, "For pa0001 Details
    i_otf TYPE STANDARD TABLE OF itcoo, "For OTF data
    i_content_txt TYPE soli_tab, "Content
    i_content_bin TYPE solix_tab, "Content
    i_objhead TYPE soli_tab,
    Work Area Declaration
    w_pa0001 TYPE ty_pa0001, "For pa0001 Details
    w_res TYPE itcpp, "SAPscript output
    "parameters
    w_otf TYPE itcoo, "For OTF
    w_pdf TYPE solisti1, "For PDF
    w_transfer_bin TYPE sx_boolean, "Content
    w_options TYPE itcpo, "SAPscript output
    "interface
    Variable Declaration
    v_len_in TYPE so_obj_len,
    v_size TYPE i.
    Constants Declaration
    CONSTANTS : c_x TYPE c VALUE 'X', "X
    c_locl(4) TYPE c VALUE 'LOCL', "Local Printer
    c_otf TYPE sx_format VALUE 'OTF', "OTF
    c_pdf TYPE sx_format VALUE 'PDF', "PDF
    c_printer TYPE sx_devtype VALUE 'PRINTER', "PRINTER
    c_bin TYPE char10 VALUE 'BIN', "BIN
    c_name TYPE string VALUE 'C:\ZZZ_JAYTEST.PDF',"Downloading
    "File Name
    c_form(11) TYPE c VALUE 'ZZZ_JAYTEST'. "Form Name
    START-OF-SELECTION.
    Selecting the records from pa0001
    SELECT pernr bukrs werks FROM pa0001
    INTO TABLE i_pa0001 UP TO 10 ROWS.
    Setting the options
    w_options-tdcopies = 1 ."Number of copies
    w_options-tdnoprev = c_x."No print preview
    w_options-tdgetotf = c_x."Return of OTF table
    w_options-tddest = c_locl."Spool: Output device
    Opening the form
    CALL FUNCTION 'OPEN_FORM'
    EXPORTING
    form = c_form
    device = c_printer
    language = sy-langu
    OPTIONS = w_options
    IMPORTING
    RESULT = w_res.
    LOOP AT i_pa0001 INTO w_pa0001.
    Writting into the form
    CALL FUNCTION 'WRITE_FORM'
    EXPORTING
    element = 'MAIN'
    window = 'MAIN'.
    ENDLOOP.
    Closing the form
    CALL FUNCTION 'CLOSE_FORM'
    IMPORTING
    RESULT = w_res
    TABLES
    otfdata = i_otf
    EXCEPTIONS
    unopened = 1
    bad_pageformat_for_print = 2
    send_error = 3
    spool_error = 4
    codepage = 5
    OTHERS = 6.
    IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
    WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
    ENDIF.
    Converting OTF data to single line
    LOOP AT i_otf INTO w_otf.
    CONCATENATE w_otf-tdprintcom w_otf-tdprintpar
    INTO w_pdf.
    APPEND w_pdf TO i_content_txt.
    ENDLOOP.
    Converting to PDF Format
    CALL FUNCTION 'SX_OBJECT_CONVERT_OTF_PDF'
    EXPORTING
    format_src = c_otf
    format_dst = c_pdf
    devtype = c_printer
    CHANGING
    transfer_bin = w_transfer_bin
    content_txt = i_content_txt
    content_bin = i_content_bin
    objhead = i_objhead
    len = v_len_in
    EXCEPTIONS
    err_conv_failed = 1
    OTHERS = 2.
    v_size = v_len_in.
    Downloading the PDF File
    CALL FUNCTION 'GUI_DOWNLOAD'
    EXPORTING
    bin_filesize = v_size
    filename = c_name
    filetype = c_bin
    TABLES
    data_tab = i_content_bin.
    If you r using this function module check it once....
    call function 'CONVERT_OTF'
    EXPORTING
    format = 'PDF'
    max_linewidth = 132
    IMPORTING
    bin_filesize = v_len_in
    TABLES
    otf = i_otf
    lines = i_tline
    EXCEPTIONS
    err_max_linewidth = 1
    err_format = 2
    err_conv_not_possible = 3
    others = 4.
    Fehlerhandling
    if sy-subrc <> 0.
    endif.
    or u can use the standard program RSTXPDFT4 to download the script into PDF format onto a particular location
    follow this link for sample program.
    http://searchsap.techtarget.com/tip/0,289483,sid21_gci1121833,00.html
    check...
    How to send smart form via email
    /people/pavan.bayyapu/blog/2005/08/30/sending-html-email-from-sap-crmerp
    Regards
    Anji

  • Dynamic CRM 2013 Online how to execute Report, generate PDF and email

    Dear All,
    I am using Dynamic CRM 2013 online. For quote, I have workflow and Dialogue processes for review process. On approval, I want the system to generate a PDF of quote report, attach the PDF and email it to the Customer.
    Better I would like, When approver, clicks on the approve button, the system should auto generate a PDF of quote report, attach the PDF and email it to the Customer, without any further input from the user. If its not possible, I may have to put button on
    quote form.
    I am using the attached code, but facing various issues.
    1. Under prepare the SOAP Message coding part, I am not sure what should be the below URL for CRM 2013 Online?
    xHReq.Open("POST", "/mscrmservices/2007/CrmService.asmx", false);
    2. What should be the emailid here? Is it Recepient Contact id(Guid) ?
    var emailid = resultXml.selectSingleNode("//CreateResult").nodeTypedValue;
    alert("emailid" + emailid.toString());
    3. Using this code, not able to create Entity for "ActivityMimeAttachment", I am getting newEntity as undefined.
    Below is the code I am using. Please check and help me out, where I am going wrong. Let me know if any better way to implement it. At present, I have put one button on quote form, on click event, below code will get executed.
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <title></title>
    <script type="text/javascript">
    var Xrm;
    if (window.opener) { Xrm = window.opener.Xrm; }
    else if (window.parent) { Xrm = window.parent.Xrm; }
    function getReportingSession() {
    var reportName = "Quotation_Report"; //set this to the report you are trying to download
    var reportId = "7C39D18F-1DC6-E311-8986-D89D6765B238"; //set this to the guid of the report you are trying to download
    var recordid = Xrm.Page.data.entity.getId();
    // recordid = recordid.substring(1, 37); //getting rid of curly brackets
    alert(recordid);
    var pth = Xrm.Page.context.getServerUrl() + "/CRMReports/rsviewer/reportviewer.aspx";
    var retrieveEntityReq = new XMLHttpRequest();
    retrieveEntityReq.open("POST", pth, false);
    retrieveEntityReq.setRequestHeader("Accept", "*/*");
    retrieveEntityReq.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    retrieveEntityReq.send("id=%7B" + reportId + "%7D&uniquename=" + Xrm.Page.context.getOrgUniqueName() + "&iscustomreport=true&reportnameonsrs=&reportName=" + reportName + "&isScheduledReport=false");
    var x = retrieveEntityReq.responseText.indexOf("ReportSession=");
    var ret = new Array();
    ret[0] = retrieveEntityReq.responseText.substr(x + 14, retrieveEntityReq.responseText.indexOf("&", x) - x - 14); //the session id
    x = retrieveEntityReq.responseText.indexOf("ControlID=");
    ret[1] = retrieveEntityReq.responseText.substr(x + 10, retrieveEntityReq.responseText.indexOf("&", x) - x - 10); //the control id
    return ret;
    function createEntity(ent, entName, upd) {
    var jsonEntity = JSON.stringify(ent);
    var createEntityReq = new XMLHttpRequest();
    var ODataPath = Xrm.Page.context.getServerUrl() + "XRMServices/2011/OrganizationData.svc";
    createEntityReq.open("POST", ODataPath + "/" + entName + "Set" + upd, false);
    createEntityReq.setRequestHeader("Accept", "application/json");
    createEntityReq.setRequestHeader("Content-Type", "application/json; charset=utf-8");
    createEntityReq.send(jsonEntity);
    var newEntity = JSON.parse(createEntityReq.responseText).d;
    alert("new entity" + newEntity);
    return newEntity;
    function createAttachment() {
    var params = getReportingSession();
    var recordid = Xrm.Page.data.entity.getId();
    alert("recordid " + recordid);
    var orgName = Xrm.Page.context.getOrgUniqueName();
    var userID = Xrm.Page.context.getUserId();
    //create email record
    // Prepare the SOAP message.
    var xml = "<?xml version='1.0' encoding='utf-8'?>" +"<soap:Envelope xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'" +
    " xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'" +
    " xmlns:xsd='http://www.w3.org/2001/XMLSchema'>" +
    "<soap:Header>" +
    "</soap:Header>" +
    "<soap:Body>" +
    "<Create xmlns='http://schemas.microsoft.com/crm/2007/WebServices'>" +
    "<entity xsi:type='email'>" +
    "<regardingobjectid type='quote'>" + recordid + "</regardingobjectid>" +
    "<subject>" + "Email with Attachment4" + "</subject>" +
    "</entity>" +
    "</Create>" +
    "</soap:Body>" +
    "</soap:Envelope>";
    // Prepare the xmlHttpObject and send the request.
    var xHReq = new ActiveXObject("Msxml2.XMLHTTP");
    xHReq.Open("POST", "/mscrmservices/2007/CrmService.asmx", false);
    xHReq.setRequestHeader("SOAPAction", "http://schemas.microsoft.com/crm/2007/WebServices/Create");
    xHReq.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
    xHReq.setRequestHeader("Content-Length", xml.length);
    xHReq.send(xml);
    // Capture the result
    var resultXml = xHReq.responseXML;
    // alert("resultXml " + resultXml);
    // Check for errors.
    var errorCount = resultXml.selectNodes('//error').length;
    if (errorCount != 0) {
    alert("ERROR");
    var msg = resultXml.selectSingleNode('//description').nodeTypedValue;
    alert(msg);
    var emailid = resultXml.selectSingleNode("//CreateResult").nodeTypedValue;
    alert("emailid" + emailid.toString());
    //var emailid = userID;
    var post = Object();
    post.Body = encodePdf(params);
    var email = new Array();
    email[0] =new Object();
    email[0].id = emailid;
    email[0].entityType ='email';
    post.Subject ="File Attachment";
    post.AttachmentNumber = 1;
    post.FileName ="Report.pdf";
    post.MimeType ="application/pdf";
    post.ObjectId = Object();
    post.ObjectId.LogicalName ="email";
    post.ObjectId.Id = email[0].id;
    post.ObjectTypeCode ="email";
    alert(post.ObjectId.Id);
    createEntity(post,"ActivityMimeAttachment", "");
    alert("created successfully");
    email.Subject = "Your Order";
    //Set The current order as the Regarding object
    email.RegardingObjectId = {
    Id: Xrm.Page.data.entity.getId(), //Get the current entity Id , here OrderId
    LogicalName: Xrm.Page.data.entity.getEntityName()//Get the current entity name, here it will be “salesOrder”
    //Create Email Activity
    SDK.JScriptRESTDataOperations.Create(email, "Email", EmailCallBack, function (error) { alert(error.message); });
    // Email Call Back function
    function EmailCallBack(result) {
    email = result; // Set the email to result to use it later in email attachment for retrieving activity Id
    var activityPartyFrom = new Object();
    // Set the From party of the ActivityParty to relate an entity with Email From field
    activityPartyFrom.PartyId = {
    Id: customerId, // id of entity you want to associate this activity with.
    LogicalName: "contact"
    // Set the "activity" of the ActivityParty
    activityPartyFrom.ActivityId = {
    Id: result.ActivityId,
    LogicalName: "email"
    // Now set the participation type that describes the role of the party on the activity).
    activityPartyFrom.ParticipationTypeMask = { Value: 2 }; // 2 means ToRecipients
    // Create the from ActivityParty for the email
    SDK.JScriptRESTDataOperations.Create(activityPartyFrom, "ActivityParty", ActivityPartyFromCallBack, function (error) { alert(error.message); });
    var activityPartyTo = new Object();
    // Set the From party of the ActivityParty to relate an entity with Email From field
    activityPartyTo.PartyId = {
    Id: ownerId, // id of entity you want to associate this activity with.
    LogicalName: "systemuser"
    // Set the "activity" of the ActivityParty
    activityPartyTo.ActivityId = {
    Id: result.ActivityId,
    LogicalName: "email"
    // Now set the participation type that describes the role of the party on the activity). activityPartyTo.ParticipationTypeMask = { Value: 1 }; // 1 means Sender
    // Create the from ActivityParty
    SDK.JScriptRESTDataOperations.Create(activityPartyTo, "ActivityParty", ActivityPartyToCallBack, function (error) { alert(error.message); });
    //ActivityParty From Callback
    function ActivityPartyFromCallBack(result) {
    //ActivityParty To Callback
    function ActivityPartyToCallBack(result) {
    var StringMaker = function () {
    this.parts = [];
    this.length = 0;
    this.append = function (s) {
    this.parts.push(s);
    this.length += s.length;
    this.prepend = function (s) {
    this.parts.unshift(s);
    this.length += s.length;
    this.toString = function () {
    return this.parts.join('');
    var keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
    function encode64(input) {
    var output = new StringMaker();
    var chr1, chr2, chr3;
    var enc1, enc2, enc3, enc4;
    var i = 0;
    while (i < input.length) {
    chr1 = input[i++];
    chr2 = input[i++];
    chr3 = input[i++];
    enc1 = chr1 >> 2;
    enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
    enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
    enc4 = chr3 & 63;
    if (isNaN(chr2)) {
    enc3 = enc4 = 64;
    else if (isNaN(chr3)) {
    enc4 = 64;
    output.append(keyStr.charAt(enc1) + keyStr.charAt(enc2) + keyStr.charAt(enc3) + keyStr.charAt(enc4));
    return output.toString();
    var bdy = new Array();
    var bdyLen = 0;
    function concat2Bdy(x) {
    bdy[bdyLen] = x;
    bdyLen++;
    function encodePdf(params) {
    bdy = new Array();
    bdyLen = 0;
    var retrieveEntityReq = new XMLHttpRequest();
    var pth = Xrm.Page.context.getServerUrl() + "/Reserved.ReportViewerWebControl.axd?ReportSession=" + params[0] + "&Culture=1033&CultureOverrides=True&UICulture=1033&UICultureOverrides=True&ReportStack=1&ControlID=" + params[1] + "&OpType=Export&FileName=Public&ContentDisposition=OnlyHtmlInline&Format=PDF";
    retrieveEntityReq.open("GET", pth, false);
    retrieveEntityReq.setRequestHeader("Accept", "*/*");
    retrieveEntityReq.send();
    BinaryToArray(retrieveEntityReq.responseBody);
    return encode64(bdy);
    </SCRIPT>
    <SCRIPT type=text/vbscript>
    Function BinaryToArray(Binary)
    Dim i
    ReDim byteArray(LenB(Binary))
    For i = 1 To LenB(Binary)
    byteArray(i-1) = AscB(MidB(Binary, i, 1))
    concat2Bdy(AscB(MidB(Binary, i, 1)))
    Next
    BinaryToArray = byteArray
    End Function
    </SCRIPT>
    </head>
    <body>
    <input type="button" onclick="createAttachment();" value="Attach Report" />
    </body>
    </html>
    Thanks. and waiting for your valuable comments.
    - Mittal

    Hello,
    Yes, I was able to make my code working as below. Tested on CRM online 2013.
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <title></title>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.1/jquery.min.js"></script>
    <script type="text/javascript">
    if (typeof (SDK) == "undefined")
    { SDK = { __namespace: true }; }
    SDK.JScriptRESTDataOperations = {
    _context: function () {
    if (typeof GetGlobalContext != "undefined")
    { return GetGlobalContext(); }
    else {
    if (typeof Xrm != "undefined") {
    return Xrm.Page.context;
    else { return new Error("Context is not available."); }
    _getServerUrl: function () {
    var serverUrl = this._context().getServerUrl()
    if (serverUrl.match(/\/$/)) {
    serverUrl = serverUrl.substring(0, serverUrl.length - 1);
    return serverUrl;
    _ODataPath: function () {
    return this._getServerUrl() + "/XRMServices/2011/OrganizationData.svc/";
    _errorHandler: function (req) {
    return new Error("Error : " +
    req.status + ": " +
    req.statusText + ": " +
    JSON.parse(req.responseText).error.message.value);
    _dateReviver: function (key, value) {
    var a;
    if (typeof value === 'string') {
    a = /Date\(([-+]?\d+)\)/.exec(value);
    if (a) {
    return new Date(parseInt(value.replace("/Date(", "").replace(")/", ""), 10));
    return value;
    Create: function (object, type, successCallback, errorCallback) {
    var req = new XMLHttpRequest();
    req.open("POST", this._ODataPath() + type + "Set", true);
    req.setRequestHeader("Accept", "application/json");
    req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
    req.onreadystatechange = function () {
    if (this.readyState == 4 /* complete */) {
    if (this.status == 201) {
    successCallback(JSON.parse(this.responseText, SDK.JScriptRESTDataOperations._dateReviver).d);
    else {
    errorCallback(SDK.JScriptRESTDataOperations._errorHandler(this));
    req.send(JSON.stringify(object));
    Retrieve: function (id, type, successCallback, errorCallback) {
    var req = new XMLHttpRequest();
    req.open("GET", this._ODataPath() + type + "Set(guid'" + id + "')", true);
    req.setRequestHeader("Accept", "application/json");
    req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
    req.onreadystatechange = function () {
    if (this.readyState == 4 /* complete */) {
    if (this.status == 200) {
    successCallback(JSON.parse(this.responseText, SDK.JScriptRESTDataOperations._dateReviver).d);
    else {
    errorCallback(SDK.JScriptRESTDataOperations._errorHandler(this));
    req.send();
    Update: function (id, object, type, successCallback, errorCallback) {
    var req = new XMLHttpRequest();
    req.open("POST", this._ODataPath() + type + "Set(guid'" + id + "')", true);
    req.setRequestHeader("Accept", "application/json");
    req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
    req.setRequestHeader("X-HTTP-Method", "MERGE");
    req.onreadystatechange = function () {
    if (this.readyState == 4 /* complete */) {
    if (this.status == 204 || this.status == 1223) {
    successCallback();
    else {
    errorCallback(SDK.JScriptRESTDataOperations._errorHandler(this));
    req.send(JSON.stringify(object));
    Delete: function (id, type, successCallback, errorCallback) {
    var req = new XMLHttpRequest();
    req.open("POST", this._ODataPath() + type + "Set(guid'" + id + "')", true);
    req.setRequestHeader("Accept", "application/json");
    req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
    req.setRequestHeader("X-HTTP-Method", "DELETE");
    req.onreadystatechange = function () {
    if (this.readyState == 4 /* complete */) {
    if (this.status == 204 || this.status == 1223) {
    successCallback();
    else {
    errorCallback(SDK.JScriptRESTDataOperations._errorHandler(this));
    req.send();
    RetrieveMultiple: function (type, filter, successCallback, errorCallback) {
    if (filter != null) {
    filter = "?" + filter;
    else { filter = ""; }
    var req = new XMLHttpRequest();
    req.open("GET", this._ODataPath() + type + "Set" + filter, true);
    req.setRequestHeader("Accept", "application/json");
    req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
    req.onreadystatechange = function () {
    if (this.readyState == 4 /* complete */) {
    if (this.status == 200) {
    successCallback(JSON.parse(this.responseText, SDK.JScriptRESTDataOperations._dateReviver).d.results);
    else {
    errorCallback(SDK.JScriptRESTDataOperations._errorHandler(this));
    req.send();
    __namespace: true
    </script>
    <script type="text/javascript">
    //Create Email and link it with Order as Regarding field
    var Xrm;
    var email = new Object();
    var ownerID = "";
    var CustomerId = "";
    if (window.opener) { Xrm = window.opener.Xrm; }
    else if (window.parent) { Xrm = window.parent.Xrm; }
    //Get ownerid who send email of quotation to customer
    function GetOwnerID() {
    var owner = Xrm.Page.getAttribute("ownerid").getValue();
    ownerID = owner[0].id;
    var ownerName = owner[0].name;
    var entityType = owner[0].entityType;
    GetToEmailGUID();
    //Get customerid who receive email of quotation from owner
    function GetToEmailGUID() {
    var Customer = Xrm.Page.getAttribute('customerid').getValue();
    CustomerId = Customer[0].id;
    var CustomerName = Customer[0].name;
    var entityType = Customer[0].entityType;
    //if CustomerId is type of "Account" then get Primary Contact id of that account
    if (entityType == "account") {
    var contact = Xrm.Page.getAttribute("customerid").getValue();
    if (contact === null) return;
    var serverUrl = Xrm.Page.context.getClientUrl();
    var oDataSelect = serverUrl + "/XRMServices/2011/OrganizationData.svc/AccountSet(guid'" + contact[0].id + "')?$select=PrimaryContactId";
    var req = new XMLHttpRequest();
    req.open("GET", oDataSelect, false);
    req.setRequestHeader("Accept", "application/json");
    req.setRequestHeader("Content-Type", "application/json;charset=utf-8");
    req.onreadystatechange = function () {
    if (req.readyState === 4) {
    if (req.status === 200) {
    var retrieved = JSON.parse(req.responseText).d;
    CustomerId = retrieved.PrimaryContactId.Id;
    else {
    alert(this.statusText);
    req.send();
    function CreateEmail() {
    GetOwnerID();
    email.Subject = "Email with Report Attachment";
    //Set The current order as the Regarding object
    email.RegardingObjectId = {
    Id: Xrm.Page.data.entity.getId(), //Get the current entity Id , here OrderId
    LogicalName: Xrm.Page.data.entity.getEntityName()//Get the current entity name, here it will be “salesOrder”
    //Create Email Activity
    SDK.JScriptRESTDataOperations.Create(email, "Email", EmailCallBack, function (error) { alert(error.message); });
    // Email Call Back function
    function EmailCallBack(result) {
    email = result; // Set the email to result to use it later in email attachment for retrieving activity Id
    var activityPartyFrom = new Object();
    // Set the From party of the ActivityParty to relate an entity with Email From field
    activityPartyFrom.PartyId = {
    Id: CustomerId, //"79EBDD26-FDBE-E311-8986-D89D6765B238", // id of entity you want to associate this activity with.
    LogicalName: "contact"
    // Set the "activity" of the ActivityParty
    activityPartyFrom.ActivityId = {
    Id: result.ActivityId,
    LogicalName: "email"
    // Now set the participation type that describes the role of the party on the activity).
    activityPartyFrom.ParticipationTypeMask = { Value: 2 }; // 2 means ToRecipients
    // Create the from ActivityParty for the email
    SDK.JScriptRESTDataOperations.Create(activityPartyFrom, "ActivityParty", ActivityPartyFromCallBack, function (error) { alert(error.message); });
    var activityPartyTo = new Object();
    // Set the From party of the ActivityParty to relate an entity with Email From field
    activityPartyTo.PartyId = {
    Id: ownerID, //"79EBDD26-FDBE-E311-8986-D89D6765B238", // id of entity you want to associate this activity with.
    LogicalName: "systemuser"
    // Set the "activity" of the ActivityParty
    activityPartyTo.ActivityId = {
    Id: result.ActivityId,
    LogicalName: "email"
    // Now set the participation type that describes the role of the party on the activity).
    activityPartyTo.ParticipationTypeMask = { Value: 1 }; // 1 means Sender
    // Create the from ActivityParty
    SDK.JScriptRESTDataOperations.Create(activityPartyTo, "ActivityParty", ActivityPartyToCallBack, function (error) { alert(error.message); });
    //ActivityParty From Callback
    function ActivityPartyFromCallBack(result) {
    //ActivityParty To Callback
    function ActivityPartyToCallBack(result) {
    GetReportId('Quotation');
    //Create attachment for the created email
    function CreateEmailAttachment() {
    //get reporting session and use the params to convert a report in PDF
    var params = getReportingSession();
    //Email attachment parameters
    var activitymimeattachment = Object();
    activitymimeattachment.ObjectId = Object();
    activitymimeattachment.ObjectId.LogicalName = "email";
    activitymimeattachment.ObjectId.Id = email.ActivityId;
    activitymimeattachment.ObjectTypeCode = "email",
    activitymimeattachment.Subject = "File Attachment";
    activitymimeattachment.Body = encodePdf(params);
    activitymimeattachment.FileName = "Report.pdf";
    activitymimeattachment.MimeType = "application/pdf";
    //Attachment call
    SDK.JScriptRESTDataOperations.Create(activitymimeattachment, "ActivityMimeAttachment", ActivityMimeAttachmentCallBack, function (error) { alert(error.message); });
    //ActivityMimeAttachment CallBack function
    function ActivityMimeAttachmentCallBack(result) {
    var features = "location=no,menubar=no,status=no,toolbar=no,resizable=yes";
    var width = "800px";
    var height = "600px";
    window.open(Xrm.Page.context.getServerUrl() + "main.aspx?etc=" + 4202 + "&pagetype=entityrecord&id=" + email.ActivityId, "_blank", features);
    // To open window which works in outlook and IE both
    //openStdWin(Xrm.Page.context.getServerUrl() + "main.aspx?etc=" + 4202 + "&pagetype=entityrecord&id=" + email.ActivityId, "_blank", width, height, features);
    //This method will get the reportId based on a report name that will be used in getReportingSession() function
    function GetReportId(reportName) {
    var oDataSetName = "ReportSet";
    var columns = "ReportId";
    var filter = "Name eq '" + reportName + "'";
    retrieveMultiple(oDataSetName, columns, filter, onSuccess);
    function retrieveMultiple(odataSetName, select, filter, successCallback) {
    var serverUrl = Xrm.Page.context.getServerUrl();
    var ODATA_ENDPOINT = "/XRMServices/2011/OrganizationData.svc";
    var odataUri = serverUrl + ODATA_ENDPOINT + "/" + odataSetName + "?";
    if (select) {
    odataUri += "$select=" + select + "&";
    if (filter) {
    odataUri += "$filter=" + filter;
    $.ajax({
    type: "GET",
    contentType: "application/json; charset=utf-8",
    datatype: "json",
    url: odataUri,
    beforeSend: function (XMLHttpRequest) {
    XMLHttpRequest.setRequestHeader("Accept", "application/json");
    success: function (data) {
    if (successCallback) {
    if (data && data.d && data.d.results) {
    successCallback(data.d.results);
    else if (data && data.d) {
    successCallback(data.d);
    else {
    successCallback(data);
    error: function (XmlHttpRequest, errorThrown) {
    if (XmlHttpRequest && XmlHttpRequest.responseText) {
    alert("Error while retrieval ; Error – " + XmlHttpRequest.responseText);
    function onSuccess(data) {
    reportId = data[0].ReportId.replace('{', ").replace('}', ");
    CreateEmailAttachment(); // Create Email Attachment
    //Gets the report contents
    function getReportingSession() {
    var pth = Xrm.Page.context.getServerUrl() + "/CRMReports/rsviewer/reportviewer.aspx";
    var retrieveEntityReq = new XMLHttpRequest();
    var Id = Xrm.Page.data.entity.getId();
    var quotationGUID = Id.replace('{', ""); //set this to selected quotation GUID
    quotationGUID = quotationGUID.replace('}', "");
    var reportName = "Quotation"; //set this to the report you are trying to download
    var reportID = "7C39D18F-1DC6-E311-8986-D89D6765B238"; //set this to the guid of the report you are trying to download
    var rptPathString = ""; //set this to the CRMF_Filtered parameter
    var strParameterXML = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'><entity name='quote'><all-attributes /><filter type='and'><condition attribute='quoteid' operator='eq' uitype='quote' value='" + quotationGUID + "' /> </filter></entity></fetch>";
    retrieveEntityReq.open("POST", pth, false);
    retrieveEntityReq.setRequestHeader("Accept", "*/*");
    retrieveEntityReq.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    rptPathString = "id=%7B" + reportID + "%7D&uniquename=" + Xrm.Page.context.getOrgUniqueName() + "&iscustomreport=true&reportnameonsrs=&reportName=" +
    reportName + "&isScheduledReport=false&p:CRMAF_Filteredquote=" + strParameterXML;
    //remove the part starting from &p:salesorderid if your report has no parameters
    retrieveEntityReq.send(rptPathString);
    var x = retrieveEntityReq.responseText.indexOf("ReportSession=");
    var ret = new Array();
    ret[0] = retrieveEntityReq.responseText.substr(x + 14, retrieveEntityReq.responseText.indexOf("&", x) - x - 14); //the session id
    x = retrieveEntityReq.responseText.indexOf("ControlID=");
    ret[1] = retrieveEntityReq.responseText.substr(x + 10, retrieveEntityReq.responseText.indexOf("&", x) - x - 10); //the control id
    return ret;
    var bdy = new Array();
    var bdyLen = 0;
    function concat2Bdy(x) {
    bdy[bdyLen] = x;
    bdyLen++;
    function encodePdf(params) {
    bdy = new Array();
    bdyLen = 0;
    var retrieveEntityReq = new XMLHttpRequest();
    var pth = Xrm.Page.context.getServerUrl() + "/Reserved.ReportViewerWebControl.axd?ReportSession=" + params[0] +
    "&Culture=1033&CultureOverrides=True&UICulture=1033&UICultureOverrides=True&ReportStack=1&ControlID=" + params[1] +
    "&OpType=Export&FileName=Public&ContentDisposition=OnlyHtmlInline&Format=PDF";
    retrieveEntityReq.open("GET", pth, false);
    retrieveEntityReq.setRequestHeader("Accept", "*/*");
    retrieveEntityReq.send();
    BinaryToArray(retrieveEntityReq.responseBody);
    return encode64(bdy);
    var StringMaker = function () {
    this.parts = [];
    this.length = 0;
    this.append = function (s) {
    this.parts.push(s);
    this.length += s.length;
    this.prepend = function (s) {
    this.parts.unshift(s);
    this.length += s.length;
    this.toString = function () {
    return this.parts.join('');
    var keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
    function encode64(input) {
    var output = new StringMaker();
    var chr1, chr2, chr3;
    var enc1, enc2, enc3, enc4;
    var i = 0;
    while (i < input.length) {
    chr1 = input[i++];
    chr2 = input[i++];
    chr3 = input[i++];
    enc1 = chr1 >> 2;
    enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
    enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
    enc4 = chr3 & 63;
    if (isNaN(chr2)) {
    enc3 = enc4 = 64;
    } else if (isNaN(chr3)) {
    enc4 = 64;
    output.append(keyStr.charAt(enc1) + keyStr.charAt(enc2) + keyStr.charAt(enc3) + keyStr.charAt(enc4));
    return output.toString();
    </script>
    <script type="text/vbscript">
    Function BinaryToArray(Binary)
    Dim i
    ReDim byteArray(LenB(Binary))
    For i = 1 To LenB(Binary)
    byteArray(i-1) = AscB(MidB(Binary, i, 1))
    concat2Bdy(AscB(MidB(Binary, i, 1)))
    Next
    BinaryToArray = byteArray
    End Function
    </script>
    </head>
    <body>
    <input type="button" onclick="CreateEmail();" value="Attach Report" />
    </body>
    </html>
    Thank you,
    Mittal.

  • Runtime error while trying to convert script to pdf and sending in mail

    Hi all,
    I m trying to convert the standard script into pdf using convert_otf fm and trying to send it as an attachment using 'SO_NEW_DOCUMENT_ATT_SEND_API1'.
    I m using fm 'SSF_FUNCTION_MODULE_NAME' to get the function module name.
    But i m getting a runtime error while executing the program..
    Can anyone help me in this issue please.
    Thanks in advance,
    Ashok

    Hi Ramesh,
    I m getting an runtime error function module not found. I ll paste the code here.
    CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
        EXPORTING
          formname           = lf_formname
        IMPORTING
          fm_name            = lf_fm_name
        EXCEPTIONS
          no_form            = 1
          no_function_module = 2
          OTHERS             = 3.
      IF sy-subrc = 0.
    error handling ent_retco = sy-subrc.
    perform protocol_update_i.
      ENDIF.
      ls_control_param-getotf = 'X'.
      DATA: l_document_output_info TYPE ssfcrespd,
            l_job_output_info TYPE ssfcrescl,
            l_job_output_options TYPE ssfcresop.
    check ent_retco eq 0.
      CALL FUNCTION 'lf_fm_name'
      EXPORTING
        archive_index = toa_dara
        archive_parameters = arc_params
        control_parameters = ls_control_param
        mail_recipient = ls_recipient
        mail_sender = ls_sender
        output_options = ls_composer_param
        user_settings = ' '
        zxekko = l_doc-xekko
        zxpekko = l_doc-xpekko
    zxaend = l_doc-xaend
        IMPORTING
          document_output_info = l_document_output_info
          job_output_info = l_job_output_info
          job_output_options = l_job_output_options
          TABLES
            l_xekpo = l_doc-xekpo[]
            l_xekpa = l_doc-xekpa[]
            l_xpekpo = l_doc-xpekpo[]
            l_xeket = l_doc-xeket[]
            l_xtkomv = l_doc-xtkomv[]
            l_xekkn = l_doc-xekkn[]
            l_xekek = l_doc-xekek[]
            l_xaend = l_doc-xaend[]
            l_xkomk = l_xkomk
            EXCEPTIONS
              formatting_error = 1
              internal_error = 2
              send_error = 3
              user_canceled = 4
              OTHERS = 5.
    CALL FUNCTION 'CONVERT_OTF'
        EXPORTING
          format                = 'PDF'
          max_linewidth         = 132
        IMPORTING
          bin_filesize          = v_len_in
        TABLES
          otf                   = l_job_output_info-otfdata
          lines                 = tb_pdf
        EXCEPTIONS
          err_max_linewidth     = 0
          err_format            = 1
          err_conv_not_possible = 2
          OTHERS                = 3.

  • Sending Invoice as PDF in email

    Hello,
    I have a requirement where I have to send Proforma Invoice as PDF in email.
    Now, the Proforma Invoice is already using output type to Print and when I see the routines in Tcode NACE
    It uses RVADAUS1 Program where it calls RV_EXPORT_DOCUMENT_PRINT function module to generate the Print document.
    This works fine.
    So, I created a new output type, copied the  RVADAUS1 to ZRVADAUS1 and modified the code where I am capturing the Spool generated through the original code and pass it to CONVERT_ABAPSPOOLJOB_2_PDF to convert it to PDF and then send it as an email.
    Now, the problem I am facing is that, I am not able to generate a Spool when I am using the medium ( '5' External Send ). So the further code of capturing Spool and convert to PDF and send as email fails.
    Any guidance is appreciated.
    Regards,
    DNP

    Hi Sudhanshu,
    Just before calling the function module RV_EXPORT_DOCUMENT_PRINT.
    I forced TNAPR-NACHA = '1'. and NAST-NACHA = '1'.
    which means I forced Transmission medium as 1(Print) instead of 5(External Send)
    This created a SPOOL.
    Regards,
    DNP
    Edited by: DNP on Aug 14, 2009 11:45 AM

  • Unable to attach PDF to email (Outlook for Mac 2011)

    We are pushing out software upgrades for CS5 and MS Office 2011 for Mac. We've discoverd that we can't use the Attach to email feature in Acrobat. The spinning rainbow wheel pops up for about a minute, and then Acrobat is non-responsive and we have to force quit. We can still drag and drop an attachment so we have a viable workaround but obviously we'd like to be able to use the automated feature.
    All software is up-to-date.
    In the preferences panel of Outlook, we have selected Outlook to be the default mail application.
    As a sidenote, this feature doesn't work with Acobat X beta either. However, in the beta version of Acrobat X, if we declare Apple's mail application to be the default, it works fine. Unfortunately we use the Office suite as part of our enterprise system, so that's what we need to work with.
    Has anyone else experienced this? I've logged a ticket with Adobe but I haven't heard back from them yet.
    Thanks for any advise.

    Take the bhama way
    figured out how to make it work.  I am using Adobe Acrobat X Pro (mac)
    and MS Outlook for Mac 2011.
    For those who are interested, this is what I did:
    1. Create a folder on desktop to save your pdf¹s files you want to email
    to.  Mine is named, "PDF to Email"
    2. Open Automator, create a "Folder Action"
    3. At the top, "Choose Folder", choose your newly created folder on the
    desktop
    4. Choose the "Rename Finder Items" action from the action list.  I chose,
    "Don¹t Add" on the add a Copy Finder Items Action menu.
    5. On the "Add Date or Time to Finder Item Names" I chose, "Name Single
    Item" from the first drop down menu.
    6. Click on "Options" at the bottom of that window to select the "Show
    this action when the workflow runs" so you can rename your         file
    something other than the Acrobat default.
    7. Choose the "Create New Outlook Mail Message" from the action list and
    add it below the "Name Single Item in Finder Item Names"
    8. Choose "File>Save As" and give your file a name.  Mine is, "PDF to
    Email".
    9. Close Automator
    10. Open Acrobat X Pro.
    11. Go to "File>Action Wizard>Create New Action"
    12. Here you choose, "Save to>A Folder on my computer"
    13. Choose the folder on the desktop that we saved earlier
    14. Save the file, with the action name you will remember.
    Now when you are in Acrobat X Pro and you want to send that .pdf file via
    Outlook for Mac 2011, follow the steps below.
    With the file you want to email open, go to "File>Action Wizard>(Action
    you created) Mine is "PDF to Email".  It will take a few seconds, but you
    will get an "Action Completed".  You will get a pop up that allows you to
    name/rename the file. Then it should open your Outlook with your .pdf
    attached and ready for sending.
    You might need to tweak the actions to suit your needs, but this should
    work for you.
    De:  DaveGrif <[email protected]>
    Responder a:  <[email protected]>
    Fecha:  Mon, 05 Dec 2011 15:56:02 -0700
    Para:  Eugenio Soberon <[email protected]>
    Asunto:  unable to attach PDF to email (Outlook for Mac
    2011)
    Re: unable to attach PDF to email (Outlook for Mac 2011)
    created by DaveGrif <http://forums.adobe.com/people/DaveGrif>  in Acrobat
    Macintosh - View the full discussion
    <http://forums.adobe.com/message/4065409#4065409>
    It's supposed to work now? I've made sure I'm on latest (check for update)
    and it says I am. Still get an error. It does bring Outlook to the
    forground, but same error when I hide Outlook - An error occurred while
    trying to create a mail document. Suggestions?
    Replies to this message go to everyone subscribed to this thread, not
    directly to the person who posted the message. To post a reply, either reply
    to this email or visit the message page:
    http://forums.adobe.com/message/4065409#4065409 To unsubscribe from this
    thread, please visit the message page at
    http://forums.adobe.com/message/4065409#4065409. In the Actions box on the
    right, click the Stop Email Notifications link. Start a new discussion in
    Acrobat Macintosh by email
    <mailto:[email protected].co
    m>  or at Adobe Forums
    <http://forums.adobe.com/choose-container!input.jspa?contentType=1&container
    Type=14&container=3399>  For more information about maintaining your forum
    email notifications please go to
    http://forums.adobe.com/message/2936746#2936746.

  • How to save the output of sap script to pdf document in sap

    hi abapers
    how to save the output of sap script in sap so that can retrieve the saved document later.
    i have to save the rcia output from sap script in pdf document in sap so that it can be retrieved later
    how to use dms

    Hi deepika,
    This thread will solve ur problem OTF  -> PDF
    Regards,
    Pravin

  • Unable to send PDFs as email attachments

    I have become unable to send PDFs as email attachments when using Firefox.
    Depending on the PDF, I either get the message “There was an error opening this document. The file is damaged and could not be repaired.” or it opens as a blank document. This occus when opening the file with both Adobe Reader and Acrobat Pro. The problem seems to be isolated to PDFs. (I am able to send Word files. If a PDF is zipped before attaching, it can be opened without problem.) This occurs on both an institutional email account and personal (Yahoo) email account. This problem is isolated to Firefox (does not happen in Chrome).
    I have reset Firefox to default settings, as well as reinstalling.
    Thank you.

    Update Adobe® Acrobat® Plug-in for Web Browsers, Version 10.1.13 to version 11.
    Also please update all of your plugins and try again.
    Does this happen when you open the pdf in pdf.js, it is possible to change the default viewer by:
    * [[How to disable the built-in PDF viewer and use another viewer]]

  • Convert sap script to pdf and send mail before close_form

    hi experts,
    I am converting a sap script to PDF and then sending that pdf to vendor mail ids.
    I am getting the Data for the conversion of pdf From close_form.But it contains the data for all the vendors . But i have to Send the mail to the specific vendors.For ex if my script output has 5 sheets each with different vendors . I have to send  1 sheet as a pdf mail for that particular vendor. so,1 sheet each for 5 differrent vendors . But the data i get from close_form is the data for all the 5 vendors. How to split the data ?. can any one help me on this issue.
    with thanks in advance,
    syed

    Hi,
        Change your driver program so that it calls the script n no of times .. and every time send mail to particular vendor ..
        Loop at vendors.
         call the form ...
         send mail ...
        endloop ...
    Regards,
    Srini.

  • Sharing PDF via email in Pages 09

    This has not been a problem. However I just upgraded to Yosemite and now I cannot share as PDF via email; no problem with word or pages but this function seems to be lost

    Since Apple has retired all Pages applications prior to v5, they have no concern about backwards compatibility, or the effect of new operating systems, or newer applications on those retired applications. There is no guarantee that any point release to Yosemite, or subsequent OS X release would enable Pages ’09 functional continuity. It simply is not an Apple agenda item.
    For those who remain attached to Pages ’09, and do not have their documents duplicated in MS Word documents — and backed up — a sudden failure of Pages ’09 would mean opening those Pages ’09 documents in Pages v5, and risk loss of content due to unsupported features.

  • Send pdf as email

    hai gurus ,
    my problem is i am sending pdf as email its working fine
    but when i go and check the pdf file in  scot transaction the file is not getting  opened
    plz help me
    thanks in advance
    anji.
    Moderator message: please search for available information/documentation before asking, provide more technical details about errors when posting again.
    Edited by: Thomas Zloch on Oct 28, 2010 10:58 AM

    Hi,
    Check this link [http://wiki.sdn.sap.com/wiki/display/Snippets/ConvertsspoolrequestintoPDFdocumentand+emails]
    BR,
    Lokeswari.
    Moderator message: please do not post just links without any further explanations.
    Edited by: Thomas Zloch on Oct 28, 2010 10:58 AM

  • How to batch PDF multiple emails already saved to system

    Hi everyone,
    I would be very grateful for advice as to whether there is a way to PDF multiple saved emails at once using Abode? I have seen that it is possible to create multiple PDFs at once of emails in Outlook - but is there a way of batch creating multiple PDFs from emails which have already been saved to the system as 'Outlook Items'?
    Whilst I know how to batch PDF Word documents etc, this doesn't seem to be an option in Adobe (we use Adobe XI) for emails. Likewise, if I simply highlight all the emails and right-click 'Convert to Adobe PDF', this replaces the name of each email as 'Memo Style' (whereas it works for Word documents).
    We have many hundreds/thousands of emails saved on our work system as 'Outlook Items' (done before we upgraded systems and were able to save emails directly as PDFs from Outlook), and we need to convert them to PDF for upload to a new database programme, so it would be very helpful indeed if there were a way of avoiding having to convert them all one by one...
    Many thanks in advance,
    Zara

    What programming method are you using with the Acrobat SDK?

  • How do I save PDF from email to iBooks

    How do I save PDF from email to iBooks like I do on iPhone.

    touch and hold the attachment in mail.  a box will open that says 'open in' and i books, along with any other apps you have that read pdf files will be offered.  select i books, or the one you want.  once it is associated with an app, it will be stored within the app.

Maybe you are looking for