Search This Blog

Monday, February 22, 2010

Database View

A view doesn't contain any data physically. It's only a logical way of grouping the required fields from one/more tables with required Joins and selection conditions. View gets records from respective database tables only in runtime and if any updates are done using the View, the data will be actually saved/modified in the database tables. If we try to create any new records using Views, all fields of the database tables which don't lie in the view are maintained either as Blank or Zero(depending on the data type).

Database View can be created on One table as well as multiple tables. Only when it is created on top of one table, we can insert records into the actual database tables using the Views. When it's created with combination of multiple tables, we can only read the data from Database tables.

Navigations to create a Database view for.

se11 -> select Object type as "view" -> Name the view ( ZDBVIEW1 ) -> Click on Create -> Opens an interface with type of views , select "Data base view" -> click on continue -> opens another Interface -> Enter Description ( any ) -> name some table say, "SPFLI" -> press enter -> Click on Relationship pushbutton on screen to get The List of related tables ->select the required tables from the list (say SBOOK , SFLIGHT ) -> Click on Copy , internally SAP Generates Auto Joins Conditions -> Click on View Fields tab button -> Click on table fields to select required fields from tables -> go to "Selection Conditions" tab -> Give the selection conditions if required, with AND/OR for multiple selection -> save the view under a package , assign with request number ->Activate the view (ignore any warnings).


 

* use the view in SE38 to fetch data into Reports.

REPORT ZVIEWTEST1 LINE-SIZE 150 NO STANDARD PAGE HEADING.

DATA : ITAB LIKE ZDBVIEW1 OCCURS 0 WITH HEADER LINE.

SELECT * FROM ZDBVIEW1 INTO TABLE ITAB.

LOOP AT ITAB.

WRITE : / ITAB-CARRID , ITAB-CITYFROM , ITAB-CITYTO , ITAB-FLDATE , ITAB-PRICE.

ENDLOOP.


 

No comments:

Post a Comment