Sie sind auf Seite 1von 397

Sun Shine Technologies

SAP R/3
SYSTEM APPLICATIONS PRODUCTS
INDATA PROCESSING

ABAP/4

Contents
1

Sun Shine Technologies


Introduction to sap
5
ABAP introduction and role of an abap consultant
6
Tcodes
8
Data Dictionary
Tables
9
Creation
13
Structure
30
Search help
20
Views
33
Data Base View
33
Projection View
38
Maintenance View
40
Help View
48
Lock Objects
51
Performance Factors
53
Buffering
Indexes
Log Data Changes
2

Sun Shine Technologies


Packages
56
Introduction to programming with keywords
60
Internal Tables
65
Types of Internal tables
75
Operations of Internal tables
77
For all entries
99
Inner joins
104
Messages
79
Open Sql
80
Modularization Techniques
105
Includes
105
Macros
109
Subrourines
108
Function Modules
111
Control Break Statements
120
Classical Reports
123

Sun Shine Technologies


Interactive Reports
127
Hide
128
Getcursor
131
ALV Reports
135
Filedcatalog
136
Events
140
Blocked
143
Hierarical
146
Interacive
149
Variant
157
Performance Issues
161
Debugging
165
Module Pool Programming
169
Screen Design
169
Events
170
Table Control
171
Tab Strip
171
4

Sun Shine Technologies


Validations
172
Scripts
173
Smartforms
206
BDC
263
Call Transaction
263
Session
280
LSMW
294
Enhancements and Modifications
311
Exits -- UserExits, Customer Exits
BAdI
338
Cross Applications
347
BAPI
381

Sun Shine Technologies

SAP R/3
System Applications and Products
Indata Processing
Introduction to SAP
SAP was founded in 1972 in walldorf, Germany.
It stands for System ApplicationProduct In Data Processing over
the year it grows and evolved to becomes the world premier
provider for client/server business solutions for which it is so well
today.
It is an Erp Product.
All the Modules of sap can be classified into
1) Technical : a) Basis
b) Abap
2) Functional : a) SD (Sales and Distribution)
b) MM (Material Management)
c) HR (Human Resources)
d) Fi/co (Finance and Controlling) . Etc.

Sun Shine Technologies

ABAP/4.
Advance Business Application
Programming.
ABAP is a programming language developed by SAP for the
interactive development of application programming.

ABAP is a fourth generation language.

IT is tightly integrated across all the modules viz like SD,


MM, HR etc..

All application programs, along with parts of the R/3 Basis


system, are written in the ABAP Workbench using ABAP,
SAPs programming language. The individual components of
application programs are stored in a special section of the
database called the R/3 Repository. The R/3 Repository
serves as a central store for all of the development objects in
the R/3 System

It contains the Cross application concept to exchange the


data from one system to another system
EX: SAP to VB
7

Sun Shine Technologies


JAVA to SAP
Characteristics of ABAP/4
ABAP supports business-related data types and operations.
You can execute calculations using special date and time
fields. The system automatically executes all necessary type
conversions.
ABAP provides a number of functions for processing
character strings.
ABAP allows you to define and call subroutines. You can even
call subroutines of other programs. There are different ways
of how to pass parameters to and from the subroutines.
ABAP contains a special type of subroutine, called function
module. Function modules are stored and maintained in a
central library. They have clearly defined data interfaces to
the calling program. You can test function modules in a
stand-alone mode independent of the calling program.
ABAP contains an SQL subset called OPEN SQL. OPEN SQL
allows you to read and change database tables independent
of the underlying database system.
ABAP allows you to define and process internal tables that
exist only for the execution period of the program. Internal
tables most efficiently support the usage of database tables
and allow you to implement complex data structures in a
program.
ABAP allows you to store data not only in databases but also
as sequential files on application and presentation servers.

Role of an ABAP Consultant


8

Sun Shine Technologies


RICEF/FRICE
R REPORTS: Fetching data from database based on the
given input and
display in a particular format.
I INTERFACES: Connect from one server to other server.
C CONVERSIONS: Conversion programs are used to
migrate data
from the legacy system to SAP system
E ENHANCEMENTS: Adding Extra Functionality to the
standard without disturbing the standard.
F FORMS: Business documents which we need to give as a
printout are designed in form of forms.

TCODES Transaction Codes


TCODE
SE11
SE38
SE37
SE41
SE51
SE71
SM30
SE78
SE21
SE24
SE91
SE93

DESCRIPTION

TCOD
E
Data Dictionary
Xd01
Abap editor
Xk01
Function Builder
Va01
Menu painter
Mm0
1
Screen painter
Me21
n
Form Builder
Co01
Table Maintenance Vl01
generator
upload logo
Vf01
Package builder
Me51
n
Class builder
Message class
Tcode creation

DESCRIPTION
Create
Create
Create
Create

customer
vendor
sales order
material

Purchase order
Production order
Delivery
Billing
Purchase
requisition

Sun Shine Technologies


LSMW
SMARTFO
RMS
SE18
SE19
SMOD
CMOD
SE80
Shdb

Lsmw
Smartforms
Badi definition
Badi
implementation
Exit definition
Exit
implementation
Object navigator
Recording

Tables
Kna1
Knb1
Knc1
Lfa1
Lfb1
Lfc1
Mara
Marc
Mard
Makt
Ekko
Ekpo
Eban
Ebkn

Tables
Vbak
Vbap
Likp
Lips
Vbrk
Vbrp
T001
T001w

Data Dictionary
Tcode: SE11
Definition:

10

Sun Shine Technologies


- Data dictionary describes the logical structures of the objects
used in application development and shows how they are
mapped to the underlying relational database in tables/views.
- It is a central repository, which is a collection of repository
objects like database tables, views, and structures.etc.
- We can create, change and display any table.
- We can also know the table definition and global types.
- It is closely integrated (linked) with ABAP Development
Workbench.
- Transaction code SE11
- It is a virtual database, which consists of metadata (definition
of underlying database)
Functionality:
- Data integrated (linked with other table), maintains data
security (authorization) and data consistency (accuracy).
- It avoids data redundancy (duplication or repetition).

Classification:
1. BASIS (table can be client dependent & client independent)
2. Technical (tables can be transparent tables, cluster tables &
pooled tables)
3. Functional (table can be master tables, transaction tables,
configuration tables & system tables)
1. BASIS Classification:
Client dependent
Also called as Client specific

Client independent
Also called as cross client
11

Sun Shine Technologies


Consists of client (MANDT) as key field
MANDT as data element
CLNT as data type
3 as length.

Doesnt consist of client (MANDT)


key field.
NOTE: table data is dependent on
client.
Table structure is common in all t
clients.

Transparent, Cluster and Pooled Tables


Transparent Table: Exists with the same structure both in
dictionary as well as in database exactly with the same data and
fields.
Pooled Table: Pooled tables are logical tables that must be
assigned to a table pool when they are defined. Pooled tables are
used to store control data. Several pooled tables can be
combined in a table pool. The data of these pooled tables are
then sorted in a common table in the database.
Cluster Table: Cluster tables are logical tables that must be
assigned to a table cluster when they are defined. Cluster tables
can be used to store control data. They can be also used to store
temporary data or texts, such as documentation.

DATA CLASSES:
a. Master Data: are used to maintain master data. Master
data is the data which is almost constant and rarely
changed. E.g. Customer master data, vendor master data,
material master data, and HR master data.
b. Transactional Data: are used to maintain transactional
data. Transactional data is the data which changes
frequently and rarely constant. E.g. sales document item
data, purchase document item data, billing document item
data, delivery document item data.
c. Customizing Data (or) configuration data: maintains
organization data. Organization data is the data which is
entered initially while setting up a new organization. E.g.
clients T000, company codes T001, country T005.
12

Sun Shine Technologies


d. System data: maintains system data (or) control data
system data is the data which is maintained and controlled
by SAP. E.g. language key T002, currency keys TCURC,
unit of measurement T006.
DELIVERY CLASS:
- Specifies the data to be transferred between clients, while
client copy or upgrade.
- It specifies the owner of the table. e.g. A-application table
(master & transactional data)
- Data can be master and transactional data, customizing data,
temporary data, etc.

Save
Technical Settings
DATA CLASS:
- Specifies the logical storage area (table space) occupied by
current table in the underlying database. The table space
depends on type of data.
Ex: (types of data)
APPL0: master data transactional tables
APPL1: transactional data transparent tables
APPl2: organization data customizing tables
13

Sun Shine Technologies


USER1: customer data class
USER2: customer data class
SIZE CATEGORY:
- Specifies the number of records expected in the database
table.
- Using technical settings tab we can maintain data class, size
category, and buffer options.
Notes:
- We can modify standard table technical settings.
- In kna1, you can enter 10,000 records but if the requirement
is to enter more than 10,000 records then you can change the
data class and increase the number of records.

CREATING A TABLE IN DATABASE:


1. Go to SE11
2. Select database table (radio button).
3. Provide a name with y or z.
4. Click on create.
5. Provide short description.
6. Provide/specify delivery class as A.
7. Data browser/table view maintenance as
display/maintenance allowed.
8. Click on save.

14

Sun Shine Technologies


9. Under package you can either type $tmp or click on local
object.
10.
Click on technical settings tab.
a. Data class: mention APPL0.
b. Size category 0.
c. Save and come back.
11.
Under fields,
To create field we fallow Data Element type Method.
Domain: Domain defines Technical attributes of a table field.
Technical attributes means Data type and length.

Se11
Select the radio button domain
Short description
15

Sun Shine Technologies


Provide data type and length
Save, check and activate.
Data Element: Data Element Defines Symantec attributes of a
table field.
Collection of domain and short description.

16

Sun Shine Technologies

Se11
Select the data type radio button
Select data element
Provide short description
Provide the domain and enter automatically data type and
length are copied since domain is already created and activated.
Come to fields tab
Provide field labels (i.e. short descriptions).
Save, check and activate.
Other way of creating the data base table fields.
Create table
Provide field name
Provide data element
Double click on data element
Save
Yes
Provide short description for data element
Provide domain
Double click on domain
Save
Yes
Provide short description for domain
Provide data type and length
17

Sun Shine Technologies


Save check and activate
Back
Provide field labels for data elements
Save check back
Now save check and activate the table.
Steps to create entries.
Click on utilities
Table contents
Create entries
Steps to display the entries
Contents
Provide from to to values
Execute
(Or)
Click on utilities
Table contents
Display values.

18

Sun Shine Technologies

F4 help creation for table field:


By Taking Data types as DATS and TIMS for Date and time fields
By taking fixed values in Domain
19

Sun Shine Technologies


By Creating Foreign Key Relationship
By Creating Search help.
Taking Fixed values in Value Range of the Domain.
Select domain radio button
Provide short description
Provide data type and length
Come to value range tab
Provide the values which need to be come as f4 for that field.
By Creating Foreign Key relationship.
FOREIGN KEY:
DEFINATION:
- Foreign key is a key field of other table.
- Foreign key serves like interface between two tables.
- Using foreign keys we can establish relationship between two
tables.
- While defining foreign key relationship cardinality has to be
specified. Cardinality mentions how many dependent records
or how referenced records are possible.
ADVANTAGES:
- It generates F4 help.
- In F4 help, check table keyfield values are populated
automatically.
- F4 help is useful while maintaining data into current table with
the help of other table entries.
- Foreign key performs field validation (if the user provides a
value from the F4 list, only then the entry is valid).
REQUIREMENT:
Whenever we want to fetch the data from two database tables
and display output, two tables must have relationship.
- Tables can be connected using foreign key.
- To create foreign key common field is required in both tables.
PRE-REQUISITIES:
20

Sun Shine Technologies


- At least two tables, with active status (with
data/content/entries).
- Two tables must have common field.
- Check table keyfield must have data element.
PROCEDURE:
- Open the foreign key table in change mode.
- Click on entry help/check tab.
- Place the cursor on foreign key field and click on foreign key
icon.
- In dialogue box, provide short description, check table name,
and (e.g. check table name is the other program from where
you want to get the field).
- Click on generate proposal tab and continue (do not check any
boxes there).
- Click on Check and copy.
- Notice the status message and check table name.
- Activate table.
TESTING/ CHECKING:
UTILITIES -> TABLE CONTENTS -> CREATE ENTRIES.
Place the cursor on foreign key field input field notice that system
generated F4 help.
System enables check table tab on successful creation of
foreign key.
Check table tab is useful to cross check the check table entries.
CARDINALITY: is also called as multiplicity.
- It defines the relationship with foreign key table.
- It precisely defines the relationship between two tables.
- It specifies the number of dependent records for one record of
check table.
1:1 each record in check table has one dependent record.
1: N each recording check table has at least one dependent
record.
1: C each record in check table has max number of dependent
record.
21

Sun Shine Technologies


1: CN each record in check table has any number of dependent
records.

VALUE TABLE: can be defined at domain level.


- Wherever this domain is used, system proposes this value
table name as check table while creating foreign key.
ADVANTAGES of specifying value table, it automatically proposes
check table name while creating foreign key.
SEARCH HELP:
- In the previous versions, it was called as MATCH CODE
OBJECT (4.6c).
- Search help replaces match code objects.
- It is also called as F4 help, possible values help, possible
entries help, input help and hit list.
- Search help can be attached to.
1. Table field.
2. Structure component
3. Data element
4. Screen field
- Search help is also independent repository object. There are
a lot of built in search helps.
- Search help can be classified into two.
1. Elementary search help
It can be created using selection method as:
Database table (fields from single table)
Database view (fields from two tables with
inner join)
Projection view (fields from single table)
Help view (fields from two tables with left
inner join).
It provides F4 help for the table field.
It fetches the data related tables and displays as
hit list.
2. Collective search help

22

Sun Shine Technologies


It is a collection of more than one elementary
search helps.

1. ELEMENTARY SEARCH HELP:


PRE-REQUISITE:
- Table status must be active.
- Table field must have data element.
- Table must contain some data/entries which can be
displayed in the hit list to the end user.
PROCEDURE:
Go to SE11.
Select search help radio-button.
Provide search help name starting with Y or Z.
Click on create -> elementary -> continue.
- Provide short description.
- Specify data collection selection method as (table name
zb3_empmaster).
- Under dialogue behavior display values immediately.
- Provide search help parameter as empno or hit F4 and select
one.
Check import and export and LPOS AND SPOS as 1 and 1.
Here, data element comes by default.
Do the same things for EMP name.With LPOS AND SPOS as 2
and 2.
Save -> check -> activate and test it.
USAGE:
This is attaching the search help to table field
- Open the table
- Click on entry/check tab.
- Place the cursor on field name and click on search help tab.
- In dialogue box, provide the search help name which was
created (zb3_shelp).
- Continue.
- Dialogue box, click on copy.
23

Sun Shine Technologies


- You will notice message in the bottom and you will find
search help name under search help tab also origin of the
input (explicit created outside and implicit created
inside).
- Save -> check -> activate ->
- Utilities -> contents -> create entries (you find f4 help to
EMP no and f4 help to EMP name as well).
-------&-------ATTACHMENT OF SEARCH HELP TO DATA ELEMENT:
1. Open the data element in change mode.
2. Click on further characteristics tab.
3. Provide search help name and parameters name.
4. Save - > check -> activate.
NOTES ON SEARCH HELP:
- Search help parameter name and field parameter name
should be same.
- Import check box specifies to import the field values from
the database and populate into hit list.
- Export check box specifies to export values from hit list to
screen field, which is chosen by the user.
- LPOS specifies the current field appearing position in the hit
list.
- SPOS specifies the current field priority in the system
generated implicit select statement.
- SDIS: this is selected for the field, we cant define further
restrictions in the system proposed value restriction dialogue
box.
- Using modified check box we can change the data element
name (data type should match).
- Using default value option, we can provide default value to
hit list.
- SEARCH HELP EXIT: using this option, we can change the
standard behavior of search help.
- HOT KEY: we can choose the current search help if it is used
in collective search help.
24

Sun Shine Technologies


DIALOGUE BEHAVIOR (Dialogue types):
Display values immediately: values are displayed
immediately when user chooses F4.

Dialogue depends on set of values: specify this option,


if the F4 entries are more than 100.
Dialogue with value restrictions: if we specify the
option system generates value restriction dialogue box.
Based on the user input the result is displayed. Here, as
soon as the end user enters any value, the multiple
selection button appears immediately which will help in
filtration. If you want to change the selection option then
click on the multiple selection button, and again click on it
to change the selection option.
Creating (Elementary Search Help)Search Help

25

Sun Shine Technologies

Attachment to the table field.

26

Sun Shine Technologies

To check the search help:

27

Sun Shine Technologies

28

Sun Shine Technologies

2. COLLECTIVE SEARCH HELP:


- Combines more than 1 elementary search help.
- Each elementary search help is created using help view.
ZZSHELP
ZESHELP1

ZESHELP2

ZHELPVIEW1

ZHELPVIEW2

ZEMP

ZDEPT

EMPNO
EMPNAME
DEPT NAME
EMPADD
ADDR

DEPT NO
DEPT NAME

ZEMP1

ZDEPT1

EMP NO
DEPT NO
EMP NAME

DEPT ADD

DEPT

ZZSHELP
ZESHELP1

ZESHELP2

ZHELPVIEW1

ZHELPVIEW2

MAKT
MARA

MARA

MARC

29

Sun Shine Technologies


- Go to SE11, under search help collective search help.
- Short description.
- Under definition -> search help parameters -> first provide
key fields (matnr, spras, etc.)
- Now provide the remaining fields (Repeated fields should not
be taken).
- Click on included search helps tab.
- Under search help -> zb3_shelp1, zb3_shelp2.
- Select first elementary search help and click on parameter
assignment - > yes -> click on copy.
- Select second elementary search help -> click on parameter
assignment -> yes -> click on copy.
PRE-REQUISITIES:
- At least 2 elementary search helps.
- Procedure:
o In the definition add the fields from both elementary
search helps (no duplicate field names).
o Under included search help tab add elementary search
help.
o Select elementary search help and click on parameter
assignment (system proposing respective elementary
search help parameters to collective search help
parameters),
ADDITIONAL OPTIONS:
o Using hidden option, we can hide any elementary
search help tab in the final display.
o After activation, we can attach collective search help to
table field or data element.
- Creating (Collective Search Help)Search Help
First we have to create the Elementary search helps.

30

Sun Shine Technologies

Then go to Data base table for which you want to assign the
collective search help.
31

Sun Shine Technologies

32

Sun Shine Technologies

STRUCTURES:
- Structure is a data type defined in ABAP Dictionary.
- Structure is a collection of components with different data
types.
- Structure is an independent repository object.
- Structure is included into data base table.
- One structure can be included into multiple database tables
(reusability).
- Structure does not contain data.
- When structure components are included in table, it becomes
table fields (data maintenance is possible).
- We can attach check table or search help to structure
component.
- It is a combination of fields.
- Structure can hold only one record at a time.

33

Sun Shine Technologies


CUSTOM CREATION OF STRUCTURE:
- Go to SE11 -> data type -> provide structure name starting
with Y or Z -> click on create -> select structure and continue.
- Provide short description.
- Under COMPONENTS TAB -> provide components name and
components type.
- Save -> Check -> Activate.
Now the structure is ready to be used.
----------------------------------------------------------------&---------------------------------------------------------------INCLUDING THE STRUCTURE INTO TABLE:
- Under database table, open the table in which you want to use
this structure.
- Provide .include in field column and provide structure name in
data element tab and press enter.
STRUCTURE TYPES:
1. FLAT STRUCTURE: is a collection of many components. It
does not consist of reference types/structures by using
.include.
2. NESTED STRUCTURE: one of the structure components is
reference to another structure.
o Including a structure while creating a structure by using
.include is called nested structure.
3. DEEP STRUCTURE: one of the structures is referring to table
type.
Notes:
1. In standard table, if you find any field in blue color, then it
means that the particular field belongs to include. And that
field does not belong to that table.
APPEND STRUCTURE:
- For a standard table, we cannot open in change mode if we
want to add some fields but the solution for this is Append
Structure.
o It is used to add additional fields to standard table (table
enhancement).
34

Sun Shine Technologies


o Without modifying the existing table structure, we can
add additional fields to standard table at the bottom.
PROCEDURE FOR APPENDING FIELDS TO STANDARD TABLE:
- Open any standard table in display mode.
- Click on append structure tab.
- Provide the append structure name starting with ZZ and
continue.
- Provide short description component name component type
(name and type should start with Z).
- Save check activate.
- Fields are added at the bottom.

DIFFERENCE BETWEEN INCLUDE STRUCTURE AND APPEND


STRUCTURES:
.INCLUDE
APPEND
- It is used to include fields to
- It is used to add additional custo
database table or structure.
fields to database table.
- It is reusable.
- Is not reusable.
- Can be added at any row of the
- It is always at the bottom of the
database table.
database table.
- It is possible for custom table only.
- It is possible for standard tables
- Append structure is not possible
cluster and pooled tables.
- For transparent tables, which co
long char (datatype).**

Difference between value/check tables:


Value table and check table is to check value is existing or not.
Value table given at Domain Level and will not restrict.
Check table given at field value.
WORKING WITH CURRENCY / QUANTITY FIELDS:
- SAP is global software and it is used across globe. Whenever
currency values are entered, it must be followed by currency
keys (data type CURR must be followed with CUKY fields).

35

Sun Shine Technologies


- For CURR field we have to provide ref table name and ref field
name.
- Generating F4 help, click on entry help /check tab.
- Place the cursor on waers and click on foreign key.
- You can use TCURC as check table.
- Whenever quantity values are entered, it must be followed by
unit of measurement (data type QUAN followed by UNIT).
- For QUAN fields we have to maintain ref. table name and ref.
field name.
Views :
Is a virtual table where we can store the data from multiple
tables.
There are 4 types of views:
1) Data Base View.
2) Projection View.
3) Maintenance View.
4) Help View.
DATABASE VIEW:
- It is a collection of data from more than 1 logically related
database tables.
- DB view implements inner join while fetching the data.
- Selection conditions are possible.
- Maintenance status read only.
- Are used to find out table relationship.
- Are used alternative for inner join.
PROCEDURE TO CREATE DATABASE VIEW:
- Under table/join condition tables enter kna1, knb1 and click
on relationship.
- Select the field and continue.
36

Sun Shine Technologies


- Click on view fields.
- Click on table fields and click on kna1 select only key fields first two fields.
- Click on table fields and click on knb1 select only key fields dont select the fields with the same name so only select
bukrs.
- Now again click on tables fields - kna1 select non-key fields
(4-5 fields) (note: here key fields are already selected, dont
uncheck them check the other fields that are required).
- Now again click on tables fields knb1 - select non-key fields
(4-5 fields).
- Save check activate.
- Utilities content Extra:
We dont have to enter join conditions here, system will propose
it.
Click on selection condition:
Kna1 kunnr - <= 0000000200
If you want to add one more condition then last tab enter AND
Kna1 land1 EQ US (case-sensitive should be capital letters
only)
If you want to add one more than last tab AND
Kna1 bukrs EQ 5000
Note:
- There would be relationship even if the date element name is
same or domain name is same.
- Field name might be different even then there would be some
relationship and that is why is shows the relationship.
- Field name should not be same under view fields tab.
- We should not select similar fields under views.
- Case sensitive, if its capital letters in database table then even
in selection condition, it should be capitals.
- And comparison value values must be in single quotes.
- Extra create statement - generates system ********
37

Sun Shine Technologies


- Extra change view type used to change the view type to
another type.
- Database view can be created on using single table also and
maintenance is also possible for standard table but we dont do
that.

38

Sun Shine Technologies

39

Sun Shine Technologies

40

Sun Shine Technologies

PROJECTION VIEW:
- It is used to hide some data of single table and in turn display
other data.
- It is always created on single table only.
- Selection conditions are not possible.
- Maintenance status read only. (it is possible but we dont do
it)
- It is used in the programs whenever we require single table
particular fields data.
PROCEDURE TO CREATE PROJECTION VIEW:
- Go to SE11 > select view > zb3_pview > create >
projection view > copy.
- Provide short description and basis table (mara).
- Click on tables field select key fields and required fields
copy.
- You will see all the selected tables under view fields.
- Save check activate.
- Utilities table content all the fields will be displayed.

41

Sun Shine Technologies

42

Sun Shine Technologies

MAINTAINENCE VIEW:
- It is used to fetch the data from more than one logically related
table.
- It also used to maintain data (insert, change, delete) into
several tables.
- It implements left outer join.
43

Sun Shine Technologies


- Working with maintenance view is a 2 step procedure:
1. View creation
2. Table maintenance generator
- Selection conditions are possible.
- Maintenance status is: read, change, insert, delete.
OVERVIEW

SINGLE SCREEN

READ
CHANGE
DELETE
INSERT
MAKT

MARA
- In the above picture, in first page which is overview page, the
user can fetch data from more than one table and he also has
access to read, change and delete data from database
permanently.
- And in the second page which is single screen page, he can
insert new entries.
- Table maintenance generator is used to create table
maintenance program to add, modify or delete records in the
database table. This can be accessed using transaction SM30,
SE54 or in SE11 -> menu utilities -> table maintenance
generator.
CUSTOM MAINTENANCE VIEW CREATION:
- Go to SE11,
- Provide view name starting with z.
- Create
- Maintenance view copy
- Short description
- Provide table name as MAKT under table/join.
- Click on relationship.
- Click on view fields, notice that left side system key fields
automatically because of left outerjoin.
- Select key fields from right side table.
44

Sun Shine Technologies


- Select non-key fields from left and right table.
- Save check.
- Now if you go to contents under utilities, you will not get result
so.
- Now step 2, which is table maintenance generator.
- Utilities -> table maintenance generator -> (SE55).
- Provide authorization group as &NC& (hit F4).
o Authorization: we are editing database table.
Authorization group is created by BASIS people and
provided to us by them. It is used to restrict the
unauthorized users while maintaining data.
o Function group: (give table/view name) is responsible to
maintain all the changes done by the users.
1. Maintenance type:
a. One step if it is one step then it is single step. Read, change,
insert, delete operations are possible from overview screen only.
All possible in one screen.
b. Step Two uses overview screen for read, change, and delete
operations. It uses single screen for insert.
2. In SAP, every screen is identified by unique number.
3. Screen number consists of 4 digits.
a. Valid screen number range 0001 to 9999.
b. Out of these, SAP reserved screen numbers are 1000 to 1010.
c. Customer screen number range 1 to 999 and 1011 to 9999.
d. Total numbers of screen are 9988.
4. You can click on find screen numbers propose screen number ->
continue.
5. Recording routine: if it is ON then system proposes, work bench
request for modifications.
6. Click on create save back.
7. Utilities -> contents -> you will get result.
8. Click on change/display button.
9. Change something.
10. It proposes request change number.
11. Continue
12. Changes here are permanent.
13. Click on new entries (it is the single screen):
45

Sun Shine Technologies


T.Codes:
SE55: table maintenance generator.
SM30: maintain table views.
Through maintain table views.
1. Go to SM30 table/view maintenance,
2. Table name : makt
3. Click on - Find maintenance dialogue.
Whenever custom table is created, maintain table maintenance
generator immediately (to protect table entries against changes).
TABLE MAINTENANCE GENERATOR &ITS EVENTS
By using this we can insert multiple records in to the table at one
shot.
What is table maintenance generator?
Table Maintenance Generator is a tool used to customize the
tables created by end users and can be changed as required, such
as making an entry to that table, deleting an entry etc.
In other words, table maintenance generator is a user interface
tool which is used to change the entry of the table or delete an
entry from the table or create an entry for the table.
Prerequisite
To make this feature work care should be taken while creating the
database table that in the 'Delivery & Maintenance' tab, the 'Table
View Maint.' should have the "Maintenance allowed" property
defined.
Transaction Codes
SE54: Generate Table Maintenance Dialog
SE55: Table view maintenance DDIC call
SE56: Table view display DDIC call
SE57: Deletion of Table Maintenance
SM30: Maintenance Table Views:
Implementation of table maintenance generator for a
custom table
Go to SE11 and create a table with the fields as per the
requirement.
46

Sun Shine Technologies


In table change mode, click on Utilities and then click on Table
maintenance generator.

Following screen will be displayed for setting up the Maintenance


generator

47

Sun Shine Technologies


Following are the available options, choose them accordingly
Authorization Group : If the table needs to be maintained by only
particular group of people, then the Authorization group needs to
be filled otherwise fill it as &NC&. To maintain the authorization
group refer to SU21.
Function group is the name to which the generated maintenance
modules will belong to.
Generally Function Group name can be same as table
name.
Maintenance screens: Maintenance can be done in 2 ways.
1. Maintenance & Overview both on one screen
2. Maintenance on one screen and overview will be on another
screen.
Provide the desired screen numbers.

Propose screen number(s) means what we have to enter in to the


overview screen box.
48

Sun Shine Technologies

After the above settings click on the create button in the Table
maintenance generator.

49

Sun Shine Technologies

After saving the changes, go to SM30 for maintaining the table.

50

Sun Shine Technologies

If we found any deviations in the headers like fields then we can


change those settings from structure level of table only. At that
time we have to delete the Table maintenance generator.
Otherwise we can get previous Skelton only in SM30 (Maintain
Table Views.)

HELP VIEW:
- Also used to fetch data from more than one table and display
output.
- It implements left outer join.
- Selection conditions are possible.
- Maintenance status is read only.
- It is used as selection method while creating elementary
search help.

51

Sun Shine Technologies

52

Sun Shine Technologies

53

Sun Shine Technologies

LOCK OBJECT:
- Lock object is used to restrict the simultaneous access of
database table entry by multiple users at a time.
54

Sun Shine Technologies


- SAP supports record level or row level locking.
- Lock object can be defined in ABAP dictionary initial screen
as a repository object.
- User defined lock object names begin with EY or EZ.
- We can lock primary table entry as well as dependent table
(secondary table) entry also.
- Lock happens by default on key fields.
- Lock modes (or) lock types:
o E exclusive/write lock if we set lock mode as E only
that particular user can perform all operations. Other
shared or exclusive locks are rejected. Others, it will not
be visible.
o S shared/read lock if the user sets lock type S, then
all the users can access the table entry. Modification by
any user is not allowed.
o X Exclusive not cumulative lock this is exclusive lock
only but it is used to perform the lock for one time only.
o Optimistic Lock Once the lock object is defined centrally and activated it
generates two function modules.
1. Enqueue_<lock object name> : this function module sets the
lock on particular table only.
2. Dequeue_<lock object name> : this function module release
the lock.
Lock mechanism handled by Enqueue work process.
PROCEDURE:
1. Define lock in ABAP dictionary.
2. Go to SE38, create ABAP executable program and call
Enqueue function module and execute it.
3. Perform the operation like update, modify, delete.
4. Check locks entry using T.code: SM12.
5. Release the lock by calling function module Dequeue.
PRE-REQUISITIES:
- Lock happens on key field only.
55

Sun Shine Technologies


PROCEDURE:
1. Go to SE11, select lock object name starting with EY or EZ.
2. Click on create.
3. Provide short description.
4. Under TABLES PRIMARY TABLE NAME zb3_empmaster.
5. LOCK MODE E WRITE LOCK.
6. Under LOCK PARAMETER TAB save check activate.
7. Go to MENU LOCK MODULES
8. Go to SE38, provide the program name starting with Y or Z.
9. Create short description type as executable program
save as local object.
10.
Click on PATTERN (CTRL+F6) -> CALL FUNCTION
ENQUEUE_EZLOCK_OBJ.
11.
Uncomment: exporting
12.
Mode = E. (Exclusive, shared or exclusive not
cumulative).
13.
Mandt
= sy-mandt
14.
Empno = 0001.
15.
Other parameters are not required, you can comment
them.
16.
Go to SM12, click on list to check.
17.
Now to unlock it -> call function module
dequeue_ezlock_obj.
---------------&--------------PERFORMANCE FACTORS IN DATABASE TABLE:
1. BUFFERING: it is available under TECHNICAL SETTINGS TAB.
2. SECONDARY INDEX CREATION:
3. LOG DATA CHANGS:
BUFFERING:
1. It is available under TECHNICAL SETTINGS TAB.
2. Every application servers consists of local buffer.
3. Buffer stores temporary data, volatile data.
4. By using buffering, it picks the data from buffer directly so it
saves lot of time. And buffering will be provided for master
data/tables because there is a chance of losing data. (In one
way it is useful but there is also a chance of losing data).
56

Sun Shine Technologies


5. TABLE -> TECHNICAL SETTINGS ->BUFFERING TAB -> under
this:
a. BUFFERING NOT ALLOWED: if we select this option table
entries are not buffered.
b. BUFFERING ALLOWED BUT SWITCHED OFF: table entries
are buffered, select this option if we dont know the
number of entries loaded into buffer.
c. BUFFERING SWITCHED ON: select this option, if we are
aware of expected entries into buffer. Under this, you
also have to specify the buffering type also.
i. FULLY BUFFERED: picks all the data and stores in
buffer. All the table entries are loaded into buffer
even if we select for single record also.
ii. SINGLE RECORD BUFFER: picks only one data and
stores in buffer (the result of select single
statement is single record).
iii. GENERIC AREA BUFFER: picks only specified data
and stores in buffer.
1. By specifying key fields, we are defining the
generic key.
2. Only generic key matching entries are loaded
into buffer.
3. Generic key is a combination of left justified
key fields.
Note: BY PASS BUFFERING is used to skip buffering and go to
database table.
INDEX:
- Primary index is created by SAP.
- It is used to improve performance. It is a data base
management system (DBMS) concept for faster retrieval of
data. And it is of two types:
o Primary key provide uniqueness and avoid duplication
of records. And we dont create primary key, it is
already created in database tables. All the key fields in
a table are called primary key.

57

Sun Shine Technologies


o Secondary indexes or secondary key to improve the
performance of a query while searching for records. We
create secondary key in SE11 and inform BASIS TEAM.
Note:
SAP recommends taking indexes as the last option to increase the
performance and even if you use this, then make sure that you
are not using not more than 4-5 indexes maximum. And in real
time, if you need to create indexes then write an email to the
basis people regarding the same.
SECONDARY INDEX CREATION:
- Index makes faster access of database table entries.
- Select statement uses index of the table while fetching the
data.
- Index works using binary search.
- Index creates field values in sorted order.
- We can create 9 index keys.
Whenever a database table is created and activated primary
index automatically creates the system on key fields.
Path to view the indexes of the table.
UTILITIES -> DATABASE OBJECT -> DATABASE UTILITY -> click on
INDEX TAB.
We can create secondary indexes based on our requirements on
non-key field.
Secondary index creation steps:
1. Open the table in change mode.
2. Click on INDEX tab.
3. Create index and continue.
4. Secondary index creation.
LOG DATA CHANGES:
We can check the checkbox under technical settings tab of any
table.

58

Sun Shine Technologies


Once this check box is enabled, system records all the changes
done by the users on the current table and final output is
displayed is stored as table history.
This is used if you want to store historical/previous data
which means before making changes. E.g. If the student
number was 1234 earlier and later if it was changed to 4567
then this log data changes is used to check what was the
previous data like in this e.g. it was 1234.
And the transaction code is SCU3 to see the previous values.
After entering the T.code you need to give the table name.
T.code to view table history: SCU3.
(in real time we will not use this, because it will slow down
the access and sometimes it might also get locked even
though if the other users are working with different
applications)
ONLY CONTENTS: is used to remove include and display all the
fields in it.
E.g. Under fields, for address, we can use include and give the
address under include. So there you will see only include and you
will not find the components under include but include has a drop
down/expand option there. Once you click on expand, you will see
the entire address. And here, if you click on ONLY CONTENTS, then
you will not see the include field but directly you will see the
entire address/components under include.
IMPORTANT: if you make some changes to the key fields here,
then it will impact the data in database. And you will not be able
to activate it. In certain cases, you need to follow below path.
UTILITIES -> DATABASE OBJECTS -> DATABASE UTILITY -> click on
activate and adjust records.Or, you can go to SE14.
PACKAGE (SE21)
- It is a collection of objects (repository objects). It was also
called as development class (old version).
- SAP defined objects belongs to SAP defined packages.
- User defined objects belongs to either $tmp (or) custom
package.
59

Sun Shine Technologies


- Custom package can be created by BASIS consultants using
package builder.
- $tmp is a default package defined by SAP.
- $tmp stores all the local objects.
- $tmp objects are never transportable.
- Zpackage - Custom packages only can be transportable.

There are two types of development clauses


(Packages):
1) Transportable Development Clause.
2) Non Transportable Development Clause.
Transportable Development Clause:
If we store our program in to transportable development clause
then we can transport the program to different systems.
Non Transportable Development Clause:

60

Sun Shine Technologies


If we store our program in to non-transportable development
clause then we cant transport those programs from one system
to other system.
TRANSPORT ORGANIZER:
Create request (or) change request:
It is generated by the system automatically, based on
system internal sequence number.
It is useful to identify the object.
It records the username, client number, project name,
object status, timestamp.
It is useful in the project management.
- Request number:
<Instance or SID> K <9nnnn>.
Ex: DEVK900504
- Instance is always 3 characters ex: ECC, DEV, QAS, DMO and
PRD.
- K Specifies constant.
- Request number is always begins with 9 maximum it
consists of 6 digits.
Note:
Whenever you save in package, it always shows previous request
number and short description so be careful.
Requests are of 3 types:
1. Workbench request:
a. Whenever the object is saved under package, then
system proposes workbench request number.
2. Customizing request:
a. Whenever standard SAP is modified (or) new data is
entered into SAP then system proposes customizing
request number.
3. Transport request:
a. It is generated by the system while transport at BASIS
level.
Workbench request:
61

Sun Shine Technologies


- System always proposes the list operation concern request
number and description in the dialogue box.
User can perform 3 operations:
a. If we want to save the current object under the same
request number and click on continue.
b. If you want to maintain new request number then click
on create request option.
c. If you want to assign the current object to previous
request number then click on own request then choose
the existing request.
SE09: Transport Organizer
- It organizes all the customizing and workbench request.
- It maintains list of all the customizing and workbench
requests.
- If the object is available under modifiable section, i.e.
modifications allowed.
- Once it is released, it will be moved to release section.
- Once the object is released, modifications are not allowed.
- Release strategy:
We have to release all the sub tasks under request.
Finally request is released.
- In general request is created and released by leads and it is
given to the users.
Task is created and released by team.
Note:
We need to release the Task first and make sure the objects are
active.
Then the request is released by leads.
Request task package.
In golden client, always keep a copy.
Procedure:
Place the cursor on task and click on release icon in tool bar
(truck symbol).
Place the cursor on request and click on release (generally leads
do this).
62

Sun Shine Technologies


Version management:
- Object concern changes can be maintained as different
versions.
- Object along with different versions are permanently stored
under version database.
- We can retrieve any version and view is possible.
- We can compare any two versions of the object is also
possible.
- For script and smartforms, version management is not
possible.
Note:
- There are no versions in the version database default.
- Menu path to create version: utilities menu -> version ->
generate version.
- Menu path to view the version: utilities menu -> version ->
version management.

-------------------------------------------------------------------------------------------------------------------------------------------PROGRAMMING
-------------------------------------------------------------------------------------------------------------------------------------------ABAP ADVANCED BUSINESS APPLICATION
PROGRAMMING:
It
It
It
It
It
It
It
It
It

is
is
is
is
is
is
is
is
is

4th generation language.


high level language.
structure programming language.
procedure oriented programming language.
event driven programming language.
object oriented programming language.
not case sensitive language.
SAP proprietary programming language.
used to develop SAP specific in house applications.
63

Sun Shine Technologies


Using 40% assembly language and 60% of C, C++ ABAP runtime
environment is developed.
ABAP EDITOR: SE38.
It is used to develop a custom program or to view the standard
program.
SA38: only to execute any program. You cannot write or change
the program here.
ABAP Editor is closely integrated with ABAP development
workbench.
ABAP Program is also independent repository object.
Sample program
1. Go to SE38.
2. Provide the program name starting with Y or Z.
3. Provide short description with some meaningful tittle.
4. Specify the ATTRIBUTE -> TYPE -> EXECUTABLE PROGRAM.
5. Save it as local object.
6. Type some write statement in single quotes (e.g. write
PRAVEEN.)
Save -> check -> activate -> execute.
Output PRAVEEN

PROGRAM TYPE:
1. TYPE 1 - EXECUTABLE PROGRAM (self-executable program)
2. TYPE I include program
3. Type M - module pool program
4. Type S subroutine pool
5. Type F function pool
6. Type K class pool
7. Type J interface pool
8. Type T type pool
9. Type X XSLT program (used to convert ABAP program to
XML and vice versa).
ABAP EDITOR STANDARDS:
- User defined program name must begin with Y or Z.
64

Sun Shine Technologies


- Every program must belong to one program type.
- Every program must have first statement as REPORT or
PROGRAM.
- Every statement must begin with a key word and end with
period.
- Every operator and operand before and after, we have to
provide space. E.g. A = B + C.
- Increment N1 = N1 + 1. Decrement N1 = N1 1.
ARTHMATIC OPERATION:
o Addition +
o Subtraction
o Multiplication *
o General Division /
o Modules mod (provides remainder)
o Division div
o Power **
LOGICAL OPERATORS:
o AND
o OR
o NOT
RELATIONAL OPERATORS:
o EQ =
o NE <> >< (here both are valid)
o GT >
o GE >=
o LT <
o LE <=
o LIKE
o NOT LIKE
o IS INITIAL
o BETWEEN..AND
BASICS:
Write..

(This is used for output statement)


65

Sun Shine Technologies


Write / jai.
Write / jai color 2.
from 1 to 7)
Write / 10 jai.
Jai
ULINE.
ULINE /5(7).
ULINE AT /5(4).
SKIP.
line).
SKIP 2.
SKIP TO LINE 15.
lines from the top.

(/ - provide new line)


(Color 2 provides colors and the range is
(10 - <col_pos>)
(Strings are placed with in single quotes)
(One complete horizontal line)
(<col_pos>, length)
(This keyword/statement is to skip one blank
(SKIP <n> provides number of blank lines.
(SKIP TO LINE <N> : it skips first 15

COMMENTS:
- These are used to describe some tables or variables as
documentation.
- It increases the readability of source code.
- Single line comment
o Place * in the first column position (*write /jai.)
- Multiple write comment
o Select multiple lines press ctrl + < for comment and
press ctrl + > to uncomment.
o Or select the line and right click and comment or
uncomment.
- In line comment:
o Within the line partial string can be commented using
Double quotes.
KEYWORDs:
DATA is used to declare variables, work areas, internal tables.
TYPES is used to define USER DEFINED (custom) elementary
data types, structure types, internal
Table types.
VARIABLE: e.g. Kunnr is a variable, but its value changes. It is not
constant.
CONSTANTS is used to define constant variable.
FIELD-SYMBOLS is used to declare field symbols.
WRITE is used to display output.
66

Sun Shine Technologies


We can create the selection-screen using 3 keywords.
1) Parameters
Parameter is a keyword which accepts the
input at runtime.
Syntax: parameter <Para name> type <data type>.
Parameter <Para name> like <database table
name>-<fieldname>.
Parameter name should not exceed 8 character lengths.
Parameter cannot accept float data type instead we can use
packed decimal (p).
Obligatory: It is a keyword which is used to provide the
input field as mandatory.
Syntax: parameter <Para name> type <data type>
obligatory.
Default: It is a keyword to provide the default values to the
input variable.
Syntax: parameter <Para name> type <data type> default
<value>.
2) Select-options:
Select-options are a keyword which accepts
single value, multiple range, multiple single values, single
ranges and multiple ranges.
Syntax: select-options <name of select options> for
<variable>.
Example: data v1 (4) type c.
Select-options s_v1 for v1.
The name of the select options acts like an internal table
with headerline.
That means the name of workarea and the name of the
internal table are similar name of the select-option.
Components of select options.
67

Sun Shine Technologies


1) Low -> lower limit value of the select-options.
2) High -> upper limit value of the select-options.
3) Sign -> include (I) or Exclude (e)
4) Option -> between (BT)
Not between (nb)
Equal (eq)
Not equal (ne).
By default select-options contains sign as include an
option as between. No intervals: It is used to remove the
intervals.
Sy: select-options s_v1 for v1 no intervals.
No-extension: It is used to remove the extension.
Sy: select-options s_v1 for v1 no-extension.
3) Selection-screen.
Selection-screen is also used to design the
selection screen with a frame.
Sy: selection-screen: begin of block <block name> with
frame title text-<no>.
-----.
-----.
Selection-screen: end of block <block name>.
Text no is a three digit number where we can enter the
title for the title
for the text.
4) Selection-screen: begin of line.
-----Selection-screen: end of line.
It is used to display selection screen components (radio
buttons or check boxes) in a single line.
5) Selection-screen: comment x(y) text-<no>.
6) Check box in the selection screen.
Sy: parameters <checkbox name> as checkbox.
7) Radio Buttons in the selection screen.

68

Sun Shine Technologies


Sy: parameters <radio button name> radio button group
<group name>.
internal tables
internal table is the collection of fields with different data types
where we can store the multiple records temporarily.
Internal tables are structured data types provided by ABAP/4.
Internal tables cannot be accessed outside the program
environment.
Purpose of internal tables
1.Internal tables are used to reorganize the contents of database
tables according to the needs of your program
2.Internal tables are used to perform calculations on subsets of
database tables.
3.The number of lines in an internal table is not fixed.
4.Internal tables exist only during the run time of a program.

In the internal table we have two fields body and header


Whenever we are assign the values first we will assign the values
to the header not to the body
Whenever we are assign the second value then first value will be
override by the second record to avoid this we use append
keyword so the first value will be assign to body
Data :begin of <Itab name> Occurs N,
<field name1> type <data type>,
<field name2 > type <data type>,
. ..
.
69

Sun Shine Technologies


<field name N> type <data type>,
End of <Itab name>.
Occurs N means we are allocate the memory dynamically for
multiple fields
Ex:
*// declaration of internal table
data: begin of itab occurs 0,
custno(10) type n,
cname
type char10,
city
type char20,
qty
type p decimals 2,
end of itab.
*// assign value to the itab
itab-custno = 1.
itab-cname = 'sati'.
itab-city ='nlg'.
itab-qty ='10.5'.
append itab.
itab-custno = 2.
itab-cname = 'gsr'.
itab-city = 'sec'.
itab-qty = '15.2'.
append itab.
*//display oput
loop at itab.
write: / itab-custno,itab-cname,itab-city,itab-qty.
endloop.
Note:
In the internal table we are storing more than one record so if we
want to print all the records the we will write the WRITE statement
in between the LOOP..ENDLOOP.

70

Sun Shine Technologies


Nested structures:
Structure with in the another structure is called nested structure
We can declare the nested structure in 3 ways
Way1:
*&---------------------------------------------------------------------*
*& Report ZEBRA7
*&---------------------------------------------------------------------*
REPORT ZEBRA7 NO STANDARD PAGE HEADING.
*// declare the first structure
data : begin of stru1,
stuno type i,
stuname type char10,
end of stru1.
*// declare the second structure
data : begin of siva ,
sivaco type char12,
sivaemp type char12.
include structure stru1.
data : end of siva.
*// assign the values to the structure
stru1-stuno = 239.
stru1-stuname = 'ram'.
siva-sivaco = 'local'.
siva-sivaemp = '234'.
*//output
write: stru1-stuno, siva-sivaco, siva-sivaemp.
Output:
239 local

234

Way 2:
*&---------------------------------------------------------------------*
*& Report ZEBRA7
*&---------------------------------------------------------------------*
71

Sun Shine Technologies


REPORT ZEBRA7 NO STANDARD PAGE HEADING.
*// declare
data : begin of stru1,
stuno type i,
stuname type char10,
end of stru1.
data : begin of emp ,
empno type i,
empname type char12,
lc_stuct like stru1,
end of emp.
*// assign
emp-empno = 100.
emp-empname = 'REDDY'.
emp-lc_stuct-stuno = 20.
emp-lc_stuct-stuname = 'ram'.
*//output
write: emp-empno, emp-empname, emp-lc_stuct-stuno, emplc_stuct-stuname.
Output:
100

REDDY

20

ram

Way 3:
*&---------------------------------------------------------------------*
*& Report ZEBRA7
*&---------------------------------------------------------------------*
REPORT ZEBRA7 NO STANDARD PAGE HEADING.
*// declare structure
data : begin of emp ,
empno type i,
empname type char12,
begin of stru1,
stuno type i,
stuname type char10,
72

Sun Shine Technologies


end of stru1,
end of emp.
*// assign values to structure
emp-empno
= 100.
emp-empname
= 'REDDY'.
emp-stru1-stuno = 20.
emp-stru1-stuname = 'ram'.
*//output
write: emp-empno, emp-empname, emp-stru1-stuno, emp-stru1stuname.
Output: 100

REDDY

20

ram

New way to create the structure and internal table:


Bu using TYPES keyword we are declare the structure and the
internal table
TYPES: is keyword is used to declare the user define data types
Syntax for creating our own data types:
TYPES: Begin of <Types name>,
Field1 Type <data type>,
Field2 Type <data type>,

..,
Field N Type <data type>,
End of <Types name>.
Syntax for declare the structure by referencing the TYPES:
DATA : <Structure Name> Type <Types Name> .
Syntax for declare the internal table by referencing the TYPES:
DATA : <Itab name> Type table of <Types Name>.
73

Sun Shine Technologies


Note:
1.In the old style we can assign the values to the internal table
directly and we can display the data from internal table.
2.In the new style directly we cant assign the values to the
internal table as we as directly we cant display the output from
the internal table
3.If we want to assign the values to the internal table first we
have to assign the values to the work area(Structure) then by
using APPEND keyword we can assign the values from work area
to internal table
4.If we want to display the data from the internal table first we
pass the data from internal table to work area from work area we
can display the values as output.
Ex:
*&---------------------------------------------------------------------*
*& Report Zvishnu
*&---------------------------------------------------------------------*
REPORT Zvishnu no standard page heading.
*//declaring types
types : begin of ty_emp,
number(10) type n,
name(10) type c,
street(10) type c,
city(10) type c,
amount(10) type p decimals 2,
end of ty_emp.
*//declaring internal table
data : lt_emp type table of ty_emp.
*//declaring structure
data : ls_emp type ty_emp.
*//assigning values to the structures
*//First Record
74

Sun Shine Technologies


ls_emp-number = 1.
ls_emp-name = 'pradeep'.
ls_emp-street = 'mehdipatnam'.
ls_emp-city = 'hyderabad.
ls_emp-amount = '1000.20'.
*//Appending the values from work area to internal table
append ls_emp to lt_emp.
*//second record
ls_emp-number = 2.
ls_emp-name = 'pradeep2'.
ls_emp-street = 'mehdipatnam2'.
ls_emp-city = 'hyderabad2'.
ls_emp-amount = '102.20'.
*//Appending the values from work area to internal table
*//3rd record
append ls_emp to lt_emp.
ls_emp-number = 3.
ls_emp-name = 'pradeep3'.
ls_emp-street = 'mehdipatnam3'.
ls_emp-city = 'hyderabad3'.
ls_emp-amount = '130.20'.
*//Appending the values from work area to internal table
append ls_emp to lt_emp.
*//desplay output
write : / 'number', 20 'name', 40 'street', 60 'city', 80 'amount'.
uline.
loop at lt_emp into ls_emp.
write : / ls_emp-number, 20 ls_emp-name, 40 ls_emp-street, 60 ls
_emp-city, 75 ls_emp-amount.
endloop.
Output:

75

Sun Shine Technologies


Some other way Declare the work area and the internal tables :
Way1:
1.if we want to declare some of the fields from any one of the
database tables
Syntax:
DATA : Begin of <work area>,
List of fields,
End of <work are>.
Ex : data : begin of wa_t001,
Bukrs like t001-bukrs,
End of wa_t001.
Declaring the internal table:
Ex : Data : lt_too1 like table of wa_t001.
Way 2:
If we want to declare the internal table with all the fields of any
database table
Syntax for declare the work area:
Data: Begin of <Work area name>.
Include structure <DB table name>.
Data : End of <work area name>.
Ex:
Data : Begin of wa_T001.
Include structure T001.
Data : end of wa_T001.
Syntax for declare the internal :
76

Sun Shine Technologies


Data : <Itab> like table of <work area>.
Ex : lt_t001 like table of wa_t001.
Way 3:
Declaring the work area and internal table by referencing the DB
table:
Data : wa_T001 type T001.
Data : lt_T001 type table of T001.
(or)
Data: lt_t001 type table of T001.
Data: Wa_T001 like line of lt_T001.
Way 4:
Declaring the work area by using the TABLES keywords
Syntax: TABLES <Table name>.
Note: By default the TABLES keyword create one work area with
the name of database table name and also contains all the fields
of DB table
Ex: TABLES T001.
Internal table and work area by referencing the Global structure :
Syntax for declare the work are by referring global structure :
Data : <Work area name> Type <Global structure name>.
Syntax for declare the internal table by referring global
structure :
Data : <Internal table> Type table of <Global structure name>.
Syntax for declare the internal table by referring global table
type:
Data : <Internal table> Type <Global Table type>.
77

Sun Shine Technologies


Note: while creating the internal table by referring the global
internal table no need to use the TYPE TABLE OF key word
Syntax for declare the work are by referring global table type :
Data : <Work area > like line of <Internal table name>.
Initializing techniques:
1.Clear
2.Refresh
3.Free
Clear:it clears the content of the work area as well as internal
table
Syntax: clear <Work area>.
Clear <Itab>.
Note:
in real time we never use CLEAR to clear the content of the
internal table. If we are working with internal table with header
line then name of work area as well as the name of the internal
table are same in this case also CLEAR clears the content of the
work area only.
If we want to clear the content of the internal table then we use []
for internal table
Syntax: clear Itab[].
Refresh:
Always clears the content of the internal table only
Syntax : Refresh <Itab>.
Free: Act like refresh
Note:

78

Sun Shine Technologies


1.Refresh clears the content of the internal table not the memory
which is allocated for that
Whereas FREE clears the content of the internal table as well as
memory which is allocated for that
Syntax: Free <Itab>.
Types of internal table:
There are 3 types of internal tables are there
1.Standard internal table
2.Sorted internal table
3.Hased internal table
Standard internal table:
1.It accept the duplicate records
2.Here all the fields non-unique fields
3.Pushing data from work area to internal table is always through
APPEND keyword
4.Searching of the records is linear search
Syntax:
Data : <Itab> Type/like standard table of <work area>.
Append: append is a keyword to transfer the data from work area
to internal table
Syntax: Append <work area> TO <Internal table>.
Sorted internal table:
1.It may or may not accept the duplicate records
2.Here we must specify one field as the unique / non-unique
3.pushing the data from work area to internal table is always
through INSERT key word
79

Sun Shine Technologies


4.Searching of the records by using the binary search
Syntax:
Data : <Itab> like/type sorted table of <work area> with
Unique/non-unique key
<Field1><field2>.
Ex: Data lt_T001 Type sorted table of wa_T001 with non-unique
key bukrs.
Insert:
It transfer the data from work area to internal table based on the
key field
Insert <work area> into table <internal table>.
Hashed internal tables:
1.It wont accept duplicate records
2.Here we must specify at least one field as unique field
3.pushing the data from work area to internal table is always
through COLLECT key word
4.Searching of the records by using the hash algorithms (Midpoint
algorithm )
Syntax:
Data: <internal table> like/type hashed table of <work area>
with unique key <field1><field2>.
Collect:
It checks the internal table whether the inserted record is
available or not, if not it act like a insert otherwise it adds the
numeric fields from work area to numeric fields in the internal
table
Syntax:
Collect <work area> into table <internal table>.

80

Sun Shine Technologies

Internal table operations:


1.Reading the data from internal table
i. Reading the single record Read
syntax : Read Table <Itab> into <work area> with key
<condition>.
Read table <Itab> into <work area> index <index number>.
READ TABLE <itab> [INTO <wa>] WITH KEY <key> [BINARY
SEARCH].
ii. Reading the multiple records - loop at
syntax: Loop at <Itab> into <work area> where <condition>.
.

Endloop.
Syntax:
2.Modify the data in the internal table by using the modify
keyword
Syntax: Modify <itab> from <work area> transporting <field
name> where <condition>.
Ex:
MODIFY lt_item FROM wa_item TRANSPORTING itemprice WHERE i
temno = wa_item-itemno.
3.Delete the data by using the delete keyword
i. deleting the duplicate records:
Syntax: delete adjacent duplicate from <Itab>.
81

Sun Shine Technologies


Ex : Delete adjacent duplicate from lt_cust.
ii. Delete the particular record
syntax : delete <Itab> where <condition>
Ex : delete lt_cust where custno = 100 and custname =
vishnu.
iii. Delete the particular record record based on the index
syntax : Delete <Itab> index <Index number>
: delete lt_cust index 3.
iv. Delete the multiple record based on the index
syntax: Delete <itab> index sy-index
Delete lt_cust index sy-index.
Sy-index: is a system field which counts the number of the
records in the internal table
V. Deleting multiple records
Syntax : Delete table Itab[].
Delete table lt_cust[].

4.Sorting the data in the internal table by using sort keyword


Sorting either in ascending or descending
By default ascending
Syntax : Sort <itab> ascending/ descending.
Sort <itab> by <field name>. (Based on the field)
Sort <itab> by <field name> ascending/ descending.
Sort <itab> by <field name1> ascending/ descending
<field name2> ascending/ descending.
82

Sun Shine Technologies


5.Counting the number of lines in the internal table and find out
which type of internal table we are using
i. Counting the number of records
syntax : Describe table <itab> LINES <variable>.
LINES: is a key word which return the number of records available
in the internal table
Ex:

Describe table lt_cust lines lv_count.

ii. Finding the type of the internal table


syntax : Describe table <itab> KIND <variable>.
Ex:

Describe table lt_cust kind lv_count.

KIND: is a keyword which return the type of internal tables


6.Moving data from one internal table to another internal table
Moving data from one internal table to another internal table
which have similar structure
Note: if the second internal table is empty
Syntax:

<Internal table2> = <Internal table1>.


Itab2[] = itab1[].

Note : if the internal table contains the data then


Syntax : Append <work area> to <Itab>.
Append lines of <itab1> to <itab2>.
Messages:
Tcode for message class is SE91.
We have 5 types of messages:
Sy: message <message type><message no.> (message class).
Message type is the type of message in the five types.
Message no is 3 digits no.
83

Sun Shine Technologies


Message class is the collection of message nos and their short
description.
ABEND Messages (A): The system displays this type of
message in a dialog window/box and after the user conforms this
message by using enter key then the system terminates the
entire transaction.
Ex: message A000 (zmsg).
Error and warning Message (E & W): The system displays this
type of message in a status bar. Ex: message E/W000 (zmsg).
Information Message (I): The system displays this type of
message in a dialog window. After user conforms by entering
enter key then it goes to selection screen.
Ex: message I000 (zmsg).
Success Message(S): The system displays this type of message
in the status bar.
Ex: message s000
(zmsg).
Generalized syntax of message:
Message <message type><message no>(message class) with
message.

Open sql:
1.open sql is used to working with the database tables not with
the internal tables
2.Inser, Update, Modify a single record always through the work
area and multiple records through the internal table
3.whenever we are working with the database table then the
structure of the work area and the internal table must be similar
through the database table
The open sql statements are
1.select
84

Sun Shine Technologies


2.Insert
3.Delete
4.Modify
5.update
Select :
Select is used to retrieve the data from the database table
By using the select query we can retrieve the single record 6 ways
Syntax :
Way1:
Select * from <DB table> into <work area> where <condition>.
Endselect.

*&---------------------------------------------------------------------*
*& Report ZVISHNU_DATA_RETRIEVE
*&---------------------------------------------------------------------*
REPORT zvishnu_data_retrieve NO STANDARD PAGE HEADING.
*// Work area declaration
DATA : wa_cust TYPE zcaddress.
*// Design selection screen for Customer
SELECTION-SCREEN BEGIN OF BLOCK blk1 WITH FRAME TITLE tex
t-001.
PARAMETERS : p_custno TYPE zcaddress-customerno.
SELECTION-SCREEN END OF BLOCK blk1.
*// Retrieve data from zcaddress
SELECT * FROM zcaddress
INTO wa_cust
WHERE customerno = p_custno.
ENDSELECT.
85

Sun Shine Technologies


*// Check the above select query is success/Not
IF sy-subrc EQ 0.
WRITE : /10 wa_cust-customerno, wa_cust-customername, wa_cu
st-strret, wa_cust-city, wa_cust-PCODE.
ELSE.
WRITE : /10 'No Data found'.
ENDIF.
Output:

Note: Zcaddress is the custom table if you double click on the


table name the we can see the table
Example2:
***LAST RECORD******************
**// work area declaration
data : wa_marc type marc.
**// retrieve data from marc table
select * from marc into wa_marc.
ENDSELECT.
**// display output
write : / wa_marc-matnr, wa_marc-werks, wa_marc-pstat, wa_mar
c-lvorm.
output: the output is last record in the marc table

86

Sun Shine Technologies


Note: marc is the standard MM table
Note: If we are not use the where condition with the
select..endselect then it will give the last record as the output
If you use the select.endselect it checks till end of the table
and displayed last record as the output
Way2.
Select <field1><field2>.<field n> from <DB table> where
<condition>.
Endselect.
*&---------------------------------------------------------------------*
*& Report ZVISHNU_DATA_RETRIEVE
*&---------------------------------------------------------------------*
REPORT zvishnu_data_retrieve NO STANDARD PAGE HEADING.
*************SELECTED FIELDS FROM MARC****************
*// types declaration for marc
types : begin of ty_marc,
matnr type matnr,
werks type werks_d,
pstat type pstat,
end of ty_marc.
*// work area declaration
data : wa_marc type ty_marc.
*// retrieve data from marc
select matnr werks pstat
from marc
into wa_marc.
ENDSELECT.
*// display output
write : / wa_marc-matnr, wa_marc-werks, wa_marc-pstat.
Output:
87

Sun Shine Technologies

Note: In real time we never use the selectendselect to


retrieve the single record from the data base table we always
used select single to retrieve the single record
Way3:
Select single * from <DB table> into <work area> where
<condition>.
REPORT zvishnu_data_retrieve NO STANDARD PAGE HEADING.
******FIRST RECORD*******************************
*// work area declaration
data : wa_mara type mara.
*// retrieve data from marc table
select single * from mara into wa_mara.
*// display output
write : / wa_mara-matnr, wa_mara-ersda, wa_mara-ernam, wa_ma
ra-mtart.
Output:

Note: if we use the select single then it will display the output
immediately after satisfying the condition
If we are not use the where condition then it displayed first record
as the output
Way4.
Select single <field1><field2>.<field n> from <DB table>
where <condition>.

88

Sun Shine Technologies


REPORT zvishnu_data_retrieve NO STANDARD PAGE HEADING.
*************SELECTED FIELDS FROM MARA****************
*// types declaration for marc
types : begin of ty_mara,
matnr type matnr,
ersda type ersda,
ernam type ernam,
end of ty_mara.
*// work area declaration
data : wa_mara type ty_mara.
*// retrieve data from marc
select single matnr ersda ernam
from mara
into wa_mara.
*// display output
write : / wa_mara-matnr, wa_mara-ersda, wa_mara-ernam.
Output:

Way5.
Select * from <DB table> into <work area> up to N rows where
<condition>.
Endselect.

REPORT zvishnu_data_retrieve NO STANDARD PAGE HEADING.


***********UPTO 1 ROW ALL FIELDS*******************
*// work area declaration
data : wa_mara type mara.
*// retrieve data from marc table
select * from mara into wa_mara up to 1 rows.
ENDSELECT.
*// display output
89

Sun Shine Technologies


write : / wa_mara-matnr, wa_mara-ersda, wa_mara-ernam, wa_ma
ra-mtart.
Output:

Way6
Select <field1><field2>.<field n> from <DB table> up to
N rows where <condition>.
Endselect.
REPORT zvishnu_data_retrieve NO STANDARD PAGE HEADING.
********UPTO 1 ROW SELECTED FIELDS*******************
*// types declaration for marc
types : begin of ty_mara,
matnr type matnr,
ersda type ersda,
ernam type ernam,
end of ty_mara.
*// work area declaration
data : wa_mara type ty_mara.
*// retrieve data from marc
select matnr ersda ernam
from mara
into wa_mara
up to 1 rows.
ENDSELECT.
*// display output
write : / wa_mara-matnr, wa_mara-ersda, wa_mara-ernam.
Output:

90

Sun Shine Technologies


Difference between the select * from and select * from up to 1
rows:
1.If we use the select * from it check all the records and we will
get last record as the output
2.If we use the select * from up to 1 rows then it will check all the
records and finally they get the first record as the output
Do to this disadvantage we use the select single in real time
Retrieve the multiple records:
Syntax:
Select <field1><field2><fieldn>
From DB table
Into table <Itab name>
Where <field> IN <select-options>.

REPORT zvishnu_data_retrieve NO STANDARD PAGE HEADING.


*//table declaration.
tables : mara.
*//types declaration for mara table.
types : begin of ty_mara,
MATNR type MATNR,
ERSDA type ERSDA,
ERNAM type ERNAM,
LAEDA type LAEDA,
AENAM type AENAM,
end of ty_mara.
*//internal table declaration.
data : lt_mara type table of ty_mara.
*//work area declaration.
data : wa_mara type ty_mara.
*//selection screen design.
selection-screen : begin of block blk1 with frame title text-100.
91

Sun Shine Technologies


select-options : s_matnr for mara-matnr.
selection-screen : end of block blk1.
if s_matnr is not initial.
*//retriving data from mara.
select matnr ersda ernam laeda aenam from mara
into table lt_mara
where matnr in s_matnr.
else.
message 'plz fill selection screen fields' type 'I'.
endif.
*//DISPLAY OUTPUT.
loop at lt_mara into wa_mara.
write : / WA_MARA-MATNR,wa_mara-ersda,wa_maraernam,wa_mara-laeda,wa_mara-aenam.
endloop.
Output:

Provide the input and click on execute

Note: whenever we are working with the select-options we use IN


instead of EQ in the here condition
92

Sun Shine Technologies


Insert:
Insert is a keyword which is used to insert the data into database
table
Insert a single record:
Insert a single record into the database table if there is no mach
found in the database based on the key field otherwise it will
ignores the records
Syntax:
Insert <DB table> from <work area>.
Example:
*&---------------------------------------------------------------------*
*& Report ZVISHNU_DATA_RETRIEVE
*&-------------------------------------------------------------------REPORT zvishnu_data_retrieve NO STANDARD PAGE HEADING.
*//internal table declaration
DATA:lt_makt TYPE TABLE OF makt.
*//work area declaration
DATA:wa_makt TYPE makt.
*//assigning first record into the workarea
wa_makt-matnr = '47'.
wa_makt-spras = 'E'.
wa_makt-maktx = 'text meterial'.
wa_makt-maktg = 'TEXT MATERIAL'.
APPEND wa_makt TO lt_makt.
CLEAR wa_makt.
*//inserting one record into makt
insert makt from wa_makt.
if sy-subrc eq 0.
WRITE : / 'inserting data succesfully'.
else.
93

Sun Shine Technologies


write : / 'inserting fail'.
endif.
Output:
We will get the output as insert successfully first time if you
execute the same program at the second time then we will get
insert fail because the record is already inserted in to the
database so system ignores the record if you try to insert second
time
Multiple records:
Insert multiple records from the internal table to database table if
there is no matches found in the data base table for all the
records in the internal table based on the key fields. If at lest one
record is matches then it simply ignores all the records from the
internal table as well as terminate the program
Syntax:
1.Insert <DBtable> from table <Itab>.
2.Loop at <Itab> into <work area>.
Insert <DB table> from <work area>.
Endloop.
Example:
*&---------------------------------------------------------------------*
*& Report ZVISHNU_DATA_RETRIEVE
*&---------------------------------------------------------------------*
REPORT zvishnu_data_retrieve NO STANDARD PAGE HEADING.
*//internal table declaration
DATA:lt_makt TYPE TABLE OF makt.
*//work area declaration
DATA:wa_makt TYPE makt.

94

Sun Shine Technologies


*//assigning first record into the workarea
wa_makt-matnr = '47'.
wa_makt-spras = 'E'.
wa_makt-maktx = 'text meterial'.
wa_makt-maktg = 'TEXT MATERIAL'.
APPEND wa_makt TO lt_makt.
CLEAR wa_makt.
*//assigning second record into the workarea
wa_makt-matnr = '45'.
wa_makt-spras = 'S'.
wa_makt-maktx = 'MESAGE'.
wa_makt-maktg = 'MESSAGE'.
APPEND wa_makt TO lt_makt.
CLEAR wa_makt.
*//assigning 3rd record into the workarea
wa_makt-matnr = '45'.
wa_makt-spras = 'E'.
wa_makt-maktx = 'MESSAGE'.
wa_makt-maktg = 'MESSAGE'.
APPEND wa_makt TO lt_makt.
CLEAR wa_makt.
*//inserting multiple record into makt
loop at lt_makt into wa_makt.
insert makt from wa_makt.
ENDLOOP.
if sy-subrc eq 0.
WRITE : / 'inserting data succesfully'.
else.
write : / 'inserting fail'.
endif.
Output:
We will get inserted success
Example2:

95

Sun Shine Technologies


*&---------------------------------------------------------------------*
*& Report ZVISHNU_DATA_RETRIEVE
*&---------------------------------------------------------------------*
REPORT zvishnu_data_retrieve NO STANDARD PAGE HEADING.
*//internal table declaration
DATA:lt_makt TYPE TABLE OF makt.
*//work area declaration
DATA:wa_makt TYPE makt.
*//assigning first record into the workarea
wa_makt-matnr = '43'.
wa_makt-spras = 'E'.
wa_makt-maktx = 'text meterial'.
wa_makt-maktg = 'TEXT MATERIAL'.
APPEND wa_makt TO lt_makt.
CLEAR wa_makt.
*//assigning second record into the workarea
wa_makt-matnr = '41'.
wa_makt-spras = 'S'.
wa_makt-maktx = 'MESAGE'.
wa_makt-maktg = 'MESSAGE'.
APPEND wa_makt TO lt_makt.
CLEAR wa_makt.
*//assigning 3rd record into the workarea
wa_makt-matnr = '41'.
wa_makt-spras = 'E'.
wa_makt-maktx = 'MESSAGE'.
wa_makt-maktg = 'MESSAGE'.
APPEND wa_makt TO lt_makt.
CLEAR wa_makt.
*//inserting multiple record into makt with out loop.
INSERT makt from TABLE lt_makt.
IF sy-subrc EQ 0.
WRITE : / 'inserting data succesfully'.
96

Sun Shine Technologies


ELSE.
WRITE : / 'inserting fail'.
ENDIF.
Output:
Inserted successfully
If you try to insert the same records once again the system enters
into short dump
Note: If we want to allow the duplicate records we use Accepting
Duplicate Keys in the syntax of insert
Syntax:
Insert DBtable> from table <Itab> accepting duplicate keys.
The above insert query insert the non-duplicate records in to the
database table and ignore the duplicate records
Note:
Sy-bbcnt is the system field which contains the number of
records successfully processed into the database table

Delete:
delete the data from the database based on the condition
syntax:
Delete from <db table> where <condition>.
Deleing the single record
REPORT zvishnu_data_retrieve NO STANDARD PAGE HEADING.
*//deleting data from zcustomer
delete from zcustomer1 where custno = 100.
if sy-subrc eq 0.
write : / 'succesfully deleted'.
else.
97

Sun Shine Technologies


WRITE:/ 'delete operation failed'.
endif.
Output: deleted success fully
*//deleting data from zcustomer
delete from zcustomer1 where custno = p_custno.
if sy-subrc eq 0.
write : / 'succesfully deleted'.
else.
WRITE:/ 'delete operation failed'.
endif.
Output: deleted success fully
*//deleting data from zcustomer
delete from zcustomer1.
if sy-subrc eq 0.
write : / 'succesfully deleted'.
else.
WRITE:/ 'delete operation failed'.
endif.
Output: deleted success fully

Delete multiple records:


REPORT zvishnu_data_retrieve NO STANDARD PAGE HEADING.
*//internal table delaration
DATA lt_makt TYPE TABLE OF makt.
*//work area declaration
DATA: wa_makt TYPE makt.
*//selection screen design
SELECTION-SCREEN BEGIN OF BLOCK blk1 WITH FRAME TITLE tex
t-100.
PARAMETERS p_matnr TYPE makt-matnr.
SELECTION-SCREEN END OF BLOCK blk1.
*//retrieve data from the MAKT
98

Sun Shine Technologies


SELECT * FROM makt
INTO TABLE lt_makt
UP TO 2 ROWS
where matnr = p_matnr.
*//deleting multiple records from makt
LOOP AT lt_makt INTO wa_makt.
DELETE FROM makt WHERE matnr = wa_makt-matnr.
ENDLOOP.
IF sy-subrc EQ 0.
WRITE : / 'succesfully deleted'.
ELSE.
WRITE:/ 'delete operation failed'.
ENDIF.
Output:
Deleted successfully
Deleted all the records from the table:
Syntax:
Delete from <table name>.
Modify:
Modify act like update if there is a match found otherwise it act
like insert.
Syntax:
Modify <db table> from <work area>.
Modify <DB table> from table <Itab>.
Commit work: is a abap key word is used for the database not for
the internal table
Commit work is used to immediate database update
*// Tables declaration
TABLES : zitem.
99

Sun Shine Technologies


*// Decalre Internal table
DATA : lt_item TYPE TABLE OF zitem.
*// Declare Work Area
DATA : wa_item TYPE zitem.
*// Selection screen design
SELECT-OPTIONS s_itemno FOR zitem-itemno.
PARAMETERS
p_itemno TYPE zitem-itemno.
**********************************
*// Retrieve data from ZITEM table
SELECT * FROM zitem
INTO TABLE lt_item
WHERE itemno IN s_itemno.
If Record is exist
IF sy-subrc EQ 0.
READ TABLE lt_item INTO wa_item WITH KEY itemno = p_itemno.
IF sy-subrc EQ 0.
wa_item-itemname = 'PEARS'.
wa_item-itemprice = 40.
ENDIF.
*// Modify Data
IF wa_item IS NOT INITIAL.
MODIFY zitem FROM wa_item.
IF sy-subrc EQ 0.
COMMIT WORK.
MESSAGE 'Successfully Modified' TYPE 'I'.
EXIT.
ELSE.
MESSAGE 'Modification is Failed' TYPE 'E'.
EXIT.
ENDIF.
ENDIF.
ENDIF.
******************************************************************
*
*// Record does not exist
100

Sun Shine Technologies


wa_item-itemno = 4.
wa_item-itemname = 'LIRIL'.
wa_item-itemprice = 400.
*// Modify Data
IF wa_item IS NOT INITIAL.
MODIFY zitem FROM wa_item.
IF sy-subrc EQ 0.
COMMIT WORK.
MESSAGE 'Successfully Modified' TYPE 'I'.
EXIT.
ELSE.
MESSAGE 'Modification is Failed' TYPE 'E'.
EXIT.
ENDIF.
ENDIF.
*****************************************************************
*// Modify Multiple records
*// Retrieve data from ZITEM table
SELECT * FROM zitem
INTO TABLE lt_item
WHERE itemno IN s_itemno.
IF sy-subrc EQ 0.
LOOP AT lt_item INTO wa_item.
wa_item-itemprice = 11111.
*// Modify data into LT_ITEM
MODIFY lt_item FROM wa_item TRANSPORTING itemprice WHER
E itemno = wa_item-itemno.
ENDLOOP.
*// MODIFY STANDARD TABLE
MODIFY zitem FROM TABLE lt_item.
IF sy-subrc EQ 0.
MESSAGE 'Successfully Modified' TYPE 'I'.
EXIT.
ELSE.
MESSAGE 'Modification is Failed' TYPE 'E'.
EXIT.
101

Sun Shine Technologies


ENDIF.
ENDIF.
Update:
Update a record in to the database table if there is match in the
database table based on the key field otherwise it ignore the
record
Syntax:
Update <DBtable> from <work area>.
Update <DBtable> from table <ITAB>.
Update particular record:
Update <DBtable> Set <field1> = <value1>
<field2> = <value2>
Where <condition>.
REPORT zupdate NO STANDARD PAGE HEADING.
*//table declaration
TABLES :zitem.
*//interenal table declaration.
DATA : lt_zitem TYPE TABLE OF zitem.
*//work area declaration
DATA : wa_zitem TYPE zitem.
*//selection screen design
SELECT-OPTIONS:s_itemno FOR zitem-itemno.
PARAMETERS : p_itemno TYPE zitem-itemno.
*//retrieve data from zitem
SELECT * FROM zitem
INTO TABLE lt_zitem
WHERE itemno in s_itemno.
102

Sun Shine Technologies


if sy-subrc eq 0.
*//update single record
IF lt_zitem IS NOT INITIAL.
READ TABLE lt_zitem INTO wa_zitem WITH KEY itemno = p_itemn
o.
IF sy-subrc EQ 0.
wa_zitem-itemname = 'colgate'.
wa_zitem-itemprice = 200.
IF wa_zitem IS NOT INITIAL.
UPDATE zitem FROM wa_zitem.
IF sy-subrc EQ 0.
COMMIT WORK.
WRITE : / 'update successfilly'.
ELSE.
WRITE : / 'update fail'.
ENDIF.
ENDIF.
ENDIF.
ENDIF.
endif.
*// update Multiple records
if lt_zitem is not INITIAL.
loop at lt_zitem into wa_zitem.
wa_zitem-itemprice = 1100.
update zitem from wa_zitem.
endloop.
if sy-subrc eq 0.
WRITE : / 'update successfilly'.
ELSE.
WRITE : / 'update fail'.
endif.
endif.
endif.
For all entries

103

Sun Shine Technologies


For all entries fetch the data based on where condition first and
next is based on ON condition
Whenever we are working with for all entries then we must
declare the one internal table for each participated data base
table and also declare the one internal table for final data
Based on the given input you will fetch the data from the
database and fill into database internal table
Based on the database internal table populate the final internal
table
Whenever we are populating the data into final internal table we
must identify read/loop of the database internal table based on
the primary keys(if the table as only one primary key that is read
otherwise it is loop)
We always used the for all entries instead of inner join because
inner join some time leads the time out
Note: Inner join is not possible for cluster and pooled tables
whenever we are using the for all entries we must consider the
header level internal table having the data or not
Note: suppose if you not consider header level internal table is
having the data or not if the header level internal table contains
no data then it will fetch entire data from next level database
Example:
Retrieve data from 2 tables (VBAK, VBAP) by using for all entries
REPORT zselect_multiple NO STANDARD PAGE HEADING.
*// Tables declaration
TABLES : vbak.
*// Types declaration for VBAK
TYPES : BEGIN OF ty_vbak,
vbeln TYPE vbeln_va,
erdat TYPE erdat,
104

Sun Shine Technologies


erzet TYPE erzet,
ernam TYPE ernam,
angdt TYPE angdt_v,
END OF ty_vbak.
*// Types declaration for VBAP
TYPES : BEGIN OF ty_vbap,
vbeln TYPE vbeln_va,
posnr TYPE posnr_va,
matnr TYPE matnr,
matwa TYPE matwa,
matkl TYPE matkl,
arktx TYPE arktx,
END OF ty_vbap.
*// Types declaration for Final Internal table
TYPES : BEGIN OF ty_final,
vbeln TYPE vbeln_va,
erdat TYPE erdat,
erzet TYPE erzet,
ernam TYPE ernam,
angdt TYPE angdt_v,
posnr TYPE posnr_va,
matnr TYPE matnr,
matwa TYPE matwa,
matkl TYPE matkl,
arktx TYPE arktx,
END OF ty_final.
*// Internal table declaration
DATA : lt_vbak TYPE TABLE OF ty_vbak,
lt_vbap TYPE TABLE OF ty_vbap,
lt_final TYPE TABLE OF ty_final.
*// Work area declaration
DATA : wa_vbak TYPE ty_vbak,
wa_vbap TYPE ty_vbap,
wa_final TYPE ty_final.
105

Sun Shine Technologies


*// Variable declaration
DATA : lv_count TYPE i.
*// Selection screen design
SELECTION-SCREEN BEGIN OF BLOCK blk1 WITH FRAME TITLE tex
t-100.
SELECT-OPTIONS s_vbeln FOR vbak-vbeln.
SELECTION-SCREEN END OF BLOCK blk1.
*// Retrieve data from VBAK
IF s_vbeln IS NOT INITIAL.
SELECT vbeln erdat erzet ernam angdt
FROM vbak
INTO TABLE lt_vbak
WHERE vbeln IN s_vbeln.
*// Retrieve data from VBAP
IF lt_vbak IS NOT INITIAL.
SELECT vbeln posnr matnr matwa matkl arktx
FROM vbap
INTO TABLE lt_vbap
FOR ALL ENTRIES IN lt_vbak
WHERE vbeln = lt_vbak-vbeln.
ENDIF.
ELSE.
MESSAGE 'Please enter selection screen field value' TYPE 'I'.
EXIT.
ENDIF.
*// Populate data into final internal table
LOOP AT lt_vbap INTO wa_vbap. " Item Table
READ TABLE lt_vbak INTO wa_vbak WITH KEY vbeln = wa_vbapvbeln.
IF sy-subrc EQ 0.
wa_final-vbeln = wa_vbak-vbeln.
wa_final-erdat = wa_vbak-erdat.
wa_final-erzet = wa_vbak-erzet.
wa_final-ernam = wa_vbak-ernam.
wa_final-angdt = wa_vbak-angdt.
wa_final-posnr = wa_vbap-posnr.
106

Sun Shine Technologies


wa_final-matnr = wa_vbap-matnr.
wa_final-matwa = wa_vbap-matwa.
wa_final-matkl = wa_vbap-matkl.
wa_final-arktx = wa_vbap-arktx.
APPEND wa_final TO lt_final.
CLEAR wa_final.
ENDIF.
ENDLOOP.
*// Count number of records in LT_FINAL table
DESCRIBE TABLE lt_final LINES lv_count.
WRITE : /10 'Number of Sales Records:', lv_count.
ULINE.
SKIP 1.
*// Display output
LOOP AT lt_final INTO wa_final.
WRITE : / wa_final-vbeln, wa_final-erdat, wa_final-erzet, wa_finalernam, wa_final-angdt,
wa_final-posnr, wa_final-matnr, wa_final-matwa, wa_finalmatkl, wa_final-arktx.
ENDLOOP.
Output:

107

Sun Shine Technologies

Inner joins
Inner joins are used to retrieve the data from multiple tables.
Whenever we are working with the inner joins then not need to
declare the types for each and every table only declare the final
types
Inner join fetch the data based on ON condition first next is based
on WHERE condition.
Retrieve the data from Mara, marc
REPORT zinnerjoin_mara NO STANDARD PAGE HEADING.
TABLES:mara.
TYPES :BEGIN OF ty_final,
matnr TYPE matnr,
108

Sun Shine Technologies


ersda TYPE ersda,
ernam TYPE ernam,
laeda TYPE laeda,
aenam TYPE aenam,
mtart TYPE mtart,
matkl TYPE matkl,
werks TYPE werks_d,
pstat TYPE pstat_d,
lvorm TYPE lvowk,
mmstd TYPE mmstd,
ekgrp TYPE ekgrp,
END OF ty_final.
*//internal table declaration
DATA:lt_final TYPE TABLE OF ty_final.
*//work area declaration
data:wa_final TYPE ty_final.
*// selection screen design
SELECTION-SCREEN BEGIN OF BLOCK blk1 WITH FRAME TITLE tex
t-100.
SELECT-OPTIONS s_matnr FOR mara-matnr.
SELECTION-SCREEN END OF BLOCK blk1.
*//retrieve data from mara & marc by using inner join
select a~matnr a~ersda a~ernam a~laeda a~aenam a~mtart a~
matkl
b~matnr b~werks b~pstat b~lvorm b~mmstd b~ekgrp
INTO CORRESPONDING FIELDS OF TABLE lt_final
from mara as a
INNER JOIN marc as b
on a~matnr = b~matnr
where a~matnr in s_matnr.
LOOP AT lt_final INTO wa_final.
WRITE : / wa_final-matnr,
wa_final-ersda,wa_final-ernam,wa_final-laeda,
wa_final-aenam,wa_final-mtart, wa_final-matkl,wa_finalwerks,wa_final-pstat,
wa_final109

Sun Shine Technologies


lvorm,wa_final-mmstd,wa_final-ekgrp.
ENDLOOP.

Modularization techniques:
Modularization techniques are used to divided the business
processing logic into reusable block of statements
This is two step processing
1. Define the reusable block
2. Calling the reusable block
In Abap we have 4 modularization techniques
1. Includes
2. Subroutines
3. Function modules
4. Macros
Includes:
Include programs are cant executed directly (non executable
programs). One include program can be used in any number of
programs
Steps to create the include program:
Go to SE38 transaction code
Enter the program name

110

Sun Shine Technologies


Click on create. One window will be triggered. Where we can enter
the title and select the TYPE as INCLUDE program. Click on save.
Then one window will be trigger where we can write our code.
After writing the code click on save and activate.
By using INCLUDE key word we can call subroutine into include
program
Syntax: INCLUDE <Include name>.

Another way to create the include program:


Go to SE38 executable program.
Define the include

Double click on zdata_retrieve99.Then system will ask do you


want create

111

Sun Shine Technologies


Click on yes. Enter the title. By default system will select the
program type as INCLUDE program.Click on save.

Include programs are used to improve the readability of the


program.
Classification of includes:
Include <prog>top.

- Global data (global declaration).


Include <prog>i01
- PAI logic.
Include
<prog>o01
- PBO logic.
Include <prog>f01
- subroutine.
Include <prog>e01
- events.
Include <prog>u01
- user exit.

Subroutines:
Subroutines are program modules which can be called from
ABAP/4 programs. Frequently used parts of program can be put
into subroutines and these subroutines can be called explicitly
from the program.
Defining Subroutines
112

Sun Shine Technologies


A subroutine is block of code introduced by FORM and concluded
by ENDFORM. Following syntax is used to define a form or
subroutine:
Syntax:
FORM <Subroutine Name> Using <Input Value1> type <Data
Type>
<Input Value2> Type <Data Type>
Changing <Output Value> Type <Data
Type>
..
ENDFORM.
Syntax for calling the subroutine:
PERFORM <subroutine name>Using <Input Value1><Input
Value2>.
Changing <Output Value1><Output
Value1>.
Note:
1. In subroutine calling should be the first and definition should be
the next
2. We cant place any executable statements after
definition of subroutine
*&---------------------------------------------------------------------*
*& Report ZVISHNU_SUBROUTINE
*&---------------------------------------------------------------------*
REPORT ZVISHNU_SUBROUTINE NO STANDARD PAGE HEADING.
PARAMETERS:p_input1 TYPE i,
p_input2 TYPE i.
data r TYPE i.
perform add USING p_input1 p_input2
CHANGING r.
write:/ 'TOTAL IS:', r.

113

Sun Shine Technologies


form add using p_p_input1
p_p_input2
changing p_r.
r = p_input1 + p_input2.
endform.
" add
There are two types of subroutines:
Internal subroutine
External subroutine
Internal subroutine: internal subroutine is nothing but definition
of subroutine as well as calling of the subroutine in same
program.
External subroutine: external subroutine is nothing but definition
of the subroutine in one program and calling of the subroutine in
another program
Syntax form calling the external subroutine:
PERFORM <Subroutine Name> in program <Program Name>
Using <Input value1><input
value2>
Changing <Output1> ..
Termination of subroutine:
Subroutine normally ends with endform.
If you want to terminate the subroutine so earlier then we use
EXIT (or) CHECK command
EXIT command is used to terminate the subroutine
unconditionally
CHECK command
is used to terminate the subroutine conditionally
Macros:
Macros are used to perform the arithmetical operations.
Macros can take up to 9 place holders. Macros are used in hrabap.
114

Sun Shine Technologies


Syntax for defining the macro
Define <macro name>.
-------.
-------.
End-of-definition.
Syntax for calling the macro.
<Macro name>.
*&---------------------------------------------------------------------*
*& Report ZMACRO
*&---------------------------------------------------------------------*

REPORT ZMACRO.
data : begin of wa,
bukrs like t001-bukrs,
butxt like t001-butxt,
ort01 like t001-ort01,
end of wa,
it like table of wa.
define zfill.
wa-bukrs = &1.
wa-butxt = &2.
wa-ort01 = &3.
append wa to it.
end-of-definition.
zfill '1000' 'tcs' 'hyd'.
zfill '2000' 'cts' 'bag'.

115

Sun Shine Technologies


loop at it into wa.
write :/ wa-bukrs,
wa-butxt,
wa-ort01.
endloop.
Difference between Macros and subroutines:
Macros

subroutines

1 In macros definition and


calling are in same program

In subroutines definition and


calling may or may not be in
same program

2 Definition should be first and


then calling

Calling should be first and then


definition

3 They can take upto 9


placeholders

They can take any no. of


placeholders.

4 We can place any executable


statement after the definition

We cant place any executable


statement after the definition.

5 They are used in hr-abap

They are used in abap and hrabap.

Function Modules: Tcode se37


1. These are reusable components those are defined in function
library.
2. Each function module be attached to the function group which
contains two include programs by default.
3. One is the global data declaration another one is for common
subroutines
All the function modules under the group can access both the
include programs

116

Sun Shine Technologies


Whenever we are calling the any one function module then all
other function modules under that group loaded in the memory of
calling program. So better to group the related function modules
into one function group
We have 3 types of unction modules are there
1. Normal Within abap we used the normal function module
2. Remote enables Cross applications (Transfer the data from
SAP to Non-Sap and Non-SAP to SAP)
3. Update Not used in real time
Note: each and every function module conations 7 Tabs
1. Attributes properties of that particular object
2. Import - Parameter
3. Export - Parameter
4. Changing - Parameter
5. Tables - Parameter
6. Exceptions used for populate the error messages
7. Source code Implementing code
Note: Before ECC we have 6 Tabs we dont have the Tables tab
Function group creation:
In se37 menu click on goto, function group, create, provide short
description
Save.
Activate the function group.
Goto se80, select function group, provide your function group and
right click on it and activate.
Function module creation:

117

Sun Shine Technologies


GOto SE80 TX code and select ur package and and create the
function group after creating the functional group goto SE37 enter
the functional module program name and click on create
And another window will be open on that window we enter the
your function group name and short text and click on SAVE button
then it will give information window click on enter
Then the function builder window will be open in that window we
have we have seven tabs

Under the attributes tab we have the properties of the particular


program
And the import tab we will enter the parameter variables in the
import tab we have parameter name (importing parameter name)
and the type is we give type for work area and associated tab we
will give the field data element name and click on enter and
select the pass value (not mandatory) and export tab we give the
export parameter the import and export is used if we retrieve the
single record.
To retrieve multiple fields we use tables

Fig: import tab options

118

Sun Shine Technologies

Fig: table tab


Under the table tab we enter the global structure name .here we
use like in type spec. tab bcz we stored more than single record

Fig: exception tab

119

Sun Shine Technologies


Fig: source code tab
In the source code tab we enter our source code like
FUNCTION zmaterial_mara.
*"---------------------------------------------------------------------*"*"Local Interface:
*" IMPORTING
*"
VALUE(I_MATNR) TYPE MATNR
*" TABLES
*"
I_ZMMATERIAL STRUCTURE ZMMATERIAL
*"---------------------------------------------------------------------*//types declaration for MARA table
TYPES : BEGIN OF ty_mara,
matnr TYPE matnr,
ersda TYPE ersda,
ernam TYPE ernam,
laeda TYPE laeda,
aenam TYPE aenam,
END OF ty_mara.
*//types declaration for MARC
TYPES : BEGIN OF ty_marc,
matnr TYPE matnr,
werks TYPE werks_d,
pstat TYPE pstat_d,
lvorm TYPE lvowk,
mmstd TYPE mmstd,
END OF ty_marc.
*//types declaration for MARD
TYPES : BEGIN OF ty_mard,
matnr TYPE matnr,
werks TYPE werks_d,
lgort TYPE lgort_d,
lfmon TYPE lfmon,
END OF ty_mard.
*//types declaration for MAKT
120

Sun Shine Technologies


TYPES:BEGIN OF ty_makt,
matnr TYPE matnr,
spras TYPE spras,
maktx TYPE maktx ,
END OF ty_makt.
*//internal table declaration
DATA : lt_mara TYPE TABLE OF ty_mara,
lt_marc TYPE TABLE OF ty_marc,
lt_mard TYPE TABLE OF ty_mard,
lt_makt TYPE TABLE OF ty_makt,
lt_zmmaterial TYPE TABLE OF zmmaterial.
*//work area declaration
DATA : wa_mara TYPE ty_mara,
wa_marc TYPE ty_marc,
wa_mard TYPE ty_mard,
wa_makt TYPE ty_makt,
wa_zmmaterial TYPE zmmaterial.
*//retrieve data from mara
SELECT matnr ersda ernam laeda aenam
FROM mara
INTO TABLE lt_mara
WHERE matnr EQ i_matnr.
*//retrieve data from marc
IF lt_mara IS NOT INITIAL.
SELECT matnr werks pstat lvorm mmstd
FROM marc
INTO TABLE lt_marc
FOR ALL ENTRIES IN lt_mara
WHERE matnr EQ lt_mara-matnr.
ENDIF.
*//retrieve data from mard
IF lt_marc IS NOT INITIAL.
SELECT matnr werks lgort lfmon
FROM mard
INTO TABLE lt_mard
FOR ALL ENTRIES IN lt_marc
121

Sun Shine Technologies


WHERE werks EQ lt_marc-werks.
ENDIF.
*//retrieve data from makt
IF lt_marc IS NOT INITIAL.
SELECT matnr spras maktx
FROM makt
INTO TABLE lt_makt
FOR ALL ENTRIES IN lt_marc
WHERE matnr EQ lt_marc-matnr.
ENDIF.
*//populating data into final internal table
LOOP AT lt_marc INTO wa_marc.
READ TABLE lt_mara INTO wa_mara WITH KEY matnr = wa_mar
c-matnr.
IF sy-subrc EQ 0.
wa_zmmaterial-matnr = wa_mara-matnr.
wa_zmmaterial-ersda = wa_mara-ersda.
wa_zmmaterial-ernam = wa_mara-ernam.
wa_zmmaterial-laeda = wa_mara-laeda.
wa_zmmaterial-aenam = wa_mara-aenam.
wa_zmmaterial-werks = wa_marc-werks.
wa_zmmaterial-pstat = wa_marc-pstat.
wa_zmmaterial-lvorm = wa_marc-lvorm.
wa_zmmaterial-mmstd = wa_marc-mmstd.
ENDIF.
READ TABLE lt_mard INTO wa_mard WITH KEY werks = wa_mar
c-werks.
IF sy-subrc EQ 0.
wa_zmmaterial-lgort = wa_mard-lgort.
wa_zmmaterial-lfmon = wa_mard-lfmon.
ENDIF.
READ TABLE lt_makt INTO wa_makt WITH KEY matnr = wa_mar
c-matnr.
IF sy-subrc EQ 0.
wa_zmmaterial-spras = wa_makt-spras.
wa_zmmaterial-maktx = wa_makt-maktx.
ENDIF.
APPEND wa_zmmaterial TO lt_zmmaterial.
122

Sun Shine Technologies


CLEAR wa_zmmaterial.
i_zmmaterial[] = lt_zmmaterial[].
ENDLOOP.
ENDFUNCTION.

After writing source code save and activate the code then we use
this function module any program. if we want to use this program
in the SE38
Go to SE38
Enter the program name click on create and save Ur program in
ur package
And enter the source code
To call the function module in to Ur program. place the courser
where we want and click on pattern tab on top of the window, and
select the CALL FUNCTION radio button enter the function module
name click on enter then it will exported in to ur program.

123

Sun Shine Technologies

SE38 code
REPORT zmaterial_data NO STANDARD PAGE HEADING MESSAGEID zmymessage.
*//internal table creation
DATA : lt_zmmaterial TYPE TABLE OF zmmaterial.
*//work area declaration
DATA :wa_zmmaterial TYPE zmmaterial.
*//selection screen design
SELECTION-SCREEN BEGIN OF BLOCK blk1 WITH FRAME.
124

Sun Shine Technologies


PARAMETERS : p_matnr TYPE mara-matnr.
SELECTION-SCREEN END OF BLOCK blk1.
*// Validating selection screen input values
IF p_matnr IS INITIAL.
MESSAGE e001.
ELSE.
MESSAGE s003.
ENDIF.
*// Calling Function Module
IF p_matnr IS NOT INITIAL.
CALL FUNCTION 'ZMATERIAL_MARA'
EXPORTING
i_matnr
= p_matnr
TABLES
i_zmmaterial = lt_zmmaterial.
ENDIF.
*//display the ouyput
LOOP AT lt_zmmaterial INTO wa_zmmaterial.
WRITE :/ wa_zmmaterial-matnr, wa_zmmaterial-ersda, wa_zmma
terial-ernam, wa_zmmaterial-laeda,wa_zmmaterial-aenam,
wa_zmmaterial-werks, wa_zmmaterial-pstat, wa_zmmateri
al-lvorm, wa_zmmaterial-mmstd, wa_zmmaterial-lgort,
wa_zmmaterial-lfmon, wa_zmmaterialspras,wa_zmmaterial-maktx.
ENDLOOP.
Difference between subroutine and function modules
Subroutines

Function modules

1 Subroutines are local, we can


access within the server

Fm we can access within the


server as well as outside of the
server also

2 We cant test the subroutine


independently

We can test the fm


independently.

3 We cant handle the errors

We can handle the errors.


125

Sun Shine Technologies

Control Break Statements:


Control break statements are used to display summarized reports.
It is also called as control level processing.
All control break statements must be maintained between loop
and Endloop.
Events:
1) AT FIRST ____ ENDAT:
It initializes the loop. It provides header information for list. It
exists only one time.
2) AT NEW <FIELD>_______ENDAT:
It executes whenever field value changes.
3) AT END OF <FIELD>_____ENDAT:
It executes at the end of field values. It provides
subtotal for the field.
4) AT LAST______ENDAT:
It terminates the loop. It is used to provide grand
total for the field.
5) SUM:
This statement performs arithmetic operations like
sum.
It is used to calculate subtotal and grand total.
If it is used in at end of ---endat it captures subtotal.
If it is used in at last----endat it captures grand total.
6) ON CHANGE OF <FIELD>_______ENDON:
It is alternative for at new. It executes whenever the
field value changes. It can be used in any loop where as at
new is used in loop and Endloop.
*&---------------------------------------------------------------------*
126

Sun Shine Technologies


*& Report ZCONTROL
*&---------------------------------------------------------------------*
REPORT ZCONTROL.
DATA v1 like vbap-vbeln.
select-OPTIONS :s_vbeln for v1.
Data : begin of ty,
vbeln like vbap-vbeln,
posnr like vbap-posnr,
matnr like vbap-matnr,
netwr like vbap-netwr,
end OF ty,

wa1 like ty,


wa like ty,

it1 like TABLE OF ty,


it like TABLE OF ty.
SELECT vbeln
posnr
matnr
netwr
from vbap
into TABLE it
WHERE vbeln in s_vbeln.
127

Sun Shine Technologies


loop at it into wa.
MOVE-CORRESPONDING wa to wa1.
append wa1 to it1.
clear wa1.
ENDLOOP.
LOOP at it1 INTO wa1.
at FIRST.
write :/ 'Sales Document Item Details'.
ULINE.
skip.
ENDAT.
at NEW vbeln.
write :/ 'Sales Document No.', wa1-vbeln color 2.
uline.
ENDAT.
WRITE: / wa1-vbeln,
wa1-posnr,
wa1-matnr,
wa1-netwr.
at END OF vbeln.
sum.
WRITE : /30 'Subtotal',wa1-netwr COLOR 3.
skip 2.
ENDAT.
128

Sun Shine Technologies


at LAST.
sum.
write : /30 'Grandtotal', wa1-netwr COLOR 4.
ENDAT.
ENDLOOP.
Classical Reports
Classical report is nothing but to display the entire information in
a single list.
Events:
1) Initialization :
Initialization is an event which is triggered
before displaying
the selection-screen. This is used to provide
the default values
to the selection screen.
Ex: initialization.
S_bukrs-low = 1000.
S_bukrs-high = 2000.
S_bukrs-sign = I.
S_bukrs option = BT.
Append s_bukrs to s_bukrs.
2) At Selection-screen :
It is an event which is triggered after
providing the input
to the selection screen and before
leaving it.
It is used to validate the given input.
Ex: At Selection-screen.
Select Burks
from t001
Into v1 up to
1 rows where
129

Sun Shine Technologies


Bukrs in s_bukrs.
Endselect.
If sy-subrc <> 0.
Message e000 (zmsg) with invalid company.
Endif.
3) At Selection-screen on <field> :
It is an event which is triggered at
the selection screen
Based on the given input field.
It is used to validate the given input of
the particular
Field.
Ex: At Selection-screen on s_lifnr.
Select lifnr
From
Lfa1
Into v1
Up to 1 rows
Where lifnr in s_lifnr.
Endselect.
If sy-subrc <> 0.
Message e000(zmsg) with invalid vendor.
Endif.
4) Start-of-selection:
It is an event which is triggered after
leaving the selection
Screen and before displaying the output.
This is used for retiring the data from the data
base and
Place in the internal table.
It is the default event in the classical report.
5) Top-of-page :
It is an event which is triggered at the top of
the page.
It is used to display the heading for the
report.

130

Sun Shine Technologies


Ex: top-of-page.
Write: / Company Details.
6) End-of-page :
It is an event which is triggered at the end of
each page.
This is used to display the footer information
to the report.
Ex: end-of-page.
Write: / footer details.
7) End-of-selection :
It is an event which is triggered after fetching
the data from
the database.
It is used for displaying the output.
The Order of the Events:
Top-of-page

Initialization
at selection screen start -of-selection
|
End-of-selection
--------------- > --------------------------------------------------- ->
Selection
screen
At selection

screen on
End-of-page

Based on the given purchasing document no. to display the


document item details.
*&---------------------------------------------------------------------*
*& Report ZCLASSICALREPORT
*&---------------------------------------------------------------------*
REPORT ZCLASSICALREPORT line-count 15(2) no standard page
heading.
131

Sun Shine Technologies


Types: begin of ty,
Ebeln type ekpo-ebeln,
ebelp type ekpo-ebelp,
matnr type ekpo-matnr,
end of ty.
Data: WA type ty,
it type table of ty.
Data v1 like ekpo-ebeln.
Select-options: s_ebeln for v1.
Initialization.
S_ebeln-low = ' '.
S_ebeln-high = ''.
Append s_ebeln to s_ebeln.
At selection-screen.
Select ebeln
from ekpo
into v1 up to
1 rows where
ebeln in s_ebeln.
Endselect.
If sy-subrc <> 0.
Message e000 (zmsg) with 'invalid po number'.
Endif.
Start-of-selection.
Select ebeln
ebelp
matnr from ekpo
into table it
where ebeln in
s_ebeln.

132

Sun Shine Technologies


End-of-selection.
Loop at it into WA.
Write: / wa-ebeln,
wa-ebelp,
wa-matnr.
Endloop.
Top-of-page.
Write: / 'Purchase order Details'.
End-of-page.
Write: / sy-datum.
Some more events:
1) At selection-screen output :
It is an event which is triggered at the
selection-screen based
on the user action.
This is used to modify the selection screen.
2) At selection-screen on value-request:
It is an event which is triggered at the time of
user clicks on f4
button in the selection screen.
This is used for creation of f4 help.
3) At selection-screen on help-request.
It is an event which is triggered at the time of
user clicks on
f1 button
in the selection screen.
Interactive Reports:
Interactive report is nothing but to display the summarized
information in the
basic list and next level information in the
secondary list.
We can have only 1 basic list and up to 20 secondary list.
System Variables related to interactive report:
133

Sun Shine Technologies


1) Sy-lsind:
It is the system variable which contains the
current list index no.
2) Sy-lisel:
It is the system variable which contains the
contents of
The selected record.
3) Sy-Lilli:
It is the system variable which contains the exact
line no.
Of the selected record.
4) Sy-ucomm :
It is the system variable which contains the
function
Code of the selected menu item.
5) Sy-linno:
It is the system variable which contains the exact
line no.
Of the last record displayed.
Events in Interactive Reports:
1) At line-selection:
It is an event which is triggered at the time of
user
Clicks on any record of any list.
2) At User-command:
It is an event which is triggered at the time
of user
Clicks on any menu items.
3) Top-of-page during line-selection.
It is an event which is triggered at the top of
each secondary list.
4) At Pf <no.> :
It is an event which is triggered at the time of
user clicks
On f1 to f12 buttons.
5) Set pf-status :

134

Sun Shine Technologies


It is an event which is used to attach our own GUI to
the program.
Interactive reports supports the user, interaction is always
through double click.
Whenever the user clicks on any record on any list then at lineselection event is triggered and list index is incremented by 1
Sy-lsind If we want to generate the data for this list then we
should know the record which is clicked by the user in the
previous list.
HIDE:
It is the keyword which maintains the copy of the previous
list with output line nos and their contents. Whenever user clicks
on any record of any list then at line-selection event will be
triggered and list index will be incremented by 1 and that
particular record will be transfer from hide area to workarea.
*&---------------------------------------------------------------------*
*& Report ZHIDE
*&---------------------------------------------------------------------*
REPORT ZHIDE.
types : begin of ty,
ebeln type ekko-ebeln, " PURCHASE-DOCUMENT NO.
bstyp type ekko-bstyp, " DOC TYPE
bsart type ekko-bsart,
end of ty.
types : begin of ty1,
ebeln type ekpo-ebeln,
ebelp type ekpo-ebelp,
135

Sun Shine Technologies


matnr type ekpo-matnr,
menge type ekpo-menge,
meins type ekpo-meins,
end of ty1.
data : wa type ty,
wa1 type ty1,
it type table of ty,
it1 type table of ty1,
v1 like ekko-ebeln.
select-OPTIONS s_ebeln for v1.
select ebeln
bstyp
bsart
from ekko
into table it
where ebeln in s_ebeln.

loop at it into wa.


write :/ wa-ebeln,
wa-bstyp,
wa-bsart.
hide : wa-ebeln,
wa-bstyp,
136

Sun Shine Technologies


wa-bsart.
endloop.
at LINE-SELECTION.
if sy-lsind = '1'.
select ebeln
ebelp
matnr
menge
meins
from ekpo
into wa1
where ebeln = wa-ebeln.
endselect.

loop at it1 into wa1.


WRITE :/ wa1-ebeln,
wa1-ebelp,
wa1-matnr,
wa1-menge,
wa1-meins.

endloop.
endif.
TOP-OF-PAGE DURING LINE-SELECTION.
137

Sun Shine Technologies


WRITE : / 'Purchase Item Details'.
Uline.

GET CURSOR:
Hide technique generates the next list based on
the line selection. If we want to generate the next list based on
the field selection then we go for get cursor technique. Get
Cursor technique returns the field name as well as field value
which is selected by the user.
Sy: get cursor field <variable1> value <variable2>.
*&---------------------------------------------------------------------*
*& Report ZGETCURSOR
*&---------------------------------------------------------------------*
REPORT ZGETCURSOR.
types : begin of ty_ekko,
ebeln type ekko-ebeln,
bsart type ekko-bsart,
lifnr type ekko-lifnr,
end of ty_ekko,
begin of ty_ekpo,
ebeln type ekpo-ebeln,
ebelp type ekpo-ebelp,
matnr type ekpo-matnr,
end of ty_ekpo,
BEGIN OF TY_LFA1,
LIFNR TYPE LFA1-LIFNR,
NAME1 TYPE LFA1-NAME1,
ORT01 TYPE LFA1-ORT01,
END OF TY_LFA1.

138

Sun Shine Technologies


Data : wa_ekko type ty_ekko,
wa_ekpo type ty_ekpo,
WA_LFA1 TYPE TY_LFA1,
it_ekko type table of ty_ekko,
it_ekpo type table of ty_ekpo,
IT_LFA1 TYPE TABLE OF TY_LFA1,
v1 like ekko-ebeln.
select-OPTIONS s_ebeln for v1.
SELECT ebeln
bsart
lifnr
from ekko
into table
it_ekko where ebeln in s_ebeln.
loop at it_ekko into wa_ekko.
write : / wa_ekko-ebeln,
wa_ekko-bsart,
wa_ekko-lifnr.
endloop.
at LINE-SELECTION.
if sy-lsind = '1'.
DATA : v2(15) type c,
v3(10) type c.
GET CURSOR FIELD v2 VALUE v3.
if v2 = 'WA_EKKO-EBELN'.
SELECT EBELN
EBELP
MATNR
INTO TABLE IT_EKPO
FROM EKPO
WHERE EBELN = V3.
139

Sun Shine Technologies


LOOP AT IT_EKPO INTO WA_EKPO.
WRITE : / WA_EKPO-EBELN,
WA_EKPO-EBELP,
WA_EKPO-MATNR.
ENDLOOP.
ELSEIF V2 = 'WA_EKKO-LIFNR'.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
INPUT
= V3
IMPORTING
OUTPUT
= V3.
SELECT LIFNR
NAME1
ORT01
FROM LFA1
INTO TABLE IT_LFA1
WHERE LIFNR = V3.
LOOP AT IT_LFA1 INTO WA_LFA1.
WRITE : / WA_LFA1-LIFNR,
WA_LFA1-NAME1,
WA_LFA1-ORT01.
ENDLOOP.
ENDIF.
ENDIF.
Program for the events set pf-status and user command.
Types: Begin of ty_vbap,
vbeln type vbap-vbeln,
posnr type vbap-posnr,
kwmeng type
vbap-kwmeng,
meins type vbap-meins,
end of ty_vbap.
140

Sun Shine Technologies


Data: wa_vbap type ty_vbap,
it_vbap type table of ty_vbap,
v1 like vbap-vbeln.
Select-options
s_vbeln for v1.
Select

vbeln
posnr
kwmeng
meins
from vbap into
table it_vbap
where vbeln in s_vbeln.
Loop at

it_vbap into wa_vbap.


Write: / wa_vbap-vbeln,
wa_vbap-posnr,
wa_vbap-kwmeng,
wa_vbap-meins.
Endloop.
Set pf-status STATUS.
AT USER-COMMAND.
If syucomm = DOWNLOAD.
function DOWNLOAD
exporting
filetype = DAT
tables
Data_tab = it_vbap.
Endif.

Call

ALV REPORTS (ABAP LIST VIEWER):


Alv is used to display the output with predefined functionalities
such as
1) Sort the list in ascending order
2) Sort the list in descending order
3) Totals
141

Sun Shine Technologies


4) Filtering
5) Down the list
6) Change the Layout
7) Senders Attachment
8) Word Processing
9) XL sheet
10) Graphics
Slis is a standard type group which contains all types related
to alv.
Whenever we are referring any type under any type group
then we must call the type group name in the program.
Type-pool is the keyword which is used to call or include the
type group name in the program.
Steps to work with ALV.
1) Declare the final Data internal table and implement the
Retrieving logics.
2) Prepare the fieldcatalog (about the displayed fields)
3) Display the output using function modules like
Reuse_Alv_Grid_Display:
It is the Function module which is
used to
Display the output in a grid
format.
Or
Reuse_Alv_List_Display:
It is the Function module which is
used to
display the output in a list format.
Input for the 2 function modules are the 2 internal tables.
1) Data internal table 2) fieldcatalog internal table.
Filling the fieldcatalog internal table:
We can fill the fieldcatalog internal table in 3 ways.

142

Sun Shine Technologies


1) Whenever we are working with all the fields from any one of
the database table, then we no need to prepare fieldcatalog
internal table. Here we simply pass I_structure_name as
database table name.
Here the function module picks the column headings from
the data element of each field and also display the output in
the similar order of the fields in the table.
2) Manually filling the fieldcatalog.
3) By using Reuse_alv_fieldcatalog_merge function
module.

1) Program with all the fields in the table.


*&---------------------------------------------------------------------*
*& Report ZALV1
*&---------------------------------------------------------------------*
REPORT ZALV1.
tables kna1.
Data : it type table of kna1.
select * from kna1 into table it.
*CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
* EXPORTING
* I_STRUCTURE_NAME
= 'KNA1'
* TABLES
* T_OUTTAB
= it.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
I_STRUCTURE_NAME
= 'KNA1'
TABLES
T_OUTTAB

= it.
143

Sun Shine Technologies


If we want to display in list format then we use first function
module and if we want to display in grid then we use second
function module.
Manually filling the field catalog.
Some of the fields in the fieldcatalog.
1) Fieldname -> name of the field
2) Col_pos -> column position
3) Seltext_M -> column heading in medium
4) Seltext_S -> column heading in small
5) Seltext_L -> column heading in large
6) Emphasize -> color ( it is 4 digits cxyz c color
indication x color no
y intensity z
foreground/background ).
7) Hotspot -> handle symbol
8) Edit -> changeable mode
9) No_zero -> remove the leading zero
Etc.
In slis we have one type i.e. slis_t_fieldcat_alv. This
contains all the fields related to fieldcatlog so we simply
declare our fieldcatlog internal table by referring this type
in the program.

Program to display customer details in ALV filling the


fieldcatalog manually.
*&---------------------------------------------------------------------*
*& Report ZALV2
*&
*&---------------------------------------------------------------------*
REPORT ZALV2.
type-pools : slis.
144

Sun Shine Technologies


Types : begin of ty,
kunnr type kna1-kunnr,
name1 type kna1-name1,
ort01 type kna1-ort01,
end of ty.
Data : wa type ty,
it type table of ty,
V1 LIKE KNA1-KUNNR.
SELECT-OPTIONS : S_KUNNR FOR V1.
Data: it_fieldcat type TABLE OF slis_fieldcat_alv,
wa_fieldcat like line of it_FIELDCAT.
SELECT KUNNR
NAME1
ORT01
FROM KNA1
INTO TABLE IT
WHERE KUNNR IN S_KUNNR.
WA_FIELDCAT-COL_POS = '1'.
WA_FIELDCAT-FIELDNAME = 'KUNNR'.
WA_FIELDCAT-SELTEXT_M = 'CUSTOMER NO.'.
APPEND WA_FIELDCAT TO IT_FIELDCAT.
CLEAR WA_FIELDCAT.
WA_FIELDCAT-COL_POS = '2'.
WA_FIELDCAT-FIELDNAME = 'NAME1'.
WA_FIELDCAT-SELTEXT_M = 'NAME OF CUST'.
APPEND WA_FIELDCAT TO IT_FIELDCAT.
CLEAR WA_FIELDCAT.
WA_FIELDCAT-COL_POS = '3'.
WA_FIELDCAT-FIELDNAME = 'ORT01'.
WA_FIELDCAT-SELTEXT_M = 'CITY'.
APPEND WA_FIELDCAT TO IT_FIELDCAT.
145

Sun Shine Technologies


CLEAR WA_FIELDCAT.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
IT_FIELDCAT
TABLES
T_OUTTAB

= IT_FIELDCAT
= IT.

By using function module


*&---------------------------------------------------------------------*
*& Report ZALV3
*&---------------------------------------------------------------------*
REPORT ZALV3.
TYPE-POOLS: SLIS.
DATA: WA TYPE ZALV_STR,
IT TYPE TABLE OF ZALV_STR,
V1 LIKE KNA1-KUNNR.
SELECT-OPTIONS: S_KUNNR FOR V1.
DATA: IT_FIELDCAT TYPE TABLE OF SLIS_FIELDCAT_ALV,
WA_FIELDCAT LIKE LINE OF IT_FIELDCAT.
SELECT KNA1~KUNNR
KNA1~NAME1
KNA1~ORT01
VBAK~VBELN
VBAK~ERDAT
VBAK~ERNAM
INTO TABLE IT
FROM KNA1 INNER JOIN VBAK
ON KNA1~KUNNR = VBAK~KUNNR
146

Sun Shine Technologies


WHERE KNA1~KUNNR IN S_KUNNR.
CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
EXPORTING
I_STRUCTURE_NAME
= 'ZALV_STR'
CHANGING
CT_FIELDCAT
= IT_FIELDCAT.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
IT_FIELDCAT
= IT_FIELDCAT
TABLES
T_OUTTAB
= IT.

Events :
In alv all the events are handled through
subroutines only.
Whenever we are working with events then we
must declare
an internal table which contains 2 fields like
1) Name : Name of the event
2) Form: Form which handle the event.
In slis we have one type i.e. slis_t_event which
contains these 2 fields so we simply declare our
event internal table by referring this type.
Events in alv:
1) Top_of_list :
It is an event which triggers at the top of the
displayed
output.
2) Top_of_page :
It is an event which triggers at the top of
each page.
3) End_of_page :
147

Sun Shine Technologies


It is an event which is triggered at the end of
each page.
4) End_of_list :
It is an event which is triggered at the end of
displayed
output.
5) User_command :
It is an event which is triggered at the time of
user
Clicks on any menu items as well as clicks on
any
record of any list.
This event acts like At line-selection, as well as
At user-command in the interactive report.
6) Pf_status_set :
This event is used to attach our own GUI to
the program.

*&---------------------------------------------------------------------*
*& Report ZALV3
*&
*&---------------------------------------------------------------------*
REPORT ZALV3.
TYPE-POOLS : SLIS.
DATA: WA TYPE ZALV_STR,
IT TYPE TABLE OF ZALV_STR,
V1 LIKE KNA1-KUNNR.
SELECT-OPTIONS : S_KUNNR FOR V1.
DATA : IT_FIELDCAT TYPE TABLE OF SLIS_FIELDCAT_ALV,
WA_FIELDCAT LIKE LINE OF IT_FIELDCAT.
DATA : IT_EVENT TYPE SLIS_T_EVENT,
WA_EVENT LIKE LINE OF IT_EVENT.
148

Sun Shine Technologies


Data : WA_layout type slis_layout_alv.
SELECT KNA1~KUNNR
KNA1~NAME1
KNA1~ORT01
VBAK~VBELN
VBAK~ERDAT
VBAK~ERNAM
INTO TABLE IT
FROM KNA1 INNER JOIN VBAK
ON KNA1~KUNNR = VBAK~KUNNR
WHERE KNA1~KUNNR IN S_KUNNR.
WA_EVENT-NAME = 'TOP_OF_PAGE'.
WA_EVENT-FORM = 'ZTOP'.
APPEND WA_EVENT TO IT_EVENT.
CLEAR WA_EVENT.
wa_layout-colwidth_optimize = 'X'.
wa_layout-zebra = 'X'.
CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
EXPORTING
I_PROGRAM_NAME
= SY-CPROG
I_STRUCTURE_NAME
I_INCLNAME
CHANGING
CT_FIELDCAT

= 'ZALV_STR'
= SY-CPROG
= IT_FIELDCAT

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'


Exporting
I_CALLBACK_PROGRAM

= SY-CPROG

149

Sun Shine Technologies


IS_LAYOUT
IT_FIELDCAT
IT_EVENTS

= WA_LAYOUT
= IT_FIELDCAT
= IT_EVENT

TABLES
T_OUTTAB

= IT.

FORM ZTOP.
DATA: IT_LIST TYPE SLIS_T_LISTHEADER,
WA_LIST LIKE LINE OF IT_LIST.
WA_LIST-INFO = 'CUSTOMER BASED SALES ORDER DETAILS'.
WA_LIST-TYP = 'A'.
APPEND WA_LIST TO IT_LIST.
CLEAR WA_LIST.
CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
EXPORTING
IT_LIST_COMMENTARY
= IT_LIST
I_LOGO
= 'LOGO'
.
ENDFORM.
BLOCKED ALV:
It is used to display the output in a block wise.
Steps to work with blocked alv:
1) Initialize the blocked alv by using the function module
Reuse_alv_block_list_init.
Input for the above function module is current program
i.e. sy-cprog.
2) Append the data internal table information to blocked alv by
using Reuse_alv_block_list_append.
Input for the above function module is
1) Data Internal Table
2) Fieldcatalog Internal Table
3) Event Internal Table

150

Sun Shine Technologies


4) Layout workarea
Repeat the same step for each data
internal table.
3) Display the blocked alv by using function module
Reuse_alv_block_list_display.
No need to pass any input values to this function module.
*&---------------------------------------------------------------------*
*& Report ZBLOCK
*&
*&---------------------------------------------------------------------*
REPORT ZBLOCK.
TYPE-POOLS: SLIS.
Data: v1 like vbak-vbeln.
SELECT-OPTIONS: s_vbeln for v1.
Data: wa1 type zblock1,
it1 type TABLE OF zblock1,
wa2 type zblock2,
it2 type TABLE OF zblock2.
Data : it_fcat1 type slis_t_fieldcat_alv,
wa_fcat1 like LINE OF it_fcat1,
it_fcat2 type slis_t_fieldcat_alv,
wa_fcat2 LIKE LINE OF it_fcat2.
Select vbeln
vbtyp
auart
FROM VBAK
INTO TABLE IT1
WHERE VBELN IN S_VBELN.
Select
151

Sun Shine Technologies


posnr
matnr
matwa
matkl
from vbap
into table it2
where vbeln in s_vbeln.
CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
EXPORTING
I_STRUCTURE_NAME
= 'ZBLOCK1'
CHANGING
CT_FIELDCAT
= it_fcat1.
CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
EXPORTING
I_STRUCTURE_NAME
= 'ZBLOCK2'
CHANGING
CT_FIELDCAT
= IT_FCAT2.
DATA: IT_EVENT1 TYPE SLIS_T_EVENT,
WA_EVENT1 LIKE LINE OF IT_EVENT1,
IT_EVENT2 TYPE SLIS_T_EVENT,
WA_EVENT2 LIKE LINE OF IT_EVENT2.
DATA: WA_LAYOUT1 TYPE SLIS_LAYOUT_ALV,
WA_LAYOUT2 TYPE SLIS_LAYOUT_ALV.
CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_INIT'
EXPORTING
I_CALLBACK_PROGRAM
= SY-CPROG.
CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_APPEND'
EXPORTING
IS_LAYOUT
= WA_LAYOUT1
IT_FIELDCAT
= IT_FCAT1
I_TABNAME
= 'IT1'
152

Sun Shine Technologies


IT_EVENTS
TABLES
T_OUTTAB

= IT_EVENT1
= IT1.

CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_APPEND'


EXPORTING
IS_LAYOUT
= WA_LAYOUT2
IT_FIELDCAT
= IT_FCAT2
I_TABNAME
= 'IT2'
IT_EVENTS
= IT_EVENT2
TABLES
T_OUTTAB
= IT2.
CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_DISPLAY'.
HIERARCHAL ALV:
details in a hierarchal

It is used to display the header and item


manner.

Reuse_alv_hierseq_list_display. : It is the function module


to display
the output in a
hierarchal manner.
The input
for the above function module is 2 data
internal tables.
1) 1 fieldcatalog internal table.
2) 1 key info work area.
*&---------------------------------------------------------------------*
*& Report ZHIER
*&---------------------------------------------------------------------*
REPORT ZHIER.
TYPE-POOLS: SLIS.
DATA: V1 LIKE VBAK-VBELN.
SELECT-OPTIONS: S_VBELN FOR V1.
Data : wa1 type zblock1,
it1 type TABLE OF zblock1,
153

Sun Shine Technologies


BEGIN OF WA2,
VBELN LIKE VBAP-VBELN,
POSNR LIKE VBAP-POSNR,
MATNR LIKE VBAP-MATNR,
MATWA LIKE VBAP-MATWA,
MATKL LIKE VBAP-MATKL,
END OF WA2,
IT2 LIKE TABLE OF WA2.
Data: it_fcat type slis_t_fieldcat_alv,
wa_fcat like LINE OF it_fcat.
Select vbeln
vbtyp
auart
FROM VBAK
INTO TABLE IT1
WHERE VBELN IN S_VBELN.
Select
VBELN
posnr
matnr
matwa
matkl
from vbap
into table it2
where vbeln in s_vbeln.
WA_FCAT-COL_POS = '1'.
WA_FCAT-FIELDNAME = 'VBELN'.
WA_FCAT-SELTEXT_M = 'SALES dOC'.
WA_FCAT-TABNAME = 'IT1'.
APPEND WA_FCAT TO IT_FCAT.
CLEAR WA_FCAT.
WA_FCAT-COL_POS = '2'.
154

Sun Shine Technologies


WA_FCAT-FIELDNAME = 'VBTYP'.
WA_FCAT-SELTEXT_M = 'DOC TYPE'.
WA_FCAT-TABNAME = 'IT1'.
APPEND WA_FCAT TO IT_FCAT.
CLEAR WA_FCAT.
WA_FCAT-COL_POS = '3'.
WA_FCAT-FIELDNAME = 'AUART'.
WA_FCAT-SELTEXT_M = 'ORDER TYPE'.
WA_FCAT-TABNAME = 'IT1'.
APPEND WA_FCAT TO IT_FCAT.
CLEAR WA_FCAT.
WA_FCAT-COL_POS = '1'.
WA_FCAT-FIELDNAME = 'POSNR'.
WA_FCAT-SELTEXT_M = 'ITEM NO'.
WA_FCAT-TABNAME = 'IT2'.
APPEND WA_FCAT TO IT_FCAT.
CLEAR WA_FCAT.
WA_FCAT-COL_POS = '2'.
WA_FCAT-FIELDNAME = 'MATNR'.
WA_FCAT-SELTEXT_M = 'MATERIAL'.
WA_FCAT-TABNAME = 'IT2'.
APPEND WA_FCAT TO IT_FCAT.
CLEAR WA_FCAT.
WA_FCAT-COL_POS = '3'.
WA_FCAT-FIELDNAME = 'MATWA'.
WA_FCAT-SELTEXT_M = 'MATERIAL ENTERED'.
WA_FCAT-TABNAME = 'IT2'.
APPEND WA_FCAT TO IT_FCAT.
CLEAR WA_FCAT.
WA_FCAT-COL_POS = '4'.
WA_FCAT-FIELDNAME = 'MATKL'.
WA_FCAT-SELTEXT_M = 'MATERIAL '.
WA_FCAT-TABNAME = 'IT2'.
APPEND WA_FCAT TO IT_FCAT.
155

Sun Shine Technologies


CLEAR WA_FCAT.
DATA : WA_KEY TYPE SLIS_KEYINFO_ALV.
WA_KEY-HEADER01 = 'VBELN'.
WA_KEY-ITEM01 = 'VBELN'.
CALL FUNCTION 'REUSE_ALV_HIERSEQ_LIST_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM
= SY-CPROG
IT_FIELDCAT
= IT_FCAT
I_TABNAME_HEADER
= 'IT1'
I_TABNAME_ITEM
= 'IT2'
IS_KEYINFO
= WA_KEY
TABLES
T_OUTTAB_HEADER
= IT1
T_OUTTAB_ITEM
= IT2.
Interactive ALV
ALV interactive reports are same as the normal interaction reports
Based on the user interaction it will go to next list
OBJECT:Retrieve the EBELN,BUKRS,BSTYP,BSART fields data from
EKKO and displayed as a output (list/grid) based on the user
interaction call
CODE:
*&---------------------------------------------------------------------*
*& Report ZALV_REPORT3
*&-------------------------------------------------------------------REPORT zalv_report3 NO STANDARD PAGE HEADING MESSAGE-ID
zmessage9.
INITIALIZATION.
*// Type group declaration
TYPE-POOLS slis.
156

Sun Shine Technologies


*// Tables declaration
TABLES : ekko.
*// Types declaration for EKKO
TYPES : BEGIN OF ty_ekko,
ebeln TYPE ebeln,
bukrs TYPE bukrs,
bstyp TYPE ebstyp,
bsart TYPE esart,
END OF ty_ekko.
*// Internal table declaration
DATA : lt_ekko TYPE TABLE OF ty_ekko,
lt_fieldcat TYPE slis_t_fieldcat_alv.
*// Work area declaration
DATA : wa_filedcat TYPE slis_fieldcat_alv,
wa_layout TYPE slis_layout_alv.
*// Selection screen design
SELECTION-SCREEN BEGIN OF BLOCK blk1 WITH FRAME TITLE te
xt-001.
SELECT-OPTIONS s_ebeln FOR ekko-ebeln.
SELECTION-SCREEN END OF BLOCK blk1.
*// radio Button Creation
SELECTION-SCREEN : BEGIN OF BLOCK blk2 WITH FRAME TITLE t
ext-100.
PARAMETERS : p_rad1 RADIOBUTTON GROUP rad1,
p_rad2 RADIOBUTTON GROUP rad1.
SELECTION-SCREEN : END OF BLOCK blk2.
*// Selection Screen validation
AT SELECTION-SCREEN ON s_ebeln.
IF s_ebeln IS INITIAL.
MESSAGE e000.
ENDIF.
157

Sun Shine Technologies


START-OF-SELECTION.
*// Retrieve data from EKKO
SELECT ebeln bukrs bstyp bsart
FROM ekko
INTO TABLE lt_ekko
WHERE ebeln IN s_ebeln.
END-OF-SELECTION.
*// Populating Fieldcatlog Structure
wa_filedcat-col_pos = 1.
wa_filedcat-fieldname = 'EBELN'.
wa_filedcat-outputlen = 10.
wa_filedcat-seltext_m = 'PO Number'.
APPEND wa_filedcat TO lt_fieldcat.
CLEAR wa_filedcat.
wa_filedcat-col_pos = 2.
wa_filedcat-fieldname = 'BUKRS'.
wa_filedcat-outputlen = 15.
wa_filedcat-seltext_m = 'Company Code'.
APPEND wa_filedcat TO lt_fieldcat.
CLEAR wa_filedcat.
wa_filedcat-col_pos = 3.
wa_filedcat-fieldname = 'BSTYP'.
wa_filedcat-outputlen = 25.
wa_filedcat-seltext_m = 'Document Category'.
APPEND wa_filedcat TO lt_fieldcat.
CLEAR wa_filedcat.
wa_filedcat-col_pos = 4.
wa_filedcat-fieldname = 'BSART'.
wa_filedcat-outputlen = 13.
wa_filedcat-seltext_m = 'Document Type'.
APPEND wa_filedcat TO lt_fieldcat.
CLEAR wa_filedcat.
*// Call Function Modoule for ALV Output
158

Sun Shine Technologies


IF p_rad1 EQ 'X'.
CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
EXPORTING
i_callback_program
= sy-repid
i_callback_user_command = 'INTARACTIVE'
is_layout
= wa_layout
it_fieldcat
= lt_fieldcat
TABLES
t_outtab
= lt_ekko.
ELSEIF p_rad2 EQ 'X'.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program
= sy-repid
i_callback_user_command = 'INTARACTIVE '
is_layout
= wa_layout
it_fieldcat
= lt_fieldcat
TABLES
t_outtab
= lt_ekko.
ENDIF.
*&---------------------------------------------------------------------*
*&
Form intaractive
*&--------------------------------------------------------------------*
-->UCOMM
text
*
-->SELFIELD text
*----------------------------------------------------------------------*
FORM intaractive USING ucomm LIKE sy-ucomm
selfield TYPE slis_selfield.
CASE ucomm.
WHEN '&IC1'.
SET PARAMETER ID 'BES' FIELD selfield-value.
CALL TRANSACTION 'ME23N' AND SKIP FIRST SCREEN.
ENDCASE.
ENDFORM.
"INTARACTIVE
Output:
Click on execute button
159

Sun Shine Technologies


Provide the selection screen values
Select the ALV LIST Display
Click on execute

U will get output like this

If the user interact with the output list then it call the ME23N
transaction code

160

Sun Shine Technologies

Like that we will get the output for both list and grid.
Transaction code creation for Reports
Go to SE93 Tcode
Enter the transaction code

Click on create
Enter the short text

161

Sun Shine Technologies

In the above screen we have 4 radio buttons


1.Program and screen (Dialog transaction) is used to create the
transaction code for module pool programming
2. Program and selection screen (report transaction ) is used to
create the transaction code for SE38 programs
3.Method of class for OO-ABAP
4.Transaction with variant (Variant transaction ) is used to
create the transaction code for variant
5.Transaction with parameters is used to create the transaction
code for TMG
So here we select the second radio button and click on enter
Then one window will be trigger where we need to enter the
program name (Which program we are creating the Tcode)
Select all the three check boxes under the GUI support

162

Sun Shine Technologies

Click on save and come back


If you execute the Zsample transaction code

then it call the report selection screen

163

Sun Shine Technologies


VARIANT
Variant is a place where we can store the selection screen field
values.
VARIANT CREATION:
First enter the data in selection screen

Click on save button

Enter the variant name and meaning.


Click on save.
How to create transport request number for varian:
1) Go to se38 transaction code and enter the program name.
2) Select variant radio button.

164

Sun Shine Technologies

3) Click on display

4) Enter the variant name


5) Go to utilities
6) Click on transport request number

165

Sun Shine Technologies


7) Enter the variant name.
8) Click on execute.

9) Click on continue button.

Default it displays the some request number . if you want save


then click on continue othervise click on new request number.
166

Sun Shine Technologies

10) Click on save

10)

Click on continue.

Click on continue.
167

Sun Shine Technologies


Performance Issues
In real time after completion of the program then we can do
1.Extend program check
2.Runtime Analysis
3.Sql trace
Extend program check:
This is used to avoid the unnecessary declarations of the program
Transaction code for the extended program check is SLIN
After completion of program
Go to menu bar
Program -> check -> extend program check
Execute
Double click on error and warnings
Identify the unnecessary declarations
Runtime analysis:
This is used to identify the total executable time of a program and
also identify the tips and tricks
Transaction code for the runtime analysis is SE30
Select the radio button PROGRAM
Provide the program name
Click on execute
Provide the sample input
Execute
Click on back button twice
Click on evaluate button in the bottom
168

Sun Shine Technologies


And identify the total execution time
Tips and tricks:
This is used to identify which one is used which one is not used
Sql trace:
This used to identify the execution time of the particular select
query
The Tcode for the Sql trace is ST05
Place the break point on the select query which one we want to
test
Later execute ST05
Click on active trace button
Then execute the select query
Go to ST05
Click on deactive trace
And click on display trace
Identify the time
Note: in real time most of the times SQL trace is run by BASIS
team
In real time the main program executable time in forground is
6000 seconds, if it is execute 600 seconds the goes to dump
We can identify the dump though ST22 Tcode
If the error is time out then we execute the program in
background
Steps to execute the program in background:
Execute the program
Provide the input
169

Sun Shine Technologies


In menu bar click on program -> execute background
Click on yes(continue)
Click on immediate and save
Note: execute the program in background then we get the output
as a pool request
The Tcode for identify spool request is SP01/sp02
coding standards :
1.Always use the binary search in the read statement
Ex: Read table Itab into work_area with key bukrs = 5000 binary
search.
Before writing the above statement we must sort the internal
table based on condition
2. Always use the select single instead of select up to 1 rows
3.We never write the select query without where condition
4.We never write select *
5.we never write the select query with in a select query or with in
loop
6.Always avoid the select.endselect
7.Always avoid loop with in loop
8.We always used the for all entries instead of inner join because
inner join some time leads the time out
Note: Inner join is not possible for cluster and pooled tables
9.whenever we are using the for all entries we must consider the
header level internal table having the data or not
Note: suppose if you not consider header level internal table is
having the data or not if the header level internal table contains
no data then it will fetch entire data from next level database
170

Sun Shine Technologies


10.In real time we always use the CASE instead of IF because
CASE is faster than the IF
11.In real time we always use the WHILE instead of DO
12.we always maintain the comments
13.Always clear the data of the work area after append statement
14.Always delete the adjacent duplicates before writing the next
level select query if it is applicable
15.We always use the sy-subrc after each read statement
16.Always maintain the code up to 72 colums in the ABAP editor.

ABAP DEBUGGER
It is useful to check the program execution flow behind the
screen.
- We can check select statement result, population of internal
tables.
- In detail checking is possible.
- It is useful to resolve runtime error.
Menu path:
From any screen:
- System menu -> utilities -> debug abap/screen/system
From ABAP Editor initial screen:
- SE38 -> debugger tab
- Program menu -> execute -> debugger
From ABAP Editor Program Screen:
- Program menu -> test -> debugger
- BREAK-POINT this system also takes us to debug mode.
- /h - this system is also used to debug the program.
Debugger is of two types:
- Classic debugger
- New debugger
Menu path to set default debugger:
171

Sun Shine Technologies


- SE38 utilities menu -> settings -> abap editor ->
debugging tab classical or new.
Switch between classic /new debugger:
- Debugging menu -> switch to classic/New debugger
Exit from debugger:
- Debugging /debugging menu exit
Before ECC 6 it was called as R/3. And in R/3 there was only one
debugger which was called as CLASSICAL DEBUGGER. But after
R/3 that means from ECC we have 2 ways to debugger and they
are
1. BREAK-POINT (also known as hard break)
2. /H or Click on the break-point icon (also known as
soft break)
Breakpoint is further divided into 2 types. They are
1. STATIC
2. DYNAMIC
1. STATIC: is fixed and cannot remove or add a breakpoint at run
time.
Syntax: BREAK-POINT.
And it is not recommended because if you forget to remove
this, then it will cause problems. Because if the quality team
runs the program then even for them it will be affected and
it will stop at the breakpoint.
Apart from this, there is another option to write
the breakpoint. And it is syntax: BREAK-SAPUSER, if
we are using this then only for the user the breakpoint
will be affected, it will not be affected for the quality
people or anyone else. But even here, this syntax has
to be deleted before it goes to the quality people.
2. DYNAMIC: is again divided into two types
1. SESSION to debug normal programs.
2. EXTERNAL to debug internet sites.
172

Sun Shine Technologies


Menu path to set default debugger to load:
Utilities ->settings -> ABAP editor -> debugging
- We can switch between classic to new and vice-versa using
debugging menu.
- Debugging menu -> exit: it stops debugging operation and
shows output.
CLASSICAL DEBUGGING:
- Common options available for all the tabs.
- F5 single step:
It is used to debug program line by line or step by
step.
- F6 execute:
It is used to execute set of statements logically
belongs together.
It is used to debug subroutine, function module,
method of time.
- F7 Return:
It is used to return the control back to main program.
- F8 Run:
It stops debugging, and control transfer to output
screen.
WATCHPOINT:
- It is used to create watch point.
- These can be set only in debugging mode.
- Maximum 10 watch points allowed per program.
- Consists of field name, whenever field value changes,
system prompts with message watch point reached.
- Watch point may consist of condition, and whenever system
meets the condition, system prompts with message watch
point reached.
- We can create multiple conditions using OR (or) AND.
- Watch points are very useful when we have a huge record
(eg.10, 000 records) and if something is wrong with a
particular record then we can use watchpoint.

173

Sun Shine Technologies


FIELD TAB: is used to analyze variable values, work area values
and system fields.
TABLE TAB: is used to analyze internal tables. We can append,
insert, change and delete internal tables entries.
Procedure to change internal table value: place the cursor on
value

Using F7 we can switch from one break point to another break


point.
STATIC BREAK POINT
DYNAMIC BREAK POINT
Can be set by coding, as hard coded
Can be set by highlighting the row o
line (place the cursor on any row, cli
on stop icon available in the applica
tool bar)
Breakpoint can be given unlimited
Are 30 per program
times.
Only useful to debug custom programs Are useful for custom program and
standard program
Can be set even if the program is in
Program has to be in Active mode.
Inactive mode.
We need to delete breakpoint manually Automatically gets deleted after
after completing the program.
execution of the program.
CALL STACK TAB: displays all the active calls as stack in
chronological order (events, modules list)
OVERVIEW TAB: displays all event list and subroutine list.
SETTINGS TAB: it consist additional debugging settings.
While debugging on the top left you will find some function keys
like F5, F6, F7 & F8.
1. F5 step by step execution.
2. F6 if it is gone into include program and if its already
checked and if there are no errors. Then to skip the include
with just one button then you can use this button so that it
will not debug the include program again.
174

Sun Shine Technologies


3. F7 (also known as RETURN) - if you have gone inside the
include program and to come out of it then use this button.
4. F8 (also known as RUN TO CURSOR) It will go to next
breakpoint or click on any line and hit F8, it will go to that
line wherever you have clicked (even if the breakpoint is not
set also). And if there are not breakpoints the program will
be directly executed.

Difference between Classical Debugger and New Debugger:


CLASSICAL
NEW
It opens ABAP debugger is same session It opens ABAP debugger in new se
Is valid upto 4.7EE (enterprise edition)
Is valid from ECC5.0 onwards
It does not support web dynpro
It supports to debug web dynpro
applications
applications
While debugging, you can see the values You can see all the records.
of 4 fields at a time.
New Debugger: Apart from this, there are many more advanced
features like find table, scroll up and down, delete table, search
record, drag and drop, go to row, etc. And we can also change
the program/coding while debugging.
Desktop 1,2,3 tabs: displays source code section and analyze
section.
STRUCTURES TAB: is used to analyze structures (workareas).
TABLES TAB: is used to analyze internal tables.
OBJECTS TAB: to analyze objects and events.
BREAKPOINT / WATCHPOINT: displays list of BPs and watchpoints.
DIFFERENT: is used to compare field values (or) work area values.
Module Pool Programming/Transaction/Dialog pool
programming
Transaction is the collection of sequential screens, which accept
the input and display the output.
Screen 100

Screen 200

Progra
m

175

Sun Shine Technologies


Database table

This is called dialog pool programming since we have an


interaction between screens.
This is called module pool programming because the flow logic of
each screen acts as a module (collection of modules).
Difference between MPP and Executable Program
MPP

Executable Program

1 We cant execute mpp


without a transaction
code.

we can execute the program


without transaction

2 The type of the mpp is M

The type of the program is 1

3 All the standard


transactions are mpp

All the standard reports are


executable programs.

Steps to work with Mpp:


1) Create a module pool program in se38 and implement the
retrieving logic.
2) Design the required screens (In se51) and attach to the
above program.
3) Design the required menus (In se41) and attach it to the
screen.
4) Design the Database tables (In se11) based on the client
requirement.
We can work the above four transactions within a single
transaction i.e. SE80.

Working with screen painter (SE51):

176

Sun Shine Technologies


Screen painter is a tool which contains both graphical as well as
alpha numeric mode.
Components of screen painter:
1) Attributes :
Attributes specify the type of the screen
whether it is a normal
or sub screen.
2) Layout:
Layout is the collection of screen elements i.e.,
checkboxes, radio buttons, i/p field, o/p field, table
control, tabs trip.
3) Element-list:
It contains the screen elements which are designed in
the screen and their data types and lengths.
4) Flow logic editor:
It contains the logic related to the screen.
Events:
1) PBO (PROCESS BEFOREOUTPUT):
It is an event which is triggered before displaying the
screen.
This is used to provide the default values to the
screen.
2) PAI (PROCESS AFTER INPUT):
It is an event which is triggered after providing the i/p
to the screen.
It is used to implement the logic.
3) POV (PROCESS ON VALUE REQUEST):
It is an event which is triggered at the time of user
clicks on f4 button. It is used to provide the list of
possible values to the i/p field.
4) POH (PROCESS ON HELP REQUEST):
It is an event which is triggered at the time of user
clicks on f1 button.
This is used to provide help document.
Vrm_set_values: It is the function module to provide the drop
down list to the input variable.
177

Sun Shine Technologies


The inputs for the above function module are:
1) Fieldname for which we want to provide drop down list.
2) An internal table which contains 2 fields key and text with
the possible information of the field.
In VRM we have one type i.e. VRM_VALUES which contains the
above 2 fields so we simply declare our internal table by referring
vrm_values.
Working with Table Control:
Table control is used to display the multiple records in a tabular
format.
Syntax of declaring the table control:
Controls <tablecontrolname> typetable view using screen
<screen no.>.
Syntax of transferring the data from internal table to table control:
Loop at <it> into <wa> with control <tablecontrol name> cursor
<tablecontrol name>-current_line.
Endloop.
Whenever we are working with loop and Endloop in any one of the
event, then we must declare a dummy loop and Endloop in
another event.
Working with SubScreen:
Subscreen area must be placed in normal screen only. Each
subscreen can call only 1 subscreen at a time.
Syntax for calling the subscreen area:
Call subscreen <subscreen area> including sy-repid <screen
no.>.
Sy-Repid is a system variable which contains the current program
name.
Working with Tabstrip:
178

Sun Shine Technologies


Tabstrip is the strip of tabs. Each tab contains 1 subscreen area.
Each subscreen area can call only 1 subscreen at a time. By
default tabstrip contains 2 tabs only and 1 tab is always active.
Syntax for declaring :
Controls <tabstrip name> type tabstrip.
Syntax for activating the Tab:
<tabstrip name>-Activetab = <tabname>.
Working with Validations:
Validations are used to identify the given input field is valid or not.
We can perform the validations always in the PAI of screen.
There are 3 types of validations:
1) System validations
2) Validation at flow logic editor
3) Validation at Abap editor.
System validation:
whenever we are working with date and
times then the
system itself verify the
date and time format. If it is an invalid format then it throws an
error.
Validation at flow logic editor:
Here the logic is maintained in the
flow logic editor only
and also provide the
list of possible inputs.
Syntax: field
<fieldname> values(<v1>,<v2>,<v3>).
Validation at Abap editor:
This is similar as validation in the at selection
screen event.
Syntax : field <fieldname>module <modulename>.
Whenever we are working with validations then back button
functionality will not work.
179

Sun Shine Technologies


If we want to perform the back operation then we provide AT
EXIT-COMMAND to module in the PAI and also select the function
type is E.
CHAIN---ENDCHAIN.
It is used to validate the related fields.
Without this system will display error field input in an enable
mode and the rest in disable mode to avoid this we use chain--endchain.

SAP- SCRIPTS (Tcode:SE71)


If we want to design the business documents such as invoices,
purchase documents, sales documents etc. we need layout sets.
These layout sets are designed through forms.
Sap-script is a tool to design the business document. The
standard sap provided layout sets for almost all the applications.
Most of the times, the abaper job is change the layout (or) adding
some additional logic to the standard driver program.
Components of scripts:
1) Layout : it is used to design the form (SE71)
2) Driver Program: it is used to fetch the data from the
database and transfer to layout sets.

Layout
Database

Driver
program

Address

Logo

Main

Footer

180

Sun Shine Technologies


Components of layout:
1) Header: Header is used to maintain all page settings and
administrative data.
2) Pages: page is the physical area where we can place the
windows.
We cant print the text on the page.
3) Windows: we cant print the data in this window.
There are 4 types of windows:
a) Main window
b) Variable window
c) Constant window
d) Graph window
In the script without main window we cant create the page. In
script minimum one main window and maximum 99 main
windows can be created.
4) Page window: In this we provide the coordinates for the window
to print on
the layout. We can print the text in this page
window.
5) Paragraph format: paragraph formats are used to print the
entire paragraph
with same font.
6) Character format: It is used to print the particular text with
required font &
style.
7) Documentation: These are used to maintain the document
related to form.

Printing the data on the page window:


Printing the data on the page window is always through
symbols.
Each symbol starts with & and ends with &.
There are 4 types of symbols:

181

Sun Shine Technologies


1) Program symbols: program symbols are the variables which
are defined in
driver program.
Ex: &wa-bukrs&
2) System symbols: system symbols are the system variables
Ex: &date&
3) Standard symbols: Standard symbols are coming from
TTDTG standard
database table. Ex: &Mr.&
4) Text symbols: These are window specific.
Text symbols are the variables which are defined
in page window. Ex: define &a& = 10.

Creating page: Click on page button on the top of window then


one window will be open then that window we will give the
page, meaning and next page

If u want to create the another page then go to menu and click on


Edit ----Create element

182

Sun Shine Technologies


Enter the page name and meaning click on continue.

And here give the next page as page2 and click on save and go to
page1 and change the next page as page2.
After creating the pages then we will create the all the windows.

Creating windows:
Click on window tab.
But we used only main and variable window in the real time
If we click on the window tab then the system will generate one
main window automatically .
If u click on the window button on the top of window then it will
give like this

183

Sun Shine Technologies

Then if u want to create the new window the go to edit- create


element.

Give the window name and meaning like that we can create any
number of windows.

Placing windows in to pages:


Placing windows in to page1:
Click on page windows button
Then if we want to insert the windows in to page1 go to edit-
create element.

184

Sun Shine Technologies


Then one pop up window will trigger where we can see all the
windows that we are created then double click on the window
then it will be placed in page

After placing the window then it will ask left margin , window
width , upper margin , window height
Fill all the requirements .

Like that we will insert the required windows in the page1.


After placing the windows in the page1.then we will place
windows in page2 in same way. Just give page2 to in the page
185

Sun Shine Technologies


window tab instead of page1 then page2 will be open then place
the windows in the page2 in the same way. in the page2 there is
no need of the left margin ,window width ,upper margin and
window height if that window is already used in the
page1.otherwise we will give the margins, height and width.
In the second page if u change the upper margin and window
height then it will not reflect to other pages.
But if u change the left margin and window width it will reflect the
other pages also.

Creating paragraph formats:


Click on paragraph formats button.

186

Sun Shine Technologies

Then enter the paragraph name(2 char) like p1 enter the meaning
and click on font button. Then we will select the font family , size,
and other options and click on save

If we want to create the another paragraph formats the go to


menu bar
Edit-- create element

Click on continue like that we can create any number of


paragraph formats
187

Sun Shine Technologies


Creating character formats:.
Click on character formats button
Give the chr. formats (2chars) like c1 and give the meaning click
on font button and select the font family, size same as paragraph
formats
In the script we are creating the paragraph and character formats
which are form dependent.
After creating all the go to the header (Basic Settings) give the
first page as page1 and default paragraph name as p1 or p2
or p3.
Click on save and activate.
And go to utilities -printing test then one pop up window will be
trigger and give the output device as lp01

And click on print preview then it will show output layout.


Displaying Company Name:
Click on page window button on top.Then page window will open
then select the window to place the company name
If we want to place the company name on window1 then double
click on that window and select
text element (F9) .then one
pop up window will be occurred

188

Sun Shine Technologies

If u click on the text element one window will be occurred like this

Instead of this window some times ms word will be opened on


that time go to menu and click on change editor then this window
will be open

If u click on
this button in that window then one popup
window will be open like this
Where we can see our paragraph formats and character formats
some other options select any one option based on your
requirement.
189

Sun Shine Technologies

Select one then enter the company name

And click on
(back button) and click on save and activate
then if u want to see the output
Steps to transfer the data from driver program to layout:
1) Create an executable program and implement the retrieving
logic.
2) Access the layout from the driver program by using
open_form function module.
3) Transfer the data from driver program to particular page
window by using write_form function module.
Repeat the same step for each which contains program
symbols.
4) Close the form by using close_form function module.
190

Sun Shine Technologies


Uploading company logo:
If u want up to load the logo then go to SE78 tcode then one
screen will be open like

Then expand the graphics general graphics then double click on


the BMAP BITMAP IMAGES then on window will be open where we
can see name,and 2 radio buttons (1.black and white bitmap
2.color bitmap image) if u want to select the color image then
select the 2nd radio button

Here we can upload the BMP(Bit map Image) images. First we


create the bit map image on our system and place the cursor in
the name and click on import(F5) button.

191

Sun Shine Technologies

Then on popup window will be opened then give the file name
(where we will give the file path in you system), name(name of
image), description and select the image type and click on
continue.

Then the image will be imported and it display some information


about image like this

192

Sun Shine Technologies

Uploading that image from SE78 to SE71


Select the window page button and it will open the page with all
windows. Select one window to up load the image.Here I selected
window2.Then click on text element

Then another window will be opened then go to insert - graphics


on menu bar
193

Sun Shine Technologies

Then another window will be open like this

Here we have 2 tabs one is stored as text(Obsolete) and


stored on document server your upload image is stored on
document server and select the radio button(either back and
white image (or) color) and click on

194

Sun Shine Technologies


Then another window will be opened

Give the image name and click on execute

If u click on the execute then one window will be occurred then


double click on the image name

If u double click on the image name then it will be include in you


script click on continur(enter)

195

Sun Shine Technologies

If u click on the continue then it will be include

And click on back button, click on save and activate.


Note: whenever we are working with the .TIFF images then we
must convert the .TIFF to text image by using the RSTXLDMC
standard program
Displaying the footer data:
Select the window page button and it will open the page with all
windows
Select one window to upload the footer data (like time , date,
pagno)
Note: In the real time most of the times we will use the footer
window to display the page numbers (or) sign in last page
Syntax of printing the page numbers:
196

Sun Shine Technologies


Page &page& of &sap script-form pages&.
Then we will get page number like this page 1 of 10

Sign in last page:


/: if &next page & = 0.
* Sun shine Technologies
/: endif.
Note: the above window will not work in MAIN window
Here I selected window6.

Then on window will be open where we enter the system fields to


generate the date time and page number dynamically.
Here we give the system fields in between the &
Enter the system fields and click on back button save and
activate.
Uploading customer address vendor address and main
window data:
In the script we cant write the code directly
We write the code in the print program (SE38) and call the script
in to print program by using function module
Script is nothing but print program (SE38) plus form

197

Sun Shine Technologies


Under the SE38 program we declare all the types, work area
,internal tables and selection screen design
Like
Zprint_program:(SE38)
*&---------------------------------------------------------------------*
*& Report ZPRINT_PROGRAM
*&---------------------------------------------------------------------*
REPORT zprint_program.
*// Tables declaration
TABLES mara.
*// Types declaration for Materail
TYPES : BEGIN OF ty_mara,
matnr TYPE matnr,
ersda TYPE ersda,
ernam TYPE ernam,
mtart TYPE mtart,
matkl TYPE matkl,
END OF ty_mara.
*// Types declaration for LFA1
TYPES : BEGIN OF ty_lfa1,
lifnr TYPE lifnr,
land1 TYPE land1_gp,
name1 TYPE name1_gp,
ort01 TYPE ort01_gp,
pstlz TYPE pstlz,
stras TYPE stras_gp,
END OF ty_lfa1.
*// Types declaration for KNA1
TYPES : BEGIN OF ty_kna1,
kunnr TYPE kunnr,
land1 TYPE land1_gp,
name1 TYPE name1_gp,
198

Sun Shine Technologies


ort01 TYPE ort01_gp,
pstlz TYPE pstlz,
stras TYPE stras_gp,
telf1 TYPE telf1,
END OF ty_kna1.
*// Internal Table declaration
DATA :lt_mara TYPE TABLE OF ty_mara.
*// Work area declaration
DATA : wa_mara TYPE ty_mara,
wa_lfa1 TYPE ty_lfa1,
wa_kna1 TYPE ty_kna1.
*// Selection Screen Design
SELECT-OPTIONS s_matnr FOR mara-matnr OBLIGATORY.
PARAMETERS : p_lifnr TYPE lfa1-lifnr OBLIGATORY,
p_kunnr TYPE kna1-kunnr OBLIGATORY.
*// Retrieve data from MARA
SELECT matnr ersda ernam mtart matkl
FROM mara
INTO TABLE lt_mara
WHERE matnr IN s_matnr.
*// Retrieve Vendor details
SELECT SINGLE lifnr land1 name1 ort01 pstlz stras
FROM lfa1
INTO wa_lfa1
WHERE lifnr = p_lifnr.
*// Retrieve Customer details
SELECT SINGLE kunnr land1 name1 ort01 pstlz stras telf1
FROM kna1
INTO wa_kna1
WHERE kunnr = p_kunnr.
( After writing the this code we call the script (SE71) into SE38 by
using 3 function modules:
199

Sun Shine Technologies


1.open_form
Here we pass the 5 export parameters
1.application
2.device
3.dialog
4.form Form Name in Caps
5.language
Here we provide only form parameter remaining 4 will generated
by the system it self.
2.write_form
Here we pass 4 export parameters
1.element it is the link between the print program corresponding
window in the script
2.function system will generate
3.type - system will generate.
4.window window name by default system will give mainas the
window name here we will give your own window name
For each and every window we call the write_form.
3.close_form
Each and every open_form we call corresponding close_form )
CALL FUNCTION 'OPEN_FORM'
EXPORTING
application
= 'TX'
device
= 'PRINTER'
dialog
= 'X'
form
= 'ZVISHNU_FORM'
language
= sy-langu.

200

Sun Shine Technologies


CALL FUNCTION 'WRITE_FORM'
EXPORTING
ELEMENT
= 'VENDOR'
FUNCTION
= 'SET'
TYPE
= 'BODY'
WINDOW
= 'WINDOW4'.
(go to SE71 select the page window button then select the
WINDOW4click on text element

Then enter the same name that are used in the element
parameter in write_form
Here we used /E( Text Element)

Then enter the vendor table(LFA1) field names that in between


the &

201

Sun Shine Technologies

Come back and click on the save and activate)


Note: whenever we are working with main window then we must
provide the text element name in the page window otherwise the
first line will be printed twice
CALL FUNCTION 'WRITE_FORM'
EXPORTING
ELEMENT
= 'CUSTOMER'
FUNCTION
= 'SET'
TYPE
= 'BODY'
WINDOW
= 'WINDOW3'.
(go to SE71 select the page window button then select the
WINDOW4click on text element

Then one window will be open


202

Sun Shine Technologies


Then enter the same name that are used in the element
parameter in write_form
Here we used /E( Text Element)

Enter the fields in the customer table (KNA1) in between the &

Click on back button and click on save and activate.)


loop at lt_mara INTO wa_mara.
CALL FUNCTION 'WRITE_FORM'
EXPORTING
ELEMENT
= 'MARERIAL'
FUNCTION
= 'SET'
TYPE
= 'BODY'
WINDOW
= 'MAIN'.
ENDLOOP.
(go to SE71 select the page window button then select the
MAIN windowclick on text element

203

Sun Shine Technologies

Then enter the same name that are used in the element
parameter in write_form

Then enter the field names that material table(MARA) in between


the &

Click on save and activate.


In the main window we use loop end loop because the data is in
the lt_mara internal table

204

Sun Shine Technologies


loop at lt_mara INTO wa_mara.
CALL FUNCTION 'WRITE_FORM'
EXPORTING
ELEMENT
= 'MARERIAL'
FUNCTION
= 'SET'
TYPE
= 'BODY'
WINDOW
= 'MAIN'.
ENDLOOP. )
CALL FUNCTION 'CLOSE_FORM'.
Note: In the real time whenever we are modifying the script or
smart form then we must maintain the backup because SAP script
and the smart form cant contains the version management this
will maintain all the changes of the program
Note: RSTXSCRP is the standard program which is used to
download the as well as upload the SAP SCRIPT
Steps to download/maintain the backup of SAP script:
Go to SE38 Tcode
Provide the program name as RSTXSCRP
Click on execute
Main window
1.we can print continuous text
2.we can split the main window
into small windows
3.Without main window we
cant design the SAP script
4.Main window is default
window in SAP script we cant
design the main window
5.Top and bottom commands
only work in main window

Variable window
1.based on the window size we
can print the text
2.we cant split the variable
window

3.without a variable window we


can design SAP script
4.we can create the variable
windows

205

Sun Shine Technologies


6.we can provide the text
element name in the main
window
7.next page = 0 is not possible
8.we can place main windows
up to 99 times for page

5. .Top and bottom commands


not work in variable window
6.we no need to maintain/
provide the text element name
in variable window
7. next page = 0 is possible
8.we can place only once the
variable window in page

Steps to print the Script in to PDF formate:


This is the 2 step process
1.Generate the spool request number
2.Convert the Spool requestnumber to PDF fromate
Note: We can convert the any output to PDF format
Steps to generate the spool request number:
Execute the driever program
Provide the input
Execute
Provide the output device LP01
And select the new spool request number check box
Click on print preview
Steps to identify the spool request:
Go to SP01/Sp02 Tcode
Click on type and identify the spool number
Steps to conver the spool to PDF:
Go to SE38 Tcode
206

Sun Shine Technologies


Provide the standard program name RSTXPDFT4
Click on execute
Provide spool request
Click on execute
Provide the file name with .PDF extension
Click on save
Note: By using the RSTXPDFT4 standard code we can convert any
output in to PDF format
Note: For creating the spool request number for SE38 programs
execute the programs in background the we will get the spool
number

Control commands:
Control commands are used to control the displayed output
Control commands always start with /:
Total we have different control commands in scripts
1. Include
This command is used to include the standard text which is
defined in SO10 Tcode.
Creating standard text: - The standard text is client
dependent.
Go to SO10 TX code enter the text name and click on create

207

Sun Shine Technologies


Then one window will be open like this then enter the data

After entering the data click on save


Calling standard text in to SE71
Select the window page button and it will open the page with all
windows
Select one window to up load the standard text
Here I selected window5.
Then click on text element

208

Sun Shine Technologies


Then one window will be open to insert the standard data go to
insert->text->standard

Then on window will be open in that window enter the text name
and click on continue (enter)

If u click on the continue button then standard will include in your


script

Click on back button save and activate.


209

Sun Shine Technologies


2. Define
This command is used to declare the variables
Ex: /: Define &special& = December10.
3. Address..endaddress
This command is used to display the address in the format of
target country
Ex: /: Address
* &wa_kna1-kunnr&
* &wa_kna1-name1&

.
/:endaddress.
4.protect.endprotect
This command is used to print the continuous with out any page
breaks
Ex: /:Protect
*Sun Shine Technologies
* Lingampally
* Hyd
/:endprotect.
5.Topendtop
This command is used print the header information only on main
window
Ex: /:Top
* Pur.doc item quantity
210

Sun Shine Technologies


/:endtop.
6.Bottomendbottom
This command is used to display the footer information in the
main window only
Ex: /:Bottom
* Total is &wa_total&
/:endbottom
7. If..endif.
It is like ordinary if and endif.
8. Caseendcase
It is like ordinary case and endcase
9. New-page
This command is used to call the next page
Ex: /:If &wa_mara-matnr& EQ 100-100
/:New-page
/:Endif
10.New-window
This command is used to call the new window
11.Set DATE/TIME mask
This is used to print date and time as per the our required formate
Ex: /:Set date mask = DD/MM/YYY
* &date&
12.perform..endperform.
This command is used to add the some additional functionality
(or) logic to the standard program
211

Sun Shine Technologies


13. Box
This command is used to draw the tables vertical line and
horizontal lines.
Syntax:
/: Box Xpos <value><unit>
Ypos <value><unit>
width <value><unit>
height
<value><unit>
frame <value><unit>
intensity <value><unit>.
Units: CM centimeter
MM Millimeter
CH char
IN inch
PT point
TW Twip

FONTs & BARCODES:


We can define custom font and barcodes using t.code SE73.
Barcode can be displayed using character formats of form.
Provide font family name. Provide meaning.
CREATING Fonts (or) Barcodes:
Go to SE73.
Select system barcodes and click on change
Create -> barcode name and meaning.
Continue with any code.
Continue with normal.
Barcode parameters continue.
Save -> you will get request number.
Provide short description.
Save.
212

Sun Shine Technologies


Place the cursor on the one that you created and click on test
barcode. Click on print preview and execute.
Go to Character format
Provide a character format and meaning.
Click on selection check box.
Barcode hit F4 (select out barcode)
Now go to windows select any window and click on text
elements
P1 <C1>&wa-vbap-matnr&</>

Working with standard sap scripts:


TTXFP is the standard database table which contains all the
custom driver programs and there forms.
TNAPR is the standard database table which contains all the
standard forms and there driver programs.
NACE is the standard transaction code which contains all the
applications and their forms and programs.
Whenever we click on print preview then it goes to NACE tcode
and identify the application.
Against application it identifies the output types and against the
output type it triggers the driver program and form. Based on the
form it will print the output.
STEPS TO CHANGE THE LAYOUT:
1) Identify the standard layout.
2) Copy the standard form to z form.
3) Convert the language
4) Change the z layout as per client requirement.
5) Place the new layout in the nace transaction.

213

Sun Shine Technologies

SMARTFORMS
Go to smartforms tx code

Here we have 3 radio buttons


1.form By using Form Radio Button we can create the smart
form, smart forms are client independent
2.style By using the style radio button we can create the
paragraph and character formats which are client independent.
3.textmodule by using the text module we can create the
standard text which is client independent .
Select the form radio button and enter the form name and click
on create.

214

Sun Shine Technologies

Under the smartforms the system will generate two main tasks
1.global settings
2.page and windows

Global settings contains 3 areas like


1.form attribute
2.form interface
3.global definition

Form attributes:
Form attributes contains the two tabs like
1.General attributes
2.Output options
215

Sun Shine Technologies

General attributes:
Nothing but properties of that particular form, here we have

Output options:
Under the output option tab we select the page formats and style

Form interface:
It is the interface between the form and driver program where we
can see the tabs like

216

Sun Shine Technologies


Global definition:
Is a place where we can declare all the global data types, it
contains 6 tabs

Global data:
Where we can declare the work area, internal tables and
variables.
Types: here we declare the user defined types
Field symbols : under the field symbols tab we can declare the
field symbols
Field symbol means is a data type where we can store ant type of
data
Initialization : where we can implements the subroutines
Form routines: where we can declare the subroutines
Currency / Quant. Fields : where we declare the currency and
quality fields
2.pages and windows:
Under the pages and windows system will generate one page and
one window by default
Page: page we can contain 3 tabs
1.General attributes: here we give the next page

217

Sun Shine Technologies

2.output options: here we select the page display either portrait


or landscape

3.backround picture :here we select the background picture name

218

Sun Shine Technologies


Windows: here we find out three tab buttons
1.general attributes: where we can select the window type

2.output options: where we need to provide the window size and


color for that particular window

3.conditions :here we can give the condition like

219

Sun Shine Technologies

System will generate one page and one main down by default and
we will create another page like this. After creating the second
page we will give the next page in page in page1 as page2.

Page 2 also the next page is page2.

220

Sun Shine Technologies

After creating the page we will create the windows under the
page
We have 4 types of windows
1.Main window
2.Secondary window
3.Copied window
4.Final window .
But in real time we used only main and secondary windows

Like the u will create any number of windows under one page.

221

Sun Shine Technologies

For each and every window we will give the position and size
under output options tab.

After entering the all the windows position by using form painter
option we can see the page layout and we can adjust the
windows.
After creating the windows in the page1 no need to create the
windows for page2 we simply copy the windows from page1 and
past in page2. select which window we want and copy from page1
and copy that window and past in page2.intially page2 we dont
have any windows.

222

Sun Shine Technologies

After entering the all the windows position by using form painter
option we can see the page layout and we can adjust the
windows.
After creating the windows and we need to create the text in
each and every page.

Creating style:
Go to smartforms tx code select the style radio button and enter
the style name.
223

Sun Shine Technologies

Click on create
Then one window will be trigger like this.

In this window we can enter the standard paragraph type it is


mandatory
Where we can create our own paragraph and character formats.
This are client independent
Creating the paragraph formats: right click on paragraph
formats and click on create node

224

Sun Shine Technologies


Then one window will trigger where we can enter our paragraph
name

click on continue.
One window will trigger where we can enter the description. And
give the font family size style under the font tab

Like that we create any number of paragraph formats .


Creating character formats: right click on character
formats and click on create node

One window will trigger where we can enter the character formats
name.
225

Sun Shine Technologies

Like that we can create any character formats . if we want to


create character formats for the bar code then we need to specify
the barcode type at standard settings tab.

and we go to
the font and select the font style, size and family.
At last we specify the standard paragraph at header data

Click on save and activate.

226

Sun Shine Technologies


Creating text module: go to smartforms tx code and enter the text
module name and click on create

One window will be trigger where we have two tabs


1.text
2.management

Under the management we can enter the style name.

Click on save . and click on text tab where we can enter our
standard data.

227

Sun Shine Technologies


And click on save.
Creating the company name:
Select the text under window1, enter the style name under the
output options

Click on general attributes and enter the company name click


on save and activate .

Uploading logo:first we can upload the logo by using SE78 tx


code.

Then expand the graphics general graphics then double click on


the BMAP BITMAP IMAGES then on window will be open where we
can see name,and 2 radio buttons (1.black and white bitmap
2.color bitmap image) if u want to select the color image then
select the 2nd radio button

228

Sun Shine Technologies

Here we can upload the BMP(Bit map Image) images. First we


create the bit map image on our system and place the cursor in
the name and click on import(F5) button.

Then on popup window will be opened then give the file name
(where we will give the file path in you system), name(name of
image), description and select the image type and click on
continue.

229

Sun Shine Technologies

Then the image will be imported and it display some information


about image like this

Uploading logo in to smartforms:


Select window2

230

Sun Shine Technologies

Click on F4 then one window will open like this

231

Sun Shine Technologies


Click on execute .
Then the system will generate list of logos that are available
select your logo and double click on it.

click on save and


activate.
Uploading standard text:
Go to SO10 TX code enter the text name and click on create

232

Sun Shine Technologies

Then on window will be open like this then enter the data

Click on save and come back.


Calling standard text into smartforms:
Select the text under window7. And select the include as the text
type.

233

Sun Shine Technologies

Then system will ask

click on yes
Then one window will trigger like this

click on F4.
Then one window will open like this

234

Sun Shine Technologies

Enter the text name in name field and click on enter.


otherwise Click on execute then system will generate list of the
standard text that are available then select you text

Click on save and activate.


Calling text module in to smartform: calling text module
select the any text under window

Select the text type as text module and click on enter the
system will ask
235

Sun Shine Technologies

click on yes.
Then one window will be open like this

Under the output option give the style name.

Under the general attributes give the name and click on enter
then the window like this

236

Sun Shine Technologies

Click on save and activate.


Creating the footer data:
First select the text under the window to create the footer data
And go to utilities -> field lisi on/off

Then we will see like this under the system fields we have all the
system fields just select the field and drag and drop.

237

Sun Shine Technologies

Click on save and activate.


Displaying the vendor address:in smart if you want we can
write the code in smartform itself otherwise we can write in
SE38(Print program)
Here I am writing code in smart form it self to display the vendor
address
Right click on window4 create -> flow logic -> program lines

Then one window will open like this.


238

Sun Shine Technologies

Here under the output parameters we give data storage


name(work area (or) internal table name)
Under the input parameter we give that parameters that are used
in where conditions in select query .

After writing the code we need to define the types declaration


for lfa1 under the global definition

239

Sun Shine Technologies


Select the global definition under global definition we have sex
tabs under the types tab we can declare the types.

Global data:
Where we can declare the variables and work area internal tables
Under the global data we can declare the work area

And click on save.


The input parameters that are used in the window will be defined
at form interface
Form interface:Itis act as the interface between the form and
driver program.

240

Sun Shine Technologies

In the form interface we declare the lifnr and click on save and
activate. And click on text under that window where we can
display the values dynamically.

Then go to utilities -> field lisi on/off

under global data we have the fields just drag


and drop
241

Sun Shine Technologies


If u want to apply the style go to output tab give the style name

Under General attributes we enter the data like this

Click on save and activate


Displaying the customer address and main window data:
For this one I write the code in se38
Go SE38 tx code and create the driver program
Zsprint_program
*// Tables declaration
TABLES ekpo.
*// Constants declaration
CONSTANTS con_sform TYPE tdsfname VALUE 'ZSMARTFORM'.
*// Types declaration for EKPO
TYPES : BEGIN OF ty_ekpo,
242

Sun Shine Technologies


ebeln TYPE ebeln,
ebelp TYPE ebelp,
statu TYPE astat,
aedat TYPE paedt,
txz01 TYPE txz01,
matnr TYPE matnr,
bukrs TYPE bukrs,
END OF ty_ekpo.
*// Types declaration for KNA1
TYPES : BEGIN OF ty_kna1,
kunnr TYPE kunnr,
land1 TYPE land1_gp,
name1 TYPE name1_gp,
ort01 TYPE ort01_gp,
pstlz TYPE pstlz,
stras TYPE stras_gp,
telf1 TYPE telf1,
END OF ty_kna1.
*// Internal table declaration
DATA : lt_ekpo TYPE TABLE OF ty_ekpo.
*// Workarea declaration
DATA : wa_ekpo TYPE ty_ekpo,
wa_kna1 TYPE ty_kna1.
*// Local variable declaration
DATA : lv_fname TYPE rs38l_fnam.
*// Selection screen design
SELECT-OPTIONS s_ebeln FOR ekpo-ebeln OBLIGATORY.
PARAMETERS: p_kunnr TYPE kna1-kunnr OBLIGATORY,
p_lifnr TYPE lfa1-lifnr.
*// Retrieve data from EKPO
SELECT ebeln ebelp statu aedat txz01 matnr bukrs
FROM ekpo
INTO TABLE lt_ekpo
WHERE ebeln IN s_ebeln.
*// Retrieve Vendor details
243

Sun Shine Technologies


*//Retrieve Data from
SELECT SINGLE kunnr land1 name1 ort01 pstlz stras telf1
FROM kna1
INTO wa_kna1
WHERE kunnr = p_kunnr.
Linking the driver program and smart form:
Now we can create the global structure for kna1 and table type
for ekpo
Go to SE11 tx code select the data type radio button enter the
structure name and click on create
Structure for kna1:

Creating table type for ekpo:


Go to SE11 tx code
Select the data type radio button first we create the global
structure for ekpo by reference that one we will create the table
type
Structure for ekpo:

244

Sun Shine Technologies

Creating table type for ekpo:


Go to SE11 tx code and enter the table type name and click on
create and select the table type radio button where we enter the
structure name under the line type.

Click on save and activate


After creating the global structure and table type we need to
specify that in form interface under global settings in the
smartform
Under the form interface tables tab we declare the table type

245

Sun Shine Technologies

Under the import tab we declare the global structure

And click on save and activate


Calling smart form in to SE38:
By using SSF_FUNCTION_MODULE_NAMEfunction module we
call the smart form in to SE38
*// Call SSF_FUNCTION_MODULE_NAME
CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
EXPORTING
formname = con_sform
IMPORTING
fm_name = lv_fname.
Here we give the smartform name as the exporting parameter
and function module name as the import parameter

246

Sun Shine Technologies


Here we cant provide the form name directly first we store the
form name in constant variable and give that constant variable
name as form name
*// Constants declaration
CONSTANTS con_sform TYPE tdsfname VALUE 'ZVISHNU_SMARTFO
RMS1'.
This con_sform is given as formname
Here the form name is of the type tdsfname.
If u want to see the type double click on the function module
name under the import parameter we can see the type of form
name

Importing parameters we give the function module name we cant


give the function module name first we store the function module
name in local variable and give the local variable name as the
fm_name
*// Local variable declaration
DATA : lv_fname TYPE rs38l_fnam.
The function module is of the type rs38l_fnam.
If u want to see the type of function module double click on
function module name under the export parameters we can see
the name

247

Sun Shine Technologies

Next we call the function module that are created by the system
while executing the smart forms
Go your smart form environment -> function module name

System will give the function module of that particular smart form

Copy the function module name and go to SE38 we call that


function module under SE38
CALL FUNCTION '/1BCDWB/SF00000214'
EXPORTING
i_lifnr
= p_lifnr
wa_kna1
= wa_kna1.
tables
gt_ekpo
= lt_ekpo.
the local variable tack the function module name at runtime so
first we call the function module by using function module name
later we give the local variable name
248

Sun Shine Technologies


CALL FUNCTION lv_fname
EXPORTING
i_lifnr
= p_lifnr
wa_kna1
= wa_kna1
tables
gt_ekpo
= lt_ekpo.
Click on save and activate the program.
And displaying the customer address
Go to your smart form and select the customer address
window( Here I selected window5)
Select the text under that window

And give the style name under output tab

Click on general attributes tab and go to utilities -> field list on/off

We get like this

249

Sun Shine Technologies

under import interface we have kna1 data just


drag and drop

Save and activate


Displaying main window data:
Right click om main window create -> table

If we create the table under table we have


1.header
2.main area
250

Sun Shine Technologies


3.footer
Table we have 5 tabs

Then we will get like this

Click on details

Then we will get like this

251

Sun Shine Technologies

Here we created the like types

Click on save and click on table painter

252

Sun Shine Technologies


Click on draw line and columns

Then select the frame by pressing shift + mouse left click and
select the outer frame to give the frame to outer frame

Like that we create the frames after right click on header create
-> line type

One window will open where we need to enter the line type and
style

253

Sun Shine Technologies

Select the line type for header


Select the line type and enter the style name click on save
Select the line type and enter the style name click on save

Like that we select the line type for main area and footer

254

Sun Shine Technologies


For main area

And click on save


For footer

Click on save
Under main window we can see like this

Create text for each and every cell


255

Sun Shine Technologies

Click on save
After creating all the windows then double click on the table
then we get like this

Go to Data tab
Under the data tab we loop the internal table

256

Sun Shine Technologies


And declare the wa_ekpo under global data under global
definition

Click on save and activate


Displaying the table header:

Like that we can enter the headers for all fields


Creating the table footer :
Select the text under the footer where we can enter the footer
data manually

257

Sun Shine Technologies

Creating main area:


Select the test under the main area

Go to utilities select field list on/off

under the global parameters we have the ekpo


data

258

Sun Shine Technologies


Drag and drop the fields there corresponding text

Like that we display the data dynamically in each and every text
in the main area.
Displaying the purchase order number:
Right click on window create -> flow logic -> program lines

Enter the code


259

Sun Shine Technologies

And go to the global definition and we need to declare the


lv_ebeln.

Displaying the lv_ebeln


Select the text under the purchase order window

260

Sun Shine Technologies

Under conditions we use only on first page

Save and activate.


Display barcode:
Here we generate the barcode based on the purchase order
number
So first we retrieve the purchase order data, in this form under
the purchase order window we already retrieved the purchase
order data but in the smartforms data in the window is window
dependent so we write the code again in this winow

261

Sun Shine Technologies

Select the text under the barcode window (window9) and enter
the style name

Go to general attributes

262

Sun Shine Technologies

Under the global data we have lv_ebeln fields drag and drop and
select the character type as
C2 14pt bar code

Click on save and activate


Upload background picture :

Click on F4 one window will trigger

263

Sun Shine Technologies

Click on execute
Then it display list of images that are available

Select one picture and double click on it and select the resolution
and output mode and position click on save and activate then in
the output mode we can see the background picture

264

Sun Shine Technologies

SE38 code:
REPORT zsprint_program1 NO STANDARD PAGE HEADING.
*// Tables declaration
TABLES ekpo.
*// Constants declaration
CONSTANTS con_sform TYPE tdsfname VALUE 'ZVISHNU_SMARTFO
RMS1'.
*// Types declaration for EKPO
TYPES : BEGIN OF ty_ekpo,
ebeln TYPE ebeln,
ebelp TYPE ebelp,
statu TYPE astat,
aedat TYPE paedt,
txz01 TYPE txz01,
matnr TYPE matnr,
265

Sun Shine Technologies


bukrs TYPE bukrs,
END OF ty_ekpo.
*// Types declaration for KNA1
TYPES : BEGIN OF ty_kna1,
kunnr TYPE kunnr,
land1 TYPE land1_gp,
name1 TYPE name1_gp,
ort01 TYPE ort01_gp,
pstlz TYPE pstlz,
stras TYPE stras_gp,
telf1 TYPE telf1,
END OF ty_kna1.
*// Internal table declaration
DATA : lt_ekpo TYPE TABLE OF ty_ekpo.
*// Workarea declaration
DATA : wa_ekpo TYPE ty_ekpo,
wa_kna1 TYPE ty_kna1.
*// Local variable declaration
DATA : lv_fname TYPE rs38l_fnam.
*// Selection screen design
SELECT-OPTIONS s_ebeln FOR ekpo-ebeln OBLIGATORY.
PARAMETERS: p_kunnr TYPE kna1-kunnr OBLIGATORY,
p_lifnr TYPE lfa1-lifnr.
*// Retrieve data from EKPO
SELECT ebeln ebelp statu aedat txz01 matnr bukrs
FROM ekpo
INTO TABLE lt_ekpo
WHERE ebeln IN s_ebeln.
*// Retrieve Vendor details
*//Retrieve Data from
SELECT SINGLE kunnr land1 name1 ort01 pstlz stras telf1
FROM kna1
INTO wa_kna1
WHERE kunnr = p_kunnr.
266

Sun Shine Technologies


CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
EXPORTING
formname
= con_sform
IMPORTING
FM_NAME
= lv_fname.
CALL FUNCTION lv_fname
EXPORTING
i_lifnr
= p_lifnr
wa_kna1
= wa_kna1
tables
gt_ekpo
= lt_ekpo.
Output:

267

Sun Shine Technologies

NACE TX CODE: (configuration settings)


Go to NACE tx code where we can see the application type
EF- for the purchase order

268

Sun Shine Technologies

Select the EF and click on output type

Select the NEU for new PO print out

269

Sun Shine Technologies

Double click on processing routines

We will get like this

Click on change

270

Sun Shine Technologies


Click on
Then one window will be trigger where we can enter the
Transm.Medium(Telex), layout module(Function Module name),
program(Print program name), form routine(NEU) , form(smart
from name)

Click on save
While saving it ask the transport request number
Here we create the customizing request instead of workbench
request
Difference between the script and smart from:
Script
1.Script is client dependent
2.in script we cant design the
page without main window
3.In the script minimum one
main window and maximum 99
main windows we can place one
page
4.In script we can creating

Smart form
1.Smart form is the client
independent
2.where as smart form we can
design the page without main
window
3.whereas in smart form
minimum 0 main windows
maximum 1 main window we
271

Sun Shine Technologies


paragraph and character
formats which are from
dependent

can place on one page


4.whereas in smart form by
using smart style option we can
design the paragraph and
5.In script for displaying the
character format which are
static text we are using
program independent
standard text option (so10)
5. whereas in smart from we
standard text is client
can use the same options for
dependent
displaying static text and in
smartform they introduced text
module concept for displaying
6.In script we cant display the
static text .text module is the
background pictures
client independent
7. In script we cant write the
6. In smart from we can display
code
the back ground pictures
8.For calling the script into the
7.In smart form we can write
driver program we are using the the code
below function modules
8. .For calling the smartform
1.open_form
into the driver we are using the
2.Write_form
below function module
3.Close_form
Ssf_function_module_name
9.For giving the page breaks in
the script we are using the
function modules
9.In the smart form we have the
10.In script we have 4 types of
option like page breaks
windows
10.In smart form we have 4
1.Varible window
types of windows
2.Main window
1.Secondary window
3.Constant window
2.main window
4.Graphical window
3.copies window
11.In the script we dont have
4.final window
the drag and drop options in
11.In smart form we can drag
windows
and drop option

272

Sun Shine Technologies


BDC: (Batch Data Conversion)
Batch Data Communication or BDC is a batch interfacing
technique that SAP developed. It is mainly used for uploading
data into the SAP R/3 system. BDC works by simulating the user
input from transactional screen via an ABAP program.

The data input data file will come in the form of a flat file which
the user save as file type txt file or prn file from the Microsoft
Excel program. An Abaper will create a program to read the text
file and upload into the SAP system.

BDC TYPES:
There are 3 types
1.Call Transaction Method
2.Session Method
3.Direct Input Method
NOTE: Both the session and call transaction method we call
BATCH INPUT method
Where the direct inputs are the standard programs to posted the
data in to SAP.

CALL TRANSATION FOR XK01:


Flat File

Itab

Tcode

SAP DB

If you are uploading data from the non-sap to sap then the flat file
structure and the Itab structure should be same data elements
also same and sequence also same but field names may be
different
273

Sun Shine Technologies


By using call transaction method we can upload master and
transaction data but we are going to prepare call transaction for
small amount of data.
In call transaction method manually we need to capture the error
records
In call Transaction method we are using 3 update modes
1.Synchronous (S)
2.Asynchronous(A)
3.Local(L)
Synchronus data processing is that in which the program calling
the update task waits for the update work process to finish the
update before it continues processing.
In Asynchronus update the callng program does not wait for
update work process to finish the update and continues as
normal.

A BDC done with sessions is always synchronus.


A BDC with call transaction is by default asynchronus
unless you define it explicitly as
call transaction 'XXXX' ...... update 'S'.

In the call transaction we are using 3 screen display modes


1.All screen Display(A)
2.No Screen Display(N)
3.Error Screen Display(E)
274

Sun Shine Technologies


Call transaction steps :
1.Recording(SHDB)
2.BDCDATA Structure
3. BDCMSGCOLL Structure
4.Display Modes (A/N/E)
5.Update Modes
6.Call Transaction Syntax
BDCDATA Structure:
It is a structure which contains 5 fields
1.PROGRAM - BDC module pool program name
2.DYNPRO - BDC Screen number
3.DYNBEGIN - BDC screen start
4.FNAM - Field name
5.FVAL - BDC field value
By using BDCDATA structure we are uploading data into SAP/R3
database by using call transaction method
BDCMSGCOLL: By using this structure we are populating the error
records in BDC call transaction method
This structure contains
1.TCODE - BDC Transaction code
2.DYNAME - Batch input module name
3.DYNUMB - Batch input screen number
4.MSGTYP- Batch input message type
5.MSGSPRA - Language ID of a message
275

Sun Shine Technologies


6.MSGID - Batch input message ID
7.MSGNR - Batch input message number
8.MSGV1 - Variable part of a message
9.MSGV2 - Variable part of a message
10.MSGV3 - Variable part of a message
11.MSGV4 - Variable part of a message
12.ENV - Batch input monitoring activity
13.FLDNAME Field Name
NOTE: the above 2,3,4,5 steps we are applying at call transaction
syntax(6th step)
Syntax: call transaction <TCODE> using <BDCDATA Structure>
MODE <Screen Display
Mode>
Update <Update Mode>
Messages into <BDCMSGCOLL
Structure >.
1.Recording (Transaction code SHDB)
Recording is a process that is provided by the SAP system to
generate the SAP data structure for batch data communication.
A sample recording for the transaction XK01 is explained
below.

Step1:Go to SHDB Tcode


Click on new recording

276

Sun Shine Technologies


Step2: Then one popup window will trigger where we can give
the recording name and Tcode

Click on start recording


Step3: Then it will call the XK01 tcode then enter the mandatory
fields

Click on enter
Then another screen will trigger then enter the fields we want
then click on enter like that we give the field for each and every
screen
Then we will get screen like this
277

Sun Shine Technologies

Click on save and click on back button


Select the recording and click on program

Then one window will trigger where we will give the program
name

278

Sun Shine Technologies

click on enter
And another window will trigger where we will give the short
description and click on source code then system will create the
program

279

Sun Shine Technologies

*&---------------------------------------------------------------------*
*& Report ZVSIHNU_BDC_VENDOR_CREAT
*&---------------------------------------------------------------------*
REPORT ZVSIHNU_BDC_VENDOR_CREATE NO STANDARD PAGE HE
ADING.
INITIALIZATION.
*//Internal Table Dclaration
DATA:lt_final TYPE TABLE OF zfinal_structure2.
*//Work Area Delaration
DATA:wa_final TYPE zfinal_structure2.
*

Batchinputdata of single transaction


DATA: bdcdata TYPE TABLE OF bdcdata,
280

Sun Shine Technologies


wa_bdcdata TYPE bdcdata.
*
messages of call transaction
DATA: messtab LIKE bdcmsgcoll OCCURS 0 WITH HEADER LINE,
wa_messtab TYPE bdcmsgcoll,
lt_messtab TYPE TABLE OF bdcmsgcoll.
*//Local Varible delaration
DATA:con_path TYPE string.
*// Selection screen design
PARAMETERS : p_path TYPE rlgrap-filename.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_path.
CALL FUNCTION 'F4_FILENAME'
EXPORTING
program_name = syst-cprog
dynpro_number = syst-dynnr
IMPORTING
file_name
= p_path.
START-OF-SELECTION.
con_path = p_path.
*//Uploading Data from Prsenetation Server
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = con_path
filetype = 'ASC'
TABLES
data_tab = lt_final.
LOOP AT lt_final INTO wa_final.
PERFORM bdc_dynpro
USING 'SAPMF02K' '0100'.
PERFORM bdc_field
USING 'BDC_CURSOR'
'RF02K-KTOKK'.
PERFORM bdc_field
USING 'BDC_OKCODE'
'/00'.
PERFORM bdc_field
USING 'RF02K-BUKRS'
wa_final-bukrs.
PERFORM bdc_field
USING 'RF02K-EKORG'
281

Sun Shine Technologies


PERFORM
PERFORM
PERFORM
PERFORM
PERFORM
PERFORM
PERFORM
PERFORM
PERFORM
PERFORM
PERFORM
PERFORM
PERFORM
PERFORM
PERFORM
PERFORM
PERFORM
PERFORM
PERFORM
PERFORM
PERFORM

wa_final-ekorg.
bdc_field
USING 'RF02K-KTOKK'
wa_final-ktokk.
bdc_dynpro
USING 'SAPMF02K' '0110'.
bdc_field
USING 'BDC_CURSOR'
'LFA1-LAND1'.
bdc_field
USING 'BDC_OKCODE'
'/00'.
bdc_field
USING 'LFA1-ANRED'
wa_final-anred.
bdc_field
USING 'LFA1-NAME1'
wa_final-name1.
bdc_field
USING 'LFA1-SORTL'
wa_final-sortl.
bdc_field
USING 'LFA1-NAME2'
wa_final-name2.
bdc_field
USING 'LFA1-STRAS'
wa_final-stras.
bdc_field
USING 'LFA1-ORT01'
wa_final-ort01.
bdc_field
USING 'LFA1-PSTLZ'
wa_final-pstlz.
bdc_field
USING 'LFA1-LAND1'
wa_final-land1.
bdc_dynpro
USING 'SAPMF02K' '0120'.
bdc_field
USING 'BDC_CURSOR'
'LFA1-KUNNR'.
bdc_field
USING 'BDC_OKCODE'
'/00'.
bdc_dynpro
USING 'SAPMF02K' '0130'.
bdc_field
USING 'BDC_CURSOR'
'LFBK-BANKS(01)'.
bdc_field
USING 'BDC_OKCODE'
'=ENTR'.
bdc_dynpro
USING 'SAPMF02K' '0210'.
bdc_field
USING 'BDC_CURSOR'
'LFB1-FDGRV'.
bdc_field
USING 'BDC_OKCODE'
'/00'.
282

Sun Shine Technologies


PERFORM bdc_field
USING 'LFB1-AKONT'
wa_final-akont.
PERFORM bdc_field
USING 'LFB1-FDGRV'
wa_final-fdgrv.
PERFORM bdc_dynpro
USING 'SAPMF02K' '0215'.
PERFORM bdc_field
USING 'BDC_CURSOR'
'LFB1-ZTERM'.
PERFORM bdc_field
USING 'BDC_OKCODE'
'/00'.
PERFORM bdc_field
USING 'LFB1-ZTERM'
wa_final-zterm.
PERFORM bdc_dynpro
USING 'SAPMF02K' '0220'.
PERFORM bdc_field
USING 'BDC_CURSOR'
'LFB5-MAHNA'.
PERFORM bdc_field
USING 'BDC_OKCODE'
'/00'.
PERFORM bdc_dynpro
USING 'SAPMF02K' '0310'.
PERFORM bdc_field
USING 'BDC_CURSOR'
'LFM1-WAERS'.
PERFORM bdc_field
USING 'BDC_OKCODE'
'/00'.
PERFORM bdc_field
USING 'LFM1-WAERS'
wa_final-waers.
PERFORM bdc_dynpro
USING 'SAPMF02K' '0320'.
PERFORM bdc_field
USING 'BDC_CURSOR'
'RF02K-LIFNR'.
PERFORM bdc_field
USING 'BDC_OKCODE'
'=ENTR'.
CALL TRANSACTION 'XK01' USING bdcdata MODE 'A'
UPDATE 'S'
MESSAGES INTO messtab.
*//Capture Error Records
IF messtab IS NOT INITIAL.
LOOP AT messtab INTO wa_messtab.
APPEND wa_messtab TO lt_messtab.
ENDLOOP.
ENDIF.
283

Sun Shine Technologies


REFRESH: messtab,bdcdata.
CLEAR wa_final.
ENDLOOP.
LOOP AT lt_messtab INTO wa_messtab.
DATA:wa_msg TYPE string.
*//Formating Error Records
CALL FUNCTION 'FORMAT_MESSAGE'
EXPORTING
id = wa_messtab-msgid
no = wa_messtab-msgnr
v1 = wa_messtab-msgv1
v2 = wa_messtab-msgv2
v3 = wa_messtab-msgv3
v4 = wa_messtab-msgv4
IMPORTING
msg = wa_msg.
//Displaying the error message
WRITE:/10 wa_msg.
ENDLOOP.
*----------------------------------------------------------------------*
*
Start new screen
*
*----------------------------------------------------------------------*
FORM bdc_dynpro USING program dynpro.
wa_bdcdata-program = program.
wa_bdcdata-dynpro = dynpro.
wa_bdcdata-dynbegin = 'X'.
APPEND wa_bdcdata TO bdcdata.
CLEAR : wa_bdcdata.
ENDFORM.
"BDC_DYNPRO
*----------------------------------------------------------------------*
*
Insert field
*
*----------------------------------------------------------------------*
FORM bdc_field USING fnam fval.
wa_bdcdata-fnam = fnam.
wa_bdcdata-fval = fval.
APPEND wa_bdcdata TO bdcdata.
284

Sun Shine Technologies


CLEAR : wa_bdcdata.
ENDFORM.
"BDC_FIELD
Call transaction for XK02:
*&---------------------------------------------------------------------*
*& Report ZVISHNU_BDC_UPLOAD
*&
*&---------------------------------------------------------------------*
REPORT zvishnu_bdc_upload NO STANDARD PAGE HEADING.
INITIALIZATION.
DATA:lt_final TYPE TABLE OF zsfinal.
DATA:wa_final TYPE zsfinal.
*// Batchinputdata of single transaction
DATA: bdcdata TYPE TABLE OF bdcdata,
wa_bdcdata TYPE bdcdata.
*// messages of call transaction
DATA: messtab LIKE bdcmsgcoll OCCURS 0 WITH HEADER LINE,
wa_messtab TYPE bdcmsgcoll,
lt_messtab TYPE TABLE OF bdcmsgcoll.
*// lOCAL VARIABLE DECLARATION
DATA : lv_path TYPE string.
*// Selection screen design
PARAMETERS : p_path TYPE rlgrap-filename.
*// Providing F4 functionality
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_path.
*// Call Function Module F4_FILENAME for getting F4 functionality
CALL FUNCTION 'F4_FILENAME'
EXPORTING
program_name = syst-cprog
285

Sun Shine Technologies


dynpro_number = syst-dynnr
IMPORTING
file_name
= p_path.
*// Start of selection
START-OF-SELECTION.
lv_path = p_path.
*// Call GUI_UPLOAD FM for uploading the data from Presentation
server
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename
= lv_path
filetype
= 'ASC'
has_field_separator = '|'
TABLES
data_tab
= lt_final.
DATA : wa_lfa1 TYPE lfa1.
LOOP AT lt_final INTO wa_final.
PERFORM bdc_dynpro
USING 'SAPMF02K' '0101'.
PERFORM bdc_field
USING 'BDC_CURSOR'
'WRF02K-D0320'.
PERFORM bdc_field
USING 'BDC_OKCODE'
'/00'.
PERFORM bdc_field
USING 'RF02K-LIFNR'
wa_final-lifnr.
PERFORM bdc_field
USING 'RF02K-BUKRS'
wa_final-bukrs.
PERFORM bdc_field
USING 'RF02K-EKORG'
wa_final-ekorg.
PERFORM bdc_field
USING 'RF02K-D0110'
'X'.
PERFORM bdc_field
USING 'RF02K-D0120'
'X'.
PERFORM bdc_field
USING 'RF02K-D0130'
'X'.
PERFORM bdc_field
USING 'RF02K-D0210'
'X'.
286

Sun Shine Technologies


PERFORM bdc_field
USING 'RF02K-D0310'
'X'.
PERFORM bdc_field
USING 'WRF02K-D0320'
'X'.
PERFORM bdc_dynpro
USING 'SAPMF02K' '0110'.
PERFORM bdc_field
USING 'BDC_CURSOR'
'LFA1-ANRED'.
PERFORM bdc_field
USING 'BDC_OKCODE'
'/00'.
PERFORM bdc_field
USING 'LFA1-ANRED'
wa_final-anred.
PERFORM bdc_field
USING 'LFA1-NAME1'
wa_final-name1.
PERFORM bdc_field
USING 'LFA1-SORTL'
wa_final-sortl.
PERFORM bdc_field
USING 'LFA1-STRAS'
wa_final-stras.
PERFORM bdc_field
USING 'LFA1-PFACH'
wa_final-pfach.
PERFORM bdc_field
USING 'LFA1-ORT01'
wa_final-ort01.
PERFORM bdc_field
USING 'LFA1-PSTLZ'
wa_final-pstlz.
PERFORM bdc_field
USING 'LFA1-PSTL2'
wa_final-pstl2.
PERFORM bdc_field
USING 'LFA1-LAND1'
wa_final-land1.
PERFORM bdc_field
USING 'LFA1-SPRAS'
wa_final-spras.
PERFORM bdc_dynpro
USING 'SAPMF02K' '0120'.
PERFORM bdc_field
USING 'BDC_CURSOR'
'LFA1-KUNNR'.
PERFORM bdc_field
USING 'BDC_OKCODE'
'/00'.
PERFORM bdc_field
USING 'LFA1-BRSCH'
wa_final-brsch.
PERFORM bdc_dynpro
USING 'SAPMF02K' '0130'.
PERFORM bdc_field
USING 'BDC_CURSOR'
'LFBK-BANKS(01)'.
287

Sun Shine Technologies


PERFORM bdc_field
USING 'BDC_OKCODE'
'=BANK'.
PERFORM bdc_dynpro
USING 'SAPLBANK' '0100'.
PERFORM bdc_field
USING 'BDC_CURSOR'
'BNKA-BANKA'.
PERFORM bdc_field
USING 'BDC_OKCODE'
'=ENTR'.
PERFORM bdc_field
USING 'BNKA-BANKA'
wa_final-banka.
PERFORM bdc_field
USING 'BNKA-STRAS'
wa_final-stras.
PERFORM bdc_field
USING 'BNKA-ORT01'
wa_final-ort01.
PERFORM bdc_dynpro
USING 'SAPMF02K' '0130'.
PERFORM bdc_field
USING 'BDC_CURSOR'
'LFBK-BANKS(01)'.
PERFORM bdc_field
USING 'BDC_OKCODE'
'=ENTR'.
PERFORM bdc_dynpro
USING 'SAPMF02K' '0210'.
PERFORM bdc_field
USING 'BDC_CURSOR'
'LFB1-ZINRT'.
PERFORM bdc_field
USING 'BDC_OKCODE'
'/00'.
PERFORM bdc_field
USING 'LFB1-AKONT'
wa_final-akont.
PERFORM bdc_field
USING 'LFB1-FDGRV'
wa_final-fdgrv.
PERFORM bdc_field
USING 'LFB1-ZINRT'
wa_final-zinrt.
PERFORM bdc_dynpro
USING 'SAPMF02K' '0310'.
PERFORM bdc_field
USING 'BDC_CURSOR'
'LFM1-KZAUT'.
PERFORM bdc_field
USING 'BDC_OKCODE'
'/00'.
PERFORM bdc_field
USING 'LFM1-WAERS'
wa_final-waers.
PERFORM bdc_field
USING 'LFM1-INCO1'
wa_final-inco1.
PERFORM bdc_field
USING 'LFM1-INCO2'
288

Sun Shine Technologies


PERFORM
PERFORM
PERFORM
PERFORM

wa_final-inco2.
bdc_field
USING 'LFM1-KZAUT'
'X'.
bdc_dynpro
USING 'SAPMF02K' '0320'.
bdc_field
USING 'BDC_CURSOR'
'RF02K-LIFNR'.
bdc_field
USING 'BDC_OKCODE'
'=ENTR'.

CALL TRANSACTION 'XK02' USING bdcdata MODE 'A'


UPDATE 'A'
MESSAGES INTO messtab.
*// Capturing error records
IF messtab IS NOT INITIAL.
LOOP AT messtab INTO wa_messtab.
APPEND wa_messtab TO lt_messtab.
CLEAR wa_messtab.
ENDLOOP.
ENDIF.
REFRESH : bdcdata, messtab.
ENDLOOP.
*// Formatting error messages
DATA : wa_msg TYPE string.
LOOP AT lt_messtab INTO wa_messtab.
CALL FUNCTION 'FORMAT_MESSAGE'
EXPORTING
id = wa_messtab-msgid
no = wa_messtab-msgnr
v1 = wa_messtab-msgv1
v2 = wa_messtab-msgv2
v3 = wa_messtab-msgv3
v4 = wa_messtab-msgv4
IMPORTING
msg = wa_msg.
*// Display error message
WRITE : /10 wa_msg.
ENDLOOP.
289

Sun Shine Technologies


*----------------------------------------------------------------------*
*
Start new screen
*
*----------------------------------------------------------------------*
FORM bdc_dynpro USING program dynpro.
* CLEAR bdcdata.
wa_bdcdata-program = program.
wa_bdcdata-dynpro = dynpro.
wa_bdcdata-dynbegin = 'X'.
APPEND wa_bdcdata TO bdcdata.
CLEAR : wa_bdcdata.
ENDFORM.
"BDC_DYNPRO
*----------------------------------------------------------------------*
*
Insert field
*
*----------------------------------------------------------------------*
FORM bdc_field USING fnam fval.
* CLEAR bdcdata.
wa_bdcdata-fnam = fnam.
wa_bdcdata-fval = fval.
APPEND wa_bdcdata TO bdcdata.
CLEAR : wa_bdcdata.
ENDFORM.
"BDC_FIELD

Session method:
Flat File
SAP DB

Itab

Session

Tcode

It is a bdc method which we are using for updating large amount


of data into SAP/R3 database, the data may be the master or
transaction data
In the bdc session method while running the program the system
will generate one session which we can see in SM35 Tcode
In the session method the system will capture the error records it
maintain the error records in SM35 Tcode

290

Sun Shine Technologies


In the BDC session and call transaction methods we need not do
more validations for the data because the transaction code will
track all validations
Session method steps:
1.recording(SHDB)
2.Call the function module BDC_OPEN_GROUP
3.Loop at Itab
4.Subroutines copy from recording
5.call the function module BDC_INSERT
6.endloop
7. Call the function module BDC_CLOSE_GROUP
8.Go to SM35 Tcode and run the session
9.see the error records in SM35 error log.

BDC_OPEN_GROUP:
Here we gave 4 parameters
1.client client name (sy-mandt)
2.group session name
3.user System user (sy-uname)
4.Keep we pass X (keep the session if finished )
If we pass space (Delete the session if finished )

BDC_INSERT:
Here we pass 2 parameters
TCODE transaction code
291

Sun Shine Technologies


Dynprotab BDCDATA
In the session method if we run the SE38 Program then system
will generate one session in SM35 Tcode. Here we have All Screen
and No Screen
Session method for XK01:
*&---------------------------------------------------------------------*
*& Report ZVSIHNU_BDC_VENDOR_CREATE
*&---------------------------------------------------------------------*
REPORT ZVSIHNU_BDC_VENDOR_CREATE NO STANDARD PAGE HE
ADING.
*//Internal Table Dclaration
DATA:lt_final TYPE TABLE OF zfinal_structure2.
*//Work Area Delaration
DATA:wa_final TYPE zfinal_structure2.
*

Batchinputdata of single transaction


DATA: bdcdata TYPE TABLE OF bdcdata,
wa_bdcdata TYPE bdcdata.
*
messages of call transaction
DATA: messtab LIKE bdcmsgcoll OCCURS 0 WITH HEADER LINE,
wa_messtab TYPE bdcmsgcoll,
lt_messtab TYPE TABLE OF bdcmsgcoll.
*//Local Varible delaration
DATA:con_path TYPE string.
*// Selection screen design
PARAMETERS : p_path TYPE rlgrap-filename.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_path.
CALL FUNCTION 'F4_FILENAME'
EXPORTING
program_name = syst-cprog
dynpro_number = syst-dynnr
292

Sun Shine Technologies


IMPORTING
file_name

= p_path.

START-OF-SELECTION.
con_path = p_path.
*//Uploading Data from Prsenetation Server
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = con_path
filetype = 'ASC'
TABLES
data_tab = lt_final.
CALL FUNCTION 'BDC_OPEN_GROUP'
EXPORTING
client = sy-mandt
group = 'FIRST'
keep = 'X'
user = sy-uname.
LOOP AT lt_final INTO wa_final.
PERFORM bdc_dynpro
USING 'SAPMF02K' '0100'.
PERFORM bdc_field
USING 'BDC_CURSOR'
'RF02K-KTOKK'.
PERFORM bdc_field
USING 'BDC_OKCODE'
'/00'.
PERFORM bdc_field
USING 'RF02K-BUKRS'
wa_final-bukrs.
PERFORM bdc_field
USING 'RF02K-EKORG'
wa_final-ekorg.
PERFORM bdc_field
USING 'RF02K-KTOKK'
wa_final-ktokk.
PERFORM bdc_dynpro
USING 'SAPMF02K' '0110'.
PERFORM bdc_field
USING 'BDC_CURSOR'
'LFA1-LAND1'.
PERFORM bdc_field
USING 'BDC_OKCODE'
'/00'.
PERFORM bdc_field
USING 'LFA1-ANRED'
293

Sun Shine Technologies


PERFORM
PERFORM
PERFORM
PERFORM
PERFORM
PERFORM
PERFORM
PERFORM
PERFORM
PERFORM
PERFORM
PERFORM
PERFORM
PERFORM
PERFORM
PERFORM
PERFORM
PERFORM
PERFORM
PERFORM
PERFORM

wa_final-anred.
bdc_field
USING 'LFA1-NAME1'
wa_final-name1.
bdc_field
USING 'LFA1-SORTL'
wa_final-sortl.
bdc_field
USING 'LFA1-NAME2'
wa_final-name2.
bdc_field
USING 'LFA1-STRAS'
wa_final-stras.
bdc_field
USING 'LFA1-ORT01'
wa_final-ort01.
bdc_field
USING 'LFA1-PSTLZ'
wa_final-pstlz.
bdc_field
USING 'LFA1-LAND1'
wa_final-land1.
bdc_dynpro
USING 'SAPMF02K' '0120'.
bdc_field
USING 'BDC_CURSOR'
'LFA1-KUNNR'.
bdc_field
USING 'BDC_OKCODE'
'/00'.
bdc_dynpro
USING 'SAPMF02K' '0130'.
bdc_field
USING 'BDC_CURSOR'
'LFBK-BANKS(01)'.
bdc_field
USING 'BDC_OKCODE'
'=ENTR'.
bdc_dynpro
USING 'SAPMF02K' '0210'.
bdc_field
USING 'BDC_CURSOR'
'LFB1-FDGRV'.
bdc_field
USING 'BDC_OKCODE'
'/00'.
bdc_field
USING 'LFB1-AKONT'
wa_final-akont.
bdc_field
USING 'LFB1-FDGRV'
wa_final-fdgrv.
bdc_dynpro
USING 'SAPMF02K' '0215'.
bdc_field
USING 'BDC_CURSOR'
'LFB1-ZTERM'.
bdc_field
USING 'BDC_OKCODE'
'/00'.
294

Sun Shine Technologies


PERFORM bdc_field
USING 'LFB1-ZTERM'
wa_final-zterm.
PERFORM bdc_dynpro
USING 'SAPMF02K' '0220'.
PERFORM bdc_field
USING 'BDC_CURSOR'
'LFB5-MAHNA'.
PERFORM bdc_field
USING 'BDC_OKCODE'
'/00'.
PERFORM bdc_dynpro
USING 'SAPMF02K' '0310'.
PERFORM bdc_field
USING 'BDC_CURSOR'
'LFM1-WAERS'.
PERFORM bdc_field
USING 'BDC_OKCODE'
'/00'.
PERFORM bdc_field
USING 'LFM1-WAERS'
wa_final-waers.
PERFORM bdc_dynpro
USING 'SAPMF02K' '0320'.
PERFORM bdc_field
USING 'BDC_CURSOR'
'RF02K-LIFNR'.
PERFORM bdc_field
USING 'BDC_OKCODE'
'=ENTR'.
CALL FUNCTION 'BDC_INSERT'
EXPORTING
tcode
= 'XK01'
TABLES
dynprotab = bdcdata.
REFRESH: messtab,bdcdata.
CLEAR wa_final.
ENDLOOP.
CALL FUNCTION 'BDC_CLOSE_GROUP'.
if sy-subrc eq 0.
write:/10 'SUCCESS'.
ENDIF.
*----------------------------------------------------------------------*
*
Start new screen
*
*----------------------------------------------------------------------*
295

Sun Shine Technologies


FORM bdc_dynpro USING program dynpro.
wa_bdcdata-program = program.
wa_bdcdata-dynpro = dynpro.
wa_bdcdata-dynbegin = 'X'.
APPEND wa_bdcdata TO bdcdata.
CLEAR : wa_bdcdata.
ENDFORM.
"BDC_DYNPRO
*----------------------------------------------------------------------*
*
Insert field
*
*----------------------------------------------------------------------*
FORM bdc_field USING fnam fval.
wa_bdcdata-fnam = fnam.
wa_bdcdata-fval = fval.
APPEND wa_bdcdata TO bdcdata.
CLEAR : wa_bdcdata.
ENDFORM.
"BDC_FIELD
OUTPUT:
Give the file path

Click on execute

In the session method after execute the program the go to SM35


Tcode . in the SM35 the system will create one session

296

Sun Shine Technologies

Select you session and click on process button

Then system will ask which mode we execute the session select
any mode and click on enter
After completion of execution then it will show how many record
are updated successfully if there is any error records then it will
displayed all error records in a log
If we want to see the error records then select the session and
click on ANALYSIS button.

297

Sun Shine Technologies


If we click on the analysis button there it will displayed list of all
the records then double click on incorrect record and click on LOG
CREATION button where it will displayed all the error records
Session method for XK02:
*&---------------------------------------------------------------------*
*& Report ZVISHNU_BDC_UPLOAD
*&
*&---------------------------------------------------------------------*
REPORT zvishnu_bdc_upload NO STANDARD PAGE HEADING.
INITIALIZATION.
DATA:lt_final TYPE TABLE OF zsfinal.
DATA:wa_final TYPE zsfinal.
*// Batchinputdata of single transaction
DATA: bdcdata TYPE TABLE OF bdcdata,
wa_bdcdata TYPE bdcdata.
*// messages of call transaction
DATA: messtab LIKE bdcmsgcoll OCCURS 0 WITH HEADER LINE,
wa_messtab TYPE bdcmsgcoll,
lt_messtab TYPE TABLE OF bdcmsgcoll.
*// lOCAL VARIABLE DECLARATION
DATA : lv_path TYPE string.
*// Selection screen design
PARAMETERS : p_path TYPE rlgrap-filename.
*// Providing F4 functionality
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_path.
*// Call Function Module F4_FILENAME for getting F4 functionality
CALL FUNCTION 'F4_FILENAME'
EXPORTING
298

Sun Shine Technologies


program_name = syst-cprog
dynpro_number = syst-dynnr
IMPORTING
file_name
= p_path.
*// Start of selection
START-OF-SELECTION.
lv_path = p_path.
*// Call GUI_UPLOAD FM for uploading the data from Presentation
server
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename
= lv_path
filetype
= 'ASC'
has_field_separator = '|'
TABLES
data_tab
= lt_final.
*// BDC Call Transaction & SESSION Methods
CALL FUNCTION 'BDC_OPEN_GROUP'
EXPORTING
client = sy-mandt
group = 'FIRST'
keep = 'X'
user = sy-uname.
DATA : wa_lfa1 TYPE lfa1.
LOOP AT lt_final INTO wa_final.
PERFORM bdc_dynpro
USING 'SAPMF02K' '0101'.
PERFORM bdc_field
USING 'BDC_CURSOR'
'WRF02K-D0320'.
PERFORM bdc_field
USING 'BDC_OKCODE'
'/00'.
PERFORM bdc_field
USING 'RF02K-LIFNR'
wa_final-lifnr.
PERFORM bdc_field
USING 'RF02K-BUKRS'
wa_final-bukrs.
PERFORM bdc_field
USING 'RF02K-EKORG'
wa_final-ekorg.
PERFORM bdc_field
USING 'RF02K-D0110'
299

Sun Shine Technologies


PERFORM
PERFORM
PERFORM
PERFORM
PERFORM
PERFORM
PERFORM
PERFORM
PERFORM
PERFORM
PERFORM
PERFORM
PERFORM
PERFORM
PERFORM
PERFORM
PERFORM
PERFORM
PERFORM
PERFORM

'X'.
bdc_field
USING 'RF02K-D0120'
'X'.
bdc_field
USING 'RF02K-D0130'
'X'.
bdc_field
USING 'RF02K-D0210'
'X'.
bdc_field
USING 'RF02K-D0310'
'X'.
bdc_field
USING 'WRF02K-D0320'
'X'.
bdc_dynpro
USING 'SAPMF02K' '0110'.
bdc_field
USING 'BDC_CURSOR'
'LFA1-ANRED'.
bdc_field
USING 'BDC_OKCODE'
'/00'.
bdc_field
USING 'LFA1-ANRED'
wa_final-anred.
bdc_field
USING 'LFA1-NAME1'
wa_final-name1.
bdc_field
USING 'LFA1-SORTL'
wa_final-sortl.
bdc_field
USING 'LFA1-STRAS'
wa_final-stras.
bdc_field
USING 'LFA1-PFACH'
wa_final-pfach.
bdc_field
USING 'LFA1-ORT01'
wa_final-ort01.
bdc_field
USING 'LFA1-PSTLZ'
wa_final-pstlz.
bdc_field
USING 'LFA1-PSTL2'
wa_final-pstl2.
bdc_field
USING 'LFA1-LAND1'
wa_final-land1.
bdc_field
USING 'LFA1-SPRAS'
wa_final-spras.
bdc_dynpro
USING 'SAPMF02K' '0120'.
bdc_field
USING 'BDC_CURSOR'
'LFA1-KUNNR'.
300

Sun Shine Technologies


PERFORM bdc_field
USING 'BDC_OKCODE'
'/00'.
PERFORM bdc_field
USING 'LFA1-BRSCH'
wa_final-brsch.
PERFORM bdc_dynpro
USING 'SAPMF02K' '0130'.
PERFORM bdc_field
USING 'BDC_CURSOR'
'LFBK-BANKS(01)'.
PERFORM bdc_field
USING 'BDC_OKCODE'
'=BANK'.
PERFORM bdc_dynpro
USING 'SAPLBANK' '0100'.
PERFORM bdc_field
USING 'BDC_CURSOR'
'BNKA-BANKA'.
PERFORM bdc_field
USING 'BDC_OKCODE'
'=ENTR'.
PERFORM bdc_field
USING 'BNKA-BANKA'
wa_final-banka.
PERFORM bdc_field
USING 'BNKA-STRAS'
wa_final-stras.
PERFORM bdc_field
USING 'BNKA-ORT01'
wa_final-ort01.
PERFORM bdc_dynpro
USING 'SAPMF02K' '0130'.
PERFORM bdc_field
USING 'BDC_CURSOR'
'LFBK-BANKS(01)'.
PERFORM bdc_field
USING 'BDC_OKCODE'
'=ENTR'.
PERFORM bdc_dynpro
USING 'SAPMF02K' '0210'.
PERFORM bdc_field
USING 'BDC_CURSOR'
'LFB1-ZINRT'.
PERFORM bdc_field
USING 'BDC_OKCODE'
'/00'.
PERFORM bdc_field
USING 'LFB1-AKONT'
wa_final-akont.
PERFORM bdc_field
USING 'LFB1-FDGRV'
wa_final-fdgrv.
PERFORM bdc_field
USING 'LFB1-ZINRT'
wa_final-zinrt.
PERFORM bdc_dynpro
USING 'SAPMF02K' '0310'.
PERFORM bdc_field
USING 'BDC_CURSOR'
'LFM1-KZAUT'.
301

Sun Shine Technologies


PERFORM bdc_field
USING 'BDC_OKCODE'
'/00'.
PERFORM bdc_field
USING 'LFM1-WAERS'
wa_final-waers.
PERFORM bdc_field
USING 'LFM1-INCO1'
wa_final-inco1.
PERFORM bdc_field
USING 'LFM1-INCO2'
wa_final-inco2.
PERFORM bdc_field
USING 'LFM1-KZAUT'
'X'.
PERFORM bdc_dynpro
USING 'SAPMF02K' '0320'.
PERFORM bdc_field
USING 'BDC_CURSOR'
'RF02K-LIFNR'.
PERFORM bdc_field
USING 'BDC_OKCODE'
'=ENTR'.
CALL FUNCTION 'BDC_INSERT'
EXPORTING
tcode
= 'XK02'
TABLES
dynprotab = bdcdata.
REFRESH : bdcdata.
ENDLOOP.
CALL FUNCTION 'BDC_CLOSE_GROUP'.
if sy-subrc eq 0.
write: / 'SUCCESS'.
endif.
*----------------------------------------------------------------------*
*
Start new screen
*
*----------------------------------------------------------------------*
FORM bdc_dynpro USING program dynpro.
* CLEAR bdcdata.
wa_bdcdata-program = program.
wa_bdcdata-dynpro = dynpro.
wa_bdcdata-dynbegin = 'X'.
302

Sun Shine Technologies


APPEND wa_bdcdata TO bdcdata.
CLEAR : wa_bdcdata.
ENDFORM.
"BDC_DYNPRO
*----------------------------------------------------------------------*
*
Insert field
*
*----------------------------------------------------------------------*
FORM bdc_field USING fnam fval.
* CLEAR bdcdata.
wa_bdcdata-fnam = fnam.
wa_bdcdata-fval = fval.
APPEND wa_bdcdata TO bdcdata.
CLEAR : wa_bdcdata.
ENDFORM.
"BDC_FIELD

Difference between session and call transaction methods:


Call transaction method
1.It can process only one
transaction at a time
2.We can handle the errors
manually
i. By using the BDCMSGCOLL
structure we can get the error
record details
ii. After getting the error
record details we need to pass
the error record details in to
Format_message function
module
iii. By running the second we
can format the error records
3.call transaction method is
faster than the session method

Session method
1.It can process any number of
transactions at a time
2.It generates lock that can
handle the errors

3.Session method is slower than


the call transaction method
4.After processing the session
only we can update the data
into database
5.It is suitable if the flat file
303

Sun Shine Technologies


4.It is immediate database
update
5.It is suitable if flat file
contains the less amount of
data
6.It returns the sy-subrc
7.we cant schedule the call
transaction in back ground

contains the large amount of


data
6.It cant return the sy-subrc
7.we can schedule the call
transaction in background

LSMW
Legacy System Migration Workbench
Tcode: Lsmw
Step-by-Step Guide for using LSMW to Update Customer Master
Records
LSMW to Update Customer Master Records with
Transaction Recording
Call Legacy System Migration Workbench by entering transaction
code LSMW. Every conversion task is grouped together as Project /
Subproject / Object structure. Create a Project called
LSMW_DEMO and a Subproject as CUSTOMERS and Object as
CUST_REC as shown in Figure 1.

Figure 1 Conversion Task with Project, Subproject and Object

304

Sun Shine Technologies


The main screen of LSMW provides wizard-like step-by-step tasks,
as shown in Figure 2. To complete your data conversion, you
need to execute these steps in sequence. Once a step is
executed, the cursor is automatically positioned to the next step.
Note that these steps may look different depending upon your
Personal menu settings. You could make step numbers visible
by Numbers on icon or hidden by Numbers off icon. You can
execute a step by double-clicking on the row. Toggle icon
Doubleclick=Display or Doubleclick=Edit, makes the step in
display mode or change mode.

Figure 2 LSMW Wizard initial screen

305

Sun Shine Technologies


Step 1: Maintain Object attributes
In this example, you will be updating the customer master records
with the help of recording a transaction (XD02). Choose radio
button Batch Input Recording and click on the recording
overview icon to record the R/3 transaction. Enter the Recording
name as XD02_REC, the description as Customer Master
Updates Recording, and the transaction code as XD02.

Figure 3 Object type Transaction Recording


The system calls the transaction code XD02 and prompts you to
complete the Change
Customer transaction, as shown in Figure 4. Enter the key
customer information (I entered customer number 1000, sales
organization 1000, distribution channel 01, and division 00) and
choose Sales view within Sales area data. Make changes to
these three fields (I entered, sales office 1010, sales group 110,
and customer group 01) and save the transaction.

Figure 4 Transaction recording for Transaction Code XD02

306

Sun Shine Technologies


Once the transaction is completed, R/3 records the flow of screens
and fields and saves the information, as shown in Figure 5.

Field Names

Default Values

Figure 5 Transaction recording overview


Note that the fields are populated with default values. The values
you entered when you recorded the transaction are set by default.
Note that if you have more fields in the recording than needed,
you can remove them by
clicking Remove Screen field icon.
Observe that the transaction-recording process stores field names
in a technical format. By pressing the F1 key on individual screen
fields and then pressing the F9 key, the system displays technical
names. You then can replace the technical names with descriptive
names. Double-click on the field RF02D-KUNNR and enter the
name as KUNNR and the description as Customer Account
Number and remove the default value. (See Figure 6.)

307

Sun Shine Technologies


Figure 6 Field attributes
Similarly, double-click on all other fields with default values and
make appropriate changes. Once you have made changes, the
recording overview screen looks like what you see in
Figure 7.

Figure 7 Transaction Recording Overview with screen field


attributes
Save your changes. When you go back to the initial screen, you
will see that the initial screen steps have changed. Since you want
to import data via the BDC method, the Direct Input and IDocrelated steps are hidden, as they are not relevant.
Step 2. Maintain Source Structures
Give a name and a description to the source structure (Figure 8).

Figure 8 Source Structure

308

Sun Shine Technologies

Step 3. Maintain Source Fields


In this step, you need to list what fields are present in the source
structure. The easiest way is to click on Table Maintenance icon
to enter Fieldname, Type and Length for each field
as shown in
Figure 9.

Figure 9 Source fields of source Structure


Note that your input file will have four fields as key fields and you
need to update three fields in the system.
Step 4: Maintain Structure Relations
Execute a step to Maintain Structure Relations. (See Figure 10.)
Since, there is only one Source and Target Structure, the
relationship is defaulted automatically.

Figure 10 Structure Relation

309

Sun Shine Technologies


Step 5: Maintain field mapping and conversion rules
Field RF02D-D0310 represents that you chose Sales view for
the customer Master screen accordingly its value should be set to
X. Keep your cursor on field RF02D-D0310 and click on Constant
rule icon to choose the constant value of X.
If your source file already has the field value, you choose rule
Source Field.
Keep cursor on field KUNNR and click on Assign Source field
icon to choose source field CUSTOMER from structure XD02S as
shown in Figure 11.

Figure 11 Assign source fields


Similarly, assign Source Field rules to the remaining fields. Once
all the fields are mapped, you should have an overview screen as
shown in Figure 12.

310

Sun Shine Technologies

Figure 12 Field mapping and Conversion rules overview


Step 6: Maintain fixed values, translations, user-defined routines
You can also maintain re-usable translations and user-defined
routines, which can be used across conversion tasks. In this case,
that step is not required.
Step 7: Specify files
In this step, we define how the layout of the input file is. The input
file is a [Tab] delimited with the first row as field names. It is
present on my PC (local drive) as C:\XD02.txt. (See Figure 13.)

311

Sun Shine Technologies

Figure 13 File attributes


Create an Excel file (Figure 14) with your data and save it as a
Tab-delimited text file on your local drive (C:\) and name it
XD02.txt.

Figure 14 Source data in Excel file (saved as Tab delimited file)


Step 8: Assign files
Execute step Assign Files (Figure 15) and the system
automatically defaults the filename to the source structure.

Figure 15 Assign file to Source Structure


Step 9: Read data
In this step, LSMW reads the data (Figure 16) from the source file
(from your PCs local drive). You have the option to read only
selected rows and convert data values to Internal format.

312

Sun Shine Technologies

Figure 16 Read Data


Step 10: Display read data
This step (Figure 17) is optional. If required, you can review the
field contents for the rows of data read.

Figure 17 Display Read Data


Step 11: Convert data
This is the step that actually converts the source data (in source
format) to a target format. Based on the conversion rules defined,
source fields are mapped to target fields.
Step 12: Display Converted data
Again this is an optional step to view how the source data is
converted to internal SAP format (Figure 18).

313

Sun Shine Technologies

Figure 18 Display Converted Data


Step 13: Create batch input session
Once the source data is converted in an internal format, you can
create a batch session to process updates (Figure 19).

Figure 19 Create Batch Input Session


Step 14: Run Batch Input Session
You can execute the BDC session by Run Batch input session.
Executing a batch input session is a standard SM35 transaction
for managing BDC sessions.Once you have successfully executed
the batch input session, the customer master records are updated
in the system. You can confirm this by viewing the customer
master records (XD03).

314

Sun Shine Technologies


Note! Browsing thru these 14 steps, you may get a feeling that
this is a very lengthy and time-consuming activity. However, for
the purposes of demonstration, I have made it detailed. Although
it looks lengthy, actually it takes hardly few hours from start-tofinish! After playing around with few simple LSMW scripts, you will
find it so easy to change and create more complex ones.
Demo Example 2
LSMW to Update Customer Master Records with Standard
Object
As an alternative to using Transaction Recording, you could also
use a standard SAP object to update Customer Master Records.
Business Object 0050 is already pre-defined in the system with
standard Batch Input Interface Program RFBIDE00.
Create an Object CUST_OBJ within Project as LSMW_DEMO and
Subproject as CUSTOMERS as shown in Figure 20.

Figure 20 LSMW Object with Standard SAP Object


Note! For the Demo example 2, I will list only those steps that are
different from the first demo example.
Step 1: Maintain Object attributes
You will be updating the customer master records with the help of
Standard Batch Input; therefore, choose radio-button Standard
315

Sun Shine Technologies


Batch/Direct Input as shown in Figure 21. Enter Object 0050
for Customer Master records and default method 0000 and click
on Save.

Figure 21 Standard Batch/Direct Input Object Attributes


Step 4: Maintain Structure Relations
Sales view of Customer Master is stored in table KNVV.
Accordingly, you need to update structure BKNVV. However, in
addition, the Standard Object 0050 also requires updates to
BGR00, BKN00 and BKNA1 structures. (If you do not maintain
Structure relations for mandatory entries, you might get a
message such as Target structure BKNA1 needs a relation to a
source structure.)

Even though you dont want to update any fields in these


structures, you need to create a relationship with source
structures. In all, you need to create relationship for four target
structures.
Create relationship between source structures XD02S with these
target structures with icon Create Relationship

Keep Cursor on these four target structures and click on icon


Create Relation and structure relations are maintained as shown
in Figure 22.

316

Sun Shine Technologies

Figure 22 Structure Relation


Step 5: Maintain field mapping and conversion rules
-- Keep your cursor on TCODE field and click on Insert Rule icon

317

Sun Shine Technologies

Figure 23 LSMW Conversion Rules


Choose radio button Constant (Figure 23) to enter value XD02
transaction code.
-- Keep your cursor on field KUNNR and click on Assign source
field icon
Choose source field Customer from source structure XD02S.
(See Figure 24.)

318

Sun Shine Technologies

Figure 24 Assign Source fields


-- Similarly, choose source fields for Sales Organization,
Distribution Channel, and Division. (See Figure 25.)

319

Sun Shine Technologies


Figure 25 Field Mapping and Conversion Rules
-- Scroll down to structure BKNVV fields and assign source fields to
three fields Sales Office, Sales Group, and Customer Group
(Figure 26).

Figure 26 Field Mapping and Conversion Rules


Save and go back to main screen.
Step 12: Display Converted data
When you convert data, LSMW automatically converts into the
appropriate structure layouts, as required by Standard program
(RFBIDE00). (See Figure 27).

320

Sun Shine Technologies

Figure 27 Converted data into multiple structures


Note that if you had only one record in source file, the converted
file has four records.
Earlier, creating this input file, so that the standard interface
program can read it, was a big nightmare, the primary reason
being that it could have multiple record layouts. Even for a simple
conversion with one input record, you would have to create this
complex file with many record layouts. The advantage of LSMW is
that it prepares these multi-layout files automatically.
Step 13: Create batch input session
Once source data is converted in internal format, you can create a
BDC session to process the updates (Figures 28 and 29).

321

Sun Shine Technologies

Figure 28 Create BDC Session

Figure 29 BDC Session CUST_OBJ created

ENHANCEMENT AND MODIFICATION

1. Personalisation :
Transaction variants are created to personalize any standard SAP
transaction. A transaction variant simplifies the usage of a
transaction by tailoring some of the features as per the business
need. It can be used to hide fields, menu functions, screens, to
322

Sun Shine Technologies


supply individual fields with default values or to change the ready
for input status of one or more fields.
This document describes the step by step process to create a
transaction variant for standard SAP transaction CO01 - create
production order. The transaction variant should have the
following restriction:

Order type is not visible in the initial screen.

Menu path Order -> Create from Planned Order is


deactivated
There are two steps, first create the transaction variant and then
attach the transaction variant to a transaction.
Creation of Transaction Variant
Transaction variant can be created by through transaction code
SHD0. The steps to create a transaction variant as follows:
1. Go to transaction SHD0. In the initial screen enter the
transaction code (in this case CO01) for which we are going to
create the transaction variant. Enter the name of the transaction
variant (say YCO01) in the "Transaction Variant" field and then

323

Sun Shine Technologies


click the "Create" button.

2. In the next screen transaction CO01 will be opened in recording


mode. As we are going to hide the field "Order type", enter some
default value (say PP01) in that field. For others we may or may
not enter values. Click "Enter". A pop-up screen will appear.

324

Sun Shine Technologies


3. In the "Confirm Screen Entries" pop-up screen we can
customize the fields. Enter the screen variant name (say
YCO01_0100) and short text (Test screen variant) here. Also for
the field "Order type" check the Invisible checkbox to hide this
field from the screen.

4. To deactivate some of the menu function click the button


"Menu functions". A pop-up screen will appear. In the pop-up
select the menu item "Order-> Create from planned order" and

325

Sun Shine Technologies


click the deactivate button.

5. The menu item will be deactivated (it will be highlighted in


yellow). Click "Enter" to come back to the original screen entries

326

Sun Shine Technologies


pop-up.

6. Click "Exit and Save" button to save the Transaction variant.


System will pop-up for a transport request. We can save it as a
local transport or save it in some transport request.

327

Sun Shine Technologies

328

Sun Shine Technologies


7. We can test the transaction variant by clicking the "Test" button
in the initial screen.

Assigning Transaction Variant to Transaction Code


After creating the transaction variant we need to assign it to a
transaction. The transaction can be used by the user to get the
required tailored version of the original transaction. The steps are
as follows:

329

Sun Shine Technologies


1. Go to transaction SE93. Enter the name of the transaction code
(say YCO01_TCODE ) to be created and click the button "Create".

2. In the next pop-up screen enter the short text, select the radio
button variant transaction and click enter.

3. In the next screen enter the transaction (CO01) and transaction


variant (YCO01) created in the previous step. Click the "save"

330

Sun Shine Technologies


button to save the variant transaction.

The variant transaction (YCO01_TCODE) is now ready and it can


be used to get the tailored version of the original production order
creation (CO01) transaction code.

331

Sun Shine Technologies


Result:
Initial Screen: Field "Order type" is not visible

332

Sun Shine Technologies


Menu: Menu item "Create from planned order" is disabled

2.Enhancement,Modification
Enhancements are the means by which we add our own/ modify
existing functionality to SAP's standard business applications.
If you try to modify any SAP standard program, it will ask you for
access key which you can get from SAP market place by
requesting SAP.
But enhancements normally dont require any special access key
and can be implemented directly
EXITS:
Adding the new functionality to the existing object
They are two types of exits are there
333

Sun Shine Technologies


1.User Exit
2.Customer Exit
USER EXITS: For Implementing the user exit we need the access
key.
CUSTOMER EXIT:
1. By using the customer exit we can add new functionality to
the exiting object
2. For customer exit first we need to find out the exit name. we
get the exit name in SMOD Tcode and find out what type of
enhancement is possible.
3. After getting the exit we need to go CMOD Tcode where we
need to create the project and assigning the enhancement to
the project and implement it.
We can do enhancements in 4 ways.
1.Function Exit
2.Screen Exit
3.Menu Exit
4. Table Exit
Steps :
To find the exit first wa have to know the package.
For example if we want to find out the package of VA01
Go to VA01 Tcode
Go to menu bar
System -> status

334

Sun Shine Technologies

Then one window will be trigger then double click on the


program name

335

Sun Shine Technologies

Go to menu bar
Go to -> attributes

336

Sun Shine Technologies

Then one window will be trigger where we can see the package
name

What are the ways we can find out the user exit:
337

Sun Shine Technologies


1.If you know the Tcode then find the package for that Tcode
EX: XK01 Tcode
Find out the package for XK01
Then go to SE80
Select package
Enter the package name
Press enter

Under package we can find out the enhancement

338

Sun Shine Technologies


2. once we know the package name go to SMOD Tcode

click on Ctrl+F
Then one window will be trigger where we can enter the package
name

Click on execute
Where we can see the Exit name

339

Sun Shine Technologies

3. Go to SE84
Select the enhancement and enter the package name

Click on execute
Where we can see the Exit name

4. Goto SPRO Tcode


Select the SAP reference

340

Sun Shine Technologies

Then we can see like this

Where we can select the SD or MM are any module


Note: Functional peoples use this one
SMOD: Implementing enhancement/exit
Go to SMOD Tcode

341

Sun Shine Technologies

Click on Ctrl + F
Enter the package name

Click on create
Then it will display the list of user exits
Find your exit based on the description
Copy the exit name
And go to SMOD Tcode initial screen
342

Sun Shine Technologies


Enter the exit name and click on display

One window will open

Click on components button


Then it will display the list of the function modules are available

343

Sun Shine Technologies

Double click on function module name


Under the function module we can see includes

344

Sun Shine Technologies

Double click and click on enter on the include name at the same
time
Note: While double click on the include program if the include
program is not implemented then we are getting some warring
message where we need to pass the enter button
Then system will ask do you want to create

Click on yes
Then it will ask the package name
Enter the package name and click on save
Then one window will open like this

345

Sun Shine Technologies

Where we can develop your code and click on save and activate
And click on back button activate the function module
Click on back button twice then we come to SMOD initial screen
Assigning enhancement to the project:
Go to CMOD Tcode
Enter the project name

Click on create
Enter the short text

346

Sun Shine Technologies


Click on save
Click on enhancement assignment button
Add the enhancement name and press enter

Click on save and come back


Click on activate to activate the button

Note:
When we deactivate the project?

347

Sun Shine Technologies


For example 6 months back some one as implemented some exit
for ME21N Tcode for adding new validations then now client is
come back he asked us to remove those validations then we are
following the below steps
Go to CMOD Tcode
Enter the project name
Click on deactivate button
Then transport the new transport request number to the another
system

TEXT ENHANCEMENT:
FIELD ENHANCMENT:
CHANGING THE FIELD LABEL:
- Change F1 help documentation of any field.
Go to mm01.
Place the cursor on material and press F1.
click on technical information (4th option)
Notice the data element (matnr).
- Goto cmod
- Go to MENU text enhancmenent keywords change
- Provide data element as matnr continue change field
label and save.
- Create request.
- Provide description.
- Continue
- Note-here again data element will come just close
the dialog box and check after 2-3 minutes.
Note:
Dialogue screen uses long text (field label).
TEXT ENHANCMENET
Go to mm01.
Place the cursor on material and press F1.
Click on technical information (4th option)
348

Sun Shine Technologies


Notice the data element (matnr).
Go to CMOD GOTO menu - > text enhancement - > data
element-> new de cust
Enter the Data element as matnr,
ZMODIFIFICATION
ORIGINAL
You will see PC Editor - edit the data as required.
Add some additional documentation.
Save back.
Continue with request.
Short text continue
Go to mm01.
Place the cursor o material and Press F1.

Enhancement Framework
Adding new functionality to the exiting object without editing
exiting code
Steps to implement the enhancement sport
Go to Tcode
EX: go to VA01
Go to menu bar
System -> status

349

Sun Shine Technologies

One window trigger like this

Double click on program name


Then main program is open
Go to menu bar
Enhancement options -> show implicit enhancement options

350

Sun Shine Technologies

And go to end of the program click on the enhancement sport

Place the cursor on and click on the enhancement


button
on application tool bar
Then go to menu bar

then system will display the exiting enhancement


implementations where we need to click on the create
enhancement implementation button
351

Sun Shine Technologies


Then give the short text and enhancement name

Click on continue button


Enter the package
Click on save
Select out enhancement implementation name click on continue
button
Then the system will create enhancement and end enhancement
Enhancement
.
..
Endenhancement.
In this between enhancement and endenhancement we are going
to write the logic for the functionality.

DIFFERENCE BETWEEN CUSTOMER EXIT AND USER EXIT:


CUSTOMER EXIT
USER EXIT
Are implemented as a part of
Are implemented as a part of
enhancement.
modification.
To implement Customer exit access not To implement user exit access key i
required.
required.
Are implemented using includes and
Are implemented using includes and
function modules.
subroutines.
352

Sun Shine Technologies

BAdi Business Add-ins.


- It is one of the enhancement technique, implemented using
object oriented ABAP.

DIFFERENCE BETWEEN CUSTOMER EXIT AND BAdis


CUSTOMER EXIT
BAdis
Procedural enhancement
Object oriented enhancement
It is implemented using function
It is implemented using interface,
modules, includes.
classes and methods.
These are not reusable
These are reusable
Customer exit - definition t.code
BAdi definition t.code SE18
SMOD
BAdi implementation t.code SE19
Customer exit implementation t.code
CMOD
Architecture customer exit
Architecture BAdis implement mul
implements 2 level landscape
level landscape.
- SAP has provided some exits so if
- Customer can add
a user wants to add some
- Industry solutions can add
features then based on the exits,
- Business partners can add
the user can add code.
Path from SAP Easy Access -> Tools abap workbench utilities
BAdis and customer exits.
BAdi
-

Enhancement:
BAdis are defined using BAdi builder.
BAdi builder is closely integrated with ABAP Workbench.
BAdis are used to add custom business functionality to
standard SAP (without changing SAP).
- BAdi supports:
o Program enhancement, menu enhancement, screen
enhancement but it does not support text
enhancement. (text means field enhancement)
o For program, menu and screen enhancement SAP
permission is required.
- T.code: SE18 SAP defined BAdi list (to define BAdi)
353

Sun Shine Technologies


- T.code SE19 - to implement BAdi.
WORKING WITH BAdis:
Step 1: understand specific requirement of client.
Step 2: search (or) locate (or) find the relevant BAdi.
Step 3: implement BAdi.
Step 4: test BAdi.
BAdi types:
1. Classic BAdi (doesnt have enhancement spot)
2. Kernal-based BAdi (new BAdi have enhancement spot)
- Every BAdi have description (functionality of BAdi)
ATTRIBUTES (tab):
Consists of package, username, data, language, name of
Add-in class)
- BAdis are again divided into:
o Multiple Use BAdis:
If the check box is enabled/checked/activated,
then it is reusable BAdi otherwise it is single used
BAdi.
o Filter dependent BAdis:
If the checkbox is enabled/checked, then that BAdi
consists of filter type as structure or data element.
It is used to implement BAdi, based on condition
(condition means filter)
INTERFACE (tab):
- Consists of interface name, and its possible methods.
- In general interface name begins with IF_EX_<BAdi name>.
F.Codes (tab):
- It consists of Menu enhancement concern FCT Codes.
SUBSCREEN (tab):

354

Sun Shine Technologies


- It consists of Screen enhancement concern calling program
name, screen number, subscreen area.
DOCUMENTATION (tab):
- It provides in detail functionality of BAdi and implementation
procedure.
BAdi interface
Methods M1, M2
C1
Interface : IF

C2
Interface: IF

Method if~M1
-----<st>------Endmethod
Method if~m2
------<st>----Endmethod

Method if~M1
-----<st>------Endmethod
Method if~m2
------<st>----Endmethod

- BAdi is implemented using object oriented ABAP.


- BAdi is an interface and interface is a collection of methods..
- SAP defined many BAdis each BAdi consists of one
interface.
o Each BAdi interface consists of methods (possible
additional functionality in the form of methods).
- In SE18: BAdi -> interface -> method1, method2.
- In SE19: Zclass -> BAdi ->
interface~method1..endmethod.
Interface~method2..endmethod.
- Once BAdi is defined and activated, it generates:
o One Interface
o one add-in class
o one implemented class
- Add-in class performs 2 operations:
o Call and control active implementation
o Filter (filter-dependent BAdi)
Search Criteria:
355

Sun Shine Technologies


- Standard procedure - T.code wise searching:
o Execute T.code.
o System menu -> status -> double click on program ->
goto menu -> attribute -> notice the package name.
- Go to T.code SE18, search for BAdi using Package.
- In SE18 information system tab o Application and component wise searching: (search in
SE18).
o Enhancement spot wise searching:
o Short description wise searching:
- T.code SPRO click on saP reference IMG CTRL+F searching with keyword - BADI.
o
o Click on execute
Implementation name and short text
It will take you to
- SE84 search for repository information system
o enhancements definition
- Search with string cl_exithandler=>get_instance (BAdis are
defined here)
o VA01 find - Find/replace 1st option
cl_exithandler=>get_instance - Double click on instance
double click on interface this interface is BAdi
interface.
- Go to SE81 search in the application hierarchy.
- Search for BAdi using description
Other search criteria:
- In SE18 - BAdi name hit F4 - click on information system
-> SD - SLS
Naming conventioons:
Interface name: zif_ex_<BAdi_name>.
Implementation class: zcl_im_<BAdi_implementation>.
Add in class: cl_ex_
Built in service class: cl_exithandler
- This service class is used to create instance for reference
variable.

356

Sun Shine Technologies


Classic BAdis are valid upto 4.0
Kernel BAdi from 5.7
BAdi interface consist of SAP defined multiple methods.
SAP provided required methods to add additional functionality.
Each method provides some functionality to SAP.
Once the BAdi interface is defined and activated, it generates
three classes.
1. Adopter class
2. Service class
3. Implement class
ADOPTER CLASS:
- It performs two activities.
o Control
It calls and controls all the implementations.
o Filter:
It implemets using filter type condition.
SERVICE CLASS:
- It is default which is automatically created for all BAdis.
- It is used while creating instance.
o Cl_exithandler=>get_instance
IMPLEMENT CLASS (OR) GENERATED CLASS:
- It implements the interface methods.
NAMING CONVENTIONS:
Interface name begins with: if_ex_<BAdi_definition>
Implementation class name begins with
ZCL_IM_<BAdi_implementation>
IMPLEMENTATION: (imagine you found the right BAdi then to
implement it.
SE18 enhancment open in display mode.
Notice:
- the enhancement spot
- Attributes tab:
357

Sun Shine Technologies

o Multiple use check box:


Single implementation (if checkbox is not checked
Multiple implementation (if check box is checked
multiple users message will come)
o Filter checkbox:
If this checkbox is check then it is filter dependant
badi.
This can be implemented using filter type.
Interface tab:
o It provides interface name and possible methods.
FCodes tab:
o Provides menu enhancement
Subsccreen tab: provides screen enhancement.
Documentation push button:
o Provides functionality of enhancement and
implementation procedure.

CUSTOM BAdi CREATION:


CREATING BAdi Report using custom BAdi implementation:
SE18 define BAdi.
SE19 implement BAdi.
SE38 BAdi Report.
For new/kernal BAdis creating enhancement spot creation is
mandatory.
- SE18 - Zen_spot BAdi can be created under enhancement
spot so spot creation is mandatory.
ZBAdi
Zinterface
o M1, M2.
BAdi name and spot name can be same or can be different.
Spot name can be same for more than one BAdi also.
PROCEDURE:
Step1:
- Se18 enhancement spot zen_spot create (without
creating the enh. Spot we cannot create BAdi).
358

Sun Shine Technologies


- Short des enhancement spot creation
- Technology comes by default.
- Composite enhancement spot leave it blank - continue
save as local object.
o Notice there are no spots, you can create, delete, etc
- Click on create BAdi name zBAdi_def1.
- Short description defining custom BAdi continue.
o BAdi definition is created, by default it is multiple use
BAdi.
- Expand BAdi - Double click on interface.
o On right side provide interface name yif_ex_BAdi_def1 hit enter create yes.
o Save as package.
o This will take you to class builder.
o Under methods - Create methods - create two methods
M1 and M2 with level - instance (dont double click on
methods).
o save - Activate interface come back activate
enhancement spot come back.
- SE18 is over.
- Under enchancement menu - create - to go to SE19 directly.
- Under create imp.
- New BAdi zen_spot create imp.
- Enh. Imp zen_spot_implementation.
- Short text enhamcement implementation continue save
as loca object.
- Under BAdi implementation provide the implementation
name - zBAdi_impl continue.
o Interface are implemented under class so creating
class is the next step.
- Expand BAdi imp and double click on implementing class
o Under imp. Class (right side) zcl_im_BAdi_impl
continue create save as local.
Next step is implementing methods.
o Double click on m1 create .
Under method endmethod write:/ BAdi
interface method M1 is implemented. activate
go back.
359

Sun Shine Technologies


o Double click on m2 under method endmethod.
Write:/ BAdi interface method M2 is
implemented.
Save and Activate and go back.
- Come back and activate.
o Just in case if you want to make some changes to the
BAdi then click on SE19 edit enhancement and yo dan
do the changes if required.
- SE18 and SE19 are over now go to se38.
- SE38 - Create - Zb2_BAdi report executable program.
*------ref variable creation
Data: iref type ref to zif_ex_BAdi_def1.
Cref type ref to ycl_im_BAdi_impl1.
Start of selection.
*------instance creation----Create object cref.
*-----assign class instance address to interface ref variable.
Iref = cref.
*----addressing interface methods using interface
instance-------*
Call method iref->m1. (dont click on pattern, manually write
this).
Call method iref->m2.
------now go to SE18 to cross check information.
-------2nd procedure to call------*------ref variable creation
Data: Cref type ref to ycl_im_BAdi_impl1.
Start of selection.
*------instance creation----Create object cref.
*----addressing interface methods using interface
instance-------*
Call method cref->zif_ex_BAdi_def~m1(dont click on
pattern, manually write this).
Call method cref->zif_ex_BAdi_def~m2
---------3rd method
360

Sun Shine Technologies


Class cl_exithandler definition load. (cl_exithandler is called
as service class)
Data iref type ref to zif_ex_BAdi_def.
Start of selection.
Call method iref c_exithandler get_instance.
Exporting
Chanign
Instance= iref
Call method
Notes for the 3rd method:
- Cl_exithandler is a built in class and global class.
- It is service class used to create instance for the exit.
- Get_instance is a static method/factory method which
creates instance.
- We have to specify class definition load syntax before
creating instance.
CLASSIC BAdi
It is old BAdi valid upto 4.7ee
It is part of enhancement frame work
but enhancement spot not required
Whenever BAdi id defined system
generates Add-in adopter class. This
adopter class calls and control active
implementations.
Methods can be addressed using call
method statement.

KERNAL-BASED BAdi
It is new BAdi valid from ecc5.0
onward.
It is a part of enhancement framewo
but enhancement spot is
required/mandatory.
it does not create add-in class

BAdi defined at kernal level.


We have acquired BAdi using GET BA
statement
New BAdi can be called using CALL B
statement
CROSS APPLICATIONS
Cross application deals with data transfer techniques.
361

Sun Shine Technologies


- We can send or receive data between SAP to SAP.
- In enterprise, data can be maintained in central server or
distributed servers.
- If data is maintained centrally,
o Adv:
Access to complete data is possible
o DIS-ADV:
Maintaining large amount of data.
We cant upgrade individual modules from one
version to another.
- If data is maintained in several servers:
o Adv:
Easy maintenance
We can upgrade independent servers
o Limitations of distributed systems:
Servers are places geographically in different
places.
Online updating is not possible.
Data migration: data is sent to another system (not a 2 way
communication)
Non-SAP -> SAP
SAP
-> Non-SAP
Data transfer: data can be sent or received from SAP to SAP. (2
way communication)
SAP r/3 <-> SAP r/3
DBMS:
1. ORDBMS:
- Data available centrally and all modules are connected to
that central server.
o Advantage:
Any module can access any data.
o Disadvantage:
Upgrade cannot happen just for one module, all
the modules needs to be updated.

362

Sun Shine Technologies


If server crashes then entire data is lost for all the
modules.
2. DDBMS:
- Database is distributed for different countries.
o advantage:
easy maintainence
If updagrade happens then it will not affect the
other countries.
If india server crashers then it will not affect other
countries.
In distributed environment:
- Data is available in several systems or servers.
- There is requirement data transfer between servers.
- Cross application technologies provides data transfer
technologies
o R.F.C remote function call
o IDoc intermediate document
o EDI electronic data interchange
o ALE application link enabled
o BAPI business application programming interface
o WORKFLOW
In distributed environment operation happens in two system.
- Whatever the operation happens in the first system is called
as outbound process.
o Outbound process initiates the data transfer.
- Whatever operation happens in the second system or
partner system is called as Inbound Process.
o Inbound Process receives data from partner system.
DATA TRANSFER:
ABAP
DATA MIGRATION
BDC, LSMW, BAPI

CROSS APPLICATION (C.A) Replacement of C.A


DATA TRANSFER
SAP NETWEAVER XI, (E
RFC, IDOC, ALE, EDI, BAPI tool)

R.F.C Remote Function Call:


363

Sun Shine Technologies


- It is a protocol/mechanism used to establish connection
between two external servers/systems (SAP r/3 to SAP r/3).
INDIAN SERVER

US SERVER

NOTES:
- Internal system within one desktop/laptop.
- External system two different systems.
- Gateway servers provide connection between two external
servers.
R.F.C:
- In general RFC can be configured by BASIS consultant.
- RFC destination name can be alpha numeric and upper case.
- connection type:
2- connecting to r/2 system
3- connecting to r/3 system
- We have to specify IP address (or) host name, system
number
- Gateway server and host details required if we are
connecting to external server.
o Gateway server is responsible to connect external
server).
- We have to specify partner system client.
o Username, password, language, detailsetc.
- Save RFC connection:
o Connection test tab is used to check the connection.
o While checking connection system may lead to two
types of errors.
Communication failure: if IP address, system
number is wrong.
System failure: if client number, username details
are
- SAP system uses R.F.C, TCP/IP, CPI-C protocols, while
exchanging data.
364

Sun Shine Technologies


o TCP/IP: Transmission control protocol and internet
protocol
o CPI-C: common programming interface/communication
- R.F.C uses Gateway Server Details.
o Gateway server provides gateway service.
o Gateway service is used to establish connection
between two external servers.
Types of R.F.C:
- tR.F.C transactional R.F.C
- aR.F.C asynchronous R.F.C
- sR.F.C synchronous R.F.C
- qR.F.C Queued R.F.C
- webR.F.C establish connection with browser
- t.code to set up R.F.C connection : SM59
STEP-BY-STEP PROCEDURE:
- Go to SM59 (from 800 client)
- Place the cursor on ABAP Connection click on Create.
R.F.C Destination - RFCALL810 (should me in capital letters.
Connection type 3 (automatically pops-up)
And hit enter twice.
Description 1 RFC destination creation
Under technical settings tab,
o load balance NO (when source system is connection
to external system can the system
hold the
load BASIS people will decide this)
o Target host - (system status host name in the
bottom, if you click on other kernel info
tab in the
bottom you can see IP address)
o System number 01 (under SAP logon screen right
click on the server name properties instance
number.
o Under save as (just click on IP Address or follow the
above procedure for IP Address)
o Gateway host (provide this if we are connecting to
external server)
365

Sun Shine Technologies


o Gateway service (provide this if we are connecting to
external server)
Logon & Security tab
o Trusted system Yes (this will take you to SAP easy
access screen) and (if you click on logon screen then it
will take you to the initial screen where you need to
enter userid and password).
o Logon
Language EN
Client 810
User SAPUSER
PW status
Password
o Unicode test
Click on connection test tab system displays the
time taken to establish the connection to the
partner system/target system. Time is displayed in
the micro seconds.
Sometimes it leads to system failure or
communication failure. For communication failure
it can IP wrong, system failure in the targer
system 810 must exists and user must exist.
o Save continue click on connection test (push button
on application tool bar) come back.
Click on remote logon:
- SAP easy access screen will come automatically.
SQL Trace:
Go to ST05
Select RFC trace
Click on Activate trace
Come to SM59
- Special options tab consists of RFC trace.
o If this check box is activated, system displays the trace
list while establishing connection.
o Using ST05 Rfc trace trace can be captured and
displayed.
Click on connection test or remote logon
366

Sun Shine Technologies


Come back to ST05 deactivate trace
Click on Display Trace continue
PROGRAM USING RFC:
Logon to 800
Go to SM59
Define RFC set up
Click on remote logon
- System opens 810 client as parallel session.
UNDER 810:
Go to SE37:
Create a function module with function
group (zrefgroup - zrefmodule).
Under attributes tab remote enabled
function module creation.
Tables tab it like kna1.
Source code data: wa type kna1.
Select * from kna1 into table it up to 10
rows order by kunnr.

Now go to 800.
Se38
Provide title
Executable save as local object.
Data: it_kna1 type table of kna1.
Wa_kna1 type kna1.
*---calling remote enabled function
module--Call function zrefmodule destination
RFCALL810. (destination will disp
810 clients information)
*----display output
Loop at it_kna1 into wa_kna1.
Write:/ wa_kna1-kunnr,
Endloop.

Note:
In RFC if you dont mention destination, then output will be of
800s client and if you mention destination with 810 clients name
then 810 clients information will be displayed.
Non-SAP to SAP data migration BDC or LSMW or BAPI (cut and
paste)
SAP to SAP data transfer copy and paste ALE, EDI, BAPI,
workflow, RFC (connection) IDOC.
RFC is maintained by Basis people.
SCC4 to check all the servers in our own system.
Call function <> destination <rfc destination name>
Bapi_companycode_getlist it gives list of company codes 165
company codes are available
367

Sun Shine Technologies


- Se37 bapi_companycode_getlist display rfc target sys
rfc810 then it will display 6 company codes available in
810 client.
-------------------------------------------------------------------&-------------------------------------------------------------Creating user in 810 client: (If you are not able to login to 810
client then follow this procedure).
811
SAP*
06071992 (SAP launch date)
Hit enter
Su01 (to create user)
User SAPUSER
Alias not required
Click on create.
Provide last name
Click on logon data tab.
Initial password
Repeat password
Click on Profiles tab.
Profile SAP_ALL and hit enter
SAP_NEW and hit enter.
Save and logoff.
Re-login with 810 SAPUSER welcome now change the
password.
Note:
SAP_ALL for accessing all screens, tables, etc.
SAP_NEW for creating new screens, new tables, etc.
-------------------------------------------------------- IDoc
-------------------------------------------------------------------IDoc:
- It is intermediate document.
- It is a container, which carries the data from one system to
another system.
- IDoc is not a process, but it is used in data transfer process.
- IDoc holds the data during data transfer.
368

Sun Shine Technologies


- If the IDoc is used in outbound system, it is called as
outbound IDoc.
- If the IDoc is used in inbound system, it is called as inbound
IDoc.
- The syntax and semantics of inbound and outbound IDoc
should be same.
- IDoc is SAP proprietary format. (proprietary means SAP owns
it)
- IDocs are of two types:
o Basic IDoc:
Which is built from the scratch
o Extended IDoc:
Which is extension to basic IDoc
Basic components of IDoc:
o Segment
o Data element
SEGMENT can be classified as:
- Segment type
o It is version independent
o SAP defined segment type begins with E1
o User defined segment type begins with Z1
- Segment definition:
o It is version depenent
o SAP defined segment definition name begins with E2
o User defined segment definition name begins with Z2
- Segment documentation:
o SAP defined segment documentation begins with E3
o User defined segment documentation begins with Z3
DATA ELEMENT:
- It describes the field related semantic and technical
properties.
Runtime components of IDoc:
- Control Record:
o It specifies the sender and receiver name
369

Sun Shine Technologies


o EDIDC table maintains control record information.
- Data record:
o It specifies which data is transferring across system
using IDoc.
o Data record information is maintained in EDIDD
structure.
- Status Record:
o Whenever IDoc is used in data transfer process, at
every milestone IDoc generates status codes and status
messages.
o It specifies the status codes and status messages.
o Status record information is stored in EDIDS table.
While IDoc transfer at every milestone, IDoc generates status
codes and status messages.
If the status code is 01 to 50 then error happened at outbound
process.
If the status code is 51 to 75 then error happened at inbound
process.
- Every IDoc must be added with message type.
- Message type specifies the type of information/data used in
IDoc.
MESSAGE TYPE INFORMATION
DEBMAS
- customer information
CREMAS
- vendor information
MATMAS
- material information
COSMAS
- cost centre information
ORDERS
- sales order / purchase order
- Every IDoc is identified by unique number.
- Most of the IDoc related T.Codes begin with WE.
IDoc
examples:
DEBMAS01
DEBMAS02
DEBMAS03

01 TO 05 are version.
IDoc = message type +
version

370

Sun Shine Technologies


DEBMAS04
DEBMAS05
WORKING WITH IDoc:
- Working with standard IDoc
- Standard IDoc enhancement
- Custom IDoc creation
IDoc Related
WE02
WE05
WE21
WE20
WE31
WE30
WE81
WE82
WE47
WE60

T.Codes:
IDoc List
IDoc List
IDoc Port Creation
IDoc partner Profile Creation
IDoc Segment creation & segment release
IDoc Creation
Logical message type creation
Assign Logical message to IDoc
IDoc Status Codes
IDoc Documentation

IDoc Types:
o Basic IDoc: it is built from the scratch. (it does not exist)
o Extended IDoc: It is extension to Basic IDoc. (adding
addional segments/fields to exising IDoc)
NOTE:
All the segments must be released before releasing the IDoc.
Once the IDoc is released then modifications are not allowed.
IDoc type is message type.
Sending system
Outbound system
Same Syntax and
semantics

Receiving system
Inbound system
Same syntax and semantics

-----------------------------------------------------------------&---------------------------------------------------------------CUSTOM IDoc CREATION:


371

Sun Shine Technologies


Step 1: Create segment
WE31 Segment creation
Step 2: IDoc creation
WE30 IDoc creation
Step 3: message creation
WE81 Logical message creation
WE82 Assign logical message to IDoc
WE31 Release segment
WE30 Release IDoc
Business Scenario:
Creating custom material IDoc.
Step 1: Segment creation
Go to WE31
Segment type (create segment) - z1mara_segment1
(underscore is accepted only once)
Click on create
Short description mara segment creation
Segm. Definition this will come automatically after we click on
released button.
Field name matnr matnr 18 (dont click on ISO co check box)
ersda ersda 8
ernam ernam 12
(not recommented to enter many fields as segment is good only
for few fields)
Save person responsible dont make any changes continue
save as package own request.
You will notice segment definition automatically updated with
transport request but not yet released.
Create another segment z1marc_segment
Click on create
Short description marc segment creation
Matnr matnr - 18
Werks werks 4
Pstat- pstat - 15
Save person responsible dont make any changes continue
save as package own request.
372

Sun Shine Technologies


Step 2: IDoc creation
WE30 obj. name zmat_idoc
Basic type (from scratch)
Click on create.
Select - Create new (right from the beginning)
- Create as copy in this list, you are copying from source
- Create successor like next version/level.
Description customer idoc creation
Continue
You will notice a Blue line create segment (we are calling
created segments)
Segment type z1mara_segment
Minimum no 1
Maximum no 999
(click on segment editor to cross check)
Continue.
You will notice one segment is ready.
Keep the cursor on the mara segment and create
Add segment as Child
Segm. Type - Z1marc_segement.
Minimum no - 1
Maximum no - 99
Save
Des
Save
Come back.
It will contain some warnings.
Go to Development menu -> object -> check you will observe all
the information messages.
Step 3: EDI logical messages type
WE81
click on change mode
Continue
Click on new entries.
Message type Zmessage_type custom logical message type
save as package save under request - creating logical message.
zcremas
373

Sun Shine Technologies


WE82 click on change mode.
New entires.
Zmessage_type zmat_idoc 700 (system status version)
Assign save under package workbench request create short
des: assigning logical message to idoc type.
Save - go back.
Step 4: Release segment
Release segment and idoc
WE31 z1mara_Segment go to edit menu set release.
Z1marc_Segment - go to edit menu set release.
You will notice the released button checked.
Step 5: Release IDoc
WE30 idoc release
Zmat_idoc edit menu set release yes (dialogue box)
Go to Development menu -> check.
Checking documentations in different formats:
WE60 documentation menu -> HTML format
Zcustomer_idoc1 other information updated.
Documentation- html format
Documentation check other formats FYI.
Note:
documentation can be saved on desktop also.
WE60 and WE61 both are same but WE61 gives more information
compared to WE60.
----------------------------------------------------------------&----------------------------------------------------------------STANDARD IDoc CREATION:
WE31 click on F4.
Click on any standard IDoc. (standard IDoc begins with E1)
Open in display mode. (you can view any IDoc from here)
WE30 click on F4.
(IDoc can be created, changed, deleted)
e.g: open cremas notice all the segments and fields in it.
Debmas
374

Sun Shine Technologies


-----------------------------------------------------------------&---------------------------------------------------------------Extended IDocs:
- It is used to add additional fields to existing/basic IDoc
(without changing standard IDoc).
- It is also called as IDoc extension or IDoc Enhancement.
- Adding additional fields can be added to standard IDoc by
adding additional segments.
Business scenario:
Extending DEBMAS06 IDoc.
Pre-requisities:
Go towe31 z1kna1_segment
Short des
Kunnr kunnr
Land1 - land1
Name1 name1
Save as package
Short description
Edit- release
Segment is ready
We30
Debamas06
Link to basic type debmas06 continue
Notice by default Debmas fields.
Now adding additional fields.
Place the curson on E1kna11 click on create segment.
Information message continue
Segm. Type z1kna1_sgement
1
99
Continue
Save as package.
Notice additional fields are added to e1kna11.
Save under package.
Short description.
375

Sun Shine Technologies


-----------------------------------------------------------------&---------------------------------------------------------------CREATING IDoc Enhancement (Adding additional functionality to
SAP Standard IDoc)
It can be done in two ways:
o Adding custom segmen
o Using customer enhancement (IDoc programming)
Adding custom segment to standard IDoc:
- We can add additional fields to standard IDoc using custom
segment.
- Custom segment consist of required additional fields.
Pre-requisite:
Go to WE31 create custom segment with required additional
fields.
WE30
Zext_debmas
Select extenstion.
Create
Create new debmas06 (standard Idoc)
Description additional fields to debmas06 IDoc.
Continue.
Expand e1kna1m place the cursor on existing segment click
on create segment.
Child segm type zikna1_segment1 1 999 continue.
Save as package.
-----------------IDoc also can be enhanced using customer exit or BAdi.
Using customer enhancement (IDoc programming):
- SAP defined enhancements related to IDocs are available in
SMOD t.code.
- Using those enhancements, we can add additional
functionality to standard IDoc.
- SMOD enhancement components function module
source code tab notice SAP defined Zinclude.
376

Sun Shine Technologies


- In the Zinclude we have to write additional functionality
related to IDoc programming.
- While implementing IDoc BAdi enhancement, we have to
write the code in respective methods.
SMOD - f4 find for Idoc (CTRL+F) select any one.
- Implementing: go to CMOD project enhancement
assignment function module zinclude.
-------------------------------------------------------------------&-------------------------------------------------------------IDoc REDUCTION (also known as reduced IDoc)
- It is also called as reduced IDoc (It is exactly opposite to
enhancement).
- Using this scenario, we can deactivate the unwanted
fields/segments while data transfer.
- We can deactivate standard IDoc concern complete segment
or segment concern few fields.
o As a result while processing IDoc, system does not read
the deactivated segment or field values from the source
system.
- T.code BD53 to deactivate.
o Specify reduced message type name zdebmas06
click on create.
o Message type reference Debmas
o Short description reducing IDoc.
o Place the cursor on segment and click on select.
Notice the color symbol and color difference.
o To deactivate field under the segment:
Double click on segment and check/uncheck the
check boxes and select.
o Continue with request.
EDI
Electronic data interchange
- It is an old technology used for data transfer.
- It is common technology used by ERP application.
- It is not SAP proprietary technology.
377

Sun Shine Technologies


- It is also called as paperless technology.
- EDI supports to exchange data between:
o NON-SAP -> NON-SAP
o NON-SAP -> SAP
o SAP
-> NON-SAP
o SAP
-> SAP
- It is mainly used for SAP -> NON-SAP communication.
- SAP implemented companies also uses EDI to exchange data
between international business partners.
NOTE - FYI:
- Very less implementations of EDI.
- Costly to implement EDI.
- Even the partner should have EDI.
SENDING SYSTEM DATABASE:
OUTBOUND PROCESS
sending system -> outbound idoc -> edi subsystem -> EDI
document -> VAN.
VAN value added ->
INBOUND PROCESS
EDI document -> EDI sub system -> inbound IDoc -> Receiving
system ->
RECEIVING SYSTEM DATABASE.
NOTE:
- Edi subsystem and EDI document process happens in OS
level.
- EDI uses RFC to establish connection between two external
systems.
- EDI uses IDoc while data transfer.
- In EDI process, while executing outbound process sending
system reads data from source system database and it
generates outbound IDoc.

378

Sun Shine Technologies


- Outbound IDoc is processed using EDI system and converted
as EDI document (O/S Level).
- EDI document is placed in VAN.
- VAN maintains all the EDI documents.
- While processing inbound process, it receives EDI document ,
convert it into inbound IDoc (by EDI subsystem) finally
update to target system database.
EDI Terminology:
PORT:
- It is a communication channel.
- ALE uses tRFC port
- EDI uses file port
- Ports can be defined using WE21 t.code
PARTNER PROFILES: (details (profiles) of business partner)
- Partner profiles can be defined using WE20 t.code
- SAP point of view 7 types of
o B bank
o BP benefits provider
o GP business partner
o KU customer
o LI vendor
o LS logical system
o US - user
EDI Subsystem:
- It is software component used in EDI process.
- It converts IDoc to EDI document format and vice-versa.
VAN:
- Value added network.
- It is used in EDI Process.
- It is a mail box, which maintains all the EDI documents as a
stack and it sends the document to respective recipient.
PROCESS CODE:
- SAP defined processed codes are of two types:
o outbound and inbound process codes
379

Sun Shine Technologies


- Every process code consists of one function module.
o Using function module, it updates data to target
system.
- Process code is used to update data to target database.
Outbound process codes - T.code: WE41
o ME10: purchase order process code
o ME11:
o SD09: invoice
o SD10: sales order confirmation
o SD12: Quotation
Inbound process codes - t.code WE42
o DEBM: DEBMAS customer master data
o HRMD: HR master data
o INVF: invoice receipt
o MATM: matmas
o ME01: order acknowledgement
Message control:
- It is mechanism used by ALE to transfer transaction data.
- MC specifies application type, message type, output type,
process code, time of data transfer, medium of data transfer.
Output type:
- It specifies type of output printer (hard copy), fax, mail, ALE,
EDI.
Note:
O/S -> D.B -> SAP
o/s can be C drive, D drive.
d.b -> database.
Every IDoc identified by unique number.
CONFIGURATION STEPS:
Steps 1 defining port
- WE21 used for port creation defining - edipartner.
- We21 place the cursor in FILE and click on create.
380

Sun Shine Technologies


- Provide port name (need not start with Y or Z)
o Description (need not start with Y or Z)
- IDoc release 4.x.
Check - Unicode format
Outbound file (tab):
Logical directory alias name (not the actual name but alias
name, ( desktop short cut ))
Physical accurate path - c/user/desktop/file.doc
Select logical/physical directory.
Function module select one from the drop down (hit F4)
edit_path_create_username (select the required one)
command file outfile
Click on outbound trigger (tab):
- RFC destination server_exec (hit F4 and select the required
one)
- Directory - xxxxxxxouttrig
Click on inbound file (tab):
Other things automatically popsup.
Inbound file infile.
Click on status file (tab).
- Directory status
- Enter function module name
- Status file in file.
Save.
Step 2 partner profile creation:
WE20 partner profile creation
Place the cursor on partner type US click on create.
Partner no: edipartner
Parter type : US
Post processing: permitted agent (tab):
- Ty US
- Agent SAPUSER
- Language En
Save notice outbound parameters enabled.
Under outbound parameters - Click on create outbound
parameters.
- Partner role: $1 specify any partner role
- Message type DEBMAS
381

Sun Shine Technologies


-

Receiver port subsystem*** (hit F4 and select one)


Transfer immediately
collect
IDoc type:
o Basic type debmas06
Save - back
Click on inbound
Partner role
Message type debmas
Process code debm
Trigger immediately
Check execute
Click on message control tab.
Click on insert row.
Application V1
----misssed notes
Process code it creates Idoc.
----missed notes
EDI partner profiles (inbound and outbound) are maintained in
EDPP1 database table.
EDP13 is another transparent table maintaining outbound partner
profile details.
EDP21 is another transparent table maintaining inbound partner
profile details.
--------------------------------------------------------- ALE
-------------------------------------------------------------------ALE: (application link enabled)
1. It is SAP proprietary technology
2. Its alternative for EDI technology.
3. Is used to transfer data between SAP to SAP.
4. Is used to exchange data between two logical systems.
5. Uses RFC port.
6. Data stored in memory buffer.
7. Uses R/3 connections.
8. Uses IDoc to transfer data.
382

Sun Shine Technologies


9. It supports data transfer/exchange mainly for SAP to SAP and
Non-SAP to SAP but not for SAP to Non-SAP.
10.
It provides reliable communication for distributed
application (communication between loosely coupled
applications).
11.
ALE technology is built on message architecture.
12.
ALE can be done in 3 steps:
a. Outbound process
b. Inbound process
c. IDoc Error handling
13.
ALE uses RFC mechanism while establishing connection
between external systems.
14.
ALE uses IDoc while data transfer.
ALE:
- It supports following scenarios:
o To distribute master data
o To distribute transaction data
o Distribute only changes (change pointers)
o IDoc extension (extended IDoc)
o IDoc reduction (reduced IDoc)
o IDoc filter
o IDoc conversion
o IDoc serialization
ALE
It is mainly used to exchange data
between logical systems

EDI
It is used to exchange data betwee
two business partners.

It is mainly used for SAP to SAP


communications.

Is mainly used to exchange data


between Non-SAP to SAP.

It uses tRFC port.

It Uses file port

It is SAP proprietary technology.

Is a common old and general


technology

383

Sun Shine Technologies


EDI:
1. Data stored in files.
2. Uses TCP/IP connections.
3. Uses EDI subsystems to transfer data.
ALE NEW Terminology:
LOGICAL SYSTEM:
- It is the alternative name given for the physical system.
- Its name can be alphanumeric.
o Ex: LS810, LS800, ALE800, ALE810, SENDER.
- Logical system names are client independent.
- We can define own logical systems.
DISTRIBUTION MODEL:
- It specifies which data is transferring across system.
- It consists of model view.
o Model view specifies sender name, receiver name and
message type.
- Using BD64 we can create custom distribution model.
MODEL VIEW:
- It specifies sender, receiver and message type information.
- We can add message type or business object to model view.
- Model view can be added to message type or Bapi.
- Its name can be MVIEW or MODEL VIEW.
- We have to configure both system, must use common model
view.
- It is called as ALE service layer.
MASTER IDoc:
- It is temporary IDoc which holds the data temporarily.
- It is generated by outbound process.
COMMUNICATION IDoc:
- It is permanent IDoc, which stores/maintains data
permanently.
- It is generated immediately after master IDoc.
- It carries data from one system to another system.
- It initiates inbound process.
384

Sun Shine Technologies


POSTING MODULE PROGRAM:
- This program is used to update data to target system
database.
- It uses process code while updating data.
- Process code uses function module.
- It can be processed either foreground or background.
MESSAGE CONTROL:
- It is the mechanism used to transfer transaction data using
ALE.
- It specifies application type, message type, medium, time of
data distribution.
MASTER DATA DISTRIBUTION:
- We can distribute master data like customer master, vendor
master, material master, HR master data between
distributed systems (or) other r/3 systems.
- Whenever outbound process executed, system collects the
data from source system and it generates master IDoc.
- Master IDoc processed through ALE service layer.
- Followed by communication IDocs will be generated.
- Communication IDoc carries the data from system to another
and it initiates inbound process.
- At the receiver end IDoc will undergo for syntax and
semantic check.
- As per the configuration it performs conversion, version
change or filter.
- Finally inbound system updates data to target system
database using posting module program.
ALE Configuration: (to distribute master data)
- We can configure system only for sending data to partner
systems/other systems (push)
(or) send and
receive data from partner systems/other systems (push and
pop)
(or) only send changes of source system to partner
systems/other systems
- This configuration will be done based on requirement.
385

Sun Shine Technologies


Operation happens in the below manner:
Sending
Master
ALE
Comm
Receivi
->
System
IDoc
Servi
unicat
ng
> ce
> ion
> system
Databas >
e (or)
Layer
IDoc
outboun
(und
d
er
system
distri
butio
n
mode
l)
Posting module program -> transaction screens > target
system database.

vers
ion cha >
gne

filte
r
con
vers
ion

Source system database -> sending system (Outbound system),


master idoc, ALE service layer (distribution model) Communication idoc -> (till here it comes under outbound
process) ->
Receiving system -> filter (conversion) (version change) ->
posting module program -> transaction screen -> targer system
database till here it comes under inbound process.
Filter to filter or restrict or control the data. (optional step)
Conversion INR to USD conversion, language conversion, data
format is mismatch. (optional step)
Posting module program updating to target system database.
Transaction screens customer creation is done through
transaction XD01, etc.
- If any errors are there then will not be updated. Through
status codes you can identify the errors.
Target system database data is updated here.
PROCESS FLOW:
- Whenever outbound process is executed, source system
collects the data from source system database and it
generates Master IDoc.
- Master IDoc is processed using ALE service layer.
- It checks the interested, configured receiving systems.
386

Post
ng
mod
ule
prog
am

Sun Shine Technologies


- Then immediately communication IDoc gets generated.
- Communication IDoc carries data from one system to
another system and it initiates inbound process.
- IDoc undergo for syntax and semantic check after receiving.
- Based on the configuration, it performs:
o Version change
o Filter
o Conversion
- Finally system triggers posting module program.
- Program updates to target system using call transaction
either in foreground or background.
- We can check target system data either at table level or
transaction level.
800
1 - Go to t.code SALE
-Define logical system (LS800)
-Assign logical system to client (LS800>800)
-Create RFC destination (LS810)
3 - WE21 define port
5 - WE20 partner profile creation
7 - BD64 distribution model
- Model view creation
- Add message type to M.view
- Generate partner profile
9 - BD10 - send material master data
BD12 send customer master data
BD14 send vendor master data
BD16 send cost center master
data
10 - WE05 check IDoc status and
collect IDoc number
11 - WE19 test tool for outbound
process (or) test IDoc status by
entering IDoc number. (this is optional
step)

810
2 - Go to t.code SALE
-Define logical system (LS810)
-Assign logical system to client (LS8
>810)
-Create RFC destination (LS800)
4 - WE21 define port
6 - WE20 partner profile creation
8 - BD64 distribution model
- Model view creation
- Add message type to M.view
- Generate partner profile
12 - BD11 get material master dat
BD13 get customer master d
BD15 get vendor master dat
BD17 get cost center master
data
13-WE05 check IDoc status and
collect IDoc
number
14-WE19 enter IDoc number and
execute posting module program
15-Check the target system data t.c
level and table level.
387

Sun Shine Technologies


Login in client 800
- Go to t.code SALE
- Basic settings
o Logical system
Define logical system
Execute.
Create on new entries
- LS800 defining logical system (type this and hit enter)
o Create own request go back back.
- Click on assign - search for our client (800) and double click
there - under logical system enter LS800 and save
information message (dialog box) yes back
o Under cross client object changes select - changes to
repository and cross client customizing allowed.
- Come back back.
- Under communication - Create RFC destination execute.
- Place the cursor on ABAP connection create
o RFC destination LS810
o Connection type 3 automatically comes
o Descritption1 RFC destination creation
o Target host name server (system->status)
o System no 01
- Click on login and security
o Under logon.
o Language EN
o Client 810
o User
o Password
- Save
- Click on connection test
- Click on remote logon
- New window will open with 810
- t.code sale
- follow the above procedure
Under 800
WE21 transaction rfc
Create generate Port name
388

Sun Shine Technologies


Descritiop Rfc destination- Ale810 and hit enter and you will see
Save and after saving it comes to ********list
Under 810
Create generate Port name
Descritiop - receiver port creation
Rfc destination- Ale810 and hit enter and you will see
Save and after saving it comes to ********list
WE20 - 800
Keep the cursor on US - Click on create
Partner no partner1
Partner type - US
Post.process
- Typ: us
- SAPuser
- En
o Save it.it comes under partner list
- Click on Create outbound parameter.
o Partner role $1
o Message type Debmas
o Reciver port a0000000015
o Collect idocs
o Basic type Debmas
o Package size 100
o Save data is saved come back
Click on create inbound parameters.
- Partner role ls
- Messag etype Debmas
- Process code debm
- Trigger immediately
- Save it
------Partner details are ready in 800------WE20 810
Partner tye ls click on create
Partner no ale800
389

Sun Shine Technologies


Partner type ls
Typ us
Agent SAPuser
Land en
Save
It come sunder type ls
Click on create outbound parameter
Role ls
Messag etype debmas
Receiver port a00000002
Output mode collect idoc
Basic type debmas latest one
Package size 1000
Save
BD64 800
- Click on change mode
- Click on create model view
o Short text
o Technical name alemodelview it will add at the
bottom
- Select our model view and click on add message type
o Model view alemodelview
o Sender LS800
o Receiver LS810
o Message Debmas
o Continue
- Now expand our alemodelview to check
- Save
- Go to Environment menu generate partner profile
- Model view alemodelview
- Partner tsystem ls810
o Ty: us
o Id SAPuser
o Version 3
o Size 100
o Transfer IDoc immediately.
o Execute it.
390

Sun Shine Technologies


- Everything should be in green color.
BD64 810
Change mode
Create model view
Short text modelview creation
Technical name alemodelview (same as in 800)
Continue
Select our m.view and click on Add message type
Ale810
Ale8000
Debmas
Save
Environment generate partner profile
Partyen system ale800
Ty us
Id SAPuser
---follow above procedure
If you see in green color then it is correct, here you should not get
any error message.
----tilll here consultant work is over---- remainitn steops are for the
urser.
To cross check go to 800
Under Kna1
BD12 customer 2000 2001
Output type debmas
Logical system LS810 (destination)
No of customer 20
Execute
you will receive 2 information message with the status. (if it
mentions 1 then it is correct if 0 then wrong)
To check go to WE05 800
Partner number as LS810 - execute
Collect the IDoc no
- Click on control rec F2 - it should be in green color
- Status record F2 you will notice IDoc generated.
Go to we19
Specify the existing - collected idoc no and execute.
391

Sun Shine Technologies


Place the cursor on segment.
Click on standard outbound - continue information message with
status.
810
Bd13 customer 2000 to 2001
- Message type Debmas
- Execute.
- Information message.
We05 partner number as LS800 execute
- Under selected IDocs you will notice traffic lights in red
color.
- Copy the IDoc number and go to WE19
- Execute
- Place the cursor on segemtn and click on inbound function
module.
o Select the function module - idoc_input_debitor (hit F4)
o In foreground
Continue
- Information message continue.
- Continue, continue, continue.
- Information message
- Go to SE16 under KNA1 enter
- Now go to XD02 and check if updated or not.
Note:
TRFC used by ale
File used by port
If you receive any error then double click on status.
BAPI
Business application programming interface:
- It is used to distribute data with third party.
- It is a good interface which provides non-SAP to SAP/viceversa communication.
- Bapis are widely used in SAP.
1. Bapi introduction business framework
392

Sun Shine Technologies


-

SAP is a collection of function areas.


Each functional area is a collection of business functions.
Each business function is a collection of business objects.
Each business object is a collection of BAPI methods.
Each BAPI method uses remote enabled function module.

- BOR: business object repository


BOR is a collection of business function and business objects.
All the business objects are stored in area called BOR.
T.code to view business object: BAPI.
BAPI t.code displays all the business objects as hierarchal
view or alphabetical view.
- Hierarchal view displays business objects list as functional
area wise.
- Alphabetical view displays business objects list as
alphabetical wise.
Business object name
AP account
AR account
Bank
COMPANY
COMPANY CODE
COST CENTRE
CUSTOMER
CUSTOMER ENQUIRY
CUSTOMER ORDER
CUSTOMER QUATATION
MATERIAL
PURCHASE ORDER

Business object type


BUS3008
BUS3007
BUS1011
BUS0014
BUS0002
BUS0012
KNA1
BUS2030
BUS2032
BUS2031
BUS1001
BUS2012

2. BUSINESS OBJECT ARCHITECTURE:


- Business object is designed using object oriented ABAP.

393

Sun Shine Technologies


- Business object core data (or) inherent data is protected by 3
outer layers. Core data is stored in the inner most layer.
o Integrity layer: it defines business object concern
business rules and consistency conditions.
o Interface layer: it defines business object concern
attributes, methods, events list.
o Access layer: it defines business object access protocols
like RFC, COM, DCOM, RMI/CORBA, etc.
3. BAPI FUNCTION MODULES:
- All BAPI function module names begins with BAPI.
- All BAPI function modules are process type:
o Remote-enabled
o BAPI FM import and export parameters are pass by
value only.
o BAPI FM are used in
BAPI reporting
While creating business object
While data migrating from non-SAP to SAP.
- Most of the BAPI methods are get list, get status.
- Go to SE37 enter BAPI* and hit F4 remove the number of
hits (click on repository info system) and hit enter.
- Function group name also begins with BAPI - name and
description also in English.
- E.g. BAPI_companycode_getlist it provides all the company
code list.
- E.g. BAPI_companycode_getdetail it provides company
code details for the given company codes.
- E.g. BAPI_salesorder_getlist it displays all the sales orders
as list.
- E.g. BAPI_salesorder_getstatus it displays sales order status
for the given sales order.
- E.g. BAPI_salesorder* - F4.
BAPI
Se38 title executable save as local.
*----declaration
Paratmeters p_sdocno like vbak-vbeln.
394

Sun Shine Technologies


Data return_status type bapireturn. (observe associated types, go
to fm under exporting)
Data it_statusinfo type bapisdstat (go to fm under tables)
*---calling function module
Call function bapi_salesorder_getstatus
Exp.
Sales docue = p_sdocno
Imp.
Retu return_status
Tables
Statusinfo it_statusinfo
If sy-subrc = 0.
*--display output
Loop at it_statusinfo into wa_statusinfo.
Write:/wa_statusinfo-doc_number, wa_statusinfo-doc_number.
Enter other fields(all these you will get from bapisdstat)
Else.
Write:/ no data found.
Endif.
BAPI
-

STRUCTURES:
SAP defined Bapi structures are available in ABAP dictionary.
All BAPI structure names begin with BAPI.
BAPI structures are used while creating BAPI FM.
BAPI structures are used while Data migration (non-SAP to
SAP).
- Go to SE11 data type bapi* - F4 search for structures
delete number of hits.
- There are two special BAPI structures:
o BAPIRETURN it provides return status of any
operation.
o BAPIRET2 it provides in detail status of any BAPI
operation.
- Go to SE11 - bapireturn

Custom bapi creation:


-Go to SE11 zbapi_import structure save.
Components carrid,
395

Sun Shine Technologies


Again go to SE11 zbai_export structure save.
Components - Connid, cityfrom, cityto
Se37 zbapifm create - function group save.
Click on remote enabled function module under attributes.
Import bapicarrid type zbapi_import pass by value (check
box)
Export return type Bapireturn pass by value
Tables bapitab like zbapi_export
Sourcecode:
Select connid cityfrom cityto from spfli into table bapitab where
carrid = bapicarrid endfunction.
Go to SW01 zflight create.
Supertype
Object type zflight
Object name zflight
Name zflight
Descritpiono zflight
Program zflight
Application z(user defined program)
Save as local.
Place the cursor on methods utilities API methods and add
methods.
Function module zbapifm.
Click on next step.
Click on next step.
Extend program select yes.
Save.
Menu bar- Object type chnge release status - implemented
Menu bar object type generate.
Menu bar - object type - change release status released.
Menu bar object type check.
Menu bar object type activate.
Go to BAPI
Click on filter and select all - you will find zflight.
BAPI enhancements:
Using implicit enhancement options we can add additional
functionality to standard BAPI function module.
Go to SE37 bapi_companycode_getdetail
396

Sun Shine Technologies


Attributes its remote enabled.
Source code click on
Go go function module enhance source code Edit menu enhancement operations show implicit
enhancement options continue.
Place the cursor on yellow color double quotes highlighted line
right click on it - enhancement implementation create.
Choose enhancement code select code enhancement
implementation zen_implementation9.
Short text enhancement implementation save as local Enter the necessary code between enhancement
endenhancement activate.
DATA MIGRATION using BAPI:
- It is one of the interface method, used to upload non-SAP
data to SAP.
- It Using BAPI method we can upload vendor master data,
customer master data, HR master data, employee master
data.
- We have to develop one executable program SE38 to upload
master data.
- It is 5 step procedure.
o Declare internal tables, workareas using bapi
structures.
o Upload data using function modules (gui_upload reads
data from flat file to internal table).
o Reading data from internal table and map to bapi
structure.
o Call relevant bapi function module to updata data to
database, pass relevant bapi structures.
o Call function module bapi_transaction_commit. (to
create it permanently)

397

Das könnte Ihnen auch gefallen