*&---------------------------------------------------------------------*
*& Report ZPPR016
*&
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*& *Work In Process Report
*&Modify by on 20130408 *
*& *
*& add by rainy on 20150720-增加数据保存自建表 DEVK905345 &
*&---------------------------------------------------------------------*
REPORT zppr016 NO STANDARD PAGE HEADING.
TABLES: afko,afpo,resb,jest,pordarch,tj02t,mara,mkpf,mseg,mbew.
DATA: BEGIN OF itab OCCURS 0,
aufnr LIKE afko-aufnr, "Order Number
zzlot_no LIKE aufk-zzlot_no, "订单批号
model LIKE afpo-matnr, "Material for Order
gmein LIKE afpo-meins,
psmng LIKE resb-enmng, "Order quantity
wemng LIKE resb-enmng, "Qty of goods received
* posnr LIKE resb-posnr,
rspos LIKE resb-rspos,
matnr LIKE resb-matnr, "Material Number
mtart LIKE mara-mtart,"物料类型
werks LIKE resb-werks, "Plant
lgort LIKE resb-lgort, "库存地点
maktx LIKE makt-maktx,
meins LIKE resb-meins, "Base Unit of Measure
usage TYPE p DECIMALS 6, "Usage
bdmng LIKE resb-bdmng, "Requirement Quantity
enmng LIKE resb-enmng, "Quantity withdrawn
dmbtr LIKE mseg-dmbtr, "MSEG LOCAL AMOUNT
openq LIKE resb-enmng, "Open qty
erfmg LIKE resb-enmng, "(F/G#ntry#ty)
wipqty LIKE resb-enmng, "WIP Qty
wipamt LIKE mseg-dmbtr, "WIP LOCAL AMOUNT
END OF itab.
TYPE-POOLS: slis.
DATA: i_fieldcat TYPE slis_t_fieldcat_alv,
l_fieldcat TYPE slis_fieldcat_alv,
xevents TYPE slis_t_event,
ls_event TYPE slis_alv_event,
gt_event TYPE slis_t_event,
gs_event TYPE slis_alv_event,
alv_layout TYPE slis_layout_alv ,
slis_ev_top TYPE slis_formname VALUE 'TOP-OF-PAGE'.
DATA: v_repid TYPE sy-repid.
DATA: gs_tabname_header TYPE slis_tabname.
DATA: wa_t001w LIKE t001w.
SELECTION-SCREEN BEGIN OF BLOCK pd WITH FRAME TITLE text-123.
*PARAMETERS: plant TYPE afpo-dwerk OBLIGATORY MEMORY ID wrk.
SELECT-OPTIONS:
plant FOR afpo-dwerk MEMORY ID wrk,
s_dispo FOR afko-dispo,
* s_laufnr FOR afko-lead_aufnr NO-DISPLAY,
s_aufnr FOR afpo-aufnr MEMORY ID auf,
s_matnr FOR afpo-matnr,
p_matnr FOR resb-matnr,
s_gstrp FOR afko-gstrp,
s_wipqty FOR resb-bdmng,
s_grund FOR mseg-grund NO-DISPLAY.
PARAMETERS:
cutoff TYPE sy-datum DEFAULT sy-datum,
wip_tol TYPE p DECIMALS 3 DEFAULT 1.
*PARAMETERS: net_wip AS CHECKBOX.
*SELECTION-SCREEN COMMENT /1(79) text-124.
*SELECTION-SCREEN COMMENT /1(79) text-125.
SELECTION-SCREEN END OF BLOCK pd.
SELECTION-SCREEN BEGIN OF BLOCK b2 WITH FRAME TITLE text-002 . " '说明'.
PARAMETERS:p_sel TYPE c AS CHECKBOX.
SELECTION-SCREEN END OF BLOCK b2.
INITIALIZATION.
AT SELECTION-SCREEN OUTPUT.
AT SELECTION-SCREEN.
SELECT * INTO wa_t001w FROM t001w WHERE werks IN plant.
AUTHORITY-CHECK OBJECT 'ZOBJECT' ID 'WERKS' FIELD wa_t001w-werks.
IF sy-subrc = 4.
MESSAGE e014(zmsg) WITH wa_t001w-werks.
ENDIF.
ENDSELECT.
IF cutoff <> sy-datum.
cutoff = sy-datum.
MESSAGE 'Curren Date被重置,请检查!' TYPE 'S'.
ENDIF.
START-OF-SELECTION.
* break misd11.
PERFORM get_all_data.
gs_tabname_header = 'ITAB'.
v_repid = sy-repid.
PERFORM alv_merge.
PERFORM build_fieldcat.
PERFORM alv_display.
*&---------------------------------------------------------------------*
*& Form ALV_MERGE
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM alv_merge.
CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
EXPORTING
i_program_name = v_repid
i_internal_tabname = gs_tabname_header
* I_STRUCTURE_NAME =
i_client_never_display = 'X'
i_inclname = v_repid
* I_BYPASSING_BUFFER =
* I_BUFFER_ACTIVE =
CHANGING
ct_fieldcat = i_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. "ALV_MERGE
*&---------------------------------------------------------------------*
*& Form ALV_DISPLAY
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM alv_display.
* Configure layout of screen
alv_layout-colwidth_optimize = 'X'.
alv_layout-zebra = ''.
alv_layout-no_min_linesize = 'X'.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
* I_INTERFACE_CHECK = ' '
i_bypassing_buffer = 'X'
i_buffer_active = ' '
i_callback_program = v_repid
* i_callback_top_of_page = 'TOP-OF-HEAD'
i_callback_pf_status_set = 'SET_PF_STATUS'
i_callback_user_command = 'USERCOMMAND'
* I_STRUCTURE_NAME =
is_layout = alv_layout
it_fieldcat = i_fieldcat
i_save = 'A'
it_events = gt_event[]
TABLES
t_outtab = itab
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. "ALV_DISPLAY
*&---------------------------------------------------------------------*
*& Form set_pf_status
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->RT_EXTAB text
*----------------------------------------------------------------------*
FORM set_pf_status USING rt_extab TYPE slis_t_extab.
SET PF-STATUS 'STATUS01'.
ENDFORM. "Set_pf_status
*&---------------------------------------------------------------------*
*& Form usercommand
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->IP_UCOMM text
* -->RS_SELFIELD text
*----------------------------------------------------------------------*
FORM usercommand USING ip_ucomm LIKE sy-ucomm
rs_selfield TYPE slis_selfield.
CASE ip_ucomm.
WHEN '&PRINT'.
* PERFORM print_wip.
PERFORM print_wip_by_model.
WHEN '&SMMY'.
PERFORM display_wip_by_model.
ENDCASE.
ENDFORM. "usercommand
*&---------------------------------------------------------------------*
*& Form GENERATE_ALV_HEADER
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM generate_alv_header .
REFRESH: gt_event.
CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
EXPORTING
i_list_type = 0
IMPORTING
et_events = gt_event
EXCEPTIONS
list_type_wrong = 1.
CLEAR gs_event.
CLEAR gs_event.
MOVE 'PF_STATUS_SET' TO gs_event-name.
MOVE 'WHOLE_TOOLBAR' TO gs_event-form.
APPEND gs_event TO gt_event.
CLEAR gs_event.
MOVE 'USER_COMMAND' TO gs_event-name.
MOVE 'USER_COMMAND' TO gs_event-form.
APPEND gs_event TO gt_event.
ENDFORM. " GENERATE_ALV_HEADER
*&---------------------------------------------------------------------*
*& Form BUILD_FIELDCAT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM build_fieldcat.
LOOP AT i_fieldcat INTO l_fieldcat.
IF sy-langu = 'E'.
CASE l_fieldcat-fieldname.
WHEN 'STATUS'.
l_fieldcat-reptext_ddic = 'Status'.
WHEN 'USAGE'.
l_fieldcat-reptext_ddic = 'BOM Usage'.
WHEN 'MODEL'.
l_fieldcat-seltext_s = 'Model Number'.
l_fieldcat-seltext_m = 'Model Number'.
l_fieldcat-seltext_l = 'Model Number'.
l_fieldcat-reptext_ddic = 'Model Number'.
WHEN 'PSMNG'.
l_fieldcat-seltext_s = 'Order Total Qty'.
l_fieldcat-seltext_m = 'Order Total Qty'.
l_fieldcat-seltext_l = 'Order Total Qty'.
l_fieldcat-reptext_ddic = 'Order Total Qty'.
WHEN 'WEMNG'.
l_fieldcat-seltext_s = 'Delivered Qty'.
l_fieldcat-seltext_m = 'Delivered Qty'.
l_fieldcat-seltext_l = 'Delivered Qty'.
l_fieldcat-reptext_ddic = 'Delivered Qty'.
WHEN 'OPENQ'.
l_fieldcat-seltext_s = 'Not Issue Qty'.
l_fieldcat-seltext_m = 'Not Issue Qty'.
l_fieldcat-seltext_l = 'Not Issue Qty'.
l_fieldcat-reptext_ddic = 'Not Issue Qty'.
WHEN 'ERFMG'.
l_fieldcat-seltext_s = 'Product Consumed'.
l_fieldcat-seltext_m = 'Product Consumed'.
l_fieldcat-seltext_l = 'Product Consumed'.
l_fieldcat-reptext_ddic = 'Product Consumed'.
WHEN 'MEINS'.
l_fieldcat-seltext_s = 'BaseUnit'.
l_fieldcat-seltext_m = 'BaseUnit'.
l_fieldcat-seltext_l = 'BaseUnit'.
l_fieldcat-reptext_ddic = 'BaseUnit'.
l_fieldcat-no_zero = 'X'.
WHEN 'WIPQTY'.
l_fieldcat-seltext_s = 'WIP(A) Qty'.
l_fieldcat-seltext_m = 'WIP(A) Qty'.
l_fieldcat-seltext_l = 'WIP(A) Qty'.
l_fieldcat-reptext_ddic = 'WIP(A) Qty'.
WHEN 'DMBTR'.
l_fieldcat-seltext_s = 'UnitCost'.
l_fieldcat-seltext_m = 'UnitCost'.
l_fieldcat-seltext_l = 'UnitCost'.
l_fieldcat-reptext_ddic = 'UnitCost'.
WHEN 'WIPAMT'.
l_fieldcat-seltext_s = 'WIP Amount'.
l_fieldcat-seltext_m = 'WIP Amount'.
l_fieldcat-seltext_l = 'WIP Amount'.
l_fieldcat-reptext_ddic = 'WIP Amount'.
ENDCASE.
ELSE.
CASE l_fieldcat-fieldname.
WHEN 'STATUS'.
l_fieldcat-reptext_ddic = '状态'.
WHEN 'USAGE'.
l_fieldcat-reptext_ddic = 'BOM用量'.
WHEN 'MODEL'.
l_fieldcat-seltext_s = '产品编码'.
l_fieldcat-seltext_m = '产品编码'.
l_fieldcat-seltext_l = '产品编码'.
l_fieldcat-reptext_ddic = '产品编码'.
WHEN 'PSMNG'.
l_fieldcat-seltext_s = '工单数量'.
l_fieldcat-seltext_m = '工单数量'.
l_fieldcat-seltext_l = '工单数量'.
l_fieldcat-reptext_ddic = '工单数量'.
WHEN 'WEMNG'.
l_fieldcat-seltext_s = '已收货'.
l_fieldcat-seltext_m = '已收货'.
l_fieldcat-seltext_l = '已收货数量'.
l_fieldcat-reptext_ddic = '已收货数量'.
WHEN 'ENMNG'.
l_fieldcat-seltext_s = '投料数量'.
l_fieldcat-seltext_m = '投料数量'.
l_fieldcat-seltext_l = '投料数量'.
l_fieldcat-reptext_ddic = '投料数量'.
WHEN 'OPENQ'.
l_fieldcat-seltext_s = '未完工'.
l_fieldcat-seltext_m = '未完工'.
l_fieldcat-seltext_l = '未完工数量'.
l_fieldcat-reptext_ddic = '未完工数量'.
WHEN 'MEINS'.
l_fieldcat-seltext_s = 'BaseUnit'.
l_fieldcat-seltext_m = 'BaseUnit'.
l_fieldcat-seltext_l = 'BaseUnit'.
l_fieldcat-reptext_ddic = 'BaseUnit'.
l_fieldcat-no_zero = 'X'.
WHEN 'ERFMG'.
l_fieldcat-seltext_s = '物料消耗'.
l_fieldcat-seltext_m = '物料消耗'.
l_fieldcat-seltext_l = '物料消耗数量'.
l_fieldcat-reptext_ddic = '物料消耗数量'.
WHEN 'WIPQTY'.
l_fieldcat-seltext_s = 'WIP'.
l_fieldcat-seltext_m = 'WIP'.
l_fieldcat-seltext_l = 'WIP数量'.
l_fieldcat-reptext_ddic = 'WIP数量'.
WHEN 'DMBTR'.
l_fieldcat-seltext_s = '单位成本'.
l_fieldcat-seltext_m = '单位成本'.
l_fieldcat-seltext_l = '单位成本'.
l_fieldcat-reptext_ddic = '单位成本'.
WHEN 'WIPAMT'.
l_fieldcat-seltext_s = 'WIP金额'.
l_fieldcat-seltext_m = 'WIP金额'.
l_fieldcat-seltext_l = 'WIP金额'.
l_fieldcat-reptext_ddic = 'WIP金额'.
ENDCASE.
ENDIF.
MODIFY i_fieldcat FROM l_fieldcat.
ENDLOOP.
ENDFORM. "BUILD_FIELDCAT
*&---------------------------------------------------------------------*
*& Form top-of-head
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM top-of-head.
DATA: t_header TYPE slis_t_listheader,
wa_header TYPE slis_listheader.
DATA v_value1(18) TYPE c.
DATA v_value2(18) TYPE c.
DATA v_info(60) TYPE c.
IF plant IS NOT INITIAL.
v_value1 = plant.
v_info = v_value1.
CLEAR wa_header.
wa_header-typ = 'S'.
IF sy-langu = '1'.
wa_header-key = '##'.
ELSE.
wa_header-key = 'Plant '.
ENDIF.
wa_header-info = v_info.
APPEND wa_header TO t_header.
ENDIF.
ENDFORM. "top-of-head
*&---------------------------------------------------------------------*
*& Form PRINT_WIP_BY_MODEL
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM print_wip_by_model .
DATA fm_name TYPE rs38l_fnam.
DATA control_parameters TYPE ssfctrlop.
DATA output_options TYPE ssfcompop.
* DATA:BEGIN OF it_wip OCCURS 0,
* model LIKE afpo-matnr, "產品
* werks LIKE aufk-werks, "场所-工厂
* matnr LIKE resb-matnr, "组件
* maktx LIKE makt-maktx, "组件描述
* meins LIKE resb-meins, "单位
* usage(13) TYPE c, "BOM用量
* bdmng LIKE resb-bdmng, "组件需求数量
* enmng LIKE resb-enmng, "组件已发数量
* openq LIKE resb-enmng, "缺料数量
* erfmg LIKE resb-enmng, "
* wipqty(13) TYPE p, "WIP数量
* dmbtr(13) TYPE p, "WIP金额
* waers TYPE waers,
* END OF it_wip.
DATA:it_wip LIKE zwip_item OCCURS 0 WITH HEADER LINE.
DATA:it_wip2 LIKE STANDARD TABLE OF it_wip.
DATA:it_head LIKE zwip_head OCCURS 0 WITH HEADER LINE.
DATA v_name TYPE t001w-name1.
DATA v_repname TYPE string.
CLEAR v_name.
SELECT SINGLE name1 INTO v_name
FROM t001w
WHERE werks = plant.
CLEAR v_repname.
CONCATENATE 'WIP PHYSICAL COUNT LIST (' plant v_name ')'
INTO v_repname.
CLEAR it_wip.
REFRESH it_wip.
LOOP AT itab.
MOVE-CORRESPONDING itab TO it_wip.
COLLECT it_wip.
it_head-model = itab-model.
it_head-werks = itab-werks.
COLLECT it_head.
ENDLOOP.
output_options-tddest = 'LP01'.
output_options-tdimmed = 'X'.
control_parameters-device = 'PRINTER'.
"control_parameters-no_dialog = 'X'.
control_parameters-preview = 'X'.
CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
EXPORTING
formname = 'ZWIP_SMARTFORM'
* VARIANT = ' '
* DIRECT_CALL = ' '
IMPORTING
fm_name = fm_name
EXCEPTIONS
no_form = 1
no_function_module = 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.
CLEAR control_parameters-no_open.
LOOP AT it_head INTO it_head.
AT FIRST.
control_parameters-no_close = 'X'.
ENDAT.
AT LAST.
control_parameters-no_close = ''.
ENDAT.
control_parameters-no_dialog = ''.
control_parameters-preview = 'X'.
output_options-tddest = 'LP01'.
output_options-tdimmed = 'X'.
output_options-tddelete = 'X'.
CLEAR it_wip2.
REFRESH it_wip2.
LOOP AT it_wip WHERE model = it_head-model
AND werks = it_head-werks.
APPEND it_wip TO it_wip2.
ENDLOOP.
CALL FUNCTION fm_name
EXPORTING
* ARCHIVE_INDEX =
* ARCHIVE_INDEX_TAB =
* ARCHIVE_PARAMETERS =
control_parameters = control_parameters
* MAIL_APPL_OBJ =
* MAIL_RECIPIENT =
* MAIL_SENDER =
output_options = output_options
user_settings = space
report_name = v_repname
wa_head = it_head
wa_cutoff = cutoff
TABLES
it_wip = it_wip2
* IMPORTING
* DOCUMENT_OUTPUT_INFO =
* JOB_OUTPUT_INFO =
* JOB_OUTPUT_OPTIONS =
EXCEPTIONS
formatting_error = 1
internal_error = 2
send_error = 3
user_canceled = 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.
control_parameters-no_open = 'X'.
ENDLOOP.
ENDFORM. " PRINT_WIP_BY_MODEL
*&---------------------------------------------------------------------*
*& Form PRINT_WIP
*&---------------------------------------------------------------------*
FORM print_wip.
DATA fm_name TYPE rs38l_fnam.
DATA control_parameters TYPE ssfctrlop.
DATA output_options TYPE ssfcompop.
DATA:BEGIN OF it_wip OCCURS 0,
* lead_aufnr TYPE co_laufnr,
aufnr LIKE afko-aufnr,
model LIKE afpo-matnr,
gmein LIKE afpo-meins,
psmng LIKE afpo-psmng,
wemng LIKE afpo-wemng,
posnr LIKE resb-posnr,
matnr LIKE resb-matnr,
maktx LIKE makt-maktx,
meins LIKE resb-meins,
usage(13) TYPE p,
bdmng LIKE resb-bdmng,
enmng LIKE resb-enmng,
openq LIKE resb-enmng,
erfmg LIKE resb-enmng,
wipqty(13) TYPE p,
dmbtr(13) TYPE p,
waers TYPE waers,
END OF it_wip.
DATA v_name TYPE t001w-name1.
DATA v_repname TYPE string.
CLEAR v_name.
SELECT SINGLE name1 INTO v_name
FROM t001w
WHERE werks = plant.
CLEAR v_repname.
CONCATENATE 'WIP PHYSICAL COUNT LIST (' plant v_name ')'
INTO v_repname.
CLEAR it_wip.
REFRESH it_wip.
LOOP AT itab.
MOVE-CORRESPONDING itab TO it_wip.
APPEND it_wip.
ENDLOOP.
output_options-tddest = 'LP01'.
output_options-tdimmed = 'X'.
control_parameters-device = 'PRINTER'.
"control_parameters-no_dialog = 'X'.
control_parameters-preview = 'X'.
CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
EXPORTING
formname = 'ZWIP_SMARTFORM'
* VARIANT = ' '
* DIRECT_CALL = ' '
IMPORTING
fm_name = fm_name
EXCEPTIONS
no_form = 1
no_function_module = 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.
CALL FUNCTION fm_name
EXPORTING
* ARCHIVE_INDEX =
* ARCHIVE_INDEX_TAB =
* ARCHIVE_PARAMETERS =
control_parameters = control_parameters
* MAIL_APPL_OBJ =
* MAIL_RECIPIENT =
* MAIL_SENDER =
output_options = output_options
user_settings = space
report_name = v_repname
TABLES
wip = it_wip
* IMPORTING
* DOCUMENT_OUTPUT_INFO =
* JOB_OUTPUT_INFO =
* JOB_OUTPUT_OPTIONS =
EXCEPTIONS
formatting_error = 1
internal_error = 2
send_error = 3
user_canceled = 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.
ENDFORM. "PRINT_WIP
*&---------------------------------------------------------------------*
*& Form GET_ALL_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM get_all_data .
DATA:BEGIN OF h_order,
aufnr TYPE afko-aufnr, "Order Number
zzlot_no LIKE aufk-zzlot_no, "订单批号
rsnum TYPE resb-rsnum,
projn TYPE afpo-projn,
dispo TYPE afko-dispo, "MRP controller for the order
* lead_aufnr TYPE afko-lead_aufnr,
stat TYPE pordarch-stat,"Product Order Status
status(10) TYPE c, "Status Description
matnr TYPE afpo-matnr, "Material Number for Order
meins TYPE afpo-meins, "Base unit of measure
lgort TYPE resb-lgort, "成品存储地点
gstrp TYPE afko-gstrp, "Basic start date
gltrp TYPE afko-gltrp, "Basic finish date
psmng TYPE afpo-psmng, "Order quantity
wemng TYPE afpo-wemng, "Qty of goods received on order unit
umrez TYPE afpo-umrez, "Numerator of conv ot base unit
umren TYPE afpo-umren, "Denominator of conv ot base unit.
istat TYPE tj02t-istat,
END OF h_order.
DATA h_order01 LIKE h_order OCCURS 10 WITH HEADER LINE.
DATA h_order02 LIKE h_order OCCURS 10 WITH HEADER LINE.
DATA:BEGIN OF d_order,
rsnum TYPE resb-rsnum,
rspos TYPE resb-rspos,
aufnr TYPE resb-aufnr,
posnr LIKE resb-posnr,
matnr TYPE resb-matnr, "Material Number
mtart LIKE mara-mtart,"物料类型
v_usage TYPE p DECIMALS 6, "Usage
werks TYPE resb-werks, "Plant
bdmng TYPE resb-bdmng, "Requirement Quantity
enmng TYPE resb-enmng, "Quantity withdrawn
openq TYPE resb-enmng, "Open qty
erfmg TYPE resb-erfmg, "Quantity in unit of entry
meins TYPE resb-meins, "Base Unit of Measure
wipqty TYPE resb-erfmg, "WIP Qty
ntgew TYPE mara-ntgew, "Net weight
ntgewg TYPE mara-ntgew, "Net Weight by gm
gewei TYPE mara-gewei, "Net Weight Unit
wipkg TYPE resb-erfmg,
ausch TYPE resb-ausch, "Component scrap in percent
avoau TYPE resb-avoau, "Operation scrap
dmbtr TYPE mseg-dmbtr, "withdrawn amount
wipamt TYPE mseg-dmbtr, "withdrawn amount
wipam2 LIKE mseg-dmbtr, "WIP LOCAL AMOUNT 2
sepqty LIKE resb-enmng, "####
wip2 LIKE resb-enmng, "WIPQTY#######
END OF d_order.
DATA d_order01 LIKE d_order OCCURS 10 WITH HEADER LINE.
TYPES: BEGIN OF st_mseg,
mblnr TYPE mseg-mblnr,
zeile TYPE mseg-zeile,
rsnum TYPE mseg-rsnum,
rspos TYPE mseg-rspos,
smbln TYPE mseg-smbln,
smblp TYPE mseg-smblp,
aufnr TYPE mseg-aufnr,
matnr TYPE mseg-matnr,
shkzg TYPE mseg-shkzg,
menge TYPE p DECIMALS 3,
bwart TYPE mseg-bwart,
grund TYPE mseg-grund,
budat TYPE mkpf-budat,
lgort TYPE mseg-lgort,
dmbtr TYPE mseg-dmbtr,
END OF st_mseg.
DATA wa_mseg TYPE st_mseg.
DATA wa_mseg2 TYPE st_mseg.
DATA it_mseg TYPE TABLE OF st_mseg WITH KEY aufnr matnr.
TYPES: BEGIN OF st_resb,
rsnum TYPE resb-rsnum,
rspos TYPE resb-rspos,
werks TYPE resb-werks,
aufnr TYPE resb-aufnr,
posnr TYPE resb-posnr,
matnr TYPE resb-matnr,
meins TYPE resb-meins,
bdmng TYPE resb-bdmng,
ausch TYPE resb-ausch,
avoau TYPE resb-avoau, "Operation scrap
END OF st_resb.
DATA wa_resb TYPE st_resb.
DATA it_resb TYPE TABLE OF st_resb WITH KEY rsnum rspos." AUFNR MATNR.
DATA ws_resb TYPE TABLE OF st_resb WITH HEADER LINE.
DATA v_tabix TYPE sy-tabix.
DATA v_menge TYPE mseg-menge.
DATA v_enmng TYPE mseg-menge.
DATA v_dmbtr TYPE mseg-dmbtr.
DATA v_budat TYPE mkpf-budat.
DATA v_cost TYPE p DECIMALS 5.
DATA v_fcost TYPE p DECIMALS 5.
DATA wa_mbew TYPE mbew.
DATA v_scrap TYPE resb-enmng.
DATA neg_wip_tol TYPE i.
DATA v_rec_count TYPE i.
CLEAR itab.
REFRESH itab.
neg_wip_tol = 0 - wip_tol.
**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~**
**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~**
SELECT k~rsnum k~aufnr
matnr zzlot_no
gstrp psmng
wemng meins
dispo umrez
umren projn
INTO CORRESPONDING FIELDS OF TABLE h_order02
FROM afko AS k
INNER JOIN afpo AS p
ON k~aufnr = p~aufnr
INNER JOIN aufk AS f
ON k~aufnr = f~aufnr
WHERE p~dwerk IN plant
AND k~aufnr IN s_aufnr
AND k~dispo IN s_dispo
AND p~matnr IN s_matnr
AND k~gstrp IN s_gstrp
AND p~dauty = '10'
AND k~ftrmi <= cutoff
AND k~aufnr NOT IN
( SELECT aufnr
FROM pordarch
WHERE ( stat = 'I0013'
OR stat = 'I0076'
OR ( stat = 'I0045' AND aedat <= cutoff )
OR ( stat = 'I0046' AND aedat <= cutoff ) )
AND inact = space )
AND k~aufnr IN ( SELECT aufnr
FROM afko
WHERE aufnr IN s_aufnr
AND gstrp IN s_gstrp
AND matnr IN s_matnr
AND dispo IN s_dispo ).
IF h_order02[] IS INITIAL.
MESSAGE '没有符合条件的数据,请检查!' TYPE 'I'.
STOP.
ENDIF.
**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~**
**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~**
*==============================================================
*READ RESB INTO INTERNAL TABLE IT_RESB
*==============================================================
CLEAR it_resb.
REFRESH it_resb.
SELECT rsnum rspos
werks aufnr
posnr matnr
meins bdmng
ausch avoau
INTO TABLE it_resb
FROM resb
FOR ALL ENTRIES IN h_order02
WHERE rsnum = h_order02-rsnum
AND matnr IN p_matnr
AND dumps <> 'X' "Phantom item
AND xloek <> 'X'. "Deleted item
*==============================================================
* begin of Read MSEG data into internal table IT_MSEG
*==============================================================
CLEAR it_mseg.
REFRESH it_mseg.
SELECT b~mblnr a~zeile a~rsnum a~rspos smbln smblp aufnr matnr shkzg
menge bwart grund b~budat lgort dmbtr
INTO TABLE it_mseg
FROM mseg AS a INNER JOIN mkpf AS b
ON a~mblnr = b~mblnr AND a~mjahr = b~mjahr
FOR ALL ENTRIES IN h_order02
WHERE a~rsnum = h_order02-rsnum AND
budat <= cutoff AND
bwart IN ('101','102','261','262').
* STATUS DESCRIPTION
* I0002 Released
* I0046 Closed
* I0045 TEL.Completed
* I0012 Delivered
* I0013 Deleted by PM
* I0076 DELETED
* Exclude no released order.
LOOP AT h_order02 INTO h_order.
SELECT SINGLE stat INTO h_order-stat
FROM pordarch
WHERE aufnr = h_order-aufnr
AND werks IN plant
AND matnr = h_order-matnr
AND stat = 'I0002'.
IF sy-subrc <> 0.
CONTINUE.
ENDIF.
* Convert order unit qty to base unit qty
h_order-psmng = h_order-psmng * h_order-umrez / h_order-umren.
h_order-wemng = h_order-wemng * h_order-umrez / h_order-umren.
* Select Product Order Status
CLEAR h_order-status.
CLEAR h_order-stat.
SELECT SINGLE stat INTO h_order-stat
FROM pordarch
WHERE aufnr = h_order-aufnr
AND werks IN plant
AND matnr = h_order-matnr
AND stat = 'I0046'.
IF sy-subrc = 0.
h_order-status = 'Closed'.
ELSE.
CLEAR h_order-stat.
SELECT SINGLE stat INTO h_order-stat
FROM pordarch
WHERE aufnr = h_order-aufnr
AND werks = plant
AND matnr = h_order-matnr
AND stat = 'I0045'.
IF sy-subrc = 0.
h_order-status = 'TEL.Completed'.
ELSE.
CLEAR h_order-stat.
SELECT SINGLE stat INTO h_order-stat
FROM pordarch
WHERE aufnr = h_order-aufnr
AND werks = plant
AND matnr = h_order-matnr
AND stat = 'I0012'.
IF sy-subrc = 0.
h_order-status = 'Delivered'.
ELSE.
h_order-status = 'Released'.
ENDIF.
ENDIF.
ENDIF.
APPEND h_order TO h_order01.
ENDLOOP.
SORT h_order01 BY aufnr matnr.
LOOP AT h_order01 INTO h_order.
CLEAR wa_resb.
CLEAR ws_resb.
REFRESH ws_resb.
LOOP AT it_resb INTO wa_resb WHERE aufnr = h_order-aufnr.
** *Get the net requirement qty (not included scrap)
ws_resb-rsnum = wa_resb-rsnum.
ws_resb-rspos = wa_resb-rspos.
ws_resb-werks = wa_resb-werks.
ws_resb-aufnr = wa_resb-aufnr.
ws_resb-posnr = wa_resb-posnr.
ws_resb-matnr = wa_resb-matnr.
ws_resb-meins = wa_resb-meins.
ws_resb-bdmng = wa_resb-bdmng.
ws_resb-ausch = wa_resb-ausch.
ws_resb-avoau = wa_resb-avoau.
COLLECT ws_resb.
CLEAR wa_resb.
ENDLOOP.
CLEAR d_order01.
REFRESH d_order01.
CLEAR d_order.
LOOP AT ws_resb.
CLEAR d_order.
d_order-rsnum = ws_resb-rsnum.
d_order-rspos = ws_resb-rspos.
d_order-werks = ws_resb-werks.
d_order-aufnr = ws_resb-aufnr.
d_order-posnr = ws_resb-posnr.
d_order-matnr = ws_resb-matnr.
d_order-meins = ws_resb-meins.
d_order-bdmng = ws_resb-bdmng.
d_order-ausch = ws_resb-ausch.
d_order-avoau = ws_resb-avoau.
* Select Quantity withdrawn(Actual Issue Qty)
CLEAR d_order-enmng.
CLEAR d_order-dmbtr.
*======================================================================
* Calculated Actul ISSUED Qty and Amount(####)
*======================================================================
CLEAR: wa_mseg, v_enmng, v_dmbtr.
LOOP AT it_mseg INTO wa_mseg WHERE rsnum = d_order-rsnum
AND rspos = d_order-rspos
AND aufnr = d_order-aufnr
AND matnr = d_order-matnr
AND ( bwart = '261' OR
bwart = '262').
IF wa_mseg-shkzg = 'S'.
wa_mseg-menge = 0 - wa_mseg-menge.
wa_mseg-dmbtr = 0 - wa_mseg-dmbtr.
ENDIF.
READ TABLE it_mseg INTO wa_mseg2 WITH KEY smbln = wa_mseg-mblnr
smblp = wa_mseg-zeile.
v_tabix = sy-tabix.
IF sy-subrc EQ 0.
wa_mseg2-menge = 0. wa_mseg2-dmbtr = 0.
wa_mseg-menge = 0. wa_mseg-dmbtr = 0.
MODIFY it_mseg FROM wa_mseg2 INDEX v_tabix
TRANSPORTING menge dmbtr.
MODIFY it_mseg FROM wa_mseg2 TRANSPORTING menge dmbtr.
ENDIF.
v_enmng = v_enmng + wa_mseg-menge.
v_dmbtr = v_dmbtr + wa_mseg-dmbtr.
ENDLOOP.
d_order-enmng = v_enmng.
d_order-dmbtr = v_dmbtr.
*======================================================================
* end of ##Actul ISSUED Qty
*======================================================================
* Calculate Open Qty
CLEAR d_order-openq.
d_order-openq = d_order-bdmng - d_order-enmng.
CLEAR v_rec_count.
SELECT COUNT( * ) INTO v_rec_count
FROM t006
WHERE msehi = ws_resb-meins
AND ( dimid = 'AAAADL' OR dimid = 'ZK1EA' ).
* Calculate usage
CLEAR d_order-v_usage.
IF h_order-psmng <> 0.
d_order-v_usage = d_order-bdmng / h_order-psmng.
ENDIF.
* Calculate Consumed qty of F/G Entry Qty
CLEAR d_order-erfmg.
d_order-erfmg = d_order-v_usage * h_order-wemng.
* Calculate WIP Qty
CLEAR d_order-wipqty.
d_order-wipqty = d_order-enmng - d_order-erfmg.
APPEND d_order TO d_order01.
ENDLOOP. "LOOP AT WS_RESB
SORT d_order01 BY posnr matnr.
LOOP AT d_order01 INTO d_order.
IF ( d_order-wipqty >= wip_tol ) OR
( d_order-wipqty <= neg_wip_tol ) .
CLEAR v_cost.
IF d_order-enmng = 0.
v_cost = 0.
ELSE.
v_cost = d_order-dmbtr / d_order-enmng.
ENDIF.
CLEAR d_order-wipamt.
d_order-wipamt = d_order-wipqty * v_cost.
CLEAR d_order-wipam2.
d_order-wipam2 = d_order-dmbtr - ( h_order-wemng * v_fcost ).
*d_order-dmbtr赋予单位成本
d_order-dmbtr = v_cost.
SELECT SINGLE maktx INTO itab-maktx
FROM makt
WHERE spras = sy-langu AND matnr = d_order-matnr.
IF sy-subrc <> 0.
SELECT SINGLE maktx INTO itab-maktx
FROM makt
WHERE matnr = d_order-matnr.
ENDIF.
itab-aufnr = h_order-aufnr.
itab-zzlot_no = h_order-zzlot_no.
* itab-lead_aufnr = h_order-lead_aufnr.
"ITAB-STATUS = H_ORDER-STATUS.
itab-model = h_order-matnr.
itab-gmein = h_order-meins.
itab-psmng = h_order-psmng.
itab-wemng = h_order-wemng.
itab-werks = d_order-werks.
* itab-posnr = d_order-posnr.
itab-rspos = d_order-rspos.
itab-matnr = d_order-matnr.
itab-usage = d_order-v_usage.
itab-bdmng = d_order-bdmng.
itab-enmng = d_order-enmng.
itab-openq = d_order-openq.
itab-meins = d_order-meins.
itab-erfmg = d_order-erfmg.
itab-wipqty = d_order-wipqty.
itab-dmbtr = d_order-dmbtr.
itab-wipamt = d_order-wipamt.
SELECT SINGLE mara~mtart FROM mara INTO itab-mtart WHERE
mara~matnr = itab-matnr.
APPEND itab.
ENDIF.
ENDLOOP. "LOOP AT D_ORDER01 INTO D_ORDER
ENDLOOP. "LOOP AT H_ORDER01 INTO H_ORDER.
DELETE itab WHERE wipqty NOT IN s_wipqty.
*&->start add by rainy on 20150720-增加数据保存自建表 DEVK905345
DATA:lv_upd TYPE c,
l_line TYPE string.
DATA:BEGIN OF lt_zppt016 OCCURS 0.
INCLUDE STRUCTURE zppt016.
DATA:END OF lt_zppt016.
*& 增加数据更新到自建表
IF p_sel EQ 'X'.
LOOP AT itab.
MOVE-CORRESPONDING itab TO lt_zppt016.
lt_zppt016-usnam = sy-uname.
lt_zppt016-datum = sy-datum.
lt_zppt016-time = sy-uzeit.
APPEND lt_zppt016.
CLEAR lt_zppt016.
ENDLOOP.
l_line = lines( lt_zppt016[] ).
*&A1.更新数据表
* break misd11.
CLEAR lv_upd.
TRY .
MODIFY zppt016 FROM TABLE lt_zppt016.
CATCH cx_sy_open_sql_db.
lv_upd = 'F'.
ENDTRY.
IF lv_upd EQ ' '.
COMMIT WORK.
MESSAGE s000(OO) WITH '成功更新' l_line '条数据!'.
ELSE.
ROLLBACK WORK.
MESSAGE e000(OO) WITH '数据更新失败,请重试!'.
ENDIF.
ENDIF.
*&->end add.
ENDFORM. " GET_ALL_DAT
*&---------------------------------------------------------------------*
*& Form DISPLAY_WIP_BY_MODEL
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM display_wip_by_model .
TYPE-POOLS: slis.
DEFINE addfield.
l_alv_filed-fieldname = &1.
l_alv_filed-reptext_ddic = &2.
l_alv_filed-outputlen = &3.
l_alv_filed-no_zero = &4.
l_alv_filed-emphasize = &5.
l_alv_filed-do_sum = &6.
l_alv_filed-no_out = &7.
* l_alv_filed-coltab_fieldname = &7.
append l_alv_filed to l_alv_filedcat.
clear l_alv_filed.
END-OF-DEFINITION.
DATA: g_repid TYPE sy-repid.
DATA: l_alv_filed TYPE slis_fieldcat_alv.
DATA: l_alv_filedcat TYPE slis_t_fieldcat_alv.
DATA: layout TYPE slis_layout_alv.
DATA: gs_print TYPE slis_print_alv,
it_sort TYPE slis_t_sortinfo_alv.
DATA:it_wip LIKE zwip_item OCCURS 0 WITH HEADER LINE.
CLEAR it_wip.
REFRESH it_wip.
LOOP AT itab.
MOVE-CORRESPONDING itab TO it_wip.
COLLECT it_wip.
ENDLOOP.
g_repid = sy-repid.
layout-box_fieldname = 'SET'.
layout-zebra = 'X'.
layout-colwidth_optimize = 'X'.
addfield 'WERKS' 'Plant' '5' 'X' '' '' ''.
addfield 'MODEL' 'Model' '15' 'X' '' '' ''.
addfield 'MATNR' 'Material NO' '20' 'X' '' '' ''.
addfield 'MAKTX' 'Material Descript' '20' 'X' '' '' ''.
addfield 'MEINS' 'Unit' '5' 'X' '' '' ''.
addfield 'USAGE' 'Usage' '5' 'X' '' '' ''.
addfield 'WIPQTY' 'WIP Quantity' '5' 'X' '' '' ''.
addfield 'WIPAMT' 'WIP Amount' '5' 'X' '' '' ''.
g_repid = sy-repid.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = g_repid
is_layout = layout
* I_CALLBACK_TOP_OF_PAGE = 'ALV_TOP_OF_PAGE'
* I_CALLBACK_USER_COMMAND = CS_CALLBACK_USER
* I_CALLBACK_PF_STATUS_SET = 'PF_STATUS_SET'
it_fieldcat = l_alv_filedcat
i_grid_title = ''
i_save = 'X'
TABLES
t_outtab = it_wip.
ENDFORM. " DISPLAY_WIP_BY_MODEL