CO02生產訂單修改記錄
記錄修改
CMOD PPCO0001
EXIT EXIT_SAPLCOBT_001
INCLUDE ZXCO1U01
*&---------------------------------------------------------------------*
*& 包含 ZXCO1U01
*&---------------------------------------------------------------------*
TABLES:caufv,resb.
DATA: BEGIN OF old_resb OCCURS 0, "更改後未儲存之RESB.
aufnr LIKE resb-aufnr,
posnr LIKE resb-posnr,
matnr LIKE resb-matnr,
rsnum LIKE resb-rsnum,
rspos LIKE resb-rspos,
xloek LIKE resb-xloek,
bdmng LIKE resb-bdmng,
objnr LIKE resb-objnr,
END OF old_resb.
DATA: BEGIN OF new_resb OCCURS 0. "資料庫中的RESB.
INCLUDE STRUCTURE old_resb.
DATA: END OF new_resb.
DATA: BEGIN OF obj_resb OCCURS 0. "插入的RESB
INCLUDE STRUCTURE old_resb.
DATA: END OF obj_resb.
DATA: i_zpco02 LIKE zpco002 OCCURS 0 WITH HEADER LINE.
DATA: i_temp LIKE zpco002 OCCURS 0 WITH HEADER LINE.
DATA: iporg LIKE msxxlist-hostadr,
ipdec(16) TYPE c,
host(18) TYPE c.
DATA:char1(20) TYPE c,
char2(20) TYPE c.
DATA: inst_flg TYPE c VALUE 'N',
chan_had TYPE c VALUE 'N'.
CHECK sy-tcode EQ 'CO02'.
** Get user IP,hostname
CALL FUNCTION 'TH_USER_INFO' " Get user IP,hostname
EXPORTING
client = sy-mandt
user = sy-uname
IMPORTING
hostaddr = iporg
terminal = host
EXCEPTIONS
OTHERS = 1.
**"Conv.IP addr to format "xxx.xxx.xxx.xxx"
CALL FUNCTION 'GWY_IPADR2STRING' "Conv.IP addr
EXPORTING
ipadr = iporg
IMPORTING
string = ipdec.
***Common var.
MOVE: sy-mandt TO i_temp-mandt,
sy-uname TO i_temp-aenam,
sy-datum TO i_temp-laeda,
sy-uzeit TO i_temp-times,
sy-tcode TO i_temp-tcode,
ipdec TO i_temp-hostip,
host TO i_temp-host,
header_table-aufnr TO i_temp-aufnr.
SELECT SINGLE gamng gstrp INTO (caufv-gamng, caufv-gstrp)
FROM caufv WHERE aufnr EQ header_table-aufnr.
IF header_table-gamng NE caufv-gamng.
MOVE: caufv-gamng TO char1, header_table-gamng TO char2.
MOVE-CORRESPONDING i_temp TO i_zpco02.
MOVE: '更改工單總數' TO i_zpco02-filed,
'U' TO i_zpco02-chnid,
char1 TO i_zpco02-value_old,
char2 TO i_zpco02-value_new.
APPEND i_zpco02.
inst_flg = 'Y'.
chan_had = 'Y'.
ENDIF.
IF header_table-gstrp NE caufv-gstrp.
MOVE-CORRESPONDING i_temp TO i_zpco02.
MOVE: '更改開工日期' TO i_zpco02-filed,
'U' TO i_zpco02-chnid,
caufv-gstrp TO i_zpco02-value_old,
header_table-gstrp TO i_zpco02-value_new.
APPEND i_zpco02.
inst_flg = 'Y'.
ENDIF.
IF inst_flg = 'Y'.
INSERT zpco002 FROM TABLE i_zpco02 ACCEPTING DUPLICATE KEYS.
inst_flg = 'N'.
ENDIF.
LOOP AT component_table WHERE vbkz EQ 'U'
OR vbkz EQ 'I'
OR vbkz EQ 'D'.
CASE component_table-vbkz.
WHEN 'I'.
MOVE-CORRESPONDING i_temp TO i_zpco02.
MOVE: '新增元件' TO i_zpco02-filed,
'I' TO i_zpco02-chnid,
'' TO i_zpco02-value_old, "old_resb-matnr
component_table-matnr TO i_zpco02-value_new,
'新增的元件' TO i_zpco02-matnr,
component_table-alpos TO i_zpco02-alpos,
sy-tabix TO i_zpco02-loopid.
APPEND i_zpco02.
inst_flg = 'Y'.
WHEN 'D'.
MOVE-CORRESPONDING i_temp TO i_zpco02.
MOVE: '刪除元件' TO i_zpco02-filed,
'D' TO i_zpco02-chnid,
resb-xloek TO i_zpco02-value_old,
component_table-xloek TO i_zpco02-value_new,
component_table-matnr TO i_zpco02-matnr,
component_table-alpos TO i_zpco02-alpos,
sy-tabix TO i_zpco02-loopid.
APPEND i_zpco02.
inst_flg = 'Y'.
WHEN 'U'.
SELECT SINGLE matnr bdmng INTO (resb-matnr, resb-bdmng)
FROM resb WHERE aufnr EQ component_table-aufnr
AND posnr EQ component_table-posnr
AND matnr EQ component_table-matnr
AND rsnum EQ component_table-rsnum
AND rspos EQ component_table-rspos.
IF component_table-matnr NE resb-matnr.
MOVE-CORRESPONDING i_temp TO i_zpco02.
MOVE: '更改元件' TO i_zpco02-filed,
'U' TO i_zpco02-chnid,
resb-matnr TO i_zpco02-value_old,
component_table-matnr TO i_zpco02-value_new,
'更改的工單元件' TO i_zpco02-matnr,
component_table-alpos TO i_zpco02-alpos,
sy-tabix TO i_zpco02-loopid.
APPEND i_zpco02.
inst_flg = 'Y'.
ELSEIF component_table-bdmng NE resb-bdmng.
CHECK chan_had NE 'Y'.
MOVE: component_table-bdmng TO char1, resb-bdmng TO char2.
MOVE-CORRESPONDING i_temp TO i_zpco02.
MOVE: '需求數量' TO i_zpco02-filed,
'U' TO i_zpco02-chnid,
char2 TO i_zpco02-value_old,
char1 TO i_zpco02-value_new,
component_table-matnr TO i_zpco02-matnr,
component_table-alpos TO i_zpco02-alpos,
sy-tabix TO i_zpco02-loopid.
APPEND i_zpco02.
inst_flg = 'Y'.
ENDIF.
ENDCASE.
ENDLOOP.
IF inst_flg = 'Y'.
INSERT zpco002 FROM TABLE i_zpco02 ACCEPTING DUPLICATE KEYS.
IF sy-subrc EQ 0.
inst_flg = 'N'.
chan_had = 'N'.
* MESSAGE ID "ZX" TYPE "W"
* NUMBER "000" WITH "SAP系統已記錄您的更改!".
ENDIF.
ENDIF.
查詢介面
*&---------------------------------------------------------------------*
*& Report ZPPR022
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT zppr022 MESSAGE-ID zhele.
TABLES:zpco002,afko.
DATA: BEGIN OF wa_item,
aufnr LIKE zpco002-aufnr,
matnr LIKE zpco002-matnr,
filed LIKE zpco002-filed,
aenam LIKE zpco002-aenam,
laeda LIKE zpco002-laeda,
chnid LIKE zpco002-chnid,
hostip LIKE zpco002-hostip,
host LIKE zpco002-host,
value_old LIKE zpco002-value_old,
value_new LIKE zpco002-value_new,
times LIKE zpco002-times,
name_last LIKE adrp-name_last,
plnbez LIKE afko-plnbez,
END OF wa_item.
DATA:BEGIN OF gs_afko,
aufnr LIKE afko-aufnr,
plnbez LIKE afko-plnbez,
END OF gs_afko.
DATA:gt_item LIKE TABLE OF wa_item.
DATA:gt_afko LIKE TABLE OF gs_afko.
SELECT-OPTIONS:s_aufnr FOR zpco002-aufnr ,
s_plnbez FOR afko-plnbez,
s_aenam FOR zpco002-aenam,
s_laeda FOR zpco002-laeda,
s_filed FOR zpco002-filed.
DATA: it_fieldcat TYPE slis_t_fieldcat_alv, "lvc_t_fcat, "列描述內表,列清單
wa_fieldcat LIKE LINE OF it_fieldcat,
it_layout TYPE slis_layout_alv. "lvc_s_layo. "表格規格屬性內表
CONSTANTS cns_user_command TYPE slis_formname VALUE 'ALV_USER_COMMAND' .
INITIALIZATION.
START-OF-SELECTION.
SELECT * INTO CORRESPONDING FIELDS OF TABLE gt_item
FROM zpco002 JOIN usr21 ON zpco002~aenam = usr21~bname
LEFT JOIN adrp ON usr21~persnumber = adrp~persnumber
WHERE aufnr IN s_aufnr
AND filed IN s_filed
AND aenam IN s_aenam
AND laeda IN s_laeda
."plnbez
IF gt_item IS INITIAL.
MESSAGE '請輸入查詢條件' TYPE 'I' DISPLAY LIKE 'E'.
ENDIF.
IF s_plnbez[] IS NOT INITIAL .
DATA: lv_tabix LIKE sy-tabix.
SELECT aufnr plnbez INTO TABLE gt_afko FROM afko WHERE plnbez IN s_plnbez.
SORT gt_afko BY aufnr.
LOOP AT gt_item INTO wa_item.
lv_tabix = sy-tabix.
READ TABLE gt_afko WITH KEY aufnr = wa_item-aufnr
BINARY SEARCH TRANSPORTING NO FIELDS.
IF sy-subrc <> 0.
DELETE gt_item INDEX lv_tabix.
CONTINUE.
ENDIF.
CLEAR:lv_tabix.
ENDLOOP.
ENDIF.
DATA : col_pos TYPE i VALUE 1.
CLEAR:it_fieldcat,wa_fieldcat.
it_layout-colwidth_optimize = 'X'.
it_layout-info_fieldname = 'COLOR'.
PERFORM fieldcat_int USING col_pos 'AUFNR' '' '訂單號' '' 'X' '' '' '' ''.
PERFORM fieldcat_int USING col_pos 'MATNR' '' '物料號' '' 'X' '' '' '' ''.
PERFORM fieldcat_int USING col_pos 'FILED' '' '欄位名' '' 'X' '' '' '' ''.
PERFORM fieldcat_int USING col_pos 'AENAM' '' '更改者' '' 'X' '' '' '' ''.
PERFORM fieldcat_int USING col_pos 'NAME_LAST' '' '姓名' '' 'X' '' '' '' ''.
PERFORM fieldcat_int USING col_pos 'LAEDA' '' '更改日期' '' 'X' '' '' '' ''.
PERFORM fieldcat_int USING col_pos 'TIMES' '' '更改時間' '' 'X' '' '' '' ''.
PERFORM fieldcat_int USING col_pos 'VALUE_OLD' '' '舊值' '' 'X' '' '' '' ''.
PERFORM fieldcat_int USING col_pos 'VALUE_NEW' '' '新值' '' 'X' '' '' '' ''.
PERFORM fieldcat_int USING col_pos 'CHNID' '' '更改標識' '' 'X' '' '' '' ''.
PERFORM fieldcat_int USING col_pos 'HOST' '' '主機名' '' 'X' '' '' '' ''.
PERFORM fieldcat_int USING col_pos 'HOSTIP' '' '主機IP地址' '' 'X' '' '' '' ''.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = sy-repid
i_callback_pf_status_set = 'SET_PF_STATUS'
i_callback_user_command = cns_user_command
is_layout = it_layout
it_fieldcat = it_fieldcat
i_save = 'A'
TABLES
t_outtab = gt_item.
FORM set_pf_status USING rt_extab TYPE slis_t_extab.
* 獲取gui狀態
DATA: wa_extab TYPE slis_extab.
* AUTHORITY-CHECK OBJECT 'ZE_ZPPT002'
* ID 'ACTVT' FIELD '01'.
* IF sy-subrc = 0.
* SET PF-STATUS 'OPEN_01' EXCLUDING rt_extab.
* ELSE.
SET PF-STATUS 'OPEN' EXCLUDING rt_extab.
* ENDIF.
ENDFORM.
FORM fieldcat_int USING p_col_pos " 1
p_fieldname " 2
p_key " 3
p_seltext_l " 4
p_edit
p_fix
* p_checkbox
p_no_out
p_tname
p_fname
p_reffi.
wa_fieldcat-col_pos = p_col_pos.
wa_fieldcat-fieldname = p_fieldname.
wa_fieldcat-key = p_key.
* wa_fieldcat-coltext = p_seltext_l.
wa_fieldcat-seltext_l = p_seltext_l.
wa_fieldcat-edit = p_edit.
wa_fieldcat-fix_column = p_fix.
* wa_fieldcat-checkbox = p_checkbox.
wa_fieldcat-no_out = p_no_out.
* wa_fieldcat-colddictxt = 'L'.
wa_fieldcat-ref_tabname = p_tname.
wa_fieldcat-ref_fieldname = p_fname.
wa_fieldcat-qfieldname = p_reffi.
APPEND wa_fieldcat TO it_fieldcat.
p_col_pos = p_col_pos + 1.
CLEAR: wa_fieldcat.
ENDFORM.
FORM alv_user_command USING r_ucomm LIKE sy-ucomm
rs_selfield TYPE slis_selfield.
* CREATE OBJECT g_event_receiver.
* SET HANDLER g_event_receiver->on_f4 FOR g_grid.
* 獲取ALV中的滑鼠勾選記錄
DATA: l_grid TYPE REF TO cl_gui_alv_grid.
CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
IMPORTING
e_grid = l_grid.
CALL METHOD l_grid->check_changed_data.
CASE r_ucomm.
WHEN '&IC1' .
CASE rs_selfield-sel_tab_field.
READ TABLE gt_item INTO wa_item INDEX rs_selfield-tabindex.
WHEN '1-AUFNR'.
SET PARAMETER ID 'ANR' FIELD rs_selfield-value.
SET PARAMETER ID 'AUFNR' FIELD wa_item-aufnr.
CALL TRANSACTION 'CO03' AND SKIP FIRST SCREEN.
ENDCASE.
ENDCASE.
ENDFORM.