ABAP Basics Understanding Concepts

Embed Size (px)

Citation preview

  • 7/27/2019 ABAP Basics Understanding Concepts

    1/26

  • 7/27/2019 ABAP Basics Understanding Concepts

    2/26

    Major Implementators:Price water House & Coopers Anderson Consulting Ernst & Young

    KPMG & Deloitte & Touche etc.,

    History

    Company : SAP AGWhen : 1972Where : Walldorf, GermanyBy Whom : 4 former IBM

    employees.R/3 Introduction : 1992 position in 1995(ISV): 5

    SAP ProductsR/2 System R/3 System

    R/2 SystemIt is a main frame system compatible to IBM,Siemens etc.,Data intensive and big centralised Industries.It is not open system.

    (It can not communicate with other systems.But with the help of ALE it can be linked toR/3 and can be made open system)

  • 7/27/2019 ABAP Basics Understanding Concepts

    3/26

    R/3 systemClient server system Multi Lingual It can be easily customized b ased on

    countrys needs. It has OSS (Online Support System) It has other services like Information serviceand Maintenance service.It has Preventive service (early watch serv.)

    SAP R/3 Architecture

    Database Server : Stores Database.Application Server : ContainsSoftware for Running the Application Logic.Presentation Server : Graphical User Interface

    The advantage of having 3 tier or 3 layeredArchitecture is to reduce traffic on theDatabase Server.

    Based on the required degree of distribution,you can combine two servers or all threeservers in the same machine (Stand alone).

    PresentaionServer

    PresentationServer

    PresentationServer

    ApplicationServer

    PresentationServer

    PresentaionServer

    ApplicationServer

    PresentationServer

    ApplicationServer

    Database

    Server

  • 7/27/2019 ABAP Basics Understanding Concepts

    4/26

    ABAP/4 Dev WorkbenchIt contain different tools for development of

    ABAP/4 objects, checking and analysing programs and finally transportation of objects.

    1) ABAP/4 Language2) Data modeler 3) Object browser 4) Repository5) Test & Analysing tools6) The Query and

    7) Work Bench Organizer

    ABAP/4 LanguageIt is the Central part of Middle ware layer that

    eliminates dependencies from Hardware,Operating Systems or database managementsystems.

    Data Modeler Relation ship between the tables are stored inthe form of ER diagrams.

    (ER = Entity Relation ship)

    Object Browser

    Hirarcheal representation of Programs,Screens, Menus, Transactions, Tables etc.,

    Repository

    The ABAP/4 Repository is made up of following Runtime Objects.Programs Screens and Dictionary

  • 7/27/2019 ABAP Basics Understanding Concepts

    5/26

    Dictionary contains Metadata. Metadata isnothing but description of data anddefinitions.

    Test & Analysing ToolsFor testing and analysing performance of Programs and Transactions.

    Work Bench Organizer Transportation of Objects between thesystems.

    Introduction to ABAP/4 ABAP : Advanced BusinessApplication Programming 4 : Fourth generation Language Multi Lingual Only Tool for developing SAPapplications. ABAP Workbench contains all tools,

    needed to create ABAP/4 Programs. ABAP/4 program contains all usual controlstructures and modularization concepts. After coding, we will save and generate.

    During generation, the system creates aRun Time object. When we execute, thesystem executes this Run Time Object.

    Structure of ABAP/4 Programs

    ABAP is different from sequential programming languages such asFORTRAN, PASCAL and

    C.

  • 7/27/2019 ABAP Basics Understanding Concepts

    6/26

    Instead it shares certain features with eventOriented programming languages such as VBand

    JAVA. An ABAP/4 program has modular structure. Source text (processing Block) alwaysconsists, Collection of One or more

    programming modules Programming module consists of sequentialstatements. With in the processing Block, we can usegeneral Control statements such as DO, IF,WHILE and

    CASE statements.Execution of ABAP/4 Programs

    For Execution of ABAP/4 Programs youneed a special Run Time Environment . This Run Time Environment is responsible

    for calling the individual program modulesone after the other .

    This Run Time Environment is nothing but

    ABAP/4 Processor .

  • 7/27/2019 ABAP Basics Understanding Concepts

    7/26

    Characteristics of ABAP/4Programming

    Declarative Elements for declaring Data. Operational Elements for Manipulating data. Control statements for processing

    program flow. Functions for processingcharacter strings. Subroutines with or without

    passing values. Central Library with special typeof Subroutines called Functionmodules. Open SQL (a subset of SQL) toread and change data base tables.

    Allows you to define and processInternal Tables. Allows you to store data as

    Sequential files on Applicationand Presentation Servers.

    Types of ABAP/4 Programs Executable program (1) INCLUDE program (I) Module pool (M) Function group (F) Subroutine pool (S)

  • 7/27/2019 ABAP Basics Understanding Concepts

    8/26

    SAP differentiates between twogeneral types of ABAP/4 Programs. Report Programs

    Dialog ProgramsReport Programs Reports are stand alone programs. We use reports to read data base tables andrepresent results in Lists Reports are collection of processing blocks,controlled by System calls depending onevents. Reports can use LDBs or SELECTSTATEMENTS defined by DEVELOPER. Reports can call Dialogue programs andvice versa.

    Dialogue Programs Dialogue programs are not stand alone

    programs. (we have to link the dialogue programs to at least one or more SCREENSand TRANSACTION CODES)

    We use Dialogue Programs to read andchange Database tables. Dialogue programs are controlled byScreen flow logic. Dialogue program is also called as Module

    pool program or TRANSACTION. These module pools are separated into PBOand PAI events. Collection of PBO, PAI and a screen iscalled DYNAMIC PROGRAM (DYNPRO). A module pool must have at least oneDYNPRO.

  • 7/27/2019 ABAP Basics Understanding Concepts

    9/26

    DATA TYPES

    System Defined 1)Elementary

    2) Structured

    User Defined 1) Elementary

    2) Structured

    1) Elementary - System Defined Data

    Types Character (C) Numeric Text (N) Integer (I) Packed (P) Float (F) Date (D) Time (T) Hexadecimal (X)

    2) Structured - System Defined DataTypes

    All Database Tables

    3) Elementary - User Defined DataTypesTypes

    4) Structured User Defined Data TypesInternal TablesField Strings

    DATA DICTIONARY

  • 7/27/2019 ABAP Basics Understanding Concepts

    10/26

    The ABAP/4 Data Dictionary is the centralcomponent of ABAP/4 Repository. It is centralised and structured source of information for business applications It is the source of every definition with inR/3 system. It is totally integrated with other tools of Dev. environment like Screen painter etc.,

    Some of the main available functions inthe ABAP/4 Dict. Management of data definitions (Select,Insert, Update and Delete) Preserve data integrity. Information about the defined relationship

    between two tables or even dictionary tellswhether table is active or empty.

    Dictionary Objects

    Tables Structures View Data element Domain Lock Objects and Match Code Objects

    TableA Table is a two dimensional data matrix. A Table contains Rows and Columns.Rows contain Records while Columncontains Fields.A Table contains zero or multiple Records.

  • 7/27/2019 ABAP Basics Understanding Concepts

    11/26

    Transparent Table, Pooled Table andClustered Table etc., comes under Tables.

    StructuresA Structure is similar to a Table that do nothave any contents. It is like Table or Viewwithout any records.The basic difference between Structure andthe Table is that the Structure does not exist atthe underlying data base level. Structure exists

    as Definition in the Dictionary. ViewA View is an imaginary table. It contains data,which are really stored in other Tables. Thecontents for the View are dynamicallygenerated when called from program.Projection (fields) and Selection (Records) arePossible using Views also.

    Data element Data element an intermediate Object

    between Domain and Table field. It isthe definition of the Properties and Typefor a Table field.

    A field in R/3 system is always associatedwith Data element, which at the same timeis related to Domain.

    Domain

    It is the formal definition of data types fromTechnical point of view.They set attributes such as data type, length,

    possible value range and so on.

  • 7/27/2019 ABAP Basics Understanding Concepts

    12/26

    Lock ObjectsUsed for locking the access to data base.This mechanism is used to enforce data

    integrity, i.e., two users can not update thesame data at the same time.With Lock Objects, you can lock a table fieldor whole table.

    Match Code ObjectsA Match Code is a tool to help you in

    searching for data from the database.

    DATA OBJECTSData Objects

    Cannot exist without Data types.Occupies memory space.Created during Run Time.

    Data Object Types

    InternalExternal

    System DefinedSpecial

    Internal Data Objects

    Variables

  • 7/27/2019 ABAP Basics Understanding Concepts

    13/26

    ConstantsLiterals

    Variables

    Data a type value 1234. During run time, Data Object A iscreated

    and its value is 1234.The value of A in this case (declared asvariable) can be changed during run time.

    a = a + 1 .

    Constants

    Constants a type i value 1234.During run time, Data Object A iscreated

    and its value is 1234.The value of A in this case (declared asconstant) cannot be changed during run time.

    LiteralsData a(10) value ABCDEF.

    During run time, Data Object A is createdand its value is ABCDEF.

    External Data ObjectsAll Table fields comes under thiscategory.Data a like sflight-carrid

    value SQ. During run time, Data Object A iscreated and its value is SQ.

    System defined Data Objects

    Space , and System variables comesunder this category.

    Data a like sy-datum.

  • 7/27/2019 ABAP Basics Understanding Concepts

    14/26

    a = sy-datum.During run time, Data Object A is createdand its value is todays date.

    Special Data ObjectsParametersSelection Criteria

    ParametersData : a type i value 123, b type i value 321.

    You can not assign another set of values to a& b, unless we change these values with in theabove code.

    Hence the need for Parameters. Parameters : a type i,

    b type i. With parametersdeclaration a selection screen is created duringrun time and the user can input any number of sets of values.

    You can assign default values variables

    declared under parameters. Parameters : a type i default 123,

    b t ype i default 321. During run time, the above default valueswill appear in the selection screen. User canuse the same values or he/she can change theabove set of values for later use.

    Selection CriteriaData : a like sflight-carrid.a = SQ. You can not assign another value to a,

    unless we change this value with in the abovecode.

    Hence the need for Selection Criteria.

  • 7/27/2019 ABAP Basics Understanding Concepts

    15/26

    Select-options a for sflight-carrid.

    With select-options declaration a selectionscreen is created during run time and the user

    can input any range of values.

    You can assign default values to variablesdeclared using select-options.

    Select-options: a for sflight-carrid defaultSQ. During run

    time, the above default values will appear inthe selection screen. User can use the samevalue or he/she can change the above valuefor later use.

    CONSTRUCTSBranching

    If * Elseif * Else *Endif.

    Case * Endcase.Looping (System index SY-

    INDEX)Do * Enddo.While * Endwhile.

    If * Elseif * Else * Endif.If a = 5.write: / five. Elseif a = 10.Write:/ Ten. Else. Write:/ Others. Endif.

    Case ** Endcase.

  • 7/27/2019 ABAP Basics Understanding Concepts

    16/26

    Case a.When 5. write: / five. When 10. Write:/ Ten. When Others. Write:/ Others. Endcase.

    Do ** Enddo. Do 2 times.

    Write:/ ABCD. Enddo.ABCD ABCD

    Do ** Enddo contd.A = 5. A = 5.Do 2 times. Do 2

    times.Write:/ A. A = a + 1.A = a + 1. Write:/ a.Enddo. Enddo.

    Do ** Enddo contd.A = 1.Do 3 times. Do 3

    times.Write:/ A. Write:/

    sy-index.A = a + 1. Enddo.Enddo.

    Do ** Enddo contd.Do 5 times. Do 5

    times.If sy-index = 3. Write:/

    sy-index.

  • 7/27/2019 ABAP Basics Understanding Concepts

    17/26

    Continue. If sy-index = 3.

    Endif. Continue.Write:/ sy-index. Endif.Enddo. Enddo.

    Do ** Enddo contd.Do 5 times. Do 5

    times.If sy-index = 3. Write:/

    sy-index.Exit. If sy-

    index = 3.Endif. Exit.Write:/ sy-index. Endif.

    Enddo. Enddo.

    While ** Endwhile. While sy-index

  • 7/27/2019 ABAP Basics Understanding Concepts

    18/26

    r2 radiobutton groupg1.

    If r1 = X .else.Endif.

  • 7/27/2019 ABAP Basics Understanding Concepts

    19/26

    OUTPUT STATEMENTSThe basic ABAP/4 statement for

    output on the Screen is WRITE. Syntax : Write f .f can be any data object.

    Horizontal LinesWrite: / sy-uline.Write:/P sy-uline.Write:/P sy-uline(L).Write:/P(L) sy-uline.

    Uline.Uline /P.Uline /P(L).

    Vertical LinesWrite:/ sy-vline.

    Write:/P sy-vline.

    Blank LinesSkip.Skip 2.Skip to line 5.

    Formatting OptionsWrite f option.

    Different Options

    Left-justified.Centered.

    Right-justified. No-gap. No-zero. No-sign.

  • 7/27/2019 ABAP Basics Understanding Concepts

    20/26

    Under g.Using Editmask m.Decimals d.Round r.Exponent e.

    Left-justified, centered, Right-justified

    Data a(50) value ABCD. Write:/ a,

    / a centered,/ a right-justified.

    NO-GAP Data : p(4) value ABCD, q(4) value EFGH.

    Write:/ p no-gap, q.

    NO-ZEROData a(5) type n value 123. Write:/ a no-zero.

    NO-SIGNData : a type i value 20,

    b type i value 25,c type i.

    C = a - b.Write: / c no-sign.

    Under g.Data : a(4) value ABCD,

    b(4) value EFGH. Write:/10 a,

    / b under a.

  • 7/27/2019 ABAP Basics Understanding Concepts

    21/26

    Using edit mask m. Data : a like sy-datum.

    A = sy-datum.

    Write:/ a,/ a using edit mask _ _ / _ _ / _ _ _ _.

    Decimals d. Data : a type p decimals 3.

    a = 123.456.

    Write:/ a decimals 2.

    Round r.Data a type p decimals 3.

    a = 123.456. Write:/ a round -2,

    / a round -1,

    / a round 1.Exponent e

    Data a type f.a = 123456.789. Write:/ a exponent -2,

    / a exponent -1,/ a exponent 1,/ a.

    Format intensified. (default)Format intensified off.Format inverse.Format inverse off. (default)Format color n.

  • 7/27/2019 ABAP Basics Understanding Concepts

    22/26

    write:/ a color n.n can be col_background.1 or col_heading ( Blue)2 or col_normal (White)3 or col_total (Yellow)4 or col_key (Olive green)

    Write :/ a color n.n can be

    5 or col_positive (Green)

    6 or col_negative (red)7 or col_group (violet)

  • 7/27/2019 ABAP Basics Understanding Concepts

    23/26

    STRING OPERATIONS ConcatenateSplitShiftReplaceTranslateOffsetString lengthString comparision

    Concatenate data : a(10),b(10),c(10),d(40).

    A = Apple. B = Orange. C =Banana.

    Concatenate A B C into D.Write:/ d.Concatenate A B C into D separated

    by /. Write:/ d.

    Split data : a(10),b(10),c(10),d(40).D = Apple/Orange/Banana. Split d at / into a b c.Write:/ a

    / b,/ c.

    ShiftData : a(6) value ABCDEF.

    Shift a.(by default shifts to left by one place)

    write: / a. BCDEFA = ABCDEF. Shift a by 2 places.

  • 7/27/2019 ABAP Basics Understanding Concepts

    24/26

    Write:/ a. CDEF Data : a(6) value ABCDEF.

    Shift a right. Write:/ a. ABCDE A =

    ABCDEF. Shift a right by 2 places. Write:/ a. ABCD

    Data : a(6) value ABCDEF .Shift a up to C. Write:/ a . CDEF

    a = ABCDEF.

    Shift a circular. Write:/ a . BCDEFA

    Data a(6) ABCDEF. Shift a circular by 2 places.Write:/ a. CDEFABa = ABCDEF. Shift a circular right by 2 places.Write:/ a. EFABCD

    ReplaceData p(6) value ABCABC. Replace ABC with DEF into p. Write:/ p. DEFABC(Replaces first occurrence only)

    TranslateData p(11) ABC ABC ABC. Translate p using ADBECF. WRITE:/ P. DEF DEF DEF

    Offset Data p(6) value ABCDEF,

    q(3).q = p+2(3).

  • 7/27/2019 ABAP Basics Understanding Concepts

    25/26

    Write :/ q. CDEq = p+0(1).Write:/ q. A

    String Length. Data: a(50) value PQRPQRPQRXYZ,

    b type i. b = strlen( a ). 15

    String Comparison

    Contains any ca Contains only co Contains string cs and Contains pattern cp.

    Contains any (ca) [ case sensitive ]If SAP ca ABAP/4. Write:/ True. Else.Write:/ False. Endif.

    True

    Contains only (co) [ case sensitive ]If SAP co ABAP/4. Write:/ True. Else.Write:/ False. Endif.

    False

    Contains string (cs) [ not case sensitive ]If ABAP/4 cs Ab. Write:/ True.

  • 7/27/2019 ABAP Basics Understanding Concepts

    26/26

    Else.Write:/ False. Endif.

    True

    Contains pattern (cp) [ not case sensitive]

    If ABAP/4 cp *aP++. Write:/ True. Else.Write:/ False.

    Endif. True