sap abap support by bob panic

210
Introduction to SAP ABAP Development by Bob Panic www.rockstarconsultinggroup.com 1

Upload: bob-panic

Post on 15-Jul-2015

276 views

Category:

Technology


1 download

TRANSCRIPT

Introduction to SAP ABAP Development by Bob PanicIntroduction to ERP (Enterprise resource planning)

There are many different systems in a large company's including planning, manufacturing, distribution, shipping, and accounting.

Enterprise resource planning (ERP) is a system that integrates all of these functions into a single system, designed to serve the needs of each different department within the enterprise. ERP is more of a methodology than a piece of software, although it does incorporate several software applications, brought together under a single, integrated interface.

Enterprise resource planning (ERP) systems integrate primary business applications; all the applications in an ERP suite share a common set of data that is stored in a central database. A typical ERP system provides applications for accounting and controlling, production and materials management, quality management, plant maintenance, sales and distribution, human resources, and project management.

Why should you be interested? Because, basically, a well-implemented and appropriate ERP system can create significant efficiencies across your business, resulting in timely business information, better customer relationships, a more cost-effective supply chain, improved internal process and, ultimately, increased profitability.

The ERP system goes far beyond being just a simple piece of software. Each implementation is unique and is designed to correspond to the implementer's various business processes. Regardless of how a company approaches it, ERP is sure to bring significant changes to how a company does business. An ERP implementation can cost millions of dollars to create, and may take several years to complete.

Once implemented however, the ERP system brings tremendous advantages. Because all systems are joined together, all departments can more easily share information. The workflow that takes place between departments can become much more automated, and ultimately, customers are better served because the individual using the customer-facing applications will have access to every bit of information regarding each relevant process. For example, someone in sales would easily be able to log into a single system to determine the status of a customer order that is still in manufacturing. All this comes at a cost though; training costs are high because employees must not only learn how to use new software, they must also learn new processes.

ERP Improves Productivity

Before ERP systems, each department in an organization would most likely have their own computer system, data and database. Unfortunately, many of these systems would not be able to communicate with one another or need to store or rewrite data to make it possible for cross computer system communication. For instance, the financials of a company were on a separate computer system than the HR system, making it more intensive and complicated to process certain functions.

Once an ERP system is in place, usually all aspects of an organization can work in harmony instead of every single system needing to be compatible with each other. For large organizations, increased productivity and less types of software are a result.

Implementing Enterprise Resource PlanningERP software is complex and expensive. Companies must devote significant human resources to ERP projects and often hire consultants or systems integrators to help implement the systems. As a result, the company can spend millions of dollars and several years on ERP projects. This report outlines the challenges companies should expect for ERP implementation and outlines the six main steps of an ERP project:

Vendor Selection

Business Strategy Formation

Application Configuration

Testing and End-user Acceptance

Training

Rollout

Benefits of implementing ERP systems:

Inventory Reduction

Improved Cash Management

Increased Revenue and Profits

Reduced Transportation and Logistics Costs

Reduced Information Technology (IT) Costs

Intangible benefits include unanticipated cost reductions, improved responsiveness to customers, more flexibility, and more effective management of the supply chain.

Advantages of ERP Systems

There are many advantages of implementing an EPR system; here are a few of them:

A totally integrated system

The ability to streamline different processes and workflows

The ability to easily share data across various departments in an organization

Improved efficiency and productivity levels

Better tracking and forecasting

Lower costs

Improved customer service

Disadvantages of ERP Systems

While advantages usually outweigh disadvantages for most organizations implementing an ERP system, here are some of the most common obstacles experienced:

Usually many obstacles can be prevented if adequate investment is made and adequate training is involved, however, success does depend on skills and the experience of the workforce to quickly adapt to the new system.

Customization in many situations is limited

The need to reengineer business processes

ERP systems can be cost prohibitive to install and run

Technical support can be shoddy

ERP's may be too rigid for specific organizations that are either new or want to move in a new direction in the near future.

ERP software packages Available in the Market

Baan from Infor Global Solutions: The Baan Corporation provides the financial and administrative consulting services.

JD Edwards Enterprise One & JD Edwards World from Oracle: JD Edward is into accounting business software development and an ERP system JDE comprises 3 basic areas of expertise, functional-business, and programmer-developer and technical-CNC-system administration.

Oracle e-Business Suite from Oracle : Oracle is into finance applications and Oracle relational database management system technology

PeopleSoft from Oracle: PeopleSoft is into Human resource management systems (HRMS) applications

SAP R/3 from SAP: The most widely used modules in this ERP are Financials and Controlling (FICO), Human Resources (HR), Materials Management (MM), Sales & Distribution (SD), and Production Planning (PP) and its an integration around 25 modules. Its the biggest ERP package in the Market.

Many more ERP packages are available in the market.------Enterprise:-Organization or Business oriented company.Resource: - Man, Money, Machines and materials etc.Planning:-Plans to maximum utilization of resources with cost minimization.

The ultimate aim of using ERP is planning with the available resources of an enterprise to get the maximum output with cost minimization.------What is SAP

SAP was founded in 1972 by five former IBM engineers in Mannheim, Germany (Dietmar Hopp, Hasso Plattner, Klaus Tschira, Claus Wellenreuther and Hans-Werner Hector) and its headquarters in Walldorf Germany and since the 2005 annual general meeting the companys official name is just SAP AG.

The acronym of SAP is Systems, Applications and Products in Data Processing" SAP is the largest software company in Europe and the third largest in the world. It ranks after Microsoft and IBM in terms of market capitalization. SAP is also the largest business application and Enterprise Resource Planning (ERP) solution and software provider in terms of revenue.

Products

SAP's products focus on Enterprise resource planning (ERP), which it helped to pioneer. The company's main product is mySAP ERP. The name of its predecessor, SAP R/3 gives a clue to its functionality: the "R" stands for real-time data processing and the number 3 relates to a 3-tier architecture: database, application server and client (SAPgui). R/2, which ran on Mainframe architecture, was the first SAP version.

Other major product offerings include Advanced Planner and Optimizer (APO), Business Information Warehouse (BW), Customer Relationship Management (CRM), Supply Chain Management (SCM), Supplier Relationship Management (SRM), Human Resource Management Systems (HRMS), Product Lifecycle Management (PLM), Exchange Infrastructure (XI), Enterprise Portal (EP) and SAP Knowledge Warehouse (KW).The APO name has been retired and rolled into SCM. The BW name (Business Warehouse) has now been rolled into the SAP NetWeaver BI (Business Intelligence) suite and functions as the reporting modules.

The company also offers a new technology platform, named SAP NetWeaver. While its original products are typically used by Fortune 500 companies, SAP is now also actively targeting small and medium sized enterprises (SME) with its SAP Business One and SAP All-in-One.According to SAP AG there are over 100,800 SAP installations serving more than 38,000 companies. SAP products are used by over 12 million people in more than 120 countries.

1. The name SAP is acronym for Systems, Applications and Products in Data Processing. SAP is an extremely complicated system where no one individual can understand all of it.

2. SAP runs on a fourth generation programming language called Advance Business Application Programming (ABAP). It has many of the features of other modern programming languages such as the familiar C, Visual Basic, and Power Builder. Your programs name conventions begins with a letter yxxx or zxxx.

3. SAP graphical user interfaces (SAPGUI) runs on Windows / NT / Unix / AS400.

4. SAP is an enterprise resource planning (ERP) software product capable of integrating multiple business applications, with each application representing a specific business area. These applications update and process transactions in real time mode. It has the ability to be configured to meets the needs of the business.

SAP R/3 is a client/server based application, utilizing a 3-tiered model. A presentation layer, or client, interfaces with the user. The application layer houses all the business-specific logic, and the database layer records and stores all the information about the system, including transactional and configuration data.

SAP R/3 functionality is structured using its own proprietary language called ABAP (Advanced Business Application Programming). ABAP, or ABAP/4 is a fourth generation language (4GL), geared towards the creation of simple, yet powerful programs. R/3 also offers a complete development environment where developers can either modify existing SAP code to modify existing functionality or develop their own functions, whether reports or complete transactional systems within the SAP framework.

ABAP's main interaction with the database system is via Open SQL statements. These statements allow a developer to query, update, or delete information from the database. Advanced topics include GUI development and advanced integration with other systems. With the introduction of ABAP Objects, ABAP provides the opportunity to develop applications with object-oriented programming.

The most difficult part of SAP R/3 is its implementation, since SAP R/3 is never used the same way in any two places. For instance, Atlas Copco can have a different implementation of SAP R/3 from Procter & Gamble. Some companies may run multiple productive clients/systems or even multiple instances of SAP R/3. This is seen, for example, when a company running R/3 acquires a new business already running R/3. They may elect to keep both systems separate, migrate one into the other, or migrate both onto a completely new instance.

The system landscape is ultimately the customer's decision. There are definite pros and cons on the continuum from single global instance / productive client (master data, impact of configuration changes on multiple business units) to separate instances per business unit (hardware costs and communication between instances/clients)

Two primary issues are the root of the complexity and of the differences:

Customization configuration - Within R/3, there are tens of thousands of database tables that may be used to control how the application behaves. For instance, each company will have its own accounting "Chart of Accounts" which reflects how its transactions flow together to represent its activity. That will be specific to a given company. In general, the behavior (and appearance) of virtually every screen and transaction is controlled by configuration tables. This gives the implementer great power to make the application behave differently for different environments. With that power comes considerable complexity.

Extensions, Bolt-Ons - In any company, there will be a need to develop interface programs to communicate with other corporate information systems. This generally involves developing ABAP/4 code, and considerable "systems integration" effort to either determine what data is to be drawn out of R/3 or to interface into R/3 to load data into the system.

Due to the complexity of implementation, these companies recruit highly skilled SAP consultants to do the job. The implementation must consider the company's needs and resources. Some companies implement only a few modules of SAP while others may want numerous modules.

SAP has several layers. The Basis System (BC) includes the ABAP programming language, and is the heart (i.e. the base) of operations and should not be visible to higher level or managerial users. Other customizing and implementation tools exist also.

------Implementation Tools for ERP SystemsThere are multiple tools available to assist in the management of ERP implementation projects. SAP R/3, for example, provides an Implementation Roadmap that is broken up into five phases. Each phase includes documentation and planning tools to help the phase move towards completion. The five phases and their respective tasks include:

Project Preparation

Building of the project team.

Designing the system (This includes network, hardware, and software requirements).

Selecting ERP vendors.

Defining the projects scope.

Business Blueprint

In this phase project team members decide and document how the business and business processes will function with the implementation of the ERP system. These decisions will guide the configuration of the ERP.

Determination of methods to transfer or integrate legacy system information into the ERP system will also occur in this phase.

Realization

Configuration of the ERP system occurs in this phase. Configuration guidelines are based on documentation from the Business Blueprint phase.

Legacy system connections are developed in this phase.

Final Preparation

Testing of the new ERP system.

Development of the Help Desk and Help Desk Procedures.

Migration of existing data.

User training.

Schedule a Roll-Out date.

Roll-Out

ERP system becomes part of everyday activities.

Help Desk fields questions about ERP system.

Monitoring of the ERP system starts in this phase.

Monitoring of the ERP system starts in this phase.

The time required for each one of these phases differs from project to project based on the size of the implementation, dedication to the projectetc. Oftentimes the finished projects scope differs from the original scopes documentation causing projects to go overtime and over budget. When this happens, it is usually testing and training that get cut short which jeopardize the overall success of the project.

-----

Why SAP1. SAP is a platform independent; it can support various databases like Oracle, SQL Server.2. SAP also supports various operating systems.3. The integrity between its various modules makes SAP more users friendly.Areas of SAPThere are three areas in SAP.1. Functional Area There are more than 25 functional modules in SAP. Those who work on functional areas are called Functional Consultants. Ex: - PP Production planning MM- material management SD- Sales and Distribution FI- Financial Accounting CO- Controlling HR- human Resources PM- Plant Maintenance. Etc.

2. Technical Area Here the technical consultants i.e. ABAPers are working. Technical Consultants will implant the ideas of functional Consultants.

3. Basis Area Here the basis people will work. The following works are generally done here Creation users, Authorization, Dispatcher and Role Allocation

R/3 System Architecture

R/3 is an integrated group of applications designed to handle the data processing for large corporations. The purpose of an R/3 system is to provide tightly integrated large scale business applications.

The below figure shows the structure of R/3 Architecture. The architecture contains four layers as Presentation Servers, Application Servers, Database Servers and Database.

PS: - Presentation Servers

AS: - Application Servers

DBS: - Database Server

DB: - Database

Presentation Servers - The Presentation server is actually a SAPGUI or the user interface. The interface accepts input from the user in the form of keystrokes, mouse clicks and function keys, sends these requests to the application server to be processed. The application server sends the results back to the SAPGUI which then formats the output display to the user.Application Server The application server is a set of executables that collectively interpret the ABAP/4 programs and manage the input and output for them. When an application server is started, these executables all start at the same time. When an application server is stopped, they all shut down together. Each application server has a profile that specifies its characteristics when it starts up and while it is running. For example, an application severs profile specifies:

Number of processes and their types

Amount of memory each process may use

Length of time a user is inactive before being automatically logged off

The application server exists to interpret ABAP/4 programs, and they only run there-the programs do not run on the presentation server. If your ABAP/4 program requests information from the database, the application server will format the request and send it to the database server.

Database Server - The database server is a set of executables that accept database requests from the application server. These requests are passed on to the RDBMS (Relation Database Management System). The RDBMS sends the data back to the database server, which then passes the information back to the application server. The application server in turn passes that information to your ABAP/4 program and then you will get the required output on your presentation server.

Database Database is nothing but a collection of data arranged for ease and speed of search and retrieval OR A database is a structured collection of records or data that is stored in a computer system. Application Server Architecture

All requests that come in from presentation servers are directed first to the dispatcher. The dispatcher writes them first to the dispatcher queue. The dispatcher pulls the requests from the queue on a first-in, first-out basis. Each request is then allocated to the first available work process. A work process handles one request at a time.

To perform any processing for a user's request, a work process needs to address two special memory areas: the user context and the program roll area. The user context is a memory area that contains information about the user, and the roll area is a memory area that contains information about the programs execution. USER Context

A user context is contains information about the user like about user name, login id and which program is running currently.

Roll Area.

Its a memory allocated by the work process for an instance of a program It contains information about the recent program which is executing currently

Value of variables, Dynamic Memory Allocation and Pointers to work Process.

Instance: - The term instance means application server

The term central instance means database server

In general the term instance means server.

Roll In: - When a job is assigned to a work process it creates pointers to the user context and roll area this process is called Roll In.

Roll Out: - After the execution of the job the pointers assigned to both user context and roll area are deleted this process is called Roll Out.

Dialog Steps: - This is the time taken by the systems to show the next screen from existing screen is called as dialog step.

Work process

This is the area in which actual work is done. There are seven types of work process each handles a specific type request.

1. Dialog or Online Process- for Dialog request.

2. Update Process- Request to update data in database.

3. Background Process- Background jobs.

4. Spool Process- print spool request.

5. Enque Process Logical lock requests

6. Message Process- Routes messages between application server with in an R/3 system

7. Gateway Process- Funnels Messages into and out of the R/3 system.

Components of Work ProcessEach Work Process is composed of the following

1. A task handler

2. An ABAP/4 Interpreter

3. A screen Interpreter.

4. A Database Interface

All requests pass through the task handler, which then funnels the request to the appropriate part of the work process and the Interpreters Interpret the ABAP/4 code.

Messages (6 types)

1. S (Success): Green color status bar.

2. E (Error): Red color status bar.

3. W (Warning): Yellow color status bar.

4. I (Information): In a pop-up box.

5. A (Abort): In a pop-up box.

6. X (Exit): Comes out of the program

Three tier architecture of R/3

Database Server

Application Server

Presentation Server

(Unlike normal Client/server architecture where you have only two layers i.e., client and server.) Communication among the 3 tiers is accomplished by standard protocol services like TCP/IP or CPIC (Common Programming Interface Communication).

In above case database server stores the data centrally. Basically contains database engine and associated processes. The database layers contain the database system used by all servers.

Application server contains software components to run the program. It contains a SAP kernel, which can run ABAP/4 program.

The presentation server is your client through which you send your request to application server. It is also called as SAP graphical user interfaces known as SAPGUI and is available in windows 3.1, Windows NT, Windows 95, and Macintosh. They all look similar whatever underlying system they are running on.

The SAPGUI includes all graphical capabilities of window interface with menu bars, tool bars, focus property, and the entire mouse clicking operations.

The R/3 system is open system in the sense that it can run on any operating system or any database and any communication technology. It means that:

R/3 system can run on any operating system platform such as UNIX, NT, 95, AS/400.

It supports various RDBMS such as SQL server, Oracle, Informix, DB2.

Standard GUIs supported by R/3 are Windows 95, NT, Windows 3.1, and Macintosh.

SAP can use standard communication protocols TCP/IP, CPIC, OSF/DCE/DME for network.

Using SAPs Open SQL

ABAP/4 code is portable between databases. To access the database in an ABAP/4 program you will code SAPs open SQL. Open SQL is a subset and variation of ANSI SQL. The ABAP/4 Interpreter passes all open SQL statements to the database interface part of the work process. There they are converted to SQL i.e. native to the installed RDBMS. For example if you were running an Oracle database your ABAP/4 Open SQL would be converted by the database interface to Oracle SQL statements.

If you use Open SQL, your SQL statements will be passed to the database interface. Using Open SQL has three advantages. All of these advantages are implemented via database interface.

Advantages using Open SQL

1. Buffering Data on the Application Server.

The database interface buffers information from the database on the application server, when data is read from the database, it can be stored in buffers on the application server. If a request is then made to access the same records, they would already be on the application server and the request is satisfied from the buffer without having to go the database. This buffering technique reduces the load on the database server and on the network link between the database and application servers and can speed up database access time by a factor of 10 to 100 times.

2. Portability: - The SQL statements will be portable between databases. For example, if for some reason your company wanted to switch from an Oracle to an Informix database, it could change the database and your ABAP/4 code would continue to run without modification.

3. Automatic client handling:-With Open SQL the client field is automatically populated by the database interface. This gives your development and testing teams may advantages. Such as the ability to perform multiple simultaneous testing and training on a single database without interface from each other

WORKING WITH R/3 system

The SAP R/3 presentation interface behaves very similarly to any other typical window application and is also known as SAPGUI. The first screen that you come across in R/3 system is SAP logon screen.

SAP R/3 logon Screen

This is the first screen that appears when you use SAP logon utility. It has four fields: the client, the user, the password and the language.

Client: Here you enter the client number. The client is group of users who has similar rights. It can be group of users in a business entity or a whole business entity or a whole company. User: The name of the SAP user identification. Users of the SAP system are client-specific, which means that user belonging to one client is valid to only the particular client.

Password: It is the password that has been assigned by the system administrator.

Language: SAP R/3 system supports multinational language on the same system at the same time, which is very useful for multinational companies with different branches in several countries and possibly using different languages.

After entering all the fields press ENTER key and system will take you to MAIN MENU screen.

User might get different screens when he logs on, depending upon default settings of the user master record i.e., if user is DEVELOPER then the screen which he often works on is editor screen and he can go directly to this screen, if system administrator sets this screen for the user.

Main features of any R/3 window are as follows: R/3 standard window elements behave exactly the same, as any other standard window application would, like minimizing a screen, setting the active window etc.

From TOP to BOTTOM, R/3 window can contain typical elements such as check boxes, push buttons, input fields and following elements:

Menu bar is the first element of the every R/3 window. It contains the menu item corresponding to the particular R/3 application. The two menu options SYSTEM and HELP are always present in every R/3 window. SYSTEM menu option contains all utilities and functions, and is available to user at all the times. The HELP menu contains all the available options for the different types and methods of obtaining online help in the system.

Standard tool bar. The second R/3 window element is present in every R/3 window. It is nothing but a collection of icons, which perform common functions like saving the object, exit etc. The various icons on std. Tool bar are as follows (from left to right):

Application tool bar: The next part of the screen contains icons most commonly used in that particular task or transaction.

Status bar is the bottom line of the screen and usually shows errors or information messages to the user. It also includes other information such as system id, session number, client, server name and the response time.Logging Off

User can log off the R/3 system from any screen. There are three ways of logging off the R/3 system, which are as follows:

From the Menu bar choose SYSTEM ( LOG OFF. In this case, you get the log off dialog box, which informs the user that any data not saved will be lost if continuing with the log off procedure.

Use/NEX transaction code in the command field. This is dangerous, since it does not ask if you want to save the data.

Clicking on the EXIT button on the R/3 initial screen.

Getting help in the R/3 system

R/3 includes many possibilities to get online help for almost every element of the system, users can get help for entire application, for specific function, for definitions of various terms used in SAP, i.e., Glossary, messages, screens, fields etc.

You obtain HELP by using any of the following options:

Help function from the R/3 window, which is compulsory menu item of every R/3 window.

? Icon of standard tool bar.

F1 function key.The SAP system provides help on most fields that appear on the R/3 system. To get help on particular field, position the cursor over it and press help button or F1 function key.

Another way in which R/3 system provides help is when system displays error messages in the status bar. Double clicking on the status bar shows additional information about the message.

ABAP/4 Development Workbench

The development environment of SAP R/3 system is fully integrated set of various development tools, data dictionary, and programming language. Full integration of all components means that changes in any part have a direct and immediate effect on all application using those components.

The screen of ABAP/4 development workbench looks like

Tools of ABAP/4 workbench

For programming:

ABAP/4 dictionary Defining, maintaining and storing the data dictionary of the SAP R/3 system stores all the dictionary objects including tables relationship and Help information. Transaction code for this is SE11.

ABAP/4 editor Creating and maintaining the ABAP/4 program, editing function modules, logical database, and screens. Transaction code is SE38.

Function library Defining and maintaining the ABAP/4 function modules. Transaction code is SE37.

Screen painter Designing and maintaining the screens in transaction. Transaction Code is SE51.

Menu painter Designing and maintaining the means for graphical user interface. Transaction code SE41.

For Navigating:

Object browser Managing and organizing the development object in a hierarchical form. Transaction code is SE80.

ABAP/4 repository information Navigating and searching for the dictionary Objects, development objects and relationship objects. Transaction code SE84.

Data browser Navigating in the data tables of the database. Transaction code is SE 16.

For Debugging:

SOL trace tracking the database calls from the system transaction and programs. Transaction code is ST05.

Debugger Stopping the program and analyzing the results of the execution of every program statement.

Runtime Analysis Analyzing the performance the system calls Transaction code is SE30

For Organizing:

Workbench organizer controlling and keeping track of development work and team related development projects and managing versions of development objects. Transaction code is SE09.

Transport system performing and managing the transport of development object across different system. Transaction code is SE01

What is ABAP/4 ?ABAP (Advanced Business Application Programming) is a programming language for developing applications for the SAP R/3 system. ABAP is one of many application-specific fourth-generation languages (4GLs) first developed in the 1980s. The most basic functions were written in ABAP. ABAP/4 is the language created by SAP AG for implementation and customization of their R/3 system.The ABAP programming language was originally used by developers to develop the SAP R/3 platform. ABAP was one of the first languages to include the concept of Logical Databases (LDBs), which provides a high level of abstraction from the basic database level.

It was also intended to be used by SAP customers to enhance SAP applications customers can develop custom reports and interfaces with ABAP programming. The language is fairly easy to learn for programmers but it is not a tool for direct use by non-programmers. Good programming skills, including knowledge of relational database design and preferably also of object-oriented concepts are required to create ABAP programs.

The ABAP/4 Development Workbench contains all tools you need to create and maintain ABAP/4 programs. ABAP/4 programs are not complied but generated. During generation, the system creates a so-called runtime object from the source code and the program attributes. When you start the program, the system executes the runtime object.

ABAP/4, a fourth generation language, contains all usual control structures and modularizing concepts for structured programming.

Characteristics of the ABAP/4 programming languages

Declarative elements for declaring data of different type and structures.

Operational elements for manipulating data.

Control elements to control processing flow.

ABAP/4 is multi-lingual. Text elements such as titles, headings, and text body are stored separately, independent of the program codes. Thus, you can change, translate, and maintain text elements without having no adapt the coding.

ABAP/4 supports business-related data types and operations. You can execute calculations using special data and time fields. The system automatically executes all necessary type conversions.

ABAP/4 provides a number of functions for processing character strings.

ABAP/4 allows you to define and call subroutines. You can even call subroutines of other programs. There are different ways of how to pass parameters to and from the Subroutines.

ABAP/4 contains a special type of subroutine, called function module. Function modules are stored and maintained in a central library. They have clearly defined data interfaces to the calling program. You can test function modules in a stand-alone mode independent of the calling program.

ABAP/4 contains an SQL subset called OPEN SQL. OPEN SQL allows you to read and change database tables independent of the underlying database system.

ABAP/4 allows you to define and process internal tables that exist only for the execution period of the program. Internal tables efficiently support the usage of database tables and allow you to implement complex data structures in a program.

ABAP/4 allows you to store data not only in databases but also as sequential files on application and presentation servers.

ABAP language Contains below mentioned topics

1. Data Dictionary Objects Data Base Tables Views Structures Data Elements Domains Search helps Lock objects Primary Key and Foreign Key Table Maintenance Generator2. Internal Tables

Internal Tables Introduction Declaring Internal Table Populating Internal Table Processing Internal Table Initializing Internal Tables

3. Moduralization Techniques

Macros

Sub-routines Function Module4. REPORTS

Classical Interactive Abap list viewer (ALV)5. BDC - Batch Data Communication

Session method Call Transaction Method

LSMW

6. Module pool Programming

Screen painter Menu painter

7. Forms

Scripts Smart forms8. Cross-Aplications

ALE & IDOCS BAPI's BADIs

User Exists

9. Miscellaneous Topics

Correction & Transport request (CTS) Transport Organizer Work Bench Request Task Creation Release Objects SAP Memory & ABAP Memory SD Flow MM FlowData Dictionary

Data dictionary is the centralized and structured source of information about a database table. Its a logical layer situated over the database.

Data Dictionary does not contains the data like Emp name, Addresses etc but rather a type of data whose function is to define the properties of data such as type, length and relationship.

Advantages of data dictionary.

Advantage of using data dictionary is avoiding inconsistencies when defining data type that will later be used in different applications. This avoids redundancies.

When a type is defined in the dictionary, it is available to any program in the application. A change in the definition of a type of data in the dictionary automatically affects any other data or program, which has this data.

Again, data dictionary is a fast and efficient way to answer questions such as which entries exist in a table of the database, what the structure of table is.

Activation of dictionary objects

For a dictionary object to be effective at runtime, that is, for a dictionary object to be available for use within a program, transaction, and so on, it must be in active status. For objects to become active, R/3 includes the ACTIVATION function.

When a table or aggregated object is activated, it is placed at the disposal of the system as a runtime object in a way that makes it available quickly for the application program to access relevant information of new activated objects.

When a dictionary object is modified, that means that the object previously existed and activated. You need to reactivate the object after modification.

When mass activation is performed massively, it might take a quite a long time. Then it should be in the background system. This type of activation is known as background activation.

The ABAP/4 Data dictionary is the central component of ABAP/4 repository. A Data dictionary is centralized and structured source of information for business application. The ABAP/4 dictionary is the core of the R/3 development system. It is the source of every definition, within R/3, from the very basic domain to the company data model. It is totally integrated with other tools of the development environment like screen painter, menu painter, and editor.

Some of the main available functions in the ABAP/4 dictionary are as follows:

Add, delete, modify, and manage the definition of the dictionary data.

Preserve the data integrity.

Be the central source of information e.g. from the dictionary you get the information about the defined relationship between two tables or even the directory tells whether table is active or empty.

It also permits documentation of system data.

In the R/3 system instead of working with original objects, you work with internal representation of objects. With this type of operation the system performance is enhanced and has the advantage that the development tools, screen interpreters always access current data.

When any of the data dictionary objects are used in other parts of the development workbench for example, in program, programmer only has to enter a table name or field name. The system automatically knows all the properties and information of the field.

To call ABAP/4 dictionary, from the main menu, Tools ( ABAP/4 workbench ( data dictionary or enter transaction SE11.

Objects of Data Dictionary1. Tables

2. views

3. Data Type

4. Domain

5. Type Group

6. Search Help

7. Lock Objects8. Primary key and Foreign key

9. Table Maintenance generator.Tables

A table is two dimensional data matrix i.e. its the combination of rows and columns. The rows contain the data record and columns contain the field.

Tables can be containing 0 or multiple records or rows.

Ex: Employee Table.

Types of Tables

1. Client Dependent

2. Client Independent

1. Client Dependent:- If the first field of a table is MANDT and data type is CLNT then it is called client dependent table. The length will be always 3.

2. Client Independent: - If the first field contains other than the MANDT then it is

Called client independent table

The client dependent tables are again of three types.

1. Transparent tables.

2. Pooled Tables.

3. Clustered Table.

1. Transparent Tables A transparent table in the dictionary has one to one relationship with a table in the database. Its structure in R/3 Data dictionary corresponding to a single database table. The database table has the same name, the same number of fields and the fields have the same names as the R/3 table definition. It contains application data. In below fig first part will shows transparent table.

2. Table Pools and Pooled Tables

A pooled table in R/3 has a many-to-one relationship with a table in the database. For one table in the database, there are many tables in the R/3 Data Dictionary. The table in the database has a different name than the tables in the DDIC, it has a different number of fields, and the fields have different names as well. Pooled tables are an SAP proprietary construct.

In the database pooled tables are stored in a single table called a table pool table.R/3 uses table pools to hold a large number (tens to thousands) of very small tables (about 10 to 100 rows each). Table pools reduce the amount of database resources needed when many small tables have to be open at the same time. Pooled tables are primarily used by SAP to hold customizing data. In the above fig second part is an example for pooled tables3. Table Clusters and Cluster Tables

A cluster table is similar to a pooled table. It has a many to one relationship with a table in the database. Many cluster tables are stored in a single table in the database called a table cluster.

Table clusters are used to hold data from a few (approximately 2 to 10) very large tables. They would be used when these tables have a part of their primary keys in common, and if the data in these tables are all accessed simultaneously. Table clusters contain fewer tables than table pools and, unlike table pools, the primary key of each table within the table cluster begins with the same field or fields. In the above fig third part is an example for cluster tables.

Restrictions on Pooled and Cluster TablesPooled and cluster tables are usually used only by SAP and not used by customers, probably because of the proprietary format of these tables within the database and because of technical restrictions placed upon their use within ABAP/4 programs.

1. On a pooled or cluster table, Secondary indexes cannot be created.2. You cannot use the ABAP/4 constructs select distinct or group by.

3. You cannot use native SQL.

4. You cannot specify field names after the order by clause. Order by primary key is the only permitted variation.

Because of these restrictions on pooled and cluster tables and because of their limited usefulness. Normally in real time system we will not create much pooled and cluster tables. Only transparent tables are used or created maximum. So we will discuss only about transparent tables

Other Components of the Table

Fields: - Fields are nothing but columns. Domain: - Domain consists of the technical characteristics of a field such as field length and data type.

Data Element: - A table is composed of fields to create a field you need a data element. The data element contains the field labels and documentation (F1 help) for the field. It contains the semantic characteristics for the field and it works like a interface between Field and Domain.

Domain and data elements are reusable. A domain can be used in more than one data element and data elements can be used in more than one field and in more than one table.

Delivery Class: - Delivery class comes under attributes. The value in the delivery class field identifies the OWNER of the data in this table. The owner is responsible for maintaining the table contents. In customer tables we always enter A Here which indicates that the table contains application data owned by the customer only.Ex: - A Application table (Master and Transaction data).

Data Class: It comes under technical settings. It defines the physical address of the database in which the table uses creates and logically stored or its a physical place where the actual data is to be stored.

Categories of data class: APPLO Master data, transparent tables.

Size Category: It also comes under technical settings. It defines the probable space requirement for a table in the database.

Categories:0:- 0 to 30,000.1:- 30,000 to 1, 20,000.2:- 1, 20,000 to 4, 90,000.3:- 4, 90,000 to 1,9,00,000

Table Maintenance allowed: Its also comes under attributes. By enabling table maintenance allowed user can be able to enter the data, change and display manually.

Approaches for creating tables:- There are two approaches you can use when creating tables.

Top-down-approach: In top down approach first we create the field then data element then domain.

Bottom-up-approach: In the bottom-up-approach first we create the domain, then data element and then field.

Direct Method: Do not have data element or domain.

Primary key: Primary key is a field or combination of fields that uniquely identify a row in the database table.

Foreign Key: Foreign Key is a key which is a primary key of another table.

Naming convention for database tables:

1. The tables we are creating are generally called as Z-tables or customizing tables.

2. The name of a table should be started with Y or Z that a user creates.

3. SAP has used A to X for its own use, Z or Y in the beginning means that the program or table is user defined.

So it avoids the redundancy between predefined and customizing tables.

Steps to Create Database TablesTo create tables, Go to transaction SE11 and select database table radio button: Give Database table name for example ZKA_EMP. All user-created tables must start with Y or Z.

Eg: ZKA_EMP. Then click on the CREATE button.

Eg: ZKA_EMP. Then click on the CREATE button and you will get the below screen.

In the Attributes (tab) screen,

Enter the short description as EMPLOYEE DETAILS. Delivery class: Under multiple entries, select A-Application table (Master and transaction data).

Check the box for the Table maintenance allowed.

Now select the fields (tab), Field name EMPNO and field type ZKA_EMPNO and check the primary key check box. Field name EMPNO and field type ZKA_EMPNO and check the primary key check box and click on save button.

When you click on save button you will get one pop-up box as shown below.

Click on the LOCAL OBJECT button.Now double click on the field type and u will get CREATE DATA ELEMENT SCREEN, click on YES.

Enter the short text EMPLOYEE NO and the domain name ZKA_EMPNO.

Now double click on the domain name ZKA_EMPNO and enter the following details.

Short text : EMPLOYEE NO. Data Type : NUMC(Click on the RIS button and select NUMC from that)

No. of characters: As per the requirement. ( Eg. 10 ).

Note: If the field is employee name then u need to select the data type to be CHAR and required no of characters.

Now SAVE (CTRL + S) , Click on the CHECK button or (CTRL + F2), and should get NO INCONSISTENSIES FOUND in the status bar.

Then click on the ACTIVATE button (CTRL + F3).

Now click on the BACK button and then,

SAVE(CTRL+S), CHECK(CTRL+F2) & ACTIVATE(CTRL+F3). Click the BACK button and u will be in the main dictionary screen.

Now click on the NEW ROWS button to enter as many fields u would prefer.

Once all the fields with the data element and the domain is set up, the table need to be activated as a whole. To activate the table the technical settings should be saved.

Before u activate, u need to set up the technical settings by clicking on the TECHNICAL SETTINGS button.

Where the data class is APPL0 (Master data, Transparent tables).

Size category is 0(0-30000).

SAVE or (CTRL+S) the technical settings.

Click BACK to get to the main screen and SAVE, CHECK AND ACTIVATE the table.

In order to give the input values(new entries), click on Utilities->Table contents->Create Entries

Enter and SAVE the values and click RESET to give the new values.

Once the values are saved, click the BACK button and click on the CONTENTS, then the EXECUTE button to see the output.

So when we click on the EXECUTE button, we get the output in the table format.

Thus the table is created.

Database ViewsA 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 releasedTypes of Views

1. Projection View2. Database View3. Maintenance View4. Help View

Projection View: This view is used to display datas 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 datas 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.Steps to create ViewsDATABASE VIEW:View can be performed for more than one table which have the foreign relationship b/w the tables. For Eg: If we have ZKA_EMP and ZKA_COM, We can perform view.

Now to start with the view. Go to transaction SE11 and select View Radio button and enter the name as below.

Eg: ZKA_DBV and click on the CREATE button.

Select the database view among the options and then click on the copy button.

Enter the short text: DATABASE VIEW.

And under the tables enter both the table names ZKA_EMP, ZKA_COM.

Now click on the RELATIONSHIPS button and select the referenced tables and click on the COPY button.

Now click on the VIEWS tab and click on the TABLE FIELD button.

Now choose the first table ZKA_EMP and select the fields required and click on the COPY button. Similarly for the second table ZKA_COM.

Now SAVE, CHECK and ACTIVATE. To see the output, click CONTENTS and EXECUTE.

Thus the database view is done with the fields in both the tables.PROJECTION VIEW: Go to SE11 and click on VIEW and enter ZKA_PV. Click on the CREATE button.

Select PROJECTION VIEW and click on the CONTINUE button.

Now enter the short text: PROJECTION VIEW.

Basis table: ZKA_COM (the table for which u need the projection view).

Now click on the TABLE FIELDS button and select the fields that we need to project and click on the COPY button.

Now SAVE, CHECK and ACTIVATE. To see the output click on the CONTENTS button and EXECUTE. Thus the projection view is created.

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.STRUCTUREStructure is a skeletal view of a table. It contains the definition of columns and dont 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 StructuresAppend 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.Steps to create Structure.In the DDIC (SE11), select DATATYPE and give the structure name: ZKA_STRUCT.

Now select STRUCTURE and click on the COPY button.

Enter the short text: STRUCTURE. Then the components (field) corresponding to the table and select the component type from the existing data type.

Click on SAVE, CHECK and ACTIVATE.

Now go the table to which the structure need to be added (ZKA_EMP).Select the row where the structure need to be added and click on EDIT->INCLUDE->INSERT

Enter the STRUCURE ZKA_STRUCT and click OK. SAVE, CHECK and ACTIVATE. To see the output, Click on CONTENTS and EXECUTE.

Select all the records and click on the CHANGE button and click on the next entry and fill in all the values and BACK button to see the output.

Thus the Structure is created.

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 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. 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 programExample 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.LOCK OBJECTSThese 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:

From initial data dictionary screen, enter the name for the object, Click Lock object radio button and then click on Create. The system displays a dialog box for Maintain Lock Objects screen

Enter short text as usual and the name for primary table.

Save

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.

Activation of Lock Object

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.

Internal Tables

By definition, internal tables are user defined structured data types. These internal tables can be created as a replica of data base table, using some or all fields of one table or more tables. These internal tables are created only during run time no memory is reserved.

Why we need internal table

Long life data is stored in database tables when we are directly modifying data there is

every possibility that we may loose data by accident, which we can not afford to do so, As such we need some intermediate etc tables to do some operations upon satisfactory results, we can modify database tables.

Defining Internal Tables:Internal table with header line: When we create internal table with header line, a default work area is created.

Internal table with out header line: In this case, we need to create explicit work area to work with it. When we need to nest the tables with in tables, we need to use this type of internal table.

Types of internal tables

1. Standard tables: - Standard tables have an internal linear index. The system can access records either by using the table index or the key. The response time for key access is proportional to the number of entries in the tables. The key of standard table is always non-unique. Standard tables can always be filled very quickly, since the system does not have to check whether there are already existing entries.

Key access to a standard table uses a linear search. This means that the time required for a search is in linear relation to the number of table entries. You should use index operations to access standard tables.

2. Sorted Tables: - Defines the tables as one that is always saved correctly sorted by key.

The system can access records either by using the table index or the key. The response time for key access is logarithmically proportional to the number of table entries, since the system uses a binary search. The key of a sorted table can be either unique or non-unique.

If the key is not unique, the system takes the entry with the lowest index. The runtime required for key access is logarithmically related to the number of table entries.

3. Hashed tables: - Hashed tables have no linear index. Hashed table is accessed using its key. The response time is independent of the number of table entries and is constant, since the system accesses the table entries using a hash algorithm. The key of a hashed table must be unique.

Defines the tables as one that is managed with an internal hash procedure. You can only access a hashed table using the generic key operations or other generic operations (sort, loop and so on) Explicit or implicit index operations (such as loop... from and insert itab with in and loop) are not allowed.

4. Index Table: - A table that can be accessed using an index. Index table is only used to specify the type of generic parameters in a from or function. That means that you can not create a table of type Index. Standard and sorted tables are index tables.

Initializing Internal Tables

Clear: Clears the header (Work Area) line of the internal table.

Syntax: clear Itab.

Clear []: Clears the body of the internal table without clearing the work area or header.

Syntax: Clear itab [].

Refresh : Delete all table entries, memory space remains occupied i.e. only removes only contents of internal table.

Free : Delete all table entries, memory space is released i.e. de-allocates memory associated with internal table.

Operations of Internal Tables1. Append: It will take data from work area or header into internal table body.

Syntax: Append itab (append itab to itab)

Append wa_itab to itab.

2. Collect: It will work similar to append operation but it will adds the same integer

fields otherwise it will append it.

Syntax: Collect itab.

3. Insert: Used to insert data at any place. For this we have to specify the index no

otherwise its goes to dump screen.

Syntax: insert itab index (Index number).

4. Modify: This operation will modify the existing records.

Syntax: Modify itab index (Index number).

5. Read: Used to read a single record from itab with key or index and it will read from

application server to the screen.

Syntax: read itab with key (field name)

6. Sort: Used to sort the internal tables and by default it is ascending.

Syntax: Sort itab by (Field name).

7. Delete: Used to delete the data from internal tables but you need to give index number

or range and field names.

Syntax: Delete itab by index (Index number)

8. Describe: Used to describe the internal tables like how many records and what kind of

internal table etc.

Syntax: Describe table itab lines (variable name)

Example for internal table operations*&---------------------------------------------------------------------*

*& Report ZBASU_INTERNAL_TABLE_OPERATION *

*& *

*&---------------------------------------------------------------------*

*& *

*& *

*&---------------------------------------------------------------------*

REPORT ZBASU_INTERNAL_TABLE_OPERATION.

DATA: BEGIN OF ITAB OCCURS 0,

F1,

F2 TYPE I,

F3(3),

END OF ITAB.

DATA: LIN.

******Append Operation

ITAB-F1 = 'A'.

ITAB-F2 = 10.

ITAB-F3 = 'BC'.

APPEND ITAB.

CLEAR ITAB.

ITAB-F1 = 'B'.

ITAB-F2 = 15.

ITAB-F3 = 'BD'.

APPEND ITAB.

CLEAR ITAB.

******* Collect Operation

ITAB-F1 = 'A'.

ITAB-F2 = 20.

ITAB-F3 = 'BC'.

COLLECT ITAB.

CLEAR ITAB.

ITAB-F1 = 'C'.

ITAB-F2 = 25.

ITAB-F3 = 'BF'.

APPEND ITAB.

CLEAR ITAB.

*******Insert Operation

ITAB-F1 = 'D'.

ITAB-F2 = 30.

ITAB-F3 = 'BG'.

INSERT ITAB INDEX 2.

CLEAR ITAB.

*******Modify OperationITAB-F1 = 'F'.

ITAB-F2 = 40.

ITAB-F3 = 'BH'.

MODIFY ITAB INDEX 2.

CLEAR ITAB.

ITAB-F1 = 'F'.

MODIFY ITAB TRANSPORTING F1 WHERE F1 = 'D'.

CLEAR ITAB.

*******Sort OperationSORT ITAB.

SORT ITAB BY F2.

******Read OperationREAD TABLE ITAB INDEX SY-TABIX INTO ITAB.

READ TABLE ITAB INDEX 3 INTO ITAB.

READ TABLE ITAB INTO ITAB WITH KEY F1 = 'D'.

WRITE:/ ITAB-F1,

ITAB-F2,

ITAB-F3.

******Describe OperationDESCRIBE TABLE ITAB LINES LIN.

******Delete OperationDELETE ITAB INDEX 2.

DELETE ITAB WHERE F1 = 'A'.

WRITE:/ 'NO OF LINES IN MY INTERNAL TABLE', LIN.

LOOP AT ITAB.

WRITE:/ ITAB-F1,

ITAB-F2,

ITAB-F3.

ENDLOOP.

REPORTS

About reports

Reports, in the R/3 system are online programs whose function is to retrieve data from database and display it or print it for the user. An end user often needs some information to look up, depending upon which various management decisions are taken, or to just see business results or simply to continue work. As R/3 is collection of all business applications, it has provided a very powerful feature to satisfy this crucial business need i.e., reports are involved at each and every step of business. This type of extracting, collecting and formatting data that is stored in database is done by REPORT program.

The program that is written to retrieve and display data is REPORT program and the data that is displayed on the screen when you execute the program is called as LIST (output of the report).

When you display data, you need to display the data, user needs. For example, user wants to see the all the employee, who has joined after 12th December 1997. In this case user has to pass this information, to the system, that he needs only those employee records where joining data is greater than 12th December 1997. For user, it is passing information to the system but for the system it is input from the user. System takes input from the user before it retrieves the data from the database. This is very common requirement of any report as the need of any business is to display data, which is required by user.

Reports are ABAP/4 programs.

You use reports to evaluation data from database tables. The results of such an evaluation can be displayed on the screen or printed form.

Reports are stand-alone programs.

The user can execute reports directly via the program name, for example, by choosing System Utilities Reporting.

A report program contains a collection of processing blocks for different events that are always triggered externally. In a report, you can react on events by programming the corresponding processing blocks or ignore the events by not writing the corresponding processing blocks. A report itself never creates events.

Reports can use logical databases or select statements defined by developer.

For each application, SAP supplies logical databases. Or you can easily create logical database yourself.

Event control of a report corresponds to a certain scheme:

When a report is executed, the ABAP/4 processor creates together with the logical database used (if any) a sequence of certain events for which you can program processing blocks. The chronology of the events is (more or less)

Steps involved in creating a Report:

1. Processing the selection screen

After starting a report, the selection screen allows the user to enter limits or control values for further report processing. The report can contain several processing blocks for events during selection screen processing, for example, for checking the input values.

2. Reading the database

After selection screen processing come the events for reading the database. Either the report reads data from relational databases it using the corresponding ABAP/4 statements (open SQL) or leaves this task to a logical database. In the latter case, the logical database creates a sequence of events to allow the report to copy the data.

3. Evaluating data and creating lists

During or after reading the database the report creates the output list. During list creation, several events allow you to layout the output list (for example, layout the page header).

4. Outputting a list

The last part of the processing sequence controlled by the ABAP/4 processor is the list output on the screen or printer. When displaying the list on the screen, user can trigger other reports, that are interactive and are event driven. For example, by clicking the mouse. By programming processing blocks for these events, you change a normal report to a so-called Interactive report. If a report does not contain event keywords, the entire coding of the report belongs to a single processing block, which is called by a standard event. This standard event is triggered directly after processing the selection screen.

Selection criteria

System accepts inputs from user through SELECTION CRITERIA.Selection criteria are nothing but input fields which allows the user to restrict information given to program for processing further data. If you dont specify any criteria for selection, your report program produces a long list of data, which might not be needed by the user. Basically, selection criteria are the fields where user enters some value for which he needs information. Through selection criteria user can enter discrete value or ranges. For example, user wants to see all the records of the employees, who have joined between 12th December 1997 and 12th May 1998. This range can be entered in selection criteria. As the user becomes more specific for mentioning the criteria, the list will be smaller and more specific.

Syntax:SELECT-OPTIONS for .

Field is the variable, which you declare for accepting input from the user.

Table field is reference field.

SELECT-OPTIONS: fld1 for sflight-fldate,

carrid1 for sflight-carrid.

Maximum length of the name Select-Options variable is 8.

When system executes this statement, the selection screen is displayed and is like this.

When you enter the desired information and click on execute button, rest of the program is executed, that is retrieval of data from database, which matches this information and the list is displayed.

Behavior of SELECT-OPTIONS

When the Select-Options statement is executed the system creates the internal table with the same variable name (in this case it will be carrid1). This table is also called as selection table. The main purpose of selection table is to store selection criteria. The table has four standard fields, which are as follows:

SIGN is a variable, which denotes the system whether the result should be included with those particular criteria. It can contain either I or E. I denotes Inclusion. The criteria are included.

E denotes Exclusion. The criteria are excluded from the result.

LOW the data type of LOW is the same as the field type of the database table, for which you are using selection criteria. This acts as lower limit of the selection.

HIGH the data type of HIGH is the same field type of the database table, for which you are using the selection criteria. This acts as higher limit. If you dont enter HIGH value then the LOW value defines a single value selection.

OPTION is two-character field, which contains operators like EQ, GT, LT, GE, and LE.

When the user enters both the values i.e., high and low then this field acts as BT (between). If you dont enter high value then all other operators can be Applicable.

For each Select-Options statement system creates internal table.

Default values for select-options

If you want to display default values for the selection criteria before your screen is displayed, give default values for the selection table fields i.e., low or high.

SELECT-OPTIONS: CARRID1 FOR SFLIGHT-CARRID DEFAULT CARRID1-LOW = LH AND CARRID1-HIGH = SQ.

In this case selection screen is displayed with default values LH for lower range and SQ for higher range. User can use same values or overwrite these values with new values, whichever he needs.

Parameters

Parameter statement is used to accept input from user. PARAMETER statement is used when you want user to enter data and depending upon what he enters you need to take action. The parameter statement declares the variable and also allows system to accept data into that variable.

Syntax.

Parameters: num type I.

Here parameter statement declares the variable and creates the selection screen on which user enters the data i.e., in this case num is declared of type I and user can enter any number. Entered value is stored in the same variable and can be used in program.

Data: m type I

Parameters: num type I

M = num 5

Write: / The number is, m.

You can define default values with parameter statement for example

Parameter: num type I default 12.

In this case when selection screen is displayed the default value is displayed. User can either use same value or overwrite the value.

Parameter of type character and length = 1, can be displayed as Checkbox and Radiobutton.

Parameter:C1 as Checkbox,

C2 as Checkbox.

Parameter:R1 Radiobutton group g1,

R2 Radiobutton group g1.

When parameter is defined as Radiobutton, it needs to be attached to one group. Only one Radiobutton of one group can be clicked.

Every parameter can be associated with language dependent text that is displayed on the selection screen. This can be done with the help of text elements.

WRITE Statement

The basic APAB/4 statement for outputting data on the screen is WRITE.

Syntax:

WRITE .

This statement outputs the field to the current list in its standard output format.

By default, the list is displayed on the screen.

The field can be any variable or table field or just literal.

PROGRAM ZDEMO

WRITE: /HELLO.

When you start this program, the system leaves the current screen i.e., your editor screen and branches to the output screen, which is also called as list screen:

The list screen has the same name as the title of the program specified in the program attributes. First line on the screen contains the list header. By default, the list header is the same as the title of the program. The current page number (1) appears on the right. The list header is followed by one line and then the output is displayed.

Write : HELLO.

Write : WORK HARD

On the screen, the output is normally left justified. But in above case, because we have used two WRITE statements, the output fields are displayed one after the other, each separated by one column (i.e., one blank). If there is not enough space for an output field on the current line, a new line is started.

Almost all system-defined fields are right justified except FLOAT, INTEGER, and PACKED i.e., number field. The numeric data types F, P, and I are right justified and padded with blanks on the left. If there is sufficient space, thousands of separators are also output. If a type P field contains decimal places, the default output length is increased by one.

With the data type D, the internal format of a date differs from its output format. When you use the WRITE statement for outputting data, the system automatically outputs dates of type D in the format specified in the users master record (e.g. DD/MM/YYYY or MM/DD/YYYY).

CLASSICAL REPORTSEvents in Classical report

Events associated with classical report are as follows and each one will be discussed in detail.

INITIALIZATION

AT SELECTION-SCREEN AT SELECTION-SCREEN ON

START-OF-SELECTION

TOP-OF-PAGE

END-OF-PAGE

END-OF-SELECTION

In this case first three events are associated with selection screen. Rests of the events are associated with your list.

INITIALIZATION

We have already seen how to fill default values for the selection criteria. But in many cases you need to calculate the value and then put it in selection criteria. For example, say, you are accepting date from user and you need to fill in the default value for lower range as sy-datum 30 days and sy-datum for higher range. In this case you are calculating lower range and then filling the criteria. This can be done in INITIALIZATION event. Piece of code to do the above task would look like the following:

Tables: Sflight.

Select-options: fldate1 for sflight-fldate.

INITIALIZATION.

Data: date1 like SY-DATUM.

Date1 = sy-datum 30.

Fldate1-low = date1.

Fldate1-high = sy-datum.

Append fldate1.

* Here appending is required because fldate1 is int table

This event is triggered when you execute your program for the first time i.e., before selection screen is displayed.

AT SELECTION-SCREEN

When user enters the values in the fields of selection screen and clicks on execute button, this event gets triggered. This event is basically for checking the values entered by the user for the fields of the selection screen i.e., data validity checking. This event is for entire selection screen. For example:

You are accepting carrid, connid, fldate from user and you dont want to proceed if user enters no value for carrid and fldate. Using AT SELECTION-SCREEN can do this.

Select-options: carrid1 for sflight-carrid,

Connid1 for sflight-connid,

F1date1 for sflight-f1date.

AT SELECTION-SCREEN.

If carrid1-low ne and fldate1-low = .

Error message.

Endif.

In this case, if both the fields are entered blank, then the user gets error message.

Basically, this event is for many fields on selection screen. Usually, it is for the fields which are logically related.

AT SELECTION-SCREEN ON

When you want to check for specific value of a field. For example, carrid should be in the range of LH and SQ. This can be done in this event. Basically, this event is for checking individual fields. You can have many AT selection-screen events in your program (i.e., for each field specified in the Select-Options).

Select-Options carrid1 for sflight-carrid.

AT SELECTION-SCREEN.

If carrid1-low ne LH and carrid1-high ne SQ.

Error message.

Endif.

Here the system will not proceed on entering wrong values.

START-OF-SELECTION

This is the first event for your list. Once all the events are triggered for selection screen, the data is retrieved from database. Data declaration, select statements are done in this event. Consider the following example:

START-OF-SELECTION.

Data: mtype i.

Tables: sflight.

Select * from sflight where carrid = LH.

Write: / sflight-carrid,sflight-connid.

Endselect.

TOP-OF-PAGE

This event is triggered with first WRITE statement or whenever new page is triggered. Advantage of using this event is that, whatever you write under this event, is applicable to all the pages. If you dont have any write statement before TOP-OF-PAGE or in START-OF-SELECTION, this event is not triggered at all. For example, if you want the name of company and column headers for all the pages, it can be written in this event.

TOP-OF-PAGE

Write: / INTELLIGROUP ASIA PVT. LTD.

Write : / 10 carrid, 20 connid, 30 fldate.

END-OF-PAGE

This event is triggered at the end of page.

End-of-page.

Write : / page number, sy-pagno.

In this case page number will be written on every page.

Conditional triggering of EOP

Consider the following case.

REPORT ZDEMO1 line-count 15(3).

Top-of-page.

Write: this line is written by top-of-page event.

Start-of-selection.

Write: this line is written by start-of-selection event.

End-of-page.

Write : this line is written by end-of-page event.

In this case EOP will never be triggered, as end of page is never reached. The total Line-count defined for page = 15 in which 3 lines are for footer area. The output of the above code will be

This line is written by top of page event.

This line is written by start of selection event.

In output screen, only two lines are written and cursor remains still on 3rd line, the end-of-page event is not triggered. To trigger end of page event, cursor should reach at the last position, in this case on 11th line.

Such cases are quite common, and could be overcome by conditional triggering of end of page.

Sy-linct is the system variable, which gives total line count of a list.

Sy-linno is the system variable, which gives the current line number where the cursor is placed on the list.

Consider the following case:

Report zdemo1 line count 20(1).

Start-of-selection.

Data: m type i.

Write: / this is first line.

Do 5 times.

Write: / the number is, sy-index.

Enddo.

M = sy-linct, sy-linno 1.

Skip x.

End-of-page.

Write: / page end.

The output of above example is as follows :

This is first line.

The number is 1

The number is 2

The number is 3

The number is 4

The number is 5

After skipping 10 lines

Page end

In this case, with all write statement, you dont reach to the end of page. After all write statement, m is calculated in this case:

M = 20 8 1, So m is 12. And 11 lines are skipped after write statement and end of page is reached. (In this case you have 6 write statement so 6 lines + 1 line for page number and 1 horizontal line which is displayed for any list. So cursor is on 8th line and is subtracted from total line count i.e, 20.)

Using Variants with selection criteria

In many cases you need report to execute report at regular interval for certain fixed values of selection criteria. That means each times you execute the report you need to enter its values again and again. ABAP/4 provides the facility by which you can define the values for selection screen and store it. Using VARIANTS can do this. It can be defined as group of values used for selection criteria while executing report. For a particular report, you create a variant which means variant created for parti