Download as pdf or txt
Download as pdf or txt
You are on page 1of 128

PEERS – SAP ABAP

COURSE MATERIAL
of
SAP - ABAP

Prepared by PEERS TECHNOLOGIES PVT LTD, HYDERABAD


PEERS – SAP ABAP
Content Page No.
1 ABAP BASICS
ABAP Basics 1
Login to the SAP System 1
What is SAP Transaction Code 3
First ABAP Program 3
ABAP Data Types And Constants 7
ABAP Variables 8
ABAP System Variables 9
Basic Operations 9
Control Statements 11
Loops 12
String Operations 14
2 ABAP DATA DICTIONARY
What is ABAP Data Dictionary? 15
What are Data Elements and Domains? 15
How to create a Domain? 17
How to create a Data Element? 19
How to create a SAP Table? 21
Maintain test data in SAP table 22
What are Primary Keys and Foreign Keys? 24
How to create a Foreign Key in SAP table? 25
3 OPEN SQL
What is Open SQL? 27
Reading Data using Open SQL 27
Selective Reading using Open SQL 28
Inserting Values using SAP Open SQL 30
Changing Values using SAP Open SQL 31
Deleting Entries using SAP Open SQL 32
Inserting or Changing Values using SAP Open SQL 33
4 MESSAGES IN ABAP
Messages in ABAP 34
SAP Message Class 36
5 ABAP INTERNAL TABLES
What is an ABAP Internal Table and How to Create it? 38
Inserting Lines into ABAP Internal Tables 40
Changing Lines in ABAP Internal Tables 42
Deleting Lines from an ABAP Internal Table 44
More on ABAP Internal Tables 46
Control Break Processing in ABAP Internal Tables 50
Control Break Processing in ABAP Internal Tables Continued 52
6 MODULARIZATION
Modularization in ABAP 54

Prepared by PEERS TECHNOLOGIES PVT LTD, HYDERABAD


PEERS – SAP ABAP
ABAP Macros 55
ABAP Include Program 56
ABAP Subroutine 58
ABAP GUIDE
Example Tables 61
Transaction Codes 61
8 Function
Creation (without exception) 63
Creation (with exception) 63
Call Functions (a,b) 64
Creation (with tables) 65
Call Function (d) 65
9 Document (or) Form
Create Form using SAP Script 66
Create Form using SMARTFORMS 70
Modify ‘Standard-Form’ layout using NACE 72
Use existing Form in ABAP program 73
LDB (Logical DataBase) or (VIEW) – creation 75
10 Reports: *see also ‘abapdocu’ simple & complex lists+
Simple report program (using LDB) 78
SAP Queries (using Tool) 79
ALV (ABAP List Viewer) 82
Hierarchical Sequential 84
Simple (Interactive) 86
Complex (Interactive) 87
Complex (with Events) 89
11 ABAP Dictionary
Creation of Type Group (user defined Type) 91
Creation of Table (user defined Table) 91
12 SCREEN Program
Simple screen program (executable) 93
Screen program (module pool) 95
Create transaction code (to execute module pool program) 97
Screen program (with Table-Control) 97
Screen program (with TabStrip-Control) 98
Screen program – data insert, update, delete (in user defined table) 103
13 BDC (Batch Data Communication)
Call Transaction – method 107
Session – method 111
LSMW (Legacy System Migration Workbench) 114
14 RFC (Remote Function Call)
Create Remote-Function 118
Call Remote-Function 119

Prepared by PEERS TECHNOLOGIES PVT LTD, HYDERABAD


PEERS – SAP ABAP
15 IDOC (Intermediate Document)
Creation 120
Sending/receiving 122
In runtime 123
16 ALE: (Application Linking Enabling) 123
17 EDI (Electronic Data Interchange) 123
18 BAPI (Business API) 124

Prepared by PEERS TECHNOLOGIES PVT LTD, HYDERABAD


PEERS – SAP ABAP
ABAP BASICS
ABAP stands for Advanced Business Application Programming. It is a programming language developed by SAP.
ABAP language syntax
 ABAP is not case sensitive.
 Every statement begins with a keyword and ends with a period.( WRITE is the keyword to print on screen )

WRITE 'Hello World!'.

 Chained statements.If consecutive statements have identical part at the beginning, then ABAP allows you to chain these
statements into a single statement. First write the identical part once and then place a colon (:). Then write the remaining
parts of the individual statements separated by commas.Normal Statements:

 WRITE 'Hello'.

WRITE 'ABAP'.

Chained Statement:

WRITE: 'Hello', 'ABAP'.

 Comments. If you want to make the entire line as comment, then enter asterisk (*) at the beginning of the line.

* This is a comment line

If you want to make a part of the line as comment, then enter double quote (―) before the comment.

WRITE 'COMMENT'. "Start of comment

Login to SAP System

First find the SAP icon on the desktop.

Double click on the SAP icon.

Prepared by PEERS TECHNOLOGIES PVT LTD, HYDERABAD Page 1


PEERS – SAP ABAP

On the logon pad select the system you want to login to and press log on button.

Enter Client, User, password and press enter.

This is SAP easy access screen. All the tools required by ABAP developer is under the node Tools.

Prepared by PEERS TECHNOLOGIES PVT LTD, HYDERABAD Page 2


PEERS – SAP ABAP
What is SAP transaction code?

SAP Transaction code is a short cut key attached to a screen. Instead of using SAP easy access menu we can also
navigate to a particular screen in SAP by entering the transaction code (T-code for short) in the command field of the
standard toolbar.

Some of the useful transaction codes for ABAP developers.

T CODE DESCRIPTION

SE11 ABAP Data Dictionary

SE16 Data Browser

SE37 Function Builder

SE38 ABAP Editor

SE41 Menu Painter

SE51 Screen Painter

SE71 SAP Script Layout

SE80 ABAP Workbench

SE91 Message Maintenance

SE93 Maintain Transaction


First ABAP Program
Let us write a ―Hello SAP ABAP‖ program.

Navigate to ABAP editor under Tools node in SAP easy access.

Prepared by PEERS TECHNOLOGIES PVT LTD, HYDERABAD Page 3


PEERS – SAP ABAP
Double click on ―ABAP Editor‖ to open the editor. ABAP editor can also be opened by entering t-code SE38 in the
command field.

This is the ABAP editor‘s initial screen. Enter the name of the program you want to create and press create. All the
customer programs must begin with ―Y‖ or ―Z‖.

In the next popup screen(Program attributes) enter the title for your program, select Executable program as type and
press save.

Prepared by PEERS TECHNOLOGIES PVT LTD, HYDERABAD Page 4


PEERS – SAP ABAP

Press Local Object to store the program in the temporary folder.

This is the screen where you can write the ABAP code.

Write the code. Press save, then syntax check( Ctrl + F2 ).

Prepared by PEERS TECHNOLOGIES PVT LTD, HYDERABAD Page 5


PEERS – SAP ABAP

If there are any syntax errors, it ill be displayed at the bottom of the screen as shown above. Correct the errors and again
check the syntax.

Successful syntax check message will be displayed in the status bar. Then activate( Ctrl + F3 ) the program.

Prepared by PEERS TECHNOLOGIES PVT LTD, HYDERABAD Page 6


PEERS – SAP ABAP
In the following screen select your program and press continue. Then run(F8) the program.

The output will be displayed as shown above.

ABAP Data Types and Constants

Data Type describes the technical characteristics of a Variable of that type. Data type is just the blue print of a
variable.
Predefined ABAP Types
DATA TYPE DESCRIPTION DEFAULT LENGTH DEFAULT VALUE

C Character 1 ‗‗

N Numeric 1 0

D Date 8 00000000

T Time 6 000000

X Hexa Decimal 1 X‘0′

I Integer 4 0

P Packed 8 0

F Float 8 0

User defined data types


Use TYPES keyword to define the data types.

TYPES: name(10) TYPE c,


length TYPE p DECIMALS 2,
counter TYPE i,
id(5) TYPE n.

Structured data types


Structured data type is grouping of several simple data types under one name.

Use the keywords BEGIN OF and END OF to create a structured data type.

TYPES: BEGIN OF student,


id(5) TYPE n,
name(10) TYPE c,
dob TYPE d,

Prepared by PEERS TECHNOLOGIES PVT LTD, HYDERABAD Page 7


PEERS – SAP ABAP
place(10) TYPE c,
END OF student.

Constants
Constants are used to store a value under a name. We must specify the value when we declare a constant and the value
cannot be changed later in the program.

Use CONSTANTS keyword to declare a constant.

CONSTANTS: pi TYPE p DECIMALS 2 VALUE '3.14',


yes TYPE c VALUE 'X'.

ABAP Variables
ABAP Variables are instances of data types. Variables are created during program execution and destroyed after
program execution.
Use keyword DATA to declare a variable.

DATA: firstname(10) TYPE c,


index TYPE i,
student_id(5) TYPE n.

While declaring a variable we can also refer to an existing variable instead of data type. For that use LIKE instead
ofTYPE keyword while declaring a variable.

DATA: firstname(10) TYPE c,


lastname(10) LIKE firstname. " Observe LIKE keyword

Structured Variable
Similar to structured data type, structured variable can be declared using BEGIN OFand END OF keywords.

DATA: BEGIN OF student,


id(5) TYPE n,
name(10) TYPE c,
dob TYPE d,
place(10) TYPE c,
END OF student.

We can also declare a structured variable by referring to an existing structured data type.

TYPES: BEGIN OF address,


name(10) TYPE c,
street(10) TYPE c,
place(10) TYPE c,
pincode(6) type n,
phone(10) type n,
END OF address.

Data: house_address type address,


office_address like house_address.

Prepared by PEERS TECHNOLOGIES PVT LTD, HYDERABAD Page 8


PEERS – SAP ABAP
Each individual field of the structured variable can be accessed using hyphen (-). For example, name field of the
house_address structure can be accessed using housing_address-name.

Character is the default data type.

DATA: true. " By default it will take C as data type


ABAP System Variables

ABAP system variables are accessible from all ABAP programs. These fields are filled by the runtime environment.
The values in these fields indicate the state of the system at any given point of time.
The complete list of ABAP system variables is found in the SYST table in SAP. Individual fields of the SYST structure can
be accessed either using “SYST-” or “SY-”.

WRITE:/ 'ABAP System Variables'.


WRITE:/ 'Client : ', sy-mandt.
WRITE:/ 'User : ', sy-uname.
WRITE:/ 'Date : ', sy-datum.
WRITE:/ 'Time : ', sy-uzeit.

Output

Basic Operations
Assigning values to ABAP variables
Use „=‟ or MOVE keyword to assign a value to a variable.

DATA: a TYPE i,
b TYPE i,
c TYPE i,
d TYPE i.

a = 10.
b = a.
MOVE 20 TO c.
MOVE c TO d.

WRITE:/ a, b, c, d.

Output

Prepared by PEERS TECHNOLOGIES PVT LTD, HYDERABAD Page 9


PEERS – SAP ABAP
Basic Arithmetic Operations

DATA: a TYPE i,
b TYPE i,
c TYPE i,
d TYPE i.

*Using Mathematical Expressions


a = 10 + 20.
b = 20 - 10.
c = 10 * 2.
d = 100 / 2.

WRITE:/ 'Using Expressions'.


WRITE:/ a, b, c, d.

*Using Keywords
add 10 to a.
subtract 5 from b.
multiply c by 2.
divide d by 2.

WRITE:/ 'Using Keywords'.


WRITE:/ a, b, c, d.

Output

Clear ABAP variables


Use keyword CLEAR to set the variables to default values.

DATA: a TYPE i,
b TYPE i.

a = 10 + 20.
b = 20 - 10.

WRITE:/ 'Before Clear'.


WRITE:/ a, b.

clear: a, b.

Prepared by PEERS TECHNOLOGIES PVT LTD, HYDERABAD Page 10


PEERS – SAP ABAP
WRITE:/ 'After Clear'.
WRITE:/ a, b.

Output

Control Statements

To control the flow of the ABAP program use the following statements.
IF – Branching Conditionally
IF statement – The code between IF and ENDIF is executed only if the condition is true.

DATA: a TYPE i VALUE 10. " We can assign a value in the declaration

IF a > 5.
WRITE:/ 'Condition True'.
ENDIF.

Output

IF-ELSE statement – The code between IF and ELSE is executed if the condition is true, the code
between ELSE andENDIF is executed if the condition is False.

DATA: a TYPE i VALUE 1.


IF a > 5.
WRITE:/ 'Condition True'.
ELSE.
WRITE:/ 'Condition False'.
ENDIF.

Output

IF-ELSEIF statement – Used to check multiple conditions.

DATA: a TYPE i VALUE 2.


IF a > 5.
WRITE:/ a, 'Greater Than', 5.
ELSEIF a > 4.
WRITE:/ a, 'Greater Than', 4.

Prepared by PEERS TECHNOLOGIES PVT LTD, HYDERABAD Page 11


PEERS – SAP ABAP
ELSEIF a > 3.
WRITE:/ a, 'Greater Than', 3.
ELSE.
WRITE:/ a, 'Less Than', 3.
ENDIF.

Output

CASE-ENDCASE – Branching based on the content of the variable.

DATA: a TYPE i VALUE 4.

CASE a.
WHEN 3.
WRITE:/ a, 'Equals', 3.
WHEN 4.
WRITE:/ a, 'Equals', 4.
WHEN OTHERS.
WRITE:/ 'Not Found'.
ENDCASE.

Output

When no condition is met, OTHERS will be executed. OTHERS is not mandatory.

Loops

DO – ENDDO – Unconditional Loop

DO can be used to execute a certain lines of codes specific number of times.

DO 5 TIMES.
WRITE sy-index. " SY-INDEX (system variable) - Current loop pass
ENDDO.

Output

WHILE ENDWHILE – Conditional Loop


WHILE can be used to execute a certain lines of codes as long as the condition is true.

WHILE sy-index < 3.

Prepared by PEERS TECHNOLOGIES PVT LTD, HYDERABAD Page 12


PEERS – SAP ABAP
WRITE sy-index.
ENDWHILE.

Output

CONTINUE – Terminate a loop pass unconditionally.


After continue the control directly goes to the end statement of the current loop pass ignoring the remaining statements in
the current loop pass, starts the next loop pass.

DO 5 TIMES.
IF sy-index = 2.
CONTINUE.
ENDIF.
WRITE sy-index.
ENDDO.

Output

CHECK – Terminate a loop pass conditionally.


If the condition is false, the control directly goes to the end statement of the current loop pass ignoring the remaining
statements in the current loop pass, starts the next loop pass.

DO 5 TIMES.
CHECK sy-index < 3.
WRITE sy-index.
ENDDO.

Output

EXIT – Terminate an entire loop pass unconditionally.


After EXIT statement the control goes to the next statement after the end of loop statement.

DO 10 TIMES.
IF sy-index = 2.
EXIT.
ENDIF.
WRITE sy-index.
ENDDO.

Output

Prepared by PEERS TECHNOLOGIES PVT LTD, HYDERABAD Page 13


PEERS – SAP ABAP
String Operations

CONCATENATE – Combines 2 or more strings into one string.

DATA: s1(10) VALUE 'Hello',


s2(10) VALUE 'ABAP',
s3(10) VALUE 'World',
result1(30),
result2(30).

CONCATENATE s1 s2 s3 INTO result1.


CONCATENATE s1 s2 s3 INTO result2 SEPARATED BY '-'.

WRITE / result1.
WRITE / result2.

Output

If the the concatenated string fits in the result string, then the system variable sy-subrc is set to 0. If the result has to be
truncated then sy-subrc is set to 4.

SPLIT – Splits a string into 2 or more smaller strings.

DATA: s1(10), s2(10), s3(10),


source(20) VALUE 'abc-def-ghi'.

SPLIT source AT '-' INTO s1 s2 s3.

WRITE:/ 'S1 - ', s1.


WRITE:/ 'S2 - ', s2.
WRITE:/ 'S3 - ', s3.

Output

If all target fields are long enough and no target fields has to be truncated then sy-subrc is set to 0, else set to 4.

SEARCH – Searches for a sub string in main string. If found then sy-subrc is set to 0, else set to 4.

DATA: string(30) VALUE 'SAP ABAP Development',


str(10) VALUE 'ABAP'.

SEARCH string FOR str.

Prepared by PEERS TECHNOLOGIES PVT LTD, HYDERABAD Page 14


PEERS – SAP ABAP
IF sy-subrc = 0.
WRITE:/ 'Found'.
ELSE.
WRITE:/ 'Not found'.
ENDIF.

Output

REPLACE – Replaces the sub string with another sub string specified, in the main string. If replaced successfully then sy-
subrc is set to 0, else set to 4.

DATA: string(30) VALUE 'SAP ABAP Development',


str(10) VALUE 'World'.

REPLACE 'Development' WITH str INTO string.


WRITE:/ string.

Output

ABAP Data Dictionary


SQL can be divided into following 2 parts.
 DML – Data Manipulation Language
 DDL – Data Definition Language
DML part consists of query and update commands like SELECT, UPDATE, DELETE, INSERT etc. ABAP programs
handle DML part of SQL.

DDL part consist of commands like CREATE TABLE, ALTER TABLE, DROP TABLE, CREATE INDEX etc. ABAP
Dictionary handles DDL part of SQL.
So ABAP Dictionary is used to create and manage data definitions (metadata). ABAP Dictionary is used to create
Tables, Data Elements, Domains, Views, Lock Objects etc.

Data Elements and Domains


While creating a table in data dictionary each table field is assigned to a data element. Each data element is in turn
assigned to a domain.
 Domain describes the technical attributes such as data type and length of a table field.
 Data Element gives the field labels and documentation for the table field.
Consider the following code. PARAMETERS is the keyword to create input fields.

PARAMETERS: p_matnr TYPE matnr.

Prepared by PEERS TECHNOLOGIES PVT LTD, HYDERABAD Page 15


PEERS – SAP ABAP
Output

In order to get the field labels use the menu in the ABAP editor GOTO->Text Elements->Selection Texts.

All the input fields will be displayed in a table.

Just check the Dictionary Ref checkbox and press enter.

The Text ( Field Label ) will be automatically read from the Data Element. Now save, activate, go back and run the
program again.

Now place the cursor on the input field and press F1 key to get the documentation from the data element.

Prepared by PEERS TECHNOLOGIES PVT LTD, HYDERABAD Page 16


PEERS – SAP ABAP

Actually this field label and documentation are maintained in the Data Element MATNR.

So if we want to create a table with two fields as ―FirstName‖ and ―SecondName‖, then only one domain is sufficient with
data type as ―CHAR‖ and length say 20. But we need two different data elements in order to display different field labels
and documentation for both the fields.

Create a Domain

To create a domain go to t-code SE11.

Select the Domain radio button, enter the the name of the domain that you want to create and press create.

Prepared by PEERS TECHNOLOGIES PVT LTD, HYDERABAD Page 17


PEERS – SAP ABAP

Enter the short description. Place the cursor in the data type and press F4 to get the list of SAP data types.

In the popup window select the correct data type.

Prepared by PEERS TECHNOLOGIES PVT LTD, HYDERABAD Page 18


PEERS – SAP ABAP

Enter the number of characters. Enter the decimal places if it applicable to data type that you have selected. Save and
activate the domain.

Creation Of a Data Element

To create a data element go to t-code SE11.

Select the Data type radio button, enter the name of the data element and press create.

Prepared by PEERS TECHNOLOGIES PVT LTD, HYDERABAD Page 19


PEERS – SAP ABAP

Select the Data Element radio button and press continue.

Enter short description. Assign a domain to the data element. Press field label tab to maintain the field labels for the data
element.

Enter the field labels, Save and activate the data element.

Prepared by PEERS TECHNOLOGIES PVT LTD, HYDERABAD Page 20


PEERS – SAP ABAP
How to create a SAP Table

Every table has a unique name and consists of rows and columns. The number of columns in a table is fixed but can have
any number of rows.
ABAP dictionary handles the DDL part of SQL in SAP. Go to ABAP dictionary (SE11) to create a SAP table. Enter the
name of the table to be created and press enter.

Enter a proper short description for the table and maintain delivery class as ‗A‘(Application Table). Now press on Fields
tab to maintain the fields of the table.

Enter the fields of the table and maintain the proper data elements for the table fields. You can use the standard data
elements or you can create your own data elements.

Prepared by PEERS TECHNOLOGIES PVT LTD, HYDERABAD Page 21


PEERS – SAP ABAP

Maintain the primary key and press save. To maintain the technical attributes of table like tablespace, size etc. press the
Technical attributes button on application toolbar.

Enter Data class, Size category and Save.

Maintain test data in SAP table

After creating a table you can test it by maintaining a couple of entries in the table. Follow the below mentioned procedure
to maintain entries in the table. But this procedure must be used only in testing or development environment not in
production environment.
Display the table in ABAP Dictionary(SE11). Use the menu path Utilities->Table Contents->Create Entries.

Prepared by PEERS TECHNOLOGIES PVT LTD, HYDERABAD Page 22


PEERS – SAP ABAP

If this menu path is disabled then go to Delivery and Maintenance tab and
enter ―Display/Maintenance Allowed‖ in ―Data Browser/Table View Maint.‖ listbox.

Save and activate the table. Then go back to menu path Utilities->Table Contents->Create Entries.

Enter some test values in the fields and press save.

Observe the message in the status bar. To display the values in the table go to Utilities->Table Contents->Display

Prepared by PEERS TECHNOLOGIES PVT LTD, HYDERABAD Page 23


PEERS – SAP ABAP

In the selection screen enter the selection criteria if you want to filter the records you want to display and press execute.

Primary Keys and Foreign Keys

A primary key is a field or group of fields that uniquely identify a record in a table. Primary key fields cannot be NULL and
cannot contain duplicate values.
If you want to link two tables, then primary key of one table will be added to another table where primary key of first table
will be become the foreign key of second table.
Consider the following two tables.

Department Table

DEPARTMENT_ID (PRIMARY DEPARTMENT_NAME


KEY)

01 Computers

02 Physics

03 Electronics

Employee Table

EMPLOYEE_ID NAME PLACE

Prepared by PEERS TECHNOLOGIES PVT LTD, HYDERABAD Page 24


PEERS – SAP ABAP
(PRIMARY KEY)

001 Jim New York

002 Jack London

003 Robin Sydney

004 Raj Bangalore

If you want to link department table and employee table, then add the primary key of department table i.e. Department_ID
to employee table. Department_ID becomes the foreign key of employee table and Department table becomes the check
table.

Employee table after creating foreign key.

EMPLOYEE_ID NAME PLACE DEPARTMENT_ID


(PRIMARY KEY) (FOREIGN KEY)

001 Jim New York 01

002 Jack London 01

003 Robin Sydney 02

004 Raj Bangalore 03

The main purpose of the foreign key is data validation. This will not allow entering a Department_ID in the employee table
that is not there in the department table. For example if you try to create a record in employee table with Department_ID
as ‘04′, it will throw an error.
Creation of a Foreign Key in SAP table

The purpose of the foreign key is to validate the data that is being entered into a table by checking entries in a check
table. Foreign keys are checked by the front end user interface only and it is not checked if you issue a direct a SQL
statement to update the database.
Follow the steps given below to create a foreign key in SAP table.

Step 1: Open the table in Data Dictionary (SE11) for which you want to create a foreign key. Select the field for which you
want to create the foreign key and press Foreign Keys button.

Step 2: In the popup window enter the check table name and press Generate proposal button.

Prepared by PEERS TECHNOLOGIES PVT LTD, HYDERABAD Page 25


PEERS – SAP ABAP

Step 3: The system proposes the foreign key relation based on the domain. Check that the foreign key relationship
proposed by the system is correct and press copy.

Foreign key is created, now save and activate the table. To check the foreign key go to menu path Utilities->Table
Contents->Create Entries.

Prepared by PEERS TECHNOLOGIES PVT LTD, HYDERABAD Page 26


PEERS – SAP ABAP
Try to create an entry in ―Zemployee‖ table with ―Department ID‖ that is not there in the ―Department‖ table. Enter the
values and try to save the entry.

Observe the error message in the status bar. The user interface does the foreign key validation before creating the
entries.

OPEN SQL
Open SQL is a set of ABAP statements that performs operations like reads, modifies or deletes data in the SAP database.
Open SQL is independent of the database system, so the syntax of the open SQL is uniform for all the databases
supported by SAP.
All open SQL statements are passed to the database interface. The DB interface converts the open SQL to native SQL
and passes it on to the database.

List of Open SQL statements

OPEN SQL DESCRIPTION

SELECT Reads data from database

INSERT Inserts lines to database

UPDATE Changes the contents of lines in database

MODIFY Inserts lines into database or changes the contents


of existing lines

DELETE Deletes lines from database

All Open SQL statements fill the following two system fields:
 SY-SUBRC – After every Open SQL statement, the system field SY-SUBRC contains the value 0 if the operation was
successful, a value other than 0 if not.
 SY-DBCNT – After an open SQL statement, the system field SY-DBCNT contains the number of database lines
processed.
Reading Data using Open SQL

SELECT is the open SQL statement to read the data from the database. The general syntax for SELECT statement is as
follows.

SELECT <result>
INTO <target>
FROM <source>
[WHERE <condition>]

CLAUSE DESCRIPTION

Prepared by PEERS TECHNOLOGIES PVT LTD, HYDERABAD Page 27


PEERS – SAP ABAP
SELECT <result> Specifies which columns you want to read, whether one line or many
lines needs to selected, and whether duplicate entries are allowed

INTO <target> Determines the target area into which the selected data is to be placed

FROM <source> Specifies the database table from which the data is to be selected

WHERE <condition> specifies which lines are to be read by specifying conditions for the
selection

DATA: gwa_employee TYPE zemployee.

WRITE:/1 'Emp ID' color 5,9 'Name' color 5,17 'Place' color 5,
27 'Phone' color 5,39 'Dept' color 5.

SELECT * FROM zemployee INTO gwa_employee.


WRITE:/1 gwa_employee-id,9 gwa_employee-name,
17 gwa_employee-place,27 gwa_employee-phone,
39 gwa_employee-dept_id.
ENDSELECT.

In the above code,


 GWA_EMPLOYEE is the work area to hold one record of table ZEMPLOYEE at a time.
 SELECT * specifies all the rows and columns are read from the database.
 SELECT – ENDSELECT works in a loop, so the code between SELECT and ENDSELECT will be executed for each
record found in the database table.
 WRITE statements are used to output the values in the list.
 If the SELECT statement returns any record then the value of the system variable SY-SUBRC is set to zero else a non
zero value will be set.
 After the SELECT statement is executed, the value of the system variable SY-DBCNT contains the number of records
read from the database. The value of SY-DBCNT is zero if no records are read from the database.
Table ZEMPLOYEE Entries

Report Output

Selective Reading using Open SQL

In Reading Data using Open SQL we have read all the rows from the database. What if we want to read only certain
records that match a certain criteria? Then we need to use the where clause of the SELECT statement.

Prepared by PEERS TECHNOLOGIES PVT LTD, HYDERABAD Page 28


PEERS – SAP ABAP
Let us write a program to read only the employees with department ID 2.

DATA: gwa_employee TYPE zemployee.


WRITE:/1 'Emp ID' COLOR 5,9 'Name' COLOR 5,17 'Place' COLOR 5,
27 'Phone' COLOR 5,39 'Dept' COLOR 5.
SELECT * FROM zemployee INTO gwa_employee WHERE dept_id = 2.
WRITE:/1 gwa_employee-id,9 gwa_employee-name,
17 gwa_employee-place,27 gwa_employee-phone,
39 gwa_employee-dept_id.
ENDSELECT.

Report Output

What if we want to select only certain columns from the database table instead of all the columns? Then we need to
specify the field list(field names) in the SELECT statement instead of specifying ‗*‘.

SELECT id phone dept_id FROM zemployee INTO CORRESPONDING FIELDS OF


gwa_employee
WHERE dept_id = 2.
WRITE:/1 gwa_employee-id,9 gwa_employee-name,
17 gwa_employee-place,27 gwa_employee-phone,
39 gwa_employee-dept_id.
ENDSELECT.

Report Output

Only columns ID, PHONE and DEPT_ID were read from the database.

To select a single record from the database use SELECT SINGLE instead of SELECT statement. SELECT SINGLE picks
the first record found in the database that satisfies the condition in WHERE clause. SELECT SINGLE does not work in
loop, so no ENDSELECT is required.

SELECT SINGLE * FROM zemployee INTO gwa_employee


WHERE dept_id = 2.
WRITE:/1 gwa_employee-id,9 gwa_employee-name,
17 gwa_employee-place,27 gwa_employee-phone,
39 gwa_employee-dept_id.

Report Output

Prepared by PEERS TECHNOLOGIES PVT LTD, HYDERABAD Page 29


PEERS – SAP ABAP

Inserting Values using SAP Open SQL

INSERT is the open SQL statement to add values to the database table. First declare a work area as the line structure of
database table and populate the work area with the desired values. Then add the values in the work area to the database
table using INSERT statement.

The syntax for the INSERT statement is as follows.

INSERT <database table> FROM <work area>


or

INSERT INTO <database table> VALUES <work area>


If the database table does not already contain a line with the same primary key as specified in the work area, the
operation is completed successfully and SY-SUBRC is set to 0. Otherwise, the line is not inserted, and SY-SUBRC is set
to 4.

DATA: gwa_employee TYPE zemployee.


gwa_employee-id = 6.
gwa_employee-name = 'MARY'.
gwa_employee-place = 'FRANKFURT'.
gwa_employee-phone = '7897897890'.
gwa_employee-dept_id = 5.
INSERT zemployee FROM gwa_employee.

EMPLOYEE table entries before INSERT

EMPLOYEE table entries after INSERT

Prepared by PEERS TECHNOLOGIES PVT LTD, HYDERABAD Page 30


PEERS – SAP ABAP
Changing Values using SAP Open SQL

UPDATE is the open SQL statement to change the values in the database table. First declare a work area as the line
structure of database table and populate the work area with the desired values for a specific key in the database table.
Then update the values for the specified key in the database table using UPDATE statement.

The syntax for the UPDATE statement is as follows.

UPDATE <database table> FROM <work area>


If the database table contains a line with the same primary key as specified in the work area, the operation is completed
successfully and SY-SUBRC is set to 0. Otherwise, the line is not inserted, and SY-SUBRC is set to 4.

DATA: gwa_employee TYPE zemployee.


gwa_employee-id = 6.
gwa_employee-name = 'JOSEPH'.
gwa_employee-place = 'FRANKFURT'.
gwa_employee-phone = '7897897890'.
gwa_employee-dept_id = 5.

UPDATE zemployee FROM gwa_employee.

EMPLOYEE table entries before UPDATE

EMPLOYEE table entries after UPDATE

We can also change certain columns in the database table using the following syntax

UPDATE <target> SET <set1> <set 2> … [WHERE <condition>].


The WHERE clause determines the lines that are changed. If we do not specify a WHERE clause, all lines will be
changed.

UPDATE zemployee SET place = 'MUMBAI' WHERE dept_id = 2.

EMPLOYEE table entries after UPDATE

Prepared by PEERS TECHNOLOGIES PVT LTD, HYDERABAD Page 31


PEERS – SAP ABAP

Deleting Entries using SAP Open SQL

DELETE is the open SQL statement to delete entries from database table. First declare a work area as the line structure
of database table and populate the work area with the specific key that we want to delete from the database table. Then
delete the entries from the database table using DELETE statement.

The syntax for the DELETE statement is as follows.

DELETE <database table> FROM <work area>


If the database table contains a line with the same primary key as specified in the work area, the operation is completed
successfully and SY-SUBRC is set to 0. Otherwise, the line is not deleted, and SY-SUBRC is set to 4.

DATA: gwa_employee TYPE zemployee.


gwa_employee-id = 6.
gwa_employee-name = 'JOSEPH'.
gwa_employee-place = 'FRANKFURT'.
gwa_employee-phone = '7897897890'.
gwa_employee-dept_id = 5.

DELETE zemployee FROM gwa_employee.

EMPLOYEE table entries before DELETE

EMPLOYEE table entries after DELETE

We can also multiple lines from the table using the WHERE clause in the DELETE statement.

DELETE FROM <database table> WHERE <condition>

DELETE FROM zemployee WHERE dept_id = 2.

EMPLOYEE table entries after DELETE

Prepared by PEERS TECHNOLOGIES PVT LTD, HYDERABAD Page 32


PEERS – SAP ABAP

Inserting or Changing Values using SAP Open SQL

MODIFY is the open SQL statement to insert or change entries in the database table. If the database table contains no
line with the same primary key as the line to be inserted, MODIFY works like INSERT, that is, the line is added. If the
database already contains a line with the same primary key as the line to be inserted, MODIFY works like UPDATE, that
is, the line is changed.

The syntax for the MODIFY statement is as follows.

MODIFY <database table> FROM <work area>


If the database table does not already contain a line with the same primary key as specified in the work area, a new line is
inserted. If the database table does already contain a line with the same primary key as specified in the work area, the
existing line is overwritten. SY-SUBRC is always set to 0.

DATA: gwa_employee TYPE zemployee.


gwa_employee-id = 6.
gwa_employee-name = 'JOSEPH'.
gwa_employee-place = 'FRANKFURT'.
gwa_employee-phone = '7897897890'.
gwa_employee-dept_id = 5.

MODIFY zemployee FROM gwa_employee.

ZEMPLOYEE table entries before MODIFY

ZEMPLOYEE table entries after MODIFY

Since there was no entry with the key 6, a new entry was added to the table.

DATA: gwa_employee TYPE zemployee.


gwa_employee-id = 6.
gwa_employee-name = 'JOHNNY'.
gwa_employee-place = 'LONDON'.
gwa_employee-phone = '7897897890'.
gwa_employee-dept_id = 3.
MODIFY zemployee FROM gwa_employee.

Since there was an entry with the key 6, the values in the existing record were modified

Prepared by PEERS TECHNOLOGIES PVT LTD, HYDERABAD Page 33


PEERS – SAP ABAP
MESSAGES IN ABAP
Messages are usually used to tell the user what is going on. The following types of messages are available in ABAP.

A Termination The message appears in a dialog box, and the program terminates. When the user has
confirmed the message, control returns to the next-highest area menu.

E Error Depending on the program context, an error dialog appears or the program
terminates.

I Status The message appears in a dialog box. Once the user has confirmed the message, the
program continues immediately after the MESSAGE statement.

S Error The program continues normally after the MESSAGE statement, and the message is
displayed in the status bar of the next screen.

W Warning Depending on the program context, an error dialog appears or the program
terminates.

X Exit No message is displayed, and the program terminates with a short dump. Program
terminations with a short dump normally only occur when a runtime error occurs.

The syntax for issuing a message is as follows.

MESSAGE <message> TYPE <message type>.

We can issue a status message as follows. Status message will be displayed in the status bar. After the message is
displayed the program continues after the MESSAGE statement.

MESSAGE 'This is a status message' TYPE 'S'.

Information message will be displayed in a dialog box. Once the user has confirmed the message, the program
continues immediately after the MESSAGE statement.

MESSAGE 'This is an information message' TYPE 'I'.

Error message in report programs will be displayed in the status bar and when the user press enter, the program
terminates.

MESSAGE 'This is an error message' TYPE 'E'.

Prepared by PEERS TECHNOLOGIES PVT LTD, HYDERABAD Page 34


PEERS – SAP ABAP

Warning message behaves similar to error message in report programs.


Exit Message – No message is displayed, and the program terminates with a short dump. Short dumps can be viewed in
t-code ST22.

MESSAGE 'This produces short dump' TYPE 'X'.

Termination Message appears in a dialog box, and the program terminates. When the user has confirmed the message,
control returns to the next-highest area menu.

MESSAGE 'This is termination message' TYPE 'A'.

Instead of hardcode the message text in the program we can maintain the message text in text symbols. In order to
maintain text symbols use the menu path Goto->Text Elements->Text Symbols in ABAP editor.

Prepared by PEERS TECHNOLOGIES PVT LTD, HYDERABAD Page 35


PEERS – SAP ABAP
In the text symbols screen we can maintain the messages with a 3 character identifier.

Then use the following message statement.

MESSAGE text-001 TYPE 'I'.

SAP Message Class

We know that we can use MESSAGE statement to issue a message in ABAP. What if we want to issue the same
message in more than one program? Do we need to hard code the same message text or maintain the same text symbols
in all the programs? The answer is NO. Instead of maintaining the same message text in all the programs maintain the
message in a Message class and use it in all the programs.
What is a Message Class?
Message Class is a like a container which holds a number of different messages. Each message in the message class is
identified with unique message number. So when you call a message in a ABAP program, you need to specify the
message class and message number.
How to create a Message Class?
First go to t-code SE91 i.e. Message Maintenance, enter the name of the message class and click on create button.

Prepared by PEERS TECHNOLOGIES PVT LTD, HYDERABAD Page 36


PEERS – SAP ABAP
Maintain the required message texts with message numbers. Then save the entries and assign it to proper development
class and transport request. Once the message class is saved we can use it in our ABAP programs.

Messages can be issued as follows.

MESSAGE s000(ztest).

Output

In the above code, the message number, message class and message type are specified in the MESSAGE statement.
We can also specify the message class in the REPORT statement as shown below, so that we can skip the message
class in the MESSAGE statements of the program.

REPORT zmessages

MESSAGE-ID ztest

MESSAGE s000.

We can also maintain placeholders for variables in messages.

Prepared by PEERS TECHNOLOGIES PVT LTD, HYDERABAD Page 37


PEERS – SAP ABAP

In the above message ―&‖ is the placeholder. At runtime the placeholders (&) will be replaced by the variable values
specified in the MESSAGE statement.

REPORT zmessages MESSAGE-ID ztest.


MESSAGE s001

WITH ‗XYZ‘ ‘1000′

Output

The values ―XYZ‖ and ―1000‖ replaces the placeholders in the actual message.

ABAP INTERNAL TABLE AND HOW TO CREATE

An Internal table is a temporary table gets created in the memory of application server during program execution and gets
destroyed once the program ends. It is used to hold data temporarily or manipulate the data. It contains one or more rows
with same structure.

An internal table can be defined using the keyword TABLE OF in the DATA statement. Internal table can be defined by
the following ways.

TYPES: BEGIN OF ty_student,


id(5) TYPE n,
name(10) TYPE c,
END OF ty_student.
DATA: gwa_student TYPE ty_student.
"Referring to local data type
DATA: it1 TYPE TABLE OF ty_student.
"Referring to local data object
DATA: it2 LIKE TABLE OF gwa_student.
"Referring to data type in ABAP dictionary
DATA: it3 TYPE TABLE OF mara.

Prepared by PEERS TECHNOLOGIES PVT LTD, HYDERABAD Page 38


PEERS – SAP ABAP
Use the APPEND statement to add data to internal table. First define the work area i.e. define a field string with a
structure similar to row of the internal table. Then place the data in the work area and use the APPEND statement to add
the data from work area to internal table.

*--------------------------------------------------------------*
*Data Types
*--------------------------------------------------------------*
TYPES: BEGIN OF ty_student,
id(5) TYPE n,
name(10) TYPE c,
END OF ty_student.

DATA: gwa_student TYPE ty_student.


*--------------------------------------------------------------*
*Data Declaration
*--------------------------------------------------------------*
"Referring to local data type
DATA: it TYPE TABLE OF ty_student.
gwa_student-id = 1.
gwa_student-name = 'JOHN'.
APPEND gwa_student TO it.
gwa_student-id = 2.
gwa_student-name = 'JIM'.
APPEND gwa_student TO it.
gwa_student-id = 3.
gwa_student-name = 'JACK'.
APPEND gwa_student TO it.

After the last APPEND statement in the above program, internal table ‗IT‘ has the following 3 entries. But the internal table
values are not persistent i.e. the internal table and its values are discarded once the program ends.

ID NAME

1 JOHN

2 JIM

3 JACK

Usually internal tables are used to hold data from database tables temporarily for displaying on the screen or further
processing. To fill the internal table with database values, use SELECT statement to read the records from the database
one by one, place it in the work area and then APPEND the values in the work area to internal table.

DATA: gwa_employee TYPE zemployee,


gt_employee TYPE TABLE OF zemployee.
SELECT * FROM zemployee INTO gwa_employee.
APPEND gwa_employee TO gt_employee.
ENDSELECT.

After ENDSELECT the internal table GT_EMPLOYEE contains all the records that are present in table ZEMPLOYEE.

Using INTO TABLE addition to SELECT statement we can also read multiple records directly into the internal table
directly. No work area used in this case. This select statement will not work in loop, so no ENDSELECT is required.

SELECT * FROM zemployee INTO TABLE gt_employee.

Prepared by PEERS TECHNOLOGIES PVT LTD, HYDERABAD Page 39


PEERS – SAP ABAP
Inserting Lines into ABAP Internal Tables

We can insert one or more lines to ABAP internal tables using the INSERT statement. To insert a single line, first place
the values we want to insert in a work area and use the INSERT statement to insert the values in the work area to internal
table.

Syntax to insert a line to internal table

INSERT <work area> INTO TABLE <internal table>.


OR
INSERT <work area> INTO <internal table> INDEX <index>.

The first INSERT statement without INDEX addition will simply add the record to the end of the internal table. But if we
want to insert the line to specific location i.e. if we want to insert it as second record then we need to specify 2 as the
index in the INSERT statement.

*--------------------------------------------------------------*
*Data Types
*--------------------------------------------------------------*
TYPES: BEGIN OF ty_student,
id(5) TYPE n,
name(10) TYPE c,
END OF ty_student.
*--------------------------------------------------------------*
*Data Declaration
*--------------------------------------------------------------*
DATA: gwa_student TYPE ty_student.
DATA: it TYPE TABLE OF ty_student.
gwa_student-id = 1.
gwa_student-name = 'JOHN'.
INSERT gwa_student INTO TABLE it.
gwa_student-id = 2.
gwa_student-name = 'JIM'.
INSERT gwa_student INTO TABLE it.

gwa_student-id = 3.
gwa_student-name = 'JACK'.
INSERT gwa_student INTO TABLE it.

WRITE:/ 'ID' COLOR 5,7 'Name' COLOR 5.


LOOP AT it INTO gwa_student.
WRITE:/ gwa_student-id, gwa_student-name.
ENDLOOP.

SKIP.
WRITE:/ 'After using Index addition' COLOR 4.

gwa_student-id = 4.
gwa_student-name = 'RAM'.
INSERT gwa_student INTO it INDEX 2.

WRITE:/ 'ID' COLOR 5,7 'Name' COLOR 5.


LOOP AT it INTO gwa_student.
WRITE:/ gwa_student-id, gwa_student-name.
ENDLOOP.

Output

Prepared by PEERS TECHNOLOGIES PVT LTD, HYDERABAD Page 40


PEERS – SAP ABAP
We can also insert multiple lines to an internal table with a single INSERT statement i.e. we can insert the lines of one
internal table to another internal table.

Syntax to insert multiple lines to internal table

INSERT LINES OF <itab1> [FROM <index 1>] [TO <index 2>] INTO TABLE <itab2>.
OR
INSERT LINES OF <itab1> [FROM <index 1>] [TO <index 2>] INTO
<itab2> INDEX <index>.
*--------------------------------------------------------------*
*Data Types
*--------------------------------------------------------------*
TYPES: BEGIN OF ty_student,
id(5) TYPE n,
name(10) TYPE c,
END OF ty_student.

*--------------------------------------------------------------*
*Data Declaration
*--------------------------------------------------------------*
DATA: gwa_student TYPE ty_student.
DATA: it TYPE TABLE OF ty_student,
it2 TYPE TABLE OF ty_student,
it3 TYPE TABLE OF ty_student,
it4 TYPE TABLE OF ty_student.

gwa_student-id = 1.
gwa_student-name = 'JOHN'.
INSERT gwa_student INTO TABLE it.

gwa_student-id = 2.
gwa_student-name = 'JIM'.
INSERT gwa_student INTO TABLE it.

gwa_student-id = 3.
gwa_student-name = 'JACK'.
INSERT gwa_student INTO TABLE it.

gwa_student-id = 4.
gwa_student-name = 'ROB'.
INSERT gwa_student INTO TABLE it.

WRITE:/ 'Inserting all the lines of IT to IT2' COLOR 4.

INSERT LINES OF it INTO TABLE it2.

WRITE:/ 'Display values of IT2' COLOR 1.


WRITE:/ 'ID' COLOR 5,7 'Name' COLOR 5.
LOOP AT it2 INTO gwa_student.
WRITE:/ gwa_student-id, gwa_student-name.
ENDLOOP.

SKIP.
WRITE:/ 'Inserting only lines 2 & 3 of IT to IT3' COLOR 4.

INSERT LINES OF it FROM 2 TO 3 INTO TABLE it3.

WRITE:/ 'Display values of IT3' COLOR 1.


WRITE:/ 'ID' COLOR 5,7 'Name' COLOR 5.
LOOP AT it3 INTO gwa_student.
WRITE:/ gwa_student-id, gwa_student-name.
ENDLOOP.

Prepared by PEERS TECHNOLOGIES PVT LTD, HYDERABAD Page 41


PEERS – SAP ABAP
gwa_student-id = 1.
gwa_student-name = 'RAM'.
INSERT gwa_student INTO TABLE it4.

gwa_student-id = 4.
gwa_student-name = 'RAJ'.
INSERT gwa_student INTO TABLE it4.

SKIP.
WRITE:/ 'Inserting only lines 2 & 3 of IT to IT4 at 2' COLOR 4.

INSERT LINES OF it FROM 2 TO 3 INTO it4 INDEX 2.

WRITE:/ 'Display values of it4' COLOR 1.


WRITE:/ 'ID' COLOR 5,7 'Name' COLOR 5.
LOOP AT it4 INTO gwa_student.
WRITE:/ gwa_student-id, gwa_student-name.
ENDLOOP.

The last INSERT statement in the above program inserts the 2nd and 3rd line from IT at index 2 in IT4, so the new lines
inserted becomes the 2nd and 3rd line in IT4.

Output

Changing Lines in ABAP Internal Tables

MODIFY is the statement to change single or multiple lines in an internal table. Use the INDEX addition to change a single
line. If we use the INDEX addition and the operation is successful, SY-SUBRC will be set to zero and the contents of the
work area overwrites the contents of the line with the corresponding index.
Instead of changing all the values of a row we can specify the fields we want to change by specifying the fieldnames in the
TRANSPORTING addition.

MODIFY <internal table> FROM <work area> [INDEX <index>]


[TRANSPORTING <f1> <f2> ... ].

We can also use the above MODIFY statement without INDEX addition inside LOOP. Inside LOOP if we do not specify
the INDEX, then the current loop line will be modified.
We can use the WHERE clause to change single or multiple lines. All the lines that meet the logical condition will be
processed. If at least one line is changed, the system sets SY-SUBRC to 0, otherwise to 4.

MODIFY <internal table> FROM <work area>


TRANSPORTING <f1> <f2> ... WHERE <condition>.
*--------------------------------------------------------------*

Prepared by PEERS TECHNOLOGIES PVT LTD, HYDERABAD Page 42


PEERS – SAP ABAP
*Data Types
*--------------------------------------------------------------*
TYPES: BEGIN OF ty_student,
id(5) TYPE n,
name(10) TYPE c,
place(10) TYPE c,
age TYPE i,
END OF ty_student.

*--------------------------------------------------------------*
*Data Declaration
*--------------------------------------------------------------*
DATA: gwa_student TYPE ty_student.
DATA: it TYPE TABLE OF ty_student.

gwa_student-id = 1.
gwa_student-name = 'JOHN'.
gwa_student-place = 'London'.
gwa_student-age = 20.
INSERT gwa_student INTO TABLE it.

gwa_student-id = 2.
gwa_student-name = 'JIM'.
gwa_student-place = 'New York'.
gwa_student-age = 21.
INSERT gwa_student INTO TABLE it.

gwa_student-id = 3.
gwa_student-name = 'JACK'.
gwa_student-place = 'Bangalore'.
gwa_student-age = 20.
INSERT gwa_student INTO TABLE it.
gwa_student-id = 4.
gwa_student-name = 'ROB'.
gwa_student-place = 'Bangalore'.
gwa_student-age = 22.
INSERT gwa_student INTO TABLE it.

WRITE:/ 'Values in IT before MODIFY' COLOR 4.

WRITE:/ 'ID' COLOR 5,7 'Name' COLOR 5, 18 'Place' COLOR 5,


37 'Age' COLOR 5.
LOOP AT it INTO gwa_student.
WRITE:/ gwa_student-id, gwa_student-name, gwa_student-place,
gwa_student-age.
ENDLOOP.
SKIP.
WRITE:/ 'Values in IT after MODIFY' COLOR 4.
gwa_student-id = 4.
gwa_student-name = 'ROB'.
gwa_student-place = 'Mumbai'.
gwa_student-age = 25.

*Change all the columns of row 4 with work area values


MODIFY it FROM gwa_student INDEX 4.
WRITE:/ 'ID' COLOR 5,7 'Name' COLOR 5, 18 'Place' COLOR 5,
37 'Age' COLOR 5.
LOOP AT it INTO gwa_student.
WRITE:/ gwa_student-id, gwa_student-name, gwa_student-place,
gwa_student-age.
ENDLOOP.
SKIP.

Prepared by PEERS TECHNOLOGIES PVT LTD, HYDERABAD Page 43


PEERS – SAP ABAP
WRITE:/ 'Values in IT after Transporting addition' COLOR 4.

gwa_student-id = 9.
gwa_student-name = 'TOM'.
gwa_student-place = 'Bangalore'.
gwa_student-age = 30.
*Change specific columns of row 4 with work
area values by
*using TRANSPORTING addition
MODIFY it FROM gwa_student INDEX 4
TRANSPORTING place.
WRITE:/ 'ID' COLOR 5,7 'Name' COLOR 5, 18
'Place' COLOR 5,
37 'Age' COLOR 5.
LOOP AT it INTO gwa_student.
WRITE:/ gwa_student-id, gwa_student-name,
gwa_student-place,
gwa_student-age.
ENDLOOP.
SKIP.
WRITE:/ 'Values in IT after MODIFY using
WHERE Clause' COLOR 4.
gwa_student-place = 'Mumbai'.
*Change multiple rows using WHERE clause
MODIFY it FROM gwa_student TRANSPORTING
place
WHERE place =
'Bangalore'.
WRITE:/ 'ID' COLOR 5,7 'Name' COLOR 5, 18
'Place' COLOR 5,
37 'Age' COLOR 5.
LOOP AT it INTO gwa_student.
WRITE:/ gwa_student-id, gwa_student-name,
gwa_student-place,
gwa_student-age.
ENDLOOP.

Output

Deleting Lines from an ABAP Internal Table


DELETE is the statement to delete one or more lines from an ABAP Internal Table. Use the INDEX addition to delete a
single line. If we use the INDEX addition and the operation is successful, SY-SUBRC will be set to zero, the line with the
corresponding index in the internal table will be deleted and the indexes of the subsequent lines will be reduced by one.
DELETE <internal table> [INDEX <index>].

We can also use the above DELETE statement without INDEX addition inside LOOP. Inside LOOP if we do not specify
the INDEX, then the current loop line will be deleted.
We can use the WHERE clause to delete single or multiple lines. All the lines that meet the logical condition will be
deleted. If at least one line is deleted, the system sets SY-SUBRC to 0, otherwise to 4.

DELETE <internal table> [FROM <n1>] [TO <n2>] [WHERE <condition>].

With WHERE clause we can also specify the lines between certain indices that we want to delete by specifying indexes in
FROM and TO additions.

Prepared by PEERS TECHNOLOGIES PVT LTD, HYDERABAD Page 44


PEERS – SAP ABAP
*--------------------------------------------------------------*
*Data Types
*--------------------------------------------------------------*
TYPES: BEGIN OF ty_student,
id(5) TYPE n,
name(10) TYPE c,
place(10) TYPE c,
age TYPE i,
END OF ty_student.
*--------------------------------------------------------------*
*Data Declaration
*--------------------------------------------------------------*
DATA: gwa_student TYPE ty_student.
DATA: it TYPE TABLE OF ty_student.
gwa_student-id = 1.
gwa_student-name = 'JOHN'.
gwa_student-place = 'London'.
gwa_student-age = 20.
INSERT gwa_student INTO TABLE it.
gwa_student-id = 2.
gwa_student-name = 'JIM'.
gwa_student-place = 'New York'.
gwa_student-age = 21.

INSERT gwa_student INTO TABLE it.


gwa_student-id = 3.
gwa_student-name = 'JACK'.
gwa_student-place = 'Bangalore'.
gwa_student-age = 20.
INSERT gwa_student INTO TABLE it.
gwa_student-id = 4.
gwa_student-name = 'ROB'.
gwa_student-place = 'Bangalore'.
gwa_student-age = 22.
INSERT gwa_student INTO TABLE it.
WRITE:/ 'Values in IT before DELETE' COLOR 4.
WRITE:/ 'ID' COLOR 5,7 'Name' COLOR 5, 18
'Place' COLOR 5,
37 'Age' COLOR 5.
LOOP AT it INTO gwa_student.
WRITE:/ gwa_student-id, gwa_student-name,
gwa_student-place,
gwa_student-age.
ENDLOOP.
SKIP.
WRITE:/ 'Values in IT after DELETE' COLOR 4.
*Delete second line from IT
DELETE it INDEX 2.
WRITE:/ 'ID' COLOR 5,7 'Name' COLOR 5, 18
'Place' COLOR 5,
37 'Age' COLOR 5.
LOOP AT it INTO gwa_student.
WRITE:/ gwa_student-id, gwa_student-name,
gwa_student-place, gwa_student-age.
ENDLOOP.
SKIP.
WRITE:/ 'Values in IT after DELETE using WHERE
Clause' COLOR 4.
*Delete entries from IT where place is
Bangalore
DELETE it WHERE place = 'Bangalore'.

Prepared by PEERS TECHNOLOGIES PVT LTD, HYDERABAD Page 45


PEERS – SAP ABAP
WRITE:/ 'ID' COLOR 5,7 'Name' COLOR 5, 18 'Place' COLOR 5, 37 'Age' COLOR 5.
LOOP AT it INTO gwa_student.
WRITE:/ gwa_student-id, gwa_student-name, gwa_student-place,
gwa_student-age.
ENDLOOP.
Output

More on ABAP Internal Tables


DESCRIBE TABLE is the statement to get the attributes like number of lines, line width of each row etc. of the internal
table. DESCRIBE TABLE statement also fills the system fields SY-TFILL (Current no. of lines in internal table), SY-
TLENG (line width of internal table) etc.

DESCRIBE TABLE <internal table> [LINES <lines>].

SORT is the statement to sort an ABAP internal table. We can specify the direction of the sort using the additions
ASCENDING and DESCENDING. The default is ascending.

SORT <internal table> [ASCENDING|DESCENDING]

We can also delete the adjacent duplicates from an internal table by using the following statement.

DELETE ADJACENT DUPLICATE ENTRIES FROM <internal table>


[COMPARING <f1> <f2> ... |ALL FIELDS].

COMPARING ALL FIELDS is the default. If we do not specify the COMPARING addition, then the system compares all
the fields of both the lines. If we specify fields in the COMPARING clause, then the system compares only the fields
specified after COMPARING of both the lines. If at least one line is deleted, the system sets SY-SUBRC to 0, otherwise to
4.
*--------------------------------------------------------------*
*Data Types
*--------------------------------------------------------------*
TYPES: BEGIN OF ty_student,
id(5) TYPE n,
name(10) TYPE c,
place(10) TYPE c,
age TYPE i,
END OF ty_student.

*--------------------------------------------------------------*
*Data Declaration
*--------------------------------------------------------------*
DATA: gwa_student TYPE ty_student.
DATA: it TYPE TABLE OF ty_student.
DATA: gv_lines TYPE i.

gwa_student-id = 1.
gwa_student-name = 'JOHN'.
gwa_student-place = 'London'.
gwa_student-age = 20.
APPEND gwa_student TO it.

gwa_student-id = 2.
gwa_student-name = 'JIM'.
gwa_student-place = 'New York'.
gwa_student-age = 21.
APPEND gwa_student TO it.

Prepared by PEERS TECHNOLOGIES PVT LTD, HYDERABAD Page 46


PEERS – SAP ABAP
gwa_student-id = 3.
gwa_student-name = 'JACK'.
gwa_student-place = 'Bangalore'.
gwa_student-age = 20.
APPEND gwa_student TO it.

gwa_student-id = 4.
gwa_student-name = 'ROB'.
gwa_student-place = 'Bangalore'.
gwa_student-age = 22.
APPEND gwa_student TO it.

gwa_student-id = 2.
gwa_student-name = 'JIM'.
gwa_student-place = 'New York'.
gwa_student-age = 21.
APPEND gwa_student TO it.

DESCRIBE TABLE it LINES gv_lines.


WRITE:/ 'No. of lines in IT : ', gv_lines.

WRITE:/ 'SY-TFILL : ', sy-tfill.


WRITE:/ 'SY-TLENG : ', sy-tleng.

WRITE:/ 'Values in IT before SORT' COLOR 4.

WRITE:/ 'ID' COLOR 5,7 'Name' COLOR 5, 18 'Place' COLOR 5,


37 'Age' COLOR 5.
LOOP AT it INTO gwa_student.
WRITE:/ gwa_student-id, gwa_student-name, gwa_student-place,
gwa_student-age.
ENDLOOP.

WRITE:/ 'Values in IT after SORT' COLOR 4.

*SORT by name
SORT it BY name DESCENDING.

WRITE:/ 'ID' COLOR 5,7 'Name' COLOR 5, 18 'Place' COLOR 5,


37 'Age' COLOR 5.
LOOP AT it INTO gwa_student.
WRITE:/ gwa_student-id, gwa_student-name, gwa_student-place,
gwa_student-age.
ENDLOOP.

WRITE:/ 'Values in IT after deleting duplicates' COLOR 4.

*Delete duplicates
SORT it.
DELETE ADJACENT DUPLICATES FROM it.

WRITE:/ 'ID' COLOR 5,7 'Name' COLOR 5, 18 'Place' COLOR 5,


37 'Age' COLOR 5.
LOOP AT it INTO gwa_student.
WRITE:/ gwa_student-id, gwa_student-name, gwa_student-place,
gwa_student-age.
ENDLOOP.

WRITE:/ 'Values in IT after deleting duplicates comparing place' COLOR 4.

*Delete duplicates comparing only place

Prepared by PEERS TECHNOLOGIES PVT LTD, HYDERABAD Page 47


PEERS – SAP ABAP
SORT it BY place.
DELETE ADJACENT DUPLICATES FROM it COMPARING place.

WRITE:/ 'ID' COLOR 5,7 'Name' COLOR 5, 18 'Place' COLOR 5,


37 'Age' COLOR 5.
LOOP AT it INTO gwa_student.
WRITE:/ gwa_student-id, gwa_student-name, gwa_student-place,
gwa_student-age.
ENDLOOP.

Output

We can exit out of LOOP/ENDLOOP processing using EXIT, CONTINUE and CHECK similar to all other LOOPS.
We can also initialize the internal table using FREE, CLEAR and REFRESH statements. CLEAR and REFRESH just
initializes the internal table where as FREE initializes the internal table and releases the memory space.

*--------------------------------------------------------------*
*Data Types
*--------------------------------------------------------------*
TYPES: BEGIN OF ty_student,
id(5) TYPE n,
name(10) TYPE c,
place(10) TYPE c,
age TYPE i,
END OF ty_student.
*--------------------------------------------------------------*
*Data Declaration
*--------------------------------------------------------------*
DATA: gwa_student TYPE ty_student.
DATA: it TYPE TABLE OF ty_student.
DATA: gv_lines TYPE i.

Prepared by PEERS TECHNOLOGIES PVT LTD, HYDERABAD Page 48


PEERS – SAP ABAP
gwa_student-id = 1.
gwa_student-name = 'JOHN'.
gwa_student-place = 'London'.
gwa_student-age = 20.
APPEND gwa_student TO it.

gwa_student-id = 2.
gwa_student-name = 'JIM'.
gwa_student-place = 'New York'.
gwa_student-age = 21.
APPEND gwa_student TO it.

WRITE:/ 'Values in IT before initializing' COLOR 4.

WRITE:/ 'ID' COLOR 5,7 'Name' COLOR 5, 18 'Place' COLOR 5,


37 'Age' COLOR 5.
LOOP AT it INTO gwa_student.
WRITE:/ gwa_student-id, gwa_student-name, gwa_student-place,
gwa_student-age.
ENDLOOP.

*Initialize IT
CLEAR it.
SKIP.
WRITE:/ 'Values in IT before initializing' COLOR 4.
WRITE:/ 'ID' COLOR 5,7 'Name' COLOR 5, 18 'Place' COLOR 5,
37 'Age' COLOR 5.
LOOP AT it INTO gwa_student.
WRITE:/ gwa_student-id, gwa_student-name, gwa_student-place,
gwa_student-age.
ENDLOOP.
*If no records are processed inside LOOP, then SY-SUBRC <> 0
IF sy-subrc <> 0.
WRITE:/ 'No records found.'.
ENDIF.

SKIP.
*We can also use IS INITIAL to check any records found in IT
IF it IS INITIAL.
WRITE:/ 'No records found in IT.'.
ENDIF.

Output

Control Break Processing in ABAP Internal Tables

Prepared by PEERS TECHNOLOGIES PVT LTD, HYDERABAD Page 49


PEERS – SAP ABAP
Control break processing is used to execute a piece of code whenever a specific condition in the data is detected during
the processing of internal table loop.
The following control break statements are available with in LOOP and ENDLOOP.
 AT FIRST / ENDAT
 AT LAST / ENDAT
 AT NEW / ENDAT
 AT END OF / ENDAT
 SUM
 ON CHANGE OF / ENDON
The code between AT NEW and ENDAT is executed only during the first loop pass. So it is used to write the headers or
some other initialization processing.

The code between AT LAST and ENDAT is executed only during the last loop pass. So it is used to write the totals or
some report footers.

*————————————————————–* *Data Declaration *————————————————————–*


DATA: gwa_spfli TYPE spfli.
DATA: gt_spfli TYPE TABLE OF spfli.

*UP TO 5 ROWS addition selects only 5 rows from table SPFLI


SELECT * UP TO 5 ROWS FROM spfli INTO TABLE gt_spfli.
LOOP AT gt_spfli INTO gwa_spfli.

AT FIRST.
WRITE:/ 'Start of Loop'.
WRITE:/ 'Flight Details'.
WRITE:/ 'Airline Code' COLOR 5,14 'Connection No.' COLOR 5,
29 'Departure City' COLOR 5, 44 'Arival City' COLOR 5.
ULINE.

ENDAT.
WRITE:/ gwa_spfli-carrid,14 gwa_spfli-connid,
29 gwa_spfli-cityfrom,44 gwa_spfli-cityto.

AT LAST.
ULINE.
WRITE:/ 'End of Loop'.

ENDAT.

ENDLOOP.

Output

Between AT FIRST and ENDAT the work area will not contain any data. The default key fields are filled with asterisks(*)
and the numeric fields are filled with zeros. The ENDAT restores the contents to the values they had prior to entering the
AT FIRST. Changes to the work area within AT FIRST and ENDAT are lost. The same applies for AT LAST and ENDAT.

Prepared by PEERS TECHNOLOGIES PVT LTD, HYDERABAD Page 50


PEERS – SAP ABAP
*————————————————————–* *Data Declaration *————————————————————–*
DATA: gwa_spfli TYPE spfli.
DATA: gt_spfli TYPE TABLE OF spfli.

*UP TO 5 ROWS addition selects only 5 rows from table SPFLI


SELECT * UP TO 5 ROWS FROM spfli INTO TABLE gt_spfli.
LOOP AT gt_spfli INTO gwa_spfli.
AT FIRST.
WRITE:/ 'Flight Details'.
WRITE:/ 'Airline Code' COLOR 5,14 'Connection No.' COLOR 5,
29 'Departure City' COLOR 5, 44 'Arival City' COLOR 5,
58 'Distance' COLOR 5.

WRITE:/ gwa_spfli-carrid,14 gwa_spfli-connid, 29 gwa_spfli-cityfrom,44 gwa_spfli-cityto, 58 gwa_spfli-distance.


ULINE.
ENDAT.
WRITE:/ gwa_spfli-carrid,14 gwa_spfli-connid,
29 gwa_spfli-cityfrom,44 gwa_spfli-cityto,
58 gwa_spfli-distance.
AT LAST.
ULINE.

WRITE:/ gwa_spfli-carrid,14 gwa_spfli-connid, 29 gwa_spfli-cityfrom,44 gwa_spfli-cityto, 58 gwa_spfli-distance.


WRITE:/ 'End of Loop'.
ENDAT.
ENDLOOP.

Output

AT NEW and ENDAT is used to detect a change in the value of the field between the loop passes. The field that is
specified in AT NEW is called control level. The code between AT NEW and ENDAT will be executed during the first loop
pass and every time the value of the control level changes or any other field left to the control level changes. Between AT
NEW and ENDAT all the fields in the work area that are right to the control level are filled with zeros and asterisks.

Similarly The code between AT END OF and ENDAT will be executed during the last loop pass and every time the value
of the control level changes or any other field left to the control level changes.

*————————————————————–* *Data Declaration *————————————————————–*


DATA: gwa_spfli TYPE spfli.
DATA: gt_spfli TYPE TABLE OF spfli.
SELECT * UP TO 5 ROWS FROM spfli INTO TABLE gt_spfli.
LOOP AT gt_spfli INTO gwa_spfli.
AT FIRST.
WRITE:/ 'Flight Details'.
WRITE:/ 'Airline Code' COLOR 5,14 'Connection No.' COLOR 5,
29 'Departure City' COLOR 5, 44 'Arival City' COLOR 5,
58 'Distance' COLOR 5.
ULINE.
ENDAT.

AT NEW carrid. WRITE:/ gwa_spfli-carrid, ‗ : New Airline‘. ULINE. ENDAT.

Prepared by PEERS TECHNOLOGIES PVT LTD, HYDERABAD Page 51


PEERS – SAP ABAP
WRITE:/14 gwa_spfli-connid,
29 gwa_spfli-cityfrom,44 gwa_spfli-cityto,
58 gwa_spfli-distance.

AT END OF carrid. ULINE. WRITE:/ ‗End of Airline : ‗, gwa_spfli-carrid. ULINE. ENDAT.


AT LAST.
WRITE:/ 'End of Loop'.
ENDAT.
ENDLOOP.

Output

Control Break Processing in ABAP Internal Tables Continued


In AT FIRST and AT LAST event blocks the numeric values in the work area contains zeros. SUM statement calculates
the totals of numeric fields and places the totals in the corresponding fields of work area.

In AT NEW and AT END OF event blocks SUM statement finds all the rows within the control level and calculates the
totals of numeric fields that are right to the control level and places the totals in the corresponding fields of work area.

*————————————————————–* *Data Declaration *————————————————————–*


DATA: gwa_spfli TYPE spfli.
DATA: gt_spfli TYPE TABLE OF spfli.

SELECT * UP TO 5 ROWS FROM spfli INTO TABLE gt_spfli.

LOOP AT gt_spfli INTO gwa_spfli.


AT FIRST.
WRITE:/ 'Flight Details'.
WRITE:/ 'Airline Code' COLOR 5,14 'Connection No.' COLOR 5,
29 'Departure City' COLOR 5, 44 'Arival City' COLOR 5,
58 'Distance' COLOR 5.
ULINE.
ENDAT.
AT NEW carrid.
WRITE:/ gwa_spfli-carrid, ' : New Airline'.
ULINE.
ENDAT.
WRITE:/14 gwa_spfli-connid,29 gwa_spfli-cityfrom,
44 gwa_spfli-cityto,58 gwa_spfli-distance.
AT END OF carrid.
ULINE.

Prepared by PEERS TECHNOLOGIES PVT LTD, HYDERABAD Page 52


PEERS – SAP ABAP
SUM.
WRITE:/ gwa_spfli-carrid,58 gwa_spfli-distance.
ULINE.
ENDAT.
AT LAST.

SUM.
WRITE:/ 'Total',58 gwa_spfli-distance.
WRITE:/ 'End of Loop'.
ENDAT.
ENDLOOP.

Output

ON CHANGE OF behaves similar to AT NEW. The syntax is as follows.

ON CHANGE OF <control level1> [or <control level2> . .].


[ELSE.]
ENDON.

*————————————————————–* *Data Declaration *————————————————————–*


DATA: gwa_spfli TYPE spfli.
DATA: gt_spfli TYPE TABLE OF spfli.

SELECT * UP TO 5 ROWS FROM spfli INTO TABLE gt_spfli.

LOOP AT gt_spfli INTO gwa_spfli.


AT FIRST.
WRITE:/ 'Flight Details'.
WRITE:/ 'Airline Code' COLOR 5,14 'Connection No.' COLOR 5,
29 'Departure City' COLOR 5, 44 'Arival City' COLOR 5,
58 'Distance' COLOR 5.
ULINE.
ENDAT.

ON CHANGE OF gwa_spfli-carrid. WRITE:/ gwa_spfli-carrid, ‗ : New Airline‘. ULINE. ENDON.


WRITE:/14 gwa_spfli-connid,29 gwa_spfli-cityfrom,
44 gwa_spfli-cityto,58 gwa_spfli-distance.

Prepared by PEERS TECHNOLOGIES PVT LTD, HYDERABAD Page 53


PEERS – SAP ABAP
ENDLOOP.

Output

Below table summarizes the differences between AT NEW and ON CHANGE OF statements.

AT NEW ON CHANGE OF

It can be used only in AT LOOP It can be used in any loop like


statement. SELECT, DO etc..

Only one control field can be Multiple control fields separated


used. by OR can be used.

AT NEW is triggered when a field ON CHANGE OF is not triggered


left to control level changes. when a field left to control level
changes.

Values in the fields to the right of Values in the fields to the right of
control level contains asterisks control level contains original
and zeros. values.

ELSE addition cannot be used. ELSE addition can be used.

Changes to work area with AT Changes to work area with ON


NEW will be lost. CHANGE OF will not be lost.
Example Tables: following tables are used in most of the database-table related examples.

MODULARIZATION IN ABAP
Modularization is breaking down the application code into smaller units, so that it is easy to maintain. Suppose if we want
to implement the same logic like adding two numbers in several places of the same program, then write the logic inside a
modularization unit and call the modularization unit where ever we want to add two numbers.

Even if we want to declare the same variables in multiple programs or use the same logic in different programs then code
the common part in the modularization unit and use it in different programs.

Advantages of Modularization are as follows.


 Easier to read, maintain and debug.
 Eliminates redundancy of code and increases reusability of code .
Different types of Modularization units called from ABAP programs.

Prepared by PEERS TECHNOLOGIES PVT LTD, HYDERABAD Page 54


PEERS – SAP ABAP
 Macros – If you want to reuse the same set of statements more than once in a program, you can include them in a macro.
You can only use a macro within the program in which it is defined.
 Include Programs – Include programs allow you to use the same source code in different programs. They are mainly
used for modularizing source code and have no parameter interface.
 Subroutines – Subroutines are normally called internally i.e. called from the same program in which it is declared. But
subroutines can also be called from external programs.
 Function Modules – Function Modules are stored in the central library and can be called from any program. Even the
function modules(RFC enabled) can be called from non-SAP systems.
 Methods – Methods used ABAP object oriented programming
Different types of Modularization units called from ABAP runtime.
 Event Blocks – Event blocks begin with a event code and ends with next processing block.
 Dialog Modules – Dialog Modules are used in PBO and PAI events of Module Pool programs.

ABAP Macros

If we want to reuse the same set of statements more than once in a program, we can include them in a macro. We can
only use a macro within the program in which it is defined. Macro definition should occur before the macro is used in the
program.

We can use the following syntax to define a macro.

DEFINE <macro name>.

...

END-OF-DEFINITION.

Demo program using Macro.

*Macro definition
DEFINE print.
write:/ 'Hello Macro'.
END-OF-DEFINITION.

WRITE:/ 'Before Using Macro'.


print.

Output

We can pass up to 9 placeholders to Macros.

Prepared by PEERS TECHNOLOGIES PVT LTD, HYDERABAD Page 55


PEERS – SAP ABAP
*Macro definition
DEFINE print.
write:/ 'Hello', &1, &2.
END-OF-DEFINITION.

WRITE:/ 'Before Using Macro'.


print 'ABAP' 'Macros'.

Output

ABAP Include Program

Include programs are not standalone programs and cannot be executed independently. They can be used as a container
for ABAP source code. They are used to organize the ABAP source code into small editable units which can be inserted
at any place in other ABAP programs using the INCLUDE statement. Include programs can be used in different programs.
The include statement copies the contents of the include program into the main program.

Include programs have no parameter interface and they cannot call themselves.

While creating the INCLUDE program using the ABAP editor choose program type as "I" i.e. INCLUDE program in the
program attributes.

Prepared by PEERS TECHNOLOGIES PVT LTD, HYDERABAD Page 56


PEERS – SAP ABAP

Syntax for Include program is as follows.

INCLUDE <Include Program Name>

Source code of ZINCLUDE_DATA.

DATA: g_name(10) TYPE c.

Source code of ZINCLUDE_WRITE.

WRITE:/ 'Inside include program'.

Source code of main program.

REPORT zmain_program.

INCLUDE zinclude_data.

Prepared by PEERS TECHNOLOGIES PVT LTD, HYDERABAD Page 57


PEERS – SAP ABAP

WRITE:/ 'Main Program'.

INCLUDE zinclude_write.

Output

ABAP Subroutine

Subroutines are procedures that we define in an ABAP program and can be called from any program. Subroutines are
normally called internally, i.e. called from the same program in which it is defined. But it is also possible to call a
subroutine from an external program. Subroutines cannot be nested and are usually defined at the end of the program.

A subroutine can be defined using FORM and ENDFORM statements.

FORM <subroutine name>.

...

ENDFORM.

A subroutine can be called using PERFORM statement.

PERFORM <subroutine name>.

Example Program.

PERFORM sub_display.

WRITE:/ 'After Perform'.

*&---------------------------------------------------------------------*
*& Form sub_display
*&---------------------------------------------------------------------*
FORM sub_display.
WRITE:/ 'Inside Subroutine'.
ENDFORM. " sub_display

Output

Prepared by PEERS TECHNOLOGIES PVT LTD, HYDERABAD Page 58


PEERS – SAP ABAP

Subroutines can call other subroutines and may also call themselves. Once a subroutine has finished running, the control
returns to the next statement after the PERFORM statement.

We can terminate a subroutine by using the EXIT or CHECK statement.

EXIT statement can be used to terminate a subroutine unconditionally. The control returns to the next statement after the
PERFORM statement.

PERFORM sub_display.

WRITE:/ 'After Perform Statement'.

*&---------------------------------------------------------------------*
*& Form sub_display
*&---------------------------------------------------------------------*
FORM sub_display.
WRITE:/ 'Before Exit Statement'.
EXIT.
WRITE:/ 'After Exit Statement'. " This will not be executed
ENDFORM. " sub_display

Output

CHECK statement can be used to terminate a subroutine conditionally. If the logical expression in the CHECK statement
is untrue, the subroutine is terminated, and the control returns to the next statement after the PERFORM statement.

DATA: flag TYPE c.

DO 2 TIMES.

PERFORM sub_display.

ENDDO.

Prepared by PEERS TECHNOLOGIES PVT LTD, HYDERABAD Page 59


PEERS – SAP ABAP
WRITE:/ 'After Perform Statement'.

*&---------------------------------------------------------------------*
*& Form sub_display
*&---------------------------------------------------------------------*
FORM sub_display.
WRITE:/ 'Before Check Statement'.

CHECK flag NE 'X'.


WRITE:/ 'Check Passed'.
flag = 'X'.
ENDFORM. " sub_display

Output

ABAP LAB - GUIDE

Prepared by PEERS TECHNOLOGIES PVT LTD, HYDERABAD Page 60


PEERS – SAP ABAP
Example Tables: following tables are used in most of the database-table related examples

Table: KNA1

Desc: Customer master

Field Name Field Description


1 Customer number
KUNNR
2 NAME1 Customer name
3 LAND1 Country
4 ORT01 City

Table: VBAK

Desc: Sales order header

Field Name Field Description


1 Sales order number
VBELN
2 ERDAT Order date
3 NETWR Net value
4 KUNNR Customer number

Table: VBAP

Desc: Sales order details

Field Name Field Description


1 Item number
POSNR
2 ARKTX Item description
3 WERKS Plant code
4 VBELN Order number

Transaction codes:

following transaction codes(T.Code) are used to carry out various tasks:

T.Code Transaction details


SE10 Transport organizer
SE11 ABAP dictionary
SE12
SE13 ABAP dictionary [technical settings]
SE14 ABAP dictionary [database utility]
SE15 Object navigator
SE16 Data browser
SE17 General table display

Prepared by PEERS TECHNOLOGIES PVT LTD, HYDERABAD Page 61


PEERS – SAP ABAP
SE18 Business add-ins [initial definition maintenance screen]
SE19 Business add-ins [initial implementation screen]
SE21 Package builder [initial screen]

SE24 Class builder


SE25
SE29 Application packets
SE30 ABAP runtime analysis
SE32 SAP R/3
SE33 Context builder
SE35 Maintain dialog modules
SE36 Logical database builder
SE37 Function builder
SE38 ABAP editor
SE39 ABAP split screen editor
SE40 Menu painter
SE41
SE43 Area menu maintenance
SE48 Call history
SE49 Program analysis
SE51 Screen painter
SE53 General table maintenance dialog
SE54
SE55
SE56
SE57
SE61 Document maintenance
SE71 Form painter [NACE]
SE72 Style
SE73 SAP script font maintenance
SE74 SAP script format conversion
SE75 SAP script setting
SE76 SAP script form translation
SE77 SAP script style conversion
SE78 SAP script graphics management
SE80 Object navigator
SE81 Application hierarchy
SE82 Create application hierarchy
SE83 Display reuse library
SE84 R/3 repository info
SE15
SE89 R/3 repository info maintain tree display
SE91 Message maintenance
SE92 System log message maintenance
SE93 Maintain transaction
SE94 Simulation: customer (enhancement to SE38)
SE95 Modification browser
SE97 Maintain transaction: call authorixation in CALL TRANSACTION

Prepared by PEERS TECHNOLOGIES PVT LTD, HYDERABAD Page 62


PEERS – SAP ABAP
NACE To modify existing standard layout
SQ01 SAP Queries
SQ02
SQ03
VA01 Sales & distribution
VA03

(1a) FUNCTION – Creation

Steps Action
1 SE37 (transaction code for Function-Builder)
2 On menu-bar , GoTo  FunctionGroup  CreateGroup
3 Function Group: ZmyGRP (give any name)
Short Description: my function group (enter any text)
4 click on continue(tick-mark)
5
LocalObject
6 Function Module: ZmyFUNC (give any name)
7 Create
8 Function Module: ZmyFUNC [see step-6]
Function Group: ZmyGRP [see step-3]
Short Description: my sample function (enter any text)
9 Save
** Import (TAB):
10 IMPORT(TAB)
Parameter names type associated type
X type i
Y type i
** Export (TAB):
11 EXPORT(TAB)
Parameter names type associated type
Z type i
** Source code (TAB):
12 SOURCE CODE(TAB)
…Enter the logic…
z = x + y.
13 Save , Check , Activate , Continue , Execute
14 Enter test data values for x , y
15 Execute
(1b) FUNCTION– Creation (WITH EXCEPTION)

Steps Action
1 SE37 (transaction code for Function-Builder)
2 On menu-bar , GoTo  FunctionGroup  CreateGroup
3 Function Group: ZmyGRP (give any name)
Short Description: my function group (give any description)
4 click on continue (tick-mark)
5 LocalObject
6 Function Module: ZmyFUNC (give any name)
7 Create
8 Function Module: ZmyFUNC, [see step-6]

Prepared by PEERS TECHNOLOGIES PVT LTD, HYDERABAD Page 63


PEERS – SAP ABAP
Function Group: ZmyGRP [see step-3]
Short Description: my sample function (enter any text)
9 Save
** Import (TAB):
10 IMPORT(TAB)
Parameter names type associated type
X type i
Y type i
** Export (TAB):
11 EXPORT(TAB)
Parameter names type associated type
Z type i
** Exception (TAB):
12 EXCEPTION(TAB)
Exception short description
MyException1 divide by zero
** Source code (TAB):
13 SOURCE CODE(TAB)
if y = 0.
Raise MyException1.
Else.
Z = x / y.
Endif.
14 Save , Check , Activate , Continue , Execute
15 Enter test data for x , y
16 Execute
FUNCTION – Call (1a, 1b)

Steps Action
1 SE38 (transaction code for ABAP editor)
2 Program name: ZmyCallFunc (give any name)
3 Type: Executable Program
4 Save , LocalObject
5 Data: a type i, b type i, c type i.
(or)
Parameters: a type i, b type i.
Data: c type i.
a = 10. b = 5.
6 Place cursor where call-function code to be inserted.
Click on ‘Pattern’ to generate codes.
(select function name: ZmyFunc) *see ‘Function with exception’ step-6]
7 Continue
8 Exporting
X = a
Y = b
Importing
Z = c.
Write: / c.
9 Save , check, activate, Execute
(2a) FUNCTION – Creation (WITH TABLES)
Steps Action

Prepared by PEERS TECHNOLOGIES PVT LTD, HYDERABAD Page 64


PEERS – SAP ABAP
1 SE37 (transaction code for Function-Builder)
2 On menu-bar , GoTo  FunctionGroup  CreateGroup
3 Function Group: ZmyGrp (enter any name)
Short Description: my function group (enter any text)
4 click on (tick-mark)
5 LocalObject
6 Function module: ZmyFunc (give any name)
7 Create
8 Function Module: ZmyFunc [see step-6]
Function Group: ZmyGrp [see step-3]
Short Description: my sample function (enter any text)
9 Save
** Import (TAB):
10 IMPORT(TAB)
Parameter names type associated type
custno type KNA1-kunnr
** Tables (TAB):
11 TABLES(TAB)
Parameter names type associated type
ITAB like KNA1
** Source code (TAB):
12 SOURCE CODE(TAB)
…Enter the logic…
select * from KNA1 into table ITAB
where kunnr = custno.
13 Save , check, activate, continue, Execute
14 Enter test data values for custno [see step-10]
15 Execute
FUNCTION – Call (2a)

Steps Action
1 SE38 (transaction code for ABAP editor)
2 Program name: ZmyCallFunc
3 Type: Executable Program
4 Save, enter the following source codes
5 Tables: KNA1.
Data: cno type KNA1-kunnr.
Data: intab type KNA1 occurs 1 with header line.
cno = ‘1000’.
6 Click on ‘Pattern’ to generate function code at cursor position (select Function Name:
ZmyFunc) *see ‘Function with tables’ step-6]
7 Click on Continue (tick mark)
8 Exporting
custno = cno.
Tables
ITAB = intab.
Loop at intab.
Write: / intab-kunnr.
Endloop.
9 Save , check, activate, Execute

Prepared by PEERS TECHNOLOGIES PVT LTD, HYDERABAD Page 65


PEERS – SAP ABAP
DOCUMENT (SCRIPT/FORM)

Script: script in SAP is known as Document.


SAP bussiness documents (Examples):

A) SALES ORDER
b) invoice

c) bill

d) purchase order
e) debit memo

f) credit memo

etc.

DESIGN AND PRINTING OF SAP BUSINESS DOCUMENTS:

PRINT

PROGRAM

Database

Every business documents consists of following 2 components:


 layout (template)
 print program.

(Note: in general enterprise business more than 200+ business documents are used.)

Prepared by PEERS TECHNOLOGIES PVT LTD, HYDERABAD Page 66


PEERS – SAP ABAP
SAP has identified most commonly used business documents and provided standard layouts and print programs for
them in the system.

Role of ABAP developer:

 80% : to modify existing layouts and print programs.


 20% : to develop new layouts and print programs.

Methods to generate SAP business documents:

 sapscripts (traditional method)


 smart forms (available since release 4.6c onwards)

ABAPer’s tasks:

 to develop new layout and print program.


 to modify existing layout.

FORM - Creation (using ‘SAP-SCRIPT’) (similar to mail-merge)

(NOTE: need to specify window sizes.)

Create Windows:
 LOGO
 HEADER
 ADDRESS
 MAIN (default )
 FOOTER

Steps Action
1 SE71 (transaction code for Form-Painter)
2 Form: ZmySapScriptFORM (enter any name)
3 Create, Continue (tick mark) in pop up box
4 Description: my form (enter any text)
Translate: (Select radio-button) ‘Do not Translate’
5 Save, LocalObject
6 Click ‘Pages’ button (F6)
7 Page: Mypage (give any name)
8 Save
9 Next page: Mypage [see step-7]
Description: my page (enter any text)
** Pages: Create Windows:
10 Click on ‘Windows’ button (F7)
11 MAIN is default window
12 on menu-bar, EDIT  CreateElement (or) (Shift+F6)
13 (Pop-up box to create LOGO window)
Window: LOGO

Prepared by PEERS TECHNOLOGIES PVT LTD, HYDERABAD Page 67


PEERS – SAP ABAP
Description: logo window (enter any text)
Click on Continue(tick mark)
14 on menu-bar, EDIT  CreateElement (or) (Shift+F6)
15 (Pop-up box to create HEADER window)
Window: HEADER
Description: header window (enter any text)
Click on Continue(tick mark)
16 on menu-bar, EDIT  CreateElement (or) (Shift+F6)
17 (Pop-up box to create FOOTER window)
Window: FOOTER
Description: footer window (enter any text)
Click on Continue(tick mark)
18 on menu-bar, EDIT  CreateElement (or) (Shift+F6)
19 (Pop-up box to create ADDRESS window)
Window: ADDRESS
Description: address window (enter any text)
Click on Continue(tick mark)
** PageWindows: Define Window size:
20 Click ‘Page Windows’ button in the top Tool-bar
21 on menu-bar, EDIT  CreateElement (or) (Shift+F6)
22 Dbl .click on ‘LOGO’ in the windows list box (or) select & rt-click  choose (or) F2
23 (Define dimensions in the lower panel)
Left margin : 1 cm width: 3 cm
Upper margin: 1 cm height:3 cm
24 on menu-bar, EDIT  CreateElement (or) (Shift+F6)
25 Dbl .click on ‘HEADER’ in the windows list box (or) select & rt-click  choose (or) F2
26 (Define dimensions in lower panel)
Left margin : 5 cm width: 14 cm
Upper margin: 1 cm height: 3 cm
27 on menu-bar, EDIT  CreateElement (or) (Shift+F6)
28 Dbl .click on ‘ADDRESS’ in the windows list box (or) select & rt-click  choose (or) F2
29 (Define dimensions in the lower panel)
Left margin : 1 cm width: 5 cm
Upper margin: 5 cm height:5 cm
30 on menu-bar, EDIT  CreateElement (or) (Shift+F6)
31 Dbl .click on ‘MAIN’ in the windows list box (or) select & rt-click  choose (or) F2
32 (Define dimensions in the lower panel)
Left margin : 2 cm width: 17 cm
Upper margin: 11 cm height:15 cm
33 on menu-bar, EDIT  CreateElement (or) (Shift+F6)
34 Dbl .click on ‘FOOTER’ in the windows list box (or) select & rt-click  choose (or) F2
35 (Define dimensions in the lower panel)
Left margin : 1 cm width: 17 cm
Upper margin: 26 cm height: 2 cm
36 Save
** Create Paragraph-Format:
37 Click on ‘ParagraphFormats’ button on the top tool-bar
38 Paragraph: P1 (give any name)
39 Save
40 Descript.: my paragraph format (enter any description)
(click on ‘Font’ button)

Prepared by PEERS TECHNOLOGIES PVT LTD, HYDERABAD Page 68


PEERS – SAP ABAP
Font size: 18
Family: Arabic simplified (click inside the textBox and select a Fontfamily from the list)
Radio buttons: BOLD, ITALIC, UNDERLINED (select [On, Off, Retain] as per your choice)
** Create Character-Format:
41 Click on ‘CharacterFormats’ button on the top tool-bar
42 Character Format: C1 (give any name)
Save
Descript.: my character format (enter any description)
Font size: 18
Family: Arabic simplified (click inside the textBox and select a Fontfamily from the list)
Radio buttons: BOLD, ITALIC, UNDERLINED (select [On, Off, Retain] as per your choice)
43 Save
44 On menu-bar, GOTO  HEADER (or F5)
45 Click on ‘BasicSettings’ button
46 First page: Mypage [see step-7] (or select from List-box)
Default paragraph: P1 [see step-37]
47 Save
** define Window Contents:
48 Click on ‘PageWindows’ button
49 Dbl.click on ‘LOGO’ in the windows list box (or) select & rt-click  choose (or) F2
50 Click on ‘TextElements’ icon on top tool-bar (F9)
51 On menu-bar: INSERT  GRAPHICS
52 (NOTE: select any image to appear in the Logo window)

‘Stored On Document Server’ (TAB)


Select radio-button, ‘Color Bitmap Image’
Name: ENJOY (click inside the textBox and select an image, e.g ‘ENJOY’)

NOTE: in the ‘Name’ box, click icon at the right corner. Click on ‘Execute’(F8) to list out the
bitmap image names. Select any image. e.g. ‘ENJOY’. Click on ‘Copy’ (tick mark)

Resolution: 100 (DPI=dots per inch)

Continue(tick-mark)
53 Back(F3)
54 Dbl.click on ‘HEADER’ in the windows list box (or) select & rt-click  choose (or) F2
55 Click on ‘Text Elements’ icon on top tool-bar (or F9)
56 (NOTE: write any text to appear in the header line e.g.)

MY Software Solutions Inc. USA


57 Back( F3)
58 Dbl.click on ‘ADDRESS’ in the windows list box (or) select & rt-click  choose (or) F2
59 Click on ‘Text Elements’ icon on top tools-bar (or F9)
60 (NOTE: write any text to appear in the address line. Get data from KNA1 table fields)

To, &KNA1-kunnr& &KNA1-name1& &KNA1-ort01&


61 Back(F3)
62 Dbl.click on ‘MAIN’ in the windows list box (or) select & rt-click  choose (or) F2
63 Click on ‘Text Elements’ icon on top tools-bar (or F9)
64 (NOTE: write any text to appear in the main body. Get data from KNA1 table fields)

Prepared by PEERS TECHNOLOGIES PVT LTD, HYDERABAD Page 69


PEERS – SAP ABAP
Dear Sir, we received the order from &KNA1-kunnr&
65 Back(F3)
66 Dbl.click on ‘FOOTER’ in the windows list box (or) select & rt-click  choose (or) F2
67 Click on ‘Text Elements’ icon on top tools-bar (or F9)
68 (NOTE: write any text to appear in the footer line)

Our goal is Customer Satisfaction


69 Back(F3)
** check Form definitions, texts , Print-Preview:
70 On menu-bar, FORM  CHECK  DEFINITIONS
71 On menu-bar, FORM  CHECK  TEXTs , continue(tick-mark) in pop-up box
[Note: it may not work for version 4.7]
72 On menu-bar, FORM  ACTIVATE
73 On menu-bar, UTILITIES  TEST PRINT (or TEST PRINTING in ver 4.7)
74 Output device: LP01
75 Click on ‘Print Preview’ (or) F8 [to view the generated Form]

FORM - Creation (using SMARTFORMS) (similar to mail-merge)

(NOTE: use built-in FORM-PAINTER to specify window sizes).


Create Windows:

 LOGO
 MAIN (created by default)
 HEADER
 FOOTER
Steps Action
1 SMARTFORMS (transaction code)
** Create Style:
2 Select radio-button, Style: ZmySmartSTYLE (enter any name)
3 Create
[ Screen divided into Left and Right panels ]
** Define Paragraph-Format:
4 On left-panel, Rt.-Click ParagraphFormat  CreateNode
5 In the pop-up box, ParagraphFormat: P1 (enter any name e.g P1)
6 Enter (tick mark)
7 Description: my paragraph format (enter any text)
8 Font (TAB) : define font characteristics for ‘Paragraph format’
Font family:
Font size: 11
Font style: Bold
Color:
Underline:
** Define Character-Format:
9 On left-panel, Rt.-Click CharacterFormat  CreateNode
10 In the pop-up box, CharacterFormat: C1 (enter any name e.g C1)
11 Enter (tick mark)
12 Description: my character format (enter any text)
13 Font(TAB) : define font characteristics for ‘Character format’
Font family:

Prepared by PEERS TECHNOLOGIES PVT LTD, HYDERABAD Page 70


PEERS – SAP ABAP
Font size: 12
Font style: Italic
Color:
Underline:
14 Save , LocalObject
15 Back (F3)
** Create Form:
16 Select radio-button, Form: ZmySmartFORM (enter any name)
17 Create
** Define Global Data:
18 On left-panel, dbl.-click ‘Global Definitions’ (or) select & press ‘ENTER’ key
19 GlobalData (TAB)
Variable name type assignment associated type (‘reference type’ in 4.6)
Intab like standard table of KNA1
Outtab type KNA1
** Create Windows & define Contents:
** Create window: LOGO:
20 On left-panel, Rt.-Click ‘%PAGE1 New page’
21 Create  Window
22 Window: LOGO
Description: logo window (enter any text or leave it blank)
(press ‘ENTER’ key)
23 On left-panel, Rt.-Click ‘LOGO’
24 Create  Graphic
25 Name: ENJOY (click inside the textBox and select a Graphic image, e.g. ENJOY)
Object:
Id:
NOTE: in the ‘Name’ box, click icon at the right corner. Select ‘color’ or ‘black & white’ bitmap
image from the pop-up panel. Click on ‘Execute’(F8) to list out the bitmap image names. Select
any image. e.g. ‘ENJOY’. Click on ‘Copy’ (tick mark)

Resolution: 100 (give any resolution, preferably 100DPI, dots per inch)
** Create window: HEADER:
26 On left-panel, Rt.-Click ‘%PAGE1 New page’
27 Create  Window
28 Window: HEADER
Desccription: header window (enter any text or leave it blank)
(Press ‘ENTER’ key)
29 On left-panel, Rt.-Click ‘HEADER’
30 Create  Text
(enter any text at the blinking cursor position, e.g. MY software technologies inc. USA)
** Create window: FOOTER:
31 On left-panel, Rt.-Click ‘%PAGE1 New page’
32 Create  Window
33 Window: FOOTER
Description: footer window (enter any text or leave it blank)
(Press ‘ENTER’ key)
34 On left-panel, Rt.-Click ‘FOOTER’
35 Create  Text
(enter any text at the blinking cursor position, e.g. YOUR future begins here)
** Define Window size, location:

Prepared by PEERS TECHNOLOGIES PVT LTD, HYDERABAD Page 71


PEERS – SAP ABAP
36 Click ‘FORM-PAINTER’ (F9) to show/hide the window design screen.
37 On lt-panel , Dbl-click on the window names (e.g. LOGO, HEADER etc.)
Drag them onto the ‘Designer Canvas’ on rt-panel.
Resize and relocate the windows as you like
Note: it requires some practice
** Define Program Lines:
38 On left-panel, Rt.-Click ‘MAIN window’
(Note: this window is created by default)
39 Create  FlowLogic  ProgramLines (Create  ProgramLines in 4.6)
(Note: if the ‘Designer Canvas’ is still visible, hide it by clicking on ‘Form Painter’)
40 GeneralAttributes (TAB)
Input parameter Output parameters
Intab Outtab
41 (write the following statement in right-bottom panel TextArea.) [NOT available in 4.6]
Select * from KNA1 into corresponding fields of table Intab.
42 Save , ‘LocalObject’
** Define LOOP:
43 On left-panel, Rt.-Click ‘%CODE1 New Program Lines1’
44 Create  FlowLogic  LOOP (Create  LOOP in 4.6)
45 Data (TAB)
‘Operand’*‘internal table’ in 4.6+: checkbox (Tick-mark)
‘Intab’ INTO ‘Outtab’ (enter internal-table names on either side of the word ‘INTO’)
46 On left-panel, Rt.-Click ‘%LOOP1 New Loop 1’
47 Create  Text
48 (Note: click ‘Insert Field’ icon with ‘+’ sign on the right-panel.
enter the following lines in the pop-up window and click ‘Continue’ (tick-mark).
To delete any selected field: highlight the field and click on ‘Delete Field’ icon with ‘-’ sign)

&outtab-kunnr&
&outtab-land1&
&outtab-name1&
&outtab-ort01&
49 Save, Check, Activate, Test (F8)
50 Function module: is generated (e.g. /1BCDWB/SF00000024)
51 SingleTest (F8) , Execute (F8)
52 Output Device: LP01
53 Click on ‘Print Preview’ (F8) [to view the generated Form]
FORM: - Copy & Modify (STANDARD LAYOUT) [layout and print Program defined by SAP]
Steps Action
** view exising STANDARD Form-name:
1 NACE (transaction code to view Standard Layouts/applications)
2 Select any Application from the list e.g V1 (sales)
3 Click on ‘Output Types’ (F5)
4 On right panel, select BA00 (order confirmation)
5 On left panel, dbl. click on ‘Processing Routines’
6 Just remember the Form to modify (e.g. RVORDER01) from the right-side list
7 Go back to initial screen by pressing ‘Back’(F3) several times (normally 3 times)
** Copy the Form:
8 SE71 (transaction code for Form-Painter)
9 On menu-bar, UTILITIES  COPY FROM CLIENT
10 Form Name: RVORDER01 [see step-6]

Prepared by PEERS TECHNOLOGIES PVT LTD, HYDERABAD Page 72


PEERS – SAP ABAP
Target Form: ZRVORDER01 (give any name)
Source Client: 800 (client code during login)
11 Execute(F8) , LocalObject , Back(F3) , Back(F3)
** Modify the layout:
12 Form: ZRVORDER01 [see step-10] target form name
13 Change
14 Click on ‘Page Windows’ (F8)
15 Dbl.click on ‘HEADER’ (or select any window to modify) *in the top ‘Page Window’ panel+
16 Click on ‘Text Elements’ icon on tool-bar (or F9)
17 Change the text (as per requirement)
18 Back (F3) to move to the ‘Page Window’ List
** check Form definitions, texts , Print-Preview:
19 On menu-bar, FORM  CHECK  DEFINITIONS
20 On menu-bar, FORM  CHECK  TEXTs , continue(tick-mark) in pop-up box
21 Select print Program ‘RVADOR01’ in the pop-up box, click ‘Copy’ (tick-mark), Back(F3)
22 On menu-bar, FORM  ACTIVATE
23 On menu-bar, UTILITIES  TEST PRINT (‘PRINTING TEST’ in version 4.7)
24 Output Device: LP01
25 Click on ‘Print Preview’ (F8)
26 Go back to initial screen by pressing ‘Back’ (F3) several times
** Replace the Form name:
27 NACE (transaction code to view Standard Layouts/Applications)
28 Select V1 (sales) [see step-2]
29 Click on ‘Output Types’ (F5)
30 On right-panel, select BA00 (order confirmation)
31 On left-panel, Dbl. click ‘Processing Routines’
32 On right-panel, Select the entire-row where ‘Form’ name (e.g. RVORDER01) to be changed
33 Click ‘Change/Display (Ctrl+F1)’ icon on tool-bar
34 Replace the ‘Form’ name.(e,g, RVORDER01 with ZRVORDER01) [see step-10]
35 Save , Continue(tick-mark) [operation successful]

FORM: use existing Form in ABAP Program

Steps Action
1 SE38 (transaction code for ABAP editor)
2 Program name: ZmyPRG1 (give any name)
3 Create
4 Title: MY Form program (give any text)
Type: Executable Program
5 Save, ‘Local object’
** add following Sourse Codes:
6 REPORT ZMYPRG1.

Tables: KNA1.
Select-options: cno for KNA1-kunnr.
*-------------------------------
** insert function: OPEN_FORM:
7 Click ‘Pattern’ (or) Ctrl+F6 , Call function: OPEN_FORM , continue (tick mark)
8 (Un-comment the following 3 lines)

Prepared by PEERS TECHNOLOGIES PVT LTD, HYDERABAD Page 73


PEERS – SAP ABAP
EXPORTING
Form = ‘ZmySapScriptFORM‘ *see ‘SAP script’ step-2]
Language = SY-LANGU

** SQL query:
9 (insert the following codes and place cursor after the last comment line)
*----------------------------------
Select * from KNA1 where kunnr in cno. [see step-4] (Note: not available in 4.6)
*---------------------------------
** insert function: START_FORM:
10 Ctrl+F6, Call function: START_FORM , continue (tick mark)
11 (Un-comment the following 5 lines)
EXPORTING
Form = ‘ZmySapScriptFORM’ *see ‘SAP script’ step-2]
Language = SY-LANGU
Start page = ‘Mypage’ *see ‘SAP script’ step-7]
Program = ‘ZmyPRG1’ [see step-2]
12 (place cursor at the last line of program codes and add the following demarcation line)
*----------------------------------------
** insert function: WRITE_FORM:
13 Ctrl+F6, Call function: WRITE_FORM , continue (tick mark)
14 (Un-comment the following 2 lines)
EXPORTING
Window = ‘ADDRESS’ *see ‘SAP script’ step-17]
15 (place cursor at the last line of program codes and add the following demarcation line)
*----------------------------------------
** insert function: WRITE_FORM:
16 Ctrl+F6 , Call function: WRITE_FORM , continue (tick mark)
17 (Un-comment the following 2 lines)
EXPORTING
Window = ‘MAIN’ *see ‘SAP script’ step-9]
18 (place cursor at the last line of program codes and add the following demarcation line)
*----------------------------------------
** insert function: END_FORM:
19 Ctrl+F6 , Call function: END_FORM , continue (tick mark)
20 (place cursor at the last line of program codes and add the following demarcation line)
*----------------------------------------
** END SELECT:
21 (place cursor at the last line and add the following codes..)

ENDSELECT.
*---------------------------------------
** insert function: CLOSE_FORM:
22 Ctrl+F6 , Call function: CLOSE_FORM , continue (tick mark)
23 Save
** Execute & Preview the Form:
24 Check , Activate , Execute (‘Direct processing’) F8
25 Cno: 1000 to 2000 (customer number: enter any range)
26 Execute (F8)
27 Output Device: LP01
28 Click on ‘Print preview’ *to display the Form output+

Prepared by PEERS TECHNOLOGIES PVT LTD, HYDERABAD Page 74


PEERS – SAP ABAP

LOGICAL DATABASES (LDB):


Definition: Logical Databases (LDBs) are special ABAP programs that retrieve data and make it available to application
programs.

A) the most common use of LDBs is to read data from different database tables by linking them to executable ABAP
programs.

PRG 1

PRG 2 LDB
DATA BASE

PRG 3

instead of programs interacts directly with databases, they interacts with logical databases.

b) in sap, ldbs are extensively used in HR-modules. (info-type) (hr-abap).

c) ldbs contain open sql statements that read data from the databases, so we there fore use sql statements in or
programs.

d) the ldb reads the program, stores in the program if necessary, and then passes them line by line to the application
program.

e) the data structure in a logical database is hierarchial.

f) many tables in the r/3 system are linked to each other using foreign key relation ships.

g) some of these dependencies form tree-like hierarchical structures.

h) logical databases read from database tables that are part of them structures.

tasks of logical databases: -


- reading the same data for several programs.
- defining the same user interface for several programs.

- improving performance.

a logical data base is made up of 3 components.

Prepared by PEERS TECHNOLOGIES PVT LTD, HYDERABAD Page 75


PEERS – SAP ABAP
1* structure:

the structure defines the data view of the logical database.

2* selections:.

the selections dfine a selection screen, which forms the user interface of the executable programs that use the logical
databases. it’s layout usually determined by a structure.

3* database program:
the data base program contains the abap statements used to read the data and pass it to the user of the logical database.

we need to define only structure, the rest of two (selections & database program) are auto-generated by the system.
Nodes:

KNA1

|--------- VBAK

|---------- VBAP

LDB: - Create ‘Logical DataBase’ (or VIEW)

Steps Action
1 SE36 (transaction for LDB creation)
2 Logical database: ZmyLDB (give any name)
3 Create
4 (in the pop-up box)
Short text: (give any text)
5 Click on ‘Create’ icon, ‘Local object’
** define parent node KNA1:
6 (in the pop-up box)
Name of Root Node: KNA1
Text: customer master table (give any text)
Select radio-button, ‘Database Table’ : KNA1
Click on ‘Create’ icon
** create child node VBAK:
7 Structure(TAB)
Under ‘Node Name’,
Right-click KNA1  InsertNodes
8 (in the pop-up box)
nd
Node name: VBAK (2 level node name)
Text: sales order table (enter any text)
Hierarchically under: KNA1 (parent node, by default)
Select radio-button, ‘Database table:’ VBAK
9 Click on ‘Insert new node’ (or F5)
** create child node VBAP:

Prepared by PEERS TECHNOLOGIES PVT LTD, HYDERABAD Page 76


PEERS – SAP ABAP
10 Structure(TAB)
Under ‘Node Name’,
Right-click on VBAK  InsertNodes
11 (in the pop-up box)
Node name: VBAP (3rd level node name)
Text: item order information
Hierarchically under: VBAK (parent node, by default)
Select radio-button, ‘Database table:’ VBAP
12 Click on ‘Insert new node’ (or F5)
13 Save
** generate ‘Selection Screen’ Source codes:
14 Click on ‘Selections’
15 Click on ‘Yes’ in the pop-up box
16 Click on ‘No’ in the pop-up box
17 We can see 2 types of selections in top and bottom panels
1. free selections (in Top panel)
2. field selections (in Bottom panel)
18 Select fields from ‘Free selections’ panel. (e.g. KNA1, VBAK, VBAP) check-box
19 Click on ‘Transfer’ (tick-mark)
** un-comment generated Source codes:
20 Some codes are automatically generated
21 (Un comment)
select-options: ? FOR kna1-kunnr (replace ? with cno)
select-options: ? FOR vbak-vbeln (replace ? with ono)
22 Save , Activate , Back (F3)
23 Click ‘Source code’ on tool-bar
24 Click on ‘Yes’ in the pop-up box
25 Double-click on include DBZmyLDBNXXX. “all system routines
** KNA1 (SELECT statement):
26
Again double-click on ‘Include xxxxxx KNA1’

27 (NOTE: uncomment the following 3 lines only and put ‘.’ After cno)
Select * from kna1
Where kunnr in cno.
Endselect.
28 Save , Check , Activate , Continue (tick mark) , Back(F3)
** VBAK (SELECT statement):
29 Again double-click on ‘Include xxxxxxx VBAK’
30 (NOTE: uncomment the following 3 lines only and put ‘.’ After ono)
Select * from vbak
Where vbeln in ono.
Endselect.
31 Save , Check , Activate , Continue (tick mark) , Back(F3)
** VBAP (SELECT statement):
32 Again double-click on ‘Include xxxxxxx VBAP’
33 (NOTE: uncomment the following 3 lines only and put ‘.’ After vbak-vbeln)
Select * from vbap
Where vbeln = vbak-vbeln.
Endselect.
34 Save , Check , Activate , Continue (tick mark) , Back (F3)

Prepared by PEERS TECHNOLOGIES PVT LTD, HYDERABAD Page 77


PEERS – SAP ABAP
** save, check , activate the Nodes:
35 Save , Activate , Continue (tick mark) , Back (F3)
36 Save , Activate , Continue (tick mark) , Back(F3) , Back(F3)

Note: don’t click ‘Save’ again in the Node-Tree(KNA1, VBAK, VBAP) screen
** test newly created LDB and view data:
37 Select ‘Logical Database:’ ZmyLDB *see step-2] (displayed by default)
38 Click on ‘Test’ icon (F8) on tool-bar
39 cno: 1000 to 1001 (customer number, Enter values)
ono: ---- to ---- (order number, leave it blank)
40 Click on Execute (F8) on tool-bar
Note: it may take few minutes to display the LDB content

REPORTS:

Popular methods to generate report are:

a) using reporting TOOL

b) using LDB

c) using SELECT statement

REPORT: - Simple Report program (using LDB) with 3 tables KNA1,VBAK,VBAP

Steps Action
1 SE38
2 Program name: ZmyLDBPrg (give any name)
3 Create
4 Title: my LDB program (enter any text)
Type: Executable Program
Logical Database: ZmyLDB (which is already created) *see ‘create LDB’ step-2]
5 Save , ‘Local object’ , *write the following source codes..+
6 REPORT ZMYLDBPRG.
Nodes: KNA1, VBAK, VBAP.
*--- column headings
Write: /5 ‘cust no’,
20 ‘cust name’,
40 ‘country’,
60 ‘order no’,
80 ‘order value’,
90 ‘item no’.
Get KNA1.
Get VBAK.
Get VBAP.
*--- column/field contents
Write: /5 KNA1-kunnr color 6 inverse on,
20 KNA1-name1 color 4 inverse on,
40 KNA1-land1 color 3 inverse on,

60 VBAK-vbeln color 2 inverse on,

Prepared by PEERS TECHNOLOGIES PVT LTD, HYDERABAD Page 78


PEERS – SAP ABAP
80 VBAK-netwr color 1 inverse on,

90 VBAP-posnr color 6 inverse on.

7 Save , check , activate , continue , Execute(‘Direct processing’) F8


8
cno: 1000 to 1001 (customer number, Enter values )
ono: ---- to ---- (order number, leave it blank)
9 Click on Execute (F8) [to generate Report]

SAP queries

ZGSRUSRGRP1
1
5
3 USER 1
QUERY 4 USER 2

USER 3

INFOSET USER 4

USER 5

USER 6

USER 7

USER 8
LOGICAL
DATABASE USER 9

DATABASE

DATABASE

REPORT: - SAP-QUERIES [report generation Tool] generates report without any ABAP coding.

Prepared by PEERS TECHNOLOGIES PVT LTD, HYDERABAD Page 79


PEERS – SAP ABAP
using LDB

Steps Action
1 SQ03 (transaction code) – create a usergroup
2 SQ02 (transaction code) – create a infoset
3 SQ03 (transaction code) – assign user and infoset to usergroup
4 SQ02 (transaction code) – assign usergroup to infoset
5 SQ01 (transaction code) – design the query layout , test/execute query

Steps Action
** create USERGROUP:
1 SQ03 (transaction code to create a usergroup)
2 User group: ZmyGrp (give any name)
3 Click ‘Create’
4 Short description: my group (enter any text)
5 Save , ‘Local object’ , Back
** create INFOSET:
6 SQ02 (transaction code to create a infoset)
7 Infoset: ZmyInfoset (give any name)
8 Create
9 Name: santanu’s infoset (give any text)
Authorization group: ZmyGrp [see step-2]
Select radio-button, ‘Logical Database’ : ZmyLDB
[see user defined table in LDB step-2]
10 Click on continue (tick mark)
11 New screen appears with TWO panels – Left and Right
** add Fields to FieldGroup: **
12 Select NODE ‘Customer Master Table’ from Right panel
13 In the Left panel , click on right-arrow icon beside ‘Customer Master Table KNA1’
14 right-click on field-name  ‘Add field to field group’
(e.g. customerNumber KNA1-kunnr). And Follow the same procedure for other fields (KNA1-
name1, KNA1-land1, KNA1-ort01)
Note: Select the required fields
15 Select another NODE from right panel and follow the same procedure as mentioned above for
VBAK (fields: vbeln, erdat, netwr, kunnr) , VBAP (fields: posnr, arktx, werks, vbeln)
16 Save , ‘Local object’
17 On manu-bar, Click on ‘Generate’ icon (or shift-F6) to generate the infoset
18 Save , Back , click ‘Yes’ in the pop-up box , Back
** assign USER and INFOSET to USERGROUP:
19 SQ03 (transaction code to assign user and infoset to usergroup)
20 Click on ‘Assign Users & Infoset’
21 Users and Change authorization for query
User name: SAPUSER [in the top left box] (username while logging in)
22 Press ‘Enter’ , Save
23 Click on ‘Assign Infoset’ (F5)
24 Select the Infoset you have created ‘ZmyInfoset’ from the list *see step-7]
25 Save , Back , Back , Back
** assign USERGROUP to INFOSET:

Prepared by PEERS TECHNOLOGIES PVT LTD, HYDERABAD Page 80


PEERS – SAP ABAP
26 SQ02 (transaction code to assign usergroup to infoset)
27 Select newly created infoset e.g. ‘ZmyInfoset’ from the list *see step-7]
28 Click on ‘Role/UserGroup Assignment’
29 Select your user-group from the generated list e.g. ‘ZmyGrp’ *see step-2]
30 Save , Back , Back
** design the Query Layout: (4.6c):
31 Note: following steps are for SAP 4.6c [ 4.7 version codes are given after step-48 ]
SQ01 (transaction code to design the query layout)
32 Query : ZmyQry (give any name)
33 Select the created Infoset e.g. ‘ZmyInfoset’ *see step-7]
34 Click on ‘Copy’ icon (tick mark)
35 Title: my SAP query using LDB (give any text)
Notes: my SAP query research work (give any text)
List format: Columns: 130
36 Select radio-button, ‘ABAP LIST ‘ under heading ‘output format’
37 Save
38 Click on ‘Basic LIST’
39 New screen appears with 4 panels(windows):
upper-left panel displays the following items:
 General data information- KNA1
 VBAK sales document
 VBAP sales document
40 On left panel , Click on right-arrow beside  ‘General data information- KNA1’ ,
And Select the required fields by clicking on (checkboxes) e.g. city, name1, country
41 On left-panel, Click on right-arrow beside  ‘VBAK sales document’,
And Select the required fields by clicking on (checkboxes)
42 On left-panel, Click on right-arrow beside  ‘VBAP sales document’,
And Select the required fields by clicking on (checkboxes)
43 Save
Click on ‘Test’ , click on Continue (tick mark) in the pop-up box
44 Enter the customer number: e.g.
cno: 1000 to 1001
45 Execute
46 Report is generated successfully
47 Optional:*** Click on ‘ALV’ button to generate user defined customized reports
48 The following operations can be performed by clicking the respective icons.
1. sort in ascending order
2. sort in descending order
3. filter
4. total
5. sub total
6. print preview
7. Microsoft excel view
8. word processing
9. mail receipt
10. ABC analysis
11. graphic view
12. change layout
13. select layout
14. save layout
** design the Query Layout: (4.7):

Prepared by PEERS TECHNOLOGIES PVT LTD, HYDERABAD Page 81


PEERS – SAP ABAP
31 Note: following steps are for SAP 4.7
SQ01 (transaction code to design the query layout)
32 Query : ZmyQry (give any name)
33 click ‘Other user group’ icon (shift+F7) on the tool-bar
34 select the user group name ‘ZmyGRP’ from the list , click on ‘Choose’
35 enter Query: ZmyQRY (any name)
36 click on ‘Infoset query’
37 select User Group: ZmyGRP (from the list)
38 select Infoset Name: ZmyInfoset
39 click ‘Continue’ (tick-mark)
40 New screen appears with 3 panels(windows)
41 upper-left panel displays the following items:
 Selection fields from InfoSet
 Customer Master Table
 Sales Order Table
 Item Order Information
42 click on the right-arrow icon beside  Selection fields from InfoSet
43 select CNO, ONO by clicking on the check-boxes
44 click on the right-arrow icon beside  Customer Master Table
45 select required fields by clicking on the (Output)check-boxes
46 click on the right-arrow icon beside  Sales Order Table
47 select required fields by clicking on the (Output)check-boxes
48 click on the right-arrow icon beside  Item Order Information
49 select required fields by clicking on the (Output)check-boxes
50
Save , Continue (tick-mark) , Continue (tick-mark)
51 Back (F3)
52 select newly created QUERY from the list, click ‘Test’ icon (Ctrl-F8) on the tool-bar
53 click ‘Continue’ (tick-mark)
54 Enter the customer number: e.g.
cno: 1000 to 1001
55 Execute
56 Report is generated successfully
REPORT: ALV [ABAP List Viewer] Report generation through ABAP program (using SELECT).

using a single table KNA1 with 4 columns .

Steps Action
1 SE38
2 Program name: ZmyALV (enter any name)
3 Create
4 Title: my report (enter any text)
Type: Executable Program
5 Save , ‘Local object’ , *enter the following source code+
6 REPORT ZMYALV.

*--- specify the type group.


TYPE-POOLS: SLIS.

*--- define the work area for the internal table

Prepared by PEERS TECHNOLOGIES PVT LTD, HYDERABAD Page 82


PEERS – SAP ABAP
*--- to store the lay-out details.
DATA: W_FCAT TYPE SLIS_FIELDCAT_ALV.

*--- define the work area for the internal table


*--- to store the lay-out details.
DATA: T_FCAT TYPE SLIS_T_FIELDCAT_ALV.

*--- define the lay-out and fill the catalog-internal-table.


W_FCAT-COL_POS = 1. “1st column
W_FCAT-FIELDNAME = 'KUNNR'. “field name
W_FCAT-SELTEXT_M = 'CUST NO'. “column/field heading
APPEND W_FCAT TO T_FCAT. “append data from work area to internal table
**------
W_FCAT-COL_POS = 2. “2nd column
W_FCAT-FIELDNAME = 'NAME1'. “field name
W_FCAT-SELTEXT_M = 'CUST NAME'. “column/field heading
APPEND W_FCAT TO T_FCAT. “append data from work area to internal table
**------
W_FCAT-COL_POS = 3. “3rd column
W_FCAT-FIELDNAME = 'ORT01'. “field name
W_FCAT-SELTEXT_M = 'CITY'. “column/field heading
APPEND W_FCAT TO T_FCAT. “append data from work area to internal table
*------
W_FCAT-COL_POS = 4. “4th column
W_FCAT-FIELDNAME = 'LAND1'. “field name
W_FCAT-SELTEXT_M = 'COUNTRY'. “column/field heading
APPEND W_FCAT TO T_FCAT. “append data from work area to internal table

*--- specify tables


TABLES: KNA1.

*--- specify types


TYPES: BEGIN OF TY_KNA1,
KUNNR TYPE KNA1-KUNNR,
NAME1 TYPE KNA1-NAME1,
ORT01 TYPE KNA1-ORT01,
LAND1 TYPE KNA1-LAND1,
END OF TY_KNA1.

*--- specify work area


DATA: W_KNA1 TYPE TY_KNA1.

*--- specify internal table


DATA: T_KNA1 TYPE STANDARD TABLE OF TY_KNA1
INITIAL SIZE 1.

*--- extract data


SELECT KUNNR NAME1 ORT01 LAND1
FROM KNA1
INTO TABLE T_KNA1.

Prepared by PEERS TECHNOLOGIES PVT LTD, HYDERABAD Page 83


PEERS – SAP ABAP
** call function REUSE_ALV_GRID_DISPLAY:
7 Place cursor after the last line , click on ‘Pattern’ (Ctrl+F6)
8 Call function: REUSE_ALV_GRID_DISPLAY , continue(tick mark)
9 (Un-comment following 4 lines)
EXPORTING
IT_FIELDCAT = T_FCAT
TABLES
T_OUTTAB = T_KNA1
10 Save , Check , Activate , Continue (tick mark)
11 Execute (direct processing) F8
12 Report is successfully generated.
(we can customize the report by selecting various icons on the tool-bar)

REPORT: Hierarchial Sequential Report (using SELECT) [using 2 tables VBAK, VBAP]

Steps Action
1 SE38
2 Program name: ZmyHierALV (enter any name)
3 Create
4 Title: my report (enter any text)
Type: Executable Program
5 Save , LocalObject
6 REPORT ZMYHIERALV.

TYPE-POOLS: SLIS.

*--- define the work area for the internal table


*--- to store the lay-out details.

DATA: W_FCAT TYPE SLIS_FIELDCAT_ALV.

*--- define the work area for the internal table


*--- to store the lay-out details.

DATA: T_FCAT TYPE SLIS_T_FIELDCAT_ALV.


DATA: W_KEYINFO TYPE SLIS_KEYINFO_ALV.

*--- type VBAK


TYPES: BEGIN OF TY_VBAK,
VBELN TYPE VBAK-VBELN,
ERDAT TYPE VBAK-ERDAT,
NETWR TYPE VBAK-NETWR,
END OF TY_VBAK.

**--- type VBAP


TYPES: BEGIN OF TY_VBAP,
VBELN TYPE VBAP-VBELN,
POSNR TYPE VBAP-POSNR,
ARKTX TYPE VBAP-ARKTX,
WERKS TYPE VBAP-WERKS,
END OF TY_VBAP.

Prepared by PEERS TECHNOLOGIES PVT LTD, HYDERABAD Page 84


PEERS – SAP ABAP
**--- work area
DATA: W_VBAK TYPE TY_VBAK,
W_VBAP TYPE TY_VBAP.

**--- internal tables


DATA: T_VBAK TYPE STANDARD TABLE OF TY_VBAK INITIAL SIZE 1,
T_VBAP TYPE STANDARD TABLE OF TY_VBAP INITIAL SIZE 1.

**--- constants
CONSTANTS: C_VBAK TYPE SLIS_TABNAME VALUE 'W_VBAK',
C_VBAP TYPE SLIS_TABNAME VALUE 'W_VBAP'.

**--- define layout and fill the Catalog internal table


**--- VBAK
st
W_FCAT-COL_POS = 1. “1 column
W_FCAT-FIELDNAME = 'VBELN'. “field name
W_FCAT-SELTEXT_M = 'ORDER NO'. “column/field heading
W_FCAT-TABNAME = C_VBAK. “assign constant value
APPEND W_FCAT TO T_FCAT. “append work area value to internal table
**----------
W_FCAT-COL_POS = 2. “2nd column
W_FCAT-FIELDNAME = 'ERDAT'. “field name
W_FCAT-SELTEXT_M = 'ORDER DATE'. “column/field heading
W_FCAT-TABNAME = C_VBAK. “assign constant value
APPEND W_FCAT TO T_FCAT. “append work area value to internal table
**----------
W_FCAT-COL_POS = 3. “3rd column
W_FCAT-FIELDNAME = 'NETWR'. “field name
W_FCAT-SELTEXT_M = 'ORDER VALUE'. “column/field heading
W_FCAT-TABNAME = C_VBAK. “assign constant value
APPEND W_FCAT TO T_FCAT. “append work area value to internal table

**---- VBAP
W_FCAT-COL_POS = 1. “1st column
W_FCAT-FIELDNAME = 'POSNR'. “field name
W_FCAT-SELTEXT_M = 'ITEM NO'. “column/field heading
W_FCAT-TABNAME = C_VBAP. “assign constant value
APPEND W_FCAT TO T_FCAT. “append work area value to internal table
*---------
W_FCAT-COL_POS = 2. “2nd column
W_FCAT-FIELDNAME = 'ARKTX'. “field name
W_FCAT-SELTEXT_M = 'ITEM DESC'. “column/field heading
W_FCAT-TABNAME = C_VBAP. “assign constant value
APPEND W_FCAT TO T_FCAT. “append work area value to internal table
*---------
W_FCAT-COL_POS = 3. “3rd column
W_FCAT-FIELDNAME = 'WERKS'. “field name
W_FCAT-SELTEXT_M = 'PLANT CODE'. “column/field heading
W_FCAT-TABNAME = C_VBAP. “assign constant value
APPEND W_FCAT TO T_FCAT. “append work area value to internal table
*---------

Prepared by PEERS TECHNOLOGIES PVT LTD, HYDERABAD Page 85


PEERS – SAP ABAP
W_KEYINFO-HEADER01 = 'VBELN'.
W_KEYINFO-ITEM01 = 'VBELN'.

SELECT VBELN ERDAT NETWR


FROM VBAK
INTO TABLE T_VBAK.

SORT T_VBAK BY VBELN.

SELECT VBELN POSNR ARKTX WERKS


FROM VBAP
INTO TABLE T_VBAP
FOR ALL ENTRIES IN T_VBAK
WHERE VBELN = T_VBAK-VBELN.

SORT T_VBAP BY POSNR.

** call function REUSE_ALV_HIERSEQ_LIST_DISPLAY:


7 Place cursor after the last line , click on ‘Pattern’
8 Call function: REUSE_ALV_HIERSEQ_LIST_DISPLAY
(or select REUSE_ALV_HIERSEQ_GRID_DISPLAY)
9 (un-comment following 8 lines)
EXPORTING
IT_FIELDCAT = T_FCAT
I_TABNAME_HEADER = C_VBAK
I_TABNAME_ITEM = C_VBAP

IS_KEYINFO = W_KEYINFO
TABLES
T_OUTTAB_HEADER = T_VBAK
T_OUTTAB_ITEM = T_VBAP
10 Save , Check , Activate , Continue (tick mark)
11 Execute
12 Report is successfully generated.
(we can customize the report by selecting various icons on the tool-bar)
REPORT: Simple Interactive Report [demo without data]

Steps Action
1 SE38
2 Program name: ZmyInterReport (give any name)
3 Create
4 Short Desc: (write any text)
Type: Executable Program
5 Save , LocalObject , [enter the following source codes]
6 REPORT ZMYINTERREPORT.

Write: / ‘This is the first MAIN screen of my report’.

*-- EVENT

Prepared by PEERS TECHNOLOGIES PVT LTD, HYDERABAD Page 86


PEERS – SAP ABAP
At line-selection.

Case SY-LSIND.
When ‘1’
Write: / ‘this is the second screen’ , SY-LSIND.
When ‘2’
Write: / ‘this is the third screen’ , SY-LSIND.
When others.
Write: / SY-LSIND.
Endcase.
7 Save , check , activate , continue
8 Execute
9 Double-click on the screen headings to move to the next level of screens
(upto 21 screens)

REPORT: Complex Interactive Report (using SELECT) [with hot-spot] with 3 tables KNA1, VBAK, VBAP. [using
selection screen for parameter input]

Steps Action
1 SE38
2 Program name: ZmyInterReportComplex1 (give any name)
3 Create
4 Title: my report (write any text)
Type: Executable Program
5 Save , LocalObject , [enter the following source codes]
6 REPORT ZMYINTERREPORTCOMPLEX1.

Tables: KNA1, VBAK, VBAP.

Select-options: cno for KNA1-kunnr. “cno = customer number


Parameters: cnt type KNA1-land1. “cnt = country

ULINE.
*--- column headings of table KNA1
Write: /5 ‘custno’,
20 ‘custname’,
40 ‘country’.

Select * from KNA1


where kunnr in cno
and cnt = land1.

*--- column/field contents of table KNA1


Write: /5 KNA1-kunnr color 6 inverse on HotSpot on,
20 KNA1-name1 color 4 inverse on,
40 KNA1-land1 color 3 inverse on.

Hide KNA1-kunnr.
Endselect.

**--- EVENT , when clicked on a line(row)

Prepared by PEERS TECHNOLOGIES PVT LTD, HYDERABAD Page 87


PEERS – SAP ABAP
At line-selection.

Case SY-LSIND.
When ‘1’. “1st level screen
Write: /30 ‘Sales order information list’.
ULINE.
*--- column headings of table VBAK
Write: /5 ‘order no’,
20 ‘order date’,
60 ‘order value’.
ULINE.

Select * from VBAK


where kunnr = KNA1-kunnr.

*--- column/field contents of table VBAK


Write: /5 VBAK-vbeln color 5 inverse on HotSpot on,
20 VBAK-erdat color 6 inverse on,
60 VBAK-netwr color 5 inverse on.

Hide VBAK-vbeln.
Endselect.
Endcase.

**--- EVENT , when clicked on a line(row)


At line-selection.

Case SY-LSIND.
When ‘2’. “2nd level screen
Write: /30 ‘Item information list’.
ULINE.
*--- column headings of table VBAP
Write: /5 ‘item no’,
21 ‘item description’,
61 ‘plant code’.
ULINE

Select * from VBAP


where vbeln = VBAK-vbeln.

*--- column/field contents of table VBAP


Write: /5 VBAP-posnr color 6 inverse on HotSpot on,
20 VBAP-arktx color 5 inverse on,
60 VBAP-werks color 3 inverse on.
Endselect.
Endcase.

7 Save , check , activate , continue


8 Execute
9 Enter:
Cno: 1000 to 1001
Cnt: DE (country code for Germany)

Prepared by PEERS TECHNOLOGIES PVT LTD, HYDERABAD Page 88


PEERS – SAP ABAP
10 click ‘Execute’ F8
11 Report is generated successfully.
12 Click on HotSpot fields to jump over to next level
e.g. click on ‘custno’ 1000  click on ‘orderno’ 5069  click on ‘item no’ 10
REPORT: Complex Report with Reporting-Events (using SELECT) [2 tables KNA1, VBAK using inner join]

Steps Action
1 SE38
2 Program name: ZmyComplexReport (give any name)
3 Create
4 Title: my report (write any text)
Type: Executable Program
5 Save , ‘Local object’ , *enter the following source codes+
6 REPORT ZMYCOMPLEXREPORT.

TABLES: KNA1, VBAK.

types: BEGIN OF ITAB ,


KUNNR TYPE KNA1-KUNNR,
NAME1 TYPE KNA1-NAME1,
LAND1 TYPE KNA1-LAND1,
VBELN TYPE VBAK-VBELN,
ERDAT TYPE VBAK-ERDAT,
NETWR TYPE VBAK-NETWR,
END OF ITAB.

*--- define work-area


data: wtab type ITAB.

*--- define internal table


data: t_itab type standard table of ITAB
with default key
initial size 1
with header line.

*--- define screen select options


SELECTION-SCREEN BEGIN OF BLOCK B1.
SELECT-OPTIONS: CNO FOR KNA1-KUNNR. “CNO = customer number
parameters: CNT type KNA1-land1. “CNT = country
SELECTION-SCREEN END OF BLOCK B1.

*--- top-of-page event


top-of-page.

*--- column/field headings


WRITE: /5 'CUSTNO',
15 'CUSTNAME',
35 'COUNTRY',
45 'SALESORDER',
60 'ORDER DATE',

Prepared by PEERS TECHNOLOGIES PVT LTD, HYDERABAD Page 89


PEERS – SAP ABAP
75 'ORDER VALUE'.

ULINE. "underline

*--- event
start-of-selection.

*--- Query with INNER JOIN

SELECT K~KUNNR K~NAME1 K~LAND1


V~VBELN V~ERDAT V~NETWR
INTO TABLE t_ITAB
FROM KNA1 AS K
INNER JOIN
VBAK AS V
ON K~KUNNR = V~KUNNR
WHERE K~KUNNR IN CNO
AND K~LAND1 = cnt.

*-- show output


loop at t_itab into wtab.
WRITE: /5 wtab-KUNNR,
15 wTAB-NAME1,
35 wTAB-LAND1,
45 wTAB-VBELN,
60 wTAB-ERDAT,
75 wTAB-NETWR.

at end of kunnr.
sum.
write:/ 'sub total of order value' , 100 wtab-netwr.
endat.

endloop.

**---Event
end-of-page.
ULINE.
7 Save , check , activate , continue
8 Execute
9 Enter: Cno: 1000 to 1002
Cnt: DE (country code for Germany)

click ‘Execute’ F8
10 Report is generated with control breaks and sub-totals

ABAP DICTIONARY: create Type-Group [User Defined TYPE]

Steps Action

Prepared by PEERS TECHNOLOGIES PVT LTD, HYDERABAD Page 90


PEERS – SAP ABAP
1 SE11
2 Select radio-button, ‘Type Group:’ Zmy1 (give any name)
3 Create
4 Short text:
5 Save
6 types: zmy1_name(10) type c,
zmy1_numc type i.

types: begin of zmy1_temp,


A type i,
B type i,
end of zmy1_temp.
7 Save , check , activate , continue (tick mark) , back
8 SE38
9 Program name: ZmyTypeProgram (give any name)
10 Create
11 Short desc:
Type: executable program
12 Save , ‘Local object’ , enter the following source codes
13 type-pools: zmy1.

data: w_itab type zmy1_temp,


c type zmy1_numc.

w_itab-a = 10.
w_itab-b = 20.

c = w_itab-a + w_itab-b.

write: / c.
14 Save , check , activate , continue(tick mark)
15 Execute
ABAP DICTIONARY: create User Defined TABLE [ ZmyEMPt , ZmyDEPT ] see step-13,24

Steps Action
1 SE11
2 Select radio-button, ‘Data type:’ YmyTP , ‘Create’ (create data element to link 2 tables)
3 Select radio-button, ‘Data element’ , click on ‘Continue’ (tick-mark) in pop-up box
** DataType(TAB):
4 Short description: (enter any text)

DataType(TAB)
Select radio-button, ‘Built-in-type’
Data type: NUMC
Length: 10
** Field label(TAB):
6 Field label(TAB)

Length Field label


Short 10 empno
7 Save , LocalObject, check , activate , continue (tick-mark) , back(F3)

Prepared by PEERS TECHNOLOGIES PVT LTD, HYDERABAD Page 91


PEERS – SAP ABAP
** create 1st table, ZmyEMPt:
8 Select radio-button, ‘Database table:’ ZmyEMPt (give any name)
9 Short description: (enter any text)
** Delivery & Maintenance(TAB):
11 Delivery & Maintenance(TAB)

Delivery class: A [application table (master & transaction data)]


Data browser/table view maint: Display maintenance allowed [select from list box]
** Fields(TAB):
13 Fields(TAB)

Field Key DataElement Dtype Length Short description


Empno tick NUMC 10
Empname CHAR 10
Deptno YmyTP[see step-2]

(Note: click on ‘Built-in type’ to select NUMC, CHAR


click on ‘Data Element’ to enter YmyTP, and press ENTER key to fill in Dtype , Length)
14 Save, LocalObject, ‘continue’(tick-mark)
15 Click on ‘Technical Settings’ (ctrl+shift+F9) on tool-bar
16 Data class: APPL0 [select from list box, choose(F2)] (master data, transparent tables)
17 Size category: 0 (zero)
Select radio-button, ‘Buffering NOT allowed’
18 Save , check , activate(revised<->active)shift+F8 , continue (tick-mark) , back(F3), back(F3)
** create 2nd table, ZmyDEPT:
19 Select radio-button, ‘Database table:’ ZmyDEPT (give any name)
20 Short description: (enter any text)
** Delivery & Maintenance(TAB):
22 Delivery & Maintenance(TAB)

Delivery class: A [application table (master & transaction data)]


Data browser/table view maint: Display maintenance allowed [select from list box]
** Fields(TAB):
24 Fields(TAB)
Field Key DataElement Dtype Length Short description
Depno tick YmyTP [see step-2]
Depname CHAR 20
(Note: click on ‘Built-in type’ to select CHAR
click on ‘Data Element’ to enter YmyTP, and press ENTER key to fill in Dtype , Length)
25 Save, LocalObject, ‘continue’(tick-mark)
26 Click on ‘Technical Settings’ on tool-bar
27 Data class: APPL0 [select from list box, choose(F2)] (master data, transparent tables)
28 Size category: 0 (zero)
Select radio-button, ‘Buffering NOT allowed’
29 Save , check , activate(revised<->active)shift+F8 , continue (tick-mark) , back(F3)
** enter data into table ZmyDEPT:
30 To enter data into table: *Note: table must be activated first (click ‘activate’,’continue’+
select from menu-bar, Utilities  TableContents  CreateEntries
31 Enter record one by one & click SAVE (crtl+S) to store data into table
Back (F3)
32 To view data from table: *Note: table must be activated first (click ‘activate’,’continue’+

Prepared by PEERS TECHNOLOGIES PVT LTD, HYDERABAD Page 92


PEERS – SAP ABAP
select from menu-bar, Utilities  TableContents  Display , Execute(F8)

Create ‘FOREIGN KEY’ to link tables: (ZmyEMPt , ZmyDEPT)


NOTE: 2 tables can be linked, only by using user defined ‘data element’
[see step-13, step-24]
1 Select the row containing field name Deptno [see step-13]
2 Click on ‘Foreign Key’ icon (in ‘Fields’ TAB)
3 Short text: linking two tables (give any text)
Check table: ZmyDEPT [see step-19] (Note: give the other table name e.g. ZmyDEPT)
4 Click on ‘Generate Proposal’ (Fields are filled with values)
5 Click on Copy (tick-mark)
6 Save , continue, check , activate, continue(tick-mark)
** enter data into table ZmyEMPt:
7 To enter data into table: *Note: table must be activated first (click ‘activate’,’continue’+
select from menu-bar, Utilities  TableContents  CreateEntries
8 Enter record one by one & click ‘SAVE’ to store data into table
(Note: when DEPTNO is selected a list-box icon appears in right corner)
9 Select ‘Deptno’ from the list-box or enter the value
10 To view data from table:
select from menu-bar, Utilities  TableContents  Display

SCREEN: Simple Screen Program: (Executable Program) with inputBox, checkboxes, commandButton

Steps Action
1 SE38
2 Program: ZMYSCREEN (enter any name)
3 Create
4 Title: my screen program (enter any text)
5 Type: Executable Program
6 Save , LocalObject , continue
7 Enter the line call screen 100. after REPORT ZMYSCREEN
8 REPORT ZMYSCREEN.

CALL SCREEN 100.


9 Dbl. Click on screen number 100.
10 Click ‘Yes’ in pop-up box , click ‘Yes’ in next pop-up box
11 Short description: my screen (enter any text)
** Layout ctrl+F7:
12 Click ‘Layout’ to design the screen
13 Drag and drop following control elements from the left side Tool-Box into the work-area
a Input box , two check boxes and a command button
14 Dbl. click on INPUT-BOX to enter properties:
I/O box
Name: IO1
15 Dbl. click on 1st CHECK-BOX (to enter properties)

CheckBox-1
Name: CB1
Text: SAP

Prepared by PEERS TECHNOLOGIES PVT LTD, HYDERABAD Page 93


PEERS – SAP ABAP
FctCode: EX1
16 Dbl. click on 2nd CHECK-BOX (to enter properties)

CheckBox-2
Name: CB2
Text: ABAP
FctCode: EX2
17 Dbl. click on COMMAND-BUTTON (to enter properties)

PushButton
Name: CMD1
Text: EXIT
FctCode: EX

[NOTE: Ok type(hidden. system default) OK ]


** Flow Logic:
18 Click ‘Flow Logic’ to define the program flow
19 Flow logic(TAB) [other tabs are ‘Attributes’, ‘Element list’]

PROCESS BEFORE OUTPUT.


* MODULE STATUS_0100.
*
PROCESS AFTER INPUT.
* MODULE USER_COMMAND_0100.

20 Un-comment the line MODULE USER_COMMAND_0100.


21 Dbl. click on the module name USER_COMMAND_0100.
22 You are in the program editor now
23 Enter the following codes between the lines..

MODULE USER_COMMAND_0100 INPUT.

ENDMODULE. " USER_COMMAND _0100 INPUT


24
MODULE USER_COMMAND_0100 INPUT.

DATA: CB1 TYPE C,


CB2 TYPE C,
IO1(5) TYPE C.

CASE SY-UCOMM.
WHEN 'EX'.
LEAVE PROGRAM.

WHEN 'EX1'.
IF CB1 = 'X'.
IO1 = 'SAP'.
ELSE.
IO1 = ' ' .

Prepared by PEERS TECHNOLOGIES PVT LTD, HYDERABAD Page 94


PEERS – SAP ABAP
ENDIF.

WHEN 'EX2'.
IF CB2 = 'X'.
IO1 = 'ABAP'.
ELSE.
IO1 = ' ' .
ENDIF.
ENDCASE.

ENDMODULE. " USER_COMMAND _0100 INPUT


25 Save , check , activate , continue(tick-mark)

26 Execute

SCREEN: Simple Screen Program: (Module Pool) with inputBox, checkboxes, commandButton

Steps Action
1 SE38
2 Program: ZMYSCREEN1 (enter any name)
3 Create
4 Title: (enter any text)
5 Type: Module Pool
6 Save, LocalObject, continue
7 Enter the line call screen 100. after PROGRAM ZMYSCREEN1.
8 PROGRAM ZMYSCREEN1.

CALL SCREEN 100.


9 Dbl. click on the screen number 100
10 Click ‘Yes’ in pop-up box , click ‘Yes’ in next pop-up box
11 Short description: my screen (enter any text)
** Layout ctrl+F7:
12 Click ‘Layout’ to design the screen
13 Drag and drop following control elements from the left side Tool-Box into the work-area
a Input box , two check boxes and a command button
14 Dbl. click on INPUT-BOX to enter properties:
I/O box
Name: IO1
15 Dbl. click on 1st CHECK-BOX (to enter properties)

CheckBox-1
Name: CB1
Text: SAP
FctCode: EX1
16 Dbl. click on 2nd CHECK-BOX (to enter properties)

CheckBox-2
Name: CB2
Text: ABAP

Prepared by PEERS TECHNOLOGIES PVT LTD, HYDERABAD Page 95


PEERS – SAP ABAP
FctCode: EX2
17 Dbl. click on COMMAND-BUTTON (to enter properties)

PushButton
Name: CMD1
Text: EXIT
FctCode: EX

[NOTE: Ok type(hidden. system default) OK ]


** Flow Logic:
18 Click ‘Flow Logic’ to define the program flow
19 Flow logic(TAB) [other tabs are ‘Attributes’, ‘Element list’]

PROCESS BEFORE OUTPUT.


* MODULE STATUS_0100.
*
PROCESS AFTER INPUT.
* MODULE USER_COMMAND_0100.

20 Un-comment the line MODULE USER_COMMAND_0100.


21 Dbl. click on the line MODULE USER_COMMAND_0100.
22 You are in the program editor now
23 Enter the following codes between the lines..

MODULE USER_COMMAND_0100 INPUT.

ENDMODULE. " USER_COMMAND _0100 INPUT


24
MODULE USER_COMMAND_0100 INPUT.

DATA: CB1 TYPE C,


CB2 TYPE C,
IO1(5) TYPE C.

CASE SY-UCOMM.
WHEN 'EX'.
LEAVE PROGRAM.

WHEN 'EX1'.
IF CB1 = 'X'.
IO1 = 'SAP'.
ELSE.
IO1 = ' ' .
ENDIF.

WHEN 'EX2'.
IF CB2 = 'X'.
IO1 = 'ABAP'.
ELSE.
IO1 = ' ' .

Prepared by PEERS TECHNOLOGIES PVT LTD, HYDERABAD Page 96


PEERS – SAP ABAP
ENDIF.
ENDCASE.

ENDMODULE. " USER_COMMAND _0100 INPUT


25 Comment or delete the line CALL SCREEN 100.
26 Save , check , activate , continue(tick-mark)

27 NOTE: you cannot Execute a ‘Module Pool’ program by clicking “Execute’ button.
You need to create a TRANSACTION-CODE to execute this program.
Transaction Code: creation

Steps Action
1 SE93
Transaction code: ZmyTrans1 (first letter must be Z or Y)
Create
Short text: (enter any text)
Select radio-button ‘Program and Screen (dialog transaction)’
Click ‘continue’ (enter)
Program: ZMYSCREEN1 (the module pool program name)
Screen number: 100 (same as module pool screen number)
Save, package: $TMP , localObject
Transaction code ZmyTrans1 is created
Enter ZmyTrans1 to execute the module pool program ‘ZMYSCREEN1’

SCREEN: Screen Program (with Table-Control)

Steps Action
1 REPORT ZSANSCREENPRG3 .
*REPORT demo_dynpro_tabcont_loop.
CONTROLS flights TYPE TABLEVIEW USING SCREEN 101.
TABLES: demo_conn, spfli.
DATA: itab TYPE TABLE OF demo_conn,
fill TYPE i.

CALL SCREEN 101.


MODULE status_0101 OUTPUT.

SELECT * FROM spfli INTO CORRESPONDING FIELDS OF TABLE itab.

SET PF-STATUS 'SCREEN_101'.


DESCRIBE TABLE itab LINES fill.
flights-lines = fill.
ENDMODULE.

MODULE fill_table_control OUTPUT.


READ TABLE itab INTO demo_conn INDEX flights-current_line.
ENDMODULE.

*&---------------------------------------------------------------------*
*& Module exit INPUT

Prepared by PEERS TECHNOLOGIES PVT LTD, HYDERABAD Page 97


PEERS – SAP ABAP
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE exit INPUT.
case sy-ucomm.
when 'EX'.
leave program.
endcase.
ENDMODULE. " exit INPUT

[Note: ‘spfli’ is a TABLE. Whereas ‘demo_conn’ is a VIEW+


** Flow Logic:
2 PROCESS BEFORE OUTPUT.
MODULE STATUS_0101.
LOOP WITH CONTROL FLIGHTS.
MODULE FILL_TABLE_CONTROL.
ENDLOOP.

PROCESS AFTER INPUT.


LOOP WITH CONTROL FLIGHTS.

ENDLOOP.
module exit.

** Layout:ctrl+F7
3 Table control
Name: FLIGHTS

Table-name: DEMO_CONN
Fileds:
CARRID
CONNID
CITYFROM
CITYTO

SCREEN: Screen Program (with TabStripControl)

Steps Action
1 SE38
2 Program: zdemo_dynpro_tabstrip_local (enter any name)
3 Create
4 Title: (enter any text)
5 Type: Executable Program
6 Save
7
REPORT ZDEMO_DYNPRO_TABSTRIP_LOCAL.

CONTROLS mytabstrip TYPE TABSTRIP.

DATA: ok_code TYPE sy-ucomm,

Prepared by PEERS TECHNOLOGIES PVT LTD, HYDERABAD Page 98


PEERS – SAP ABAP
save_ok TYPE sy-ucomm.

DATA: NUM1 TYPE i,


NUM2 TYPE i,
ANS TYPE p decimals 2.

DATA: ADD(1) TYPE C,


SUB(1) TYPE C,
MUL(1) TYPE C,
DIV(1) TYPE C.

mytabstrip-activetab = 'PUSH1'.

CALL SCREEN 100.

MODULE status_0100 OUTPUT.


SET PF-STATUS 'SCREEN_100'.
SET TITLEBAR 'MYTITLE'.
ENDMODULE.

MODULE cancel INPUT.


LEAVE PROGRAM.
ENDMODULE.

MODULE user_command INPUT.


save_ok = ok_code.
CLEAR ok_code.
IF save_ok = 'OK'.
MESSAGE i888(sabapdocu) WITH 'MYTABSTRIP-ACTIVETAB ='
mytabstrip-activetab.
ENDIF.
ENDMODULE.

MODULE calculation.

CASE SY-UCOMM.
WHEN 'RADIO'.
IF ADD = 'X'.
ANS = NUM1 + NUM2.
mytabstrip-activetab = 'PUSH3'.

ELSEIF SUB = 'X'.


ANS = NUM1 - NUM2.
mytabstrip-activetab = 'PUSH3'.

ELSEIF MUL = 'X'.


ANS = NUM1 * NUM2.
mytabstrip-activetab = 'PUSH3'.

ELSEIF DIV = 'X'.


ANS = NUM1 / NUM2.
mytabstrip-activetab = 'PUSH3'.

ENDIF.
ENDCASE.

ENDMODULE.

Prepared by PEERS TECHNOLOGIES PVT LTD, HYDERABAD Page 99


PEERS – SAP ABAP
Note: dbl-click SCREEN_100, MYTITLE to define PF-STATUS , TITLEBAR

create screen: 100

8 double-click on screen number 100 to create screen 100

** Flow Logic: screen 100

9 PROCESS BEFORE OUTPUT.


MODULE STATUS_0100.
CALL SUBSCREEN: SUB1 INCLUDING SY-REPID '0110',
SUB2 INCLUDING SY-REPID '0120',
SUB3 INCLUDING SY-REPID '0130'.
PROCESS AFTER INPUT.
MODULE CANCEL AT EXIT-COMMAND.
CALL SUBSCREEN: SUB1,
SUB2,
SUB3.
MODULE USER_COMMAND.

** Layout screen 100


10 Note: place a tabStrip control with 3 tabs
(each tab containing a subscreen area)

tabstrip control:
name: MYTABSTRIP
tab title: 3

(tab1)push-button:
name: PUSH1
text: Tab_page_1
fctCode: PUSH1

(tab2)push-button:
name: PUSH2
text: Tab_page_2
fctCode: PUSH2

(tab3)push-button:
name: PUSH3
text: Tab_page_3
fctCode: PUSH3

subscreen area(1):
name: SUB1

subscreen area(2):
name: SUB2

subscreen area(3):
name: SUB3

push-button:
name: BUTTON
text: Cont.
icon: ICON_OKAY
fctCode: OK

Prepared by PEERS TECHNOLOGIES PVT LTD, HYDERABAD Page 100


PEERS – SAP ABAP
system-defined hidden field:
type: OK
name: OK_CODE

Create sub-screen: 110


11 SE51
12 Program: ZDEMO_DYNPRO_TABSTRIP_LOCAL [see step-1]
Screen number: 0110
13 Create
14 Short description: sub screen 1 (give any text)
15 Select radio-button ‘SubScreen’ under ‘Screen Type’
16 Layout subScreen 110: Click ‘Layout’ on tool-bar
17 Note: place a text-field near top-left corner of the screen

Text-field:
Name: TEXT1
Text: Subscreen 1

Note: place 2 text-fields and


2 i/o fields

Text-field:
Name: LABEL1
Text: Number1:

Text-field:
Name: LABEL2
Text: Number2:

i/o-field:
Name: NUM1

i/o-field:
Name: NUM2

Note: select ‘Element list’ -> ‘General attr’ tab.


for NUM1 and NUM2 i/o fields , select format as ‘NUMC’ (to disallow entry of
characters in the input fields)
18 Save , activate

Create sub-screen: 120


19 Program: ZDEMO_DYNPRO_TABSTRIP_LOCAL [see step-1]
Screen number: 0120
20 Create
21 Short description: sub screen 2 (give any text)
22 Select radio-button ‘SubScreen’ under ‘Screen Type’
23 Layout subScreen 120: Click ‘Layout’ on tool-bar
24 Note: place a text-field near top-left corner of the screen

Text-field:
Name: TEXT2
Text: Subscreen 2

Prepared by PEERS TECHNOLOGIES PVT LTD, HYDERABAD Page 101


PEERS – SAP ABAP
Note: place 4 radio buttons

Radio-button:
name: ADD
text: Addition
fctCode: RADIO

Radio-button:
name: SUB
text: Subtraction
fctCode: RADIO

Radio-button:
name: MUL
text: Multiplication
fctCode: RADIO

Radio-button:
name: DIV
text: Division
fctCode: RADIO

flow logic: subScreen 120


PROCESS BEFORE OUTPUT.
PROCESS AFTER INPUT.

module calculation.

25 Save, activate

Create sub-screen: 130


26 Program: ZDEMO_DYNPRO_TABSTRIP_LOCAL [see step-1]
Screen number: 0130
27 Create
28 Short description: sub screen 3 (give any text)
29 Select radio-button ‘SubScreen’ under ‘Screen Type’
30 Layout subScreen 130: Click ‘Layout’ on tool-bar
31 Note: place a text-field near top-left corner of the screen

Text-field:
Name: TEXT3
Text: Subscreen 3

Note: place a text-field and


a i/o-field

Text-field:
Name: RESULT
Text: Result

i/o-field:
Name: ANS
remove Tick-mark from ‘input field’ to make it read only

Prepared by PEERS TECHNOLOGIES PVT LTD, HYDERABAD Page 102


PEERS – SAP ABAP
Note: select Tab ‘Element list’ -> ‘General attr’ .
for ANS i/o field, select format as ‘INT4’ (to allow decimal places and disallow entry of
characters in the input field)
Save, activate

execute the screen program

go to source-code of screen-program ZDEMO_DYNPRO_TABSTRIP_LOCAL

click Check(ctrl+F2) , Activate(ctrl+F3) , Execute(Direct processing F8)

SCREEN: Screen Program – data insert, update, delete in user defined table (using Table Control)

Steps Action
1 create an user-defined table ‘ZAJDEPT’
field type length key
DNO NUMC 10 tick
DNAME CHAR 10
Note: DNO is a primary key field
see ‘ABAP Dictionary - create user-defined tables’..
2
SE38
3 Program: ZSANDATAENTRYSCREEN (enter any name)
4
Create
5 Title: (enter any text)
6 Type: Executable Program
7 Save
** Program source code:
8 REPORT ZSANDATAENTRYSCREEN.
CONTROLS MY_TBL_CTRL TYPE TABLEVIEW USING SCREEN 100.
TABLES: ZAJDEPT.
DATA: itab TYPE TABLE OF ZAJDEPT,
fill TYPE i.
DATA: IO_DNO type ZAJDEPT-DNO,
IO_DNAME type ZAJDEPT-DNAME.
DATA: IO_STATUS(40) type C.
call screen 100.
*---[MODULE] STATUS_010
MODULE STATUS_0100 OUTPUT.
SELECT * FROM ZAJDEPT INTO CORRESPONDING FIELDS OF TABLE itab.
DESCRIBE TABLE itab LINES fill.
MY_TBL_CTRL-lines = fill.
ENDMODULE. " STATUS_0100 OUTPUT
*---[MODULE] FILL TABLE CONTROL
MODULE fill_table_control OUTPUT.

Prepared by PEERS TECHNOLOGIES PVT LTD, HYDERABAD Page 103


PEERS – SAP ABAP
READ TABLE itab INTO ZAJDEPT INDEX MY_TBL_CTRL-current_line.
ENDMODULE.
*---[MODULE] BUTTON ACTION
MODULE button_action INPUT.
CASE SY-UCOMM.
*--- EXIT
WHEN 'EXIT'.
LEAVE PROGRAM.
*--- INSERT
WHEN 'INSERT'.
ZAJDEPT-DNO = IO_DNO.
ZAJDEPT-DNAME = IO_DNAME.
INSERT ZAJDEPT.
IF SY-SUBRC <> 0.
IO_STATUS = 'SORRY! ENTRY ALREADY EXISTS'.
ELSE.
IO_STATUS = 'INSERTED DATA SUCCESSFULLY'.
ENDIF.
*--- UPDATE
WHEN 'UPDATE'.
ZAJDEPT-DN0 = IO_DNO.
ZAJDEPT-DNAME = IO_DNAME.
UPDATE ZAJDEPT.
IF SY-SUBRC <> 0.
IO_STATUS = 'SORRY! RECORD DOES NOT EXIST'.
ELSE.
IO_STATUS = 'UPDATED DATA SUCCESSFULLY'.
ENDIF.
*--- DELETE
WHEN 'DELETE'.
ZAJDEPT-DN0 = IO_DNO.
DELETE ZAJDEPT.
IF SY-SUBRC <> 0.
IO_STATUS = 'SORRY! RECORD DOES NOT EXIST'.
ELSE.
IO_STATUS = 'DELETED RECORD SUCCESSFULLY'.
ENDIF.
ENDCASE.
ENDMODULE. " button_action INPUT

create screen: 100

9 double-click on screen number 100

** Flow Logic:

10 *--- PBO

PROCESS BEFORE OUTPUT.


MODULE STATUS_0100.
LOOP WITH CONTROL MY_TBL_CTRL.
MODULE FILL_TABLE_CONTROL.
ENDLOOP.

Prepared by PEERS TECHNOLOGIES PVT LTD, HYDERABAD Page 104


PEERS – SAP ABAP
*--- PAI
PROCESS AFTER INPUT.
LOOP WITH CONTROL MY_TBL_CTRL.
ENDLOOP.
MODULE button_action.

** Layout:

11 text-field:
name: LABEL_HEADING
text: DATA_management_in_table_ZAJDEPT-_by_Santanu

Box:
name: BOX_DATA_ENTRY
text: data_entry
Note: place the following 4 fields inside the rectangular BOX area BOX_DATA_ENTRY
text-field:
name: LABEL_DNO
text: Department_no:

i/o-field:

name: IO_DNO

format: NUMC

text-field:

name: LABEL_DNAME

text: Department_name:

i/o-field:

name: IO_DNAME

format: CHAR

i/o-field:

name: IO_STATUS

input field: <remove tick mark> to use it as read only field

table-control:

name: MY_TBL_CTRL

seperators: vertical, horizontal <select tick mark>

Prepared by PEERS TECHNOLOGIES PVT LTD, HYDERABAD Page 105


PEERS – SAP ABAP
Note: [it is used to display table contents during runtime]

click on ‘Dictionary/program fields window (F6)’ icon on the tool-bar.

enter ‘ZAJDEPT’ in the Table/Field name text-box and press ‘ENTER’ key.

select fields.. DNO, DNAME by clicking on the extreme left button.

place the selected fields inside the table-control MY_TBL_CTRL

push-button:

name: INSERT

text: Insert_data

fctCode: INSERT

push-button:

name: UPDATE

text: Update_data

fctCode: UPDATE

push-button:

name: DELETE

text: Delete_data

fctCode: DELETE

push-button:

name: EXIT

text: Exit

fctCode: EXIT

12 Save, activate

13 click on Back(F3) icon to go back to program source code screen

14 Save, check, activate, Execute

15 Now you can insert, modify , delete data in your table ZAJDEPT [see step-1]

BDC: (Batch Data Communication) is used to MIGRATE data from SAP to SAP system or from a non-SAP
legacy-system to SAP system.

Prepared by PEERS TECHNOLOGIES PVT LTD, HYDERABAD Page 106


PEERS – SAP ABAP
Different methods of BDC are:

(a) Call-Transaction - method

(b) Session - method

(c) LSMW (Legacy System Migration Workbench) - tool

In all the above methods you have to prepare a flat file containing the data in the required format to be uploaded to the
SAP system. You need to call the function ' UPLOAD' to do this. Then the contents of the flat file have to copied to your
internal table and then u need to call the transaction through which you want to update the database. You internal table
should also have the information relating to the structure BDCDATA which is having the details like the module pool
program name, screen no. The basic concept of updating the database is same in all the 3 methods but only the method
differs.

In session method after the data transfer program is coded, in order to process that particular session you have to go to
TC: SM 35 to process the session.

BDC: Call-Transaction – method (migrate data from text file ‘c:\my.txt’ to table LFA1)

Steps Action

Note: to avoid obstacle during data migration process remember the following points..
a) view the destination table(LFA1) data before data migration [using SE16. see step-37]
b) for example, if the last record data in table:LFA1, field:LIFNR(vendor code) is 1600, then the
first value of the same field in data file ‘C:\MY.TXT’ should be 1602 (1600+2).
c) during recording process a set of data is entered through the screen, which also gets
inserted into the same table (LFA1). Ensure that LIFNR(vendor code) value during screen-
recording is given as 1601 (1600+1) [see step-6] and the same value does not exist in table
LFA1.
d) there should not be any duplicate data in LIFNR (it is a primary field with unique data)

** create data file:


1 [see step-37] to view content of table LFA1 before migrating the data
Create tab-separated text file (c:\my.txt) to store sample data:
1602 0001 0001 ANIL YR IN INR
1603 0001 0001 SAM AV IN INR
Note: 1st column data should not exist in table LFA1
1st column represents LIFNR(vendor code)
2nd column represents EKORG(purchase organization)
3rd column represents KTOKK(account group)
4th column represents NAME1(name)
5th column represents SORTL(search term)
6th column represents LAND1(country)
7th column represents WAERS(currency)

** Recording:
2 SHDB (transaction code for) Transaction Recorder: recording overview
3 Click ‘New recording’ on tool-bar
4 (in pop-up window..)
Recording: ZmyRec (give any name)

Prepared by PEERS TECHNOLOGIES PVT LTD, HYDERABAD Page 107


PEERS – SAP ABAP
Transaction code: MK01 (prepare a technical Log for MK01)
(Note: MK01 is the transaction-code for SAP standard data entry screen create vendor –
purchasing )
5 Click on ‘Start recording’
6 Vendor: 1601 (select a non-existing vendor code)
Purchase organization: 0001 (give any code)
Account group: 0001 (give any code)
Press ‘Enter’ key
Name: santanu
Search term: SN
Country: IN
Press ‘Enter’ key , ‘Enter’ key… to move to next page
Currency: INR
Press ‘Enter’ key
(Note: this record also gets inserted into table LFA1)
(provide data for mandatory fields…flagged with tick-marks)
7 Save(ctrl+S) , Save(ctrl+S) [technical Log is created] , Back(F3)
8 Recording: ZmyRec [see step-4] (select from List)
** generate program codes:
9 Click on ‘Program’ (shift+F5) on tool-bar
10 Program name: ZmyCallTrans (give any name)
Select radio-button ‘Transfer from recording’
Click ‘continue’ (tick-mark)
11 Title: BDC call transaction (enter any text)
Type: Executable program
12 Click on ‘Source Code’ (F5), ‘Local Object’
13 Auto generated program is displayed
14 Save , go back to initial screen by clicking ‘Back’(F3) few times
** program source codes (add/modify):
15 SE38 (transaction code for ABAP editor)
16 Program name appears (e.g. ZmyCallTrans) [see step-10]
17 Click on ‘Change’
18 (Add following codes after the line ‘report ZMYCALLTRANS …..’ )
*--- define source internal table
Data: begin of ITAB occurs 1,
F1 type LFA1-LIFNR,
F2 type LFA1-EKORG,
F3 type LFA1-KTOKK,
F4 type LFA1-NAME1,
F5 type LFA1-SORTL,
F6 type LFA1-LAND1,
F7 type LFA1-WAERS,
End of ITAB.
*--- create destination internal table
Data: JTAB type BDCDATA occurs 1 with header line.

19 Dbl. click on the line ‘Include BDCRECx1’


20 Click ‘YES’ in the pop-up box
21 Click on ‘Display’ (F7)
22 Copy last two code blocks, ‘Start new screen’, ‘Insert field’
23 Back(F3)

Prepared by PEERS TECHNOLOGIES PVT LTD, HYDERABAD Page 108


PEERS – SAP ABAP
24 Paste the copied blocks [see step-22+ after the line ‘perform close_group’
25 Place cursor just after the line ‘perform open_group’
26 Ctrl+F6 or Click on ‘Pattern’ (to select the function name and generate codes)
27 Call function: WS_UPLOAD , click on ‘continue’ (tick-mark)
Note: WS_UPLOAD (for 4.6c) , GUI_UPLOAD (for 4.7e)
If any Warning message-box appears, just click on Tick-mark
28 (Un-comment these 4 lines)
EXPORTING
Filename: ‘ C:\my.txt ‘ [see step-1] (Note: blank space before and after the file name)
Filetype: ‘DAT’ (for tab separated fields) (Note: in CAPS only)
Data_tab: ITAB [see step-23]
(you may delete the extra commented lines for readability. But not mandatory)
29 (Replace particular fields with Internal-table fields)
e.g.
perform bdc_field using 'RF02K-LIFNR'
ITAB-F1.
perform bdc_field using 'RF02K-EKORG'
ITAB-F2.
perform bdc_field using 'RF02K-KTOKK'
ITAB-F3.
perform bdc_field using 'LFA1-NAME1'
ITAB-F4.
perform bdc_field using 'LFA1-SORTL'
ITAB-F5.
perform bdc_field using 'LFA1-LAND1'
ITAB-F6.
perform bdc_field using 'LFM1-WAERS'
ITAB-F7.
30 (Delete following 5 lines..)
Include bdcrecx1.
Start_of_selection.
Perform open_group.
Perform bdc_transaction using ‘MK01’.
Perform close_group.
31 (Place cursor just before the 1st line of ‘perform bdc_ …..’ and add the following 2 lines)
LOOP AT ITAB.
REFRESH JTAB.
32 (Place cursor just after the last line of ‘perform bdc_ …..’ and add the following 2 lines)
CALL TRANSACTION 'MK01' USING JTAB MODE 'A'.
ENDLOOP.
33 (under the bottom 2 code-blocks ‘start new screen’ , ‘insert field’ , Replace all…)
BDCDATA with JTAB
34 (under the bottom code-block ‘insert field’ , Replace …)
NoData with ‘ ‘ or SPACE
35 Save , Check , Activate, continue(tick-mark) , Execute , Continue (tick-mark) in pop up box
36 Click on ‘Enter’ key many times (still the recording procedure is complete).
** view contents of Table LFA1:
37 (Note: use steps 37-40 to view data before and after migration)

SE16 (transaction code) to view newly migrated data from file ‘C:\my.txt’ [see step-1]
38 Table name: LFA1 , click on ‘Table Contents’ icon (F7)

Prepared by PEERS TECHNOLOGIES PVT LTD, HYDERABAD Page 109


PEERS – SAP ABAP
39 Cno: 1600 to 1650 (enter any vendor-code range) [this step is optional]
40 Execute
Note: ** completed program should look like this:
Report ZMYCALLTRANS no standard page heading line-size 255.
*--- define source internal table
data: begin of ITAB occurs 1,
F1 type LIFNR,
F2 type EKORG,
F3 type KTOKK,
F4 type NAME1,
F5 type SORTL,
F6 type LAND1,
F7 type WAERS,
end of ITAB.
*--- create destination internal table
data: JTAB type BDCDATA occurs 1 with header line.
*--- upload source data from flatfile to source internal table
CALL FUNCTION 'WS_UPLOAD'
EXPORTING
FILENAME = ' C:\MY.TXT '
FILETYPE = 'DAT'
TABLES
DATA_TAB = ITAB.
LOOP AT ITAB.
REFRESH JTAB.
perform bdc_dynpro using 'SAPMF02K' '0107'.
perform bdc_field using 'BDC_CURSOR'
'RF02K-KTOKK'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
perform bdc_field using 'RF02K-LIFNR'
ITAB-F1.
perform bdc_field using 'RF02K-EKORG'
ITAB-F2.
perform bdc_field using 'RF02K-KTOKK'
ITAB-F3.
perform bdc_dynpro using 'SAPMF02K' '0110'.
perform bdc_field using 'BDC_CURSOR'
'LFA1-DATLT'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
perform bdc_field using 'LFA1-NAME1'
ITAB-F4.
perform bdc_field using 'LFA1-SORTL'
ITAB-F5.
perform bdc_field using 'LFA1-LAND1'
ITAB-F6.
perform bdc_dynpro using 'SAPMF02K' '0120'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
perform bdc_dynpro using 'SAPMF02K' '0310'.
perform bdc_field using 'BDC_CURSOR'

Prepared by PEERS TECHNOLOGIES PVT LTD, HYDERABAD Page 110


PEERS – SAP ABAP
'LFM1-WAERS'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
perform bdc_field using 'LFM1-WAERS'
ITAB-F7.
perform bdc_dynpro using 'SAPMF02K' '0320'.
perform bdc_field using 'BDC_CURSOR'
'RF02K-LIFNR'.
perform bdc_field using 'BDC_OKCODE'
'=UPDA'.
CALL TRANSACTION 'MK01' USING JTAB MODE 'A'.
ENDLOOP.
*----------------------------------------------------------------------*
* Start new screen *
*----------------------------------------------------------------------*
FORM BDC_DYNPRO USING PROGRAM DYNPRO.
CLEAR JTAB.
JTAB-PROGRAM = PROGRAM.
JTAB-DYNPRO = DYNPRO.
JTAB-DYNBEGIN = 'X'.
APPEND JTAB.
ENDFORM.
*----------------------------------------------------------------------*
* Insert field *
*----------------------------------------------------------------------*
FORM BDC_FIELD USING FNAM FVAL.
IF FVAL <> SPACE.
CLEAR JTAB.
JTAB-FNAM = FNAM.
JTAB-FVAL = FVAL.
APPEND JTAB.
ENDIF.
ENDFORM.

Note: for subsequent data transfer follow the steps below:


a) change the data in file (c:\my.txt) [see step-1]
b) create a fresh recording with new set of data [step2 – step7]
c) execute the progra ZmyCallTrans [see step-15,16]
d) view the newly inserted data in table LFA1 [step37 - step40]

BDC: Session - method

Steps Action

Note: to avoid obstacle during data migration process remember the following points..

a) view the destination table(LFA1) data before data migration [using SE16]

b) for example, if the last record data in table:LFA1, field:LIFNR(vendor code) is 1600, then the
first value of the same field in data file ‘C:\MY.TXT’ should be 1602 (1600+2).

c) during recording process a set of data is entered through the screen, which also gets

Prepared by PEERS TECHNOLOGIES PVT LTD, HYDERABAD Page 111


PEERS – SAP ABAP
inserted into the same table (LFA1). Ensure that LIFNR(vendor code) value during screen-
recording is given as 1601 (1600+1) [see step-25]and the same value does not exist in table
LFA1.

d) there should not be any duplicate data in LIFNR (it is a primary field with unique data)

*** Same as BDC-Call transaction. (just add the following steps) ***

1 Create tab-separated text file (c:\my.txt) to store sample data:

1602 0001 0001 ANIL YR IN INR


1603 0001 0001 SAM AV IN INR

Note: 1st column data should not exist in table LFA1


1st column represents LIFNR(vendor code)
nd
2 column represents EKORG(purchase organization)
rd
3 column represents KTOKK(account group)
4th column represents NAME1(name)
5th column represents SORTL(search term)
6th column represents LAND1(country)
7th column represents WAERS(currency)

2 SE38
3 Program: ZmySessionTrans (enter any name)
4 Create
5 Title: my BDC session transaction (enter any text)
Type: Executable Program
6 Save , LocalObject
7 Copy and paste entire Call-transaction program codes already done.
8 Place cursor just before the line ‘Loop at ITAB’
** call function BDC_OPEN_GROUP:
9 Ctrl+F6 or Click on ‘Pattern’ (to select the function name and generate codes)
10 Call function: BDC_OPEN_GROUP , click on continue (tick mark)
11 (Un-comment following 4 lines)
EXPORTING
Client = sy-mandt (Note: represents login ClientNumber. e.g. ‘800’)

Group = ‘mySession’ (Note: represents SessionName) [give


any name]
User = sy-uname (Note: represents login UserName. e.g.
‘sapuser’)
12 Place cursor just before the line ‘ENDLOOP’
** call function BDC_INSERT:
13 Ctrl+F6 or Click on ‘Pattern’
14 Call function: BDC_INSERT , click on continue (tick mark)
15 (Un-comment following 3 lines)

EXPORTING

Prepared by PEERS TECHNOLOGIES PVT LTD, HYDERABAD Page 112


PEERS – SAP ABAP
Tcode = ‘MK01’
DynProTab = JTAB
16 Place cursor after the line ‘ENDLOOP’
** call function BDC_CLOSE_GROUP:
17 Ctrl+F6 or Click on ‘Pattern’
18 Call function: BDC_CLOSE_GROUP , click on continue (tick mark)
19 Save , Check , Activate, continue(tick-mark) , Back(F3), Back(F3)
**Start Recording:
20 SM35 (transaction code for Session Manager)
21 Click ‘Recording’ (ctrl+F8) on tool bar
22 Click ‘New recording’ on tool-bar
23 (in pop-up window..)
Recording: ZmyRec (give any name)
Transaction code: MK01 (prepare a technical Log for MK01)

(Note: MK01 is the transaction-code for SAP standard data entry screen create vendor –
purchasing )
24 Click on ‘Start recording’
25 Vendor: 1601 (select a non-existing vendor code)
Purchase organization: 0001 (give any code)
Account group: 0001 (give any code)
Press ‘Enter’ key
Name: santanu
Search term: SN
Country: IN
Press ‘Enter’ key , ‘Enter’ key… to move to next page
Order Currency: INR

Press ‘Enter’ key

(Note: this record also gets inserted into table LFA1)


(provide data for mandatory fields…flagged with tick-marks)
Create and Schedule JOB
26 SM36
27 Job name: MyJOB
28 Click ‘Enter’ key
29 Click on ‘ABAP Program’
30 Name: ZmySession [see step-3]
Language: en (default)
31
Save (ctrl-S)
32 Click on ‘Job Selection’ (shift-F1) on menu-bar
33 Job name: MyJOB
User name: SAPUSER (default)
34 Set values for..
FROM-DATE , TO-DATE
FROM-TIME , TO-TIME
Select necessary checkboxes: JobStatus:- tickmark on [Scheduled] checkbox
(remove tickMarks from other checkBoxes)
ABAP program name: ZmySession [see step-3]

Prepared by PEERS TECHNOLOGIES PVT LTD, HYDERABAD Page 113


PEERS – SAP ABAP
35
Execute
36 Job is now submitted as SCHEDULED for timebound execution (but not Released yet)
37 NOTE: if you want to RELEASE the job immediately..follow the steps below..
a) select the JOB from the List by clicking on the left-most button
b) click on Release (ctrl-shift-F10)on the tool-bar
c) Click on Immediate button in the pop-up window,
d) click on Save

BDC: LSMW (Legacy System Migration Workbench) - tool

The LSMW comprises the following main steps:


 Read data (legacy data in spreadsheet tables and/or sequential files).
 Convert data (from the source into the target format).
 Import data (to the database used by the R/3 application).
But, before these steps, you need to perform following steps :

 Define source structure : structure of data in the source file.


 Define target structure : structure of SAP that receives data.
 Field mapping: Mapping between the source and target structure with conversions, if any.
 Specify file: location of the source file

List of Radio-buttons:

1. Maintain object attributes


2. Maintain source structures
3. Maintain source fields
4. Maintain structure relations
5. Maintain field mapping and conversion rules
6. Maintain fixed values, translations, user-defined routines
7. Specify files
8. Assign files
9. Import data
10. Display imported data
11. Convert data
12. Display converted data
13. Create batch input session
14. Run batch input session
Steps Action

Note: to avoid obstacle during data migration process remember the following points..

a) view the destination table(LFA1) data before data migration [using SE16. see step-95]

b) for example, if the last record data in table:LFA1, field:LIFNR(vendor code) is 1600, then the
first value of the same field in data file ‘C:\MY.TXT’ should be 1602 (1600+2).

c) during recording process a set of data is entered through the screen, which also gets
inserted into the same table (LFA1). Ensure that LIFNR(vendor code) value during screen-
recording is given as 1601 (1600+1) [see step-20] and the same value does not exist in table
LFA1.

Prepared by PEERS TECHNOLOGIES PVT LTD, HYDERABAD Page 114


PEERS – SAP ABAP
d) there should not be any duplicate data in LIFNR (it is a primary field with unique data)

1 ** create data file C:\MY.TXT:


Create tab-separated data file C:\MY.TXT

1602 0001 0001 ANIL YR IN INR


1603 0001 0001 SAM AV IN INR

Note: 1st column data should not exist in table LFA1


st
1 column represents LIFNR(vendor code)
nd
2 column represents EKORG(purchase organization)
3rd column represents KTOKK(account group)
th
4 column represents NAME1(name)
5th column represents SORTL(search term)
6th column represents LAND1(country)
7th column represents WAERS(currency)

2 ** create fields file C:\MYFIELDS.TXT:


Create a file ‘C:\myfields.txt’ in NOTEPAD with following fields:
LIFNR
EKORG
KTOKK
NAME1
SORTL
LAND1
WAERS
1 LSMW (transaction code)
2 On menu-bar, EDIT  Create Entry
** Define Project, subProject, Object:
3 Project: MyPROJ (give any name)
Description: (enter any text)
4 Click on ‘continue’ (tick-mark)
5 Sub project: MySUB (give any name)
Description: (enter any text)
6 Click on ‘continue’ (tick-mark)
7 Object: MYSESSION (enter any session name)
Name: (enter any text)
8 Click on ‘continue’ (tick-mark)
9 Click ‘Continue’ (F8) icon on tool-bar
1. [Maintain Object Attributes] :
10 Select 1st radio-button, ‘Maintain Object Attributes’
11 ‘Execute’ (ctrl-F8) on tool-bar
12 Click ‘Display/Change’ (ctrl-F1) icon on tool-bar
13 Select radio-button, ‘Batch Input Recording’
14 Click on ‘Recordings Overview’ icon (or)
on menu-bar, GOTO  Recordings Overview (or) [shift+F9]
15 Click ‘Create Recording’ (ctrl-F1) icon on tool-bar
16 Recording: ZmyREC (give any name)
Description: (enter any text)
17 Click on ‘continue’ (tick-mark)

Prepared by PEERS TECHNOLOGIES PVT LTD, HYDERABAD Page 115


PEERS – SAP ABAP
18 Transaction code: MK01

(Note: MK01 is the transaction-code for SAP standard data entry screen create vendor –
purchasing )
19 Click on ‘continue’ (tick-mark)
20
Vendor: 1601 (select a non-existing vendor code)
Purchase organization: 0001 (give any code)
Account group: 0001 (give any code)

Press ‘Enter’ key

Name: santanu
Search term: SN
Country: IN

Press ‘Enter’ key , ‘Enter’ key… to move to next page

Order Currency: INR

Press ‘Enter’ key


(Note: this record also gets inserted into table LFA1)
(provide data for mandatory fields…flagged with tick-marks)
21 Click ‘Enter’ key
22
Save (ctrl+S)
23
24 A ‘create recording’ tree-structure appears
25 click Place the cursor on top-right empty block (of RF02K-LIFNR or RF02K-KTOKK)
26 Click on ‘Default All’ (ctrl-F2) on tool bar to pre-populate the field values & labels
27
28 Save , Back(F3) , Back(F3)
29 Recording: ZmyREC [see step-16]
30 Save , Back(F3)
2. [Maintain Source Structures ] :
31 Select 2nd radio-button, ‘Maintain Source Structures’
32 Click Execute (ctrl-F8) on tool-bar
33 Click ‘Display/Change’ (ctrl-F1) icon on tool-bar
34 Click ‘Create a structure’ (ctrl-F4) icon on tool-bar
35 Source structure: ZmySRC (give any name)
Description: (enter any text)
36 Click on ‘continue’ (tick-mark)
37 Save , Back(F3)
3. [Maintain Source Fields] :
rd
38 Select 3 radio-button, ‘Maintain Source Fields’
39 Click Execute (ctrl+F8)
40 Click ‘Display/Change’ (ctrl-F1) icon on tool-bar
41 Place cursor(click) on ‘ZmySRC’ *see step-34]
42 On menu-bar, SourceFields  CopyFields
43 Select radio-button, ‘Upload’
44 Click on ‘continue’ (tick-mark) , Click on ‘continue’ (tick-mark)

Prepared by PEERS TECHNOLOGIES PVT LTD, HYDERABAD Page 116


PEERS – SAP ABAP
45 Select the FIELDS file ‘C:\myfields.txt’ *see step-2] to pre populate fieldlength, type
(select file in the file-browser window and click ‘Open’)
46 Save , Back(F3)
4. [Maintain Structure Relations] :
47 Select 4th radio-button, ‘Maintain Structure Relations’
48 Click Execute (ctrl+F8)
49 Click ‘Display/Change’ (ctrl-F1) icon on tool-bar
50 Save , Back(F3)
5. [Maintain Field Mapping & Conversion Rules] :
th
51 Select 5 radio-button, ‘Maintain Field Mapping & Conversion Rules’
52 Click Execute (ctrl+F8)
Fields-tree appears
53 Click ‘Display/Change’ (ctrl-F1) icon on tool-bar
54 Place cursor just beside the first ‘I’ icon (NOT on the icon) and click
55 On menu-bar, Extras  AutoFieldMapping
56 Click on ‘continue’ (tick-mark) in the pop-up box
57 Click on ‘Accept Proposal’ continuously until ‘autofield mapping’ is completed
58 Click on ‘continue’ (tick-mark)
59 Field tree-structure with recorded data appears
60 Save , Back(F3)
**Don’t use** 6. *Maintain fixed values, translations, user-defined routines] :
61 DON’T Select 6th radio-button, ‘Maintain fixed values, translations, user-defined routines’
7. [Specify Files] :
th
62 Select 7 radio-button, ‘Specify Files’
63 Click Execute (ctrl-F8)
64 Click ‘Display/Change’ (ctrl-F1) icon on tool-bar
65 Select(click) ‘Legacy Data on the PC(Front End)’
66 Click ‘Add entry’ (ctrl-F2) icon on tool-bar
67 File: C:\my.txt [see step-1]
Name: my Flat File (give any name)
Select radio-button, ‘Tabulator’ (under heading ‘Separators’) *for Tab separated data file]
68 Click on ‘continue’ (tick-mark)
69 Save , Back(F3)
8. [Assign Files] :
th
70 Select 8 radio-button, ‘Assign Files’
71 Click Execute (ctrl-F8)
72 Click ‘Display/Change’ (ctrl-F1) icon on tool-bar
73 Save , Back(F3)
9. [Import Data] :
74 Select 9th radio-button, ‘Import Data’
75 Click Execute (ctrl-F8) , Execute (F8) , Back(F3), Back(F3)
10. [Display Imported Data] :
76 Select 10th radio-button, ‘Display Imported Data’
77 Click Execute (ctrl-F8) , Click on ‘continue’ (tick-mark) , Back(F3)
11. [Convert Data] :
78 Select 11th radio-button, ‘Convert Data’
79 Click Execute(ctrl-F8) , Execute(F8) , Back(F3) , Back(F3)
12. [Display Converted Data] :
th
80 Select 12 radio-button, ‘Display Converted Data’
81 Click Execute(ctrl-F8) , Click on ‘continue’ (tick-mark) , Back(F3)

Prepared by PEERS TECHNOLOGIES PVT LTD, HYDERABAD Page 117


PEERS – SAP ABAP
13. [Create Batch Input Session] :
82 Select 13th radio-button, ‘Create Batch Input Session’
83 Click Execute(ctrl-F8) , Execute(F8) , Click on ‘continue’ (tick-mark) in pop-up box
14. [Run Batch Input Session] :
84 Select 14th radio-button, ‘Run Batch Input Session’
85 Click Execute(ctrl-F8)
86 Select the ‘Session name’ MYSESSION from the list [see step-7]
(select entire row by clicking on extreme left corner button)

[Note: it will be in NEW state]


87 Click ‘Process’ *process session+ (F8) on tool-bar
88 Select radio-button, ‘Process/Foreground’
89 Click on ‘Process’ (enter) in the pop-up window
90 Press ‘Enter’ key (or click ‘tick-mark’) continuously until ‘session overview’ pop-up appears
with message ‘processing of batch input session completed’
91 click on ‘session overview’ or ‘exit batch input’
** Data Migration COMPLETED **
92 LOG --to view the session log-book [this step is optional]

Click ‘Log’ (F7) on tool-bar ,


Now select the session name by clicking on the left-most button ,
Click on ‘Display’ (F2) on tool-bar
93 ANALYSIS – to view analysis report [this step is optional]

select the session name by clicking on the left-most button ,


Click ‘Analysis’ (‘Analyze Session’ F2) on tool-bar
94 STATISTICS –to view the statistics [this step is optional]

select the session name by clicking on the left-most button ,


Click ‘Statistics’ (shift- F1) on tool-bar
** view table data:
95 SE16
96 Table name: LFA1 , click on ‘Table Contents’ icon (F7)
enter a range of LIFNR values (e.g. 1600 to 1650) [optional]
97 click Execute (F8) on tool-bar

Note: for subsequent data migration from the same data file ‘C:\MY.TXT’(with different sets of data)
into the same destination table(LFA1), just follow the steps from step-74 onwards

RFC: Remote Function – Creation (1a)

Steps Action
1 SE37 (transaction code for Function-Builder)
2 GoTo (on menu bar)
3 Function Groups
4 Create Group
5 function group: zmygrp
short description: my function group
6 click on tick-mark
7 Local object

Prepared by PEERS TECHNOLOGIES PVT LTD, HYDERABAD Page 118


PEERS – SAP ABAP
8 Function module: ZmyFunc
9 Create
10 Function module: ZmyFunc [see step-8]
Function group: zmygrp [see step-5]
Short description: my sample RFC (give any text)
11 Save , ‘Local object’
12 Click on ATTRIBUTE(tab)
Select radio-button ‘Remote-enable module’
** IMPORT(tab):
13 Click on IMPORT(tab)
Parameter names type associated type pass value **(mandatory)
X type i tick (select)
Y type i tick (select)
** EXPORT(tab):
14 Click on EXPORT(tab)
Parameter names type associated type pass value **(mandatory)
Z type i tick (select)
** SOURCE CODE (tab):
15 Click on SOURCE CODE(tab)
…Enter the logic…
z = x + y.
16 Save , Check , Activate , Continue , Execute
17 Enter test data values for x , y
18 Click ‘Execute’ (F8) to test the function

RFC: Remote Function Call - function call (1a)

Steps Action
1 SE38 (transaction code for ABAP editor)
2 Program name: ZmyRFC
Create
3 Executable
Short description: santanu’s RFC
Type: executable program
4 Save , ‘Local object’
5 Data: a type i, b type i, c type i.
(or)
Parameters: a type i, b type i.
Data: c type i.

a = 10. b = 5.
6 Click on ‘Pattern’ ctrl+F6to generate function code
Select radio-button ‘Call function:’ and enter function name ZmyFunc [see RFC function
creation step-8]
7 Continue
8 Call function ‘Zmyfunc’ destination ‘NONE’
Exporting
X = a
Y = b
Importing

Prepared by PEERS TECHNOLOGIES PVT LTD, HYDERABAD Page 119


PEERS – SAP ABAP
Z = c.
Write: / c.

NOTE: add statement destination ‘NONE’ to test the remote function call in local system. In real
life use the remote computer name. e.g destination ‘HONGKONG’
9 Save , check, activate, execute

IDOC (Intermediate DOCument)

- IDOCs are data containers


- IDOCs are text fields in a specific format as specified by ANSI or ‘EDIFACT’
- IDOCs are exchanged between 2 business systems that can understand and process IDOCs
- IDOCs are used in ALE and EDI integration
- IDOC types are: a) designed components or, b) templates
- IDOCs are runtime components available only during execution
- IDOCs are used to exchange data for ALE
- IDOCs are used to exchange data for EDI
- IDOCs are runtime objects instantiated from the IDOC TYPEs

IDOC-TYPE (class)

IDOC (object)

Basic IDOC-TYPE (basic Base class)

Extended IDOC-TYPE (derived class - inheritance)

Note: each field structure should not exceed 100 bytes. An IDOC can have any number of SEGMENTs, but atleast one
SEGMENT should be mandatory

IDOC-TYPE

|------ SEGMENT

|------ segment definition (segment name)

|------ segment fields (defined with data elements e.g. KUNNR, …. )

|------ segment documentation (document available with data element)

Prepared by PEERS TECHNOLOGIES PVT LTD, HYDERABAD Page 120


PEERS – SAP ABAP
Process to define IDOC:

Step1: define ‘SEGMENT’ (transaction code WE31)

Step2: create ‘IDOC TYPE’ and attach ‘SEGMENT’ (transaction code WE30)

Step3: release ‘SEGMENT’ (transaction code WE31)

Step4: release ‘IDOC TYPE’ (transaction code WE30)

Step5: define a ‘LOGICAL MESSAGE’ (transaction code WE81)

Step6: attach ‘IDOC TYPE’ to ‘LOGICAL MESSAGE’ (transaction code WE82)

Step7: view ‘IDOC TYPE’ documentation (transaction code WE60)

Steps Action
1 WE31
2 Segment type: ZmySEG (give any name)
3 Click on ‘Create’ icon (F5)
4 Short description: (enter any text)
5 Field name data element
CustNo kunnr
CustName name1
OrderNo vbeln-va
OrderValue netwer
6 Press ‘Enter’ key
7 Right most column gets filled with Field-lengths
8 Save , continue(tick mark) , ‘Local object’ , Back , back
9 WE30
10 Object name: ZmyOBJ (give any name)
11 Click on ‘Create’ icon (F5)
12 Select radi-button ‘Create new’ (default)
Short description:
13 Click on ‘continue’ (tick mark)
14 Select ‘ZmyOBJ’ from the list
15 Click on ‘Create’ icon (shift+F6)
16 A pop-up window appears
17 Segment type: ZmySEG
Select check-box ‘Mandatory Seg’
Minimum number: 10
Maximum number: 100
18 Continue(tick mark) , Save , ‘Local object’ , Back , Back
19 WE31
20 On menu-bar, select: EDIT  Set Release
21 Click on ‘Check’ (it will display segment consistency message)
22 Back , Back
23 WE30
24 On menu-bar, select: EDIT  Set Release
25 Click ‘Yes’ in the pop-up box
26 Click on ‘Check’ (it will display message: ZmyOBJ is released)

Prepared by PEERS TECHNOLOGIES PVT LTD, HYDERABAD Page 121


PEERS – SAP ABAP
27 Back , Back
28 WE81
29 Screen appears with list of Messages
30 Click on ‘Change’ icon (ctrl+F1)
31 Click on ‘continue’ (tick mark) in the pop-up box
32 Click on ‘New Entries’ (F5) on tool-bar
33 Message type short text
ZmyMSG (enter any name) santanu’s message (enter any text)
34 Click on ‘Create Request’ (F8) in the pop-up box
35 Short description: ZmyREQUEST (give any text)
36 Save , continue (tick mark) , Back , Back
37 WE82
38 Screen appears with list of Messages
39 Click on ‘Change’ icon (ctrl+F1)
40 Click on ‘continue’ (tick mark) in the pop-up box
41 Click on ‘New Entries’ (F5) on tool-bar
42 Message type basic type release
ZmyMSG [see step-33] ZmyOBJ [see step-10] 46c (for 4.6c, 47e for 4.7e)
43 Save
44 Click on ‘Continue’ in the pop-up box
45 Back , Back
46 WE60
47 Click on ‘Display Tree’ icon (F8)
Click on ‘Expand SubTree’ icon (optional)
Click on ‘Collapse SubTree’ icon (optional)
To have total tree view
48 Back
49 Click on ‘HTML’ (optional) to save data in HTML file.
Click on ‘Transport Data’ (F5) to Transport Data (Warning: DON’t try in local system)
Click on ‘C-header’ (optional) to save data as C-header file (visual .NET)
Click on ‘Parser’ (F9)(optional) to display documentation of IDOC record types, click on
‘DisplayErrorLog’ to show errors(if any)

IDOC: (sending/receiving)

Steps System1 (sending system) System2 (receiving system)


1 Select the data Receive the IDOC and store it
2 Extract selected data Extract data from IDOC
3 Instantiate IDOC-TYPE into IDOC object Transfer/use extracted data into respective
application
4 Fill the IDOC with extracted data
5 Provide partner information to IDOC
6 Push IDOC into communition network
7 =OUTBOUND PROCESS= =INBOUND PROCESS=

Prepared by PEERS TECHNOLOGIES PVT LTD, HYDERABAD Page 122


PEERS – SAP ABAP
IDOC: in runtime
Steps Action
1 IDOC-TYPE is instantiated into IDOC
2 One unique 16 character number is attached to IDOC within the client
3 One ‘control record’ is attached
4 SEGMENTs are translated into ‘data records’
5 ‘status records’ are attached on crossing each mile-stone of IDOC processing
6 Syntax rules are checked
7 ‘control record’ is just like address-envelope

ALE: (Application Linking Enabling)


- to distribute data, we have to replicate data
- 100% uptime should be assured
ALE configuration:

Steps Action
1 On ‘source system’
goto an application e.g. SALE
2 Under ‘sending system’ and ‘receiving system’ define the logical system by entering the
DESTINATION system name & SOURCE system name. These names must be saved in a
‘development class’ e.g. ZmyDEV’
3 Assign clients to ‘Logical client’
4 Select the clients that are going to act as source and destination system and change their names
accordingly. (client: 800, 810)
5 ‘Logical client’ assignment – completed--
6 Set the RFC destination and configure it
7 Use the RFC destination, if it exists.
8 Create a new destination, if it doesn’t exist.
9 Modelling and implementing business process:
10 Under this, maintain distributed model & distributed views by creating MODEL –VIEW and
MESSAGE-TYPE
11 Transport the MODEL-VIEW that is developed into a MODEL-VIEW class
12 Generate ‘partner profile’ by giving the ‘Logical system name’
13 NOTE: carry out the same procedure for the other ‘client system’

Reference Book: ‘configuring ALE and EDI’ – by Arvind Nagpal

EDI: (Electronic Data Interchange) - configuration

Steps Action
1 WE21 (transaction code: to create a port)
2 Name:
Desc:
Function module:
Outbound file name:
RFC destination name:
Command file name: CONVERTER_SRART
3 WE41 (transaction code: for OUTBOUND process)
4 Process code: ZmyOUTPROCESS
Description: santanu’s outbound process

Prepared by PEERS TECHNOLOGIES PVT LTD, HYDERABAD Page 123


PEERS – SAP ABAP
Or use..

WE42 (transaction code: for INBOUND process)


Process code: ZmyINPROCESS
Description: santanu’s inbound process
5 WE20 (transaction code: to create ‘partner profile’)
6 Partner number:
User:
Type:
Language:
Port:
7 Transfer IDOC
8 NACE (transaction code)
9 Select APPLICATION
10 Select TYPE
11 Click on ‘Execute’

BAPI : Business API (Application Program Interface)


Protocol:
SAP’s application model is ‘transaction’ model, where as Java/VB follows ‘object oriented’ model

Steps Action
1 BAPI (transaction code)
2 1. Cross application components
2. Accounting - general
3. Financial accounting
4. Treasury
5. Controlling
6. Investment management
7. Enterprise controlling
8. Real estate management
9. Logistics – general
10. Sales & Distribution (SD) – basic functions, sales, billing, sales support
11. Materials management (MM)
12. Logistics execution
13. Quality management (QM)
14. Plant maintenance (PM)
15. Customer service
16. Production planning & Control
17. Project system
18. Environment, Health & Safety
19. Personnel management (HR)
20. Personal Time management (HR)
21. Pay roll (HR)
22. Training (HR)
23. Basic component service
3 NOTE: SPRO (transaction code) for entering into MM, FICO, etc.
IMG (transaction code) for implementation guide
4 SW01 (transaction code) to create an object

Prepared by PEERS TECHNOLOGIES PVT LTD, HYDERABAD Page 124

You might also like