SAP 预设了一个类型组 GFW ,做简单的excel图形输出
话不多说,直接上代码:
*&---------------------------------------------------------------------*
*& Report ZCYCLE057
*&---------------------------------------------------------------------*
*& 测试输出excel图像
*&---------------------------------------------------------------------*
REPORT ZCYCLE057.TYPE-POOLS: gfw.INCLUDE gfw_prog_text.DATA: ok_code TYPE sy-ucomm.
DATA: y_values TYPE TABLE OF gprval WITH HEADER LINE, "图形数据x_texts TYPE TABLE OF gprtxt WITH HEADER LINE. "图形名称REFRESH y_values.
REFRESH x_texts.START-OF-SELECTION.PARAMETERS P1 TYPE CHAR1.y_values-rowtxt = 'sales'.
y_values-val1 = 5000.
y_values-val2 = 8000.
y_values-val3 = 3000.
y_values-val4 = 10000.
APPEND y_values.x_texts-coltxt = '2009'.
APPEND x_texts.
x_texts-coltxt = '2010'.
APPEND x_texts.
x_texts-coltxt = '2011'.
APPEND x_texts.
x_texts-coltxt = '2012'.
APPEND x_texts.CALL SCREEN 100 STARTING AT 20 5..*&---------------------------------------------------------------------*
*& Module STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
MODULE status_0100 OUTPUT.SET PF-STATUS 'ZCYCLE'.
* SET TITLEBAR 'xxx'.* "Only Display one chart(单个图表)
* CALL FUNCTION 'GFW_PRES_SHOW'
* EXPORTING
* container = 'CONTAINER' "a screen WITH an empty container must be defined
* presentation_type = gfw_prestype_lines
** PRESENTATION_TYPE = gfw_prestype_time_axis
** PRESENTATION_TYPE = gfw_prestype_area
** PRESENTATION_TYPE = gfw_prestype_horizontal_bars
* TABLES
* values = y_values
* column_texts = x_texts
* EXCEPTIONS
* error_occurred = 1
* OTHERS = 2."Display multi-chart(多个图表,预留6个可直接使用)CALL FUNCTION 'GFW_PRES_SHOW_MULT'EXPORTINGcontainer = 'CONTAINER1' "容器参数presentation_type = gfw_prestype_lines "图表类型 -- 线状图header = 'CONTAINER1' "图表标题
* orientation = gfw_orient_columnsshow = gfw_false "//optionalTABLESvalues = y_valuescolumn_texts = x_textsEXCEPTIONSerror_occurred = 1OTHERS = 2.CALL FUNCTION 'GFW_PRES_SHOW_MULT'EXPORTINGcontainer = 'CONTAINER2'presentation_type = gfw_prestype_pie_chart "饼状图header = 'CONTAINER2'
* orientation = gfw_orient_columnsshow = gfw_false "//optionalTABLESvalues = y_valuescolumn_texts = x_textsEXCEPTIONSerror_occurred = 1OTHERS = 2.CALL FUNCTION 'GFW_PRES_SHOW_MULT'EXPORTINGcontainer = 'CONTAINER3'presentation_type = gfw_prestype_area "线状图带阴影header = 'CONTAINER3'
* orientation = gfw_orient_columnsshow = gfw_false "//optionalTABLESvalues = y_valuescolumn_texts = x_textsEXCEPTIONSerror_occurred = 1OTHERS = 2.CALL FUNCTION 'GFW_PRES_SHOW_MULT'EXPORTINGcontainer = 'CONTAINER'presentation_type = gfw_prestype_horizontal_bars "横状条形图"presentation_type = gfw_prestype_vertical_bars "竖状条形图orientation = gfw_orient_columnsheader = 'CONTAINER' "图表标题show = gfw_true "//mandatory!!! 注意,最后一个,这个参数必传TABLESvalues = y_valuescolumn_texts = x_textsEXCEPTIONSerror_occurred = 1OTHERS = 2.ENDMODULE.
*&---------------------------------------------------------------------*
*& Module USER_COMMAND_0100 INPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE user_command_0100 INPUT.CASE ok_code.WHEN 'SAVE'.LEAVE TO SCREEN 0.WHEN 'BACK' OR 'CANCEL' OR 'EXIT'.LEAVE TO SCREEN 0.WHEN OTHERS.ENDCASE.
ENDMODULE.
再基于报表创建屏幕 100(四个容器控件分别命名为:CONTAINER、CONTAINER1、CONTAINER2、CONTAINER3):
然后去SE80 里根据功能模块 REUSE_ALV_GRID_DISPLAY 找到标准ALV图标,复制给我们的程序
激活程序,直接测试,效果如下