abap notes

38
Data Declaration in SAP ABAP Programming Declare single value variable:Variable can be declared by two ways, first by declaring based on data type, second by declared it refer to table field. Data d_data1 TYPE type. " berdasarkan type data Data d_data2 LIKE customer-customerno. " refer ke field tertentu Data types: C (character) N (numeric) D (date) T (Time) X (byte / hexadecimal) I (integer) P (packed number) F (floating point number) Internal TableInternal tables provide a means of taking data from a fixed structure and storing it in working memory in ABAP. The data is stored line by line in memory, and each line has the same structure. In ABAP, internal tables fulfill the function of arrays. DATA: BEGIN OF t_report OCCURS 10, field1 LIKE customer-customerno, field2 TYPE I, field3(20) TYPE C, END OF t_report. In above example, we define internal table contatin 3 fields, field-1 refer to field customer-customerno, field-2 type Integer, field-3 type character with field length 10 character. OCCURS 10 means that it reserve 10 line of memory at initialization, in run time memory will expand automatically when data exceed the limit.

Upload: deepflm

Post on 08-Nov-2014

57 views

Category:

Documents


7 download

DESCRIPTION

Abap Notes

TRANSCRIPT

Page 1: Abap Notes

Data Declaration in SAP ABAP Programming

Declare single value variable:Variable can be declared by two ways, first by declaring based on

data type, second by declared it refer to table field.

Data d_data1 TYPE type. " berdasarkan type dataData d_data2 LIKE customer-customerno. " refer ke field tertentu

Data types:C (character)N (numeric)D (date)T (Time)X (byte / hexadecimal)I (integer)P (packed number)F (floating point number)

Internal TableInternal tables provide a means of taking data from a fixed structure and storing it in working memory in ABAP. The data is stored line by line in memory, and each line has the same structure. In ABAP, internal tables fulfill the function of arrays.DATA: BEGIN OF t_report OCCURS 10,field1 LIKE customer-customerno,field2 TYPE I,field3(20) TYPE C,END OF t_report.

In above example, we define internal table contatin 3 fields, field-1 refer to field customer-customerno, field-2 type Integer, field-3 type character with field length 10 character. OCCURS 10 means that it reserve 10 line of memory at initialization, in run time memory will expand automatically when data exceed the limit.

My First SAP ABAP Programme

my first ABAP program

No, it's not a "hello world" program ;p

One of main job of an ABAPer is create ABAP report.

Page 2: Abap Notes

Report content 4 basic component.

1. Data declaration .

2. Selection screen.

3. Select Data.

4. Write Report.

I assume you already familiar with data dictionary. For an example, we have a table "SFLIGHT",

with following fields:

1. CARRID (Airline carrier ID)

2. CONNID (Flight connection Id)

3. FLDATE (Flight date).

4.SEATSMAX (Maximum capacity).

We wan to create a report that can be filtered based on Airline carrier ID and Flight connection

Id.

Go to transaction code SE38 (SAP Menu->Tools>ABAP Workbench->Development->ABAP

Editor), enter program name with prefix Z, for example ZTEST0001, then choose "Create"

button.

Then, enter title for program, and choose 1 "Executable Program" for program type. If screen

input for development class appear, click "Local Object".

Then, go to following steps.

Page 3: Abap Notes

1. Data declaration

TABLES: sflight.

DATA: BEGIN OF t_report OCCURS 3,carrid LIKE sflight-carrid,connid LIKE sflight-connid,fldate LIKE sflight-fldate,seatsmax LIKE sflight-seatsmax,END OF t_report.

2. Selection screen

SELECT-OPTIONS s_carrid FOR sflight-carrid.SELECT-OPTIONS s_connid FOR sflight-connid.

It will generate selection screen like picture below.

3. Select data

SELECT * FROM sflightWHERE carrid IN s_carrid ANDconnid IN s_connid.t_report-carrid = sflight-carrid.t_report-connid = sflight-connid.t_report-fldate = sflight-fldate.t_report-seatsmax = sflight-seatsmax.APPEND t_report.ENDSELECT.IF sy-subrc NE 0. "sy-subrc = return codeWRITE 'Data not found'.ENDIF.

Page 4: Abap Notes

4. Write data

LOOP AT t_report.skip. "comment:Go to next lineWRITE t_report-carrid.WRITE t_report-connid.WRITE t_report-fldate.WRITE t_report-seatsmax.ENDLOOP.

The result :

Here is the complete program:

REPORT ZTEST0001 .*Data Declarationtables: sflight.

DATA: BEGIN OF t_report OCCURS 3,carrid LIKE sflight-carrid,connid LIKE sflight-connid,fldate LIKE sflight-fldate,seatsmax LIKE sflight-seatsmax,END OF t_report.

*Selection ScreenSELECT-OPTIONS s_carrid FOR sflight-carrid.

Page 5: Abap Notes

SELECT-OPTIONS s_connid FOR sflight-connid.

*Get DataSELECT * FROM sflightWHERE carrid IN s_carrid ANDconnid IN s_connid.t_report-carrid = sflight-carrid.t_report-connid = sflight-connid.t_report-fldate = sflight-fldate.t_report-seatsmax = sflight-seatsmax.APPEND t_report.ENDSELECT.IF sy-subrc NE 0.WRITE 'Data not found'.ENDIF.

*Write DataLOOP AT t_report.skip. "comment:Go to next lineWRITE t_report-carrid.WRITE t_report-connid.WRITE t_report-fldate.WRITE t_report-seatsmax.ENDLOOP.

SAP ABAP Data Dictionary Tutorial

1

in Share

email

Digg Digg

A data dictionary is a central source of information for the data in a information management system. Its main function is to support the creation and management of data definitions (or “metadata”).

What is Data dictionary used for ?

Management of data definitions Provision of information for evaluations

Support for software development

Page 6: Abap Notes

Support for documentation

Ensuring that data definitions are flexible and up-to-date

Objects in the ABAP Dictionary resided on three levels that support their re-usability. These levels are:

1. Tables and structures2. Data elements

3. Domains

Lets look into them in detail -

Domains Describes the technical characteristics of a table field Specifies a value range which describes allowed data values for the fields

Fields referring to the same domain (via the data elements assigned to them) are changed when a change is made to the domain

Ensures consistency

Ex. Purchasing document number (EBELN)

Page 7: Abap Notes

Data Elements Describes the role played by a field in a technical context Fields of same semantic meaning can refer to the same data element

Contains the field information

Ex. Purchasing document number (EBELN)

Tables Represent the Database Tables where data actually resides. Tables can be defined independently of the database in the ABAP Dictionary.

The fields of the table are defined with their (database-independent) SAP ABAP data types and lengths.

Page 8: Abap Notes

Structures Are record declarations that do NOT correspond to a Database Table. Just like user-defined data type.

Defined like a table and can then be addressed from ABAP programs.

Structures contain data only during the runtime of a program.

Aggregated Objects of ABAP DictionaryAggregated means consisting of several components. In the ABAP Dictionary, aggregated objects are objects which come from several different transparent tables.

1. Views2. Search Help

3. Lock Objects

Lets look into them in detail

Page 9: Abap Notes

Views Views in SAP _ ABAP are used to summarize data which is distributed among several tables The data of a view is not actually physically stored. The data of a view is instead derived from

one or more other tables

It is tailored to the needs of a specific application

Search Help A Search help is a tool to help you search for data records in the system An efficient and user-friendly search assists users where the key of a record is unknown

Lock Objects Simultaneous accessing of the same data record by two users in the SAP system is synchronized

by a lock mechanism. Locks are set and released by calling certain function modules. These function modules are

generated automatically from the definition of so-called lock objects in the ABAP/4 Dictionary

Page 10: Abap Notes

Function modules :Enqueue_<obj name> – to lock the table

dequeue_<obj name> – to release the lock

Important Transactions

SE11 : Data Dictionary Initial Screen (SE12 Display only) SE13 : ABAP Dictionary : Technical Settings

SE14 : Database Utility

SE15 : Repository Information System

SE16 : Data Browser

SE17 : General table Display

SE55 : Table View Maintenance

SM30: Table Maintenance

==================================================================================

Data Types in ABAP Data Dictionary

Data Types in the ABAP Dictionary  

The ABAP Dictionary allows you to define global data types. You can use the TYPE addition of

an appropriate ABAP statement to refer to these data types in any ABAP program.

Page 11: Abap Notes

You define these data types using the  ABAP Dictionary. The following input fields are relevant to data types:

There are three groups on the initial screen:

Database Tables and Views

One of the most important tasks of the  ABAP Dictionary is to administer database tables in the central database of the SAP system.. The Dictionary contains meta-descriptions of the database tables, and uses these to create the physical tables in the database. A view is a "virtual table" containing fields from one or more tables.

In the description of a database table, the table lines consist of single fields or columns. An elementary data type must be assigned to each column. The elementary types in the ABAP

Page 12: Abap Notes

Dictionary are data elements. Like data objects in ABAP programs, database tables and views have data types as attributes. A line of a database table or view has the data type of a flat 

structure, which consists of individual data elements.

In ABAP programs, you can use the TYPE addition with the data type of a database table or

view. You may refer to the whole structure or to individual components:

... TYPE dbtab ...

refers to the complex data type of the structure,

... TYPE dbtab-comp ...

refers to the elementary data type of component comp.

If you define a complex data type type as a structure using

TYPES type TYPE dbtab.

the components of the data type type inherit the names of the components of the database

table or view, and can be addressed in the program using type-comp .

To ensure compatibility with previous releases, you can still use the LIKE addition to refer to

database tables or views, except within classes. The reason for this is that in earlier releases, the physical presence of the database tables as objects was emphasized, even though the Dictionary only contains meta-descriptions and data types.

Defining program-local data types by referring to database tables and views is one of the essential techniques for processing data from database tables in ABAP. Data objects that you define in this way always have the right type to contain data from the corresponding database table. ABAP Open SQL allows you to read a single field, a range of fields, or an entire database table or view into an internal table.

Page 13: Abap Notes

TYPES: city       TYPE spfli-cityfrom,       spfli_type TYPE STANDARD TABLE OF spfli WITH DEFAULT KEY.

DATA: wa_city  TYPE city,      wa_spfli TYPE spfli_type.

...

SELECT SINGLE cityfrom FROM spfli                       INTO wa_city                       WHERE carrid = 'LH' AND connid = '400'.

...

SELECT * FROM spfli INTO TABLE wa_spfli.

...

This example defines an elementary data type city that refers to a single field of the database

table SPFLI and an internal table spfli_type, whose line type is the same as the structure of

the database table. The SELECTstatement reads data from the database into the corresponding

data objects.

Data TypesData types are the actual type definitions in the ABAP Dictionary. They allow you to define elementary types, reference types, and complex types that are visible globally in the system. The data types of database tables are a subset of all possible types, namely flat structures. Global object types (classes and interfaces) are not stored in the ABAP Dictionary, but in the class library. You create them using the Class Builder.

For a detailed description of data types and their definitions, refer to the  Types section of the ABAP Dictionary documentation. The following descriptions mention the types only briefly, along with how you can refer to them from ABAP programs.

Data ElementsData elements in the ABAP Dictionary describe individual fields. They are the smallest indivisible units of the complex types described below, and are used to specify the types of columns in the database. Data elements can be elementary types or reference types.

Elementary Types

Page 14: Abap Notes

Elementary types are part of the dual-level domain concept for fields in the ABAP Dictionary. The elementary type has semantic attributes, such as texts, value tables, and documentation, and has a data type. There are two different ways to specify a data type:

By directly assigning an ABAP Dictionary type.

You can assign a predefined ABAP Dictionary type and a number of characters to an elementary type. The ABAP Dictionary has considerably more predefined types than the ABAP programming language. The number of characters here is not the field length in bytes, but the number of valid characters excluding formatting characters. The data types are different because the predefined data types in the ABAP Dictionary have to be compatible with the external data types of the database tables supported by the SAP Web AS ABAP.

When you refer to data types from the ABAP Dictionary in an ABAP program, the predefined Dictionary types are converted to ABAP types as follows:

Dictionary type

Meaning Maximum length n ABAP type

DEC Calculation/amount field 1-31, 1-17 in tables P((n+1)/2)

INT1 Single-byte integer 3 Internal only

INT2 Two-byte integer 5 Internal only

INT4 Four-byte integer 10 I

CURR Currency field 1-17 P((n+1)/2)

CUKY Currency key 5 C(5)

QUAN Quantity 1-17 P((n+1)/2)

UNIT Unit 2-3 C(n)

PREC Accuracy 16 Internal only

FLTP Floating point number 16 F(8)

NUMC Numeric text 1-255 N(n)

CHAR Character 1-255 C(n)

LCHR Long character 256-max C(n)

Page 15: Abap Notes

STRING String of variable length 1-max STRING

RAWSTRING Byte sequence of variable length

1-max XSTRING

DATS Date 8 D

ACCP Accounting period YYYYMM

6 N(6)

TIMS Time HHMMSS 6 T

RAW Byte sequence 1-255 X(n)

LRAW Long byte sequence 256-max X(n)

CLNT Client 3 C(3)

LANG Language internal 1, external 2 C(1)

("max" in LCHR and LRAW is the value of a preceding INT2 field. The "internal" length of a LANG field is in the Dictionary, the "external" length refers to the display on the screen.

Assigning a domain

The technical attributes are inherited from a domain. Domains are standalone Repository objects in the ABAP Dictionary. They can specify the technical attributes of a data element. One domain can be used by any number of data elements. When you create a domain, you must specify a Dictionary data type (see above table) and the number of characters.

Reference Types

Reference types describe single fields that can contain references to global classes and interfaces from the ABAP class library.

In an ABAP program, you can use the TYPE addition to refer directly to a data element. The

predefined Dictionary data types of the domain are then converted into the corresponding ABAP types.

If you define a local data type in a program by referring to a data element as follows:

TYPES dtype TYPE data_element.

Page 16: Abap Notes

the semantic attributes of the data element are inherited and will be used, for example, when you display a data object with type dtype on the screen. Since all data types in the ABAP

Dictionary are based on data elements, they all contain the corresponding semantic attributes.

TYPES company TYPE s_carr_id.

DATA wa_company TYPE company.

wa_company = 'UA '.

WRITE: 'Company:', wa_company.

This example defines a local type company that refers to the data element S_CARR_ID. The

data element is linked to the identically-named domain S_CARR_ID. The domain defines the technical attributes as data type CHAR with length 3.  The local data type COMPANY in the

program therefore has the ABAP type c(3). COMPANY also adopts the semantic attributes of

the data element. In the above example, we declare a data object wa_company with this type

and display it on a list. If the user chooses F1 help for the output field, the help text stored in the ABAP Dictionary will appear in a dialog box.

StructuresA structure is a sequence of any other data types from the ABAP Dictionary, that is, data elements, structures, table types, or database tables. When you create a structure in the ABAP Dictionary, each component must have a name and a data type.

Page 17: Abap Notes

In an ABAP program, you can use the TYPEaddition to refer directly to a structure.

If you define a local data type in a program by referring to a structure as follows:

TYPES dtype TYPE structure.

the construction blueprint of the structure is used to create a local structure 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 structure in the program. The components of the local structure dtype have the same names as those of the structure in the

ABAP Dictionary.

To ensure compatibility with previous releases, it is still possible to use the LIKE addition in an

ABAP program to refer to a structure in the ABAP Dictionary (except in classes).

Suppose the structure STRUCT is defined as follows in the ABAP Dictionary:

Field name Type name Short Description

COL1 CHAR01 Character field with length 1

COL2 CHAR08 Character field with length 8

COL3 CHAR10 Character field with length 10

The types CHAR01 to CHAR10 are data elements with corresponding domains. We can refer to this structure in ABAP:

TYPES struct_type TYPE struct.

DATA wa TYPE struct_type.

wa-col1 = '1'.wa-col2 = '12345678'.wa-col3 = '1234567890'.

This program creates a local structure in the program - struct_type  - and a corresponding

data object wa. We can address the components using the component names from the original

structure.

Page 18: Abap Notes

Table typesTable 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 TYPEaddition 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.

Suppose the table type STRUCT_TABLE is defined in the Dictionary with the line type STRUCT from the previous example. We can refer to this in ABAP:

TYPES table_type TYPE struct_table.

DATA: table_wa TYPE table_type,      line_wa  LIKE LINE OF table_wa.

...

LOOP AT table_wa INTO line_wa.  ...  WRITE: line_wa-col1, line_wa-col1, line_wa-col1.  ...ENDLOOP.

This program defines an internal table type table_type . From it, we define data

objects table_wa and, consequently, line_wa. line_wa corresponds to the line type of the

table type in the Dictionary, and is therefore compatible with the structure STRUCT

Page 19: Abap Notes

Type GroupsBefore Release 4.5A, it was not possible to define standalone types in the ABAP Dictionary to which you could refer using a TYPEaddition in an ABAP program. It was only possible to refer to

flat structures. Structures in programs corresponded to the structures of database tables or structures in the ABAP Dictionary. In ABAP programs, you could only refer to database tables and structures in the ABAP Dictionary using LIKE. It was, however, possible to refer to

individual components of the Dictionary type. Complex local data types such as internal tables or deep structures had no equivalent in the ABAP Dictionary. The solution to this from Release 3.0 onwards was to use 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 TYPESstatements.

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.

Note:

As of release 6.40, you can also define data types and constants in the public visibility area of global classes, by which type groups can be completely replaced.

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

Page 20: Abap Notes

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.

ABAP Dictionary Interview Questions

Q. What’s the full form of ECC?

Ans: Enterprice Central Component.

Q. What’s the full form of IDES?

Ans: Internet Demonstration and Evaluation System.

Q. What’s ABAP dictionary and its role in SAP?

Page 21: Abap Notes

Ans: ABAP dictionary is the central information base for the developers. This manages all

definitions(metadata) required for different applications in SAP. ABAP dictionary is completely integrated into

ABAP development workbench. All other component of ABAP development workbench can access the data

definitions(meta data) stored in the data dictionary.

Role: ABAP data dictionary supports

definition of user-defined types (data elements, structures, table types). structure of database objects (tables, indexes and views) can also be defined.

These user-defined types/objects are then automatically created in the underlying relational database using the above data definitions.

The ABAP dictionary also provides tools for editing screen fields (e.g., for assigning a field an input help i.e. F4 help).

Data dictionary ensures data integrity, consistency and security.

Q. What are the main object types of ABAP dictionary?

Ans: The object types of ABAP dictionary can be of following type:

Tables : Tables are defined in the ABAP Dictionary independently of the database.A table having the same structure is then created from this table definition in the underlying database.

Views : are logical views on more than one table. The structure of the view is defined in the ABAP Dictionary. A view on the database can then be created from this structure.

Types   (elements, structures, table types) : Types are created in ABAP programs. The structure of a type can be defined globally in ABAP programs. Changes to a type automatically take effect in all the programs using the type.

Lock objects :are used to synchronize access to the same data by more than one user. Function modules that can be used in application programs are generated from the definition of a lock object in the ABAP Dictionary.

Domains : Different fields having the same technical type can be combined in domains. Domain defines the value range of all table fields and structure components that refer to this domain.

Data element : The ABAP Dictionary also contains the information displayed with the F1 and F4 help for a field in an input template. The documentation about the field is created for a data element.

Input help : The list of possible input values that appears for the input help is created by a foreign key or a search help.

Q. Note on SAP tables(defining through ABAP dictionary).Ans: Tables are defined independently of the

database in ABAP dictionary. The fields of the table are defined with their (Database-independent) data types

and lengths. Using the table definitions stored in the ABAP dictionary, a table is automatically created in the

physical database(when the table is activated).

Q. What are the components of a table definition.

Ans:

Table fields : For table fields, field names and data types are defined. Foreign keys:  Relationship between the table and the other tables are defined.

Page 22: Abap Notes

Technical settings : Data class and size category defines that what type of tableto be created and how much space required.

Indexes : Secondary indexes are created for a table for faster data selection.

Again following are defined for a table fields:

Field name  can be of maximum 16 characters in a table and must start with a letter. Key flag  determines if a field should be the table key. Field type  depicts the data type of the field in the ABAP dictionary. Field length  denotes the number of valid places in the field. Decimal places  Number of places after decimal point for float type value. Short text  describes the business meaning of the field.

Also fields from other structures can be added to the table definition as include.

Q. How data Type, field Length and short Text of any field is assigned?

Ans: i. Data type, field length (and if necessary decimal places) short text can be directly assigned to a field in

the table definition.

ii. Data element can be assigned to a field so that data type, field length (and decimal places) are automatically

determined from the domain of the data element. The short description of the data element is then assigned to

the field as a short text.

Q. What are the assignment options to the field?

Ans: i. Direct assignment of data types, field length, short text to a field.

ii. Data element assignment to a field.

iii. An input check(check table) for a field can be defined with a foreign key.

iv. A search help can be assigned to a field.

v. Reference field or reference table must be specified for a table field that holds currency or quantity type

value.

Q. What’s reference table and reference field?

Ans: Reference table is specified for fields containing quantities(data type QUAN) or currency(Data type

CURR). This reference table must contain a field with the format for the currency key (data type CUKY) or

unit of measure (data type UNIT). This field is called the reference field of the output field. The reference field

can also reside in the table itself.

E.g.: TAB1 contains the field PRICE which holds price values. Field UNIT contains currency key for PRICE.

So,TAB1 is the reference table for field PRICE and UNIT is the reference field for field PRICE. 

Page 23: Abap Notes

Q. What’s table include?

Ans: In addition to listing the individual fields in a table or structure, fields from another structure can be

included as includes.

Q. What’s named include?

Ans: If an include is added to define a database table or database structure, a name can be assigned to that

included (included substructure). The group of fields of that include can be addressed as a whole in ABAP

application programs with a group name which is called as named include.

E.g.:We can access field of a table/ structure in the ABAP application program in the following manner:

1. <TABLE / STRUCTURE NAME > - < FIELD NAME>2. <TABLE / STRUCTURE NAME > - <GROUP NAME>-<FIELD NAME>3. <TABLE / STRUCTURE NAME > - <GROUP NAME>

Q. Give an example of nested include.Ans: Structure S1 may include structure S2 and again S2 may include

S3.

Q.What’s the maximum depth of nested includes in a table?

Ans: Maximum depth is 9 i.e. maximum 9 structures can be included in a table/structure.

Q. What’s the number of characters limit for field name?

Ans: A field name may not have more than 16 characters in a table, but in a structure maximum 30 characters

are allowed for a field name.

Q. What are foreign keys?

Ans: Relationships between tables are defined in the ABAP dictionary by creating foreign keys.

Q. Whare are the uses of foreign keys in SAP?

Ans:

Using foreign keys(as main table-field is linked with check table), input value check for any input field can be done.

Foreign keys can also be used to link several tables.Explaination on foreign keys:Suppose, tab1(Foreign key table or dependent table) contains the following fields: fld1(primary key), fld2, fld3, fld4, fld5 and Tab2(Referenced table) contains the following fields: fld6(primary key), fld7(primary key), fld8, fld9 and tab1-fld2 is connected to tab2-fld5, tab1-fld4 is connected to tab2-fld6Therefore, fld2 and fld4 fields of the table tab1 are called as foreign key fields to the table tab2 and tab2 is called as check table or referenced table.

Q. What are foreign key fields?

Page 24: Abap Notes

Ans: One field of the foreign key table corresponds to each key field of the check table. That field of the is

called as foreign key field.

Uses: A foreign key permits assigning data records in the foreign key table and check table. One record of the

foreign key table uniquely identifies a record of the check table (using the value entries in the foreign key

fields of the foreign key table).

Q. What’s check table?

Ans: Check table is maintained at field level for data validation.

Q. What’s check field?

Ans: One of the foreign key field is marked as the check field. This depicts that the foreign key relationship is

maintained for that field. When a value is entered for that check field in the table, input validation checking is

done i.e. a checking is done that whether the inserted value exists in the check table or not. If doesn’t exist then

system rejects the entry else input validation check for that field is successful.

Q. What’s generic and constant foreign keys?

Q. What’s cardinality?

Q. What are the types of foreign key fields?

Q. What are text table?

Q. What is ‘technical settings’ of a table?What are the important parameters to be mentioned within it?

Q. What’s data class?

Ans: Data class is that which allows the table to get automatically assigned under specific tablespace/dbspace

during table creation in the SAP database i.e. dataclass determines that under which table space/dbspace the

table will be stored.

Q. How many types of data classes are there in SAP?

Data classes are mainly of three types(for application tables):

i.Choose APPL0(master data) for data that is frequently accessed but rarely updated/changed.

ii.Choose APPL1(transaction data) for data that is frequently changed.

iii.Choose APPL2(organizational data) for customizing data that is defined/entered

during system installation and rarely changed.

Page 25: Abap Notes

The other two types of data classes are:USR and USR1(for customer’s own development purpose).

Q. What’s size category?

Ans: The Size category is used to defined the space requirement for the table in the database.

Q. How many types of size category are there in SAP?

Ans: There are five size categories. Size category from 0 to 4 can be choosen for the tables. A certain fixed

memory size is assigned to each category in the SAP database.

Q. What’s the utility of size category?

Ans: During table creation, the SAP system reserves an initial space i.e. an initial extent) in the database.If in

any case more space is needed, then additional memory is added according to the mentioned size category for

that table. correct size category prevents the creation of a large number of small extents for a table i.e. prevents

memory wastage.

Q. What’s buffering?

Q. How buffers are filled up?

Q. What are the different buffering types?

Q. What are the different buffering permissions?

Q. How database tables are buffered?

Q. What’s logging?

Q. How many tables are there in SAP?

Ans: i. Transparent tables, ii. Pool tables, iii. Cluster tables.

Q. What is transparent table?

Ans: The tables which create 1-to-1 correspondence between the table definition in the ABAP data dictionary

and the table definition in the physical database are called as transparent tables in SAP.

Q. Give examples of transparent table.

Ans: VBAK, VBAP, KNA1 etc.

Q. What is table pool?

Page 26: Abap Notes

Ans: Table pool is a table in the SAP database in which many pool tables are assigned.

Q. What are pool tables?

Ans: Tables assigned to a table pool are called as pool tables.

Q. What are table clusters?

Ans: Table cluster is a table in the SAP database in which many cluster tables are stored.

Q. What are clustered tables?

Ans: Tables assigned to a Table cluster are called as clustered tables.

Q. Uses of table pool or table cluster.

Ans: Table pool or table cluster is used to store SAP’s internal control information (screen sequences, program

parameters, temporary data, continuous texts such as documentation).

Q. Example of table cluster and cluster tables.

Ans: i. The table cluster RFBLG holds data for five transparent tables i.e. BSEC, BSED, BSEG, BSES and

BSET.

ii. Other examples of table clusters are CDCLS, CDHDR, RFBLG, DOKCLU, DOKTL .

Q. What are the differences between transparent and cluster/pool tables?

Ans: i. A transparent table has 1-to-1 cardinality between the table definition in the data dictionary and in the

table definition of sap database whereas cluster/pool tables have many-to-1 cardinality between the table

definition in the data dictionary and in the table definition of sap database.

ii. Transparent tables are accessible both by Open and native SQL statements whereas table pool/cluster tables

are accessible only by open SQL but never by native SQL.

iii. Transparent tables can store table relevant data whereas table pool or cluster tables can store only system

data/ application data based on the transparent tables.

Q. What are tabs under the maintenance screen of the ABAP data dictionary screen?

Ans: There are five tabs under ABAP dictionary.

i.Attributes,

ii.Delivery & maintenance,

Page 27: Abap Notes

iii. Fields,

iv. Entry help/check,

v. Currency/Quantity fields.

Q. What is delivery class?

Ans: We need to insert an delivery class value while creating customized table in SAP through the transaction

code SE11. Delivery class is that which regulates the transport of the table’s data records (during SAP

installations, SAP software upgrade, client copies, and data transport to other SAP system). SAP and its

customers have different write types depending on the variety of delivery class. If Delivery class is A, it

depicts that the application table for master and transaction data changes only rarely.

Q. How many types of delivery classes are there in SAP?

Ans: There are following delivery classes:

i. A: Application table (master and transaction data) is maintained by the customers

using application transaction.

ii. C: Customer table. Data is maintained only by the customer.

iii. L: Table for storing temporary data.

iv. G: Customer table, new data records can be inserted but may not overwrite or delete existing ones.

v. E: System table with its own namespaces for customer entries.

vi. S: System table, data changes have the status of program changes i.e. System table

for program’s nature. Maintained only by SAP. E.g.: Codes for SAP transactions.

vii. W: System table for system operation and maintenance. Table contents are maintained by

maintenance transactions. E.g.: function module table.

Q. What are the differences between domain and data element?

Ans: i.Domain depicts the technical attributes of a field (its data type, field length, no. of decimal places,

appreance on the sreen) of a SAP database table. Whereas data element denotes the semantic attributes(short

description, label names) for a field.

ii.Data elements are directly attaced to the fields of SAP database tables and each data element has an

underlying domain within it. Whereas domains are not directly attached to the fields and a single domain can

be under many data elements.

Page 28: Abap Notes

iii.Within domain value range of a field can be described. Whereas within the data element parameter id and

search help for a particular field can be assigned.

Q. What’s value table?

Ans: Value table is maintained at domain level in SAP. During domain creation, value range of the domain is

defined by specifying value table. Suppose for a particular domain, its value table holds the values ‘A’, ‘B’,

‘Z’. So whenever the domain will be used, system will allow to use these values only.

=================================================================

What is SAP ABAP Data Dictionary ?

What is ABAP Data Dictionary ?

Purpose

Data definitions (metadata) are created and managed in the ABAP Dictionary. The ABAP Dictionary permits a central description of all the data used in the system without redundancies. New or modified information is automatically provided for all the system components. This ensures data integrity, data consistency and data security.

You can create the corresponding objects (tables or views) in the underlying relational database using these data definitions. The ABAP Dictionary therefore describes the logical structure of the objects used in application development and shows how they are mapped to the underlying relational database in tables or views.

The ABAP Dictionary also provides standard functions for editing fields on the screen, for example for assigning a screen field an input help.

What Information is Stored in the ABAP Dictionary?

The most important object types in the ABAP Dictionary are tables, views, types, domains, search helps and lock objects.

Page 29: Abap Notes

Tables are defined in the ABAP Dictionary independently of the database. A table having the same structure is then created from this table definition in the underlying database.

Views are logical views on more than one table. The structure of the view is defined in the ABAP Dictionary. A view on the database can then be created from this structure.

Types are used in ABAP programs. The structure of a type can be defined globally in ABAP programs. Changes to a type automatically take effect in all the programs using the type.

Lock objects are used to synchronize access to the same data by more than one user. Function modules that can be used in application programs are generated from the definition of a lock object in the ABAP Dictionary.

Different fields having the same technical type can be combined in domains. A domain defines the value range of all table fields and structure components that refer to this domain.

The ABAP Dictionary also contains the information displayed with the F1 and F4 help for a field in an input template. The documentation about the field is created for a data element that describes the meaning of the contents of a table field. The list of possible input values that appears for the input help is created by a foreign key or a search help.

Integration in the ABAP Workbench

The ABAP Dictionary is completely integrated in the ABAP Workbench. The R/3 System works interpretatively, permitting the ABAP Dictionary to be actively integrated in the development environment. Instead of the original objects, the interpreters see only internal representations of these objects.

These internal representations are adjusted automatically when the system finds that changes have been made in the ABAP Dictionary. This ensures that the screen and ABAP interpreters, input help, database interface, and development tools always access current data.

The following ABAP program lists the airline carriers (see Flight model) and carrier IDs contained in table SCARR.

Page 30: Abap Notes

DATA: SCARR_TAB TYPE SCARR.SELECT * INTO SCARR_TAB FROM SCARR.WRITE: / SCARR_TAB-CARRID, SCARR_TAB-CARRNAME.ENDSELECT.

Only structure SCARR_TAB is declared in the program. All the information about this structure, such as the field names, data types and field lengths, are copied from table SCARR, which is defined in the ABAP Dictionary. This information about table SCARR is called from the ABAP Dictionary when the program is generated.

This means that the source text of the program need not be adjusted when a change is made to table SCARR, for example when the length of a table field is changed. The next time the program is called, the system automatically determines that the structure of table SCARR has changed. The program is simply regenerated, thereby retrieving up-to-date information about table SCARR from the ABAP Dictionary.

When you work on development projects, objects of the ABAP Dictionary can be changed any number of times before being activated and made available to the operative components of the system. Objects can have both an active and an inactive version in the ABAP Dictionary at the same time.

Inactive ABAP Dictionary objects have no effect on the runtime system (ABAP processor, database interface). This permits greater changes to several objects without

Page 31: Abap Notes

impairing the executability of the system. The objects can only be activated together when they have all been changed.