*&---------------------------------------------------------------------*
*& Report ZFIR013
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT zfir013.
TABLES:acdoca.
TYPES: BEGIN OF typ_alv,
rbukrs TYPE acdoca-rbukrs,
racct TYPE acdoca-racct,
txt50 TYPE skat-txt50,
lifnr TYPE acdoca-lifnr,
name1 TYPE lfa1-name1,
kunnr TYPE acdoca-kunnr,
name2 TYPE kna1-name1,
rcntr TYPE acdoca-rcntr,
ktext TYPE cskt-ktext,
aufnr TYPE acdoca-aufnr,
ktext2 TYPE coas-ktext,
rtcur TYPE acdoca-rtcur,
yqcje TYPE acdoca-tsl,
bqcje TYPE acdoca-hsl,
yjfje TYPE acdoca-tsl,
bjfje TYPE acdoca-hsl,
ydfje TYPE acdoca-tsl,
bdfje TYPE acdoca-hsl,
yqmye TYPE acdoca-tsl,
bqmye TYPE acdoca-hsl,
END OF typ_alv.
DATA: gt_alv TYPE TABLE OF typ_alv WITH HEADER LINE.
DATA : BEGIN OF gt_acdoca OCCURS 0,
rbukrs TYPE acdoca-rbukrs,
gjahr TYPE acdoca-gjahr,
poper TYPE acdoca-poper,
racct TYPE acdoca-racct,
lifnr TYPE acdoca-lifnr,
kunnr TYPE acdoca-kunnr,
rcntr TYPE acdoca-rcntr,
aufnr TYPE acdoca-aufnr,
rtcur TYPE acdoca-rtcur,
ebeln TYPE acdoca-ebeln,
tsl TYPE acdoca-tsl,
hsl TYPE acdoca-hsl,
zuonr TYPE acdoca-zuonr,
drcrk TYPE acdoca-drcrk,
fiscyearper TYPE acdoca-fiscyearper,
END OF gt_acdoca.
DATA : BEGIN OF gt_skat OCCURS 0,
racct TYPE acdoca-racct,
txt50 TYPE skat-txt50,
END OF gt_skat.
DATA : BEGIN OF gt_lfa1 OCCURS 0,
lifnr TYPE acdoca-lifnr,
name1 TYPE lfa1-name1,
END OF gt_lfa1.
DATA : BEGIN OF gt_kna1 OCCURS 0,
kunnr TYPE acdoca-kunnr,
name1 TYPE kna1-name1,
END OF gt_kna1.
DATA : BEGIN OF gt_cskt OCCURS 0,
rcntr TYPE acdoca-rcntr,
ktext TYPE cskt-ktext,
END OF gt_cskt.
DATA : BEGIN OF gt_coas OCCURS 0,
aufnr TYPE acdoca-aufnr,
ktext TYPE coas-ktext,
END OF gt_coas.
DATA : BEGIN OF gt_ska1 OCCURS 0,
saknr TYPE ska1-saknr,
glaccount_type TYPE ska1-glaccount_type,
END OF gt_ska1.
DATA : BEGIN OF gt_skb1 OCCURS 0,
saknr TYPE skb1-saknr,
mitkz TYPE skb1-mitkz,
END OF gt_skb1.
DATA: screen_start_date TYPE sy-datum,
screen_end_date TYPE sy-datum,
select_start_date TYPE sy-datum,
qc_gjahr TYPE acdoca-gjahr,
qc_poper TYPE acdoca-poper,
st_fiscyearper TYPE acdoca-fiscyearper,
en_fiscyearper TYPE acdoca-fiscyearper.
DATA: gs_layout TYPE lvc_s_layo,
gs_fieldcat TYPE lvc_s_fcat,
gt_fieldcat TYPE lvc_t_fcat.
DATA: gs_layout_detail TYPE lvc_s_layo,
gs_fieldcat_detail TYPE lvc_s_fcat,
gt_fieldcat_detail TYPE lvc_t_fcat.
DEFINE mac01 .
CLEAR gs_fieldcat .
gs_fieldcat-fieldname = &1 .
gs_fieldcat-scrtext_l = &2 .
gs_fieldcat-scrtext_s = &2 .
gs_fieldcat-scrtext_m = &2 .
gs_fieldcat-edit = &3 .
* gs_fieldcat-key = &4 .
IF &1 = 'LIFNR' OR &1 = 'KUNNR' OR &1 = 'RCNTR' OR &1 = 'AUFNR'.
gs_fieldcat-no_zero = 'X' .
ENDIF.
* gs_fieldcat-no_out = &5 .
gs_fieldcat-ref_table = &4 .
gs_fieldcat-ref_field = &5 .
gs_fieldcat-cfieldname = &6.
APPEND gs_fieldcat TO gt_fieldcat .
END-OF-DEFINITION.
SELECTION-SCREEN: BEGIN OF BLOCK b1 WITH FRAME TITLE TEXT-001.
SELECT-OPTIONS: s_bukrs FOR acdoca-rbukrs OBLIGATORY.
PARAMETERS: p_gjahr TYPE acdoca-gjahr OBLIGATORY.
SELECT-OPTIONS: s_poper FOR acdoca-poper OBLIGATORY,
s_racct FOR acdoca-racct,
s_lifnr FOR acdoca-lifnr,
s_kunnr FOR acdoca-kunnr,
s_rcntr FOR acdoca-rcntr,
s_aufnr FOR acdoca-aufnr.
SELECTION-SCREEN:END OF BLOCK b1.
START-OF-SELECTION.
PERFORM get_data.
PERFORM process_data.
PERFORM show_alv.
*&---------------------------------------------------------------------*
*& Form get_data
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM get_data .
* DATA: lv_fiscyearper TYPE acdoca-fiscyearper.
SORT s_poper BY high DESCENDING.
READ TABLE s_poper INDEX 1.
IF s_poper-high IS NOT INITIAL.
en_fiscyearper = p_gjahr && s_poper-high.
ELSE.
en_fiscyearper = p_gjahr && s_poper-low.
ENDIF.
SORT s_poper BY low ASCENDING.
READ TABLE s_poper INDEX 1.
screen_start_date = p_gjahr && s_poper-low+1(2) && '01'.
select_start_date = screen_start_date - 1.
st_fiscyearper = select_start_date+0(4) && '0' && select_start_date+4(2).
* qc_gjahr = select_start_date+0(4).
* qc_poper = select_start_date+4(2).
CLEAR:gt_acdoca[].
SELECT
rbukrs
gjahr
poper
racct
lifnr
kunnr
rcntr
aufnr
rtcur
ebeln
tsl
hsl
zuonr
drcrk
fiscyearper
INTO CORRESPONDING FIELDS OF TABLE gt_acdoca[]
FROM acdoca
WHERE rbukrs IN s_bukrs
AND racct IN s_racct
* AND lifnr IN s_lifnr
AND kunnr IN s_kunnr
AND rcntr IN s_rcntr
AND aufnr IN s_aufnr
AND fiscyearper <= en_fiscyearper
AND bstat NE 'C'.
* AND (
* ( gjahr = p_gjahr AND poper IN s_poper )
* OR ( gjahr = qc_gjahr AND poper = qc_poper )
* ).
IF gt_acdoca[] IS INITIAL.
MESSAGE '没有符合条件数据' TYPE 'S' DISPLAY LIKE 'E'.
LEAVE LIST-PROCESSING.
ELSE.
SELECT
saknr AS racct
txt50
INTO CORRESPONDING FIELDS OF TABLE gt_skat[]
FROM skat
FOR ALL ENTRIES IN gt_acdoca[]
WHERE saknr = gt_acdoca-racct
AND spras = 1.
SORT gt_skat[] BY racct.
SELECT
lifnr
name1
INTO CORRESPONDING FIELDS OF TABLE gt_lfa1[]
FROM lfa1
FOR ALL ENTRIES IN gt_acdoca[]
WHERE lifnr = gt_acdoca-lifnr
AND spras = 1.
SORT gt_lfa1[] BY lifnr.
SELECT
kunnr
name1
INTO CORRESPONDING FIELDS OF TABLE gt_kna1[]
FROM kna1
FOR ALL ENTRIES IN gt_acdoca[]
WHERE kunnr = gt_acdoca-kunnr
AND spras = 1.
SORT gt_kna1[] BY kunnr.
SELECT
kostl AS rcntr
ktext
INTO CORRESPONDING FIELDS OF TABLE gt_cskt[]
FROM cskt
FOR ALL ENTRIES IN gt_acdoca[]
WHERE kostl = gt_acdoca-rcntr
AND spras = 1.
SORT gt_cskt[] BY rcntr.
SELECT
aufnr
ktext
INTO CORRESPONDING FIELDS OF TABLE gt_coas[]
FROM coas
FOR ALL ENTRIES IN gt_acdoca[]
WHERE aufnr = gt_acdoca-aufnr.
SORT gt_coas[] BY aufnr.
SELECT
saknr
glaccount_type
INTO CORRESPONDING FIELDS OF TABLE gt_ska1[]
FROM ska1
FOR ALL ENTRIES IN gt_acdoca[]
WHERE saknr = gt_acdoca-racct.
SORT gt_ska1[] BY saknr.
SELECT
saknr
mitkz
INTO CORRESPONDING FIELDS OF TABLE gt_skb1[]
FROM skb1
FOR ALL ENTRIES IN gt_acdoca[]
WHERE saknr = gt_acdoca-racct.
SORT gt_skb1[] BY saknr.
ENDIF.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form process_data
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM process_data .
CLEAR gt_alv[].
LOOP AT gt_acdoca.
CLEAR gt_alv.
gt_alv-rbukrs = gt_acdoca-rbukrs.
gt_alv-racct = gt_acdoca-racct.
READ TABLE gt_skat WITH KEY racct = gt_alv-racct BINARY SEARCH.
IF sy-subrc = 0.
gt_alv-txt50 = gt_skat-txt50.
ENDIF.
gt_alv-rtcur = gt_acdoca-rtcur.
IF gt_acdoca-fiscyearper <= st_fiscyearper." AND gt_acdoca-poper = qc_poper.
gt_alv-yqcje = gt_acdoca-tsl.
gt_alv-bqcje = gt_acdoca-hsl.
IF gt_acdoca-racct >= '2202020000' AND gt_acdoca-racct <= '2202029999'.
* gt_alv-yqcje = gt_acdoca-tsl.
* gt_alv-bqcje = gt_acdoca-hsl.
IF gt_acdoca-lifnr IS INITIAL.
SELECT SINGLE lifnr
INTO gt_alv-lifnr
FROM ekko
WHERE ebeln = gt_acdoca-ebeln.
IF gt_alv-lifnr IS INITIAL.
gt_alv-lifnr = |{ gt_acdoca-zuonr ALPHA = IN }|.
ENDIF.
SELECT SINGLE name1
INTO gt_alv-name1
FROM lfa1
WHERE lifnr = gt_alv-lifnr
AND spras = 1.
ELSE.
gt_alv-lifnr = gt_acdoca-lifnr.
READ TABLE gt_lfa1 WITH KEY lifnr = gt_alv-lifnr BINARY SEARCH.
IF sy-subrc = 0.
gt_alv-name1 = gt_lfa1-name1.
ENDIF.
ENDIF.
ELSE.
READ TABLE gt_skb1 WITH KEY saknr = gt_acdoca-racct.
IF sy-subrc = 0.
IF gt_skb1-mitkz = 'K'.
* gt_alv-yqcje = gt_acdoca-tsl.
* gt_alv-bqcje = gt_acdoca-hsl.
gt_alv-lifnr = gt_acdoca-lifnr.
READ TABLE gt_lfa1 WITH KEY lifnr = gt_alv-lifnr BINARY SEARCH.
IF sy-subrc = 0.
gt_alv-name1 = gt_lfa1-name1.
ENDIF.
ELSEIF gt_skb1-mitkz = 'D'.
* gt_alv-yqcje = gt_acdoca-tsl.
* gt_alv-bqcje = gt_acdoca-hsl.
gt_alv-kunnr = gt_acdoca-kunnr.
READ TABLE gt_kna1 WITH KEY kunnr = gt_alv-kunnr BINARY SEARCH.
IF sy-subrc = 0.
gt_alv-name2 = gt_kna1-name1.
ENDIF.
ENDIF.
ENDIF.
* IF gt_alv-yqcje IS INITIAL.
READ TABLE gt_ska1 WITH KEY saknr = gt_acdoca-racct.
IF sy-subrc = 0.
IF gt_ska1-glaccount_type = 'P'.
* gt_alv-yqcje = gt_acdoca-tsl.
* gt_alv-bqcje = gt_acdoca-hsl.
gt_alv-rcntr = gt_acdoca-rcntr.
gt_alv-aufnr = gt_acdoca-aufnr.
READ TABLE gt_cskt WITH KEY rcntr = gt_alv-rcntr BINARY SEARCH.
IF sy-subrc = 0.
gt_alv-ktext = gt_cskt-ktext.
ENDIF.
READ TABLE gt_coas WITH KEY aufnr = gt_alv-aufnr BINARY SEARCH.
IF sy-subrc = 0.
gt_alv-ktext2 = gt_coas-ktext.
* ELSE.
* CLEAR gt_alv-aufnr.
ENDIF.
IF gt_alv-ktext2 IS INITIAL.
CLEAR gt_alv-aufnr.
ENDIF.
ENDIF.
ENDIF.
* ENDIF.
ENDIF.
ELSE.
IF gt_acdoca-drcrk = 'S'.
gt_alv-yjfje = gt_acdoca-tsl.
gt_alv-bjfje = gt_acdoca-hsl.
ELSE.
gt_alv-ydfje = gt_acdoca-tsl.
gt_alv-bdfje = gt_acdoca-hsl.
ENDIF.
IF gt_acdoca-racct >= '2202020000' AND gt_acdoca-racct <= '2202029999'.
* gt_alv-yqmye = gt_acdoca-tsl.
* gt_alv-bqmye = gt_acdoca-hsl.
* IF gt_acdoca-drcrk = 'S'.
* gt_alv-yjfje = gt_acdoca-tsl.
* gt_alv-bjfje = gt_acdoca-hsl.
* ELSE.
* gt_alv-ydfje = gt_acdoca-tsl.
* gt_alv-bdfje = gt_acdoca-hsl.
* ENDIF.
IF gt_acdoca-lifnr IS INITIAL.
SELECT SINGLE lifnr
INTO gt_alv-lifnr
FROM ekko
WHERE ebeln = gt_acdoca-ebeln.
IF gt_alv-lifnr IS INITIAL.
gt_alv-lifnr = |{ gt_acdoca-zuonr ALPHA = IN }|.
ENDIF.
SELECT SINGLE name1
INTO gt_alv-name1
FROM lfa1
WHERE lifnr = gt_alv-lifnr
AND spras = 1.
ELSE.
gt_alv-lifnr = gt_acdoca-lifnr.
READ TABLE gt_lfa1 WITH KEY lifnr = gt_alv-lifnr BINARY SEARCH.
IF sy-subrc = 0.
gt_alv-name1 = gt_lfa1-name1.
ENDIF.
ENDIF.
ELSE.
READ TABLE gt_skb1 WITH KEY saknr = gt_acdoca-racct.
IF sy-subrc = 0.
IF gt_skb1-mitkz = 'K'.
* gt_alv-yqmye = gt_acdoca-tsl.
* gt_alv-bqmye = gt_acdoca-hsl.
* IF gt_acdoca-drcrk = 'S'.
* gt_alv-yjfje = gt_acdoca-tsl.
* gt_alv-bjfje = gt_acdoca-hsl.
* ELSE.
* gt_alv-ydfje = gt_acdoca-tsl.
* gt_alv-bdfje = gt_acdoca-hsl.
* ENDIF.
gt_alv-lifnr = gt_acdoca-lifnr.
READ TABLE gt_lfa1 WITH KEY lifnr = gt_alv-lifnr BINARY SEARCH.
IF sy-subrc = 0.
gt_alv-name1 = gt_lfa1-name1.
ENDIF.
ELSEIF gt_skb1-mitkz = 'D'.
* gt_alv-yqmye = gt_acdoca-tsl.
* gt_alv-bqmye = gt_acdoca-hsl.
* IF gt_acdoca-drcrk = 'S'.
* gt_alv-yjfje = gt_acdoca-tsl.
* gt_alv-bjfje = gt_acdoca-hsl.
* ELSE.
* gt_alv-ydfje = gt_acdoca-tsl.
* gt_alv-bdfje = gt_acdoca-hsl.
* ENDIF.
gt_alv-kunnr = gt_acdoca-kunnr.
READ TABLE gt_kna1 WITH KEY kunnr = gt_alv-kunnr BINARY SEARCH.
IF sy-subrc = 0.
gt_alv-name2 = gt_kna1-name1.
ENDIF.
ENDIF.
ENDIF.
* IF gt_alv-yqcje IS INITIAL.
READ TABLE gt_ska1 WITH KEY saknr = gt_acdoca-racct.
IF sy-subrc = 0.
IF gt_ska1-glaccount_type = 'P'.
* gt_alv-yqmye = gt_acdoca-tsl.
* gt_alv-bqmye = gt_acdoca-hsl.
* IF gt_acdoca-drcrk = 'S'.
* gt_alv-yjfje = gt_acdoca-tsl.
* gt_alv-bjfje = gt_acdoca-hsl.
* ELSE.
* gt_alv-ydfje = gt_acdoca-tsl.
* gt_alv-bdfje = gt_acdoca-hsl.
* ENDIF.
gt_alv-rcntr = gt_acdoca-rcntr.
gt_alv-aufnr = gt_acdoca-aufnr.
READ TABLE gt_cskt WITH KEY rcntr = gt_alv-rcntr BINARY SEARCH.
IF sy-subrc = 0.
gt_alv-ktext = gt_cskt-ktext.
ENDIF.
READ TABLE gt_coas WITH KEY aufnr = gt_alv-aufnr BINARY SEARCH.
IF sy-subrc = 0.
gt_alv-ktext2 = gt_coas-ktext.
* ELSE.
* CLEAR gt_alv-aufnr.
ENDIF.
IF gt_alv-ktext2 IS INITIAL.
CLEAR gt_alv-aufnr.
ENDIF.
ENDIF.
ENDIF.
* ENDIF.
ENDIF.
ENDIF.
gt_alv-yqmye = gt_acdoca-tsl.
gt_alv-bqmye = gt_acdoca-hsl.
COLLECT gt_alv.
ENDLOOP.
DELETE gt_alv WHERE yqcje IS INITIAL
AND bqcje IS INITIAL
AND yjfje IS INITIAL
AND bjfje IS INITIAL
AND ydfje IS INITIAL
AND bdfje IS INITIAL
AND yqmye IS INITIAL
AND bqmye IS INITIAL.
IF s_lifnr[] IS NOT INITIAL.
DELETE gt_alv WHERE lifnr NOT IN s_lifnr[].
ENDIF.
IF gt_alv[] IS INITIAL.
MESSAGE '没有符合条件数据' TYPE 'S' DISPLAY LIKE 'E'.
LEAVE LIST-PROCESSING.
ELSE.
SORT gt_alv[] BY racct.
ENDIF.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form show_alv
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM show_alv .
*-行属性
CLEAR gs_layout.
gs_layout-zebra = 'X' . " 显示界面成色带交替
gs_layout-sel_mode = 'B' . " 选择模式()
gs_layout-detailinit = 'X' . " 是否可以弹出细节屏幕
gs_layout-cwidth_opt = 'X' . " 优化宽度
* gs_layout-box_fname = 'SEL' . " 指明复选框
*-列属性
CLEAR gt_fieldcat[] .
mac01: 'RBUKRS ' '公司代码 ' '' 'ACDOCA' 'RBUKRS' ''.
mac01: 'RACCT ' '会计科目 ' '' 'ACDOCA' 'RACCT' ''.
mac01: 'TXT50 ' '科目描述 ' '' '' '' ''.
mac01: 'LIFNR ' '供应商 ' '' 'ACDOCA' 'LIFNR' ''.
mac01: 'NAME1 ' '供应商名称 ' '' '' '' ''.
mac01: 'KUNNR ' '客户 ' '' 'ACDOCA' 'KUNNR' ''.
mac01: 'NAME2 ' '客户名称 ' '' '' '' ''.
mac01: 'RCNTR ' '成本中心 ' '' 'ACDOCA' 'RCNTR' ''.
mac01: 'KTEXT ' '成本中心描述 ' '' '' '' ''.
mac01: 'AUFNR ' '内部订单 ' '' 'ACDOCA' 'AUFNR' ''.
mac01: 'KTEXT2 ' '内部订单描述 ' '' '' '' ''.
mac01: 'RTCUR ' '货币 ' '' '' '' ''.
mac01: 'YQCJE ' '期初金额(原币) ' '' '' '' 'RTCUR'.
mac01: 'BQCJE ' '期初金额(本币) ' '' '' '' ''.
mac01: 'YJFJE ' '借方金额(原币) ' '' '' '' 'RTCUR'.
mac01: 'BJFJE ' '借方金额(本币) ' '' '' '' ''.
mac01: 'YDFJE ' '贷方金额(原币) ' '' '' '' 'RTCUR'.
mac01: 'BDFJE ' '贷方金额(本币)' '' '' '' ''.
mac01: 'YQMYE ' '期末余额(原币) ' '' '' '' 'RTCUR'.
mac01: 'BQMYE ' '期末余额(本币) ' '' '' '' ''.
LOOP AT gt_fieldcat INTO gs_fieldcat.
CASE gs_fieldcat-fieldname.
WHEN 'SEL'.
gs_fieldcat-checkbox = 'X'.
* gs_fieldcat-hotspot = 'X'.
MODIFY gt_fieldcat FROM gs_fieldcat.
WHEN 'MEINS'.
gs_fieldcat-edit_mask = '==CUNIT'.
MODIFY gt_fieldcat FROM gs_fieldcat.
ENDCASE.
ENDLOOP.
*-ALV函数
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
EXPORTING
i_callback_program = sy-repid
i_callback_pf_status_set = 'SUB_STATUS'
i_callback_user_command = 'SUB_USER_COMMAND'
is_layout_lvc = gs_layout
it_fieldcat_lvc = gt_fieldcat
i_save = 'A'
TABLES
t_outtab = gt_alv[]
EXCEPTIONS
program_error = 1
OTHERS = 2.
ENDFORM.
*&---------------------------------------------------------------------*
*& FORM SUB_STATUS
*&---------------------------------------------------------------------*
* 状态栏
*----------------------------------------------------------------------*
* --> P1 TEXT
* <-- P2 TEXT
*----------------------------------------------------------------------*
FORM sub_status USING rt_extab TYPE slis_t_extab .
CLEAR: rt_extab.
REFRESH: rt_extab.
SET PF-STATUS 'STATUS001'.
ENDFORM. " LVC_SET_STATUS
*&---------------------------------------------------------------------*
*& FORM SUB_USER_COMMAND
*&---------------------------------------------------------------------*
* 控制按钮
*----------------------------------------------------------------------*
* --> P1 TEXT
* <-- P2 TEXT
*----------------------------------------------------------------------*
FORM sub_user_command USING p_ucomm TYPE sy-ucomm
p_rs_selfield TYPE slis_selfield.
DATA:ls_grid TYPE REF TO cl_gui_alv_grid. "GRID定义
* 取得屏幕更新数据
CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
IMPORTING
e_grid = ls_grid.
CALL METHOD ls_grid->check_changed_data.
CASE p_ucomm.
WHEN '&IC1' .
IF p_rs_selfield-fieldname = 'YJFJE' OR p_rs_selfield-fieldname = 'BJFJE'.
CLEAR gt_alv.
READ TABLE gt_alv INDEX p_rs_selfield-tabindex.
PERFORM show_detail USING 'S'.
ELSEIF p_rs_selfield-fieldname = 'YDFJE' OR p_rs_selfield-fieldname = 'BDFJE'.
CLEAR gt_alv.
READ TABLE gt_alv INDEX p_rs_selfield-tabindex.
PERFORM show_detail USING 'H'.
ENDIF.
ENDCASE.
*-同时内表中的数据也随之刷新
p_rs_selfield-col_stable = 'X' . " 行
p_rs_selfield-row_stable = 'X' . " 列
p_rs_selfield-refresh = 'X' . " 当用户在显式界面上对数据进行修改时,
ENDFORM. " LVC_USER_COMMAND
*&---------------------------------------------------------------------*
*& Form show_detail
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM show_detail USING shkzg TYPE c.
DEFINE mac02.
CLEAR: gs_fieldcat_detail.
gs_fieldcat_detail-fieldname = &1 .
gs_fieldcat_detail-scrtext_l = &2 .
gs_fieldcat_detail-scrtext_s = &2 .
gs_fieldcat_detail-scrtext_m = &2 .
gs_fieldcat_detail-edit = &3 .
* gs_fieldcat-key = &4 .
IF &1 = 'LIFNR' OR &1 = 'KUNNR' OR &1 = 'RCNTR' OR &1 = 'AUFNR'.
gs_fieldcat_detail-no_zero = 'X' .
ENDIF.
* gs_fieldcat-no_out = &5 .
gs_fieldcat_detail-ref_table = &4 .
gs_fieldcat_detail-ref_field = &5 .
gs_fieldcat-cfieldname = &6.
APPEND gs_fieldcat_detail TO gt_fieldcat_detail.
END-OF-DEFINITION.
RANGES: r_lifnr FOR acdoca-lifnr,
r_kunnr FOR acdoca-kunnr,
r_rcntr FOR acdoca-rcntr,
r_aufnr FOR acdoca-aufnr.
CLEAR:r_lifnr[],r_kunnr[],r_rcntr[],r_aufnr[].
IF gt_alv-lifnr IS NOT INITIAL.
r_lifnr-sign = 'I'.
r_lifnr-option = 'EQ'.
r_lifnr-low = gt_alv-lifnr.
APPEND r_lifnr.
ENDIF.
IF gt_alv-kunnr IS NOT INITIAL.
r_kunnr-sign = 'I'.
r_kunnr-option = 'EQ'.
r_kunnr-low = gt_alv-kunnr.
APPEND r_kunnr.
ENDIF.
IF gt_alv-rcntr IS NOT INITIAL.
r_rcntr-sign = 'I'.
r_rcntr-option = 'EQ'.
r_rcntr-low = gt_alv-rcntr.
APPEND r_rcntr.
ENDIF.
IF gt_alv-aufnr IS NOT INITIAL.
r_aufnr-sign = 'I'.
r_aufnr-option = 'EQ'.
r_aufnr-low = gt_alv-aufnr.
APPEND r_aufnr.
ENDIF.
SELECT
acdoca~belnr,
acdoca~docln,
acdoca~rwcur,
acdoca~rhcur,
acdoca~racct,
acdoca~tsl,
acdoca~hsl,
acdoca~sgtxt,
acdoca~usnam
INTO TABLE @DATA(lt_acdoca)
FROM acdoca
* INNER JOIN ekko
* ON ekko~ebeln = acdoca~ebeln
WHERE acdoca~rbukrs = @gt_alv-rbukrs
AND acdoca~racct = @gt_alv-racct
* AND ( acdoca~lifnr = @gt_alv-lifnr OR ekko~lifnr = @gt_alv-lifnr )
AND acdoca~lifnr IN @r_lifnr
AND acdoca~kunnr IN @r_kunnr
AND acdoca~rcntr IN @r_rcntr
AND acdoca~aufnr IN @r_aufnr
AND acdoca~belnr NOT LIKE 'B%'
AND acdoca~fiscyearper <= @en_fiscyearper
AND acdoca~fiscyearper > @st_fiscyearper
AND acdoca~bstat NE 'C'
AND acdoca~drcrk = @shkzg
AND acdoca~ebeln = ''.
SELECT
acdoca~belnr,
acdoca~docln,
acdoca~rwcur,
acdoca~rhcur,
acdoca~racct,
acdoca~tsl,
acdoca~hsl,
acdoca~sgtxt,
acdoca~usnam
APPENDING TABLE @lt_acdoca
FROM acdoca
INNER JOIN ekko
ON ekko~ebeln = acdoca~ebeln
WHERE acdoca~rbukrs = @gt_alv-rbukrs
AND acdoca~racct = @gt_alv-racct
AND ( acdoca~lifnr IN @r_lifnr OR ekko~lifnr IN @r_lifnr )
AND acdoca~kunnr IN @r_kunnr
AND acdoca~rcntr IN @r_rcntr
AND acdoca~aufnr IN @r_aufnr
AND acdoca~belnr NOT LIKE 'B%'
AND acdoca~fiscyearper <= @en_fiscyearper
AND acdoca~fiscyearper > @st_fiscyearper
AND acdoca~bstat NE 'C'
AND acdoca~drcrk = @shkzg
AND acdoca~ebeln NE ''.
*-行属性
CLEAR gs_layout_detail.
gs_layout_detail-zebra = 'X' . " 显示界面成色带交替
gs_layout_detail-sel_mode = 'B' . " 选择模式()
gs_layout_detail-detailinit = 'X' . " 是否可以弹出细节屏幕
gs_layout_detail-cwidth_opt = 'X' . " 优化宽度
* gs_layout-box_fname = 'SEL' . " 指明复选框
*-列属性
CLEAR gt_fieldcat_detail[] .
mac02: 'BELNR ' '凭证编号 ' '' 'ACDOCA' 'BELNR' ''.
mac02: 'DOCLN ' '凭证行项目 ' '' 'ACDOCA' 'DOCLN' ''.
mac02: 'RWCUR ' '余额交易货币 ' '' 'RWCUR' 'RWCUR' ''.
mac02: 'RHCUR ' '交易货币 ' '' 'ACDOCA' 'RHCUR' ''.
mac02: 'RACCT ' '科目号 ' '' 'ACDOCA' 'RACCT' ''.
mac02: 'TSL ' '以余额交易货币计的金额 ' '' 'ACDOCA' 'TSL' 'RTCUR'.
mac02: 'HSL ' '以公司代码货币计的金额 ' '' 'ACDOCA' 'HSL' ''.
mac02: 'SGTXT ' '文本 ' '' 'ACDOCA' 'SGTXT' ''.
mac02: 'USNAM ' '用户名 ' '' 'ACDOCA' 'USNAM' ''.
LOOP AT gt_fieldcat_detail INTO gs_fieldcat_detail.
CASE gs_fieldcat_detail-fieldname.
WHEN 'SEL'.
gs_fieldcat_detail-checkbox = 'X'.
* gs_fieldcat-hotspot = 'X'.
MODIFY gt_fieldcat_detail FROM gs_fieldcat_detail.
WHEN 'MEINS'.
gs_fieldcat_detail-edit_mask = '==CUNIT'.
MODIFY gt_fieldcat_detail FROM gs_fieldcat_detail.
ENDCASE.
ENDLOOP.
*-ALV函数
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
EXPORTING
i_callback_program = sy-repid
is_layout_lvc = gs_layout_detail
it_fieldcat_lvc = gt_fieldcat_detail
i_save = 'A'
TABLES
t_outtab = lt_acdoca[]
EXCEPTIONS
program_error = 1
OTHERS = 2.
ENDFORM.
在该代码中,如果涉及到货币是日币,韩币等币种,在alv中展示的是缩小100倍的数值,这是因为上述币种在sap中没有小数,sap展示会以缩小100倍展示。在SAP中,由于日元和韩元等货币值是没有小数位的,所以在做手工过账或者是后勤过账时金额都是整数,但是在存表时系统会金额会自动缩小100倍,预留两位小数。
解决方法1:
gs_fieldcat-cfieldname = &6.
mac01: 'YQCJE ' '期初金额(原币) ' '' '' '' 'RTCUR'.
解决方法2:
系统中有个后台表TCURX,TCURX存储货币的小数位CURRDEC,系统通过函数CURRENCY_CONVERTING_FACTOR进行数据转换,例如日元的小数位为0,当存表时,会自动缩小100倍,所以当我们在开发自定义报表时也需要调用该函数,系统会自动在后台表的数据基础上扩大100倍。