Skip to Content
avatar image
Former Member

Scripts to mails

how do i attach the SCRIPTS to mails

Title was edited by:

Alvaro Tejada Galindo

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

2 Answers

  • avatar image
    Former Member
    Oct 24, 2007 at 05:15 PM

    Hi

    You can use and configure the Script Output using the Medium 7(for sending Mails)

    and maintain the setting in SCOT and SOST tcodes

    and maintain the mail ids in the respective master data

    the driver program will take care of that automatically.

    or you can convert the Spool ID of the script to PDF using the fun module CONVERT_ABAPSPOOLJOB_2_PDF and using the func tion module SO_NEW_DOCUMENT_ATT_SEND_API1 you can send the mail

    But you have to write this complete code in the program.

    ashish

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Oct 25, 2007 at 04:20 AM

    Hi,

    Copy the below code for email functionality in your driver program.

    • Work Area

    DATA: gs_struct TYPE itcpo, " SAPscript output interface

    gs_itcpp TYPE itcpp, " SAPscript output parameters

    gs_docdata TYPE sodocchgi1, " Data of an object which can be changed

    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 table 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

    • Variables used to pass to GUI_DOWNLOAD

    DATA: gv_filesize TYPE i,

    gv_bin_filesize TYPE i,

    gv_pos TYPE i,

    gv_len TYPE i,

    gv_tab_lines TYPE i.

    • Variables used for Save Dialog Box

    DATA : gv_file_name TYPE string,

    gv_file_path TYPE string,

    gv_full_path TYPE string.

    ********Constants *******************************************

    DATA : gc_tst(3) TYPE c VALUE 'TST',

    gc_testing(7) TYPE c VALUE 'Testing'.

    START-OF-SELECTION.

    gs_struct-tdgetotf = 'X'.

    gs_struct-tdnoprev = 'X'.

    CALL FUNCTION 'OPEN_FORM'

    EXPORTING

    device = 'PRINTER'

    dialog = 'X'

    form = 'ZTEST_G'

    language = sy-langu

    OPTIONS = gs_struct

    EXCEPTIONS

    canceled = 1

    device = 2

    form = 3

    OPTIONS = 4

    unclosed = 5

    mail_options = 6

    archive_error = 7

    invalid_fax_number = 8

    more_params_needed_in_batch = 9

    spool_error = 10

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

    CALL FUNCTION 'START_FORM'

    EXPORTING

    form = 'ZTEST_G'

    startpage = 'PAGE01'

    program = sy-repid

    EXCEPTIONS

    form = 1

    format = 2

    unended = 3

    unopened = 4

    unused = 5

    spool_error = 6

    codepage = 7

    OTHERS = 8.

    IF sy-subrc <> 0.

    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

    WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

    ENDIF.

    CALL FUNCTION 'WRITE_FORM'

    EXPORTING

    element = 'MAIN'

    function = 'SET'

    type = 'BODY'

    window = 'MAIN'

    EXCEPTIONS

    element = 1

    function = 2

    type = 3

    unopened = 4

    unstarted = 5

    window = 6

    bad_pageformat_for_print = 7

    spool_error = 8

    codepage = 9

    OTHERS = 10.

    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 'END_FORM'

    EXCEPTIONS

    unopened = 1

    bad_pageformat_for_print = 2

    spool_error = 3

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

    MOVE-CORRESPONDING gs_struct TO gs_itcpp.

    CALL FUNCTION 'CLOSE_FORM'

    IMPORTING

    RESULT = gs_itcpp

    TABLES

    OTFDATA = gt_otf

    EXCEPTIONS

    UNOPENED = 1

    BAD_PAGEFORMAT_FOR_PRINT = 2

    SEND_ERROR = 3

    SPOOL_ERROR = 4

    CODEPAGE = 5

    OTHERS = 6

    .

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

    gs_reclist-receiver = 'bijja.geeta@wipro.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.

    Reward points if useful...

    Add comment
    10|10000 characters needed characters exceeded