Send mail/fax/print SAPSCRIPT

Hi Experts,
I need to modify SAPSCRIPT in transaction F.64.
This Layout I need to send as Email/fax/print as per user requirement.
Could give me sample code tht i need to modify in Print program to achieve the above functionality///.............
Its Urgent.........Answers will be rewarded...

Hi,
For mail attachemnt:
REPORT Z_SCRIPT .
DATA: itcpo LIKE itcpo,
tab_lines LIKE sy-tabix.
Variables for EMAIL functionality
DATA: maildata LIKE sodocchgi1.
DATA: mailpack LIKE sopcklsti1 OCCURS 2 WITH HEADER LINE.
DATA: mailhead LIKE solisti1 OCCURS 1 WITH HEADER LINE.
DATA: mailbin LIKE solisti1 OCCURS 10 WITH HEADER LINE.
DATA: mailtxt LIKE solisti1 OCCURS 10 WITH HEADER LINE.
DATA: mailrec LIKE somlrec90 OCCURS 0 WITH HEADER LINE.
DATA: solisti1 LIKE solisti1 OCCURS 0 WITH HEADER LINE.
*PERFORM send_form_via_email.
FORM SEND_FORM_VIA_EMAIL *
FORM send_form_via_email.
CLEAR: maildata, mailtxt, mailbin, mailpack, mailhead, mailrec.
REFRESH: mailtxt, mailbin, mailpack, mailhead, mailrec.
Creation of the document to be sent File Name
maildata-obj_name = 'TEST'.
Mail Subject
maildata-obj_descr = 'Subject'.
Mail Contents
mailtxt-line = 'Here is your file'.
APPEND mailtxt.
Prepare Packing List
PERFORM prepare_packing_list.
Set recipient - email address here!!!
mailrec-receiver = 'email.COM'.
mailrec-rec_type = 'U'.
APPEND mailrec.
Sending the document
CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
EXPORTING
document_data = maildata
put_in_outbox = ' '
TABLES
packing_list = mailpack
object_header = mailhead
contents_bin = mailbin
contents_txt = mailtxt
receivers = mailrec
EXCEPTIONS
too_many_receivers = 1
document_not_sent = 2
operation_no_authorization = 4
OTHERS = 99.
ENDFORM.
Form PREPARE_PACKING_LIST
FORM prepare_packing_list.
CLEAR: mailpack, mailbin, mailhead.
REFRESH: mailpack, mailbin, mailhead.
DESCRIBE TABLE mailtxt LINES tab_lines.
READ TABLE mailtxt INDEX tab_lines.
maildata-doc_size = ( tab_lines - 1 ) * 255 + STRLEN( mailtxt ).
Creation of the entry for the compressed document
CLEAR mailpack-transf_bin.
mailpack-head_start = 1.
mailpack-head_num = 0.
mailpack-body_start = 1.
mailpack-body_num = tab_lines.
mailpack-doc_type = 'RAW'.
APPEND mailpack.
Creation of the document attachment
This form gets the OTF code from the SAPscript form.
If you already have your OTF code, I believe that you may
be able to skip this form. just do the following code, looping thru
your SOLISTI1 and updating MAILBIN.
PERFORM get_otf_code.
LOOP AT solisti1.
MOVE-CORRESPONDING solisti1 TO mailbin.
APPEND mailbin.
ENDLOOP.
DESCRIBE TABLE mailbin LINES tab_lines.
mailhead = 'TEST.OTF'.
APPEND mailhead.
Creation of the entry for the compressed attachment
mailpack-transf_bin = 'X'.
mailpack-head_start = 1.
mailpack-head_num = 1.
mailpack-body_start = 1.
mailpack-body_num = tab_lines.
mailpack-doc_type = 'OTF'.
mailpack-obj_name = 'TEST'.
mailpack-obj_descr = 'Subject'.
mailpack-doc_size = tab_lines * 255.
APPEND mailpack.
ENDFORM.
Form GET_OTF_CODE
FORM get_otf_code.
DATA: BEGIN OF otf OCCURS 0.
INCLUDE STRUCTURE itcoo .
DATA: END OF otf.
DATA: itcpo LIKE itcpo.
DATA: itcpp LIKE itcpp.
CLEAR itcpo.
itcpo-tdgetotf = 'X'.
Start writing OTF code
CALL FUNCTION 'OPEN_FORM'
EXPORTING
form = 'Z08V3_COLLI'
language = sy-langu
options = itcpo
dialog = ' '
EXCEPTIONS
OTHERS = 1.
CALL FUNCTION 'START_FORM'
EXCEPTIONS
error_message = 01
OTHERS = 02.
CALL FUNCTION 'WRITE_FORM'
EXPORTING
window = 'MAIN'
EXCEPTIONS
error_message = 01
OTHERS = 02.
Close up Form and get OTF code
CALL FUNCTION 'END_FORM'
EXCEPTIONS
error_message = 01
OTHERS = 02.
MOVE-CORRESPONDING itcpo TO itcpp.
CALL FUNCTION 'CLOSE_FORM'
IMPORTING
result = itcpp
TABLES
otfdata = otf
EXCEPTIONS
OTHERS = 1.
Move OTF code to structure SOLI form email
CLEAR solisti1. REFRESH solisti1.
LOOP AT otf.
solisti1-line = otf.
APPEND solisti1.
ENDLOOP.
ENDFORM
For FAx Attaxhment:
REPORT RSKSENDF MESSAGE-ID SK.
Test report to send a test fax
sends a fax to the number <TO_CNTRY>-<TO_NMBER>
containing an automatically generated message text.
TABLES: USR03.
PARAMETERS: TO_CNTRY LIKE T005-LAND1 OBLIGATORY,
TO_NMBER LIKE TSP01-RQTELENUM OBLIGATORY,
FROM_USR(30) TYPE C DEFAULT SY-UNAME,
TO_RECIP(30) TYPE C DEFAULT SY-UNAME.
SAPscript content ITAB
DATA: BEGIN OF TEST_DOC OCCURS 10.
INCLUDE STRUCTURE TLINE.
DATA: END OF TEST_DOC.
SAPscript header struct
DATA BEGIN OF HEADER.
INCLUDE STRUCTURE THEAD.
DATA END OF HEADER.
INITIALIZATION.
get county from user addres in usr03
system->user profile->user address
check if not empty
SELECT SINGLE * FROM USR03 WHERE BNAME = SY-UNAME.
IF SY-SUBRC = 0 AND USR03-LAND1 <> SPACE.
TO_CNTRY = USR03-LAND1.
ENDIF.
START-OF-SELECTION.
PERFORM FILL_UP_TEST_DOC.
PERFORM SHOW_TEST_DOC.
AT PF08.
PERFORM SEND_FAX TABLES TEST_DOC USING TO_CNTRY
TO_NMBER.
AT SELECTION-SCREEN ON TO_NMBER.
PERFORM CHECK_NUMBER USING TO_CNTRY TO_NMBER.
*& Form CHECK_NUMBER
FORM CHECK_NUMBER USING
COUNTRY
NUMBER.
DATA: SERVICE LIKE TSKPA-SERVICE VALUE 'TELEFAX',
LEN LIKE SY-FDPOS.
FIELD-SYMBOLS <P>.
windows GUI push the ? from mandatory input instead
of overwriting it
LEN = STRLEN( TO_NMBER ).
IF LEN > 1.
SUBTRACT 1 FROM LEN.
ASSIGN TO_NMBER+LEN(1) TO <P>.
IF <P> = '?'.
<P> = SPACE.
ENDIF.
ENDIF.
official check FM
CALL FUNCTION 'TELECOMMUNICATION_NUMBER_CHECK'
EXPORTING
COUNTRY = COUNTRY
NUMBER = NUMBER
SERVICE = SERVICE.
on old 21?/22? release you may have to handle the
exception
because the Function uses RAISE instead of
MESSAGE... RAISING....
ENDFORM. " CHECK_NUMBER
*& Form FILL_UP_TEST_DOC
fills test text in itab TEST_DOC *
real life example needs to get real life data *
FORM FILL_UP_TEST_DOC.
DATA: DATUM(12) TYPE C,
UZEIT(10) TYPE C.
SAPscript initialization
of course, you may want to set a few parameter
(FORM,LAYOUT,....)
CALL FUNCTION 'INIT_TEXT'
EXPORTING
ID = 'ST '
LANGUAGE = SY-LANGU
NAME = 'FOO-BAR'
OBJECT = 'TEXT'
IMPORTING
HEADER = HEADER
TABLES
LINES = TEST_DOC
EXCEPTIONS
OTHERS = 1.
IF SY-SUBRC <> 0.
MESSAGE A400 WITH 'INIT_TEXT'.
ENDIF.
PERFORM ADD_EMPTY_LINE.
WRITE: SY-DATUM TO DATUM.
WRITE: SY-UZEIT TO UZEIT.
PERFORM ADD_LINES USING 'This is test Telefax'(001)
DATUM UZEIT.
PERFORM ADD_EMPTY_LINE.
PERFORM ADD_LINES USING 'From: &'(002) FROM_USR SPACE.
PERFORM ADD_LINES USING 'To: &'(003) TO_RECIP SPACE.
PERFORM ADD_LINES USING 'Fax number: & &'(004)
TO_CNTRY TO_NMBER.
PERFORM ADD_EMPTY_LINE.
PERFORM ADD_LINES USING
'This is a test fax send by Report RSKSENDF'(005)
SPACE SPACE.
PERFORM ADD_LINES USING 'on SAP system & '(006)
SY-SYSID SPACE.
PERFORM ADD_EMPTY_LINE.
PERFORM ADD_LINES USING
'the quick brown fox jumps over the lazy dog.'(101)
SPACE SAPCE.
PERFORM ADD_LINES USING
'THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG.'(102)
SPACE SAPCE.
PERFORM ADD_EMPTY_LINE.
PERFORM ADD_LINES USING 'End of test'(007) SPACE
SPACE.
ENDFORM. " FILL_UP_TEST_DOC
*& Form ADD_LINES
printf a line an appends it in test_doc *
--> cformat format.
--> p1 param1
--> p2 param2
FORM ADD_LINES USING CFORMAT P1 P2.
TEST_DOC-TDFORMAT = '/'.
TEST_DOC-TDLINE = CFORMAT.
IF TEST_DOC-TDLINE CA '&'.
REPLACE '&' WITH P1 INTO TEST_DOC-TDLINE.
IF TEST_DOC-TDLINE CA '&'.
REPLACE '&' WITH P2 INTO TEST_DOC-TDLINE.
ENDIF.
ENDIF.
APPEND TEST_DOC.
ENDFORM. " ADD_LINES
*& Form ADD_EMPTY_LINE
appends an empty line to test_doc *
FORM ADD_EMPTY_LINE.
TEST_DOC-TDFORMAT = '/'.
CLEAR TEST_DOC-TDLINE.
APPEND TEST_DOC.
ENDFORM. " ADD_EMPTY_LINE
*& Form SHOW_TEST_DOC
lists the test doc for aproval *
*>>>> this is for fun only because PRINT_TEXT also
offers a preview *
FORM SHOW_TEST_DOC.
FORMAT COLOR COL_BACKGROUND INTENSIFIED OFF.
WRITE: / 'Test fax would look like this:'(020).
ULINE.
SKIP.
LOOP AT TEST_DOC.
IF TEST_DOC-TDLINE <> SPACE.
WRITE:/ TEST_DOC-TDLINE.
ELSE.
SKIP.
ENDIF.
ENDLOOP.
SKIP.
ULINE.
FORMAT COLOR COL_POSITIVE INTENSIFIED OFF.
WRITE: 'Press PF8 to send it'(021).
ENDFORM. " SHOW_TEST_DOC
*& Form SEND_FAX
send fax by calling SAPscript *
Note: Instead of using PRINT_TEXT you may also *
call OPEN_FORM / WRITE_FORM_LINES / CLOSE_FORM, *
this allows you to use a similar program structure *
as with NEW-PAGE PRINT ON / WRITE / NEW-PAGE PRINT
OFF *
FORM SEND_FAX
TABLES DOC2FAX STRUCTURE TEST_DOC
USING COUNTRY
NUMBER.
DATA: SID(5) TYPE N.
DATA BEGIN OF POPT.
INCLUDE STRUCTURE ITCPO.
DATA END OF POPT.
DATA BEGIN OF PRES.
INCLUDE STRUCTURE ITCPP.
DATA END OF PRES.
CLEAR POPT.
POPT-TDCOPIES = 1. " one copy
POPT-TDDEST = " done internaly by script,
POPT-TDPRINTER = " do not fill !!!
POPT-TDNEWID = 'X'. " do not reuse old spool request
POPT-TDDATASET = 'TEST'(022). " fill as you want
POPT-TDSUFFIX1 = 'FAX'(023). " fill as you want
POPT-TDSUFFIX2 = SY-UNAME. " fill as you want
POPT-TDIMMED = 'X'. " send now
POPT-TDLIFETIME = 8. " keep 8 days in spool
POPT-TDTELENUM = NUMBER. " number without country code
POPT-TDTELELAND = COUNTRY. " country of recipient
POPT-TDCOVER = 'test fax'(024).
POPT-TDCOVTITLE = 'test fax'(024).
POPT-TDIEXIT = 'X'.
CALL FUNCTION 'PRINT_TEXT'
EXPORTING
APPLICATION = 'TX'
ARCHIVE_INDEX = ' '
ARCHIVE_PARAMS = ' '
DEVICE = 'TELEFAX' "<<< here we say: fax it !
DIALOG = 'X'
HEADER = HEADER
OPTIONS = POPT
IMPORTING
RESULT = PRES
TABLES
LINES = DOC2FAX
EXCEPTIONS
OTHERS = 01.
do not bother with exception in sample code
CANCELED = 01
DEVICE = 02
FORM = 03
OPTIONS = 04
UNCLOSED = 05
UNKNOWN = 06
FORMAT = 07
TEXTFORMAT = 08
EXTERNAL = 09.
IF SY-SUBRC = 0.
arriving here means we could send:
SID = PRES-TDSPOOLID.
IF SID > '00000'.
MESSAGE S433 WITH SID.
ENDIF.
LEAVE .
ELSE.
do not bother with exception in sample code
MESSAGE A400 WITH 'PRIN_TEXT'.
ENDIF.
ENDFORM. " SEND_FAX
TESTING:
You can check with the transactions SOST or SOSB to monitor the outputs sent out from SAP.
Regards,
Shiva Kumar

Similar Messages

  • Send mail/fax from SAPSCRIPT

    Hi Experts,
    Could you provide with sample code to send email and fax from the print program of a Sap Script...
    Its urgent......plezzz help...
    answers will be rewarded..

    Hi Abhay,
    better option is to convert your spool request to PDF and
    send it
    call function 'CONVERT_ABAPSPOOLJOB_2_PDF'
    exporting
    src_spoolid = mi_rqident
    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.
    check sy-subrc = 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.
    then call FM after populating attachment data
    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
    Award points if useful
    Thanks,
    Ravee..

  • How to activate "Send mail" from print preview in ME23N

    In ME23N there is a "print preview"-button that shows a preview of the PO. In the preview-windows there is a Text-menu with a "Send mail"-command, but that command is not active. How can I activate this command so that it is possible to send the PO to an email-recepient?
    I have configured the smtp-functionality (SCOT++) and sending PO's as email to suppliers in ME9F works fine by choosing "Send external". But still the Send mail-option is inactive in preview-mode. Any tips?
    Regards,
    Thor-Egil

    please maintain output condition record (MN04) as "external send"
    Also make sure that you have maintained the proper email ID in vendor master

  • Problem in sending mail-------- stop printing

    Hi ABAPers,
    I am trying to send pdf attachment from sap to outlook mail .
    I am getting the mail but the problem is evertime before sending the atttachment to outlook mail,it is populating the printer for printing.
    How can i stop the printing action.
    Regards
    Debjani
    The code is given below:
    CALL FUNCTION 'SSF_GET_DEVICE_TYPE'
        EXPORTING
          i_language    = 'E'
          i_application = 'SAPDEFAULT'
        IMPORTING
          e_devtype     = p_e_devtype.
      p_control_parameters-no_dialog = 'X'.
       p_control_parameters-preview = ' '.
       p_control_parameters-GETOTF = 'X'.
      p_output_options-xsfcmode = 'X'.
      p_output_options-xsf = space.
      p_output_options-xdfcmode = 'X'.
      p_output_options-xdf = space.
    p_output_options-tdprinter = p_e_devtype.
       p_output_options-tdnewid = 'X'.
       p_output_options-TDNOPREV = 'X'.
      CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
           EXPORTING
             formname                 = 'ZREQUEST_FORM'
          IMPORTING
            fm_name                  = frm
             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.
      CALL FUNCTION   frm                " '/1BCDWB/SF00000304'
                       EXPORTING
                         control_parameters         =  p_control_parameters
                         output_options             =  p_output_options
                         user_settings              = 'X'
                       IMPORTING
                         job_output_info            = p_job_output_info
              TABLES
                itab                       = itab
                it71                       = it71
                      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.
    spd = p_job_output_info-spoolids.
    CLEAR spd1.
    READ TABLE spd INTO spd1 INDEX 1.
    IF sy-subrc = 0.
    GD_SPOOL_NR = spd1.
    ENDIF.
    CALL FUNCTION 'CONVERT_OTFSPOOLJOB_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_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
       OTHERS                         = 12
    IF sy-subrc <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
             WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
      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.
      PERFORM process_email.
        IF sy-sysid = c_dev.
          wait up to 5 seconds.
          SUBMIT rsconn01 WITH mode   = 'INT'
                          WITH output = 'X'
                          AND RETURN.
        ENDIF.
    CHECK NOT ( p_email1 IS INITIAL ).
      REFRESH it_mess_bod.
    Default subject matter
      gd_subject         = 'Subject'.
      gd_attachment_desc = 'Attachname'.
    CONCATENATE 'attach_name' ' ' INTO gd_attachment_name.
      it_mess_bod        = 'Message Body text, line 1'.
      APPEND it_mess_bod.
    If no sender specified - default blank
      IF p_sender EQ space.
        gd_sender_type  = space.
      ELSE.
        gd_sender_type  = 'INT'.
      ENDIF.
    Send file by email as .xls speadsheet
      PERFORM send_file_as_email_attachment
                                   tables it_mess_bod
                                          it_mess_att
                                    using p_email1
                                                      'Request Form for Transport'
                                          'PDF'
                                          gd_attachment_name
                                          gd_attachment_desc
                                          p_sender
                                          gd_sender_type
                                 changing gd_error
                                          gd_reciever.
    FORM send_file_as_email_attachment tables it_message
                                              it_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:   t_packing_list like sopcklsti1 occurs 0 with header line,
            t_contents like solisti1 occurs 0 with header line,
            t_receivers like somlreci1 occurs 0 with header line,
            t_attachment like solisti1 occurs 0 with header line,
            t_object_header like solisti1 occurs 0 with header line,
            w_cnt type i,
            w_sent_all(1) type c,
            w_doc_data like sodocchgi1.
      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'.
      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.
      w_doc_data-sensitivty = 'F'.
      CLEAR t_attachment.
      REFRESH t_attachment.
      t_attachment[] = it_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.
      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
      CLEAR t_receivers.
      REFRESH t_receivers.
      t_receivers-receiver = ld_email.
      t_receivers-rec_type = 'U'.
      t_receivers-com_type = 'INT'.
      t_receivers-notif_del = 'X'.
      t_receivers-notif_ndel = 'X'.
      APPEND 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.

    Hi Debjani
    Please add this line while populating your Recievers table,
    CLEAR t_receivers.
    REFRESH t_receivers.
    t_receivers-receiver = ld_email.
    t_receivers-rec_type = 'U'.
    t_receivers-com_type = 'INT'.
    t_receivers-no_print = 'X'.
    t_receivers-notif_del = 'X'.
    t_receivers-notif_ndel = 'X'.
    APPEND t_receivers.
    Hope this helps !
    ~ Ranganath

  • Mail & fax option in Smartforms

    Hi,
    Is there an option of sending mails & fax through Smartforms.Pleas guide me through this query.
    Thanks.

    Go to SPAD and check if u have configured Fax machine in SAP or not..
    Then u select the Medium as 5 and then go to NACE..select the application ...
    then press condition type...
    there u will get a list of output types..just select the one for your object and double click on it..
    Enter the necessary values and then u will be taken to a screen..
    There on Top left u can see communication method...
    Enter the Fax dest that u  have seen in SPAD tcode..
    Reward the points if u find the answer helpful.
    Thanks.

  • Print out as well as Sending mail of invoice

    Hi
    I have a requirement   in invoice like, i need print out as well as I need to send mail to the user.
    In T-code VF03 ,  My user will be giving only one  transaction medium as External send.
    But  he needs the print out of the invoice also. how can we arrive at the solution for this..
    Kindly send me reply .
    Regards
    Uma

    Hello Uma,
    Yes, it is possible.
    As you are aware, the medium will be selected as per the input:
    1     Print output
    2     Fax
    4     Telex
    5     External send
    6     EDI
    7     Simple Mail
    8     Special function
    9     Events (SAP Business Workflow)
    A     Distribution (ALE)
    If the user is selecting the Print output and he wants the same to be mailed, then add the logic to send the mail in the Z program.
    You can get the value for medium in the program with the NAST-NACHA structure.
    Please let me know if any more details are required.
    Regards,
    Selva K

  • PO output with mail, fax and print

    I have created a PO with message type medium 5 (i.e. External send).
    Now I go inside 'Communication method' and I can see communication strategy field, I select EML there (i.e EMAIL, FAX, PRINT).
    Now after saving PO is getting mailed and also fax is working, but it is not printing out.
    1. Is there any separate settings required for print out?
    If I select medium as print out then print is working.
    Please advice.
    Thanks

    Can you please explain more please?
    1. Is this possible for PO output?
    2. I have Email,Fax and print option, then if email goes then other two will not work?
    3.Where the print will come, is this the printer mentioned in the communication method?
    4.Where can I get the configuration steps for this?
    Please advice.

  • Why does my printer automatically go to send a fax when I just want to print?

    Why does my printer automatically go to send a fax when I just want to print?
    This question was solved.
    View Solution.

    Hi pa_tom,
    In your printers folder on your computer, is the default printer set to your printer, or your printer- fax?
    If I have solved your issue, please feel free to provide kudos and make sure you mark this thread as solution provided!
    Although I work for HP, my posts and replies are my own opinion and not those of HP.

  • Printing Long text in Send Mail Task

    Hi All,
    My requirement is to print the long text of particular error message in the send mail task, which will be sent to outlook.
    for this i have an activity beforr the mail task, where i have filled the multiline parameter called 'TEXT' and this is exported to workflow also.
    In my send mail task, in the body of the message, using insert expression i have inserted the multiline container 'TEXT' with the option of line break, so it came &TEXT##&.
    But once the WF is executed , i checked the WF log and found that the mail is sent and i have checked the container 'TEXT' in my previous activity where the TEXT container has 10 lines.
    But when i checked the mail in SOST the contents of TEXT is not getting printed.
    What will be the issue?
    Thanks and Regards,
    Swaminathan

    @Rick
    How is TEXT defined in the container? Is it passed in via the binding?
    I think if at all you want to use the container element in the mail then binding is not necessary from workflow to task.
    @Swaminathan PJ 
    the multiline container 'TEXT' with the option of line break, so it came &TEXT##&.
    Try to print the entire text continuosly with out line breaks then it works.

  • I get SEND A FAX Window when I try to print in Word on HP All in One J5780 Windows 7.

    I get SEND A FAX Window when I try to print in Word on HP All in One J5780 on Windows 7. I recently moved to Windows 7 64 bit and Word 2010 and download the latest software for my J5780

    HI,
    GO to the control panel and check which printer is listed as the default printer. Most likely this is the J5780 (fax) instead of the J5780. Right click the correct  printer icon and choose "use a default" to correct it.
    Say "Thanks" by clicking the Kudos Star in the post that helped you.
    Although I work for HP my posts and replies are my own
    Please mark the post that solves your problem as "Accepted Solution"

  • I want to send a fax. I can not find an efax icon on the screen on my printer. How do I send a fax?

    I have an HP Photosmart Premium e-All-in-One Printer - C310a . I want to send a fax. I can not find an efax icon on the screen on my printer. How do I send a fax?

    This model does not include e-Fax. The product specifications are here: Product Specifications. If you want a model with e-Fax, you should check out the HP Photosmart eStation C510.
    I am an employee of Hewlett Packard.
    - - Please mark Accept As Solution if it solves your problem so others can more easily find the answer - -
    - - Please click the Kudos star if you would like to say thanks - -

  • Enable Send Mail option in print preview

    Hi,
    Is it possible to enable the 'Send Mail' option in the print preview of the form output. If possible how do we do that. Please let me know.
    <removed by moderator>
    Thanks & Regards,
    Prasanth
    Edited by: Thomas Zloch on May 13, 2010 11:17 AM

    Hai ,
    Your can send mail using the function Module : SO_NEW_DOCUMENT_SEND_API1 , check where you need to use this function module any  user exit is available for this at the time of print preview .
    Regards,
    K.Vinay Kumar

  • Reg sending mail attachment

    Hi,
    im working on sending report output as mail attachment in pdf format..
    but im not getting the required output,,,i.e., even after entering email addresses in the selection screen....im not getting any mail to the respective mail-ids..
    im pasting the code..pls fix the problem..
    pls let me know wat we have to do in SCOT transaction after executing the program....pls respond ..pls ..
    TABLES : t001,                                         "COMPANY CODE
             knb1,                                         "CUSTOMER MASTER(COMPANY CODE)
             cdhdr,                                        "CHANGE DOCUMENT HEADER
             knkk,                                         "CUSTOMER MASTER CREDIT MANAGEMENT: CONTROL AREA DATA
             kna1,                                         "GENERAL DATA IN CUSTOMER MASTER
             adrc,                                         "ADDRESSES (BUSINESS ADDRESS SERVICES)
             t001s,                                        "ACCOUNTING CLERKS
             adrt,                                         "COMMUNICATION DATA TEXT (BUSINESS ADDRESS SERVICES)
             adr6.                                         "E-MAIL ADDRESSES (BUSINESS ADDRESS SERVICES)
    TABLES: itcpo,                                         "SAPscript output interface
            itcpp.                                         "SAPscript output parameters
    TYPES:   BEGIN OF y_t001,
                      bukrs TYPE bukrs,
                      kkber TYPE kkber,
                      adrnr TYPE adrnr,
             END OF y_t001.
    TYPES:   BEGIN OF y_cust,
                      p_objectid TYPE cdobjectv,
             END OF y_cust.
    TYPES:   BEGIN OF y_knkk,
                      kunnr TYPE kunnr,
                      kkber TYPE kkber,
                      dtrev TYPE dtrev_cm,
                      nxtrv TYPE nxtrv_cm,
                      klimk TYPE klimk,
                      dbwae TYPE dbwae_cm,
             END OF y_knkk.
    TYPES:   BEGIN OF y_customer,
                      kunnr TYPE kunnr,
                      adrnr TYPE adrnr,
             END OF y_customer.
    TYPES:   BEGIN OF y_custo ,
                      kunnr TYPE  kunnr,
                      name  TYPE  name1_gp,
                      kkber TYPE kkber,
             END OF y_custo.
    TYPES:   BEGIN OF y_knkk1,
                      kunnr LIKE knkk-kunnr,
                      dtrev LIKE knkk-dtrev,
                      nxtrv LIKE knkk-nxtrv,
                      klimk LIKE knkk-klimk,
             END OF y_knkk1.
    TYPES:   BEGIN OF y_report_display,
                      kunnr TYPE kunnr,
                      name  TYPE name1_gp,
                      dtrev TYPE dtrev_cm,
                      nxtrv TYPE nxtrv_cm,
                      klimk TYPE klimk,
                      dbwae TYPE dbwae_cm,
             END OF y_report_display.
    TYPES:   BEGIN OF y_adrt,
                      addrnumber TYPE adrnr,
                      comm_type  TYPE ad_comm,
                      remark     TYPE ad_remark2,
                      persnumber TYPE ad_persnum,
                      date_from  TYPE ad_date_fr,
                      consnumber TYPE ad_consnum,
                      smtp_addr  TYPE ad_smtpadr,
              END OF y_adrt.
    *TYPES : BEGIN OF y_adr6,
                     addrnumber TYPE ad_addrnum,
                     persnumber TYPE ad_persnum,
                     date_from  TYPE ad_date_fr,
                     consnumber TYPE ad_consnum,
                     smtp_addr  TYPE ad_smtpadr,
           END OF y_adr6.
    *TYPES:   BEGIN OF y_addr,
                     addrnumber TYPE adrnr,
                     name1  TYPE ad_name1,
                     postcode TYPE ad_pstcd1,
                     city1    TYPE ad_city1,
                     street   TYPE ad_street,
                     housenum TYPE ad_hsnm1,
                     telnum   TYPE ad_tlnmbr1,
                     faxnum   TYPE ad_fxnmbr1,
            END OF y_addr.
    TYPES:   BEGIN OF y_custnam,
                      adrnr TYPE adrnr,
                      name2 TYPE ad_name1,
             END OF y_custnam.
    TYPES:   BEGIN OF y_kna1,
                      kunnr TYPE kunnr,
                      adrnr TYPE adrnr,
                      name1 TYPE name1,
                     END OF y_kna1.
    TYPES:   BEGIN OF y_knb1,
                      kunnr TYPE kunnr,
                      bukrs TYPE bukrs,
                      busab TYPE busab,
             END OF y_knb1.
    TYPES:   BEGIN OF y_clv,
                      dtrev TYPE dtrev_cm,
                      nxtrv TYPE nxtrv_cm,
                      klimk TYPE klimk,
             END OF y_clv.
    TYPES:    BEGIN OF y_ccname,
                       sname TYPE t001s-sname,
              END OF y_ccname.
    *TYPES DECLARATION FOR DESIGING SCRIPT
    TYPES : BEGIN OF y_adrc,
               addrnumber LIKE adrc-addrnumber,
               name1 LIKE adrc-name1,
               post_code1 LIKE adrc-post_code1,
               city1 LIKE adrc-city1,
               street LIKE adrc-street,
               house_num1 LIKE adrc-house_num1,
               tel_number LIKE adrc-tel_number,
               nation LIKE adrc-nation ,
               fax_number LIKE adrc-fax_number,
               country LIKE adrc-country,
               END OF y_adrc.
    *TO GET C1 (CUSTOMER NAME IN RUSSIAN
    TYPES : BEGIN OF y_adrc1,
            addrnumber LIKE adrc-addrnumber,
            name1 LIKE adrc-name1,
            nation LIKE adrc-nation,
            END OF y_adrc1.
    *TO GET C7
    TYPES :BEGIN OF y_t001s,
            bukrs LIKE t001s-bukrs,    "Company Code
            busab LIKE t001s-busab,
            sname LIKE t001s-sname,
            END OF y_t001s.
    CONSTANTS:
    c_printer         LIKE itcpp-tddevice VALUE 'PRINTER',
    c_true(1)         TYPE c VALUE 'X',
    c_1(1)            TYPE n VALUE '1',
    c_pdf_format(3)   TYPE c VALUE 'PDF',
    c_u               LIKE soos1-recesc   VALUE 'U',
    c_recipient_name  LIKE soos1-recnam   VALUE 'U-',
    c_english         LIKE sy-langu       VALUE 'E',
    c_f               LIKE sood1-objsns   VALUE 'F',
    c_int(3)          TYPE c VALUE 'INT',
    c_main(4)         TYPE c VALUE 'ITEM',
    c_main_window(4)  TYPE c VALUE 'MAIN',
    c_header(6)       TYPE c VALUE 'HEADER',
    c_minus_sign(1)   TYPE c VALUE '-',
    c_document_type   LIKE sood-objtp     VALUE 'EXT',
    c_space(1)        TYPE c VALUE ' '.
    DATA t_result LIKE itcpp.
    DATA :w_t001      TYPE t001,
          w_custo     TYPE y_custo,
          w_knkk      TYPE y_knkk,
          w_cust      TYPE y_cust,
          w_customer  TYPE y_customer,
          w_report_display TYPE y_report_display,
         w_addr      TYPE y_addr,
          w_custnam   TYPE y_custnam,
          w_adrt      TYPE y_adrt,
         w_adr6      TYPE y_adr6,
          w_kna1      TYPE y_kna1,
          w_knb1      TYPE y_knb1,
          w_clv       TYPE y_clv,
          w_ccname    TYPE y_ccname.
    DATA:    w_error_found(1)       TYPE c,
             w_key_date_text(30)    TYPE c,
             w_total(10)            TYPE p DECIMALS 2,
             w_htddevice            LIKE itcpp-tddevice.
    DATA: E_PROFILE LIKE SOPRD.
    DATA:   t_t001            TYPE STANDARD TABLE OF y_t001,
            t_custo           TYPE STANDARD TABLE OF y_custo,
          t_knkk            TYPE STANDARD TABLE OF y_knkk,
            t_cust            TYPE STANDARD TABLE OF y_cust,
            t_customer        TYPE STANDARD TABLE OF y_customer,
            t_report_display  TYPE STANDARD TABLE OF y_report_display,
           t_addr            TYPE STANDARD TABLE OF y_addr,
            t_custnam         TYPE STANDARD TABLE OF y_custnam,
            t_adrt            TYPE STANDARD TABLE OF y_adrt,
           t_adr6            TYPE STANDARD TABLE OF y_adr6,
            t_kna1            TYPE STANDARD TABLE OF y_kna1,
            t_knb1            TYPE STANDARD TABLE OF y_knb1,
            t_clv             TYPE STANDARD TABLE OF y_clv,
            t_ccname          TYPE STANDARD TABLE OF y_ccname.
    DATA : number LIKE spell,
           amount(1000) TYPE c.
    For storing error log
    DATA: BEGIN OF t_error OCCURS 0,
            kunnr LIKE kna1-kunnr,
            comm(30) TYPE c,
          END OF t_error.
    For storing customer's email address
    DATA: BEGIN OF t_email OCCURS 0,
            smtp_addr LIKE adr6-smtp_addr,
          END OF t_email.
    To be used in the function to send a layout via email
    DATA: t_otfdata LIKE itcoo OCCURS 0 WITH HEADER LINE,
          t_htline  LIKE tline OCCURS 0 WITH HEADER LINE.
    DATA DECLARATIONS FOR DESIGING SCRIPT
    DATA : it_t001 TYPE STANDARD TABLE OF y_t001,
           wa_t001 TYPE y_t001.
    DATA : it_adrc TYPE STANDARD TABLE OF y_adrc,
            wa_adrc type  y_adrc.
    DATA : it_adrc1 TYPE STANDARD TABLE OF y_adrc1,
           wa_adrc1 TYPE y_adrc1.
    DATA : it_knb1 TYPE STANDARD TABLE OF y_knb1,
           wa_knb1 TYPE y_knb1.
    DATA : it_kna1 TYPE STANDARD TABLE OF y_kna1,
           wa_kna1 TYPE y_kna1.
    DATA : it_knkk TYPE STANDARD TABLE OF y_knkk,
           wa_knkk TYPE y_knkk.
    DATA : it_knkk1 TYPE STANDARD TABLE OF y_knkk1,
           wa_knkk1 TYPE y_knkk1.
    DATA : it_t001s TYPE STANDARD TABLE OF y_t001s,
           wa_t001s TYPE y_t001s.
    *DATA STATEMENTS FOR EMAIL ADDRESSES
    DATA : it_adrt TYPE TABLE OF y_adrt,
           wa_adrt TYPE y_adrt,
           wa_email LIKE t_email.
    *DATA : it_adr6 TYPE TABLE OF y_adr6,
          wa_adr6 TYPE y_adr6,
    DATA : counter TYPE i,
           counter1 TYPE i,
           c5 LIKE spell.
    SELECTION-SCREEN BEGIN OF BLOCK clcn WITH FRAME TITLE text-200.
    SELECTION-SCREEN SKIP.
    PARAMETERS:     p_bukrs LIKE t001-bukrs OBLIGATORY,                    "COMPANY CODE
                    p_kkber LIKE t001-kkber OBLIGATORY.                    "CREDIT CONTROL AREA
    SELECT-OPTIONS: s_kunnr FOR knb1-kunnr OBLIGATORY,                     "CUSTOMER NUMBER
                    s_datum FOR sy-datum OBLIGATORY DEFAULT sy-datum.      "DATE OF CREDIT LIMIT UPDATE
    SELECTION-SCREEN SKIP.
    PARAMETERS : p_simul AS CHECKBOX DEFAULT 'X'.                          "RUN IN SIMULATION MODE
    SELECTION-SCREEN SKIP.
    PARAMETERS : p_lemail LIKE adr6-smtp_addr.                             " EMAIL
    SELECTION-SCREEN END OF BLOCK clcn.
    AT SELECTION-SCREEN.
      PERFORM f0100_validate_bukrs.  "*  For Company Code.
      PERFORM f0200_validate_kkber.  "* For Credit Control Area.
      PERFORM f0300_validate_kunnr.  "* For Customer Number
      PERFORM f0400_validate_datum.  "* For Date of Credit Limit Update
      PERFORM f0500_validate_simul.  "* For simulation mode and e-mail address
    *======================================================================
    START-OF-SELECTION.
      PERFORM f1000_get_customer.          "** COLLECT INFO FOR REPORT DISPLAY
      IF p_simul is initial AND NOT P_lemail IS INITIAL.
        PERFORM F1000_CHECK_GATEWAY_CONNECTION.
      ENDIF.
      IF p_simul IS INITIAL AND  NOT p_lemail IS INITIAL.
        PERFORM f3000_process_data_script USING t_report_display.
      ENDIF.
    END-OF-SELECTION.
      IF NOT p_simul IS INITIAL.
        PERFORM f2000_display_customer USING t_report_display.
      ENDIF.
    FORM f0100_validate_bukrs.
      DATA : w_bukrs TYPE bukrs.
    VALIDATION OF P_BUKRS
      SELECT SINGLE bukrs
                    FROM t001
                    INTO w_bukrs
                    WHERE bukrs EQ p_bukrs.
      IF sy-subrc NE 0.
        MESSAGE e999(zf) WITH 'Invalid Company Code' p_bukrs.   "(E01).
    *AUTHORIZATION CHECK
        AUTHORITY-CHECK OBJECT 'F_BKPF_BUK'
                            ID 'BUKRS' FIELD p_bukrs
                            ID 'ACTVT' FIELD '03'.
        IF sy-subrc NE 0.
          MESSAGE e999(zf)  WITH 'No Authorization for company code' p_bukrs."(e06).
        ENDIF.
      ENDIF.
    ENDFORM.                    " F0100_VALIDATE_BUKRS
    *Eject
    *&      Form  F0200_VALIDATE_KKBER
         *-> CREDIT CONTROL AREA AUTHORITY CHECK
    FOR CREDIT CONTROL AREA.
    FORM f0200_validate_kkber.
      DATA : w_kkber LIKE t001-kkber.
      SELECT SINGLE kkber
              FROM t001
              INTO w_kkber
              WHERE bukrs EQ p_bukrs
                AND   kkber EQ p_kkber.
      IF sy-subrc NE 0.
        MESSAGE e999(zf) WITH
       'Credit Control Area' p_kkber 'not defined for Company Code' p_bukrs."(e02).
       MESSAGE e999 WITH text-e02 p_kkber .
      ENDIF.
    ENDFORM.                    "F0200_VALIDATE_KKBER
    *&      Form  F0300_VALIDATE_KUNNR
         *-> CUSTOMER NUMBER AUTHORITY CHECK
    FORM f0300_validate_kunnr.
    VALIDATION OF S_KUNNR
      DATA : w_kunnr TYPE kunnr,
             w_bukrs TYPE bukrs.
      IF s_kunnr IS INITIAL .
        MESSAGE e999 WITH 'Enter Customer Number'(e04).
        SUBMIT (sy-cprog) VIA SELECTION-SCREEN.
      ENDIF.
      LOOP AT s_kunnr.
        CLEAR : w_kunnr,
                w_bukrs.
        IF NOT s_kunnr-low IS INITIAL.
          SELECT SINGLE kunnr bukrs
          FROM knb1 INTO (w_kunnr ,w_bukrs)
          WHERE kunnr EQ s_kunnr-low
          AND bukrs EQ p_bukrs.
          IF sy-subrc NE 0.
            MESSAGE e999(zf)  WITH 'Customer S_KUNNR-LOW not defined in company code' p_bukrs."(e03).
          ENDIF.
        ENDIF. "if not s_kunnr-low is initial.
        IF NOT s_kunnr-high IS INITIAL.
          CLEAR : w_kunnr,
                  w_bukrs.
          SELECT SINGLE kunnr bukrs
          FROM knb1 INTO (w_kunnr , w_bukrs)
          WHERE kunnr EQ s_kunnr-high
          AND bukrs EQ p_bukrs.
          IF sy-subrc NE 0.
            MESSAGE e999(zf)  WITH 'Customer S_KUNNR-HIGH not defined in company code' p_bukrs."(e03).
          ENDIF.
        ENDIF. "if not s_kunnr-high is initial.
      ENDLOOP. " loop at s_kunnr
    ENDFORM.                    " F0200_VALIDATE_KUNNR
    *&      Form  F0400_VALIDATE_DATUM
         *-> DATE OF CREDIT LIMIT UPDATE
    FORM f0400_validate_datum.
      IF s_kunnr IS INITIAL AND s_datum IS INITIAL.
        MESSAGE e999 WITH 'Enter either Date of CL update or Customer number.'(e04).
      ENDIF.
    ENDFORM.                    "F0400_VALIDATE_DATUM
    *&      Form  F1000_GET_CUSTOMER
          text
    -->  p1        text
    <--  p2        text
    FORM f1000_get_customer .
      DATA : w_kunnr LIKE knkk-kunnr,
               w_kkber LIKE knkk-kkber.
      IF s_datum IS NOT INITIAL.
        SELECT objectid
               FROM cdhdr
               INTO TABLE t_cust
               WHERE  objectclas IN ('KLIM','DTREV','NXTRV')
               AND  change_ind IN ('U','I')
               AND udate IN s_datum.
              WHERE ( objectclas EQ 'KLIM' OR objectclas EQ 'DTREV' OR  objectclas EQ 'NXTRV')
              AND  ( change_ind EQ 'U' OR change_ind EQ 'I')
              AND udate IN s_datum .
      ENDIF.
      IF sy-subrc NE 0.
        MESSAGE s999 WITH 'There is no data for selected period'(e07).
      ELSE.
        MOVE t_cust TO t_customer.
      ENDIF.
      SORT t_customer BY kunnr.
      IF NOT t_customer[] IS INITIAL.
        SELECT kunnr
               kkber
               dtrev
               nxtrv
               klimk
               dbwae
               FROM knkk
               INTO TABLE t_knkk
               FOR ALL ENTRIES IN t_customer
               WHERE kunnr = t_customer-kunnr
               AND   kkber = p_kkber.
      ELSE.
        MESSAGE e999 WITH text-e07.
      ENDIF.
      IF sy-subrc NE 0.
      ENDIF.
      SORT t_knkk BY kunnr kkber.
      IF NOT t_knkk[] IS INITIAL.
        SELECT   kunnr
                 name1
        FROM kna1
        INTO TABLE t_custo
        FOR ALL ENTRIES IN t_knkk
        WHERE kunnr = t_knkk-kunnr.
      ENDIF.
      IF sy-subrc = 0.
      ENDIF.
      SORT t_custo BY kunnr kkber.
      LOOP AT t_custo INTO w_custo.
        CLEAR w_knkk.
        READ TABLE t_knkk INTO w_knkk WITH KEY kunnr = w_custo-kunnr
                                      BINARY SEARCH.
        IF sy-subrc = 0.
          w_report_display-kunnr = w_custo-kunnr.
          w_report_display-name  = w_custo-name.
          w_report_display-dtrev = w_knkk-dtrev.
          w_report_display-nxtrv = w_knkk-nxtrv.
          w_report_display-klimk = w_knkk-klimk.
          w_report_display-dbwae = w_knkk-dbwae.
          APPEND w_report_display TO t_report_display .
        ENDIF.
      ENDLOOP.
    ENDFORM.                    " F1000_GET_CUSTOMER
    *&      Form  F2000_DISPLAY_CUSTOMER
          text
         -->P_T_REPORT_DISPLAY  text
    FORM f2000_display_customer  USING    p_t_report_display.
      DATA: no  TYPE n  VALUE 1.
      DATA: t_data TYPE STANDARD TABLE OF y_report_display.
      t_data = p_t_report_display.
      DATA : w_data LIKE LINE OF t_data .
      ULINE (118).
      WRITE:/ sy-vline,
              8 'CREDIT LIMIT CHANGE NOTIFICATION REPORT ON',
              sy-datum , 118 sy-vline.
      ULINE (118).
      WRITE:/ sy-vline,'NO'(008) ,
            10 sy-vline, 11 'CUSTOMER NUMBER',
            28 sy-vline, 29 'CUSTOMER NAME', 43 sy-vline,
            44 'CREDIT LIMIT VALID', 63 sy-vline ,
            64 'CREDIT LIMIT AMOUNT', 85 sy-vline, 86 'CURRENCY',
            95 sy-vline , 96 'Notification Status',118 sy-vline.
      ULINE (118).
      WRITE:/ sy-vline,43 sy-vline, 44 'FROM', 53 sy-vline,
      56 'TILL', 63 sy-vline, 118 sy-vline .
      ULINE (118).
      LOOP AT t_data INTO w_data.
        WRITE:/ sy-vline, no,
              10 sy-vline, 11 w_data-kunnr ,
              28 sy-vline, 29 w_data-name, 43 sy-vline, 44 w_data-dtrev,
              53 sy-vline, 56 w_data-nxtrv ,63 sy-vline ,64 w_data-klimk,
              85 sy-vline, 86 w_data-dbwae,
              95 sy-vline , 118 sy-vline.
        no = no + 1.
        ULINE (118).
      ENDLOOP.
    ENDFORM.                    " F2000_DISPLAY_CUSTOMER
    *&      Form  F3000_PROCESS_DATA_SCRIPT
          text
         -->P_T_REPORT_DISPLAY  text
    FORM f3000_process_data_script  USING    p_t_report_display.
      DATA: t_data TYPE STANDARD TABLE OF y_report_display.
      t_data = p_t_report_display.
      DATA : w_data LIKE LINE OF t_data .
      DATA: temp_is_negative(1) TYPE c,
               temp_text(20)       TYPE c,
               temp_sname          LIKE t001s-sname,
               temp_email          LIKE adr6-smtp_addr.
      DATA : number LIKE spell,
             amount(255) TYPE c.
      PERFORM f3100_initialize_settings.
      LOOP AT t_data INTO w_data.
        AT NEW kunnr.
          CLEAR w_error_found.
          IF p_simul IS INITIAL AND  NOT p_lemail IS INITIAL.
            PERFORM f3300_open_form.
           data:  wa_t001 like line of t001
            DATA : begin of wa_t001,
                   adrnr like t001-adrnr,
                   end of wa_t001.
            SELECT SINGLE
                   adrnr FROM t001 INTO wa_t001
                   WHERE bukrs = p_bukrs.
          DATA: BEGIN OF wa_adrc,
                 addrnumber LIKE adrc-addrnumber,
                 name1 LIKE adrc-name1,
                 post_code1 LIKE adrc-post_code1,
                 city1 LIKE adrc-city1,
                 street LIKE adrc-street,
                 house_num1 LIKE adrc-house_num1,
                 tel_number LIKE adrc-tel_number,
                 nation LIKE adrc-nation ,
                 fax_number LIKE adrc-fax_number,
                 country LIKE adrc-country,
               END OF wa_adrc.
       SELECT SINGLE
                addrnumber
                name1
                post_code1
                city1
                street
                house_num1
                tel_number
                nation
                fax_number
                country
                FROM adrc
                INTO corresponding fields of wa_adrc
                WHERE addrnumber EQ wa_t001-adrnr  AND
                      nation EQ ' '.
            PERFORM f3700_write_form.
            DATA: wa_kna1 LIKE LINE OF t_kna1,
                  wa_adrcc LIKE LINE OF it_adrc.
            SELECT SINGLE
                   kunnr
                   adrnr FROM kna1
                   INTO  wa_kna1
                   WHERE kunnr = w_data-kunnr.
            IF sy-subrc EQ 0.
              SELECT SINGLE
                     addrnumber
                     name1
                     FROM adrc
                     INTO wa_adrcc
                     WHERE addrnumber = wa_kna1-adrnr
                     AND nation = ' '.
            ENDIF.
            PERFORM f3701_write_form.
            DATA : wa_knkk LIKE LINE OF t_knkk.
            DATA : counter TYPE i,
                   counter1 TYPE i.
            IF sy-subrc EQ 0.
          SELECT SINGLE KUNNR
                 DTREV
                 NXTRV
                 KLIMK  FROM KNKK INTO WA_KNKK WHERE
                 KUNNR EQ W_DATA-KUNNR.
            ENDIF.
            CALL FUNCTION 'SPELL_AMOUNT'
             EXPORTING
               amount          = w_knkk-klimk
       CURRENCY        = ' '
       FILLER          = ' '
               language        = sy-langu
             IMPORTING
               in_words        = number.
            IF sy-subrc <> 0.
      MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
            ENDIF.
            amount = number-word.
            PERFORM f3702_write_form.
            DATA: wa_knb1 LIKE LINE OF t_knb1.
            IF sy-subrc EQ 0.
              SELECT SINGLE
                     busab
                     FROM   knb1
                     INTO   wa_knb1
                     WHERE  kunnr = w_data-kunnr
                     AND    bukrs = p_bukrs.
            ENDIF.
            DATA : wa_t001s LIKE LINE OF it_t001s.
            IF sy-subrc EQ 0.
              SELECT SINGLE bukrs
                 busab
                 sname
                 FROM t001s
                 INTO wa_t001s
                 WHERE bukrs = wa_knb1-bukrs
                 AND busab = wa_knb1-busab.
            ENDIF.
            PERFORM f3703_write_form.
            PERFORM f3704_write_form.
            IF counter1 < counter.
              PERFORM f3705_write_form.
            ENDIF.
            PERFORM f3706_close_form.
          ENDIF.
        ENDAT.
        IF w_error_found EQ c_true.
        ENDIF.
        AT END OF kunnr.
    PERFORM F3400_WRITE_FORM USING C_TOTAL C_MAIN_WINDOW.
         PERFORM F3500_CLOSE_FORM.
          IF p_simul IS INITIAL AND  NOT p_lemail IS INITIAL.       "Email setting
            PERFORM f3200_get_email_addr USING w_data-kunnr.
            PERFORM f3600_send_data_via_email USING w_data-kunnr.
          ENDIF.
        ENDAT.
      ENDLOOP.
      WRITE:/ ' E-Mail is sent to the customer'.
    ENDFORM.                    " F3000_PROCESS_DATA_SCRIPT
    *&      Form  F3100_INITIALIZE_SETTINGS
          text
    -->  p1        text
    <--  p2        text
    FORM f3100_initialize_settings .
      SELECT SINGLE spld
            INTO itcpo-tddest
            FROM usr01
            WHERE bname EQ sy-uname.
      IF sy-subrc NE 0.
        itcpo-tddest = 'LOCAL'.
      ENDIF.
      w_htddevice      = c_printer.
      itcpo-tddest = ''.
      itcpo-tdrdidev = ''.
      itcpo-tdsenddate = sy-datum.
      itcpo-tdsendtime = sy-uzeit.
      itcpo-tdschedule = 'IMM'.
      itcpo-tdimmed = ' '.
    itcpo-tdnewid    = c_true.            "PRINT: New spool request
      itcpo-tdlifetime = c_1.               "PRINT: Spool retention period
      itcpo-tdgetotf   = c_true.
      IF p_simul IS INITIAL AND  NOT p_lemail IS INITIAL.       "Email setting
        itcpo-tdgetotf     = c_true.
      ENDIF.
    ENDFORM.                    " F3100_INITIALIZE_SETTINGS
    *&      Form  f0500_validate_simul
          text
    -->  p1        text
    <--  p2        text
    FORM f0500_validate_simul .
      IF p_simul IS INITIAL AND p_lemail IS INITIAL.       "Email setting
       MESSAGE e999(zf) WITH 'Enter Email address'.            "(e05).
      ENDIF.
    ENDFORM.                    " f0500_validate_simul
    *&      Form  F3600_SEND_DATA_VIA_EMAIL
          text
         -->P_W_DATA_KUNNR  text
    FORM f3600_send_data_via_email  USING p_w_data_kunnr.
      DATA:   fle1(2)       TYPE p,
              fle2(2)       TYPE p,
              off1          TYPE p,
              hltlines      TYPE i,
              temp_filesize TYPE i,
              hfeld(500)    TYPE c,
              header(50)   TYPE c,
              htabix        LIKE sy-tabix,
              x_sent_to_all LIKE sonv-flag.
      DATA: BEGIN OF x_objcont OCCURS 0.
              INCLUDE STRUCTURE soli.
              INCLUDE STRUCTURE SOLISTI1.
      DATA: END OF x_objcont.
      DATA: BEGIN OF x_object_hd_change.
              INCLUDE STRUCTURE sood1.
      DATA: END OF x_object_hd_change.
      DATA: BEGIN OF x_receivers OCCURS 0.
              INCLUDE STRUCTURE soos1.
             INCLUDE STRUCTURE SOMLRECI1.
      DATA: END OF x_receivers.
      DATA: BEGIN OF x_objhead OCCURS 1.
              INCLUDE STRUCTURE soli.
      DATA: END OF x_objhead.
    **Data: begin of objpack occurs 0.
             include structure SOPCKLSTI1.
    **Data: end of objpack.
    **Data: begin of email_data occurs 0.
             include structure SODOCCHGI1.
    **Data: end of email_data.
    Converts the layout set to PDF format
      CALL FUNCTION 'CONVERT_OTF'
        EXPORTING
          format                = c_pdf_format
        IMPORTING
          bin_filesize          = temp_filesize
        TABLES
          otf                   = t_otfdata
          lines                 = t_htline
        EXCEPTIONS
          err_max_linewidth     = 1
          err_format            = 2
          err_conv_not_possible = 3
          OTHERS                = 4.
      IF sy-subrc NE 0.
        w_error_found = c_true.
        t_error-kunnr = p_w_data_kunnr.
        t_error-comm  = 'Error in conversion to PDF format.'(e08).
        APPEND t_error.
        CLEAR t_error.
        EXIT.
      ENDIF.
    Convert the PDF file into an internal table which to be used in the
    function that will send a PDF file to a email address
      DESCRIBE TABLE t_htline LINES hltlines.
    DESCRIBE FIELD T_HTLINE LENGTH FLE1 IN BYTE MODE.
      DESCRIBE FIELD t_htline LENGTH fle1
                                  IN CHARACTER MODE.
    DESCRIBE FIELD X_OBJCONT LENGTH FLE2 IN BYTE MODE.
      DESCRIBE FIELD x_objcont LENGTH fle2
                                   IN CHARACTER MODE.
      CLEAR x_objcont.
      REFRESH x_objcont.
      LOOP AT t_htline.
        htabix = sy-tabix.
        MOVE t_htline TO hfeld+off1.
        IF htabix = hltlines.
          fle1 = STRLEN( t_htline ).
        ENDIF.
        off1 = off1 + fle1.
        IF off1 GE fle2.
          CLEAR x_objcont.
          x_objcont = hfeld(fle2).
          APPEND x_objcont.
          SHIFT hfeld BY fle2 PLACES.
          off1 = off1 - fle2.
        ENDIF.
        IF htabix = hltlines.
          IF off1 GT 0.
            CLEAR x_objcont.
            x_objcont = hfeld(off1).
            APPEND x_objcont.
          ENDIF.
        ENDIF.
      ENDLOOP.
    LOOP AT t_email.
       x_receivers-receiver = t_email-smtp_addr.
       x_receivers-rec_type = c_u.
       APPEND x_receivers.
    ENDLOOP.
    x_receivers-receiver = p_lemail.
    x_receivers-rec_type = c_u.
    APPEND x_receivers.
    DESCRIBE TABLE x_objcont LINES sy-tfill.
    READ TABLE x_objcont INDEX sy-tfill.
    email_data-doc_size = ( sy-tfill - 1 ) * 255 + STRLEN( x_objcont ).
    CLEAR objpack-transf_bin.
    objpack-head_start = 1.
    objpack-head_num = 0.
    objpack-body_start = 1.
    objpack-body_num = sy-tfill.
    objpack-doc_type = 'RAW'.
    APPEND objpack.
    email_data-obj_descr = 'Notification'.
    APPEND email_data.
    IF x_receivers[] IS NOT INITIAL.
       CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
         EXPORTING
           document_data = email_data
           put_in_outbox = 'X'
           commit_work   = 'X' "used from rel. 6.10
         TABLES
           packing_list  = objpack
           object_header = email_fname
           contents_bin  = email_text
           contents_txt  = x_objcont
           receivers     = x_receivers.
    endif.
      CLEAR x_objhead.
      REFRESH x_objhead.
      CLEAR x_object_hd_change.
      x_object_hd_change-objnam = 'EMAIL'(t04).
      header = 'Procter & Gamble'(t05).
      x_object_hd_change-objdes = header.                         "Title
      x_object_hd_change-objla = c_english.                       "Language
      x_object_hd_change-objsns = c_f.
      x_object_hd_change-objlen = temp_filesize.
      x_object_hd_change-file_ext = c_pdf_format.
    Transfer the email address to an internal table which will be used
    in the function that will send a PDF file to a email address
      CLEAR x_receivers.
      REFRESH x_receivers.
      LOOP AT t_email.
        x_receivers-sndex = c_true.
        x_receivers-sndpri = c_1.
        x_receivers-recesc = c_u.
        x_receivers-recnam = c_recipient_name.
    Populate the email address of the customer
        x_receivers-recextnam = t_email-smtp_addr.
        x_receivers-recesc = c_english.
        x_receivers-sndart = c_int.
        APPEND x_receivers.
      ENDLOOP.
      x_receivers-sndex = c_true.
      x_receivers-sndpri = c_1.
      x_receivers-recesc = c_u.
      x_receivers-recnam = c_recipient_name.
    Populate the Local mail address
      x_receivers-recextnam = p_lemail.
      x_receivers-recesc = c_english.
      x_receivers-sndart = c_int.
      APPEND x_receivers.
    Calling a SAP function to send out email with attachment of PDF file
      CALL FUNCTION 'SO_OBJECT_SEND'
        EXPORTING
          object_hd_change           = x_object_hd_change
          object_type                = c_document_type
          outbox_flag                = c_true
        IMPORTING
          sent_to_all                = x_sent_to_all
        TABLES
          objcont                    = x_objcont
          objhead                    = x_objhead
          receivers                  = x_receivers
        EXCEPTIONS
          active_user_not_exist      = 1
          communication_failure      = 2
          component_not_available    = 3
          folder_not_exist           = 4
          folder_no_authorization    = 5
          forwarder_not_exist        = 6
          note_not_exist             = 7
          object_not_exist           = 8
          object_not_sent            = 9
          object_no_authorization    = 10
          object_type_not_exist      = 11
          operation_no_authorization = 12
          owner_not_exist            = 13
          parameter_error            = 14
          substitute_not_active      = 15
          substitute_not_defined     = 16
          system_failure             = 17
          too_much_receivers         = 18
          user_not_exist             = 19
          x_error                    = 20
          OTHERS                     = 21.
      IF sy-subrc NE 0.
        w_error_found = c_true.
        t_error-kunnr = p_w_data_kunnr.
        t_error-comm  = 'Error in sending email.'(e09).
        APPEND t_error.
        CLEAR t_error.
      ELSEIF sy-subrc EQ 0.
        COMMIT WORK.
    *Transmit Mail
        SUBMIT rsconn01 WITH mode = c_int
        WITH output = c_space
        AND RETURN.
      ENDIF.
    ENDFORM.                    " F3600_SEND_DATA_VIA_EMAIL
    *&      Form  F3200_GET_EMAIL_ADDR
          text
         -->P_T_REPORT_DISPLAY  text
    FORM f3200_get_email_addr USING p_w_data_kunnr.
      REFRESH t_customer.
      REFRESH t_adrt.
      REFRESH t_email.
      DATA: t_data TYPE STANDARD TABLE OF y_report_display.
    t_data = p_t_report_display.
      DATA : w_data LIKE LINE OF t_data .

    Sending mail with attachment
    This program will allowed you to send email with attachment.
    First, specify the attachment file from your local hardisk and execute.
    Next, specify the sender email address and click the send button.
    report y_cr17_mail.
    data method1 like sy-ucomm.
    data g_user like soudnamei1.
    data g_user_data like soudatai1.
    data g_owner like soud-usrnam.
    data g_receipients like soos1 occurs 0 with header line.
    data g_document like sood4 .
    data g_header like sood2.
    data g_folmam like sofm2.
    data g_objcnt like soli occurs 0 with header line.
    data g_objhead like soli occurs 0 with header line.
    data g_objpara like selc occurs 0 with header line.
    data g_objparb like soop1 occurs 0 with header line.
    data g_attachments like sood5 occurs 0 with header line.
    data g_references like soxrl occurs 0 with header line.
    data g_authority like sofa-usracc.
    data g_ref_document like sood4.
    data g_new_parent like soodk.
    data: begin of g_files occurs 10 ,
    text(4096) type c,
    end of g_files.
    data : fold_number(12) type c,
    fold_yr(2) type c,
    fold_type(3) type c.
    parameters ws_file(4096) type c default 'c:\debugger.txt'.
    Can me any file fromyour pc ....either xls or word or ppt etc ...
    g_user-sapname = sy-uname.
    call function 'SO_USER_READ_API1'
    exporting
    user = g_user
    PREPARE_FOR_FOLDER_ACCESS = ' '
    importing
    user_data = g_user_data
    EXCEPTIONS
    USER_NOT_EXIST = 1
    PARAMETER_ERROR = 2
    X_ERROR = 3
    OTHERS = 4
    if sy-subrc <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    endif.
    fold_type = g_user_data-outboxfol+0(3).
    fold_yr = g_user_data-outboxfol+3(2).
    fold_number = g_user_data-outboxfol+5(12).
    clear g_files.
    refresh : g_objcnt,
    g_objhead,
    g_objpara,
    g_objparb,
    g_receipients,
    g_attachments,
    g_references,
    g_files.
    method1 = 'SAVE'.
    g_document-foltp = fold_type.
    g_document-folyr = fold_yr.
    g_document-folno = fold_number.
    g_document-objtp = g_user_data-object_typ.
    *g_document-OBJYR = '27'.
    *g_document-OBJNO = '000000002365'.
    *g_document-OBJNAM = 'MESSAGE'.
    g_document-objdes = 'sap-img.com testing by program'.
    g_document-folrg = 'O'.
    *g_document-okcode = 'CHNG'.
    g_document-objlen = '0'.
    g_document-file_ext = 'TXT'.
    g_header-objdes = 'sap-img.com testing by program'.
    g_header-file_ext = 'TXT'.
    call function 'SO_DOCUMENT_REPOSITORY_MANAGER'
    exporting
    method = method1
    office_user = sy-uname
    ref_document = g_ref_document
    new_parent = g_new_parent
    importing
    authority = g_authority
    tables
    objcont = g_objcnt
    objhead = g_objhead
    objpara = g_objpara
    objparb = g_objparb
    recipients = g_receipients
    attachments = g_attachments
    references = g_references
    files = g_files
    changing
    document = g_document
    header_data = g_header
    FOLMEM_DATA =
    RECEIVE_DATA =
    File from the pc to send...
    method1 = 'ATTCREATEFROMPC'.
    g_files-text = ws_file.
    append g_files.
    call function 'SO_DOCUMENT_REPOSITORY_MANAGER'
    exporting
    method = method1
    office_user = g_owner
    ref_document = g_ref_document
    new_parent = g_new_parent
    importing
    authority = g_authority
    tables
    objcont = g_objcnt
    objhead = g_objhead
    objpara = g_objpara
    objparb = g_objparb
    recipients = g_receipients
    attachments = g_attachments
    references = g_references
    files = g_files
    changing
    document = g_document
    header_data = g_header
    method1 = 'SEND'.
    g_receipients-recnam = 'MK085'.
    g_receipients-recesc = 'B'.
    g_receipients-sndex = 'X'.
    append g_receipients.
    call function 'SO_DOCUMENT_REPOSITORY_MANAGER'
    exporting
    method = method1
    office_user = g_owner
    ref_document = g_ref_document
    new_parent = g_new_parent
    importing
    authority = g_authority
    tables
    objcont = g_objcnt
    objhead = g_objhead
    objpara = g_objpara
    objparb = g_objparb
    recipients = g_receipients
    attachments = g_attachments
    references = g_references
    files = g_files
    changing
    document = g_document
    header_data = g_header.
    *-- End of Program
    also try this one for background scheduling the same
    Sending mail with attachment report in Background
    Pay attention because it’s working with output list from spool converted to pdf.
    =================================================================================
    z_send_email_fax_global
    FUNCTION-POOL z_gfaian_mail_fax. “MESSAGE-ID ..
    WORK TABLE AREAS
    TABLES: tsp01.
    INTERNAL TABLES
    DATA: lt_rec_tab LIKE STANDARD TABLE OF soos1 WITH HEADER LINE,
    lt_note_text LIKE STANDARD TABLE OF soli WITH HEADER LINE,
    lt_attachments LIKE STANDARD TABLE OF sood5 WITH HEADER LINE.
    DATA: lt_objcont LIKE STANDARD TABLE OF soli WITH HEADER LINE,
    lt_objhead LIKE STANDARD TABLE OF soli WITH HEADER LINE.
    DATA: pdf_format LIKE STANDARD TABLE OF tline WITH HEADER LINE.
    TYPES: BEGIN OF y_files,
    file(60) TYPE c,
    END OF y_files.
    DATA: lt_files TYPE STANDARD TABLE OF y_files WITH HEADER LINE.
    DATA: l_objcont LIKE soli OCCURS 0 WITH HEADER LINE.
    DATA: l_objhead LIKE soli OCCURS 0 WITH HEADER LINE.
    STRUCTURES
    DATA: folder_id LIKE soodk,
    object_id LIKE soodk,
    link_folder_id LIKE soodk,
    g_document LIKE sood4,
    g_header_data LIKE sood2,
    g_folmem_data LIKE sofm2,
    g_header_data LIKE sood2,
    g_receive_data LIKE soos6,
    g_ref_document LIKE sood4,
    g_new_parent LIKE soodk,
    l_folder_id LIKE sofdk,
    v_email(50).
    DATA: hd_dat like sood1.
    VARIABLES
    DATA: client LIKE tst01-dclient,
    name LIKE tst01-dname,
    objtype LIKE rststype-type,
    type LIKE rststype-type.
    DATA: numbytes TYPE i,
    arc_idx LIKE toa_dara,
    pdfspoolid LIKE tsp01-rqident,
    jobname LIKE tbtcjob-jobname,
    jobcount LIKE tbtcjob-jobcount,
    is_otf.
    DATA: outbox_flag LIKE sonv-flag VALUE ‘X’,
    store_flag LIKE sonv-flag,
    delete_flag LIKE sonv-flag,
    owner LIKE soud-usrnam,
    on LIKE sonv-flag VALUE ‘X’,
    sent_to_all LIKE sonv-flag,
    g_authority LIKE sofa-usracc,
    w_objdes LIKE sood4-objdes.
    DATA: c_file LIKE rlgrap-filename,
    n_spool(6) TYPE n.
    DATA: cancel.
    DATA: desired_type LIKE sood-objtp,
    real_type LIKE sood-objtp,
    attach_type LIKE sood-objtp,
    otf LIKE sood-objtp VALUE ‘OTF’, ” SAPscript Ausgabeformat
    ali LIKE sood-objtp VALUE ‘ALI’. ” ABAP lists
    CONSTANTS
    CONSTANTS: ou_fol LIKE sofh-folrg VALUE ‘O’,
    c_objtp LIKE g_document-objtp VALUE ‘RAW’,
    c_file_ext LIKE g_document-file_ext VALUE ‘TXT’.
    =================================================================================
    z_send_email_fax2
    FUNCTION z_faian_mail_fax2.
    ””Interface local:
    *” IMPORTING
    *” REFERENCE(SRC_SPOOLID) LIKE TSP01-RQIDENT
    *” REFERENCE(FAX_MAIL_NUMBER) TYPE SO_NAME
    *” REFERENCE(HEADER_MAIL) TYPE SO_OBJ_DES
    *” REFERENCE(OBJECT_TYPE) TYPE SO_ESCAPE
    *” TABLES
    *” LT_BODY_EMAIL STRUCTURE SOLI
    *” EXCEPTIONS
    *” ERR_NO_ABAP_SPOOLJOB
    Fist part: Verify if the spool really exists
    SELECT SINGLE * FROM tsp01 WHERE rqident = src_spoolid.
    IF sy-subrc NE 0.
    RAISE err_no_abap_spooljob. “doesn’t exist
    ELSE.
    client = tsp01-rqclient.
    name = tsp01-rqo1name.
    CALL FUNCTION ‘RSTS_GET_ATTRIBUTES’
    EXPORTING
    authority = ‘SP01&#8242;
    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
    OTHERS = 5.
    IF objtype(3) = ‘OTF’.
    desired_type = otf.
    ELSE.
    desired_type = ali.
    ENDIF.
    CALL FUNCTION ‘RSPO_RETURN_SPOOLJOB’
    EXPORTING
    rqident = src_spoolid
    desired_type = desired_type
    IMPORTING
    real_type = real_type
    TABLES
    buffer = l_objcont
    EXCEPTIONS
    no_such_job = 14
    type_no_match = 94
    job_contains_no_data = 54
    no_permission = 21
    can_not_access = 21
    read_error = 54.
    IF sy-subrc EQ 0.
    attach_type = real_type.
    ENDIF.
    CALL FUNCTION ‘SO_FOLDER_ROOT_ID_GET’
    EXPORTING
    owner = sy-uname
    region = ou_fol
    IMPORTING
    folder_id = l_folder_id
    EXCEPTIONS
    OTHERS = 5.
    fill out informations about the header of the email
    CLEAR: g_document.
    g_document-foltp = l_folder_id-foltp.
    g_document-folyr = l_folder_id-folyr.
    g_document-folno = l_folder_id-folno.
    g_document-objtp = c_objtp.
    g_document-objdes = header_mail.
    g_document-file_ext = c_file_ext.
    g_header_data-objdes = header_mail.
    CALL FUNCTION ‘SO_DOCUMENT_REPOSITORY_MANAGER’
    EXPORTING
    method = ‘SAVE’
    office_user = sy-uname
    IMPORTING
    authority = g_authority
    TABLES
    objcont = lt_body_email
    attachments = lt_attachments
    CHANGING
    document = g_document
    header_data = g_header_data
    EXCEPTIONS
    OTHERS = 1.
    folder_id-objtp = l_folder_id-foltp.
    folder_id-objyr = l_folder_id-folyr.
    folder_id-objno = l_folder_id-folno.
    object_id-objtp = c_objtp.
    object_id-objyr = g_document-objyr.
    object_id-objno = g_document-objno.
    link_folder_id-objtp = l_folder_id-foltp.
    link_folder_id-objyr = l_folder_id-folyr.
    link_folder_id-objno = l_folder_id-folno.
    REFRESH lt_rec_tab.
    CLEAR lt_rec_tab.
    lt_rec_tab-sel = ‘X’.
    lt_rec_tab-recesc = object_type. “This field for FAX/MAIL
    lt_rec_tab-recnam = ‘U-’.
    lt_rec_tab-deliver = ‘X’.
    lt_rec_tab-not_deli = ‘X’.
    lt_rec_tab-read = ‘X’.
    lt_rec_tab-mailstatus = ‘E’.
    lt_rec_tab-adr_name = fax_mail_number.
    lt_rec_tab-sortfield = fax_mail_number.
    lt_rec_tab-recextnam = fax_mail_number.
    lt_rec_tab-sortclass = ‘5&#8242;.
    APPEND lt_rec_tab.
    lt_rec_tab-recextnam = fax_mail_number.
    lt_rec_tab-recesc = object_type.
    lt_rec_tab-sndart = ‘INT’.
    lt_rec_tab-sndpri = 1.
    APPEND lt_rec_tab.
    lt_files-file = c_file.
    APPEND lt_files.
    begin of insertion by faianf01
    hd_dat-objdes = header_mail.
    CALL FUNCTION ‘SO_ATTACHMENT_INSERT’
    EXPORTING
    object_id = object_id
    attach_type = attach_type
    object_hd_change = hd_dat
    owner = sy-uname
    TABLES
    objcont = l_objcont
    objhead = l_objhead
    EXCEPTIONS
    active_user_not_exist = 35
    communication_failure = 71
    object_type_not_exist = 17
    operation_no_authorization = 21
    owner_not_exist = 22
    parameter_error = 23
    substitute_not_active = 31
    substitute_not_defined = 32
    system_failure = 72
    x_error = 1000.
    IF sy-subrc > 0.
    ENDIF.
    end of insertion by faianf01
    send email from SAPOFFICE
    CALL FUNCTION ‘SO_OBJECT_SEND’
    EXPORTING
    folder_id = folder_id
    object_id = object_id
    outbox_flag = outbox_flag
    link_folder_id = link_folder_id
    owner = sy-uname
    check_send_authority = ‘X’
    TABLES
    receivers = lt_rec_tab
    note_text = lt_note_text
    EXCEPTIONS
    active_user_not_exist = 35
    communication_failure = 71
    component_not_available = 1
    folder_no_authorization = 5
    folder_not_exist = 6
    forwarder_not_exist = 8
    object_no_authorization = 13
    object_not_exist = 14
    object_not_sent = 15
    operation_no_authorization = 21
    owner_not_exist = 22
    parameter_error = 23
    substitute_not_active = 31
    substitute_not_defined = 32
    system_failure = 72
    too_much_receivers = 73
    user_not_exist = 35.
    ENDIF.
    ENDFUNCTION.
    =================================================================================
    z_send_email_fax
    FUNCTION ZCBFS_SEND_MAIL.
    ””Interface local:
    *” IMPORTING
    *” REFERENCE(SRC_SPOOLID) LIKE TSP01-RQIDENT
    *” REFERENCE(HEADER_MAIL) TYPE SO_OBJ_DES
    *” TABLES
    *” LIST_FAX_MAIL_NUMBER STRUCTURE SOLI
    *” EXCEPTIONS
    *” ERR_NO_ABAP_SPOOLJOB
    DATA: vg_achou(1) TYPE n.
    Fist part: Verify if the spool really exists
    vg_achou = 1.
    DO 60 TIMES.
    SELECT SINGLE * FROM tsp01 WHERE rqident = src_spoolid.
    IF sy-subrc IS INITIAL.
    CLEAR vg_achou.
    EXIT.
    ELSE.
    WAIT UP TO 1 SECONDS.
    ENDIF.
    ENDDO.
    IF vg_achou = 1.
    RAISE err_no_abap_spooljob. “doesn’t exist
    ENDIF.
    client = tsp01-rqclient.
    name = tsp01-rqo1name.
    CALL FUNCTION ‘RSTS_GET_ATTRIBUTES’
    EXPORTING
    authority = ‘SP01&#8242;
    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
    OTHERS = 5.
    IF objtype(3) = ‘OTF’.
    desired_type = otf.
    ELSE.
    desired_type = ali.
    ENDIF.
    CALL FUNCTION ‘RSPO_RETURN_SPOOLJOB’
    EXPORTING
    rqident = src_spoolid
    desired_type = desired_type
    IMPORTING
    real_type = real_type
    TABLES
    buffer = l_objcont
    EXCEPTIONS
    no_such_job = 14
    type_no_match = 94
    job_contains_no_data = 54
    no_permission = 21
    can_not_access = 21
    read_error = 54.
    IF sy-subrc EQ 0.
    attach_type = real_type.
    ENDIF.
    CALL FUNCTION ‘SO_FOLDER_ROOT_ID_GET’
    EXPORTING
    owner = sy-uname
    region = ou_fol
    IMPORTING
    folder_id = l_folder_id
    EXCEPTIONS
    OTHERS = 5.
    fill out informations about the header of the email
    CLEAR: g_document.
    g_document-foltp = l_folder_id-foltp.
    g_document-folyr = l_folder_id-folyr.
    g_document-folno = l_folder_id-folno.
    g_document-objtp = c_objtp.
    g_document-objdes = header_mail.
    g_document-file_ext = c_file_ext.
    g_header_data-objdes = header_mail.
    CALL FUNCTION ‘SO_DOCUMENT_REPOSITORY_MANAGER’
    EXPORTING
    method = ‘SAVE’
    office_user = sy-uname
    IMPORTING
    authority = g_authority
    TABLES
    attachments = lt_attachments
    CHANGING
    document = g_document
    header_data = g_header_data
    EXCEPTIONS
    OTHERS = 1.
    folder_id-objtp = l_folder_id-foltp.
    folder_id-objyr = l_folder_id-folyr.
    folder_id-objno = l_folder_id-folno.
    object_id-objtp = c_objtp.
    object_id-objyr = g_document-objyr.
    object_id-objno = g_document-objno.
    link_folder_id-objtp = l_folder_id-foltp.
    link_folder_id-objyr = l_folder_id-folyr.
    link_folder_id-objno = l_folder_id-folno.
    REFRESH lt_rec_tab.
    LOOP AT LIST_FAX_MAIL_NUMBER.
    lt_rec_tab-recextnam = LIST_FAX_MAIL_NUMBER-LINE.
    lt_rec_tab-recesc = ‘U’.
    lt_rec_tab-sndart = ‘INT’.
    lt_rec_tab-sndpri = 1.
    APPEND lt_rec_tab.
    ENDLOOP.
    lt_files-file = c_file.
    APPEND lt_files.
    hd_dat-objdes = header_mail.
    CALL FUNCTION ‘SO_ATTACHMENT_INSERT’
    EXPORTING
    object_id = object_id
    attach_type = attach_type
    object_hd_change = hd_dat
    owner = sy-uname
    TABLES
    objcont = l_objcont
    objhead = l_objhead
    EXCEPTIONS
    active_user_not_exist = 35
    communication_failure = 71
    object_type_not_exist = 17
    operation_no_authorization = 21
    owner_not_exist = 22
    parameter_error = 23
    substitute_not_active = 31
    substitute_not_defined = 32
    system_failure = 72
    x_error = 1000.
    IF sy-subrc > 0.
    ENDIF.
    send email from SAPOFFICE
    CALL FUNCTION ‘SO_OBJECT_SEND’
    EXPORTING
    folder_id = folder_id
    object_id = object_id
    outbox_flag = outbox_flag
    link_folder_id = link_folder_id
    owner = sy-uname
    TABLES
    receivers = lt_rec_tab
    note_text = lt_note_text
    EXCEPTIONS
    active_user_not_exist = 35
    communication_failure = 71
    component_not_available = 1
    folder_no_authorization = 5
    folder_not_exist = 6
    forwarder_not_exist = 8
    object_no_authorization = 13
    object_not_exist = 14
    object_not_sent = 15
    operation_no_authorization = 21
    owner_not_exist = 22
    parameter_error = 23
    substitute_not_active = 31
    substitute_not_defined = 32
    system_failure = 72
    too_much_receivers = 73
    user_not_exist = 35.
    ENDFUNCTION.
    regards,
    srinivas
    <b>*reward for useful answers*</b>

  • Smartform to convert as pdf attachment and sending mail.

    Program to convert smartform as PDF and send PDF as an atachment to email id.
    ********Variable Declarations ****************************
    DATA: gv_form_name TYPE rs38l_fnam, " Used to store the function module generated by Smartform
    gv_bin_filesize TYPE i, " Store the file size
    gv_pos TYPE i,
    gv_len TYPE i,
    gv_tab_lines TYPE i.
    *******Constants ******************************************
    DATA : gc_text(11) TYPE c VALUE 'Form Output',
    gc_tst(3) TYPE c VALUE 'TST',
    gc_testing(7) TYPE c VALUE 'Testing'.
    CONSTANTS : c_formname           TYPE tdsfname VALUE 'ZSMART_T'.     "Zsmart_t is the smartform name.
    ********Work Area Declarations ****************************
    DATA: gs_docdata TYPE sodocchgi1, " Data of an object which can be changed
    gs_ctrlop TYPE ssfctrlop, " Smart Forms: Control structure
    gs_outopt TYPE ssfcompop, " SAP Smart Forms: Smart Composer (transfer) options
    gs_otfdata TYPE ssfcrescl, " Smart Forms: Return value at end of form printing
    gs_reclist TYPE somlreci1, " SAPoffice: Structure of the API Recipient List
    gs_pdf_tab TYPE tline, " Workarea for SAP Script Text Lines
    gs_objbin TYPE solisti1, " SAPoffice: Single List with Column Length 255
    gs_objpack TYPE sopcklsti1. " SAPoffice: Description of Imported Object Components
    ********Internal tables Declarations ****************************
    DATA: gt_reclist TYPE TABLE OF somlreci1, " SAPoffice: Structure of the API Recipient List
    gt_pdf_tab TYPE TABLE OF tline, " SAPscript: Text Lines
    gt_otf TYPE TABLE OF itcoo, " OTF Structure
    gt_objbin TYPE TABLE OF solisti1, " SAPoffice: Single List with Column Length 255
    gt_objpack TYPE TABLE OF sopcklsti1. " SAPoffice: Description of Imported Object Components
    DATA: customer TYPE scustom,
          bookings TYPE ty_bookings,
          connections TYPE ty_connections.
    CLEAR : gv_form_name,
    gs_ctrlop,
    gs_outopt,
    gs_otfdata,
    gv_bin_filesize,
    gv_pos,
    gv_len,
    gv_tab_lines.
    START-OF-SELECTION.
    Generate Function Module name
      CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
        EXPORTING
          formname           = c_formname
        IMPORTING
          fm_name            = gv_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.
    Assigning values to Form Control Structure and Form Composer
      gs_ctrlop-getotf = 'X'.
      gs_ctrlop-device = 'PRINTER'.
      gs_ctrlop-preview = ''.
      gs_ctrlop-no_dialog = 'X'.
      gs_outopt-tddest = 'LP01'.  "or  'LOCL'.
    Getting the OTFDATA
      CALL FUNCTION gv_form_name
        EXPORTING
          control_parameters = gs_ctrlop
          output_options     = gs_outopt
          user_settings      = ' '
          customer           = customer
          bookings           = bookings
          connections        = connections
        IMPORTING
          job_output_info    = gs_otfdata
        EXCEPTIONS
          formatting_error   = 1
          internal_error     = 2
          send_error         = 3
          user_canceled      = 4.
      IF sy-subrc <> 0.
        MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
        WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
      ENDIF.
    Assigning the OTFDATA to OTF Structure table
      CLEAR gt_otf.
      gt_otf[] = gs_otfdata-otfdata[].
    Convert the OTF DATA to SAP Script Text lines
      CLEAR gt_pdf_tab.
      CALL FUNCTION 'CONVERT_OTF'
        EXPORTING
          format                = 'PDF'
          max_linewidth         = 132
        IMPORTING
          bin_filesize          = gv_bin_filesize
        TABLES
          otf                   = gt_otf
          lines                 = gt_pdf_tab
        EXCEPTIONS
          err_max_linewidth     = 1
          err_format            = 2
          err_conv_not_possible = 3
          OTHERS                = 4.
      IF sy-subrc <> 0.
        MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
        WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
      ENDIF.
    Assigning the Description of the object sent in the mail
      CLEAR gs_docdata.
      gs_docdata-obj_name = gc_tst.
      gs_docdata-obj_descr = gc_testing.
    Assigning the email id to Structure of the API Recipient List table
      CLEAR : gt_reclist, gs_reclist.
    IF internal mail id
    gs_reclist-receiver = sy-uname.
    GS_RECLIST-REC_TYPE = 'B'.
    if external mail id
      gs_reclist-receiver = mailid.com'.
      gs_reclist-rec_type = 'U'.
      APPEND gs_reclist TO gt_reclist.
    Passing the SAP Script text lines to SAPoffice: Single List with Column Length 255 table
      CLEAR : gs_objbin, gs_pdf_tab.
      LOOP AT gt_pdf_tab INTO gs_pdf_tab.
        gv_pos = 255 - gv_len.
        IF gv_pos > 134. "length of pdf_table
          gv_pos = 134.
        ENDIF.
        gs_objbin+gv_len = gs_pdf_tab(gv_pos).
        gv_len = gv_len + gv_pos.
        IF gv_len = 255. "length of out (contents_bin)
          APPEND gs_objbin TO gt_objbin.
          CLEAR: gs_objbin, gv_len.
          IF gv_pos < 134.
            gs_objbin = gs_pdf_tab+gv_pos.
            gv_len = 134 - gv_pos.
          ENDIF.
        ENDIF.
      ENDLOOP.
      IF gv_len > 0.
        APPEND gs_objbin TO gt_objbin.
      ENDIF.
    Filling the details in SAPoffice: Description of Imported Object Components table
      DESCRIBE TABLE gt_objbin LINES gv_tab_lines.
      CLEAR gs_objbin.
      READ TABLE gt_objbin INTO gs_objbin INDEX gv_tab_lines.
      IF sy-subrc = 0.
        gs_objpack-doc_size = ( gv_tab_lines - 1 ) * 255 + STRLEN( gs_objbin ).
        gs_objpack-transf_bin = 'X'.
        gs_objpack-head_start = 1.
        gs_objpack-head_num = 0.
        gs_objpack-body_start = 1.
        gs_objpack-body_num = gv_tab_lines.
        gs_objpack-doc_type = 'PDF'.
        gs_objpack-obj_name = 'ATTACHMENT'.
        gs_objpack-obj_descr = 'test'.
        APPEND gs_objpack TO gt_objpack.
      ENDIF.
    Sending the Form Output in the PDF format to email
      CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
        EXPORTING
          document_data              = gs_docdata
          put_in_outbox              = 'X'
          commit_work                = 'X'
        TABLES
          packing_list               = gt_objpack
          contents_bin               = gt_objbin
          receivers                  = gt_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.
        MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
        WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
      ELSE.
        WRITE 'Sent Successfully'.
      ENDIF.
      SUBMIT rsconn01
      WITH mode EQ 'INT'
      AND RETURN.
    END-OF-SELECTION.

    Hi
    Use function modules
              CALL FUNCTION 'CONVERT_OTF'
    and  CALL FUNCTION 'SX_TABLE_LINE_WIDTH_CHANGE'  to convert as a pdf document
    for sending mail  CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
    Regards,
    Gopi

  • Convert internal table data to pdf format and send mail to Users

    Hi all ,
    I want to convert the data available in internal table to pdf format and then send it to mail .
    Please tell me wht are the fn modules available to convert the data from internal table to pdf and then send it mail .
    regards
    santosh .

    Hi Santosh
    Sending mail with attachment report in Background
    Content Author: Fernando Faian
    I have read the hint about "Sending mail with attachment report".
    It's great, but how can I make this function work in background??
    I had that needed last year too. See attachment a function group with two functions. The second one has that functionality to send email or fax (SAP office) with attachment objects in background job using SO_ATTACHMENT_INSERT function. 
    Pay attention because it’s working with output list from spool converted to pdf. 
    =================================================================================
    z_send_email_fax_global
    FUNCTION-POOL z_gfaian_mail_fax.            "MESSAGE-ID ..
    WORK TABLE AREAS
    TABLES: tsp01.
    INTERNAL TABLES
    DATA: lt_rec_tab LIKE STANDARD TABLE OF soos1 WITH HEADER LINE,
          lt_note_text   LIKE STANDARD TABLE OF soli  WITH HEADER LINE,
          lt_attachments LIKE STANDARD TABLE OF sood5 WITH HEADER LINE.
    DATA: lt_objcont LIKE STANDARD TABLE OF soli WITH HEADER LINE,
          lt_objhead LIKE STANDARD TABLE OF soli WITH HEADER LINE.
    DATA: pdf_format LIKE STANDARD TABLE OF tline WITH HEADER LINE.
    TYPES: BEGIN OF y_files,
           file(60) TYPE c,
           END OF y_files.
    DATA: lt_files TYPE STANDARD TABLE OF y_files WITH HEADER LINE.
    DATA: l_objcont     LIKE soli OCCURS 0 WITH HEADER LINE.
    DATA: l_objhead     LIKE soli OCCURS 0 WITH HEADER LINE.
    STRUCTURES
    DATA: folder_id      LIKE soodk,
          object_id      LIKE soodk,
          link_folder_id LIKE soodk,
          g_document     LIKE sood4,
         g_header_data  LIKE sood2,
          g_folmem_data  LIKE sofm2,
          g_header_data  LIKE sood2,
          g_receive_data LIKE soos6,
          g_ref_document LIKE sood4,
          g_new_parent   LIKE soodk,
          l_folder_id    LIKE sofdk,
          v_email(50).
    DATA: hd_dat  like sood1.
    VARIABLES
    DATA: client  LIKE tst01-dclient,
          name    LIKE tst01-dname,
          objtype LIKE rststype-type,
          type    LIKE rststype-type.
    DATA: numbytes TYPE i,
          arc_idx LIKE toa_dara,
          pdfspoolid LIKE tsp01-rqident,
          jobname LIKE tbtcjob-jobname,
          jobcount LIKE tbtcjob-jobcount,
          is_otf.
    DATA: outbox_flag LIKE sonv-flag VALUE 'X',
          store_flag  LIKE sonv-flag,
          delete_flag LIKE sonv-flag,
          owner       LIKE soud-usrnam,
          on          LIKE sonv-flag VALUE 'X',
          sent_to_all LIKE sonv-flag,
          g_authority LIKE sofa-usracc,
          w_objdes    LIKE sood4-objdes.
    DATA: c_file LIKE rlgrap-filename,
          n_spool(6) TYPE n.
    DATA: cancel.
    DATA: desired_type  LIKE sood-objtp,
          real_type LIKE sood-objtp,
          attach_type LIKE sood-objtp,
          otf LIKE sood-objtp VALUE 'OTF', " SAPscript Ausgabeformat
          ali LIKE sood-objtp VALUE 'ALI'. " ABAP lists
    CONSTANTS
    CONSTANTS: ou_fol LIKE sofh-folrg              VALUE 'O',
               c_objtp    LIKE g_document-objtp    VALUE 'RAW',
               c_file_ext LIKE g_document-file_ext VALUE 'TXT'.
    =================================================================================
    z_send_email_fax2
    FUNCTION z_faian_mail_fax2.
    ""Interface local:
    *"  IMPORTING
    *"     REFERENCE(SRC_SPOOLID) LIKE  TSP01-RQIDENT
    *"     REFERENCE(FAX_MAIL_NUMBER) TYPE  SO_NAME
    *"     REFERENCE(HEADER_MAIL) TYPE  SO_OBJ_DES
    *"     REFERENCE(OBJECT_TYPE) TYPE  SO_ESCAPE
    *"  TABLES
    *"      LT_BODY_EMAIL STRUCTURE  SOLI
    *"  EXCEPTIONS
    *"      ERR_NO_ABAP_SPOOLJOB
    Fist part: Verify if the spool really exists
      SELECT SINGLE * FROM tsp01 WHERE rqident = src_spoolid.
      IF sy-subrc NE 0.
        RAISE err_no_abap_spooljob. "doesn't exist
      ELSE.
        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
                  OTHERS        = 5.
        IF objtype(3) = 'OTF'.
          desired_type = otf.
        ELSE.
          desired_type = ali.
        ENDIF.
        CALL FUNCTION 'RSPO_RETURN_SPOOLJOB'
             EXPORTING
                  rqident              = src_spoolid
                  desired_type         = desired_type
             IMPORTING
                  real_type            = real_type
             TABLES
                  buffer               = l_objcont
             EXCEPTIONS
                  no_such_job          = 14
                  type_no_match        = 94
                  job_contains_no_data = 54
                  no_permission        = 21
                  can_not_access       = 21
                  read_error           = 54.
        IF sy-subrc EQ 0.
          attach_type = real_type.
        ENDIF.
        CALL FUNCTION 'SO_FOLDER_ROOT_ID_GET'
             EXPORTING
                  owner     = sy-uname
                  region    = ou_fol
             IMPORTING
                  folder_id = l_folder_id
             EXCEPTIONS
                  OTHERS    = 5.
    fill out informations about the header of the email
        CLEAR: g_document.
        g_document-foltp     = l_folder_id-foltp.
        g_document-folyr     = l_folder_id-folyr.
        g_document-folno     = l_folder_id-folno.
        g_document-objtp     = c_objtp.
        g_document-objdes    = header_mail.
        g_document-file_ext  = c_file_ext.
        g_header_data-objdes    = header_mail.
        CALL FUNCTION 'SO_DOCUMENT_REPOSITORY_MANAGER'
             EXPORTING
                  method      = 'SAVE'
                  office_user = sy-uname
             IMPORTING
                  authority   = g_authority
             TABLES
                  objcont     = lt_body_email
                  attachments = lt_attachments
             CHANGING
                  document    = g_document
                  header_data = g_header_data
             EXCEPTIONS
                  OTHERS      = 1.
        folder_id-objtp = l_folder_id-foltp.
        folder_id-objyr = l_folder_id-folyr.
        folder_id-objno = l_folder_id-folno.
        object_id-objtp = c_objtp.
        object_id-objyr = g_document-objyr.
        object_id-objno = g_document-objno.
        link_folder_id-objtp = l_folder_id-foltp.
        link_folder_id-objyr = l_folder_id-folyr.
        link_folder_id-objno = l_folder_id-folno.
        REFRESH lt_rec_tab.
       CLEAR lt_rec_tab.
       lt_rec_tab-sel        = 'X'.
       lt_rec_tab-recesc     = object_type.   "This field for FAX/MAIL
       lt_rec_tab-recnam     = 'U-'.
       lt_rec_tab-deliver    = 'X'.
       lt_rec_tab-not_deli   = 'X'.
       lt_rec_tab-read       = 'X'.
       lt_rec_tab-mailstatus = 'E'.
       lt_rec_tab-adr_name   = fax_mail_number.
       lt_rec_tab-sortfield  = fax_mail_number.
       lt_rec_tab-recextnam  = fax_mail_number.
       lt_rec_tab-sortclass  = '5'.
       APPEND lt_rec_tab.
          lt_rec_tab-recextnam = fax_mail_number.
          lt_rec_tab-recesc = object_type.
          lt_rec_tab-sndart = 'INT'.
          lt_rec_tab-sndpri = 1.
          APPEND lt_rec_tab.
        lt_files-file = c_file.
        APPEND lt_files.
    begin of insertion by faianf01
        hd_dat-objdes = header_mail.
        CALL FUNCTION 'SO_ATTACHMENT_INSERT'
             EXPORTING
                  object_id                  = object_id
                  attach_type                = attach_type
                  object_hd_change           = hd_dat
                  owner                      = sy-uname
             TABLES
                  objcont                    = l_objcont
                  objhead                    = l_objhead
             EXCEPTIONS
                  active_user_not_exist      = 35
                  communication_failure      = 71
                  object_type_not_exist      = 17
                  operation_no_authorization = 21
                  owner_not_exist            = 22
                  parameter_error            = 23
                  substitute_not_active      = 31
                  substitute_not_defined     = 32
                  system_failure             = 72
                  x_error                    = 1000.
        IF sy-subrc > 0.
        ENDIF.
    end of insertion by faianf01
    send email from SAPOFFICE
        CALL FUNCTION 'SO_OBJECT_SEND'
             EXPORTING
                  folder_id                  = folder_id
                  object_id                  = object_id
                  outbox_flag                = outbox_flag
                  link_folder_id             = link_folder_id
                  owner                      = sy-uname
                 check_send_authority       = 'X'
             TABLES
                  receivers                  = lt_rec_tab
                 note_text                  = lt_note_text
             EXCEPTIONS
                  active_user_not_exist      = 35
                  communication_failure      = 71
                  component_not_available    = 1
                  folder_no_authorization    = 5
                  folder_not_exist           = 6
                  forwarder_not_exist        = 8
                  object_no_authorization    = 13
                  object_not_exist           = 14
                  object_not_sent            = 15
                  operation_no_authorization = 21
                  owner_not_exist            = 22
                  parameter_error            = 23
                  substitute_not_active      = 31
                  substitute_not_defined     = 32
                  system_failure             = 72
                  too_much_receivers         = 73
                  user_not_exist             = 35.
      ENDIF.
    ENDFUNCTION.
    =================================================================================
    z_send_email_fax
    FUNCTION ZCBFS_SEND_MAIL.
    ""Interface local:
    *"  IMPORTING
    *"     REFERENCE(SRC_SPOOLID) LIKE  TSP01-RQIDENT
    *"     REFERENCE(HEADER_MAIL) TYPE  SO_OBJ_DES
    *"  TABLES
    *"      LIST_FAX_MAIL_NUMBER STRUCTURE  SOLI
    *"  EXCEPTIONS
    *"      ERR_NO_ABAP_SPOOLJOB
      DATA: vg_achou(1) TYPE n.
    Fist part: Verify if the spool really exists
      vg_achou = 1.
      DO 60 TIMES.
        SELECT SINGLE * FROM tsp01 WHERE rqident = src_spoolid.
        IF sy-subrc IS INITIAL.
          CLEAR vg_achou.
          EXIT.
        ELSE.
          WAIT UP TO 1 SECONDS.
        ENDIF.
      ENDDO.
      IF vg_achou = 1.
        RAISE err_no_abap_spooljob. "doesn't exist
      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
                OTHERS        = 5.
      IF objtype(3) = 'OTF'.
        desired_type = otf.
      ELSE.
        desired_type = ali.
      ENDIF.
      CALL FUNCTION 'RSPO_RETURN_SPOOLJOB'
           EXPORTING
                rqident              = src_spoolid
                desired_type         = desired_type
           IMPORTING
                real_type            = real_type
           TABLES
                buffer               = l_objcont
           EXCEPTIONS
                no_such_job          = 14
                type_no_match        = 94
                job_contains_no_data = 54
                no_permission        = 21
                can_not_access       = 21
                read_error           = 54.
      IF sy-subrc EQ 0.
        attach_type = real_type.
      ENDIF.
      CALL FUNCTION 'SO_FOLDER_ROOT_ID_GET'
           EXPORTING
                owner     = sy-uname
                region    = ou_fol
           IMPORTING
                folder_id = l_folder_id
           EXCEPTIONS
                OTHERS    = 5.
    fill out informations about the header of the email
      CLEAR: g_document.
      g_document-foltp     = l_folder_id-foltp.
      g_document-folyr     = l_folder_id-folyr.
      g_document-folno     = l_folder_id-folno.
      g_document-objtp     = c_objtp.
      g_document-objdes    = header_mail.
      g_document-file_ext  = c_file_ext.
      g_header_data-objdes    = header_mail.
      CALL FUNCTION 'SO_DOCUMENT_REPOSITORY_MANAGER'
           EXPORTING
                method      = 'SAVE'
                office_user = sy-uname
           IMPORTING
                authority   = g_authority
           TABLES
                attachments = lt_attachments
           CHANGING
                document    = g_document
                header_data = g_header_data
           EXCEPTIONS
                OTHERS      = 1.
      folder_id-objtp = l_folder_id-foltp.
      folder_id-objyr = l_folder_id-folyr.
      folder_id-objno = l_folder_id-folno.
      object_id-objtp = c_objtp.
      object_id-objyr = g_document-objyr.
      object_id-objno = g_document-objno.
      link_folder_id-objtp = l_folder_id-foltp.
      link_folder_id-objyr = l_folder_id-folyr.
      link_folder_id-objno = l_folder_id-folno.
      REFRESH lt_rec_tab.
      LOOP AT LIST_FAX_MAIL_NUMBER.
        lt_rec_tab-recextnam = LIST_FAX_MAIL_NUMBER-LINE.
        lt_rec_tab-recesc = 'U'.
        lt_rec_tab-sndart = 'INT'.
        lt_rec_tab-sndpri = 1.
        APPEND lt_rec_tab.
      ENDLOOP.
      lt_files-file = c_file.
      APPEND lt_files.
      hd_dat-objdes = header_mail.
      CALL FUNCTION 'SO_ATTACHMENT_INSERT'
           EXPORTING
                object_id                  = object_id
                attach_type                = attach_type
                object_hd_change           = hd_dat
                owner                      = sy-uname
           TABLES
                objcont                    = l_objcont
                objhead                    = l_objhead
           EXCEPTIONS
                active_user_not_exist      = 35
                communication_failure      = 71
                object_type_not_exist      = 17
                operation_no_authorization = 21
                owner_not_exist            = 22
                parameter_error            = 23
                substitute_not_active      = 31
                substitute_not_defined     = 32
                system_failure             = 72
                x_error                    = 1000.
      IF sy-subrc > 0.
      ENDIF.
    send email from SAPOFFICE
      CALL FUNCTION 'SO_OBJECT_SEND'
           EXPORTING
                folder_id                  = folder_id
                object_id                  = object_id
                outbox_flag                = outbox_flag
                link_folder_id             = link_folder_id
                owner                      = sy-uname
           TABLES
                receivers                  = lt_rec_tab
                note_text                  = lt_note_text
           EXCEPTIONS
                active_user_not_exist      = 35
                communication_failure      = 71
                component_not_available    = 1
                folder_no_authorization    = 5
                folder_not_exist           = 6
                forwarder_not_exist        = 8
                object_no_authorization    = 13
                object_not_exist           = 14
                object_not_sent            = 15
                operation_no_authorization = 21
                owner_not_exist            = 22
                parameter_error            = 23
                substitute_not_active      = 31
                substitute_not_defined     = 32
                system_failure             = 72
                too_much_receivers         = 73
                user_not_exist             = 35.
    ENDFUNCTION.
    Regards,
    Sree

Maybe you are looking for