Skip to Content
0
Former Member
Dec 21, 2006 at 12:27 PM

scripts to pdf to email

19 Views

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.