Thursday, November 27, 2008

CL_GUI_CHART_ENGINE

SAP have released their CL_GUI_CHART_ENGINE tool in ECC 6.0. I had such a great reaction from my users just now that I thought I had better share it with you. It was fiddly to get right, but once working the results are fast and high impact.

The requirement is for a high speed data entry screen for the sales call team - no web dynpro please - everything keyboard based and fast. So it is a traditional screen dynpro with the chart for sizzle.


Implementing the chart control is simple - create a cutom control and instantiate the chart control in it during initialisation.

create object lo_container exporting container_name = 'CC_CHART'.
create object gsdynp-chart exporting parent = lo_container.

Now load a bunch of XML to format the chart. Download SAP's Chart Designer tool to generate the XML you require (here). Save it in the MIME repository and extract it using cl_wb_mime_repository=>load_mime and load it into the chart using the chart engine's set_customizing method.

Here is the code I used to extract the XML chart formatting from the MIME repository.


form get_chart_xml changing p_xml type xstring.

data:
lv_xstr type xstring,
lt_xmlr type sdokcntbins,
ls_xmlr type sdokcntbin,
lv_io type skwf_io,
lo_conv type ref to cl_abap_conv_obj.

*-- Load the xml template
* The chart XML is created using SAP's Chart Designer Tool
* The XML definition is stored in the MIME repository
* as YSD_CREDIT_CHART. For performance, the logical address
* is coded here directly.

lv_io-objtype = 'L'.
lv_io-class = 'M_APP_L'.
lv_io-objid = '492EEFF3E0C7014DE10080000A00D597'.
call method cl_wb_mime_repository=>load_mime
exporting
io = lv_io
importing
bin_data = lt_xmlr
changing
language = sy-langu
exceptions
no_io = 1
illegal_io_type = 2
not_found = 3
error_occured = 4
others = 5.
check sy-subrc = 0.

*-- Convert raw to xstring
create object lo_conv.
loop at lt_xmlr into ls_xmlr.
call method lo_conv->convert
exporting
inbuff = ls_xmlr
outbufflg = 25000
importing
outbuff = lv_xstr.
concatenate p_xml lv_xstr into p_xml in byte mode.
endloop.
free lo_conv.

endform. " GET_CHART_XML




And here is the code I used to create the chart:





*&---------------------------------------------------------------------*
*& Form SET_CHART
*&---------------------------------------------------------------------*
form set_chart using p_visible.

statics:
lo_container type ref to cl_gui_custom_container.

data:
lv_xml type xstring,
lv_txt(6),
xml type string.

*-- Initialise chart controls
if lo_container is not bound.
create object lo_container
exporting
container_name = 'CC_CHART'.
endif.

if gsdynp-chart is not bound.
create object gsdynp-chart
exporting
parent = lo_container.
endif.

*-- Set visibility
call method lo_container->set_visible
exporting
visible = p_visible.

if p_visible is initial.
exit.
endif.

*-- Format the chart
perform get_chart_xml changing lv_xml.
gsdynp-chart->set_customizing( xdata = lv_xml ).

*-- Create chart data
if gsdynp-klprz < lv_txt =" '0'."> 100.
lv_txt = '100'.
else.
write gsdynp-klprz to lv_txt.
endif.
xml = ''.
concatenate xml '' into xml.
concatenate xml '' into xml.
concatenate xml lv_txt into xml.
concatenate xml '
' into xml.
concatenate xml '
' into xml.
gsdynp-chart->set_data( data = xml ).

endform. " SET_CHART

3 comments:

Matthias said...

Hello,
thanks a lot, I was trying to import the xml from chart designer in a much more complicated way.

But could you perhaps add the data definition for gsdynp-klprz

and explain the creating of the chart data. I've problems to add a second line to the second Y-Axis.

Thanks a lot

Matthias

Peter said...

Hi Matthias,

GSDYNP-KLPRZ is simply a data value of type klprz_f02l, the percentage value in dec 5 format with 2 decimal places.

You can run the sample program GRAPHICS_GUI_CE_DEMO to see how multiple data series are represented.

Peter

Ramana said...

Hi All,

I need to create Graphical Monthly Schedule planning dashboard using GANTT CHART.
Can you please suggest me or provide any example for the above.