Вы находитесь на странице: 1из 62

ABAP for functional consultants

Agenda
Da y 1 Introduction to ABAP Workbe nch
Clie nt Se r ve r Ar chite ctur e ABAP Re pos itor y and ABAP Wor k Be nch Tr ans actions Intor duction to ABAP Pr ogr am m ing Language

Da y 2 Da ta Mode lling a nd Da ta Obje cts


Str uctur e s Inte r nal Table s Tr ans par e nt Table s

Da y 3 Use r Ex its a nd Ba di's


Function M odule s

Da y 4
ALE & Idocs Sm ar tfor m s

Da y 5
ABAP De bugge r Pe r for m ance E xte nde d Syntax Che ck

Introduction to Client server architecture

Presentation server

SAP GUI Enterprise Portal ABAP Program

Application server

Database layer

Introduction to client server architecture


Database layer is the lowest level. Data is managed using the relational database management system (RDBMS) concept. This layer includes all application data, programs. The ABAP programs run in the application layer. The ABAP programs then read the data needed for processing from the database. The Presentation layer contains user interface like SAP GUI, Enterprise Portal for the user to view the data from the application layer

ABAP Repository and ABAP Workbench


ABAP Repository ABAP Repository is the central place for all ABAP objects . Repository contains both SAP standard and custom objects. Repository is client independent. Search tool in a repository is repository information system. This is used to make random search like search for all programs by a particular package To get to the repository information system, follow the menu path from SAP access Menu. Tools->ABAP Workbench->Overview->Information system.

ABAP Workbench
Contains tools for editing and creating objects in the repository. The most important tools are ABAP Editor for editing source code ABAP dictionary for editing database.. Screen Painter for configuring screens. Menu Painter for designing user interfaces Function Builder for maintaining function modules Class builder for maintaining classes and interfaces
4

Introduction to ABAP Programming Language


ABAP is platform independent. It is independent of the database and operating system. Open SQL can be embedded in ABAP for direct database access. Is upward compatible. ABAP programs have individual statements The first word is the ABAP Keyword and the last statement ends with a period. Statements can be written in multiple lines with atleast one space between words ABAP does not differentiate between upper and lowercase for keywords. Comment lines begin with a * Double quotes indicate the rest of the statement is comment. Identical beginning part of the records are written by a colon. After the colon the end parts are separated by commas. Sample ABAP Statements Data: lv_result lv_start type type i, i. Chained statements

Move

to

lv_result.
5

Some system fields

System field sy-index sy-tcode Sy-datum Sy-uzeit Sy-repid

Description Loop counter Current transaction Local date of system Local time in system Name of the current program

Sy-langu
Sy-mandt Sy-uname

Logon language
Logon client Logon Name of user

Structures
Structures allows to combine values that logically belong to one data object. Structure variables are defined in the program with DATA statement.

Structure types can refer to globally defined structures in ABAP dictionary or local for the particular program.
With TYPES statement you can define local structures TYPES: BEGIN OF structure name. END OF structure name.

DATA gs_vbeln TYPE VBELNTMP.

Definition of structures global type

vbeln
gs_vbeln

selkz

intkz

Defining Global Structures

Name of structure

Name of component

Type to which component is assigned

Structures
Components of structure are addressed using the structure name component name. MOVE-CORRESPONDING copies the contents of the source structure to target structure one component at a time.

First name Employee

Last name

Address

Phone

DOJ

Emp_master First name

Middle name

Last name

DOJ

SSN

Transparent table
Transparent table Field
Described by

Data Element
Points to

Domain

Database

Table with data

Technical structure of a transparent table


Transparent tables defined in the application is a part of the corresponding database table that stores the actual data. The fields of the transparent table point to the corresponding columns on the database table. Data elements are used to describe the individual fields. Data elements refer to domains for technical properties. In addition to list of fields we need more information to create a database table some of them are Key fields are to declared at the beginning of the table. This determines the key of the table. Technical properties that are needed to create the database table like size and mode of access. Secondary indexes and buffering to speed up access to the table.`

Defining a transparent table

Definition of a transparent table is similar to a structure except that fields of a transparent table are a list of elementary fields. Transparent tables can also be used like structures in programming for defining structure types. The major difference between structure and transparent table is the corresponding table on the physical database. Also there are technical properties like key fields definition and size which are defined in transparent table.

Differences between transparent table and structure

ABAP Program

ABAP Dictionary
Transparent table VBAP

Database

DATA gs_vbap TYPE vbap. SELECTFROM VBAP INTO gs_vbap..

VBAP

BA BA 17

gs_vbap

DATA gs_vbap TYPE zs_vbap.

Structure ZS_VBAP

gs_vbap

Transparent tables as data types Dos and Donts

DOs

Use transparent tables as data types only when we use it in direct connection with accessing a database.
DONTs Transparent tables should not be used as data types in all cases. Transparent table should not be used as data types in defining user interfaces. If transparent table is used as data type in user interface or interface it causes dependency on definition of database objects.

Internal tables
Internal table is a data object to keep identically structured data records at runtime. Number of data records depends on system capabilities only. ABAP runtime system manages the size of internal table. Individual data sets are known as table rows or table entries. Used in retaining data from database tables or sequential files for future processing. Also used in formatting data.

DATA gt_tab TYPE standard <Table Type>.


DATA gt_itab TYPE Sorted TABLE OF < struc >. Hashed

DATA gt_itab TYPE TABLE OF <Struc_type>.

15

Access Internal tables

APPEND APPEND gs to gt_itab.

INSERT
INSERT gs into table gt_itab <Condition>.

16

Access Internal tables


READ READ TABLE gt_itab into gs <condition>

CHANGE MODIFY TABLE gt_itab FROM gs <condition>

DELETE

XXXXXXXX

DELETE gt_itab <condition>

17

Reports

18

Report: Structure
Most reports will generally follow the following pattern: Data Declaration Parameter and/or Select Options Events

Output

19

Report: Events
Reports react to user action, called events. Initialization

At Selection-Screen
Start-of-Selection End-of-Selection Top of Page End of Page

20

Report: Use of Events


Initialization (Default value in selection fields)
Used for assigning any default values to fields on the selection screen

At Selection-Screen
Used to validate screen input

Start-of-Selection
Select data from tables and build logic to retrieve and manipulate data

End-of-Selection
To aggregate (Totals, Sum, etc)

Top of Page
Called the first time a write statement is executed in the program. Prints the column headers

End of Page
For displaying footer text like page no, etc.

21

Report: Exercise
Build a report where the user enters the sales order no and the report displays, those sales order no header and line item details

22

User Exits and BADIs

23

User Exits (Customer Exits)


User Exit / BADI The R/3 enhancement concept allows you to add your own functionality to SAPs standard business applications without having to modify the original applications Advantage of User-Exits They do not affect standard SAP source code

They do not affect software updates

User Exits (Customer Exits) Types of Exits


Menu Exits Menu exits add items to the pulldown menus in standard SAP applications . You can use these menu items to call up your own screens or to trigger entire add-on applications.
Screen exits add fields to screens in R/3 applications Function module exits add functions to R/3 applications

Screen Exits

Function Module Exits

User Exits : How to find?


Using TCode SMOD Search in code for Call Customer From table TADIR

User Exits (Customer Exits)


Creating an Add-On Project
Find appropriate Enhancement Name (Transaction SMOD ABAP Workbench Utilities Enhancement Definition Go to Transaction CMOD

User Exits (Customer Exits)


Creating an Add-On Project Enter Enhancement Name (MGA00001)

User Exits (Customer Exits)

User Exits (Customer Exits)


Activate Project

User Exits (Customer Exits)


Sample Function Exit Code

User Exits (Customer Exits) - Exercise


Implement a user exit which will change the description of the sales

order line item. If the sales order line item description is 123, it will change the sales order description to 789.

BADI (Business Add-Ins)


Business add-ins are enhancements to the standard version of the system using OOPs Concept BADIs can be for single use or multiple use. BADIs can be filter specific, for eg for a country, for a company code, etc BADIs are supported by SAP in case of upgrades.

BADI
It allow for a multi-level system landscape (SAP, countryspecific versions, industry solutions, partner, customer, and so on). You can create definitions and implementations of BADI at any level of the system landscape.

User Exits
Customer exits support twolevel infrastructure (SAP and customer solutions )

BADI (Business Add-Ins)


To Display Available List of BADI From the SAP menu, choose Tools ABAP Workbench Utilities Business Add-Ins (transaction SE18)

BADI (Business Add-Ins)


To Implement BADI From the SAP menu, choose Tools ABAP Workbench Utilities Business Add-Ins (transaction SE19) and Activate it.

BADI (Business Add-Ins)


To Implement BADI From the SAP menu, choose Tools ABAP Workbench Utilities Business Add-Ins (transaction SE19)

BADI (Business Add-Ins)

Interface

Function Modules

38

Report - Function Module


Function modules are ABAP routines that are stored in a central function library They are not application-specific, and available system wide

You call a function module by its name (which must be unique) in a CALL FUNCTION statement
Function modules must belong to a pool called a function group.

Function Builder Transaction SE37

Report - Function Module


Function Module has 4 types of Parameters
Importing Values to be imported into the function module are passed using the importing parameter. Only work areas or structures can be passed Exporting Values to be passed out of the function module to the calling program are passed using the exporting parameter. Only work areas or structures can be passed Changing Changing parameters are used to pass data which is likely to be processed and changed in the function module and returned back to the calling program. Tables Internal tables can be passed the function module using the tables parameter

Report - Function Module


Initial screen - Creating a new Function Module

Report - Function Module


Function Module Interface

Report - Function Module


Function Module Interface

Report - Function Module

You can Trigger Exception using RAISE statement Call a function module from within any ABAP program Using Call Function
CALL FUNCTION <function module> [EXPORTING f1 = [IMPORTING f1 = [CHANGING f1 = [TABLES f1 = [EXCEPTIONS e1 = [ERROR_MESSAGE [OTHERS = ro]]. a1.... a1.... a1.... a1.... r1.... = fn fn fn fn en = = = = = an] an] an] an] rn rE]

Report - Function Module


Remote Enabled Function Modules (RFC) are special Function Modules which can be called from a different SAP system The remote destination should be defined in TCode SM59 While creating a RFC select the Remote Enable Module option button on the attributes tab of the Function Module.

Report - Function Module - Exercise


Create a function module, which will have the sales order no as the importing parameter and will return the corresponding billing document details.

ALE-Idocs

47

ALE Integration technology

Accounting
Controlling Purchasing

Sales shipping and billing

Local Purchasing
Sales, shipping and billing Plant Maintenance Inventory Management

Purchasing Inventory Management

ALE
Supports data consistency and data availability in distributed systems. Integrating system through asynchronous messaging using IDOCs or coupling systems narrowly through synchronous BAPI calls. Enables distribution between systems with different versions. Enables SAP R/3 to communicate to other systems. Provides functions for administration, monitoring and development. Library of ALE business processes to cover important business functions.

IDocs
An IDOC is a container for the data of a business object or technical R/3 object. Each IDOC has a message type. This indicates the type of business object or the business function of the data. Message types have processing rules in the receiving system. An IDOC contains segment hierarchy. The IDOC type describes the technical structure of the IDOC. IDOC types have versions.

50

IDocs
An Idoc consists of 3 types of records. Control Record. One Control Record per Idoc. Data Record. Multiple data records per idoc. Data Records contain Data to be transffered Status Record. Status Record will have give the status of the idoc. Idoc status can be checked using TCodes WE02, WE05 and WE09 IDocs can be reprocessed using TCode BD87 To copy Idocs use TCode WE19

51

IDocs Outbound Staus


2 3 4 5 6 7 8 9 10 11 12, 13, 14 15 16 17 18 20 22 23 24 25 26 27 29 30 31 33 34 36 37 38 39 40 41 Yes No Yes Yes No Yes No Yes No Yes No Yes No Yes No Yes No Yes No Yes Yes Yes Yes No No No Yes Yes Yes No No Yes No Error Error if transaction SM58 indicates an RFC transmission Error Error Harmless Error Harmless Error Harmless Error Harmless Warning Harmless Warning Harmless Error Harmless Error Harmless Warning Error Error Error Harmless Harmless Harmless Error Error Error Harmless Harmless Error Harmless Error passing data to port Data pass to port OK Control information of EDI subsystem Translation Translation Syntax check Syntax check Interchange handling Interchange handling Dispatch OK Interchange acknowledgement negative Functional acknowledgement Functional acknowledgement negative Triggering EDI subsystem Triggering EDI subsystem Dispatch OK, acknowledgement still due Retransmission Control information of EDI subsystem Processing despite syntax error Syntax check ALE error Error in ALE services Ready for dispatch (ALE) IDOC is marked for deletion Original of an IDOC which was edited Error in control record of IDOC Timeout error; electronic signature not performed IDOC added incorrectly IDOC archived Receive confirmed Application document not created in target system Application document created in target document

52

IDocs Inbound Staus

Code 51, 52 53 54 55 56 60 61 62 63 64 65 68 70 73

Error Yes No Yes No Yes Yes Yes No Yes No Yes No No No

Event Severity Error Harmless Error Harmless Error Error Warning Harmless Error Harmless Error Harmless Harmless Harmless

SAP Meaning Posting error Posting successful Error during formal application check Formal application check IDOC with error added Syntax error Processing despite syntax error IDOC passed to application Error passing IDOC to application IDOC ready to be passed to application ALE error IDOC is marked for deletion Original of an IDOC which was edited IDOC archived

53

Smartforms

54

Smartforms
SRM

SAP Fin

SAP Smart forms CRM SAP HR

Why Smart forms and some advantages over SAPscript


Used to print documents with consistent design. Smart forms include tools for designing forms and defining user interfaces to the application programs that use the form.

With WAS ( Web application server ) smart forms can be generated in HTML and be made available to users.
There are a number of predefined forms for all SAP applications.

Advantages over SAPscript


Easier to customize forms as the tools offer more functions and also because the interface between forms and application programs have been redesigned. Some tasks such as retrieving additional data within forms do not require the use of special scripting language. SAP smartforms are repository objects and can be connected to the transport system.

Calling a smartform
To call the initial screen of a smartform call the transaction /SMARTFORMS. To select the relevant form objects choose the radio button Forms Styles Text Modules To work on the form choose form and then the radio button.

To create , display and change forms there is a graphical tool called the SAP Form Builder.
Never change the standard smart forms as they will be lost during the upgeade. To change a smartform copy the original form to a Z or customer namespace and then modify the form. To make settings specific to SAP Form Builder use the menupath Ultilities>Migration->Import SAPscript form.
57

SAP form builder

Navigation Tree

Maintenance Screen

Form Painter

Edit Smartforms
Use SAP Form Builder to edit forms. SAP Form builder is divided into three areas: Navigation Tree: Graphical tree to display hierarchy in SAP smart forms. Individual form elements are displayed as nodes. The field list with variables is displayed below the navigation tree. Maintenance Screen: This is used to edit the attributes of the node selected. We can use the table painter to determine the layout of the table. All error messages are displayed below the maintenance screen. Form Painter: This is used to determine the layout of the page, such as the position and size of the text windows. Smartforms are connected to the transport system so they have to be assigned to packages. We can do this when we save the text module for the first time. Each smartform has a original language. The original language can be changed via the general properties tab.

59

Smartforms Exercise
Edit a customized PO smartform to add a new column at the item level

60

Thank You

61