It's a known fact that customers are very sensitive to the appeal of charts. Creating graphical charts (bar, pie char, lines graphs) in ABAP is simple. There are two main methods for creating charts in ABAP
- Using the class CL_GFW
- Using the function module GFW_PRES_SHOW
There are also other classes and function modules derived from these ones. Use transaction GRAL to explore all possibilities provided by this class and this FM.
The following are two short examples of the huge potential of function module GFW_PRES_SHOW :
- Code: Select all
* Contain the constants for the graph type
TYPE-POOLS: GFW.
DATA: VALUES TYPE TABLE OF GPRVAL WITH HEADER LINE,
COLUMN_TEXTS TYPE TABLE OF GPRTXT WITH HEADER LINE.
REFRESH VALUES.
REFRESH COLUMN_TEXTS.
VALUES-ROWTXT = 'Salary'.
VALUES-VAL1 = 50000.
VALUES-VAL2 = 51000.
APPEND VALUES.
VALUES-ROWTXT = 'Life cost'.
VALUES-VAL1 = 49000.
VALUES-VAL2 = 51200.
APPEND VALUES.
COLUMN_TEXTS-COLTXT = '2003'.
APPEND COLUMN_TEXTS.
COLUMN_TEXTS-COLTXT = '2004'.
APPEND COLUMN_TEXTS.
* Call a chart into a standard container, this function could be used for many
* different graphic types depending on the presentation_type field :
* gfw_prestype_lines
* gfw_prestype_area
* gfw_prestype_horizontal_bars
* gfw_prestype_pie_chart
* gfw_prestype_vertical_bars
* gfw_prestype_time_axis
CALL FUNCTION 'GFW_PRES_SHOW'
EXPORTING
CONTAINER = 'CONTAINER' "A screen with an empty container must be defined
PRESENTATION_TYPE = GFW_PRESTYPE_LINES
TABLES
VALUES = VALUES
COLUMN_TEXTS = COLUMN_TEXTS
EXCEPTIONS
ERROR_OCCURRED = 1
OTHERS = 2.
Resulting in this:

The following uses the EXACT same function with a different presentation type
- Code: Select all
REFRESH VALUES.
REFRESH COLUMN_TEXTS.
VALUES-ROWTXT = ''.
VALUES-VAL1 = 10.
VALUES-VAL2 = 35.
VALUES-VAL3 = 45.
VALUES-VAL4 = 8.
VALUES-VAL5 = 2.
APPEND VALUES.
COLUMN_TEXTS-COLTXT = 'Fun'.
APPEND COLUMN_TEXTS.
COLUMN_TEXTS-COLTXT = 'Cars'.
APPEND COLUMN_TEXTS.
COLUMN_TEXTS-COLTXT = 'House'.
APPEND COLUMN_TEXTS.
COLUMN_TEXTS-COLTXT = 'Services'.
APPEND COLUMN_TEXTS.
COLUMN_TEXTS-COLTXT = 'Others'.
APPEND COLUMN_TEXTS.
CALL FUNCTION 'GFW_PRES_SHOW'
EXPORTING
CONTAINER = 'CONTAINER'
PRESENTATION_TYPE = GFW_PRESTYPE_PIE_CHART
X_AXIS_TITLE = 'Expenses'
Y_AXIS_TITLE = 'Expenses2'
TABLES
VALUES = VALUES
COLUMN_TEXTS = COLUMN_TEXTS
EXCEPTIONS
ERROR_OCCURRED = 1
OTHERS = 2

(Courtesy Dany Charbonneau[/url])
Further to this, I've found some old macros that I used in a previous project. These macros simplufy the specification of various elements in the graphics packages.
- Code: Select all
*----------------------------------------------------------------------*
* INCLUDE YGRAPH *
* *
* This include defines constants and macros for use during the *
* building of data tables for the STAT_GRAPHICS function module *
* *
*----------------------------------------------------------------------*
*
Data: w__catagory type i. " Curve catagory
*
Define Graph_Colour.
Constants c_cc_&2(2) type c value '&1'.
End-of-Definition.
Define Graph_Catagory.
Constants c_ct_&2 type c value '&1'.
End-of-Definition.
Define Continuous.
Constants c_co_&2 type c value '&1'.
End-of-Definition.
Define Markers.
Constants c_ma_&2 type c value '&1'.
End-of-Definition.
*Eject
***********************************************************************
*
* Macro: Next_Curve.
*
* Purpose: Introduces the next curve in the data table.
*
* Entry: Number of samples in the curve
* Option table name
*
* Exit: None
*
* Called By: Next_Curve 10 t_opts
*
* Calls:
*
* Modification History:
*
* Date Reason Version Who
*
Define Next_Curve.
Clear &2.
Concatenate '$' &1 into &2.
Append &2.
End-of-Definition.
*Eject
***********************************************************************
*
* Macro: Curve_Colour
*
* Purpose: Specifies the curve colour
*
* Entry: Curve color from constant list below.
* Option table name
*
* Exit: None
*
* Called By: Curve_Colour c_gc_white t_opts.
*
* Calls:
*
* Modification History:
*
* Date Reason Version Who
*
Define Curve_Colour.
Clear &2.
Concatenate 'COLOR=' c_cc_&1 into &2.
Append &2.
End-of-Definition.
*Eject
***********************************************************************
*
* Macro: Curve_Width
*
* Purpose: Specifies the curve width. If this is outside
* the bounds of 0-20 then it is set to 0.
*
* Entry: Curve width
* Option table name
*
* Exit: None
*
* Called By: Curve_width 2 t_opts.
*
* Calls:
*
* Modification History:
*
* Date Reason Version Who
*
Define Curve_Width.
Clear &2.
If &1 >= 0
and &1 <= 20.
Concatenate 'THICK=' '&1' into &2.
Else.
Move 'THICK=0' to &2.
EndIf.
Append &2.
End-of-Definition.
*Eject
***********************************************************************
*
* Macro: Curve_Catagory
*
* Purpose: Specifies the curve catagory
*
* Entry: Curve catagory from constant list below.
* Option table name
*
* Exit: None
*
* Called By: Curve_Catagory continuous t_opts
*
* Calls:
*
* Modification History:
*
* Date Reason Version Who
*
Define Curve_Catagory.
Clear &2.
Concatenate 'C_ART=' c_ct_&1 into &2.
Append &2.
Move c_ct_&1 to w__catagory.
End-of-Definition.
*Eject
***********************************************************************
*
* Macro: Curve_type
*
* Purpose: Specifies the curve type
*
* Entry: Curve type from constant list below.
* Option table name
*
* Exit: None
*
* Called By: Curve_type solid t_opts
*
* Calls:
*
* Modification History:
*
* Date Reason Version Who
*
Define Curve_Type.
Clear &2.
If w__catagory = c_ct_continuous.
Concatenate 'CTYPE=' c_co_&1 into &2.
Else.
Concatenate 'CTYPE=' c_ma_&1 into &2.
EndIf.
Append &2.
End-of-Definition.
*Eject
***********************************************************************
*
* Macro: Legend_Text
*
* Purpose: Specifies the legend text for the current curve
*
* Entry: Legend text in quotes
* Option table name
*
* Exit: None
*
* Called By: Legend_Text 'This is the curve legend'.
*
* Calls:
*
* Modification History:
*
* Date Reason Version Who
*
Define Legend_Text.
Clear &2.
Concatenate 'LTEXT=' &1 into &2.
Append &2.
End-of-Definition.
*Eject
*
* Constants
*
Graph_Colour: 0 Black,
1 White,
2 Blue,
3 Yellow,
4 Green,
5 Magenta,
6 Red,
7 Cyan,
8 Darkgray,
9 Gray,
10 Darkblue,
11 Darkyellow,
12 Darkgreen,
13 Darkmagenta,
14 Darkred,
15 Darkcyan.
*
Graph_Catagory: 0 Continuous,
1 Markered.
*
* Curve types.
*
Continuous: 0 Solid,
1 Dots,
2 Short_dashes,
3 Dashes,
4 Dash_short_dash,
5 Double_short_dash,
6 long_dashes,
7 Dash_double_short_dash.
*
Markers: 0 Crosses,
1 Plus_Signs,
2 Small_Circles,
3 8_Point_Stars,
4 Squares,
5 Dots.

