业务需求: 按工厂、物料采购类型、特殊采购类型(标准的外部采购)、MRP控制者、计划日期批量转采购申请,取代MD14,MD15。MRP RUN后,定时JOB处理,并在转换后通过邮件发送附件清单通知到采购进行处理。
在生产菜单下阶中,其中一个MDUM-在后台,这是一个后台执行转换的标准程式。
可以看到程式变式名称RMCVPLRQ。SE38执行此程式,界面如下。此标准程式功能已基本满足需求。
1、界面区别:
在此基础上增加:
1、邮件发送功能(附件包含转换成功的申请及失败的错误信息)
2、固定标识默认启用
3、增加特殊采购选项
改造后屏幕效果如下:
2、执行后的功能区别
标准程式:
改造后程式:转换成功清单和错误清单分开显示,也方便后续通过邮件发送清单。
邮件发送附件效果:
3、标准的程式不改动。复制标准程式代码,新增程序名。
REPORT zpp_rpt001 MESSAGE-ID 001.
*--> Globale Variable
TABLES:plaf, t001w,t024d, t100, t141, t399d, t438a,
t439a, mdfd, t450, t450n, t460c, t46at,zmail.
*--> Selektionsbereiche
RANGES: gt_beskz FOR plaf-beskz,
gt_dispo FOR plaf-dispo.
DATA: gs_beskz_wa LIKE LINE OF gt_beskz,
gs_dispo_wa LIKE LINE OF gt_dispo.
*--> Protokoll
TYPES: BEGIN OF messageline,
plnum LIKE plaf-plnum,
msgid LIKE sy-msgid,
msgno LIKE sy-msgno,
msgv1 LIKE sy-msgv1,
msgv2 LIKE sy-msgv2,
msgv3 LIKE sy-msgv3,
msgv4 LIKE sy-msgv4,
END OF messageline.
TYPES: messagetab TYPE messageline OCCURS 0.
*******ALV Type pool declaration
TYPE-POOLS :slis.
*--->Constant for layout save
CONSTANTS: gc_save VALUE 'A'.
*--->constant for optimize colwidth
CONSTANTS: gc_colwidth_optimize TYPE c VALUE 'X'.
*--->Constant for Allow switch to list
CONSTANTS: gc_layout TYPE c VALUE 'X'.
*---> constant for structure name
CONSTANTS: gc_mdpomsg LIKE dd02l-tabname VALUE 'MDALV_POMSG'.
*---> constant for no columns headings
CONSTANTS: gc_no_colhead TYPE c VALUE 'X'.
*---> constant for top of page selection text
CONSTANTS : gc_s TYPE c VALUE 'S'.
*---> constant for top of page header text
CONSTANTS : gc_h TYPE c VALUE 'H'.
*--->ALV Global Declarations
DATA: g_repid LIKE sy-repid.
DATA: g_title LIKE sy-title.
DATA: gt_fieldcat TYPE slis_t_fieldcat_alv.
DATA: gs_layout TYPE slis_layout_alv.
DATA:layout TYPE lvc_s_layo.
DATA: gt_eventtab TYPE slis_t_event,
gt_fieldcat_alv TYPE slis_t_fieldcat_alv WITH HEADER LINE. "定义存放字段信息的内表
*--->Global count variables
DATA: gv_succs(5) TYPE c.
DATA: gv_errors(5) TYPE c.
DATA: gv_pos TYPE i.
DATA: plaf2 LIKE plaf,
mdba TYPE TABLE OF mdba WITH HEADER LINE.
TYPES :
BEGIN OF typ_table,
bannr LIKE mdba-bannr, "采购申请编号
banps LIKE mdba-banps, "采购申请的项目编号
bsart LIKE mdba-bsart, "订单类型(采购)
matnr LIKE mdba-matnr, "物料号
werks LIKE mdba-werks, "工厂
lgort LIKE mdba-lgort, "库存地点
menge LIKE mdba-menge, "待转换的数量
meins LIKE mdba-meins, "基本计量单位
lfdat LIKE mdba-lfdat, "交货日期
frgdt LIKE mdba-frgdt, "采购申请批准日期
webaz LIKE mdba-webaz, "以天计的收货处理时间
ekgrp LIKE mdba-ekgrp, "采购组
dispo LIKE mdba-dispo, "MRP 控制者(物料计划人)
lifnr LIKE mdba-lifnr, "期望的供应商
flief LIKE mdba-flief, "固定的供应商
infnr LIKE mdba-infnr, "采购信息记录的编号
wepos LIKE mdba-wepos, "货物收据标识
repos LIKE mdba-repos, "发票收据标识
ekorg LIKE mdba-ekorg, "采购组织
fixkz LIKE mdba-fixkz, "采购申请是固定的
beskz LIKE mdba-beskz, "采购类型
plifz LIKE mdba-plifz, "计划的天数内交货
END OF typ_table,
BEGIN OF typ_join,
tab1 TYPE tabname,
field1 TYPE fieldname,
tab2 TYPE tabname,
field2 TYPE fieldname,
END OF typ_join.
DATA: gs_variant_h TYPE disvariant,
gs_variant_i TYPE disvariant,
gv_colno TYPE i.
DATA:
go_docking_con TYPE REF TO cl_gui_docking_container,
go_splitter_con TYPE REF TO cl_gui_splitter_container,
go_con_tables TYPE REF TO cl_gui_container,
go_con_top TYPE REF TO cl_gui_splitter_container,
go_con_error TYPE REF TO cl_gui_container,
go_alv_tables TYPE REF TO cl_gui_alv_grid,
go_alv_top TYPE REF TO cl_gui_alv_grid,
go_alv_error TYPE REF TO cl_gui_alv_grid,
ref_container TYPE REF TO cl_gui_container.
DATA:
lt_plaf TYPE TABLE OF typ_table WITH HEADER LINE,
gt_tables TYPE TABLE OF typ_table,
gs_table TYPE typ_table,
gt_joins TYPE TABLE OF typ_join,
gs_join TYPE typ_join.
DATA:
gt_fieldcat_tables TYPE lvc_t_fcat,
gt_fieldcat_joins TYPE lvc_t_fcat,
gs_fieldcat TYPE lvc_s_fcat,
gt_fieldcat1 TYPE lvc_t_fcat,
gs_fieldcaterr TYPE lvc_s_fcat,
gt_fieldcaterr TYPE lvc_t_fcat,
gt_f4_tables TYPE lvc_t_f4,
gt_f4_joins TYPE lvc_t_f4,
gs_f4 TYPE lvc_s_f4,
gt_exclude TYPE ui_functions,
gs_exclude TYPE ui_func.
*&-----------------------------------------------
DATA:ok_code LIKE sy-ucomm.
*--->Internal table for output ALV
DATA:gt_mdpomsg TYPE STANDARD TABLE OF mdalv_pomsg.
DATA:gs_mdpomsg LIKE LINE OF gt_mdpomsg.
*--------------------------------------------------------*
* Mail related declarations
*--------------------------------------------------------*
CONSTANTS:
con_tab TYPE c VALUE cl_abap_char_utilities=>horizontal_tab,
con_cret TYPE c VALUE cl_abap_char_utilities=>cr_lf.
DATA send_request TYPE REF TO cl_bcs.
DATA document TYPE REF TO cl_document_bcs.
DATA recipient TYPE REF TO if_recipient_bcs.
DATA bcs_exception TYPE REF TO cx_bcs.
DATA main_text TYPE bcsy_text.
DATA: binary_content TYPE solix_tab,
binary_content1 TYPE solix_tab.
DATA: size TYPE so_obj_len,
size2 TYPE so_obj_len.
DATA sent_to_all TYPE os_boolean.
DATA : email_addr LIKE TABLE OF zmailadd WITH HEADER LINE.
*--> Gemeinsame Inlcudes mit der Online-Transaktion
INCLUDE: mm61xval, "Konstanten der Bedarfsplanung
mm61pf10. "Pruefroutinen fuer Werk/Disponent
*-------------------------------
*--> Parameters
*-------------------------------
SELECTION-SCREEN BEGIN OF BLOCK sl_par WITH FRAME TITLE text-s01.
PARAMETERS: pv_werks LIKE rm61p-werks OBLIGATORY MEMORY ID wrk DEFAULT '1000',
pv_dispo LIKE rm61p-dispo MEMORY ID dgr DEFAULT 'AM1',
pv_pertr LIKE rm61p-pertr OBLIGATORY DEFAULT sy-datlo,
pv_beskz LIKE rm61p-beskz DEFAULT 'F',
pv_sobes LIKE rm61p-esobs DEFAULT '0'.
SELECTION-SCREEN SKIP.
SELECT-OPTIONS pt_matnr FOR plaf-matnr.
PARAMETERS: p_chk AS CHECKBOX DEFAULT 'X'.
SELECTION-SCREEN END OF BLOCK sl_par.
SELECTION-SCREEN BEGIN OF BLOCK vd_par WITH FRAME TITLE text-s02.
PARAMETERS: pv_fixkz LIKE rm61p-fixkz DEFAULT 'X',
pv_kzzuo LIKE rm61p-kzzuo.
SELECTION-SCREEN END OF BLOCK vd_par.
*--->ALV Variable initialization
INITIALIZATION.
g_repid = sy-repid.
g_title = sy-title.
*--> Selektionsparameter ueberpruefen
AT SELECTION-SCREEN ON pv_werks.
PERFORM read_t001w USING pv_werks.
AT SELECTION-SCREEN ON pv_dispo.
IF NOT pv_dispo IS INITIAL.
PERFORM read_t024d USING pv_werks pv_dispo.
ENDIF.
*--> Eigentliche Umsetzung
START-OF-SELECTION.
PERFORM convert_pl_orders.
END-OF-SELECTION.
*MAIL相關程式碼
IF p_chk = 'X'.
IF lt_plaf[] IS NOT INITIAL OR gt_mdpomsg IS NOT INITIAL.
PERFORM create_content.
PERFORM send.
ENDIF.
ENDIF.
"输出100屏幕
CALL SCREEN 100.
*-------------------------------------*
* CONVERT_PL_ORDERS *
* *
* Der Funktionsbaustein MD_PLANNED_ORDER_2_REQUISITION macht einen *
* Commit. Damit darf er nicht innerhalb einer Select-Schleife stehen. *
* Um das Problem zu umgehen werden Pakete von 100 Planauftraegen *
* in eine interne Tabelle gelesen und anschließend verarbeitet. *
*----------------------------------------------------------------------*
FORM convert_pl_orders.
DATA: ls_cm61o LIKE cm61o,
lt_plnum LIKE plaf-plnum OCCURS 0,
ls_plaf LIKE plaf,
lv_plnum LIKE plaf-plnum,
lv_errors TYPE i,
lv_succs TYPE i,
lt_messages TYPE messagetab.
*--> Zaehler initialisieren
lv_errors = 0.
lv_succs = 0.
*--->Initialization of global count variables.
gv_errors = 0.
gv_succs = 0.
*--> Steuerparameter setzen
CLEAR ls_cm61o.
ls_cm61o-trtyp = 'V'. "Change
ls_cm61o-lockx = 'X'. "Lock planned order
ls_cm61o-autho = 'X'. "Authority check durchfuehren
ls_cm61o-stpre = 'V'. " 'VC' Change but no Save
ls_cm61o-wtpst = 'X'."Wait for time stamp
ls_cm61o-darkx = 'I'. "Abwicklung dunkel "警告跳过
ls_cm61o-nodia = 'X'. "No Dialog screen(BkGrnd)
*--> Initialisierung
CLEAR lt_plnum. REFRESH lt_plnum.
CLEAR gt_beskz. REFRESH gt_beskz.
CLEAR gt_dispo. REFRESH gt_dispo.
*--> Selektionstabellen aufbauen
IF NOT pv_dispo IS INITIAL.
CLEAR gs_dispo_wa.
gs_dispo_wa-sign = 'I'.
gs_dispo_wa-option = 'EQ'.
gs_dispo_wa-low = pv_dispo.
APPEND gs_dispo_wa TO gt_dispo.
ENDIF.
IF pv_beskz EQ beskze
OR pv_beskz EQ beskzf.
CLEAR gs_beskz_wa.
gs_beskz_wa-sign = 'I'.
gs_beskz_wa-option = 'EQ'.
gs_beskz_wa-low = pv_beskz.
APPEND gs_beskz_wa TO gt_beskz.
ENDIF.
*--> zunaechst alle Planauftragsnummer selektieren
SELECT plnum INTO TABLE lt_plnum
FROM plaf
WHERE matnr IN pt_matnr
AND plwrk EQ pv_werks
AND dispo EQ pv_dispo " gt_dispo
AND beskz EQ pv_beskz "IN gt_beskz
AND sobes EQ pv_sobes
AND plscn EQ '000'
AND umskz EQ charx
AND pertr GE pv_pertr.
*--> Lesen und umsetzen der Planauftraege
LOOP AT lt_plnum INTO lv_plnum.
SELECT SINGLE * FROM plaf
INTO ls_plaf
WHERE plnum EQ lv_plnum.
IF sy-subrc NE 0.
CONTINUE.
ENDIF.
PERFORM convert_pl_order USING ls_plaf
ls_cm61o
CHANGING lv_errors
lv_succs
lt_messages.
ENDLOOP.
*--> Ausgabe Protokoll
PERFORM show_errors USING lv_succs lv_errors lt_messages.
*--->ALV conversion starts
ENDFORM. "CONVERT_PL_ORDERS
*----------------------------------------------------------------------*
* CONVERT_PL_ORDER *
*----------------------------------------------------------------------*
FORM convert_pl_order
USING VALUE(is_plaf) LIKE plaf
is_cm61o LIKE cm61o
CHANGING cv_errors TYPE i
cv_succs TYPE i
ct_messages TYPE messagetab.
DATA: ls_message TYPE messageline.
*--> Fixierungskennzeichen
IF pv_fixkz = 'X'.
is_plaf-auffx = 'X'.
ENDIF.
*--> Planauftrag in Banf umsetzen
CALL FUNCTION 'MD_PLANNED_ORDER_2_REQUISITION'
EXPORTING
plaf1 = is_plaf
cm61o = is_cm61o
findsource = pv_kzzuo
IMPORTING
plaf2 = plaf2
mdba2 = mdba
EXCEPTIONS
error = 1.
*--> Protokoll falls Fehler
IF sy-subrc > 0.
ls_message-plnum = is_plaf-plnum.
ls_message-msgid = sy-msgid.
ls_message-msgno = sy-msgno.
ls_message-msgv1 = sy-msgv1.
ls_message-msgv2 = sy-msgv2.
ls_message-msgv3 = sy-msgv3.
ls_message-msgv4 = sy-msgv4.
APPEND ls_message TO ct_messages.
cv_errors = cv_errors + 1.
ELSE.
cv_succs = cv_succs + 1.
MOVE-CORRESPONDING mdba TO lt_plaf.
APPEND lt_plaf.
ENDIF.
ENDFORM. "CONVERT_PL_ORDER
*----------------------------------------------------------------------*
* SHOW_ERRORS *
*----------------------------------------------------------------------*
FORM show_errors
USING iv_succs TYPE i
iv_errors TYPE i
it_messages TYPE messagetab.
DATA: ls_message TYPE messageline,
lv_error LIKE sy-lisel.
LEAVE TO LIST-PROCESSING.
* WRITE: / 'Erfolgreich umgesetzt:'(001), IV_SUCCS.
* WRITE: / 'Fehler beim Umsetzen: '(002), IV_ERRORS.
*--->Move processed count to respective variables
MOVE iv_succs TO gv_succs.
MOVE iv_errors TO gv_errors.
IF iv_errors > 0.
* SKIP.
* WRITE: / 'Folgende Fehler sind aufgetreten:'(003).
LOOP AT it_messages INTO ls_message.
CALL FUNCTION 'RPY_MESSAGE_COMPOSE'
EXPORTING
message_id = ls_message-msgid
message_number = ls_message-msgno
message_var1 = ls_message-msgv1
message_var2 = ls_message-msgv2
message_var3 = ls_message-msgv3
message_var4 = ls_message-msgv4
IMPORTING
message_text = lv_error
EXCEPTIONS
message_not_found = 1.
IF sy-subrc = 0.
* WRITE: / 'Planauftrag'(004), LS_MESSAGE-PLNUM, ':', LV_ERROR.
*-->Moving planned order number and formated message to internal table
*--> for ALV display
MOVE ls_message-plnum TO gs_mdpomsg-plnum.
MOVE lv_error TO gs_mdpomsg-baltmsg.
APPEND gs_mdpomsg TO gt_mdpomsg.
ENDIF.
ENDLOOP.
ENDIF.
ENDFORM. "SHOW_ERRORS
*&---------------------------------------------------------------------
*& Form OUTPUT_ALV
*&---------------------------------------------------------------------
* This subroutine contains all the necessary form routines for
* ALV conversion
*----------------------------------------------------------------------
FORM output_alv .
*--->This routine is to prepare fieldcatlog
PERFORM fieldcat_alv_build CHANGING gt_fieldcat.
*-->This routine is to handle layout events
PERFORM layout_alv_build CHANGING gs_layout.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = g_repid
it_fieldcat = gt_fieldcat
i_save = gc_save
is_layout = gs_layout
" it_events = gt_eventtab
TABLES
t_outtab = gt_mdpomsg
EXCEPTIONS
program_error = 1
OTHERS = 2.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
ENDFORM. " OUTPUT_ALV
*&---------------------------------------------------------------------
*& Form FIELDCAT_INIT_BUILD
*&---------------------------------------------------------------------
* This subroutine is to prepare a fieldcatlog
*----------------------------------------------------------------------
* XT_FIELDCAT This is for storing fieldcatlog properties
*----------------------------------------------------------------------
FORM fieldcat_alv_build CHANGING xt_fieldcat TYPE slis_t_fieldcat_alv.
CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
EXPORTING
i_program_name = g_repid
i_structure_name = gc_mdpomsg
CHANGING
ct_fieldcat = xt_fieldcat
EXCEPTIONS
inconsistent_interface = 1
program_error = 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.
ENDFORM. " FIELDCAT_ALV_BUILD
*&---------------------------------------------------------------------*
*& Form LAYOUT_ALV_BUILD
*&---------------------------------------------------------------------*
* This subroutine is to have the possibility to switch from ALV
* fullscreen grid to simle list and optimizes column width
*----------------------------------------------------------------------*
* <--XS_LAYOUT Layout structure
*----------------------------------------------------------------------*
FORM layout_alv_build CHANGING xs_layout TYPE slis_layout_alv.
xs_layout-allow_switch_to_list = gc_layout.
xs_layout-colwidth_optimize = gc_colwidth_optimize.
*if there are no error records suppress col headers
IF gv_errors = 0.
xs_layout-no_colhead = gc_no_colhead.
ENDIF.
ENDFORM. " LAYOUT_ALV_BUILD
FORM frm_alv_set_columns .
REFRESH gt_fieldcat_alv.
PERFORM frm_set_l_fieldcat USING:
'BANNR' '采购申请编号',
'BANPS' '申请项目编号 ',
'BSART' '订单类型(采购)',
'MATNR' '物料号 ',
'WERKS' '工厂',
'LGORT' '库存地点',
'MENGE' '待转换的数量',
'MEINS' '基本计量单位',
'LFDAT' '交货日期',
'FRGDT' '采购申请批准日期',
'WEBAZ' '以天计的收货处理时间',
'EKGRP' '采购组 ',
'DISPO' 'MRP 控制者',
'LIFNR' '期望的供应商',
'FLIEF' '固定的供应商',
'INFNR' '信息记录编号 ',
'EKORG' '采购组织',
'WEPOS' '货物收据标识',
'REPOS' '发票收据标识',
'EKORG' '采购组织',
'FIXKZ' '采购申请是固定的',
'BESKZ' '采购类型',
'PLIFZ' '计划的天数内交货'.
ENDFORM.
FORM frm_set_l_fieldcat USING pv_name pv_textl.
DATA: ls_fieldcat TYPE slis_fieldcat_alv.
gv_pos = gv_pos + 1.
ls_fieldcat-col_pos = gv_pos.
ls_fieldcat-fieldname = pv_name.
ls_fieldcat-seltext_l = pv_textl.
ls_fieldcat-no_zero = 'X'.
APPEND ls_fieldcat TO gt_fieldcat_alv.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form GET_FIELDCAT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM get_fieldcat .
CLEAR gs_fieldcat.
gs_fieldcat-col_pos = 1.
gs_fieldcat-fieldname = 'BANNR'.
gs_fieldcat-scrtext_m = '采购申请编号'.
APPEND gs_fieldcat TO gt_fieldcat1.
CLEAR gs_fieldcat.
gs_fieldcat-col_pos = 2.
gs_fieldcat-fieldname = 'BANPS'.
gs_fieldcat-scrtext_m = '申请项目行号'.
APPEND gs_fieldcat TO gt_fieldcat1.
CLEAR gs_fieldcat.
gs_fieldcat-col_pos = 3.
gs_fieldcat-fieldname = 'BSART'.
gs_fieldcat-scrtext_m = '订单类型(采购)'.
APPEND gs_fieldcat TO gt_fieldcat1.
CLEAR gs_fieldcat.
gs_fieldcat-col_pos = 4.
gs_fieldcat-fieldname = 'MATNR'.
gs_fieldcat-scrtext_m = '物料号'.
APPEND gs_fieldcat TO gt_fieldcat1.
CLEAR gs_fieldcat.
gs_fieldcat-col_pos = 5.
gs_fieldcat-fieldname = 'WERKS'.
gs_fieldcat-scrtext_m = '工厂'.
APPEND gs_fieldcat TO gt_fieldcat1.
CLEAR gs_fieldcat.
gs_fieldcat-col_pos = 6.
gs_fieldcat-fieldname = 'LGORT'.
gs_fieldcat-scrtext_m = '库存地点'.
APPEND gs_fieldcat TO gt_fieldcat1.
CLEAR gs_fieldcat.
gs_fieldcat-col_pos = 7.
gs_fieldcat-fieldname = 'MENGE'.
gs_fieldcat-scrtext_m = '待转换的数量'.
APPEND gs_fieldcat TO gt_fieldcat1.
CLEAR gs_fieldcat.
gs_fieldcat-col_pos = 8.
gs_fieldcat-fieldname = 'MEINS'.
gs_fieldcat-scrtext_m = '基本计量单位'.
APPEND gs_fieldcat TO gt_fieldcat1.
CLEAR gs_fieldcat.
gs_fieldcat-col_pos = 9.
gs_fieldcat-fieldname = 'LFDAT'.
gs_fieldcat-scrtext_m = '交货日期'.
APPEND gs_fieldcat TO gt_fieldcat1.
CLEAR gs_fieldcat.
gs_fieldcat-col_pos = 10.
gs_fieldcat-fieldname = 'FRGDT'.
gs_fieldcat-scrtext_m = '批准日期'.
APPEND gs_fieldcat TO gt_fieldcat1.
CLEAR gs_fieldcat.
gs_fieldcat-col_pos = 11.
gs_fieldcat-fieldname = 'WEBAZ'.
gs_fieldcat-scrtext_m = '收货处理时间'.
APPEND gs_fieldcat TO gt_fieldcat1.
CLEAR gs_fieldcat.
gs_fieldcat-col_pos = 12.
gs_fieldcat-fieldname = 'EKGRP'.
gs_fieldcat-scrtext_m = '采购组'.
APPEND gs_fieldcat TO gt_fieldcat1.
CLEAR gs_fieldcat.
gs_fieldcat-col_pos = 13.
gs_fieldcat-fieldname = 'DISPO'.
gs_fieldcat-scrtext_m = 'MRP控制者'.
APPEND gs_fieldcat TO gt_fieldcat1.
CLEAR gs_fieldcat.
gs_fieldcat-col_pos = 14.
gs_fieldcat-fieldname = 'LIFNR'.
gs_fieldcat-scrtext_m = '期望的供应商'.
APPEND gs_fieldcat TO gt_fieldcat1.
CLEAR gs_fieldcat.
gs_fieldcat-col_pos = 15.
gs_fieldcat-fieldname = 'FLIEF'.
gs_fieldcat-scrtext_m = '固定的供应商'.
APPEND gs_fieldcat TO gt_fieldcat1.
CLEAR gs_fieldcat.
gs_fieldcat-col_pos = 16.
gs_fieldcat-fieldname = 'INFNR'.
gs_fieldcat-scrtext_m = '信息记录编号'.
APPEND gs_fieldcat TO gt_fieldcat1.
CLEAR gs_fieldcat.
gs_fieldcat-col_pos = 17.
gs_fieldcat-fieldname = 'EKORG'.
gs_fieldcat-scrtext_m = '采购组织'.
APPEND gs_fieldcat TO gt_fieldcat1.
CLEAR gs_fieldcat.
gs_fieldcat-col_pos = 18.
gs_fieldcat-fieldname = 'WEPOS'.
gs_fieldcat-scrtext_m = '货物收据标识'.
APPEND gs_fieldcat TO gt_fieldcat1.
CLEAR gs_fieldcat.
gs_fieldcat-col_pos = 19.
gs_fieldcat-fieldname = 'REPOS'.
gs_fieldcat-scrtext_m = '发票收据标识'.
APPEND gs_fieldcat TO gt_fieldcat1.
CLEAR gs_fieldcat.
gs_fieldcat-col_pos = 20.
gs_fieldcat-fieldname = 'FIXKZ'.
gs_fieldcat-scrtext_m = '申请固定标识'.
APPEND gs_fieldcat TO gt_fieldcat1.
CLEAR gs_fieldcat.
gs_fieldcat-col_pos = 21.
gs_fieldcat-fieldname = 'BESKZ'.
gs_fieldcat-scrtext_m = '采购类型'.
APPEND gs_fieldcat TO gt_fieldcat1.
CLEAR gs_fieldcat.
gs_fieldcat-col_pos = 22.
gs_fieldcat-fieldname = 'PLIFZ'.
gs_fieldcat-scrtext_m = '计划交货时间'.
APPEND gs_fieldcat TO gt_fieldcat1.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form GET_FIELDCATERROR
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM get_fieldcaterror .
CLEAR gs_fieldcaterr.
gs_fieldcaterr-col_pos = 1.
gs_fieldcaterr-fieldname = 'PLNUM'.
gs_fieldcaterr-scrtext_m = '计划单号'.
APPEND gs_fieldcaterr TO gt_fieldcaterr.
CLEAR gs_fieldcaterr.
gs_fieldcaterr-col_pos = 2.
gs_fieldcaterr-fieldname = 'BALTMSG'.
gs_fieldcaterr-scrtext_m = '错误消息'.
APPEND gs_fieldcaterr TO gt_fieldcaterr.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form SHOWDLV
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM showdlv .
" CHECK go_docking_con IS INITIAL.
"创建容器
CREATE OBJECT go_docking_con
EXPORTING
repid = sy-repid
dynnr = sy-dynnr
extension = 1200 "alv宽度
ratio = 0
metric = 0.
"拆分为上、下
CREATE OBJECT go_splitter_con
EXPORTING
parent = go_docking_con
rows = 2
columns = 1.
go_splitter_con->set_column_width( EXPORTING id = 1 width = 1000 ).
"创建已成功的ALV
go_con_tables = go_splitter_con->get_container( row = 1 column = 1 ).
CREATE OBJECT go_alv_tables
EXPORTING
i_parent = go_con_tables.
"创建失败的的ALV
go_con_error = go_splitter_con->get_container( row = 2 column = 1 ).
CREATE OBJECT go_alv_error
EXPORTING
i_parent = go_con_error.
"显示ALV
PERFORM alv_prepare_layout CHANGING layout.
PERFORM get_fieldcat.
layout-grid_title = '表清单【已转】'.
CALL METHOD go_alv_tables->set_table_for_first_display
EXPORTING
is_layout = layout
i_save = 'A'
i_default = 'X' "允许定义默认布局
CHANGING
it_outtab = lt_plaf[]
it_fieldcatalog = gt_fieldcat1[].
PERFORM get_fieldcaterror.
layout-grid_title = '表清单【错误】'.
CALL METHOD go_alv_error->set_table_for_first_display
EXPORTING
is_layout = layout
i_save = 'A'
i_default = 'X' "允许定义默认布局
CHANGING
it_outtab = gt_mdpomsg[]
it_fieldcatalog = gt_fieldcaterr[].
ENDFORM.
*&---------------------------------------------------------------------*
*& Form ALV_PREPARE_LAYOUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* <--P_LAYOUT text
*----------------------------------------------------------------------*
FORM alv_prepare_layout CHANGING ps_layout TYPE lvc_s_layo.
ps_layout-zebra = 'X'.
ps_layout-sel_mode = 'A'.
ps_layout-smalltitle = 'X'.
ps_layout-cwidth_opt = 'X'.
ENDFORM. "alv_prepare_layout
*&---------------------------------------------------------------------*
*& Module STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE status_0100 OUTPUT.
SET PF-STATUS 'ZSTANDARD'.
SET TITLEBAR 'ZTITLE'.
ENDMODULE.
*&---------------------------------------------------------------------*
*& Module ALV_DISPLAY OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE alv_display OUTPUT.
PERFORM showdlv.
ENDMODULE.
*&---------------------------------------------------------------------*
*& Module USER_COMMAND_0100 INPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE user_command_0100 INPUT.
DATA: code100 LIKE sy-ucomm.
code100 = ok_code.
CLEAR:ok_code.
CASE code100.
WHEN 'BACK'.
LEAVE TO SCREEN 0.
WHEN 'UP'.
LEAVE TO SCREEN 0.
WHEN 'EXIT'.
LEAVE TO SCREEN 0.
ENDCASE.
ENDMODULE.
*&---------------------------------------------------------------------*
*& Form CREATE_CONTENT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM create_content .
CONSTANTS: gc_tab TYPE c VALUE cl_bcs_convert=>gc_tab,
gc_crlf TYPE c VALUE cl_bcs_convert=>gc_crlf.
DATA:lv_dzeit TYPE string,
lv_days TYPE string,
lv_plifz TYPE string,
lv_menge(17).
DATA: lv_string1 TYPE string,
lv_string2 TYPE string,
gv_mat TYPE string,
lv_line TYPE string,
gv_mat1 TYPE string,
lv_line1 TYPE string.
CONCATENATE '采购申请编号' '申请项目编号 ' '订单类型(采购)' '物料号 ' '工厂' '库存地点' '待转换的数量'
'基本计量单位' '交货日期' '采购申请批准日期' '以天计的收货处理时间' '采购组 ' 'MRP控制者' '期望的供应商'
'固定的供应商' '信息记录编号 ' '采购组织' '货物收据标识' '发票收据标识' '采购组织' '采购申请是固定的' '采购类型'
'计划的天数内交货'
INTO lv_line SEPARATED BY gc_tab .
CONCATENATE gv_mat lv_line gc_crlf INTO gv_mat.
LOOP AT lt_plaf.
lv_menge = lt_plaf-menge.
lv_days = lt_plaf-webaz.
lv_plifz = lt_plaf-plifz.
CONCATENATE lt_plaf-bannr
lt_plaf-banps
lt_plaf-bsart
lt_plaf-matnr
lt_plaf-werks
lt_plaf-lgort
lv_menge
lt_plaf-meins
lt_plaf-lfdat
lt_plaf-frgdt
lv_days
lt_plaf-ekgrp
lt_plaf-dispo
lt_plaf-lifnr
lt_plaf-flief
lt_plaf-infnr
lt_plaf-ekorg
lt_plaf-wepos
lt_plaf-repos
lt_plaf-ekorg
lt_plaf-fixkz
lt_plaf-beskz
lv_plifz
INTO lv_line SEPARATED BY gc_tab .
CONCATENATE gv_mat lv_line gc_crlf INTO gv_mat.
ENDLOOP.
"标题
CONCATENATE
'计划订单号' '消息反馈'
INTO lv_line1 SEPARATED BY gc_tab.
* 换行
CONCATENATE gv_mat1 lv_line1 gc_crlf INTO gv_mat1.
LOOP AT gt_mdpomsg INTO DATA(gs_mdpomsg).
. CONCATENATE gs_mdpomsg-plnum
gs_mdpomsg-baltmsg
INTO lv_line1 SEPARATED BY gc_tab.
* 换行
CONCATENATE gv_mat1 lv_line1 gc_crlf INTO gv_mat1.
ENDLOOP.
CLEAR lv_line.
CLEAR lv_line1.
* --------------------------------------------------------------
* convert the text string into UTF-16LE binary data including
* byte-order-mark. Mircosoft Excel prefers these settings
* all this is done by new class cl_bcs_convert (see note 1151257)
TRY.
cl_bcs_convert=>string_to_solix(
EXPORTING
iv_string = gv_mat " lv_string1
iv_codepage = '4103' "suitable for MS Excel, leave empty
iv_add_bom = 'X' "for other doc types
IMPORTING
et_solix = binary_content
ev_size = size ).
CATCH cx_bcs.
MESSAGE e445(so).
ENDTRY.
TRY.
cl_bcs_convert=>string_to_solix(
EXPORTING
iv_string = gv_mat1 " lv_string1
iv_codepage = '4103' "suitable for MS Excel, leave empty
iv_add_bom = 'X' "for other doc types
IMPORTING
et_solix = binary_content1
ev_size = size2 ).
CATCH cx_bcs.
MESSAGE e445(so).
ENDTRY.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form SEND
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM send .
TRY.
* -------- create persistent send request ------------------------
send_request = cl_bcs=>create_persistent( ).
* -------- create and set document with attachment ---------------
* create document object from internal table with text
APPEND 'Dear All:' TO main_text.
APPEND ' ' TO main_text.
APPEND ' 计划订单转换采购申请明细,' TO main_text.
APPEND ' ' TO main_text.
APPEND ' 詳情請見附檔, 謝謝.' TO main_text.
APPEND ' ' TO main_text.
APPEND ' 未转换物料清单务必查看!无数据则忽略,反之需手动处理' TO main_text.
APPEND ' ' TO main_text.
APPEND ' 此為SAP系統自動發信功能, 請勿直接回覆, 謝謝.'
TO main_text.
DATA: wa_subject TYPE so_obj_des,
p_lines TYPE i.
wa_subject = '[JOB]计划订单转换采购申请明细'.
document = cl_document_bcs=>create_document(
i_type = 'RAW'
i_text = main_text
i_subject = wa_subject ).
* add the spread sheet as attachment to document object
document->add_attachment(
i_attachment_type = 'xls' "#EC NOTEXT
i_attachment_subject = '已转采购申请清单' "#EC NOTEXT
i_attachment_size = size
i_att_content_hex = binary_content ).
document->add_attachment(
i_attachment_type = 'xls' "#EC NOTEXT
i_attachment_subject = '未转换清单' "文件名称
i_attachment_size = size2
i_att_content_hex = binary_content1 ).
* add document object to send request
send_request->set_document( document ).
* --------- add recipient (e-mail address) -----------------------
** create recipient object
DATA:mailto TYPE ad_smtpadr.
* recipient = cl_cam_address_bcs=>create_internet_address( mailto
*).
*
** add recipient object to send request
* send_request->add_recipient( recipient ).
SELECT * FROM zmail INTO CORRESPONDING FIELDS OF TABLE email_addr WHERE spec2 = ' 条件 '.
"自定义邮件列表 地址和分类两个栏位,自己可建立表
IF email_addr[] IS NOT INITIAL .
LOOP AT email_addr.
mailto = email_addr-spec1.
recipient = cl_cam_address_bcs=>create_internet_address( mailto ).
send_request->add_recipient( recipient ).
ENDLOOP.
ENDIF.
* ---------- send document ---------------------------------------
sent_to_all = send_request->send( i_with_error_screen = 'X' ).
COMMIT WORK.
IF sent_to_all IS INITIAL.
MESSAGE i500(sbcoms) WITH mailto.
ELSE.
MESSAGE s022(so).
ENDIF.
* ------------ exception handling ----------------------------------
* replace this rudimentary exception handling with your own one !!!
CATCH cx_bcs INTO bcs_exception.
MESSAGE i865(so) WITH bcs_exception->error_type.
ENDTRY.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form GET_FIELDCATSCR
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM get_fieldcatscr .
CLEAR gs_fieldcat.
gs_fieldcat-col_pos = 1.
gs_fieldcat-fieldname = 'WERKS'.
gs_fieldcat-scrtext_m = '工厂'.
APPEND gs_fieldcat TO gt_fieldcat1.
CLEAR gs_fieldcat.
gs_fieldcat-col_pos = 2.
gs_fieldcat-fieldname = 'SPEC1'.
gs_fieldcat-scrtext_m = '地址'.
APPEND gs_fieldcat TO gt_fieldcat1.
ENDFORM.