Monday, April 27, 2009

Table Types

Table types are construction blueprints for internal tables that are stored in the ABAP Dictionary. When you create a table type in the ABAP Dictionary, you specify the line type, access type, and key. The line type can be any data type from the ABAP Dictionary, that is, a data element, a structure, a table type, or the type of a database table. You can also enter a predefined Dictionary type directly as the line type, in the same way that you can with a domain.

In an ABAP program, you can use the TYPE addition to refer directly to a table type. If you define a local data type in a program by referring to a table type as follows:
TYPES dtype TYPE table.

The construction blueprint of the table type is used to create a local internal table dtype in the program. The predefined Dictionary data types of the domains used by the data elements in the structure are converted into the corresponding ABAP types. The semantic attributes of the data elements are used for the corresponding components of the internal table in the program.

Lock Objects

These types of objects are used for locking the access to database records in table. This mechanism is used to enforce data integrity that is two users cannot update the same data at the same time. With lock objects you can lock table-field or whole table.

In a system where many users can access the same data, it becomes necessary to control the access to the data. In R/3 system this access control is built-in on database tables. Developers can also lock objects over table records.

To lock an object you need to call standard functions, which are automatically generated while defining the lock object in ABAP/4 dictionary. This locking system is independent of the locking mechanism used by the R/3 system. Whenever an object is locked, either by in built locking mechanism or by function modules, it creates corresponding entry in global system table i.e. table is locked. The system automatically releases the lock at the end of transaction.

Creating Lock Objects

Lock object is an aggregated dictionary object and can be defined by using the following steps:

1. From initial data dictionary screen, enter the name for the object, Click Lock object radiobutton and then click on Create. The system displays a dialog box for Maintain Lock Objects screen
2. Enter short text as usual and the name for primary table.
3. Save
4. Select Tables option
From this screen you can: Select secondary tables, if any, linked by foreign key relationship.

Fields for the lock objects. This option allows you to select fields for objects (R/3 system allows locking up to record level). Lock object argument are not selected by user but are imposed by the system and includes all the primary keys for the table.


Types of locks

You can lock the table or record by using following types of locking:

Exclusive (E) or Read mode: The locked data can only be displayed or modified by single user i.e. the owner of the object. Access to other users is denied.

Shared (S) or Write Mode: Several users can access the same record simultaneously, but only in display mode and except the first one, who has asked for the data in update mode.

Exclusive not cumulating (X) it is similar to exclusive lock. It allows only a single user access. E can be called several times from the same transaction. In contrast, a lock type X can be called only once during the transaction. Any other call for this lock is rejected.

When you activate the lock object, the functions are automatically generated. And these are ENQUEUE-EZN and DEQUEUE-EZN. EZN is name of the lock object.

While ENQUEUE is used in program to set the code over the selected data depending upon the lock object arguments. DEQUEUE is used to release the lock.

Type Groups

Type groups were based on the include technique, and allowed you to store any type definitions globally in the Dictionary by defining them using TYPES statements. The definition of a type group is a fragment of ABAP code which you enter in the ABAP Editor. The first statement for the type group pool is always: TYPE-POOL pool.

After that, you define data types using the statement TYPES. It was also possible to define global constants using the CONSTANTS statement. All the names of these data types and constants must begin with the name of the type group and an underscore: pool_

In an ABAP program, you must declare a type group as follows before you can use it: TYPE-POOLS pool. This statement allows you to use all the data types and constants defined in the type group pool in your program. You can use several type groups in the same program.

Let the type group HKTST be created as follows in the ABAP Dictionary:

TYPE-POOL hktst.
TYPES: BEGIN OF hktst_typ1,
col1(10) TYPE c,
col2 TYPE i,
END OF hktst_typ1.

TYPES hktst_typ2 TYPE p DECIMALS 2.
CONSTANTS hktst_eleven TYPE i VALUE 11.

This type group defines two data types HKTST_TYP1 and HKTST_TYP2, as well as a constant HKTST_ELEVEN with the value 11.

Any ABAP program can use this definition with the TYPE-POOLS statement:

TYPE-POOLS hktst.
DATA: dat1 TYPE hktst_typ1,
dat2 TYPE hktst_typ2 VALUE '1.23'.
WRITE: dat2, / hktst_eleven.
The output is: 1.23, 11

The data types defined in the type group are used to declare data objects with the DATAstatement and the value of the constant is, as the output shows, known in the program

Example for type Group
*&---------------------------------------------------------------------*
*& Report ZBASU_TYPE_GROUP *
*& *
*&---------------------------------------------------------------------*
*& *
*& *
*&---------------------------------------------------------------------*

REPORT ZBASU_TYPE_GROUP .
TYPE-POOLs: ZTYPE .
Tables: mara.

data: itab type table of ztype_basu with header line.
select-options: material for mara-matnr.

select * from mara into corresponding fields of table itab where matnr
in material.

write:/ ztype_a.
loop at itab.
write:/ itab-matnr,
itab-ersda,
itab-ernam.
endloop.

***************** Type Group defined DDIC
TYPE-POOL ZTYPE .

constants: ZTYPE_a type i value 10.
types: begin of ztype_basu,
matnr like mara-matnr,
ersda like mara-ersda,
ernam like mara-ernam,
end of ztype_basu.

Structures in ABAP

Structure is a skeletal view of a table. It contains the definition of columns and don’t have any contents. Structure is generally a template based on which a table is created. The basic difference between structure and table is that the structure does not exist at the underlying database system level. Structure exists as definition in the dictionary.

Types of Structures

Append Structure:- It will add Fields to the table from last . we can't use that structure in another table. An append structure is a structure assigned to just one table. When a table is activated, all append structures for the table are found and appended to the table.Append structures are used to add customer fields to SAP tables and Custom tables also.

Include Structure: Include structures can used by us to add fields into any ztables and SAP tables also. Because in a Ztable we can add fields where ever we want. Include structure can be used more than one time in a table. The same include structure can be included to any no of custom tables.

Search Help

Search helps are independent Repository objects that you create using the ABAP Dictionary. They are used to present input help for screen fields which gives list of all possible values for either primary key or non primary keys.

The input help (F4 help) is a standard function of the R/3 System. It permits the user to display a list of possible values for a screen field. A value can be directly copied to an input field by list selection.

The fields having an input help are shown in the R/3 System by the input help key to the right of the field. This key appears as soon as the cursor is positioned on the corresponding screen field. The help can be started either by clicking on this screen element or with function key F4.

Since the input help is a standard function, it should look and behave the same throughout the entire R/3 System. The development environment therefore provides tools for assigning a standardized input help to a screen field.

When you define a parameter of a search help, you must also define whether it should be used to copy data to the input help (IMPORT parameter) or whether to return data from the input help (EXPORT parameter).

Types of Search helps

Elementary search helps:- defines a search path where we will define the table from which the data has to be read and the selection criteria. Through import and export parameters. Used when we gets the data rom a single table.

Collective search helps:- Combination of elementary search helps. When we need to fetch data based on multiple selection criteria s. More than one tables are selection from multiple tables.

Diff Between Elementary search helps & Collective search helps

1) Elementary search helps describe a search path. The elementary search help must define where the data of the hit list should be read from (selection method), how the exchange of values between the screen template and selection method is implemented (interface of the search help) and how the online input help should be defined (online behaviour of the search help).

2) Collective search helps combine several elementary search helps. Collective search help thus can offer several alternative search paths.

3) An elementary search help defines the standard flow of an input help.
4) A collective search help combines several elementary search helps. The user can thus choose one of several alternative search paths with collective search help.
5) A collective search help comprises several elementary search helps. It combines all the search paths that are meaningful for a field.

6) Both elementary search helps and other search helps can be included in a collective search help. If other collective search helps are contained in collective search help, they are expanded to the level of the elementary search helps when the input help is called.

Wednesday, April 15, 2009

Database Views

A view is a logical window to a table or more than one table, the data from a view is not actually physically stored instead being derived from one or more tables. A view can be used to summarize data which is distributed among several tables. It does not contain memory space. During runtime it contains memory after the execution the memory will be released

Types of Views

1. Projection View
2. Database View
3. Maintenance View
4. Help View


Projection View: This view is used to display data’s from only one table i.e. view can draw upon only one table, this means that only the data that actually required is exchanged when the database is accessed. Selection conditions cannot be specified for projection view.


Database View: This view is used to display data’s from more than one table. Database views are implement an inner join, that is, only records of the primary table for which the corresponding records of the secondary tables also exist are fetched. In database views, the join conditions can be formulated using equality relationships between any base fields. Inconsistencies between primary and secondary table could, therefore, lead to reduced selection set.


Maintenance View: This view is used to for data manipulation like insert, update, delete, modify etc. Data from several tables can be summarized in a maintenance view and maintained collectively via this view. That is the data is entered via the view and then distributed to the underlying tables by the system.


Help View: This view is used to displaying possible values of field from one or more than one table i.e. used to output additional information when the online help system is called or when F4 is pressed on the field.