What is SAP Bar Chart Graphics?
The SAP Bar Chart Graphics displays bar charts over a given time period, and allows the user to manipulate the bar charts. An ideal tool to develop a planning board.
Features of SAP Bar Chart Graphics:
Two ways to call Bar Chart Graphics:
Call as a Window – Here the bar chart appears in a separate window.
Calling as a Control – Here the bar chart appears as a control.
The key function groups:
The key function modules used when calling a bar chart as a window:
The key function modules used when calling a bar chart as a control:
The common key function modules used in window/control:
A simple Bar Chart example:
///////////////////////////////////////////////////////////////////////////////////////////////////////
REPORT zbarchartsimple.
INCLUDE sgrccnst.
INCLUDE lbarccon.
INCLUDE barcdata.
DATA: chart LIKE bcchart-id,
section LIKE bcsection-id,
val LIKE bcvals-val.
PARAMETER: gruppe LIKE tbcgt-prf_gruppe DEFAULT 'DEMO',
name LIKE tbcgt-prf_name DEFAULT '000000000001',
index LIKE tbcgt-prf_index DEFAULT '1'.
* Assign Graphic profile
graph_profile-prf_gruppe = gruppe.
graph_profile-prf_name = name.
graph_profile-prf_index = index.
* Start and end of the timeline
CALL FUNCTION 'BARC_SET_TIME_AXIS'
EXPORTING
start = '01.01.2012;'
end = '31.12.2012;'.
* Add 1st Chart
CALL FUNCTION 'BARC_ADD_CHART'
IMPORTING
id = chart.
* Width of the column in the tables
CALL FUNCTION 'BARC_SET_COLUMN_WIDTH'
EXPORTING
chart_id = chart
width = 4000.
* Heading for the table
boxes-id = 1.
boxes-type = bc_const-row_box.
boxes-chart_id = chart.
boxes-form_type = 'B1'.
boxes-color_type = 'B0'.
APPEND boxes.
box_vals-id = boxes-id.
box_vals-fl = '0'.
box_vals-val = 'Table Header'.
APPEND box_vals.
positions-obj_id = boxes-id.
positions-obj_type = bc_const-box_object.
positions-chart_id = chart.
positions-row_number = 0.
APPEND positions.
WRITE boxes-id TO val.
CALL FUNCTION 'BARC_SET_CHART_ATTRIB'
EXPORTING
fl = bc_const-chart_title_box
id = chart
val = val.
* Add a Section of time axis
CALL FUNCTION 'BARC_ADD_SECTION'
EXPORTING
size = 100
start = '01.01.2012;'
unit = '5'
IMPORTING
id = section.
* Add a Ribbon to a Section
CALL FUNCTION 'BARC_ADD_RIBBON'
EXPORTING
chart_id = chart
color_type = 'R1'
section_id = section
unit = '5'.
CALL FUNCTION 'BARC_ADD_RIBBON'
EXPORTING
chart_id = chart
color_type = 'R2'
section_id = section
unit = '3'.
* Create Rows for the Table
PERFORM set_boxes TABLES boxes
box_vals
positions
USING chart.
* Set Nodes in Graph area
PERFORM set_nodes TABLES nodes
node_vals
positions
USING chart.
stat = sgrc_const-stat_1. "Open Window, Transfer Data, Wait for Input
DO.
* Start Bar Chart
CALL FUNCTION 'BARC_GRAPHIC_PBO'
EXPORTING
confirm = space
profile = graph_profile
stat = stat
TABLES
boxes = boxes
box_vals = box_vals
deletions = deletions
links = links
link_vals = link_vals
nodes = nodes
node_vals = node_vals
positions = positions.
* Wait for user input
CALL FUNCTION 'GRAPH_RECEIVE'
IMPORTING
mcode = m_typ
EXCEPTIONS
inv_communication = 1
no_batch = 2.
IF NOT sy-subrc IS INITIAL.
EXIT.
ENDIF.
CASE m_typ.
WHEN sgrc_const-m_typ_d.
EXIT.
WHEN sgrc_const-m_typ_i.
* Evaluation of data from the graph
CALL FUNCTION 'BARC_GRAPHIC_PAI'
IMPORTING
graph_cmd = graph_cmd
TABLES
boxes = boxes
box_vals = box_vals
deletions = deletions
nodes = nodes
node_vals = node_vals
positions = positions
links = links
link_vals = link_vals
EXCEPTIONS
inv_winid = 1.
abap_cmd = graph_cmd.
stat = sgrc_const-stat_4. "Wait for input
ENDCASE.
ENDDO.
FORM make_box TABLES boxes STRUCTURE bcboxes
box_vals STRUCTURE bcvals
positions STRUCTURE bcposition
USING chart LIKE bcchart-id
id TYPE i
format
color
text
row TYPE i.
boxes-id = id.
boxes-type = bc_const-row_box.
boxes-chart_id = chart.
boxes-form_type = format.
boxes-color_type = color.
APPEND boxes.
box_vals-id = boxes-id.
box_vals-fl = '0'.
box_vals-val = text.
APPEND box_vals.
positions-obj_id = boxes-id.
positions-obj_type = bc_const-box_object.
positions-chart_id = boxes-chart_id.
positions-row_number = row.
APPEND positions.
ENDFORM.
FORM set_boxes TABLES boxes STRUCTURE bcboxes
box_vals STRUCTURE bcvals
positions STRUCTURE bcposition
USING chart LIKE bcchart-id.
PERFORM make_box TABLES boxes box_vals positions
USING chart 2 'B1' 'B1' 'Row - 1' 1.
PERFORM make_box TABLES boxes box_vals positions
USING chart 3 'B1' 'B1' 'Row - 2' 2.
PERFORM make_box TABLES boxes box_vals positions
USING chart 4 'B1' 'B1' 'Row - 3' 3.
PERFORM make_box TABLES boxes box_vals positions
USING chart 5 'B1' 'B1' 'Row - 4' 4.
PERFORM make_box TABLES boxes box_vals positions
USING chart 6 'B1' 'B1' 'Row - 5' 5.
ENDFORM.
FORM set_nodes TABLES nodes STRUCTURE bcnodes
node_vals STRUCTURE bcnvals
positions STRUCTURE bcposition
USING chart LIKE bcchart-id.
nodes-id = 1.
nodes-chart_id = chart.
APPEND nodes.
node_vals-id = nodes-id.
node_vals-chart_id = nodes-chart_id.
node_vals-fl = '1'.
node_vals-val = '12.01.2012;'.
APPEND node_vals.
node_vals-fl = '2'.
node_vals-val = '27.06.2012;'.
APPEND node_vals.
node_vals-fl = bc_const-add_layer.
node_vals-val = '00'.
APPEND node_vals.
positions-obj_id = nodes-id.
positions-obj_type = bc_const-node_object.
positions-chart_id = nodes-chart_id.
positions-row_number = 1.
APPEND positions.
*----------------------------------------------------------------------*
nodes-id = 2.
nodes-chart_id = chart.
APPEND nodes.
node_vals-id = nodes-id.
node_vals-chart_id = nodes-chart_id.
node_vals-fl = '1'.
node_vals-val = '02.02.2012;'.
APPEND node_vals.
node_vals-fl = '2'.
node_vals-val = '25.07.2012;'.
APPEND node_vals.
node_vals-fl = bc_const-add_layer.
node_vals-val = '01'.
APPEND node_vals.
positions-obj_id = nodes-id.
positions-obj_type = bc_const-node_object.
positions-chart_id = nodes-chart_id.
positions-row_number = 2.
APPEND positions.
*----------------------------------------------------------------------*
nodes-id = 3.
nodes-chart_id = chart.
APPEND nodes.
node_vals-id = nodes-id.
node_vals-chart_id = nodes-chart_id.
node_vals-fl = '1'.
node_vals-val = '01.04.2012;'.
APPEND node_vals.
node_vals-fl = '2'.
node_vals-val = '25.09.2012;'.
APPEND node_vals.
node_vals-fl = bc_const-add_layer.
node_vals-val = '02'.
APPEND node_vals.
positions-obj_id = nodes-id.
positions-obj_type = bc_const-node_object.
positions-chart_id = nodes-chart_id.
positions-row_number = 3.
APPEND positions.
*----------------------------------------------------------------------*
nodes-id = 4.
nodes-chart_id = chart.
APPEND nodes.
node_vals-id = nodes-id.
node_vals-chart_id = nodes-chart_id.
node_vals-fl = '1'.
node_vals-val = '11.02.2012;'.
APPEND node_vals.
node_vals-fl = '2'.
node_vals-val = '11.07.2012;'.
APPEND node_vals.
node_vals-fl = bc_const-add_layer.
node_vals-val = '00'.
APPEND node_vals.
positions-obj_id = nodes-id.
positions-obj_type = bc_const-node_object.
positions-chart_id = nodes-chart_id.
positions-row_number = 4.
APPEND positions.
*----------------------------------------------------------------------*
nodes-id = 5.
nodes-chart_id = chart.
APPEND nodes.
node_vals-id = nodes-id.
node_vals-chart_id = nodes-chart_id.
node_vals-fl = '1'.
node_vals-val = '01.05.2012;'.
APPEND node_vals.
node_vals-fl = '2'.
node_vals-val = '11.12.2012;'.
APPEND node_vals.
node_vals-fl = bc_const-add_layer.
node_vals-val = '01'.
APPEND node_vals.
positions-obj_id = nodes-id.
positions-obj_type = bc_const-node_object.
positions-chart_id = nodes-chart_id.
positions-row_number = 5.
APPEND positions.
ENDFORM.
///////////////////////////////////////////////////////////////////////////////////////////////////////
Calling a Bar Chart as a control example:
///////////////////////////////////////////////////////////////////////////////////////////////////////
REPORT zbarchartcontrol.
INCLUDE sgrccnst.
INCLUDE lbarccon.
INCLUDE barcdata.
INCLUDE <ctldef>.
DATA: all_boxes LIKE bcboxes OCCURS 0 WITH HEADER LINE,
all_box_vals LIKE bcvals OCCURS 0 WITH HEADER LINE,
all_links LIKE bclinks OCCURS 0 WITH HEADER LINE,
all_link_vals LIKE bcnvals OCCURS 0 WITH HEADER LINE,
all_nodes LIKE bcnodes OCCURS 0 WITH HEADER LINE,
all_node_vals LIKE bcnvals OCCURS 0 WITH HEADER LINE,
all_positions LIKE bcposition OCCURS 0 WITH HEADER LINE.
DATA: chart LIKE bcchart-id,
section LIKE bcsection-id,
val LIKE bcvals-val,
barc_ocx TYPE cntl_handle,
this_repid LIKE sy-repid,
this_dynnr LIKE sy-dynnr,
ok_code TYPE syucomm,
save_ok_code LIKE ok_code,
graph_cmd_info LIKE bccmdinfo,
gr_sel_field LIKE net_graph-sel_field,
layer_kind LIKE tbcl-layer_type,
settings LIKE barc_set,
symboltype LIKE tbcl-symboltype.
PARAMETER: gruppe LIKE tbcgt-prf_gruppe DEFAULT 'DEMO',
name LIKE tbcgt-prf_name DEFAULT '000000000001',
index LIKE tbcgt-prf_index DEFAULT '1'.
this_dynnr = '100'.
this_repid = sy-repid.
CALL FUNCTION 'BARCHART_CREATE'
EXPORTING
owner_repid = this_repid
dynnr = this_dynnr
CHANGING
handle = barc_ocx.
* Assign Graphic profile
graph_profile-prf_gruppe = gruppe.
graph_profile-prf_name = name.
graph_profile-prf_index = index.
* Start and end of the timeline
CALL FUNCTION 'BARC_SET_TIME_AXIS'
EXPORTING
start = '01.01.2012;'
end = '31.12.2012;'.
* Add 1st Chart
CALL FUNCTION 'BARC_ADD_CHART'
IMPORTING
id = chart.
* Width of the column in the tables
CALL FUNCTION 'BARC_SET_COLUMN_WIDTH'
EXPORTING
chart_id = chart
width = 4000.
* Heading for the table
boxes-id = 1.
boxes-type = bc_const-row_box.
boxes-chart_id = chart.
boxes-form_type = 'B1'.
boxes-color_type = 'B0'.
APPEND boxes.
box_vals-id = boxes-id.
box_vals-fl = '0'.
box_vals-val = 'Table Header'.
APPEND box_vals.
positions-obj_id = boxes-id.
positions-obj_type = bc_const-box_object.
positions-chart_id = chart.
positions-row_number = 0.
APPEND positions.
WRITE boxes-id TO val.
CALL FUNCTION 'BARC_SET_CHART_ATTRIB'
EXPORTING
fl = bc_const-chart_title_box
id = chart
val = val.
* Add a Section of time axis
CALL FUNCTION 'BARC_ADD_SECTION'
EXPORTING
size = 100
start = '01.01.2012;'
unit = '5'
IMPORTING
id = section.
* Add a Ribbon to a Section
CALL FUNCTION 'BARC_ADD_RIBBON'
EXPORTING
chart_id = chart
color_type = 'R1'
section_id = section
unit = '5'.
CALL FUNCTION 'BARC_ADD_RIBBON'
EXPORTING
chart_id = chart
color_type = 'R2'
section_id = section
unit = '3'.
* Create Rows for the Table
PERFORM set_boxes TABLES boxes
box_vals
positions
USING chart.
* Set Nodes in Graph area
PERFORM set_nodes TABLES nodes
node_vals
positions
USING chart.
CALL FUNCTION 'BARC_LOGIC'
TABLES
all_boxes = all_boxes
all_box_vals = all_box_vals
all_links = all_links
all_link_vals = all_link_vals
all_nodes = all_nodes
all_node_vals = all_node_vals
all_positions = all_positions
boxes = boxes
box_vals = box_vals
deletions = deletions
links = links
link_vals = link_vals
nodes = nodes
node_vals = node_vals
positions = positions.
stat = sgrc_const-stat_1. "Open Window, Transfer Data, Wait for Input
CALL SCREEN 100.
FORM make_box TABLES boxes STRUCTURE bcboxes
box_vals STRUCTURE bcvals
positions STRUCTURE bcposition
USING chart LIKE bcchart-id
id TYPE i
format
color
text
row TYPE i.
boxes-id = id.
boxes-type = bc_const-row_box.
boxes-chart_id = chart.
boxes-form_type = format.
boxes-color_type = color.
APPEND boxes.
box_vals-id = boxes-id.
box_vals-fl = '0'.
box_vals-val = text.
APPEND box_vals.
positions-obj_id = boxes-id.
positions-obj_type = bc_const-box_object.
positions-chart_id = boxes-chart_id.
positions-row_number = row.
APPEND positions.
ENDFORM.
FORM set_boxes TABLES boxes STRUCTURE bcboxes
box_vals STRUCTURE bcvals
positions STRUCTURE bcposition
USING chart LIKE bcchart-id.
PERFORM make_box TABLES boxes box_vals positions
USING chart 2 'B1' 'B1' 'Row - 1' 1.
PERFORM make_box TABLES boxes box_vals positions
USING chart 3 'B1' 'B1' 'Row - 2' 2.
PERFORM make_box TABLES boxes box_vals positions
USING chart 4 'B1' 'B1' 'Row - 3' 3.
PERFORM make_box TABLES boxes box_vals positions
USING chart 5 'B1' 'B1' 'Row - 4' 4.
PERFORM make_box TABLES boxes box_vals positions
USING chart 6 'B1' 'B1' 'Row - 5' 5.
ENDFORM.
FORM set_nodes TABLES nodes STRUCTURE bcnodes
node_vals STRUCTURE bcnvals
positions STRUCTURE bcposition
USING chart LIKE bcchart-id.
nodes-id = 1.
nodes-chart_id = chart.
APPEND nodes.
node_vals-id = nodes-id.
node_vals-chart_id = nodes-chart_id.
node_vals-fl = '1'.
node_vals-val = '12.01.2012;'.
APPEND node_vals.
node_vals-fl = '2'.
node_vals-val = '27.06.2012;'.
APPEND node_vals.
node_vals-fl = bc_const-add_layer.
node_vals-val = '00'.
APPEND node_vals.
positions-obj_id = nodes-id.
positions-obj_type = bc_const-node_object.
positions-chart_id = nodes-chart_id.
positions-row_number = 1.
APPEND positions.
*----------------------------------------------------------------------*
nodes-id = 2.
nodes-chart_id = chart.
APPEND nodes.
node_vals-id = nodes-id.
node_vals-chart_id = nodes-chart_id.
node_vals-fl = '1'.
node_vals-val = '02.02.2012;'.
APPEND node_vals.
node_vals-fl = '2'.
node_vals-val = '25.07.2012;'.
APPEND node_vals.
node_vals-fl = bc_const-add_layer.
node_vals-val = '01'.
APPEND node_vals.
positions-obj_id = nodes-id.
positions-obj_type = bc_const-node_object.
positions-chart_id = nodes-chart_id.
positions-row_number = 2.
APPEND positions.
*----------------------------------------------------------------------*
nodes-id = 3.
nodes-chart_id = chart.
APPEND nodes.
node_vals-id = nodes-id.
node_vals-chart_id = nodes-chart_id.
node_vals-fl = '1'.
node_vals-val = '01.04.2012;'.
APPEND node_vals.
node_vals-fl = '2'.
node_vals-val = '25.09.2012;'.
APPEND node_vals.
node_vals-fl = bc_const-add_layer.
node_vals-val = '02'.
APPEND node_vals.
positions-obj_id = nodes-id.
positions-obj_type = bc_const-node_object.
positions-chart_id = nodes-chart_id.
positions-row_number = 3.
APPEND positions.
*----------------------------------------------------------------------*
nodes-id = 4.
nodes-chart_id = chart.
APPEND nodes.
node_vals-id = nodes-id.
node_vals-chart_id = nodes-chart_id.
node_vals-fl = '1'.
node_vals-val = '11.02.2012;'.
APPEND node_vals.
node_vals-fl = '2'.
node_vals-val = '11.07.2012;'.
APPEND node_vals.
node_vals-fl = bc_const-add_layer.
node_vals-val = '00'.
APPEND node_vals.
positions-obj_id = nodes-id.
positions-obj_type = bc_const-node_object.
positions-chart_id = nodes-chart_id.
positions-row_number = 4.
APPEND positions.
*----------------------------------------------------------------------*
nodes-id = 5.
nodes-chart_id = chart.
APPEND nodes.
node_vals-id = nodes-id.
node_vals-chart_id = nodes-chart_id.
node_vals-fl = '1'.
node_vals-val = '01.05.2012;'.
APPEND node_vals.
node_vals-fl = '2'.
node_vals-val = '11.12.2012;'.
APPEND node_vals.
node_vals-fl = bc_const-add_layer.
node_vals-val = '01'.
APPEND node_vals.
positions-obj_id = nodes-id.
positions-obj_type = bc_const-node_object.
positions-chart_id = nodes-chart_id.
positions-row_number = 5.
APPEND positions.
ENDFORM.
MODULE graphic_pbo OUTPUT.
CALL FUNCTION 'BARC_GRAPHIC_PBO'
EXPORTING
abap_cmd = abap_cmd
confirm = 'X'
profile = graph_profile
stat = stat
status_text = status_text
control_handle = barc_ocx
TABLES
boxes = boxes
box_vals = box_vals
deletions = deletions
links = links
link_vals = link_vals
nodes = nodes
node_vals = node_vals
positions = positions
EXCEPTIONS
err_in_profile = 1
inv_profile = 2
inv_winid = 3.
ENDMODULE.
MODULE status_0100 OUTPUT.
SET PF-STATUS 'GRAFIK'.
SET TITLEBAR '100'.
ENDMODULE.
MODULE user_command_0100 INPUT.
DATA: retval TYPE i.
save_ok_code = ok_code.
CLEAR ok_code.
CASE save_ok_code.
WHEN 'EXIT'.
PERFORM end_100.
WHEN 'QUIT'.
PERFORM end_100.
WHEN 'BACK'.
PERFORM end_100.
WHEN OTHERS.
IF save_ok_code(4) = sgrc_const-event
OR save_ok_code(4) = sgrc_const-shell_event.
* Event Double Click
PERFORM user_command.
ELSE. "function Code
* Otherwise function code passed to graphics
CALL FUNCTION 'BARCHART_SET_FUNCTION_CODE'
EXPORTING
handle = barc_ocx
function_code = save_ok_code
IMPORTING
return = retval.
IF retval = 0.
* If data changes associated with function code
PERFORM user_command.
IF abap_cmd = bc_const-get_selection
OR abap_cmd = bc_const-get_overlap
OR abap_cmd = bc_const-get_settings
OR abap_cmd = bc_const-get_color.
CALL FUNCTION 'BARC_GRAPHIC_PBO'
EXPORTING
abap_cmd = abap_cmd
stat = stat
control_handle = barc_ocx.
PERFORM user_command.
ENDIF.
ELSE.
stat = sgrc_const-stat_4. "Wait for input
ENDIF.
ENDIF.
ENDCASE.
ENDMODULE.
FORM end_100.
CALL FUNCTION 'BARC_GRAPHIC_PAI'
EXPORTING
control_handle = barc_ocx
at_control_destroy = sgrc_const-yes.
CALL FUNCTION 'CONTROL_DESTROY'
CHANGING
h_control = barc_ocx
EXCEPTIONS
OTHERS = 1.
SET SCREEN 0.
LEAVE SCREEN.
ENDFORM.
FORM user_command.
* Evaluation of the data from the graphic
CALL FUNCTION 'BARC_GRAPHIC_PAI'
EXPORTING
control_handle = barc_ocx
IMPORTING
graph_cmd = graph_cmd
graph_cmd_info = graph_cmd_info
gr_sel_field = gr_sel_field
layer_type = layer_kind
settings = settings
symboltype = symboltype
TABLES
boxes = boxes
box_vals = box_vals
deletions = deletions
links = links
link_vals = link_vals
nodes = nodes
node_vals = node_vals
positions = positions
EXCEPTIONS
inv_winid = 1.
CLEAR: abap_cmd,
status_text.
stat = sgrc_const-stat_4. "Wait for input
* Evaluation of user commands
CASE graph_cmd.
WHEN bc_const-ask_for_delete.
abap_cmd = graph_cmd.
WHEN bc_const-ask_for_scaleleft.
abap_cmd = graph_cmd.
WHEN bc_const-ask_for_scaleright.
abap_cmd = graph_cmd.
WHEN bc_const-ask_for_back.
abap_cmd = graph_cmd.
WHEN bc_const-ask_for_quit.
abap_cmd = graph_cmd.
WHEN bc_const-ask_for_exit.
abap_cmd = graph_cmd.
ENDCASE.
CALL FUNCTION 'BARC_LOGIC'
EXPORTING
graph_cmd = graph_cmd
TABLES
all_boxes = all_boxes
all_box_vals = all_box_vals
all_links = all_links
all_link_vals = all_link_vals
all_nodes = all_nodes
all_node_vals = all_node_vals
all_positions = all_positions
boxes = boxes
box_vals = box_vals
deletions = deletions
links = links
link_vals = link_vals
nodes = nodes
node_vals = node_vals
positions = positions.
ENDFORM.
///////////////////////////////////////////////////////////////////////////////////////////////////////
Lesson -2 will teach you all about Bar Chart Profile & making an interactive planning board.
1. Graph title appears in the window title bar
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
6 | |
5 | |
3 | |
3 | |
2 | |
2 | |
2 | |
2 | |
1 | |
1 |