Archive

Archive for the ‘Web Dynpro Abap’ Category

Dinamic Url Generation for an Abap Web Dynpro Application

This is an example to construct the URL for an Abap Web Dynpro application.

Value of abs_url will be :

http://host.domain.com/sap/bc/webdynpro/sap/zwd_application?PARAM_NAME1=value1&PARAM_NAME2=value2

 DATA: t_parameters TYPE tihttpnvp,
 l_parameters TYPE ihttpnvp,
 appl_name TYPE string,
 abs_url TYPE string,
 abs_url_char(500).


 START-OF-SELECTION.
appl_name = 'ZWD_APPLICATION'.

 l_parameters-name = 'PARAM_NAME1'.
 l_parameters-value = 'value1'.
 APPEND l_parameters TO t_parameters.

 l_parameters-name = 'PARAM_NAME2'.
 l_parameters-value = 'value2'.
 APPEND l_parameters TO t_parameters.

 cl_wd_utilities=>construct_wd_url( EXPORTING application_name = appl_name
                                             in_parameters = t_parameters
 IMPORTING out_absolute_url = abs_url ).


abs_url_char = abs_url.

**open application in the browser
  CALL FUNCTION 'CALL_BROWSER'
 EXPORTING
 URL                          = abs_url_char.
Categories: Web Dynpro Abap Tags:

Download a Smartform to Pdf from Web Dynpro Abap

This is an example to download a Smartform to PDF from a Web Dynpro Abap.
The method ONACTIONSHOW_PDF is binded to “onAction” event Button

method ONACTIONSHOW_PDF.

DATA: smartform_fm  TYPE rs38l_fnam,
bin_pdf TYPE TABLE OF docs,
bin_tline TYPE TABLE OF tline,
bin_filesize TYPE i,
bin_pdfx TYPE xstring,
v_device_type TYPE rspoptype,
v_output_options TYPE ssfcompop,
v_control_parameters TYPE ssfctrlop.

**CONVERT SMARTFORM TO BINARY XSTRING PDF
CALL FUNCTION 'SSF_GET_DEVICE_TYPE'
EXPORTING
    i_language             = 'I'
    i_application          = 'SAPDEFAULT'
IMPORTING
     e_devtype              = v_device_type
EXCEPTIONS
     no_language            = 1
     language_not_installed = 2
     no_devtype_found       = 3
     system_error           = 4
     OTHERS                 = 5.

v_output_options-tdprinter = v_device_type.
v_control_parameters-no_dialog = 'X'.
v_control_parameters-getotf = 'X'.

CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
EXPORTING
      formname                 = 'ZSMARTFORM'
IMPORTING
      fm_name                  = smartform_fm
EXCEPTIONS
no_form                  = 1
no_function_module       = 2
OTHERS                   = 3.

CALL FUNCTION smartform_fm
EXPORTING
       control_parameters         = v_control_parameters
       output_options             = v_output_options
       id_document                = doc_id
IMPORTING
       job_output_info            = v_output_stampa
EXCEPTIONS
formatting_error           = 1
internal_error             = 2
send_error                 = 3
user_canceled              = 4
OTHERS                     = 5.

***CONVERT OTF TO PDF
CLEAR: bin_pdf,bin_tline,bin_filesize,bin_pdfx.

CALL FUNCTION 'CONVERT_OTF'
EXPORTING
      format                      = 'PDF'
IMPORTING
      bin_filesize                =  bin_filesize
      bin_file                    = bin_pdfx
TABLES
      otf                         = v_output_stampa-otfdata
      lines                       = bin_tline.

**ATTACH PDF TO RESPONSE
CL_WD_RUNTIME_SERVICES=>ATTACH_FILE_TO_RESPONSE(
i_filename = 'PDFSMARTFORM.PDF'
i_content = bin_pdfx
i_mime_type = 'application/pdf' ).

endmethod.

Executing a Web Dynpro Application inside the SapGui

We can not only execute a Web Dynpro Application in a Web Browser (InternetExplorer) , but also inside the SapGui.

Creating a custom Transaction ZWD_GUI :
Transaction Code : WDYID with ‘Skip initial screen’ selected.

Parameters : APPLICATION – Web Dynpro Application Name (ZWDA_XXXXX)
STARTMODE – GUI

Google Charts in Web Dynpro Abap (SFLIGHT Example)

I want to explain how we can use google chart tools in a Web Dynpro Abap application.

How it works Google Chart Tools (Chart API):

 
http://code.google.com/intl/en/apis/chart/

The Google Chart API returns a chart image in response to a URL GET.

So i created an abap class (ZCL_GOOGLE_CHART) to concatenate this parameters url dynamically .
Now my class constructor accepts only bar and pie chart types

This is an example displaying 2 charts from SFLIGHT Table:

 
-First Chart (Bars) represents Flights Prices (SFLIGHT-PRICE) for all table records (one instance created in wddomodifyview)

-Second Chart (Pie) represents a percentage between maximum number of seats and occupied seats for each single row (a new instance is created at each lead selection).

I have 2 Attributes URL_BARS and URL_PIE, binded to Source Image UI.



 
The first url is generated in wddomodifieview.

DATA: bar_chart type ref to ZCL_GOOGLE_CHART.
CREATE OBJECT bar_chart
EXPORTING
chart_type = 'bvs' "bar vertical
* width = '250'
* height = '100'.
v_title-title = 'Prices'.
bar_chart->set_title( chart_title = v_title )


bar_chart->set_axis( axis_opt = 'x' ). "set X Axis
key_field = 'PRICE'.
bar_chart->set_data_from_table(
data_table = t_sflight
fieldname = key_field "field for data
* fieldname_legend =
* position_legend =
).
label_field = 'CONNID'.
bar_chart->set_bar_label_table(
data_table = t_sflight
fieldname = label_field
).
url_bars = bar_chart->get_url( ).


lo_el_url_google_chart->set_attribute(
name = `URL_BARS`
value = url_bars ).


 
This is the generated Url:
http://chart.apis.google.com/chart?&cht=bvs&chs=250x100&chtt=Prices&chxt=x&chd=t:899,1499,1090,6000,849,1&chds=0,6000&chxl=0:|0400|0454|0455|3577|0026|0101

 

The Second chart will be refreshed at each row selection (onLeadSelect), where the percentage between Max Capacity/Occupied Seats is calculated
Pie Url:
http://chart.apis.google.com/chart?&cht=p&chs=250x100&chd=t:14,86&chdl=%%20Occup|%%20Free&chl=14|86

 

You can read also this great blog from SDN (i found it after i wrote this blog) by T.Jung

Follow

Get every new post delivered to your Inbox.