ABAP顾问
分类:
2007-12-31 18:12:00
REPORT z_barry_job_list .
TYPE-POOLS: slis.
TABLES:p0105_af,btch2170.
DATA: gd_fieldcat TYPE slis_t_fieldcat_alv.
DATA: sla TYPE slis_layout_alv ,
ivariant LIKE disvariant,
i_repid LIKE sy-repid ,
i_excluding TYPE slis_t_extab.
DATA: BEGIN OF in_wa .
INCLUDE STRUCTURE btcselect.
DATA: END OF in_wa.
DATA: BEGIN OF itab OCCURS 0 .
INCLUDE STRUCTURE tbtcjob_bk.
DATA: END OF itab.
DATA: it_packing_list LIKE sopcklsti1 OCCURS 0 WITH HEADER LINE,
it_contents LIKE solisti1 OCCURS 0 WITH HEADER LINE,
it_receivers LIKE somlreci1 OCCURS 0 WITH HEADER LINE,
it_attachment LIKE solisti1 OCCURS 0 WITH HEADER LINE,
gd_cnt TYPE i,
gd_sent_all(1) TYPE c,
gd_doc_data LIKE sodocchgi1,
gd_error TYPE sy-subrc.
DATA: it_message TYPE STANDARD TABLE OF solisti1 INITIAL SIZE 0
WITH HEADER LINE.
PARAMETERS : p_user LIKE btch2170-username OBLIGATORY DEFAULT sy-uname .
SELECT-OPTIONS: s_date FOR btch2170-from_date NO-EXTENSION
DEFAULT sy-datum ,
s_addr FOR p0105_af-email DEFAULT .
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-010.
SELECTION-SCREEN BEGIN OF LINE.
PARAMETERS p_pre AS CHECKBOX DEFAULT 'X' .
SELECTION-SCREEN COMMENT (10) text-001 FOR FIELD p_pre .
PARAMETERS p_sch AS CHECKBOX DEFAULT 'X' .
SELECTION-SCREEN COMMENT (10) text-002 FOR FIELD p_sch .
PARAMETERS p_rea AS CHECKBOX DEFAULT 'X'.
SELECTION-SCREEN COMMENT (10) text-003 FOR FIELD p_rea .
PARAMETERS p_run AS CHECKBOX DEFAULT 'X'.
SELECTION-SCREEN COMMENT (10) text-004 FOR FIELD p_run .
PARAMETERS p_fin AS CHECKBOX DEFAULT 'X'.
SELECTION-SCREEN COMMENT (10) text-005 FOR FIELD p_fin .
PARAMETERS p_abo AS CHECKBOX DEFAULT 'X'.
SELECTION-SCREEN COMMENT (10) text-006 FOR FIELD p_abo .
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN END OF BLOCK b1.
START-OF-SELECTION.
PERFORM getdata.
PERFORM outdata.
* PERFORM send_mail.
*---------------------------------------------------------------------*
* FORM getdata *
*---------------------------------------------------------------------*
FORM getdata.
in_wa-jobname = '*'.
in_wa-username = p_user .
in_wa-from_date = s_date-low.
in_wa-to_date = s_date-high .
***Job的状态
in_wa-prelim = p_pre.
in_wa-schedul = p_sch.
in_wa-ready = p_rea .
in_wa-running = p_run.
in_wa-finished = p_fin.
in_wa-aborted = p_abo.
CALL FUNCTION 'BP_JOB_SELECT_SM37B'
EXPORTING
jobselect_dialog = 'N'
jobsel_param_in = in_wa
TABLES
* JOBSELECT_JOBLIST =
jobselect_joblist_b = itab
EXCEPTIONS
invalid_dialog_type = 1
jobname_missing = 2
no_jobs_found = 3
selection_canceled = 4
username_missing = 5
OTHERS = 6 .
ENDFORM.
*&---------------------------------------------------------------------*
*& Form outdata
*&---------------------------------------------------------------------*
FORM outdata.
sla-colwidth_optimize = 'X'.
sla-zebra = 'X'.
i_repid = sy-repid.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = i_repid
i_structure_name = 'TBTCJOB_BK'
is_layout = sla
TABLES
t_outtab = itab
EXCEPTIONS
program_error = 1
OTHERS = 2.
ENDFORM. " outdata
*---------------------------------------------------------------------*
* FORM send_email_message *
*---------------------------------------------------------------------*
FORM send_mail.
DATA: txt TYPE string .
gd_doc_data-doc_size = 1.
gd_doc_data-obj_langu = sy-langu.
gd_doc_data-obj_name = 'SAPRPT'.
CONCATENATE 'Job监控自动发送邮件' '' INTO gd_doc_data-obj_descr.
gd_doc_data-sensitivty = 'F'.
LOOP AT itab.
CASE itab-status.
WHEN 'P'.
txt = 'PRELIMINARY'.
WHEN 'S'.
txt = 'SCHEDULED'.
WHEN 'Y'.
txt = 'READY'.
WHEN 'R'.
txt = 'RUNNING'.
WHEN 'F'.
txt = 'FINISHED'.
WHEN 'A'.
txt = 'ABORTED'.
ENDCASE.
CONCATENATE itab-jobname ',' txt INTO it_message .
APPEND it_message.
ENDLOOP.
CLEAR it_packing_list.
REFRESH it_packing_list.
it_packing_list-transf_bin = space.
it_packing_list-head_start = 1.
it_packing_list-head_num = 0.
it_packing_list-body_start = 1.
DESCRIBE TABLE it_message LINES it_packing_list-body_num.
it_packing_list-doc_type = 'RAW'.
APPEND it_packing_list.
CLEAR it_receivers.
REFRESH it_receivers.
LOOP AT s_addr.
it_receivers-receiver = s_addr-low.
it_receivers-rec_type = 'U'.
it_receivers-com_type = 'INT'.
it_receivers-notif_del = 'X'.
it_receivers-notif_ndel = 'X'.
APPEND it_receivers.
CLEAR it_receivers.
ENDLOOP.
CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
EXPORTING
document_data = gd_doc_data
put_in_outbox = 'X'
IMPORTING
sent_to_all = gd_sent_all
TABLES
packing_list = it_packing_list
contents_txt = it_message
receivers = it_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.
IF sy-subrc = 0 .
WAIT UP TO 2 SECONDS.
SUBMIT rsconn01 WITH mode = 'INT'
WITH output = 'X'
AND RETURN.
ENDIF.
ENDFORM. " SEND_EMAIL_MESSAGE
chinaunix网友2010-01-05 15:03:24
不对啊,put_in_outbox = 'X' 应该在SAP邮箱里能看到。明明有记录,但我的提示也是NO MESSGAE SENT 。奇怪!