2011 Mar 23 1:20 PM
Hello,
I have copied report BARCOCX1 and want to show a bar chart within a control.
Now I am looking for a solution to trigger an event orPAI after the user makes a
double-click on a box in the chart area.
I´ve tried to debug transaction CM21 but I didn´t find the necessary settings / customizing.
Can anybody help? Thank you.
Kind regards,
Oliver
2011 Sep 25 4:07 PM
Hi,
Better later then never
Reacting to event can be a little be tricky for a barchart object as you have to code everything by yourself. Your PAI module should be something like this:
MODULE pai INPUT.
save_ok_code = ok_code.
CLEAR ok_code.
CASE save_ok_code.
WHEN 'EXIT' OR 'QUIT' OR 'BACK'.
PERFORM end_300. "Free controls
WHEN OTHERS.
IF save_ok_code(4) = sgrc_const-event "Event '%_GC'
OR save_ok_code(4) = sgrc_const-shell_event. "Shell-Event '%_GS'
*------ Handle Barchart events
PERFORM user_command.
PERFORM action_after_event.
ELSE. "Function code
*------ Send function code to graphic (transfer graph_cmd)
CALL METHOD barchart->set_function_code
EXPORTING
function_code = save_ok_code
IMPORTING
return = gf_retval.
IF gf_retval = 0.
PERFORM user_command. "User command
ELSE.
*-------- Function code cannot be directly transferred (Zoom in, ...)
stat = sgrc_const-stat_4. "Wait for input
ENDIF.
ENDIF.
ENDCASE.
ENDMODULE. " USER_COMMAND_0300 INPUT
Then In your user command form you have to call the method graphic_pai of your barchart object. It will update the boxes/nodes attributes tables and return a graph command.
FORM user_command.
"..
* Analyze data returned by the graphic (PAI)
CALL METHOD barchart->graphic_pai
IMPORTING
graph_cmd = graph_cmd
graph_cmd_info = graph_cmd_info
gr_sel_field = gr_sel_field
layer_type = layer_kind
settings = gw_settings
symboltype = symboltype
CHANGING
charts = gt_charts[]
boxes = boxes[]
box_vals = box_vals[]
deletions = deletions[]
links = links[]
link_vals = link_vals[]
nodes = nodes[]
node_vals = node_vals[]
positions = positions[].
and after that, process the graph command returned in GRAPH_CMD parameter and call function BARC_LOGIC to update again the internal tables for boxes, nodes, ..:
CLEAR: abap_cmd, status_text.
stat = sgrc_const-stat_4. "Wait for input
* Process graph commands ------------------------------------ >>>>>>>>>>
CASE graph_cmd.
*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*
WHEN bc_const-ask_for_insert. "Box/node/layer Insertion
PERFORM ask_for_insert.
*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*
WHEN bc_const-ask_for_modify. "Box/node/layer modification
PERFORM ask_for_modify.
*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*
WHEN bc_const-double_click. "Double-click
PERFORM event_double_click.
"...
*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*
WHEN gc_dis_person. "Display person master data
PERFORM display_master_data.
ENDCASE. "case GRAPH_CMD
*<<<<<<<<<< ------------------------------------------------------------
* Actualise charts tables
CHECK graph_cmd IS NOT INITIAL.
CALL FUNCTION 'BARC_LOGIC'
EXPORTING
graph_cmd = graph_cmd
TABLES
all_boxes = gt_all_boxes
all_box_vals = gt_all_box_vals
all_links = gt_all_links
all_link_vals = gt_all_link_vals
all_nodes = gt_all_nodes
all_node_vals = gt_all_node_vals
all_positions = gt_all_positions
boxes = boxes
box_vals = box_vals
deletions = deletions
links = links
link_vals = link_vals
nodes = nodes
node_vals = node_vals
positions = positions.
The constants used above are defined in include LBARCCON.
2011 Sep 25 4:43 PM
With the example above, the EVENT_DOUBLE_CLICK form should contain some logic to send a new command to the barchart:
FORM event_double_click .
DATA: lw_selected_node TYPE bcnvals.
* Check if a box has been clicked in table part
READ TABLE boxes INDEX 1.
IF sy-subrc = 0.
IF boxes-chart_id = gf_chart_1. "Double-click on chart 1
abap_cmd = gc_dis_person.
ELSE. "Double-click on chart 2
abap_cmd = gc_dis_order. "Display order master data
ENDIF.
ENDIF.
ENDFORM.
Then our form ACTION_AFTER_EVENT will take care of sending a new function code to trigger the desired action... In the case here, display the person signaletic data when a box is double-clicked on the top chart, or the order master data when the bottom chart is double-clicked.
FORM action_after_event .
DATA: lf_retval TYPE i,
lf_new_function_code TYPE sy-ucomm.
CASE abap_cmd(2).
WHEN 'SL'. lf_new_function_code = abap_cmd.
WHEN OTHERS. EXIT.
ENDCASE.
CHECK abap_cmd IS NOT INITIAL.
CALL METHOD barchart->set_function_code
EXPORTING
function_code = lf_new_function_code
IMPORTING
return = lf_retval.
IF lf_retval = 0.
PERFORM user_command.
ENDIF.
ENDFORM. " ACTION_AFTER_EVENT
Hope it helps,
m.