19
Generated by Jive on 2013-08-30+02:00 1 How to pass data from ABAP to Web Dynpro ABAP - Part 1 Introduction This document explains how to pass data from ABAP to Web Dynpro ABAP application. Here I am taking a simple and well known example, Flight data and display bookings of flights, to explain how to pass data to Web Dynpro ABAP application from ABAP. Scenario 1. Create an ABAP ALV report to display flight data. 2. Create a Web Dynpro ABAP application to display bookings of flight. 3. When we double click on any record of flight data in ALV, We have to pass the selected flight data and display Flight bookings Web dynpro application in SAP GUI. Generally, we can pass data to Web Dynpro application through URL parameters (when displaying web dynpro application in browser). But here, we are displaying web dynpro application in SAP GUI itself. So we cannot pass data to web dynpro application through URL parameters. Here we are going to use Shared Memory Objects concept to pass data to Web Dynpro ABAP application from ABAP.

ABAP - Part 1 Introduction How to pass data from ABAP to Web Dynpro · PDF fileHow to pass data from ABAP to Web Dynpro ABAP - Part 1 Introduction This document explains how to pass

  • Upload
    hoangtu

  • View
    235

  • Download
    7

Embed Size (px)

Citation preview

Page 1: ABAP - Part 1 Introduction How to pass data from ABAP to Web Dynpro · PDF fileHow to pass data from ABAP to Web Dynpro ABAP - Part 1 Introduction This document explains how to pass

Generated by Jive on 2013-08-30+02:001

How to pass data from ABAP to Web DynproABAP - Part 1

Introduction This document explains how to pass data from ABAP to Web Dynpro ABAP application.

Here I am taking a simple and well known example, Flight data and display bookings offlights, to explain how to pass data to Web Dynpro ABAP application from ABAP.

Scenario

1. Create an ABAP ALV report to display flight data.2. Create a Web Dynpro ABAP application to display bookings of flight.3. When we double click on any record of flight data in ALV, We have to pass the selected flight data and

display Flight bookings Web dynpro application in SAP GUI.

Generally, we can pass data to Web Dynpro application through URL parameters (whendisplaying web dynpro application in browser). But here, we are displaying web dynproapplication in SAP GUI itself. So we cannot pass data to web dynpro application throughURL parameters.

Here we are going to use Shared Memory Objects concept to pass data to Web DynproABAP application from ABAP.

Page 2: ABAP - Part 1 Introduction How to pass data from ABAP to Web Dynpro · PDF fileHow to pass data from ABAP to Web Dynpro ABAP - Part 1 Introduction This document explains how to pass

How to pass data from ABAP to Web Dynpro ABAP - Part 1

Generated by Jive on 2013-08-30+02:002

Shared Memory

The shared memory is a memory area on an application server, which isaccessed by all of this server’s ABAP programs.

To make use of shared memory object:

1. Create ‘Shared Memory-Enabled’ class.2. Create a Shared Memory Area.

Step 1: Creating ‘Shared Memory-Enabled’ class

Execute transaction SE24 (Class Builder). Enter class name and click on create button.

Enter description and click on OK.

Page 3: ABAP - Part 1 Introduction How to pass data from ABAP to Web Dynpro · PDF fileHow to pass data from ABAP to Web Dynpro ABAP - Part 1 Introduction This document explains how to pass

How to pass data from ABAP to Web Dynpro ABAP - Part 1

Generated by Jive on 2013-08-30+02:003

Go to Properties tab and select 'Shared Memory-Enabled' Check box.

Page 4: ABAP - Part 1 Introduction How to pass data from ABAP to Web Dynpro · PDF fileHow to pass data from ABAP to Web Dynpro ABAP - Part 1 Introduction This document explains how to pass

How to pass data from ABAP to Web Dynpro ABAP - Part 1

Generated by Jive on 2013-08-30+02:004

Go to Attributes tab and create an attribute to hold the data

Page 5: ABAP - Part 1 Introduction How to pass data from ABAP to Web Dynpro · PDF fileHow to pass data from ABAP to Web Dynpro ABAP - Part 1 Introduction This document explains how to pass

How to pass data from ABAP to Web Dynpro ABAP - Part 1

Generated by Jive on 2013-08-30+02:005

Go to methods tab and create methods: set_selected_flight and get_selected_flight, toenable our ABAP programs to access the attribute.

Create method set_selected_flight :

Select the method and click on parameters button to create parameters

Create an importing parameter is_flight of type sflight.

Page 6: ABAP - Part 1 Introduction How to pass data from ABAP to Web Dynpro · PDF fileHow to pass data from ABAP to Web Dynpro ABAP - Part 1 Introduction This document explains how to pass

How to pass data from ABAP to Web Dynpro ABAP - Part 1

Generated by Jive on 2013-08-30+02:006

Now create one more method get_selected_flight:

create an exporting parameter es_flight of type sflight.

Page 7: ABAP - Part 1 Introduction How to pass data from ABAP to Web Dynpro · PDF fileHow to pass data from ABAP to Web Dynpro ABAP - Part 1 Introduction This document explains how to pass

How to pass data from ABAP to Web Dynpro ABAP - Part 1

Generated by Jive on 2013-08-30+02:007

Enter the below code in SET_SELECTED_FLIGHT by double clicking on it.

SET_SELECTED_FLIGHT

method SET_SELECTED_FLIGHT.

* Set Flight Data

ms_flight = is_flight.

endmethod.

Enter the below code in GET_SELECTED_FLIGHT by double clicking on it.

GET_SELECTED_FLIGHT

method GET_SELECTED_FLIGHT.

* Get Selected Flight

Page 8: ABAP - Part 1 Introduction How to pass data from ABAP to Web Dynpro · PDF fileHow to pass data from ABAP to Web Dynpro ABAP - Part 1 Introduction This document explains how to pass

How to pass data from ABAP to Web Dynpro ABAP - Part 1

Generated by Jive on 2013-08-30+02:008

es_flight = ms_flight.

endmethod.

Now Save and Activate the class.

This class is called as 'Root Class'.

Step 2: Creating Shared Memory Area

Here we will use our created root class as 'global area root class' of our new memory area.

Execute transaction SHMA. Enter Area name and click on create button.

Page 9: ABAP - Part 1 Introduction How to pass data from ABAP to Web Dynpro · PDF fileHow to pass data from ABAP to Web Dynpro ABAP - Part 1 Introduction This document explains how to pass

How to pass data from ABAP to Web Dynpro ABAP - Part 1

Generated by Jive on 2013-08-30+02:009

Enter description, In Root class enter the created 'Shared Memory-Enabled' class in step 1,and select client-specific Area check box.

Page 10: ABAP - Part 1 Introduction How to pass data from ABAP to Web Dynpro · PDF fileHow to pass data from ABAP to Web Dynpro ABAP - Part 1 Introduction This document explains how to pass

How to pass data from ABAP to Web Dynpro ABAP - Part 1

Generated by Jive on 2013-08-30+02:0010

Click on Save.

Once you click on save, it will automatically generate an Area Class with the given Areaname. you can see it in SE24 transaction by giving the area name and click on display.

This second step gives us 'Area Handle' - a specific class which is needed to interact withthe memory object created in step 1.

Page 11: ABAP - Part 1 Introduction How to pass data from ABAP to Web Dynpro · PDF fileHow to pass data from ABAP to Web Dynpro ABAP - Part 1 Introduction This document explains how to pass

How to pass data from ABAP to Web Dynpro ABAP - Part 1

Generated by Jive on 2013-08-30+02:0011

We are done with creating Shared Memory Object.

Now we will use this in our ABAP program to export data to shared memory and in our webdynpro application to import data from shared memory.

Creating Web Dynpro ABAP Application

Step 1: Create a Web Dynpro Component

Go to the SE80 transaction and create a Web Dynpro Component.

Enter Description and click on OK.

Step 2: Data Binding

Go to the Context tab of Main View and create a node BOOKINGS.

Page 12: ABAP - Part 1 Introduction How to pass data from ABAP to Web Dynpro · PDF fileHow to pass data from ABAP to Web Dynpro ABAP - Part 1 Introduction This document explains how to pass

How to pass data from ABAP to Web Dynpro ABAP - Part 1

Generated by Jive on 2013-08-30+02:0012

Enter dictionary structure SBOOK, cardinality 0..n and click on Add attributes from structure.

Select the required fields and click on OK.

Step 3: Layout Design.

Now Go to Layout tab, and click on Web Dynpro Code Wizard( magic symbol button).

Page 13: ABAP - Part 1 Introduction How to pass data from ABAP to Web Dynpro · PDF fileHow to pass data from ABAP to Web Dynpro ABAP - Part 1 Introduction This document explains how to pass

How to pass data from ABAP to Web Dynpro ABAP - Part 1

Generated by Jive on 2013-08-30+02:0013

Double click on Table to create and bind Table UI.

Click on context and select the Bookings Node.

Click on OK.

Now we can see the Table UI in the layout.

Now goto Methods tab, and enter below code in WDDOINIT method.

WDDOINIT

method WDDOINIT.

* Data declarations

DATA: lo_nd_bookings TYPE REF TO if_wd_context_node,

lt_bookings TYPE wd_this->Elements_bookings,

Page 14: ABAP - Part 1 Introduction How to pass data from ABAP to Web Dynpro · PDF fileHow to pass data from ABAP to Web Dynpro ABAP - Part 1 Introduction This document explains how to pass

How to pass data from ABAP to Web Dynpro ABAP - Part 1

Generated by Jive on 2013-08-30+02:0014

lr_shm_handle TYPE REF TO zcl_flight_data_area, " Area Class

lr_shm_root TYPE REF TO zcl_flight_data_root, " Root Class

ls_flight TYPE sflight.

lo_nd_bookings = wd_context->get_child_node( name = wd_this->wdctx_bookings ).

TRY.

* Reading from Shared Memory ( Importing from memory )

lr_shm_handle = zcl_flight_data_area=>attach_for_read( ).

lr_shm_handle->root->get_selected_flight(

importing

es_flight = ls_flight ).

lr_shm_handle->detach( ).

* Here ls_flight contains the data if exported to shared memory,

* else it will catch the exception

CATCH cx_shm_no_active_version

cx_shm_read_lock_active

cx_shm_change_lock_active

cx_shm_exclusive_lock_active

cx_shm_inconsistent.

Page 15: ABAP - Part 1 Introduction How to pass data from ABAP to Web Dynpro · PDF fileHow to pass data from ABAP to Web Dynpro ABAP - Part 1 Introduction This document explains how to pass

How to pass data from ABAP to Web Dynpro ABAP - Part 1

Generated by Jive on 2013-08-30+02:0015

ENDTRY.

* Get Flight Bookings Data

SELECT * FROM sbook INTO TABLE lt_bookings WHERE carrid = ls_flight-carrid

AND connid = ls_flight-connid

AND fldate = ls_flight-fldate.

* Binding data to table

lo_nd_bookings->bind_table( new_items = lt_bookings set_initial_elements = abap_true).

endmethod.

Now Save and Activate the Web Dynpro Component.

Create Application.

Create Web Dynpro Application and save it.

Creating Transaction for Web Dynpro ABAP Application

Go to the SE93 transaction, Enter Transaction name and click on create.

Page 16: ABAP - Part 1 Introduction How to pass data from ABAP to Web Dynpro · PDF fileHow to pass data from ABAP to Web Dynpro ABAP - Part 1 Introduction This document explains how to pass

How to pass data from ABAP to Web Dynpro ABAP - Part 1

Generated by Jive on 2013-08-30+02:0016

Enter description, select 'Transaction with parameters' radio button and click on OK.

Page 17: ABAP - Part 1 Introduction How to pass data from ABAP to Web Dynpro · PDF fileHow to pass data from ABAP to Web Dynpro ABAP - Part 1 Introduction This document explains how to pass

How to pass data from ABAP to Web Dynpro ABAP - Part 1

Generated by Jive on 2013-08-30+02:0017

In the following screen,

• Enter Transaction WDYID• Select 'Skip Initial screen'• Select GUI Support• Under Default Values, Enter:

Name Value

APPLICATION ZWD_BOOKINGS_SHM_DEMO

STARTMODE SAPGUI

Page 18: ABAP - Part 1 Introduction How to pass data from ABAP to Web Dynpro · PDF fileHow to pass data from ABAP to Web Dynpro ABAP - Part 1 Introduction This document explains how to pass

How to pass data from ABAP to Web Dynpro ABAP - Part 1

Generated by Jive on 2013-08-30+02:0018

Page 19: ABAP - Part 1 Introduction How to pass data from ABAP to Web Dynpro · PDF fileHow to pass data from ABAP to Web Dynpro ABAP - Part 1 Introduction This document explains how to pass

How to pass data from ABAP to Web Dynpro ABAP - Part 1

Generated by Jive on 2013-08-30+02:0019

In the next part, How to pass data from ABAP to Web Dynpro ABAP - Part 2 we will see creating ALV report

and how to attach data to Shared Memory.