背景:此程序实现了财务报表的统计。
REPORT ZJGLCO001.
TABLES:FAGLFLEXT,CSKT,SKAT.
TYPE-POOLS:slis.
DATA: BEGIN OF ITEM OCCURS 0,
RBUKRS LIKE FAGLFLEXT-RBUKRS, " 公司代码
RYEAR LIKE FAGLFLEXT-RYEAR, " 会计年度
RCNTR LIKE FAGLFLEXT-RCNTR, " 成本中心
RACCT LIKE FAGLFLEXT-RACCT, " 会计科目
RFAREA LIKE FAGLFLEXT-RFAREA, " 费用类型
KTEXT LIKE CSKT-KTEXT, " 成本中心名称
TXT20 LIKE SKAT-TXT20, "科目名称
TSL01 LIKE FAGLFLEXT-TSL01, " 1月金额
TSL02 LIKE FAGLFLEXT-TSL02, " 2月金额
TSL03 LIKE FAGLFLEXT-TSL03, "3月金额
TSL04 LIKE FAGLFLEXT-TSL04, " 4月金额
TSL05 LIKE FAGLFLEXT-TSL05, " 5月金额
TSL06 LIKE FAGLFLEXT-TSL06, " 6月金额
TSL07 LIKE FAGLFLEXT-TSL07, "7月金额
TSL08 LIKE FAGLFLEXT-TSL08, " 8月金额
TSL09 LIKE FAGLFLEXT-TSL09, " 9月金额
TSL10 LIKE FAGLFLEXT-TSL10, " 10月金额
TSL11 LIKE FAGLFLEXT-TSL11, "11月金额
TSL12 LIKE FAGLFLEXT-TSL12, " 12月金额
R_SUM LIKE FAGLFLEXT-TSL01, " 定义列数据类型.
END OF ITEM.
DATA:BEGIN OF STRUCTURE,
RBUKRS LIKE FAGLFLEXT-RBUKRS, " 公司代码
RYEAR LIKE FAGLFLEXT-RYEAR, " 会计年度
RCNTR LIKE FAGLFLEXT-RCNTR, " 成本中心
RACCT LIKE FAGLFLEXT-RACCT, " 会计科目
RFAREA LIKE FAGLFLEXT-RFAREA, " 费用类型
KTEXT LIKE CSKT-KTEXT, " 成本中心名称
TXT20 LIKE SKAT-TXT20, "科目名称
TSL01 LIKE FAGLFLEXT-TSL01, " 1月金额
TSL02 LIKE FAGLFLEXT-TSL02, " 2月金额
TSL03 LIKE FAGLFLEXT-TSL03, "3月金额
TSL04 LIKE FAGLFLEXT-TSL04, " 4月金额
TSL05 LIKE FAGLFLEXT-TSL05, " 5月金额
TSL06 LIKE FAGLFLEXT-TSL06, " 6月金额
TSL07 LIKE FAGLFLEXT-TSL07, "7月金额
TSL08 LIKE FAGLFLEXT-TSL08, " 8月金额
TSL09 LIKE FAGLFLEXT-TSL09, " 9月金额
TSL10 LIKE FAGLFLEXT-TSL10, " 10月金额
TSL11 LIKE FAGLFLEXT-TSL11, "11月金额
TSL12 LIKE FAGLFLEXT-TSL12, " 12月金额
R_SUM LIKE FAGLFLEXT-TSL01, " 定义列数据类型.
END OF STRUCTURE.
DATA: gd_repid LIKE sy-repid.
DATA: i_grid_settings TYPE lvc_s_glay.
DATA: afield TYPE slis_fieldcat_alv.
DATA: fieldcat TYPE TABLE OF slis_fieldcat_alv WITH HEADER LINE.
DATA: layout TYPE slis_layout_alv.
DATA: l_pos TYPE i VALUE 1.
DATA: lt_h LIKE TABLE OF item WITH HEADER LINE.
DATA: lft_h LIKE TABLE OF item WITH HEADER LINE.
DATA: lft_i LIKE TABLE OF item WITH HEADER LINE.
DATA: p_i TYPE i,p_h TYPE i , l_msg(70),l_kzwi1 LIKE vbap-kzwi1,l_zzye LIKE bsid-dmbtr.
DEFINE fill.
afield-col_pos = l_pos.
afield-fieldname = &1.
afield-seltext_l = &2.
afield-no_zero = &3.
afield-key = &4.
afield-edit = &5.
append afield to fieldcat.
clear afield.
l_pos = l_pos + 1.
END-OF-DEFINITION.
SELECTION-SCREEN BEGIN OF BLOCK BLA WITH FRAME TITLE text-001.
SELECT-OPTIONS:
S_RBUKRS FOR FAGLFLEXT-RBUKRS NO INTERVALS OBLIGATORY , " 公司代码
S_RYEAR FOR FAGLFLEXT-RYEAR NO INTERVALS OBLIGATORY , " 会计年度
S_RCNTR FOR FAGLFLEXT-RCNTR, " 成本中心
S_RACCT FOR FAGLFLEXT-RACCT, " 会计科目
S_RFAREA FOR FAGLFLEXT-RFAREA. "费用类型
SELECTION-SCREEN END OF BLOCK BLA.
START-OF-SELECTION.
PERFORM frm_get_data.
IF item[] IS NOT INITIAL.
PERFORM frm_show_data.
ELSE.
MESSAGE s001(00) WITH '没有查询到数据'.
ENDIF.
FORM frm_get_data.
SELECT FAGLFLEXT~TSL01 FAGLFLEXT~TSL02 FAGLFLEXT~TSL03 FAGLFLEXT~TSL04 FAGLFLEXT~TSL05 FAGLFLEXT~TSL06 FAGLFLEXT~TSL07 FAGLFLEXT~TSL08 FAGLFLEXT~TSL09 FAGLFLEXT~TSL10 FAGLFLEXT~TSL11 FAGLFLEXT~TSL12 FAGLFLEXT~RACCT FAGLFLEXT~RCNTR
INTO CORRESPONDING FIELDS OF TABLE ITEM
FROM FAGLFLEXT
WHERE FAGLFLEXT~RBUKRS IN S_RBUKRS
AND FAGLFLEXT~RYEAR IN S_RYEAR
AND FAGLFLEXT~RCNTR IN S_RCNTR
AND FAGLFLEXT~RACCT IN S_RACCT
AND FAGLFLEXT~RFAREA IN S_RFAREA.
LOOP AT ITEM.
ITEM-R_SUM = ITEM-TSL01 + ITEM-TSL02 + ITEM-TSL03 + ITEM-TSL04 + ITEM-TSL05 + ITEM-TSL06 + ITEM-TSL07 + ITEM-TSL08 + ITEM-TSL09 + ITEM-TSL10 + ITEM-TSL11 + ITEM-TSL12.
SELECT SINGLE TXT20 INTO ITEM-TXT20
FROM SKAT WHERE SAKNR = ITEM-RACCT.
SELECT SINGLE KTEXT INTO ITEM-KTEXT
FROM CSKT WHERE KOSTL = ITEM-RCNTR.
MODIFY ITEM .
STRUCTURE-TXT20 = 'SUM'.
STRUCTURE-TSL01 = ITEM-TSL01 + STRUCTURE-TSL01 .
STRUCTURE-TSL02 = ITEM-TSL02 + STRUCTURE-TSL02 .
STRUCTURE-TSL03 = ITEM-TSL03 + STRUCTURE-TSL03 .
STRUCTURE-TSL04 = ITEM-TSL04 + STRUCTURE-TSL04 .
STRUCTURE-TSL05 = ITEM-TSL05 + STRUCTURE-TSL05 .
STRUCTURE-TSL06 = ITEM-TSL06 + STRUCTURE-TSL06 .
STRUCTURE-TSL07 = ITEM-TSL07 + STRUCTURE-TSL07 .
STRUCTURE-TSL08 = ITEM-TSL08 + STRUCTURE-TSL08 .
STRUCTURE-TSL09 = ITEM-TSL09 + STRUCTURE-TSL09 .
STRUCTURE-TSL10 = ITEM-TSL10 + STRUCTURE-TSL10 .
STRUCTURE-TSL11 = ITEM-TSL11 + STRUCTURE-TSL11 .
STRUCTURE-TSL12 = ITEM-TSL12 + STRUCTURE-TSL12 .
STRUCTURE-R_SUM = ITEM-R_SUM + STRUCTURE-R_SUM .
ENDLOOP.
APPEND STRUCTURE TO ITEM.
ENDFORM.
FORM frm_show_data .
i_grid_settings-edt_cll_cb = 'X'. "显示界面可编辑字段上修改了数据,回车后立即更新内表的数据
layout-colwidth_optimize = 'X'. "设置字段列宽自适应
layout-zebra = 'X'.
CLEAR afield.
REFRESH fieldcat."clear,refresh,free
fill 'RCNTR' '成本中心名称' '' '' ''.
fill 'RACCT' '科目' '' '' ''.
fill 'TXT20' '科目名称' '' '' ''.
fill 'TSL01' '1月金额' '' '' ''.
fill 'TSL02' '2月金额' '' '' ''.
fill 'TSL03' '3月金额' '' '' ''.
fill 'TSL04' '4月金额' '' '' ''.
fill 'TSL05' '5月金额' '' '' ''.
fill 'TSL06' '6月金额' '' '' ''.
fill 'TSL07' '7月金额' '' '' ''.
fill 'TSL08' '8月金额' '' '' ''.
fill 'TSL09' '9月金额' '' '' ''.
fill 'TSL10 ' '10月金额' '' '' ''.
fill 'TSL11' '11月金额' '' '' ''.
fill 'TSL12 ' '12月金额' '' '' ''.
fill 'R_SUM ' '汇总' '' '' ''.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
"显示界面可编辑字段上修改了数据,回车后就会立即将内表的数据也修改
i_grid_settings = i_grid_settings
"标记当前程序
i_callback_program = sy-cprog
it_fieldcat = fieldcat[]
is_layout = layout
i_callback_user_command = 'USER_COMMAND' "此处是用户动作的入口
i_callback_pf_status_set = 'SET_STATUS' "此处是工具栏的入口
TABLES
t_outtab = item. "此处是数据内表
ENDFORM. " FRM_SHOW_DAT
FORM set_status USING rt_extab TYPE slis_t_extab.
SET PF-STATUS 'STANDARD'."工具栏的图标可以从SAPLKKBL程序的接口standard复制
ENDFORM.
FORM user_command USING rf_ucomm LIKE sy-ucomm
rs TYPE slis_selfield .
rs-refresh = 'X'."屏幕事件触发后自动刷新屏幕
CASE rf_ucomm.
WHEN '&IC1'.
READ TABLE item INDEX rs-tabindex.
WHEN '&BACK' OR '&QUIT' OR '&CANCEL'.
LEAVE PROGRAM.
ENDCASE.
ENDFORM.
功能展示
1 .
逻辑处理重点
1.如何处理对列和行的求和;
处理方法
1.列直接定义及累加;
2.定义一个结构,然后添加内表中(通过很多行求总方法添加);
总结:1,尽可能在F1里先看英文文档;(SELECT OPTIONS里找到必输文档)
2. 不管是写程序,还是troubleshooting的时候,尽可能要参照一个例子;
3. 注意大写和空格;
4. 如果是处理一个表,从程序优化的角度来说尽可能只有一个循环。