Sie sind auf Seite 1von 152

SAP

SYSTEMS, APPLICATIONS and PRODUCTS in data processing ERP: E: Enterprise / Company Ex: Reddy Labs, Reliance, GE, GM, BMW R: Resources Man -> employee Machines -> plants/manufacturing units Materials -> items/products (raw, semi finished, finished) Money -> finance (profit/loss) P: Planning (effective plans for maximum profits with minimum resources) ERP Software: Software which is used to maintain the business activities of a company/enterprise is called ERP software. The business activities are How many customers/vendors/materials How many sales orders/delivery orders/invoice How much profits/loss How many employees/leaves/provident funds/income tax How many plants/stock available/stock damaged etc. The available softwares are, People Soft Used by small companies Supports less number of business applications/scenarios/programs Supports less number of business modules Less cost software Very good at HR module Oracle Used by medium sized companies

Supports limited number of business applications Supports limited number of business modules High cost software Very good at finance (FI) module SAP It is an ERP software which is used by medium sized as well as top MNCs SAP supports every scenario or business application SAP supports almost every module in the business (around 45+ modules) Very high cost software It is excellent at integration between all the SAP modules *** We cant do any black business in SAP (i.e., the information is stored in a secured way where you cant do any black business)

ABAP
ADVANCED BUSINESS APLLICATION PROGRAMMING It is a 4th generation language i.e. ABAP/4, the entire ERP software is developed by using a single programming language which is called as ABAP. SAP Modules SD : sales and distribution MM : material management FI : finance CO : controlling HR : human resources CRM : customer relation management SRM : supply relation management, etc.

Functional Consultants: A consultant who is responsible for configuring the real time business scenarios like how many plants, sales organizations, materials etc in SAP software is called as functional consultants. ABAP Consultants: A consultant who is responsible for developing new programs, screens, tables or modifying standard SAP programs is called as ABAP consultants. BASIS Consultants: A consultant responsible for installing the SAP software, configuring the servers, controlling network traffic, creating usernames and passwords etc are called as BASIS consultants. Roles and responsibilities of ABAP consultants: Receiving a ticket from TL Analyze the business requirement Estimate the number of hours for business requirement Develop the object Perform unit testing Release the developed object to testing server Prepare technical document for object System Landscape:

Development Server: A server where all the ABAP consultants will be developing the real time objects for a business requirement is called development server. Once the development is finished, we should do a sample testing called as unit testing. Quality Server: A server where all the functional consultants or testing consultants will be testing the developed objects is called a testing server. It is also called as quality server. Production Server: A server where all the developed objects will be used in the live business market to maintain the business is called production server. It contains the live business data of customers. Note: As an ABAP consultant, we will be working only at development sever, not the quality and production severs. ABAP consultants with more than 4 or 5 years of experience will have the access to quality sever but not production server. Sand Box Sever: It is a server where we do our R&D work is called a sand box sever. Everybody will have access to the sand box server. SAP R/3 Architecture: In software engineering there are 3 architectures Single tier architecture Two tier architecture Three tier architecture Single tier architecture: A system which is responsible for loading the program, compiling, interpreting, executing as well as storing the data in the same system is called single tier architecture. In simple words a system responsible for front end and back end operations is called single tier architecture. Ex: All C language programs in olden days are written using single tier architecture. Two tier architecture: In this architecture we have two layers, server layer and client layer. 2. a. Sever layer: In this layer we have a single system with very high configuration called as server. This sever is responsible for executing the programs as well as storing the data. 2. b. Client layer: In this later we have multiple systems which are connected to a server. All the business users will be operating from client systems. The server will receive the request from the client system and gives back the response (i.e. result). Ex: SAP R/2, Oracle

Disadvantages of two tier architecture: As the number of client systems increases the load on the database server will increase and the response time will be delayed Since the response time is delayed the output will be very slow on the client system which is very big disadvantage To overcome this problem we have a new architecture called as three tier architecture Three tier architecture: In this architecture we have three layers, they are database server layer, application server layer and presentation sever layer. 3. a. Database server layer: A server which is responsible only for storing the data is called database server layer. 3. b. Application sever layer: A server which is responsible for only executing the applications or programs is called application sever layer. 3. c. Presentation server layer: A server which is responsible for just presenting the output and taking the input is called as presentation sever layer. Ex: SAP R/3 architecture.

History of SAP: In 1972, five IBM employees started a company by name SAP AG (angelsko) Their objective was to develop a business or ERP software In 1980 the company released the first ERP software by name SAP R/2, where R stands for real time and 2 stands for two tier architecture In 1990 the company released advanced version of SAP R/2 by name SAP R/3, where 3 stands for three tier architecture Even today also we are using SAP R/3

Chapter 01

Log into SAP: Double click on SAP GUI or SAP LOGON icon Select development server name (ECC6) Click on LOGON Provide username: SAPUSER password: INDIA123 Press enter SAP EASY ACCESS screen is displayed Transaction Code: It is a unique code or shortcut code to execute a specific program and its corresponding screen. Ex: SE11: Displays ABAP dictionary SE38: Displays ABAP editor SE37: Displays ABAP function builder SE21: Displays ABAP package builder SE80: Displays ABAP development work bench . Etc. Naming conventions:

These objects will starts with any character Except Y and Z. These objects cant be modified directly.

The objects must start with either Y or Z. These objects can be changed however we want.

PACKAGE: It is a container of developed objects Each project contains a single package (generally) Packages are created by BASIS consultants or team leads when the project is started All our objects must be stored in the package only SE21 is the TCODE for creating a package Steps to create a package: Go SE21 Give the package name ZSAP_ABAP Click on create, provide short description Click on create, save and enter Press enter Click on save, a package is created Transport Request Number: A number which is used to transport an object from one server to another server within system landscape is called transp Ex:

ECCK is the name of development server.

Package types:

Steps to create a program: Go to SE38, give the program name zsample Click on create, provide description Select type = EXECUTABLE Click on save Provide the package name and press enter Click on create request icon Provide short description and press enter A transport request number will be generated, just press enter The ABAP editor is opened Click on save and activate WRITE: It is the statement which is used to print a text on the output screen. Ex: Write hello world. Syntax:

: Chain Operator: It is a statement which is used to display multiple texts which are separated by commas using a single write statement. Report zsample. Write hello world. Write welcome to sap abap Write / igrow soft. Write: / cno, cname, city. Write: / 3 cno, 15 cname, 25 city. Write: / 25(25) IBM India left-justified color 1. (Displaying background color) Write: / 25(25) IBM India centered color 2. Write: / 25(25) IBM India right-justified color 3. Write: / 25(25) IBM India right-justified color 6 inverse. (Displaying font color) System Variables: A variable which is defined by the system is called a system variable All system variables are automatically assigned with some values All system variables will start with SY or SYST All system variables are stored in SYST structure Ex: Write / sy-uline. (Displays horizontal line) Write / sy-datum. (Displays systems date as per date settings in SU3 Tcode) Write / sy-uzeit. (Displays systems time) Write / sy-uname. (Displays systems user name) Write / sy-repid. (Displays report name) Write / 25(25) sy-uline. (Horizontal line at specified position) Write / 25 sy-vline. (Vertical line of height 1line)

Ex to draw a box: Write / 25(25) sy-uline. Write / 25 sy-vline. Write 49 sy-vline. Write / 25(25) sy-uline.

Develop a report to display customer details as below.

What is a chain operator? What is a system variable and where they are stored? What are the roles and responsibilities of ABAP consultant? Explain the system landscape of your project? Explain 3 tier architecture? What are the modules you have worked on? What is your team size of your project? How many colors are there in sap abap? User defined variables: It is the keyword which is to declare a variable of certain data type and length. Syntax: (Data is keyword) Data: <variable name> (length) TYPE <data type> value <default value> Ex: Data: v_fname(15) type c value ibm, v_lname(15) type c. V_lname = ibm india private limited.

Write: / v_fname, / v_lname. Data types in ABAP:

Ex: Data: v_fname(15) type c, V_pincode(6) type n, V_dob type d, V_time type t, V_count type I, V_cost type p decimals 2, V_totalcost type p. V_fname = ibm india. V_pincode = 509001. V_dob = 19821231. V_time = 102030. V_count = 1.

V_cost = 1999.999. V_totalcost = 1999.999. Write: / v_fname, / v_pincode, / v_dob, / v_time, / v_count, / v_cost, / v_totalcost. Conditional statements: If <condition is true>. . . Endif. If <condition is true>. . Else. . Endif. If <condition1 is true>. . Elseif <condition2 is true>. . Elseif <condition3 is true>. . Else. . Endif. Case <condition>. When value1. .

When value2. . When value3. . When others. . End case. Difference between if-elseif-endif and case statements: The if-elseif-endif statement will compare each condition until the true statement is executed The case- end case statement will not compare each condition, instead it will directly jump to the true condition i.e. why always use case-end case statement instead of if-elseif-endif Parameters: It is a keyword which is used to create an input field on the selection screen. The selection screen is called input screen. Syntax: Parameters: <parameter name> (length) type <data type> The output screen is called as list screen, the input screen is called selection screen Ex: (On if) Parameters: p_land1(3) type c. If p_land1 = . Write: / please enter a value. Endif. (On if-else) If p_land1 = in. Write: / we are calculating tax for Indian customers. Else. Write: / we are calculating tax for non Indian customers.

Endif. (On if-elseif-else-endif) If p_land1 = in. Write: / we are calculating tax for IN customers. Elseif p_land1 = us. Write: / we are calculating tax for US customers. Elseif p_land1 = uk. Write: / we are calculating tax for UK customers. Else. Write: / please enter a valid country code. (On caseend case) Case p_land1. When in. Write: / we are calculating tax for IN customers. When us. Write: / we are calculating tax for US customers. When uk. Write: / we are calculating tax for UK customers. When others. Write: / please enter a valid country code. End case. Loop statement: Do . Enddo While . Endwhile Loop at <itab> . Endloop

Loop statements are those statements which are executed repeatedly depending on a condition or fixed number of times. There are 3 types of loop statements. Do enddo: Syntax: Do <n> times. . . Enddo. While endwhile: Syntax: While <condition is true>. . . Endwhile. Ex: Data: v_count type i. V_count = 0. Do 10 times. V_count = v_count + 1. Write / v_count. Enddo. Data: v_count type i. V_count = 0. While v_count < 10. V_count = v_count + 1. Write / v_count. Endwhile. Using EXIT, CONTINUE statements: EXIT: It is a statement which is used to exit or terminate the loop.

CONTINUE: This statement is used to continue the next iteration or cycle by ending the iteration. Ex: Data: v_count type i. V_count = 0. EXIT ex: Do 10 times. V_count = v_count + 1. If v_count =5. Exit. Endif. Write / v_count. Enddo. CONTINUE ex: Do 10 times. V_count = v_count + 1. If v_count = 5. Continue. Endif. Write / v_count. Enddo. SY-INDEX: *** It is a system variable which stores the loop iteration or cycle or loop index number, to specify whether it is a first loop or second or third etc. Ex: Do 10 times.

Write / sy-index. Enddo. Write sy-uline. Do 10 times. If sy-index = 5. Exit. Endif. Write / sy-index. Enddo. Displaying date:

Note: ***Always the date is stored in YYYYMMDD format, but it is displayed depending on user settings in SU3 Tcode.
Ex: Data: v_date1 type d. Data: v_date2 type dats. V_date1 = 20110331. V_date1 = 20110330. Write: / v_date1,

/ v_date2. Output: 31032011 30.03.2011 Changing user settings: Go to SU3 Tcode Click on defaults tab Change the date format to the required format Click on save Logout From SAP and re login into SAP Then only our changes will be effected Execute the same program, below is the output 03312011 03/30/2011 Using EDIT MASK: EDIT MASK is the statement which is used to change the date separators within the program, without changing at SU3 Tcode. Syntax: Write / v_date1 using edit mask __/__/____ Ex: Data: v_date1 type dats. V_date1= 20111230. Write: / v_date1 using edit mask __.__.____. Write: / v_date1 using edit mask __/__/____. Write: / v_date1 using edit mask __-__-____. DEBUGGING: It is an SAP tool to check how each statement is executed in a program There are two ways to start debugging Break point

Using /H on selection screen Break point: It is a point to break the execution of a program at a particular place is called break point. There are two types of break points 1.a. Static break point: It is a break point which is fixed in a program and which cannot be deleted automatically is called static break point. It is set using keyword BREAK-POINT. 1.b. Dynamic break point: It is a break point which is deleted automatically after some time is called dynamic break point. It is set by clicking on icon . Steps for debugging: Create a program as below Report zdebug no standard page heading. Data: v_name(15) type c. Data: v_pincode(6) type n. V_name = ibm india. V_pincode = 500082. Write: / v_name, / v_pindcode. Put the cursor on any line and click on break point symbol Execute the program, the ABAP debugger will starts Click on debugger Switch to classic debugger Double click on v_name, v_pincode Click on single step (F5) icon Check the program execution line by line The output will be displayed

Chapter 02

2. ABAP Dictionary
It is a central repository where we define and maintain the objects which are related to database. The objects are,

Database table: It is an object which stores data in the form of rows and columns. Each row is called as record, and each column is called as field. So, to define a table we have to define the fields first. Defining a field:

FIELD = DATA ELEMENT + DOMAIN Domain: It is an object which specifies technical information such as data type and length for a field is called domain. It also specifies sign, lower case, conversion routine, fixed values, and value table. Data element: It is an object which specifies semantic information such as field description, field labels (short, medium, long and heading). Advantages of data element and domain: Reusability: The same data element and domain can be reused by multiple table fields, instead of creating again and again. These are also used in creating foreign key relationship, search help, ale-idocs. Key field: A field which is used to identify the record uniquely is called a key field. In a table there should be at least one key field. We can create number of key fields (max 16 key fields). Steps to create domain:

Save, check and activate Steps to create data element: Go to SE11 Select data type Give a name, ex zcno Create -> select data element Provide short description Provide domain name as zcno Press enter Click on field label tab, specify short, medium, long and heading labels Save, check and activate Steps to create a table: Go to SE11 Provide the table name zcust_table Click on create Provide description Specify delivery class as A Specify display maintenance allowed Click on fields tab Provide the field name, data element name as below

Click on save Click on technical settings button Provide the details as data class -> APPL0, size category -> 0 Click on save and click on back Save and activate the table Creating records into the table: Go to SE11 Give the table name and click on change Click on utilities -> table contents -> create

Provide the cno, cname, city Repeat the same procedure and create the records Displaying the table contents: Click on utilities -> table contents -> display Click on execute button The records will be displayed

Create a table to store material data with below fields Material number, material type, material units, and material group. Components of table:

Delivery class: It specifies the type of the data that stored in a table. The data can be business data or system data. Business data means application data (master and transaction data). The following options are available. Display maintenance: It specifies whether the data should be displayed as well as maintained. Data maintenance means creation, deletion, and changing. There are 3 options available. Display maintenance allowed: Data is displayed and maintained

Delivery class
A C L G, E, S, W

Short text
Application table (master and transaction data) Customizing table; maintenance only by customer; not SAP import Table for storing temporary data, delivery report System data

Display maintenance not allowed: Data is not displayed and not maintained Display maintenance allowed with restrictions: Data is displayed, but maintenance is given only for some users based restrictions Data class: It specifies the physical area of a table inside the database.

Depending on the table we are suppose to select the required option. The options available are, Data Class APPL0 APPL1 APPL2 Description Master data, transparent tables Transaction data, transparent tables Organization and customizing

Master data: The data which never changes or which changes very rarely is called master data. Ex: cno, cname, city etc. Transaction data: The day to day business data or the data which changes every day is called transaction data. Ex: customer bank transaction data Organization data: The data which is related to organization or company like how many company codes, plants, sales organization etc, is called organization data. Size category: It specifies the maximum number of records that can be stored in a table. The possible options are available as below.

In the real time we always set size category as 0, because we have to use small amount of memory. Suppose if the memory is not sufficient the system will automatically increase the size. Size category 0 1 2 3 . . Number of data records of table expected 0 to 6,100 6,100 to 24,000 24,000 to 98,000 98,000 to 390,000

Buffer/cache memory: It is a temporary memory to store the data. It is mainly used to increase the system performance. The functionality of buffer is defined as below.

The system program/tables request for the data The system will check whether the data is available in cache/buffer memory If it is available the data will be immediately given back to the system program/table, thereby increasing the system performance Suppose if the data is not available, the request will be sent to database, and the response will be given back to buffer or cache memory to store a copy for future references After the copy is stored then the data will be given back to the system program/table Buffering options: Buffering not allowed: Data is not stored in buffer Buffering allowed but not switched off: Used by SAP Buffering switched on: Data is stored in buffer By default buffering not allowed will be selected. *** Buffering types: Single record buffer: Only first record will be stored in the buffer Fully buffered: All the records will be stored in the buffer Generic area: The key fields data is called generic area. Only generic area data will be stored in the buffer Client number: It is a unique number which is used to provide security to the data at the database level. The field name, data element, and domain for client number is MANDT. In the real time we use the client number (100,120), (200,220), (300,320).

Types of tables based on client number

i.

ii.

Client dependent table If the first field is MANDT, then it is i. called as client dependent table This table stores data in specific client ii. only

Client independent table If the first field is not MANDT, then it is called client independent table Data is stored in all clients without security

Client dependent table: Create a table by name zcust_table_dp with below fields.

Create some records in the table and display then. Now login to 810 client Open the table and display the data The data will not be available, because it is a client dependent table

What are the roles and responsibilities of an ABAP consultant? What is a ticket? What is the client number you are using in the project? (100) What is the system landscape of your project? What is a data dictionary? What is the difference between data element and domain? What is a key field? Can we create a table without a key field? (no) How many key fields can be created in a table? (16) What is a client number? What is the difference between client dependent and independent table?

Structure: It is a container of reusable fields Structures are defined in data dictionary Once the structures are defined we must include them in tables There are two options for including the structures in tables Include structure Append structure Difference between include structure and append structure: Include This option is used only with custom 1. tables 2. These include structures are reusable by 3. multiple tables Just give field name as .include and data element as structure name append Used only with standard SAP tables Not reusable Click on append structure button to create structure and add to table

1. 2. 3.

Ex on include structure: Step 1: Create a structure by name zaddr with fields city, country, postal code Go to SE11, select data type, provide a name zaddr Click on create and provide the description Specify the fields and data elements Component Rtype (field type) (reference) City Country Pcode Save and activate Steps 2: Include the structure in a table as below Open any table Provide the field name as .include, data element as structure name (zaddr) Enter The fields will be automatically copied

Component name (DE name) Zcity Zcountry zpcode

Click on Click on

or or

to display the fields to compress the fields

Note: Sometimes we may get unpredictable errors in a table, due to adding or deleting the fields in a table. To solve the error follow the below
steps. Go to SE14 Provide the table name Click on edit button Click on activate and adjust database button Ex on append structure: Business requirement: Add a custom field mname (middle name) to the standard SAP table kna1 (customer master table). Open the table kna1 in display mode Click on append structure button A pop-up is displayed, click on create icon Provide the append name zapp1 and press enter Provide the field name as mname and data element as zmname Save, activate and click on back Check the table in the field, it will be available at the bottom Currency and Quantity fields: For every currency and quantity field we have to specify the corresponding units also. CURR: It is the data type which is used to store the amount or price fields. CUKY: It is the data type which is used to store the corresponding units for the currency fields. QUAN: It is the data type which is used to specify the quantity for a material or stock. UNIT: It is the data type which is used to specify the units for the quantity fields. Steps for currency, quantity fields: First define a currency or quantity field using CURR or QUAN data types Then define the corresponding units using CUKY or UNIT data types Finally link the currency and quantity fields with the corresponding units by providing reference table name and reference field name

Ex on currency/quantity fields: Open any table Add the below fields

Field Amount Amt_units Quantity Qua_units

Data element Zamount Zamt_units Zquantity Zqua_units

Data type Curr(5,2) Cuky(5) Quan(5,2) Unit(3)

Reference table Yycust_table Yycust_table

Reference field Amt_units Qua_units

Save and activate the table Foreign key relation: The relation between two tables for validating the data is called foreign key relation. Validation means checking whether the va Check table: A master table which stores master data is called a check table. Foreign key table: A table which is linked with check table for validating the data is called foreign key table.

Steps for foreign key relation: Step 1: Create a table by name zcustomers with fields customer number and customer name, also create some records.

Step 2: Create another table by name zcustomers_bank with fields cno, bankid and bankname. Step 3: Create the foreign key relation as below Open the table zcustomer_bank Select cno field Click on foreign keys button Provide the check table name as zcustomer Click on generate proposal button Click on copy button Save and activate Step 4: Unit testing Click on utilities -> table contents -> create Enter the invalid customer number and click on save The error message will be displayed Real time ex on foreign key relation:

Domain with field values: It is used for validation at the domain level We have to maintain some fixed values at the domain, so that all the table fields will be referring to this domain will be checked against with the fix If a wrong value is entered system will raise the error message

This option is only used whenever the number of values are less than 10 or 15 If the values are more than 15, we go for foreign key relation The main advantage of domain with fixed values is reusability Steps: Open the table zcustomer_bank Add an extra field by name gender with data element and domain as zgender Now go to the domain zgender, double click on it Click on value range tab Maintain the fixed values as below Fix.val M F Male Female Short text

Save and activate the domain and the table Go to unit testing Enter the invalid value for gender The error will be displayed VALUE TABLE: *** A table name defined at the domain level so that all the table fields will be referring to the domain will be checked or validated with a single table called as value table. The main advantage of value table is to automate the system for foreign key relation i.e. the system will automatically display check table name along with proposal. Steps for value table: Create a table zzcustomer with field cno and cname, also create some records Maintain the check table name at domain level called as value table Go to the domain zcno Click on value range tab Provide the value table as zzcustomer Save and activate, domain and table Create another table by name zzcustomer_bank with fields cno, bankid, bankname Maintain the foreign key relation as below Open zzcustomer_bank table Select cno field and click on foreign key button A pop-up displayed as below

If we click on yes, foreign key relation will be automatically displayed If we click on no, it will not be displayed Differences between check table and value table:

Check table It is defined at field level FK relation is not automatic, that means we must enter check table name

Value table It is defined at domain level FK relation is automatic, that means once we maintain value table, FK relation will be automatically displayed

Domain properties: SIGN: It is used to store the sign of a number, whether it is positive sign or negative sign Lower Case: This option is used to store a value in the combination of capital and small letters *** By default SAP will convert the entire value into capital letters If we dont want capital letters, please select lower case option Conversion Routine: It is a sub-program or function module which is used to convert a value from internal format to external format and vice versa Conversion routine function modules: Go to any domain, ex: MATNR The conversion routine will be displayed, ex: MATN1 Double click on MATN1 The function modules will be displayed as below CONVERSION_EXIT_MATN1_INPUT: This function module is used to convert material number from external format to internal format. CONVERSION_EXIT_MATN1_OUTPUT: This function module is used to convert material number from internal format tot external format.

Table Maintenance Generator (SM30): It is a standard SAP program created in the form of function modules to maintain mass amount of data. Maintenance means creation, deletion and modification. It is also used for validating the table data using the concept of events. *** Steps for TMG: Create any table by name zcust with mandt, cno, cname and land1 Save and activate the table Click on utilities -> select table maintenance generator Provide the details as below Authorization group = &NC& Function group = zcust (table name) Maintenance type one step Click on find screen number button A pop-up is displayed, just press enter The screen number will be automatically proposed Click on create icon The TMG will be created in the form of function modules Activating TMG: Go to SE80 Select function group from the list Provide function group name (table name) and press enter Right click on function group name and select activate Unit testing: Go to SM30 Provide the table name Click on maintain button Enter customer number, name and country Click on save, the data will be saved Validations with TMG: The validation are possible using the concept called events There are around 39 events available For each event we need to provide a routine name (sub-program name)

Inside the routine we have to write the ABAP code for validating the data Events in TMG: Open the table Click on utilities and select TMG Click on environment -> modification -> events A new screen will be displayed Click on new entries button Click on help button on the first row, first column The 39 events will be displayed Main event 01 02 03 04 05 .. .. Short text Before saving the data in the database After saving the data in the database Before deleting the data displayed After deleting the data displayed Creating a new entry . .

Provide the routine name for any event in the second column T (event name) 05 Znew_rec Form routine (routine name)

New sub-program which will be created for writing the logic Ex on validation: Business Requirement: Raise an error message whenever a new record or customer is created without providing the country or land1. Create a table by name zkna1 with kunnr, land1, name1 fields Create a TMG Click on environment -> modifications -> events Click on new entries button Select the event 05 (creating a new record) and provide sub-routine name (sub-program name)

Event name 05 .. .. Znew_rec .. ..

Form routine

Editor
.

Click on editor icon Press enter 2 times (sub-program will be created automatically) Write the below ABAP code Form znew_rec. If zkna1_land1 = . Message please enter country type E. Endif. Endform. Save and activate Click on back, save Click on back, save Click on save An information message will be displayed as function group cant be processed Click on back -> back -> back Go to SE80 and activate function group Got SM30 and test it

Create a table by name zlfa1 with vendor number, name, date and user name. Create TMG and validate the TMG so that date and username automatically saved.

VIEWS
A view is collection of fields from multiple tables The multiple tables must be joined to create a view There must be at least one common field to create a view View does not store any data, it fetches the data from multiple tables and displays the data

JOINS
It is a concept which is used to join or combine two or more tables to read the data. There are two types of joins. Inner join Outer join or left outer join Inner join:

In this type of join (inner) it will display or fetch only the matching records between two or multiple tables. Outer join: In this type of join, it will display all the records from the left table or first table. Then it will check whether there are any matching records. If the matching records are available, it will display the data, else it will display the value as blank. Types of views: There are 4 types of views Database view Projection view Help view Maintenance view Database view: A view created on two or more tables using inner join concept is called database view In this view we can only read the data We cannot maintain the data We can provide selections to read the data Ex on database view: Develop a database view on MARA and MAKT tables to display material number, material type, material units, language and description. Go to SE11 Provide the view name zdb_view Click on create Select database view Provide description Provide the table names and joining condition

Click on view fields tab Click on table fields button Double click on MARA and select MATNR, MTART and MEINS

Click on copy Again click on table fields button Double click on MAKT and select SPRAS, MAKTX Click on copy Click on condition tab Provide the condition as below Table Makt Save and activate Click on contents Click on execute, the data will be displayed Spras Field name Eq Operation Comparison value E

Develop a database view on vbak and vbap tables to display vbeln, vkorg, vtweg, posnr, matnr and netwr. Develop a database view on ekko and ekpo tables to display ebeln, ekorg, ebelp and matnr. Projection view: A view created on single table is called projection view. Projection views are mainly used to minimize the database interface (number of fields) and improve the system performance. We can maintain the data in the projection views. We cannot provide any selections in the projection views. Ex on projection view: Go to SE11 Provide the view name zproj_view Click on create, provide description Provide the basis table as mara Click on table fields button Select matnr, mtart, mbrsh and meins Click on copy button Save and activate Click on contents and display the view

Maintaining the data: To maintain the data, we have to provide the key fields i.e. mandt, matnr Go to the view and add the first field as mandt Click on maintenance status tab Select read and change radio button Select display maintenance allowed Save, activate and display the data Help view: A view created on two or more tables using outer join concept is called help view. Help view are specially designed for search helps. We cannot execute help views directly, instead we have to include help views inside the search helps. We cannot maintain the data in help views. Ex on help views: Go to SE11 Provide the view name zhelp_view Click on create Provide description Provide the table name as makt and click on relationships button Select Click on copy, the join condition will be automatically displayed Click on view fields tab Provide the field names matnr, mtart, meins and maktx by clicking on table fields button Provide the selection condition if required Save and activate We cannot test this help view If we want to test we should create a search help Maintenance view: A view created on two or more tables using inner join concept is called maintenance views We can maintain the data in maintenance views Maintenance view are used by SAP for internal purpose In the real time we dont create any maintenance views because the data should be saved or modified in multiple tables which leads inconsistency If we want save or modify the data, we have to use standard SAP transactions or BAPIs Search Helps (SH): Providing a help functionality or F4 functionality for an input field is called search help. There are two types of search help. Elementary search help Collective search help

Elementary search help: Providing a single search help for an input field is called elementary search help. Collective search help: Collection of elementary search helps for an input filed is called collective search help. Assigning search helps: Once search helps are created we have to assign them At program-selection screen level At table-level At sap-screen level Selection-screen: Input screen to a program or search is called selection screen. Parameters: It is a keyword to declare or create an input field on the selection screen. Ex: Parameters p_kunnr(10) type c. Parameters p_matnr(20) type c. Match code object: It is a keyword which is used to assign a search help to the input fields on the selection screen. By default standard SAP search help will be displayed. If we dont want standard search help then we use match code object to assign our own search help. Syntax: Parameters: <parameter name> (length) type <data type> match code object <sh_name> Parameters: <parameter name> type <table-fname> (field name) match code object <sh_name> Ex on elementary search help: Go to SE11 Provide the search help name zel_sh Click on create and provide description Provide the selection method as mara Provide the search help parameter as below Search help parameter Matnr Mtart Save, activate and test it Imp Exp 1 2 Lpos 1 2 Spos Sids ..

Assigning search help at program-selection screen level: Go to SE38 Create a program by name zsh_prog Write the below code

Parameters: p_matnr1 type mara-matnr. Displays stands SHs Parameters: p_matnr2 type mara-matnr match code object zel_sh. Displays custom or our own SHs Assigning SHs at table level: Step 1: Create a table by name zcustomers with cno, name and city Step 2: Create a search help as below Go to SE11 Provide the SH name zsh_zcustomer Click on create and provide description Provide the selection method as zcustomer Provide the search help parameters as below SHP Cno Cname City Imp Exp 1 2 3 Lpos 1 2 3 Spos

Save, activate and test it Step 3: Let us assign the SH to the table Open the table zcustomer Select the cno field and click on SH button The proposal will be automatically generated Just change the proposal as below SHP Cno Cname City Table name Zcustomer Field name Cno

Press enter Save and activate the table Click on contents icon Click on help button of customer number filed The list of the values will be displayed Collective search help: A collection of elementary search helps is called collective search helps. Step 1: Create a elementary SH by name zel_sh1 with selection method as mara and sh parameters matnr, mtart. Step 2: Create another elementary SH by name zel_she2 with selection method as mara and sh parameters matnr, meins. Step 3: Create a collective search help as below Go to SE11 Provide the SH name zcoll_sh Click on crate and provide description Provide the SH parameters matnr, mtart and meins with import, export and data elements Click on included search helps tab Provide the first search help name as zel_sh1 and click on parameter assignment button Click on yes button the proposal will be generated automatically Provide the second search help name zel_sh2 and click on parameter assignment button Click on yes button the proposal will be generated automatically Save, activate and test it Finally assign the SH at the program level or table level Components of SH: Selection method: It specifies the table name or the view name from where the values have to be selected. Provide the table name, if the values have to be selected from single table. Provide the view name (help view), if the values have to be selected from multiple tables. SPOS: It specifies the position of the field on the selection-screen. LPOS: It specifies the position of the field on the list-screen. Importing: If this check box is selected, the value will be imported from selection screen to the list screen and corresponding values will be displayed. Exporting: If this check box is selected, the value by the user will be exported from the list screen to the selection screen.

Dialog type: It specifies whether the value restriction screen should be disabled or not. There are 3 options available. Display values immediately: The values will be immediately displayed without value restriction screen. Dialog with value restriction: The value restriction screen will be displayed first and then output values are displayed. Dialog depends on set of values: If values are less than 500, then values will be displayed immediately else value restriction screen will be displayed. Search Help Exit: It is a function module exit where we design the custom search help by writing the ABAP statements inside the function module, which is not possible with the direct data dictionary SH. The function module must be of type F4IF_SHLP_EXIT_EXAMPLE ***. That means the function module exit should contain the same importing and exporting parameters of standard SAP function module. F4IF_SHLP_EXIT_EXAMPLE

TYPE GROUP: (ABAP dictionary) It is an object which contains the reusable user defined types. Ex: SLIS is a type group given by SAP for developing ALV reports.

What is the difference between table and structure? What is the difference between append structure and include structure? What is the difference between check table and value table? What do you mean by fixed values with domain? What is a conversion routine? How do you enter lower case letters on the screen? What is a selection screen? What is a view does the view stores any data? What are the different types of the views? What is a SH and its types? What is a collective SH? What is a match code object? What is a parameter? What is a TMG and its Tcode? Can you validate the table data using TMG, if yes what are the events available? What is a SH exit, SPOS, LPOS, importing and exporting? Types of Tables: There are 3 types of tables. Transparent tables Pooled tables Clustered tables Transparent tables: These are used to store business data (master and transaction data). Whenever a transparent table is created in data dictionary the same table will be created in the database with the same name and the fields.

That means transparent tables will have one to one relation between data dictionary table and database table. By default all the tables created by ABAP consultants are called as transparent tables. Pooled tables: These tables are used to store system data like screen sequence data, historical data and statistical data. All the pooled tables from data dictionary will be stored in a single table by name TABLE POOL in database.

That means pooled tables will have many to one relationship between data dictionary tables and the database tables. The fields in the table pool are, TAB name stores name of the pooled table VARKEY stores key fields of pooled table DATALN stores length of the data VARDATA stores the data of pooled table continuously like notepad files Clustered tables: These tables are also used to store system data such as screen sequence, historical data and statistical data. These tables also have many to one relationship. All the clustered tables from data dictionary will be stored in a single table by name TABLE CLUSTER.

Cluster tables are same as pooled tables; the difference is cluster table stores the data in the form of pages with the time stamp (who created, when created and so on).

Chapter 03

3. INTERNAL TABLES

Internal table is a temporary memory location which can store the data from database table. By default the size of the internal table will be 8KB It can store n number of records The size of the internal table will increase dynamically

Work Area (WA): It is also temporary memory location which can store only a single record. All the operations on internal table must be executed via WORK AREA.

Syntax: (for internal table i.e. itab) Data <itab name> type table of <database table> Or Data <itab name> type table of <userdefined type> Or Data <itab name> type <database table> occurs 0 (obsolete statement) Syntax: (for work area i.e. wa) Data <wa name> type <database table> Or Data <wa name> type <userdefined type>

Data <wa name> type <database table> occurs 0 with header line (itab and wa will be created; obsolete statement) SELECT statement: It is the statement which is used to select data from database table into internal table (or) work area. Syntax: Select * (or) f1 f2 f3 From <database table> Into table <itab/wa> Where <f1> = <val> And <f2> = <val> . . . . . . LOOP. ENDLOOP: This statement is used to read each record from internal table into work area. Syntax: Loop at <itab> into <wa> . . . Endloop . Ex Business Requirement: Develop a report to display customer details. Report zcustomer_report . Data i_kna1 type table of kna1 . Data wa_kna1 type kna1 . Select * from kna1 into table i_kna1 where land1 = us . Loop at i_kna1 into wa_kna1 . Write : / wa_kna1-kunnr, wa_kna1-name1, wa_kna1-land1 . Endloop .

Develop a report display material details ( MARA) Develop a report to display vendor details (LFA1) User defined types: It is used to define our own TYPE with the fields required for the internal table. TYPES is the keyword to define a user defined type. Syntax: Types : begin of <type name>, f1 type <table-fname>, f2 type <table-fname>, ., End of <type name>. Ex on user defined types: Types: begin of ty_kna1, Kunnr type kna1-kunnr, Land1 type kna1-land1, Name1 type kna1-name1, Ort01 type kna1-ort01, End of ty_kna1. Data: i_kna1 type table of ty_kna1. Data: wa_kna1 type ty_kna1. Select kunnr land1 name1 ort01 From kna1 Into table i_kna1 Where land1 = us. Loop at i_kna1 into wa_kna1. Write: / wa_kna1-kunnr, wa_kna1-name1, wa_kna1-land1, wa_kna1-ort01. Endloop.

Select into corresponding fields: This statement is used whenever the selected fields and the internal table fields are miss matched, i.e. the source fields and the internal table fields are not in the proper order. Ex: Same program as above, do the change to select statement. Select * From kna1 Into corresponding fields of table i_kna1 Where land1 = us. Note: But itab (i_kan1) contains only 4 fields, so use select ., corresponding fields. This statement should never be used in the real time, because it puts unnecessary load on the select statement for comparing source and target fields. Operations on internal tables: Append Insert Sort Describe table Read table (with index and with key) Loop endloop Modify Delete Delete adjacent duplicates Clear Refresh Free Append lines of Insert lines of Move itab1 to itab2 Collect Append: This statement is used to add a record from work area to internal table. The record is always added at the bottom. Syntax: Append <wa> to <itab>.

Ex: Wa_kna1-kunnr = 1011. Wa_kna1-name1 = aaa. Wa_kna1-land1 = us. Append wa_kna1 to i_kna1. Insert: This statement is used to insert a record from work area to internal table at the specified location. Syntax: Insert <wa> into <itab> index <index number>. Ex: Wa_kna1-kunnr = 1022. Wa_kna1_name1 = bbb. Wa_kna1-land1 = in. Insert wa_kna1 into i_kna1 index 5. Sort: This statement is used to sort the internal table data either in ascending order or descending order. By default it will sort in ascending order based on field1, field2, field3etc. Syntax: Sort <itab> by f1, f2, f3 .. Ascending / Descending. Ex: Sort i_kna1 by kunnr. (by default it is ascending order ) Sort i_kna1 by land1 descending. (sorts in descending order) Sort i_kna1. (by default it sort in ascending order based on f1, f2, f3, . . . etc) Ex: Types: begin of ty_kna1 kunnr land1 name1 ort01 End of ty_kna1. Data: i_kna1 type table of ty_kna1. Data: wa_kna1 type ty_kna1.

Select kunnr land1 name1 ort01 From kna1 into table i_kna1 Up to 10 rows. Wa_kna1-kunnr = 1011. Wa_kna1-land1 = us. Wa_kna1-name1 = aaa. Append wa_kna1 to i_kna1. Wa_kna1-kunnr = 1022. Wa_kna1-land1 = in. Wa_kna1-name1 = bbb. Insert wa_kna1 into i_kna1 index 5. *sort i_kna1 by kunnr. *sort i_kna1 by land1 descending. Sort i_kna1. Loop at i_kna1 into wa_kna1. Write: / wa_kna1-kunnr, wa_kna1-land1, wa_kna1-name1. Endloop. Describe table: This statement is used to find the total number of records in a internal table. Syntax: (data: v_index type i.) Describe table <itab> lines <v_index>. Ex: Describe table i_kna1 lines v_lines. Write: / total customers are:, v_lines.

Read table with index: This statement is used to read a single record from internal table into work area given by the index number. Syntax: Read table <itab> into <wa> index <index number>. Ex: Read table i_kna1 into wa_kna1 index 5. Write: / wa_kna1-kunnr, wa_kna1-land1, wa_kna1-name1. Read table with key: This statement is used to read a single record from internal table into work area with field name and field value. Syntax: Read table <itab> into <wa> with key <field name1> = <field value> <field name2> = <field value> <field name3> = <field value> Binary Search. Ex: Read table i_kna1 into wa_kna1 with key kunnr = 1011 binary search. Write: / wa_kna1-kunnr, wa_kna1-land1, wa_kna1-name1. Binary Search: It is a search algorithm which is used to read the data very fastly from internal table The functionality of binary search is described below The entire internal table data will be divided into two halfs The system will search for the record either in the first half or second half based on rough estimation Suppose if the system assumes the record to be available in the first half, the entire second half will be deleted, thereby reducing half of the burden on the system Now the system will again divide the first half into two more halfs Again the system will search for the record either in the first half or second half Suppose if the record assume to be available in the second half, the entire first half will be deleted, thereby reducing 75% burden on the system The process will continue until it finds the exact record

Note: ***The prerequisite for binary search is the internal table should be sorted in ascending order.
(Program continuation) Data: v_lines type i. Describe table i_kna1 lines v_lines. Write: / total customers are:, v_lines. Loop at i_kna1 into wa_kna1. Write: / wa_kna1-kunnr, wa_kna1-name1, wa_kna1-land1, wa_kna1-ort01. Endloop. Write / sy-uline. Read table i_kna1 into wa_kna1 index 5. Write: / wa_kna1-kunnr, wa_kna1-name1, wa_kna1-land1, wa_kna1-ort01. Write / sy-uline. Sort i_kna1 by kunnr.

Read table i_kna1 into wa_kna1 with key kunnr = 1011 binary search. Write: / wa_kna1-kunnr, wa_kna1-name1, wa_kna1-land1, wa_kna1-ort01. Loop Endloop: This statement is used to read multiple records from internal table into work area serially one by one, one by one. Syntax: Loop at <itab> into <wa> . Endloop. Loop at <itab> into <wa> where <f1> = <val> and <f2> = <val> and <f3> = <val> . Endloop. Loop at <itab> into <wa> from <n1> to <n2> endloop.

A real time example on loopendloop - Business requirement: Develop a customer master report to display customer details along with the bank details (kna1, knbk). Modify: This statement is used to modify a single record or multiple records based on the condition. Syntax: Modify <itab> from <wa> index <index number> transporting <f1> <f2> <f3> Modify <itab> from <wa> transporting <f1> <f2> <f3> .where <condition>. Transporting: This keyword specifies the list of the fields to be modified from work area to internal table. SY-TABIX: (SY: system, TAB: internal table, IX: index) this system variable automatically stores the index number of the internal table record which is currently processed in the work area. SY-INDEX: It is a system variable which stores the loop [ do-endo, while-endwhile ] iteration or cycle number. Ex1: Sort i_kna1 by kunnr. Read table i_kna1 into wa_kna1 with key kunnr = 1011 binary search. Wa_kna1-land1 = usa. Modify i_kna1 from wa_kna1 index sy-tabix transporting land1.

Loop at i_kna1 into wa_kna1. Write: / wa_kna1-kunnr, wa_kna1-name1, wa_kna1-land1, wa_kna1-ort01. Endloop. Ex2: (modifying multiple records) Wa_kna1-land1 = usa. Modify i_kna1 from wa_kna1 transporting land1 where land1 = us. Loop at i_kna1 into wa_kna1. Write: / wa_kna1-kunnr, wa_kna1-name1, wa_kna1-land1, wa_kna1-ort01. Endloop. Delete: This statement is used to delete a single record or multiple records depending on the condition. Syntax: Delete <itab> index <index number>. Delete <itab> where <f1> = <val> and <f2> = <val> and <f3> = <val>. . Ex1: (deleting single record) Delete i_kna1 index 5. Loop . Endloop. Ex2: (deleting single record) Delete i_kna1 where kunnr = 1011. Loop. Endloop. Ex3: (deleting multiple records) Delete i_kna1 where land1 = us Loop. Endloop. Delete adjacent duplicates: This statement is used to delete the duplicate records which are adjacent to each other (side by side). The prerequisite for the statement is the internal table should be sorted.

Syntax: Delete adjacent duplicates from <itab> Comparing <f1> <f2> <f3>. (or) Comparing ALL fields. Ex: Wa_kna1-kunnr = 1022. Wa_kna1-land1 = in. Wa_kna1-name1 = bbb. Insert wa_kna1 into index 5. Insert wa_kna1 into index 8. Insert wa_kna1 into index 3. Sort i_kna1 by kunnr. Delete adjacent duplicates from i_kna1 comparing all fields. Loop at i_kna1 into wa_kna1. Write: / wa_kna1-kunnr, wa_kna1-name1, wa_kna1-land1, wa_kna1-ort01. Endloop. Clear: This statement is used to clear or delete the data from work area. In the old version the clear statement was also used to clear the data from internal table also. Syntax: Clear <wa>. Clear <itab> [ ]. (body 8K of itab, i.e. old syntax) Ex: Append wa_kna1 to i_kna1. Clear wa_kna1. Refresh: This statement is used to delete the data from internal table only. Syntax: Refresh <itab>.

Ex: Refresh i_kna1. Free: This statement is same as clear and refresh. The difference is, the free statement will delete the data as well as memory also. But the clear and refresh statements will delete only data but not memory. Syntax: Free <wa/itab>. Ex: Free i_kna1. Free wa_kna1. Append lines of: This statement is used to append multiple records from one internal table to another internal table. Syntax: Append lines of <itab1> from <n1> to <n2> to <itab2>. Ex: Data: i_kna1 type table of ty_kna1. Data: i_kna1_tmp type table of ty_kna1. Data: wa_kna1 type ty_kna1. Select kunnr name1 land1 From kna1 into table i_kna1 Up to 10 rows. Append lines of i_kna1 from 3 to 5 to i_kna1_tmp. Loop at i_kna1_tmp into wa_kna1. Write: / wa_kna1_tmp-kunnr, wa_kna1_tmp-name1, wa_kna1_tmp-land1. Endloop. Insert lines of: This statement is used to insert multiple records from one internal table to another internal table at a specified location.

Syntax: Insert lines of <itab> from <n1> to <n2> into <itab2> index <index number>. Ex: Same program as above with below change. Insert lines of i_kna1 from 6 to 8 into i_kna1_tmp index 2. Move itab1 to itab2: This statement is used to move all the data of one internal table to the other internal table. Syntax: Itab2 [ ] = itab1 [ ]. Ex: I_kna1_tmp [ ] = i_kna1 [ ]. Loop at i_kna1_tmp into wa_kna1. .. Endloop. (Or) Loop at i_kna1 into wa_kna1. Append wa_kna1 to i_kna1_tmp. Endloop. Loop at i_kna1_tmp to wa_kna1. .. Endloop.

What is the output of program? Loop at i_kna1 into wa_kna1. Append wa_kna1.

Write: / wa_kna1-kunnr, wa_kna1-name1, wa_kna1-land1. Endloop. Collect:

Collect statement is same as append statement. The difference is, the append statement will append the record from work area to internal table without checking Whereas the collect statement will check whether the work area record already exists in the internal table with the same key (C, N, D, T data types) If yes it will add the numerical fields If no it will append record *** Syntax: Collect <wa> into <itab>. Ex: Types: begin of ty_kna1, Kunnr type kna1-kunnr, Name1 type kna1-name1, Amount type I, End of ty_kna1.

Data: i_kna1 type table of ty_kna1. Data: wa_kna1 type ty_kna1. Wa_kna1-kunnr = 1011. Wa_kna1-name1 = reliance. Wa_kna1-amount = 100. Collect wa_kna1 into i_kna1. Wa_kna1-kunnr = 1022. Wa_kna1-name1 = hero motor corp. Wa_kna1-amount = 200. Collect wa_kna1 into i_kna1. Wa_kna1-kunnr = 1011. Wa_kna1-name1 = reliance. Wa_kna1-amount = 50. Collect wa_kna1 into i_kna1. Write: / wa_kna1-kunnr, wa_kna1-name1, wa_kna1-amount. Endloop. Types of internal tables: There are three types of internal tables. Standard internal table Sorted internal table STANDARD ITAB Hashed internal table
1. 2.

3.
4. 5. 6.

These are the default itabs created by ABAP consultants We can read a record using index or key We can use either linear search or binary search for reading a record If we use linear search, then, response time number of records If we use binary search then , response time (number of records) We can sort these internal tables wherever we want

1.

2.

3. 4.

SORTED ITAB These are not default itabs, they are special type of itabs where the data is automatically sorted whenever you insert the data into the table The data is inserted using the insert statement, not the append statement (we cant use append here) It uses only binary search since the data is already sorted The response time is Response time= ( N)

1.

2.

3.

4.

5.

HASHED ITAB These are not default internal tables, these are also special type of itabs where we can use only key operations That means for reading a record we can use the key operation, we cant use index operation The response time is always constant regardless of the number of records Hashed tables should be used only when we want to work with all the fields of database table and with all records, i.e. when working with mass amount of data The response time is constant because it will be using hashed algorithms

Obsolete (outdated) way of declaring itab: Occurs 0: Defines 8KB body for itab Occurs 0 with header line: Defines itab with 8KB body and implicit (automatic) header (wa) Syntaxes: Data: <itab> type <dbtable> occurs 0. (only body is created) Data: <itab> type <db table> occurs 0 with header line. (body and header [wa] will be created by same name) Data: <wa> type <db table>. (only header [wa] will be created) Data: begin of <itab> occurs 0, f1 type table-fname, f2 type table-fname, f3 type table-fname end of <itab>. (body and header [wa] will be created with user defined fields) Operations on old syntaxes:

1. 2. 3. 4. 5.

OPERATION Append Insert Read table Loop . Endloop Modify

1. 2. 3. 4. 5.

NEW SYNTAX Append <wa> to <itab> Insert <wa> into <itab> index <number> Read table <itab> into <wa> index / with key Loop at <itab> into <wa> Modify <itab> from <wa> index <number> transporting f1 f2 f3 .

1. 2. 3. 4. 5.

OLD SYNTAX Append <itab> Insert <itab> index <number> Read table <itab> index / with key Loop at <itab> Modify <itab> index <number> transporting f1 f2 f3 .

What is an itab and wa? How much size will be allocated for itab and wa? What is the difference between append and insert, append and collect? How do you find total number of records in an internal table? What is binary search explain it? What is the prerequisite for binary search? What is transporting? What is the difference between sy-index and sy-tabix? *** What is the difference between clear, refresh and free? *** How do you move the data from one itab to another itab? How do you move limited records from one itab to another itab? What is occurs 0, header line? What are the different types of itabs? What is types statement? Do we use select corresponding fields, if no why?

Chapter 04

4. OPEN SQL
SAP is database independent, i.e. SAP can use any database (oracle, sql server, my sql, Sybase, db2 etc) to store the data SAP can understand only ABAP. But the databases can understand only their own language, i.e. oracle can understand pl/sql and sql server can understand t-sql So the communication between SAP ABAP and the databases is difficult To avoid this difficulty we need an interface which is automatically provided by SAP by name R/3 Interface Layer

Open SQL: The statements which are converted from ABAP to respective database statements by R/3 interface layer are called as open SQL statements. Native SQL: The statements which directly communicate with database without interacting with R/3 interface layer are called as native SQL statements. Note: In the real time we will be working with open SQL statements only ***. List of open SQL statements: Insert <db table> from table <itab>. (Multiple records) Insert <db table> from <wa>. (Single record) Update <db table> from table <itab>. Update <db table> from <wa> Modify <db table> from table <itab>. Modify <db table> from <wa>. Delete <db table> from table <itab>. Delete <db table> from <wa>.

System variables used with open SQL: There are two system variables which get updated automatically whenever an open SQL statement is executed. SY-SUBRC: (System sub-operation return code) sy-subrc is a system variable which specifies whether the open SQL statement is successful or not. Sy-subrc = 0, it is successful. Sy-subrc = 0, it is unsuccessful. SY-DBCNT: (System database count) this system variable specifies how many records are successfully processed with an open SQL statement. Difference between modify, insert and update: Insert: It will insert the data into database table from itab or work area. Update: It will update the record, if the record already exists in the database table. If the record does not exist it does not update any record.

Modify:

Modify statement works as insert or update. If the record already exists it will work as update else it will work as insert. Note: When working with the open SQL statements the internal table should be declared directly referring to database tables not the user defined types. Ex: Data: i_kna1type table of ty_kna1.

Data: i_kna1 type table of kna1. Update: There are two types of updates.

Syntax Update <db table> From <wa>.

Syntax Update <db table> Set <f1> = <val> <f2> = <val> .. Where <condition>.

Ex on open SQL(T001W Plant/Branches): Report zopen_sql. Data: i_t001w type table of t001w. Data: wa_t001w type t001w. Wa_t001w_werks = hyd1. Wa_t001w_name1 = hyd plant1. Append wa_t001w to i_t001w. Wa_t001w_werks = hyd2. Wa_t001w_name1 = hyd plant2. Append wa_t001w to i_t001w. Insert t001w from table i_t001w. Delete t001w from table i_t001w. Update t001w from table i_t001w. Update t001w set ort01 = panjagutta where werks = hyd1.

Modify t001w from table i_t001w. If sy-subrc = 0. Write: / plants are successfully inserted / updated / modified:, sy-dbcnt. Else. Write: / plants are not inserted / updated / modified. Endif. Select . With joins: This statement is used to fetch the data simultaneously from multiple database tables There should be at least one common field between the tables to fetch the data The tables must be joined using inner join/outer join In the real time this is used only for two or three internal tables It should not be used for more than three tables because it puts heavy load on the database Syntax: Select t1~f1 t1~f2 t2~f1 t2~f3 t3~f1 t3~f2 Into table <itab> From <t1> as <alias name> inner join/left outer join <t2> as <alias name> on <t1>~f1 = <t2>~f1 Inner join/left outer join <t3> as <alias name> on <t1>~f1 = <t3>~f1 Where <condition>. Ex: Business requirement: Develop a report to display material details and description details (mara, makt). Types: begin of ty_mara_makt, Matnr type mara-matnr,

Mtart type mara-mtart, Meins type mara-meins, Spras type makt-spras, Maktx type makt-maktx, End of ty_mara_makt. Data: i_mara_makt type table of ty_mara_makt. Data: wa_mara_makt type ty_mara_makt. Select a~matnr a~mtart a~meins b~spras b~maktx Into table i_mara_makt From mara as a inner join makt as b on a~matnr = b~matnr Where b~spras = en. Loop at i_mara_makt into wa_mara_makt. Write: / wa_mara_makt-matnr, wa_mara_makt-mtart, wa_mara_makt-meins, wa_mara_makt-spras, wa_mara_makt-maktx. Endloop. Select. For all entries: This statement is used to replace inner joins This statement can be used to fetch the data from more than three tables, that means select with joins must be used only for two or three tables If we want to fetch the data from more than three tables then use SELECTFOR ALL ENTRIES Syntax: Select .

From <database table> into table <itab> For all entries in <itab2> Where <f1> = <itab2>-f1 and <f2> = <itab2>-f2. Itab2 is an internal table which already has some data. ***** The prerequisite for select for all entries is, the internal table should be checked whether it is empty or not. Suppose if for all entries table is empty, the where condition fails and all the records will be fetched irrespective of condition Suppose if the for all entries table is not empty the where condition will be success and only the matching records will be fetched from the database Ex1: Types: begin of ty_mara, Matnr type mara-matnr, Mtart type mara-mtart, Meins type mara-meins, End of ty_mara. Types: begin of ty_makt, Matnr type makt-matnr, Spras type makt-spras, Maktx type makt-maktx, End of ty_makt. Data: i_mara type table of ty_mara. Data: i_makt type table of ty_makt. Data: wa_mara type ty_mara. Data: wa_makt type ty_makt. Wa_mara-matnr = 100-100.

Wa_mara-mtart = halb. Wa_mara-meins = st. Append wa_mara to i_mara. Wa_mara-matnr = 100-120. Wa_mara-mtart = roh. Wa_mara-meins = st. Append wa_mara to i_mara. If i_mara is not initial. Select matnr spras maktx From makt into table i_makt For all entries in i_mara Where matnr = i_mara-matnr. Endif. *Loop at i_mara into wa_mara. *Loop at i_makt into wa_makt where matnr = wa_mara-matnr. *Write: / wa_mara-matnr, wa_mara-mtart, wa_mara-meins, wa_makt-spras, wa_makt-maktx. *Endloop. *Endloop. Sort i_mara by matnr. Sort i_makt by matnr. Loop at i_makt into wa_makt. Read table i_mara into wa_makt with key matnr = wa_makt-matnr binary search. Write: / wa_mara-matnr, wa_mara-mtart, wa_mara-meins, wa_makt-spras, wa_makt-maktx. Endloop.

Ex2 on selectfor all entries: Types: begin of ty_final, Matnr type mara-matnr, Mtart type mara-mtart, Meins type mara-meins, Spras type makt-spras, Maktx type makt-maktx, End of ty_final. Types: begin of ty_mara, Matnr type mara-matnr, Mtart type mara-mtart, Meins type mara-meins, End of ty_mara. Types: begin of ty_makt, Spras type makt-spras, Maktx type makt-maktx, End of ty_makt. Data: i_mara type table of ty_mara. Data: i_makt type table of ty_makt. Data: i_final type table of ty_final. Data: wa_mara type ty_mara. Data: wa_makt type ty_makt. Data: wa_final type ty_final. Parameters: p_mtart type mara-mtart.

Select * From mara into table i_mara Where mtart = p_mtart. Select * From makt into table i_makt For all entries in i_mara Where matnr = i_mara-matnr. Sort i_mara by matnr. Sort i_makt by matnr. Loop at i_makt into wa_makt. Read table i_mara into wa_mara with key matnr = wa_makt-matnr binary search. Wa_final-matnr= wa_mara-matnr. Wa_final-mtart = wa_mara-mtart. Wa_final-meins = wa_mara-meins. Wa_final-spras = wa_makt-spras. Wa_final-maktx = wa_makt-maktx. Append wa_final to i_final. Clear: wa_final, wa_mara, wa_makt. Endloop. Loop at i_final into wa_final. Write: / wa_final-matnr, wa_final-mtart, wa_final-meins, wa_final-spras, wa_final-maktx. Endloop.

Develop a customer master report to display master details and bank details (kna1, knbk) Develop a sales order report to display header details and item details (vbak, vbap) Develop a delivery report to display header details and item details (likp, lips) Develop a invoice/billing report to display header details and item details (vbrk, vbrp)

Chapter 05

5. SD FLOW (SALES AND DISTRIBUTION)

Header data: The data related to organization or company or plant etc is called header data. Item data: The data which is related to item or products or materials is called item data. Select single/ up to 1 rows: Select single It is used to read exact record (single record) To read the exact record we need all key fields It is used for validation when all key fields are available It is faster, because all the key fields are available Syntax Select single * or .. From <database table> Into <wa> Where <specify all key fields> Select.up to 1 rows It is used to read appropriate record (single record) To read appropriate record we need some key fields, not all the key fields It is also used for validation when some key fields are available in program It is slow, because all the key fields are not available Syntax Select From <database table> Into <wa> Where <specify part of key fields> End select.

Ex: Report zopen_sql. Data: v_matnr type mara-matnr. Data: v_prctr type cepc-prctr. Parameters: p_matnr type mara-matnr. Parameters: p_prctr type cepc-prctr. Select single matnr From mara Into v_matnr Where matnr = p_matnr. If sy-subrc <> 0. Message invalid material number type E. Else. Write: / v_matnr color 5. Endif. Select prctr From cepc Into v_prctr Where prctr = p_prctr End select. If sy-subrc <> 0. Message invalid profit center number type E. Else. Write: / v_prctr color 5. Endif.

Select screen statements: Input screen to a program or report is called as selection screen. Statement Parameters Select-options Selection-screen commands Description Used to create input field, check box, radio buttons Used to create two input fields for entering range of numbers Set of statements for designing selection screen beautifully

Parameters: This statement is used to create a single input field check box, radio buttons. Syntax: Parameters: <pname> type <table-fname>. Parameters: <pname> type <table-fname> obligatory. (means mandatory field) Parameters: <pname> as check box. Parameters: <pname> radio button group <group name> default X. Note: Whenever a check box or radio button is selected the value X will be stored in the corresponding parameter variable. Ex: (on parameters) Parameters: p_kunnr type kna1-kunnr obligatory. Parameters: p_land1 type kna1-land1. Parameters: p_dload as checkbox. Parameters: p_rb1 radiobutton group aaa. P_rb2 radiobutton group aaa default X. P_rb3 radiobutton group aaa. If p_dload = X. Write: / check box is selected. Else. Write: / check box is not selected. If p_rb1 = X. Write: / radio button 1 is selected. Elseif p_rb2 = X. Write: / radio button 2 is selected. Elseif p_rb3 = X. Write: / radio button 3 is selected. Endif.

Select-options: This statement is used to create two input fields so that we can enter a range of values. In addition to that we can enter, Multiple single values (1, 7, 15, 17, 33, 99, ..) Multiple ranges (1-10, 25-29, 66-100, .) Exclude single values (4, 14, 33, ..) Exclude ranges (22-56, 67-98, .) All the above options are only visible when you click on multiple selection or extension box . Syntax: Select-options: <so-name> for <table-fname>. Select-options: <so-name> for <table-fname> no intervals. (only lower input field is displayed) Select-options: <so-name> for <table-fname> no-extension. (extension box is not displayed) Select-options: <so-name> for <table-fname> no intervals no-extension. Note: Whenever we use select-options with the select statement, we have to use IN operator instead = operator in the where condition. Ex: (on select-options) Tables kna1. Data: i_kna1 type table of kna1. Data: wa_kna1type kna1. Select-options: s_kunnr1 for kna1-kunnr. Select-options: s_kunnr2 for kna1-kunnr no intervals. Select-options: s_kunnr3 for kna1-kunnr no-extension. Select-options: s_kunnr4 for kna1-kunnr no intervals no-extension. Select * From kna1 Into table i_kna1 Where kunnr in s_kunnr1. Loop at i_kna1into wa_kna1.

Write: / wa_kna1-kunnr, wa_kna1-name1. Endloop. Select-options internal table: Whenever we declare select-options, an internal table will be created automatically in the back end. The fields of the internal table are, Sign Option Low High *** Sign: Stores I (inclusive) or E (exclusive) I means only specified values will be selected E means only specified values will be excluded Option: Stores the option like BT, NB, EQ, NE, LT, LE, GT and GE. By default BT is stored. Low: Stores lower value entered on selection screen. High: Stores higher value entered on selection screen. Selection screen commands: These are used to design the selection screen beautifully. Selection-screen uline: Displays horizontal line on selection screen. Selection-screen skip: Displays blank line on selection screen. Selection-screen begin of block <block name> with frame title <text-001>. ..... Selection-screen end of block. (displays a block for selection screen elements) Selection-screen begin of line. selection-screen end of line. (displays selection Screen elements in a horizontal line) Selection-screen comments pos(width) <text>. (displays a field label/text for selection screen element) Selection-screen texts: It is used to provide our own labels or data dictionary field labels or meaningful texts for the selection screen input fields Go to SE38 -> open any program Create a parameter statement ex:- p_kunnr type kna1-kunnr -> now click on goto-> text elements -> selection texts Click on save and test the program

Variants: Saving the selection screen data into an object for future references is called a variant Enter the data on selection screen fields Click on save Provide the variant name and description as test1 Click on save, the variant will be created Ex on selection-screen commands: Selection-screen begin of block b1 with frame title text-001. Select-options: s_kunnr for kna1-kunnr. Selection-screen uline. Parameters: p_land1 type kna1-land1. Selection-screen skip. Parameters: p_matnr type mara-matnr. Selection-screen end of block b1. Selection-screen begin of block b2 with frame title text-002. Selection-screen begin of line. Selection-screen comment 2(15) text-003. Parameters: p_lifnr type lfa1-lifnr. Selection-screen comment 30(10) text-004. Parameters: p_land2 type lfa1-land1. Selection-screen end of line. Selection-screen end of block b2.

Chapter 06

6. MODULARIZATION IN ABAP
Dividing the main program into sub-programs for better readability and reusability is called modularization technique

Modularization is implemented in the form of, Include programs Function modules Sub-routines Classes and methods Macros (used in HR ABAP)

Include Programs It is a sub-program which contains set of reusable statements It does not contain any parameter interface, i.e. no importing and no exporting parameters These sub-programs cant be executed independently To execute the sub-programs we must insert them inside the main program for execution Syntax: Include zxyz. Double click and create Ex: Report zmoudlarization. Include z_modularization_top. (Tables kna1. Data: i_mara type table of mara. Data: wa_mara type mara.) Selection-screen begin of block b1 with frame title text-001. Select-options: s_kunnr for kna1-kunnr. Parameters: p_land1 type kna1-land1. Selection-screen end of block b1. Include zmodularization_getdata. (Select * from mara Into table i_mara Where kunnr in s_kunnr and land1 = p_land1.) Include zmodularization_dispdata. (Loop at i_kna1 into wa_kna1. Write: / . . Endloop.) Function Modules: It is also a sub-program which contains set of reusable statements for reusability Function modules are mainly used for reusability Ex: GUI_UPLOAD: upload data into internal table from flat file GUI_DOWNLOAD: download data into internal table SPELL_AMOUNT: converts amount into words

KD_FILENAME_GET_ON_F4: provides browse option for searching a file Function module contain parameter interface, i.e. importing and exporting parameters Function modules can be executed independently They can also be executed from the main program Function Group: It is a container or group of function modules First we have to create function group then we should create the function modules SE80 or SE37 are T-codes for function group Components of Function Module: Importing: Input parameters (variables or work areas) are called as importing parameters Exporting: Output parameters (variables or work areas) are called as exporting parameters Changing: Parameters (variables or work areas) which act as importing or exporting are called as changing Tables: Internal tables (8kb size) which act as importing or exporting are called as tables parameters Exceptions: These are used to catch certain types of the errors in the function module Source Code: It contains the original logic or set of reusable statements for a specific task Steps to create function group: Go to SE80 Select function group from the list Provide a function group name Zfg1_funcgroup -> enter Provide the description Click on save and activate Or Go to SE37 Click on goto -> function group -> create group Provide function group name, description Save and activate

Steps to create a function module: Business requirement: Develop a reusable function module to display customer details. Step 1: Create a function module in SE37 as below Go to SE37, Provide function module name zget_cust_details Click on create Provide the function group name, description Click on save Provide the importing parameter as below Im_kunnr type kna1-kunnr Provide the exporting parameter as below Ex_kna1 type kna1 Provide the exception as below No_kunnr no_kunnr Write the below source code If im_kunnr is initial. Raise no_kunnr. Else. Select single * from kna1 Into ex_kna1 Where kunnr = im_kunnr. Endif. Save, activate and test it Note: Whenever an exception is raise from function module, it is caught or stored in SY-SUBRC system variable. *** Step 2: Calling the function module in main program Click on pattern button Provide the function module name and press enter The code will be automatically generated Modify the code as below Data: wa_kna1 type kna1. Parameters: p_kunnr type kna1-kunnr. Call function zget_cust_details Exporting Im_kunnr = p_kunnr Importing Ex_kna1 = wa_kna1

Exceptions No_kunnr = 1 Invalid_kunnr = 2 Others = 3. If sy-subrc = 0. Write: / wa_kna1-kunnr, wa_kna1-land1, wa_kna1-name1. Elseif sy-subrc = 1. Message please enter customer number type E. Elseif sy-subrc = 2. Message please enter valid customer number type E. Endif. DEBUGGING: Single step (F5): This button is used for line by line execution in the debugging. Execute (F6): This button is used to execute a sub-program (function module or sub-routine) at a single click. Return (F7): This button is used to return from sub-program to main program. Run to (F8): This button is used to run to the next break point available. If the break point is not available it will execute the entire program. Watch point: A point to watch for a particular value in a program is called watch point. Ex: Loop at i_kna1 into wa_kna1. Write: / wa_kna1-kunnr, wa_kna1-land1, wa_kna1-name1. Endloop. Execute the program in the debugging Double click on wa_kna1-kunnr Put the cursor on wa_kna1-kunnr and click on watch point Provide the relational operator as = and comparison value as 6666 Press enter, a watch point is created Now click on F8, watch point will be immediately reached

Develop a FM to display vendor details(lfa1) Import: im_lifnr -> type -> lfa1-lifnr Exception: no_lifnr.

Invalid_lifnr. Source code: if i_lifnr is initial. Raise no_lifnr. Else. Select single * from lfa1 into ex_lfa1 where lifnr = im_lifnr. Endif. If sy-subrc <> 0. Message please enter valid number type E. Endif. (Calling function module in program) Data: wa_lfa1 type lfa1. Parameters: p_lifnr type lfa1-lifnr. Call function zget_vendor_details Exporting Im_lifnr = p_lifnr Importing Ex_lfa1 = wa_lfa1 Exceptions No_lifnr = 1 Invalid_lifnr = 2 Others = 3. If sy-subrc = 0. Write: / wa_lfa1-lifnr, wa_lfa1-land1. Elseif sy-subrc = 1. Message please enter value type E. Elseif sy-subrc = 2. Message please enter valid number type E. Endif. Develop a FM to display material details (mara) Import: im_matnr -> type -> mara-matnr. Export: ex_mara -> type -> mara. Exception: no_matnr. Invalid_matnr. Source code: if im_matnr is initial. Raise no_matnr. Else. Select single * from mara into ex_mara where matnr = im_matnr.

Endif. If sy-subrc <> 0.


Message please enter valid material number type E. Endif. (Calling function module) Data: wa_mara type mara. Parameters: p_matnr type mara-matnr. Call function zget_material_details Exporting Im_matnr = p_matnr Importing Ex_mara = wa_mara Exceptions No_matnr = 1 Invalid_matnr = 2 Others = 3. If sy-subrc = 0. Write: / wa_mara-matnr, wa_mara-meins, wa_mara-mtart. Elseif sy-subrc = 1. Message please enter number type E. Elseif sy-subrc = 2. Message please enter valid material number type E. Endif. Ex Using tables, changing parameters: Business requirement: Develop a reusable function module to display list of the customers for a given country code Go to SE37 Provide the function module name zget_cust_list Click on create, provide function group, name and description Provide the parameters as below Im_land1 -> type -> kna1-land1. (Tables): i_kna1 -> like -> kna1. (Changing): v_name -> type -> kna1-name1.

Write the below source code Select * from kna1 into table i_kna1 where land1 = im_land1. If v_name = ibm. V_name = international business machines. Elseif v_name = tcs. V_name = tata consultancy services. Endif. Endfunction. Save, activate and test it

Calling the function in main program: Parameters: p_land1 type kna1-land1. Data: i_kna1 type table of kna1. Data: wa_kna1 type kna1. Data: v_name type kna1-name1. V_name = ibm. Call function zget_cust_list Exporting Im_land1 = p_land1 Tables I_kna1 = i_kna1 Changing V_name = v_name. Write: / sy-uline. Write: / v_name color 5. Write: / sy-uline. Loop at i_kna1 into wa_kna1. Write: / wa_kna1-kunnr, wa_kna1-name1. Endloop.

Develop a reusable function module to display sales order items for a given sales order (vbap, vbak) Develop two reusable function module to display delivery details, invoice details for given delivery number , invoice number

SUB ROUTINES
Sub routines: It is also a sub program which contains reusable statements Subroutines are mainly used for readability of a program Sometimes they can also be used for reusability Subroutines contains parameters interface i.e. import, exporting parameters Subroutines cant be executed independently We cant handle exceptions in subroutines Subroutines are called as local modularization, whereas function modules are called as global modularization Syntax: This syntax is of two steps Subroutine definition or declaration: Perform <subroutine name> using <v1> <v2> Changing <cv1> <cv2> Tables <itab1> <itab2>. Form <subroutine name> using <fv1> <fv2> Changing <fcv1> <fcv2> Tables <fitab1> <fitab2>. . . Endform. Components of subroutine: Using: It acts as importing parameters Changing: It acts as exporting parameters Tables: Itabs acts as importing and exporting parameters

Actual Parameters

Formal Parameters

Types of subroutines: There are two types of subroutines Internal subroutines or local subroutines External subroutines

Local sub-routines: If sub routine definition and implementation are available in the same program, it is called as local sub routines. External sub-routines: If sub routine definition and implementation are available in separate programs then it is called as external sub routines. Passing values between sub-routine definition and implementation: There are 3 ways to pass the values, Pass by reference (same memory) Pass by value (separate memory) Pass by value and return (separate memory) Pass by reference: In this step, the actual and formal parameters will be referring to same memory. Suppose if the formal parameter is changed, actual parameters will also be changed, since they are referring to same memory. Pass by reference is identified by key word USING. Perform abcd using a.

Form abcd using f_a.

.. .. Endform. Pass by value: In this step the actual and formal parameters will be referring to separate memory. Suppose if the formal parameter is changed, the actual parameter will not be changed, since they are referring to separate memory.

Perform abcd using a.

Form abcd using value(f_a).

.. .. f_a = f_a + 10. .. .. Endform. Pass by value is identified by the key word USING VALUE(). Pass by value and return: In this step actual and formal parameters will be referring to separate memory. Suppose if the formal parameter is changed the actual parameter is also changed when the sub routine implementation is executed completely. Pass by value and return is identified by the key word CHANGING VALUE().

Perform abcd changing a.

Form abcd changing value(f_a). ... ... f_a = f_a + 10.

Endform. Ex: Data: a type i. A = 0. Write: / before executing the sub routine:, a. *perform pass_by_ref using a. *perform pass_by_value using a. Perform pass_by_value_and_return changing a. Write: / after executing the sub routine:, a. Form pass_by_ref using f_a. f_a = f_a + 10. Endform. Form pass_by_value using value(f_a). f_a = f_a + 10. Endform. Form pass_by_value_and_return changing value (f_a). Break-point. Skip. Skip. f_a = f_a + 10. Skip. Skip. Endform.

Develop a reusable function module to display sales order items to given sales order. Select * from vbap into table i_vbap Where vbeln = im_vbeln. Parameters: p_vbeln type vbap_vbeln. Data: i_vbap type table of vbap. Data: wa_vbap type vbap. Call function zget_cust_list Exporting Im_vbeln = i_vbeln Importing I_vbap = i_vbap. Loop at i_vbap into wa_vbap. Write: / wa_vbap-posnr, wa_vbap-matnr. Endloop. Select * from lips into table i_lips Where vbeln = im_vbeln. Parameters: p_vbeln type lips-vbeln. Data: i_lips type table of lips. Data: wa_lips type lips. Call function zget_cust_list2 Exporting Im_vbeln = p_vbeln

Tables I_lips = i_lips. Loop at i_lips into wa_lips. Write: / wa_lips-vbeln, wa_lips-posnr, wa_lips-ernam. Endloop. Im_vbeln -> type -> vbrp-vbeln. I_vbrp -> like -> vbrp. Select * from vbrp into table i_vbrp Where vbeln = im_vbeln. Data: i_vbrp type table of vbrp. Data: wa_vbrp type vbrp. Parameters: p_vbeln type vbrp-vbeln. Call function zget_cust_list3 Exporting Im_vbeln = p_vbeln Tables I_vbrp = i_vbrp. Loop at i_vbrp into wa_vbrp. Write: / wa_vbrp-vbeln, wa_vbrp-fkart, wa_vbrp-fktyp. Endloop. Ex on sub-routine reusability: Data: v_maktx type makt-maktx. Parameters: p_matnr1 type mara-matnr, p_matnr2 type mara-matnr, p_matnr3 type mara-matnr. Perform get_desc using p_matnr1 changing v_maktx.

Write: / v_maktx. Clear v_maktx. Perform get_desc using p_matnr2 changing v_maktx. Write: / v_maktx. Clear v_maktx. Perform get_desc using p_matnr3 changing v_maktx. Write: / v_maktx. Clear v_maktx. Form get_desc using f_matnr changing f_maktx. Select single maktx From makt Into f_maktx Where matnr = f_matnr and spras = en. Endform.

Chapter 07

7. Classical Reports
A report with single input screen (selection screen) and single output screen (list screen) is called a classical report. Events in classical reports: All the ABAP programs or reports are developed using events, because ABAP is EVENT DRIVEN programming language i.e. the entire ABAP program execution is based on order of events.

Load of program: This event is used to load the program into memory for execution. This is the internal event which we cant see. Initialization: This event is used to initialize the default values to program variables and selection screen variables.

At selection screen output: This event is used to modify the selection screen dynamically based on user actions on the selection screen. This event is triggered or executed for every action on the selection screen. At selection screen on field: This event is used to validate a single input field on the selection screen. At selection screen on value request: This event is used to provide a search help for an input field. This event is triggered whenever the user clicks on search help button. At selection screen on help request: This event is used to provide help information for an input field. This event is triggered whenever the user clicks on help button i.e. F1 button. At selection screen: This event is used to validate multiple fields of the selection screen. Whereas at selection screen on field is used to validate a single input field. Start of selection: This event is used to write the original business logic statements i.e. all select statements. It is also used to indicate the starting point of a program. It is the default event. ***** End of selection: It is used to indicate the start of selection has been ended. It doesnt have any importance in ABAP. It is mainly used with logical databases, which are obsolete in ABAP (LDBs are used in old version of ABAP). But LDBs are still used in HR ABAP, so end of selection is mainly used in HR ABAP, not the ABAP. Top of page: This event is used to display constant page heading for all pages of list screen. This event is triggered after the first write statement. ***** End of page: This event is used to provide constant footer information across all the pages of the list screen. To display end of page or footer information, we have to reserve some lines as footer lines using the statement.

Ex on classical reports: Develop a material master report with material type and industry sector as parameters and material number, material type, industry sector, units, material group etc on the output screen. Develop a sales order report to display header, item details

Develop a delivery order report to display header, item details

Develop a invoice report to display header, item details

Ex on at selection-screen output: This event is used to modify the selection screen dynamically based on user actions. Screen: It is a structure in data dictionary which is used to modify the properties of selection-screen fields. At the runtime of the program the screen will contain the properties where we can modify by using the ABAP logic. Ex: Loop at screen. . . Endloop. The fields available for modifying are Name: name of selection-screen field Group1: modification id of selection-screen fields Input: specifies whether the input is enabled or disabled, if input = 1; it means input is enabled, if input = 0; it means input is disabled Active: specifies whether field should be displayed or hidden, if active = 1 it is displayed, if active = 0 it is hidden Modification ID: It is an ID assigned to a group of selection-screen fields so that their properties can be modified with the help of modification ID. Suppose if the modification ID is not available then we have to modify each selection-screen field individually which makes program very complex. Syntax:

Parameters: <pname> type <table field> modif id <modification id name>. Parameters: p_kunnr type kna1-kunnr modif id aaa, P_kname type kna1-name modif id aaa, P_lifnr type lfa1-lifnr modif id bbb, P_lname type lfa1-name1 modif id bbb. Parameters: rb_cust radiobutton group r1 default x user-command ucomm, rb_vend radiobutton group r1. At selection-screen output. If rb_cust = x. Loop at screen. If screen-group1 = aaa. Screen-input = 1. Elseif. Screen-group1 = bbb. Screen-input = 0. Endif. Modify screen. Endloop. If rb_vend = x. Loop at screen. If screen-group1 = aaa. Screen-input = 0. Elseif screen-group1 = bbb. Screen-input = 1. Endif.

Modify screen. Endloop. Endif. Differences between at selection-screen on-field and at selection-screen.

At selection-screen on-field It is used to validate a single field Whenever there is an error on a field, the entire screen will be disabled, except the error field

At selection-screen Used to validate multiple fields Whenever there is an error on a field, the entire screen will be enabled

Ex: Data: v_mtart type mara-mtart. Data: v_mbrsh type mara-mbrsh. Parameters: p_matnr type mara-mtart. Parameters: p_mbrsh type mara-mbrsh. *at selection-screen on p_mtart. *perform validate_mtart. *at selection-screen on p_mbrsh. *perform validate_mbrsh. At selection-screen. Perform validate_mtart. Perform validate_mbrsh. Form validate_mtart. Select mtart From mara into v_mtrat Up to 1 rows Where mtart = p_mtart

End select. If sy-subrc <> 0. Message please enter a valid material type type E. Endif. Endform. Form validate_mbrsh. Select mbrsh From mara into v_mbrsh Up to 1 rows Where mbrsh = p_mbrsh End sel ect. If sy-subrc <> 0. Message please enter a valid value type E. Endif. Endform.

Chapter 08

8. INTERACTIVE REPORTS
Displaying the basic information on the basic list and the detailed information in the secondary list is called interactive report. The first list is called basic list and the number is 0. The remaining lists are called as secondary lists and the number starts from 1 to 20. So totally there are 21 lists. The list number is stored in a system variable SY-LSIND (system list index number). Interactive Report Events: At line-selection At user command Top-of-page during at line selection At PF At line-selection: This event is triggered whenever the user double clicks on any list line. To know the selected line contents we have two keywords or statements. Hide Get Cursor At user command: This event is triggered whenever the user clicks on customer GUI button. Top-of-page during line-selection: This event is used for providing the constant page heading for the secondary window. At PF: This event is used or triggered whenever the user clicks on function keys (F1, F2, F3,). This statement or event is obsolete in new versions (ecc 5.0, 6.0). Ex: Write: / this is a basic list with number:, sy-lsind. Top-of-page. Write: / 45 Basic list color 5. At line-selection. Break-point. Write: / this is a secondary list with number:, sy-lsind. Top-of-page during line-selection.

Write: / 45 Secondary list color 5. Hide: It is a keyword which is used to hide the data into a temporary memory called as hide area. The hide statement must be used within loop.endloop, so that it will hide all the values into hide area. Ex: Loop at itab into wa. Hide: wa-f1, wa-f2, Endloop. Functionality of hide: Whenever the user double clicks on any list line, the event at line-selection will be triggered. The system also identifies the line number where the user has double clicked and reads the corresponding record using line number into hide area. *** Now we can start developing secondary list using hide variable.

Ex on interactive report: Develop a material master report which displays the basic details in the basic list and description details in the secondary list. Data: i_mara type table of ty_mara. Data: i_makt type table of ty_makt. Data: wa_mara type ty_mara.

Data: wa_makt type ty_makt. Select * from mara into table i_mara up to 100 rows. Loop at i_mara into wa_mara. Write: / wa_mara-matnr, wa_mara-mtart, wa_mara-mbrsh, wa_mara-meins. Hide wa_mara-matnr. Endloop. At line-selection. Sy-lsind = 1. Select * from makt into table i_makt where matnr = wa_mara-matnr. Loop at i_makt into wa_ makt. Write: / wa_makt-matnr, wa_makt-spras, wa_makt-maktx. Endloop. Get Cursor: This statement is used to read or get the selected line contents i.e., field name and field value into local variables. Syntax: Get cursor field <v_fname> Value <v_fvalue>. The main advantage of cursor is, We dont have any hide area or temporary memory We can generate interactive reports based on field name and field value which is not possible with hide statement The main difference between hide and get cursor is with the hide statement system uses line number and gets the value into hide variables, without knowing what is the field name. whereas the get cursor will get the exact field name and field value with which we can generate various interactive reports based on field names

Conversion routine: It is a function module which is used to convert a value from internal format to external format and vice versa. Conversion exits or maintained at domain level. Go to the domain and double click on conversion exit. The conversion exit function modules will be displayed. Ex: CONVERSION_EXIT_INPUT: used to convert a value from external format to internal format. CONVERSION_EXIT_OUTPUT: used to convert a value from internal format to external format. Ex on get cursor: Develop a material master report to display material details on basic list (matnr, mtart, mbrsh, meins). Suppose if the user double clicks on matnr display the description details on the secondary list. Suppose if the user double clicks on material type display the mtart details on the secondary list. Data: i_mara type table of ty_mara. Data: i_makt type table of ty_makt. Data: i_t134 type table of ty_t134.

Data: wa_mara type ty_mara. Data: wa_makt type ty_makt. Data: wa_t134 type ty_t134. Data: v_fieldname(20) type c. Data: v_fieldvalue(18) type c. Select * from mara Into table i_mara up to 100 rows. Loop at i_mara into wa_mara. Write: / wa_mara-matnr, wa_mara-mtart, wa_mara-mbrsh, wa_mara-meins. Endloop. At line-selection. Sy-lsind = 1. Get cursor field v_fieldname Value v_fieldvalue. If v_fieldname = wa_mara-matnr. Call function conversion_exit_matn1_input Exporting Value = v_fieldvalue Importing Value = v_fieldvalue. Select * from makt Into table i_makt where matnr = v_fieldvalue. Loop at i_makt into wa_makt. Write: / wa_makt-matnr, wa_makt-spras, wa_makt-maktx. Endloop.

Elseif v_fieldname = wa_mara-mtart. Select * from t134 Into table i_t134 where mtart = v_fieldvalue. Loop at i_t134 into wa_t134. Write: / Endloop. Endif. At User-Command: This event is triggered whenever the user clicks on custom gui button. Custom GUI: It is used to create our own menus in the menu bar, our own buttons in the application tool bar, enabling the standard buttons on the standard tool bar. Syntax: Set PF_STATUS <custom_gui menu name>. Double click and create Or SE41 is t-code for creating custom gui (also called as menu painter). FCT Code (function code): It is a short cut code assigned to a button to identify the button click. The FCT codes are automatically stored in a system variable sy-ucomm (user command). Ex: Set pf_status my_menu. (Double click and create on my_menu) Write: this is an example for custom menus. Double click on my_menu Click on yes button Provide description and press enter By default 3 bars will be available as below

Expand the function keys provide the FCT code back for the back buttons Save, activate and test it Working with menu bar: Expand the menu bar options
Provide the menu name as list and double click on it Now provide the function code and text

Save and activate Click on back and go to the program and write the below code At user-command. If sy-ucomm = mm01. Call transaction mm01. Elseif sy-ucomm = xd01. Call transaction xd01. Elseif sy-ucomm = se11. Call transaction se11. Endif. Save, activate and test it

Working with application tool bar: Expand the application tool bar Provide an FCT code in the first box, HELP Double click on HELP Press enter Provide the function text, icon name, information text and press enter Double click on any shortcut code Provide the icon text, press enter Save and activate Click on back and go to the program Write the below code inside the program At user-command. If sy-ucomm = help. Message this is a help button type I. Endif. Save, activate and test it A real time example on USER COMMAND: Develop a report which displays each record with the help of check box. Provide 3 buttons

on application tool bar. Data: i_kna1 type table of kna1. Data: i_kna1_sel_recs type table of kna1. Data: wa_kna1 type kna1.

Data: v_chkbox(1) type c. Data: v_lines type i. Select * from kna1 into table i_kna1 up to 100 rows. Set pf_status menu_100. Perform disp_data. At user-command. Sy-lsind = 0. Case sy-ucomm. When sall. V_chkbox = x. Perform disp_data. When dall. V_chkbox = . Perform disp_data. When dload. Perform download_data. End case. Form disp_data. Loop at i_kna1 into wa_kna1. Write: v_chkbox as checkbox, wa_kna1-kunnr, wa_kna1-land1, wa_kna1-name1. Endloop. End form. Form download_data. Describe table i_kna1 line v_lines. Do v_lines times.

Read line sy-index field value v_chkbox wa_kna1-kunnr wa_kna1-land1 wa_kan1-name1. If v_chkbox = x. Append wa_kna1 to i_kna1_sel_recs. Endif. Enddo. Call function gui_download Exporting Filename = c:\kna1.txt Filetype = asc Write field separator = x Tables Data_tab = i_kna1_sel_recs. End form.

Chapter 09

9. ALV REPORTS

(ABAP LIST VIEWER) Display the data in list format or grid format with pre-defined options and better look-end feel is called an ALV reports. The main advantages of ALV reports are Better look-end feel Pre-defined options like 1.Sort in ascending order 2.Sort in descending order 3.Setting filters 4.Totals and subtotals 5.Downloading data 6.Changing layouts etc The ALV reports are developed using function modules REUSE_ALV_GRID_DISPLAY: Displays data in grid format REUSE_ALV_LIST_DISPLAY: Displays data in list format REUSE_ALV_FIELDCATELOG_MERGE: Generates a field catelog automatically REUSE_ALV_EVENTS_GET: Displays ALV events REUSE_ALV_COMMENTARY_WRITE: Displays logo, top of page, end of list REUSE_ALV_HIERSEQLIST_DISPLAY: Displays hierarchical ALV REUSE_ALV_BLOCKED_DISPLAY: Displays blocked ALV Ex on ALV with structure: Data: i_mara type table of mara. Data: wa_mara type mara. Start-of-selection. Perform get_data. End-of-selection. Perform disp_data.

Form get_data. Select * from mara Into table i_mara Up to 100 rows Endform. Form disp_data. Call function reuse_alv_grid_display Exporting I_callback_program = sy-repid I_structurename = mara Tables Out_tab = i_mara. Endform. Type Group: It is a container of reusable user defined types. There are so many type groups given by SAP. SLIS is a type group which contains user defined types for ALV reports. Type Pool: It is a keyword to assign the type group to our program so that our program can access all user defined types in the type group. It is similar to #include<stdio.h> in C language. Field Catelog: It is an internal table which contains the list of the fields to be displayed in ALV report. We can also set various properties for each field using the field catelog. COL_POS: Specifies column position FIELD NAME: Specifies field name TAB NAME: Specifies internal table name SELTEXT_S: Specifies short text for ALV column SELTEXT_M: Specifies medium text for ALV column SELTEXT_L: Specifies long text for ALV column

EDIT = X: Displays the ALV column in editable mode DO_SUM = X: Displays total to be calculated on an ALV column SUBTOT = X: Displays subtotals to be calculated on an ALV column HOTSPOT = X: Specifies the ALV column to display as a link EMPHASIZE = CXYZ: Specifies color for an ALV column, where C (Color), X (Color number), Y (BG color [0, 1]), Z (Font color [0, 1]). NO_OUT = X: Specifies the ALV column to be hidden KEY = X: Specifies the ALV column as a key field Note: All the field catelog options are available in the type group SLIS. Creating Field Catelog:

Steps for the ALV field catelog program: Step 1: Define the internal table and work area for field catelog Step 2: Write the below logic Start-of-selection. Perform get_data. Perform create_fcat. End-of-selection. Perform disp_alv. Step 3: Define the field catelog, subroutine as below Form create_fcat. V_pos = v_pos + 1. Wa_fcat-col_pos = v_pos. Wa_fcat-fieldname = matnr. Wa_fcat-tabname = i_mara. Wa_fcat-seltext_m = material num. Wa_fcat-key = x. Append wa_fcat to i_fcat. Clear wa_fcat. .. .. Endform. Step 4: Display the alv using field catelog Form disp_alv. Call function REUSE_ALV_GRID_DISPLAY Exporting

I_callback_program = sy-repid It_fieldcat = i_fcat Tables T_outtab = i_mara. Endform. Using FIELD_CATELOG_MERG: This option is used to create the field catelog automatically without manual coding. Just call the function module REUSE_ALV_FIELDCATELOG_MERG it will automatically generates a field catelog with all the fields of internal table along with their properties. If we want we can modify the field catelog which is generated automatically, using the below logic. Loop at i_fcat into wa_fcat. Modify i_fcat from wa_fcat index sy-tabix. Endloop. But in the real time, we dont use this option because the internal table should be declared using the old syntax, occurs 0 and all the fields should be defined using LIKE statement, not with the TYPE statement. Ex: Form create_fcat_auto. Call function REUSE_ALV_FIELDCATELOG_MERGE Exporting I_program_name = sy-repid I_internal_tabname = i_mara I_inclname = sy-repid Changing

Ct_fieldcat = i_fcat Loop at i_fcat into wa_fcat. If wa_fcat-fieldname = meins. Wa_fcat-emphasize = c610. Endif. Modify i_fcat from wa_fcat index sy-tabix transporting emphasize. Endloop. ALV with layout: The layout option is used to decorate or embellish all the fields of ALV report. We have the below options for layout. ZEBRA = X: all alv rows are displayed with alternative colors COLWIDTH_OPTIMIZE = X: all alv columns will be optimized to display entire alv information EDIT = X: all alv columns will be editable mode NO_HLINE = X: horizontal lines are not displayed NO_VLINE = X: vertical lines are not displayed For the layout options we need to declare a work area with below syntax. Data: <wa_layout> type SLIS_LAYOUT_ALV. Steps for ALV with layout program: Step 1: Define the data declaration for the layout Step 2: Write the below code Start-of-selection. Perform get_data. Perform create_fcat. Perform create_layout. End-of-selection. Perform disp_alv.

Step 3: Define the ALV subroutine as below Form create_layout. Wa_layout-zebra = x. Wa_layout-colwidth_optimize = x. Wa_layout-edit = x. Wa_layout-no_hline = x. Wa_layout-no_vline = x. Endform. Step 4: Finally display the alv Form disp_alv. Call function REUSE_ALV_GRID_DISPLAY Exporting I_callback_program = sy-repid Is_layout = wa_layout It_fieldcat = i_fcat Tables T_outtab = i_mara. Endform. ALV with grand totals: To calculate grand totals, set the property or option DO_SUM = X for the currency or quantity fields. Ex: V_pos = v_pos + 1. Wa_fcat-col_pos = v_pos. Wa_fcat-fieldname = netwr. Wa_fcat-tabname = i_vbap.

Wa_fcat-seltext_m = netvalue. Wa_fcat-do_sum = x. Append w_fcat to i_fcat. Clear wa_fcat. Or Select the column netwr in the ALV output and click on button. ALV with sub-totals: To calculate the sub totals, we have to identify based on which field the sub totals needs to be calculated. After finding the field name, we have to set The data in sorting order Set the property SUBTOT = X Step 1: Create an internal table and work area for sorting internal tables. Data: i_sort type slis_t_sortinfo_alv. Data: wa_sort like line of i_sort. Step 2: Write the below code in the program. Start-of-selection. Perform get_data. End-of-selection. Perform create_fcat. Perform calc_subtotals. Perform disp_alv. Step 3: Write the below logic for sub totals. Form calc_subtotals. Wa_sort-fieldname = vbeln. Wa_sort-up = x. Wa_sort-subtot = x. Append wa_sort to i_sort.

Endform. Step 4: Call the function module and export the parameter. Call function reuse_alv_grid_display Exporting I_callback_program = sy-repid It_fieldcat = i_fcat It_sort = i_sort Tables T_outtab = i_vbap. ALV with events: There are around 17 events in the ALV All the events are available in the function module REUSE_ALV_EVENTS_GET Just call this function module, we can import all the events into an internal table (i_events) For each event we have to provide a sub routine name and then define the sub routine using form..endform Ex: Type-pools: slis. Data: i_events type slis_t_event. Data: wa_events like line of i_events. Call function reuse_alv_events_get Importing Et_events = i_events. Read table i_events into wa_events with key name = top-of-page. Wa_events_form = form-top. Modify i_events from wa_events index sy-tabix. Skip.

Form top. . . Endform. ALV with TOP_OF_PAGE and END_OF_LIST events: The function module resue_alv_commentary_write is used to display the top-of-page, end-of-list, images in ALV reports Just call the function module and provide the internal table (which contains heading or footer information) Ex: Data: i_heading type slis_t_listheader. Data: wa_heading like line of i_heading. Form form_top. Wa_heading-typ = h. (H-heading, S-subheading, A-italic letters) Wa_heading-info = material master report. Append wa_heading to i_heading. Call function reuse_alv_commentary_write Exporting It_list_commentary = i_heading. Endform. Form form_eol. Refresh i_heading. Wa_heading-typ = s. Wa_heading-info = all rights reserved for sap gdc, waldroff, germany.

Append wa_heading to i_heading. Call function reuse_alv_commentary write Exporting It_list_commentary = i_heading. Endform. Using images in ALVs: The image must be uploaded from our system (presentation server) into SAP server using t-code OAER Go to OAER Provide the details as below Class name: pictures Class type: OT Object key: image001 (image name) Execute Expand standard document types folder Double click on screen Select the image and press enter Again press enter The image is successfully uploaded Go to the above program and just provide the image name Form form_top. Call function reuse_alv_commentary_write Exporting It_list_commentary = i_heading I_logo = image001. Endform.

Interactive ALVs
Whenever the user double clicks, the event user-command will be triggered in ALV reports For this event we have to define a sub routine with the below syntax

Ex: Form form_uc using ucomm type sy-ucomm selfield type slis_selfield. Select * From makt Into corresponding fields of table i_makt Where matnr = selfield-value. Perform create_fcat2. *Perform get_events. Perform disp_alv2. Endform.

SAP memory: It is a global memory which is used to pass the data between external sessions (session 1 and session 2) To pass the data to SAP memory, we use the statement called set parameter To receive the data from SAP memory, we use the statement called get parameter

Syntax: Set parameter <parameter id> value <field value>. Get parameter <parameter id> value <field value>. Finding parameter id: Go to any transaction (mm02, va02 etc) Click on F1 on material number field or sales order number field SAP help will be displayed Click on technical information icon It will display Program name Screen number GUI status Table name *** Field name *** Search help name Data element name Parameter id ***

Finally we found the parameter id using the above procedure Ex on SAP memory using set parameter: Parameters: p_vbeln type vbak-vbeln.

*call transaction va02. Call transaction va02 and skip first screen. ABAP memory: It is a local memory which is used to pass the data between programs within a single session To pass the data to ABAP memory we use export statement To receive the data we use import statement

Syntax: Export <value> to memory-id <memory id name>. Import <value> to <local variable> from memory-id <memory id name>. Submit: It is the keyword which is used to call another program from current program. Syntax: Submit <prog2>. Submit and Return: This statement is used to call another ABAP program from current program and automatically return from second program to first program.

Syntax: Submit <prog2> and Return. Ex:

Hierarchical ALVs: Displaying the data in the form of hierarchy on a single screen is called hierarchical ALV report These reports are mainly used to display header and item information The function module is reuse_alv_hierseq_list_display To this function module, we have to specify or export the header table name and item table name as well as the key information

Key: It is a key information which contains the common key fields between header table and item table. We can specify a maximum of 5 key fields to relate or link the header and item table. Ex: Form create_key_info. Wa_key-header01 = vbeln. Wa_key-item01 = vbeln. Common key fields between header and item table

Endform. Form disp_alv. Call function reuse_alv_hierseq_list_display Exporting I_callback_prog = sy-repid It_fieldcat = i_fcat I_tabname_header = i_vbak I_tabname_item = i_vbap Is_keyinfo = wa_key Tables T_outtab_header = i_vbak T_outtab_item = i_vbap. Endform.

Blocked ALV report: (Obsolete in SAP) Displaying the data in the form of blocks is called blocked ALV report The function modules used are REUSE_ALV_BLOCK_LIST_INIT (used to initialize blocked alv report) REUSE_ALV_BLOCK_LIST_DISPLAY (displays blocked alvs with all blocks) REUSE_ALV_BLOCK_LIST_APPEND (used to append a block to blocked alv)

Control Break Statements


These are special set of statements which are used to control the execution of each statement available between loopendloop. The control break statements work only between loopendloop. The control break statements are, At first: This statement is executed for the first iteration of the loop, i.e. when sy-tabix = 1. At last: It is triggered for the last iteration of the loop, i.e. sy-tabix = last record (n).\ At new <field name>: It is triggered whenever there is a new value on a particular field. At end of <field name>: It is triggered whenever the new value ends on a particular field. Note: At first is used to display headings At last is used to display grand totals At new is used to display sub headings At end is used to display sub totals Sum: It is a key word which is used to calculate the totals or sum automatically on the currency and quantity fields.

Ex: Types: begin of ty_vbap, Vbeln type vbap-vbeln, Matnr type vbap-matnr, Zmeng type vbap-zmeng, Netwr type vbap- netwr, End of ty_vbap. Data: i_vbap type table of ty_vbap. Data: wa_vbap type ty_vbap. Start-of-selection. Select * from vbap Into corresponding fields of table i_vbap Up to 100 rows. Loop at i_vbap into wa_vbap. At first. Write: / sy-uline. Write: / 2 sales doc no, 15 matno, 36 quantity, 55 price. Write: / sy-uline. Endat. At new vbeln. Write: / 2 new sales doc no color 5, wa_vbap-vbeln.

Endat. Write: / 2 wa_vbap-vbeln, 15 wa_vbap-matnr, 36 wa_vbap-zmeng, 55 wa_vbap-netwr. At end of vbeln. Sum. Write: / 40 subtot is: color 4, wa_vbap-netwr color 4. Endat.

Lock Objects: Lock objects are used to lock the database table records for some point of time. There are 3 types of locks Exclusive lock Shared lock Exclusive but not cumulative Exclusive lock: The locked data can be read or processed by one user only. A request for another exclusive lock or for a shared lock is rejected. Shared lock: Several users can read the same data at the same time, but as soon as a user edits the data, a second user can no longer access this data.

Exclusive but not cumulative lock: Exclusive locks can be requested by the same (transaction) user more than once and handled successively, but an exclusive but not cumulative lock can only be requested once by a given user. All other lock requests are rejected. Where do we use lock objects? Lock objects are used when we are working with open SQL statements like insert, update and modify and delete. Since these are database statements we should lock the data to maintain the consistency. Lock object function modules: Whenever we create a lock object, two function modules will be created automatically. ENQUE_<lock object name> used to lock the table data DEQUEUE_<lock object name> used to unlock the table data Steps to create lock objects: Go to SE11 Provide the lock object name Ex: ez_too1w Click on create and provide the description Click on tables tab Provide the table name as t001w and lock mode as write lock (exclusive lock) Click on lock parameter tab, the key fields will be automatically added Save and activate Two function modules will be created, go to SE37 and check them Using lock objects in program: Call function enqueue_ez_t001ww Exporting Mode_t001w = E Mandt = sy-mandt Werks = hyd3 Exceptions Foreign_lock = 1

System_failure = 2 Others = 3. If sy-subrc = 0. Update t001w set bwkey = 04 Where werks = hyd3. If sy-subrc = 0. Write: / plants are successfully updated, sy-dbcnt. Endif. Call function dequeue_ez_t001ww Exporting Mode_t001w = E Mandt = sy-mandt Werks = hyd3. Elseif sy-subrc = 1. Message already locked by a user type E. Endif. Runtime Analysis (SE30): It is used to check the efficiency of a program, transaction code; function module in terms of what is the load on database server, application server, presentation server. The runtime analysis is displayed in the form of graph containing two colors. Red color: Which indicates the program contains statements which take long time. Green color: Indicates the program is excellent. Note: Always the load on the database server should be very less i.e. 40%. The load on the application server and presentation server can be more. Ex: Data: i_bkpf type table of bkpf. Data: wa_bkpf type bkpf.

Select * from bkpf Into table i_bkpf Where xblnr < > . (xblnr is not a key field) Loop at i_bkpf into wa_bkpf. Write: / wa_bkpf-bukrs, wa_bkpf-belnr. Endloop. Checking runtime analysis for the above program: Go to SE30 Select program and provide the program name Click on the button execute The output will be displayed Click on back Click on evaluate button The graph will be displayed as below

Modify the program as below Data: i_bkpf. Data: wa_bkpf. Select * from bkpf Into table i_bkpf Where bukrs = 0001. (bukrs is a key field) Loop

. Endloop. Check the runtime analysis using the above steps

The graph will be displayed with database load with < 40% (around 9%) Performance Tuning: It is used to display the time taken by each open SQL statement i.e. insert, modify, delete, update, select The performance tuning will be displayed in terms of time as well as color If any statement is displayed with red color, then it means the statement is taking long time for execution which is not correct If the statement is displayed with yellow color then it is an exact and correct statement So all our programs must be tested for performance tuning If the statements are red in color, then we have to modify them by following the best programming standards Ex: Data: i_bkpf type table of bkpf. Data: wa_bkpf type bkpf. Select * from bkpf Into table i_bkpf Where xblnr < > .

Loop at i_bkpf into wa_bkpf. Write: / wa_bkpf-belnr, wa_bkpf-bukrs. Endloop. Check the performance tuning as below Go to ST05 Click on activate trace button Execute your program in another session and click on back Now deactivate the trace by clicking on deactivate trace button Now click on display trace button The trace will be displayed as below

In the above trace there is a red color statement which is taking a long time for execution, so we need to modify the program Change the code as below Types: begin of ty_bkpf, Bukrs type bkpf-bukrs, Belnr type bkpf-belnr, Gjahr type bkpf-gjahr, Xblnr type bkpf-xblnr, End of ty_bkpf. Data: i_bkpf type table of ty_bkpf. Data: wa_bkpf type ty_bkpf. Select bukrs belnr gjahr xblnr From bkpf Into table i_bkpf Where bukrs = 0001. Loop at i_bkpf into wa_bkpf. . Endloop. Now check the performance tuning using the above steps

All the statements will be displayed with yellow color Index: Indexes are used to read the data very fastly from the database table. There are two types of indexes. Primary index: An index which is automatically created on the key field is called primary index. Whenever an index is created the data will be sorted in ascending order to read the data quickly. Secondary index: An index created on non key fields to read the data fastly is called secondary index. Secondary indexes are normally created by ABAP consultants to improve the performance of a program. Which contains a select statement with non key fields in the where condition. Steps for creating secondary index: Open a standard SAP table Click on indexes button A pop up is displayed Click on create icon Provide the description as index on non key field city Click on table fields button and select mandt, kunnr, ort01 Press enter, save and activate The index is created If we want to check the indexes of table, just click on indexes button Note: We can create a maximum of 9 secondary indexes in a table.

Best Programming Standards used in the Real Time Never use select * Never use select * into corresponding fields Always use key fields in where condition Suppose if we want to use non key fields in where condition we have to create secondary index Never use joins for more than 3 tables Always use for all entries for more than 3 tables Check if first internal table is not initial or initial when using for all entries Always use binary search for reading a records Make sure that internal table is sorted before using binary search Always declare internal tables using user defined types Never use occurs 0 with header line

Das könnte Ihnen auch gefallen