2007 Jul 02 12:04 PM
How can we create Views?
2007 Jul 02 12:16 PM
Views
Why do you need views?
Creating a view by join, projection and selection
Join conditions and foreign keys
Selection of data with views
Database views
Maintenance views
Inner and outer joins
Why do you Need Views?
F1 F2 F3
F4 F5
F6 F7 F8
Table 3
Table 2
Table 1
View on the tables
View on data
that is
distributed on
more than one
table
F1 F2 F3 F5 F8
Data for an application object is often distributed on several database tables. Database
systems therefore provide you with a way of defining application-specific views on data
in several tables. These are called views.
Data from several tables can be combined in a meaningful way using a view (join). You
can also hide information that is of no interest to you (projection) or only display those
data records that satisfy certain conditions (selection).
??The data of a view can be displayed exactly like the data of a table in the extended
table maintenance.
Structure of a View Starting Situation
Table
TABA
Table
TABB
1 1
2 1
2
2
Text 1 Text 3
Text 4
Text 5
Text 2
Text 6
A
A
B
B
Field 1 Field 2 Field 3 Field 4 Field 5
Field 1 Field 2 Field 3 Field 4 Field 5
1 Text 1
1 Text 1
1 Text 1
1 Text 1
2 Text 2
2 Text 2
2 Text 2
2 Text 2
1
1
2
2
Text 3
Text 4
Text 5
Text 6
A
A
B
B
1
1
2
2
Text 3
Text 4
Text 5
Text 6
A
A
B
B
Cross-product of
tables TABA and
TABB
The structure of a view and selection of the data using this view will be shown with an
example.
Given two tables TABA and TABB. Table TABA contains 2 entries and table TABB 4
entries.
The tables are first appended to one another. This results in the cross-product of the
two tables, in which each record of TABA is combined with each record of TABB.
Structure of a View Join Condition
Join condition: TABA - Field 1 = TABB - Field 3
Field 1 Field 2 Field 3 Field 4 Field 5
1 Text 1
1 Text 1
1 Text 1
1 Text 1
2 Text 2
2 Text 2
2 Text 2
2 Text 2
1
1
2
2
Text 3
Text 4
Text 5
Text 6
A
A
B
B
1
1
2
2
Text 3
Text 4
Text 5
Text 6
A
A
B
B
Reduction of
the crossproduct
??Usually the entire cross-product is not a meaningful selection. You should therefore limit
the cross-product with a join condition. The join condition describes how the records of
the two tables are related.
??In our example, Field 3 of TABB identifies Field 1 of TABA. The join condition is then:
TABA - Field 1 = TABB - Field 3
??With this join condition, all the records whose entry in Field 1 is not identical to the
entry in Field 3 are removed from the cross product. The column for Field 3 in the view
is therefore unnecessary.
Cahead Technologies
Cahead Technologies, #403/404, 2nd Floor, Chord Road Plaza, 20th Main, 1st Block, Rajajinagar, Bangalore-
560010.Tel: +91 80 3131624 3686 5220. Cell: 98860-10740. Visit us: www.cahead.com
48
Structure of a View Field selection (Projection)
Field 1 Field 2 Field 4 Field 5
1 Text 1
1 Text 1
2 Text 2
2 Text 2
Text 3
Text 4
A
B
Text 5
Text 6
A
B
Field 1 Field 2 Field 5
1 Text 1
1 Text 1
2 Text 2
2 Text 2
Text 3
Text 4
Text 5
Text 6
Projection
??Often some of the fields of the tables involved in a view are of no interest. You can
explicitly define the set of fields to be included in the view (projection).
Structure of a View Selection Condition
Selection condition: TABB - Field 4 = A.
Field 1 Field 2 Field 5
1 Text 1
1 Text 1
2 Text 2
2 Text 2
Text 3
Text 4
Text 5
Text 6
Field 1 Field 2 Field 5
1 Text 1
1 Text 1
2 Text 2
2 Text 2
Text 3
Text 4
Text 5
Text 6
Field 4
A
B
A
B
The set of records that can be displayed with the view can be further restricted with a
selection condition.
In our example, only those records with value 'A' in Field 4 should be displayed with the
view.
A selection condition therefore can also be formulated with a field that is not contained
in the view.
How are Tables Linked to Views?
MANDT CARRID CONNID FLDATE BOOKID CUSTOMID ... SBOOK
MANDT CARRID CONNID ... CITYFROM ... CITYTO ... SPFLI
001
001
MANDT ID NAME CITY ... SCUSTOM
001 122356 Smith New York ...
122356
122356
...
...
001
001
New York
Berlin Tokyo
AA Berlin
AA
LH
LH
48
324
324
48
...
...
...
...
3689
3690
...
...
...
...
Example: Travel agencies sometimes have to check which customer is booked on
which flights. The corresponding data is distributed on several tables:
SCUSTOM: Customer data, such as the customer number, name and address
SBOOK: Booking data, such as the carrier, flight number and passenger (customer
number)
SPFLI: Flight data, such as the city of departure and city of arrival
You have to create a view on tables SCUSTOM, SBOOK and SPFLI to obtain the booking
data.
In this case the join conditions are:
SBOOK-MANDT = SCUSTOM-MANDT
SBOOK-CUSTOMID = SCUSTOM-ID
SPFLI-MANDT = SBOOK-MANDT
SPFLI-CARRID = SBOOK-CARRID
SPFLI-CONNID = SBOOK-CONNID
Structure of the View
MANDT ID NAME CITY CARRID CONNID FLDATE BOOKID CITYFROM CITYTO
001
001
122356 Smith New York AA 48 3689 New York Berlin
122356 Smith New York LH 324 3690 Berlin Tokyo
View SCUS_BOOK for customer bookings
4.9.1999
9.9.1999
You can get the bookings for a particular customer by selecting the corresponding
records for keys MANDT and CUSTOMID in table SBOOK.
You can get the flight data from table SPFLI for each booking in table SBOOK by
selecting the corresponding record for the keys MANDT, CARRID and CONNID from
table SPFLI.
You can display only the customer bookings which were not canceled using the view
with the following selection condition:
SBOOK-CANCELED <> 'X'
The join conditions can also be derived from the existing foreign key relationships.
Copying the join conditions from the existing foreign keys is supported in the
maintenance transaction.
The field names of the underlying table fields are normally used as field names in the
view. However, you can also choose a different field name. This is necessary for
instance if two fields with the same name are to be copied to the view from different
tables. In this case you must choose a different name for one of the two fields in the
view.
Data Selection with Views
REPORT CUSBOOK1.
PARAMETERS: CUSTOMID LIKE SBOOK-CUSTOMID.
DATA: BOOKINGS TYPE SCUS_BOOK.
WRITE: / Existing bookings for customer, CUSTOMID, :.
SELECT * FROM SCUS_BOOK INTO BOOKINGS
WHERE CUSTOMID = CUSTOMID.
WRITE: / CUSTOMER, BOOKINGS-NAME, booked for,
BOOKINGS-CARRID,BOOKINGS-CONNID, from,BOOKINGS-CITYFROM,
to,BOOKINGS-CITYTO, on,BOOKINGS-FLDATE.
ENDSELECT.
IF SY-SUBRC <> 0.
WRITE: / No bookings exist.
ENDIF.
??You would get the same results using nested SELECT statements:
SELECT * FROM SCUSTOM WHERE ID = CUSTOMID.
SELECT * FROM SBOOK WHERE CUSTOMID = SCUSTOM-ID.
SELECT * FROM SPFLI WHERE CARRID = SBOOK-CARRID AND
CONNID = SBOOK-CONNID
WRITE: / Customer, SCUSTOM-NAME, booked on, SPFLI-CARRID, SPFLICONNID,
from, SPFLI-CITYFROM, to, SPFLI-CITYTO, on, SBOOK-FLDATE.
ENDSELECT.
ENDSELECT.
ENDSELECT.
??Selection with a database view, however, is usually more efficient than selection with a
nested SELECT statement.
As of Release 4.0 you can formulate the join condition directly in OPEN SQL.
A view has type character and can be accessed in programs like all other types and can
be used to define data objects.
Database Views
F6 F7 F8
Table 3
F4 F5
Table 2
F1 F2 F3
Table 1
View definition in the ABAP Dictionary
View definition in
the database
Is created in the DB
during activation
ABAP program
F1 F2 F3 F5 F8
F1 F2 F3 F5 F8
Database interface
A database view is defined in the ABAP Dictionary and automatically created on the
database during activation. Accesses to a database view are passed directly to the
database from the database interface. The database software performs the data
selection.
If the definition of a database view is changed in the ABAP Dictionary, the view created
on the database must be adjusted to this change. Since a view does not contain any
data, this adjustment is made by deleting the old view definition and creating the view
again in the ABAP Dictionary with its new definition.
The maintenance status defines whether you can only read with the view or whether
you can also write with it. If a database view was defined with more than one table, this
view must be read only.
The data read with a database view can be buffered. View data is buffered analogously
to tables. The technical settings of a database view control whether the view data may
be buffered and how this should be done. The same settings (buffering types) can be
used here as for table buffering. The buffered view data is invalidated when the data in
one of the base tables of the view changes.
Includes in Database Views
F 7 F 8
TABB
iinclluded iin
viiew
Database view on TABA, TABB and TABC
TABA TABB TABC
F 1 F 3 F 4 F 5 F 6 F 8
F 1 F 2 F 3 F 4 F 5 F 6
You can include entire tables in database views. In this case all the fields of the included
table become fields of the view (whereby you can explicitly exclude certain fields). If
new fields are included in the table or existing fields are deleted, the view is
automatically adjusted to this change. A new or deleted field is therefore automatically
included in the view or deleted from it.
If an append structure is added to a table included in a view, the fields added with the
append structure are automatically included in the view.
To include a table in a view, you must enter the character '*' in field View field in the
view maintenance, the name of the table to be included in the field Table and the
character '*' again in the field Field name.
??If you do not want to include a field of the included table in the view, proceed as
follows:
Enter a '-' in the field View field.
Enter the name of the included table in the field Table.
Enter the name of the field in the field Field name.
Maintenance Views
F6 F7 F8
Table 3
F1 F2 F3
Table 1
Table 2
F4 F5
Maintenance
view on the
tables Data exchange with
the maintenance view
Foreign key Foreign key
F1 F2 F3 F5 F8
Application object
Data that is distributed on more than one table often forms a logical unit, called an
application object. You should be able to display, change and create the data of such an
application object together. Users usually are not interested in the technical
implementation of the application object, such as the distribution of the data on several
tables.
You can maintain complex application objects in a simple way using a maintenance
view. The data is automatically distributed on the underlying database tables.
All the tables used in a maintenance view must be linked with a foreign key. This means
that the join conditions are always derived from the foreign key in the maintenance
view. You cannot enter the join conditions directly as in a database view.
A maintenance interface with which the data of the view can be displayed, changed and
created must be generated from the definition of a maintenance view in the ABAP
Dictionary.
When the maintenance interface is created, function modules that distribute the data
maintained with the view on the underlying tables are automatically generated.
The maintenance interface is generated with the Transaction Generate Table View
(Transaction SE54) or from the view maintenance screen with Environment ->
Tab.maint.generator.
Inner and Outer Joins
What is displayed with the view?
Inner join Outer join
Table TABA Table TABB
Join condition
Field 1 Field 2 Field 4
A Text 1
B Text 2
Text 3
Text 4
Field 1 Field 2 Field 4
A Text 1
B Text 2
Text 3
Text 4
C Text 5
A
B
Text 1
Text 2
Field 1 Field 2
C Text 5
A
B
Text 3
Text 4
Field 3 Field 4
The set of data that can be selected with a view greatly depends on whether the view
implements an inner join or an outer join.
With an inner join, you only get those records which have an entry in all the tables
included in the view. With an outer join, on the other hand, those records that do not
have a corresponding entry in some of the tables included in the view are also selected.
The hit list found with an inner join can therefore be a subset of the hit list found with
an outer join.
Database views imp lement an inner join. You only get those records which have an
entry in all the tables included in the view.
Maintenance views implement an outer join.
2007 Jul 02 12:17 PM
Go to SE11,
select the radio button for view. enter a name eg. ztable
click create.
select the tables which you want...
and the fields.
and create...
please revert back if you have any questions.
Regards
Dinesh
ps: reward points
2007 Jul 02 12:17 PM
Custom Views can be created by going to T.Code SE11.
More details :
http://help.sap.com/saphelp_nw70/helpdata/en/cf/21ecab446011d189700000e8322d00/frameset.htm
http://help.sap.com/saphelp_nw70/helpdata/en/66/33f52010dd11d6999300508b5d5211/frameset.htm
http://help.sap.com/saphelp_nw70/helpdata/en/cf/21ecd2446011d189700000e8322d00/frameset.htm
2007 Jul 02 12:37 PM
Hi ,
go to se11.
enter a name for the view and click create.
Radio button option will be displayed
asking you to select one among them
1.Database view
2.Projection view
3.Maintenance view
4.Help View
click on the required type of view.
Hope it helps you.
2007 Jul 03 5:43 AM
What is the Different Types and Usage of Views
This is often asked in an interview about the types of views
The followings are different types of views:
- Database View (SE11)
- Help View ( SE54)
- Projection View
- Maintenance View ( SE54 )
1.Creating Help Views
2.Creating a Database View
3.Creating Maintenance Views
Procedure
4 .Creating Projection Views
Procedure
Enter an explanatory short text in the field Short text.
You can for example find the view at a later time using this short text.
Enter a table name in the field Base table.
A projection view always contains exactly one table.
Select the fields of the base table that you want to include in the view.
Choose Table fields. The fields of the table are now displayed in a dialog box. You can copy fields by selecting them in the first column and choosing Copy.
Save your entries.
You are asked to assign the view a development class. You can change this development class later with Goto ® Object directory entry.
Choose .
Result
The help view is activated. At activation, a log is written; it can be displayed with Utilities ® Activation log. If errors or warnings occurring when the view was activated, they are displayed directly in the activation log.
reward points if it is usefulll .....
Girish
| User | Count |
|---|---|
| 3 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |