如何开发一个费用类别统计报表
【摘要】 需求接到一个需求对公司的费用类别作统计,要求选择屏幕如下: 实现方式首先定义一个自定义报表维护公司需要的费用编号通过 SAP 的 BSEG 后台表找出公司下对应的会计核算凭证段计算金额的总和 数据定义首先,定义 ALV 需要常见字段和我们这个报表中需要的字段,如下:*--------------------------------------------------------------...
需求
接到一个需求对公司的费用类别作统计,要求选择屏幕如下:
实现方式
- 首先定义一个自定义报表维护公司需要的费用编号
- 通过 SAP 的
BSEG
后台表找出公司下对应的会计核算凭证段 - 计算金额的总和
数据定义
首先,定义 ALV 需要常见字段和我们这个报表中需要的字段,如下:
*----------------------------------------------------------------------*
* Data Declarations
*----------------------------------------------------------------------*
TYPE-POOLS: slis, abap.
TABLES: bseg, zfit029.
DATA: BEGIN OF gs_out,
zcode_cost LIKE zfit029-zcode_cost, " 费用编号
zcost_desc LIKE zfit029-zcost_desc, " 费用描述
month_1 LIKE bseg-dmbtr,
month_2 LIKE bseg-dmbtr,
month_3 LIKE bseg-dmbtr,
month_4 LIKE bseg-dmbtr,
month_5 LIKE bseg-dmbtr,
month_6 LIKE bseg-dmbtr,
month_7 LIKE bseg-dmbtr,
month_8 LIKE bseg-dmbtr,
month_9 LIKE bseg-dmbtr,
month_10 LIKE bseg-dmbtr,
month_11 LIKE bseg-dmbtr,
month_12 LIKE bseg-dmbtr,
END OF gs_out.
DATA: gt_out LIKE TABLE OF gs_out WITH HEADER LINE.
DATA: gs_zfit029 TYPE zfit029,
gt_zfit029 LIKE TABLE OF gs_zfit029.
DATA: BEGIN OF gs_bseg,
zcode_cost TYPE zfit029-zcode_cost, " 费用类别编号
zcost_desc TYPE zfit029-zcost_desc, " 费用类别描述
bukrs TYPE bseg-bukrs, " 公司代码
hkont TYPE bseg-hkont, " 总账科目
gjahr TYPE bseg-gjahr, " 财年
buzei TYPE bseg-buzei, " 会计凭证中的行项目数
shkzg TYPE bseg-shkzg, " 借方/贷方标识
h_hwaer TYPE bseg-h_hwaer, " 币种 pswsl
prctr TYPE bseg-prctr, " 利润中心
h_monat TYPE bseg-h_monat, " 月份
dmbtr TYPE bseg-dmbtr, " 按本位币计的金额
h_budat TYPE bseg-h_budat, " 凭证中的过账日期
kostl TYPE bseg-kostl, " 成本中心
belnr TYPE bseg-belnr, " 会计凭证
END OF gs_bseg.
DATA: gt_bseg LIKE TABLE OF gs_bseg WITH KEY zcode_cost.
DATA: BEGIN OF gs_total,
zcode_cost LIKE zfit029-zcode_cost,
h_monat LIKE bseg-h_monat,
h_hwaer LIKE bseg-h_hwaer,
zcost_desc LIKE zfit029-zcost_desc,
h_budat LIKE bseg-h_budat,
dmbtr LIKE bseg-dmbtr,
shkzg LIKE bseg-shkzg,
END OF gs_total.
DATA: gs_total1 LIKE gs_total.
DATA: gt_total LIKE STANDARD TABLE OF gs_total,
gt_total1 LIKE STANDARD TABLE OF gs_total WITH HEADER LINE.
DATA: gv_tabix TYPE sy-tabix,
gv_zcode TYPE zfit029-zcode_cost.
DATA: BEGIN OF gs_detail,
zcode_cost LIKE zfit029-zcode_cost,
zcost_desc LIKE zfit029-zcost_desc,
hkont TYPE bseg-hkont,
shkzg TYPE bseg-shkzg,
dmbtr LIKE bseg-dmbtr,
h_hwaer TYPE bseg-h_hwaer,
bukrs TYPE bseg-bukrs,
kostl TYPE bseg-kostl,
prctr TYPE bseg-prctr,
belnr TYPE bseg-belnr,
gjahr TYPE bseg-gjahr,
h_monat LIKE bseg-h_monat,
h_budat TYPE bseg-h_budat,
END OF gs_detail.
DATA gt_detail LIKE STANDARD TABLE OF gs_detail.
DATA gv_kkurs TYPE prcd_elements-kkurs.
DATA lastdate TYPE bseg-h_budat.
* ALV Data Declarations
DATA: gs_layout TYPE lvc_s_layo,
gs_fieldcat TYPE lvc_s_fcat,
gt_fieldcat TYPE lvc_t_fcat,
i_layout TYPE lvc_s_layo,
is_fieldcat TYPE lvc_s_fcat,
it_fieldcat TYPE lvc_t_fcat,
gs_all_fieldcat TYPE lvc_s_fcat,
gt_all_fieldcat TYPE lvc_t_fcat,
gd_repid LIKE sy-repid.
选择屏幕部分
接下来定义 ALV 中需要显示的字段,主要包括选择屏幕和选项,结束选择屏幕后的数据读取操作:
*----------------------------------------------------------------------*
* Selection Screen
*----------------------------------------------------------------------*
SELECTION-SCREEN BEGIN OF BLOCK y1 WITH FRAME TITLE TEXT-001.
SELECT-OPTIONS:
so_bukrs FOR bseg-bukrs,
so_prctr FOR bseg-prctr.
PARAMETERS: p_gjahr LIKE bseg-gjahr OBLIGATORY DEFAULT sy-datlo(4).
SELECTION-SCREEN END OF BLOCK y1.
*----------------------------------------------------------------------*
* Start-of-selection.
*----------------------------------------------------------------------*
START-OF-SELECTION.
PERFORM data_retrieval.
PERFORM build_fieldcatlog.
PERFORM build_layout.
PERFORM display_alv_report.
END-OF-SELECTION.
数据抓取
按照规则,抓取我们需要的后台数据:
*&---------------------------------------------------------------------*
*& Form DATA_RETRIEVAL
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM data_retrieval .
DATA: lv_zcode_cost TYPE zfit029-zcode_cost.
REFRESH: gt_zfit029,
gt_bseg.
SELECT zcode_cost
zcost_desc
saknr
txt20 FROM zfit029 INTO CORRESPONDING FIELDS OF TABLE gt_zfit029.
IF gt_zfit029 IS NOT INITIAL.
SELECT bukrs
hkont
gjahr
buzei
shkzg
dmbtr
h_hwaer
prctr
h_monat
h_budat
kostl
belnr FROM bseg INTO CORRESPONDING FIELDS OF TABLE gt_bseg
FOR ALL ENTRIES IN gt_zfit029
WHERE bukrs IN so_bukrs
AND prctr IN so_prctr
AND gjahr = p_gjahr
AND hkont = gt_zfit029-saknr.
ENDIF.
" 根据 bseg 和 zit029 两个表的总账科目号连接到内表
LOOP AT gt_bseg INTO gs_bseg.
READ TABLE gt_zfit029 INTO gs_zfit029 WITH KEY saknr = gs_bseg-hkont.
IF sy-subrc = 0.
gs_bseg-zcode_cost = gs_zfit029-zcode_cost.
gs_bseg-zcost_desc = gs_zfit029-zcost_desc.
ENDIF.
MODIFY gt_bseg FROM gs_bseg.
CLEAR:gs_bseg,
gs_zfit029.
ENDLOOP.
MOVE-CORRESPONDING gt_bseg TO gt_total.
" 循环按借贷标识把金额换算成正负
LOOP AT gt_total INTO gs_total.
IF gs_total-shkzg = 'H'.
gs_total-dmbtr = gs_total-dmbtr * ( -1 ).
ELSE.
gs_total-dmbtr = gs_total-dmbtr.
ENDIF.
MODIFY gt_total FROM gs_total.
CLEAR: gs_total.
ENDLOOP.
SORT gt_total BY zcode_cost h_monat h_hwaer. " 根据费用编号、月份、币种排序
" 按编号、币种、月份、时期 分类求和
LOOP AT gt_total INTO gs_total GROUP BY ( k1 = gs_total-zcode_cost
k2 = gs_total-h_hwaer
k3 = gs_total-h_monat
k4 = gs_total-h_budat
k5 = gs_total-zcost_desc ) ASSIGNING FIELD-SYMBOL(<total>).
gs_total1-zcode_cost = <total>-k1.
gs_total1-h_hwaer = <total>-k2.
gs_total1-h_monat = <total>-k3.
gs_total1-h_budat = <total>-k4.
gs_total1-zcost_desc = <total>-k5.
gs_total1-dmbtr = REDUCE s_sum( INIT temp TYPE bseg-dmbtr FOR line IN GROUP <total>
NEXT temp = temp + line-dmbtr ).
APPEND gs_total1 TO gt_total1.
CLEAR gs_total1.
ENDLOOP.
" 先按照本币求和,然后再按当前记账日期的上一个月份维护的汇率,换算为 USD
DATA: ld_last_day_of_month TYPE sy-datum.
LOOP AT gt_total1 INTO gs_total1.
IF gs_total1-h_hwaer NE 'USD'.
CALL FUNCTION 'RP_LAST_DAY_OF_MONTHS'
EXPORTING
day_in = gs_total1-h_budat
IMPORTING
last_day_of_month = ld_last_day_of_month
EXCEPTIONS
day_in_no_date = 1
OTHERS = 2.
IF gs_total1-h_budat EQ ld_last_day_of_month. " 如果当前日期是最后一天,则减去一个月取汇率
CALL FUNCTION 'FIMA_DATE_CREATE'
EXPORTING
i_date = gs_total1-h_budat
i_months = '-1'
IMPORTING
e_date = lastdate.
gs_total1-h_budat = lastdate.
ENDIF.
CLEAR: gv_kkurs.
CALL FUNCTION 'ZRFC_EXCHANGERATE'
EXPORTING
i_waers1 = gs_total1-h_hwaer
i_waers2 = 'USD'
i_date = gs_total1-h_budat
IMPORTING
e_kkurs = gv_kkurs.
gs_total1-dmbtr = gs_total1-dmbtr * gv_kkurs.
MODIFY gt_total1 FROM gs_total1.
CLEAR gs_total1.
ENDIF.
ENDLOOP.
然后按照月份求和:
LOOP AT gt_total1 INTO gs_total1.
AT NEW zcode_cost.
lv_zcode_cost = gs_total1-zcode_cost.
ENDAT.
IF lv_zcode_cost EQ gs_total1-zcode_cost AND gs_total1-h_monat EQ 01.
gs_out-month_1 = gs_out-month_1 + gs_total1-dmbtr.
gs_out-zcode_cost = gs_total1-zcode_cost.
gs_out-zcost_desc = gs_total1-zcost_desc.
ELSEIF lv_zcode_cost EQ gs_total1-zcode_cost AND gs_total1-h_monat EQ 02.
gs_out-month_2 = gs_out-month_2 + gs_total1-dmbtr.
gs_out-zcode_cost = gs_total1-zcode_cost.
gs_out-zcost_desc = gs_total1-zcost_desc.
ELSEIF lv_zcode_cost EQ gs_total1-zcode_cost AND gs_total1-h_monat EQ 03.
gs_out-month_3 = gs_out-month_3 + gs_total1-dmbtr.
gs_out-zcode_cost = gs_total1-zcode_cost.
gs_out-zcost_desc = gs_total1-zcost_desc.
ELSEIF lv_zcode_cost EQ gs_total1-zcode_cost AND gs_total1-h_monat EQ 04.
gs_out-month_4 = gs_out-month_4 + gs_total1-dmbtr.
gs_out-zcode_cost = gs_total1-zcode_cost.
gs_out-zcost_desc = gs_total1-zcost_desc.
ELSEIF lv_zcode_cost EQ gs_total1-zcode_cost AND gs_total1-h_monat EQ 05.
gs_out-month_5 = gs_out-month_5 + gs_total1-dmbtr.
gs_out-zcode_cost = gs_total1-zcode_cost.
gs_out-zcost_desc = gs_total1-zcost_desc.
ELSEIF lv_zcode_cost EQ gs_total1-zcode_cost AND gs_total1-h_monat EQ 06.
gs_out-month_6 = gs_out-month_6 + gs_total1-dmbtr.
gs_out-zcode_cost = gs_total1-zcode_cost.
gs_out-zcost_desc = gs_total1-zcost_desc.
ELSEIF lv_zcode_cost EQ gs_total1-zcode_cost AND gs_total1-h_monat EQ 07.
gs_out-month_7 = gs_out-month_7 + gs_total1-dmbtr.
gs_out-zcode_cost = gs_total1-zcode_cost.
gs_out-zcost_desc = gs_total1-zcost_desc.
ELSEIF lv_zcode_cost EQ gs_total1-zcode_cost AND gs_total1-h_monat EQ 08.
gs_out-month_8 = gs_out-month_8 + gs_total1-dmbtr.
gs_out-zcode_cost = gs_total1-zcode_cost.
gs_out-zcost_desc = gs_total1-zcost_desc.
ELSEIF lv_zcode_cost EQ gs_total1-zcode_cost AND gs_total1-h_monat EQ 09.
gs_out-month_9 = gs_out-month_9 + gs_total1-dmbtr.
gs_out-zcode_cost = gs_total1-zcode_cost.
gs_out-zcost_desc = gs_total1-zcost_desc.
ELSEIF lv_zcode_cost EQ gs_total1-zcode_cost AND gs_total1-h_monat EQ 10.
gs_out-month_10 = gs_out-month_10 + gs_total1-dmbtr.
gs_out-zcode_cost = gs_total1-zcode_cost.
gs_out-zcost_desc = gs_total1-zcost_desc.
ELSEIF lv_zcode_cost EQ gs_total1-zcode_cost AND gs_total1-h_monat EQ 11.
gs_out-month_11 = gs_out-month_11 + gs_total1-dmbtr.
gs_out-zcode_cost = gs_total1-zcode_cost.
gs_out-zcost_desc = gs_total1-zcost_desc.
ELSEIF lv_zcode_cost EQ gs_total1-zcode_cost AND gs_total1-h_monat EQ 12.
gs_out-month_12 = gs_out-month_12 + gs_total1-dmbtr.
gs_out-zcode_cost = gs_total1-zcode_cost.
gs_out-zcost_desc = gs_total1-zcost_desc.
ENDIF.
AT END OF zcode_cost.
APPEND gs_out TO gt_out.
CLEAR:gs_out.
ENDAT.
CLEAR: gs_total1.
ENDLOOP.
最后是建立 FIELDCAT 和设置 LAYOUT
*&---------------------------------------------------------------------*
*& Form BUILD_FIELDCATLOG
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM build_fieldcatlog .
DATA: l_pos TYPE i VALUE 1.
CLEAR: l_pos.
REFRESH gt_fieldcat.
CLEAR gs_fieldcat.
l_pos = l_pos + 1.
gs_fieldcat-col_pos = l_pos.
gs_fieldcat-fieldname = 'ZCODE_COST'.
gs_fieldcat-coltext = '费用编号'.
gs_fieldcat-ref_table = 'ZFIT029'.
gs_fieldcat-ref_field = 'ZCODE_COST'.
APPEND gs_fieldcat TO gt_fieldcat.
gs_fieldcat-col_pos = l_pos.
gs_fieldcat-fieldname = 'ZCOST_DESC'.
gs_fieldcat-coltext = '费用描述'.
gs_fieldcat-ref_table = 'ZFIT029'.
gs_fieldcat-ref_field = 'ZCOST_DESC'.
APPEND gs_fieldcat TO gt_fieldcat.
CLEAR gs_fieldcat.
gs_fieldcat-col_pos = l_pos.
gs_fieldcat-fieldname = 'MONTH_1'.
gs_fieldcat-coltext = '一月'.
APPEND gs_fieldcat TO gt_fieldcat.
CLEAR gs_fieldcat.
gs_fieldcat-col_pos = l_pos.
gs_fieldcat-fieldname = 'MONTH_2'.
gs_fieldcat-coltext = '二月'.
APPEND gs_fieldcat TO gt_fieldcat.
CLEAR gs_fieldcat.
gs_fieldcat-col_pos = l_pos.
gs_fieldcat-fieldname = 'MONTH_3'.
gs_fieldcat-coltext = '三月'.
APPEND gs_fieldcat TO gt_fieldcat.
CLEAR gs_fieldcat.
gs_fieldcat-col_pos = l_pos.
gs_fieldcat-fieldname = 'MONTH_4'.
gs_fieldcat-coltext = '四月'.
APPEND gs_fieldcat TO gt_fieldcat.
CLEAR gs_fieldcat.
gs_fieldcat-col_pos = l_pos.
gs_fieldcat-fieldname = 'MONTH_5'.
gs_fieldcat-coltext = '五月'.
APPEND gs_fieldcat TO gt_fieldcat.
CLEAR gs_fieldcat.
gs_fieldcat-col_pos = l_pos.
gs_fieldcat-fieldname = 'MONTH_6'.
gs_fieldcat-coltext = '六月'.
APPEND gs_fieldcat TO gt_fieldcat.
CLEAR gs_fieldcat.
gs_fieldcat-col_pos = l_pos.
gs_fieldcat-coltext = '七月'.
gs_fieldcat-fieldname = 'MONTH_7'.
APPEND gs_fieldcat TO gt_fieldcat.
CLEAR gs_fieldcat.
gs_fieldcat-col_pos = l_pos.
gs_fieldcat-coltext = '八月'.
gs_fieldcat-fieldname = 'MONTH_8'.
APPEND gs_fieldcat TO gt_fieldcat.
CLEAR gs_fieldcat.
gs_fieldcat-col_pos = l_pos.
gs_fieldcat-fieldname = 'MONTH_9'.
gs_fieldcat-coltext = '九月'.
APPEND gs_fieldcat TO gt_fieldcat.
CLEAR gs_fieldcat.
gs_fieldcat-col_pos = l_pos.
gs_fieldcat-fieldname = 'MONTH_10'.
gs_fieldcat-coltext = '十月'.
APPEND gs_fieldcat TO gt_fieldcat.
CLEAR gs_fieldcat.
gs_fieldcat-col_pos = l_pos.
gs_fieldcat-fieldname = 'MONTH_11'.
gs_fieldcat-coltext = '十一月'.
APPEND gs_fieldcat TO gt_fieldcat.
CLEAR gs_fieldcat.
gs_fieldcat-col_pos = l_pos.
gs_fieldcat-fieldname = 'MONTH_12'.
gs_fieldcat-coltext = '十二月'.
APPEND gs_fieldcat TO gt_fieldcat.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form BUILD_LAYOUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM build_layout .
gs_layout-zebra = 'X'.
gs_layout-cwidth_opt = 'X'.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form DISPLAY_ALV_REPORT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM display_alv_report .
gd_repid = sy-repid.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
EXPORTING
i_callback_program = gd_repid
i_callback_pf_status_set = 'PF_STATUS_SET'
i_callback_user_command = 'USER_COMMAND'
is_layout_lvc = gs_layout
it_fieldcat_lvc = gt_fieldcat
i_save = 'X'
TABLES
t_outtab = gt_out
EXCEPTIONS
program_error = 1
OTHERS = 2.
IF sy-subrc <> 0.
ENDIF.
ENDFORM.
FORM pf_status_set USING rt_extab TYPE slis_t_extab.
SET PF-STATUS 'ZSTATUS'.
ENDFORM.
FORM user_command USING s_ucomm TYPE sy-ucomm
re_selfield TYPE slis_selfield.
CASE s_ucomm.
WHEN '&IC1'.
CLEAR: gv_tabix.
gv_tabix = re_selfield-tabindex.
CLEAR: gs_detail,
gs_out.
READ TABLE gt_out INTO gs_out INDEX gv_tabix.
IF sy-subrc = 0.
gv_zcode = gs_out-zcode_cost.
PERFORM get_detail.
PERFORM display_detail.
ENDIF.
WHEN 'DETAIL'.
PERFORM get_all.
PERFORM dispaly_all.
WHEN OTHERS.
ENDCASE.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form DISPLAY_DETAIL
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM display_detail .
PERFORM frm_i_fieldcat.
PERFORM frm_i_setlayout.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
EXPORTING
i_callback_program = sy-repid
i_grid_title = '费用编号明细'
is_layout_lvc = i_layout
it_fieldcat_lvc = it_fieldcat
TABLES
t_outtab = gt_detail
EXCEPTIONS
program_error = 1
OTHERS = 2.
IF sy-subrc <> 0.
ENDIF.
ENDFORM.
FORM frm_i_setlayout.
i_layout-zebra = 'X'.
i_layout-sel_mode = 'A'.
i_layout-cwidth_opt = 'X'.
ENDFORM.
FORM frm_i_fieldcat.
DATA: l_pos TYPE i.
CLEAR: l_pos.
REFRESH: it_fieldcat.
CLEAR is_fieldcat.
is_fieldcat-col_pos = l_pos.
is_fieldcat-fieldname = 'ZCODE_COST'.
is_fieldcat-coltext = '费用编号'.
is_fieldcat-ref_table = 'ZFIT029'.
is_fieldcat-ref_field = 'ZCODE_COST'.
APPEND is_fieldcat TO it_fieldcat.
CLEAR is_fieldcat.
is_fieldcat-col_pos = l_pos.
is_fieldcat-fieldname = 'ZCOST_DESC'.
is_fieldcat-coltext = '费用描述'.
is_fieldcat-ref_table = 'ZFIT029'.
is_fieldcat-ref_field = 'ZCOST_DESC'.
APPEND is_fieldcat TO it_fieldcat.
CLEAR is_fieldcat.
l_pos = l_pos + 1.
is_fieldcat-col_pos = l_pos.
is_fieldcat-fieldname = 'HKONT'.
is_fieldcat-coltext = '总账科目'.
is_fieldcat-ref_table = 'BSEG'.
is_fieldcat-ref_field = 'HKONT'.
APPEND is_fieldcat TO it_fieldcat.
CLEAR is_fieldcat.
l_pos = l_pos + 1.
is_fieldcat-col_pos = l_pos.
is_fieldcat-fieldname = 'SHKZG'.
is_fieldcat-coltext = '借贷标识'.
is_fieldcat-ref_table = 'BSEG'.
is_fieldcat-ref_field = 'SHKZG'.
APPEND is_fieldcat TO it_fieldcat.
CLEAR is_fieldcat.
l_pos = l_pos + 1.
is_fieldcat-col_pos = l_pos.
is_fieldcat-fieldname = 'DMBTR'.
is_fieldcat-coltext = '金额'.
is_fieldcat-ref_table = 'BSEG'.
is_fieldcat-ref_field = 'DMBTR'.
APPEND is_fieldcat TO it_fieldcat.
CLEAR is_fieldcat.
l_pos = l_pos + 1.
is_fieldcat-col_pos = l_pos.
is_fieldcat-fieldname = 'H_HWAER'.
is_fieldcat-coltext = '本币'.
is_fieldcat-ref_table = 'BSEG'.
is_fieldcat-ref_field = 'H_HWAER'.
APPEND is_fieldcat TO it_fieldcat.
CLEAR is_fieldcat.
l_pos = l_pos + 1.
is_fieldcat-col_pos = l_pos.
is_fieldcat-fieldname = 'BUKRS'.
is_fieldcat-coltext = '公司'.
is_fieldcat-ref_table = 'BSEG'.
is_fieldcat-ref_field = 'BUKRS'.
APPEND is_fieldcat TO it_fieldcat.
CLEAR is_fieldcat.
l_pos = l_pos + 1.
is_fieldcat-col_pos = l_pos.
is_fieldcat-fieldname = 'KOSTL'.
is_fieldcat-coltext = '成本中心'.
is_fieldcat-ref_table = 'BSEG'.
is_fieldcat-ref_field = 'KOSTL'.
APPEND is_fieldcat TO it_fieldcat.
CLEAR is_fieldcat.
l_pos = l_pos + 1.
is_fieldcat-col_pos = l_pos.
is_fieldcat-fieldname = 'PRCTR'.
is_fieldcat-coltext = '利润中心'.
is_fieldcat-ref_table = 'BSEG'.
is_fieldcat-ref_field = 'PRCTR'.
APPEND is_fieldcat TO it_fieldcat.
CLEAR is_fieldcat.
l_pos = l_pos + 1.
is_fieldcat-col_pos = l_pos.
is_fieldcat-fieldname = 'BELNR'.
is_fieldcat-coltext = '会计凭证'.
is_fieldcat-ref_table = 'BSEG'.
is_fieldcat-ref_field = 'BELNR'.
APPEND is_fieldcat TO it_fieldcat.
CLEAR is_fieldcat.
l_pos = l_pos + 1.
is_fieldcat-col_pos = l_pos.
is_fieldcat-fieldname = 'GJAHR'.
is_fieldcat-coltext = '财年'.
is_fieldcat-ref_table = 'BSEG'.
is_fieldcat-ref_field = 'GJAHR'.
APPEND is_fieldcat TO it_fieldcat.
CLEAR is_fieldcat.
l_pos = l_pos + 1.
is_fieldcat-col_pos = l_pos.
is_fieldcat-fieldname = 'H_MONAT'.
is_fieldcat-coltext = '月份'.
is_fieldcat-ref_table = 'BSEG'.
is_fieldcat-ref_field = 'H_MONAT'.
APPEND is_fieldcat TO it_fieldcat.
CLEAR is_fieldcat.
l_pos = l_pos + 1.
is_fieldcat-col_pos = l_pos.
is_fieldcat-fieldname = 'H_BUDAT'.
is_fieldcat-coltext = '过帐日期'.
is_fieldcat-ref_table = 'BSEG'.
is_fieldcat-ref_field = 'H_BUDAT'.
APPEND is_fieldcat TO it_fieldcat.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form GET_DETAIL
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM get_detail .
SORT gt_bseg BY zcode_cost h_monat. " 根据费用编号和月份排序
REFRESH gt_detail.
LOOP AT gt_bseg INTO gs_bseg .
IF gs_bseg-zcode_cost = gv_zcode.
MOVE-CORRESPONDING gs_bseg TO gs_detail.
APPEND gs_detail TO gt_detail.
CLEAR: gs_detail,
gs_bseg.
ENDIF.
ENDLOOP.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form DISPALY_ALL
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM dispaly_all .
PERFORM frm_i_setlayout.
PERFORM frm_gt_all_fieldcat.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
EXPORTING
i_callback_program = sy-repid
i_grid_title = '所有明细'
is_layout_lvc = i_layout
it_fieldcat_lvc = gt_all_fieldcat
TABLES
t_outtab = gt_bseg
EXCEPTIONS
program_error = 1
OTHERS = 2.
IF sy-subrc <> 0.
ENDIF.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form FRM_GT_ALL_FIELDCAT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM frm_gt_all_fieldcat .
DATA: l_pos TYPE i.
CLEAR: l_pos.
REFRESH: gt_all_fieldcat.
CLEAR gs_all_fieldcat.
l_pos = l_pos + 1.
gs_all_fieldcat-col_pos = l_pos.
gs_all_fieldcat-fieldname = 'ZCODE_COST'.
gs_all_fieldcat-coltext = '费用编号'.
gs_all_fieldcat-ref_table = 'ZFIT029'.
gs_all_fieldcat-ref_field = 'ZCODE_COST'.
APPEND gs_all_fieldcat TO gt_all_fieldcat.
CLEAR gs_all_fieldcat.
gs_all_fieldcat-col_pos = l_pos.
gs_all_fieldcat-fieldname = 'ZCOST_DESC'.
gs_all_fieldcat-coltext = '费用描述'.
gs_all_fieldcat-ref_table = 'ZFIT029'.
gs_all_fieldcat-ref_field = 'ZCOST_DESC'.
APPEND gs_all_fieldcat TO gt_all_fieldcat.
CLEAR gs_all_fieldcat.
l_pos = l_pos + 1.
gs_all_fieldcat-col_pos = l_pos.
gs_all_fieldcat-fieldname = 'HKONT'.
gs_all_fieldcat-coltext = '总账科目'.
gs_all_fieldcat-ref_table = 'BSEG'.
gs_all_fieldcat-ref_field = 'HKONT'.
APPEND gs_all_fieldcat TO gt_all_fieldcat.
CLEAR gs_all_fieldcat.
l_pos = l_pos + 1.
gs_all_fieldcat-col_pos = l_pos.
gs_all_fieldcat-fieldname = 'BUZEI'.
gs_all_fieldcat-coltext = '会计凭证行项目'.
gs_all_fieldcat-ref_table = 'BSEG'.
gs_all_fieldcat-ref_field = 'BUZEI'.
APPEND gs_all_fieldcat TO gt_all_fieldcat.
CLEAR gs_all_fieldcat.
l_pos = l_pos + 1.
gs_all_fieldcat-col_pos = l_pos.
gs_all_fieldcat-fieldname = 'BELNR'.
gs_all_fieldcat-coltext = '会计凭证'.
gs_all_fieldcat-ref_table = 'BSEG'.
gs_all_fieldcat-ref_field = 'BELNR'.
APPEND gs_all_fieldcat TO gt_all_fieldcat.
CLEAR gs_all_fieldcat.
l_pos = l_pos + 1.
gs_all_fieldcat-col_pos = l_pos.
gs_all_fieldcat-fieldname = 'SHKZG'.
gs_all_fieldcat-coltext = '借贷'.
gs_all_fieldcat-ref_table = 'BSEG'.
gs_all_fieldcat-ref_field = 'SHKZG'.
APPEND gs_all_fieldcat TO gt_all_fieldcat.
CLEAR gs_all_fieldcat.
l_pos = l_pos + 1.
gs_all_fieldcat-col_pos = l_pos.
gs_all_fieldcat-fieldname = 'DMBTR'.
gs_all_fieldcat-coltext = '金额'.
gs_all_fieldcat-ref_table = 'BSEG'.
gs_all_fieldcat-ref_field = 'DMBTR'.
APPEND gs_all_fieldcat TO gt_all_fieldcat.
CLEAR gs_all_fieldcat.
l_pos = l_pos + 1.
gs_all_fieldcat-col_pos = l_pos.
gs_all_fieldcat-fieldname = 'H_HWAER'.
gs_all_fieldcat-coltext = '本币'.
gs_all_fieldcat-ref_table = 'BSEG'.
gs_all_fieldcat-ref_field = 'H_HWAER'.
APPEND gs_all_fieldcat TO gt_all_fieldcat.
CLEAR gs_all_fieldcat.
l_pos = l_pos + 1.
gs_all_fieldcat-col_pos = l_pos.
gs_all_fieldcat-fieldname = 'BUKRS'.
gs_all_fieldcat-coltext = '公司'.
gs_all_fieldcat-ref_table = 'BSEG'.
gs_all_fieldcat-ref_field = 'BUKRS'.
APPEND gs_all_fieldcat TO gt_all_fieldcat.
CLEAR gs_all_fieldcat.
l_pos = l_pos + 1.
gs_all_fieldcat-col_pos = l_pos.
gs_all_fieldcat-fieldname = 'KOSTL'.
gs_all_fieldcat-coltext = '成本中心'.
gs_all_fieldcat-ref_table = 'BSEG'.
gs_all_fieldcat-ref_field = 'KOSTL'.
APPEND gs_all_fieldcat TO gt_all_fieldcat.
CLEAR gs_all_fieldcat.
l_pos = l_pos + 1.
gs_all_fieldcat-col_pos = l_pos.
gs_all_fieldcat-fieldname = 'PRCTR'.
gs_all_fieldcat-coltext = '利润中心'.
gs_all_fieldcat-ref_table = 'BSEG'.
gs_all_fieldcat-ref_field = 'PRCTR'.
APPEND gs_all_fieldcat TO gt_all_fieldcat.
CLEAR gs_all_fieldcat.
l_pos = l_pos + 1.
gs_all_fieldcat-col_pos = l_pos.
gs_all_fieldcat-fieldname = 'BELNR'.
gs_all_fieldcat-coltext = '会计凭证'.
gs_all_fieldcat-ref_table = 'BSEG'.
gs_all_fieldcat-ref_field = 'BELNR'.
APPEND gs_all_fieldcat TO gt_all_fieldcat.
CLEAR gs_all_fieldcat.
l_pos = l_pos + 1.
gs_all_fieldcat-col_pos = l_pos.
gs_all_fieldcat-fieldname = 'GJAHR'.
gs_all_fieldcat-coltext = '财年'.
gs_all_fieldcat-ref_table = 'BSEG'.
gs_all_fieldcat-ref_field = 'GJAHR'.
APPEND gs_all_fieldcat TO gt_all_fieldcat.
CLEAR gs_all_fieldcat.
l_pos = l_pos + 1.
gs_all_fieldcat-col_pos = l_pos.
gs_all_fieldcat-fieldname = 'H_MONAT'.
gs_all_fieldcat-coltext = '月份'.
gs_all_fieldcat-ref_table = 'BSEG'.
gs_all_fieldcat-ref_field = 'H_MONAT'.
APPEND gs_all_fieldcat TO gt_all_fieldcat.
CLEAR gs_all_fieldcat.
l_pos = l_pos + 1.
gs_all_fieldcat-col_pos = l_pos.
gs_all_fieldcat-fieldname = 'H_BUDAT'.
gs_all_fieldcat-coltext = '过帐日期'.
gs_all_fieldcat-ref_table = 'BSEG'.
gs_all_fieldcat-ref_field = 'H_BUDAT'.
APPEND gs_all_fieldcat TO gt_all_fieldcat.
ENDFORM.
运行结果
报表执行结果:
然后点击单独的月份,可以查看当前费用编号的明细信息:
【版权声明】本文为华为云社区用户原创内容,转载时必须标注文章的来源(华为云社区)、文章链接、文章作者等基本信息, 否则作者和本社区有权追究责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)