*&---------------------------------------------------------------------*
*& Report ZRATE
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT ZRATE.
DATA :
BEGIN OF PO_ITEM,
FWAERS TYPE WAERS," 項目交貨日期
TWAERS TYPE WAERS," 期望供應商
CRATE TYPE P DECIMALS 5,
END OF PO_ITEM.
TYPE-POOLS: SLIS.
DATA: GT_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV,
GS_LAYOUT TYPE SLIS_LAYOUT_ALV.
DATA: ITEMS LIKE PO_ITEM OCCURS 0 WITH HEADER LINE.
SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001.
PARAMETERS: P_DATE LIKE SY-DATUM DEFAULT SY-DATUM.
PARAMETERS: P_RATE LIKE TCURT-WAERS DEFAULT 'USD'.
SELECTION-SCREEN END OF BLOCK B1.
SELECT WAERS INTO PO_ITEM-FWAERS
FROM TCURT WHERE SPRAS = 'M'.
PO_ITEM-TWAERS = P_RATE.
CALL FUNCTION 'READ_EXCHANGE_RATE'
EXPORTING
CLIENT = SY-MANDT
DATE = P_DATE
FOREIGN_CURRENCY = PO_ITEM-TWAERS
LOCAL_CURRENCY = PO_ITEM-FWAERS
TYPE_OF_RATE = 'M'
IMPORTING
EXCHANGE_RATE = PO_ITEM-CRATE
EXCEPTIONS
NO_RATE_FOUND = 1
NO_FACTORS_FOUND = 2
NO_SPREAD_FOUND = 3
DERIVED_2_TIMES = 4
OVERFLOW = 5
ZERO_RATE = 6
OTHERS = 7.
IF PO_ITEM-CRATE <= 0.
CALL FUNCTION 'READ_EXCHANGE_RATE'
EXPORTING
CLIENT = SY-MANDT
DATE = P_DATE
FOREIGN_CURRENCY = PO_ITEM-FWAERS
LOCAL_CURRENCY = PO_ITEM-TWAERS
TYPE_OF_RATE = 'M'
IMPORTING
EXCHANGE_RATE = PO_ITEM-CRATE
EXCEPTIONS
NO_RATE_FOUND = 1
NO_FACTORS_FOUND = 2
NO_SPREAD_FOUND = 3
DERIVED_2_TIMES = 4
OVERFLOW = 5
ZERO_RATE = 6
OTHERS = 7.
PO_ITEM-CRATE = PO_ITEM-CRATE * -1.
ENDIF.
IF PO_ITEM-CRATE < 0.
PO_ITEM-CRATE = 1 / ABS( PO_ITEM-CRATE ).
ENDIF.
APPEND PO_ITEM TO ITEMS.
CLEAR PO_ITEM.
ENDSELECT.
DATA: LS_FIELDCAT TYPE SLIS_FIELDCAT_ALV.
CLEAR LS_FIELDCAT.
LS_FIELDCAT-COL_POS = 1.
LS_FIELDCAT-FIELDNAME = 'FWAERS'.
LS_FIELDCAT-SELTEXT_L = 'FROM'.
LS_FIELDCAT-SELTEXT_M = 'FROM'.
LS_FIELDCAT-SELTEXT_S = 'FROM'.
LS_FIELDCAT-OUTPUTLEN = 4.
LS_FIELDCAT-KEY = 'X'.
APPEND LS_FIELDCAT TO GT_FIELDCAT.
CLEAR LS_FIELDCAT.
LS_FIELDCAT-COL_POS = 2.
LS_FIELDCAT-FIELDNAME = 'TWAERS'.
LS_FIELDCAT-SELTEXT_L = 'To'.
LS_FIELDCAT-SELTEXT_M = 'To'.
LS_FIELDCAT-SELTEXT_S = 'To'.
LS_FIELDCAT-OUTPUTLEN = 4.
LS_FIELDCAT-KEY = 'X'.
APPEND LS_FIELDCAT TO GT_FIELDCAT.
CLEAR LS_FIELDCAT.
LS_FIELDCAT-COL_POS = 3.
LS_FIELDCAT-FIELDNAME = 'CRATE'.
LS_FIELDCAT-SELTEXT_L = 'RATE'.
LS_FIELDCAT-SELTEXT_M = 'RATE'.
LS_FIELDCAT-SELTEXT_S = 'RATE'.
LS_FIELDCAT-OUTPUTLEN = 10.
LS_FIELDCAT-KEY = 'X'.
APPEND LS_FIELDCAT TO GT_FIELDCAT.
CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
EXPORTING
* I_BYPASSING_BUFFER = 'X'
* I_BUFFER_ACTIVE = ' '
* I_CALLBACK_PROGRAM = G_REPID
IT_FIELDCAT = GT_FIELDCAT[]
* I_CALLBACK_PF_STATUS_SET = G_STATUS
* I_CALLBACK_USER_COMMAND = 'USER_COMMAND'
* IT_EVENTS = IT_EVENTS
* IS_LAYOUT = X_LAYOUT
I_SAVE = 'A'
TABLES
T_OUTTAB = ITEMS
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.
阅读(808) | 评论(0) | 转发(0) |