Skip to Content
author's profile photo Former Member
Former Member

Payslip to be sent as mail in PDF Format

Dear All,

Please help me in solvong this

I need to send Payslip to Users ( Employees) in mail as a PDF file in 4.7 version.

Thanks in Advance.

Regards,

Add a comment
10|10000 characters needed characters exceeded

Related questions

4 Answers

  • author's profile photo Former Member
    Former Member
    Posted on Aug 30, 2007 at 09:48 AM

    REPORT yacpr0013 .

    PARAMETERS: p_rec TYPE somlreci1 DEFAULT 'test@hotmail.com' LOWER CASE OBLIGATORY,

    p_spool LIKE tsp01-rqident OBLIGATORY.

    CONSTANTS: c_true TYPE boolean_flg VALUE 'X'.

    TYPES: ty_tab_pdf TYPE tline OCCURS 0.

    • Type for binary attachment table.

    TYPES: ty_tab_objbin TYPE solisti1 OCCURS 0.

    DATA: i_objbin TYPE ty_tab_objbin.

    START-OF-SELECTION.

    PERFORM f_convert_to_pdf CHANGING i_objbin.

    PERFORM f_send_email USING p_rec i_objbin.

    &----


    *& @FORMS

    &----


    &----


    *& Form send_email

    &----


    • Subroutine to be able to send a simple email. Check transaction

    • SOST for output. If it makes it to SOST, it's then just a matter

    • of ensuring BASIS has done the appropriate config.

    ----


    FORM f_send_email USING pv_rec TYPE somlreci1

    pi_objbin TYPE ty_tab_objbin.

    DATA: li_reclist LIKE somlreci1 OCCURS 0 WITH HEADER LINE.

    DATA: li_objtxt LIKE solisti1 OCCURS 0 WITH HEADER LINE.

    DATA: li_objpack LIKE sopcklsti1 OCCURS 0 WITH HEADER LINE.

    DATA: ls_doc_chng LIKE sodocchgi1.

    DATA: li_objhead LIKE solisti1 OCCURS 0 WITH HEADER LINE.

    DATA: lv_tab_lines LIKE sy-tabix.

    • Creation of the document to be sent

    • File Name

    ls_doc_chng-obj_name = 'SENDFILE'.

    • Mail Subject

    ls_doc_chng-obj_descr = 'Email header'(em1).

    • Completing the recipient list

    li_reclist-receiver = pv_rec.

    li_reclist-rec_type = 'U'.

    APPEND li_reclist.

    • Mail Contents

    li_objtxt = 'line 1 of the email body'(bd1).

    APPEND li_objtxt.

    CLEAR li_objtxt. " put in a blank line

    APPEND li_objtxt.

    li_objtxt = 'line 2 of the email body'(bd2).

    APPEND li_objtxt.

    li_objtxt = 'line 3 of the email body'(bd3).

    APPEND li_objtxt.

    • Calculate email size in bytes

    DESCRIBE TABLE li_objtxt LINES lv_tab_lines.

    READ TABLE li_objtxt INDEX lv_tab_lines.

    ls_doc_chng-doc_size = ( lv_tab_lines - 1 ) * 255 + STRLEN( li_objtxt ).

    • Creation of the entry for the compressed document

    • for the email text

    CLEAR li_objpack-transf_bin.

    li_objpack-head_start = 1.

    li_objpack-head_num = 0.

    li_objpack-body_start = 1.

    li_objpack-body_num = lv_tab_lines.

    li_objpack-doc_type = 'RAW'.

    APPEND li_objpack.

    • Creation of the document attachment

    • (Assume that the data in OBJBIN is in BMP format)

    DESCRIBE TABLE pi_objbin LINES lv_tab_lines.

    li_objhead = 'Save as name.PDF'(em5).

    APPEND li_objhead.

    CLEAR li_objpack.

    **/ Creation of the entry for the compressed/attached document

    li_objpack-transf_bin = c_true.

    li_objpack-head_start = 1.

    li_objpack-head_num = 1.

    li_objpack-body_start = 1.

    li_objpack-body_num = lv_tab_lines.

    li_objpack-doc_type = 'PDF'.

    li_objpack-obj_name = 'Possibly hover name'.

    li_objpack-obj_descr = 'Real Name'(em6).

    li_objpack-doc_size = lv_tab_lines * 255.

    APPEND li_objpack. "/ .

    • Sending the document

    CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1' "/ .

    EXPORTING

    document_data = ls_doc_chng

    put_in_outbox = 'X'

    TABLES

    packing_list = li_objpack

    object_header = li_objhead

    contents_bin = pi_objbin

    contents_txt = li_objtxt

    receivers = li_reclist

    EXCEPTIONS

    too_many_receivers = 1

    document_not_sent = 2

    operation_no_authorization = 4

    OTHERS = 99.

    IF sy-subrc <> 0.

    WRITE: / 'unsuccessful', sy-subrc.

    ELSE.

    WRITE: / 'successful'.

    ENDIF.

    **/Take_note it is a requirement to do a commit work for the

    • email to go into transaction SOST.

    COMMIT WORK. "/Take_note .

    ENDFORM. "send_email

    &----


    *& Form convert_to_pdf

    &----


    • Convert the spool number on the screen to a PDF

    ----


    FORM f_convert_to_pdf CHANGING pi_objbin TYPE ty_tab_objbin.

    DATA: li_pdf TYPE ty_tab_pdf,

    lv_spool LIKE tsp01-rqident.

    lv_spool = p_spool.

    **/ Call the standard function

    CALL FUNCTION 'CONVERT_ABAPSPOOLJOB_2_PDF'

    EXPORTING

    src_spoolid = lv_spool "/ .

    no_dialog = ' '

    • DST_DEVICE =

    • PDF_DESTINATION =

    • IMPORTING

    • pdf_bytecount = numbytes

    • pdf_spoolid = pdfspoolid

    • LIST_PAGECOUNT =

  • btc_jobname = jobname

  • btc_jobcount = jobcount

  • TABLES

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

    IF sy-subrc <> 0.

    WRITE: / 'error', sy-subrc.

    ENDIF.

    **/ Convert the PDF format to the table type required for the attachment.

    CALL FUNCTION 'QCE1_CONVERT' "/ .

    TABLES

    t_source_tab = li_pdf

    t_target_tab = pi_objbin

    EXCEPTIONS

    convert_not_possible = 1

    OTHERS = 2.

    IF sy-subrc <> 0.

    WRITE: / 'error', sy-subrc.

    ENDIF.

    ENDFORM. "convert_to_pdf

    Hope this helps.......

Add a comment
10|10000 characters needed characters exceeded

  • Posted on Aug 30, 2007 at 09:51 AM
    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Aug 30, 2007 at 10:21 AM

    Here is the code to send the Smartform to mail as PDF attachment.

    &----


    *& Report ZTEST_PDF_MAIL

    *&

    &----


    REPORT ZTEST_PDF_MAIL.

    • Internal Table declarations

    DATA: I_OTF TYPE ITCOO OCCURS 0 WITH HEADER LINE,

    I_TLINE TYPE TABLE OF TLINE WITH HEADER LINE,

    I_RECEIVERS TYPE TABLE OF SOMLRECI1 WITH HEADER LINE,

    I_RECORD LIKE SOLISTI1 OCCURS 0 WITH HEADER LINE,

    • Objects to send mail.

    I_OBJPACK LIKE SOPCKLSTI1 OCCURS 0 WITH HEADER LINE,

    I_OBJTXT LIKE SOLISTI1 OCCURS 0 WITH HEADER LINE,

    I_OBJBIN LIKE SOLISTI1 OCCURS 0 WITH HEADER LINE,

    I_RECLIST LIKE SOMLRECI1 OCCURS 0 WITH HEADER LINE,

    • Work Area declarations

    WA_OBJHEAD TYPE SOLI_TAB,

    W_CTRLOP TYPE SSFCTRLOP,

    W_COMPOP TYPE SSFCOMPOP,

    W_RETURN TYPE SSFCRESCL,

    WA_DOC_CHNG TYPE SODOCCHGI1,

    W_DATA TYPE SODOCCHGI1,

    WA_BUFFER TYPE STRING, "To convert from 132 to 255

    • Variables declarations

    V_FORM_NAME TYPE RS38L_FNAM,

    V_LEN_IN LIKE SOOD-OBJLEN,

    V_LEN_OUT LIKE SOOD-OBJLEN,

    V_LEN_OUTN TYPE I,

    V_LINES_TXT TYPE I,

    V_LINES_BIN TYPE I.

    CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'

    EXPORTING

    FORMNAME = 'ZTEST'

    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 = 'X'.

    CALL FUNCTION V_FORM_NAME

    EXPORTING

    CONTROL_PARAMETERS = W_CTRLOP

    OUTPUT_OPTIONS = W_COMPOP

    USER_SETTINGS = 'X'

    IMPORTING

    JOB_OUTPUT_INFO = W_RETURN

    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[].

    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.

    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[].

    • 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 = 0.

    I_OBJPACK-BODY_START = 1.

    DESCRIBE TABLE I_OBJBIN LINES V_LINES_BIN.

    READ TABLE I_OBJBIN INDEX V_LINES_BIN.

    I_OBJPACK-DOC_SIZE = V_LINES_BIN * 255 .

    I_OBJPACK-BODY_NUM = V_LINES_BIN.

    I_OBJPACK-DOC_TYPE = 'PDF'.

    I_OBJPACK-OBJ_NAME = 'smart'.

    I_OBJPACK-OBJ_DESCR = 'test'.

    APPEND I_OBJPACK.

    CLEAR I_RECLIST.

    I_RECLIST-RECEIVER = 'nareshreddy.k@gmail.com'.

    I_RECLIST-REC_TYPE = 'U'.

    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.

    If you want to send some text as Body of the Mail then follow this once

    when u r callin the FM'SO_NEW_DOCUMENT_ATT_SEND_API1'.. points to remember

    1.u have to pass the body of content in table CONTENTS_TXT(ia m using I_OBJBIN) (each line a record) then. suppose i have appended 11 records to the table CONTENTS_TXT .

    2.PACKING_LIST(iam usign I_OBJPACK) table u ahve to append a redord as follows

    I_OBJPACK-TRANSF_BIN = ' '.

    I_OBJPACK-HEAD_START = 000000000000001.

    I_OBJPACK-HEAD_NUM = 000000000000001.

    I_OBJPACK-BODY_START = 000000000000002

    I_OBJPACK-BODY_NUM = 000000000000010.

    I_OBJPACK-DOC_TYPE = 'RAW'.

    append I_OBJPACK-.

    by the above code system treat the first line in table I_OBJBIN as header and the 2nd line to 10 lines tread as body.

    CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'

    EXPORTING

    DOCUMENT_DATA = WA_DOC_CHNG

    PUT_IN_OUTBOX = '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.

    regards,

    srinivas

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Aug 30, 2007 at 10:48 AM

    HI

    use function convert_abap_spool2pdf to convert the doc to pdf

    then use 'SO_NEW_DOCUMENT_ATT_SEND_API1' to send it via mail as attachment

    Thanks

    vivekanand

    Add a comment
    10|10000 characters needed characters exceeded

  • Before answering

    You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
    You must be Logged in to submit an answer.

    Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.