SBasic ABAP
SBasic ABAP
SAP-BASIC ABAP
NAME :B V Ashokkumar
INSTITUTE : RELIENCE GLOBAL SERVICES
AUTHOR : RAJA SHEKAR
PH : +91-9573050709
Ashokkumar
SAP-ABAP 2
INDEX
1 Introduction to ERP 5
2 Introduction to SAP R/3 6
3 SAP R/3 Services 8
4 Introduction to ABAP/4 & ABAP Work Bench Tools 10
5 ABAP Data types 12
6 ABAP Programming Structures 14
7 Steps to Write & Create SAP Program 16
8 Tips for Writing a Program in Real Time 19
9 Internal Table & difference between database table & internal table 20
10 Reading Data from Body to Work Area (or) Header Line 22
(1. LOOP….ENDLOOP, 2. READ)
11 Selection Screen (1. Select-options, 2. Ranges, 3. Parameters ) 26
12 Other SELECT-OPTIONS keywords (1. Obligatory, 2. No Intervals, 28
3. No-Extension, 4. No-Display)
13 Other Important Keywords for Internal Table (1. Append, 2. Sort, 3. Delete 31
Adjacent Duplicates, 4. Collect 5. Modify )
14 6. Deleting Data from Internal Table by (1. Fresh, 2. Refresh, 3. Clear, 4. Delete 36
)
15 7. Describe Keyword 37
16 8. Coping data b/w work areas (1. Move, 2. Move-Correspondig) 38
17 9. Coping data b/w internal tables (1. Loop…….Endloop, 2. Append Lines) 39
18 Control Break Statements (1. At First, 2. At Last, 3. At New, 4. At Change, 41
5. At End )
19 Insert keyword & Syntaxes for Internal Tables 45
20 System Fields for Internal Table 46
21 DML Operations on Database Table (insert, update, delete, modify keywords) 48
22 Types of Internal Tables 50
23 Data Dictionary (9 objects) 1. Database Table 51
24 2. Structure (.include & Append Structure) 55
25 3. View(Database view, Projection view) 58
26 4. Search Help (Elementary search help, Collective search help) 60
27 Table Maintenance Generator (TMG) (TCode, Default values, Check boxes) 63
28 Text Table 70
29 Some Important Steps for Working with Standard Tables 72
30 Types of Tables (Transparent, Cluster, Pooled Tables) 73
31 Open SQL Statements & Native SQL Statements 74
32 Buffering (Single Record, Generic, Full Buffering) 75
Ashokkumar
SAP-ABAP 3
33 MODULES(1. MM Module) 76
34 Inner Joins 79
35 Table Fields & Links (1. LFA1, 2. EKKO, 3. EKPO) 84
36 Message Handling 86
37 Modularization Techniques (5) 88
1. Subroutines (Internal Subroutine, External Subroutine)
38 Break Point (1. Static Break Point 2. Dynamic Break Point) 90
39 Pass by Value & Pass by Reference 91
40 Table Fields & Links (1. MKPF, 2. MSEG) 94
41 Function Module (1. Normal, 2. Remote Enabled, 3. ALv) 96
42 Include Program 100
43 Field Symbol 101
44 FOR ALL ENTRIES 103
45 Table Fields & Links (1. MARA, 2. MAKT, 3. TSPAT) 108
46 2. SD Module 109
47 String Operations (shift, translate, replace, strlen, offset functionality, split, 111
concatenate, condense)
48 Looping Statements (1. Conditional, 2. Unconditional) 115
49 CONTINUE, CHECK, EXIT keywords 118
50 Mathematical Operations (1. Frac, 2. Ceil 3. Floor, 4. Abs, 5. Rem, 6. Mod, 120
7. Sign, 8. Trunc, 9. Div )
51 SAP Memory & ABAP Memory 122
52 Support Project 125
53 System Landscape 126
54 Version Management 130
55 Sub Objects in ABAP Editor (1. Source Code, 2. Variants, 3. Attributes, 131
4. Documentation, 5. Text Elements)
56 Interview Questions ABAP Editor 133
57 Interview Questions Internal Tables 136
58 Interview Questions Data Dictionary 143
59 LFA1 Table 161
60 EKKO Table 162
61 EKPO Table 163
62 MKPF Table 164
63 MSEG Table 165
64 MARA Table 166
65 MAKT & TSPAT Tables 167
Ashokkumar
SAP-ABAP 4
Ashokkumar
SAP-ABAP 5
ERP
ERP:
Enterprise Resource Planning
ERP is a package under which all the business resources are integrated in one system
Enterprise-------organization
Resource--------FICO, HR, MM, PP, SD, CRM
Types of ERP:
1. High End ERP
2. Mid Range ERP
SAP R/3
Ashokkumar
SAP-ABAP 6
SAP R/3:
Systems, Applications, Products in data processing
R/3------ Real time 3 tier architecture
History:
SAP AG---- developed by 5 IBM employees in 1973----in woldoff (Germany)
SAP R/1(Finance)------1973
SAP R/2 (Mainframes)------1978
SAP R/3 (Client Server Technology)----1992
Systems:
These are basic resources for implementing a project
Examples:
Servers, Hardware, Soft ware, Systems, Network, Database………etc
BASIS Consultant:
Roles:
1. Installation
2. Maintenance
3. Configuration
4. Customization (or) Administration
Applications:
These are collection of Screens
Each Screen is a collection of Fields
Use---Applications are used by Clients (or) End Users
Create---Applications are created by Abapars (or) Technical Consultant (or) ABAP Consultant
Customized Data----Applications data customized by Functional Consultant
Functional Consultant:
Roles:
1. Customization of Data
2. Getting requirements from Clients
3. Preparing Functional Documents
4. Preparing End User Manuals (or) Snapshots
5. Providing end user Training
Products:
These are called Objects
Ashokkumar
SAP-ABAP 7
These are created by Programming
14-08-2014
Features of SAP:
1. Designed based on RDBMS
2. Designed based on R/3 Architecture
3. Database independent
4. Supports all types of industry specific solutions
5. International package available in 40 languages
6. It can be customized using ABAP language
7. Best ERP for FI, SD, MM, PP, HR, CR
8. Supports Client-Server Technology
9. Highly versatile (Operating System independent)
10.Supports web based application softwares
Spool Service
Dialog Update
Service Service
Note:
In real time once report is created, then it is scheduled in background by BASIS Consultants,
they will set time & event related to it
5. En-queue Service:
It maintains data integrity (locking mechanism) in SAP
6. Message Service:
It is for Error & Exception handling
7. Gateway Service:
It is for distributed environment
Note:
The above 7 services are part of Application Server
Versions in SAP:
Version Year
1.0 & 1.1 1991
2.0 & 2.1 1991
3.0 & 3.1 1992
4.0 1998
4.6A, 4.6B, 4.6C 2000
4.7EE 2003
ECC 5.0 2005 (ECC----Enterprise Core Component)
ECC 6.0 2006 (Present Working)
BI/BO 2008 (Business Independent)
CRM, SCM, PLM 2009 (Customer Relationship Management, Product Lifecycle
Management)
1. Production Software:
It is Real time
Every company should purchase this software from SAP
Here you will find only live data
Clients (End Users) are works with Production Software
2. IDES Software:
International Demonstration & Education System Software
It is also known as Training Software
Here you can find data for practice & examples for practice
Ashokkumar
SAP-ABAP 10
16-08-2014
ABAP/4
Advanced Business Application Programming 4th Generation Language
All SAP applications are designed & developed using ABAP Language
It is a high level language
Features of ABAP:
1. It was designed based on ‘C’ language
2. It is a platform independent language
3. It is a case insensitive language
4. It is database independent
5. It is truly business oriented language
6. It is rich in data types
7. It was designed based on Object Oriented Programming
8. It is an event driven programming language
9. It is highly user friendly
10.It supports web based applications also
2. ABAP Editor:
It works with Transaction Code (OR) T Code SE38 (System Engineering)
Here we can create & execute Programs
3. Screen Painter:
It works with Transaction Code (OR) T Code SE51 (System Engineering)
Here we can design Applications (OR) Screens
4. Class Builder:
It works with Transaction Code (OR) T Code SE24 (System Engineering)
It is for Object Oriented ABAP
5. Function Builder:
Ashokkumar
SAP-ABAP 11
It works with Transaction Code (OR) T Code SE37 (System Engineering)
Here we can work with Function Modules
6. Object Navigator:
It works with Transaction Code (OR) T Code SE80 (System Engineering)
Here we can create & modify the Objects & store the Objects
Note:
In Object Navigator you can develop all Objects in SAP
It is also known as a True ABAP Development Work Bench
Ashokkumar
SAP-ABAP 12
18-08-2014
ABAP Programming
ABAP Data Types:
ABAP data types are classified into 4 categories
They are:
1. Numeric
2. Character
3. String
4. Hexadecimal
1. Numeric:
These are classified into 3 categories
They are:
i) Integer (I)
ii) bPacked Decimal (P)
iii) Floating point (F)
i) Integer (I):
It holds integer values
Ex: 102, 55, 74, …..
2. Character:
These are classified into 3 categories:
They are:
i) Character (C)
ii) Date (D)
iii) Time (T)
i) Character (C):
It holds character value provided in ‘ ’ (single quotes)
Ashokkumar
SAP-ABAP 13
Note:
In ABAP programming the default data type is Character
ii) Date:
Use Date data type to store date values
The default SAP format for date is YYYYMMDD
iii) Time:
Use Time data type to store time values
The default SAP format for time is HHMMSS
3. String (String):
A group of characters combined to form a String
4. Hexadecimal (HX):
It is for SAP graphics management
Note:
QUAN, CURR, NUME are SAP provided business data types for storing Quantities,
Currencies & other Numeric values
Type Keyword:
It specifies the type of data an Object (Variable) can hold
Example:
1. Data ch type String --------hi, hello, how are you,………
2. Data cnt type I ------54, 1025, 748,…….
3. Data count type P values 2 -------145.22, 52.69,……
4. Data chr(10) type C ------ ‘a’, ‘h’,………
Data Keyword:
Using Data keyword Objects are defined in ABAP programming
Using Data keyword memory is allocated in buffer by system
Note:
Every Object (OR) Variable should be define using Data keyword
Ashokkumar
SAP-ABAP 14
Programming Structures:
These are 2 types
They are:
1. Pre defined Programming Structure
2. User defined Programming Structure
1. Work Area:
Work Area is a Structure (group of fields with different data types)
It holds only one single record during run time
Syntax: Chain Operator Name of Work Area (any name)
Data: Begin of wa_KNA1, { wa_table name (OR) w_table name is recommended }
Customer(10) type C,
Name(20) type C,
City(20) type C,
End of wa_KAN1. Period Symbol
Field Name
Note-1:
With above syntax during run time a Work Area wa_KNA1 is created in Application Server
Note-2:
Work Area name can be any name
In companies we have to follow Naming (Coding) standards while creating a program
According to these standards Work Area should always begins with w_ (OR) wa_
followed by Table Name
Note-3:
Every Object (Work Area) should be define with Data keyword
Note-4:
Every Programming Structure should begins with Begin of & ends with End of followed by
the Programming Structure name
Ashokkumar
SAP-ABAP 15
Note-5:
: is known as Chain Operator
It provides the repetition of the Declarative Part
Requirement:
Transfer Customer Master Data from Database Server to Application Server & from
Application Server to Presentation Server
Solution:
Select kunnr name1 ORT01 from KNA1 into wa_KNA1. ----- Data transfer from
Database Server to Application Server (Work Area)
Write:/10 wa_KNA1-Customer,
30 wa_KNA1-Name, data transfer from Work Area to Virtual Page then
60 wa_KNA1-City. Presentation Server
Endselect. ----------- it repeats the Select statement until records completed
Work Area
Virtual Page
Ashokkumar
SAP-ABAP 16
20-08-2014
Steps to write & execute SAP program:
Double click on SAP Logon on Desktop
You will find a Logon Pad
Double click on Development (121.241.50.175)
Provide Client: 800 (only for practice purpose)
User: user1 to user10
Password: Rgsabap
You will find SAP Easy Access screen (Screen 0)
On top of the screen you will find cursor blinking at Command Prompt (or)
Command Field. Here you should type Transaction Codes (T Codes) in real time
Next to Command Prompt you will find Standard Icons (Standard Application Tool
Bar). Here you cannot add Customized Icons
Under Standard Application Tool Bar you will find Text Area. It specifies
documentation of current application
Under Text Area you will find Customized Application Tool Bar when you can add
your own icons apart from Standard ones
Under Customize Application Tool Bar you will find Work Area where user performs
his tasks (or) navigations
Then press Enter you will find a pop-up here leave Package:___________ as blank
Click on Local Object button
Note-1:
In real time Objects needs to be transported from Development client to Testing client & from
Testing client to Production client. For that Objects should always be saved in a package. If an
Object is saved in Local Object it cannot be transported between clients (Non Transportable
Objects)
Note-2:
Local Object is meant for practicing Objects in real time
Note-3:
Ashokkumar
SAP-ABAP 17
All Executable Objects are Report Programs
Note-4:
On top of the program in Comment Section you should provide
1. Technical Consultant name
2. Functional Consultant name
3. Objective of the program
4. Transport Request number
5. Date of Creation (or) Change
Writing Program:
Report ZSD_Customer_Report -----------title of program
Ashokkumar
SAP-ABAP 18
Select Ctrl+F3 (or) Candle Icon to activate. You will find an Inactive Objects pop-up
then press Enter
With activation Objects are ultimately stored in Database Server
With activation Objects can be integrated with each other in SAP
21-08-2014
Debugging:- Work Area
Using debugging you can check (OR) test internal execution of a program
It is an important tool for testing programs in real time
Note:
/H is T Code for debugging
New Debugger:
Currently in real time we are working with only New Debugger
It is providing additional features compare to Old Debugger
Working:
Provide Program:_______ name
Select Debugging button
Select Desktop1 tab
Under Variable: type wa_kna1-customer, wa_kna1-name, wa_kna1-city & press Enter
Select F5 for single step debugging
Ashokkumar
SAP-ABAP 19
Tips for Writing a Program in Real Time:
1. Always start a program with Y (or) Z followed by Module name
Ex-1: MM module
ZMM_Material_Details
Ex-2: SD module
ZSD_Sales_Register
Ex-3: HR module
ZHR_Employee_Details
2. Provide Apt Title for a program
3. In real time always save the Object in a Package. But for practicing save Object in Local
Object
4. Provide Comments in a program wherever require
5. Try to write your program as Neat as possible
6. Try to write your program in Capital letters
7. Always select Pretty Printer (shift+F1) option after writing a program
8. Always Activate your program once it is created
Note:
Only activated programs can be debugged
Only activated programs can be integrated in SAP
Only activated programs can be transported between clients
Ashokkumar
SAP-ABAP 20
INTERNAL TABLES
2. Internal Table:
Internal table is a temporary table created in RAM in Application Server
It is created & filled with data during run time (execution time)
Once execution is performed it is rolled out (or) discarded
Note:
Use Internal table for storing multiple records during run time
Que: What is exact purpose of Internal table. Do you think should be created in ABAP
programming?
Ans: In real time we are creating Internal table for storing different types of application data
from different tables at one place
2. Header Line:
It is a default Work Area & holds single record
Note:
Header Line is system defined Work Area & Work Area is user defined Header Line
Syntax:
DATA: BEGIN OF it_kna1 OCCURS 0,
customer(20) TYPE C,
name(20) TYPE C,
city(20) TYPE C,
END OF it_kna1.
Ashokkumar
SAP-ABAP 21
Note:
1. With above syntax an Internal table it_kna1 is crated in Application Server
2. You can provide any name. But in real time Internal table should always begins with it_
(or) i_ followed by table name
3. With BEGIN option Header Line is created & OCCURS option Body is created
4. 0, 1, 2, 3, …..9 is called Size Category
5. Both Header Line & Body name is same (it_kna1)
Ashokkumar
SAP-ABAP 22
22-08-2014
Reading Data from Body to Work Area (or) Header Line:
1. LOOP ……….. ENDLOOP
2. READ keywords
Syntax:
LOOP AT it[INTO wa]
[FROM m][TO n]
[where codition].
…………
…………
ENDLOOP.
LOOP AT it:
Reads multiple records (record by record) from Body to Header Line
Note:
Internally system converts LOOP AT it as LOOP AT it INTO it.
Working:
Go to SE38
Program: ZSD_LOOPENDLOOP
Select Create option
Title; Internal Table
Type: Executable Program
Select Save option
Leave Package:__________ blank
Select Local Object option
Note;
Activate the program then select F8 to execute the program
Note:
You will find a Cap symbol which indicates Header Line (holds only single record)
Select F5 for single step debugging
Note:
1. Table keyword will transfer the data directly to Internal Table to Body
2. Always use Table keyword in select statement if you are working with Internal Tables
3. As long as you are in loop system will read next record in-line in an Internal Table.
Once the loop is terminated again the loop starts reading from 1st line
Working:
Go to SE38
Program: ZSD_INTERNAL_WORKAREA
Select Create option
Title: Internal Table & Work Area
Type: Executable Program
Select Save option
Leave Package:__________ blank
Select Local Object option
Ashokkumar
SAP-ABAP 24
Pg) REPORT ZSD_ INTERNAL_WORKAREA.
* provide internal table & work area
TYPES: BEGIN OF ty_kna1,
customer (20) TYPE C,
name(20) TYPE C,
city(20) TYPE C,
END OF ty_kna1.
DATA: wa_kna1 TYPE ty_kna1,
it_kna1 TYPE TABLE OF ty_kna1.
* provide extraction logic
SELECT kunnr name1 ort01 FROM kna1 INTO TABLE it_kna1.
* Appling processing logic
LOOP AT it_kna1 INTO wa_kna1.
WRITE:/10 wa_kna1-customer,
30 wa_kna1-name,
60 wa_kna1-city.
ENDLOOP.
Note:
1. Using TABLE OF you can create your own body
2. Using TYPES keyword Structures are created in ABAP programming
3. In ABAP programming always create Objet (Work Area & Body) based on Structures
4. Avoid creating Internal Table with OCCURS clause
Example:
1. LOOP AT it INTO wa FROM 100.
2. LOOP AT it INTO wa FROM TO 50.
3. LOOP AT it INTO wa FROM 100 TO 200.
Ashokkumar
SAP-ABAP 25
23-08-2014
2. READ:
It reads a single record from Body to Header Line (or) Work Area
Syntax:
READ TABLE it[INTO wa]
[INDEX n][WITH KEY keyexpression]
[TRANSPORTING fieldname]
[Binary Serach]
Binary Search:
It reads data from Body to Work Area based on binary search algorithm
Note:
1. Use binary search if Internal table is larze
2. Data should be sorted before Appling binary search algorithm
3. There should be no duplicate records in Internal Table
4. Binary search algorithm improves performance of programming
Ashokkumar
SAP-ABAP 26
SELECTION-SCREEN:
Using Selection Screen you can create a selection screen based on given requirement (Input
Values, Radio Buttons, Check Boxes…………..)
Input Values:
1. You can create with ------ Select-Options
2. You can create with ------ Parameters
3. You can create with ------ Ranges
1. SELECT-OPTIONS:
Using select-options you can create a selection screen with range of input values
Syntax:
SELECT-OPTIONS: s_kunnr for kna1-kunnr.
With above syntax system will create a selection screen in the following manner
With above syntax system will create an implicit Internal Table with following fields
Low High Sign Option
100 200 I (including) BT (between)
Note:
The default comparison operator for select-options in ‘IN’
Text Elements:
Using text elements (text-000 to text-009) you can provide field labels in selection screen
Double click on Text-000
You will find a pop-up Yes
Provide Text: Enter Customer Code
Select Selection Texts tab
Provide Text: Customer Code
Activate the screen (Ctrl+F3)
Go to back (F3)
Note:
Using Tables work area system will create a Work Area with all the fields of kna1 table. In
programming it is mandatory to declare for declaring select-options
Ashokkumar
SAP-ABAP 28
25-08-2014
Other SELECT-OPTIONS keywords:
i) OBLIGATORY
ii) NO INTERVALS
iii) NO-EXTENSION
iv) NO-DISPLAY
i) OBLIGATORY:
Using this addition you can make selection screen fields as Mandatory
Syntax:
SELECT-OPTIONS: s_kunnr FOR kna1-kunnr OBLIGATORY.
ii) NO INTERVALS:
Using no intervals you can remove high option from selection screen input field with select-
options
Syntax:
SELECT-OPTIONS: s_kunnr FOR kna1-kunnr NO INTERVALS.
iii) NO-EXTENSION:
With this addition Multiple Selections option is removed from selection screen with select-
options
Syntax:
SELECT-OPTIONS: s_kunnr FOR kna1-kunnr NO-EXTENSION.
iv) NO-DISPLAY:
With this addition selection screen input field will be hidden mode
Syntax:
SELECT-OPTIONS: s_kunnr FOR kna1-kunnr NO-DISPLAY.
2. PARAMETERS:
Using parameters you can create a selection screen with single input value
Syntax:
PARAMETERS p_kunnr TYPE kunnr. (or)
PARAMETERS p_kunnr LIKE kna1-kunnr.
Note:
1. With above syntax system will define (or) create a selection screen in the following
manner
Ashokkumar
SAP-ABAP 30
Pg) * provide tables work area
TABLES kna1.
* provide objects
DATA: BEGIN OF wa_kna1,
customer(20) TYPE C,
name(20) TYPE C,
city(20) TYPE C,
END OF wa_kna1.
Note:
1. If you are not providing SINGLE addition with PARAMETERS for fletching a single
record then it is mandatory to provide ENDSELECT
2. In real time never use SELECT with ENDSELECT (it reduces performance of the
program)
3. RANGES:
It work similar to SELECT-OPTIONS
Syntax:
RANGES s_kunnr FOR kna1-kunnr.
Note:
In new versions RANGES keyword is not allowed (it is out dated)
Ashokkumar
SAP-ABAP 31
Other Important Keywords for Internal Table:
1. APPEND keyword:
It appends record from Work Area to Body
Syntax:
APPEND wa TO it.
2. SORT keyword:
It sorts Internal Table Body data based on ascending (or) descending
Syntax:
SORT <it> BY <field1> ASCENDING (or) DESCENDING
Note:
The default order of sorting is ASCENDING
Note:
Before Appling above keyword it is mandatory to sort Internal Table
26-08-2014
4. COOLECT Keyword:
It provides summarized representation of data in an Internal Table
Note:
COLLECT checks the data based on Key Field (Character Field) in an internal table Body, if
the record is not existing it will performs Append job, if it is already existing it will Add
(Collects) Numeric Values based on Character Field inside the Body.
Syntax:
COLLECT wa INTO it.
Ques-3: Suppose there are more than one Character Fields then what is the rollback of
COLLECT keyword?
Ans: If there are two (or) more than two Character Fields it will Collect (add) the data only
when both the Character Fields are same
5. MODIFY keyword:
This keyword modifies Internal Table’s Body data based on given requirement
Syntax:
MODIFY it FROM wa [TRANSPORTING <field1> <filed2> ……..]
[INDEX n]
[WHERE condition]
Note:
1. Always provide MODIFY with in LOOP………..ENDLOOP of the Internal Table
which you want to modify
2. If you are providing MODIFY outside LOOP……..ENDLOOP then INDEX addition
(or) WHERE condition is mandatory
Ashokkumar
SAP-ABAP 36
6. Deleting Data from Internal Table:
i) FREE
ii) REFRESH
iii) CLEAR
iv) DELETE
i) FREE:
It deletes Internal Table’s Body data along with memory
Syntax:
FREE it. (where it is Internal Table name)
ii) REFRESH:
It deletes Internal Table’s Body data but memory will not be affected
Syntax:
REFRESH it.
iii) CLEAR:
It deletes 1. Body data------- CLEAR it[ ].
2. Work Area data------- CLEAR wa.
3. Ordinary Variable data --------- CLEAR total.
Note:
CLEAR it[ ] is applicable only where Internal Table is created with OCCURS clause
Example:
1. CLEAR it[ ]. ------- deletes Header Line’s data
2. CLEAR it. -------- deletes Body’s data
iv) DELETE:
It deletes Body data based on requirement
Syntax:
DELETE it [INDEX n]
[FROM m] [TO n]
[WHERE condition]
Example:
1. LOOP AT it INTO wa.
DELETE it.
ENDLOOP.
2. DELETE it INDEX 5.
27-08-2014
Ashokkumar
SAP-ABAP 37
7. DESCRIBE keyword:
It returns the Count of number of records in an Internal Table
Syntax:
DATA n TYPE I.
DESCRIBE TABLE it LINES n.
Example:
DATA: BEGIN OF wa,
material(20) TYPE C,
quan TYPE I,
END OF wa.
DATA it LIKE TABLE OF wa.
DATA n TYPE I.
wa-material = ‘F001’.
wa-quan = 50.
APPEND wa TO it.
wa-material = ‘F002’.
wa-quan = 150.
APPEND wa TO it.
wa-material = ‘F001’.
wa-quan = 250.
APPEND wa TO it.
wa-material = ‘F002’.
wa-quan = 350.
APPEND wa TO it.
DESRIBE TABLE it LINES n.
WRITE n.
Ashokkumar
SAP-ABAP 38
8. Coping Data between Work Areas:
i) MOVE keyword:
It transfers (or) moves data from one Work Area to another Work Area if the Structures are
same.
Example:
MOVE wa TO wa1.
Note:
In real time avoid using MOVE-CORRESPONDING
instead use wa1-material = wa-material.
wa1-quan = wa-quan.
Ashokkumar
SAP-ABAP 39
9. Coping Data between Internal Tables:
i) LOOP AT it INTO wa.
APPEND wa TO it1.
ENDLOOP.
Ques: What will happened if CLEAR is provided before WRITE & the same CLEAR is
provided after WRITE?
Ans: If CLEAR is provided before WRITE statements it will clear Work Area data so nothing
is transformed from Work Area to Virtual page (Hence no output)
If CLEAR is provided after WRITE statements data is transformed from Work Area to
Virtual page then Work Area is cleared (Hence you will find output list)
Ashokkumar
SAP-ABAP 41
28-08-2014
Control Break Statements:- (Events)
1. AT FIRST
2. AT LAST
3. AT NEW
4. AT END OF
5. ON CHANGE OF
Using these statements you can control the flow of ABAP programming statement with in the
LOOP……………ENDLOOP
AT FIRST:
It triggers during first loop iteration (first loop pass)
Syntax:
AT FIRST.
------------
-----------
ENDAT.
Note:
Use AT FIRST for providing Headers in ABAP Report
AT LAST:
It triggers for last line of an Internal Table (or) It triggers during last loop iteration
Syntax:
AT LAST.
------------
-----------
ENDAT.
Note:
Use AT LAST for printing Grand Totals in a Report
AT NEW:
It triggers for a group of similar contents (based on Character Value) in an Internal Table. (or)
It triggers whenever there is a change in field values in an Internal Table based on Character
Value
Syntax:
AT NEW <field name>.
------------
-----------
ENDAT.
Note:
Ashokkumar
SAP-ABAP 42
Use AT NEW for printing unique values for key fields in an Internal Table
AT END OF:
It will triggers the end of group of similar values in an Internal Table based on Character Field
Syntax:
AT END OF <field name>.
------------
-----------
ENDAT.
Note:
Use AT END OF for returning grand totals in an Internal Table
ON CHANGE OF:
It works similar to AT NEW
Syntax:
ON CHANGE OF <field name>.
------------
-----------
ENDON.
Note:
1. Due to some draw backs currently we are not using ON CHANGE OF
2. You should provide above Control Break Statements within the LOOP……..ENDLOOP
3. Don’t provide any conditional statements (IF, CASE,…….etc) with in Control Break
Statements
Requirement:
Material Details Report
--------- AT FIRST
The Material Cod is: F001
50 5000
100 10000
The Total Quantity is: 150 AT NEW
The Total Amount is: 15000
wa-material = ‘F002’.
wa-quan = 70.
wa-amount = 6000.
APPEND wa TO it.
wa-material = ‘F001’.
wa-quan = 100.
wa-amount = 10000.
APPEND wa TO it.
wa-material = ‘F002’.
wa-quan = 100.
wa-amount = 12000.
APPEND wa TO it.
* sorting it by material
SORT it BY material.
AT FIRST.
WRITE:/50 ‘Materials Details Report’ COLOR 1.
SKIP.
ULINE.
ENDAT.
Ashokkumar
SAP-ABAP 44
AT NEW material.
WRITE:/ ‘The Material Code is:’, wa-material.
SKIP.
ENDAT.
WRITE:/10 wa-quan,
30 wa-amount.
AT END OF material.
SUM.
WRITE:/ ‘The Total Quantity is:’, wa-quan,
/ ‘The Total Amount is:’, wa-amount.
ULINE.
ENDAT.
AT LAST.
SUM.
WRITE:/ ‘The Grand Total Quantity is:’, wa-quan,
/ ‘The Grand Total Amount is:’, wa-amount.
ULINE.
ENDAT.
ENDLOOP.
30-08-2014
Ques: What is the difference between SUM & COLLECT keywords?
Ans: COLLECT keyword is applicable LOOP……….ENDLOOP without usage of Control
Break Statements
COLLECT keyword performs totals inside internal table body based on one (or) more
than one Character Values
SUM keyword performs totals only one Single Character Value for Control Break
Statements places the values in Work Area
COLLECT keyword works outside LOOP………ENDLOOP also where as SUM
keyword can be applied only with in LOOP………ENDLOOP
Ashokkumar
SAP-ABAP 45
INSERT keyword:
Inserts Work Area data at a specific index position inside Internal Table Body
Syntax:
INSERT <work area name> INTO <internal table name> INDEX <line number>.
* creating variable
DATA n TYPE I.
wa-material = ‘F002’.
wa-quan = 70.
wa-amount = 6000.
APPEND it TO it.
wa-material = ‘F001’.
wa-quan = 100.
wa-amount = 10000.
Ashokkumar
SAP-ABAP 47
APPEND it TO it.
wa-material = ‘F002’.
wa-quan = 100.
wa-amount = 12000.
APPEND it TO it.
Ashokkumar
SAP-ABAP 48
DML Operations on Database Table:
a) INSERT
b) UPDATE
c) DELETE
Syntax:
1. MODIFY <database table name> FROM TABLE <internal table name>
2. MODIFY <database table name> FROM TABLE <work area name>
Example-1:
TABLES kna1.
wa-kunnr = ‘0000009083’.
wa-name1 = ‘rahul’.
wa-ort01 = ‘mumbai’.
wa-pstlz = ‘400002’.
APPEND wa TO it.
Example-2:
UPDATE keyword:
Updates specific fields based on given requirement
Syntax:
UPDATE <database table name> SET field1 = wa-filed1, field2 = wa-field2……….
………….. WHERE <codition>.
Ashokkumar
SAP-ABAP 49
Example:
DELETE keyword:
Deletes database tables data based on given requirement
Syntax:
1. DELETE <database table name> FROM TABLE <internal table name>.
2. DELETE FROM <database table name> WHERE <condition>
Example-1:
DELETE kna1 FROM TABLE it.
WRITE:/ ‘number of records deleted:’, SY-DBCNT.
Example-2:
LOOP AT it INTO wa.
DELETE FROM kna1 WHERE kunnr = wa-kunnr.
ENDLOOP.
Example-3:
DELETE FROM kna1 WHERE kunnr = ‘0000009083’.
INSERT keyword:
Inserts data into database table
Syntax:
INSERT INTO <database table name> VALUES <work area name>.
Ashokkumar
SAP-ABAP 50
Types of Internal Tables:
1. Standard Table
2. Hashed Table
3. Sorted Table
4. Index Table
Note:
The default Internal Table is Standard
Assignments-1:
Students Details Report
Sno Sname Phy Chem Maths Total
100 satya 70 60 90 220
101 pruthvi 80 70 60 210
102 raj 90 80 80 250
240 210 230 680
Assignment-2:
Material Quan
F001 50
F001 100
F002 70
F002 150
F001 150
F002 220
Hint:
1. Create 3 Internal Tables
2. Use DELETE ADJACENT DUPLICATE keyword
3. Use CLEAR keyword
Ashokkumar
SAP-ABAP 51
01-09-2014
Data Dictionary
It is also called ABAP Dictionary
It is a repository of data
T Code for Data Dictionary is SE11
Database Table:
It is a set of fields which holds data persistently
Data Element:
Using Data Element you can provide field documentation for a specific field
Conceptually Data Element = Field Lable + Domain
Domain:
It specifies the technical attributes of a field (Data Type & Field Size)
Ques-2: SAP is providing so many tables then why you created a table?
Ans: SAP is not providing table for Allowances,
Similarly SAP is not providing a table for Transportation Details.
Example: Delivery challana number, date, truck number……….etc
Similarly in real time we have to create a table for Customer mail ids for sending invoice
details…….etc
Ashokkumar
SAP-ABAP 52
Table Creation:
Go to SE11
Provide Title: ZMM_TR
Select Create option
Provide Short Description: Truck Entry Details
Note:
In real time we are working with application data.
Application data is 2 types
1. Master Data
2. Transactional Data
Master Data:
It is created only once in Client Database & modified very rarely
Example:
Bank Master Data, Customer Master Data, Vendor Master Data, Employee Master Data…etc
Transactional Data:
It is always created based on Master Data
It is modified frequently in SAP database
Example:
Purchase Order Data, Sales Order Data………..etc
Delivery Class:
It specifies the type of data a table can hold
A-------specifies Application Data
Provide Table View Maintenance: Display Maintenance Allowed (both display & create
entries is allowed)
Select Fields tab
Field key Data Element
TRNO ZTR_DAT
Double click on ZTR_DAT
You will find a message pop-up select Yes option
Select Local Object option
Again you will find a warning: application table should be client specific the press Enter
You will find a pop-up: create the data element then click Yes
Provide Short Description: Truck Number
Provide Domain: ZTR_Domain
Double click on Domain Name (ZTR_Domain)
Click Yes
Select Local Object
Note:
Ashokkumar
SAP-ABAP 53
$TMP is a default package for non-transportable object (local object)
You will find a pop-up: create the domain click Yes
Provide Short Description: Domain for Truck Field
Data Type: CHAR
No. Characters: 10
Activate the domain (Ctrl+F3)
Select Local Object
Go to back (F3)
Select Field Label tab
Length field lable
Short 10 trno
Medium 20 Truck Number
Lang 40 Truck Number
Heading 50 Truck Number
Activate data element (Ctrl+F3)
Go to back (F3)
Field key data element
Ddate LFDAT
Driver ZDR_DAT
Double click on ZDR_DAT
Save Yes
You will find a warning pop-up: Enter
You will find a pop-up: create data element Yes
Provide Short Description: Driver Name
Provide Domain: CHAR20
Select Field Label tab
Provide Short Description: Driver Name
Length field lable
Short 10 Dname
Medium 20 Driver Name
Lang 40 Driver Name
Heading 50 Driver Name
Activate data element (Ctrl+F3)
Go to back (F3)
Select Technical Settings button
Provide Data Class: APPL0 (APPL0---for master data & APPL1---for
transactional data)
Provide Size Category: 0 (it means table holds up to 8000 records)
Select Save option (Ctrl+s)
Select back (F3)
Activate Table (Ctrl+F3)
During activation you will find a warning pop-up select Yes
Ashokkumar
SAP-ABAP 54
Ignore the warnings & go back (F3)
Step-1:
Navigation for Inserting Records into a Table:
Select Utilites---Table Contents---Create Entries
TRNO:_______
Ddate:_________
Driver:_________
Save (Ctrl+S)
Select Reset button for new record
Step-2:
Navigation for Viewing Records in a Table:
Select Utilities---Table Contents---Display
Select Clock symbol (F8)
Ashokkumar
SAP-ABAP 55
02-09-2014
Structure:
It is a group of fields
Physically it will never hold any data
Structure can be reuse in other programs & other tables
Structure Creation:
Go to SE11
Select Data Type: ZMM_Order
Select Create option
You will find a pop-up select Structure option & press Enter
Provide Short Description: Order Fields
Provide Component: EBELN
BEDAT
Provide Component Type: EBELN
BEDAT
Activate structure (Ctrl+F3)
Select Local Object
You will find warnings pop-up then select Yes
Ignore warnings & go back (F3)
Condition (or) Pre represents for maintaining a Relationship between Two Tables:
In SAP if you want to create relationship between two tables there should be Key Field with
common data between tables even the fields are not common there should be common data
between two tables
MANDAT MANDAT
DCNO ZDAT_DC
Double click on ZDAT_DC
Click on Yes, Local Object & Yes
Provide Short Description: Data Element for DC
Provide Domain: CHAR10
Select Field Label option
Medium: 20
Field Label: Delivery Challana
Activate Field (Ctrl+F3)
Like add all required fields (DCdate, TRNO)
Select TRNO field
Select Foreign Keys option
You will find a pop-up provide Short Text: Relationship
Check Table: ZMM_TR
Select Generate Proposal button
Select Enter option
Provide Field: .include
Ashokkumar
SAP-ABAP 57
Data Element: ZMM_Order (it provides EBLEN, BEDAT fields)
Select Technical Settings option
Provide Data Class: APPL1 (for Transactional data)
Size Category: 0 (for upto 8000 records)
Select Save option (Ctrl+s)
Data Class:
It is a physical storage location (or) table space where tables are stored ultimately after
activation. It is of 3 types
1. APPL0 (holds master data tables)
2. APPL1 (holds transactional data tables)
3. APPL2 (holds organizational & customizing data related tables)
Size Category:
It specifies the probable space requirement for a table in the database
Go to back (F3)
Activate the table (Ctrl+F3)
Select Content option
Apply F4 on Truck Number field
You will find data related to Check Table
Go to back (F3)
Select Utilities--Table Contents--Create Entries
Note:
In real time we are not creating any relationships between tables
Ques: What is the difference between Client Dependant & Client Independent tables?
Ans: A table created without MANDT field is Client Independent table. Client Independent
tables are available in other clients also with data
A table created with MANDT field is Client Dependant table. Client Dependent tables
are available in other clients also without data
Note:
In real time it is always advisable to create Client Dependant tables
Ashokkumar
SAP-ABAP 58
View:
It is a logical table (virtual table) which is created based on other tables
It hires Fields & Data from other tables
Types of Views:
1. Database View
2. Projection View
3. Help View
4. Maintenance View
Database View:
It is always created based on two (or) more than two tables having relationship between them
Ashokkumar
SAP-ABAP 59
Testing Database View:
Select Contents option
Select Clock symbol (F8)
Note:
View always holds common data (linked data between two (or) more than two tables)
03-09-2014
Projection View:
It created based on a single table with specific fields
Ashokkumar
SAP-ABAP 60
Search Help:
Using search help you can search application data based on given search criteria
Search help works based on F4 function key
Note:
In a table (or) tables there is large volume of application data. Manual search of data will take
lot of time. SAP is providing an option called Search Help for searching data as for
requirement
Note:
In real time calling a search help using MATCHCODE OBJECT is outdated
Testing:
Select Contents option
Apply F4 on TRNO field
You will find an error then
Go to SE38
Provide Program: ZMM_TR
Select Create option
Write PARAMETERS p_tr TYPE ZMM_TR-TRNO.
Activate program then go back & test the table
Ashokkumar
SAP-ABAP 63
Table Maintenance Generator (TMG):
Using TMG you can directly Insert, Update, Delete data from a database table
Note:
1. In real time for certain requirements when data is not linked with other tables. Data can
be inserted (or) manipulated from table level directly. This can be done by creating a
TMG on that table
2. TMG is allowed only for ZEE tables
Creating TMG:
Go to SE80
Under Test Repository select Function Group option
Provide Function Group: ZMAIL_GR then press Enter
You will find a pop-up create object press Yes
Again you will find a pop-up Short Text: Mail Group then press Enter
Select Local Object
Go to SE11
Provide Database Table: ZSD_MAIL
Select Change option
Select Utilities---Table Maintenance Generator
Provide Authorization Group: &NC&
Provide Function Group: ZMAIL_GR
Select One Step option
Select Scr Number(s) button
You will find a pop-up select Propose Screen Number option then press Enter
Select Create option (F6)
Ashokkumar
SAP-ABAP 65
Select Save option (Enter)
Select Local Object (Enter)
Creating TCode:
Go to SE93
Provide Transaction Code: ZMAIL
Select Create option
Provide Short Text: Customer Mail Details
Select Transaction with Parameters (Parameter Transaction) option then press Enter
Provide Transaction: SM30
Scroll down to bottom then provide
Name of Screen Field Value
ViewName SZD_MAIL
Update X
Save (Ctrl+s)
Select Favorites---Inset Transaction
Provide Transaction Code: ZMAIL then press Enter
Testing TMG:
Provide Run TCode: ZMAIL then press Enter
Provide Table: ZSD_MAIL
Select Maintain option
Select New Entries button
Insert records & save
Go to SE38
Provide Program: SAPLZMAIL_GR
Select Change option
Activate the program (Ctrl+F3)
Go to SM30
Provide Table: ZFI_LIMITS
Select Maintain option
Select New Entries option
Insert records & Save
04-09-2014
Adding Check boxes in Table in TMG:
Create Table First:
Go to SE11
Provide Database Table: ZPP_MACHINE
Select Create option
Provide Short Description: Machine Down Time
Provide Delivery Class: A
Provide Table View Maintenance: Display Maintenance Allowed (both display & create
entries is allowed)
Select Fields tab
Field key Data Element
MANDT _/ MANDT
MACHNO _/ ZMACH_DAT
BUDAT _/ BUDAT
STIME ZSTART_DAT
ETIME ZEND_DAT
DTIME ZDOWN_DAT
CHK ZCHK_DAT
Creating TCode:
Go to SE93
Provide Transaction Code: ZDOWN
Select Create option
Provide Short Text: Machine Down Time
Select Transaction with Parameters (Parameter Transaction) option then press Enter
Provide Transaction: SM30
Scroll down to bottom then provide
Name of Screen Field Value
ViewName SPP_MACHINE
Update X
Save (Ctrl+s)
Select Favorites---Inset Transaction
Provide Transaction Code: ZDOWN then press Enter
Testing:
Go to SE38
Provide Program: SAPLZDOWN
Select Change option
Activate the program (Ctrl+F3)
Go to SM30
Provide Table: ZPP_MACHINE
Select Maintain option
Select New Entries option
Insert records & Save
Ashokkumar
SAP-ABAP 70
Text Table:
Use text table for storing explanatory texts. For storing such texts it is not advisable to store in
Primary Table
Note:
Text Tables works based on Primary & Foreign key relationship
Select SPRAS
Select Foreign keys option
You will find a pop-up then press Yes & then press Enter
Select DEPT
Select Foreign keys option
Provide Check Table: ZTEXT_TAB
Select Generate Proposal button
At bottom select Keys Fields of a Text Table option
Provide Cardinality 1:N then press Enter
Select MANDT
Select Foreign keys option
You will find a pop-up then press Yes & then press Enter
Activate table (Ctrl+F3)
Ashokkumar
SAP-ABAP 72
Some Important Steps for Working with Standard Tables:
Go to SE11
Provide Database Table: KNA1
Select Display option
Select Contents option
Step-1:
Navigation for Getting Selected Fields in Output List:
Select Settings---Format List----Choose Fields option
By default all fields are selected then select Deselect option (Shift+F2)
Select required fields KUNNR, NAME1, ORT01, PSTLZ then Enter
Execute (F8)
Step-2:
Adding (or) Removing Fields from Selection Screen:
Select Settings---Fields for Selection option
Select & deselect fields based on requirement then Enter
Step-3:
Transforming Data from SAP to Local File (XL Sheet):
Select F8
Select Local File option (last from 5th option) (Ctrl+Shift+F9)
You will find a pop-up select Spread Sheet option then Enter
You will find a pop-up apply F4 on Directory field
You will find a pop-up then select Desktop
Provide File Name: Customer then select Save option
Select Generate option
Ashokkumar
SAP-ABAP 73
05-09-2014
Types of Tables:
1. Transparent Table
2. Cluster Table
3. Pooled Table
Transparent Table:
It is a default table in SAP
It holds application data (master data & transactional data)
It follows one-to-one relationship (a table created in Presentation Server, if with the
same Structure & Fields another table created in Database Server)
These tables can be accessed even outside SAP
This table allows both Open SQL & Native SQL statements
In real time we are mostly working with Transparent Table
Note:
You cannot apply Inner-Join statement on Cluster Table
Ashokkumar
SAP-ABAP 74
Open SQL & Native SQL Statements:
Native SQL Statements:
These are traditional SQL statements
With Native SQL Statement request is directly forwarded to Database Server which
processes the request & returns the response
With Native SQL statement performance of the system is highly degraded
Syntax:
EXEC SQL.
SELECT………………
ENDEXECSQL.
These are normal SQL statements which are converted to embedded SQL using database
interface which is further passed to Buffer, if data is available in Buffer you will get the
response
Ashokkumar
SAP-ABAP 75
Buffering Concept:
Buffering is a way of improving performance which accessing data from database. Whenever
you run a program it will make a request to Buffer for data, if it is not available it will make a
request to Database Server which returns response to Buffer & simultaneously to Program.
Next time whenever you run the same program this time it will collect the data directly from
Buffer
Note:
Buffering is important for frequent & common accessing of application data
Types of Buffering:
1. Single Record Buffering
2. Generic Buffering
3. Full Buffering
Full Buffering:(SELECT *)
This buffer is allocated when you are fletching all the fields from database table
Check Table:
It works based on Primary & Foreign key relationship. Data is always validated at Field level
Value Table:
It is a default Check Table & it always maintained under Domain under Value Range option
Ashokkumar
SAP-ABAP 76
09-09-2014
MODULES
MM Module:
Materials Management Module
Departments in MM Module:
1. Purchase
2. Warehouse
3. General Stores
4. Finance in MM
Quotation PO Approval
Vendor Payment
Ashokkumar
SAP-ABAP 77
Purchase Order:
Vendor: PO Date:
Vendor Details:
Payment Terms:
Item No. of Pieces Unit price Amount
10 2 100 200
-- - - -
- - - -
Brief Flow:
PR
PR Purchase
RFQ
PO
PO Release
GRN
IV
Vendor Payment
2. Purchase Order:
T codes: ME21N, ME22N, ME23N
Tables: EKKO, EKPO, EKBE, EKKN, EKAN, EKET
Note: The key field is EBELN (PO number)
3. Goods Receipt:
Ashokkumar
SAP-ABAP 78
T codes: MIGO
Tables: MKPF, MIEG
Note: The key field is MBLNR (Material Document Number)
4. Invoice Verification:
T codes: MIR0, MIR7
Tables: RBKP, RSEG
Note: The key field is BELNR (Accounting Document Number)
Ashokkumar
SAP-ABAP 79
Inner Joins:
Use inner joins for fletching common data from two (or) more than two tables
Syntax-1:
SELECT LFA1~lifnr LFA1~name1
EKKO~ebeln EKKO~bedat
EKPO~menge EKPO~netpr
INTO TABLE <it> FROM LFA1
INNER JOIN EKKO ON LFA1~lifnr=EKKO~lifnr
INNER JOIN EKPO ON EKKO~ebeln=EKPO~ebeln
WHERE <codition>
Syntax-2:
SELECT A~lifnr A~name1
B~ebeln B~bedat
C~menge C~netpr
INTO TABLE <it> FROM LFA1 AS A
INNER JOIN EKKO AS B ON A~lifnr=B~lifnr
INNER JOIN KKPO AS C ON B~ebeln=C~ebeln
WHERE <codition>
10-09-2014
Example:
Lifnr name1 ebeln lifnr bedat
1 X
2 Y
3 Z
4 M
100 1
200 1
300 2
400 2
500 3
Ashokkumar
SAP-ABAP 81
Requirement:
Purchase Order Details based on Vendors
Input:
Vendor code ------- s_lifnr to
Company code---- s_bukrs to
Plant ------- s_werks to
Material type------ s_matnr to
Material group---- s_matkl to
Po date--------------s_bedat to
Summary
Details
1000 EKPO-meins
3000 2.6.2.14 100-100 50 2000 PC
3001 15.6.2014 100-101 70 3000 PC
Totals 120 5000
1001
5001 3.6.201 F001 2 80 PC
5002 9.6.2014 F002 1 90 PC
5003 15.6.2014 F003 3 100 PC
Totals 6 270
Solution:
Go to SE38
Provide Program: ZMM_Purchase_Order_Details
Select Create
Title: Purchase Order Details based on Vendors
Type: Executable Program
Select Save, Local Object
IF p_rb1 EQ ‘X’.
SORT it_po BY lifnr.
Ashokkumar
SAP-ABAP 83
LOOP AT it_po INTO wa_po.
AT NEW lifnr.
WRITE:/10 wa_po-lifnr COLOR 1.
SKIP.
ENDAT.
AT END OF lifnr.
SUM.
FORMAT COLOR COL_TOTAL INTENSIFIED OFF.
NEW-LINE.ULINE AT 1(135).
WRITE:/ SY-VLINE,
10 ‘Totals’,
70 wa_po-menge,
90 wa_po-netpr,
135 SY-VLINE.
ENDAT.
AT LAST.
SUM.
FORMAT COLOR COL_TOTAL INTENSIFIED OFF.
NEW-LINE.ULINE AT 1(135).
WRITE:/10 ‘Grand Totals’,
70 wa_po-menge,
90 wa_po-netpr,
135 SY-VLINE.
ENDAT.
ENDLOOP.
ELSE
LOOP AT it_po INTO wa_po.
Ashokkumar
SAP-ABAP 84
AT FIRST.
FORMAT COLOR COL_HEADING INTENSIFIED ON.
NEW-LINE.ULINE AT 1(135).
WRITE:/ SY-VLINE,
10 ‘Vendor Code’,
25 ‘PO Number’,
35 ‘PO Date’,
45 ‘Material Code’,
60 ‘Unit of Measure’,
70 ‘Quantity’,
80 ‘Unit Price’,
135 SY-VLINE.
NEW-LINE.ULINE AT 1(135).
ENDAT.
ENDLOOP.
ENDIF.
Ashokkumar
SAP-ABAP 85
LFA1 Table:
This table holds Vendor Master Data
Fields:
1. Lifnr-------Vendor Number
2. Land1-----Country of Vendor
3. Name1----Name of Vendor
4. Ort01-----City of Vendor
5. Pstlz------Postal Code of Vendor
6. Adrnr-----Address Number
Links:
LFA1~adrnr
ADRC~addrnumber
7. Brsch-----Industry Key
EKKO Table:
This table holds Purchase Order Header Data
Fields:
1. Ebeln-------Purchase Order Number
2. Bukrs------Company Code
3. Bsart-------Purchasing Document Type
4. Statu-------Status of Purchase Order
5. Lifnr-------Vendor Number
Links:
LFA1~lifnr
EKKO~lifnr
6. Zterm------Payment Terms
7. Zbd1p-----Cash Discount Percentage
8. Ekorg------Purchase Organization (Purchase Department)
9. Ekgrp------Purchasing Group
10.Waers------Currency
11.Wkurs------Exchange Rate
12.Bedat-------Purchase Order Date
13.Inco1, Inco2-------International Terms for Carrying Bussiness
14.Knumv------Tax Number
Links:
Ashokkumar
SAP-ABAP 86
EKKO~knumv
KONU~knumv
15.Kalsm------Pricing Procedure
16.Frgke-------Release Indicator
EKPO Table:
This table holds Purchase Document Item Data
Fields:
1. Ebeln-------Purchase Order Number
Links:
EKKO~ebeln
EKPO~ebeln
2. Ebelp------Item Number
3. Txzo1-----Item Text
4. Matnr-----Material Code
5. Werks-----Plant
6. Lgort------Storage Location
7. Matkl-----Material Group
8. Menge------Purchase Order Quantity
9. Meins------Unit of Measurement
10.Netpr------Unit Price
11.Netwr------Total Price
12.Mwskz-----Sales Tax Code
13.Elikz--------Delivery Completed Indicator
Ashokkumar
SAP-ABAP 87
11-09-2014
Message Handling:
Using MESSAGE keyword you can display your own message
Note:
SY-SUBRC
It returns values after ABAP statement
It returns 0 if an ABAP statement is processed successfully otherwise it returns
Exception (other than 0 value)
Example:
SELECT…………………
…………………………..
IF SY-SUBRC EQ 0.
MESSAGE ‘Data Found’ TYPE ‘I’.
ELSE.
MESSAGE ‘Enter Valid Input’ TYPE ‘E’.
Message Class:
You can store all the messages in Message Class also
T-code for Message Class is SE91
Example:
IF SY-SUBRC EQ 0.
MESSAGE I000(zmm_mess1).
ELSE.
MESSAGE E001(zmm_mess1).
Message Options:
Ashokkumar
SAP-ABAP 88
I-----Information------Information pop-up is displayed
S----Status------Message is displayed in Status Bar
W----Warning-----A yellow color warning message is displayed & Control will switch to next
Screen
E-----Error------Red color message is displayed & Control will stay in same Screen
A----Amend-----Control will switch to Screen 0
X-----Exit-------Control will switch to ABAP Runtime Screen (ST22)
Ashokkumar
SAP-ABAP 89
12-09-2014
Modularization Techniques:
There are 5 modularization techniques in SAP.
They are
1. Subroutines
2. Function Modules
3. Include
4. Macro
5. Field Symbol
In real time you should ensure that every program should be highly readable & reusable
For achieving readability & reusability we have to work with modularization techniques
Subroutines:
Subroutine is like a mini program which can be called within the same program (or)
from other programs
Using Subroutines you can perform Calculations, Call other function modules, Write
statements……….etc
Types of Subroutines:
1. Internal Subroutines
2. External Subroutines
Internal Subroutines:
In this both calling part & definition part are in same program
Syntax:
PERFORM <subroutine name> USING <param1> <param2> ………….
Note:
1. In above syntax PERFORM will call its FORM & simultaneously pass Parameters to its
FORM
2. Subroutine name can be any name. The same name should be used both in PERFORM
& FORM
3. The Parameters defined in PERFORM are called Actual Parameters. These parameters
have global visibility & must be defined in a program
Ashokkumar
SAP-ABAP 90
4. The parameters maintained in FORM are called Formal Parameters. These parameters
have local visibility & are automatically created based on Actual Parameters
5. Actual Parameters will pass values to Formal Parameters by using USING option
6. The number of Actual Parameters should be same that of Formal Parameters
Example:
WRITE:/ ‘Welcome to Subroutine’.
PERFORM sub.
WRITE:/ ‘First Call’.
PERFORM sub.
WRITE:/ ‘Second Call’.
FORM sub.
WRITE:/ ‘Inside Sub’.
ENDFORM.
Output:
Welcome to Subroutine
Inside Sub
First Call
Inside Sub
Second Call
Ashokkumar
SAP-ABAP 91
Debugging:
Break Point:
Using break point the execution of a program can be terminated & until the break point is
reached
Note:
In real time for large programs debugging each & every part of a program is time consuming.
If you know where the problem arises you can directly keep a break point & test the program
Note:
Dynamic break point is used if you are not aware of the exact problem in your program.
During debugging you can set dynamic break point at different, different places & you can
remove the same dynamically
Note:
Static break point is used if you know the exact problem in your program & you want to debug
the same code N number of times
Ashokkumar
SAP-ABAP 92
Pass by Value & Pass by Reference:
Pass by Value:
In pass by value, value (or) values is passed from Actual Parameters to Formal
Parameters
Both calling part & definition part will share different memory locations
In call by value nothing is reflected back to calling part
Example:
DATA v1 TYPE C VALUE ‘a’.
PERFORM sub USING v1.
WRITE:/ v1.
FORM sub USING VALUE(p1).
p1 = ‘b’.
WRITE:/ p1.
ENDFORM.
Output:
b
a
Pass by Reference:
In pass by reference value is not passed to Formal Parameters instead a Pointer (or)
Reference (or) Address is passed to Formal Parameters
Any changes done in Formal Parameters will be effected to Actual Parameters also
Example:
DATA v1 TYPE C VALUE ‘a’.
PERFORM sub USING (or) CHANGING v1.
WRITE:/ v1.
FORM sub USING (or) CHANGING p1.
p1 = ‘b’.
WRITE:/ p1.
ENDFORM.
Output:
b
b
Ashokkumar
SAP-ABAP 93
External Subroutines:
In external subroutines both PERFORM & FORM maintained in separate programs
Example:
Go to SE38
Program: ZMM_GRM_DETAILS
Create
Title: GRM Details
Type: Executable Program
Save
Local Object
Ashokkumar
SAP-ABAP 94
SELECT MKPF~mblnr MKPF~budat MSEG~menge MSEG~matnr
MSEG~dmbtr INTO TABLE it_mseg FROM MKPF
INNER JOIN MSEG
ON MKPF~mblnr = MSEG~mblnr
WHERE MKPF~mblnr BETWEEN grm_low AND grm_high
AND MSEG~werks BETWEEN plnt_low AND plnt_high
AND MKPF~budat BETWEEN date_low AND date_high
AND MSEG~bwart EQ ‘101’.
Output:
s_mblnr : 49000000 to 490005000
s_werks: 1000 to 1200
s_budat: 15.11.1994 to 01.06.2009
Execute (F8)
Ashokkumar
SAP-ABAP 95
13-09-2014
MKPF Table:
It holds Material Document Header Data
Fields:
1. Mblnr ---------- Material Document Number
2. Mjahr ---------- Material Document Year
3. Blart ---------- Material Document Type
4. Budat ---------- Material Document Date
5. Xblrn ---------- Reference Document (Purchase Order Document) Number
MSEG Table:
It holds Material Document Item Data
Fields:
1. Mblnr ------ Material Document Number
2. Mjahr ------ Material Document Year
3. Bwart ------ Moment Type
4. Werks ------ Plant
5. Lgort ------- Storage Location
6. Charg ------ Batch Number
7. Lifnr ------- Vendor Account Number
Link:
LFA1-lifnr
MSEG-lifnr
Link:
EKPO-ebeln
MSEG-ebeln
Link:
Ashokkumar
SAP-ABAP 96
EKPO-ebelp
MSEG-ebelp
Ashokkumar
SAP-ABAP 97
Function Module:
Function Module is a piece of code which performs a specific task based on given
requirement
Function Module is a responsible program which always accepts Parameters & returns a
Value
Function Group:
It is a collection of identical objects
Without Function Group you cannot create a Function Module
In one Function Group we can maintain 99 Function Modules
Apart from this SAP providing more than 120000 Function Modules which are
surrounding more than 10000 Function Modules
Syntax:
CALL FUNCTION ‘<FUNCTION MODULE NAME>’. ------ calling part (SE38)
Ashokkumar
SAP-ABAP 98
These are Parameters which are pass & return from a Function Module
Exporting:
These are Variables (or) Field Groups which are pass to a Function Module in order to perform
a task
Importing:
Function Modules always returns a value via Importing Parameters
Tables:
These are Internal Tables
Changing:
In latest versions Table Parameters are replaced by Changing
Note:
1. Exporting & Importing Parameters works based on Pass by Value
2. Tables & Changing Parameters works based on Pass by Reference
Step-1:
Go to SE80
Under Test Repository select Function Group
Provide Function Group name: ZCAL_GR
Enter, Yes
Provide Short Text: Function Group for Calculations
Select Save, Local Object
Ashokkumar
SAP-ABAP 99
Step-2:
Go to SE37
Function Module: ZCALC_MOD
Create
Function Group: ZCAL_GR
Short Text: Function Module for Calculations
Enter, Enter
Import tab
Parameter Name Typing Associated Type
X TYPE I
Y TYPE I
Export tab
Parameter Name Typing Associated Type
Z TYPE I
Exception tab
Exception Short Text
No_Data Wrong Calculation
Step-3:
Go to SE38
Program: ZCALC_CALL_SUM
Create
Title: Function Module for Calculations
Type: Executable Program
Save, Local Object
PARAMETERS: a TYPE I,
b TYPE I.
DATA c TYPE I.
Assignment:
Accept a number as input say 3900 & the Function Module should return the same number in
figures say Three Thousand and Nine Hundred
Ashokkumar
SAP-ABAP 101
Include Program:
Include Program’s memory is available to any ABAP work bench tool
Example:
INCLUDE ZNC1
WRITE:/ ‘work’.
INCLUDE ZNC2
INCLUDE ZNC1.
WRITE:/ ‘hard’.
REPORT ZNC3
INCLUDE ZNC2.
Note:
Include Program is a program (or) reusable program without any Parameters
Ashokkumar
SAP-ABAP 102
Field Symbol:
Field Symbol is analog to pointer concept in ‘C’ language
It holds Reference of other Variables & returns Value stored in the Reference
Note:
Using Field Symbol you can improve performance of a program
Example:
Go to SE38
Program: ZMM_FIELDSYMBOL
Create
Title: Field Symbols
Type: Executable Program
Save, Local Object
TABLES: LFA1.
INCLUDE ZVEND_DECC.
PERFORM get_data.
PERFORM display_data.
FORM get_data.
Ashokkumar
SAP-ABAP 103
SELECT lifnr land1 name1 ort01 pstlz stras INTO TABLE it_lfa1
FROM LFA1
WHERE lifnr IN s_lifnr
AND land1 IN s_land1.
ENDFORM.
FORM display_data.
LOOP AT it_lfa1 ASSIGNING <l_fs>.
WRITE:/10 <l_fs>-lifnr,
30 <l_fs>-land1,
50 <l_fs>-name1,
70 <l_fs>-ort01,
90 <l_fs>-pstlz,
110 <l_fs>-stras,
ENDLOOP.
ENDFORM.
Note:
Nowadays most of the companies are using Field Symbols instead of Work area
Ashokkumar
SAP-ABAP 104
19-09-2014
FOR ALL ENTRIES keyword:
Using FOR ALL ENTRIES you can fetch common data between two tables
Syntax:
SELECT <field1> <field2>……… FROM <database table> INTO TABLE
<internal table> FOR ALL ENTRIES IN <database internal table> WHERE
<condition>
Example:
Segment wise Materials Details
Input:
1. Material Code
2. Material Type
3. Material Group
4. Division
Output:
Material Code Material Description Segment Description
Processing Logic:
1. Get Matnr Spart fields from MARA table based on input
2. Pass Spart field of MARA table to TSPAT table & get Vtext field where Spras field EQ
to ‘EN’
3. Pass Matnr field of MARA table to MAKT table & get Maktx field where Spars field
EQ to ‘EN’
Solution:
Go to SE38
Program: ZMM_SEGMENTWISE_MATERIALS
Create
Title: Segment wise Materials Details
Save, Local Object
* calling Subroutines
PERFORM get_mara.
PERFORM get_makt.
Ashokkumar
SAP-ABAP 106
PERFORM get_tspat.
PERFORM combine_data.
PERFORM display_data.
* getting matnr & spart from MARA table by comparing with input
FORM get_mara.
IF SY-SUBRC NE 0.
MESSAGE ‘Enter Valid Input’ TYPE ‘E’ DISPLAY LIKE ‘I’.
LEAVE LIST-PROCESSING.
ENDIF.
ENDFORM.
* getting spart & vtext from TSPAT table by comparing spart of TSPAT with spart of MARA
FORM get_tspat.
ENDFORM.
* getting matnr & maktx from MAKT table by comparing matnr of MAKT with matnr of
MARA
FORM get_makt.
ENDFORM.
ENDFORM.
* displaying output
FORM display-data.
LOOP AT it_final INTO wa_final.
AT FIRST.
NEW-LINE.ULINE AT 1(135).
WRITE:/ SY-VLINE,
10 ‘Material Code’,
30 ‘Material Description’,
60 ‘Segment Description’,
135 SY-VLINE.
NEW-LINE.ULINE AT 1(135).
ENDAT.
20-09-2014
Pitfalls of FOR ALL ENTRIES: (Drawbacks)
1. Before applying FOR ALL EMTRIES it is mandatory to check whether base internal
table is having data (or) not
If you are not checking,
Assume if base internal table is completely empty then it will fetch all records from
database table
2. It act as a SELECT DISTINCT (It removes duplicate set of records from an internal
table)
Example:
BSEG Table
belnr hkgnt
1000 301011
301012
301012 ---- These records will be removed
301012
301013
301014
3. If base internal table is too large there will be performance degration
Note:
In real time always use
1. INNER JOINS for extracting common data between two tables
2. FOR ALL ENTRIES for extracting & combining multiple tables records
Ashokkumar
SAP-ABAP 109
MARA Table:
It holds Material Master Data
Fields:
1. Matnr -------- Material Number
2. Ersda --------- Date of Creation
3. Ernam -------- Person who Created that Material
4. Mtart --------- Material Type
5. Mbrsg -------- Industry Key
6. Matkl --------- Material Group
7. Bismt --------- Old Material Number
8. Miens --------- Unit of Measurement
9. Brgew -------- Gross Weight
10.Ntgew -------- Net Weight
11.Spart ---------- Division Code
MAKT Table:
TSPAT Table:
It holds Division Description Details
Fields:
1. Spras --------- Language Key
2. Spart --------- Division Code
3. Vtext --------- Division Description
Ashokkumar
SAP-ABAP 110
SD Module:
Sales & Distribution Module
Departments in SD Module:
1. Marketing
2. Excise
3. Billing
4. Finance part of SD
Process Flow:
Inquiry
Quotation
Sales Order
Delivery
Excise Invoice
Invoice
FI Module
Quotation:
Tcodes: VA21, VA22, VA23
Tables: VBAK, VBAP
Note: The key field is vbeln
Sales Order:
Tcodes: VA01, VA02, VA03
Tables: VBAK, VBAP
Note: The key field is vbeln
Delivery:
Ashokkumar
SAP-ABAP 111
Tcodes: Vl01N, VL02N, VL03N
Tables: LIKP, LIPS
Note: The key field is vbeln (Delivery Number)
Excise Invoice:
Tcodes: J1IS, J1IEX, J1ID
Tables: J_1IEXCHDR, J_1IEXCDTL, J_1IMOCUST
Note: The key field is exnum
Invoice:
Tcodes: VF01, VF02, VF03
Tables: VBRK, VBRP
Note: The key field is vbeln (Invoice Number)
Other Tables:
VBKD, VBFA, VBPA, VBUK, VBUV, KONV, KONR
Ashokkumar
SAP-ABAP 112
String Operations:
1. SHIFT
2. TRANSLATE
3. REPLACE
4. STRLEN
5. OFFSET FUNCTIONALITY
6. SPLIT
7. CONCATINATE
8. CONDENSE
SHIFT keyword:
It shifts a specific string to left (or) right side by deleting required options in a particular string
Syntax-1:
SHIFT <string> LEFT DELETING LEADING <option>
Syntax-2:
SHIFT <string> RIGHT DELETING TRAILING <option>
TRANSLATE keyword:
It converts the case of a particular string from lower to upper and vice-versa
Syntax-1:
TRANSLATE str TO UPPER CASE
Syntax-2:
TRANSLATE str TO LOWER CASE
Example: SATYA--------satya
DATA: str(10) TYPE C VALUE ‘SATYA’.
TRANSLATE str TO LOWER CASE.
WRITE:/ str
Output:
satya
REPLACE keyword:
Ashokkumar
SAP-ABAP 113
It replaces a string with another string based on requirement
Syntax:
REPLACE <string1> WITH <string2> INTO <final string>
Example: rupees-------dollars
DATA: str(30) TYPE C VALUE ‘one thousand rupees’.
REPLACE ‘rupees’ WITH ‘dollars’ INTO str.
WRITE:/ str.
Output:
one thousand dollars
STRLEN keyword:
It returns length of a string
Syntax:
n = STRLEN ( str ).
Where n is Integer Variable
Example:
DATA: str(10) TYPE C VALUE ‘satya’,
n TYPE I.
n = STRLEN ( str ).
WRITE:/ n.
Output:
5
1. st = str + 2 ( 1 ). --------output------ C
2. st = str + 4 ( 2 ). --------output------ EF
SPLIT keyword:
It splits a single string based on special charectors
Syntax:
SPLIT <string> AT <special charector> INTO <stirng1> <string2> <string3>…..
Example:
DATA: str(10) TYPE C VALUE ‘cool-drink’,
Ashokkumar
SAP-ABAP 114
str1(10) TYPE C,
str2(10) TYPE C.
SPLIT str AT ‘-’ INTO str1 str2.
WRITE:/ str1,
str2.
Output:
cool
drink
CONCATENATE keyword:
It concatenates two (or) more than two strings into a final string
Syntax:
CONCATENATE <str1> <str2> <str3> INTO <final string> SAPARATED BY
<special character>.
Example-1:
DATA: data(10) TYPE C.
CONCATENATE SY-DATUM + 6(2) SY-DATUM + 4(2) SY-DATUM + 0(4) INTO
date SAPARATED BY ‘.’.
WRITE:/ date.
Output:
20.09.2014
Example-2:
DATA: year(4),
mon(2),
day(2),
date(10).
year = SY-DATUM + 0(4).
mon = SY-DATUM + 4(2).
day = SY-DATUM + 6(2).
CONCATENATE day mon year INTO date SAPARATED BY ‘.’.
WRITE:/ date.
Output:
20.09.2014
Ashokkumar
SAP-ABAP 115
CONDENSE keyword:
It combines a specific string by removing gaps between them
Syntax:
CONDENSE <string> NO-GAPS.
Example:
DATA: str(20) TYPE C VALUE ‘satya narayana’.
CONDENSE str NO-GAPS.
WRITE:/ str.
Output:
satyanarayana
Assignment:
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
Ashokkumar
SAP-ABAP 116
Looping Statements:
Branching:
a. Conditional Statements
b. Unconditional Statements
Conditional Statements:
1. IF…………ENDIF.
Sytax-1:
IF <condition>.
Do this
ENDIF.
Sytax-2:
IF <condition>.
Do this
ELSE.
Do this
ENDIF.
Sytax-3:
IF <condition>.
Do this
ELSE IF <condition>
Do this
ELSE.
Do this
ENDIF.
Note:
Use ELSE IF condition only a single condition is true
2. CASE…………..ENDCASE
Syntax:
CASE <expression>.
WHEN <exp1>.
Do this
WHEN <exp2>.
Do this
……….
……….
Ashokkumar
SAP-ABAP 117
WHEN OTHERS.
Do this
ENDCASE.
3. WHILE statement:
Syntax:
WHILE <condition>
----------
----------
ENDWHILE.
Unconditional Statements:
1. DO…………….ENDDO.
Syntax-1:
DO.
---------
---------
ENDDO.
Syntax-2:
DO <n> TIMES.
---------
---------
ENDDO.
Syntax-3:
DO <n> TIMES VARYING <expression> FROM <m> NEXT <n>.
---------
---------
ENDDO.
Operators:
a. Logical Operators
b. Relational Operators
Logical Operators:
1. AND
2. OR
3. NOT
Relational Operators:
1. GT----- >
Ashokkumar
SAP-ABAP 118
2. LT ----- <
3. GE ---- >=
4. LE ---- <=
5. NE ------ <>
6. EQ ------ =
Ashokkumar
SAP-ABAP 119
CONTINUE keyword:
Whenever CONTINUE is executed it terminates the current LOOP pass & returns the control
to next LOOP pass
Example:
DATA rem TYPE I.
DO 20 TIMES.
rem = SY-INDEX MOD 2.
IF rem NE 0.
CONTINUE.
ENDIF.
WRITE:/ SY-INDEX.--------- current LOOP pass number
ENDDO.
Output:
2 4 6 8 …………………… 20
CHECK keyword:
If check expression is true it will allows the remaining LOOP pass else it will terminates the
current loop pass
Syntax:
CHECK <expression>.
Example:
DATA rem TYPE I.
DO 20 TIMES.
rem = SY-INDEX MOD 2.
CHECK rem = 2.
WRITE:/ SY-INDEX.--------- current LOOP pass number
ENDDO.
22-09-2014
EXIT keyword:
When the keyword EXIT is executed the whole loop will be terminated
Example:
DATA: n TYPE I VALUE 10.
DO n TIMES.
IF SY-INDEX >= n.
EXIT.
ENDIF.
Ashokkumar
SAP-ABAP 120
WRITE:/ SY-INDEX.
ENDDO.
Ashokkumar
SAP-ABAP 121
Mathematical Operations:
Ex: 5.55
1. FRAC -------- 0.55
2. CEIL --------- 6.0
3. FLOOR ----- 5.0
4. SIGN -------- 1 (+)
5. ABS --------- 5.55 (always returns only positive value)
6. TRUNC ---- 5.0
Ex: 6 / 2
7. REM -------- 0
8. DIV --------- 3
9. MOD ------- 0
FRAC:
It returns fraction part from a decimal value
CEIL:
It returns highest value in existing decimal value
FLOOR:
It returns lowest value from a particular decimal value
SIGN:
It returns the signature (positive (or) negative) from a particular numeric value
ABS:
It returns absolute value from a numeric value
TRUNC:
It truncates (removes) decimal part from a numeric value
DIV:
It returns devisor
Example:
DATA: n TYPE P DECIMALS 2 VALUE ‘5.55’,
m TYPE P DECIMALS 2.
m = FRAC(n). WRITE:/ m
m = TRUNC(n). WRITE:/ m
Ashokkumar
SAP-ABAP 122
m = CEIL(n). WRITE:/ m
m = FLOOR(n). WRITE:/ m
m = ABS(n). WRITE:/ m
m = SIGN(n). WRITE:/ m
Assignments:
1. Formats
a. 1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
b. *
* *
* * *
* * * *
* * * * *
c. *
* * *
* * * * *
* * * * * * *
Ashokkumar
SAP-ABAP 123
SAP and ABAP Memory:
ABAP Memory:
Transferring data between two programs is done using ABAP memory
Transferring data from ABAP report to other Standard Application is done by using SAP
memory
Question: Explain why you written Export Import Functionality in your real time?
Answer:
The above functionality is for reusability
Sometimes we needs to write a logic which already provided by a program
Instead of writing the same program from beginning you can use the above functionality
for getting the data from other programs
Example:
Go to SE38
Program: YIMPORT_PROG
Create
Title: Import Program
Type: Executable Program
Save, Local Object
TABLES: EKPO.
Ashokkumar
SAP-ABAP 124
SELECTION-SCREEN: BEGIN OF BLOCK b1 WITH FRAME TITLE text-000.
SELECT-OPTIONS: s_matnr FOR EKPO-matnr,
s_werks FOR EKPO-werks.
SELECTION-SCREEN: END OF BLOCK b1.
TABLES: EKPO.
SELECT ebeln matnr menge netpr FROM EKPO INTO TABLE it_ekpo
WHERE matnr IN s_matnr
AND werks IN s_werks.
Output:
Execute IMPORT_PROG
s_matnr 100-100 to 100-500
s_werks 1000 to 1100
Ashokkumar
SAP-ABAP 126
23-09-2014
Support Project:
In Support Project End user will raise Tickets (Issues) based on priority
Issues are directly raised by End user in Production Client which are automatically
updated to Solution Manager
Solution Manager is a free Ticketing Tool given by SAP for raising tickets
Help Desk people from Consulting Company will receive the Tickets & forward it to
respective Functional Consultants based on priority
If the issue is Functional (related to Application, Customizing Issue……….etc) then
Functional Consultant will resolve it
If the issue is Technical (related to Programming, Enhancement…….etc) then
Functional Consultant will prepare Functional Document & forward it to Technical
Consultant (ABAPER)
Based on Functional Document ABAPER will create Technical Document & forward it
to Team Leader for approval
If everything is fine ABAPER will develop the Object in Development Client
Once the Object is developed then series of Testing will done by ABAPER, Functional
Consultant & End user
Finally after final testing by End user the Object is transported to Production System
with the help of Basis Consultant
Ashokkumar
SAP-ABAP 127
System Landscape:
It is also known as Correction & Transportation System (CTS)
In real time End user will raise issues which are received by Functional Consultant
For Technical Issues Functional Consultant will prepare Functional Document & based
on that Technical Consultant will prepare Technical Document
Technical Consultant will forward Technical Document to Team Leader who will
approve it
Objects are developed in Development Client
While creating Objects system will prompt you for to save the object
In real time Objects are always saved in a Package
Once Objects are saved system will generate Request Numbers (Main Request Number
& Sub Request Number)
Objects are always stored in Sub Request Number
Once Object is developed based on coding standards you should release Request
Numbers in SE10
Then you should forward a mail to Basis Consultant for transporting Transport Request
(TR) numbers from Development Client to Quality Client
In Quality Server testing is done by ABAPER, Functional Consultant, End user
If everything is fine again you will forward a mail to Basis Consultant to transport the
TR Numbers from Quality Server to Production Server
4. Quality Server is meant for testing. Here recent data (10 days back) is available
5. Production Server is Live Server in real time. It holds live data of a company. Day to
day activities of a company are maintained (or) stored in Production Server
6. Only Development Client is in change mode. Quality & Production Clients are always
in display mode
7. In real time as an ABAPER you can access Development & Quality Clients
8. End user can access Quality & Production Clients
9. FC can access any of these Clients
10.Package is a collection of Objects. In real time we are not creating any package.
Throughout the life time in a company we are working with a single package
Ashokkumar
SAP-ABAP 128
11.Objects are always stored in Sub Request Number is transported from one client to
another
12.In real time Basis Consultant is responsible for transporting Request Numbers from one
client to another
13.Once a Request Number is released (or) transported system will prompt you for a new
Request Number
14.In real time as a TC we have to work with Work Bench Request. FC will work with
Customizing Request
15.Request Numbers are always forwarded from Development to Quality & Quality to
Production Clients
Note:
Reverse transportation of a Request Number is not possible under any circumstances in SAP
16.In real time all the issues are posted in Production System & Threads are updated in
Solution Manager
17.E071 is a standard table which holds all Objects & their Request Numbers history
18.In real time our job to create Object & release the Request Number in SE10
19.In real time different companies are having different System Landscapes. In some
companies there will 1 Development & 3 Testing Clients & in some 1 Development & 1
Testing Client & in some companies Development & Quality Clients are Cross Clients
20.In Quality Server only 85% to 90% of testing is done as it holds recent data. If you want
to test the live data you have to work with Production Server
24-09-2014
Steps in System Landscape:
1. Work with SE80 (create a Package)
2. Work with SE38 (create a Program)
3. Work with SE10 (release Sub Request Number, release Main Request Number)
Step-1:
Go to SE80
Select Package option
Provide Package name: ZABAP
Yes
Short Description: New Package
Save
(OR)
Go to SE11
Provide Database Table name: V_TDEVC
Select Display option
Select Contents option
Select Package option
Ashokkumar
SAP-ABAP 129
Provide Package name: ZABAP
Short Description: New Package
Save
Step-2:
Go to SE38
Program: ZDEMO_PACKAGE
Create
Title: Package Program
Type: Executable Program
Save
Package: ZABAP
Save (Enter)
Note:
1. By default you may find a Request Number. The Request Number belongs to some
other ABAPER
2. Never select Enter option on that pop-up
Step-3:
Go to SE10
Select Work Bench Request
Under Request Status, select Modifiable check box & deselect Released check box
Select Display option
Expand Main Request Number
Select Sub Request Number
Select Truck Symbol (F9)
Select Main Request Number
Select Truck Symbol (F9)
Go to Back (F3)
Select Released check box & deselect Modifiable check box
Select Display option
Note:
Ashokkumar
SAP-ABAP 130
Up to here you have to perform in real time, from here you have to send a mail to your Basis
Consultant for transporting TR-Number from Development Client to Quality Client
Once the Request Number is transported from Development Client to Quality Client as
a TC now you have to login to Quality Server & test the Object
If it is fine now you will send a mail to your FC to test the same
If it is fine FC will update the Tread in Solution Manager to test the Object
Similarly End user will perform final testing in Quality Server
Note:
Always store identical Objects in one Request Number & different Objects in different
Request Numbers
Ashokkumar
SAP-ABAP 131
Version Management:
Using Version Management you can get the history of a program with Request
Numbers, User name, Date of creation & change
It is highly useful to programmer if requires to retrieve old version instead of current
version
Example:
Go to SE38
Program: ZDEMO
Select Utilities ----------- Versions ------ Version Management
Ques: How you can store an Object from Local Object to existing Package?
Ans:
Go to SE38
Program: name which is stored in Local object
Select Goto ---- Object Directory Entry
Select Change option
Package: ZABAP
Save
Ques: How you can delete an Object from existing Request Number?
Ans:
Go to SE11
Database Table: E071
Display
Contents option
Object Name; program name (ZDEMO)
Execute (F8)
Go to SE10
Select Display
Expand Main Request Number
Expand Sub Request Number
Expand Program option
Select your program
Select Delete option
You will find a message, Enter
Yes
Ashokkumar
SAP-ABAP 132
Sub Objects in ABAP Editor:
1. Source Code
2. Variants
3. Attributes
4. Documentation
5. Text Elements
Source Code:
It is nothing but source code of a program
Attributes:
It specifies attributes of a program (Title, Type, Date of creation & Change,………..etc)
Documentation:
Using this option you can provide documentation for a program
Example:
Go to SE38
Program: ZDEMO
Documentation
Change
Provide Purpose: The report is displaying segment wise materials details
Provide Integration: No
Provide Prerequisites: s_matnr
s_werks
Save
Text Elements:
Using Text Elements you can maintain Labels (or) Selection Screen Fields
Example:
Go to SE38
Program: ZDEMO
Text Elements
Change
Selection Text
Name Text
s_matnr Material Code
s_werks Plant
Activate
Ashokkumar
SAP-ABAP 133
Variants:
Using Variants you can provide default input values for a Selection Screen
In background scheduling report, the reports are executed automatically by system in
background. For such reports the input values are supplied by using Variants
Example:
Go to SE38
Program: ZDEMO
Variants
Change
Variant: ZVAR
Create
Enter input values
i.e. 100-100 to 100-500
fart
Select Attribute option (F6)
Meaning: Variant Creation
Save
Run the report
Select Get Variant option
Double click on variant name (ZVAR)
Ashokkumar
SAP-ABAP 134
ABAP-EDITOR
Interview Questions & Answers:
1Q: What is ERP?
Ans: ERP is a package under which all the business resources are integrated in one system
4Q: Where you can also execute programs other than ABAP Editor (SE38)?
Ans: We can also execute programs in Object Navigator (SE80)
8Q: Which file is generated by system when you execute the program?
Ans: SAPGUI.EXE file
Ashokkumar
SAP-ABAP 135
9Q: What is purpose of Activating the Objects?
Ans:
To store the Objects in Database Server
To integrate the Objects with each other
To debug & transport the objects
13Q: What is the difference between Database table & Internal table?
Ans: Database Table Internal Table
4. It is created in Database Server ------- 1. It is created in Application Server
5. It holds data permanently ------- 2. It holds data temporarily
6. It holds only specific type of data ----- 3. It holds data of different tables of at one place
Ans:
APPEND always appends record to Internal Table (if record exists (or) not)
MODIFY always modifies (adds field value) only if record exists in an Internal Table
22Q: What will happen if CLEAR is providing before Work Area & the same CLEAR is
provided in after Work Area?
Ans:
If CLEAR is provided before Work Area data so nothing is transferred from Work Area
to Virtual Page (hence no output)
If CLEAR is provided after Work Area, data is transferred from Work Area to Virtual
Page then Work Area is cleared (hence you will find output)
Ashokkumar
SAP-ABAP 137
INTERNAL TABLES
All duplicates with same combination of matnr and werks will be deleted
Ashokkumar
SAP-ABAP 138
3Q : What is the size of internal table?
Ans:
The size of the internal tables is set using the 'OCCURS n' clause.
Here ‘n’ refers to a integer number that specifies the size.
Usually it given as 'OCCURS 0' which creates an internal table with the memory space
of 8kb.
The size of the internal table is the product of width and number of lines of the internal
table. We can set the estimated number of lines of internal table in the OCCURS
parameter.
When first table entry is filled the runtime system allocates suitable memory to hold the
whole table
If the memory allocated is not sufficient then again a block of memory is allocated (in
case of number of lines more than estimated lines).
Therefore the OCCURS parameter does not affect the actual size of the internal table
but the performance of the internal table operations.
So if you are not able to estimate the lines, then give occurs parameter to zero.
Then system automatically does it for you.
Ashokkumar
SAP-ABAP 139
7Q : What are field groups and internal tables?
Ans:
Field groups are nothing but a similar type of fields grouped under single name (group)
or grouping of the fields is called field groups.
Internal tables are stored temp memory/in buffer for the further processing of the fields.
Ashokkumar
SAP-ABAP 140
10Q: What do mean by table types.
Ans:
The table type determines how ABAP will access individual table entries.
Internal tables can be divided into three types:
1. Standard tables
It has an internal linear index.
From a particular size upwards, the indexes of internal tables are administered as trees.
In this case, the index administration overhead increases in logarithmic and not linear
relation to the number of lines.
The system can access records either by using the table index or the key.
The response time for key access is proportional to the number of entries in the table.
The key of a standard table is always non-unique.
You cannot specify a unique key.
This means that standard tables can always be filled very quickly, since the system does
not have to check whether there are already existing entries.
Ashokkumar
SAP-ABAP 141
The line types of internal tables can be any ABAP data types - elementary, structured, or
internal tables.
The individual lines of an internal table are called table lines or table entries.
Each component of a structured line is called a column in the internal table.
Ashokkumar
SAP-ABAP 142
15Q: What are internal tables, value tables, check tables, transparent tables?
Ans:
Internal table:
It is a standard data type object, which exists only during the runtime of the program.
Check table:
Check table will be at field level checking.
Value table:
Value table will be at domain level checking
Ex: scarr table is check table for carrid.
Transparent table:
Exists with the same structure both in dictionary as well as in database exactly with the same
data and fields
16Q: Explain choosing a table type in internal table.
Ans : The table type (and particularly the access method) that you will use depends on how the
typical internal table operations will be most frequently executed.
18Q: What is the difference between internal table and work area?
Ans :
An internal table is a run time instance.
It get created when program starts execution.
*It get destroyed when program terminates.
It has two different parts:
Header Line (optional)
Body (Compulsory).
*Any value that comes to (or) goes from internal table, that travels through header line.
Ashokkumar
SAP-ABAP 143
19Q: Difference between database tables and internal tables?
Ans :
The basic difference is database tables are stored in DB server
Internal tables are virtual tables these are created run time only
Internal tables are created dynamically
The memory of internal tables is not permanent memory
For internal tables the memory will be created in the application server and it is external
memory and terminates after the program termination.
Ashokkumar
SAP-ABAP 144
DATA DICTIONARY
Interview Questions & Answers:
1Q: Have you ever created a Z-Table? Why explain the requirement?
Ans: Yes, SAP is not providing table for Allowances. Simultaneously SAP is not providing a
table for Transportation Details. Simultaneously in real time we have to create a table for
Customer Mail Ids for sending invoice details………….etc
5 Q: What is the difference between Top-Bottom & Bottom-Top approach of crating tables?
Ans: Top-Bottom:
Table---Data Element----Domain
Bottom-Top:
Domain-----Data Element----Table
Ashokkumar
SAP-ABAP 145
7 Q: What is the difference between Database View & Projection View?
Ans:
Database View is always created based on two (or) more than two tables having
relationship between them
Projection View is created based on a single table with specific fields
8 Q: What is the difference between Open SQL statements & Native SQL statements?
11Q: Mention some Cluster Tables that you are using in real time?
Ans: These tables hold SAP proprietary format data (system data, statistical data, control
data……)
Example: BSEG, KONU
Domain:
It specifies the technical attributes of a field (Data Type & Field Size)
21Q: What is the difference between Client Dependent Table & Client Independent Table?
Ans:
A table created without MANDT field is Client Independent table. Client Independent
tables are available in other clients also with data
A table created with MANDT field is Client Dependant table. Client Dependent tables
are available in other clients also without data
23Q: What is the difference between Master Data & Transactional Data?
Ans: Master Data:
It is created only once in Client Database & modified very rarely
Example:
Bank Master Data, Customer Master Data, Vendor Master Data, Employee Master Data…etc
Transactional Data:
It is always created based on Master Data
It is modified frequently in SAP database
Example:
Purchase Order Data, Sales Order Data………..etc
Size Category:
It specifies the probable space requirement for a table in the database
25Q: What is TMG? What is the need of creating TMG in real time?
Ans:
Using TMG you can directly Insert, Update, Delete data from a database table
Ashokkumar
SAP-ABAP 148
In real time for certain requirements when data is not linked with other tables. Data can
be inserted (or) manipulated from table level directly. This can be done by creating a
TMG on that table
27Q: How you can create List Boxes & Check Boxes in TMG?
28Q: How you can provide Default Values such as Date & Time automatically in a table
whenever user select Save option?
29Q: Mention some important Events that you created with TMG?
Ans: CREATE_ENTRY
Ans:
Ashokkumar
SAP-ABAP 150
35Q: Why it is mandatory to Activate a table in SAP?
Ans:
To store the Objects in Database Server
To integrate the Objects with each other
To debug & transport the objects
Ashokkumar
SAP-ABAP 152
7Q : How many types of size categories and data classes are there?
Ans:
There are five size categories (0-4) and
11 data classes
Only three of size categories are appropriate for application tables:
1. APPL0- Master data (data frequently accessed but rarely updated)
2. APPL1- Transaction data (data that is changed frequently)
3. APPL2- Organizational data (customizing data that is entered when system is configured
and then rarely changed)
Ashokkumar
SAP-ABAP 153
12Q: What is a table cluster?
Ans :
15Q: How is conversion of data types done between ABAP/4 & DB layer?
Ans : Conversion between ABAP/4 data types and the database layer is done within the
database interface.
16Q: How is conversion of data types done between ABAP/4 & external level?
Ans : Conversion between the external layer and the ABAP/4 layer is done in the SAP dialog
manager DYNP.
19Q: How can we set the table spaces and extent sizes?
Ans : You can specify the extent sizes and the table space (physical storage area in the
database) in which a transparent table is to be stored by setting the size category and data
class.
Ashokkumar
SAP-ABAP 155
24Q: What functions does a data dictionary perform?
Ans :
In a data management system, the principal functions performed by the data dictionary are
• Management of data definitions.
• Provision of information for evaluation.
• Support for s/w development.
• Support form documentation.
• Ensuring that the data definitions are flexible and up-to-date.
26Q: What are the uses of the information in the Data dictionary?
Ans :
The following information is directly taken from the Data dictionary:
• Information on fields displayed with F1 help.
• Possible entries for fields displayed with F4 help.
• Matchcode and help views search utilities.
29Q: In the ABAP/4 Dictionary Tables can be defined independent of the underlying database
(T/F).
Ans: True.
Ashokkumar
SAP-ABAP 156
30Q: ABAP/4 Dictionary contains the Logical definition of the table.
Ans :
31Q: A field containing currency amounts (data type CURR) must be assigned to a reference
table and a reference field. Explain.
Ans:
As a reference table, a system containing all the valid currencies is assigned or any other
table, which contains a field with the currency key format.
This field is called as reference field.
The assignment of the field containing currency amounts to the reference field is made
at runtime.
The value in the reference field determines the currency of the amount.
32Q: A field containing quantity amounts (data type QUAN) must be assigned to a reference
table and a reference field. Explain?
Ans :
As a reference table, a system table containing all the valid quantity units is assigned or
any other table, which contains a field with the format or quantity units (data type
UNIT).
This field is called as reference field.
The assignment of the field containing quantity amounts to the reference field is made at
runtime.
The value in the reference field determines the quantity unit of the amount.
33Q: What is the significance of Technical settings (specified while creating a table in the data
dictionary)?
Ans:
By specifying technical settings we can control how database tables are created in the
database. The technical settings allows us to
• Optimize storage space requirements.
• Table access behavior.
• Buffering required.
• Changes to entries logged.
Ans:
• The delivery class controls the degree to which the SAP or the customer is responsible for
table maintenance.
• Whether SAP provides the table with or without contents.
• Determines the table type.
• Determines how the table behaves when it is first installed, at upgrade, when it is transported,
and when a client copy is performed.
36Q: What is the max. no. Of structures that can be included in a table or structure.
Ans: Nine.
Ans:
• Append Structures and
• Customizing Includes.
40Q: If a table that is to be extended contains a long field, we cannot use append structures
why?
Ans:
Long fields in a table must always be located in the end, as the last field of the table.
If a table has an append structure the append line must also be on the last field of the
table.
41Q: Can we include customizing include or an append structure with Pooled or Cluster
tables?
Ans: No.
42Q: What are the two ways for restricting the value range for a domain?
Ashokkumar
SAP-ABAP 158
Ans:
• By specifying fixed values.
• By stipulating a value table.
43Q: Structures can contain data only during the run time of a program (T/F)
Ans: True.
46Q: The data of a view is not physically stored, but derived from one or more tables (t/f)
Ans: True.
47Q: What are the 2 other types of Views, which are not allowed in Release 3.0?
Ans:
• Structure Views.
• Entity Views.
*50Q: What is the max no of match code Id's that can be defined for one Match code object?*
Ans: A match code Id is a one character ID that can be a letter or a number.
*51Q: Can we define our own Match Code ID's for SAP Matchcodes?*
Ans : Yes, the number 0 to 9 are reserved for us to create our own Match Code Ids for a SAP
defined Match code object.
Ashokkumar
SAP-ABAP 159
If the data in one of the base tables of a match code ID changes, the match code data has
to be updated.
The update type stipulates when the match code is to be updated and how it is to be
done.
The update type also specifies which method is to be used for Building match codes.
You must specify the update type when you define a match code ID.
53Q: Can matchcode object contain Ids with different update types?
Ans: Yes.
55Q: What are the two different ways of building a match code object?
Ans :
A match code can be built in two different ways:
1. Logical structure:
The match code data is set up temporarily at the moment when the match code is accessed.
(Update type I, k).
2. Physical Structure:
The match code data is physically stored in a separate table in the database. (Update type A, S,
P).
Ashokkumar
SAP-ABAP 160
56Q: What are the differences between a Database index and a match code?
Ans:
• Match code can contain fields from several tables whereas an index can contain fields from
only one table.
• Match code objects can be built on transparent tables and pooled and cluster tables.
58Q: Can you delete a domain, which is being used by data elements?
Ans: No.
62Q: Can you delete data element, which is being used by table fields.
Ans : No.
63Q: Can you define a field without a data element?
Ans : Yes. If you want to specify no data element and therefore no domain for a field, you can
enter data type and field length and a short text directly in the table maintenance.
Ashokkumar
SAP-ABAP 161
66Q: What is a view?
Ans :
A view is a logical view on one or more tables.
A view on one or more tables
i.e., the data from a view is not actually physically stored instead being derived from one or
more tables.
Ans:
• Database View
• Help View
• Projection View
• Maintenance View
Ashokkumar
SAP-ABAP 162
LFA1 Table:
This table holds Vendor Master Data
Fields:
1. Lifnr-------Vendor Number
2. Land1-----Country of Vendor
3. Name1----Name of Vendor
4. Ort01-----City of Vendor
5. Pstlz------Postal Code of Vendor
6. Adrnr-----Address Number
Links:
LFA1~adrnr
ADRC~addrnumber
7. Brsch-----Industry Key
Ashokkumar
SAP-ABAP 163
EKKO Table:
This table holds Purchase Order Header Data
Fields:
1. Ebeln-------Purchase Order Number
2. Bukrs------Company Code
3. Bsart-------Purchasing Document Type
4. Statu-------Status of Purchase Order
5. Lifnr-------Vendor Number
Links:
LFA1~lifnr
EKKO~lifnr
6. Zterm------Payment Terms
7. Zbd1p-----Cash Discount Percentage
8. Ekorg------Purchase Organization (Purchase Department)
9. Ekgrp------Purchasing Group
10.Waers------Currency
11.Wkurs------Exchange Rate
12.Bedat-------Purchase Order Date
13.Inco1, Inco2-------International Terms for Carrying Bussiness
14.Knumv------Tax Number
Links:
EKKO~knumv
KONU~knumv
15.Kalsm------Pricing Procedure
16.Frgke-------Release Indicator
Ashokkumar
SAP-ABAP 164
EKPO Table:
This table holds Purchase Document Item Data
Fields:
1. Ebeln-------Purchase Order Number
Links:
EKKO~ebeln
EKPO~ebeln
2. Ebelp------Item Number
3. Txzo1-----Item Text
4. Matnr-----Material Code
5. Werks-----Plant
6. Lgort------Storage Location
7. Matkl-----Material Group
8. Menge------Purchase Order Quantity
9. Meins------Unit of Measurement
10.Netpr------Unit Price
11.Netwr------Total Price
12.Mwskz-----Sales Tax Code
13.Elikz--------Delivery Completed Indicator
Ashokkumar
SAP-ABAP 165
MKPF Table:
It holds Material Document Header Data
Fields:
1. Mblnr ---------- Material Document Number
2. Mjahr ---------- Material Document Year
3. Blart ---------- Material Document Type
4. Budat ---------- Material Document Date
5. Xblrn ---------- Reference Document (Purchase Order Document) Number
Ashokkumar
SAP-ABAP 166
MSEG Table:
It holds Material Document Item Data
Fields:
1. Mblnr ------ Material Document Number
2. Mjahr ------ Material Document Year
3. Bwart ------ Moment Type
4. Werks ------ Plant
5. Lgort ------- Storage Location
6. Charg ------ Batch Number
7. Lifnr ------- Vendor Account Number
Link:
LFA1-lifnr
MSEG-lifnr
Link:
EKPO-ebeln
MSEG-ebeln
Link:
EKPO-ebelp
MSEG-ebelp
Ashokkumar
SAP-ABAP 167
MARA Table:
It holds Material Master Data
Fields:
1. Matnr -------- Material Number
2. Ersda --------- Date of Creation
3. Ernam -------- Person who Created that Material
4. Mtart --------- Material Type
5. Mbrsg -------- Industry Key
6. Matkl --------- Material Group
7. Bismt --------- Old Material Number
8. Miens --------- Unit of Measurement
9. Brgew -------- Gross Weight
10.Ntgew -------- Net Weight
11.Spart ---------- Division Code
Ashokkumar
SAP-ABAP 168
MAKT Table:
TSPAT Table:
It holds Division Description Details
Fields:
1. Spras --------- Language Key
2. Spart --------- Division Code
3. Vtext --------- Division Description
Ashokkumar