Skip to Content
0
Former Member
May 31, 2013 at 07:57 AM

pdF attachment through function module in workflow .

571 Views

Hello friend ,

I have created method in business object , in side method I have called function module and written code for invoice as as an PDF and send mail to outlook though the function module CALL FUNCTION 'SO_DOCUMENT_SEND_API1' . after perfect execution of function module and method and event in business object I have created workflow and assignn that business object and event . Everything is perfect , when I run the business object mail is coming but if I execute workflow nothing is coming , but if I comment smart form part and execute workflow mail is coming with pdf attachment only , inside nothing is there . I am not getting whats the problem , size of pdf is 22kb is this proble .

MY code in function mode

*-> Receiving parameter for the external mail . from the include (LZVBAKP1F02) .

DATA : V_OBJECT_KEY TYPE SWR_STRUCT-OBJECT_KEY ,

INDXKEY LIKE INDX-SRTFD.

 

 

INDXKEY = 'BILXKEY'.

IMPORT V_OBJECT_KEY FROM DATABASE INDX(ST) ID INDXKEY.

MOVE V_OBJECT_KEY TO V_VBELN .

*-> Generating form .

*-> Start function module for smart forms .

CALL FUNCTION 'SSF_GET_DEVICE_TYPE'

EXPORTING

I_LANGUAGE = V_LANGUAGE

I_APPLICATION = 'SAPDEFAULT'

IMPORTING

E_DEVTYPE = V_E_DEVTYPE.

ST_OUTPUT_OPTIONS-TDPRINTER = V_E_DEVTYPE.

ST_CONTROL_PARAMETERS-NO_DIALOG = 'X'.

ST_CONTROL_PARAMETERS-GETOTF = 'X'.

* SORT I_FINAL BY VBELN.

 

*-> Download the forms .

CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'

EXPORTING

FORMNAME = 'ZLB_BIL_INV2'

IMPORTING

FM_NAME = FNAM.

 

*-> Passing data to smartforms .

IF FNAM IS NOT INITIAL.

CALL FUNCTION FNAM

EXPORTING

USER_SETTINGS = 'X'

V_VBELN = V_VBELN

CONTROL_PARAMETERS = ST_CONTROL_PARAMETERS

OUTPUT_OPTIONS = ST_OUTPUT_OPTIONS

IMPORTING

DOCUMENT_OUTPUT_INFO = ST_DOCUMENT_OUTPUT_INFO

JOB_OUTPUT_INFO = ST_JOB_OUTPUT_INFO

JOB_OUTPUT_OPTIONS = ST_JOB_OUTPUT_OPTIONS.

 

*............CONVERT TO OTF TO PDF................*

CLEAR: V_BIN_FILESIZE.

CALL FUNCTION 'CONVERT_OTF_2_PDF'

IMPORTING

BIN_FILESIZE = V_BIN_FILESIZE

TABLES

OTF = ST_JOB_OUTPUT_INFO-OTFDATA

DOCTAB_ARCHIVE = IT_DOCS

LINES = IT_LINES

EXCEPTIONS

ERR_CONV_NOT_POSSIBLE = 1

ERR_OTF_MC_NOENDMARKER = 2

OTHERS = 3.

IF SY-SUBRC <> 0.

* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

ENDIF.

CLEAR: LWA_PDFDATA.

LOOP AT IT_LINES INTO LWA_PDFDATA .

TRANSLATE LWA_PDFDATA USING ' ~'.

CONCATENATE GD_BUFFER LWA_PDFDATA INTO GD_BUFFER.

ENDLOOP.

TRANSLATE GD_BUFFER USING '~ '.

DO.

IT_MESS_ATT = GD_BUFFER.

APPEND IT_MESS_ATT TO IT_RECORD.

CLEAR: IT_MESS_ATT.

SHIFT GD_BUFFER LEFT BY 255 PLACES.

IF GD_BUFFER IS INITIAL.

EXIT.

ENDIF.

ENDDO.

*-> Move Record of attachment .

IT_ATTACH[] = IT_RECORD[] .

*->Message body .

IT_MESSAGE = 'ONLY FOR THE INTERNAL PURPOSE'.

APPEND IT_MESSAGE.

IT_MESSAGE = 'Not to be forwarded to customer. This is auto generated'.

APPEND IT_MESSAGE.

IT_MESSAGE = 'Invoice and actual values may differ in physical invoice'.

APPEND IT_MESSAGE.

CONCATENATE 'Invoice no' V_VBELN 'has been generated' INTO IT_MESSAGE SEPARATED BY SPACE.

APPEND IT_MESSAGE.

SELECT SINGLE KUNNR FROM VBPA INTO V_SOLD

WHERE VBELN = V_VBELN

AND PARVW = 'AG'.

SELECT SINGLE NAME1 ORT01 FROM KNA1 INTO (V_NAME1, V_ORT01) WHERE KUNNR = V_SOLD.

CONCATENATE 'for the Customer' V_NAME1 ',' V_ORT01 INTO IT_MESSAGE SEPARATED BY SPACE.

APPEND IT_MESSAGE .

SELECT SINGLE VGBEL FROM VBRP INTO V_VGBEL

WHERE VBELN = V_VBELN.

CONCATENATE 'against dispatch advice No:' V_VGBEL '.' INTO IT_MESSAGE SEPARATED BY SPACE.

APPEND IT_MESSAGE.

*>#End of message#.

PERFORM SEND_FILE_AS_EMAIL_ATTACHMENT

TABLES IT_MESSAGE

IT_ATTACH

USING RECEIVER

'New Invoice has been generated'

'pdf'

'filename'

' '

' '

' '

CHANGING GD_ERROR

GD_RECIEVER.

*->Instructs mail send program for SAPCONNECT to send email(rsconn01)

PERFORM INITIATE_MAIL_EXECUTE_PROGRAM.

 

ENDFUNCTION.

 

*&---------------------------------------------------------------------

*& Form SEND_FILE_AS_EMAIL_ATTACHMENT

*&---------------------------------------------------------------------

* Send email

*----------------------------------------------------------------------

FORM SEND_FILE_AS_EMAIL_ATTACHMENT TABLES PIT_MESSAGE

PIT_ATTACH

USING P_EMAIL

P_MTITLE

P_FORMAT

P_FILENAME

P_ATTDESCRIPTION

P_SENDER_ADDRESS

P_SENDER_ADDRES_TYPE

CHANGING P_ERROR

P_RECIEVER.

DATA: LD_ERROR TYPE SY-SUBRC,

LD_RECIEVER TYPE SY-SUBRC,

LD_MTITLE LIKE SODOCCHGI1-OBJ_DESCR,

LD_EMAIL LIKE SOMLRECI1-RECEIVER,

LD_FORMAT TYPE SO_OBJ_TP ,

LD_ATTDESCRIPTION TYPE SO_OBJ_NAM ,

LD_ATTFILENAME TYPE SO_OBJ_DES ,

LD_SENDER_ADDRESS LIKE SOEXTRECI1-RECEIVER,

LD_SENDER_ADDRESS_TYPE LIKE SOEXTRECI1-ADR_TYP,

LD_RECEIVER LIKE SY-SUBRC.

DATA : V_VBELN TYPE VBAK-VBELN ,

CNT TYPE I ,

V_OBJECT_KEY TYPE SWR_STRUCT-OBJECT_KEY ,

INDXKEY LIKE INDX-SRTFD .

DATA: G_MSG_LINES TYPE SY-TABIX,

GT_OUTPUT_SOLI LIKE SOLI OCCURS 0 WITH HEADER LINE ,

G_LINES TYPE SY-TABIX.

CLEAR : V_OBJECT_KEY.

* GET PARAMETER ID 'VBL' FIELD V_VBELN .

INDXKEY = 'BILXKEY'.

IMPORT V_OBJECT_KEY FROM DATABASE INDX(ST) ID INDXKEY.

MOVE V_OBJECT_KEY TO V_VBELN .

 

LD_EMAIL = P_EMAIL.

LD_MTITLE = P_MTITLE.

LD_FORMAT = P_FORMAT.

LD_ATTDESCRIPTION = P_ATTDESCRIPTION.

LD_ATTFILENAME = P_FILENAME.

LD_SENDER_ADDRESS = P_SENDER_ADDRESS.

LD_SENDER_ADDRESS_TYPE = P_SENDER_ADDRES_TYPE. "Fill the document data.

W_DOC_DATA-DOC_SIZE = 1. "Populate the subject/generic message attributes

W_DOC_DATA-OBJ_LANGU = SY-LANGU.

W_DOC_DATA-OBJ_NAME = 'SAPRPT'.

CONCATENATE LD_MTITLE '(' V_VBELN ')' INTO W_DOC_DATA-OBJ_DESCR SEPARATED BY SPACE .

* W_DOC_DATA-OBJ_DESCR = LD_MTITLE .

W_DOC_DATA-SENSITIVTY = 'F'. "Fill the document data and get size of attachment

* CLEAR W_DOC_DATA.

READ TABLE IT_ATTACH INDEX W_CNT.

W_DOC_DATA-DOC_SIZE = ( W_CNT - 1 ) * 255 + STRLEN( IT_ATTACH ).

W_DOC_DATA-OBJ_LANGU = SY-LANGU.

W_DOC_DATA-OBJ_NAME = 'SAPRPT'.

* W_DOC_DATA-OBJ_DESCR = LD_MTITLE.

* SELECT VBELN FROM VBAK INTO TABLE IT_VBELN WHERE ERDAT = SY-DATUM ."AND ERZET = SY-UZEIT .

*

* SORT IT_VBELN BY VBELN DESCENDING.

* READ TABLE IT_VBELN INDEX 1.

*

* V_VBELN = IT_VBELN-VBELN .

 

* SELECT VBELN FROM ZVBAKP INTO TABLE IT_VBELN WHERE VBELN = V_OBJECT_KEY .

*-> If the order has gone for block .

* CONCATENATE LD_MTITLE '(' V_VBELN ')' INTO W_DOC_DATA-OBJ_DESCR SEPARATED BY SPACE .

***CHANGED BY PRYANKA ::: HTML FORMAT

**** DESCRIBE TABLE IT_MESSAGE LINES G_MSG_LINES.

**** READ TABLE IT_MESSAGE INDEX G_MSG_LINES.

**** W_DOC_DATA-DOC_SIZE = ( G_MSG_LINES - 1 ) * 255 + STRLEN( IT_MESSAGE ).

****

*****- Creation of the entry for the compressed document

**** T_PACKING_LIST-TRANSF_BIN = ' '.

**** T_PACKING_LIST-HEAD_START = 1.

**** T_PACKING_LIST-HEAD_NUM = 0.

**** T_PACKING_LIST-BODY_START = 1.

**** T_PACKING_LIST-BODY_NUM = G_MSG_LINES.

***** T_PACKING_LIST-DOC_TYPE = 'HTM' . "C_DOC_TYPE_HTM.

**** T_PACKING_LIST-DOC_TYPE = 'RAW' . "C_DOC_TYPE_HTM.

****

*****- Append

**** APPEND T_PACKING_LIST.

 

* W_DOC_DATA-SENSITIVTY = 'F'.

CLEAR T_ATTACHMENT.

REFRESH T_ATTACHMENT.

T_ATTACHMENT[] = PIT_ATTACH[]. "Describe the body of the message

CLEAR T_PACKING_LIST.

REFRESH T_PACKING_LIST.

T_PACKING_LIST-TRANSF_BIN = SPACE.

T_PACKING_LIST-HEAD_START = 1.

T_PACKING_LIST-HEAD_NUM = 0.

T_PACKING_LIST-BODY_START = 1.

DESCRIBE TABLE IT_MESSAGE LINES T_PACKING_LIST-BODY_NUM.

T_PACKING_LIST-DOC_TYPE = 'RAW'.

APPEND T_PACKING_LIST. "Create attachment notification

T_PACKING_LIST-TRANSF_BIN = 'X'.

T_PACKING_LIST-HEAD_START = 1.

T_PACKING_LIST-HEAD_NUM = 1.

T_PACKING_LIST-BODY_START = 1.

DESCRIBE TABLE T_ATTACHMENT LINES T_PACKING_LIST-BODY_NUM.

T_PACKING_LIST-DOC_TYPE = LD_FORMAT.

T_PACKING_LIST-OBJ_DESCR = LD_ATTDESCRIPTION.

CONCATENATE 'Invoice' V_VBELN INTO T_PACKING_LIST-OBJ_DESCR SEPARATED BY SPACE .

* T_PACKING_LIST-OBJ_DESCR = 'Invoice'.

T_PACKING_LIST-OBJ_NAME = LD_ATTFILENAME.

T_PACKING_LIST-DOC_SIZE = T_PACKING_LIST-BODY_NUM * 255.

APPEND T_PACKING_LIST. "ADD THE RECIPIENTS EMAIL ADDRESS

**

*-> Retriving mail ID from the database ZSDMID transaction YDMID .

DESCRIBE TABLE GT_OUTPUT_SOLI LINES G_LINES.

*- Don't create attachment if no data is present

IF G_LINES <> 0.

LOOP AT GT_OUTPUT_SOLI." INTO GF_OUTPUT_SOLI.

IT_MESSAGE = GT_OUTPUT_SOLI.

*- Append

APPEND IT_MESSAGE ."GF_OBJTXT TO GT_OBJTXT.

*- Clear

ENDLOOP.

ENDIF.

CLEAR T_RECEIVERS.

T_RECEIVERS-RECEIVER = 'PRIYANKA@CLCINDIA.COM' . "For mail address

T_RECEIVERS-REC_TYPE = 'U'.

T_RECEIVERS-COM_TYPE = 'INT'.

T_RECEIVERS-NOTIF_DEL = 'X'.

T_RECEIVERS-NOTIF_NDEL = 'X'.

APPEND T_RECEIVERS.

T_RECEIVERS-RECEIVER = 'JOY@CLCINDIA.COM' . "For mail address

T_RECEIVERS-REC_TYPE = 'U'.

T_RECEIVERS-COM_TYPE = 'INT'.

T_RECEIVERS-NOTIF_DEL = 'X'.

T_RECEIVERS-NOTIF_NDEL = 'X'.

APPEND T_RECEIVERS.

 

CLEAR T_RECEIVERS.

 

CALL FUNCTION 'SO_DOCUMENT_SEND_API1'

EXPORTING

DOCUMENT_DATA = W_DOC_DATA

* put_in_outbox = 'X'

SENDER_ADDRESS = LD_SENDER_ADDRESS

SENDER_ADDRESS_TYPE = LD_SENDER_ADDRESS_TYPE

COMMIT_WORK = 'X'

IMPORTING

SENT_TO_ALL = W_SENT_ALL

TABLES

PACKING_LIST = T_PACKING_LIST

CONTENTS_BIN = T_ATTACHMENT

CONTENTS_TXT = IT_MESSAGE

RECEIVERS = T_RECEIVERS

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. " POPULATE ZERROR RETURN CODE

 

LD_ERROR = SY-SUBRC. " POPULATE ZRECEIVER RETURN CODE

LOOP AT T_RECEIVERS.

LD_RECEIVER = T_RECEIVERS-RETRN_CODE.

ENDLOOP.

ENDFORM. "send_file_as_email_attachment

*&---------------------------------------------------------------------

*& Form INITIATE_MAIL_EXECUTE_PROGRAM

*&---------------------------------------------------------------------

* Instructs mail send program for SAPCONNECT to send email.

*----------------------------------------------------------------------

FORM INITIATE_MAIL_EXECUTE_PROGRAM.

WAIT UP TO 2 SECONDS.

SUBMIT RSCONN01 WITH MODE = 'INT'

WITH OUTPUT = 'X'

AND RETURN.

ENDFORM. " INITIATE_MAIL_EXECUTE_PROGRAM