取退货单数(凡是小票有一笔退货即算退货单),退货金额(取金额为负数)
TYPES: BEGIN OF ty_balance,
/BIC/ZPRPTDTID TYPE /BIC/OIZPRPTDTID,
/BIC/ZBUSDE TYPE /BIC/OIZBUSDE,
/BIC/ZSTORE TYPE /BIC/OIZSTORE,
* /BIC/ZTHJE TYPE /BIC/OIZTHJE,
* /BIC/ZTHJS TYPE /BIC/OIZTHJS,
/BIC/ZDTLQTY TYPE /BIC/OIZDTLQTY,
/BIC/ZPOSRPTID TYPE /BIC/OIZPOSRPTID,
/BIC/ZDTLFTAMT TYPE /BIC/OIZDTLFTAMT,
END OF ty_balance.
TYPES: BEGIN OF TY_HEADER,
/BIC/ZBUSDE TYPE /BIC/OIZBUSDE,
/BIC/ZSTORE TYPE /BIC/OIZSTORE,
/BIC/ZPOSRPTID TYPE /BIC/OIZPOSRPTID,
END OF TY_HEADER.
DATA: l_t_balance TYPE STANDARD TABLE OF ty_balance,
l_wa_balance LIKE LINE OF l_t_balance,
L_T_HEADER TYPE STANDARD TABLE OF TY_HEADER,
L_WA_HEADER LIKE LINE OF L_T_HEADER,
l_wa_result TYPE _ty_s_TG_1,
l_t_result TYPE _ty_t_TG_1,
l_line TYPE I,
T_LINE TYPE I,
L_ZDTLFTAMT TYPE /BIC/OIZDTLFTAMT.
BREAK-POINT.
IF RESULT_PACKAGE IS NOT INITIAL.
SELECT /BIC/ZBUSDE /BIC/ZSTORE /BIC/ZPOSRPTID
INTO TABLE L_T_HEADER
FROM /BIC/AZCELT00200
FOR ALL ENTRIES IN RESULT_PACKAGE
WHERE /BIC/ZSTORE = RESULT_PACKAGE-/BIC/ZSTORE
AND /BIC/ZBUSDE = RESULT_PACKAGE-CALDAY.
SORT L_T_HEADER BY /BIC/ZSTORE /BIC/ZBUSDE /BIC/ZPOSRPTID.
DELETE ADJACENT DUPLICATES FROM L_t_header COMPARING /BIC/ZBUSDE
/BIC/ZSTORE /BIC/ZPOSRPTID.
SELECT /BIC/ZPRPTDTID /BIC/ZBUSDE /BIC/ZSTORE /BIC/ZDTLQTY
/BIC/ZPOSRPTID /BIC/ZDTLFTAMT
INTO TABLE l_t_balance
FROM /BIC/AZCELT00200
FOR ALL ENTRIES IN RESULT_PACKAGE
WHERE /BIC/ZSTORE = RESULT_PACKAGE-/BIC/ZSTORE
AND /BIC/ZBUSDE = RESULT_PACKAGE-CALDAY.
SORT l_t_balance BY /BIC/ZPRPTDTID /BIC/ZSTORE /BIC/ZBUSDE.
CLEAR: L_LINE, T_LINE.
LOOP AT RESULT_PACKAGE INTO l_wa_result.
LOOP AT L_T_HEADER INTO L_WA_HEADER where /BIC/ZBUSDE =
L_WA_result-calday
AND /BIC/ZSTORE = L_WA_result-/BIC/ZSTORE.
LOOP AT L_T_BALANCE INTO L_WA_BALANCE
WHERE /BIC/ZBUSDE = L_WA_HEADER-/BIC/ZBUSDE
AND /BIC/ZSTORE = L_WA_HEADER-/BIC/ZSTORE
AND /BIC/ZPOSRPTID = L_WA_HEADER-/BIC/ZPOSRPTID.
IF L_WA_BALANCE-/BIC/ZDTLQTY < 0.
L_LINE = L_LINE + 1.
L_ZDTLFTAMT = L_ZDTLFTAMT + L_WA_BALANCE-/BIC/ZDTLFTAMT.
ENDIF.
ENDLOOP.
IF L_LINE >= 1.
L_LINE = 1.
ENDIF.
T_LINE = T_LINE + L_line.
CLEAR L_line.
ENDLOOP.
L_WA_RESULT-/BIC/ZTHJS = L_WA_RESULT-/BIC/ZTHJS + T_LINE.
L_WA_RESULT-/BIC/ZTHJE = L_ZDTLFTAMT.
CLEAR: T_Line, l_zdtlftamt.
MODIFY RESULT_PACKAGE FROM L_WA_RESULT.
ENDLOOP.
ENDIF.