*&---------------------------------------------------------------------*
*& Report ZTEST
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT ZTEST.
TYPE-POOLS: SLIS.
DATA: I_FIELDCAT_ALV TYPE SLIS_T_FIELDCAT_ALV WITH HEADER LINE,
I_LAYOUT TYPE SLIS_LAYOUT_ALV, "alv的格式
I_FIELDCAT TYPE SLIS_FIELDCAT_ALV,
TMP_TITLE(70),
W_REPID LIKE SY-REPID.
**---------------------------------------------------------------------*
*** Types
**---------------------------------------------------------------------*
DATA : POS TYPE I,
LW_TITLE(150) TYPE C,
S_mat TYPE CKMLHD-MATNR.
*选择屏幕
data:BEGIN OF itab OCCURS 0,
matnr like mara-matnr,
KALNR like CKMLHD-kalnr,
BDATJ like ckmlcr-bdatj,
POPER like ckmlcr-poper,
VNPRD_EA like ckmlcr-VNPRD_EA,
vnprd_ma like ckmlcr-vnprd_ma,
ABPRD_O LIKE CKMLCR-ABPRD_O,
ZUPRD_O LIKE CKMLCR-ZUPRD_O,
EBPRD_EA LIKE CKMLCR-EBPRD_EA,
ABPRD_mO LIKE CKMLCR-ABPRD_mO,
ZUPRD_mO LIKE CKMLCR-ZUPRD_mO,
EBPRD_mA LIKE CKMLCR-EBPRD_mA,
ESTPRD like mlcd-ESTPRD,
mstprd like mlcd-mstprd,
testprd like mlcd-estprd,
WFPCY LIKE CKMLCR-ABPRD_O,
end of itab.
SELECTION-SCREEN BEGIN OF BLOCK BLK1 WITH FRAME TITLE TEXT-001.
SELECTION-SCREEN SKIP.
PARAMETERS P_BDATJ LIKE CKMLCR-BDATJ OBLIGATORY DEFAULT '2011'.
SELECTION-SCREEN SKIP.
PARAMETERS: P_POPER LIKE CKMLCR-POPER OBLIGATORY DEFAULT '12'.
SELECTION-SCREEN SKIP.
PARAMETERS P_WERKS LIKE CKMLHD-BWKEY OBLIGATORY DEFAULT 'PS01'.
SELECTION-SCREEN SKIP.
SELECT-OPTIONS: S_MATNR FOR S_mat.
SELECTION-SCREEN SKIP.
SELECTION-SCREEN END OF BLOCK BLK1.
CONCATENATE ' ' P_BDATJ '年' P_POPER
'月'
'未分配差异表' INTO LW_TITLE.
START-OF-SELECTION.
PERFORM GETDATA. "
PERFORM LAYOUT_BUILD. "
PERFORM FIELDS. "
PERFORM DISPLAY_DATA. "
*&---------------------------------------------------------------------*
*& Form getdata
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM GETDATA.
select CKMLHD~matnr
CKMLHD~KALNR
ckmlcr~BDATJ
ckmlcr~POPER
ckmlcr~VNPRD_EA
ckmlcr~vnprd_ma
ckmlcr~ABPRD_O
ckmlcr~ZUPRD_O
ckmlcr~EBPRD_EA
ckmlcr~ABPRD_mO
ckmlcr~ZUPRD_mO
ckmlcr~EBPRD_mA
INTO CORRESPONDING FIELDS OF TABLE itab
from ckmlhd
join ckmlcr on ckmlhd~kalnr = ckmlcr~kalnr
where ckmlhd~matnr in s_matnr
and ckmlhd~bwkey = p_werks
and ckmlcr~BDATJ = p_BDATJ
and ckmlcr~POPER = p_poper.
loop at itab.
select sum( ESTPRD ) sum( mstprd ) into (itab-tESTPRD,itab-mstprd)
from mlcd
where kalnr = itab-kalnr
and bdatj = itab-bdatj
and poper = itab-poper
and CATEG = 'VN'.
itab-estprd = itab-vnprd_ea + itab-vnprd_ma - ( itab-testprd + itab-mstprd ).
itab-WFPCY = itab-EBPRD_EA + + itab-VNPRD_EA - itab-ZUPRD_O - itab-ABPRD_O
+ itab-EBPRD_mA + + itab-VNPRD_mA - itab-ZUPRD_mO - itab-ABPRD_mO.
modify itab.
endloop.
ENDFORM. "GETDATA
*&---------------------------------------------------------------------*
*& Form layout_build
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM LAYOUT_BUILD.
I_LAYOUT-ZEBRA = 'X'.
I_LAYOUT-DETAIL_POPUP = 'X'. "
W_REPID = SY-REPID. "
I_LAYOUT-F2CODE = '&ETA'."
I_LAYOUT-NO_VLINE = 'X'."
I_LAYOUT-COLWIDTH_OPTIMIZE = 'X'. "
I_LAYOUT-DETAIL_INITIAL_LINES = 'X'.
I_LAYOUT-DETAIL_TITLEBAR = '详细内容'."
ENDFORM. "layout_build
*&---------------------------------------------------------------------*
*& Form fields
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM FIELDS.
REFRESH I_FIELDCAT_ALV.
POS = 0.
CLEAR I_FIELDCAT.
TMP_TITLE = LW_TITLE."
I_FIELDCAT-COL_POS = POS. "
I_FIELDCAT-FIELDNAME = 'MATNR'.
I_FIELDCAT-SELTEXT_L = '物料号'. "
APPEND I_FIELDCAT TO I_FIELDCAT_ALV.
POS = POS + 1.
I_FIELDCAT-COL_POS = POS.
I_FIELDCAT-FIELDNAME = 'WFPCY'.
I_FIELDCAT-SELTEXT_L = '没有被分摊'.
APPEND I_FIELDCAT TO I_FIELDCAT_ALV.
POS = POS + 1.
I_FIELDCAT-COL_POS = POS.
I_FIELDCAT-FIELDNAME = 'ESTPRD'.
I_FIELDCAT-SELTEXT_L = '未分配价格差异'.
APPEND I_FIELDCAT TO I_FIELDCAT_ALV.
CLEAR I_FIELDCAT.
ENDFORM. "fields
*&---------------------------------------------------------------------*
*& Form display_data
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM DISPLAY_DATA.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM = W_REPID "
I_SAVE = ''
IS_LAYOUT = I_LAYOUT "
IT_FIELDCAT = I_FIELDCAT_ALV[] "
I_GRID_TITLE = TMP_TITLE
TABLES
T_OUTTAB = itab. "
ENDFORM. "display_data