REPORT zfir084.
TABLES: bseg,bkpf,skat,acdoca,cskt,/srep/is_group.
TYPES: BEGIN OF ty_outtab,
rbukrs TYPE acdoca-rbukrs,
werks TYPE acdoca-werks,
AUFNR TYPE acdoca-AUFNR,
gjahr TYPE acdoca-gjahr,
belnr TYPE acdoca-belnr,
docln TYPE acdoca-docln,
racct TYPE acdoca-racct,
hsl TYPE acdoca-hsl,
kdauf TYPE acdoca-kdauf,
kdpos TYPE acdoca-kdpos,
END OF ty_outtab.
DATA: gs_outtab TYPE ty_outtab,
gt_outtab TYPE TABLE OF ty_outtab.
DATA: gt_fieldcat TYPE lvc_t_fcat,
gs_fieldcat TYPE lvc_s_fcat,
gs_layout TYPE lvc_s_layo.
SELECTION-SCREEN BEGIN OF BLOCK bk1 WITH FRAME TITLE TEXT-001.
SELECT-OPTIONS: s_bukrs FOR acdoca-rbukrs,
s_poper FOR acdoca-poper,
s_werks FOR acdoca-werks,
s_AUFNR FOR acdoca-AUFNR,
s_kdauf FOR acdoca-kdauf.
SELECTION-SCREEN END OF BLOCK bk1.
************************************************************************
* 初始化数据赋值
************************************************************************
INITIALIZATION.
s_poper = VALUE #( low = sy-datum+4(2) sign = 'I' option = 'EQ' ) .
APPEND s_poper.
************************************************************************
* 选择屏幕数据检查
************************************************************************
AT SELECTION-SCREEN.
************************************************************************
* 数据的查询整理
************************************************************************
START-OF-SELECTION.
PERFORM frm_get_sqldata.
************************************************************************
* 结果清单的输出
************************************************************************
END-OF-SELECTION.
PERFORM frm_show_alv. "alv显示数据
*&---------------------------------------------------------------------*
*& Form frm_get_sqldata
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM frm_get_sqldata .
DATA lv_hsl TYPE acdoca-hsl.
SELECT
*
FROM acdoca
INTO CORRESPONDING FIELDS OF TABLE @gt_outtab
WHERE rbukrs IN @s_bukrs
AND poper IN @s_poper
AND werks IN @s_werks
AND AUFNR IN @S_AUFNR
AND kdauf IN @s_kdauf
AND racct IN (
'5001010100',
'5001010200',
'5001010300',
'5001020100',
'5001020101',
'5001020102',
'5001020103',
'5001020104',
'5001020105',
'5001020106',
'5001020107',
'5001020108',
'5001020109',
'5001020110',
'5001020111',
'5001020112',
'5001020113',
'5001030100',
'5001030201',
'5001030202',
'5001030203',
'5001030300',
'5001030301',
'5001030400',
'5001030500',
'7043010100',
'7043010200',
'7043020100',
'7043020200',
'7043020300'
).
SORT gt_outtab BY rbukrs werks AUFNR.
LOOP AT gt_outtab ASSIGNING FIELD-SYMBOL(<fs>).
lv_hsl = lv_hsl + <fs>-hsl.
AT END OF AUFNR.
IF lv_hsl EQ 0.
DELETE gt_outtab WHERE AUFNR EQ <fs>-AUFNR.
ENDIF.
CLEAR lv_hsl.
ENDAT.
ENDLOOP.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form frm_show_alv
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM frm_show_alv .
PERFORM frm_fieldcat. "alv界面展示字段添加
PERFORM frm_layout. "ALV全局属性定义
PERFORM frm_output. "调用ALV函数显示数据
ENDFORM.
*&---------------------------------------------------------------------*
*& Form frm_fieldcat
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM frm_fieldcat .
CLEAR: gs_fieldcat,gt_fieldcat.
DEFINE addfieldcat.
gs_fieldcat-fieldname = &1."字段名
gs_fieldcat-coltext = &2.
gs_fieldcat-no_zero = &3."字符不显示前导0
gs_fieldcat-icon = &4.
gs_fieldcat-ref_field = &5."参考字段名
gs_fieldcat-ref_table = &6."参考表名
APPEND gs_fieldcat TO gt_fieldcat.
END-OF-DEFINITION.
addfieldcat 'RBUKRS' '公司代码 ' space space space space.
addfieldcat 'WERKS' '工厂 ' space space space space.
addfieldcat 'AUFNR' '订单号 ' space space space space.
addfieldcat 'GJAHR' '会计年度 ' space space space space.
addfieldcat 'BELNR' '凭证号 ' space space space space.
addfieldcat 'DOCLN' '凭证行项目' space space space space.
addfieldcat 'RACCT' '科目号 ' space space space space.
addfieldcat 'HSL' '金额' space space space space.
addfieldcat 'KDAUF' '销售订单' space space space space.
addfieldcat 'KDPOS' '销售订单行项目' space space space space.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form frm_layout
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM frm_layout .
gs_layout-cwidth_opt = 'X'. " 自动调节字段长度
gs_layout-sel_mode = 'D'. " 选择模式,可选择多行
gs_layout-zebra = 'X'. " 颜色交替显示
gs_layout-no_merging = 'X'.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form frm_output
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM frm_output .
DATA: r_repid TYPE sy-repid.
r_repid = sy-repid.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
EXPORTING
i_callback_program = r_repid
is_layout_lvc = gs_layout
it_fieldcat_lvc = gt_fieldcat
i_save = 'A'
TABLES
t_outtab = gt_outtab
EXCEPTIONS
program_error = 1
OTHERS = 2.
IF sy-subrc <> 0.
* Implement suitable error handling here
MESSAGE ID sy-msgty TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
ENDFORM.