Friday, March 11, 2011

Reuse Java Dictionary Types in Web Dynpro Development Components

PURPOSE

Dictionary perspective is one of the many perspectives available in NWDS. We often come across scenarios where we feel custom data types can be re-used. E.g. a String data type of length 20 can be re-used by a number of applications. This can be achieved using dictionary perspective.

Also, there are scenarios where we want a persistent data store like a table and are left with no option other than using R/3 or external database like oracle or SQL.

In dictionary perspective we can create a table to store persistent data thus avoiding the use of R/3 or external database.

SCOPE

This document is meant for all Java Web Dynpro developers and SAP portal technical architects.

Java Dictionary

· The SAP Web Application Server provides varied options for all aspects of application development. Different techniques, such as JDBC, are provided also for the database connection for applications.

· Central storage for neutral platform definition of data types and database objects is very helpful if you are programming extensive SAP applications. SAP provides this storage area in the form of the Java Dictionary.

The Java Dictionary enables the following:

· Data type descriptions for Web applications can be described centrally, redundancy-free, and independently of the program code.

· In standard J2EE programming, there are three layers: presentation layer, business layer, and database layer. Cross-layer, reusable storage of data descriptions is possible.

· You can define platform-independent data types.

· The provided type system is based on XML.

· In the Java Dictionary, you can store metadata and services for database objects and user interfaces (Web Dynpro).

· The Java Dictionary provides additional data compared to the database catalog of the respective database system being used. Data type definitions for fields, for example, can be given an input help or a field label.


Elementary Data Types

Elementary data types are used in the new SAP programming model for user interfaces, Web Dynpro. Information from the Java Dictionary can be used in many ways:

· If a type from the Dictionary is assigned to an input field, the Web Dynpro runtime automatically checks whether the values entered match the type.

· If there is a fixed set of values for a type, this value set is proposed to the user in a dropdown list.

· The label text for an input field or the heading of a table column can be derived, on the basis of the respective language, from the Dictionary information on the field (or column). This is done through the generation of suitable properties files.

Tables & Indexes

With Open SQL for Java, SAP offers a persistence framework that ensures automatic portability in all database systems. All tables and indexes that are created in the database must be defined first in the Java Dictionary.

The tables defined in the Java Dictionary can be accessed using Open SQL/JDBC or Open SQL/SQLJ. For SQLJ, SAP provides additional utilities (SQLJ Editor, Translator, and so on). As of now, we are going to concentrate on using Open SQL/JDBC.

Type checks that are executed in Open SQL for Java are based on the definitions in the Java Dictionary

Why use Java Dictionary

Java Dictionary Framework applied in conjunction with NWDS can help you avoid redundant data type definitions. You can create the application specific data types, tables in dictionary and can reuse them extensively in other applications.

Java Dictionary follows ‘Write Once, Reuse Everywhere’ paradigm.

This document demonstrates how to apply data types defined in a Development Component (DC) of type Dictionary as types of database table columns and, on the other hand, as the data types of UI elements within Web Dynpro for Java views. Consider the following scenario:

Within Dictionary DCs, data domain experts

  • Develop application specific data types.
  • Apply them as types of database table columns.
  • Check the types into the Design Time Repository server (DTR) of NWDI.

Subsequently, Web Dynpro skilled developers can check them out and reuse consistently within Web Dynpro DCs.

This way Dictionary DCs can act as a type repository of the database layer and presentation layer of your, possibly complex, Java application, as you can view in the picture below. If you change a Dictionary type, all the objects that use it are established upon generation. The objects that are found are automatically adjusted to include the change.

Prerequisites

  • SAP Netweaver Developer Studio 04/04s

  • SAP J2EE Engine configured in Windows->Preferences

Steps for consuming Java Dictionary Project in Web Dynpro DC

We will go through the following successive development steps:

· Create Development Component (DC) of type ‘Dictionary’

· Define Dictionary types : Simple Types ,Structures & Database Tables

· Make Dictionary type DC visible to other DCs

· Build , Create .sda and deploy Dictionary DC on J2EE server

· Create Web Dynpro DC and Define UI fields

· Create DC of type Enterprise Application Project

· Define Database Alias

· Define Project References

· Build, deploy Enterprise Application DC

· Insert Records in Java Dictionary Table

· Select Records from Java Dictionary Table

STEPS

Create Development Component (DC) of type ‘Dictionary’

Open Java Dictionary Perspective

Open NWDS 04. Go to Windows->Open Perspective->Other

Select Dictionary. Click on OK.

Click on File menu->New->Other



Select Development Component.

Click on Next Local Development->My Components. Click Next.

Provide name as ‘dictionary’, caption as ‘Dictionary DC’and type as ‘Dictionary’

Click Next. Keep the default settings. Click on Finish.

Define Dictionary data types: Simple Types, Structures & Database Tables

Go to Dictionary Explorer->dictionary->Dictionaries->Local Dictionary

->Data Types->Simple Types. Right click on it.

Create Simple Type EMPID

Click on Finish.

Navigate to the Definition tab of Simple type.

Keep type as String and Maximum length as 10.

Create another simple type NAME of type String and Maximum Length 30.

Right click on the Structures node of Data Types.

Create New Structure ‘Employee’.

Provide Package. Click on Finish

Create 2 elements in Employee structure: EMPID and NAME of respective simple types EMPID and NAME.

Right click on Database Tables node of Local Dictionary.

Create Database Table TMP_EMPLOYEE

Click on Finish.

Define two table columns EMPID and NAME of respective simple types EMPID and NAME.

Make Dictionary type DC visible to other DCs

Expand DC Metadata node of the Dictionary DC. Right click on Public Parts

->New Public Part

Give the name pp_dictionary. Click on Next.

In the next screen, select Dictionary Simple Type. Check checkboxes for com/sap/mypackage/EMPID and com/sap/mypackage/NAME.

Then select Dictionary Structure. Check com/sap/mypackage/Employee. Select Dictionary Database Table. Check /TMP_EMPLOYEE.

Click on Finish

Build , Create .sda and deploy Dictionary DC on J2EE server

Right Click on Dictionary DC ->Development Component->Build

Create Archive (.sda= software development archive)

Right Click on Dictionary DC ->Development Component->Deploy

Create Web Dynpro DC and Define UI fields

File->New->Development Component Project ‘dictionary_wd’.

Right Click on Web Dypro Components->New. Create a new Web Dynpro component ‘DictionaryUsageComp’ with view name ‘DictionaryUsage’.

Go to dictionary_wd->DC Metadata->DC Definition->Used DCs. Right click on Used DCs->Add Used DC.



Navigate to My Components->dictionary->pp_dictionary.

Reuse of Dictionary types requires that you select the following dependency types:

Ø Build Time (affected Web Dynpro objects need the Dictionary type for compilation)

Ø Run Time (at runtime, the Web Dynpro application dynamically links to the Dictionary data type deployed to the target server)

Right click on dictionary_wd->Development Component->Build

Now navigate to Web Dynpro Components->DictionaryUsageComp->Views->DictionaryUsage. Select Context tab.

Define Context node Person with structure binding to Employee Structure defined earlier in Dictionary DC .

Click on Next

Click on Finish. Switch to Layout tab. Add following UI elements.

· Add an onAction event handler onActionCreateRecord() for button ‘Create Record’

· Add an onAction event handler onActionDisplayRecords() for button ‘Display Records’.

Create DC of type Enterprise Application Project

· Open J2EE DC Perspective

· File->New->Development Component->J2EE->Enterprise Application with name ‘ear_dc’.

Right click on ear_dc->New->META-INF/data-source-aliases.xml

Provide Alias name as DSSAP



Right Click on ear_dc->Properties->Project References

Check checkboxes for ‘dictionary’ DC and ‘dictionary_wd’ DC. Click on OK.


Build, deploy Enterprise Application DC

  • Right Click on ear_dc->Development Component->Build
  • Right Click on ear_dc->Development Component->Deploy

Insert Records in Java Dictionary Table

In order to insert the records into the java dictionary table TMP_EMPLOYEE

On the click of button ‘Create Record’, following code snippet needs to be added to onActionCreateRecord().

Display Records from Java Dictionary Table

In order to display the records from dictionary table TMP_EMPLOYEE on th click of button ‘Display Records’, following code snippet needs to be added to onActionDisplayRecords().

Delete Records from Java dictionary Table

In order to delete a record from dictionary table TMP_EMPLOYEE on the click of button ‘Delete Record’, following code snippet needs to be added to onActionDeleteRecord().

Build, Deploy and run the application






No comments:

Tutorials on SAP-ABAP

Adobe Interactive Forms Tutorials

Business Server Pages (BSP)

Userexits/BADIs

Web Dynpro for ABAP (Step by step procedure for web dynpro,Tutorials on Web Dynpro,)

ALV Tutorials

goodsites