0% found this document useful (0 votes)
2K views

Complete Dictionary Objects

The document discusses dictionary objects in ABAP including tables, views, and data elements. It describes how to create custom database tables in ABAP including defining fields, primary keys, delivery and technical settings, and generating table maintenance. Table maintenance allows users to view, insert, update and delete table records. The document also compares creating table fields directly versus using data elements and domains.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2K views

Complete Dictionary Objects

The document discusses dictionary objects in ABAP including tables, views, and data elements. It describes how to create custom database tables in ABAP including defining fields, primary keys, delivery and technical settings, and generating table maintenance. Table maintenance allows users to view, insert, update and delete table records. The document also compares creating table fields directly versus using data elements and domains.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 96

CORE ABAP FROM GENSOFT TECHNOLOGIES

POWERED BY Mr. Sridhar Sunkari

Dictionary objects (se11):

Used for creating and managing data definitions (metadata). By using


data definitions, we can create the underlying database objects.
Following are the dictionary objects.

1. Tables

2. Views

3. Data elements

4. Domains

5. Type Groups

6. Search Helps

7. Table Types

8. Lock objects

9. Structures

Table can be used to store the data permanently.

Data  Master data / Transaction data

Master data:

The data which doesn’t change frequently is known as master data.

Example: Empno, ename, customer no, customer name,bank account no,


bank account holder name, material data, vendor data.

Transaction data:

Day to day business data is called transaction data.

Example:-Emp attendance details, emp salaries, customer orders, bank


transactions, purchase order data, sales order data

Business Document’s- are used for data exchange


CORE ABAP FROM GENSOFT TECHNOLOGIES
POWERED BY Mr. Sridhar Sunkari

Enquiry form, quotation, purchase order document, sales order


document, billing document, delivery schedule document.

 Every business document contains 1 header record and one or more


item record’s.

 Header records data will be stored in header tables.

 Item records data will be stored in item tables.

Example for Header and item tables:

VBRK  Billing document header data

Key fields  mandt(client), vbeln(billing document no)

Eg: vbeln  0090005178

VBRP  Billing document item data

Key fields  mandt (client), vbeln (billing document no), posnr


(item no)

Eg: vbeln  0090005178  contains 4 items

Other header and item tables: - Sales Documents (VBAK and VBAP),
Purchase Documents (EKKO and EKPO)

 As part of database tables we can directly use the standard


tables, enhance the standard table (adding fields).

 We can also create the custom tables for storing the customer
specific data.

To create dictionary objects, we use t-code -> se11.

Primary key:

A field declared as primary key can’t accept the duplicate values.


CORE ABAP FROM GENSOFT TECHNOLOGIES
POWERED BY Mr. Sridhar Sunkari

In SAP, every table must contain minimum 1 primary key field and
maximum 16 primary key fields. Primary key fields should be at the
beginning of the table.

Combination of primary key fields is called as composite key.

Based on the client field, the database tables are classified into two
types.

i. Client dependent tables

ii. Client independent tables

Client dependent tables:

The tables which contains MANDT as first field is called client


dependent.

MANDT field will hold the client no.

The records in these tables are specific to the client i.e. the record
inserted in one client will not be available in other client.

Eg: KNA1, MARA, LFA1, VBAK, VBAP, EKKO, EKPO, VBRK, VBRP

Client independent tables:

This table which doesn’t contain MANDT field.

The record’s in this tables are not specific to any client’s i.e. they
are available across the client’s by default.

Eg: TFDIR, TADIR….

Table creation:

 A table is dictionary object which is a collection of rows


(records) and columns (fields)

 Tables are used for storing the data permanently.

In ABAP a table field can be created in two ways:-


CORE ABAP FROM GENSOFT TECHNOLOGIES
POWERED BY Mr. Sridhar Sunkari

i. By using direct data types.

ii. By using data elements and domains (recommended).

Procedure for creating custom database tables:

i. Analyze the fields and the corresponding data types.

ii. Create and activate the table.

iii. Generate table maintenance.

iv. Declare and define events (if required) at the table


maintenance level.

v. Create the t-code for the table maintenance.

Minimum settings required for creating custom database tables:

Delivery and maintenance settings:

1. Delivery class.

2. Data browser / table view maintenance.

Delivery class:

It is used for controlling the transporting of table data.

The possible value’s are “A” or “C”.

A -> application table used for storing master and transaction data.

Generally it is recommended to create the client dependent table as


application table.

C -> customizing table used for storing customers specific data.

Data browser / table view maintenance:

It can contain the following 3 possible values.

In dialog box:
CORE ABAP FROM GENSOFT TECHNOLOGIES
POWERED BY Mr. Sridhar Sunkari

1. Display / Maintenance allowed with restriction.

Note:

In this we can only view the data but we can’t perform the
operations like insertion, deletion and modification.

2. Display Maintenance allowed.

It supports all the operations i.e we can view, insert , delete


and modify.

3. Display maintenance not allowed.

It doesn’t support any of the operations.

Technical settings:

1. Data class.

2. Size category

Data class:

It specifies the schema (partition) in which the table as to be


stored. As an ABAP Consultant we will use only Master Schema (APPL0)
and Transaction schema (APPL1).

Size category:

It specifies the initial amount of memory that needs to be allocated


for the database table.

 When the initial memory is utilized, the memory gets extended


automatically to the amount of initial size.

 In size category the range of number of data records depends


upon “structure of the table”.

Enhancement category:

It specifies the type of enhancement that can be made to the table.


CORE ABAP FROM GENSOFT TECHNOLOGIES
POWERED BY Mr. Sridhar Sunkari

Enhancement is a process of adding the additional fields in the


standard tables.

Limitations of table fields’ creation using direct data types:

 Always the character field values are captured in upper case.

 We cannot impose validations on table data.

 It doesn’t support reusability

 Cannot maintain field labels

Table maintenance:

After creating every database table, ABAP consultant must generate


Table Maintenance.

 The table maintenance allows the end user to maintain the table
for performing the operations like insertion, deletion,
Modification and view the data (display).

 For generating table maintenance we require function group.

 A function group is an object which stores the objects related


to table maintenance. I.e. dependent objects (screens,
subroutines, f.m’s) related to table maintenance are stored
inside function group.

 For creating Function group, we use se80

 As part of generating table maintenance, we need to specify


maintenance type which is of two types.

 Maintenance type is of two types:-

i. One step:

In one step only one screen is generated called as overview


screen in which all the CRUD (create, read, update and delete)
operations are performed.
CORE ABAP FROM GENSOFT TECHNOLOGIES
POWERED BY Mr. Sridhar Sunkari

ii. Two step:

 In two step, Two screens will be generated, overview screen and


single screen.

 In overview screen we can only view the data, delete the data
and modify the data.

 In single screen we can insert the data.

Procedure for generating Table maintenance:

1. Create /Consider a function group (se80)->z830fgroup

2. In SE11, navigate to the table, choose the menu ‘utilities


table maintenance generator’

Authorization group  &nc&

Note: Authorization group is an object created by BASIS


consultant which is associated with set of users who are
authorized to maintain a particular object (table).

Function group  z830fgroup (existing function group)

Maintenance type one step (select the radiobutton)

Propose ‘overview screen’ no by choosing ‘find scr


numbers’ propose screen no. on appl.toolbar

3. Click on create button (appl.toolbar)

 Once a table maintenance is generated, we can maintain the table


using the T-code “SM30”.

 To minimize the process of table maintenance, we need to create


custom t-code for every table maintenance

Custom t-code creation SE93

Creating T-code for table maintenance:


CORE ABAP FROM GENSOFT TECHNOLOGIES
POWERED BY Mr. Sridhar Sunkari

SE93 .provide custom t-code (ZTEMP), create  provide short


text( … ), choose the radiobutton ‘Transaction with parameters’
Provide Transaction (SM30), select the checkbox ‘skip initial screen’
, in gui support select the checkbox ‘sap gui for windows’ and provide
default values for the skipped screen at the end

Name of screen field value

Viewname z845emp

Update X

Note: For collecting screen field names, goto sm30 initial screen,
press f1 in table/view field and collect the screen field name,
similarly put focus on ‘maintain’ button, press f1 and collect the
function code (upd) (equal to update)

Note: Whenever we create t-code for any object, select the check box
‘SAP GUI for windows’, otherwise t-code cannot be used (incomplete).

Table creation using data elements and domains:

Two Ways:

1. TOP-DOWN Approach (Field - Data Element Domain)

2. BOTTOM-UP Approach (Domain  Data Element  Field)

Data element: is a reusable dictionary object which provides


description for the field. I.e. the description (labels) maintained
at data element level will automatically appear on the screens
wherever the data element / corresponding field is referred. It can be
created by referring to a direct data type / referring to a domain. We
can also associate a search help (f4 help) as part of data element.

Domain: is a reusable dictionary object which stores technical


properties of the field like data type, size, fixed values, value
table….
CORE ABAP FROM GENSOFT TECHNOLOGIES
POWERED BY Mr. Sridhar Sunkari

Note: In a client dependent table we have to give minimum two primary


key fields otherwise if only ‘mandt’ is primary key field then we can
maintain maximum of single record.

Collection of Primary key fields is called as Composite key.

Creating dictionary structures (Global structures): A structure is a


collection of different types of fields (se11  choose data type radio
button, provide name of structure (z830str), Create  choose structure
radio button and create the required fields.

Once a dictionary structure is created, we can include the dictionary


structure in other dictionary structures / database tables by using
.include keyword.

We can also include dictionary structures inside local structures of


repository objects using the statements ‘include structure <structure
name> or ‘include type <structure name>’.

Dictionary structure:
CORE ABAP FROM GENSOFT TECHNOLOGIES
POWERED BY Mr. Sridhar Sunkari

Including Dictionary structures in other Dictionary Objects:


CORE ABAP FROM GENSOFT TECHNOLOGIES
POWERED BY Mr. Sridhar Sunkari

Including Dictionary structures in Repository Objects (Executable


program):

REPORT ZUSEGLOBALSTR.

types : begin of ty_emp,
         empno type i,
         ename(20) type c.
*              include structure  z7amstr.
         include type z7amstr.
types : empdesig(25) type c,
        end of ty_emp.
CORE ABAP FROM GENSOFT TECHNOLOGIES
POWERED BY Mr. Sridhar Sunkari

data wa_emp type ty_emp.

wa_emp-empno = 6.
wa_emp-ename = 'Ravi'.
wa_emp-jdate = sy-datum.
wa_emp-jtime = sy-uzeit.
wa_emp-empdesig = 'Manager'.

write :/ wa_emp-empno,
       / wa_emp-ename,
       / wa_emp-jdate,
       / wa_emp-jtime,
       / wa_emp-empdesig.

Note: Once a table maintenance is generated and later on if we make


any changes to the table like (adding new fields, change in field
label/data type…), these changes will not reflect the existing table
maintenance. For reflecting these changes, we need to delete the
existing table maintenance and re-generate the same.

Events at table level:

We can define and implement the events as part of table maintenance to


handle user actions.These events are implemented in the subroutine
which is stored in a include program of the function group.

Requirement: Whenever a new entry is created in the table


(z730employee), automatically we need to assign appl.server date and
time to the table fields (jdate and jtime).

Navigation: In the table maintenance screen, choose the menu


environment  modification  events, click on ‘new entries’ button,
provide the following

T(time of event) Form routines

05 abc (after giving subroutine name, press enter key


it shows an icon in the editor column button)
CORE ABAP FROM GENSOFT TECHNOLOGIES
POWERED BY Mr. Sridhar Sunkari

To define the subroutine, click on the corresponding editor button,


choose new include, continue.

form abc.
  z730employee-jdate = sy-datum.
  z730employee-jtime = sy-uzeit.
endform.

SAVE AND ACTIVATE.

Note: After Implementing events at table level, we need to activate


the function group of table maintenance so that the include programs
of that function group gets adjusted otherwise when we maintain the
table, it generates runtime error.

Type groups:

 It is a collection of global types and constants.

 All the components in the type group must prefix with type group
name followed by ‘_’.

 Inside the type group we can use only types and constant
keywords.

 To use the components of the type group inside the repository


objects, We must declare the type group by using the keyword
“type-pools" . This declaration is mandatory before EHP5.

 Standard type-groups: CNTL, CNDP, SLIS, ICON, VRM…..

Type-group creation in SE11:

TYPE-POOL ZABC .

*data  x type  i. "syntax  error

*constants  x type  i. "syntax  error

*constants  x type  i value  10. "syntax  error


CORE ABAP FROM GENSOFT TECHNOLOGIES
POWERED BY Mr. Sridhar Sunkari

constants zabc_x type i value 10.
constants zabc_y type string value 'Gensoft'.

types zabc_m type i.

types : begin of zabc_emp,
           empno type i,
           ename type string,
           empdesig type string,
        end of zabc_emp.

types : begin of zabc_student,
              cname type string.
*                     include  structure z7amstr.  "(or)
              include type z7amstr.
types : caddr type string,
        end of zabc_student.

Using Type-group in Executable program:

*type-pools  zabc. "mandatory  till ECC  6.0


write :/ zabc_x,zabc_y.

*zabc_m  = 20.  "syntax error


uline.
data gv_m type zabc_m.
gv_m = 20.
write :/ gv_m.

uline.
data wa_emp type zabc_emp.
wa_emp-empno = 6.
wa_emp-ename = 'Raju'.
wa_emp-empdesig = 'Manager'.
write :/ wa_emp-empno,
CORE ABAP FROM GENSOFT TECHNOLOGIES
POWERED BY Mr. Sridhar Sunkari

       / wa_emp-ename,
       / wa_emp-empdesig.

Indexes:

 Indexing is a process of arranging the data in an order.

 Indexes are always created on top of database tables.

 There are two types of indexes:-

1. Primary index 2. Secondary index.

Primary index:

 Primary index is created by sap itself on top of primary key


field.

 As a developer we can create only a secondary index and it can


be created on non-primary key fields.

Secondary indexes are of two types:

1. Unique. 2. Non-unique.

Unique Secondary Index:

Whenever a unique secondary index is created on a field we can’t


maintain duplicate values for that field. Whenever a unique
secondary index is created on client dependent tables, client
field (MANDT) should be part of indexed fields.

Non-Unique Secondary Index:

Whenever a non-unique secondary index is created on a field, it is


possible to maintain duplicate values for that field.

:
CORE ABAP FROM GENSOFT TECHNOLOGIES
POWERED BY Mr. Sridhar Sunkari

A view is a reusable dictionary object which doesn’t exist physically


i.e. it is virtual table (IMAGINARY TABLE). The data in the view will
be populated only in the runtime. i.e a view doesn’t hold any data by
default. Views are used for hiding the original table names, hiding
field names, restricting the access to table data, to read data from
one or more tables. Views are created on top of database tables.

They are 4 types of views.

i. Database view

ii. Projection view

iii. Maintenance view

iv. Help view

Database view:

 It can be created either on single table or multiple tables.

 It supports both projection and selection

 Projection is a process of selecting only required fields and


selection is a process of imposing conditions on accessing the
table data.

 A database view created on single table can be “Read only (or)


“Read and Change”. I.e. the changes made to the data at the view
level will automatically reflect the corresponding base table.

 A database view created on multiple tables is always “Read


only”.

 We cannot generate table maintenance for db views.

 Whenever we create any view based on multiple tables, we must


provide the join conditions by comparing with logically related
fields, otherwise it will lead to Cartesian product (No. of
entries of one table * No of resultant values of other table)
CORE ABAP FROM GENSOFT TECHNOLOGIES
POWERED BY Mr. Sridhar Sunkari

 Whenever we create database view on multiple tables with join


conditions, it constructs the resultant values based on inner
join.

Example: Database view on single table


CORE ABAP FROM GENSOFT TECHNOLOGIES
POWERED BY Mr. Sridhar Sunkari
CORE ABAP FROM GENSOFT TECHNOLOGIES
POWERED BY Mr. Sridhar Sunkari
CORE ABAP FROM GENSOFT TECHNOLOGIES
POWERED BY Mr. Sridhar Sunkari

Save and activate the view, execute the view directly and check
the no. of records and data retrieved.

Executable program: using above view in select query

REPORT ZUSE_DBVIEW_KNA1 line-size 140.

types : BEGIN OF ty_customer.
           include type zdbview_kna1.
types end of ty_customer.

data : t_customer type table of ty_customer,
       wa_customer type ty_customer.
CORE ABAP FROM GENSOFT TECHNOLOGIES
POWERED BY Mr. Sridhar Sunkari

select * from zdbview_kna1 into table t_customer.
  if sy-subrc eq 0.
      write :/ 'No of records fetched :',sy-dbcnt.
      loop at t_customer into wa_customer.
        write :/ wa_customer-mandt,
                 wa_customer-kunnr,
                 wa_customer-land1,
                 wa_customer-fname,
                 wa_customer-lname,
                 wa_customer-ort01.
      endloop.
  else.
    message 'No data' type 'I'.
endif.

Example: Database view on multiple tables


CORE ABAP FROM GENSOFT TECHNOLOGIES
POWERED BY Mr. Sridhar Sunkari
CORE ABAP FROM GENSOFT TECHNOLOGIES
POWERED BY Mr. Sridhar Sunkari
CORE ABAP FROM GENSOFT TECHNOLOGIES
POWERED BY Mr. Sridhar Sunkari
CORE ABAP FROM GENSOFT TECHNOLOGIES
POWERED BY Mr. Sridhar Sunkari

Save and activate the view, execute the view directly and check
the no. of records and data retrieved.

Executable program: using above view in select query

REPORT ZUSE_DB_HEADER_ITEM line-size 140.

*  Retrieving data  from 2  tables using  inner join  in select  quer


y

*types  : BEGIN  OF ty_sales,


*                 mandt type  vbak-mandt,
*                 vbeln type  vbak-vbeln,
*                 erdat type  vbak-erdat,
CORE ABAP FROM GENSOFT TECHNOLOGIES
POWERED BY Mr. Sridhar Sunkari

*                 ernam type  vbak-ernam,
*                 posnr type  vbap-posnr,
*                 matnr type  vbap-matnr,
*            end  of ty_sales.
*
*data  : t_sales  type table  of ty_sales,
*           wa_sales type  ty_sales.
*
*select  vbak~mandt vbak~vbeln  vbak~erdat vbak~ernam
*           posnr matnr
*            into  table t_sales
*           from vbak  INNER JOIN  vbap
*           on vbak~vbeln  = vbap~vbeln
*           where vbak~vbeln  in ('0000004970','0000004971','0000004
972').
*   if  sy-subrc eq  0.
*         write  :/ 'No  of records  fetched :',sy-dbcnt.
*         loop  at t_sales  into wa_sales.
*            write  :/ wa_sales-mandt,
*                          wa_sales-vbeln,
*                          wa_sales-erdat,
*                          wa_sales-ernam,
*                          wa_sales-posnr,
*                          wa_sales-matnr.
*         endloop.
*   else.
*      message  'No data'  type 'I'.
*endif.

*  Retrieving data  from view  related to  2 tables  avoiding joins 


in  select query
types : BEGIN OF ty_sales.
           include type zdb_head_item.
types end of ty_sales.
CORE ABAP FROM GENSOFT TECHNOLOGIES
POWERED BY Mr. Sridhar Sunkari

data : t_sales type table of ty_sales,
       wa_sales type ty_sales.

select * from zdb_head_item into table t_sales.
  if sy-subrc eq 0.
      write :/ 'No of records fetched :',sy-dbcnt.
      loop at t_sales into wa_sales.
        write :/ wa_sales-mandt,
                 wa_sales-vbeln,
                 wa_sales-erdat,
                 wa_sales-ernam,
                 wa_sales-posnr,
                 wa_sales-matnr.
      endloop.
  else.
    message 'No data' type 'I'.
endif.

Projection view:

 It is always created on single table

 It supports only projection but not selection.

 We go for projection view, whenever we need to share complete


data of the base table but with limited fields.

 Maintenance status can be Read (or) Read and Change.


CORE ABAP FROM GENSOFT TECHNOLOGIES
POWERED BY Mr. Sridhar Sunkari
CORE ABAP FROM GENSOFT TECHNOLOGIES
POWERED BY Mr. Sridhar Sunkari

Note:

For both database and projection view’s we can’t generate Table


Maintenance.

Foreign key relationship between tables:

We create foreign key relationship between two tables to maintain


data consistency. i.e the data of one table is based on data of
other table.

In foreign key relationship, two tables are involved.

A) Check table b) Foreign key table


CORE ABAP FROM GENSOFT TECHNOLOGIES
POWERED BY Mr. Sridhar Sunkari

Check table: is a parent table where we maintain the key data


(unique values).

To create a foreign key relationship between two tables, the


two tables must contain at least one field which is having
common domain and in one of the table the common field should
be a primary key field and this table is considered as check
table as it maintains unique values for that common field.

On the other table common field, we create foreign key which


is called as foreign key table.

Once a foreign key relationship is created, it maintains


referential integrity. According to this, in the foreign key
table we can enter only those values for the FOREIGN KEY field
(common field) which needs to be available in check table
common field.

I.E. We need to insert a child row (record in the foreign key


table) only when there is a corresponding record in parent
record (records in parent table->check table).

Example:

Department table: (z830_dept)

Fields:

Deptno(PK) zdept_no zdept_no int4

Dname zdname ydname char20

Loc zloc zloc char15

Deptno’s:- 10,20,30

Employee table (z830_empl)

Fields:

empno zemp_num
CORE ABAP FROM GENSOFT TECHNOLOGIES
POWERED BY Mr. Sridhar Sunkari

ename zename

empdesig zempdesig

dno zdnum zdept_no int4

Note: Create foreign key on ‘dno’ field

Maintenance view:

 This is always created on single table, based on the foreign key


table selected, SAP proposes join condition.

 We can generate table maintenance for maintenance view

 Its support both selection and projection.


CORE ABAP FROM GENSOFT TECHNOLOGIES
POWERED BY Mr. Sridhar Sunkari
CORE ABAP FROM GENSOFT TECHNOLOGIES
POWERED BY Mr. Sridhar Sunkari
CORE ABAP FROM GENSOFT TECHNOLOGIES
POWERED BY Mr. Sridhar Sunkari
CORE ABAP FROM GENSOFT TECHNOLOGIES
POWERED BY Mr. Sridhar Sunkari

View cluster: - is a collection of views which are grouped


together and it simplifies the maintenance of complex cross-client
data (across the tables)

Material tables:

MARA (MATERIAL MASTER DATA) --> MANDT, MATNR

MARC (MATERIAL PLANT DATA) --> MANDT, MATNR, WERKS

MARD (MATERIAL STORAGE LOCATION DATA) --> MANDT, MATNR, WERKS, LGORT
CORE ABAP FROM GENSOFT TECHNOLOGIES
POWERED BY Mr. Sridhar Sunkari

Relationship:- Each Material of MARA table can contain zero / one


/more plants in MARC. EACH Material plant of MARC can contain zero /
one / more storage locations in MARD.

1. Create Maintenance view on ‘MARA’ table


CORE ABAP FROM GENSOFT TECHNOLOGIES
POWERED BY Mr. Sridhar Sunkari
CORE ABAP FROM GENSOFT TECHNOLOGIES
POWERED BY Mr. Sridhar Sunkari
CORE ABAP FROM GENSOFT TECHNOLOGIES
POWERED BY Mr. Sridhar Sunkari

2. Generate Table maintenance for above maintenance view


CORE ABAP FROM GENSOFT TECHNOLOGIES
POWERED BY Mr. Sridhar Sunkari

3. Create maintenance view on MARC table


CORE ABAP FROM GENSOFT TECHNOLOGIES
POWERED BY Mr. Sridhar Sunkari
CORE ABAP FROM GENSOFT TECHNOLOGIES
POWERED BY Mr. Sridhar Sunkari
CORE ABAP FROM GENSOFT TECHNOLOGIES
POWERED BY Mr. Sridhar Sunkari

4. Generate table maintenance for above view


CORE ABAP FROM GENSOFT TECHNOLOGIES
POWERED BY Mr. Sridhar Sunkari

5. Create maintenance view for MARD table


CORE ABAP FROM GENSOFT TECHNOLOGIES
POWERED BY Mr. Sridhar Sunkari
CORE ABAP FROM GENSOFT TECHNOLOGIES
POWERED BY Mr. Sridhar Sunkari
CORE ABAP FROM GENSOFT TECHNOLOGIES
POWERED BY Mr. Sridhar Sunkari

6. Generate Table maintenance for above view


CORE ABAP FROM GENSOFT TECHNOLOGIES
POWERED BY Mr. Sridhar Sunkari

7. Create the view cluster(se54)

Se54  click on ‘edit view cluster’ (appl.toolbar),


CORE ABAP FROM GENSOFT TECHNOLOGIES
POWERED BY Mr. Sridhar Sunkari

Provide view cluster name (z830viewcluster), click on


create/change,
CORE ABAP FROM GENSOFT TECHNOLOGIES
POWERED BY Mr. Sridhar Sunkari

Provide description(……) in header entry…


CORE ABAP FROM GENSOFT TECHNOLOGIES
POWERED BY Mr. Sridhar Sunkari

Provide object structure as follows:


CORE ABAP FROM GENSOFT TECHNOLOGIES
POWERED BY Mr. Sridhar Sunkari

Select each entry, click on field dependencies …

Come back to header entry, and click on activate.


CORE ABAP FROM GENSOFT TECHNOLOGIES
POWERED BY Mr. Sridhar Sunkari

Save and activate, test

Working with Currency and Quantity Fields:

Whenever a table field or structure field contains curr (currency) or


Quan (quantity) fields, we must specify reference table and reference
field.

The reference table can be same table (or) external table and
reference field can be same table field (or) external table field.

The reference data type for (curr) currency is ‘cuky’ and reference
data type for (quan) quantity is ‘unit’.

TCURC  Table for Currency Codes

TOO6  Table for units of measurement


CORE ABAP FROM GENSOFT TECHNOLOGIES
POWERED BY Mr. Sridhar Sunkari

Scenario 1: Reference table  Same table


CORE ABAP FROM GENSOFT TECHNOLOGIES
POWERED BY Mr. Sridhar Sunkari

Scenario 2: Reference table  External table


CORE ABAP FROM GENSOFT TECHNOLOGIES
POWERED BY Mr. Sridhar Sunkari
CORE ABAP FROM GENSOFT TECHNOLOGIES
POWERED BY Mr. Sridhar Sunkari

Table types: is the reusable dictionary object

Table types are the internal tables created at database level.

A Table type can refer to a direct data type / line type (structure)/
reference type (class or interface)

Example 1: Table Type Creation:

Scenario 1: Table Type referring to direct data type (single field)


CORE ABAP FROM GENSOFT TECHNOLOGIES
POWERED BY Mr. Sridhar Sunkari

Example: Using above table type in executable programs

REPORT ZUSE_TTYPE1.

data gt_ttype type z830ttype1. "internal  table
data gs_ttype like line of gt_ttype. "work  area

clear gs_ttype.
gs_ttype = 'Raju'.
append gs_ttype to gt_ttype.

clear gs_ttype.
gs_ttype = 'Ravi'.
append gs_ttype to gt_ttype.
CORE ABAP FROM GENSOFT TECHNOLOGIES
POWERED BY Mr. Sridhar Sunkari

clear gs_ttype.
gs_ttype = 'Ashok'.
append gs_ttype to gt_ttype.

clear gs_ttype.
gs_ttype = '10'.
append gs_ttype to gt_ttype.

loop at gt_ttype into gs_ttype.
  write :/ gs_ttype.
endloop.

Scenario 2: Table Type referring to line type (structure)


CORE ABAP FROM GENSOFT TECHNOLOGIES
POWERED BY Mr. Sridhar Sunkari

Example: Using above table type in executable programs

REPORT ZUSE_TTYPE2.

data gt_emp type z830ttype2. "internal  table
*data  gs_emp like  line of  gt_emp. "work  area (or)
data gs_emp type z830ltype. "work  area

clear gs_emp.
gs_emp-empno = 1.
gs_emp-ename = 'Ravi'.
gs_emp-empdesig = 'Manager'.
append gs_emp to gt_emp.

clear gs_emp.
CORE ABAP FROM GENSOFT TECHNOLOGIES
POWERED BY Mr. Sridhar Sunkari

gs_emp-empno = 2.
gs_emp-ename = 'Vamshi'.
gs_emp-empdesig = 'Employee'.
append gs_emp to gt_emp.

clear gs_emp.
gs_emp-empno = 3.
gs_emp-ename = 'Kiran'.
gs_emp-empdesig = 'Supervisor'.
append gs_emp to gt_emp.

clear gs_emp.
gs_emp-empno = 4.
gs_emp-ename = 'Praveen'.
gs_emp-empdesig = 'CEO'.
append gs_emp to gt_emp.

loop at gt_emp into gs_emp.
  write :/ gs_emp-empno,
           gs_emp-ename,
           gs_emp-empdesig.
endloop.

Standard table types: LVC_T_FCAT, LVC_T_ROW, LVC_T_COL…..

Example 2: Table Type Creation:


CORE ABAP FROM GENSOFT TECHNOLOGIES
POWERED BY Mr. Sridhar Sunkari
CORE ABAP FROM GENSOFT TECHNOLOGIES
POWERED BY Mr. Sridhar Sunkari

Using Table Type in Executable program:

Report 1: Table type referred with Header line

REPORT ZUSEDBVIEW2 line-size 120.

data t_dbview type zemp_dept WITH HEADER LINE.

select * from zdataview
        into table t_dbview.
if sy-subrc eq 0.
     write :/ 'No of records retrieved :',sy-dbcnt.
     loop at t_dbview.
       write :/ t_dbview-empno,
                t_dbview-ename,
                t_dbview-empdesig,
CORE ABAP FROM GENSOFT TECHNOLOGIES
POWERED BY Mr. Sridhar Sunkari

                t_dbview-dno,
                t_dbview-deptno,
                (25) t_dbview-dname,
                t_dbview-loc.
     endloop.
else.
  write :/ 'No data'.
endif.

Report 2: Table type referred without Header line

REPORT ZUSEDBVIEW3 line-size 120.

data t_dbview type zemp_dept.  "internal  table without  header


*data  wa_dbview like  zemp_dept. "syntax  error
*data  wa_dbview type  zdataview. "(or)
data wa_dbview like line of t_dbview.

select * from zdataview
        into table t_dbview.
if sy-subrc eq 0.
     write :/ 'No of records retrieved :',sy-dbcnt.
     loop at t_dbview into wa_dbview.
       write :/ wa_dbview-empno,
                wa_dbview-ename,
                wa_dbview-empdesig,
                wa_dbview-dno,
                wa_dbview-deptno,
                (25) wa_dbview-dname,
                wa_dbview-loc.
     endloop.
else.
  write :/ 'No data'.
endif.

Lock Objects:

1. They are used for performing row-level locking of the table data
CORE ABAP FROM GENSOFT TECHNOLOGIES
POWERED BY Mr. Sridhar Sunkari

2. By Default, Object level locking (Repository / Dictionary


objects) is taken care by SAP itself. i.e only one user can edit
an object at any point of time, other users can only read the
object.

3. Lock Objects names must start with ‘EZ’ (or) ‘EY’ and locking is
done based on primary key field/s

4. Whenever a Lock object is created, SAP creates 2 Function modules

a) ‘ENQUEUE_<LOCK OBJECT NAME>’ - used for locking the row


b) ‘DEQUEUE_<LOCK OBJECT NAME>’ - used for releasing the lock
Types of Lock Modes:

1. Exclusive / Write Lock  In this, only one user can read or edit
the locked record. If other users request for the Exclusive lock,
his request will be rejected but the request is stored in the
queue. Once the first user releases the exclusive lock, the
exclusive lock access is given to other user in the queue.

2. Shared / Read Lock: In this, multiple users can read the locked
record and if a user modifies the locked record, the modified
data is not accessible to other users.

3. Exclusive but not cumulative: It is similar to Exclusive lock,


but other users request is not stored in the queue, but instead
the others users have to send the fresh request.

LOCK OBJECTS CREATION AND USAGE

Lock Object Creation:

1. Create Lock object in SE11


CORE ABAP FROM GENSOFT TECHNOLOGIES
POWERED BY Mr. Sridhar Sunkari

2. In Tables tab, provide table name as ‘KNA1’


CORE ABAP FROM GENSOFT TECHNOLOGIES
POWERED BY Mr. Sridhar Sunkari

3. In Lock parameter tab, SAP proposes Lock parameters based on key


fields
CORE ABAP FROM GENSOFT TECHNOLOGIES
POWERED BY Mr. Sridhar Sunkari

Activate, SAP generates 2 function modules, check them using go to


menu  lock modules

Using Lock objects in Executable programs:

REPORT ZUSE_LOCKOBJECTS.

PARAMETERS p_kunnr type kna1-kunnr.

data : gv_name1 type kna1-name1,
       gv_ort01 type kna1-ort01.

set pf-status 'ABC'. "double  click on  status name-invokes  menu painte


r(SE41)
CORE ABAP FROM GENSOFT TECHNOLOGIES
POWERED BY Mr. Sridhar Sunkari

*  Lock the  customer
CALL FUNCTION 'ENQUEUE_EZLOCKOBJ_CUSTNO'
 EXPORTING
   MODE_KNA1            = 'E'
   MANDT                = SY-MANDT
   KUNNR                = p_kunnr
 EXCEPTIONS
   FOREIGN_LOCK         = 1
   SYSTEM_FAILURE       = 2
   OTHERS               = 3.

IF SY-SUBRC eq 1.
  message 'Customer is locked' type 'E'.
endif.

select single name1 ort01
        from kna1
    into (gv_name1,gv_ort01)
      where kunnr = p_kunnr.
if sy-subrc eq 0.
  write :/ 'Customer Name :',gv_name1,
         / 'Customer City :',gv_ort01.
else.
  write :/ 'No customer'.
ENDIF.

at USER-COMMAND.
 case sy-ucomm.
  when 'FC1'.
      leave PROGRAM.
  when 'FC2'.
*  release the  lock on  customer
    CALL FUNCTION 'DEQUEUE_EZLOCKOBJ_CUSTNO'
     EXPORTING
       MODE_KNA1       = 'E'
       MANDT           = SY-MANDT
       KUNNR           = p_kunnr.
  endcase.

Note: To test Lock object functionality, run the above two programs in
2 sessions and provide customer no in one session, execute, displays
CORE ABAP FROM GENSOFT TECHNOLOGIES
POWERED BY Mr. Sridhar Sunkari

customer record if found (output). In another session, provide same


customer no and try to execute, it says the record is locked. Now, in
the first session unlock the record by clicking on the user defined
button ‘release lock’ in the application toolbar and execute the same
customer in the second session, now it displays data.

Note: ‘Set pf-status <status name>’ is used for creating user-defined


GUI status and using this we can invoke the menu painter tool (SE41)
where we can manage the menu bar, standard toolbar and application
toolbar. Whenever we define our custom GUI status, SAP looses
functionality of some of the std.toolbar buttons , in order to enable
them, assign a function code and implement the logic in the at user-
command event. When the user interacts with menu bar items /
std.toolbar buttons / appl. Toolbar buttons, SAP triggers ‘AT USER-
COMMAND’ button and the corresponding function code will be captured
in the system field ‘SY-UCOMM’ (function code is always captured in
upper case).To Invoke the Menu painter tool, double click on GUI
status name in the set pf-status statement.

Application toolbar buttons in the GUI status ‘ABC’:


CORE ABAP FROM GENSOFT TECHNOLOGIES
POWERED BY Mr. Sridhar Sunkari

Assigning function code for the back button in the GUI status for
enabling it:

SEARCH HELPS:

It is a reusable dictionary object used for providing list of values


as input help to the user.

It is triggered when the user presses ‘F4’ key in the Input Field.

Once a Search help is created, we can associate the search help at 3


different levels:

1. Data element level


CORE ABAP FROM GENSOFT TECHNOLOGIES
POWERED BY Mr. Sridhar Sunkari

2. Selection-Screen input field level

3. Module Pool (Dialog screen) input field level

There are 2 types of Search helps:

1. Elementary Search Help  provides single input path for


list of values

2. Collective Search Help  collection of elementary search


helps  provides multiple input paths for list of values

Elementary Search Help creation 1:

Create the following table:


CORE ABAP FROM GENSOFT TECHNOLOGIES
POWERED BY Mr. Sridhar Sunkari

Create the Elementary search help:


CORE ABAP FROM GENSOFT TECHNOLOGIES
POWERED BY Mr. Sridhar Sunkari

Elementary Search Help creation 2:

Create the following table:


CORE ABAP FROM GENSOFT TECHNOLOGIES
POWERED BY Mr. Sridhar Sunkari

Create the Elementary search help:


CORE ABAP FROM GENSOFT TECHNOLOGIES
POWERED BY Mr. Sridhar Sunkari

Collective Search help creation:

Assign parameter to the parameter of elementary search helps:


CORE ABAP FROM GENSOFT TECHNOLOGIES
POWERED BY Mr. Sridhar Sunkari

Attaching search help at the data element level: (either elementary /


collective)
CORE ABAP FROM GENSOFT TECHNOLOGIES
POWERED BY Mr. Sridhar Sunkari

Executable program: Attaching search help to the selection screen


input field (either elementary / collective search help)

REPORT ZUSE_SEARCHHELP.

*PARAMETERS  p_name type  zabap_team-emp_name MATCHCODE  OBJECT zeles1. 


"program  level elementary  search help
PARAMETERS p_name type zabap_team-emp_name MATCHCODE OBJECT zcolls. "p
rogram  level collective  search help

*PARAMETERS  p_name type  zabap_team-emp_name.

*PARAMETERS  p_name type  zemp_name.


CORE ABAP FROM GENSOFT TECHNOLOGIES
POWERED BY Mr. Sridhar Sunkari

Executable program: Attaching search help to the module pool screen


input field properties:

Search Help Selection Method: As part of creating Elementary Search


Help, We need to provide the selection method. This selection method
can be either a database table or database view or help view. We go
for database table when we need to get the entries of search help (f4
values) from a single table. We go for views when we need to get the
entries of search help (f4 values) from multiple tables. In case of
database view created on multiple tables, it implements inner join and
in case of help view created on multiple tables, it implements left
outer join.

Example 2: To explain selection method of search help


CORE ABAP FROM GENSOFT TECHNOLOGIES
POWERED BY Mr. Sridhar Sunkari

Table 1: z9amemp

Table 1: z9amemp entries


CORE ABAP FROM GENSOFT TECHNOLOGIES
POWERED BY Mr. Sridhar Sunkari

Table 2: z9amdept
CORE ABAP FROM GENSOFT TECHNOLOGIES
POWERED BY Mr. Sridhar Sunkari

Table 2: z9amdept entries


CORE ABAP FROM GENSOFT TECHNOLOGIES
POWERED BY Mr. Sridhar Sunkari

Now, Create Foreign key relationship between above 2 tables:


CORE ABAP FROM GENSOFT TECHNOLOGIES
POWERED BY Mr. Sridhar Sunkari

Scenario 1: Database view  multiple tables


CORE ABAP FROM GENSOFT TECHNOLOGIES
POWERED BY Mr. Sridhar Sunkari
CORE ABAP FROM GENSOFT TECHNOLOGIES
POWERED BY Mr. Sridhar Sunkari

Elementary Search Help Selection method  Database view


CORE ABAP FROM GENSOFT TECHNOLOGIES
POWERED BY Mr. Sridhar Sunkari

Select required parameters and then execute  displays 6 records


CORE ABAP FROM GENSOFT TECHNOLOGIES
POWERED BY Mr. Sridhar Sunkari

Scenario 2: Help View Multiple Tables


CORE ABAP FROM GENSOFT TECHNOLOGIES
POWERED BY Mr. Sridhar Sunkari
CORE ABAP FROM GENSOFT TECHNOLOGIES
POWERED BY Mr. Sridhar Sunkari

Elementary Search Help Selection method  Help view


CORE ABAP FROM GENSOFT TECHNOLOGIES
POWERED BY Mr. Sridhar Sunkari

Select required parameters and then execute  displays 7 records


CORE ABAP FROM GENSOFT TECHNOLOGIES
POWERED BY Mr. Sridhar Sunkari

Using Views in Select Queries:

Database view  multiple tables


CORE ABAP FROM GENSOFT TECHNOLOGIES
POWERED BY Mr. Sridhar Sunkari
CORE ABAP FROM GENSOFT TECHNOLOGIES
POWERED BY Mr. Sridhar Sunkari

Report 1:

REPORT ZUSEDBVIEW.

types : begin of ty_dbview.
            include type zdataview.
types end of ty_dbview.

data : t_dbview type table of ty_dbview,
      wa_dbview type ty_dbview.

select * from zdataview
        into table t_dbview.
CORE ABAP FROM GENSOFT TECHNOLOGIES
POWERED BY Mr. Sridhar Sunkari

if sy-subrc eq 0.
     write :/ 'No of records retrieved :',sy-dbcnt.
     loop at t_dbview into wa_dbview.
       write :/ wa_dbview-empno,
                wa_dbview-ename,
                wa_dbview-empdesig,
                wa_dbview-dno,
                wa_dbview-deptno,
                wa_dbview-dname,
                wa_dbview-loc.
     endloop.
else.
  write :/ 'No data'.
endif.

Report 2: Formatted Output

REPORT ZUSEDBVIEW1 line-size 120.

types : begin of ty_dbview.
            include type zdataview.
types end of ty_dbview.

data : t_dbview type table of ty_dbview,
      wa_dbview type ty_dbview.

select * from zdataview
        into table t_dbview.
if sy-subrc eq 0.
     write :/ 'No of records retrieved :',sy-dbcnt.
     loop at t_dbview into wa_dbview.
       write :/ wa_dbview-empno,
                wa_dbview-ename,
                wa_dbview-empdesig,
                wa_dbview-dno,
                wa_dbview-deptno,
CORE ABAP FROM GENSOFT TECHNOLOGIES
POWERED BY Mr. Sridhar Sunkari

                (25) wa_dbview-dname,
                wa_dbview-loc.
     endloop.
else.
  write :/ 'No data'.
endif.

You might also like