Professional Documents
Culture Documents
By
KARTHIK. V
1
Table of Contents
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.
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.
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.
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:
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
BHAVANA Page | 6
SAP ABAP TRAINING
Syntax of Packed Decimal (P): -
BHAVANA Page | 7
SAP ABAP TRAINING
Syntax of Numeric Char (N): -
BHAVANA Page | 8
SAP ABAP TRAINING
5. ABAP DATA BASE TABLE
BHAVANA Page | 9
SAP ABAP TRAINING
b) Creation of Data Base Table and display contents.
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
➢ 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.
➢ 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.
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.).
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)
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.
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.
BHAVANA Page | 18
SAP ABAP TRAINING
➢ Displays Data browser for ZSB_STUDENT table.
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
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.
BHAVANA Page | 22
SAP ABAP TRAINING
➢ Click on create, select structure and provide description.
➢ Specify the fields and data elements and save and activate.
BHAVANA Page | 23
SAP ABAP TRAINING
2) Append structure: used in both customize and standard table
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.
➢ Open the Second Table ZSH_BKPF. Select the BUKRS field from the table.
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.
BHAVANA Page | 27
SAP ABAP TRAINING
➢ Index name provide with 3 characters provide field name and save and activate.
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.
➢ 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”.
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.
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’.
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.
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
➢ 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.
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.
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)
➢ 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.
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
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.
Go to SE11
Click on ‘Create’.
BHAVANA Page | 54
SAP ABAP TRAINING
Select ‘elementary search help’.
BHAVANA Page | 55
SAP ABAP TRAINING
b) Creating Collective Search Help
BHAVANA Page | 56
SAP ABAP TRAINING
Select ‘include search help’ tab and provide the search help name which we create
inelementary search help.
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
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
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>.
REPORT ZSB_MYFIRSTPROGRAM.
write / 'hello'.
write ' this is' .
write ' my first program' .
write :/ 'hello' , ' this is' , ' my first program'.
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.
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**
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**
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.
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.
REPORT ZSB_CONDITIONAL_STMTS.
gv_num = 10.
skip.
gv_num = 150.
if gv_num < 15.
BHAVANA Page | 68
SAP ABAP TRAINING
write: 'smaller number'.
else.
write: 'Bigger number'.
endif.
skip.
if gv_num1 = 1.
write: 'sunday'.
elseif gv_num1 = 2.
write: 'monday'.
else.
write: 'the number is invalid'.
endif.
skip.
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.
skip.
skip.
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.
REPORT ZSB_INTERNALTABLE5.
BHAVANA Page | 72
SAP ABAP TRAINING
gs_emp-eid = 1.
gs_emp-ename = 'bhavana'.
gs_Emp-eadd = 'ongole'.
gs_emp-amnt = 500.
gs_emp-eid = 4.
gs_emp-ename = ' '.
gs_Emp-eadd = 'HYDERABAD'.
gs_emp-amnt = 500.
BHAVANA Page | 73
SAP ABAP TRAINING
gs_emp-eid = 5.
gs_emp-ename = 'rani'.
gs_Emp-eadd = 'hyd'.
gs_emp-amnt = 500.
gs_emp-eid = 6.
gs_emp-ename = 'raj'.
gs_Emp-eadd = 'delhi'.
gs_emp-amnt = 500.
gs_emp-eid = 7.
gs_emp-ename = 'ram'.
gs_Emp-eadd = 'goa'.
gs_emp-amnt = 500.
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.
gs_emp-eid = 3.
gs_emp-ename = 'sai'.
gs_Emp-eadd = 'chennai'.
gs_emp-amnt = 500.
gs_emp-eid = 4.
gs_emp-ename = ' '.
gs_Emp-eadd = 'HYDERABAD'.
gs_emp-amnt = 500.
BHAVANA Page | 75
SAP ABAP TRAINING
gs_emp-amnt = 500.
gs_emp-eid = 6.
gs_emp-ename = 'raj'.
gs_Emp-eadd = 'delhi'.
gs_emp-amnt = 500.
gs_emp-eid = 7.
gs_emp-ename = 'ram'.
gs_Emp-eadd = 'goa'.
gs_emp-amnt = 500.
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.
OUTPUT:
BHAVANA Page | 77
SAP ABAP TRAINING
b) Create a program using stop statement
REPORT ZSB_INTERNALTABLE6.
gs_emp-eid = 1.
gs_emp-ename = 'bhavana'.
gs_Emp-eadd = 'ongole'.
gs_emp-amnt = 500.
gs_emp-eid = 2.
gs_emp-ename = 'pavan'.
gs_Emp-eadd = 'Hyderabad'.
BHAVANA Page | 78
SAP ABAP TRAINING
gs_emp-amnt = 500.
gs_emp-ename = 'sai'.
gs_Emp-eadd = 'chennai'.
gs_emp-amnt = 500.
gs_emp-eid = 4.
gs_emp-ename = ' '.
gs_Emp-eadd = 'HYDERABAD'.
gs_emp-amnt = 500.
gs_emp-eid = 5.
BHAVANA Page | 79
SAP ABAP TRAINING
gs_emp-enamgs_emp-amnt = 500.
gs_emp-eid = 6.
gs_emp-ename = 'raj'.
gs_Emp-eadd = 'delhi'.
gs_emp-amnt = 500.
gs_emp-eid = 7.
gs_emp-ename = 'ram'.
gs_Emp-eadd = 'goa'.
gs_emp-amnt = 500.
gs_emp-eid = 1.
BHAVANA Page | 80
SAP ABAP TRAINING
gs_emp-ename = 'bhavana'.
gs_Emp-eadd = 'ongole'.
gs_emp-amnt = 500.
gs_emp-eid = 2.
gs_emp-ename = 'pavan'.
gs_Emp-eadd = 'Hyderabad'.
gs_emp-amnt = 500.
gs_emp-eid = 3.
gs_emp-ename = 'sai'.
gs_Emp-eadd = 'chennai'.
gs_emp-amnt = 500.
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.
gs_emp-eid = 6.
gs_emp-ename = 'raj'.
gs_Emp-eadd = 'delhi'.
gs_emp-amnt = 500.
BHAVANA Page | 82
SAP ABAP TRAINING
gs_emp-eid = 7.
gs_emp-ename = 'ram'.
gs_Emp-eadd = 'goa'.
gs_emp-amnt = 500.
write:/ gs_emp-eid,
gs_emp-ename,
gs_Emp-eadd,
gs_emp-amnt.
endloop.
skip 3.
BHAVANA Page | 83
SAP ABAP TRAINING
OUTPUT:
REPORT ZSB_INTERNALTABLE4.
gs_emp-eid = 1.
gs_emp-ename = 'bhavana'.
gs_Emp-eadd = 'ongole'.
gs_emp-amnt = 500.
BHAVANA Page | 84
SAP ABAP TRAINING
gs_emp-eid = 2.
gs_emp-ename = 'pavan'.
gs_Emp-eadd = 'Hyderabad'.
gs_emp-amnt = 500.
gs_emp-eid = 3.
gs_emp-ename = 'sai'.
gs_Emp-eadd = 'chennai'.
gs_emp-amnt = 500.
gs_emp-eid = 4.
gs_emp-ename = ' '.
gs_Emp-eadd = 'HYDERABAD'.
gs_emp-amnt = 500.
gs_emp-eid = 5.
gs_emp-ename = 'rani'.
gs_Emp-eadd = 'hyd'.
gs_emp-amnt = 500.
BHAVANA Page | 85
SAP ABAP TRAINING
gs_emp-eid = 6.
gs_emp-ename = 'raj'.
gs_Emp-eadd = 'delhi'.
gs_emp-amnt = 500.
gs_emp-eid = 7.
gs_emp-ename = 'ram'.
gs_Emp-eadd = 'goa'.
gs_emp-amnt = 500.
gs_emp-eid = 1.
gs_emp-ename = 'bhavana'.
gs_Emp-eadd = 'ongole'.
gs_emp-amnt = 500.
gs_emp-eid = 2.
gs_emp-ename = 'pavan'.
gs_Emp-eadd = 'Hyderabad'.
gs_emp-amnt = 500.
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.
gs_emp-eid = 4.
gs_emp-ename = ' '.
gs_Emp-eadd = 'HYDERABAD'.
gs_emp-amnt = 500.
gs_emp-eid = 5.
gs_emp-ename = 'rani'.
gs_Emp-eadd = 'hyd'.
gs_emp-amnt = 500.
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.
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.
COLLECT: It will save the records but the remove the duplicates.
REPORT ZSB_INTERNALTABLE3.
gs_emp-eid = 1.
gs_emp-ename = 'bhavana'.
gs_Emp-eadd = 'ongole'.
gs_emp-amnt = 500.
BHAVANA Page | 90
SAP ABAP TRAINING
gs_emp-ename = 'pavan'.
gs_Emp-eadd = 'Hyderabad'.
gs_emp-amnt = 500.
gs_emp-eid = 3.
gs_emp-ename = 'sai'.
gs_Emp-eadd = 'chennai'.
gs_emp-amnt = 500.
gs_emp-eid = 4.
gs_emp-ename = ' '.
gs_Emp-eadd = 'HYDERABAD'.
gs_emp-amnt = 500.
gs_emp-eid = 5.
gs_emp-ename = 'rani'.
gs_Emp-eadd = 'hyd'.
gs_emp-amnt = 500.
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.
gs_emp-eid = 7.
gs_emp-ename = 'ram'.
gs_Emp-eadd = 'goa'.
gs_emp-amnt = 500.
gs_emp-eid = 1.
gs_emp-ename = 'bhavana'.
gs_Emp-eadd = 'ongole'.
gs_emp-amnt = 500.
gs_emp-eid = 2.
gs_emp-ename = 'pavan'.
gs_Emp-eadd = 'Hyderabad'.
BHAVANA Page | 92
SAP ABAP TRAINING
gs_emp-amnt = 500.
gs_emp-eid = 3.
gs_emp-ename = 'sai'.
gs_Emp-eadd = 'chennai'.
gs_emp-amnt = 500.
gs_emp-eid = 4.
gs_emp-ename = ' '.
gs_Emp-eadd = 'HYDERABAD'.
gs_emp-amnt = 500.
gs_emp-eid = 5.
gs_emp-ename = 'rani'.
gs_Emp-eadd = 'hyd'.
gs_emp-amnt = 500.
gs_emp-eid = 6.
gs_emp-ename = 'raj'.
gs_Emp-eadd = 'delhi'.
BHAVANA Page | 93
SAP ABAP TRAINING
gs_emp-amnt = 500.
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.
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
WORK AREA:
Syntax:
DATA: <WANAME> TYPE <DATABASE TABLENAME>.
(Or)
DATA: <WANAME>TYPE<USER DEFINED TYPE>.
BHAVANA Page | 96
SAP ABAP TRAINING
Variable:
A temporary memory location which can store a single value.
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>.
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.
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>.
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
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.
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>.
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>.
COLLECT
It is similar to APPEND statement.
Syntax:
COLLECT <WA> INTO <ITAB>.
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.
That means the multiple tables must be joined using one or two fields.
INNER JOIN
OUTER JOIN
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,
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'.
OUTPUT:
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.
REPORT zsb_outer_join.
END OF ty_final.
DATA : gt_final TYPE TABLE OF ty_final,
gs_Final TYPE ty_final,
gt_lines TYPE i.
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.
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.
REPORT ZSB_FOR_ALL_ENTRIES.
ENDLOOP.
Syntax:
select * from <dbtable> into table < itab>.
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.
Ex: select vbeln ernam erdat auart from vbak into table gt_Vbak.
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>.
REPORT ZSB_SELECT1.
SELECT * FROM mara INTO TABLE WT_MARA. " It is used to read all the fields da
ta ".
REPORT ZSB_SELECT2.
SELECT MATNR
ERNAM
MTART
MEINS
ATTYP
FROM MARA INTO TABLE GT_MARA. " it is to display particular
REPORT ZSB_SELECT_STMTS.
SELECT MATNR
ERNAM
MTART
MEINS
ATTYP
FROM MARA INTO TABLE GT_MARA UP TO 100 ROWS WHERE MTART =
'HAWA' AND ERNAM = 'BPINST' .
REPORT ZSB_SELECT3.
REPORT ZSB_SELECT5.
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.
REPORT ZSB_SELECT6.
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.
REPORT ZSB_SELECT7.
SELECT *
FROM mara INTO CORRESPONDING FIELDS OF TABLE GT_MARA UP TO 20
ROWS WHERE MTART = 'HAWA' AND ERNAM = 'BPINST'..
REPORT ZSB_SELECT8.
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'..
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.
OUTPUT:
WRITE : / GS_MARA.
OUTPUT:
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.
REPORT ZSB_SELECTION_SCREEN.
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.
REPORT ZSB_SELECTION_SCREEN2.
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.
OUTPUT:
REPORT ZSB_SELECTION_SCREEN3.
SELECTION-SCREEN SKIP.
SELECTION-SCREEN ULINE.
SELECTION-SCREEN SKIP.
SELECTION-SCREEN ULINE.
If P_CHKBOX = 'X'.
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.
OUTPUT:
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.
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.
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'.
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 '.
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.
else.
WRITE: /'invalid'.
SKIP 2.
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:
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.
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'.
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.
SKIP 2.
ENDLOOP.
SKIP 2.
ENDLOOP.
SKIP 2.
ENDLOOP.
REPORT ZSB_DELETE.
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.
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'.
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.
skip 3.
ENDLOOP.
skip 3.
SORT gt_sinfo.
ENDLOOP.
skip 3.
ENDLOOP.
Output:
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
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.
And now, Create an Executable program where we can use the include programs.
*&--------------------------------------------------------*
*& 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'.
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'.
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'.
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.
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.
OUTPUT:
b) Subroutines
Sub routines contains piece of ABAP code which are mainly used for
readability and reusability.
Subroutines are procedures, that we can define in any ABAP program & calling
from the same or some other ABAP program.
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.
TYPES OF PASSING VALUES: There are 3 types to send the values from sub
routine definition to sub routine implementation.
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.
REPORT ZSB_SUBROUTINE1.
gv_A = 10.
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.
REPORT ZSB_SUBROUTINE2.
gv_A = 10.
ENDFORM.
OUTPUT:
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.
REPORT ZSB_SUBROUTINES3.
gv_A = 10.
ENDFORM.
OUTPUT:
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.
Press enter. Click on ‘yes’ button. Provide short text. Function Group will
be created.
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)
IMPORT:
Input to a Function module is called Importing parameter.
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
SOURSE CODE:
Contain the ABAP code for a FMOD.
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.
LOAD-OF-PROGRAM
INITIALIZATION
AT SELECTION-SCREEN OUTPUT
AT SELECTION-SCREEN ON FIELD
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.
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.
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.
INITIALIZATION.
p_vkorg = 1710.
AT SELECTION-SCREEN.
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.
END-OF-SELECTION.
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.
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.
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
At user-command:
It’s an event which is triggered at the time of user clicks on any menu item.
At PF <Function Key>:
It’s an event which is triggered at the time of user clicks on F1 to F12 function keys.
ALV Reports are mainly used to display the data in the form of either Grid or List Format
with good look and feel.
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
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
REPORT ZSB_ALV_WIT_STR.
*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.
Grid display:
List display:
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
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
REPORT ZSB_ALV_FCAT_MANUAL.
**
**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'
type-pools slis.
data : gt_vbak type table of vbak,
gt_Fcat type slis_t_fieldcat_alv,
gs_fcat type slis_fieldcat_alv.
gs_fcat-col_pos = 1.
gs_fcat-fieldname = 'VBELN'.
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.
case gs_fcat-fieldname.
WHEN 'VBELN'.
OUTPUT:
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.
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
REPORT ZSB_ALV_WIT_LAYOUT.
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'.
OUTPUT
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.
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.
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.
.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.
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.
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.
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'.
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.
REPORT ZSB_ALV_EVENTS_LOGO.
***
***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.
wa_heading-typ = 'H'.
wa_heading-info = 'SALES ORDER DETAILS'.
APPEND wa_HEADING TO it_heading.
OUTPUT:
EPORT zsb_alv_interactive.
START-OF-SELECTION.
**PERFORM INTERACT.
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.
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.
*&---------------------------------------------------------------------*
wa_heading-typ = 'H'.
wa_heading-info = 'SALES ORDER ITEM DETAILS'.
APPEND wa_heading TO it_heading.
FORM heading .
wa_heading-typ = 'H'.
wa_heading-info = 'SALES ORDER DETAILS'.
APPEND wa_heading TO it_heading.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form BUTTONS
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
ENDFORM.
OUTPUT:
REPORT zsb_alv_hierarchal.
TYPE-POOLS slis.
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'.
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.
REPORT ZSB_ALV_BLOCKED.
Control break statements are work with in the loop at internal table. Before using the
control break statements.
o At First
o At New<field name>
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.
AT END OF <field name>: -This event triggered at the last record of each block.
AT LAST: -This is an event which is triggered at the last record of internal table.
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.
WRITE gs_vbapt-netwr.
ENDAT.
lv_num = lv_num + 1.
at LAST.
WRITE lv_num.
ENDAT.
ENDLOOP.
OUTPUT:
It is a special type of programming which is used to create custom SAP Screen as per
business requirement.
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
SCREEN:
MODULE:
It is a sub-program which contains the ABAP code for a screen.
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.
Click on YES.
Name T1.
Save it.
OUTPUT
and click on
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:
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.
OUTPUT:
Tab strip’s are used to divide the main screen into sub screens to display mass amount of
data.
Each sub screen must have an area to display the sub screen called as Sub screen area
Go to SE80.
Click on YES.
Provide title and select type as module pool and save it in package.
Click on Flow-Logic.
Drag and drop onto layout and it will be loading a screen i.e., tabstrip wizard.
The names of program includes in which the data definitions and the input/output
modules are to be created:
0101
0102
0103
101, 102 ,103 all the logic was automatically assigned for that.
Click on continue.
Save it.
OUTPUT:
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 Loop at ITAB into WA with control <table control name> (IN PBO).
Endloop
Endloop.
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
Vertical scrollbar: In Table control by default, we don’t get vertical scroll bar.
<TABLECONTROLNAME>-LINES = <NO>
Horizontal & Vertical Lines: In Table control by default, we don’t get vertical and
Horizontal lines.
Steps:
Go to SE80.
Click on YES
Provide title and select type as module pool and save it in package.
Click on Flow-Logic.
Drag and drop onto layout and it will be loading a screen i.e., table control wizard.
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
Click on continue
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:
Click on continue
OUTPUT
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)
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.
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
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
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 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.
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.
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.
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.
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
If the file is located in application server, we use the below syntaxes to read or write the
data into files.
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”.
we use the below statement to read the data from application server file.
Syntax: READ DATASET <filename> INTO <variable>
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.
START-OF-SELECTION.
gv_path = p_path.
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.
OUTPUT:
Click on execute.
Go to /OAL11.
Upload file to AL11, select directory (DIR_HOME) to upload file in application server.
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.
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.
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
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)
So, we use the middleware technologies like TIBCO or XI to communicate between SAP
to non-SAP.
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.
DEBMAS is an IDOC
Whenever an IDOC is transmitted at runtime, there are 3 components which are added
automatically to the IDOC.
Step1: First create the required segment in WE31 with some fields.
Go to WE31.
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.
Give the minimum no. as 1, maximum no. as 9999 because each customer will have more
than 1 bank account.
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.
In this step we maintain a connection between sender system and receiver system which
is called as RFC Destination.
The Tcode is “SM59”.
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:
These are the IDOC’s which are derived from MASTER IDOC.
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.
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.
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.
Go to WE81.
Go to WE82.
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.
CUSTOM IDOC’S
Custom IDoc’s are generally copied from the standard IDoc by adding OR removing
extra segments.
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.
It also a remote enable function module which is used to communicate between SAP-
SAP or SAP-NONSAP servers.
Later, this RFC Function module will be inserted into a business object, now it is
converted into BAPI.
Methods are:
BUS2012
Methods are:
o BAPI_PO_GETDETAIL
o BAPI_PO_GETITEMS
BAPI RFC
1.used to communicate between SAP- 1.used to communicate between
SAP & NONSAP-SAP. SAP-SAP & NONSAP-SAP.
USAGE OF BAPI’S:
Reports:
STEP 1:
Click on continue.
Click on create.
Go to SE37.
Source code
Click on continue.
Press enter.
Click on Yes
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.
Go to SE38.
Execute it.
OUTPUT:
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.
We need sap access key for user exits, that is why these are called as modifications.
These are zinclude programs which are available inside a fuction module.
Technically these are called as enhancement, we don’t require any access key.
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.
Double click and create the zinclude and write your abap code.
Menu exit: -
This exit is used to add custom menus to the standard menu bar.
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
A menu exit is used to add custom menu and function module exit is use to add the abap
Screen exit: -
This exit is used to add custom sap screen to the standard sap screen is called screen Exit.
Each screen exit will have a function module exit to write the abap code for the custom
screen.
This is exit is used to change the standard field labels of input fields on sap screen. This
Project: -
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.
Steps:
Go to se93.
Give the tcode name.
Click on display
Double click on the program name.
A pop up is displayed.
Give the string as call customer, select radio button in main program and press enter.
Double click on main program name and continue until the call customer functions are
displayed.
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.
Step1 in detail:
Go to se93
Click on display.
Go to smod transaction
A pop up is displayed.
Click on execute.
The list of the function module exit, menu exits, screen exits will be displayed.
Go to se84.
If we use CALL CUSTOMER to search for an exit, we directly get M exit without
enhancement name.
Modsap is the table which will give the enhancement name for an exit.
Steps:
Go to se11.
Click on display.
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.
Click on continue.
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.
A Badi which has only one implementation (single class) is called single implementation
Badi.
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
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.
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.
Click on display.
Double click on the method GET_INSTANCE and Put a break point on the below
method GET_CLASS_NAME_BY_INTERFACE.
Steps
7. Windows are: main, var, grapical 7. Windows are: main, secondary, copies
windows in sapscripts. and final windows in smartforms.
independent.
Create a Smartform.
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
COMPONENTS OF SMARTFORMS
page
Window
Graphic
Address
Text
Table
-- Header
-- Body
-- Footer
Template
Folder
Program Line
Alternative
Command
Loop
This will contain all the pages and the windows, which are used in the smartform.
Just provide address no, it will automatically display the address as per the country
formats.
displayed.
table data.
Template: template is also like a table which does not expand. That means it will have
Folder: it is a container which is used to group all the sub nodes. it is like a folder in
normal language.
Click on Create.
Form attributes
In table click on pencil icon and draw 6 columns in first row (%LTYPE1).
Go back.
If you click on to Table1 new table 1, you can see the data
Execute it.
Test it
Click on execute
Import a logo
Click on continue
Execute it
called BDC.
Outbound process
Inbound process
OUTBOUND PROCESS:
The process of transferring the data from SAP to NON-SAP or another SAP server is
Legacy system-> extract -> flat file -> upload -> itab sap server
The process of receiving the data from NON-SAP to SAP server is called as “Inbound
Process”.
It is the process of transferring the data from flat file into SAP by calling a transaction
Properties:
This method is used for transferring less amount of data (<10,000 records).
We need to handle the errors and the success messages by declaring an internal
Syntax:
UPDATE <A/S>
MODE <A/E/N>
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
In simple words, it holds all the screen related information and field information to be
RMMG1-MATNR ‘1011’
RMMG1-MBRSH ‘FOOD’
RMMG1-MTART ‘FERT’
RZSEL ‘X’
- - - - -
- - - - -
To find the above information for each field, press F1 on particular field
Please note down the program name, screen number, screen field name.
Since, it is very difficult to note down the technical information for each field, we have
UPDATE WORK PROCESS: This work process is responsible for updating the data into the
database.
In this type of the call transaction screens will communicate with the update work process
It immediately starts to process the next record without waiting for the update to be
finished.
It is generally not recommended for the large amount of data, because the called
In this mode, the called transaction communicates with the update work process to update
Once the update is finished, then it continues to process the next record.
It is generally recommended for large amount of data because it returns success and error
messages.
__________________________________________________________
MODE DESCRIPTION
___________________________________________________________
MESSAGES:
In the called transaction, we need to handle the messages by declaring an internal table of
type BDCMSGCOLL.
MSGID Message ID
The variable BDCMSGCOLL – MSGV1 will contain the created material number or
Whenever the message type is error, we need to use the function module
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.
Steps:
Go to Tcode SHDB.
Click on new recording.
Create material give material name, industry sector and material type.
Click on enter
Save it
Go to se38
Click on create
REPORT ZSB_BDC_CALL_TRANSACTION.
TYPES:BEGIN OF ty_final,
END OF ty_final,
BEGIN OF ty_output,
text(200) TYPE c,
nodata TYPE c.
* EXPORTING
* PROGRAM_NAME = SYST-CPROG
* FIELD_NAME =''
IMPORTING
file_name = p_path.
START-OF-SELECTION.
gv_path = p_path.
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.
ENDIF.
'RMMG1-MTART'.
'=ENTR'.
gs_final-matnr.
gs_Final-mbrsh.
gs_Final-mtart.
'=ENTR'.
'X'.
'/00'.
gs_Final-maktx.
'MARA-MEINS'.
gs_final-meins.
'NORM'.
CLEAR gs_final.
ENDLOOP.
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
not_found = 1
OTHERS = 2.
IF sy-subrc <> 0.
ENDIF.
CLEAR:gs_output, gs_mess.
ENDLOOP.
WRITE:/ gs_output-text.
ENDLOOP.
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*----------------------------------------------------------------------*
* -->PROGRAM text
* -->DYNPRO text
*----------------------------------------------------------------------*
CLEAR bdcdata.
bdcdata-program = program.
bdcdata-dynpro = dynpro.
bdcdata-dynbegin = 'X'.
APPEND bdcdata.
ENDFORM. "BDC_DYNPRO
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->FVAL text
*----------------------------------------------------------------------*
CLEAR bdcdata.
bdcdata-fnam = fnam.
bdcdata-fval = fval.
APPEND bdcdata.
ENDIF.
ENDFORM.
Go to se16n
Execute it
M123
This method is used to transfer large amount of data (e.g.: >10,000 to 10 lakhs)
Create a session
Process a session
Session: A session contains a group of records, which have to be transferred into SAP.
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
Keep = ‘X’, specifies the session to be available in the session queue for processing at a
Just call the function module and provide the above parameters.
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
BDC_CLOSEGROUP:
This function module is used to close the session which is created by function module
BDC_OPENGROUP.
Go to SM35
Select either foreground or background or error mode, click on the process button.
Status of session:
To know the status or to know how many records are successfully processed, follow the
below steps.
it will clearly display all the messages whether each record is successful or error with
Steps:
Go to code SE38
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.
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
CLEAR gs_final.
REFRESH bdcdata.
CLEAR bdcdata.
ENDLOOP.
**********************************************
*&---------------------------------------------------------------------*
*& Form BDC_DYNPRO
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->PROGRAM text
* -->DYNPRO text
*----------------------------------------------------------------------*
FORM bdc_dynpro USING program dynpro.
CLEAR bdcdata.
*&---------------------------------------------------------------------*
*& 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.
Execute it
Execute
UNIT TESTING:
Goto SM35
Click on process
LSMW
It is a SAP tool which is used to transfer the data from legacy system to SAP.
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
Enter.
Enter.
Provide object name (ZSB_LSMW_MM01_OBJ).
Provide short description of object.
Enter.
Click on execute.
Enter.
Provide the transaction code (mm01).
Enter.
Provide the material name (MATERIAL2), choose industry sector
(MECHANICAL ENGINEERING) and give material type (COUPONS).
Click on continue.
Give description
Click on save
Save, back.
Save, back.
Save, back.
STEP 7: Assign files
Select step 7 and Click on execute.
Save, back.
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.
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.
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.
1.Header
Administrative data
Basic settings
2. pages
3.Windows
4.Page windows
5.Paragraph format
6.Charecter format
7.Layout
1. HEADER
Administrative data
It contains the data related to package name, client no, user name and languages
It contains the data related to settings like page format, orientation, first page, default
paragraph
2. PAGES
If next page is not specified then it will consider the same page as next page.
Windows:
Main window
Variable window
Constant window
Graphical window
Main window:
A Window which automatically expands depending upon the data is called 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:
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.
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:
4. PAGE WINDOWS
5. PARAGRAPH FORMAT
Tabs: Tabs are used to specify a position in sap script so that the text will be displayed at
6. CHARACTER FORMAT
format.
7. LAYOUT
OPEN_FORM
WRITE_FORM
It is used to write Some information on the SAP Script form using Text
Element.
CLOSE_FORM
It is used to call another SAP Script into current SAP Script (Nested
Scripts).
END_FORM
A program which contains business logic statements i.e., all select statements, loops,
All the variables, work areas, internal tables which are declared in the driver program will
If we want to display the variables or work area values, we need to follow below syntax.
Syntax: &variable&
&workarea fname&
Go to SE71
provide FORM name.
Click on create and provide description.
Click on create.
Provide description.
Click on continue.
Click on save.
Click on save.
Click on save.
Click on continue.
Click on Layout
Click on continue.
Click on continue.
Go to page windows.
Go to SE38.
Click on create.
Save it in package.
Click on execute.
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.
It is a development tool based on Eclipse, which allows you to use the power and
You can recover the session when you log out. This reduces their impact.
Project Exploration View: This view allows the user to explore the various ABAP
packages and objects from an ABAP connection.
Toolbars
CDS Views one can expose, model, link, aggregate, the data present in the
database, and thus make it more easily accessible.
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
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.
Click on finish.
Choose the view template which we have to create. And click on finish.
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.
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
OUTPUT:
OUTPUT:
OUTPUT:
OUTPUT:
OUTPUT:
Before view extension
In order to add separate fields in the CDS view as well like a join and that is
AD-HOC Association Concept.
Right click on any row (with ebeln ‘LH ‘) choose Follow Association.
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
ENDCLASS.
ENDCLASS.
Components of a Class:
Events: -
Interfaces: -
These are mainly used to extend the scope or functionality of the class.
OBJECTS
Each object has a unique identity i.e., memory and its own attributes.
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
TABLES PARAMETER:
In the methods, we don’t have any option for specifying internal tables
directly.
EVENTS IN OO ABAP
TYPES OF EVENTS
Standard Events: Events which are defined and raised by SAP are called
Standard Events.
CONSTRUCTORS
Types of CONSTRUCTORS
Interface
Interfaces are independent structure which are used in a class to extend the
functionality of a class.
Polymorphism
outside of the class Components defined in the public visibility section can be
Steps
Go to SE38.
Click on save.
Save it in package.
Go to SE24.
Click on create.
Click on continue.
Provide description.
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.
OUTPUT
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 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
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.
d) Create search help for the fields buzid for the table zsb_bseg.
f) Create search help for the fields bldat for the table zsb_bkpf.
h) Create collective search help for the both above search help.