*&---------------------------------------------------------------------*
*& Report ZPPR0045
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT zppr0045.
TABLES:aufk.
TABLES:sscrfields,icon,rlgrap.
DATA:gt_fieldcat TYPE lvc_t_fcat,
gw_fieldcat TYPE lvc_s_fcat,
gv_repid TYPE sy-repid,
gs_layout TYPE lvc_s_layo,
gt_sort TYPE lvc_t_sort,
gw_sort TYPE lvc_s_sort.
TYPES:BEGIN OF tys_out,
aufnr TYPE aufnr,
matnr_top TYPE matnr,
maktx_top TYPE maktx,
menge_top TYPE menge_d,
meins_top TYPE meins,
posnr TYPE aposn,
matnr TYPE matnr,
maktx TYPE maktx,
maabc TYPE marc-maabc,
maabc_txt TYPE dd07t-ddtext,
kausf TYPE zdekausf,
"req_quan TYPE menge_d,
"withdrawn_quantity TYPE menge_d,
entry_quantity TYPE menge_d,
meins TYPE meins,
sfztl TYPE flag,
menge_jy TYPE menge_d,
werks TYPE werks_d,
sortf TYPE stpox-sortf,
alpgr TYPE stpox-alpgr,
alprf TYPE stpox-alprf,
mtype TYPE bapi_mtype,
msg TYPE bapi_msg,
rsnum TYPE rsnum,
rspos TYPE rspos,
lgort TYPE lgort_d,
ewahr TYPE resb-ewahr,
cellcolor TYPE lvc_t_scol,
sel(1),
END OF tys_out.
DATA:gt_out TYPE TABLE OF tys_out,
gw_out LIKE LINE OF gt_out.
SELECTION-SCREEN:BEGIN OF BLOCK b1 WITH FRAME TITLE TEXT-001.
SELECT-OPTIONS:s_aufnr FOR aufk-aufnr,
s_erdat FOR aufk-erdat,
s_ernam FOR aufk-ernam.
SELECTION-SCREEN:END OF BLOCK b1.
START-OF-SELECTION.
BREAK yangtao.
PERFORM frm_get_data.
PERFORM frm_display_alv.
*&---------------------------------------------------------------------*
*& Form FRM_GET_DATA
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM frm_get_data .
DATA:lt_status TYPE TABLE OF jstat.
DATA:lw_object TYPE bapi_pp_order_objects, "objects
lt_component TYPE TABLE OF bapi_order_component, "components.
lw_component LIKE LINE OF lt_component. "operations
DATA:lv_number TYPE bapi_order_key-order_number.
DATA:lt_stpox LIKE TABLE OF stpox WITH HEADER LINE.
DATA:lt_stpoxs LIKE TABLE OF stpox WITH HEADER LINE.
DATA:cstmat TYPE cstmat.
TYPES:BEGIN OF tys_mard,
werks TYPE werks_d,
matnr TYPE matnr,
labst TYPE mard-labst,
mng01 TYPE menge_d,
END OF tys_mard.
DATA:lt_mard TYPE TABLE OF tys_mard,
lw_mard LIKE LINE OF lt_mard,
lt_mard_total TYPE TABLE OF tys_mard,
lw_mard_total LIKE LINE OF lt_mard_total.
DATA(lv_flag) = VALUE flag( ).
DATA:lr_lgort TYPE RANGE OF t001l-lgort.
DATA:lt_mdpsx TYPE TABLE OF mdps.
"替代料内表
TYPES:BEGIN OF tys_tdl,
aufnr TYPE aufnr,
sortf TYPE stpox-sortf,
alpgr TYPE stpox-alpgr,
alprf TYPE stpox-alprf,
cfbs TYPE flag, "重复标识
sfztl TYPE flag,
END OF tys_tdl.
DATA:lt_tdl TYPE TABLE OF tys_tdl.
"替代料数量表
TYPES:BEGIN OF tys_sl,
aufnr TYPE aufnr,
sortf TYPE stpox-sortf,
alpgr TYPE stpox-alpgr,
" alprf TYPE stpox-alprf,
entry_quantity TYPE menge_d,
sfztl TYPE flag,
END OF tys_sl.
DATA:lt_sl TYPE TABLE OF tys_sl.
"主替代料唯一数量
TYPES:BEGIN OF tys_ztl,
aufnr TYPE aufnr,
matnr_top TYPE matnr,
sortf TYPE stpox-sortf,
alpgr TYPE stpox-alpgr,
alprf TYPE stpox-alprf,
entry_quantity TYPE menge_d,
menge_jy TYPE menge_d,
sfztl TYPE flag,
END OF tys_ztl.
DATA:lt_ztl TYPE TABLE OF tys_ztl.
DATA:lv_menge TYPE menge_d,
lv_entry_quantity TYPE menge_d,
lv_numc TYPE numc15.
SELECT aufk~aufnr,
aufk~objnr,
afpo~matnr,
afpo~psmng,
afpo~meins,
aufk~werks,
afko~stlal,
afko~stlan
INTO TABLE @DATA(lt_aufk)
FROM aufk INNER JOIN afpo ON aufk~aufnr = afpo~aufnr
INNER JOIN afko ON afko~aufnr = afpo~aufnr
WHERE aufk~aufnr IN @s_aufnr AND
aufk~erdat IN @s_erdat AND
aufk~ernam IN @s_ernam AND
aufk~auart IN ( 'ZP01','ZP02' ,'ZP08' ).
APPEND VALUE #( sign = 'E' option = 'CP' low = 'W*' ) TO lr_lgort.
LOOP AT lt_aufk INTO DATA(lw_aufk).
REFRESH:lt_component,lt_status,lt_stpox,lt_stpoxs,lt_mard.
CLEAR:lv_number .
lw_object-components = abap_true.
lw_object-operations = abap_true.
CALL FUNCTION 'STATUS_READ'
EXPORTING
client = sy-mandt
objnr = lw_aufk-objnr
TABLES
status = lt_status
EXCEPTIONS
object_not_found = 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.
DATA(lv_author) = VALUE flag( ).
LOOP AT lt_status INTO DATA(lw_status).
IF lw_status-stat = 'I0076' AND lw_status-inact = ''."如果删除的,也直接跳过
CLEAR:lv_flag.
EXIT.
ENDIF.
IF lw_status-stat = 'I0001' AND lw_status-inact = ''."只要创建激活状态的
lv_flag = 'X'.
EXIT.
ENDIF.
ENDLOOP.
IF lv_flag = ''.
CONTINUE.
ENDIF.
lv_number = lw_aufk-aufnr.
CALL FUNCTION 'BAPI_PRODORD_GET_DETAIL'
EXPORTING
number = lv_number
order_objects = lw_object
TABLES
component = lt_component.
CLEAR:lv_flag.
CALL FUNCTION 'CS_BOM_EXPL_MAT_V2'
EXPORTING
capid = 'PP01'
datuv = sy-datum
emeng = '' "'1' "p_emeng
mehrs = '' "lv_mehrs "X多层 空单层
mtnrv = lw_aufk-matnr
stlal = lw_aufk-stlal
stlan = lw_aufk-stlan
mdmps = ''
stpst = 0
werks = lw_aufk-werks
IMPORTING
topmat =
标签:sy,aufk,主替,lv,lw,自动,工单,TYPE,menge
From: https://blog.csdn.net/twins622/article/details/145209840