Sending output to a printer in a background job

I did a quick search on this issue and found a few suggestions.  One suggestion was to use something like this:
SUBMIT RSFLFIND ... TO SAP-SPOOL DESTINATION 'LT50'.
I looked at the SAP help for SUBMIT and it was quite helpful however it raised a few questions.  The program that am writing will be run in the background.  I want to create a simple report that will print at several different printers when it is done.  Looking at the help section (specifically this part):
"The SUBMIT statement accesses an executable program rep. The executable program is executed as described under Calling Executable Reports.
The program name rep can either be specified directly or as the content of a character-like data object name. The data object name must contain the name of the program to be accessed in block capitals. If the program specified in name is not found, an irretrievable exception is generated.
The selscreen_options additions can be used to determine the selection screen for the program accessed and to supply it with values.
The list_options additions allow you to influence the output medium and the page size in the basic list for the program accessed.
You can schedule the program for background processing by specifying job_options. "
It seems like I would create a simple program like this:
DATA: number TYPE tbtcjob-jobcount,
      name TYPE tbtcjob-jobname VALUE 'JOB_TEST',
      print_parameters TYPE pri_params.
CALL FUNCTION 'JOB_OPEN'
  EXPORTING
    jobname          = name
  IMPORTING
    jobcount         = number
  EXCEPTIONS
    cant_create_job  = 1
    invalid_job_data = 2
    jobname_missing  = 3
    OTHERS           = 4.
IF sy-subrc = 0.
  SUBMIT submitable TO SAP-SPOOL
                    SPOOL DESTINATION 'LT50'.
                    VIA JOB name NUMBER number
                    AND RETURN.
  IF sy-subrc = 0.
    CALL FUNCTION 'JOB_CLOSE'
      EXPORTING
        jobcount             = number
        jobname              = name
        strtimmed            = 'X'
      EXCEPTIONS
        cant_start_immediate = 1
        invalid_startdate    = 2
        jobname_missing      = 3
        job_close_failed     = 4
        job_nosteps          = 5
        job_notex            = 6
        lock_failed          = 7
        OTHERS               = 8.
    IF sy-subrc <> 0.
    ENDIF.
  ENDIF.
ENDIF.
That will then call the background job and the output will go to the print spool.  I have a few reservations about this.  The print spool will not be determined until the background job.  The background job creates sales orders and the material group, in the sales order, determines the printer that the final report will go to.  Also, if this is the way to do it, do I just do simple write statements in the background job?

Hi,
Please try this ... perhaps it may help.
SUBMIT submitable TO SAP-SPOOL
                  SPOOL DESTINATION 'LT50'.
                  IMMEDIATELY 'X'           "Add here
                  VIA JOB name NUMBER number
                  AND RETURN.
OR
SUBMIT submitable TO SAP-SPOOL
                  SPOOL DESTINATION 'LT50'.
                  IMMEDIATELY 'X'           "Add here
                  WITHOUT SPOOL DYNPRO      "Add here
                  VIA JOB name NUMBER number
                  AND RETURN.
Regards,
Ferry Lianto

Similar Messages

  • REP-1885 Can't send output to the printer

    I got the error: REP-1885 Can't send output to the printer
    when trying to print a report from Live Previewer.
    Report Builder: 6.0.8.19
    Oracle 8.1.7.2
    Any help is much appreciated.

    hello,
    i'd try the latest patchset and if that does not help, contact oracle support services.
    regards,
    philipp

  • How to send output of a print  to a single pool in smartforms

    Hi,
    when iam taking a an out put from the invoice all the output has to be send to a single pool .means if we give an invoice number in vf03 and issue the output and if we choose print then it will directly got to spool.but requirement is to store all the spool numbers on application server and finall we have to convert all these into single pdf and then we have to print that.
    can any body tell me where to store these spool numbers and how we can send at a time to print
    help me pleases
    sasi

    Hi Sasi,
    Check the following:
    Exporting the Contents of a Spool Request as a PDF File
    Use
    You want to export the contents of a spool request as a PDF file to a directory of your choice, and print the file as required. The PDF file contains the print data in the format in which it would be output by the printer.
    The following procedure is irrelevant for the PDF-based form printing integrated as of SAP Web Application Server 6.40, since a PDF file is already returned. See also Displaying and Printing PDF-Based Forms.
    Procedure
    The PDF file is generated as follows with report RSTXPDFT4:
    1. Generate a spool request from the document to be printed.
    2. In transaction SE38, start report rstxpdft4.
    3. In the displayed window, enter the spool request number and the directory in which the PDF file is to be stored.
    Leave the Download PDF File option selected.
    Choose Execute.
    4. In the next window, you can confirm or change the path in which the file is be stored.
    Save your entries.
    5. The system displays a log from which you can see whether the report was successfully performed.
    You can then open the file from the directory and print it as required.
    Constraints·        The PDF conversion only supports true bar codes for Smart Forms, which were generated with the new bar code technology. In all other cases, the bar code is only simulated.  
    ·        PDF conversion, especially of ABAP lists, is slower and is therefore not suitable for mass printing. However, you can speed up the conversion to PDF using the FASTLISTCONV option in report RSTXPDF3.
    ·        The font selection for ABAP lists is predefined in the PDF converter and cannot be changed.
    For more information about constraints, see SAP Note 323736 in the SAP Service Marketplace.
    For further reference check the SAP documentation...
    http://help.sap.com/saphelp_erp2005/helpdata/en/94/45c53bcc422d42e10000000a114084/frameset.htm
    Thanks and Regards,
    Bharat Kumare Reddy.V

  • Problem while sending output to a printer

    Hi,
    I am trying to send an output to a remote printer (on the same LAN)
    I have the remote printer configured on my machine, and while adding a new printer in Central's printer database, I am specifying the IP address of the printer in the physical device section. (i.e. \\192.168.*.*)
    In my job file, I tried giving options: -z"Printer Name", -z"Printer ID" and even removed -z option to achieve the default printing specified on my job, which is a print to the remote printer.
    But the printing is not taking place.
    Can sombody please guide me with regards to what is the correct approach in sending print to a remote printer (I am aware of the printer IP and port). What exact options do I need to specify in printer/job database and in the job file?
    Thanks and Regards,
    Aalap

    The -z option would normally refer to the "logical printer" name that is within the Job Management Database, Printers definition section (-zAcctPrt). Whether the actual print queue is defined on the server where Central is running or on another server the format for this entry is the same:
    b \\ServerName\QueName
    Then the Windows printer setup would be using the TCP/IP port for the printer. I don't have the exact instructions in front of me but setting up a print queue for Central is something like:
    Select "local printer"
    Select "create a new port"
    Select "Standard TCP/IP Port"
    Type in the IP # for the printer & change port name as desired
    Device Type of "Standard" and "Generic Network Card" should work
    For printer driver, Select Generic manufacturer & Generic/Text Only for the printer type (this works when using Print Agent targets because all printer control information is embedded within the print file.
    Give it a name of your choice.
    Print a test page to see if it works.
    In the above example of a logical printer definiation, the name given the new print queue would be used.
    b * * * All samples/instructions based on a Microsoft Windows Server 2000 system * * *

  • Print binary as background job

    Hi experts,
    Is there a way to send binary(xstring) to a printer, eg. jpg/doc/pdf, as a background job with abap.
    Mvh,
    Alex

    Alexander,
    check these threads:
    Printing binary data in PDF format
    Solution! (Hopefully) :Print label image in GIF format
    Save print output as PDF file in front end system using PDF printer output device

  • Printing Invoices in Background Jobs

    Hello,
    We have an o/p type that is processed each time a billing document is created. The o/p type prints the billing document as soon as it is saved. When we have a billing due list program run in background the printouts are waiting in the Spool and are not printed. Is there any way we can print the documents when the billing due list program runs in background.
    Any help would be appreciated.
    Thanks,
    Alam.

    Hello Alam,
    If your question was answered, please close this thread and assign the points to the person that give you the answer.
    Regards,
    Eric

  • Send Attachment via background job

    Hi,
    Is there any function module/program  in SAP where we can send attachment to external parties via scheduled background job?
    Thank you.

    Dear YEO WEI KOK,
    Please check the following link: 
    http://www.sap-img.com/abap/sending-mail-with-attachment-report-in-background.htm
    Hope this helps you.
    Do award points if you found them useful.
    Regards,
    Rakesh

  • Types of Background jobs

    Hi,
    Can anybody pl tell me the difference between Scheduled Job and Released job in background processing. Or send me some doc regarding types of background jobs.
    Thanks...
    Hardik

    There are two ways to schedule a job from a program:
    1. the "express" method using the BP_JOBVARIANT_SCHEDULE function module
    2. the "full-control" method using the JOB_OPEN, JOB_SUBMIT, and JOB_CLOSE function modules.
    With this method, you have full control over such job options as printing, start time options, and so on.
    To schedule a job from within a program using the express method, you need only call the BP_JOBVARIANT_SCHEDULE function module.
    With BP_JOBVARIANT_OVERVIEW, you can offer your users a simplified display and management function for their "express-method" jobs.
    call function 'BP_JOBVARIANT_SCHEDULE'
    exporting
    title_name = 'Documentation Check' " Displayed as title of
    " of scheduling screens
    job_name = 'DocuCheck' " Name of background
    " processing job
    prog_name = 'RSTWGZS2' " Name of ABAP
    " report that is to be
    " run -- used also to
    " select variants
    exceptions
    no_such_report = 01. " PROG_NAME program
    " not found.
    call function 'BP_JOBVARIANT_OVERVIEW' " List the jobs that
    exporting " have been scheduled
    title_name = 'Documentation Check' " Displayed as title
    " of overview screen
    job_name = 'DokuCheck' " Jobs with this name
    " are listed
    prog_name = 'RSTWGZS2'
    exceptions
    no_such_job = 01.
    For further information check the link below
    http://help.sap.com/saphelp_nw2004s/helpdata/en/c4/3a80eb505211d189550000e829fbbd/frameset.htm

  • Error in Schedule Background Job for Deadline Monitoring of swu3

    While Auto Customization swu3 i am getting error message 'Output device "" not known' in 'Schedule Background Job for Deadline Monitoring'
    Please advice what could be cause of it

    the earlier problem of background job was solved by changing the  output device assigned to user wf-batch .
    regarding the transport request :
    when i was trying to execute the step : "Schedule bakgrd for missed deadlines " MANUEL it was giving me an option of SAVE AND SCHEDULE . which was creating the transport request . but when i executed it automatically it worked fine without asking a request to me ... i don't know why )-: ... probablly we can specify a different interval then the standard of three minutes and which will be transported (it's just a guess) . i have  executed it  automatically ...
    well thanks all for u r help

  • How to send background program output to a printer

    Hi !
    I created a background report,running via a job in background. I need to display the output of the background report via two channels : a printer and an e
    mail. I created the output of the report by using the command Write, and the output is printed to screen. However this solution is good for an online report and not for background report ? and my question is how to send the background report output to a printer in background .
    Thanks
    Moshe

    Hi,
    If you are using JOB_OPEN, JOB_SUBMIT & JOB_CLOSE to execute the program in background, then in the FM JOB_SUBMIT you have a parameter PRIPARAMS for which you need to pass a value.
    Before that get all the Print Parameters using FM GET_PRINT_PARAMETERS. Then pass the same to PRIPARAMS.
    This would solve the problem.
    Best regards,
    Prashant

  • Background job  step - Printer - Output device  table

    Hi,
    When creating background job, printer- output device also specified for every step. Which table to check for job name and output device combination ?
    Thanks.

    Hi Raj check table TBTCP

  • Send output as PDF during background job

    Dear
    can you suggest how to send output of schedule job log in PDF as attachment insted of HTML.
    If i schedule any job & set spool receiption, then spool log is sent as html attachment,
    but i want to send it as pdf is there is any way  to change defalult attachment type.
    In addition to it can i set message text during scheduling job, or can i insert message text in body along with
    attachment. So that i can type desired message in Body, any standard template is available to change its text.
    regards
    Pranav

    Answer on the first question:
    trxn SCOT
    double click the INT node  that sends your mail out
    suported adres typs: internet click on SET
    There you have 3 report types: set these to PDF. ( you can not set BO/Link to pdf)
    I have to admit i have never tested, so let us know if this works !
    Answer on the second question:
    Not really ( AFAIK) , you can modify the header line of the message  (and spool)  via:
    SM36 , shedule the job, during every step you can click at the bottem on "print specifications", then properties
    There you can modify Name and title.
    Maybe a cover page could fit your needs partially?
    http://help.sap.com/saphelp_nw70/helpdata/en/d9/4a951b51ea11d189570000e829fbbd/frameset.htm

  • Aperture 3: After sending my book for printing to Apple the Apple Store told me that my text and the background have the same color and they couldn't print the book. But I couldn't find any problem in the preview. How could I find the problem pages?

    Aperture 3: After sending my book for printing to Apple the Apple Store told me that my text and the background have the same color and they couldn't print the book. But I couldn't find any problem in the preview. How could I find the pages where the problems are? Or otherwise, why doesn't print Apple the book how it is. Idon't need the text which couldn'be seen.

    The forum is for Logic Pro users.. I will ask the moderators to move it to a more appropriate forum for your question/subject
    Cheers..

  • Background job not showing full output of Report

    Dear Experts
    we have created zpgm for stad report and try to take output as mail to particular user for future analysis bcaz stad gives only 2 days report only we need keep report for months together so when we run job in foreground it shows proper output but when same thing when we run from background it shows only some part of report in mail (we are unable to get full output through background job )
    we send mail through spool receipts we have created folder and maintain user for getting mails through so15 distribution list
    we need some input to come out of this major issue
    if there is any other workaround let me know
    Regards

    Hello,
    If a job is defined by transaction SM36, the print format parameters will only be taken into account, if they are saved as user specific print parameters of the batch user. If no user specific print format
    is defined,  the ALV standard logic will be processed adjusting the print format to the actual line size of the report.
    For example, the list line size is about 132 characters, the widest available format of the chosen printer will be selected X_65_132.
    The problem would be solved by defining a device type which is no format assigned to print, or by defining user specific print format parameters for the batch user, who creates the jobs in SM36 (see
    SAP note 1179399, item 6).
    Regards,
    David

  • Urgent ...how to send output of sap through mail

    Could you please guide me how to send output of SAP Script  through mail in PDF format.
    Thanks in Advance....
    Regards,
    Kumar.

    *& Report  ZSPOOLTOPDF                                                 *
    *& Converts spool request into PDF document and emails it to           *
    *& recipicant.                                                         *
    *& Execution                                                           *
    *& This program must be run as a background job in-order for the write *
    *& commands to create a Spool request rather than be displayed on      *
    *& screen                                                              *
    REPORT  zspooltopdf.
    PARAMETER: p_email1 LIKE somlreci1-receiver,
               p_sender LIKE somlreci1-receiver,
                   p_delspl  AS CHECKBOX.
    *DATA DECLARATION
    DATA: gd_recsize TYPE i.
    Spool IDs
    TYPES: BEGIN OF t_tbtcp.
            INCLUDE STRUCTURE tbtcp.
    TYPES: END OF t_tbtcp.
    DATA: it_tbtcp TYPE STANDARD TABLE OF t_tbtcp INITIAL SIZE 0,
          wa_tbtcp TYPE t_tbtcp.
    Job Runtime Parameters
    DATA: gd_eventid LIKE tbtcm-eventid,
          gd_eventparm LIKE tbtcm-eventparm,
          gd_external_program_active LIKE tbtcm-xpgactive,
          gd_jobcount LIKE tbtcm-jobcount,
          gd_jobname LIKE tbtcm-jobname,
          gd_stepcount LIKE tbtcm-stepcount,
          gd_error    TYPE sy-subrc,
          gd_reciever TYPE sy-subrc.
    DATA:  w_recsize TYPE i.
    DATA: gd_subject   LIKE sodocchgi1-obj_descr,
          it_mess_bod LIKE solisti1 OCCURS 0 WITH HEADER LINE,
          it_mess_att LIKE solisti1 OCCURS 0 WITH HEADER LINE,
          gd_sender_type     LIKE soextreci1-adr_typ,
          gd_attachment_desc TYPE so_obj_nam,
          gd_attachment_name TYPE so_obj_des.
    Spool to PDF conversions
    DATA: gd_spool_nr LIKE tsp01-rqident,
          gd_destination LIKE rlgrap-filename,
          gd_bytecount LIKE tst01-dsize,
          gd_buffer TYPE string.
    Binary store for PDF
    DATA: BEGIN OF it_pdf_output OCCURS 0.
            INCLUDE STRUCTURE tline.
    DATA: END OF it_pdf_output.
    CONSTANTS: c_dev LIKE  sy-sysid VALUE 'DEV',
               c_no(1)     TYPE c   VALUE ' ',
               c_device(4) TYPE c   VALUE 'LOCL'.
    *START-OF-SELECTION.
    START-OF-SELECTION.
    Write statement to represent report output. Spool request is created
    if write statement is executed in background. This could also be an
    ALV grid which would be converted to PDF without any extra effort
      WRITE 'Hello World'.
      new-page.
      commit work.
      new-page print off.
      IF sy-batch EQ 'X'.
        PERFORM get_job_details.
        PERFORM obtain_spool_id.
    Alternative way could be to submit another program and store spool
    id into memory, will be stored in sy-spono.
    *submit ZSPOOLTOPDF2
           to sap-spool
           spool parameters   %_print
           archive parameters %_print
           without spool dynpro
           and return.
    Get spool id from program called above
    IMPORT w_spool_nr FROM MEMORY ID 'SPOOLTOPDF'.
        PERFORM convert_spool_to_pdf.
        PERFORM process_email.
        if p_delspl EQ 'X'.
          PERFORM delete_spool.
        endif.
        IF sy-sysid = c_dev.
          wait up to 5 seconds.
          SUBMIT rsconn01 WITH mode   = 'INT'
                          WITH output = 'X'
                          AND RETURN.
        ENDIF.
      ELSE.
        SKIP.
        WRITE:/ 'Program must be executed in background in-order for spool',
                'request to be created.'.
      ENDIF.
          FORM obtain_spool_id                                          *
    FORM obtain_spool_id.
      CHECK NOT ( gd_jobname IS INITIAL ).
      CHECK NOT ( gd_jobcount IS INITIAL ).
      SELECT * FROM  tbtcp
                     INTO TABLE it_tbtcp
                     WHERE      jobname     = gd_jobname
                     AND        jobcount    = gd_jobcount
                     AND        stepcount   = gd_stepcount
                     AND        listident   <> '0000000000'
                     ORDER BY   jobname
                                jobcount
                                stepcount.
      READ TABLE it_tbtcp INTO wa_tbtcp INDEX 1.
      IF sy-subrc = 0.
        message s004(zdd) with gd_spool_nr.
        gd_spool_nr = wa_tbtcp-listident.
        MESSAGE s004(zdd) WITH gd_spool_nr.
      ELSE.
        MESSAGE s005(zdd).
      ENDIF.
    ENDFORM.
          FORM get_job_details                                          *
    FORM get_job_details.
    Get current job details
      CALL FUNCTION 'GET_JOB_RUNTIME_INFO'
           IMPORTING
                eventid                 = gd_eventid
                eventparm               = gd_eventparm
                external_program_active = gd_external_program_active
                jobcount                = gd_jobcount
                jobname                 = gd_jobname
                stepcount               = gd_stepcount
           EXCEPTIONS
                no_runtime_info         = 1
                OTHERS                  = 2.
    ENDFORM.
          FORM convert_spool_to_pdf                                     *
    FORM convert_spool_to_pdf.
      CALL FUNCTION 'CONVERT_ABAPSPOOLJOB_2_PDF'
           EXPORTING
                src_spoolid              = gd_spool_nr
                no_dialog                = c_no
                dst_device               = c_device
           IMPORTING
                pdf_bytecount            = gd_bytecount
           TABLES
                pdf                      = it_pdf_output
           EXCEPTIONS
                err_no_abap_spooljob     = 1
                err_no_spooljob          = 2
                err_no_permission        = 3
                err_conv_not_possible    = 4
                err_bad_destdevice       = 5
                user_cancelled           = 6
                err_spoolerror           = 7
                err_temseerror           = 8
                err_btcjob_open_failed   = 9
                err_btcjob_submit_failed = 10
                err_btcjob_close_failed  = 11
                OTHERS                   = 12.
      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.
    ENDFORM.
          FORM process_email                                            *
    FORM process_email.
      DESCRIBE TABLE it_mess_att LINES gd_recsize.
      CHECK gd_recsize > 0.
      PERFORM send_email USING p_email1.
    perform send_email using p_email2.
    ENDFORM.
          FORM send_email                                               *
    -->  p_email                                                       *
    FORM send_email USING p_email.
      CHECK NOT ( p_email 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.
      it_mess_bod        = 'Message Body text, line 2...'.
      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_email
                                          'Example .xls documnet attachment'
                                          'PDF'
                                          gd_attachment_name
                                          gd_attachment_desc
                                          p_sender
                                          gd_sender_type
                                 changing gd_error
                                          gd_reciever.
    ENDFORM.
          FORM delete_spool                                             *
    FORM delete_spool.
      DATA: ld_spool_nr TYPE tsp01_sp0r-rqid_char.
      ld_spool_nr = gd_spool_nr.
      CHECK p_delspl <> c_no.
      CALL FUNCTION 'RSPO_R_RDELETE_SPOOLREQ'
           EXPORTING
                spoolid = ld_spool_nr.
    ENDFORM.
    *&      Form  SEND_FILE_AS_EMAIL_ATTACHMENT
          Send email
    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.
    ENDFORM.
    regards,
    venkat

Maybe you are looking for