Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Batch program

Former Member
0 Likes
435

Hello all,

I want to develop a report that should be able to run in batch and have results sent in an email.

What exactly i have to do.... i am new to this.....thank you for help in advace.....

2 REPLIES 2
Read only

Former Member
0 Likes
416

Here is e-mail code.

FORM email.

DATA: l_test TYPE xfeld,

l_email_sent TYPE os_boolean,

send_email TYPE char1,

it_output TYPE STANDARD TABLE OF solisti1,

wa_output LIKE LINE OF it_output,

mail TYPE REF TO zcl_sendmail,

v_attach_subject(50) TYPE c,

line_break TYPE char2 VALUE %_cr_lf.

"Needed to create table directly from field_catalog

DATA: l_data TYPE REF TO data,

l_wa TYPE REF TO data.

FIELD-SYMBOLS: <fs_table> TYPE STANDARD TABLE,

<fs_line> TYPE ANY,

<fs_field> TYPE ANY.

CREATE OBJECT mail.

mail->set_subject( EXPORTING im_subject = p_subjct ).

LOOP AT s_messag.

wa_message = s_messag-low.

APPEND wa_message TO it_message.

ENDLOOP.

mail->set_message( EXPORTING im_message = it_message ).

LOOP AT s_recipe.

wa_recipients = s_recipe-low.

APPEND wa_recipients TO it_recipients.

ENDLOOP.

mail->add_recipients( EXPORTING im_smtp_addresses = it_recipients ).

mail->set_sender( EXPORTING im_sender = p_sender ).

"To get the fields built in the correct order.

SORT gt_fieldcat BY col_pos ASCENDING.

"This will create a table reference from the fieldcatalog.

PERFORM xalv_dynamic_tablebuild

TABLES gt_fieldcat

USING l_data.

"This create the appropriate structure for the table

ASSIGN l_data->* TO <fs_table>.

CREATE DATA l_wa LIKE LINE OF <fs_table>.

ASSIGN l_wa->* TO <fs_line>.

"This places only the columns from your fieldcatalog into your dynamic table.

LOOP AT it_orders INTO wa_orders.

MOVE-CORRESPONDING wa_orders TO <fs_line>.

APPEND <fs_line> TO <fs_table>.

ENDLOOP.

"Adds header for Excel

LOOP AT gt_fieldcat INTO wa_fieldcat.

CONCATENATE wa_output-line wa_fieldcat-seltext_l INTO wa_output-line SEPARATED BY ','.

ENDLOOP.

CONCATENATE wa_output-line line_break INTO wa_output-line SEPARATED BY ','.

APPEND wa_output TO it_output.

CLEAR wa_output.

"Adds data for Excel

LOOP AT <fs_table> INTO <fs_line>.

DO.

ASSIGN COMPONENT sy-index OF STRUCTURE <fs_line> TO <fs_field>.

IF sy-subrc 0.

EXIT.

ENDIF.

CONCATENATE wa_output-line <fs_field> INTO wa_output-line SEPARATED BY ','.

ENDDO.

CONCATENATE wa_output-line line_break INTO wa_output-line SEPARATED BY ','.

APPEND wa_output TO it_output.

CLEAR wa_output.

ENDLOOP.

CONCATENATE 'ZSD_ORDER_SEARCH' sy-datum sy-uzeit INTO v_attach_subject.

mail->add_attachment( EXPORTING

im_attachment_type = 'csv'

im_attachment_subject = v_attach_subject

im_att_content_text = it_output

).

mail->send_email(

EXPORTING

im_test = l_test

RECEIVING

re_email_sent = l_email_sent

EXCEPTIONS

send_email_failed = 1

message_invalid = 2

subject_invalid = 3

recipients_invalid = 4

OTHERS = 5

).

IF sy-subrc 0 OR l_email_sent = ' '.

MESSAGE i000(zrf) WITH 'Email not sent'.

ENDIF.

ENDFORM. "email

Here is where I am populating F4 variant table.

&----


*& Form f4_for_variant

&----


FORM f4_for_variant.

it_var-report = sy-repid.

CALL FUNCTION 'REUSE_ALV_VARIANT_F4'

EXPORTING

is_variant = it_var

i_save = 'A'

IMPORTING

es_variant = it_var

EXCEPTIONS

not_found = 2.

IF sy-subrc = 2.

MESSAGE s899 WITH text-054. " No Variants

ELSE.

p_var = it_var-variant.

ENDIF.

ENDFORM. "f4_for_variant

Here is part of my fieldcatalog.

&----


*& Form build_fieldcat

&----


FORM build_fieldcat .

wa_fieldcat-emphasize = 'C100'.

wa_fieldcat-tabname = 'IT_ORDERS'.

wa_fieldcat-fieldname = 'VBELN'.

wa_fieldcat-seltext_m = 'Sales Doc'.

wa_fieldcat-seltext_l = 'Sales Document'.

wa_fieldcat-outputlen = 10.

wa_fieldcat-col_pos = 1.

wa_fieldcat-hotspot = 'X'.

APPEND wa_fieldcat TO gt_fieldcat.

CLEAR wa_fieldcat.

wa_fieldcat-tabname = 'IT_ORDERS'.

wa_fieldcat-fieldname = 'POSNR'.

wa_fieldcat-seltext_m = 'Item'.

wa_fieldcat-seltext_l = 'Sales Document Item'.

wa_fieldcat-outputlen = 6.

wa_fieldcat-col_pos = 2.

APPEND wa_fieldcat TO gt_fieldcat.

CLEAR wa_fieldcat.

wa_fieldcat-tabname = 'IT_ORDERS'.

wa_fieldcat-fieldname = 'VKORG'.

wa_fieldcat-seltext_m = 'Sales Org'.

wa_fieldcat-seltext_l = 'Sales Organization'.

wa_fieldcat-outputlen = 10.

wa_fieldcat-col_pos = 3.

APPEND wa_fieldcat TO gt_fieldcat.

CLEAR wa_fieldcat.

And finally how I call the fieldcatalog to create ALV.

&----


*& Form display_list

&----


FORM display_list .

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

i_callback_program = sy-repid

it_fieldcat = gt_fieldcat[]

it_events = gt_events[]

i_save = 'A'

is_variant = it_var

is_layout = ps_layout

i_callback_user_command = 'HOTBUTTON'

TABLES

t_outtab = it_orders.

ENDFORM. " display_list

Kevin

Read only

Former Member
0 Likes
416

Hi Siddhesh.

On SM36, when you are setting a step for job, there is a print specifications button. It open a print background parameters.

For output Device, you can choose a email-pdf based printer.

This device must be created by your basis and defined to send e-mails

Then, just output the results by Write statment or ALV grid in your report program

The screen displayed will be sended in a attached pdf file by e-mail.

Darley