2006 Dec 21 12:27 PM
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 'sirisha.matta@mytecsoft.com',
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.
2006 Dec 21 1:58 PM
If you set up a printer with device type PDF1 - and send your output to it everything will be take care of for you. You just have to make sure there is a valid email address available and the form will be converted to pdf and mailed to the email address.
2006 Dec 21 2:02 PM
HI,
Look at the below thread
Look at the below Program ..
* Function : Send any spool ( OTF / LIST )as attachment to an e-mail
* using ABAP program.
*&---------------------------------------------------------------------*
REPORT Z_RMTIWARI_SEND_SPOOL_MAIL_ATT .
*----------------------------------------------------------------------*
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
2006 Dec 21 3:36 PM
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 'sirisha.matta@mytecsoft.com',
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.
2006 Dec 22 10:56 AM
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.
-
X_SPOOL_ID is an integer field - CONCATENATE can only be used with character fields