cancel
Showing results for 
Search instead for 
Did you mean: 

smartforms

Former Member
0 Kudos

Hi Folks,

My requiremnet is to convert the form into pdf and send it as an attachment via external email. i have written the follwoing code but the problem is it is sending the email but the attachment doesn't open .The following is the error message i get

Adobe Reader could not open 'test[2].pdf because it is either not a supported file type or because the file has been damaged ( for example, it was sent as an email attachment and wasn't correctly decoded.

the following is the code.

CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'

EXPORTING

FORMNAME = 'ZSAMPLE_PURCHASE'

IMPORTING

FM_NAME = V_FORM_NAME

EXCEPTIONS

NO_FORM = 1

NO_FUNCTION_MODULE = 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.

W_CTRLOP-GETOTF = 'X'.

W_CTRLOP-NO_DIALOG = 'X'.

W_COMPOP-TDNOPREV = ' '.

CALL FUNCTION V_FORM_NAME

EXPORTING

CONTROL_PARAMETERS = W_CTRLOP

OUTPUT_OPTIONS = W_COMPOP

USER_SETTINGS = 'X'

WA_EKKO = WA_EKKO

WA_KNA1 = WA_KNA1

WA_LFA1 = WA_LFA1

WA_ADRC = WA_ADRC

WA_ADRC1 = WA_ADRC1

WA_T001W = WA_T001W

WA_JPTIDCDASSIGN = WA_JPTIDCDASSIGN

WA_MAKT = WA_MAKT

IMPORTING

JOB_OUTPUT_INFO = W_RETURN

TABLES

IT_EKPO = IT_EKPO

EXCEPTIONS

FORMATTING_ERROR = 1

INTERNAL_ERROR = 2

SEND_ERROR = 3

USER_CANCELED = 4

OTHERS = 5

.

IF SY-SUBRC <> 0.

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

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

ENDIF.

I_OTF[] = W_RETURN-OTFDATA[].

**********removing the initial and final markers from the OTF data*********

DELETE W_RETURN-OTFDATA WHERE TDPRINTCOM = '//'.

****************searching for the end-of-page in OTF table***********

READ TABLE I_OTF WITH KEY TDPRINTCOM = 'EP'. MY_TABIX = SY-TABIX + 1.

*

********appending the modified OTF table to the final OTF table*******

INSERT LINES OF W_RETURN-OTFDATA INTO I_OTF INDEX MY_TABIX.

                        • converting OTF data into pdf data**************************

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.

LOOP AT I_TLINE.

TRANSLATE I_TLINE USING '~'.

CONCATENATE WA_BUFFER I_TLINE INTO WA_BUFFER.

ENDLOOP.

TRANSLATE WA_BUFFER USING '~'.

DO.

I_RECORD = WA_BUFFER.

APPEND I_RECORD.

SHIFT WA_BUFFER LEFT BY 255 PLACES.

IF WA_BUFFER IS INITIAL.

EXIT.

ENDIF.

ENDDO.

  • Attachment

REFRESH:

I_RECLIST,

I_OBJTXT,

I_OBJBIN,

I_OBJPACK.

CLEAR WA_OBJHEAD.

I_OBJBIN[] = I_RECORD[].

  • APPEND I_RECORD.

              • Create Message Body Title and Description****************

I_OBJTXT = 'test with pdf-Attachment!'.

APPEND I_OBJTXT.

DESCRIBE TABLE I_OBJTXT LINES V_LINES_TXT.

READ TABLE I_OBJTXT INDEX V_LINES_TXT.

WA_DOC_CHNG-OBJ_NAME = 'smartform'.

WA_DOC_CHNG-EXPIRY_DAT = SY-DATUM + 10.

WA_DOC_CHNG-OBJ_DESCR = 'smartform'.

WA_DOC_CHNG-SENSITIVTY = 'F'.

WA_DOC_CHNG-DOC_SIZE = V_LINES_TXT * 255.

        • Main Text*****************************

CLEAR I_OBJPACK-TRANSF_BIN.

I_OBJPACK-HEAD_START = 1.

I_OBJPACK-HEAD_NUM = 0.

I_OBJPACK-BODY_START = 1.

I_OBJPACK-BODY_NUM = V_LINES_TXT.

I_OBJPACK-DOC_TYPE = 'RAW'.

APPEND I_OBJPACK.

        • Attachment (pdf-Attachment)*************

I_OBJPACK-TRANSF_BIN = 'X'.

I_OBJPACK-HEAD_START = 1.

I_OBJPACK-HEAD_NUM = 1.

I_OBJPACK-BODY_START = 1.

I_OBJPACK-BODY_NUM = V_LINES_BIN.

I_OBJPACK-DOC_TYPE = 'PDF'.

I_OBJPACK-OBJ_NAME = 'smartform'.

  • CONCATENATE 'smartform''.pdf' INTO I_OBJPACK-OBJ_DESCR.

I_OBJPACK-OBJ_DESCR = 'test'.

I_OBJPACK-DOC_SIZE = V_LINES_BIN * 255 .

APPEND I_OBJPACK.

  • Länge des Attachment ermitteln

CLEAR I_RECLIST.

I_RECLIST-RECEIVER = 'prabhaschandv@gmail.com'.

I_RECLIST-REC_TYPE = 'U'.

I_RECLIST-EXPRESS = 'X'.

APPEND I_RECLIST.

CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'

EXPORTING

DOCUMENT_DATA = WA_DOC_CHNG

PUT_IN_OUTBOX = 'X'

COMMIT_WORK = 'X'

TABLES

PACKING_LIST = I_OBJPACK

OBJECT_HEADER = WA_OBJHEAD

CONTENTS_BIN = I_OBJBIN

CONTENTS_TXT = I_OBJTXT

RECEIVERS = I_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:/ 'Error When Sending the File', SY-SUBRC.

ELSE.

WRITE:/ 'Mail sent'.

ENDIF.

What could be the problem ..

Any help would be appreciated .

thanks

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Redfriend,

I guess the problem lies in the conversion functional module. Since you are not handling the error you may not know. Try this ..

                        • converting OTF data into pdf data**************************

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.

<b>

*--either have a breakpoint here or check for Sy-subrc and errro out with respective information.
For example
If you get sy-subrc = 2 then its a format error.

</b>

ENDIF.

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi ,

I am able to download into the pdf correctly problem arisies when it is sent as an attachment to the external mail .. i think the problem is with the FM 'SO_NEW_DOCUMENT_ATT_SEND_API1.. i am not able to get where the problem is....

Thanks

Former Member
0 Kudos

hey but the sy-subrc is returning zero.. so there is no problem in the conversion. can u help me in tat...

Former Member
0 Kudos

Do compare with this program

TABLES: tsp01.

DATA otf LIKE itcoo OCCURS 100 WITH HEADER LINE.

DATA cancel.

DATA pdf LIKE tline OCCURS 100 WITH HEADER LINE.

DATA doctab LIKE docs OCCURS 1 WITH HEADER LINE.

DATA: numbytes TYPE i,

arc_idx LIKE toa_dara,

pdfspoolid LIKE tsp01-rqident,

jobname LIKE tbtcjob-jobname,

jobcount LIKE tbtcjob-jobcount,

is_otf.

DATA: client LIKE tst01-dclient,

name LIKE tst01-dname,

objtype LIKE rststype-type,

type LIKE rststype-type.

  • Check if spool id exists

SELECT SINGLE * FROM tsp01 WHERE rqident = spoolno.

IF sy-subrc <> 0.

WRITE: / 'Spoolauftrag existiert nicht'(003)

COLOR COL_NEGATIVE.

EXIT.

ENDIF.

client = tsp01-rqclient.

name = tsp01-rqo1name.

CALL FUNCTION 'RSTS_GET_ATTRIBUTES'

EXPORTING

authority = 'SP01'

client = client

name = name

part = 1

IMPORTING

type = type

objtype = objtype

EXCEPTIONS

fb_error = 1

fb_rsts_other = 2

no_object = 3

no_permission = 4.

IF objtype(3) = 'OTF'.

is_otf = 'X'.

ELSE.

is_otf = space.

ENDIF.

IF is_otf = 'X'.

CALL FUNCTION 'CONVERT_OTFSPOOLJOB_2_PDF'

EXPORTING

src_spoolid = spoolno

no_dialog = ' '

IMPORTING

pdf_bytecount = numbytes

pdf_spoolid = pdfspoolid

btc_jobname = jobname

btc_jobcount = jobcount

TABLES

pdf = 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.

CASE sy-subrc.

WHEN 0.

  • WRITE: / 'Funktion CONVERT_OTFSPOOLJOB_2_PDF erfolgreich'(001)

  • COLOR COL_POSITIVE.

WHEN 1.

WRITE: / 'Kein OTF- und kein ABAP-Spoolauftrag'(002)

COLOR COL_NEGATIVE.

EXIT.

WHEN 2.

WRITE: / 'Spoolauftrag existiert nicht'(003)

COLOR COL_NEGATIVE.

EXIT.

WHEN 3.

WRITE: / 'Keine Berechtigung zum Lesen Spoolauftrag'(004)

COLOR COL_NEGATIVE.

EXIT.

WHEN OTHERS.

WRITE: / 'Fehler bei Funktion CONVERT_OTFSPOOLJOB_2_PDF'(005)

COLOR COL_NEGATIVE.

EXIT.

ENDCASE.

ELSE.

CALL FUNCTION 'CONVERT_ABAPSPOOLJOB_2_PDF'

EXPORTING

src_spoolid = spoolno

no_dialog = ' '

IMPORTING

pdf_bytecount = numbytes

pdf_spoolid = pdfspoolid

btc_jobname = jobname

btc_jobcount = jobcount

TABLES

pdf = 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.

CASE sy-subrc.

WHEN 0.

  • WRITE: / 'Funktion CONVERT_ABAPSPOOLJOB_2_PDF erfolgreich'(006)

  • COLOR COL_POSITIVE.

WHEN 1.

WRITE: / 'Kein OTF- und kein ABAP-Spoolauftrag'(002)

COLOR COL_NEGATIVE.

EXIT.

WHEN 2.

WRITE: / 'Spoolauftrag existiert nicht'(003)

COLOR COL_NEGATIVE.

EXIT.

WHEN 3.

WRITE: / 'Keine Berechtigung zum Lesen Spoolauftrag'(004)

COLOR COL_NEGATIVE.

EXIT.

WHEN OTHERS.

WRITE: / 'Fehler bei Funktion CONVERT_ABAPSPOOLJOB_2_PDF'(007)

COLOR COL_NEGATIVE.

EXIT.

ENDCASE.

ENDIF.

                              • Download PDF file ***********

CHECK download = 'X'.

IF NOT ( jobname IS INITIAL ).

WRITE: / 'Konvertierung per Hintergrundjob'(008)

COLOR COL_NORMAL,

jobname, jobcount.

EXIT.

ENDIF.

CALL FUNCTION 'DOWNLOAD'

EXPORTING

bin_filesize = numbytes

filename = p_file

filetype = 'BIN'

mode = ' '

silent = 'X'

IMPORTING

act_filename = p_file

filesize = numbytes

cancel = cancel

TABLES

data_tab = pdf.

Reward Points if it is helpful

Thanks

Seshu