ABAP For SD Consultants

You might also like

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

SD2012: ABAP for SD Consultants

V 1.0

©India SAP CoE, Slide 1


ABAP …?
ABAP used to be an abbreviation of Allgemeiner Berichts Aufbereitungs Prozessor,
the German meaning of "generic report preparation processor", but was later
renamed to Advanced Business Application Programming

It is one of the many the application-specific fourth-generation languages

It was originally used by SAP developers to develop the SAP R/3 platform. It is
also used by SAP customers to enhance SAP applications – add custom reports
and interfaces, and enhance user experience.

It is a structured language like C.

Its syntax is somewhat similar to COBOL

The actual processing logic of an application program is written in ABAP. The


ABAP processor executes the processing logic of the application program, and
communicates with the database

©India SAP CoE, Slide 2


ABAP for SD Consultants
1 PrepareMe

2 TellMe

3 ShowMe

4 LetMe

5 HelpMe
©India SAP CoE, Slide 3
ABAP for SD Consultants
1 PrepareMe

2 TellMe

3 ShowMe

4 LetMe

5 HelpMe
©India SAP CoE, Slide 4
Purpose
1. Comprehensive: ERP software supports an organizations all the
business transactions and links them together using real-time
integration.

2. Integration: Real-time integration means that each change or update in


one application causes the automatic change or update of the data in
the other applications involved.

3. Scalability: ERP software caters to the needs of small business house


with say less than 10 users to multi billion dollar companies.

4. Interfaces (EDI-ALE-IDOC): Directly Sending & receiving information


from other systems helps in efficient functioning of business
processes without the need for multiple data entry.

5. Adaptability: Last but not the least, the softwares should be


customizable to meet the specific needs of an organization that are not
available as standard functionalities.

©India SAP CoE, Slide 5


Adaptability is the key

©India SAP CoE, Slide 6


Use
Tables & Data Storage Interfaces EDI, ALE, Idoc
structures & Retrieval

Processing
Routines, Methods
Logic Programs,
Includes

Adaptability Utilities
Reports,
Interfaces,
Conversions,
Enhancements Debug, Tracer,
and Forms Notes, Patches

©India SAP CoE, Slide 7


ABAP provides the framework & processing logic

©India SAP CoE, Slide 8


Challenges

ABAP shall enable to meet the frequent changes in business requirements


by,

- enhancing the existing programs

- adding customer functionality to existing Transactions without modifying it.

- Program testing and debugging

- Data conversion with the combination of other techniques

©India SAP CoE, Slide 9


ABAP for SD Consultants
1 PrepareMe

2 TellMe

3 ShowMe

4 LetMe

5 HelpMe
©India SAP CoE, Slide 10
R/3 Architecture

©India SAP CoE, Slide 11


R/3 Architecture
Presentation Layer

The presentation layer contains the software components that make up the
SAPgui (graphical user interface). This layer is the interface between the R/3
System and its users. The R/3 System uses the SAPgui to provide an intuitive
graphical user interface for entering and displaying data.

Application Layer

The application layer consists of one or more application servers and a message
server. Each application server contains a set of services used to run the R/3
System

Database Layer

The database layer consists of a central database system containing all of the
data in the R/3 System. The database system has two components - the
database management system (DBMS), and the database itself.

©India SAP CoE, Slide 12


ABAP Program code
A computer program (often simply called a program) is an example of computer
software that prescribes the actions ("computations") that are to be carried out by
a computer.

All ABAP programs are modular in structure and made up of processing blocks.
There are two kinds of processing blocks, those that are called from outside a
program by the ABAP runtime system, and those that can be called by ABAP
statements in ABAP programs

©India SAP CoE, Slide 13


Reports

• Reports are Executable Programs that read data from the database,
processes the data and display the data to the required format.

• Mostly a report does not make any changes to the database

• You can either display the output of a report on the screen, print it
or send it to a file. You can also save it, so that it can be displayed
as often as you like. It is important to be able to do this, because
reading large volumes of original data can impair system
performance.

• Examples of reports are Classical ABAP reports, queries, and


drilldown interactive reports.

©India SAP CoE, Slide 14


Interfaces
Interface refers to the data transfer between two independent systems.
ALE is used for SAP to SAP communication and EDI is mostly used for any two
system communication.

Benefits of EDI-ALE:
• Reduced Data Entry Errors
• Reduced Processing Cycle time
• Availability of Data in electronic form
• Reduced Paperwork
• Reduced Cost
• Standard means of communication

Sender System Data Container - IDOC Receiving System

Purchase Sales
Order Order

©India SAP CoE, Slide 15


Conversion
Conversion programs helps in data transfer from an external system into the SAP R/3
System. In other words, this type of transfer refers to a one-time transfer from a legacy
system to the SAP system. Legacy system is the old system that is being
replaced by the SAP system.

GUI_UPLOAD

Batch Input
Direct Input

Legacy SAP
AL11
Application Application OPEN DATA SET Application
data server file READ DATASET data
CLOSE DATASET

©India SAP CoE, Slide 16


Enhancement
• Enhancements are plug points provided by SAP to add customer
functionality to existing SAP Transactions without modifying it.
• Transaction Code : CMOD, SMOD,SE18, SE19.

Advantages.

They do not affect standard


SAP Code.
• They do not affect software
updates

Techniques for Enhancements


• Customer Exits
• User Exits
Enhancements act as hooks.
• Business Add-Ins.
You can hang your own add-on functionality
onto these hooks.

©India SAP CoE, Slide 17


Forms
• Forms are used for creating and maintaining the output for printing in SAP
system. As output medium it also supports a printer, fax, e-mail or the
internet (by using the generated XML output).
• Transaction Code : SE71, SMARTFORMS

Printer

Application
Program

Web Browser

©India SAP CoE, Slide 18


ABAP for SD Consultants
1 PrepareMe

2 TellMe

3 ShowMe

4 LetMe

5 HelpMe
©India SAP CoE, Slide 19
Modularization
Program Structure

ABAP programs are responsible for data processing within the individual dialog
steps of an application program. This means that the program cannot be
constructed as a single sequential unit but must be divided into sections that
can be assigned to the individual dialog steps.
To meet this requirement, ABAP programs have a modular structure. Each
module is called a processing block. A processing block consists of a set of
ABAP statements. When you run a program, you effectively call a series of
processing blocks. They cannot be nested.
The following diagram shows the structure of an ABAP program:

Data Declaration Dialog Modules Event Blocks Subroutines

©India SAP CoE, Slide 20


Modularization
Procedures:
Procedures contain a set of statements, and are called from other ABAP
programs. ABAP contains the following kinds of procedures,

• Subroutines
• Subroutines are procedures that you can define in any ABAP
program and also call from any program.

• Function modules
• Function modules are procedures that are defined in function
groups and can be called from any ABAP program.

• Include
• If you want to use the same sequence of statements in several
programs, you can code them once in an include program.

©India SAP CoE, Slide 21


ABAP Program code
Subroutines :
Subroutines are principally for local modularization, that is, they are generally
called from the program in which they are defined. You can use subroutines to
write functions that are used repeatedly within a program. You can define
subroutines in any ABAP program.

©India SAP CoE, Slide 22


ABAP Program code
Function Modules :
Function modules are for global modularization, that is, they are always called
from a different program. Function modules contain functions that are used in
the same form by many different programs. They are important in the R/3
System for encapsulating processing logic and making it reusable. Function
modules must be defined in a function group, and can be called from any
program

T Code - SE37

©India SAP CoE, Slide 23


ABAP Program code
Include Programs
Include programs are global R/3 Repository objects. They are solely for
modularizing source code, and have no parameter interface

Creating Include.
Use Transaction SE38 to create a include program.

Using Include
Include <incl>
This inserts the source code <incl> into the ABAP/4 program during the
syntax check and during generation. The INCLUDE statement performs
the same function as if you were to copy the source code of <incl> to
the position of the statement in the calling program.

©India SAP CoE, Slide 24


SAP Database
• The SAP database contains literally thousands of tables that store
information. Some products like ECC and R/3 have more than 30,000 tables
in fact, whereas other products like CRM might have fewer than 10,000.

• These tables are tied to each other through established relationships. This
connection of multiple tables through relationships creates what is known
as a Relational Database Management System (RDBMS).

• Primary Key - Database tables in an RDBMS are required to contain a unique


field that individually distinguishes one particular record from all others in
the database. Eg: VBELN is primary key in VBAK.

• Foreign Key - You use the primary key field in one table to link it to another.
The common link field in the other table is usually not the primary key in the
other table: It is called a foreign key. MATNR is primary key in MARA table
and foreign key in VBAP.

©India SAP CoE, Slide 25


Data Dictionary
• A data dictionary is a central source of information for application data.

• Data Dictionary is Accessed Via Transaction Code SE11,SE16,SE16N

©India SAP CoE, Slide 26


Structure of Data Dictionary
• Transaction Code : SE11 – Define/Manage components of Data Dictionary.
• Transaction Code : SE16 – Define/Manage Table Only.

VIEW 1 VIEW 2 Search Help 2

TABLE 1 TABLE 2 TABLE 3 Structure 1

Search Help 1

DOMAIN

©India SAP CoE, Slide 27


SE11, SE16, SE16N
SE11 SE16 SE16N

This transaction is a This transaction is used This transaction is an


generic transaction for to see the contents of the SAP Enjoy transaction
data dictionary where you table. Table maintenance with a much more user
can maintain all data is not possible here . friendly appearance; it
dictionary objects . supports custom controls
in the form of ALV
controls.

©India SAP CoE, Slide 28


Important SD Tables
Sales Document table
• VBAK Sales Document: Header Data
• VBAP Sales Document: Item Data
• VBFA Sales document: Document flow
• VBPA Sales document: Partner profile
• VBEP Sales document: schedule line data
• VBEH Sales document: schedule line history

Delivery Document table


• LIKP Delivery: Header Data
• LIPS Delivery: Item data
• VBUK Sales document: Header status
• VBUP Sales document: Item status

Billing Document table


• VBRK Billing: Header Data
• VBRP Billing: Item Data

©India SAP CoE, Slide 29


Reports
• Report is executable code that read data from the database, processes the
data and displays the data to the required format.

• Transaction Code : SE38


• Reports are classified into Classical reports and ALV.
Sorting in Descending order
Sorting in ascending order

Summation/Total

Filter ABC Analysis

Graphical display

©India SAP CoE, Slide 30


Process Flow: Classical Report

©India SAP CoE, Slide 31


Process Flow: Interactive Report
event keyword external control
event begin
event end processing block
internal control

event keyword external control

processing block
internal control

…...

©India SAP CoE, Slide 32


Events
INITIALIZATION

AT SELECTION-SCREEN

START-OF-SELECTION

END-OF-SELECTION
} TOP-OF-PAGE

END-OF-PAGE
TOP-OF-PAGE DURING
LINE-SELECTION
AT LINE-SELECTION
Interactive Events AT USER-COMMAND
AT PF<nn>

©India SAP CoE, Slide 33


Events
ABAP/4 report programs are event driven programs
The different events in a report Program are:
Initialization.
Initialization of all the values. You can fill your selection screen with
some values at runtime.
At Selection-Screen.
Validation & Checks of inputted values happen here
Start-of-Selection.
Here the program starts selecting values from tables.
End-of-selection.
After all the data has been selected this event writes the data to the
screen.
Interactive Events.
Used for interactive reporting. It is used to create a detailed list from a
basic list.

©India SAP CoE, Slide 34


Interfaces
• ALE (Application Link Enabling ) is a SAP terminology used mostly for SAP
to SAP communication in Distributed servers system.

• EDI (Electronic Data Interchange) is a technology in itself with its own set of
standards and used mostly for communication between any 2 systems on
different networks

• IDOC (Intermediate Document) is a Data container

• Important T-codes like


WE02 – To view the IDOC
WE09 – To search for an IDOC based on data in the IDOC
WE19 – Test tool to create and simulate an IDOC.

• Important IDOC Status are (For Inbound IDOC)


53 - IDOC successfully posted
51 – IDOC Failed
64 - IDOC ready to be transferred to Application

©India SAP CoE, Slide 35


Conversions/Data Upload
•Data is the single most important asset of a business and data conversion is
therefore a critical success factor in any SAP system implementation.

•Data Migration is the migration/conversion/upload of data from source “legacy


system” to target SAP R/3 system .

Legacy System R/3 System

BATCH INPUT
Data

©India SAP CoE, Slide 36


Conversions/Data Upload

• The Legacy System Migration Workbench (LSMW) is a tool


recommended by SAP that can be use to transfer data once only or
periodically from legacy systems into an R/3 System. Transaction
Code – LSMW

• BDC (Batch Data Communication) also referred as Batch Input is a


technique for mass input of data where data input into SAP screens
is simulated.

• BDC allows to perform database updates in the background using


standard SAP transactions. The resultant entries will be as if the
user had manually entered the data via SAP and no bypassing of
any of the standard SAP consistency checks, authorizations etc.

©India SAP CoE, Slide 37


Overview of Batch Input Session

The first batch input method is to create a batch


BDC
input session. It is the processing of this batch
PROGRAM input session that updates the database, not the
External execution of the batch input program.
Data

BATCH SAP
INPUT DATABASE
SESSION TABLE

©India SAP CoE, Slide 38


Batch Input Methods
METHOD #1 CALL TRANSACTION
Data consistency check with the help of screen logic.

BATCH INPUT SESSION


METHOD #2 Data consistency check with the help of screen logic.

DIRECT INPUT
METHOD #3 SAP function modules execute the consistency checks

©India SAP CoE, Slide 39


Process flow of Batch Input Session

Opens the Session

Process BDC table for each record

Close the Session

Function Modules
©India SAP CoE, Slide 38
Processing Batch Input sessions
When you create a batch input session, it remains in the batch
input queue until it is explicitly started. Session processing can be
started in two ways:

An on-line user can start the session using the batch input menu
options. (To access the batch input options, choose System ®
Services ® Batch Input.) Transaction code - SM35

You can submit the background job RSBDCSUB to start a session


in background processing. If several sessions have the same
name, RSBDCSUB starts them all.

©India SAP CoE, Slide 39


Transaction Recorder (SHDB)
T-Code SHDB is used for recording the transactions as well as creating the
skeleton programs that contain all the necessary code for creating batch
input sessions

Features:
You can use the recording to create

Data transfer programs that use batch input or CALL TRANSACTION


Batch input sessions
Test data
Function modules.

Note: It doesn‟t record F1, F4 and Scrollbar movements

©India SAP CoE, Slide 40


Steps in Transaction Recorder
Step 1. T-Code SM35 Step 2. Create a customer
Create new recoding

©India SAP CoE, Slide 41


Steps in Transaction Recorder

©India SAP CoE, Slide 42


Steps in Transaction Recorder
Step 3. Recording completed. Step 4. Recording Created and
Save the recording saved

©India SAP CoE, Slide 43


Data upload flow

Research Transaction

Code BDC Program

Execute BDC Program

Batch Input Session Control

Process Batch Input Session

©India SAP CoE, Slide 44


Steps of LSMW
Create Project, Sub-Project and Object

Maintain object attribute, Source


Structures, Source Field

Field mappings and Translations

Specify and assign the data file

Read the data file and Convert data in


SAP format

Start DI programs and


SAP Database will Update

©India SAP CoE, Slide 45


Enhancement
Suppose we need some functionality which is not provided in sap what do you do. SAP
has provided you with three options.

1) Customizing – Done through SPRO


2) Modifications –Break the SAP standard code and modify.
3) User Exits – To avoid modifications, SAP has provide some exit points to add
customer's own program .

• User exits are routine which SAP allows you to add in additional customized programs
process without affecting the standard SAP programs.

• User exits allow developers to access and modify program components and data
objects in the standard SAP System.

• On upgrade, each user exit must be checked to ensure that it conforms to the standard
system.

SAP user exit are usually declare as a form routine :-

form userexit_xxx
........................
endform

©India SAP CoE, Slide 46


Enhancement
• User Exits for SD are found in IMG under
Sales & Distribution→ System Modifications→ User Exits

• Business Add-Ins for SD are found in IMG under


Sales & Distribution→ System Modifications→ Business Add-In

• Function Module exit is implemented as:


CALL CUSTOMER.-FUNCTION <3 digit suffix>

©India SAP CoE, Slide 47


User Exits
Few examples of User Exit programs in Sales Order

User exits are in the program MV45AFZZ


E.g...
• USEREXIT_MOVE_FIELD_TO_VBAK - assign values to new fields at sales
document header level.

User exits in the program MV45AFZA


E.g...
• USEREXIT_MOVE_FIELD_TO_KOMKD
Include or assign values to additional header fields in the communication
structure KOMKD taken as a basis for the material determination.

User-Exits in program MV45AFZB


E.g...
• USEREXIT_CHECK_VBAK
This user exit can be used to carry out additional checks (e.g. for completion) in
the document header.

©India SAP CoE, Slide 48


User Exits
Few examples of User Exit programs in Invoice

User exits are in the program RV60AFZZ


E.g...
USEREXIT_NUMBER_RANGE -
The internal number range used in the standard system is specified in
the billing type table and can be changed in this user exit.

User exits in the program RV60AFZC


E.g...
USEREXIT_FILL_VBRK_VBRP
This user exit is only called when the billing document is created. It is
used to provide the header and the item of the new billing document
with deviating or additional data.

©India SAP CoE, Slide 49


Forms
• SAPscript and Smartform are the tool that SAP provides for
creating layout sets.
• Transaction Code for SAP Script is SE71
• Transaction Code for Smartform is SMARTFORMS
• SMARTFORMS are client independent while SAP Script are Client
Dependent
• The basic configuration required to do for Smartform/SAPscript is
creating output type and attaching the Smartform to the output
type.
• NACE is the transaction to set the output type.
• In NACE transaction first the application is selected ( e.g.V1 Sales,
V2 Shipping etc). Then output type is selected. Sometimes output
type is created newly if driver program and Smartform are custom
program and not SAP standard ones

©India SAP CoE, Slide 50


Forms
Whenever new output type is created , 3 parameters are required. They
are :
- Smart form / SAP script Name
- Driver Program Name
- ENTRY routine name.

Form Description Program name SAPscript name Smartform name

Sales order RVADOR01 RVORDER01


confirmation

Delivery Note RLE_DELNOTE RVDELNOTE LE_SHP_DELNOTE

INVOICE RLB_INVOICE RVINVOICE01 LB_BIL_INVOICE

©India SAP CoE, Slide 51


How SAPscript works ?
Output determination configuration

Read Data
Output Form
S
SAP Layout set
Program
Doocuument
Sales order, Billing
Layouts of Sales
document etc
order, Billing
document etc

Printer / Font Configuration

• Output program: Extracts data from SAP data dictionary


• Layout set: Formats the extracted data
• Output determination configuration: Configures triggering event, timing/destination
• Printer / Font configuration: Configures impact / laser printer, bar code, logo

©India SAP CoE, Slide 52


How SMARTFORM works ?
Smartform has 3 driving components : Print Program, Layout
Set and Function module.

1. Application Data is
fetched by the Print
Program from the
database depending
upon the selection
screen parameter.
2. Function module of a
Layout Set is called in
a program for
placement of the
data.
3. The output of
application document
is sent to printer or
mail or fax.

©India SAP CoE, Slide 53


Scheduling a Background Job
T-Code SM36

©India SAP CoE, Slide 54


Scheduling a Background Job
Chose Job Overview to view all existing Job status

©India SAP CoE, Slide 55


Utilities
Debugger - It enables observations and validations of code by
displaying data objects and help in checking the flow logic of code.

SAP Notes provide urgent corrections and solutions for smaller


problems.

Runtime Analysis - It shows how long system takes to process ABAP


code, from single statements to a complete transaction. It also helps to
know the System and the data retrieval time from database. T- Code is
SE30.

SQL Trace - It helps to knowing the tables for data retrieval by


activating the trace by ST05 and then execute the functionality.

©India SAP CoE, Slide 56


Debugger
• It is a tool which enables the programmer to monitor the execution
of a program, stop it, re-start it, run it in slow motion, change values
in memory and even, in some cases, go back in time.

• The basic steps in debugging are:


– Recognize that a bug exists
– Isolate the source of the bug
– Identify the cause of the bug
– Determine a fix for the bug
– Apply the fix and test it

©India SAP CoE, Slide 57


Utilities: Debugger
• The debugger is a programming tool used to analyze ABAP programs by line
or section.
• With this tool we can display data objects and check the flow logic of
programs
Debugger Function Keys (/h)
F5 Execute a single line of code.
F6 Execute block of code
F7 Return
F8 Run to Cursor

Display Modes for Debugger:

Fields : Displays the contents of a variable


in the code.
Table : Displays the contents of an
internal table.
Breakpoints : Displays list of Break-points
in the code.
Watchpoints : It is set to interrupt the program
for field value changes.

©India SAP CoE, Slide 58


Utilities: SAP Notes/Patch
• SAP Notes contains instructions to remove errors from SAP System.
• Transaction Codes : SNOTE , SPAU ,OSS1 or SAP Market Place

Major Features

• Finding an SAP Note


• Loading an SAP Note
• Classifying SAP Notes
• Implementing Correction
Instructions

SAP Notes can be searched


Implemented based on Note
Number, Application
Component , Implementation
Status.

©India SAP CoE, Slide 59


Utilities: ABAP Runtime Analysis
• The runtime analysis provides an overview of the duration and performance
of your source code, from individual statements up to complete
transactions.
• Transaction Code : SE30

Major Functions.
• Gives Tips & Tricks for coding
• Setting the measurement
restrictions
• Start the runtime analysis in the
current
session
• Start the runtime analysis in a
parallel session
• Display and process
performance files
• Display database, system and
ABAP execution time

©India SAP CoE, Slide 60


Utilities: Trace
• Trace tool is used to monitor and analyze the performance of the system in
database accesses and remote calls of reports and transactions.
• Transaction Code : ST05

Major Features

• Trace on (starts recording)


• Trace off (stops recording)
• Trace function selection
SQL Trace, Enqueue Trace.
Display the basic or extended list
• Start the Explain SQL to analyze
an SQL statement or trace file
• Give details of database usage

©India SAP CoE, Slide 61


ABAP for SD Consultants
1 PrepareMe

2 TellMe

3 ShowMe

4 LetMe

5 HelpMe
©India SAP CoE, Slide 62
LetMe
In debug mode let the participant(s) find a Z message in a particular Txn

Let the participant(s) find out a table where F1→F9 will reach a structure

Let the participant(s) find out a User Exit

Let the participant(s) apply a note through Txn <snote>

©India SAP CoE, Slide 63


ABAP for SD Consultants
1 PrepareMe

2 TellMe

3 ShowMe

4 LetMe

5 HelpMe
©India SAP CoE, Slide 64
Tips and Tricks
• <Kopf> is a German word for Head. This generally all Header tables have a
<K> in their name which distinguishes them from the Position tables with a <P>
in them. for example VBAK/P or VBRK/P

• Use table TSTC to find out all „Z‟ Programs and Transaction Codes existing in a
system.

• By pressing F1 → F9 will normally show you the field & table. If you reach the
structure then to find a table check where-used-list ............ More details?

• To find out a User Exit, check in IMG for system modifications. To find
enhancement, go to SMOD and check with the help of application area and
development class

• In debug mode you can change the values in a table and test

• How to see Spool request, use T-code SP01

©India SAP CoE, Slide 65


Additional Info
Variants
Variants are input data which are filled in the selection screen and then
saved so that at runtime the variant can be selected and then the entire
selection screen is filled with the desired values

Background Processing
When a program takes a long time to execute then one can execute the
program in background so that a job is set up for that program.
The job can be seen in transaction SM37.
The job log gives the exact start time and the end time for the job

CATCH - Catching Runtime Errors


CATCH SYSTEM-EXCEPTIONS except1 = rc1 ... exceptn = rcn.
ENDCATCH.
The CATCH…ENDCATCH block allows the programmer to catch
ABAP runtime errors and assign these to a SY_SUBRC value

Comments
Commented lines in the program start with asterisk (*)
To comment a part of line use double codes (“).
©India SAP CoE, Slide 66
Additional Info
• Unlike most IMG configuration, all program except SAP-scripts are
necessarily client independent. Thus a program developed in one client in
a server is also automatically available in all other clients in the same
server.

• Print Program is assigned to Output Condition Type. This assignment


needs to be done manually in all the clients.

•Table document.

©India SAP CoE, Slide 67

You might also like