Skip to Content
avatar image
Former Member

smartform sending pdf file as a mail

i have done a mailing a pdf as mail i am able to down load a file in to the systam which is perfect but i am not able to send the mail can any one tell me whats the problem in this and guide me if there is any problem.

CALL FUNCTION 'GUI_FILE_SAVE_DIALOG'

EXPORTING

WINDOW_TITLE = 'Save as'

DEFAULT_EXTENSION = 'PDF'

DEFAULT_FILE_NAME = W_FNAME

  • WITH_ENCODING =

  • FILE_FILTER =

  • INITIAL_DIRECTORY =

  • DEFAULT_ENCODING =

IMPORTING

FILENAME = W_FNAME

  • PATH =

  • FULLPATH =

USER_ACTION = v_action

  • FILE_ENCODING =

.

if v_action = '9'.

exit.

endif.

CALL FUNCTION 'GUI_DOWNLOAD'

EXPORTING

BIN_FILESIZE = W_BIN_SIZE

FILENAME = W_FNAME

FILETYPE = 'BIN' "'ASC'

IMPORTING

FILELENGTH = V_FILESIZE

TABLES

DATA_TAB = T_PDF_TAB

EXCEPTIONS

FILE_WRITE_ERROR = 1

NO_BATCH = 2

GUI_REFUSE_FILETRANSFER = 3

INVALID_TYPE = 4

NO_AUTHORITY = 5

UNKNOWN_ERROR = 6

HEADER_NOT_ALLOWED = 7

SEPARATOR_NOT_ALLOWED = 8

FILESIZE_NOT_ALLOWED = 9

HEADER_TOO_LONG = 10

DP_ERROR_CREATE = 11

DP_ERROR_SEND = 12

DP_ERROR_WRITE = 13

UNKNOWN_DP_ERROR = 14

ACCESS_DENIED = 15

DP_OUT_OF_MEMORY = 16

DISK_FULL = 17

DP_TIMEOUT = 18

FILE_NOT_FOUND = 19

DATAPROVIDER_EXCEPTION = 20

CONTROL_FLUSH_ERROR = 21

OTHERS = 22 .

IF SY-SUBRC <> 0.

MESSAGE 'File not downloaded succesfully' TYPE 'E'.

ELSE.

CONCATENATE 'File : ' W_FNAME 'downloaded succesfully ' INTO MSG1.

MESSAGE MSG1 TYPE 'I'.

ENDIF.

*********************************************************

data : GD_DOC_DATA type SODOCCHGI1.

data : LT_MAILPACK type standard table of SOPCKLSTI1.

data : LA_MAILPACK type SOPCKLSTI1.

data : LT_OBJTXT type STANDARD TABLE OF SOMLRECI1 WITH HEADER LINE.

DATA:LF_LINES TYPE I.

DATA LV_OUTPUT TYPE SDOKCNTBINS WITH HEADER LINE.

*DATA LV_OUTPUT TYPE standard table of SOLISTI1 .

data pdf_file type XSTRING.

DATA: IT_RECEIVERS TYPE STANDARD TABLE OF SOMLRECI1 WITH HEADER

LINE.

data iv_mailid type AD_SMTPADR.

move W_FNAME to pdf_file.

Data : w_buffer TYPE string.

*data : i_record LIKE solisti1 OCCURS 0

*WITH HEADER LINE.

data : i_record LIKE solisti1 OCCURS 0

WITH HEADER LINE.

data : s_record LIKE solisti1 OCCURS 0

WITH HEADER LINE.

*

  • CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'

  • EXPORTING

  • BUFFER = pdf_file "PDF file from function module

  • TABLES

  • BINARY_TAB = LV_OUTPUT.

*

  • DESCRIBE TABLE LV_OUTPUT LINES LF_LINES.

loop at T_PDF_TAB.

*TRANSLATE T_PDF_TAB USING '~'.

CONCATENATE w_buffer T_PDF_TAB INTO w_buffer.

endloop.

*TRANSLATE w_buffer USING '~ '.

DO.

i_record = w_buffer.

APPEND i_record.

SHIFT w_buffer LEFT BY 255 PLACES.

IF w_buffer IS INITIAL.

EXIT.

ENDIF.

ENDDO.

s_record[] = i_record[].

*DESCRIBE TABLE T_PDF_TAB LINES LF_LINES.

select single SMTP_ADDR from ADR6 into iv_mailid where ADDRNUMBER =

IV_ADDNR_VENDOR.

  • DATA:LT_OBJTXT LIKE SOLISTI1 OCCURS 10 WITH HEADER LINE.

MOVE 'Email sent to you from SAP' TO LT_OBJTXT.

APPEND LT_OBJTXT.

GD_DOC_DATA-OBJ_DESCR = 'PDF'.

GD_DOC_DATA-OBJ_NAME = 'PDFMail'.

GD_DOC_DATA-OBJ_DESCR = 'PDF'.

GD_DOC_DATA-SENSITIVTY = 'O'.

  • GD_DOC_DATA-EXPIRY_DAT = SY-DATUM + 15.

GD_DOC_DATA-DOC_SIZE = STRLEN( LT_OBJTXT ).

CLEAR LA_MAILPACK.

LA_MAILPACK-HEAD_START = 1.

LA_MAILPACK-HEAD_NUM = 0.

LA_MAILPACK-BODY_START = 1.

LA_MAILPACK-BODY_NUM = 1.

  • LA_MAILPACK-DOC_TYPE = 'RAW'.

LA_MAILPACK-DOC_SIZE = STRLEN( LT_OBJTXT ).

APPEND LA_MAILPACK TO LT_MAILPACK.

CLEAR LA_MAILPACK.

LA_MAILPACK-TRANSF_BIN = ''.

LA_MAILPACK-HEAD_START = 1.

LA_MAILPACK-HEAD_NUM = 1.

LA_MAILPACK-BODY_START = 1.

LA_MAILPACK-DOC_TYPE = 'PDF'.

LA_MAILPACK-BODY_NUM = LF_LINES.

LA_MAILPACK-DOC_SIZE = LF_LINES * 255.

LA_MAILPACK-OBJ_DESCR = 'Open'.

LA_MAILPACK-OBJ_NAME = 'MAIL'.

APPEND LA_MAILPACK TO LT_MAILPACK.

IT_RECEIVERS-RECEIVER = iv_mailid.

IT_RECEIVERS-REC_TYPE = 'U'.

APPEND IT_RECEIVERS.

CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'

EXPORTING

DOCUMENT_DATA = GD_DOC_DATA

PUT_IN_OUTBOX = 'X'

COMMIT_WORK = 'X'

  • IMPORTING

  • SENT_TO_ALL =

  • NEW_OBJECT_ID =

TABLES

PACKING_LIST = LT_MAILPACK

  • OBJECT_HEADER =

CONTENTS_BIN = s_record

CONTENTS_TXT = LT_OBJTXT

  • CONTENTS_HEX = LV_OUTPUT

  • CONTENTS_HEX = s_record

  • OBJECT_PARA =

  • OBJECT_PARB =

RECEIVERS = IT_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

.

IF SY-SUBRC <> 0.

MESSAGE 'Mail was not sent' type 'E'.

else.

MESSAGE 'Mail was sent Succesfully' type 'S'.

ENDIF.

thanks and regards ,

venkat.

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

3 Answers

  • avatar image
    Former Member
    Dec 10, 2008 at 10:50 AM

    hi,

    try this.

    CALL FUNCTION 'RSPO_RETURN_SPOOLJOB'

    EXPORTING

    RQIDENT = GD_SPOOL_NR

    FIRST_LINE = 1

    LAST_LINE = 1000

    DESIRED_TYPE = 'RAW'

    TABLES

    BUFFER = GT_SPOOL_FILE

    EXCEPTIONS

    NO_SUCH_JOB = 1

    JOB_CONTAINS_NO_DATA = 2

    SELECTION_EMPTY = 3

    NO_PERMISSION = 4

    CAN_NOT_ACCESS = 5

    READ_ERROR = 6

    TYPE_NO_MATCH = 7

    OTHERS = 8.

    IF SY-SUBRC <> 0.

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

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

    ENDIF.

    select single rqclient

    rqo1name

    into (gv_client, gv_name)

    from tsp01

    where RQIDENT = GD_SPOOL_NR.

    CALL FUNCTION 'RSTS_GET_ATTRIBUTES'

    EXPORTING

    AUTHORITY = 'SP01'

    CLIENT = GV_CLIENT

    NAME = GV_NAME

    PART = 1

    IMPORTING

    TYPE = GV_TYPE

    OBJTYPE = GV_OBJTYPE

    EXCEPTIONS

    FB_ERROR = 1

    FB_RSTS_OTHER = 2

    NO_OBJECT = 3

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

    IF GV_OBJTYPE(3) = 'OTF'.

    GV_IS_OTF = 'X'.

    ELSE.

    GV_IS_OTF = SPACE.

    ENDIF.

    IF GV_IS_OTF EQ 'X'.

    CALL FUNCTION 'CONVERT_OTFSPOOLJOB_2_PDF'

    EXPORTING

    SRC_SPOOLID = GD_SPOOL_NR

    NO_DIALOG = ' '

    IMPORTING

    PDF_BYTECOUNT = GD_BYTECOUNT

    PDF_SPOOLID = GV_PDFSPOOLID

    BTC_JOBNAME = GV_JOBNAME

    BTC_JOBCOUNT = GV_JOBCOUNT

    TABLES

    PDF = IT_PDF_OUTPUT.

    ELSE.

    CALL FUNCTION 'CONVERT_ABAPSPOOLJOB_2_PDF'

    EXPORTING

    SRC_SPOOLID = GD_SPOOL_NR

    NO_DIALOG = C_NO

    DST_DEVICE = C_DEVICE

    IMPORTING

    PDF_BYTECOUNT = GD_BYTECOUNT

    TABLES

    PDF = IT_PDF_OUTPUT

    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.

    endif.

    if SY-SUBRC eq 0.

    • Transfer the 132-long strings to 255-long strings

    LOOP AT IT_PDF_OUTPUT.

    TRANSLATE IT_PDF_OUTPUT USING ' ~'.

    CONCATENATE GD_BUFFER IT_PDF_OUTPUT INTO GD_BUFFER.

    ENDLOOP.

    TRANSLATE GD_BUFFER USING '~ '.

    DO.

    IT_MESS_ATT = GD_BUFFER.

    APPEND IT_MESS_ATT.

    SHIFT GD_BUFFER LEFT BY 255 PLACES.

    IF GD_BUFFER IS INITIAL.

    EXIT.

    ENDIF.

    ENDDO.

    endif.

    thanks,

    krishna.

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Dec 10, 2008 at 10:53 AM

    refer below program

    c_par-preview = space.

    c_par-getotf = 'X'.

    out_opt-tddest = 'EPSON-COMMON'.

    CALL FUNCTION fm_name

    EXPORTING

    control_parameters = c_par

    output_options = out_opt

    user_settings = space

    vbeln = it_vbeln-vbeln

    pdf = r2

    rbiclear = c3

    IMPORTING

    job_output_info = opt

    einv = einv.

    i_otf = opt-otfdata.

    CALL FUNCTION 'CONVERT_OTF'

    EXPORTING

    format = 'PDF'

    max_linewidth = 132

    IMPORTING

    bin_filesize = v_len_in

    TABLES

    otf = i_otf

    lines = i_tline.

    • IF lv_check EQ 1.

    • CALL METHOD cl_gui_frontend_services=>file_save_dialog

    • CHANGING

    • filename = file_name

    • path = file_path

    • fullpath = full_path.

    • ENDIF.

    CLEAR full_path.

    move wa_exnum to lv_exnum.

    shift lv_exnum left deleting leading '0'.

    move 'C:\SAPWORKDIR\' to file_path.

    CONCATENATE file_path 'Invoice_E' lv_exnum '.PDF' INTO full_path.

    CALL FUNCTION 'GUI_DOWNLOAD'

    EXPORTING

    bin_filesize = v_len_in

    filename = full_path

    filetype = 'BIN'

    IMPORTING

    filelength = file_size

    TABLES

    data_tab = i_tline.

    • For mailing

    IF ch2 EQ 'X'.

    DATA sub TYPE string.

    CALL FUNCTION 'QCE1_CONVERT'

    TABLES

    t_source_tab = i_tline

    t_target_tab = so_ali[]

    EXCEPTIONS

    convert_not_possible = 1

    OTHERS = 2.

    • Mail Contents

    refresh objtxt[].

    objtxt = space.

    APPEND objtxt.

    objtxt = 'Dear Sir/Madam,'.

    APPEND objtxt.

    • Determining the Email Ids of Mail Receivers

    PERFORM fetch_mailids.

    objtxt = 'Copy to :'.

    APPEND objtxt.

    LOOP AT reclist.

    objtxt = reclist-receiver.

    APPEND objtxt.

    ENDLOOP.

    objtxt = space.

    APPEND objtxt.

    objtxt = '<This is system generated message>.'.

    APPEND objtxt.

    objtxt = space.

    APPEND objtxt.

    • Mail Body of message over.

    DESCRIBE TABLE objtxt[] LINES v_lines_txt.

    CONCATENATE 'Inv.' invno INTO sub SEPARATED BY space.

    doc_chng-obj_name = sub.

    doc_chng-expiry_dat = sy-datum + 10.

    • Mail Subject

    refresh objpack[].

    CONCATENATE 'Pricol Dispatch - Invoice' invno '- Reg.' INTO sub SEPARATED BY space.

    doc_chng-obj_descr = sub.

    doc_chng-sensitivty = 'F'.

    doc_chng-doc_size = v_lines_txt * 255.

    objpack-transf_bin = ' '.

    objpack-head_start = 1.

    objpack-head_num = 0.

    objpack-body_start = 1.

    objpack-body_num = v_lines_txt.

    objpack-doc_type = 'RAW'.

    APPEND objpack.

    *PDF Attachment

    DESCRIBE TABLE so_ali[] LINES lineno.

    objpack-transf_bin = 'X'.

    objpack-head_start = 1.

    objpack-head_num = 1.

    objpack-body_start = 1.

    objpack-doc_size = lineno * 255 .

    objpack-body_num = lineno.

    objpack-doc_type = 'PDF'.

    objpack-obj_name = 'INVOICE'.

    objpack-obj_descr = 'Invoice'.

    objpack-obj_langu = 'E'.

    APPEND objpack.

    CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'

    EXPORTING

    document_data = doc_chng

    put_in_outbox = 'X'

    commit_work = 'X'

    TABLES

    packing_list = objpack

    contents_txt = objtxt[]

    contents_bin = so_ali[]

    *contents_hex = so_ali[]

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

    PERFORM mail.

    MESSAGE 'Mail sent successfully' TYPE 'S'.

    *SUBMIT RSCONN01 WITH MODE = MODE.

    ENDIF.

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Dec 11, 2008 at 11:03 AM

    Hi Venkat,

    IT_RECEIVERS-RECEIVER = iv_mailid.-------------> You have pass the mail id here
    IT_RECEIVERS-REC_TYPE = 'U'.
    APPEND IT_RECEIVERS.

    CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'

    EXPORTING

    DOCUMENT_DATA = GD_DOC_DATA

    PUT_IN_OUTBOX = 'X'

    COMMIT_WORK = 'X'

    • IMPORTING

    • SENT_TO_ALL =

    • NEW_OBJECT_ID =

    After check in the transaction in sost for the status of the mail.

    Regards,

    Sravanthi

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member Former Member

      First try to send some report list through ALV functionality. Just to see whether your system is configured for HTTP mails or no? If its configured then you should be able to send mail.

      I have created a program for the same requirement. I think your code is right only.

      Please let me know after checking with your basis team about the configuration.

      It will definitely work. If it wont then tell me I will give you other solution.

      Thanks,

      Hemal Shah