TYPES:BEGIN OF TY_MSEG,
MBLNR TYPE MSEG-MBLNR,
MJAHR TYPE MSEG-MJAHR,
ZEILE TYPE MSEG-ZEILE,
BUKRS TYPE MSEG-BUKRS,
BWART TYPE MSEG-BWART,
MATNR TYPE MSEG-MATNR,
WERKS TYPE MSEG-WERKS,
MENGE TYPE MSEG-MENGE,
UMWRK TYPE MSEG-UMWRK,
PRCTR TYPE MSEG-PRCTR,
PPRCTR TYPE MSEG-PPRCTR,
SOBKZ TYPE MSEG-SOBKZ,
PS_PSP_PNR TYPE MSEG-PS_PSP_PNR,
END OF TY_MSEG.
DATA:IT_MSEG TYPE TABLE OF TY_MSEG WITH HEADER LINE.
DATA:ITAB TYPE TABLE OF ZFI_PROFIT_DOC WITH HEADER LINE.
DATA:IT_RESULT TYPE TABLE OF ZFI_PROFIT_DOC WITH HEADER LINE.
TYPES:BEGIN OF TY_MBEW ,
MATNR TYPE MBEW-MATNR,
BWKEY TYPE MBEW-BWKEY,
STPRS TYPE MBEW-STPRS, "标准价格
PEINH TYPE MBEW-PEINH,
BWPRH TYPE MBEW-BWPRH, "商业价格1
BWPH1 TYPE MBEW-BWPH1, "商业价格2
BWPEI TYPE MBEW-BWPEI,
END OF TY_MBEW.
DATA:IT_MBEW TYPE TABLE OF TY_MBEW WITH HEADER LINE.
DATA:G_STPRS1 TYPE MBEW-STPRS.
DATA:G_STPRS2 TYPE MBEW-STPRS.
DATA:G_STPRS3 TYPE MBEW-STPRS.
TYPES:BEGIN OF TY_QBEW,
MATNR TYPE QBEW-MATNR,
BWKEY TYPE QBEW-BWKEY,
PSPNR TYPE QBEW-PSPNR,
STPRS TYPE MBEW-STPRS, "标准价格
PEINH TYPE MBEW-PEINH,
END OF TY_QBEW.
DATA:IT_QBEW TYPE TABLE OF TY_QBEW WITH HEADER LINE.
DATA:DOCUMENTHEADER TYPE BAPIACHE09.
DATA:OBJ_KEY TYPE BAPIACHE09-OBJ_KEY.
DATA:ACCOUNTGL TYPE TABLE OF BAPIACGL09 WITH HEADER LINE.
DATA:CURRENCYAMOUNT TYPE TABLE OF BAPIACCR09 WITH HEADER LINE.
DATA:RETURN TYPE TABLE OF BAPIRET2 WITH HEADER LINE.
DATA:G_FLAG(1).
type-pools: slis.
data: ws_fieldcat type slis_t_fieldcat_alv with header line.
data: ws_fieldgroups_tab type slis_t_sp_group_alv,
ws_layout type slis_layout_alv,
ws_sortfields_tab type slis_t_sortinfo_alv with header line.
data: nn type i value 0.
data: v_repid like sy-repid.
data: title type lvc_title .
data: gt_events type slis_t_event.
data:gs_events like line of gt_events.
data:gt_event_exit type slis_t_event_exit.
data:gs_event_exit type slis_event_exit.
*ADDED BY SHIMING 20091117
TYPES:BEGIN OF TY_T001,
BUKRS TYPE T001-BUKRS,
BUTXT TYPE T001-BUTXT,
END OF TY_T001.
DATA:GT_T001 TYPE TABLE OF TY_T001 WITH HEADER LINE.
SELECTION-SCREEN BEGIN OF BLOCK MAIN WITH FRAME TITLE TEXT-001.
SELECT-OPTIONS:S_BUKRS FOR MSEG-BUKRS OBLIGATORY DEFAULT ‘6000‘.
SELECT-OPTIONS:S_BUDAT FOR MKPF-BUDAT.
SELECT-OPTIONS:S_MBLNR FOR MKPF-MBLNR.
SELECTION-SCREEN SKIP.
parameters:P_POST RADIOBUTTON GROUP SHI,
P_DISP RADIOBUTTON GROUP SHI,
P_BLDAT TYPE BKPF-BLDAT.
SELECTION-SCREEN END OF BLOCK MAIN.
at selection-screen.
REFRESH GT_T001.CLEAR GT_T001.
SELECT BUKRS
BUTXT
FROM T001
INTO TABLE GT_T001
WHERE BUKRS IN S_BUKRS.
LOOP AT GT_T001.
AUTHORITY-CHECK OBJECT ‘F_BKPF_BUK‘
ID ‘BUKRS‘ FIELD GT_T001-BUKRS
ID ‘ACTVT‘ DUMMY.
IF SY-SUBRC <> 0.
MESSAGE E013(ZFICO001) WITH GT_T001-BUKRS.
ENDIF.
ENDLOOP.
START-OF-SELECTION.
IF P_POST = ‘X‘.
PERFORM FRM_GET_DATA.
PERFORM FRM_POST_DATA.
PERFORM FRM_DIS_DATA.
ELSE.
PERFORM FRM_GET_LOG.
PERFORM FRM_DIS_LOG.
ENDIF.
*&---------------------------------------------------------------------*
*& Form FRM_GET_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM FRM_GET_DATA .
IF S_BUDAT[] IS INITIAL.
S_BUDAT-SIGN = ‘I‘.
S_BUDAT-OPTION = ‘EQ‘.
S_BUDAT-LOW = SY-DATUM.
APPEND S_BUDAT.
ENDIF.
SELECT A~MBLNR
A~MJAHR
A~ZEILE
A~BUKRS
A~BWART
A~MATNR
A~WERKS
A~MENGE
A~UMWRK
A~PRCTR
A~PPRCTR
A~SOBKZ
A~PS_PSP_PNR
INTO TABLE IT_MSEG
FROM MSEG AS A
INNER JOIN MKPF AS B
ON A~MBLNR = B~MBLNR
AND A~MJAHR = B~MJAHR
WHERE A~BUKRS IN S_BUKRS
AND B~BUDAT IN S_BUDAT
AND A~XAUTO = ‘‘
AND ( A~BWART = ‘Z31‘ OR A~BWART = ‘Z71‘ )
AND A~MBLNR IN S_MBLNR.
SELECT *
FROM ZFI_PROFIT_DOC
INTO TABLE ITAB
WHERE BUKRS IN S_BUKRS.
LOOP AT IT_MSEG.
CLEAR ITAB.
READ TABLE ITAB WITH KEY MBLNR = IT_MSEG-MBLNR
MJAHR = IT_MSEG-MJAHR
ZEILE = IT_MSEG-ZEILE
FLAG = ‘‘.
IF SY-SUBRC = 0.
DELETE IT_MSEG.
CONTINUE.
ENDIF.
ENDLOOP.
DELETE ITAB WHERE FLAG = ‘‘.
IF ITAB[] IS NOT INITIAL.
SELECT MBLNR
MJAHR
ZEILE
BUKRS
BWART
MATNR
WERKS
MENGE
UMWRK
PRCTR
PPRCTR
SOBKZ
PS_PSP_PNR
APPENDING TABLE IT_MSEG
FROM MSEG
FOR ALL ENTRIES IN ITAB
WHERE MBLNR = ITAB-MBLNR
AND MJAHR = ITAB-MJAHR
AND ZEILE = ITAB-ZEILE.
ENDIF.
IF IT_MSEG[] IS INITIAL.
MESSAGE ‘NO RECORD!‘ TYPE ‘E‘.
ENDIF.
SORT IT_MSEG BY MBLNR MJAHR ZEILE.
DELETE ADJACENT DUPLICATES FROM IT_MSEG COMPARING MBLNR MJAHR ZEILE.
IF IT_MSEG[] IS NOT INITIAL.
SELECT MATNR
BWKEY
STPRS
PEINH
BWPRH
BWPH1
BWPEI
FROM MBEW
INTO TABLE IT_MBEW
FOR ALL ENTRIES IN IT_MSEG
WHERE MATNR = IT_MSEG-MATNR
AND BWKEY = IT_MSEG-WERKS.
SELECT MATNR
BWKEY
PSPNR
STPRS
PEINH
FROM QBEW
INTO TABLE IT_QBEW
FOR ALL ENTRIES IN IT_MSEG
WHERE MATNR = IT_MSEG-MATNR
AND BWKEY = IT_MSEG-WERKS
AND PSPNR = IT_MSEG-PS_PSP_PNR.
ENDIF.
ENDFORM. " FRM_GET_DATA
*&---------------------------------------------------------------------*
*& Form FRM_POST_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM FRM_POST_DATA .
LOOP AT IT_MSEG.
MOVE-CORRESPONDING IT_MSEG TO IT_RESULT.
CLEAR RETURN.
LOOP AT RETURN WHERE ( TYPE = ‘E‘ OR TYPE = ‘A‘ ) AND NUMBER NE ‘609‘ .
G_FLAG = ‘X‘.
IT_RESULT-DATUM = SY-DATUM.
IT_RESULT-UZEIT = SY-UZEIT.
CONCATENATE ‘调入凭证出错,请手工处理:‘ RETURN-MESSAGE INTO IT_RESULT-MESSAGE.
APPEND IT_RESULT.
CLEAR IT_RESULT.
EXIT.
ENDLOOP.
IF G_FLAG EQ ‘X‘.
CALL FUNCTION ‘BAPI_TRANSACTION_ROLLBACK‘.
ELSE.
CALL FUNCTION ‘BAPI_TRANSACTION_COMMIT‘.
IT_RESULT-BELNR1 = OBJ_KEY+0(10).
* IT_RESULT-GJAHR = OBJ_KEY+14(4).
IT_RESULT-DATUM = SY-DATUM.
IT_RESULT-UZEIT = SY-UZEIT.
IT_RESULT-MESSAGE = ‘凭证过帐成功!‘.
APPEND IT_RESULT.
CLEAR IT_RESULT.
wait up to 1 seconds.
ENDIF.
ENDIF.
ENDLOOP.
IF IT_RESULT[] IS NOT INITIAL.
MODIFY ZFI_PROFIT_DOC FROM TABLE IT_RESULT.
IF SY-SUBRC EQ 0.
COMMIT WORK.
ELSE.
ROLLBACK WORK.
ENDIF.
ENDIF.
ENDFORM. " FRM_POST_DATA
*&---------------------------------------------------------------------*
*& Form FRM_DIS_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM FRM_DIS_DATA .
refresh:ws_fieldcat.
refresh gt_events.
*添加ALV events
refresh gt_events.
*添加ALV events
clear gs_events.
gs_event_exit-ucomm = ‘SAVE‘.
gs_event_exit-after = ‘X‘.
append gs_event_exit to gt_event_exit.
* 填充各列
perform fill_alv_fieldcat using ‘MBLNR‘ ‘物料凭证号‘.
perform fill_alv_fieldcat using ‘MJAHR‘ ‘物料凭证年度‘.
perform fill_alv_fieldcat using ‘ZEILE‘ ‘物料凭证项目‘.
perform fill_alv_fieldcat using ‘BUKRS‘ ‘公司代码‘.
perform fill_alv_fieldcat using ‘BELNR‘ ‘会计凭证编号(调出)‘.
perform fill_alv_fieldcat using ‘BELNR1‘ ‘会计凭证编号(调入)‘.
perform fill_alv_fieldcat using ‘GJAHR‘ ‘会计年度‘.
perform fill_alv_fieldcat using ‘MESSAGE‘ ‘消息‘.
ENDFORM. " FRM_DISLOG
*&---------------------------------------------------------------------*
*& Form fill_alv_fieldcat
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_FIELDNAME text
* -->P_REPTEXT_DDIC text
*----------------------------------------------------------------------*
form fill_alv_fieldcat using p_fieldname type slis_fieldname
p_reptext_ddic like dd03p-reptext.
endform. " DISPLAY_DATA
*&---------------------------------------------------------------------*
*& Form STANDARD_FULLSCREEN
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
form set_pf using rt_extab type slis_t_extab.
set pf-status ‘STANDARD_FULLSCREEN‘." EXCLUDING rt_extab.
endform. "set_status
*&---------------------------------------------------------------------*
*& Form FRM_GET_LOG
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM FRM_GET_LOG .
SELECT *
FROM ZFI_PROFIT_DOC
INTO TABLE ITAB
WHERE BUKRS IN S_BUKRS
AND DATUM IN S_BUDAT.
ENDFORM. " FRM_GET_LOG
*&---------------------------------------------------------------------*
*& Form FRM_DIS_LOG
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM FRM_DIS_LOG .
refresh:ws_fieldcat.
refresh gt_events.
*添加ALV events
refresh gt_events.
*添加ALV events
clear gs_events.
gs_event_exit-ucomm = ‘SAVE‘.
gs_event_exit-after = ‘X‘.
append gs_event_exit to gt_event_exit.
* 填充各列
perform fill_alv_fieldcat using ‘MBLNR‘ ‘物料凭证号‘.
perform fill_alv_fieldcat using ‘MJAHR‘ ‘物料凭证年度‘.
perform fill_alv_fieldcat using ‘ZEILE‘ ‘物料凭证项目‘.
perform fill_alv_fieldcat using ‘BUKRS‘ ‘公司代码‘.
perform fill_alv_fieldcat using ‘BELNR‘ ‘会计凭证编号(调出)‘.
perform fill_alv_fieldcat using ‘BELNR1‘ ‘会计凭证编号(调入)‘.
perform fill_alv_fieldcat using ‘GJAHR‘ ‘会计年度‘.
perform fill_alv_fieldcat using ‘MESSAGE‘ ‘消息‘.
perform fill_alv_fieldcat using ‘DATUM‘ ‘过帐日期‘.
perform fill_alv_fieldcat using ‘UZEIT‘ ‘过帐时间‘.
tables
t_outtab = ITAB
exceptions
program_error = 1
others = 2.
ENDFORM. " FRM_DIS_LOG
*&---------------------------------------------------------------------*
*& Form user_command
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->RF_UCOMM text
* -->RS text
*----------------------------------------------------------------------*
form user_command using rf_ucomm like sy-ucomm
rs type slis_selfield.
data: lr_grid type ref to cl_gui_alv_grid.
call function ‘GET_GLOBALS_FROM_SLVC_FULLSCR‘
IMPORTING
e_grid = lr_grid.
call method lr_grid->check_changed_data.
rs-refresh = ‘X‘. "自动刷新
case rf_ucomm.
WHEN ‘&IC1‘.
CHECK RS-TABINDEX GT 0.
READ TABLE ITAB INDEX RS-TABINDEX.
CHECK SY-SUBRC EQ 0.
IF ITAB-MBLNR NE ‘‘ AND RS-FIELDNAME = ‘MBLNR‘.
SET PARAMETER ID ‘MBN‘ FIELD ITAB-MBLNR.
SET PARAMETER ID ‘MJA‘ FIELD ITAB-MJAHR.
CALL TRANSACTION ‘MB03‘ AND SKIP FIRST SCREEN.
ENDIF.
IF ITAB-BELNR NE ‘‘ AND RS-FIELDNAME = ‘BELNR‘.
SET PARAMETER ID ‘BLN‘ FIELD ITAB-BELNR.
SET PARAMETER ID ‘BUK‘ FIELD ITAB-BUKRS.
SET PARAMETER ID ‘GJR‘ FIELD ITAB-GJAHR.
CALL TRANSACTION ‘FB03‘ AND SKIP FIRST SCREEN.
ENDIF.
IF ITAB-BELNR1 NE ‘‘ AND RS-FIELDNAME = ‘BELNR1‘.
SET PARAMETER ID ‘BLN‘ FIELD ITAB-BELNR1.
SET PARAMETER ID ‘BUK‘ FIELD ITAB-BUKRS.
SET PARAMETER ID ‘GJR‘ FIELD ITAB-GJAHR.
CALL TRANSACTION ‘FB03‘ AND SKIP FIRST SCREEN.
ENDIF.
endcase.
rs-refresh = ‘X‘.
endform. "user_command
*&---------------------------------------------------------------------*
*& Form user_command
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->RF_UCOMM text
* -->RS text
*----------------------------------------------------------------------*
form user_command1 using rf_ucomm like sy-ucomm
rs type slis_selfield.
data: lr_grid type ref to cl_gui_alv_grid.
call function ‘GET_GLOBALS_FROM_SLVC_FULLSCR‘
IMPORTING
e_grid = lr_grid.
call method lr_grid->check_changed_data.
rs-refresh = ‘X‘. "自动刷新
case rf_ucomm.
WHEN ‘&IC1‘.
CHECK RS-TABINDEX GT 0.
READ TABLE IT_RESULT INDEX RS-TABINDEX.
CHECK SY-SUBRC EQ 0.
IF IT_RESULT-MBLNR NE ‘‘ AND RS-FIELDNAME = ‘MBLNR‘.
SET PARAMETER ID ‘MBN‘ FIELD IT_RESULT-MBLNR.
SET PARAMETER ID ‘MJA‘ FIELD IT_RESULT-MJAHR.
CALL TRANSACTION ‘MB03‘ AND SKIP FIRST SCREEN.
ENDIF.
IF IT_RESULT-BELNR NE ‘‘ AND RS-FIELDNAME = ‘BELNR‘.
SET PARAMETER ID ‘BLN‘ FIELD IT_RESULT-BELNR.
SET PARAMETER ID ‘BUK‘ FIELD IT_RESULT-BUKRS.
SET PARAMETER ID ‘GJR‘ FIELD IT_RESULT-GJAHR.
CALL TRANSACTION ‘FB03‘ AND SKIP FIRST SCREEN.
ENDIF.
IF IT_RESULT-BELNR1 NE ‘‘ AND RS-FIELDNAME = ‘BELNR1‘.
SET PARAMETER ID ‘BLN‘ FIELD IT_RESULT-BELNR1.
SET PARAMETER ID ‘BUK‘ FIELD IT_RESULT-BUKRS.
SET PARAMETER ID ‘GJR‘ FIELD IT_RESULT-GJAHR.
CALL TRANSACTION ‘FB03‘ AND SKIP FIRST SCREEN.
ENDIF.