You are on page 1of 537

Project Report on

EXPERIENTIAL LEARNING ON SAP ABAP


Dissertation submitted to

By

YENIKAPATI SAI BHAVANA

Under the Guidance of:

KARTHIK. V

SAP ABAP Technical Consultant,


EmpowerSys Technology & Learning Services,
Bangalore

1
Table of Contents

1. INTRODUCTION TO SAP ABAP ...................................................................................... 1


2. SAP ABAP DICTIONARY .................................................................................................. 2
3. PACKAGE BUILDER .......................................................................................................... 3
a) Package ............................................................................................................................... 3
b) Creation of package:.......................................................................................................... 3
4. DATA TYPES OF ABAP...................................................................................................... 6
5. ABAP DATA BASE TABLE ................................................................................................ 9
a) Components of data base Table in ABAP DDIC ............................................................ 9
b) Creation of Data Base Table and display contents. ...................................................... 10
c) Creating Currency and Quantity field for data base Table: ....................................... 20
6. STRUCTURES IN ABAP ................................................................................................... 22
a) Creating a structure (include structure) ....................................................................... 22
b) Assigning structure to table ............................................................................................ 23
7. FOREIGN KEY RELATIONSHIP ................................................................................... 25
a) Creation of foreign key relationship between two tables ............................................. 25
8. INDEXES FOR DATA BASE TABLE ............................................................................. 27
a) Creation of secondary index ........................................................................................... 27
9. VIEWS IN SAP ABAP ........................................................................................................ 29
a) Creation of Base view ...................................................................................................... 29
b) Creation of Projection view............................................................................................. 35
c) Creation of Maintenance view ........................................................................................ 36
d) Creation of Help view ...................................................................................................... 41
10. LOCK OBJECTS IN DDIC ............................................................................................... 44
a) Creation of lock object .................................................................................................... 45
11. TABLE TYPE ...................................................................................................................... 47
12. TABLE MAINTENANCE GENERATOR (TMG) .......................................................... 49
a) Creation of TMG for data base table ............................................................................ 49
b) Creating Transaction code for table maintenance generator ...................................... 51
13. SEARCH HELP ................................................................................................................... 54
a) Creating Elementary Search Help ................................................................................. 54
b) Creating Collective Search Help ..................................................................................... 56

2
14. TYPES OF TABLES ............................................................................................................ 58
15. SYSTEM VARIABLES ........................................................................................................ 59
a) Creating program using system variables ..................................................................... 60
b) Create a database table using system variables ............................................................ 63
16. CONDITIONAL STATEMENTS ....................................................................................... 66
a) Creating a program using all conditional statements................................................... 68
17. LOOP BREAK STATEMENTS ........................................................................................ 72
a) Create a program using exit statement .......................................................................... 72
b) Create a program using stop statement ......................................................................... 78
c) Create a program using continue statement ................................................................. 84
18. PROCESSING STATEMENTS .......................................................................................... 90
a) Create a program using processing statements ............................................................ 90
19. INTERNAL TABLE AND WORK AREA ......................................................................... 96
20. JOINS ................................................................................................................................... 107
a) Creating a program using inner join............................................................................ 107
b) Creating a program using outer join............................................................................ 110
21. FOR ALL ENTERIES ........................................................................................................ 113
a) Creating a program using for all entries...................................................................... 114
22. SELECT STATEMENTS ................................................................................................. 116
a) Program to select all the fields from data base table into Work area ....................... 118
b) Program to select particular fields from data base table into Internal table ...... 120
c) Program to select particular fields from data base table into Internal table using
where condition ..................................................................................................................... 122
d) Program to select all the fields from data base table into internal table with where
condition and using rows ...................................................................................................... 124
e) Program to select all the fields from data base table into work area using append.. 126
f) Program to select particular fields from data base table internal table using append
128
g) Program to select into corresponding fields from data base table internal table using
where condition ..................................................................................................................... 130
h) Program to select into corresponding fields from data base table work area using
where condition ..................................................................................................................... 132
i) Program to select single field from data base table internal table using where
condition ................................................................................................................................. 134
j) Program to select single field from data base table internal table up to 1 row using
where condition ..................................................................................................................... 135

3
23. SELECTION SCREEN ...................................................................................................... 136
a) Creating a program using selection screen parameters ............................................. 137
b) Creating a program using selection screen select-options .......................................... 139
c) Creating a program using selection screen commands............................................... 141
24. PROGRAMS USING LIST OF INTERNAL TABLE OPERATIONS ......................... 144
a) Create a program using read operation: ..................................................................... 144
b) Create a program using sort operation ........................................................................ 149
c) Create a program using delete operation ..................................................................... 154
25. MODULARIZATION TECHNIQUES ............................................................................ 159
a) Include program................................................................................................................ 159
b) Subroutines........................................................................................................................ 167
c) Function module ................................................................................................................ 173
26. REPORTS IN SAP ABAP .................................................................................................. 182
a) Classical report............................................................................................................... 182
b) Interactive Report .......................................................................................................... 188
c) ALV (ABAP List Viewer) Report ................................................................................. 190
27. CONTROL BREAK STATEMENTS ............................................................................... 228
28. MODULE POOL PROGRAMMING ............................................................................... 232
a) Steps to create module pool programming. ................................................................. 233
b) Steps to create a module pool programming using real time example ..................... 242
c) Steps to create a MPP using tabstrip ........................................................................... 247
d) Steps to create MPP using Table control ..................................................................... 256
29. PERFORMANCE TUNING .............................................................................................. 268
30. WORKING WITH FILES ................................................................................................. 272
31. ALE - IDOC’S ..................................................................................................................... 278
32. BAPI ((Business Application Programming Interface) ................................................... 302
33. ENHANCEMENTS ............................................................................................................ 318
a) Using call customer function ............................................................................................ 322
b) Using SMOD transaction ................................................................................................. 328
34. BADI (Business Add-ins).................................................................................................... 340
a) Using CL_EXITHANDLER ............................................................................................ 342
b) Using SE84 Tcode ............................................................................................................. 345
35. SMARTFORMS .................................................................................................................. 347
36. Batch Data Communication ............................................................................................... 386

4
37. SESSION METHOD .......................................................................................................... 414
38. LSMW METHOD............................................................................................................... 428
39. SCRIPTS .............................................................................................................................. 452
40. S4HANA............................................................................................................................... 475
a) ABAP Development Tool (ADT) ..................................................................................... 476
b) steps to create an ABAP project in Eclipse .................................................................... 477
41. CDS VIEW .......................................................................................................................... 480
a) Creation of basic CDS views ............................................................................................ 481
i) CDS view –select with key ............................................................................................. 485
ii) CDS view-select * .......................................................................................................... 486
iii) CDS views-select distinct ............................................................................................. 487
b) CDS views with Joins ........................................................................................................ 488
c) CDS View with Expressions and Session Variables ...................................................... 489
d) Consume CDS View in an ABAP Program .................................................................... 490
e) CDS View Extension ......................................................................................................... 492
f) CDS View with Association ............................................................................................. 494
g) CDS View with Parameters.............................................................................................. 499
42. OOPS ABAP ........................................................................................................................ 502
a) Creating a class in SAP ABAP ......................................................................................... 506
b) Creating methods .............................................................................................................. 509
c) Calling the method from the program ............................................................................ 511
43. AMDP (ABAP Managed Database Procedure) ............................................................... 512
ASSIGNMENT-1 ...................................................................................................................... 513
a) Create a table using following fields ............................................................................... 513
b) Create a table using following fields ............................................................................... 514
c) Create a Database view .................................................................................................... 515
d) Create a Help view............................................................................................................ 515
e) Create a maintenance view .............................................................................................. 516
f) Create a projection view ................................................................................................... 516
g) Create a lock object for the y_t001 table ........................................................................ 517
h) Create an elementary search help for the table y_t001………………………………..518
i) Create an elementary search help for the table y_t001w……………………………...518
j) Create collective search help with both the search helps .............................................. 519
k) Create an include structure for the below fields ............................................................ 520

5
ASSIGNMENT-2 ...................................................................................................................... 521
a) Create a database table using following fields ............................................................... 521
b) Create a database table using following fields ............................................................... 522
c) Create search help for the fields gjahr for the table zsb_bseg. ..................................... 523
d) Create search help for the fields buzid for the table zsb_bseg. .................................... 523
e) Create collective search help for the both above search help. ...................................... 524
f) Create search help for the fields bldat for the table zsb_bkpf. ..................................... 524
g) Create search help for the fields blart for the table zsb_bkpf. ..................................... 525
h) Create collective search help for the both above search help. ...................................... 525
i) Create a foreign key relationship for the tables zsb_bkpf and zsb_bseg..................... 526
relation between the tables is bukrs .................................................................................... 526
j) Create database view for the tables ekko ekpo ............................................................... 526
k) Create a maintenance view for the tables lfa1 and lfb1 ................................................ 527
l) Create help view for the table bsec................................................................................... 527
m) Create a lock object using the table zsb_bseg ............................................................... 528
n) Create a lock object using the table zsb_bkpf ................................................................ 528

6
ASSIGNMENT TABLES
ASSIGNMENT 1

a)

b)

c)

7
ASSIGNMENT-2

a)

b)

8
1. INTRODUCTION TO SAP ABAP

SAP was started in 1972 by five former IBM employees by name SAP AG with a vision
of creating standard application software for real-time business processing. In 1980
the company released the first ERP software by name SAP R/1(Real time –one Tier
Architecture) and has issued several releases, such as SAP R/1, SAP R/2, and SAP R/3.

Sap (Systems Applications and Products in Data Processing) and world's leading
provider of business software solutions.

SAP is the ERP (Enterprise Resource Planning) system that aims to integrate all the
different modules in the company and which supports almost every business module in
the business.

ABAP (Advanced Business Application Programming language) is a the fourth-


generation programming language and technical module of SAP, which is used to
developthe applications related to SAP. With the help of ABAP, one can customize
SAP according to the requirement. It is now used along with Java as the main
programming language for the SAP application server.

BHAVANA Page | 1
SAP ABAP TRAINING
2. SAP ABAP DICTIONARY

ABAP dictionary is one of the most important tools of the ABAP workbench, which
is usedto create and manage the metadata (data about data). It, is used to store the
descriptions of data definitions and also known as Data Dictionary.

DDIC is the central storage area, which allows users to maintain the repository
objects
related to the particular database and contains the central description of all the data
used inthe SAP system without any redundancy.

Repository of ABAP Data Dictionary

BHAVANA Page | 2
SAP ABAP TRAINING
3. PACKAGE BUILDER
Package builder is one of the important tools used for implementation in ABAP
workbench.

a) Package
Package is a development object that stores the objects such as menus, screens,
functional modules, transactions etc. Package builder is used to develop and
maintaining development classes, classes and transfer objects to other packages.

b) Creation of package:

➢ Go to T-code SE21.
➢ Select Radio Button for package and give package name.

➢ Click on Create

BHAVANA Page | 3
SAP ABAP TRAINING
➢ Provide short description and click on continue.

➢ Click on Create Request and Provide short Description and save.

BHAVANA Page | 4
SAP ABAP TRAINING
➢ Package is created with the name ZSB_EMP_TECHM2

BHAVANA Page | 5
SAP ABAP TRAINING
4. DATA TYPES OF ABAP

Data types:

1. Numeric Data types: Integer(I), Float(F), Packed Decimal(P)

2. Character data types: Char(C), Numeric char(N), Date(D), Time(T)

Note: - Char is alpha numeric. That means it accept the integer and character.

Note: - Here Integer, Float, Date and Time are fixed length data types & rest

of the data types arevariable length data types.

Syntax of Integer (I): -

Data <variable name> type I.

Ex: - data A type I.

The initial / default value of integer is ‘0’.

Syntax of Float (F): -

Data <variable name> type F.

Ex: - data A type F.

The initial value of integer is ‘.00’.

BHAVANA Page | 6
SAP ABAP TRAINING
Syntax of Packed Decimal (P): -

Data <variable name> (<length>) type P decimals <no>.

Ex: - data A (10) type P decimal 3.

The initial value of packed decimal is ‘.000’ (number of decimals)

Syntax of Char (C): -

Data <variable name> (<length>) type C.

Ex: - data A (5) type C.

The initial value of char is ‘space / empty’.

Syntax of Date (D): -

Data <variable name> type D.

Ex: - data A type D.

The initial format is ‘YYYYMMDD’. (20140425)

BHAVANA Page | 7
SAP ABAP TRAINING
Syntax of Numeric Char (N): -

Data <variable name> (<length>) type N.

Ex: - data A (10) type N.

The initial value of Numeric Char is ‘000’. (Based on length)

Syntax of Time (T): -

Data <variable name> type T.

Ex: - data A type T.

The initial value of time is ‘000000’. format is ‘HHMMSS’

BHAVANA Page | 8
SAP ABAP TRAINING
5. ABAP DATA BASE 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.

 So, to define a field, we have to specify the below things:

FIELD = DATA ELEMENT + DOMAIN

a) Components of data base Table in ABAP DDIC

BHAVANA Page | 9
SAP ABAP TRAINING
b) Creation of Data Base Table and display contents.

➢ Go to TRCODE SE11 and select radio button data base Table.


➢ Give the table name (start with y or z) and click on create.

Delivery Class:

Delivery class is used to define the type of data that we want to store in our table.
The data can be business data, which means Application data (Master and
transaction data) or system data. We will choose Application Data for out Delivery
Class.

Display/Maintenance:

This option is used to allow us that whether we want only display the data or also
want to maintain the data. Here the data maintenance means creating, deleting, or
updating the data.

BHAVANA Page | 10
SAP ABAP TRAINING
➢ There are three options available for this field:

• Display/maintenance allowed

• Display/maintenance not allowed

• Display/maintenance allowed with restrictions

➢ Choose the Application data (A) for our delivery class.


➢ Choose Display maintenance Allowed for Display/Maintenance.

➢ Click on Fields Tab provide Field name, data types, Length and provide short
description.

Field Name: The name which we provide to each field in the table is known as
the fieldname.
Key flag: It specifies whether that particular field belongs to the Key field or not.
Field length: It defines the number of characters that can be entered into the field.

BHAVANA Page | 11
SAP ABAP TRAINING
Decimal Places: It specifies how many digits are permitted after the decimal
point, and it can only be used f r the numeric data.
Field Labels in Data Element: The field labels are used to provide the text
information to the data element
Short text: It specifies the meaning of the particular field entered within the table.
Domain: The domain is an object that defines the technical information of the
field, such as data type and length.
Data Element: The data element is an object that specifies the semantic
information of the field, such as description, labels, etc.

(i) STEPS TO CREATE DATA ELEMENT AND THE DOMAIN:

➢ SE11 > select radio button data type, provide name (ZEMPNAME)
➢ Click on create.

BHAVANA Page | 12
SAP ABAP TRAINING
➢ Select data element and click on continue.

➢ Give short description and go to field label tab and save.

➢ Give domain name and double click on the domain name.

BHAVANA Page | 13
SAP ABAP TRAINING
➢ Click on ‘yes’ to create Domain.
➢ Give short description.
➢ Give Data type (Ex: CHAR) and No of Char (8,10,15&20 etc.).

➢ Save, check and activate the Domain. Go Back.


➢ Save, check and activate the Data Element. Go back.

BHAVANA Page | 14
SAP ABAP TRAINING
➢ Create Data elements and Domains for all the fields of the table with respective data
type and no of characters.

ZSB_STUDENT TABLE

(ii) Technical settings for data base table (Delivery class and size
category)

 Click on Technical Settings, Select data class (APPL0) and Size category.

BHAVANA Page | 15
SAP ABAP TRAINING
 DATA CLASS: It defines the actual area of the table inside the database. The
options available
for the data class are given below, which we can select according to our table:

APPL0: Master Data, Transparent Tables (We can access frequently as well as
update rarely)

APPL1: Transaction data.

APPL2: Organizing and customizing.

 SIZE CATEGORY: It determines the space require for the table.

Here Buffering not allowed is selected for which is default value for
Transaction Table where data changes frequently.

BHAVANA Page | 16
SAP ABAP TRAINING
➢ Save the Technical Settings.

➢ Save, check for syntax and activate the table.

BHAVANA Page | 17
SAP ABAP TRAINING
➢ Provide the Data to the table (ZSB_STUDENT).
 In the Menu bar >click on Utilities >table Contents >Create Entries
 Provide the data. Click on save. Refresh. Again provide data.
 Repeat same steps for all the entries.

➢ Steps to Display the records for the Data Base Table.


➢ Menu Barclick on Utilities > Table Contents >
Display.

BHAVANA Page | 18
SAP ABAP TRAINING
➢ Displays Data browser for ZSB_STUDENT table.

➢ Click on Execute (F8).

OUTPUT:

BHAVANA Page | 19
SAP ABAP TRAINING
c) Creating Currency and Quantity field for data base Table:
Currency and Quant fields are special as they need a UNIT that is for currency need
currency type like EURO, USD etc., whereas for quantity need to know the unit
that is KM, HOURS etc.

 CURR: It is the data type which is used to store the currency amount or price
fields.

 CUKY: It is the data type which is used to store the corresponding units (INR
or USD or EURO) 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 (KGS or EA or
PC) for the quantity fields.

BHAVANA Page | 20
SAP ABAP TRAINING
➢ Providing Reference Table and Reference field name for currency and
quantity fields

BHAVANA Page | 21
SAP ABAP TRAINING
6. STRUCTURES IN ABAP

Structure is a data type in DDIC composed of Data element, table types


and tables. it issimilar to table, except it doesn’t have primary key or technical
characteristics.

These are reusable components.

Two types of structures:

1) Include structure: These structures are reusable by multiple tables and used only
withcustom tables.

2) Append structure: These are not reusable and used only by SAP tables.

a) Creating a structure (include structure)


➢ Go to SE11  Select data type  provide name (ZSBinclude)

BHAVANA Page | 22
SAP ABAP TRAINING
➢ Click on create, select structure and provide description.

➢ Specify the fields and data elements and save and activate.

b) Assigning structure to table

1) Include structure: used in only customize table

➢ Open the table which is created already (ZSB_STUDENT)


➢ provide field name as .include
➢ Data element as Structure name (ZSBINCLUDE)

BHAVANA Page | 23
SAP ABAP TRAINING
2) Append structure: used in both customize and standard table

➢ Open table, click on append Structure and provide name (ZSBAPPEND)


➢ Save and activate the table.
➢ Assign append to the table same as include.

BHAVANA Page | 24
SAP ABAP TRAINING
7. FOREIGN KEY RELATIONSHIP

Foreign keys are used to establish the relationship between the different tables present in
the ABAP Dictionary.

The check table is the table that stores the master data. The other table, which is
linked with the check table to validate its own field data, is called a foreign key table.

The foreign key relationship is about relating or connecting two different tables to avoid
redundancy and perform table validations in ABAP.

a) Creation of foreign key relationship between two tables


➢ Go to SE11, create the first database table as Check table (ZSB_BSEG)

➢ Open the Second Table ZSH_BKPF. Select the BUKRS field from the table.

➢ Now click on the foreign keys button.

BHAVANA Page | 25
SAP ABAP TRAINING
➢ New windows will pop, where provide the Check table name, which is containing
the master data.

➢ Now click on the create proposal button, and then click on the copy button.
➢ Click on save, check and activate it.

BHAVANA Page | 26
SAP ABAP TRAINING
8. INDEXES FOR DATA BASE TABLE

Indexes are used to avoid the duplicate data and improve the performance while accessing
the table.

1. Primary Index: Primary indexes in SAP are created automatically by the SAP
systemusing key fields of database tables.

2. Secondary Index: Secondary Indexes are created manually and managed by the
SAPABAP consultant. We can create up to 9 secondary indexes.

a) Creation of secondary index

➢ Go to SE11, Provide Table name


➢ Click on change mode, click on Index and create index.

BHAVANA Page | 27
SAP ABAP TRAINING
➢ Index name provide with 3 characters provide field name and save and activate.

➢ Secondary Index for Table ZSB_EMPL with following fields.

BHAVANA Page | 28
SAP ABAP TRAINING
9. VIEWS IN SAP ABAP

Views are the data dictionary repository objects in ABAP, which are used to view thedata
of several tables in one place.

A view is similar to the database table, but it does not contain any physical data,
instead it derives data from different tables and acts like a virtual table (table without
any existence). Since it does not physically store any data, and the database only
contains the view definition, hence it takes very little space in the database.

a) Creation of Base view


➢ If a view is created on one or more tables by combining the fields using inner join,
such a view is called Database view. Since this view uses the inner join, it only
combines the matching records from the table.

➢ Go to SE11. Click the radio button in front of View option, and give a name to
the view then click the create button given on the screen.

BHAVANA Page | 29
SAP ABAP TRAINING
➢ A pop-up window will appear with all the views, from where select the
"Database view" and click on the Copy button.

➢ A view maintains screen appears that contains multiple tabs, where first provide
the description in the field "Short description”. Select the Table/Join
Conditions tab and will provide the table names (MARA).
➢ When we click on the Relationships button, all the tables with the foreign key
relationship with the base table (MARA) will be displayed.

BHAVANA Page | 30
SAP ABAP TRAINING
➢ As another table, we have selected EKPO (SAP standard table), and clicked
on the copy button, given at the bottom of the screen.

➢ Once we will select the EKPO table, all the join conditions field names will
be filledautomatically.

BHAVANA Page | 31
SAP ABAP TRAINING
➢ Move to the next tab, which is View fields, to select the fields of both tables
that wewant to display
➢ After selecting the fields, click on the Copy button. Similarly, we will choose the
Fields of another table (EKPO).

BHAVANA Page | 32
SAP ABAP TRAINING
BHAVANA Page | 33
SAP ABAP TRAINING
➢ We display the records that we have selected using the database view.
Click onthe Content option given at the screen.

➢ Can view all the records using the execute button given at the above image. It will
display all the records.

OUTPUT:

BHAVANA Page | 34
SAP ABAP TRAINING
b) Creation of Projection view

➢ ABAP Projection views are special views used to hide some fields of a database
table and display only the required or selected fields. Hence, using this type of
view, we can minimize the fields by projecting only required fields and rest fields
will be filtered out.
➢ This view allows us to read and also maintain the needed data.
➢ The projection view is created on a single table only.

Steps:
➢ Go to SE11 Click the radio button in front of view option
➢ Provide a name to the view
➢ click the Create button given on the screen

➢ A pop-up window will appear with all the views, from where select the “PROJECTION

BHAVANA Page | 35
SAP ABAP TRAINING
VIEW”.

➢ Provide Basis Table for the table which view to be created.

➢ Give Fields names, save and activate.

c) Creation of Maintenance view

BHAVANA Page | 36
SAP ABAP TRAINING
➢ Maintenance view is created on two or more tables, which is used to maintain the
data of several tables altogether. It helps us to maintain the complex application
objects easily.
➢ It can combine several tables in a single unit, but the tables must have a foreign
keyrelationship.
➢ It allows us to maintain and read the data of the table.

STEPS:

➢ Go to SE11 Click the radio button in front of View option, and give a name to
the view then click the create button given on the screen.

➢ Pop-up window will appear with all the views, from where select the
"Maintenanceview," and click on the Copy.

BHAVANA Page | 37
SAP ABAP TRAINING
➢ Click on the Table/Join Conditions tab; provide the name of the primary table for
view underthe Table column.

BHAVANA Page | 38
SAP ABAP TRAINING
➢ Go to the View fields tab, click on the Table Fields button to select the fields from
each Table (primary and secondary).

➢ Go to the and select the Maint.Status tab and select the appropriate radio button. Select the
other fields.

BHAVANA Page | 39
SAP ABAP TRAINING
➢ Go to the Utilities> Table Maintenance Generator. Fill the details as shown.
Save it and activate the view.

➢ Now go to sm30 Transaction code and click on maintain. The data will be displayed
as below.

BHAVANA Page | 40
SAP ABAP TRAINING
d) Creation of Help view

➢ The Help views are created on two or more tables, specifically for the "Search-
helps" object in DDIC. It means they are used to provide the input helps (F4)
option for different fields in ABAP.
➢ When going to search help, views with outer join act as the selection methods and
these methods can be either a table or a view, which specifies that data can be
selected from a view or table. For such purpose, we need to create the help views
in ABAP.

Steps to create Help view

➢ Go to SE11 Click the radio button in front Help view.


➢ Provide a name to the view.
➢ Click the Create button given on the screen.

BHAVANA Page | 41
SAP ABAP TRAINING
➢ Pop-up window will appear with all the views, from where select the
“HELPVIEW," and click on the Copy.

➢ Click on the Table/Join Conditions tab; provide the name of the primary
table for view under the Table column.

➢ Move to the next tab, which is View fields, to select the fields of both
tables that wewant to display.

BHAVANA Page | 42
SAP ABAP TRAINING
➢ Select the Maint.Status tab and set the read-only radio button.

➢ Click on the Save and Activate. Once it is activated, we can use the help view
as theselection method for Search Help.

BHAVANA Page | 43
SAP ABAP TRAINING
10. LOCK OBJECTS IN DDIC

To Avoid Parallel access, we use lock objects. is used to synchronize access to thesame
data by more than one program
Whenever we create a lock object two function module will be created.
1) ENQUE: used to lock the object.
2) DEQUE: used to unlock the object.
Whenever we create a lock object naming convention need to be maintained as ‘EZ/EY’.

There are 3 types of Lock Objects:

1. Write/Exclusive lock:

The locked data can only be displayed or edited by a single user. A request for
anotherexclusive lock or for a shared lock is rejected.

2. Read/Shared lock:

More than one user can access the locked data at the same time in display mode. A
request for another shared lock is accepted, even if it comes from another user. An
exclusive lock isrejected.

3. Exclusive but not cumulative:

Exclusive locks can be requested several times from the same transaction and are
processed successively. All other lock requests are rejected.

BHAVANA Page | 44
SAP ABAP TRAINING
a) Creation of lock object

➢ Go to transaction SE11. Click ‘Lock Object’ radio button.


➢ Enter the name of lock object starting with E and click the Create button.

➢ Enter the table name in Name field and select the lock mode as Shared Lock.

BHAVANA Page | 45
SAP ABAP TRAINING
➢ Click on Lock parameter tab, the following screen will appear.

 Save and activate. Automatically 2 function modules will generate. To check


function modules, we can use Go to → Lock Modules.

 Click Lock Modules and the following screen will open.

BHAVANA Page | 46
SAP ABAP TRAINING
11. TABLE TYPE

A Table Type in SAP ABAP is a global reusable object which is used to define structure
and functional attributes of an internal table in ABAP.

➢ Go to SE11. Select radio button Data Type click and create.

➢ Select as Table type and provide short description.

BHAVANA Page | 47
SAP ABAP TRAINING
➢ Provide Line Type as Structure name (ZSBINCLUDE)
➢ Save and activate the data type.

BHAVANA Page | 48
SAP ABAP TRAINING
12. TABLE MAINTENANCE GENERATOR (TMG)

SAP Table Maintenance Generator (TMG) is a tool to generate a table maintenance


program i.e., it will generate a program to maintain (Create, Edit & Delete) entries in
a table.

a) Creation of TMG for data base table

➢ To generate a table maintenance generator (TMG) for a table, Display the table in
ABAP dictionary. (SE11)

BHAVANA Page | 49
SAP ABAP TRAINING
➢ Go to Menu, Utilities –> Table Maintenance Generator
➢ Enter the proper authorization group (&NC& is without any authorization) and
function group and Select “one step” for maintenance type
➢ Click on “Find screen Numbers” on application toolbar.

➢ Select Propose screen numbers and click on continue. The screen number
for overviewscreen will be automatically populated. Now click on Create

BHAVANA Page | 50
SAP ABAP TRAINING
b) Creating Transaction code for table maintenance generator

➢ Table maintenance program is created bar. Now to maintain entries in the table,
➢ Go to Maintain Table Views (SM30) and enter table name and click on maintain.

➢ Here we can maintain records by updating or deleting or modifying.


➢ Click on New Entries button on application toolbar to maintain new entries in the table.
➢ Go to transaction code SE93, enter the transaction code name and click create.

BHAVANA Page | 51
SAP ABAP TRAINING
➢ Enter the short text; select the radio button “Transaction with
parameters(parameter transaction)” and click continue.

BHAVANA Page | 52
SAP ABAP TRAINING
 Select check box skip initial screen and Select All the GUI support
options SelectAll the GUI support options

 Provide screen filed value as view name (TABLE NAME


ZSB_STUDENT) andUPDATE (X) then Save it.

BHAVANA Page | 53
SAP ABAP TRAINING
13. SEARCH HELP

 Providing a help for the list of the values to be selected on input field is
calledsearch help.

 There are two types of search helps.

1. Elementary search help: A single search help for an input field is


calledelementary search help.

2. Collective search help: Group of elementary search help for a single


inputfield is called collective search help.

a) Creating Elementary Search Help

 Go to SE11

 Select search help radio button and provide name.

 Click on ‘Create’.

BHAVANA Page | 54
SAP ABAP TRAINING
 Select ‘elementary search help’.

 Give short description.

 Provide selection method (ZSB_T001).

 Provide the parameter.

 Save and activate.

BHAVANA Page | 55
SAP ABAP TRAINING
b) Creating Collective Search Help

 Go to SE11 and select search help radio button.

 Provide name and click on ‘Create’.

 Select ‘Collective Search Help’ radio button.

 Give short description.

 Provide the values in definition tab.

BHAVANA Page | 56
SAP ABAP TRAINING
 Select ‘include search help’ tab and provide the search help name which we create
inelementary search help.

 Save and activate.


BHAVANA Page | 57
SAP ABAP TRAINING
14. TYPES OF TABLES
There are 3 Types of tables:
1. Transparent tables
2. Cluster tables
3. Pool tables

Transparent tables: - Transparent tables are one to one relationship. That is if


you create one transparent table in the data dictionary, then it’ll store like only
one data base table in the data base.

Cluster table: - This tables are many – one relationship. That is if you create the
many clustered tables in DDIC then they will form like a table cluster & store in
the data base. Buffering isn’t possible for clustered table. From this reason only
fetching the data from clustered table take more time. Clustered table is suitable
when you fetch the fewer amounts of data from more fields.

Pooled table: - Pooled tables are many – one relationship. That means if you
create many pooled tables in DDIC, then they will form like a table pool & stored
in the data base. Pooled tables are suitable when we fetch the large amount of
data from fewer fields.

BHAVANA Page | 58
SAP ABAP TRAINING
15. 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 across the page width)
 Write / 25 sy-vline. (Displays Vertical line of height 1 line)
 Write / sy-datum. (Displays system’s date as per date settings in SU3 Tcode)
 Write / sy-uzeit. (Displays system’s time)
 Write / sy-uname. (Displays system’s username)
 Write / sy-repid. (Displays report name)

WRITE: It is the Statement which is used to print a text on the output screen.
It is similar to PRINTF in C language.
Ex: Write ‘hello world’.
Syntax: Write: / pos (width) ‘text1’ left/right/centered justified color <color number>.

CHAIN OPERATOR: It is a statement which is used to display multiple texts which


are separated by using a single WRITE statement.

 ‘ / ’  Represents New Line


BHAVANA Page | 59
SAP ABAP TRAINING
a) Creating program using system variables

REPORT ZSB_MYFIRSTPROGRAM.

write 'hello this is my first program'.


write / 'hello world'.

write / 'hello'.
write ' this is' .
write ' my first program' .
write :/ 'hello' , ' this is' , ' my first program'.

write : ' bhavana' COLOR 1.


write / : 'bhavana' COLOR 1.
write / : 'bhavana' COLOR 2.
write / : 'bhavana' COLOR 3.
write / : 'bhavana' COLOR 4.
write / : 'bhavana' COLOR 5.
write / : 'bhavana' COLOR 6.
write / : 'bhavana' COLOR 7.
write / : 'bhavana' COLOR 1 INVERSE.
write / : 'bhavana' COLOR 2 INVERSE.
write / : 'bhavana' COLOR 3 INVERSE.
write / : 'bhavana' COLOR 4 INVERSE.
write / : 'bhavana' COLOR 5 INVERSE.
write / : 'bhavana' COLOR 6 INVERSE.
write / : 'bhavana' COLOR 7 INVERSE.
skip.
WRITE : 40 'welcome'.
WRITE : /(40) 'welcome'.

WRITE : 50(32) 'welcome'.

BHAVANA Page | 60
SAP ABAP TRAINING
WRITE : 50(32) 'welcome' LEFT-JUSTIFIED.
WRITE : 50(32) 'welcome' CENTERED.
WRITE : 50(32) 'welcome' RIGHT-JUSTIFIED.
WRITE : 25(25) 'welcome' LEFT-JUSTIFIED color 1.
skip.
WRITE : 25(25) 'welcome' right-justified color 2.
skip.
WRITE : 25(25) 'welcome' centered color 3.
skip.
WRITE : 25(25) 'welcome' LEFT-JUSTIFIED COLOR 4 INVERSE .
SKIP.
write /25 sy-uline.
SKIP.
write /25 sy-vline.

write / sy-datum.
write / sy-uzeit.
write / sy-uname.
write / sy-repid.

write /25(25) sy-uline.


write /25 sy-vline.
write 49 sy-vline.
write /25(25) sy-uline.

write /(50) sy-uline.


write / sy-vline.
write 25 sy-vline.
write 50 sy-vline.
write /(50) sy-uline.
write / sy-vline.
write 25 sy-vline.

BHAVANA Page | 61
SAP ABAP TRAINING
write 50 sy-vline.
write /(50) sy-uline.

OUTPUT:

BHAVANA Page | 62
SAP ABAP TRAINING
b) Create a database table using system variables

REPORT ZSB_MYFIRSTPROGRAM.

*table1**

write /(100) sy-uline.


write / sy-vline.
write (90) 'CUSTOMER REPORT' centered color 6 inverse.
write 100 sy-vline.
write / sy-vline.
write 100 sy-vline.

write /(100) sy-uline.


write / sy-vline.
write 'cno'.
write 25 sy-vline.
write 'cname'.
write 50 sy-vline.
write 'city'.
write 75 sy-vline.
write 'country'.
write 100 sy-vline.
write /(100) sy-uline.

BHAVANA Page | 63
SAP ABAP TRAINING
write / sy-vline.
write 25 sy-vline.
write 50 sy-vline.
write 75 sy-vline.
write 100 sy-vline.
write /(100) sy-uline.
skip.

*table2**

write /(50) sy-uline.


write / sy-vline.
write (45) 'REPORT ' centered.
write 50 sy-vline.

write /(50) sy-uline.


write / sy-vline.
write '1.BHAVANA'.
write 25 sy-vline.
write 'SAP TRAINING'.
write 50 sy-vline.
write /(50) sy-uline.

BHAVANA Page | 64
SAP ABAP TRAINING
write / sy-vline.
write '2.PAVAN'.
write 25 sy-vline.
write 'ABAP TRAINING'.
write 50 sy-vline.
write /(50) sy-uline.

OUTPUT:

BHAVANA Page | 65
SAP ABAP TRAINING
16. CONDITIONAL STATEMENTS
Conditional statements are used to execute block of statements based on given condition.

Types of conditional statements:


IF...ENDIF
Syntax: If<condition>.
<statement block>.
Endif.

IF–ELSE...ENDIF
Syntax: If<condition>.
<statement block>.
Else.
<statement block>.
Endif.

IF-ELSEIF-ELSE...ENDIF
Syntax: If<condition>.
<statement block>.
Elseif.
<statement block>.
Else.
<statement block>.
Endif.

BHAVANA Page | 66
SAP ABAP TRAINING
CASE-WHEN...ENDIF
Syntax: Case<field>.
When<field1>.
<statement block>.
When<field2>.
<statement block>.
When others.
<statement block>.
Endcase.

LOOPING:

 Conditional (Do-Enddo).
 Un Conditional (While-Endwhile).

Do Statement:
Syntax:
Do <N> times.

...
...

Enddo.

BHAVANA Page | 67
SAP ABAP TRAINING
While Statement:
Syntax:
While <condition>.

...
...

Endwhile.

a) Creating a program using all conditional statements

REPORT ZSB_CONDITIONAL_STMTS.

data: gv_num type i.

gv_num = 10.

if gv_num < 15.


write: 'smaller number'.
endif.

skip.

gv_num = 150.
if gv_num < 15.

BHAVANA Page | 68
SAP ABAP TRAINING
write: 'smaller number'.
else.
write: 'Bigger number'.
endif.

skip.

data: gv_num1 type i.

parameters p_num type i.


gv_num1 = p_num.

if gv_num1 = 1.
write: 'sunday'.
elseif gv_num1 = 2.
write: 'monday'.
else.
write: 'the number is invalid'.
endif.

skip.

data: gv_num2 type i.


gv_num2 = p_num.

BHAVANA Page | 69
SAP ABAP TRAINING
case gv_num2.
when 1.
write: 'sunday'.
when 2.
write: 'monday'.
when others.
write: 'the number is invalid'.
endcase.

skip.

data: gv_num3 type i.


gv_num3 = 10.

while gv_num3 < 15.


write:/' SAP ABAP TRAINING'.
gv_num3 = gv_num3 + 1.
endwhile.

skip.

data: gv_num4 type i.


gv_num4 = 10.
do gv_num4 times.
write:/' SAP ABAP TRAINING'.
enddo.

skip.

write: 'program ended'.

BHAVANA Page | 70
SAP ABAP TRAINING
OUTPUT:

BHAVANA Page | 71
SAP ABAP TRAINING
17. LOOP BREAK STATEMENTS

If you want to break the normal flow of an ABAP loop, you need control break statements.

ABAP provide three-loop control statements, i.e., EXIT, STOP and CONTINUE.

 Exit statement: it will come out of the loop but it will stay inside the program.

 Stop Statement: it will come out of the loop and come out of the program.

 Continue statement: it will Skip the current iteration and go for the next iteration.

a) Create a program using exit statement

REPORT ZSB_INTERNALTABLE5.

TYPES: BEGIN OF ty_emp,


eid TYPE char10,
ename TYPE char25,
eadd TYPE char35,
amnt TYPE i,
END OF ty_emp.

data:gt_emp TYPE STANDARD TABLE OF ty_emp,


gs_Emp TYPE ty_emp.

BHAVANA Page | 72
SAP ABAP TRAINING
gs_emp-eid = 1.
gs_emp-ename = 'bhavana'.
gs_Emp-eadd = 'ongole'.
gs_emp-amnt = 500.

append gs_emp TO gt_emp.


clear gs_emp.
gs_emp-eid = 2.
gs_emp-ename = 'pavan'.
gs_Emp-eadd = 'Hyderabad'.
gs_emp-amnt = 500.

append gs_emp TO gt_emp.


clear gs_emp.
gs_emp-eid = 3.
gs_emp-ename = 'sai'.
gs_Emp-eadd = 'chennai'.
gs_emp-amnt = 500.

append gs_emp TO gt_emp.


clear gs_emp.

gs_emp-eid = 4.
gs_emp-ename = ' '.
gs_Emp-eadd = 'HYDERABAD'.
gs_emp-amnt = 500.

append gs_emp TO gt_emp.


clear gs_emp.

BHAVANA Page | 73
SAP ABAP TRAINING
gs_emp-eid = 5.
gs_emp-ename = 'rani'.
gs_Emp-eadd = 'hyd'.
gs_emp-amnt = 500.

insert gs_emp INTO gt_emp INDEX 1.


clear gs_emp.

gs_emp-eid = 6.
gs_emp-ename = 'raj'.
gs_Emp-eadd = 'delhi'.
gs_emp-amnt = 500.

insert gs_emp INTO gt_emp INDEX 2.


clear gs_emp.

gs_emp-eid = 7.
gs_emp-ename = 'ram'.
gs_Emp-eadd = 'goa'.
gs_emp-amnt = 500.

insert gs_emp INTO gt_emp INDEX 3.


clear gs_emp.

gs_emp-eid = 1.
gs_emp-ename = 'bhavana'.
gs_Emp-eadd = 'ongole'.
gs_emp-amnt = 500.

BHAVANA Page | 74
SAP ABAP TRAINING
collect gs_emp INTO gt_emp.
clear gs_emp.

gs_emp-eid = 2.
gs_emp-ename = 'pavan'.
gs_Emp-eadd = 'Hyderabad'.
gs_emp-amnt = 500.

collect gs_emp INTO gt_emp.


clear gs_emp.

gs_emp-eid = 3.
gs_emp-ename = 'sai'.
gs_Emp-eadd = 'chennai'.
gs_emp-amnt = 500.

collect gs_emp INTO gt_emp.


clear gs_emp.

gs_emp-eid = 4.
gs_emp-ename = ' '.
gs_Emp-eadd = 'HYDERABAD'.
gs_emp-amnt = 500.

collect gs_emp INTO gt_emp.


clear gs_emp.
gs_emp-eid = 5.
gs_emp-ename = 'rani'.
gs_Emp-eadd = 'hyd'.

BHAVANA Page | 75
SAP ABAP TRAINING
gs_emp-amnt = 500.

collect gs_emp INTO gt_emp.


clear gs_emp.

gs_emp-eid = 6.
gs_emp-ename = 'raj'.
gs_Emp-eadd = 'delhi'.
gs_emp-amnt = 500.

collect gs_emp INTO gt_emp.


clear gs_emp.

gs_emp-eid = 7.
gs_emp-ename = 'ram'.
gs_Emp-eadd = 'goa'.
gs_emp-amnt = 500.

collect gs_emp INTO gt_emp.


clear gs_emp.

loop at gt_emp into gs_emp.


if gs_emp-eadd = 'goa'.

exit.
" it will come out of the loop and and will stay inside the program to execute
another statements.
endif.

BHAVANA Page | 76
SAP ABAP TRAINING
write:/ gs_emp-eid,
gs_emp-ename,
gs_Emp-eadd,
gs_emp-amnt.
endloop.
skip 3.

WRITE:/ 'program ends'.

OUTPUT:

BHAVANA Page | 77
SAP ABAP TRAINING
b) Create a program using stop statement

REPORT ZSB_INTERNALTABLE6.

TYPES: BEGIN OF ty_emp,


eid TYPE char10,
ename TYPE char25,
eadd TYPE char35,
amnt TYPE i,
END OF ty_emp.

DATA: gt_emp TYPE STANDARD TABLE OF ty_emp,


gs_Emp TYPE ty_emp.

gs_emp-eid = 1.
gs_emp-ename = 'bhavana'.
gs_Emp-eadd = 'ongole'.
gs_emp-amnt = 500.

append gs_emp TO gt_emp.


clear gs_emp.

gs_emp-eid = 2.
gs_emp-ename = 'pavan'.
gs_Emp-eadd = 'Hyderabad'.

BHAVANA Page | 78
SAP ABAP TRAINING
gs_emp-amnt = 500.

append gs_emp TO gt_emp.


clear gs_emp.
gs_emp-eid = 3.

gs_emp-ename = 'sai'.
gs_Emp-eadd = 'chennai'.
gs_emp-amnt = 500.

append gs_emp TO gt_emp.


clear gs_emp.

gs_emp-eid = 4.
gs_emp-ename = ' '.
gs_Emp-eadd = 'HYDERABAD'.
gs_emp-amnt = 500.

append gs_emp TO gt_emp.


clear gs_emp.

gs_emp-eid = 5.

BHAVANA Page | 79
SAP ABAP TRAINING
gs_emp-enamgs_emp-amnt = 500.

insert gs_emp INTO gt_emp INDEX 1.


clear gs_emp.

gs_emp-eid = 6.
gs_emp-ename = 'raj'.
gs_Emp-eadd = 'delhi'.
gs_emp-amnt = 500.

insert gs_emp INTO gt_emp INDEX 2.


clear gs_emp.

gs_emp-eid = 7.
gs_emp-ename = 'ram'.
gs_Emp-eadd = 'goa'.
gs_emp-amnt = 500.

insert gs_emp INTO gt_emp INDEX 3.


clear gs_emp.

gs_emp-eid = 1.

BHAVANA Page | 80
SAP ABAP TRAINING
gs_emp-ename = 'bhavana'.
gs_Emp-eadd = 'ongole'.
gs_emp-amnt = 500.

collect gs_emp INTO gt_emp.


clear gs_emp.

gs_emp-eid = 2.
gs_emp-ename = 'pavan'.
gs_Emp-eadd = 'Hyderabad'.
gs_emp-amnt = 500.

collect gs_emp INTO gt_emp.


clear gs_emp.

gs_emp-eid = 3.
gs_emp-ename = 'sai'.
gs_Emp-eadd = 'chennai'.
gs_emp-amnt = 500.

collect gs_emp INTO gt_emp.


clear gs_emp.

BHAVANA Page | 81
SAP ABAP TRAINING
gs_emp-eid = 4.
gs_emp-ename = ' '.
gs_Emp-eadd = 'HYDERABAD'.
gs_emp-amnt = 500.
collect gs_emp INTO gt_emp.
clear gs_emp.

gs_emp-eid = 5.
gs_emp-ename = 'rani'.
gs_Emp-eadd = 'hyd'.
gs_emp-amnt = 500.

collect gs_emp INTO gt_emp.


clear gs_emp.

gs_emp-eid = 6.
gs_emp-ename = 'raj'.
gs_Emp-eadd = 'delhi'.
gs_emp-amnt = 500.

collect gs_emp INTO gt_emp.


clear gs_emp.

BHAVANA Page | 82
SAP ABAP TRAINING
gs_emp-eid = 7.
gs_emp-ename = 'ram'.
gs_Emp-eadd = 'goa'.
gs_emp-amnt = 500.

collect gs_emp INTO gt_emp.


clear gs_emp.

loop at gt_emp into gs_emp.


if gs_emp-ename = 'bhavana'.
stop. " it will come out of the loop and also come out of the program execution.
endif.

write:/ gs_emp-eid,
gs_emp-ename,
gs_Emp-eadd,
gs_emp-amnt.
endloop.
skip 3.

WRITE:/ 'program ends'.

BHAVANA Page | 83
SAP ABAP TRAINING
OUTPUT:

c) Create a program using continue statement

REPORT ZSB_INTERNALTABLE4.

TYPES: BEGIN OF ty_emp,


eid TYPE char10,
ename TYPE char25,
eadd TYPE char35,
amnt TYPE i,
END OF ty_emp.

data:gt_emp TYPE STANDARD TABLE OF ty_emp,


gs_Emp TYPE ty_emp.

gs_emp-eid = 1.
gs_emp-ename = 'bhavana'.
gs_Emp-eadd = 'ongole'.
gs_emp-amnt = 500.

append gs_emp TO gt_emp.


clear gs_emp.

BHAVANA Page | 84
SAP ABAP TRAINING
gs_emp-eid = 2.
gs_emp-ename = 'pavan'.
gs_Emp-eadd = 'Hyderabad'.
gs_emp-amnt = 500.

append gs_emp TO gt_emp.


clear gs_emp.

gs_emp-eid = 3.
gs_emp-ename = 'sai'.
gs_Emp-eadd = 'chennai'.
gs_emp-amnt = 500.

append gs_emp TO gt_emp.


clear gs_emp.

gs_emp-eid = 4.
gs_emp-ename = ' '.
gs_Emp-eadd = 'HYDERABAD'.
gs_emp-amnt = 500.

append gs_emp TO gt_emp.


clear gs_emp.

gs_emp-eid = 5.
gs_emp-ename = 'rani'.
gs_Emp-eadd = 'hyd'.
gs_emp-amnt = 500.

insert gs_emp INTO gt_emp INDEX 1.


clear gs_emp.

BHAVANA Page | 85
SAP ABAP TRAINING
gs_emp-eid = 6.
gs_emp-ename = 'raj'.
gs_Emp-eadd = 'delhi'.
gs_emp-amnt = 500.

insert gs_emp INTO gt_emp INDEX 2.


clear gs_emp.

gs_emp-eid = 7.
gs_emp-ename = 'ram'.
gs_Emp-eadd = 'goa'.
gs_emp-amnt = 500.

insert gs_emp INTO gt_emp INDEX 3.


clear gs_emp.

gs_emp-eid = 1.
gs_emp-ename = 'bhavana'.
gs_Emp-eadd = 'ongole'.
gs_emp-amnt = 500.

collect gs_emp INTO gt_emp.


clear gs_emp.

gs_emp-eid = 2.
gs_emp-ename = 'pavan'.
gs_Emp-eadd = 'Hyderabad'.
gs_emp-amnt = 500.

collect gs_emp INTO gt_emp.

BHAVANA Page | 86
SAP ABAP TRAINING
clear gs_emp.

gs_emp-eid = 3.
gs_emp-ename = 'sai'.
gs_Emp-eadd = 'chennai'.
gs_emp-amnt = 500.

collect gs_emp INTO gt_emp.


clear gs_emp.

gs_emp-eid = 4.
gs_emp-ename = ' '.
gs_Emp-eadd = 'HYDERABAD'.
gs_emp-amnt = 500.

collect gs_emp INTO gt_emp.


clear gs_emp.

gs_emp-eid = 5.
gs_emp-ename = 'rani'.
gs_Emp-eadd = 'hyd'.
gs_emp-amnt = 500.

collect gs_emp INTO gt_emp.


clear gs_emp.

gs_emp-eid = 6.
gs_emp-ename = 'raj'.
gs_Emp-eadd = 'delhi'.
gs_emp-amnt = 500.

BHAVANA Page | 87
SAP ABAP TRAINING
collect gs_emp INTO gt_emp.
clear gs_emp.

gs_emp-eid = 7.
gs_emp-ename = 'ram'.
gs_Emp-eadd = 'goa'.
gs_emp-amnt = 500.

collect gs_emp INTO gt_emp.


clear gs_emp.

loop at gt_emp into gs_emp.

if gs_emp-eadd = 'chennai'.
CONTINUE. " it will skip the iteration and go to the next iteration.
endif.

write:/ gs_emp-eid,
gs_emp-ename,
gs_Emp-eadd,
gs_emp-amnt.
endloop.

skip 3.
WRITE:/ 'program ends'.

BHAVANA Page | 88
SAP ABAP TRAINING
OUTPUT:

BHAVANA Page | 89
SAP ABAP TRAINING
18. PROCESSING STATEMENTS
APPEND: It is a keyword used to transfer data from work area to the last
record of internal table.

INSERT: it will save anywhere in the based on the index number.

COLLECT: It will save the records but the remove the duplicates.

a) Create a program using processing statements

REPORT ZSB_INTERNALTABLE3.

TYPES: BEGIN OF ty_emp,


eid TYPE char10,
ename TYPE char25,
eadd TYPE char35,
amnt TYPE i,
END OF ty_emp.

data:gt_emp TYPE STANDARD TABLE OF ty_emp,


gs_Emp TYPE ty_emp.

gs_emp-eid = 1.
gs_emp-ename = 'bhavana'.
gs_Emp-eadd = 'ongole'.
gs_emp-amnt = 500.

append gs_emp TO gt_emp.


clear gs_emp.
gs_emp-eid = 2.

BHAVANA Page | 90
SAP ABAP TRAINING
gs_emp-ename = 'pavan'.
gs_Emp-eadd = 'Hyderabad'.
gs_emp-amnt = 500.

append gs_emp TO gt_emp.


clear gs_emp.

gs_emp-eid = 3.
gs_emp-ename = 'sai'.
gs_Emp-eadd = 'chennai'.
gs_emp-amnt = 500.

append gs_emp TO gt_emp.


clear gs_emp.

gs_emp-eid = 4.
gs_emp-ename = ' '.
gs_Emp-eadd = 'HYDERABAD'.
gs_emp-amnt = 500.

append gs_emp TO gt_emp.


clear gs_emp.

gs_emp-eid = 5.
gs_emp-ename = 'rani'.
gs_Emp-eadd = 'hyd'.
gs_emp-amnt = 500.

insert gs_emp INTO gt_emp INDEX 1.

BHAVANA Page | 91
SAP ABAP TRAINING
clear gs_emp.
gs_emp-eid = 6.
gs_emp-ename = 'raj'.
gs_Emp-eadd = 'delhi'.
gs_emp-amnt = 500.

insert gs_emp INTO gt_emp INDEX 2.


clear gs_emp.

gs_emp-eid = 7.
gs_emp-ename = 'ram'.
gs_Emp-eadd = 'goa'.
gs_emp-amnt = 500.

insert gs_emp INTO gt_emp INDEX 3.


clear gs_emp.

gs_emp-eid = 1.
gs_emp-ename = 'bhavana'.
gs_Emp-eadd = 'ongole'.
gs_emp-amnt = 500.

collect gs_emp INTO gt_emp.


clear gs_emp.

gs_emp-eid = 2.
gs_emp-ename = 'pavan'.
gs_Emp-eadd = 'Hyderabad'.

BHAVANA Page | 92
SAP ABAP TRAINING
gs_emp-amnt = 500.

collect gs_emp INTO gt_emp.


clear gs_emp.

gs_emp-eid = 3.
gs_emp-ename = 'sai'.
gs_Emp-eadd = 'chennai'.
gs_emp-amnt = 500.

collect gs_emp INTO gt_emp.


clear gs_emp.

gs_emp-eid = 4.
gs_emp-ename = ' '.
gs_Emp-eadd = 'HYDERABAD'.
gs_emp-amnt = 500.

collect gs_emp INTO gt_emp.


clear gs_emp.

gs_emp-eid = 5.
gs_emp-ename = 'rani'.
gs_Emp-eadd = 'hyd'.
gs_emp-amnt = 500.

collect gs_emp INTO gt_emp.


clear gs_emp.

gs_emp-eid = 6.
gs_emp-ename = 'raj'.
gs_Emp-eadd = 'delhi'.

BHAVANA Page | 93
SAP ABAP TRAINING
gs_emp-amnt = 500.

collect gs_emp INTO gt_emp.


clear gs_emp.

gs_emp-eid = 7.
gs_emp-ename = 'ram'.
gs_Emp-eadd = 'goa'.
gs_emp-amnt = 500.
collect gs_emp INTO gt_emp.
clear gs_emp.

loop at gt_emp into gs_emp.


write:/ gs_emp-eid,
gs_emp-ename,
gs_Emp-eadd,
gs_emp-amnt.
endloop.
skip 3.
loop at gt_emp into gs_emp WHERE ename = 'bhavana'.
write:/ gs_emp-eid,
gs_emp-ename,
gs_Emp-eadd,
gs_emp-amnt.
endloop.
skip 3.
loop at gt_emp into gs_emp FROM 3 to 6.
write:/ gs_emp-eid,
gs_emp-ename,
gs_Emp-eadd,
gs_emp-amnt.

BHAVANA Page | 94
SAP ABAP TRAINING
endloop.
skip 3.
WRITE:/ 'program ends'.

OUTPUT:

BHAVANA Page | 95
SAP ABAP TRAINING
19. INTERNAL TABLE AND WORK AREA

INTERNAL TABLE: (Heart of the ABAP)

Run time instance of database table / Xerox copy of database table.


It is a temporary location which is created during runtime of a program to store the data of
database tables.
Syntax:
DATA : <ITAB_NAME> TYPE TABLE OF <DATABASE TABLE NAME>
(Or)

DATA : <ITAB_NAME> TYPE TABLE OF <USER DEFINED TYPE>

WORK AREA:

A temporary memory location which can store a single record.

Syntax:
DATA: <WANAME> TYPE <DATABASE TABLENAME>.
(Or)
DATA: <WANAME>TYPE<USER DEFINED TYPE>.

Accessing work areas:


Syntax:
<WANAME>-<FIELDNAME> = ‘VALUE’.

BHAVANA Page | 96
SAP ABAP TRAINING
Variable:
A temporary memory location which can store a single value.

Reading the data from data base tables:


Select is the statement which is used to read the data from data base tables into
internal tables.
Syntax:
SELECT <F1>
<F2>
<F3> (OR) *
FROM <DATABASE TABLE NAME>
INTO TABLE <ITAB NAME>
WHERE <CONDITION>.

Displaying internal table data:


To display each record from internal table, we need to read each record in to work area
and then use the WRITE statement and display each field.

Syntax:
LOOP AT
<ITAB NAME> INTO <WA NAME>
ENDLOOP.

BHAVANA Page | 97
SAP ABAP TRAINING
Types:
It is a statement which is used to declare our own custom data types.
Then we can declare our variables referring to above user defined data types.

Syntax:
TYPES: BEGIN OF <USER DEFINED TYPE NAME>,
<F1> TYPE <TABLE NAME- FIELD NAME>,
<F2> TYPE <TABLE NAME- FIELD NAME>,
<F3> TYPE <TABLE NAME- FIELD NAME>,
END OF <USER DEFINED TYPE NAME>.

Into corresponding fields:


It is the statement which is used to compare each field from source to target internal table which
puts extra burden on the data base.

*** We should never use this statement in Real-Time.

Syntax:
SELECT <F1>
<F2>
<F3>
FROM <DATA BASE TABLE>
INTO CORRESPONDING FIELDS OF TABLE <ITAB>.

BHAVANA Page | 98
SAP ABAP TRAINING
Best programming standards:
1. Always declare the internal tables using user defined TYPES statement.
2. Never use SELECT *, instead of use select list of the fields.
3. Never use INTO CORRESPONDING FIELDS OF.
4. The source list of the fields and the target internal table fields list must be same.

List of the internal table operations:


1. APPEND
2. INSERT
3. SORT
4. DESCRIBE TABLE
5. READ TABLE
6. LOOP AT
7. MODIFY
8. DELETE
9. DELETE ADJACENT DUPLICATES FROM
10. CLEAR
11. REFRESH
12. FREE
13. COLLECT
14. MOVE-CORRESPONDING
15. APPEND LINES OF
16. INSERT LINES OF

BHAVANA Page | 99
SAP ABAP TRAINING
APPEND
This statement is used to add a single record from work area to internal table.
The record always added at the bottom of the internal table.
Syntax:
APPEND <WA> TO <ITAB>.

INSERT
This statement is used to insert the record from work area into internal table at a specified
location.
Syntax:
INSERT <WA> INTO <ITAB> INDEX <NO>.

SORT
This is the statement used to sort the internal table data either in ascending order or descending
order.
Sort statement start’s the data by ascending order by default.
It sort’s based on order of the fields i.e., F1, F2, and F3......
Syntax:
SORT <ITAB> BY <F1>
<F2>
<F3> <ASCENDING / DESCENDING>.

BHAVANA Page | 100


SAP ABAP TRAINING
DESCRIBE TABLE
This statement is used to find the total no of records in an internal table.
Syntax:
DESCRIBE TABLE <ITAB> LINES <VAR NAME>

READ TABLE
This statement is used to read a single record from internal table into work area.
There are two forms of the read statement
1. With index
2. With Key

Read Table with Index:


This statement will read the record specified by the index number into work area.
Syntax:
READ TABLE <ITAB> INTO <WA> INDEX <NO>.

Read Table with Key:


This statement is used to read a single record from internal table into work area which is
specified by the field values.
Syntax:
READ TABLE <ITAB> INTO <WA> WITH KEY<F1> = <VALUE>
<F2> = <VALUE>
BINARY SEARCH.

BHAVANA Page | 101


SAP ABAP TRAINING
Note:
The pre-requisite for the above statement is the internal table should be sorted in ascending
order.
Binary Search:
It is one type of algorithm which is used to improve the time taken for reading a record from an
internal table.
In real time every read statement will have Binary search keyword.

LOOP AT.......ENDLOOP
This statement is used to read multiple records from internal table in to work area one by one.

Syntax 1:
LOOP AT <ITAB> INTO <WA>.
....
....
....
ENDLOOP.

Syntax 2:
LOOP AT <ITAB> INTO <WA> FROM <N1> TO <N2>.
.....
.....
ENDLOOP.

BHAVANA Page | 102


SAP ABAP TRAINING
Syntax 3:
LOOP AT <ITAB> INTO <WA> WHERE <FNAME1 = VALUE>
<FNAME2 = VALUE>
....
....
....
ENDLOOP.

MODIFY
This statement is used to modify a single record or multiple records based on the condition.
Syntax:
MODIFY <ITAB> FROM <WA>
INDEX<NO>
TRANSPORTING <FNAMEl>
<FNAME2>
<FNAME3>.

DELETE
This statement is used to delete the data from internal table.
Syntax:
1. DELETE <ITAB> FROM <WA>.
2. DELETE <ITAB> INDEX <NO>.
3. DELETE <ITAB> WHERE<F1> = <VALUE>
<F2> = <VALUE>.

BHAVANA Page | 103


SAP ABAP TRAINING
DELETE ADJACENT DUPLICATES FROM
This statement is used to delete the duplicate records which are adjacent i.e., side by side
to each other.
The pre-requisite for this statement is the internal table should be sorted in ascending order.
Syntax:
DELETE ADJACENT DUPLICATES FROM <ITAB> COMPARING <F1>
<F2>
<F3> (Or)
ALL FIELDS.

CLEAR
This statement is used to delete the data from a variable or work area or internal table.
Syntax:
1. CLEAR <VARIABLE NAME>.
2. CLEAR <WORK AREA>
3. CLEAR <ITAB> [].

REFRESH
This statement is used to delete the data from internal table only.
Syntax:
REFRESH <ITAB NAME>.

BHAVANA Page | 104


SAP ABAP TRAINING
FREE
This statement is similar to CLEAR and REFRESH
i.e., it will also delete the data from a variable, work area, internal table.
But the difference is,
 With the clear and refresh statement the data will be deleted but not the memory.
 With the FREE statement the data will be deleted and memory also.
Syntax:
1. FREE <VARIABLE NAME>.
2. FREE <WORK>.
3. FREE <ITAB>.

COLLECT
It is similar to APPEND statement.

The difference between the APPEND and COLLECT is,


The COLLECT statement check’s whether the work area record already exists in the internal
table or not.
 If it exists it will add the numeric field.
 If it doesn’t exist it will add new record to internal table. (APPEND)

Syntax:
COLLECT <WA> INTO <ITAB>.

BHAVANA Page | 105


SAP ABAP TRAINING
APPEND LINES OF
This statement is used to add multiple records from one ITAB to another ITAB.
Syntax:
APPEND LINES OF <ITAB> FROM <N1> TO <N2><ITAB2>.

INSERT LINES OF
This statement is used to add the data from one internal table another internal table at a specified
location with INDEX number.
Syntax:
INSERT LINES OF <ITAB> FROM <N1> TO <N2><ITAB2>INDEX <NO>.

MOVE CORRESPONDING:
This statement is used to move the data for corresponding fields from one work area to another
work area.
Syntax:
MOVE-CORRESPONDING <WAI> TO <WA2>.

Note:
This is a very dangerous statement as it has to compare each field from source work area to
target work area instead of use below statement.

BHAVANA Page | 106


SAP ABAP TRAINING
20. JOINS
 This statement is used to fetch the data simultaneously from multiple tables.

 That means the multiple tables must be joined using one or two fields.

 There should be at least one common field between tables.

 There are two types of joins.

 INNER JOIN

 OUTER JOIN

a) Creating a program using inner join


Inner join:
1. In this join only the matching records between the tables will be fetched.
2.The unmatched records are not selected.

REPORT zsb_inner_join.
TYPES: BEGIN OF ty_final,
vbeln TYPE vbak-vbeln,
erdat TYPE vbak-erdat,
ernam TYPE vbak-ernam,
auart TYPE vbak-auart,
vkorg TYPE vbak-vkorg,
posnr TYPE vbap-posnr,
matnr TYPE vbap-matnr,

BHAVANA Page | 107


SAP ABAP TRAINING
matkl TYPE vbap-matkl,
*** mtart TYPE mara-mtart,
*** mbrsh TYPE mara-mbrsh,
END OF ty_final.

DATA : gt_final TYPE TABLE OF ty_final,


gs_Final TYPE ty_final.
* gt_lines TYPE i.

SELECT a~vbeln
a~erdat
a~ernam
a~auart
a~vkorg
b~posnr
b~matnr
b~matkl
** c~mtart
** c~mbrsh
INTO TABLE gt_final FROM vbak AS a
INNER JOIN vbap AS b ON a~vbeln = b~vbeln
**** INNER JOIN mara as c on b~matnr = c~matnr
WHERE vkorg = 1010. "and auart = 'TA'.

BHAVANA Page | 108


SAP ABAP TRAINING
"DESCRIBE TABLE gt_Final LINES gt_lines.
"WRITE: gt_lines, 'No of records'.

LOOP AT gt_final INTO gs_final.


WRITE : / gs_final-vbeln,
gs_Final-posnr,
gs_Final-matnr,
gs_final-matkl,
gs_Final-ernam,
gs_final-vkorg,
gs_Final-erdat,
gs_final-auart.
ENDLOOP.

OUTPUT:

BHAVANA Page | 109


SAP ABAP TRAINING
b) Creating a program using outer join
Outer join:
1. In this join all the records from the first table or left table will be selected first.

2. If there are any matching records from second, third tables, then the data will
bedisplayed.

3.Suppose if there are no matching records, the data will be displayed as blank
fromsecond and third tables.

Transaction code: SE38

REPORT zsb_outer_join.

TYPES: BEGIN OF ty_final,


vbeln TYPE vbak-vbeln,
erdat TYPE vbak-erdat,
ernam TYPE vbak-ernam,
auart TYPE vbak-auart,
vkorg TYPE vbak-vkorg,
posnr TYPE vbap-posnr,
matnr TYPE vbap-matnr,
matkl TYPE vbap-matkl,

END OF ty_final.
DATA : gt_final TYPE TABLE OF ty_final,
gs_Final TYPE ty_final,
gt_lines TYPE i.

BHAVANA Page | 110


SAP ABAP TRAINING
SELECT a~vbeln
a~erdat
a~ernam
a~auart
a~vkorg
b~posnr
b~matnr
b~matkl
INTO TABLE gt_final FROM vbak AS a
LEFT OUTER JOIN vbap AS b ON a~vbeln = b~vbeln
WHERE vkorg = 1710 AND auart = 'TA'.
DESCRIBE TABLE gt_Final LINES gt_lines.

WRITE: gt_lines, 'No of records'.


LOOP AT gt_final INTO gs_final.
WRITE: / gs_final-vbeln,
gs_Final-posnr,
gs_Final-matnr,
gs_final-matkl,
gs_Final-ernam,
gs_final-vkorg,
gs_Final-erdat,
gs_final-auart.
ENDLOOP.

BHAVANA Page | 111


SAP ABAP TRAINING
OUTPUT:

BHAVANA Page | 112


SAP ABAP TRAINING
21. FOR ALL ENTERIES

 This statement is used to replace select with joins.

 Because JOINS statement cannot be used for more than three tables.

 If we use more than three tables it puts heavy load on the Database, because the
datahas to be selected by comparing each table in the database server.

 So, it takes the long time for execution.

 In such cases we go for SELECT FOR ALL ENTRIES.

 This statement will never put load on the database. Because only two tables
(Internaltable and database tables) are compared.

Syntax:

Select F1 F2 F3….
From <DB.Table1>
Into table <ITAB> Where <conditions>.
If ITAB1[] is not
initial.Select F1 F2
F3……
From
<DB.Table2>
Into table
<ITAB2>
For all entries in <ITAB1>
Where F1= <ITAB1-F1> AND F2= <ITAB-F2>.
Endif.

BHAVANA Page | 113


SAP ABAP TRAINING
a) Creating a program using for all entries

REPORT ZSB_FOR_ALL_ENTRIES.

DATA : gt_vbak TYPE TABLE of vbak,


gs_Vbak TYPE vbak,
gt_vbap TYPE TABLE of vbap,
gs_Vbap TYPE vbap.

SELECT * from vbak INTO TABLE gt_vbak.


IF gt_Vbak IS NOT INITIAL.
SELECT * from vbap INTO TABLE gt_Vbap
FOR ALL ENTRIES IN gt_Vbak
WHERE vbeln = gt_Vbak-vbeln.
ENDIF.

LOOP AT gt_vbap INTO gs_Vbap.


READ TABLE gt_Vbak INTO gs_vbak WITH key vbeln = gs_Vbap-vbeln.
IF sy-subrc = 0.
WRITE:/ gs_Vbap-vbeln,
gs_Vbap-matnr,
gs_Vbak-erdat,
gs_Vbak-ernam,
gs_vbak-auart.
ENDIF.

ENDLOOP.

BHAVANA Page | 114


SAP ABAP TRAINING
OUTPUT:

BHAVANA Page | 115


SAP ABAP TRAINING
22. SELECT STATEMENTS
 SELECT STATEMENTS are to Read the data to internal table.

Syntax:
 select * from <dbtable> into table < itab>.

IT IS USED TO READ ALL THE FILEDS DATA

 select f1 f2 f3 f4 f5 f6 from <dbtable> into table < itab>.

IT IS USED TO READ ON PARTICLUAR FILEDS DATA WHICH IS


SELECTED IN THE SELEECT QUERY

1) select * from <dbtable> into table < itab> where < condition> upto <n> rows.

Ex: select * from vbak into table gt_vbak where vbeln = 124635 upto 100 rows.

2) select f1 f2 f3 f4 f5 f6 from <dbtable> into table < itab>where < condition>.

Ex: select vbeln ernam erdat auart from vbak into table gt_Vbak.

3) select * from <dbtable> into < WA> where < condition>.


append < wa> to <itab>.
endselect.

Ex: select * from vbak into gs_Vbak where < condition>.


append gs_Vbak to gt_Vbak.
endselect.

BHAVANA Page | 116


SAP ABAP TRAINING
4) select f1 f2 f3 f4 f5 f6 from <dbtable> into < WA> where < condition>.
append < wa> to <itab>.
endselect.

Ex: select vbeln ernam erdat auart from vbak into gs_Vbak where < condition>.
append gs_Vbak to gt_Vbak.
endselect.

5) select * from <dbtable> into corresponing fields of table < itab> where < condition>.

Ex: select * from vbak into correpoding fields of table gt_Vbak where < condition>.

6) select f1 f2 f3 f4 f5 f6 from <dbtable> intocorresponing fields of table < itab> where <
condition>.

Ex: select vbeln ernam erdat auart from vbak into correpoding fields of table gt_Vbak
where < condition>.

To fetch single records from the database table.

1) select sinlge * / f1 f2 f3 from <dbtable> into <wa> where <condition>.

2) select * / f1 f2 f3 from <dbtable> into <wa> upto 1 row where <condition>.


endselect.

BHAVANA Page | 117


SAP ABAP TRAINING
a) Program to select all the fields from data base table into Work area

REPORT ZSB_SELECT1.

TYPES: BEGIN OF ty_mara,


matnr TYPE mara-matnr,
ernam TYPE mara-ernam,
mtart TYPE mtart,
meins TYPE meins,
attyp TYPE attyp,
END OF ty_mara.

data : gt_mara TYPE STANDARD TABLE OF ty_mara,


gs_mara TYPE ty_mara.
DATA: WT_MARA TYPE STANDARD TABLE OF MARA,
WS_MARA TYPE MARA.

SELECT * FROM mara INTO TABLE WT_MARA. " It is used to read all the fields da
ta ".

LOOP AT WT_MARA INTO WS_MARA.


WRITE: / WS_MARA-MATNR , WS_MARA-ERNAM, WS_MARA-
MTART ,WS_MARA-MEINS, WS_MARA-ATTYP.
ENDLOOP.

WRITE: / 'PROGRAM ENDED'.

BHAVANA Page | 118


SAP ABAP TRAINING
OUTPUT:

BHAVANA Page | 119


SAP ABAP TRAINING
b) Program to select particular fields from data base table into
Internal table

REPORT ZSB_SELECT2.

TYPES: BEGIN OF ty_mara,


matnr TYPE mara-matnr,
ernam TYPE mara-ernam,
mtart TYPE mtart,
meins TYPE meins,
attyp TYPE attyp,
END OF ty_mara.

data : gt_mara TYPE STANDARD TABLE OF ty_mara,


gs_mara TYPE ty_mara.
DATA: WT_MARA TYPE STANDARD TABLE OF MARA,
WS_MARA TYPE MARA.

SELECT MATNR
ERNAM
MTART
MEINS
ATTYP
FROM MARA INTO TABLE GT_MARA. " it is to display particular

fields data which is selected in the select query ."

LOOP AT GT_MARA INTO GS_MARA.


WRITE: / GS_MARA-MATNR , GS_MARA-ERNAM, GS_MARA-
MTART ,GS_MARA-MEINS, GS_MARA-ATTYP.
ENDLOOP.

WRITE : / 'PROGRAM ENDED'.

BHAVANA Page | 120


SAP ABAP TRAINING
OUTPUT:

BHAVANA Page | 121


SAP ABAP TRAINING
c) Program to select particular fields from data base table into Internal table
using where condition

REPORT ZSB_SELECT_STMTS.

TYPES: BEGIN OF ty_mara,


matnr TYPE mara-matnr,
ernam TYPE mara-ernam,
mtart TYPE mtart,
meins TYPE meins,
attyp TYPE attyp,
END OF ty_mara.

data : gt_mara TYPE STANDARD TABLE OF ty_mara,


gs_mara TYPE ty_mara.

DATA: WT_MARA TYPE STANDARD TABLE OF MARA,


WS_MARA TYPE MARA.

SELECT MATNR
ERNAM
MTART
MEINS
ATTYP
FROM MARA INTO TABLE GT_MARA UP TO 100 ROWS WHERE MTART =
'HAWA' AND ERNAM = 'BPINST' .

LOOP AT GT_MARA INTO GS_MARA.


WRITE: / GS_MARA-MATNR , GS_MARA-ERNAM, GS_MARA-
MTART ,GS_MARA-MEINS, GS_MARA-ATTYP.
ENDLOOP.

Write : / 'Program ENDED'.

BHAVANA Page | 122


SAP ABAP TRAINING
OUTPUT:

BHAVANA Page | 123


SAP ABAP TRAINING
d) Program to select all the fields from data base table into internal table
with where condition and using rows

REPORT ZSB_SELECT3.

TYPES: BEGIN OF ty_mara,


matnr TYPE mara-matnr,
ernam TYPE mara-ernam,
mtart TYPE mtart,
meins TYPE meins,
attyp TYPE attyp,
END OF ty_mara.

data : gt_mara TYPE STANDARD TABLE OF ty_mara,


gs_mara TYPE ty_mara.
DATA: WT_MARA TYPE STANDARD TABLE OF MARA,
WS_MARA TYPE MARA.

SELECT * FROM mara INTO TABLE WT_MARA UP TO 30 ROWS WHERE MTA


RT = 'HAWA' AND ERNAM = 'BPINST' .

LOOP AT WT_MARA INTO WS_MARA.


WRITE: / WS_MARA-MATNR , WS_MARA-ERNAM, WS_MARA-
MTART ,WS_MARA-MEINS, WS_MARA-ATTYP.
ENDLOOP.

WRITE: / 'PROGRAM ENDED'.

BHAVANA Page | 124


SAP ABAP TRAINING
OUTPUT:

BHAVANA Page | 125


SAP ABAP TRAINING
e) Program to select all the fields from data base table into work area using
append

REPORT ZSB_SELECT5.

TYPES: BEGIN OF ty_mara,


matnr TYPE mara-matnr,
ernam TYPE mara-ernam,
mtart TYPE mtart,
meins TYPE meins,
attyp TYPE attyp,
END OF ty_mara.

data : gt_mara TYPE STANDARD TABLE OF ty_mara,


gs_mara TYPE ty_mara.
DATA: WT_MARA TYPE STANDARD TABLE OF MARA,
WS_MARA TYPE MARA.

SELECT * FROM MARA INTO WS_MARA WHERE MTART = 'HAWA' . " It is used to read
data into work area".
APPEND WS_MARA TO WT_MARA.
ENDSELECT.

LOOP AT WT_MARA INTO WS_MARA.


WRITE: / WS_MARA-MATNR , WS_MARA-ERNAM, WS_MARA-MTART ,WS_MARA-
MEINS, WS_MARA-ATTYP.
ENDLOOP.

WRITE: / 'PROGRAM ENDED'.

BHAVANA Page | 126


SAP ABAP TRAINING
OUTPUT:

BHAVANA Page | 127


SAP ABAP TRAINING
f) Program to select particular fields from data base table internal table
using append

REPORT ZSB_SELECT6.

TYPES: BEGIN OF ty_mara,


matnr TYPE mara-matnr,
ernam TYPE mara-ernam,
mtart TYPE mtart,
meins TYPE meins,
attyp TYPE attyp,
END OF ty_mara.

data : gt_mara TYPE STANDARD TABLE OF ty_mara,


gs_mara TYPE ty_mara.
DATA: WT_MARA TYPE STANDARD TABLE OF MARA,
WS_MARA TYPE MARA.

SELECT MATNR
ERNAM
MTART
MEINS
ATTYP
FROM MARA INTO GS_MARA UP TO 20 ROWS WHERE MTART = 'HAWA' AN
D ERNAM = 'BPINST'. " select stmt using work area for particular fields
data which is selected in the select query ."
APPEND GS_MARA TO GT_MARA.
ENDSELECT.

BHAVANA Page | 128


SAP ABAP TRAINING
OUTPUT:

BHAVANA Page | 129


SAP ABAP TRAINING
g) Program to select into corresponding fields from data base table
internal table using where condition

REPORT ZSB_SELECT7.

TYPES: BEGIN OF ty_mara,


matnr TYPE mara-matnr,
ernam TYPE mara-ernam,
mtart TYPE mtart,
meins TYPE meins,
attyp TYPE attyp,
END OF ty_mara.

data : gt_mara TYPE STANDARD TABLE OF ty_mara,


gs_mara TYPE ty_mara.
DATA: WT_MARA TYPE STANDARD TABLE OF MARA,
WS_MARA TYPE MARA.

SELECT *
FROM mara INTO CORRESPONDING FIELDS OF TABLE GT_MARA UP TO 20
ROWS WHERE MTART = 'HAWA' AND ERNAM = 'BPINST'..

LOOP AT GT_MARA INTO GS_MARA.


WRITE: / GS_MARA-MATNR , GS_MARA-ERNAM, GS_MARA-
MTART ,GS_MARA-MEINS, GS_MARA-ATTYP.
ENDLOOP.

WRITE: / 'PROGRAM ENDED'.

BHAVANA Page | 130


SAP ABAP TRAINING
OUTPUT:

BHAVANA Page | 131


SAP ABAP TRAINING
h) Program to select into corresponding fields from data base table
work area using where condition

REPORT ZSB_SELECT8.

TYPES: BEGIN OF ty_mara,


matnr TYPE mara-matnr,
ernam TYPE mara-ernam,
mtart TYPE mtart,
meins TYPE meins,
attyp TYPE attyp,
END OF ty_mara.

data : gt_mara TYPE STANDARD TABLE OF ty_mara,


gs_mara TYPE ty_mara.
DATA: WT_MARA TYPE STANDARD TABLE OF MARA,
WS_MARA TYPE MARA.

SELECT MATNR
ERNAM
MTART
MEINS
ATTYP
FROM mara INTO CORRESPONDING FIELDS OF TABLE GT_MARA UP TO 20 R
OWS WHERE MTART = 'HAWA' AND ERNAM = 'BPINST'..

LOOP AT GT_MARA INTO GS_MARA.


WRITE: / GS_MARA-MATNR , GS_MARA-ERNAM, GS_MARA-
MTART ,GS_MARA-MEINS, GS_MARA-ATTYP.
ENDLOOP.

WRITE: / 'PROGRAM ENDED'.

BHAVANA Page | 132


SAP ABAP TRAINING
OUTPUT:

BHAVANA Page | 133


SAP ABAP TRAINING
i) Program to select single field from data base table
internal table using where condition
REPORT ZSB_SELECT9.

TYPES: BEGIN OF ty_mara,


matnr TYPE mara-matnr,
ernam TYPE mara-ernam,
mtart TYPE mtart,
meins TYPE meins,
attyp TYPE attyp,
END OF ty_mara.

data : gt_mara TYPE STANDARD TABLE OF ty_mara,


gs_mara TYPE ty_mara.
DATA: WT_MARA TYPE STANDARD TABLE OF MARA,
WS_MARA TYPE MARA.

SELECT MATNR
ERNAM
MTART
MEINS
ATTYP
FROM MARA INTO GS_MARA UP TO 1 ROWS WHERE MTART = 'HAWA' AND ERNAM = 'B
PINST'.

ENDSELECT.

WRITE : / GS_MARA.

WRITE : / 'PROGRAM ENDED'.

OUTPUT:

BHAVANA Page | 134


SAP ABAP TRAINING
j) Program to select single field from data base table
internal table up to 1 row using where condition
REPORT ZSB_SELECT10.

TYPES: BEGIN OF ty_mara,


matnr TYPE mara-matnr,
ernam TYPE mara-ernam,
mtart TYPE mtart,
meins TYPE meins,
attyp TYPE attyp,
END OF ty_mara.

data : gt_mara TYPE STANDARD TABLE OF ty_mara,


gs_mara TYPE ty_mara.
DATA: WT_MARA TYPE STANDARD TABLE OF MARA,
WS_MARA TYPE MARA.

SELECT SINGLE MATNR


ERNAM
MTART
MEINS
ATTYP
FROM MARA INTO GS_MARA WHERE MTART = 'HAWA' AND ERNAM = 'BPINST'.

WRITE : / GS_MARA.

WRITE : / 'PROGRAM ENDED'.

OUTPUT:

BHAVANA Page | 135


SAP ABAP TRAINING
23. SELECTION SCREEN
 An input screen is called SELECTION – SCREEN.

 For Designing the Selection Screen, we have the following Statements


 Parameters.
 Select – Options.
 Selection – Screen Commands.

Parameters: Parameters are used to create input fields, Check Boxes,Radio Buttons on
theSelection – Screen.

Select – options: Select – Options is used to create two i/p fields on the selection
screen. Sothat the user can enter range of values.

Select – Screen Commands:


Below of the statements are commands which are used to
designthe selection – screen.
1. Selection – Screen Begin of Block Used to create a block (or)
-- Box for fields.
--
Selection – Screen End of Block.
2. Selection – Screen ULINE ----- Displays Horizontal Line.
3. Selection – Screen Skip ---------Displays Blank Line.

BHAVANA Page | 136


SAP ABAP TRAINING
a) Creating a program using selection screen parameters

REPORT ZSB_SELECTION_SCREEN.

DATA : I_KNA1 TYPE TABLE OF KNA1.


DATA : WA_KNA1 TYPE KNA1.

PARAMETERS P_LAND1 TYPE KNA1-LAND1.

PARAMETERS P_CHKBOX AS CHECKBOX.

PARAMETERS: P_RB1 RADIOBUTTON GROUP AAA,


P_RB2 RADIOBUTTON GROUP AAA DEFAULT 'X'.

SELECT * FROM KNA1 INTO TABLE I_KNA1


WHERE LAND1 = P_LAND1.

If P_CHKBOX = 'X'.
Write:/ 'CheckBox is Selected'.
Else.
write:/ 'checkbox is not selected'.
Endif.

SKIP 2.

If P_RB1 = 'X'.
Write:/ 'RB1 is Selected'.
Else.
Write:/ 'RB2 is Selected'.
Endif.

SKIP 2.

LOOP AT I_KNA1 INTO WA_KNA1.


WRITE:/ WA_KNA1-KUNNR,
WA_KNA1-LAND1,
WA_KNA1-NAME1,
WA_KNA1-ORT01.
ENDLOOP.

BHAVANA Page | 137


SAP ABAP TRAINING
OUTPUT:

BHAVANA Page | 138


SAP ABAP TRAINING
b) Creating a program using selection screen select-options

REPORT ZSB_SELECTION_SCREEN2.

DATA : I_KNA1 TYPE TABLE OF KNA1.


DATA : WA_KNA1 TYPE KNA1.

PARAMETERS P_LAND1 TYPE KNA1-LAND1.

PARAMETERS P_CHKBOX AS CHECKBOX.

PARAMETERS: P_RB1 RADIOBUTTON GROUP AAA,


P_RB2 RADIOBUTTON GROUP AAA DEFAULT 'X'.

DATA : GV_KUNNR TYPE KNA1-KUNNR.


SELECT-OPTIONS : S_KUNNR FOR GV_KUNNR.

SELECT-OPTIONS : S_KUNNR1 FOR GV_KUNNR NO-EXTENSION.


SELECT-OPTIONS : S_KUNNR2 FOR GV_KUNNR NO INTERVALS.
SELECT-OPTIONS : S_KUNNR3 FOR GV_KUNNR NO INTERVALS NO-EXTENSION.

If P_CHKBOX = 'X'.
Write:/ 'CheckBox is Selected'.
Else.
write:/ 'checkbox is not selected'.
Endif.

SKIP 2.

If P_RB1 = 'X'.
Select * from KNA1 into table I_KNA1 where KUNNR in S_KUNNR.
ElseIF P_RB2 = 'X'.
SELECT * FROM KNA1 INTO TABLE I_KNA1 WHERE LAND1 = P_LAND1.
Endif.

SKIP 2.

BHAVANA Page | 139


SAP ABAP TRAINING
LOOP AT I_KNA1 INTO WA_KNA1.
WRITE:/ WA_KNA1-KUNNR,
WA_KNA1-LAND1,
WA_KNA1-NAME1,
WA_KNA1-ORT01.
ENDLOOP.

OUTPUT:

BHAVANA Page | 140


SAP ABAP TRAINING
c) Creating a program using selection screen commands

REPORT ZSB_SELECTION_SCREEN3.

DATA : I_KNA1 TYPE TABLE OF KNA1.


DATA : WA_KNA1 TYPE KNA1.

SELECTION-SCREEN BEGIN OF BLOCK b3 WITH FRAME TITLE text-003.

PARAMETERS P_LAND1 TYPE KNA1-LAND1.


PARAMETERS P_CHKBOX AS CHECKBOX.
PARAMETERS: P_RB1 RADIOBUTTON GROUP AAA,
P_RB2 RADIOBUTTON GROUP AAA DEFAULT 'X'.

SELECTION-SCREEN SKIP.
SELECTION-SCREEN ULINE.

SELECTION-SCREEN BEGIN OF BLOCK b2 WITH FRAME TITLE text-002.

DATA : GV_KUNNR TYPE KNA1-KUNNR.


SELECT-OPTIONS : S_KUNNR FOR GV_KUNNR.

SELECTION-SCREEN SKIP.
SELECTION-SCREEN ULINE.

SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.

SELECT-OPTIONS : S_KUNNR1 FOR GV_KUNNR NO-EXTENSION.


SELECT-OPTIONS : S_KUNNR2 FOR GV_KUNNR NO INTERVALS.
SELECT-OPTIONS : S_KUNNR3 FOR GV_KUNNR NO INTERVALS NO-EXTENSION.

SELECTION-SCREEN END OF BLOCK b1.

SELECTION-SCREEN END OF BLOCK b2.

SELECTION-SCREEN END OF BLOCK b3.

If P_CHKBOX = 'X'.

BHAVANA Page | 141


SAP ABAP TRAINING
Write:/ 'CheckBox is Selected'.
Else.
write:/ 'checkbox is not selected'.
Endif.

SKIP 2.

If P_RB1 = 'X'.
Select * from KNA1 into table I_KNA1 where KUNNR in S_KUNNR.
ElseIF P_RB2 = 'X'.
SELECT * FROM KNA1 INTO TABLE I_KNA1 WHERE LAND1 = P_LAND1.
Endif.

SKIP 2.

LOOP AT I_KNA1 INTO WA_KNA1.


WRITE:/ WA_KNA1-KUNNR,
WA_KNA1-LAND1,
WA_KNA1-NAME1,
WA_KNA1-ORT01.
ENDLOOP.

OUTPUT:

BHAVANA Page | 142


SAP ABAP TRAINING
BHAVANA Page | 143
SAP ABAP TRAINING
24. PROGRAMS USING LIST OF INTERNAL TABLE
OPERATIONS

Read: This statement is used to read a single record from internal table into work area.

Sort: This is the statement used to sort the internal table data either in ascending
orderor descending order.
Delete: This statement is used to delete the data from internal table.

a) Create a program using read operation:


REPORT ZSB_READ_TABLE.

TYPES: BEGIN OF ty_sinfo,


snum TYPE n3,
sname TYPE char10,
sclass TYPE char6,
scity TYPE char15,
sfee TYPE i,
END OF ty_sinfo.

DATA : gt_sinfo TYPE TABLE OF ty_sinfo,


gs_sinfo TYPE ty_sinfo.

gs_sinfo-snum = '1'.
gs_sinfo-sname = 'karthik'.
gs_sinfo-sclass = 'ABAP'.
gs_sinfo-scity = 'Banglore'.
gs_sinfo-sfee = '15000'.
APPEND gs_sinfo TO gt_sinfo.

CLEAR gs_sinfo.

gs_sinfo-snum = '2'.
gs_sinfo-sname = 'Sairam'.
gs_sinfo-sclass = 'B_TECH'.
gs_sinfo-scity = 'Hyderabad'.
gs_sinfo-sfee = '13000'.
APPEND gs_sinfo TO gt_sinfo.

BHAVANA Page | 144


SAP ABAP TRAINING
CLEAR gs_sinfo.

gs_sinfo-snum = '3'.
gs_sinfo-sname = 'Vamshi'.
gs_sinfo-sclass = 'B_TECH'.
gs_sinfo-scity = 'Hyderabad'.
gs_sinfo-sfee = '13000'.
COLLECT gs_sinfo INTO gt_sinfo.

CLEAR gs_sinfo.

gs_sinfo-snum = '4'.
gs_sinfo-sname = 'Harish'.
gs_sinfo-sclass = 'B_TECH'.
gs_sinfo-scity = 'Hyderabad'.
gs_sinfo-sfee = '18000'.
COLLECT gs_sinfo INTO gt_sinfo.

CLEAR gs_sinfo.

gs_sinfo-snum = '3'.
gs_sinfo-sname = 'Vamshi'.
gs_sinfo-sclass = 'B_TECH'.
gs_sinfo-scity = 'Hyderabad'.
gs_sinfo-sfee = '13000'.
COLLECT gs_sinfo INTO gt_sinfo.

CLEAR gs_sinfo.

gs_sinfo-snum = '5'.
gs_sinfo-sname = ' '.
gs_sinfo-sclass = 'B_TECH'.
gs_sinfo-scity = ' '.
gs_sinfo-sfee = '13000'.
COLLECT gs_sinfo INTO gt_sinfo.

CLEAR gs_sinfo.

gs_sinfo-snum = '6'.
gs_sinfo-sname = 'Rahul'.

BHAVANA Page | 145


SAP ABAP TRAINING
gs_sinfo-sclass = 'CEH_V10'.
gs_sinfo-scity = 'Banglore '.
gs_sinfo-sfee = '13000'.
INSERT gs_sinfo INTO gt_sinfo INDEX 1.

CLEAR gs_sinfo.

gs_sinfo-snum = '7'.
gs_sinfo-sname = 'vishwa'.
gs_sinfo-sclass = 'CEH_V10'.
gs_sinfo-scity = 'chennai '.
gs_sinfo-sfee = '13000'.
INSERT gs_sinfo INTO gt_sinfo INDEX 6.

CLEAR gs_sinfo.

gs_sinfo-snum = '8'.
gs_sinfo-sname = 'mahesh'.
gs_sinfo-sclass = ''.
gs_sinfo-scity = 'mumbai '.
gs_sinfo-sfee = '13000'.
INSERT gs_sinfo INTO gt_sinfo INDEX 2.

CLEAR gs_sinfo-sclass.

gs_sinfo-snum = '9'.
gs_sinfo-sname = 'shaleen'.
gs_sinfo-sclass = 'CEH_V10'.
gs_sinfo-scity = 'Banglore '.
gs_sinfo-sfee = '13000'.
INSERT gs_sinfo INTO gt_sinfo INDEX 4.

gs_sinfo-snum = '9'.
gs_sinfo-sname = 'shaleen'.
gs_sinfo-sclass = 'CEH_V10'.
gs_sinfo-scity = ' '.
gs_sinfo-sfee = '13000'.
INSERT gs_sinfo INTO gt_sinfo INDEX 4.

gs_sinfo-snum = '9'.
gs_sinfo-sname = 'shaleen'.
gs_sinfo-sclass = 'CEH_V10'.
gs_sinfo-scity = 'Banglore '.

BHAVANA Page | 146


SAP ABAP TRAINING
gs_sinfo-sfee = '13000'.
INSERT gs_sinfo INTO gt_sinfo INDEX 4.

skip 3.
loop at gt_sinfo INTO gs_sinfo ."INDEX 4.
IF sy-subrc = 0.
WRITE: / 'id-num :',gs_sinfo-snum,
'Name :',gs_sinfo-sname,
'class :',gs_sinfo-sclass,
'city :',gs_sinfo-scity ,
'fee :',gs_sinfo-sfee.

else.
WRITE: /'invalid'.
ENDIF.
ENDLOOP.

skip 3.
READ TABLE gt_sinfo INTO gs_sinfo INDEX 4.
IF sy-subrc = 0.
WRITE: / 'id-num :',gs_sinfo-snum,
'Name :',gs_sinfo-sname,
'class :',gs_sinfo-sclass,
'city :',gs_sinfo-scity ,
'fee :',gs_sinfo-sfee.

else.
WRITE: /'invalid'.
ENDIF.

SKIP 2.

READ TABLE gt_sinfo INTO gs_sinfo WITH KEY scity = 'Banglore'.


IF sy-subrc = 0.
WRITE: / 'id-num :',gs_sinfo-snum,
'Name :',gs_sinfo-sname,
'class :',gs_sinfo-sclass,
'city :',gs_sinfo-scity ,
'fee :',gs_sinfo-sfee.

else.
WRITE: /'invalid'.

BHAVANA Page | 147


SAP ABAP TRAINING
ENDIF.

SKIP 2.

SORT gt_sinfo BY sname .


READ TABLE gt_sinfo INTO gs_sinfo WITH KEY sname = 'karthik' BINARY SEARCH.

IF sy-subrc = 0.
WRITE: / 'id-num :',gs_sinfo-snum,
'Name :',gs_sinfo-sname,
'class :',gs_sinfo-sclass,
'city :',gs_sinfo-scity ,
'fee :',gs_sinfo-sfee.

else.
WRITE: /'invalid'.
ENDIF.

Output:

BHAVANA Page | 148


SAP ABAP TRAINING
b) Create a program using sort operation
REPORT ZSB_SORT_TABLE.

TYPES: BEGIN OF ty_sinfo,


snum TYPE n3,
sname TYPE char10,
sclass TYPE char6,
scity TYPE char15,
sfee TYPE i,
END OF ty_sinfo.

DATA : gt_sinfo TYPE TABLE OF ty_sinfo,


gs_sinfo TYPE ty_sinfo.

gs_sinfo-snum = '1'.
gs_sinfo-sname = 'karthik'.
gs_sinfo-sclass = 'ABAP'.
gs_sinfo-scity = 'Banglore'.
gs_sinfo-sfee = '15000'.
APPEND gs_sinfo TO gt_sinfo.

CLEAR gs_sinfo.

gs_sinfo-snum = '2'.
gs_sinfo-sname = 'Sairam'.
gs_sinfo-sclass = 'B_TECH'.
gs_sinfo-scity = 'Hyderabad'.
gs_sinfo-sfee = '13000'.
APPEND gs_sinfo TO gt_sinfo.

CLEAR gs_sinfo.

gs_sinfo-snum = '3'.
gs_sinfo-sname = 'Vamshi'.
gs_sinfo-sclass = 'B_TECH'.
gs_sinfo-scity = 'Hyderabad'.
gs_sinfo-sfee = '13000'.
COLLECT gs_sinfo INTO gt_sinfo.

CLEAR gs_sinfo.

BHAVANA Page | 149


SAP ABAP TRAINING
gs_sinfo-snum = '4'.
gs_sinfo-sname = 'Harish'.
gs_sinfo-sclass = 'B_TECH'.
gs_sinfo-scity = 'Hyderabad'.
gs_sinfo-sfee = '18000'.
COLLECT gs_sinfo INTO gt_sinfo.

CLEAR gs_sinfo.

gs_sinfo-snum = '3'.
gs_sinfo-sname = 'Vamshi'.
gs_sinfo-sclass = 'B_TECH'.
gs_sinfo-scity = 'Hyderabad'.
gs_sinfo-sfee = '13000'.
COLLECT gs_sinfo INTO gt_sinfo.

CLEAR gs_sinfo.

gs_sinfo-snum = '5'.
gs_sinfo-sname = ' '.
gs_sinfo-sclass = 'B_TECH'.
gs_sinfo-scity = ' '.
gs_sinfo-sfee = '13000'.
COLLECT gs_sinfo INTO gt_sinfo.

CLEAR gs_sinfo.

gs_sinfo-snum = '6'.
gs_sinfo-sname = 'Rahul'.
gs_sinfo-sclass = 'CEH_V10'.
gs_sinfo-scity = 'Banglore '.
gs_sinfo-sfee = '13000'.
INSERT gs_sinfo INTO gt_sinfo INDEX 1.

CLEAR gs_sinfo.

gs_sinfo-snum = '7'.
gs_sinfo-sname = 'vishwa'.
gs_sinfo-sclass = 'CEH_V10'.
gs_sinfo-scity = 'chennai '.
gs_sinfo-sfee = '13000'.

BHAVANA Page | 150


SAP ABAP TRAINING
INSERT gs_sinfo INTO gt_sinfo INDEX 6.

CLEAR gs_sinfo.

gs_sinfo-snum = '8'.
gs_sinfo-sname = 'mahesh'.
gs_sinfo-sclass = ''.
gs_sinfo-scity = 'mumbai '.
gs_sinfo-sfee = '13000'.
INSERT gs_sinfo INTO gt_sinfo INDEX 2.

CLEAR gs_sinfo-sclass.

gs_sinfo-snum = '9'.
gs_sinfo-sname = 'shaleen'.
gs_sinfo-sclass = 'CEH_V10'.
gs_sinfo-scity = 'Banglore '.
gs_sinfo-sfee = '13000'.
INSERT gs_sinfo INTO gt_sinfo INDEX 4.

gs_sinfo-snum = '9'.
gs_sinfo-sname = 'shaleen'.
gs_sinfo-sclass = 'CEH_V10'.
gs_sinfo-scity = ' '.
gs_sinfo-sfee = '13000'.
INSERT gs_sinfo INTO gt_sinfo INDEX 4.

gs_sinfo-snum = '9'.
gs_sinfo-sname = 'shaleen'.
gs_sinfo-sclass = 'CEH_V10'.
gs_sinfo-scity = 'Banglore '.
gs_sinfo-sfee = '13000'.
INSERT gs_sinfo INTO gt_sinfo INDEX 4.

SORT gt_sinfo.

LOOP AT gt_sinfo INTO gs_sinfo.

WRITE: / 'id-num :',gs_sinfo-snum,


'Name :',gs_sinfo-sname,
'class :',gs_sinfo-sclass,
'city :',gs_sinfo-scity ,
'fee :',gs_sinfo-sfee.

BHAVANA Page | 151


SAP ABAP TRAINING
ENDLOOP.

SKIP 2.

SORT gt_sinfo BY sfee.

LOOP AT gt_sinfo INTO gs_sinfo.

WRITE: / 'id-num :',gs_sinfo-snum,


'Name :',gs_sinfo-sname,
'class :',gs_sinfo-sclass,
'city :',gs_sinfo-scity ,
'fee :',gs_sinfo-sfee.

ENDLOOP.

SKIP 2.

SORT gt_sinfo DESCENDING.

LOOP AT gt_sinfo INTO gs_sinfo.

WRITE: / 'id-num :',gs_sinfo-snum,


'Name :',gs_sinfo-sname,
'class :',gs_sinfo-sclass,
'city :',gs_sinfo-scity ,
'fee :',gs_sinfo-sfee.

ENDLOOP.

SKIP 2.

SORT gt_sinfo DESCENDING BY sclass.

LOOP AT gt_sinfo INTO gs_sinfo.

WRITE: / 'id-num :',gs_sinfo-snum,


'Name :',gs_sinfo-sname,
'class :',gs_sinfo-sclass,
'city :',gs_sinfo-scity ,
'fee :',gs_sinfo-sfee.

ENDLOOP.

BHAVANA Page | 152


SAP ABAP TRAINING
Output:

BHAVANA Page | 153


SAP ABAP TRAINING
c) Create a program using delete operation

REPORT ZSB_DELETE.

TYPES: BEGIN OF ty_sinfo,


snum TYPE n3,
sname TYPE char10,
sclass TYPE char6,
scity TYPE char15,
sfee TYPE i,
END OF ty_sinfo.

DATA : gt_sinfo TYPE TABLE OF ty_sinfo,


gs_sinfo TYPE ty_sinfo.

gs_sinfo-snum = '1'.
gs_sinfo-sname = 'karthik'.
gs_sinfo-sclass = 'ABAP'.
gs_sinfo-scity = 'Banglore'.
gs_sinfo-sfee = '15000'.
APPEND gs_sinfo TO gt_sinfo.

CLEAR gs_sinfo.

gs_sinfo-snum = '2'.
gs_sinfo-sname = 'Sairam'.
gs_sinfo-sclass = 'B_TECH'.
gs_sinfo-scity = 'Hyderabad'.
gs_sinfo-sfee = '13000'.
APPEND gs_sinfo TO gt_sinfo.

CLEAR gs_sinfo.

gs_sinfo-snum = '3'.
gs_sinfo-sname = 'Vamshi'.
gs_sinfo-sclass = 'B_TECH'.
gs_sinfo-scity = 'Hyderabad'.
gs_sinfo-sfee = '13000'.
COLLECT gs_sinfo INTO gt_sinfo.

CLEAR gs_sinfo.

BHAVANA Page | 154


SAP ABAP TRAINING
gs_sinfo-snum = '4'.
gs_sinfo-sname = 'Harish'.
gs_sinfo-sclass = 'B_TECH'.
gs_sinfo-scity = 'Hyderabad'.
gs_sinfo-sfee = '18000'.
COLLECT gs_sinfo INTO gt_sinfo.

CLEAR gs_sinfo.

gs_sinfo-snum = '3'.
gs_sinfo-sname = 'Vamshi'.
gs_sinfo-sclass = 'B_TECH'.
gs_sinfo-scity = 'Hyderabad'.
gs_sinfo-sfee = '13000'.
COLLECT gs_sinfo INTO gt_sinfo.

CLEAR gs_sinfo.

gs_sinfo-snum = '5'.
gs_sinfo-sname = ' '.
gs_sinfo-sclass = 'B_TECH'.
gs_sinfo-scity = ' '.
gs_sinfo-sfee = '13000'.
COLLECT gs_sinfo INTO gt_sinfo.

CLEAR gs_sinfo.

gs_sinfo-snum = '6'.
gs_sinfo-sname = 'Rahul'.
gs_sinfo-sclass = 'CEH_V10'.
gs_sinfo-scity = 'Banglore '.
gs_sinfo-sfee = '13000'.
INSERT gs_sinfo INTO gt_sinfo INDEX 1.

CLEAR gs_sinfo.

gs_sinfo-snum = '7'.
gs_sinfo-sname = 'vishwa'.
gs_sinfo-sclass = 'CEH_V10'.
gs_sinfo-scity = 'chennai '.
gs_sinfo-sfee = '13000'.

BHAVANA Page | 155


SAP ABAP TRAINING
INSERT gs_sinfo INTO gt_sinfo INDEX 6.

CLEAR gs_sinfo.

gs_sinfo-snum = '8'.
gs_sinfo-sname = 'mahesh'.
gs_sinfo-sclass = ''.
gs_sinfo-scity = 'mumbai '.
gs_sinfo-sfee = '13000'.
INSERT gs_sinfo INTO gt_sinfo INDEX 2.

CLEAR gs_sinfo-sclass.

gs_sinfo-snum = '9'.
gs_sinfo-sname = 'shaleen'.
gs_sinfo-sclass = 'CEH_V10'.
gs_sinfo-scity = 'Banglore '.
gs_sinfo-sfee = '13000'.
INSERT gs_sinfo INTO gt_sinfo INDEX 4.

gs_sinfo-snum = '9'.
gs_sinfo-sname = 'shaleen'.
gs_sinfo-sclass = 'CEH_V10'.
gs_sinfo-scity = ' '.
gs_sinfo-sfee = '13000'.
INSERT gs_sinfo INTO gt_sinfo INDEX 4.

gs_sinfo-snum = '9'.
gs_sinfo-sname = 'shaleen'.
gs_sinfo-sclass = 'CEH_V10'.
gs_sinfo-scity = 'Banglore '.
gs_sinfo-sfee = '13000'.
INSERT gs_sinfo INTO gt_sinfo INDEX 4.

DELETE gt_sinfo INDEX 4.

LOOP AT gt_sinfo INTO gs_sinfo.

WRITE: / 'id-num :',gs_sinfo-snum,


'Name :',gs_sinfo-sname,
'class :',gs_sinfo-sclass,
'city :',gs_sinfo-scity ,
'fee :',gs_sinfo-sfee.

BHAVANA Page | 156


SAP ABAP TRAINING
ENDLOOP.

skip 3.

DELETE gt_sinfo WHERE scity = 'chennai'.


LOOP AT gt_sinfo INTO gs_sinfo.

WRITE: / 'id-num :',gs_sinfo-snum,


'Name :',gs_sinfo-sname,
'class :',gs_sinfo-sclass,
'city :',gs_sinfo-scity ,
'fee :',gs_sinfo-sfee.

ENDLOOP.

skip 3.

SORT gt_sinfo.

DELETE ADJACENT DUPLICATES FROM gt_sinfo COMPARING ALL FIELDS.


LOOP AT gt_sinfo INTO gs_sinfo.

WRITE: / 'id-num :',gs_sinfo-snum,


'Name :',gs_sinfo-sname,
'class :',gs_sinfo-sclass,
'city :',gs_sinfo-scity ,
'fee :',gs_sinfo-sfee.

ENDLOOP.

skip 3.

SORT gt_sinfo BY sname.

DELETE ADJACENT DUPLICATES FROM gt_sinfo COMPARING sname.


LOOP AT gt_sinfo INTO gs_sinfo.

WRITE: / 'id-num :',gs_sinfo-snum,


'Name :',gs_sinfo-sname,

BHAVANA Page | 157


SAP ABAP TRAINING
'class :',gs_sinfo-sclass,
'city :',gs_sinfo-scity ,
'fee :',gs_sinfo-sfee.

ENDLOOP.

Output:

BHAVANA Page | 158


SAP ABAP TRAINING
25. MODULARIZATION TECHNIQUES

 Modularization techniques are used to divide the business processing logic into
reusable block of statements.
This is two steps procedure.
1. Define the reusable block,
2. Calling the reusable block.
 There are 2 types of modularization techniques.
1. Source code modularizing technique: Include and Macros
2. Functionality modularizing technique: Subroutine and Function module
 In real time, every program must be divided into modules.
 In ABAP, Modularization is implemented using following techniques.
 Include Programs
 Function Modules
 Subroutines

a) Include program

 It contains set of reusable statements & cannot be executed.


 It should be inserted in the main program, or executable program
 Include programs are used to improve the readability of the program.
 We can’t execute an include independently where as the same include program
can be include to any number of executable programs.
 In the real time include programs are used to maintain the all declarations of the
program.

Syntax: INCLUDE <include program name>

BHAVANA Page | 159


SAP ABAP TRAINING
Steps to create INCLUDE program:

 Execute SE38.
 Provide the include program name.
 Click on create.

 Provide title.
 Select the type is “Include program”.
 Click on save, give package and continue.

BHAVANA Page | 160


SAP ABAP TRAINING
 Provide the Include program with reusable statements.

 So, here we created ZSB_MODULARIZATION_TOP (INCLUDE program name)


program with reusable statements. Save and activate.

 Here, we can provide any number of INCLUDE programs to be used in the


executable program. (ZSB_MODULARIZATION_TOP1—>save&activate).

 And now, Create an Executable program where we can use the include programs.

 Created an Executable program with name ZSB_MODULARIZATION with


description as modularization using include and type executable program.

BHAVANA Page | 161


SAP ABAP TRAINING
 ZSB_MODULARIZATION_TOP (INCLUDE PROGRAM 1)

 ZSB_MODULARIZATION_TOP1 (INCLUDE PROGRAM 2)

*&--------------------------------------------------------*
*& Include ZSB_MODULARIZATION_TOP1
*&--------------------------------------------------------*

gs_sinfo-snum = '1'.
gs_sinfo-sname = 'karthik'.
gs_sinfo-sclass = 'ABAP'.
gs_sinfo-scity = 'Banglore'.
gs_sinfo-sfee = '15000'.
APPEND gs_sinfo TO gt_sinfo.

CLEAR gs_sinfo.

gs_sinfo-snum = '2'.

BHAVANA Page | 162


SAP ABAP TRAINING
gs_sinfo-sname = 'Sairam'.
gs_sinfo-sclass = 'B_TECH'.
gs_sinfo-scity = 'Hyderabad'.
gs_sinfo-sfee = '13000'.
APPEND gs_sinfo TO gt_sinfo.

CLEAR gs_sinfo.

gs_sinfo-snum = '3'.
gs_sinfo-sname = 'Vamshi'.
gs_sinfo-sclass = 'B_TECH'.
gs_sinfo-scity = 'Hyderabad'.
gs_sinfo-sfee = '13000'.
COLLECT gs_sinfo INTO gt_sinfo.

CLEAR gs_sinfo.

gs_sinfo-snum = '4'.
gs_sinfo-sname = 'Harish'.
gs_sinfo-sclass = 'B_TECH'.
gs_sinfo-scity = 'Hyderabad'.
gs_sinfo-sfee = '18000'.

BHAVANA Page | 163


SAP ABAP TRAINING
COLLECT gs_sinfo INTO gt_sinfo.

CLEAR gs_sinfo.

gs_sinfo-snum = '3'.
gs_sinfo-sname = 'Vamshi'.
gs_sinfo-sclass = 'B_TECH'.
gs_sinfo-scity = 'Hyderabad'.
gs_sinfo-sfee = '13000'.
COLLECT gs_sinfo INTO gt_sinfo.

CLEAR gs_sinfo.

gs_sinfo-snum = '5'.
gs_sinfo-sname = ' '.
gs_sinfo-sclass = 'B_TECH'.
gs_sinfo-scity = ' '.
gs_sinfo-sfee = '13000'.
COLLECT gs_sinfo INTO gt_sinfo.

CLEAR gs_sinfo.

gs_sinfo-snum = '6'.
gs_sinfo-sname = 'Rahul'.

BHAVANA Page | 164


SAP ABAP TRAINING
gs_sinfo-sclass = 'CEH_V10'.
gs_sinfo-scity = 'Banglore '.
gs_sinfo-sfee = '13000'.
INSERT gs_sinfo INTO gt_sinfo INDEX 1.

CLEAR gs_sinfo.

gs_sinfo-snum = '7'.
gs_sinfo-sname = 'vishwa'.
gs_sinfo-sclass = 'CEH_V10'.
gs_sinfo-scity = 'chennai '.
gs_sinfo-sfee = '13000'.
INSERT gs_sinfo INTO gt_sinfo INDEX 6.

CLEAR gs_sinfo.

gs_sinfo-snum = '8'.
gs_sinfo-sname = 'mahesh'.
gs_sinfo-sclass = ''.
gs_sinfo-scity = 'mumbai '.
gs_sinfo-sfee = '13000'.
INSERT gs_sinfo INTO gt_sinfo INDEX 2.

BHAVANA Page | 165


SAP ABAP TRAINING
CLEAR gs_sinfo-sclass.

gs_sinfo-snum = '9'.
gs_sinfo-sname = 'shaleen'.
gs_sinfo-sclass = 'CEH_V10'.
gs_sinfo-scity = 'Banglore '.
gs_sinfo-sfee = '13000'.
INSERT gs_sinfo INTO gt_sinfo INDEX 4.

gs_sinfo-snum = '9'.
gs_sinfo-sname = 'shaleen'.
gs_sinfo-sclass = 'CEH_V10'.
gs_sinfo-scity = ' '.
gs_sinfo-sfee = '13000'.
INSERT gs_sinfo INTO gt_sinfo INDEX 4.

gs_sinfo-snum = '9'.
gs_sinfo-sname = 'shaleen'.
gs_sinfo-sclass = 'CEH_V10'.
gs_sinfo-scity = 'Banglore '.
gs_sinfo-sfee = '13000'.
INSERT gs_sinfo INTO gt_sinfo INDEX 4.

BHAVANA Page | 166


SAP ABAP TRAINING
 Save, activate & execute the main program (ZSB_MODULARIZATION)

OUTPUT:

b) Subroutines

 Sub routines contains piece of ABAP code which are mainly used for
readability and reusability.

 These are also used for local modularization.

 Subroutines are procedures, that we can define in any ABAP program & calling
from the same or some other ABAP program.

 Procedure is the collection of statements.


 SYNTAX: The Syntax contains two steps

BHAVANA Page | 167


SAP ABAP TRAINING
o Sub routine definition

Perform<subroutine>Using<V1><V2> ACTUAL
Changing<CH1><CH2> PARAMETERS
Tables<IT1><IT2>

o Sub routine Implementation

Form<subroutine> Using<V1><V2>
Changing<CH1><CH2> FORMAL
Tables<IT1><IT2> PARAMETERS
End Form


Types of Sub Routines:
There are two types of Sub routines.
o Local Sub Routines
o Global Sub Routines

Local sub routines: If Sub routine definition and implementation are available in
same program then it is called as local sub routines.
i.e., if PERFORM And FORM…… END FORM, are available in same program
then it is called as local sub routines.

Global sub routines: If sub routines definition is available in one program and
sub routineimplementation is available in another program then it is called as
global Subroutines (or) external sub routines.

PARAMETERS OF SUB ROUTINES:

 USING: Importing variables to sub routines are defined with using.

 CHANGING: Exporting variables are defined with changing.

BHAVANA Page | 168


SAP ABAP TRAINING
 TABLES: Internal tables for importing and exporting are defined with tables.

TYPES OF PASSING VALUES: There are 3 types to send the values from sub
routine definition to sub routine implementation.

 Pass by reference

 Pass by value (or) call by value

 Pass by value and return




PASS BY REFERENCE:

 In this type, the actual and formal parameters will be referring to the same
memorylocation.

 If any changes are made to the formal parameters, the actual parameters will also
be effected.

Program using PBR (Pass by reference)

REPORT ZSB_SUBROUTINE1.

DATA: gv_A TYPE i.

gv_A = 10.

WRITE:/ gv_A , 'before perform stamtement'.

PERFORM PBR1 using gv_A.

WRITE:/ gv_A , 'After perform stamtement'.


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

BHAVANA Page | 169


SAP ABAP TRAINING
*& Form PBR1
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> GV_A
*&---------------------------------------------------------------------*
FORM pbr1 USING p_gv_a.

WRITE:/ gv_A , 'in perform stamtement'.


gv_A = gv_A + 10.
WRITE:/ gv_A , 'Change after perform stamtement'.

ENDFORM.

OUTPUT:

PASS BY VALUE:

 In this type the actual and formal parameters will be referring to separate
memorylocations.

 If your changes are made to the formal parameters, it will not affect the
actualparameters.

 Pass By Value is identified by the keyword VALUE ().

BHAVANA Page | 170


SAP ABAP TRAINING
Program using PBV (Pass by value)

REPORT ZSB_SUBROUTINE2.

DATA: gv_A TYPE i.

gv_A = 10.

WRITE:/ gv_A , 'before perform stamtement'.

PERFORM PBV using gv_A .

WRITE:/ gv_A , 'After perform stamtement'.


*&---------------------------------------------------------------------*
*& Form PBV
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> GV_A
*&---------------------------------------------------------------------*
FORM pbv USING value(gv_a).

WRITE:/ gv_A , 'in perform stamtement'.


gv_A = gv_A + 10.
WRITE:/ gv_A , 'Change after perform stamtement'.

ENDFORM.

 OUTPUT:

BHAVANA Page | 171


SAP ABAP TRAINING
PASS BY VALUE AND RETURN:

 In this type the actual and formal parameters will be referring to separate
memorylocations.

 If any changes are made to the formal parameters, the actual parameters
will bechanged Only when sub routine implementation (or) the entire sub
routine is executed.

Program using PBVR

REPORT ZSB_SUBROUTINES3.

DATA: gv_A TYPE i.

gv_A = 10.

WRITE:/ gv_A , 'before perform stamtement'.

PERFORM pbrv CHANGING gv_A.

WRITE:/ gv_A , 'After perform stamtement'.


*&---------------------------------------------------------------------*
*& Form pbrv
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& <-- GV_A
*&---------------------------------------------------------------------*
FORM pbrv CHANGING p_gv_a.

WRITE:/ gv_A , 'in perform stamtement'.


gv_A = gv_A + 10.
WRITE:/ gv_A , 'changes after perform stamtement'.

ENDFORM.

OUTPUT:

BHAVANA Page | 172


SAP ABAP TRAINING
c) Function module

 A Function module is a sub program which contains a piece of abap code


which isused for specific functionality or a task.
 Function modules contains importing and exporting parameters.
 Function modules also contains Exceptions to raise Error messages.
 Function modules can be tested independently.
 Function modules can be debugged independently.
 Function modules are mainly used for global modularization i.e., once a
function module is created it can be used by multiple programs throughout
SAP.

FUNCTION GROUP:
 It is a Group or container of function modules.
 Whenever we create a function module, it must be saved under a group
called as function group.
 Different Function modules in a function group can share global data.

BHAVANA Page | 173


SAP ABAP TRAINING
(TOP include program)
 There are two ways to create a function group.
1. From Tcode SE80
2. From Tcode SE37 click on Menu Go to Function groupscreate
group

STEPS TO CREATE FUNCTION GROUP:

 Go to SE80. Select Function group. Give the function group name as


ZSB_FUNCTION_GROUP.

 Press enter. Click on ‘yes’ button. Provide short text. Function Group will
be created.

BHAVANA Page | 174


SAP ABAP TRAINING
 Whenever a function Group is created, by default a main program and two
include programs will be created.

 Always the function group should be activated immediately .

 Now right click on the function group and activate entire group.
 To display and modify function group double click on function group
object name. (ZSB_FUNCTION_GROUP)

BHAVANA Page | 175


SAP ABAP TRAINING
 Now go to SE37 Transaction code. Give function module name
(ZSB_FUNCTION MODULE) and click on create.

 Give function group name (ZSB_FUNCTION_GROUP) and provide short


text. Click on save.

 A warning pop-up will come. Click on continue.

 Our Function Module is created.

BHAVANA Page | 176


SAP ABAP TRAINING
COMPONENTS OF FUNCTION MODULE:
Function module consists of following components.
 ATTTIBUTES:

 IMPORT:
Input to a Function module is called Importing parameter.

BHAVANA Page | 177


SAP ABAP TRAINING
 EXPORT:
Output from a function module is called as exporting

 CHANGING:
A variable/work area which acts as Imports/ Export are called as changing
parameters

 TABLES:
Internal tables as Input & output are called as table parameters

BHAVANA Page | 178


SAP ABAP TRAINING
 EXCEPTIONS:
Exceptions are used to catch certain type of errors

 SOURSE CODE:
Contain the ABAP code for a FMOD.

BHAVANA Page | 179


SAP ABAP TRAINING
 OUTPUT:

 Give input parameter value

BHAVANA Page | 180


SAP ABAP TRAINING
 Click on “Display output list of Function module:

BHAVANA Page | 181


SAP ABAP TRAINING
26. REPORTS IN SAP ABAP
REPORT:
Report is the combination of given inputs to the selection-screen retrieving the
data from data base based on the given input & display the output in a predefined
format.

Types of reports:

 Classical reports
 Interactive reports
 ALV reports

a) Classical report

 A report with single input screen (selection screen) and single output screen
(list screen) is called Classical report.
 It’s nothing but to display the entire information in a single list.

Events in Classical Reports: -


All the ABAP programs are developed using events becauseABAP is “EVENT
DRIVEN PROGRAMMING LANGUAGE” i.e., the entire ABAP program execution is
based on order of events.

 LOAD-OF-PROGRAM

 INITIALIZATION
 AT SELECTION-SCREEN OUTPUT

 AT SELECTION-SCREEN ON FIELD

BHAVANA Page | 182


SAP ABAP TRAINING
 AT SELECTION-SCREEN ON VALUE REQUEST

 AT SELECTION-SCREEN ON HELP REQUEST

 AT SELECTION-SCREEN

 START OF SELECTION

 END OF SELECTION

 TOP-OF-PAGE
 END-OF-PAGE

Load of program:
This event is used to load the program into the memory for execution.
This is internal event, which we cannot see.

Initialization:
It’s an event which is triggered before displaying the selection-screen.
It’s used to provide the default values to the selection-screen.

At selection-screen output:
It’s an event which is triggered at the selection-screen based on the user action.
This is used to modify the selection-screen.

BHAVANA Page | 183


SAP ABAP TRAINING
At selection-screen on field:
It’s an event which is triggered at the selection-screen based on particular input field.
This is used to validate the particular input field.

At selection-screen on value-request:
It’s an event which is triggered at the time of click on F4 button.
This is used to provide the list of possible values to the input variables.

At selection-screen on help-request:
It’s an event which is triggered at the time of click on F1 button.
This is used to provide the help document to the input variable

At selection-screen:
It’s an event which is triggered after provide the input to the screen & before leaving the
selection-screen.
This is used to validate the given input.

Start-of-selection:
It’s an event which is triggered after leaving the selection-screen & before display the output.
This is used to fetch the data from data base & place into internal table.

BHAVANA Page | 184


SAP ABAP TRAINING
End-of-selection:
It’s an event which is triggered after completion of the logic.
This is used to display the output.

Top-of-page:
It’s an event which is triggered of the top of each page.
It’s used to display the header information.

End-of-page:
It’s an event which is triggered of the end of each page.
It’s used to display the footer information.

Create a Program using events in classical report:


REPORT zsb_classical_report1 LINE-COUNT 25(3).

DATA: gt_Vbak TYPE TABLE OF vbak,


gs_Vbak TYPE vbak.

DATA: gv_vkorg TYPE vkorg.

PARAMETERS: p_vkorg TYPE vkorg.

INITIALIZATION.
p_vkorg = 1710.

AT SELECTION-SCREEN.

BHAVANA Page | 185


SAP ABAP TRAINING
SELECT SINGLE vkorg INTO gv_Vkorg FROM vbak WHERE vkorg = p_vkorg.
IF sy-subrc NE 0.
MESSAGE 'Please provide correct value of sales organization' TYPE 'E'.
ENDIF.

AT SELECTION-SCREEN OUTPUT.
** AT SELECTION-SCREEN ON FIELD.
** AT SELECTION-SCREEN ON VALUE-REQUEST FOR FIELD.
** AT SELECTION-SCREEN ON HELP-REQUEST FOR FIELD.

START-OF-SELECTION.

SELECT * FROM Vbak INTO TABLE gt_vbak WHERE vkorg = p_vkorg.

END-OF-SELECTION.

LOOP AT gt_vbak INTO gs_Vbak.


WRITE:/ gs_Vbak-vbeln,
gs_Vbak-erdat,
gs_Vbak-ernam,
gs_Vbak-auart,
gs_Vbak-vkorg.
HIDE gs_Vbak-vbeln.
ENDLOOP.

TOP-OF-PAGE.

ULINE.
WRITE: 'Sales order' , ' created date' , 'created by' , 'Sales order type', 'Sales organization'.
ULINE.

END-OF-PAGE.

ULINE.
WRITE: 'continue' , sy-pagno.
ULINE.

BHAVANA Page | 186


SAP ABAP TRAINING
Output:

BHAVANA Page | 187


SAP ABAP TRAINING
b) Interactive Report

 It’s nothing but to display the summarized information in the first list & detailed
information in the secondary list.
 The first list is called basic list and the number is 0.
 The remaining lists are called secondary lists and the number starts from 1 to 20.
 So, there are total 21 lists. We can view multiple lists simultaneously.
 The current list index number is stored in SY-LSIND.
 If you select any line, then the selected line data is stored in SY-LISEL.

Events in Interactive report


1. At line selection
2. At user-command.
3. Top-of-page during line-selection.
4. At PF <Function Key>

At line selection:
It’s an event which is triggered at the time of user clicks on any record of any list.
To know the selected contents, we have two Key words.

 HIDE
 GET CURSOR

BHAVANA Page | 188


SAP ABAP TRAINING
HIDE:
Hide is a key word which is used to hide the data temporarily memory is called as HIDE area for
further processing.
We use the HIDE statement with in the LOOP……END LOOP, so that the hide key word will
hide the values into hide area.
Functionality of HIDE:
Whenever the user double clicks on any list line, the event at line selection will be triggered.
The system automatically identifies the line number where the user has doble clicked and reads
the corresponding record into hide variable.
GET-CURSOR:
Get-cursor technique writes the field name as well as field value which is clicked by the user.
Syntax: GET CURSOR field<v_fname>value <v_fvalue>.

At user-command:
It’s an event which is triggered at the time of user clicks on any menu item.

Top-of-page during line-selection:


It’s an event which is triggered at the top of each secondary list.

At PF <Function Key>:
It’s an event which is triggered at the time of user clicks on F1 to F12 function keys.

BHAVANA Page | 189


SAP ABAP TRAINING
c) ALV (ABAP List Viewer) Report

ALV Reports are mainly used to display the data in the form of either Grid or List Format
with good look and feel.

The advantages of ALV Reports are:

1. Good Look and Feel


2.Pre defined options given by SAP like Asc, Desc, Filtering, Downloading, Changing Layout,
sending Mail.... etc.

FUNCTION MODULES FOR DEVELOPING ALV REPORTS:

REUSE_ALV_GRID_DISPLAY--Display ALV data in GRID format


REUSE_ALV_LIST_DISPLAY--Display ALV data in LIST format
REUSE_ALV_COMMENTARY_WRITE--Display TOP-OF-PAGE, LOGO, END-OF-LIST.
REUSE_ALV_FIELDCATELOG_MERGE--Generate field catalog automatically
REUSE_ALV_EVENTS_GET--Display ALV Events
REUSE_ALV_HIERSEQ_LIST_DISPLAY--Display hierarchical ALV
REUSE_ALV_BLOCKED_LIST_DISPLAY--Display blocked ALV

LIST OF ALV's
ALV with structure
ALV with field catalog
ALV with layout options
ALV with field catalog merge
ALV with LOGO/TOP OF PAGE/END OF LIST
Interactive ALV
Interactive ALV by calling a transaction
Hierarchical ALV
Blocked ALV

BHAVANA Page | 190


SAP ABAP TRAINING
ALV with Structures:
Develop a material master report which displays all the fields.

STEPS:
Declare an internal table and work area for table.
Write an select statements to fetch the data.
Call function module REUSE_ALV_GRID_DISPLAY and specify the below parameters.
Structure name
Program name
Internal table name

Program using ALV with Structures:

REPORT ZSB_ALV_WIT_STR.

data: gt_Sflight type table of sflight.

select * from sflight into table gt_Sflight.

*grid-display********

***
*** CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
*** EXPORTING
***
***
*** I_CALLBACK_PROGRAM = sy-repid
***
*** I_STRUCTURE_NAME = 'SFLIGHT'
***
***
*** TABLES
*** t_outtab = gt_sflight
*** EXCEPTIONS
*** PROGRAM_ERROR =1
*** OTHERS = 2.
***
*** IF sy-subrc <> 0.
**** Implement suitable error handling here
*** ENDIF.

BHAVANA Page | 191


SAP ABAP TRAINING
*list-display**********
CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
EXPORTING
* I_INTERFACE_CHECK =''
* I_BYPASSING_BUFFER =
* I_BUFFER_ACTIVE =''
I_CALLBACK_PROGRAM = sy-cprog
* I_CALLBACK_PF_STATUS_SET =''
* I_CALLBACK_USER_COMMAND =''
I_STRUCTURE_NAME = 'sflight'
* IS_LAYOUT =
* IT_FIELDCAT =
* IT_EXCLUDING =
* IT_SPECIAL_GROUPS =
* IT_SORT =
* IT_FILTER =
* IS_SEL_HIDE =
* I_DEFAULT = 'X'
* I_SAVE =''
* IS_VARIANT =
* IT_EVENTS =
* IT_EVENT_EXIT =
* IS_PRINT =
* IS_REPREP_ID =
* I_SCREEN_START_COLUMN =0
* I_SCREEN_START_LINE =0
* I_SCREEN_END_COLUMN =0
* I_SCREEN_END_LINE =0
* IR_SALV_LIST_ADAPTER =
* IT_EXCEPT_QINFO =
* I_SUPPRESS_EMPTY_DATA = ABAP_FALSE
* IMPORTING
* E_EXIT_CAUSED_BY_CALLER =
* ES_EXIT_CAUSED_BY_USER =
TABLES
t_outtab = gt_sflight
* EXCEPTIONS
* PROGRAM_ERROR =1
* OTHERS =2
.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.

BHAVANA Page | 192


SAP ABAP TRAINING
OUTPUT:

Grid display:

List display:

BHAVANA Page | 193


SAP ABAP TRAINING
ALV WITH FIELD CATALOG:

Field Catalog:
It is an internal table which contains the list of the fields along with the field properties to
be displayed in ALV Report

The properties/options are:

1. COL_POS = 1
2. FIELD NAME--> Specifies the name of the field
3. TABLE NAME--> Specifies the name of the internal table
4. SEL TEXT_S--> Specifies short
SEL TEXT_S--> Specifies long
SEL TEXT_S--> Specifies medium

5. DO_SUM ='X'--> For grand totals


6. SUBTOT ='X'--> Sub totals to be calculated
7. EDIT ='X'--> Field can be editable
8. EMPHASIZE ='CXYZ' --> Specifies the color to the fields
C--> Indicates color
X--> Color Numbers
Y--> Background color---- 1 on BG color
0 off BG color
Z--> Font color---1 On Font color
0 Off Font color
9. REFERENCE TABLENAME
REFERENCE FIELDNAME -->To copy all the properties from data dictionary to a field
catalog field.
10. KEY --> Specify the key field
11. HOTSPOT --> For selection
12. NO_OUT --> Field will not be displayed in output

Generation of Field catalog:


It is generated using 2 ways.
1) Manually
2) Automatically by using FM

BHAVANA Page | 194


SAP ABAP TRAINING
program using ALV with MANUAL FIELD CATALOG

REPORT ZSB_ALV_FCAT_MANUAL.

****field catolog for single record

**
**type-pools slis.
**data : gt_vbak type table of vbak,
** gt_Fcat type slis_t_fieldcat_alv,
** gs_fcat type slis_fieldcat_alv.
**
**
**select * from vbak into table gt_vbak.
**
** gs_fcat-col_pos = 1.
** gs_fcat-fieldname = 'VBELN'.
** gs_fcat-seltext_m = 'sales order'.
** append gs_fcat to gt_fcat.
**
** CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
** EXPORTING
*** I_INTERFACE_CHECK =''
*** I_BYPASSING_BUFFER =''
*** I_BUFFER_ACTIVE =''
** I_CALLBACK_PROGRAM = sy-repid
*** I_CALLBACK_PF_STATUS_SET =''
*** I_CALLBACK_USER_COMMAND =''
*** I_CALLBACK_TOP_OF_PAGE =''
*** I_CALLBACK_HTML_TOP_OF_PAGE =''
*** I_CALLBACK_HTML_END_OF_LIST =''
*** I_STRUCTURE_NAME =
*** I_BACKGROUND_ID =''
*** I_GRID_TITLE =
*** I_GRID_SETTINGS =
*** IS_LAYOUT =
** IT_FIELDCAT = gt_fcat
*** IT_EXCLUDING =
*** IT_SPECIAL_GROUPS =
*** IT_SORT =
*** IT_FILTER =
*** IS_SEL_HIDE =
*** I_DEFAULT = 'X'

BHAVANA Page | 195


SAP ABAP TRAINING
*** I_SAVE =''
*** IS_VARIANT =
*** IT_EVENTS =
*** IT_EVENT_EXIT =
*** IS_PRINT =
*** IS_REPREP_ID =
*** I_SCREEN_START_COLUMN =0
*** I_SCREEN_START_LINE =0
*** I_SCREEN_END_COLUMN =0
*** I_SCREEN_END_LINE =0
*** I_HTML_HEIGHT_TOP =0
*** I_HTML_HEIGHT_END =0
*** IT_ALV_GRAPHICS =
*** IT_HYPERLINK =
*** IT_ADD_FIELDCAT =
*** IT_EXCEPT_QINFO =
*** IR_SALV_FULLSCREEN_ADAPTER =
*** O_PREVIOUS_SRAL_HANDLER =
*** IMPORTING
*** E_EXIT_CAUSED_BY_CALLER =
*** ES_EXIT_CAUSED_BY_USER =
** TABLES
** t_outtab = gt_vbak
** EXCEPTIONS
** PROGRAM_ERROR =1
** OTHERS =2
** .
** IF sy-subrc <> 0.
*** Implement suitable error handling here
** ENDIF.

***field catalog for multiple records

type-pools slis.
data : gt_vbak type table of vbak,
gt_Fcat type slis_t_fieldcat_alv,
gs_fcat type slis_fieldcat_alv.

select * from vbak into table gt_vbak.

gs_fcat-col_pos = 1.
gs_fcat-fieldname = 'VBELN'.

BHAVANA Page | 196


SAP ABAP TRAINING
gs_fcat-seltext_m = 'sales order'.
gs_Fcat-key = 'X '.
* it will show different color ******
append gs_fcat to gt_fcat.

clear gs_fcat.

gs_fcat-col_pos = 2.
gs_fcat-fieldname = 'ERDAT'.
gs_fcat-seltext_m = 'CREATED DATE'.
append gs_fcat to gt_fcat.

clear gs_fcat.

gs_fcat-col_pos = 3.
gs_fcat-fieldname = 'ERNAM'.
gs_fcat-seltext_m = 'CREATED BY'.
append gs_fcat to gt_fcat.

clear gs_fcat.

gs_fcat-col_pos = 4.
gs_fcat-fieldname = 'AUART'.
gs_fcat-seltext_m = 'SO DOC TYPE'.
append gs_fcat to gt_fcat.

clear gs_fcat.

gs_fcat-col_pos = 5.
gs_fcat-fieldname = 'VKORG'.
gs_fcat-seltext_m = 'sales organization'.
append gs_fcat to gt_fcat.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'


EXPORTING
* I_INTERFACE_CHECK =''
* I_BYPASSING_BUFFER =''
* I_BUFFER_ACTIVE =''
I_CALLBACK_PROGRAM = sy-repid
* I_CALLBACK_PF_STATUS_SET =''
* I_CALLBACK_USER_COMMAND =''
* I_CALLBACK_TOP_OF_PAGE =''

BHAVANA Page | 197


SAP ABAP TRAINING
* I_CALLBACK_HTML_TOP_OF_PAGE =''
* I_CALLBACK_HTML_END_OF_LIST =''
* I_STRUCTURE_NAME =
* I_BACKGROUND_ID =''
* I_GRID_TITLE =
* I_GRID_SETTINGS =
* IS_LAYOUT =
IT_FIELDCAT = gt_fcat
* IT_EXCLUDING =
* IT_SPECIAL_GROUPS =
* IT_SORT =
* IT_FILTER =
* IS_SEL_HIDE =
* I_DEFAULT = 'X'
* I_SAVE =''
* IS_VARIANT =
* IT_EVENTS =
* IT_EVENT_EXIT =
* IS_PRINT =
* IS_REPREP_ID =
* I_SCREEN_START_COLUMN =0
* I_SCREEN_START_LINE =0
* I_SCREEN_END_COLUMN =0
* I_SCREEN_END_LINE =0
* I_HTML_HEIGHT_TOP =0
* I_HTML_HEIGHT_END =0
* IT_ALV_GRAPHICS =
* IT_HYPERLINK =
* IT_ADD_FIELDCAT =
* IT_EXCEPT_QINFO =
* IR_SALV_FULLSCREEN_ADAPTER =
* O_PREVIOUS_SRAL_HANDLER =
* IMPORTING
* E_EXIT_CAUSED_BY_CALLER =
* ES_EXIT_CAUSED_BY_USER =
TABLES
t_outtab = gt_vbak
EXCEPTIONS
PROGRAM_ERROR =1
OTHERS =2
.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.

BHAVANA Page | 198


SAP ABAP TRAINING
OUTPUT:
For single record

For multiple records

BHAVANA Page | 199


SAP ABAP TRAINING
program using ALV with FIELD CATALOG MERGE
REPORT ZSB_ALV_FCAT_MERGE.

DATA : GT_VBAK TYPE TABLE OF VBAK,


GT_FCAT TYPE SLIS_T_FIELDCAT_ALV,
GS_FCAT TYPE SLIS_FIELDCAT_ALV.

SELECT * FROM VBAK INTO TABLE GT_VBAK.

CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'


EXPORTING
I_PROGRAM_NAME = sy-repid
* I_INTERNAL_TABNAME =
I_STRUCTURE_NAME = 'VBAK'
* I_CLIENT_NEVER_DISPLAY = 'X'
* I_INCLNAME =
* I_BYPASSING_BUFFER =
* I_BUFFER_ACTIVE =
CHANGING
ct_fieldcat = gt_fcat
EXCEPTIONS
INCONSISTENT_INTERFACE =1
PROGRAM_ERROR =2
OTHERS = 3.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.

loop at gt_fcat into gs_fcat.

*** for single record ******************************

**** if gs_fcat-fieldname = 'VBELN'.


**** gs_fcat-no_out = ' '.
***** no_out = 'X' means this field will not be displayed fot that particular field and no_out = ' ' means this f
ield will be displayed.
**** endif.

** for multiple records *********************************

case gs_fcat-fieldname.
WHEN 'VBELN'.

BHAVANA Page | 200


SAP ABAP TRAINING
gs_fcat-no_out = ' '.
WHEN 'ERDAT'.
gs_fcat-no_out = ' '.
WHEN 'ERNAM'.
gs_fcat-no_out = ' '.
WHEN 'AUART'.
gs_fcat-no_out = ' '.
WHEN OTHERS.
gs_fcat-no_out = 'X'.
ENDCASE.

MODIFY gt_fcat FROM gs_fcat.


endloop.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'


EXPORTING
* I_INTERFACE_CHECK =''
* I_BYPASSING_BUFFER =''
* I_BUFFER_ACTIVE =''
I_CALLBACK_PROGRAM = sy-cprog
* I_CALLBACK_PF_STATUS_SET =''
* I_CALLBACK_USER_COMMAND =''
* I_CALLBACK_TOP_OF_PAGE =''
* I_CALLBACK_HTML_TOP_OF_PAGE =''
* I_CALLBACK_HTML_END_OF_LIST =''
* I_STRUCTURE_NAME =
* I_BACKGROUND_ID =''
* I_GRID_TITLE =
* I_GRID_SETTINGS =
* IS_LAYOUT =
IT_FIELDCAT = gt_fcat
* IT_EXCLUDING =
* IT_SPECIAL_GROUPS =
* IT_SORT =
* IT_FILTER =
* IS_SEL_HIDE =
* I_DEFAULT = 'X'
* I_SAVE =''
* IS_VARIANT =
* IT_EVENTS =
* IT_EVENT_EXIT =
* IS_PRINT =
* IS_REPREP_ID =
* I_SCREEN_START_COLUMN =0

BHAVANA Page | 201


SAP ABAP TRAINING
* I_SCREEN_START_LINE =0
* I_SCREEN_END_COLUMN =0
* I_SCREEN_END_LINE =0
* I_HTML_HEIGHT_TOP =0
* I_HTML_HEIGHT_END =0
* IT_ALV_GRAPHICS =
* IT_HYPERLINK =
* IT_ADD_FIELDCAT =
* IT_EXCEPT_QINFO =
* IR_SALV_FULLSCREEN_ADAPTER =
* O_PREVIOUS_SRAL_HANDLER =
* IMPORTING
* E_EXIT_CAUSED_BY_CALLER =
* ES_EXIT_CAUSED_BY_USER =
TABLES
t_outtab = gt_vbak
EXCEPTIONS
PROGRAM_ERROR =1
OTHERS =2
.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.

OUTPUT:

BHAVANA Page | 202


SAP ABAP TRAINING
ALV with LAYOUT

Layout:
It is a structure or work area which is used to decorate or embellish the output of ALV report.
Layout contains the few properties to decorate the ALV output.

The properties are,

1. ZEBRA ='X'.
Displays ALV with different colors
2. COLWIDTH-OPTIMIZE='X'.
Each column in ALV o/p displayed with maximum length, to display the entire data.
3. EDIT='X'.
All the columns are displayed in editable mode.
4. NO_VLINE ='X'.
Vertical lines will not be displayed
5. NO_HLINE ='X'.
Horizontal lines will not be displayed

Program using ALV with Layout

REPORT ZSB_ALV_WIT_LAYOUT.

data: gt_Sflight type table of sflight,


gs_layout type slis_layout_Alv.

select * from sflight into table gt_Sflight.

gs_layout-zebra = 'X'.
gs_layout-colwidth_optimize = 'X'.
* gs_layout-edit = 'X'.
gs_layout-no_vline = 'X'.
gs_layout-no_hline = 'X'.
* gs_layout-no_keyfix = 'X'.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'


EXPORTING
* I_INTERFACE_CHECK =''
* I_BYPASSING_BUFFER =''

BHAVANA Page | 203


SAP ABAP TRAINING
* I_BUFFER_ACTIVE =''
I_CALLBACK_PROGRAM = SY-REPID
* I_CALLBACK_PF_STATUS_SET =''
* I_CALLBACK_USER_COMMAND =''
* I_CALLBACK_TOP_OF_PAGE =''
* I_CALLBACK_HTML_TOP_OF_PAGE =''
* I_CALLBACK_HTML_END_OF_LIST =''
I_STRUCTURE_NAME = 'SFLIGHT'
* I_BACKGROUND_ID =''
* I_GRID_TITLE =
* I_GRID_SETTINGS =
IS_LAYOUT = gs_layout
* IT_FIELDCAT =
* IT_EXCLUDING =
* IT_SPECIAL_GROUPS =
* IT_SORT =
* IT_FILTER =
* IS_SEL_HIDE =
* I_DEFAULT = 'X'
* I_SAVE =''
* IS_VARIANT =
* IT_EVENTS =
* IT_EVENT_EXIT =
* IS_PRINT =
* IS_REPREP_ID =
* I_SCREEN_START_COLUMN =0
* I_SCREEN_START_LINE =0
* I_SCREEN_END_COLUMN =0
* I_SCREEN_END_LINE =0
* I_HTML_HEIGHT_TOP =0
* I_HTML_HEIGHT_END =0
* IT_ALV_GRAPHICS =
* IT_HYPERLINK =
* IT_ADD_FIELDCAT =
* IT_EXCEPT_QINFO =
* IR_SALV_FULLSCREEN_ADAPTER =
* O_PREVIOUS_SRAL_HANDLER =
* IMPORTING
* E_EXIT_CAUSED_BY_CALLER =
* ES_EXIT_CAUSED_BY_USER =
TABLES
t_outtab = gt_sflight
EXCEPTIONS
PROGRAM_ERROR =1

BHAVANA Page | 204


SAP ABAP TRAINING
OTHERS =2
.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.

OUTPUT

BHAVANA Page | 205


SAP ABAP TRAINING
ALV with GRAND TOTALS:

The totals can be calculated in two ways


By clicking on ∑ALV output field.
By programmatically setting the option
DO_SUM='X', for a currency/quantity field in FCAT.

Program using ALV with GRAND TOTALS

REPORT ZSB_ALV_WIT_GRAND_TOTALS.

type-pools slis.
data : gt_vbak type table of vbak,
gt_Fcat type slis_t_fieldcat_alv,
gs_fcat type slis_fieldcat_alv.

select * from vbak into table gt_vbak.

gs_fcat-col_pos = 1.
gs_fcat-fieldname = 'VBELN'.
gs_fcat-seltext_m = 'sales order'.
gs_Fcat-key = 'X '.
* it will show different color ******
append gs_fcat to gt_fcat.

clear gs_fcat.

gs_fcat-col_pos = 2.
gs_fcat-fieldname = 'ERDAT'.
gs_fcat-seltext_m = 'CREATED DATE'.
append gs_fcat to gt_fcat.

clear gs_fcat.

BHAVANA Page | 206


SAP ABAP TRAINING
gs_fcat-col_pos = 3.
gs_fcat-fieldname = 'ERNAM'.
gs_fcat-seltext_m = 'CREATED BY'.
append gs_fcat to gt_fcat.

clear gs_fcat.

gs_fcat-col_pos = 4.
gs_fcat-fieldname = 'AUART'.
gs_fcat-seltext_m = 'SO DOC TYPE'.
append gs_fcat to gt_fcat.

clear gs_fcat.

gs_fcat-col_pos = 5.
gs_fcat-fieldname = 'VKORG'.
gs_fcat-seltext_m = 'sales organization'.
append gs_fcat to gt_fcat.

gs_fcat-col_pos = 6.
gs_fcat-fieldname = 'NETWR'.
gs_fcat-seltext_m = 'sales order price'.
gs_fcat-do_sum = 'X'.
append gs_fcat to gt_fcat.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'


EXPORTING
* I_INTERFACE_CHECK =''
* I_BYPASSING_BUFFER =''
* I_BUFFER_ACTIVE =''
I_CALLBACK_PROGRAM = sy-repid
* I_CALLBACK_PF_STATUS_SET =''
* I_CALLBACK_USER_COMMAND =''
* I_CALLBACK_TOP_OF_PAGE =''
* I_CALLBACK_HTML_TOP_OF_PAGE =''
* I_CALLBACK_HTML_END_OF_LIST =''
* I_STRUCTURE_NAME =
* I_BACKGROUND_ID =''

BHAVANA Page | 207


SAP ABAP TRAINING
* I_GRID_TITLE =
* I_GRID_SETTINGS =
* IS_LAYOUT =
IT_FIELDCAT = gt_fcat
* IT_EXCLUDING =
* IT_SPECIAL_GROUPS =
* IT_SORT =
* IT_FILTER =
* IS_SEL_HIDE =
* I_DEFAULT = 'X'
* I_SAVE =''
* IS_VARIANT =
* IT_EVENTS =
* IT_EVENT_EXIT =
* IS_PRINT =
* IS_REPREP_ID =
* I_SCREEN_START_COLUMN =0
* I_SCREEN_START_LINE =0
* I_SCREEN_END_COLUMN =0
* I_SCREEN_END_LINE =0
* I_HTML_HEIGHT_TOP =0
* I_HTML_HEIGHT_END =0
* IT_ALV_GRAPHICS =
* IT_HYPERLINK =
* IT_ADD_FIELDCAT =
* IT_EXCEPT_QINFO =
* IR_SALV_FULLSCREEN_ADAPTER =
* O_PREVIOUS_SRAL_HANDLER =
* IMPORTING
* E_EXIT_CAUSED_BY_CALLER =
* ES_EXIT_CAUSED_BY_USER =
TABLES
t_outtab = gt_vbak
EXCEPTIONS
PROGRAM_ERROR =1
OTHERS =2

.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.

BHAVANA Page | 208


SAP ABAP TRAINING
OUTPUT

BHAVANA Page | 209


SAP ABAP TRAINING
ALV WITH SUB TOTALS

To calculate sub totals, we need to find out on What basis (field name) the sub totals need to be
calculated.
We need to sort the field in ascending order.
Then we need to set the property SUBTOT ='x' in FACT.

Program using ALV with SUB TOTALS

REPORT ZSB_ALV_WIT_SUB_TOTALS.

type-pools slis.
data : gt_vbak type table of vbak,
gt_Fcat type slis_t_fieldcat_alv,
gs_fcat type slis_fieldcat_alv,
i_sort type slis_t_sortinfo_alv,
wa_sort type slis_sortinfo_alv.

select * from vbak into table gt_vbak.

gs_fcat-col_pos = 1.
gs_fcat-fieldname = 'VBELN'.
gs_fcat-seltext_m = 'sales order'.
gs_Fcat-key = 'X '.
* it will show different color ******
append gs_fcat to gt_fcat.

clear gs_fcat.

gs_fcat-col_pos = 2.
gs_fcat-fieldname = 'ERDAT'.
gs_fcat-seltext_m = 'CREATED DATE'.
append gs_fcat to gt_fcat.

clear gs_fcat.

gs_fcat-col_pos = 3.
gs_fcat-fieldname = 'ERNAM'.
gs_fcat-seltext_m = 'CREATED BY'.

BHAVANA Page | 210


SAP ABAP TRAINING
append gs_fcat to gt_fcat.

clear gs_fcat.

gs_fcat-col_pos = 4.
gs_fcat-fieldname = 'AUART'.
gs_fcat-seltext_m = 'SO DOC TYPE'.
append gs_fcat to gt_fcat.

clear gs_fcat.

gs_fcat-col_pos = 5.
gs_fcat-fieldname = 'VKORG'.
gs_fcat-seltext_m = 'sales organization'.
append gs_fcat to gt_fcat.

clear gs_fcat.

gs_fcat-col_pos = 6.
gs_fcat-fieldname = 'NETWR'.
gs_fcat-seltext_m = 'sales order price'.
gs_fcat-do_sum = 'X'.
append gs_fcat to gt_fcat.

WA_SORT-SPOS = '1'.
WA_SORT-FIELDNAME = 'VBELN'.
WA_SORT-UP = 'X'.
WA_SORT-SUBTOT = 'X'.
APPEND WA_SORT TO I_SORT.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'


EXPORTING
* I_INTERFACE_CHECK =''
* I_BYPASSING_BUFFER =''
* I_BUFFER_ACTIVE =''
I_CALLBACK_PROGRAM = sy-repid
* I_CALLBACK_PF_STATUS_SET =''
* I_CALLBACK_USER_COMMAND =''
* I_CALLBACK_TOP_OF_PAGE =''
* I_CALLBACK_HTML_TOP_OF_PAGE =''
* I_CALLBACK_HTML_END_OF_LIST =''

BHAVANA Page | 211


SAP ABAP TRAINING
* I_STRUCTURE_NAME =
* I_BACKGROUND_ID =''
* I_GRID_TITLE =
* I_GRID_SETTINGS =
* IS_LAYOUT =
IT_FIELDCAT = gt_fcat
* IT_EXCLUDING =
* IT_SPECIAL_GROUPS =
IT_SORT = i_sort
* IT_FILTER =
* IS_SEL_HIDE =
* I_DEFAULT = 'X'
* I_SAVE =''
* IS_VARIANT =
* IT_EVENTS =
* IT_EVENT_EXIT =
* IS_PRINT =
* IS_REPREP_ID =
* I_SCREEN_START_COLUMN =0
* I_SCREEN_START_LINE =0
* I_SCREEN_END_COLUMN =0
* I_SCREEN_END_LINE =0
* I_HTML_HEIGHT_TOP =0
* I_HTML_HEIGHT_END =0
* IT_ALV_GRAPHICS =
* IT_HYPERLINK =
* IT_ADD_FIELDCAT =
* IT_EXCEPT_QINFO =
* IR_SALV_FULLSCREEN_ADAPTER =
* O_PREVIOUS_SRAL_HANDLER =
* IMPORTING
* E_EXIT_CAUSED_BY_CALLER =
* ES_EXIT_CAUSED_BY_USER =
TABLES
t_outtab = gt_vbak
EXCEPTIONS
PROGRAM_ERROR =1
OTHERS =2
.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.

BHAVANA Page | 212


SAP ABAP TRAINING
OUTPUT:

BHAVANA Page | 213


SAP ABAP TRAINING
EVENTS AND LOGO IN ALV:

Program using Events in ALV

REPORT ZSB_ALV_EVENTS_LOGO.

data : gt_vbak type table of vbak,


gt_events type table of slis_alv_event,
gs_events type slis_alv_event,
it_heading type table of slis_listheader,
wa_heading type slis_listheader.

select * from vbak into table gt_vbak.

**CALL FUNCTION 'REUSE_ALV_EVENTS_GET'


*** EXPORTING
*** I_LIST_TYPE =0
** IMPORTING
** ET_EVENTS = gt_events
** EXCEPTIONS
** LIST_TYPE_WRONG =1
** OTHERS =2
** .
**IF sy-subrc <> 0.
*** Implement suitable error handling here
**ENDIF.

***
***READ TABLE gt_Events into gs_events with key name = 'TOP-OF-PAGE'.
***if sy-subrc = 0.
*** gs_events-form = 'HEADING'.
*** MODIFY gt_events FROM gs_events. "INDEX sy-tabix.
***endif.

*PERFORM HEADING.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'


EXPORTING
* I_INTERFACE_CHECK =''
* I_BYPASSING_BUFFER =''
* I_BUFFER_ACTIVE =''
I_CALLBACK_PROGRAM = sy-repid
* I_CALLBACK_PF_STATUS_SET =''

BHAVANA Page | 214


SAP ABAP TRAINING
* I_CALLBACK_USER_COMMAND =''
I_CALLBACK_TOP_OF_PAGE = 'HEADING'
* I_CALLBACK_HTML_TOP_OF_PAGE =''
* I_CALLBACK_HTML_END_OF_LIST =''
I_STRUCTURE_NAME = 'VBAK'
* I_BACKGROUND_ID =''
* I_GRID_TITLE =
* I_GRID_SETTINGS =
* IS_LAYOUT =
* IT_FIELDCAT =
* IT_EXCLUDING =
* IT_SPECIAL_GROUPS =
* IT_SORT =
* IT_FILTER =
* IS_SEL_HIDE =
* I_DEFAULT = 'X'
* I_SAVE =''
* IS_VARIANT =
IT_EVENTS = gt_events
* IT_EVENT_EXIT =
* IS_PRINT =
* IS_REPREP_ID =
* I_SCREEN_START_COLUMN =0
* I_SCREEN_START_LINE =0
* I_SCREEN_END_COLUMN =0
* I_SCREEN_END_LINE =0
* I_HTML_HEIGHT_TOP =0
* I_HTML_HEIGHT_END =0
* IT_ALV_GRAPHICS =
* IT_HYPERLINK =
* IT_ADD_FIELDCAT =
* IT_EXCEPT_QINFO =
* IR_SALV_FULLSCREEN_ADAPTER =
* O_PREVIOUS_SRAL_HANDLER =
* IMPORTING
* E_EXIT_CAUSED_BY_CALLER =
* ES_EXIT_CAUSED_BY_USER =
TABLES
t_outtab = gt_vbak
EXCEPTIONS
PROGRAM_ERROR =1
OTHERS =2
.
IF sy-subrc <> 0.

BHAVANA Page | 215


SAP ABAP TRAINING
* Implement suitable error handling here
ENDIF.
*&---------------------------------------------------------------------*
*& Form HEADING
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM heading .

wa_heading-typ = 'H'.
wa_heading-info = 'SALES ORDER DETAILS'.
APPEND wa_HEADING TO it_heading.

CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'


EXPORTING
it_list_commentary = it_heading
I_LOGO = 'ZSB_LOGO'
* I_END_OF_LIST_GRID =
* I_ALV_FORM =
.
ENDFORM.

OUTPUT:

BHAVANA Page | 216


SAP ABAP TRAINING
INTERACTIVE ALV'S:

EPORT zsb_alv_interactive.

DATA : gt_vbak TYPE TABLE OF vbak,


gs_vbak TYPE vbak,
gt_vbap TYPE TABLE OF vbap,
it_heading TYPE TABLE OF slis_listheader,
wa_heading TYPE slis_listheader.

START-OF-SELECTION.

SELECT * FROM vbak INTO TABLE gt_vbak.

**PERFORM INTERACT.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'


EXPORTING
i_callback_program = sy-repid
i_callback_user_command = 'INTERACT'
i_callback_top_of_page = 'HEADING'
i_structure_name = 'VBAK'
TABLES
t_outtab = gt_vbak
EXCEPTIONS
program_error =1
OTHERS = 2.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.
REFRESH it_heading.
*&---------------------------------------------------------------------*
*& Form INTERACT
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM interact USING ucomm TYPE sy-ucomm
selfield TYPE slis_selfield.

BHAVANA Page | 217


SAP ABAP TRAINING
IF ucomm = '&IC1'.

REFRESH it_heading.
READ TABLE gt_vbak INTO gs_vbak INDEX selfield-tabindex.
IF sy-subrc = '0'.
SELECT * FROM vbap INTO TABLE gt_vbap WHERE vbeln = gs_vbak-vbeln.
ENDIF.

** PERFORM BUTTONS.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'


EXPORTING
i_callback_program = sy-repid
i_callback_pf_status_set = 'BUTTONS'
i_callback_top_of_page = 'HEADING1'
i_structure_name = 'VBAP'
TABLES
t_outtab = gt_vbap
EXCEPTIONS
program_error =1
OTHERS = 2.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.

REFRESH it_heading.

ENDIF.

IF sy-ucomm = 'DDIC'.
CALL TRANSACTION 'SE11'.
ELSEIF sy-ucomm = 'SAVE'.
CALL TRANSACTION 'SE38'.
ELSEIF sy-ucomm = 'BACK'.
SET SCREEN 0.
ELSEIF sy-ucomm = 'EXIT'.
LEAVE SCREEN.
ELSEIF sy-ucomm = 'TCODE'.
CALL TRANSACTION 'SE93'.
ENDIF.

ENDFORM.

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

BHAVANA Page | 218


SAP ABAP TRAINING
*& Form HEADING
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM heading1 .

wa_heading-typ = 'H'.
wa_heading-info = 'SALES ORDER ITEM DETAILS'.
APPEND wa_heading TO it_heading.

CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'


EXPORTING
it_list_commentary = it_heading
i_logo = 'ZSB_LOGO'
* I_END_OF_LIST_GRID =
* I_ALV_FORM =
.
ENDFORM.

FORM heading .

wa_heading-typ = 'H'.
wa_heading-info = 'SALES ORDER DETAILS'.
APPEND wa_heading TO it_heading.

CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'


EXPORTING
it_list_commentary = it_heading
i_logo = 'ZSB_LOGO'
* I_END_OF_LIST_GRID =
* I_ALV_FORM =
.

ENDFORM.
*&---------------------------------------------------------------------*
*& Form BUTTONS
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text

BHAVANA Page | 219


SAP ABAP TRAINING
*&---------------------------------------------------------------------*
FORM buttons USING extab TYPE slis_t_extab.

SET PF-STATUS 'ZSB_GUI' EXCLUDING extab. .

ENDFORM.

OUTPUT:

When double clicks any field, it displays like below.

BHAVANA Page | 220


SAP ABAP TRAINING
HIERARCHICAL ALV:

REPORT zsb_alv_hierarchal.

TYPE-POOLS slis.

TYPES: BEGIN OF ty_vbak,


vbeln TYPE vbak-vbeln,
erdat TYPE vbak-erdat,
ernam TYPE vbak-ernam,
END OF ty_vbak,
BEGIN OF ty_vbap,
vbeln TYPE vbap-vbeln,
posnr TYPE vbap-posnr,
matnr TYPE vbap-matnr,
END OF ty_vbap.

DATA:gt_vbak TYPE TABLE OF ty_vbak,


gt_vbap TYPE TABLE OF ty_vbap,
gs_key TYPE slis_keyinfo_alv,
gt_fcat TYPE TABLE OF slis_fieldcat_alv,
gs_fcat TYPE slis_fieldcat_alv.

START-OF-SELECTION.
SELECT vbeln erdat ernam
FROM vbak
INTO TABLE gt_vbak
UP TO 124 ROWS.
IF sy-subrc = 0.
SELECT vbeln posnr matnr
FROM vbap
INTO TABLE gt_vbap
FOR ALL ENTRIES IN gt_vbak
WHERE vbeln = gt_vbak-vbeln.
IF sy-subrc = 0.

ENDIF.
ENDIF.

gs_key-header01 = 'VBELN'.
gs_key-item01 = 'VBELN'.

BHAVANA Page | 221


SAP ABAP TRAINING
gs_fcat-fieldname = 'VBELN'.
gs_fcat-tabname = 'GT_VBAK'.
gs_fcat-seltext_m = 'So number'.
APPEND gs_fcat TO gt_fcat.
CLEAR gs_fcat.

gs_fcat-fieldname = 'ERDAT'.
gs_fcat-tabname = 'GT_VBAK'.
gs_fcat-seltext_m = 'Date'.
APPEND gs_fcat TO gt_fcat.
CLEAR gs_fcat.

gs_fcat-fieldname = 'ERNAM'.
gs_fcat-tabname = 'GT_VBAK'.
gs_fcat-seltext_m = 'Name'.
APPEND gs_fcat TO gt_fcat.
CLEAR gs_fcat.

gs_fcat-fieldname = 'VBELN'.
gs_fcat-tabname = 'GT_VBAP'.
gs_fcat-seltext_m = 'So number'.
APPEND gs_fcat TO gt_fcat.
CLEAR gs_fcat.

gs_fcat-fieldname = 'POSNR'.
gs_fcat-tabname = 'GT_VBAP'.
gs_fcat-seltext_m = 'item number'.
APPEND gs_fcat TO gt_fcat.
CLEAR gs_fcat.

gs_fcat-fieldname = 'MATNR'.
gs_fcat-tabname = 'GT_VBAP'.
gs_fcat-seltext_m = 'Mat number'.
APPEND gs_fcat TO gt_fcat.
CLEAR gs_fcat.

CALL FUNCTION 'REUSE_ALV_HIERSEQ_LIST_DISPLAY'


EXPORTING
* I_INTERFACE_CHECK = ' '
i_callback_program = sy-repid
* I_CALLBACK_PF_STATUS_SET =''
* I_CALLBACK_USER_COMMAND =''
* IS_LAYOUT =

BHAVANA Page | 222


SAP ABAP TRAINING
it_fieldcat = gt_fcat
* IT_EXCLUDING =
* IT_SPECIAL_GROUPS =
* IT_SORT =
* IT_FILTER =
* IS_SEL_HIDE =
* I_SCREEN_START_COLUMN =0
* I_SCREEN_START_LINE =0
* I_SCREEN_END_COLUMN =0
* I_SCREEN_END_LINE = 0
* I_DEFAULT = 'X'
* I_SAVE =''
* IS_VARIANT =
* IT_EVENTS =
* IT_EVENT_EXIT =
i_tabname_header = 'GT_VBAK'
i_tabname_item = 'GT_VBAP'
* I_STRUCTURE_NAME_HEADER =
* I_STRUCTURE_NAME_ITEM =
is_keyinfo = gs_key
* IS_PRINT =
* IS_REPREP_ID =
* I_BYPASSING_BUFFER =
* I_BUFFER_ACTIVE =
* IR_SALV_HIERSEQ_ADAPTER =
* IT_EXCEPT_QINFO =
* I_SUPPRESS_EMPTY_DATA = ABAP_FALSE
* IMPORTING
* E_EXIT_CAUSED_BY_CALLER =
* ES_EXIT_CAUSED_BY_USER =
TABLES
t_outtab_header = gt_vbak
t_outtab_item = gt_vbap
EXCEPTIONS
program_error =1
OTHERS = 2.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.

BHAVANA Page | 223


SAP ABAP TRAINING
OUTPUT:

BHAVANA Page | 224


SAP ABAP TRAINING
BLOCKED ALV:

REPORT ZSB_ALV_BLOCKED.

DATA: gT_vbak TYPE TABLE OF vbak,


gt_vbap TYPE TABLE OF vbap,
gt_fcat TYPE TABLE OF slis_fieldcat_alv,
gt_fcat1 TYPE TABLE OF slis_fieldcat_alv,
gt_events TYPE TABLE OF slis_alv_event,
gs_layout TYPE slis_layout_alv.

SELECT * FROM vbak INTO TABLE gt_Vbak UP TO 5 ROWS.


IF sy-subrc = 0.
SELECT * FROM vbap INTO TABLE gt_Vbap FOR ALL ENTRIES IN gt_Vbak
WHERE vbeln = gt_Vbak-vbeln.
ENDIF.

CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_INIT'


EXPORTING
i_callback_program = sy-repid
.
CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
EXPORTING
i_program_name = sy-repid
i_structure_name = 'VBAK'
CHANGING
ct_fieldcat = gt_fcat
EXCEPTIONS
inconsistent_interface = 1
program_error =2
OTHERS = 3.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.

CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_APPEND'


EXPORTING
is_layout = gs_layout
it_fieldcat = gt_fcat
i_tabname = 'VBAK'
it_events = gt_events
TABLES
t_outtab = gt_vbak

BHAVANA Page | 225


SAP ABAP TRAINING
.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.

CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'


EXPORTING
i_program_name = sy-repid
i_structure_name = 'VBAP'
CHANGING
ct_fieldcat = gt_fcat1
EXCEPTIONS
inconsistent_interface = 1
program_error =2
OTHERS = 3.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.

CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_APPEND'


EXPORTING
is_layout = gs_layout
it_fieldcat = gt_fcat1
i_tabname = 'VBAP'
it_events = gt_events
TABLES
t_outtab = gt_vbap
.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.

CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_DISPLAY'


EXCEPTIONS
PROGRAM_ERROR =1
OTHERS =2
.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.

BHAVANA Page | 226


SAP ABAP TRAINING
OUTPUT:

BHAVANA Page | 227


SAP ABAP TRAINING
27. CONTROL BREAK STATEMENTS

 Control break statements are work with in the loop at internal table. Before using the
control break statements.

 We must sort the internal table based on at new field.

 Control break statements are

o At First

o At New<field name>

o At End of <field name>

o At last, each control break statement ends with Endat.

 AT FIRST: -This is an event which is triggered at the first record of internal table.

 Advantage: -This is used to display the header information for internal table.

 AT NEW <field name>: -It’s an event which is triggered at the first record of each block.

 Advantage: -It’s used to display the individual fields.

 AT END OF <field name>: -This event triggered at the last record of each block.

 Advantage: -This is used to display the sub total.

 AT LAST: -This is an event which is triggered at the last record of internal table.

 Advantage: -It’s used to display the grand total.

BHAVANA Page | 228


SAP ABAP TRAINING
 Program for control break statements

REPORT ZSB_CONTROL_BREAK_STMNTS.

TYPES:BEGIN OF ty_vbap,
vbeln TYPE vbap-vbeln,
posnr TYPE vbap-posnr,
matnr TYPE vbap-matnr,
netwr TYPE vbap-netwr,
END OF ty_vbap.
data: gt_vbap TYPE STANDARD TABLE OF ty_vbap,"vbap,
gs_vbap TYPE ty_vbap,
gs_vbapt TYPE ty_vbap.

START-OF-SELECTION.
SELECT vbeln
posnr
matnr
netwr
FROM vbap
into TABLE gt_vbap
UP TO 123 ROWS.
if sy-subrc = 0.

endif.
data lv_num type i.
data lv_total TYPE vbap-netwr.
sort gt_vbap.
LOOP AT gt_vbap INTO gs_vbap.
MOVE-CORRESPONDING gs_vbap to gs_vbapt.
at FIRST.
lv_num = 1.
Write: 'First statement'.
ENDAT.

at NEW vbeln.
WRITE / gs_vbapt-vbeln.
ENDAT.

on CHANGE OF gs_vbap-vbeln.
WRITE gs_vbapt-vbeln.
endon.

BHAVANA Page | 229


SAP ABAP TRAINING
*lv_total = sum(gs_vbapt-netwr).
at END OF vbeln.
sum.

WRITE gs_vbapt-netwr.
ENDAT.
lv_num = lv_num + 1.

at LAST.
WRITE lv_num.
ENDAT.
ENDLOOP.

WRITE 'program ended'.

OUTPUT:

BHAVANA Page | 230


SAP ABAP TRAINING
BHAVANA Page | 231
SAP ABAP TRAINING
28. MODULE POOL PROGRAMMING

It is a special type of programming which is used to create custom SAP Screen as per
business requirement.

SE80 is the TCODE for creating MPP programs.

Every MPP program must be executed with a transaction.

Events in Module Pool Programming

There are four events available.



 PBO (Process Before Output): Triggered before MPP screen is displayed.

 PAI (Process After Input): Triggered after MPP screen is displayed when user raises an
action. Also, Now PBO is also triggered.

 POV (Process on Value Request): Triggered when User Clicks on search help or F4
Button.

 POH (Process on Help Request): Triggered when User Clicks on search help or F1
Button.

Include programs:
 Basically, there are four include programs which are created automatically for an MPP
program

 <MPP name>_TOP top include program  All data declarations.

 <MPP name>_o01PBO include program  All logic related to PBO event.

 <MPP name>_I01PAI include program  All logic related to PAI event.

BHAVANA Page | 232


SAP ABAP TRAINING
 <MPP name>_F01Forms include program All logic related to subroutines.

SCREEN:

 It is a visible layout which is displayed in the output. The components of the


Screen are
 Components of Screen:

 Attributes: Properties of screen.

 Element List: List of UI/Library elements.

 Flow-Logic: Abap logic related to MPP.

 Layout: Screen Designing Area.

a) Steps to create module pool programming.

 MODULE:

 It is a sub-program which contains the ABAP code for a screen.

 Flow-Logic cannot understand ABAP statements. So, the entire


ABAP code is written in the form of modules.

 Since the entire abap logic is divided in the form of modules, that
is why it is called MODULE POOL PROGRAMMING.

Steps:

 Go to SE80.

 Select program from dropdown list.

BHAVANA Page | 233


SAP ABAP TRAINING
 Give a name & press enter.

 Click on YES.

 Tick on create with top include.

BHAVANA Page | 234


SAP ABAP TRAINING
 Provide title and select type as module pool and save it in package.

 Right click on program nameCreateScreen.

BHAVANA Page | 235


SAP ABAP TRAINING
 Give the screen number as 0100 and Press ENTER.

 Give the description.

BHAVANA Page | 236


SAP ABAP TRAINING
 Click on Flow-Logic.

 Uncomment the modules and create them as below.

 Click on Layout Button.

BHAVANA Page | 237


SAP ABAP TRAINING
 Drag and drop text UI element onto the screen.

 Double click on it.

 Provide the name and texts.

 Name T1.

 Text ‘This is the sample MPP Program’.

BHAVANA Page | 238


SAP ABAP TRAINING
 Click on Flow Logic.

 Double click on PBO module.

 Right click on the program nameCreateGUI Status.

 Right click on the program nameCreateGUI title.

BHAVANA Page | 239


SAP ABAP TRAINING
 Click on Save and Back.

 Double click on PAI module.

 Save and activate.

 Right click on Program nameCreateTransaction.

BHAVANA Page | 240


SAP ABAP TRAINING
 Give the text, program name, screen number.

 Select all the checkboxes at the bottom.

 Save it.

 Execute the transaction and test the program.

OUTPUT

BHAVANA Page | 241


SAP ABAP TRAINING
b) Steps to create a module pool programming using real time example

 Create a MPP program in SE80 and create all include programs

 Create a Screen and create PBO and PAI Modules

 Go to TOP Include program and declare the following.

 Save & Activate TOP Include program immediately

 Now go to Screen 0100 layout.

 Click on Dictionary/Program fields ICON

BHAVANA Page | 242


SAP ABAP TRAINING
 Give the name as gs_mara

 and click on

 Select all fields and press enter

 Place all the fields on the screen.

 Now Drag and drop text fields from library and place them before each input field.

 Now Drag and drop a button also and provide the details as below:

 Also provide FCT code as GET

BHAVANA Page | 243


SAP ABAP TRAINING
 Finally, the screen should look as below:

FCT CODE:
It is a function code which is used to identify the button which is clicked.
The FCTCODE is automatically stored in a system variable SY-UCOMM.

 Double click on PAI module

 Save, Activate, Test it.

 Double click on PBO module

BHAVANA Page | 244


SAP ABAP TRAINING
 Right click on the program nameCreateGUI Status.

 Right click on the program nameCreateGUI Title.

 Enter the Material no

 Click on GET button

 The details should be displayed

BHAVANA Page | 245


SAP ABAP TRAINING
 Making Input Fields Disable:

 Double click on any input field



 The properties screen is displayed

 Set the property as below

 Select program  input  not possible

OUTPUT:

BHAVANA Page | 246


SAP ABAP TRAINING
c) Steps to create a MPP using tabstrip

 Tab strip’s are used to divide the main screen into sub screens to display mass amount of
data.

 Each sub screen is called as a TAB.

 Each sub screen Should be designed separately with a no.

 Each sub screen must have an area to display the sub screen called as Sub screen area

 Go to SE80.

 Select program from dropdown list.

 Give a name & press enter.

 Click on YES.

 Tick on create with top include.

BHAVANA Page | 247


SAP ABAP TRAINING
 Provide top include name

 Provide title and select type as module pool and save it in package.

 Save and activate immediately.

 Right click on program nameCreateScreen.

 Give the screen number as 0100 and Press ENTER.

BHAVANA Page | 248


SAP ABAP TRAINING
 Give the description.

 Click on Flow-Logic.

 Click on Layout Button

 Click on tabstrip wizard icon

 Drag and drop onto layout and it will be loading a screen i.e., tabstrip wizard.

BHAVANA Page | 249


SAP ABAP TRAINING
 Click on continue.

 Provide tabstrip name as TBSTR and click on continue

 Provide tab text and click on continue

BHAVANA Page | 250


SAP ABAP TRAINING
 Click on continue.

 The names of program includes in which the data definitions and the input/output
modules are to be created:

 Include for the data definition.


 Include for the PBO module
 Include for the PAI module

BHAVANA Page | 251


SAP ABAP TRAINING
 Click on continue.
 The following objects will be generated:
Subscreens:

0101

0102

0103

BHAVANA Page | 252


SAP ABAP TRAINING
 Click on complete.

 Automatically it will go to layout page.

 Click on save and activate then go to flow logic.

 Right on program name and click on activate.

 101, 102 ,103 all the logic was automatically assigned for that.

BHAVANA Page | 253


SAP ABAP TRAINING
 Right click on the program nameCreateTransaction.

 Provide transaction code and short text.

 Select the first radio button (Program and Dynpro).

 Click on continue.

 Give the text, program name, screen number.

 Select all the checkboxes at the bottom.

 Save it.

BHAVANA Page | 254


SAP ABAP TRAINING
 Execute the transaction and test the program.

OUTPUT:

BHAVANA Page | 255


SAP ABAP TRAINING
d) Steps to create MPP using Table control

 TABLE CONTROL: It is an element which is used to display the data in the form of a
table format is called TABLE CONTROL.

 There are 3 important points to be followed, when working with table control.

o Table control declaration.

o Loop at ITAB into WA with control <table control name> (IN PBO).

Endloop

o Loop at ITAB (IN PAI).

Endloop.

 Table control declaration



 Syntax: -

 Controls: <table control> name type table view using screen <screen no>.

BHAVANA Page | 256


SAP ABAP TRAINING
Loop at PBO

 The loop at ITAB into WA…………end loop must be used in PBO event to read each
record from ITAB internal table into work area and then work area to table control
columns.

 Loop at PAI

 The loop at ITAB into WA…………end loop must be used in PAI event to read each
record from table control columns into internal table

 PBO event

 ITAB --------------WA----------------Table control.

 Loop at ITAB into WA with control <table control name>

 Endloop

PAI event

BHAVANA Page | 257


SAP ABAP TRAINING
 Table Control ---------Internal Table ------------- Work area.

 Loop at ITAB.

 Endloop.

 Vertical scrollbar: In Table control by default, we don’t get vertical scroll bar.

 To display it, use the below syntax

<TABLECONTROLNAME>-LINES = <NO>

 Horizontal & Vertical Lines: In Table control by default, we don’t get vertical and
Horizontal lines.

Steps:

 Go to SE80.

 Select program from dropdown list.

 Give a name & press enter.

 Click on YES

 Tick on create with top include

BHAVANA Page | 258


SAP ABAP TRAINING
 Provide top include name

 Provide title and select type as module pool and save it in package.

 Save and activate immediately.

BHAVANA Page | 259


SAP ABAP TRAINING
 Right click on program nameCreateScreen.

 Give the screen number as 0100 and Press ENTER.

 Give the description.

 Click on Flow-Logic.

 Click on Layout Button

 Click on table control wizard icon

 Drag and drop onto layout and it will be loading a screen i.e., table control wizard.

BHAVANA Page | 260


SAP ABAP TRAINING
 Click on continue.

 Provide table control name as TBCL and click on continue

 Provide dictionary table name (we have to select the table whose fields should be used as
the columns of the table control) and click on continue

BHAVANA Page | 261


SAP ABAP TRAINING
 Click on continue.
 Next, we have to select which fields of the table should be displayed as columns in the
table control.

 Click on continue

 In table control attributes select the radio button (output only)

BHAVANA Page | 262


SAP ABAP TRAINING
 Click on continue.

 Go to next step Select additional table maintenance functions.

 Click on continue.
 Here you must specify the names of program includes in which the data declarations, the
input/output modules and the subroutines are to be created:

 Include for the data definitions

 Include for PBO modules

 Include for PAI modules

 Include for subroutines

BHAVANA Page | 263


SAP ABAP TRAINING
 Click on continue.

BHAVANA Page | 264


SAP ABAP TRAINING
 Click on complete.

 Automatically it will go to layout page.

 Click on save and then go to flow logic

 Right click on program name and activate it.

 Right click on the program nameCreateTransaction.

 Provide transaction code and short text.

BHAVANA Page | 265


SAP ABAP TRAINING
 Select the first radio button (Program and Dynpro).

 Click on continue

 Give the text, program name, screen number.

 Select all the checkboxes at the bottom.

 Save it and activate.

BHAVANA Page | 266


SAP ABAP TRAINING
 Execute the transaction and test the program.

OUTPUT

BHAVANA Page | 267


SAP ABAP TRAINING
29. PERFORMANCE TUNING

 Run Extended syntax checks with character literals checkbox switched on & Code
Inspector to rectify all relevant errors and warning (e.g., Use the results of the above
checks to remove all variables/constants etc. that are declared but are not used)

 Transaction SE30 (ABAP Runtime Analysis) must be checked to measure/compare


program performance/runtime if program has multiple inefficient databases selects or
complicated internal table operations.

 Use transaction ST05 (SQL Trace) to see what indices your database accesses are using.
Check these indices against your “where” clause to assure they are significant. Check
other indices for this table and where you have to change your “where” clause to use it.
Create new indices, if necessary, but do not forget to check the impact by consulting
onsite coordinator.

 TYPE (data element) command is used while declaring the fields whenever feasible
instead of LIKE. Remember not always the data element name matches with the table
field name.

 Internal Table is defined with “TYPE STANDARD TABLE OF” & Work-Areas is used
instead of header lines.

 Global variables are minimized by declaring local variables or by-passing variables


through parameters & arguments while creating internal subroutine(s)

 In SELECT statement, only the required fields are selected in the same order as they
reside on the database table/structure/view.

 For selecting single row from a database table, “SELECT UP to 1 Rows” is used. “Select
Single” is used only when full primary key combination is known

 No SELECT * is used

 Use “SELECT INTO TABLE” rather than “SELECT INTO CORRESPONDING


FIELDS OF TABLE”.

BHAVANA Page | 268


SAP ABAP TRAINING
 Always specify as many primary keys as possible in WHERE clause to make the Select
efficient.

 Always select into an internal table, except when the table will be very large (i.e., when
the internal table will be greater than 500,000 records). Use “Up to N Rows” when the
number of records needed is known

 Select statement within a GET event is not used.

 Wild cards like ‘A%’ is avoided as much as possible.

 Nested Select is not used instead “Inner Join” and/or “For all Entries” is used. “For all
Entries” is to be used over “Loop at ITAB / Select / ENDLOOP” (FOR ALL ENTRIES
retrieves a unique result set so ensure you retrieve the full key from the database).

 When creating joins over database tables there should be an index at least on the inner
table for the fields in the join condition else use “FOR ALL ENTRIES” select statement.

 Usage of JOIN is limited to a maximum of 2 i.e., not more than 3 database tables are
joined at one time.

 CHECK that the internal table used in FOR ALL ENTRIES is NOT empty as this will
retrieve all entries from the table.

 Delete adjacent duplicate entries from internal table before selection from database table
using “FOR ALL ENTRIES” statement.

 For copying internal tables use ‘=’ operator instead of Looping & Appending.

 SORT inside a LOOP is not used.

 Sort internal table by fields in the correct order, which are used in a READ TABLE
statement using BINARY SEARCH. If the order of sorting is invalid the BINARY
SEARCH will never work.

BHAVANA Page | 269


SAP ABAP TRAINING
 For large internal tables where only, some rows are to be processed, use SORT and then
the READ TABLE command is used to set index to first relevant row before looping
from that index. Use CHECK or IF…EXIT…ENDIF as appropriate to exit from the loop.
 Sort fields and Sort Order on the SORT statement should be mentioned explicitly (e.g.,
SORT ITAB BY FLD1 FLD2 ASCENDING).

 Hashed table is used for processing large amount of data (provided that you access single
records only, and all with a fully specified key).

 DELETE or SORT is not used on a hashed table since it increases memory consumption.

 Sorted table is used for range accesses involving table key or index accesses.

 Fields specified in the WHERE condition with the critical operators NOT and <>
(negative SQL statements) cannot be used for a search using database indexes. Whenever
possible formulate SQL statements positively.

 When coding IF or CASE, testing conditions are nested so that the most frequently true
conditions are processed first. Also, CASE is used instead of IF when testing multiple
fields “equal to” something.

 LOOP AT ITAB INTO WORKAREA WHERE K = ‘XXX’ should be used instead of


LOOP AT ITAB INTO WORKAREA / CHECK ITAB-K = ‘XXX’.
 Also READ TABLE INTO WORKAREA should be used instead of only READ
TABLE.

 After the APPEND statement inside a loop, the work area that has been appended is
cleared.

 Internal tables, Work areas & Global Variables are freed when no longer needed (e.g.,
using the FREE / REFRESH command), especially when the tables are large, or the
program is a batch program.

 Do not delete the records of internal table inside the Loop – End loop.
 Do not use: LOOP AT ITAB WHERE EQUNR = ‘00001011’.
 DELETE ITAB.

BHAVANA Page | 270


SAP ABAP TRAINING
 ENDLOOP.
 Use: DELETE ITAB WHERE EQUNR = ‘00001011’.

 Use the MODIFY ITAB ... TRANSPORTING f1 f2 ... for single line and MODIFY
ITAB ... TRANSPORTING f1 f2 ... WHERE condition for a set of line, to accelerate the
updating of internal table.
 If possible, Update/Insert statement is used instead of Modify.

 Are the following steps ensured during database updates?


 Lock data to be edited
 Read current data from the database
 Process data and write it to the database

 Release the locks set at the beginning.

 Try to avoid logical databases. If your program uses a logical database but does not
require all fields belonging to a certain GET event, always use the FIELDS addition to
reduce the amount of data selected by the logical database.

 Avoid the aggregate (Count, Max, Min) functions in the database selection.

 Use Parallel Cursor methods for nested loop into the internal tables if second internal
table contains considerable number of records.

 In Smart form/ Sap script do not make redundant data retrieval where data is available in
interface

BHAVANA Page | 271


SAP ABAP TRAINING
30. WORKING WITH FILES
In SAP, a file can be located either in presentation server or application server.

If the file is located in presentation server, we can use GUI_UPLOAD,


GUI_DOWNLOAD function modules to read or write the data in files.

If the file is located in application server, we use the below syntaxes to read or write the
data into files.

 OPEN DATASET<filename>FOR<input/output/append>IN TEXT MODE


ENCODING DEFAULT

 READ DATASET <filename> INTO <variable>

 TRANSFER <variable/wa> to <fname>.

 CLOSE DATASET<filename>.
Open dataset: This statement is used to open a file in application
server for

 INPUT : means, the file is opened for reading the data from file
 OUTPUT : means, the file is opened for writing the data into file.
 APPEND : means, the file is opened for appending new records into
the file.

Close dataset: This statement is used to close the file which is opened by “OPEN
DATASET”.

 Note: AL11 is the transaction code for directories in application server.


 The default directories which are generally used are

 DIR_HOME, DIR_TEMP, DIR_NAME.

BHAVANA Page | 272


SAP ABAP TRAINING
Reading data from file:

 we use the below statement to read the data from application server file.

 Syntax: READ DATASET <filename> INTO <variable>

Writing data into application server:

 We use the below statement for writing the data into application server file.

 Syntax: TRANSFER <variable/wa> to <fname>.
Steps:

 Go to se38.
 Give the program name ( zsb_pl2_al2_pl ) & Click on create.
 Provide title name and select type as executable program.
 Click on continue.
 Save it in package.
Program on working with files:

REPORT zsb_pl2_al2_pl.

TYPES :BEGIN OF ty_final,


kunnr TYPE rf02d-kunnr,
name1 TYPE kna1-name1,
ort01 TYPE kna1-ort01,
pstlz TYPE kna1-pstlz,
END OF ty_final.

DATA :gt_final TYPE TABLE OF ty_final,


gs_final TYPE ty_final,
gv_path TYPE rlgrap-filename,
gt_raw TYPE truxs_t_text_data.

BHAVANA Page | 273


SAP ABAP TRAINING
DATA : gv_fname TYPE char40 VALUE 'F:\usr\sap\S4H\D34\work\',
gv_file TYPE string,
gv_field TYPE string.

PARAMETERS p_path TYPE ibipparms-path.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_path.

CALL FUNCTION 'F4_FILENAME'


EXPORTING
program_name = syst-cprog
dynpro_number = syst-dynnr
field_name = ' '
IMPORTING
file_name = p_path.

START-OF-SELECTION.

gv_path = p_path.

CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'


EXPORTING
I_FIELD_SEPERATOR = 'X'
* I_LINE_HEADER =
i_tab_raw_data = GT_RAW
i_filename = GV_PATH
TABLES
i_tab_converted_data = GT_FINAL
* EXCEPTIONS
* CONVERSION_FAILED =1
* OTHERS =2
.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.

CONCATENATE gv_fname 'BHAVANA' sy-datum sy-uzeit'.CSV' INTO gv_field .

OPEN DATASET gv_field FOR OUTPUT IN TEXT MODE ENCODING DEFAULT .

BHAVANA Page | 274


SAP ABAP TRAINING
LOOP AT gt_final INTO gs_final.

CONCATENATE gs_final-kunnr
gs_final-name1
gs_final-ort01
gs_final-pstlz INTO gv_file SEPARATED BY ','.
TRANSFER gv_file TO gv_field.

CLEAR: gv_file,gs_final.

ENDLOOP.
CLEAR gt_final[].
CLOSE DATASET gv_field.

WRITE : / 'PROGRAM ENDED'.

OUTPUT:

 Click on execute.

BHAVANA Page | 275


SAP ABAP TRAINING
 Click on allow.

 Go to /OAL11.

 Upload file to AL11, select directory (DIR_HOME) to upload file in application server.

BHAVANA Page | 276


SAP ABAP TRAINING
 Double click on DIR_HOME.

 Double on file name (VYSHNAVI201113015409.CSV).

BHAVANA Page | 277


SAP ABAP TRAINING
31. ALE - IDOC’S
ALE:

 ALE is a technology which is used to communicate between the servers available at


different geographical locations.

 To send the data and receive the data from one server to another server, we need a
dedicated network which is called as ALE (Application Link Enabling).

 Application means customer Master Appl, Material Master Appl, Sales Order Appl.

 Link means a network or connection.

 Enabling means Enable the link.

Types of data transfers

 Basically, we have two types of data transfers



 1.Outbound data transfer.

 2.Inbound data transfer.

BHAVANA Page | 278


SAP ABAP TRAINING
Outbound data transfer:

Whenever we send the data from a system to another system. It is called as outbound
data transfer i.e., data moving out of SAP is called as outbound data transfer.

Inbound data transfer:

Whenever we receive the data from a system is called Inbound data transfer i.e.,
data coming into SAP server is called Inbound data transfer

Communication between SAP to SAP:

ALE is a technology which is used to communicate between SAP-to-SAP server.



The data transfer is always in the form of a document called as “IDOC” (Intermediate
Document).

Communication between SAP to Non-SAP:

EDI (Electronic Data Interchange) is the technology which is used to communicate


between SAP server to non-SAP server.

Since IDOC is an SAP tool. The Non-SAP system cannot understand the format of
IDOC’s.

So, we use the Middleware technologies like TIBCO (or) XI to communicate between
SAP to Non-SAP.

The data transfer is always through a type of a document called as IDOC. (Post Cover)

BHAVANA Page | 279


SAP ABAP TRAINING
Since IDOC is an SAP tool, only SAP system can understand IDOC’s.

Non-SAP system cannot understand the IDOC’s.

So, we use the middleware technologies like TIBCO or XI to communicate between SAP
to non-SAP.

The IDOC is converted into XML, and it is given to TIBCO or XI.

The middleware technologies will again convert the data into a format which can be
understood by the receiver system.

IDOC’S
IDOC: - It is an intermediate document which contains the data.

 Technically IDOC is a group of segments.



 Each segment is group of fields.

 Segments are like structures.

 All the standard SAP segments will start with letter E1.

 All the custom segments must start with the letter Z1.

BHAVANA Page | 280


SAP ABAP TRAINING

 EX: - 1. DEBMAS: 01, 02, 03,04,05 is an ex for custom IDOC.

 2. CREMAS: 01, 02, 03…is an example for vendor IDOC.

 3. MATMAS: 01, 02, 03…… is an example for material IDOC.
 Where (05 is the latest version)

Example for segment: -

DEBMAS is an IDOC

E1KNA1(Cust.Master Seg)  kunnr, name1, land1 are fields.

E1KNB1(Cust.Companycode) kunnr, bukrs are the fields.

E1KNBK (customer bank details)kunnr, Banks are the fields.

WE31 is the transaction code for segment definition.

WE30 is the transaction code for IDOC type.

Runtime components of IDOC: -

Whenever an IDOC is transmitted at runtime, there are 3 components which are added
automatically to the IDOC.

BHAVANA Page | 281


SAP ABAP TRAINING
o Control record.
o Data record.
o Status record.

Steps to create an IDOC

Step1: First create the required segment in WE31 with some fields.

Step2: Create an IDOC in WE30 by inserting all the above segments.

Step1: Steps to create a segment.

 Go to WE31.

 Give the segment type as ZSB_KNA1

BHAVANA Page | 282


SAP ABAP TRAINING
 Click on the button create.

 Give short description.

 Give the list of the fields as below.

BHAVANA Page | 283


SAP ABAP TRAINING
 Click on save and back.

 Click on edit from menu barset release.

 The segment definition is completed, and it is released also



 Released status indicates that the segment definition is completed, and it can be used to
transfer the data.

Similarly create one more segment by the name ZSB_KNBK.

BHAVANA Page | 284


SAP ABAP TRAINING
 Click on the button create.

 Give short description.

 Give the list of the fields as below.

 Click on save and back.

 Click on edit from menu barset release.

BHAVANA Page | 285


SAP ABAP TRAINING
 The segment definition is completed, and it is released also

 Released status indicates that the segment definition is completed, and it can be used to
transfer the data.

Step2: Create IDOC from T-CODE WE30.

 Go to WE30 and give IDOC name as ZSB_DEBMAS05.

 Click on the button create.

BHAVANA Page | 286


SAP ABAP TRAINING
 Give description and press enter.

 Click on the button create segment

BHAVANA Page | 287


SAP ABAP TRAINING
 A pop-up is raised.

 Give the segment name as ZSB_KNA1.

 Give the minimum and maximum no. as ‘1’ because customer master will have single
record.
 Select the check box if we want to make the segment as mandatory segment.

 Press enter.

 Now, Put the cursor on ZSB_KNA1, click on the button create.

BHAVANA Page | 288


SAP ABAP TRAINING
 A pop-up is raised.

 Select the first radio button and press enter.

 Give the segment type ZSB_KNBK.

 Give the minimum no. as 1, maximum no. as 9999 because each customer will have more
than 1 bank account.

BHAVANA Page | 289


SAP ABAP TRAINING
 Press enter.

 Finally, the hierarchy should look as below.

CONFIGURATION SETTINGS FOR ALE

BHAVANA Page | 290


SAP ABAP TRAINING
1.Define Logical system:

 In this step we define a logical name for the sending & receiving SAP server systems.

 The Tcode is ‘’SALE”.

 Click on new entries and provide logical system as (S4H_LOCAL9) and name.

BHAVANA Page | 291


SAP ABAP TRAINING
 You will find logical system and name (i.e., which you are given in above) in below.

 2.Assign client to the Logical system:



 Here we maintain a client for the sending & receiving system to transfer the particular
client data.

 The Transaction code is “SALE”.

 Click on to assign logical system to client

BHAVANA Page | 292


SAP ABAP TRAINING
 Click on new entries.
 Provide client number and name, city, and name of the logical system.
 Select second radio button (automatic recording of changes).
 Click on save.

 New entries will be updated.

BHAVANA Page | 293


SAP ABAP TRAINING
3.Maintain RFC Destination:

 In this step we maintain a connection between sender system and receiver system which
is called as RFC Destination.

 The Tcode is “SM59”.

BHAVANA Page | 294


SAP ABAP TRAINING
 Provide destination name and connection type.

 Provide client number and save.

BHAVANA Page | 295


SAP ABAP TRAINING
 Activate and click on execute.

4.Define Port:

 Port specifies the medium of transferring the data from one system to another system
 WE21 is the Tcode for defining a Port.

5.Maintain Outbound Partner Profile:

 Here we need to maintain the details of the receiver's system.



 The details are

 1.whom to send (Receiver's name)

 2.what to send (IDOC name)

 3.when to send (Immediately or collect)

 4.How to send (Name of the port)

6.Maintain Distribution Model:

 It contains the list of receivers who receives the data.

BHAVANA Page | 296


SAP ABAP TRAINING
MASTER IDOC:

 It is an internal table which consists of data to be sent from SX system to RX system.


 Suppose we are sending 100 materials from SX to RX, then MASTER IDOC will be
generated for each material. i.e., for 100 materials we get 100 MASTER IDOC’s.

COMMUNICATION IDOC:

 These are the IDOC’s which are derived from MASTER IDOC.

 A COMMUNICATION IDOC is an IDOC which is generated for each receiver.

OUTBOUND PROGRAM:

 A program which is used to start the process of data transfer from SX to RX.

 With the help of selection screen, MASTER IDOC will be generated and then
COMMINICATION IDOC’s will be generated and will be sent to Receiver system.

BHAVANA Page | 297


SAP ABAP TRAINING
PROCESS CODE (OPEN SQL):

 Process code is a function module.

 It is available at receiver side.

 Processing code is responsible for receiving the data from IDOC and updating the data
into data base tables.

MESSAGE TYPE:

 It specifies the type of the application from which IDOC’s are being used. The
application may be material master or customer master and vendor master etc.

 WE81 is Tcode for defining a message type.

 Always IDOC type and Message type should be linked with each other.

 WE82 is Tcode used to create a link between message type and IDOC.

STEPS FOR IDOC AND MESSAGE TYPES

 Define segment -------------------- WE31



 Define IDOC Type -------------------- WE30

 Define message type -------------------- WE81

 Link Message type and IDOC type ------------------- WE82

 Go to WE81.

 Click on new entries

 Provide message type and short text

BHAVANA Page | 298


SAP ABAP TRAINING
 Click on save.

 Go to WE82.

 Click on new entries

 Provide message type, basic type, and release.

 Click on save.

FILTERING:

 Whenever we send the data from source system to receiver’s system, by default all the
IDoc’s and segments are received.

 Suppose if we want to receive only few IDoc’s or segments based on a particular value
which is called as a filter value then it is called as filtering.

BHAVANA Page | 299


SAP ABAP TRAINING
Filtering is of two types:

 IDoc filter: Filtering the unwanted IDOC’S is called IDOC filtering.



 Segment filter: Filtering the unwanted segments in an IDoc is called segment filtering.

CUSTOM IDOC’S
 Custom IDoc’s are generally copied from the standard IDoc by adding OR removing
extra segments.

We have two concepts available under custom IDoc’s.

Extended IDoc Type:

 Ex: IDoc Type = standard IDoc Type + Extra custom segments.


Reduced IDoc Type:

 It is an IDoc which consists of only the required segments and fields.



 All the unwanted segments and filters are completely removed.

 ‘BD53’ is the Tcode for reduced IDoc.

BHAVANA Page | 300


SAP ABAP TRAINING
CHANGE POINTERS
It is a technique of sending required data i.e., materials or customers or vendors which
are changed during a certain period of time is called change pointers.

Steps required for change pointers:


 Activate change pointer centrally BD61 is the TCode.

 Activate change pointer for message type  BD50 is the TCode.

 Activate change pointer for particular fields  BD52 is the TCode.

 Run the TCode BD21 or the program RBDMIDOC.

 NOTE: - The changes are generally stored in 2 tables: CDHDR, CDPOS.

BHAVANA Page | 301


SAP ABAP TRAINING
32. BAPI ((Business Application Programming Interface)
 SAP BAPI is a standard interface to the business object models in SAP products.

 It also a remote enable function module which is used to communicate between SAP-
SAP or SAP-NONSAP servers.

 Basically, BAPI uses RFC Technology.

 In the initial stage it is an RFC Function Module.

 Later, this RFC Function module will be inserted into a business object, now it is
converted into BAPI.

BUSINESS OBJECT REPOSITARY (BOR):

 It is a repository of business objects or container of business objects.

 SWO1 is the Tcode for Business Objects.

BHAVANA Page | 302


SAP ABAP TRAINING
BUSINESS OBJECT (BO):

 It is an object which is similar to class, which is group of attributes methods, interfaces,


key fields, events for a particular Business Application or Scenario.

 SW01 is the TCODE for Business Object Repository.


 Examples for Business objects are,
 BUS1001 – Materials
 BUS2012 – Purchase Order
 BUS1001

Methods are:

o BAPI_Material _Get detail


o BAPI_Material_GETLIST

 BUS2012

Methods are:

o BAPI_PO_GETDETAIL
o BAPI_PO_GETITEMS

BHAVANA Page | 303


SAP ABAP TRAINING
Differences between RFC & BAPI

BAPI RFC
1.used to communicate between SAP- 1.used to communicate between
SAP & NONSAP-SAP. SAP-SAP & NONSAP-SAP.

2. remote enabled FM 2.remote enabled FM

3. BAPIs are part of Business Objects 3. RFCs are called as Standalone


Function Modules.
4.which are used to communicate with 4.This is not possible with RFC’s.
other BAPI’s, events, Interfaces, Because they are standalone FM’S.
attributes, Key fields etc., with in a
single B.O.

USAGE OF BAPI’S:

 BAPI’S are used in 3 scenarios.

1) Report generation using BAPI’S

2) Using standard or custom BAPI to communicate between SAP & NONSAP

3) Using BAPI’s for uploading data into SAP instead of BDC.

RULES FOR BAPI’S:

 Every BAPI should start with BAPI or ZBAPI.


 All the Importing and Exporting parameters should be of Type structures, not the direct
Data Types.
 All the structures must start with BAPI or ZBAPI.

BHAVANA Page | 304


SAP ABAP TRAINING
 All the Parameters must be pass by Value because BAPI’S doesn’t support pass by
reference.
 Every BAPI should have a returning Parameter by Name RETURN or BAPIRET2, to
display success or error messages.
 If BAPI is Success, we have to use another BAPI BAPI_TRANSACTION_COMMIT to
Save the Data into Database Tables.
 If the BAPI has error, use another BAPI BAPI_TRANSACTION_ROLLBACK to revert
back the changes made to the Database Tables.

Report generation using BAPI’S

Reports:

 Develop a Report which displays Material Details


 Develop a Report which displays list of the Materials for a given Range.
 Develop a report which displays PO Details
 Develop a report which displays list of items for a PO.

a) Develop a Custom BAPI to display the Material details

STEP 1:

Create structures for Importing and Exporting Parameters.

 Create a structure in SE11 for importing parameter.

 Select datatype and provide name.

BHAVANA Page | 305


SAP ABAP TRAINING
 Click on create.

 A pop-up will be displayed, select the radio button as structure.

 Click on continue.

 Give short description and create a single field MATNR.

BHAVANA Page | 306


SAP ABAP TRAINING
 Save and activate.

 Go back and create another structure in SE11 for exporting parameter.

 Select datatype and provide name.

 Click on create.

 A pop-up will be displayed, select the radio button as structure.

 Give short description.

 Then mention whatever fields you want to display in bapi output.

BHAVANA Page | 307


SAP ABAP TRAINING
 Save and activate.

STEP2: Create a function module and make it as remote enabled.

 Go to SE37.

 Provide function module name and create.

 Provide function group name and short text

BHAVANA Page | 308


SAP ABAP TRAINING
 Click on save.

 In attributes select the radio button as remote-enabled module.

 Specify importing parameter with pass by value.

 Specify the exporting parameter

BHAVANA Page | 309


SAP ABAP TRAINING
 Return parameter type BAPIRET2.

 Source code

BHAVANA Page | 310


SAP ABAP TRAINING
STEP 3: Create a BO.

 Go to SWO1 and give the BO name as ZYBUS1009


 Click on Create Specify the details as below:

 Click on continue.

STEP 4: insert RFC into BO so that it will be converted into BAPI.

 Put the cursor on methods.

BHAVANA Page | 311


SAP ABAP TRAINING
 Click on Utilities  API-METHODS  ADD METHOD.

 Give the Function Module name as ZBAPI_MATERIAL_DATA.

 Press enter.

BHAVANA Page | 312


SAP ABAP TRAINING
 click on NEXT STEP button

 Again, click on NEXT STEP button


 A pop-up is displayed with below message

 Click on Yes

 Now our RFC is converted into BAPI

BHAVANA Page | 313


SAP ABAP TRAINING
 Click on save.

 Goto edit  Change Release Status  Object Type  Implemented

BHAVANA Page | 314


SAP ABAP TRAINING
 Again, Goto edit  Change Release Status  Object Type  Released

 Now our Business Object is released, and it can be visible/used by NON-SAP System.
 Mapping from NON-SAP fields to BAPI fields will be done by NON-SAP Consultants.
 The Remote connection between SAP and NON-SAP Servers will be done by BASIS
Consultants.
 As an ABAP Consultant, our role is to develop a BAPI and give it to NON-SAP
Consultants.

BHAVANA Page | 315


SAP ABAP TRAINING
a) Develop a program for uploading material master data.

 Go to SE38.

 Provide program name and click on create.

BHAVANA Page | 316


SAP ABAP TRAINING
 Save and activate.

 Execute it.

OUTPUT:

BHAVANA Page | 317


SAP ABAP TRAINING
33. ENHANCEMENTS
 It is a concept by which we add extra code to the standard sap software without
modifying it is called enhancement.
 Each enhancement point is called as exit point.

Types of enhancements

 User exits
 Customer exits
 Badi’s
 Enhancement spots

User exits:
 These are subroutines where we can write our custom code to enhance the application.

 Technically, these are called as modifications.

 We need sap access key for user exits, that is why these are called as modifications.

 These are available only in sd module.


 Each user exit will start with userexit_xxxx.
Ex: - perform userexit_xxxx.
Form userexit_xxxx
End form.

BHAVANA Page | 318


SAP ABAP TRAINING
Customer exit:

 These are zinclude programs which are available inside a fuction module.

 Each function module is called as customer exit.

 Technically these are called as enhancement, we don’t require any access key.

 Customer exits are available in all modules.

 There are four types of customer exits.

 Function module exit


 Menu exit
 Screen exit
 Field exit (absolete now).

Function module exit: -

 This exit is used when we want to write custom coding to enhance the standard sap

application.

 Each function module exit will have a predefined signature i.e importing and exporting

parameters.

 Based upon the importing and exporting parameters write the custom code.

 Each function module exit will have a zinclude.

 Double click and create the zinclude and write your abap code.

BHAVANA Page | 319


SAP ABAP TRAINING
 Each function module exit will start with Exit_xxxx_001.

Menu exit: -

 This exit is used to add custom menus to the standard menu bar.

 Each menu exit is identified by ‘+’ symbol.

 Double click on the ‘+’ symbol and create the custom menu.

 Every menu exit should have a function module exit to add the abap coding for the

custom menu options.

 A menu exit is used to add custom menu and function module exit is use to add the abap

logic for the corresponding menu exit.

Screen exit: -

 This exit is used to add custom sap screen to the standard sap screen is called screen Exit.

 All the screen exits will be of type subscreen.

 Each subscreen is identified by screen no

 Double click on the screen no and create a screen of type subscreen.

 Each screen exit will have a function module exit to write the abap code for the custom

screen.

BHAVANA Page | 320


SAP ABAP TRAINING
Field exit: -

 This is exit is used to change the standard field labels of input fields on sap screen. This

are absolete in sap.

 Sap does not support this.

Project: -

 The project is a group of enhancements.

 Each enhancement is group of exits i.e., Function module exit, screen exit, menu exit.
 A project must be created so that the enhancements which are available under a project
will move into active state and then our coding will be executed.

BHAVANA Page | 321


SAP ABAP TRAINING
Note:
 A project is group of enhancements, but each enhancement cannot be linked to more
than one project.
 CMOD is the transaction to create a project.
 SMOD is the transaction for searching the enhancement exits.
Searching for enhancements or exits

 Basically, we have three ways to search for an exit.

 1. Using call customer function



 2. Using SMOD tcode.

 3. Using se84 tcode.

a) Using call customer function

Steps:

 Go to se93.
 Give the tcode name.

 Click on display
 Double click on the program name.

BHAVANA Page | 322


SAP ABAP TRAINING
BHAVANA Page | 323
SAP ABAP TRAINING
 Click on the find button.

 A pop up is displayed.

 Give the string as call customer, select radio button in main program and press enter.

BHAVANA Page | 324


SAP ABAP TRAINING
 Click on continue.

 Double click on main program name and continue until the call customer functions are

displayed.

BHAVANA Page | 325


SAP ABAP TRAINING
 Double click on 001

BHAVANA Page | 326


SAP ABAP TRAINING
 Again, double click on 001

 The function module exit will display.

BHAVANA Page | 327


SAP ABAP TRAINING
b) Using SMOD transaction

Step1: - First we have to find out the package name for transaction.

 Step2: - Go to smod transaction and find the enhancements using the package name.

BHAVANA Page | 328


SAP ABAP TRAINING
 Step3: - sometimes we can find the enhancements using the description, application

component also in smod transaction.

Step1 in detail:

 Go to se93

 Give a tcode name

 Click on display.

 Note down the package name.

BHAVANA Page | 329


SAP ABAP TRAINING
Step2 in detail

 Go to smod transaction

 Click on utilities  find

 A pop up is displayed.

 Give the package name.

 Click on execute.

 The list of the enhancements will be displayed.

BHAVANA Page | 330


SAP ABAP TRAINING
 Double click on the enhancement name.

 The list of the function module exit, menu exits, screen exits will be displayed.

Using SE84 Tcode

 Go to se84.

 Expand enhancement folder.

 Expand customer exit folder.

BHAVANA Page | 331


SAP ABAP TRAINING
 Double click on enhancements.

 Give the package name

BHAVANA Page | 332


SAP ABAP TRAINING
 Click on execute

 Double click on the enhancement name

BHAVANA Page | 333


SAP ABAP TRAINING
Step3 in detail

Finding enhancements for an exit

 If we use CALL CUSTOMER to search for an exit, we directly get M exit without

enhancement name.

 But if we use SMOD, we get enhancements and then we get EXITS.

 Modsap is the table which will give the enhancement name for an exit.

Steps:

 Go to se11.

 Give the table name as modsap.

 Click on display.

BHAVANA Page | 334


SAP ABAP TRAINING
 Click on table contents.

 Give the member as exit name.

 Click on execute button.

 Enhancement name will be displayed.

BHAVANA Page | 335


SAP ABAP TRAINING
Finding the exact or correct exit

 After finding the list of the enhancements or function module exit, put a break point in all
the function module exit.
 First create project in cmod transaction.

 Put a break point in fm exits.


 Execute the transaction.
 Now you can find easily which is correct exit based on your requirement.

Steps to find user exits

 Go to transaction code va03


 Click on SYSTEM  status.

BHAVANA Page | 336


SAP ABAP TRAINING
 A pop up is displayed.
 Double click on the program name.

BHAVANA Page | 337


SAP ABAP TRAINING
 Click on the find button.

 Give the string as user exit.

 Select the radio button in main program and press enter.

 Give the main program name and press enter.

 Click on continue.

 Double click on perform userexit_save_doccument_prepare.

BHAVANA Page | 338


SAP ABAP TRAINING
 Continue the process until you find out the user exits.

 Ex: - perform userexit_save_doccument_prepare.

 Ex: - perform userexit_save_doccument.

BHAVANA Page | 339


SAP ABAP TRAINING
34. BADI (Business Add-ins)
 It is another way of implementing enhancements to the standard programs without
modifying the original code.
 Badi’s are implemented using oo programming technique
 Technically a badi is nothing but an interface.
 Each badi consists of the method without implementation called as badi definition.
 We need to create classes to write the abap code by implementing the methods called as
badi implementation.
 Se18 is the tcode for badi definition.
 Se19 is the tcode for Badi implementation.
 The interface name for a badi will be as below.
 Ex: - IF_EX_<BADI NAME>
 The class name for a badi will be as below.
 Ex: - ZCL_EX_<IMPLEMENTATION NAME>

Advantages of BADI’S

 The main advantage of using badi’s is, we can create multiple implementations for a
single BADI definition.
 Whereas with the exits, we can create a single implementation.

i.e., A single project for an enhancement.

 We cannot create another project (implementation) for enhancement which is already


used. That is why we go for BADI’s.

BHAVANA Page | 340


SAP ABAP TRAINING
Types of BADI’S

1. Single implementation Badi.


2. Multiple implementation Badi.
3. Filter Badi.
4. Custom Badi (Not used/Rarely used)

1. Single implementation Badi: -

 A Badi which has only one implementation (single class) is called single implementation
Badi.

2. Multiple implementation Badi: -

 A BADI which has multiple implementations is called multiple implementation Badi.


 By default, all the implementations will be executed.
 We cannot control the sequence of execution of multiple implementations

3.Filter Badi: -

 It is type of Badi which has a filter value so that only those implementations which
satisfy the filter value are executed.
 The remaining implementations are not executed this type of Badi is called a filter Badi.
 The filter value will be DE generally.
 Examples of filter values are land1, bukrs, werks

BHAVANA Page | 341


SAP ABAP TRAINING
Properties of BADI’S

 If WITH IN SAP checkbox is selected, then this badi is only used by sap.
 If multiple use checkbox is selected, then it is a multiple implementation badi.
 If multiple use checkbox is not selected, then it is a single implementation badi.
 If filter dependent checkbox is selected, then it is filter dependent badi.
 We need to specify the filter type such as land1, bukrs,werks.for the filter badi.

Finding the badi for a TCODE.

There are 2 ways for finding a BADI.

 Using class CL_EXITHANDLER


 Using SE84 Tcode

a) Using CL_EXITHANDLER

CL_EXITHANDLER is the class and GET_INSTANCE is the method to find the list of
the badi’s for transaction.

Steps:

 Go to se24.

BHAVANA Page | 342


SAP ABAP TRAINING
 Give the class name as CL_EXITHANDLER.

 Click on display.

 Double click on the method GET_INSTANCE and Put a break point on the below
method GET_CLASS_NAME_BY_INTERFACE.

BHAVANA Page | 343


SAP ABAP TRAINING
 Click on execute.

BHAVANA Page | 344


SAP ABAP TRAINING
b) Using SE84 Tcode

Steps

 Find the package name for a transaction code


 Go to se84.
 Expand enhancement folder.

 Expand business add ins folder.

 Double click on the definition.


 Give the package name.

BHAVANA Page | 345


SAP ABAP TRAINING
 Click on execute.

 The list of badi’s is displayed.

BHAVANA Page | 346


SAP ABAP TRAINING
35. SMARTFORMS
 Smart form is a GUI Tool which is used to design the business legal documents such as

Delivery note,Purchase order,Invoice etc.

 The transcation code is SMARTFORMS

 Smartforms are client independent

 It is advanced version of scripts

 It is basically a GUI tool for user friendly maintenance

SAP Smart Forms – Architecture

BHAVANA Page | 347


SAP ABAP TRAINING
Differences b/w scripts & smartforms

SAP SCRIPTS SAP SMARTFORMS

1. Sapscripts are client dependent. 1. Smartforms are client independent.

2. Main window is compulsary 2. Main window is not compulsary.

3. No function module will be generated. 3. Smartforms generates a function module


when activated.
4. Sapscripts allows only black and white 4. Smartforms texts can be written in
texts. various colors.
5. Sapscripts has repeated transfer of 5. There is no transfer of control b/w
control. program and form in smartforms. Once the
control is transferred to FMOD, it will not
come back to driver program.
6. Only single page format is possible. 6. Multiple page formats are possible.

7. Windows are: main, var, grapical 7. Windows are: main, secondary, copies
windows in sapscripts. and final windows in smartforms.

FINDING SMARTFORM FUN.MOD NAME

 WHY SMARTFORMS ARE CLIENT INDEPENDENT?

 Whenever a smartform is activated a function module will be generated which

contains the entire source code of the smartform.

BHAVANA Page | 348


SAP ABAP TRAINING
 Since function modules are client independent ,SAP Smartforms are also client

independent.

HOW DO YOU FIND SMARTFORM FUN.MOD NAME STATICALLY?

 Create a Smartform.

BHAVANA Page | 349


SAP ABAP TRAINING
 Save and activate.

 Click on Environment  Function module name.

HOW DO YOU FIND SMARTFORM FUN.MOD NAME DYNAMICALLY FROM


PROGRAM?

 USING FM: SSF_FUNCTION_MODULE_NAME

It is a function module which is used to find out the dynamically generated fuction
module of a smartform.

SMART STYLES

 These are used to create the paragraph formats and character formats

 The main advantage of using smartstyles is ‘REUSABILITY’

BHAVANA Page | 350


SAP ABAP TRAINING
 That means, once you create a smartstyle, we can reuse the same
 Smartstyle in multiple smartforms.
 The Tcode is SMARTSTYLES.

COMPONENTS OF SMARTFORMS

There are two main nodes in Smartforms.


1.Global Settings
 Form Attribute
 Form Interface
 Global Definition
2.Pages and Windows
1. Global settings:

 It is used to provide the basic settings for the smartform.


 Form Attributes: It specifies the general attributes like who created, Date, time,
package, translate options, default smartstyle, Page format (DINA4/DINA5)
 Form interface: it acts as a mediator between a driver program and a smart form.
 The main functionality of form interface is it will import the parameters which are
exported by driver program.
 The parameters can be variables, work areas, internal tables etc.
 Global definition: it will contain the variables to be used within the smart form.
 We can define variables, user defined data types, field symbols, initialization code,
Subroutine, currency/quantity fields.
 It is mainly used for declaring or defining the above variables.

BHAVANA Page | 351


SAP ABAP TRAINING
2. Pages and Windows

 page

 Window

 Graphic

Address

Text

Table

-- Header

-- Body

-- Footer

 Template

 Folder

 Program Line

 Alternative

 Command

 Loop

BHAVANA Page | 352


SAP ABAP TRAINING
Pages and windows

 This will contain all the pages and the windows, which are used in the smartform.

 By default, a page will be created by name %page1.

 By default, a window will be created by name ‘MAIN’ under the page1.

 For each page, we need to specify the next page

 E.g.: page = %page1

 Next page = %page1 or %page2

Nodes under pages

 Page: It is used to define the layout of a smartform.

 We can have different pages with different layouts.

 Window: it is used to display information or text at a particular place on a page.

 Graphic: it is used to display logos or images on the smartforms.

 Address: it is used to display the address of customer or vendor or employee,

organization address, workplace address etc.

 Just provide address no, it will automatically display the address as per the country

formats.

BHAVANA Page | 353


SAP ABAP TRAINING
Nodes under the window

Text: it is used to display the information or text in a window.

Table: it is used to display the information in the form of table.

 Whenever we create table by default HEADER, MAIN AREA, FOOTER will be

displayed.

 The main functionality of a table is it expands automatically depending on the internal

table data.

 We need to provide the name of the internal table for a table.

Template: template is also like a table which does not expand. That means it will have

fixed number of rows and columns.

Program lines: it is used to write some lines of abap code.

Alternative: it is used to provide alternative conditions like true or false.

 It is like IF…. ELSE……ENDIF in abap.

Loop: it is used to loop an internal table.

Command: it is used to trigger an external event to call a new page.

Folder: it is a container which is used to group all the sub nodes. it is like a folder in

normal language.

BHAVANA Page | 354


SAP ABAP TRAINING
Window Types
Various window types

 Main window: For continuous output


 Secondary window: For output with a fixed length
 Final window: Special type of secondary window for outputting the information
that is not known until the end of form processing
 Copies window: Special type of secondary window for marking pages as copy or
original.

BHAVANA Page | 355


SAP ABAP TRAINING
Steps To Create SmartForm

 Goto ‘SMARTFORMS’ Tcode.

 Give the form name as ‘ZSB_SMARTFORMS’.

 Click on Create.

 Expand global setting

 Form attributes

BHAVANA Page | 356


SAP ABAP TRAINING
BHAVANA Page | 357
SAP ABAP TRAINING
 Form interface

BHAVANA Page | 358


SAP ABAP TRAINING
 Global definitions

BHAVANA Page | 359


SAP ABAP TRAINING
 Save and activate.

 Expand Pages and Windows

BHAVANA Page | 360


SAP ABAP TRAINING
 Right click on the main window  create  Table

 In table click on pencil icon and draw 6 columns in first row (%LTYPE1).

BHAVANA Page | 361


SAP ABAP TRAINING
 Right click on header  create  table line

 Mention line type as %LTYPE1.

BHAVANA Page | 362


SAP ABAP TRAINING
 Then all the 6 columns are automatically assigned for it.

 Rename each cell

BHAVANA Page | 363


SAP ABAP TRAINING
BHAVANA Page | 364
SAP ABAP TRAINING
BHAVANA Page | 365
SAP ABAP TRAINING
 Right click on VBELN new column 1  create  Text.

 So, a text element will be triggered.

 Double click on the output options.

BHAVANA Page | 366


SAP ABAP TRAINING
 Click on general attributes. It will open Microsoft window screen.

 Click on to text editor

 It will navigate to another screen.

BHAVANA Page | 367


SAP ABAP TRAINING
 Click on goto  change editor.

BHAVANA Page | 368


SAP ABAP TRAINING
 Give field name.

 Go back. Below screen will display.

 Right click on main area  create  table line.

 Mention line type as %LTYPE1.

BHAVANA Page | 369


SAP ABAP TRAINING
 Then all the 6 columns are automatically assigned for it.

BHAVANA Page | 370


SAP ABAP TRAINING
 Right click on VBELN new column 1  create  Text.

BHAVANA Page | 371


SAP ABAP TRAINING
 So, a text element will be triggered.

 Double click on the output options.

 Click on general attributes. It will open Microsoft window screen.

BHAVANA Page | 372


SAP ABAP TRAINING
 Click on to text editor

 It will navigate to another screen.

BHAVANA Page | 373


SAP ABAP TRAINING
 Click on goto  change editor.

 Give field name.

 Go back.

 If you click on to Table1 new table 1, you can see the data

BHAVANA Page | 374


SAP ABAP TRAINING
 Save and activate.

 Click on test (execute)

 It automatically open function module

 Execute it.

BHAVANA Page | 375


SAP ABAP TRAINING
 Again click on execute

 Click on print preview.

BHAVANA Page | 376


SAP ABAP TRAINING
BHAVANA Page | 377
SAP ABAP TRAINING
 Go back

 Click on table1 new table 1  table

 Select %LINE1 and Give borders

 Save and activate

 Test it

 Click on execute

BHAVANA Page | 378


SAP ABAP TRAINING
 Click on print preview

BHAVANA Page | 379


SAP ABAP TRAINING
BHAVANA Page | 380
SAP ABAP TRAINING
 Click on table1 new table 1  data

 Select upto 10 rows

 Save and activate

 Right click on %page1 new page  create  graphic

 Graphic1 is created. Give name, object, ID and resoultion.

 Save and activate.

BHAVANA Page | 381


SAP ABAP TRAINING
 Go to Tcode SE78 for upload the logo.

 Expand GRAPHICS general graphics

 Double click BMAP bitmap images

 Click on to print preview

 Import a logo

BHAVANA Page | 382


SAP ABAP TRAINING
 Select the file name and provide description.

 Click on continue

 Now go back to Smartforms Graphics window

 Save and activate

BHAVANA Page | 383


SAP ABAP TRAINING
 Test it

 Execute it

BHAVANA Page | 384


SAP ABAP TRAINING
 Click on print preview.

BHAVANA Page | 385


SAP ABAP TRAINING
36. Batch Data Communication
 It is the technique of transferring in data from legacy system (NON-SAP) to SAP is

called BDC.

 There are two techniques available for transferring data.

 Outbound process

 Inbound process

OUTBOUND PROCESS:

The process of transferring the data from SAP to NON-SAP or another SAP server is

called “Outbound Process”.

Legacy system-> extract -> flat file -> upload -> itab sap server

BHAVANA Page | 386


SAP ABAP TRAINING
INBOUND PROCESS:

 The process of receiving the data from NON-SAP to SAP server is called as “Inbound

Process”.

 BDC is an “Inbound Process”.

DIFFERENT METHODS OF BDC:

 Call transaction (Screen Level Processing)

 Session method (Screen Level Processing)

 Direct input method-> (Standard SAP Programs)

 LSMW -> (A tool)

 BAPI method -> (Advanced Technique, which is very Good)

BHAVANA Page | 387


SAP ABAP TRAINING
CALL TRANSACTION METHOD:

 It is the process of transferring the data from flat file into SAP by calling a transaction

through a series of sequence of steps.

 Properties:

 This method is used for transferring less amount of data (<10,000 records).

 This method uses Synchronous and Asynchronous updates.

 This method will update the DB immediately.

 We need to handle the errors and the success messages by declaring an internal

table of type BDCMSGCOLL.

 This method is very fast.

Syntax:

 Call Transaction <Tcode>

 Using <BDC DATA>

 UPDATE <A/S>

 MODE <A/E/N>

 MESSAGES INTO <Message Internal Table>

BHAVANA Page | 388


SAP ABAP TRAINING
BDC Data:

 It is a structure defined in a data dictionary with the below fields.

 Program -> Name of the program of a screen

 Dynpro -> Screen number

 Dynbegin -> Start the Process

 Fnam -> Field name on the SAP screen

 Fval -> Field value on to the field name of SAP screen

USE OF BDC DATA:

 It is a structure which holds the information related to each screen i.e., program name,

screen no, field name, field values, information of that particular screen to be transferred

into the SAP.

 In simple words, it holds all the screen related information and field information to be

transferred into corresponding SAP transaction.

BHAVANA Page | 389


SAP ABAP TRAINING
Program Dynpro Dynbegin Fnam Fval

SAPLGMM 0060 ‘X’

RMMG1-MATNR ‘1011’

RMMG1-MBRSH ‘FOOD’

RMMG1-MTART ‘FERT’

SAPLGMM 0070 ‘X’

RZSEL ‘X’

- - - - -

- - - - -

 To find the above information for each field, press F1 on particular field

 It will display help information.

 Click on the button “technical information”

 It will show the entire technical information of a screen.

 Please note down the program name, screen number, screen field name.

BHAVANA Page | 390


SAP ABAP TRAINING
 This procedure has to be repeated for each field on a SAP screen.

 Since, it is very difficult to note down the technical information for each field, we have

an alternate and easy method called as “RECORDING METHOD”.

Update: There are two types of updates are available.

 Asynchronous update (COMMIT)

 Synchronous update (COMMIT & WAIT)

DIAL0G WORK PROCESS: A work process which is dedicated to process screen

information is called “Dialog work process”.

 There will be 6 to 7 dialog work processes.

 These dialog work processes are defined by basis consultant.

UPDATE WORK PROCESS: This work process is responsible for updating the data into the

database.

 There will be always only ‘1’ update work process.

BHAVANA Page | 391


SAP ABAP TRAINING
ASYNCHRONOUS UPDATE (COMMIT):

 In this type of the call transaction screens will communicate with the update work process

to update the data into database.

 It doesn’t wait for the update to be finished.

 It immediately starts to process the next record without waiting for the update to be

finished.

 That’s why this process is very fast.

 It is generally not recommended for the large amount of data, because the called

transaction doesn’t return any success or error messages.

SYNCHRONOUS UPDATE (COMMIT & WAIT):

 In this mode, the called transaction communicates with the update work process to update

the data into database.

 It will wait for the update to be finished.

 Once the update is finished, then it continues to process the next record.

 That’s why this process is very slow.

 It is generally recommended for large amount of data because it returns success and error

messages.

BHAVANA Page | 392


SAP ABAP TRAINING
MODE:

 It specifies the type of the mode to execute the transaction.

 There are 3 options for mode

__________________________________________________________

MODE DESCRIPTION

___________________________________________________________

A All-screen mode (Foreground)

E Error screen mode (only error screens will be displayed)

N No screen mode (Background)

MESSAGES:

 In the called transaction, we need to handle the messages by declaring an internal table of

type BDCMSGCOLL.

 All the messages will be stored in the above internal table.

BHAVANA Page | 393


SAP ABAP TRAINING
The structure of BDCMSGCOLL is as below:

 MSGTYP Message type (E-error, S-success W –Warning etc.)

 MSGID Message ID

 MSGNR Message number

 MSGV1 Variable part of a message

 MSGV2 Variable part of a message

 MSGV3 Variable part of a message

 MSGV4 Variable part of a message

 The variable BDCMSGCOLL – MSGV1 will contain the created material number or

vendor number whenever the message type is success (S).

 Whenever the message type is error, we need to use the function module

FORMAT_MESSAGE to display the meaningful message.

RECORDING METHOD:

 Since, it is very difficult to find technical information of each field on the screen, we go
for a method called as “Recording method”.
 The recording method is going to record all the fields in the transaction, and it generated
the technical information such as program name, screen no, field name, field value for
each field on the SAP screen.

BHAVANA Page | 394


SAP ABAP TRAINING
 By using the recording method, it is very easy to create a BDC program.

Steps:

 Go to Tcode SHDB.
 Click on new recording.

 Provide recording name and transaction code

BHAVANA Page | 395


SAP ABAP TRAINING
 Click on start recording.

 Create material  give material name, industry sector and material type.

 Click on enter

 Select view as basic data 1

BHAVANA Page | 396


SAP ABAP TRAINING
 Click on continue.

 Give description and select base unit of measure as PC

 Save it

BHAVANA Page | 397


SAP ABAP TRAINING
 Again, save it.

 Recording is created successfully.

BHAVANA Page | 398


SAP ABAP TRAINING
 Select the record name

 Click create program

 Provide program name

 Select second radio button (transfer from recording)

BHAVANA Page | 399


SAP ABAP TRAINING
 Click on continue.

 Give title and type as executable program.

 Click on source code. Save in package

BHAVANA Page | 400


SAP ABAP TRAINING
 Source code for recording

BHAVANA Page | 401


SAP ABAP TRAINING
Using call transaction method:

 Go to se38

 Program name ZSB_BDC_CALL_TRANSACTION

 Click on create

 Source code for main program

Code for Call Transaction:

REPORT ZSB_BDC_CALL_TRANSACTION.

TYPES:BEGIN OF ty_final,

matnr TYPE matnr,

mbrsh TYPE mbrsh,

mtart TYPE mtart,

maktx TYPE maktx,

meins TYPE meins,

END OF ty_final,

BEGIN OF ty_output,

text(200) TYPE c,

BHAVANA Page | 402


SAP ABAP TRAINING
END OF ty_output.

DATA:gt_final TYPE TABLE OF ty_final,

gs_final TYPE ty_final,

gv_path TYPE rlgrap-filename,

gt_raw TYPE truxs_t_text_data,

gt_mess TYPE TABLE OF bdcmsgcoll,

gs_mess TYPE bdcmsgcoll,

gt_output TYPE TABLE OF ty_output,

gs_output TYPE ty_output,

bdcdata LIKE bdcdata OCCURS 0 WITH HEADER LINE,

nodata TYPE c.

PARAMETERS: p_path TYPE ibipparms-path.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_path.

CALL FUNCTION 'F4_FILENAME'

* EXPORTING

* PROGRAM_NAME = SYST-CPROG

BHAVANA Page | 403


SAP ABAP TRAINING
* DYNPRO_NUMBER = SYST-DYNNR

* FIELD_NAME =''

IMPORTING

file_name = p_path.

START-OF-SELECTION.

gv_path = p_path.

CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'

EXPORTING

* I_FIELD_SEPERATOR =

i_line_header = 'X'

i_tab_raw_data = gt_raw

i_filename = gv_path

TABLES

i_tab_converted_data = gt_final

EXCEPTIONS

conversion_failed =1

OTHERS = 2.

BHAVANA Page | 404


SAP ABAP TRAINING
IF sy-subrc <> 0.

* Implement suitable error handling here

ENDIF.

LOOP AT gt_final INTO gs_final.

PERFORM bdc_dynpro USING 'SAPLMGMM' '0060'.

PERFORM bdc_field USING 'BDC_CURSOR'

'RMMG1-MTART'.

PERFORM bdc_field USING 'BDC_OKCODE'

'=ENTR'.

PERFORM bdc_field USING 'RMMG1-MATNR'

gs_final-matnr.

PERFORM bdc_field USING 'RMMG1-MBRSH'

gs_Final-mbrsh.

PERFORM bdc_field USING 'RMMG1-MTART'

gs_Final-mtart.

PERFORM bdc_dynpro USING 'SAPLMGMM' '0070'.

PERFORM bdc_field USING 'BDC_CURSOR'

BHAVANA Page | 405


SAP ABAP TRAINING
'MSICHTAUSW-DYTXT(01)'.

PERFORM bdc_field USING 'BDC_OKCODE'

'=ENTR'.

PERFORM bdc_field USING 'MSICHTAUSW-KZSEL(01)'

'X'.

PERFORM bdc_dynpro USING 'SAPLMGMM' '4004'.

PERFORM bdc_field USING 'BDC_OKCODE'

'/00'.

PERFORM bdc_field USING 'MAKT-MAKTX'

gs_Final-maktx.

PERFORM bdc_field USING 'BDC_CURSOR'

'MARA-MEINS'.

PERFORM bdc_field USING 'MARA-MEINS'

gs_final-meins.

PERFORM bdc_field USING 'MARA-MTPOS_MARA'

'NORM'.

PERFORM bdc_dynpro USING 'SAPLSPO1' '0300'.

PERFORM bdc_field USING 'BDC_OKCODE'

BHAVANA Page | 406


SAP ABAP TRAINING
'=YES'.

CALL TRANSACTION 'MM01' USING bdcdata

UPDATE 'S' MODE 'A' MESSAGES INTO gt_mess.

CLEAR gs_final.

ENDLOOP.

LOOP AT gt_mess INTO gs_mess.

CALL FUNCTION 'FORMAT_MESSAGE'

EXPORTING

id = gs_mess-msgid

lang = sy-langu

no = gs_mess-msgnr

v1 = gs_mess-msgv1

v2 = gs_mess-msgv2

v3 = gs_mess-msgv3

v4 = gs_mess-msgv4

IMPORTING

msg = gs_output-text

BHAVANA Page | 407


SAP ABAP TRAINING
EXCEPTIONS

not_found = 1

OTHERS = 2.

IF sy-subrc <> 0.

* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

APPEND gs_output TO gt_output.

CLEAR:gs_output, gs_mess.

ENDLOOP.

LOOP AT gt_output INTO gs_output.

WRITE:/ gs_output-text.

ENDLOOP.

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

*& Form BDC_DYNPRO

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

BHAVANA Page | 408


SAP ABAP TRAINING
* text

*----------------------------------------------------------------------*

* -->PROGRAM text

* -->DYNPRO text

*----------------------------------------------------------------------*

FORM bdc_dynpro USING program dynpro.

CLEAR bdcdata.

bdcdata-program = program.

bdcdata-dynpro = dynpro.

bdcdata-dynbegin = 'X'.

APPEND bdcdata.

ENDFORM. "BDC_DYNPRO

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

*& Form BDC_FIELD

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

* text

*----------------------------------------------------------------------*

BHAVANA Page | 409


SAP ABAP TRAINING
* -->FNAM text

* -->FVAL text

*----------------------------------------------------------------------*

FORM bdc_field USING fnam fval.

IF fval <> nodata.

CLEAR bdcdata.

bdcdata-fnam = fnam.

bdcdata-fval = fval.

APPEND bdcdata.

ENDIF.

ENDFORM.

 Save and activate

 Execute it and select the file path

BHAVANA Page | 410


SAP ABAP TRAINING
 Click on execute.

 To check if the created material exists

 Go to se16n

 Give table name as MARA and click on enter

 In selection criterial, give the created material name (Ex: M123)

 Execute it

 M123

BHAVANA Page | 411


SAP ABAP TRAINING
 E124

BHAVANA Page | 412


SAP ABAP TRAINING
 S125

BHAVANA Page | 413


SAP ABAP TRAINING
37. SESSION METHOD
SESSION METHOD:

 This method is used to transfer large amount of data (e.g.: >10,000 to 10 lakhs)

 It is basically a 2-step process

 Create a session

 Process a session

Session: A session contains a group of records, which have to be transferred into SAP.

 To create a session, we use the below function modules.

 BDC_Opengroup

 BDC_Insert

 BDC_Closegroup

BDC OPENGROUP: This function module is used to create a session with the below

parameters.

 client no = client no

 username = username

 group name = Session Name

BHAVANA Page | 414


SAP ABAP TRAINING
 Keep = ’X’

 hold Date = session is locked until the specified date

 Keep = ‘X’, specifies the session to be available in the session queue for processing at a

later point of time.

 Just call the function module and provide the above parameters.

 The session will be created

BDC_INSERT:

 This function module is used to transfer the data from BDCDATA structure into the

session.

 Just call the function module and provide the transaction code name and BDCDATA

internal table name.

BDC_CLOSEGROUP:

 This function module is used to close the session which is created by function module

BDC_OPENGROUP.

 Once the session is created, we need to process the session.

BHAVANA Page | 415


SAP ABAP TRAINING
Processing the session:

 SM35 is the transaction code for processing the session.

 Go to SM35

 Select the session name. e.g.: ZSESS1

 Click on process button.

 Select either foreground or background or error mode, click on the process button.

 The session will be processed.

Status of session:

 To know the status or to know how many records are successfully processed, follow the

below steps.

 select the session name. e.g.: ZSESS1

 click on the button Analysis

 click on the tap Log.

 it will clearly display all the messages whether each record is successful or error with

clear meaningful messages.

BHAVANA Page | 416


SAP ABAP TRAINING
Difference between call transaction and Session method

Steps:

 Go to code SE38

 Provide program name

BHAVANA Page | 417


SAP ABAP TRAINING
 Click on to create.

 Provide title name and select type as executable program

 Save it in package

REPORT ZSB_BDC_SESSION_METHOD.

TYPES:BEGIN OF ty_final,
matnr TYPE matnr,
mbrsh TYPE mbrsh,
mtart TYPE mtart,
maktx TYPE maktx,
meins TYPE meins,
END OF ty_final,
BEGIN OF ty_output,
text(200) TYPE c,
END OF ty_output.

DATA:gt_final TYPE TABLE OF ty_final,


gs_final TYPE ty_final,
gv_path TYPE rlgrap-filename,
gt_raw TYPE truxs_t_text_data,
gt_mess TYPE TABLE OF bdcmsgcoll,
gs_mess TYPE bdcmsgcoll,
gt_output TYPE TABLE OF ty_output,

BHAVANA Page | 418


SAP ABAP TRAINING
gs_output TYPE ty_output,
bdcdata LIKE bdcdata OCCURS 0 WITH HEADER LINE,
nodata TYPE c.

PARAMETERS: p_path TYPE ibipparms-path.


AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_path.
CALL FUNCTION 'F4_FILENAME'
* EXPORTING
* PROGRAM_NAME = SYST-CPROG
* DYNPRO_NUMBER = SYST-DYNNR
* FIELD_NAME =''
IMPORTING
file_name = p_path.

START-OF-SELECTION.
gv_path = p_path.
CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'
EXPORTING
* I_FIELD_SEPERATOR =
i_line_header = 'X'
i_tab_raw_data = gt_raw
i_filename = gv_path
TABLES
i_tab_converted_data = gt_final

BHAVANA Page | 419


SAP ABAP TRAINING
EXCEPTIONS
conversion_failed =1
OTHERS = 2.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.
*********************************
CALL FUNCTION 'BDC_OPEN_GROUP'
EXPORTING
client = sy-mandt
group = 'ZSBSESSION'
keep = 'X'
user = sy-uname.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.

LOOP AT gt_final INTO gs_final.


PERFORM bdc_dynpro USING 'SAPLMGMM' '0060'.
PERFORM bdc_field USING 'BDC_CURSOR'
'RMMG1-MTART'.
PERFORM bdc_field USING 'BDC_OKCODE'
'=ENTR'.
PERFORM bdc_field USING 'RMMG1-MATNR'

BHAVANA Page | 420


SAP ABAP TRAINING
gs_final-matnr.
PERFORM bdc_field USING 'RMMG1-MBRSH'
gs_Final-mbrsh.
PERFORM bdc_field USING 'RMMG1-MTART'
gs_Final-mtart.
PERFORM bdc_dynpro USING 'SAPLMGMM' '0070'.
PERFORM bdc_field USING 'BDC_CURSOR'
'MSICHTAUSW-DYTXT(01)'.
PERFORM bdc_field USING 'BDC_OKCODE'
'=ENTR'.
PERFORM bdc_field USING 'MSICHTAUSW-KZSEL(01)'
'X'.
PERFORM bdc_dynpro USING 'SAPLMGMM' '4004'.
PERFORM bdc_field USING 'BDC_OKCODE'
'/00'.
PERFORM bdc_field USING 'MAKT-MAKTX'
gs_Final-maktx.
PERFORM bdc_field USING 'BDC_CURSOR'
'MARA-MEINS'.
PERFORM bdc_field USING 'MARA-MEINS'
gs_final-meins.
PERFORM bdc_field USING 'MARA-MTPOS_MARA'
'NORM'.
PERFORM bdc_dynpro USING 'SAPLSPO1' '0300'.

BHAVANA Page | 421


SAP ABAP TRAINING
PERFORM bdc_field USING 'BDC_OKCODE'
'=YES'.
CALL FUNCTION 'BDC_INSERT'
EXPORTING
tcode = 'MM01'
TABLES
dynprotab = bdcdata
EXCEPTIONS
internal_error = 1
not_open =2
queue_error =3
tcode_invalid =4
printing_invalid = 5
posting_invalid = 6
OTHERS = 7.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.

CLEAR gs_final.
REFRESH bdcdata.
CLEAR bdcdata.

ENDLOOP.

BHAVANA Page | 422


SAP ABAP TRAINING
CALL FUNCTION 'BDC_CLOSE_GROUP'
* EXCEPTIONS
* NOT_OPEN =1
* QUEUE_ERROR =2
* OTHERS =3
.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.

WRITE : 'session is successfully created and closed'.

**********************************************
*&---------------------------------------------------------------------*
*& Form BDC_DYNPRO
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->PROGRAM text
* -->DYNPRO text
*----------------------------------------------------------------------*
FORM bdc_dynpro USING program dynpro.
CLEAR bdcdata.

BHAVANA Page | 423


SAP ABAP TRAINING
bdcdata-program = program.
bdcdata-dynpro = dynpro.
bdcdata-dynbegin = 'X'.
APPEND bdcdata.
ENDFORM. "BDC_DYNPRO

*&---------------------------------------------------------------------*
*& Form BDC_FIELD
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->FNAM text
* -->FVAL text
*----------------------------------------------------------------------*
FORM bdc_field USING fnam fval.
IF fval <> nodata.
CLEAR bdcdata.
bdcdata-fnam = fnam.
bdcdata-fval = fval.
APPEND bdcdata.

ENDIF.
ENDFORM.

BHAVANA Page | 424


SAP ABAP TRAINING
 Save and activate

 Execute it

 Provide file path

 Execute

UNIT TESTING:

After executing the program

 Goto SM35

 Select on session name (ZSBSESSION)

BHAVANA Page | 425


SAP ABAP TRAINING
 Click on process

 In processing mode select third radio button (background)

 Click on process

 Go back & Click on execute

BHAVANA Page | 426


SAP ABAP TRAINING
 Double click on processing button

BHAVANA Page | 427


SAP ABAP TRAINING
38. LSMW METHOD

LSMW: LEGACY SYSTEM MIGRATION WORKBENCH

 LSMW is used to upload the data from file to SAP system.

LSMW

 It is a SAP tool which is used to transfer the data from legacy system to SAP.

 It is mainly used to transfer very less amount of data. (<5000)

 LSMW contains very little coding

 It is mainly designed for consultants who doesn’t have any programming language. i.e.,

functional consultants.

 At the time of creating the LSMW we need to provide project (Module name), sub

project (application), object (task).

 The transaction code for LSMW is ‘LSMW’.

BHAVANA Page | 428


SAP ABAP TRAINING
 There are 4 methods available in LSMW.
 Direct input method
 Recording method
 BAPI method
 ALE/IDOC method.
 LSMW is a more user-friendly tool, through which one can do the same work as the
BDC. One just has to follow the 14 steps.
 BDC is basically a program which is either generated by SAP after a recording or
programmed by an abaper. It’s like running the transaction manually but all the data is
populated in the screens automatically.
 LSMW provides various methods for migration of data, namely those of direct input,
batch input recording and IDOC. BDC however simply makes use of recording. There
are 2 ways of implementing BDC, the call transaction method and the session method.
 In LSMW, mapping is taken care of with the help of SAP, where as in BDC one has to
provide explicit mapping directions.
 In BDC, we can schedule the job, so the uploading can be done at the same time or later
periodically while in LSMW. It has to be done at once only. So, through LSMW, one
can’t upload large amount of data. Hence, we use LSMW for updating or inserting below
5000 records and we use BDC to upload records more than 5000.

BHAVANA Page | 429


SAP ABAP TRAINING
Steps to work with LSMW:
 Execute Transaction code LSMW.

 Provide the project name (ZSB_LSMW)

 Click on create in the application tool bar.


 Provide short description of project.

 Enter.

BHAVANA Page | 430


SAP ABAP TRAINING
 Provide sub project name (ZSB_LSMW_MM01)
 Provide short description of sub project.

 Enter.
 Provide object name (ZSB_LSMW_MM01_OBJ).
 Provide short description of object.

 Enter.

 Click on execute.

BHAVANA Page | 431


SAP ABAP TRAINING
 Go to user menu

 Select the check boxes of process steps we use

BHAVANA Page | 432


SAP ABAP TRAINING
 Click on continue
 Give numbering

STEP1: Define object attributes


 Select define object attributes

 Click on execute (Ctrl + F8).

BHAVANA Page | 433


SAP ABAP TRAINING
 Click on change mode.

BHAVANA Page | 434


SAP ABAP TRAINING
 Select the radio button Batch Input Recording.

 Click on over view icon in the right side.

BHAVANA Page | 435


SAP ABAP TRAINING
 Place the cursor on recordings.

 Click on create recording.

 Provide the recording name(ZSB_REC_MM01) & short description.

 Enter.
 Provide the transaction code (mm01).

 Enter.
 Provide the material name (MATERIAL2), choose industry sector
(MECHANICAL ENGINEERING) and give material type (COUPONS).

BHAVANA Page | 436


SAP ABAP TRAINING
 Click on enter.
 Select the view as Basic Data 1

 Click on continue.
 Give description

BHAVANA Page | 437


SAP ABAP TRAINING
 Provide Basic Unit of Measure as PC

 Click on save

BHAVANA Page | 438


SAP ABAP TRAINING
 Click on default all in the application tool bar.

BHAVANA Page | 439


SAP ABAP TRAINING
 Save.
 Back, come back.

 Provide the recording name (ZSB_REC_MM01).

BHAVANA Page | 440


SAP ABAP TRAINING
 Save, back.
 It will automatically go to second step.

STEP 2: Define source structures


 Select step 2 and Click on execute.

 Click on change mode.

 Place the cursor on source structure.


 Click on create structure.

 Provide source structure is internal table name and provideshort description.

BHAVANA Page | 441


SAP ABAP TRAINING
 Enter.

 Save, back.

STEP 3: Define source fields


 Select on step 3 and Click on execute.

 Click on change mode.

BHAVANA Page | 442


SAP ABAP TRAINING
 Place the cursor on internal table name
 Click on change mode.
 Click on table Maintenance icon in the application tool bar.
 Provide field names. (Data types & lengths which is similar as file).

 Save, back.

BHAVANA Page | 443


SAP ABAP TRAINING
 Save, back.

STEP 4: Define structure relations


 Select step 4 & Click on execute

 Click on change mode.


 Save, back.

STEP 5: Main field mapping and conversion rules


 Select step5 & Click on execute.

BHAVANA Page | 444


SAP ABAP TRAINING
 Click on change mode.

 Select each field.


 If the field is coming from flat file, then click on source field.
 Otherwise click on rule in the application tool bar.
 Select the radio button constant.
 Enter.
 Provide the constant value.

BHAVANA Page | 445


SAP ABAP TRAINING
 Save, back.

BHAVANA Page | 446


SAP ABAP TRAINING
STEP 6: Specify files

 Select step 6 and Click on execute.

 Click on change mode.

 Select the legacy data on the PC (Frontend).

 Click on create or adding on top.

BHAVANA Page | 447


SAP ABAP TRAINING
 Browse the filename.

 Provide short description.

 Select the delimiter is tabulator.

BHAVANA Page | 448


SAP ABAP TRAINING
 Click on continue.

 Save, back.
STEP 7: Assign files
 Select step 7 and Click on execute.

BHAVANA Page | 449


SAP ABAP TRAINING
 Click on change mode.

 Save, back.

STEP 8: Read data


 Click on execute.
 Click on execute.
 Back, click on back.
STEP 9: Display read data

BHAVANA Page | 450


SAP ABAP TRAINING
 Click on execute.
 Enter.
 Click on back.
STEP 10: Convert data
 Click on execute.
 Click on execute.
 Back, click on back.
STEP 11: Display converted data
 Click on execute.
 Enter.
 Back.
STEP 12: Create batch input session
 Click on execute.
 Select the check box keep.
 Execute.
 Enter.
STEP 13: Run batch input session
 Click on execute.
 Select the session name.
 Process.
 Click on process.

BHAVANA Page | 451


SAP ABAP TRAINING
39. SCRIPTS

 In the real time if you want to design the business documents, such as offer letters,
experience letters, invoices, commercial invoices etc. we need layout sets. These are
designed through forms. Forms are either SAP scripts or smart forms.

 SAP-Script is a tool to display the business documents.

 The standard SAP provided layout sets foralmost all the applications. Most of the
times the ABAPer job is either change the layout or adding some additional logic to
the standard driver program.

 It is an SAP tool which is used to generate printable business documents like invoice,
sale order, delivery note, Employee forms etc.

 The advanced version of script is smart form.

 SAP scripts are client dependent i.e. If a script is developed in client 100, it is not
visible in another client 120 or 130.

Why scripts are client dependent???

 Whenever an SAP script is generated, it is internally stored as texts.

 All texts (& data) are client dependent (SAP RULE).

 Because texts are client dependent.

 SAP scripts are also client dependent.

 SE71 is the Transaction code for Scripts.

BHAVANA Page | 452


SAP ABAP TRAINING
 Components of SAP Scripts

 1.Header

 Administrative data

 Basic settings

 2. pages

 3.Windows

 4.Page windows

 5.Paragraph format

 6.Charecter format

 7.Layout

 1. HEADER

It contains the header information of the SAP Script.

 Administrative data

 It contains the data related to package name, client no, user name and languages

BHAVANA Page | 453


SAP ABAP TRAINING
 Basic settings

 It contains the data related to settings like page format, orientation, first page, default
paragraph

 2. PAGES

 SAP script is a group of pages.

 Each page contains a layout.

 The layout is used to design the page.

 Page is a group of windows.

 We can create 99 Pages only.

 For every page, we need to specify next page

 If next page is not specified then it will consider the same page as next page.

Windows:

 A window contains some information to display on script.

 The entire page information is divided in the form of windows.

BHAVANA Page | 454


SAP ABAP TRAINING
3. WINDOWS

 There are four types of windows:

 Main window

 Variable window

 Constant window

 Graphical window

Main window:

 A Window which automatically expands depending upon the data is called main window.

 Each page contains only one main Window.

 As there are 99 pages only in scripts, we can have maximum 99 main windows only

 The main Window data is divided into blocks called as text elements.

Text Element:

 It is used to display the specific block of information.

 Text elements are represented by ‘/E’.

 The entire main Window data is divided into blocks called as text elements.

 Now, display a particular text element, so that only that specific info related to text

element is displayed.

BHAVANA Page | 455


SAP ABAP TRAINING
Constant Window:

 A Window which is constant for all the pages is called constant Window.

Variable Window:

 A Window which does not expand i.e., width and height is fixed.

Graphical Window:

 A window which is used to display graphics or images.

4. PAGE WINDOWS

 The windows assigned to particular page are called page windows.

5. PARAGRAPH FORMAT

 It is used to specify a particular format

 (Font size/family/Bold/italic/underlined) for all the characters in a paragraph.

 We can also specify TABS.

 Tabs: Tabs are used to specify a position in sap script so that the text will be displayed at

that particular position.

BHAVANA Page | 456


SAP ABAP TRAINING
 Tabs are represented by, (2 commas).

6. CHARACTER FORMAT

 A format which is used by a group of characters inside a paragraph is called a character

format.

7. LAYOUT

 It is a place where we design the page with windows.

Function Modules in SAP Scripts

The various function modules available in SAP Scripts are:

 OPEN_FORM

 This is used to open a form for execution by loading it into memory

 WRITE_FORM

 It is used to write Some information on the SAP Script form using Text

Element.

 CLOSE_FORM

 It is used to close the form which is opened by open form

BHAVANA Page | 457


SAP ABAP TRAINING
 START_FORM

 It is used to call another SAP Script into current SAP Script (Nested

Scripts).

 END_FORM

 It is used to end the form which started by START_FORM.

Driver Program (Print Prg):

 A program which contains business logic statements i.e., all select statements, loops,

appends etc., is called Driver prg.

 In simple words, a program which is used to drive or print the script.

 All the variables, work areas, internal tables which are declared in the driver program will

be automatically transferred to SAP Scripts.

 If we want to display the variables or work area values, we need to follow below syntax.

Syntax: &variable&

&workarea fname&

BHAVANA Page | 458


SAP ABAP TRAINING
Steps to create scripts

 Go to SE71
 provide FORM name.
 Click on create and provide description.

 Click on create.
 Provide description.

BHAVANA Page | 459


SAP ABAP TRAINING
 Click on save.
 Save it in package.

 Create page 1: Click on pages  Give page name  enter give


meaning.

BHAVANA Page | 460


SAP ABAP TRAINING
 Click on save.
 Create windows

 Click on Windows (by default main window will be added)

 Click on edit  create element  give window name and description.

 Click on continue.

BHAVANA Page | 461


SAP ABAP TRAINING
 Click on save.

 Create a page window

 Click on page windows

 Edit, create element

BHAVANA Page | 462


SAP ABAP TRAINING
 Double click on each window provide height width left/right margin.

 Click on save.

BHAVANA Page | 463


SAP ABAP TRAINING
 Create paragraph formats
 Click on paragraph format  give paragraph name and description.

 Click on save.

Create a character format

BHAVANA Page | 464


SAP ABAP TRAINING
 Click on create a character format.

 Give char format and description.

 Click on save.

 Go to settings  click on form painter.

BHAVANA Page | 465


SAP ABAP TRAINING
 Select graphical form painter

 Click on continue.

BHAVANA Page | 466


SAP ABAP TRAINING
Layout:

 Click on Layout

 Save and activate it.

 Go to tcode SE78 for uploading the logo.

 Double click on BMAP Bitmap images.

 Provide name and color bitmap image.

BHAVANA Page | 467


SAP ABAP TRAINING
 Click on import.

 Provide file name and description.

 Click on continue.

 Click on print preview.

BHAVANA Page | 468


SAP ABAP TRAINING
 Go to layout  graphic window  create give name and resolution.

 Click on continue.

 Go to page windows.

 Click on text element, it will automatically redirect to Microsoft word screen.

 Click on Go to  change editor.

 Provide paragraph text.

BHAVANA Page | 469


SAP ABAP TRAINING
 Click on back button.

 Click on back button.

 Basic settings: provide paragraph and page.

BHAVANA Page | 470


SAP ABAP TRAINING
PROGRAM TO CALL SCRIPT

 Go to SE38.

 Provide program name.

 Click on create.

 Provide title and select type as executable program.

BHAVANA Page | 471


SAP ABAP TRAINING
 Click save.

 Save it in package.

BHAVANA Page | 472


SAP ABAP TRAINING
 Click on save and activate it.

 Click on execute.

BHAVANA Page | 473


SAP ABAP TRAINING
 Click on print preview.

BHAVANA Page | 474


SAP ABAP TRAINING
40. S4HANA
SAP HANA based applications provide best application performance by pushing the
execution into the database as possible. All the data is stored in in-memory database,
so the reading data is much faster as compared to a conventional database.

SAP HANA supports real-time data replication and hence removes unnecessary
latency and complexity of data load.
SAP HANA Roadmap to S/4 HANA

S/4 HANA
S/4 HANA Business suite is based on the native HANA platform. and is the next
generation Business Suite which connects people, business networks and devices
and works in real time.

S/4 HANA represents efficiency, simplicity and innovation master data is managed
centrally, for example partners, customers and vendors.

BHAVANA Page | 475


SAP ABAP TRAINING
a) ABAP Development Tool (ADT)

It is a development tool based on Eclipse, which allows you to use the power and

Flexibility. It has the following features.

 You can connect to multiple ABAP systems simultaneously.

 You can recover the session when you log out. This reduces their impact.

 Can be developed on both ABAP and non-ABAP platforms.

 The ADT looks like this:

 Project Exploration View: This view allows the user to explore the various ABAP
packages and objects from an ABAP connection.

BHAVANA Page | 476


SAP ABAP TRAINING
 Tree view: this view displays the structure of the object open in the editing

It displays the parameters, projections, joins, etc. in a hierarchical manner.


 Editing space: window where the view is expanded.

 Perspectives: a configuration of views and editing spaces.

 Objects: open objects in the editing space.

 Toolbars

 Views: screens displaying the functionality of the tool.

b) steps to create an ABAP project in Eclipse

 Menu window  perspective  open perspective  other, change the perspective to


ABAP Perspective  ABAP.

 Create a new ABAP project in file  New  ABAP project.

BHAVANA Page | 477


SAP ABAP TRAINING
 Choose the system on which you want to develop and enter the login and password.

BHAVANA Page | 478


SAP ABAP TRAINING
BHAVANA Page | 479
SAP ABAP TRAINING
41. CDS VIEW
 CDS (Core Data Services) Views is an improvement on the ABAP (Data
Dictionary) layer. They provide a more advanced and semantically rich data
model.

 CDS Views one can expose, model, link, aggregate, the data present in the
database, and thus make it more easily accessible.

 CDS is a collection of SAP-specific languages. It is an extension of SQL


and at the same time a data definition language (DDL), a data
manipulation language (DML) and an authorization control language
(DCL). With this, we can create a virtual data model called VDM
(Virtual Data Model).

There are three types of views:

 Basic: these are used to bring data directly from the physical tables in the database.

 Composite: this type of view is used to link basic views together through associations

(like SQL joins between views). They are then used by the consumption views.

 Consumption: these views allow you to create a specific query from a “composite”

view. This is the only type of view that can be exposed to the OData or transient service

to be consumed for reporting.

BHAVANA Page | 480


SAP ABAP TRAINING
The features added in the extended SQL of CDS are:

 SQL features: calculations, aggregations, UNION, joins and GROUP BY.

 Associations: to link several tables and/or views.

 annotations: allow to define meta-models such as naming, ABAP permissions, view


extensibility.

 Extensibility: a view can be extended by a client application without modifying it, which
makes it reusable and flexible.

 ABAP security: CDS uses ABAP authorization objects and transport layers. In addition,
security can be defined explicitly with annotations.

a) Creation of basic CDS views


 Double click on favorite packages  New  other ABAP repository object.

BHAVANA Page | 481


SAP ABAP TRAINING
 Select Data Definition, and then choose next.

 Provide name and description and click on next.

BHAVANA Page | 482


SAP ABAP TRAINING
 Accept the default transport request (local) by simply choosing Next
again.

 Click on finish.

 Choose the view template which we have to create. And click on finish.

BHAVANA Page | 483


SAP ABAP TRAINING
 Enter the SQL view name (ZSB_VBAK)

The SQL view name is the internal/technical name of the view which
will be created in the database.

 Enter the CDS view (ZSB_CDS_BASIC) as the data source for your view.

 Click on save and activate.

 CDS Views are defined in a source DDL and at activation time it generates two objects:

• SQL View: this is an invisible object in the ABAP dictionary that cannot be

modified.

• CDS View: the simplest form of CDS View is the projection, i.e., a selection of fields

from a single table.

BHAVANA Page | 484


SAP ABAP TRAINING
i) CDS view –select with key

 Right click on the program select run as  ABAP application (F8)


 OUTPUT: select particular fields with key

BHAVANA Page | 485


SAP ABAP TRAINING
ii) CDS view-select *
Select * select all columns from underlying data source

Save and activate.

OUTPUT:

BHAVANA Page | 486


SAP ABAP TRAINING
iii) CDS views-select distinct

OUTPUT:

The keyword DISTINCT ensures that result tables contain no duplicates

BHAVANA Page | 487


SAP ABAP TRAINING
b) CDS views with Joins

OUTPUT:

BHAVANA Page | 488


SAP ABAP TRAINING
c) CDS View with Expressions and Session Variables

OUTPUT:

BHAVANA Page | 489


SAP ABAP TRAINING
d) Consume CDS View in an ABAP Program

 Right click on User package within an ABAP project to create an ABAP


program.

 Provide name and description then click on next.

BHAVANA Page | 490


SAP ABAP TRAINING
 Click on finish.

BHAVANA Page | 491


SAP ABAP TRAINING
OUTPUT

e) CDS View Extension

BHAVANA Page | 492


SAP ABAP TRAINING
 Extension for view ZSB_CDS_BASIC.

OUTPUT:
Before view extension

After view extension

BHAVANA Page | 493


SAP ABAP TRAINING
f) CDS View with Association

BHAVANA Page | 494


SAP ABAP TRAINING
Add required data elements from data source.

BHAVANA Page | 495


SAP ABAP TRAINING
Right click and Select ‘Show SQL create Statement’.

In order to add separate fields in the CDS view as well like a join and that is
AD-HOC Association Concept.

BHAVANA Page | 496


SAP ABAP TRAINING
BHAVANA Page | 497
SAP ABAP TRAINING
OUTPUT

Right click on any row (with ebeln ‘LH ‘) choose Follow Association.

BHAVANA Page | 498


SAP ABAP TRAINING
Pop- up window will open, click the Association type.

g) CDS View with Parameters

BHAVANA Page | 499


SAP ABAP TRAINING
BHAVANA Page | 500
SAP ABAP TRAINING
OUTPUT

BHAVANA Page | 501


SAP ABAP TRAINING
42. OOPS ABAP
 Object orientation simplifies software design to make it easier understand,
maintain, and reuse. Objects Oriented Programming (OOP) represents a
different way of thinking in writing software.

 Class: A Class is a user defined data type with attributes methods types
and events for a particular entity or business scenario or business
application

 Class creation is of 2 steps:

1. CLASS CL_CLASSNAME DEFINITION.

ENDCLASS.

2. CLASS CL_CLASSNAME IMPLEMENTATION.

ENDCLASS.

Components of a Class:

 Attributes: - Any data variables), constants declared within a class are


called as attributes of the class.

 Methods: - Methods contain a block of code, providing some functionality


for a class.

 Events: -

 Events are like actions performed by the user.

 Each event must be linked to a method for writing the corresponding

BHAVANA Page | 502


SAP ABAP TRAINING
business logic for the action/event raised by the user.

 Interfaces: -

 Interfaces are similar to classes which contain methods Without any


implementation.

 These are mainly used to extend the scope or functionality of the class.

OBJECTS

 Objects are instances of classes.

 Each object has a unique identity i.e., memory and its own attributes.

 Objects are created with the command CREATE OBJECT.

 Once an object is created, we have an instance of class with separate


memory

 Syntax: It is also 2 step process.

 STEP1: DATA: instance TYPE REF TO CL_CLASSNAME.

 STEP2: CREATE OBJECT instance.

Global Class and Local Class:

 Classes in ABAP Objects can be declared either globally or locally.

 Global Class: Global classes and interfaces are defined in the Class Builder
(Transaction SE24) in the ABAP Workbench.

 All of the ABAP programs in an R/3 System can access the global classes

BHAVANA Page | 503


SAP ABAP TRAINING
 Local Class: Local classes are defined in an ABAP program (Transaction
SE38) and can only be used in the program in which they are defined.

Methods using table types

TABLES PARAMETER:

 In the methods, we don’t have any option for specifying internal tables
directly.

 Whereas in function modules, we have an option by name TABLE where


we can specify the internal tables directly.

 Tables are absolute in OO-ABAP.

 That’s why this option is not available.

 If we want to use tables parameters, then we need to create a table type in


data dictionary.

EVENTS IN OO ABAP

 Events are like actions performed by the user.

 Each event must be linked to a method for writing the corresponding


business logic for the action/event raised by the user.

TYPES OF EVENTS

 There are 2 types of events:

 Standard Events: Events which are defined and raised by SAP are called
Standard Events.

BHAVANA Page | 504


SAP ABAP TRAINING
 Custom Events: Events which are defined, raised and also handled by
creating event handler methods are called Custom Events.

CONSTRUCTORS

 Constructors are special type of methods.

 constructor methods are executed automatically whenever a object is


created or Whenever a class is loaded.

Types of CONSTRUCTORS

There are 2 Types of constructors:

1.INSTANCE Constructor: constructor method is executed

automatically whenever a object is created or instantiated.

2. STATIC Constructor: This method is executed automatically

whenever a first call to the class is made.

Interface

 Interfaces are independent structure which are used in a class to extend the
functionality of a class.

Polymorphism

 It is a concept by which the same method names will behave differently in


different classes i.e., each method will have its own implementation in
different different classes but with the same name.

BHAVANA Page | 505


SAP ABAP TRAINING
Inheritance

 Inheritance is the concept of passing the properties of one class to another


class.
a) Creating a class in SAP ABAP

 Class components can be defined in public, private, or protected visibility


sections that control how these components could be accessed.

 The private visibility section is used to deny access to components from

outside of the class Components defined in the public visibility section can be

accessed from any context.

Steps

 Go to SE38.

 Provide the program name.

BHAVANA Page | 506


SAP ABAP TRAINING
 Click on create.

 Give title and select type as executable program.

 Click on save.
 Save it in package.

BHAVANA Page | 507


SAP ABAP TRAINING
OUTPUT

BHAVANA Page | 508


SAP ABAP TRAINING
b) Creating methods

 Go to SE24.

 Click on create.

 Provide name and select radio button class.

 Click on continue.

 Provide description.

BHAVANA Page | 509


SAP ABAP TRAINING
 Click on save.

 Save it in package.
 Go to the tab-page: Methods. Enter the details for the method– mention
name, type of method (instance/static), in which visibility.

 Click on Parameters and enter parameters for the method.

 Click on the source Code to implement the method.

BHAVANA Page | 510


SAP ABAP TRAINING
c) Calling the method from the program

OUTPUT

BHAVANA Page | 511


SAP ABAP TRAINING
43. AMDP (ABAP Managed Database Procedure)

 The technique in which stored procedure or database procedure that are stored in ABAP
repository and transported by ABAP transport is called ABAP-Managed Database Procedure.

 The implementation of AMDP is written in HANA SQL Script language and executed on the
database.

AMDP Developing Environment

 ABAP-Managed Database Procedures (AMDP) development is only supported in the Eclipse-


based development environment (ABAP Development Tools) and NOT in SAP GUI Class
Builder, SE24.

 AMDP Class: A global class that contains the interfaces “IF_AMDP_MARKER_HDB” is called
AMDP Class

 AMDP Method: A method declaration in AMDP class with addition of “BY DATABASE
PROCEDURE” in implementation section is called AMDP method.

 FOR: It specifies the database system on which AMDP runs. For example, HDB stands for SAP
HANA Database

 LANGUAGE: It specifies the database language of the implementation.

 USING: It specifies different database tables which can be used inside the ABAP method.
Support transparent tables and Dictionary views.

 OPTIONS: It specifies only reads are permitted on the database tables in the database procedure.
Support only READ-ONLY parameter.

BHAVANA Page | 512


SAP ABAP TRAINING
ASSIGNMENT-1
a) Create a table using following fields

TABLE NAME: ZSB_T001

BHAVANA Page | 513


SAP ABAP TRAINING
b) Create a table using following fields

TABLE NAME: ZSB_T001W

BHAVANA Page | 514


SAP ABAP TRAINING
c) Create a Database view

d) Create a Help view

BHAVANA Page | 515


SAP ABAP TRAINING
e) Create a maintenance view

f) Create a projection view

BHAVANA Page | 516


SAP ABAP TRAINING
g) Create a lock object for the y t001 table

BHAVANA Page | 517


SAP ABAP TRAINING
h) Create an elementary search help for the table y t001

i) Create an elementary search help for the table y t001w

BHAVANA Page | 518


SAP ABAP TRAINING
j) Create collective search help with both the search helps

BHAVANA Page | 519


SAP ABAP TRAINING
k) Create an include structure for the below fields

BHAVANA Page | 520


SAP ABAP TRAINING
ASSIGNMENT-2

a) Create a database table using following fields

BHAVANA Page | 521


SAP ABAP TRAINING
b) Create a database table using following fields

BHAVANA Page | 522


SAP ABAP TRAINING
c) Create search help for the fields gjahr for the table zsb_bseg.

d) Create search help for the fields buzid for the table zsb_bseg.

BHAVANA Page | 523


SAP ABAP TRAINING
e) Create collective search help for the both above search help.

f) Create search help for the fields bldat for the table zsb_bkpf.

BHAVANA Page | 524


SAP ABAP TRAINING
g) Create search help for the fields blart for the table zsb_bkpf.

h) Create collective search help for the both above search help.

BHAVANA Page | 525


SAP ABAP TRAINING
i) Create a foreign key relationship for the tables zsb_bkpf and zsb_bseg
relation between the tables is bukrs

j) Create database view for the tables ekko ekpo

BHAVANA Page | 526


SAP ABAP TRAINING
k) Create a maintenance view for the tables lfa1 and lfb1

l) Create help view for the table bsec

BHAVANA Page | 527


SAP ABAP TRAINING
m) Create a lock object using the table zsb_bseg

n) Create a lock object using the table zsb_bkpf

BHAVANA Page | 528


SAP ABAP TRAINING
THE END

BHAVANA Page | 529


SAP ABAP TRAINING

You might also like