introduction to abap prorgamming

Upload: wyfwong

Post on 03-Jun-2018

243 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/12/2019 Introduction to ABAP Prorgamming

    1/72

    Introduction to ABAP Programming

    What Is ABAP?

    ABAP stands for Advanced Business Application Programming. ABAP is a programminglanguage that was developed by SAP for developing commercial applications in SAPenvironment.

    The development process of ABAP went through the following evolutionary stages:

    In early days (!"#s$ ABAP stood for %Allgemeiner Berichts&Aufbereitungs

    Pro'essor ()eneric *eport )eneration Processor$. That time ABAP wasimplemented as a macro assembler under *+, and e-clusively used for creatingreports.

    In mid !#s/ ABAP had become an interpreted language and was powerful

    enough to be used to create business application programs/ in particular toprogram dialog&controlled transactions.

    In early !!#s/ the SAP *+0 system was born and ABAP become ABAP+1/ that

    ABAP 1)2 (1th)eneration Programming 2anguage$. It now formed the technicaland software basis of the entire SAP System. Apart from system core which iswritten in 3/ all SAP application modules/ *+0 Basis System and the developmentenvironment were now created in ABAP+1.

    At the end of !!#s/ ABAP is e-tended with ob4ect oriented programming

    constructs and from this point on/ the language was 5nown as ABAP 6b4ects.

    In the beginning of ,###s ABAP programs were made 7nicode&3ompatible inorder to support the internationali'ation of the SAP System.

    8ith SAP technology platform under the name %SAP 9et8eaver/ ABAP become

    the programming interface of the SAP 9et8eaver Application Server ABAP (ASABAP$.

  • 8/12/2019 Introduction to ABAP Prorgamming

    2/72

    Introduction to ABAP Programming

    What is SAP NetWeaver?

    SAP 9et8eaver is SAPs (Systems Applications and Products in ;ata Processing$technological platform (3omponents/ Tools and Applications$ which provides a runtime

    and development environment for all SAP applications.

    SAP 9et8eaver is the fully interoperable 8eb&based cross&application platform that canbe used to develop not only SAP applications but others as well. It allows a developer tointegrate information and processes from geographically dispersed locations usingdiverse technologies/ including

  • 8/12/2019 Introduction to ABAP Prorgamming

    3/72

    Introduction to ABAP Programming

    Components:

    Application Server:Supports platform&independent 8eb services/ business

    applications/ and standards&based development

    Business Warehouse:Integrate data from across the enterprise and transform it

    into information to drive sound decision ma5ing.

    Business Process Management:Provides tools to help you model/ e-ecute/ and

    monitor business processes based on a single/ consistent process model.

    Process Integration:;elivers S6A&based technology that supports application&

    to&application (A,A$ and business&to&business (B,B$ integration/ and toaccelerate composite application development.

    Master Data Management:=nsures cross&system data consistency and a singleversion of master data for supplier/ product/ customer/ or user&defined data ob4ectsin heterogeneous environments.

    SAP NetWeaver Mobile:Provides a mobile runtime environment based on open

    and fle-ible technology standards and a powerful development environment forbuilding integrated mobile solutions with native or browser&based user interfaces.

    SAP NetWeaver Portal:7nifies critical information and applications to give

    users role&based views that span the enterprise/ enabling you to ta5e fulladvantage of your information resources.

    SAP Auto-ID Inrastructure:)ives you all the capabilities you need to integrate

    all automated sensing devices @ including *I; (*adio reuency Identification$technology electronically captures/ stores/ and transmits data readers and printers/Bluetooth devices/ embedded systems/ and bar&code devices.

    I!entit" Management:Celps companies manage users access to applications

    securely and efficiently/ while meeting audit and compliance reuirements.

    Inormation #iec"cle Management:=nables companies to decommission

    redundant SAP system while preserving full auditing and reporting capabilitiesfor stored data.

    $ools:

    A!aptive Computing Controller:Provides a central point of control for

    assigning computing resources and optimi'ing their use.

    0

  • 8/12/2019 Introduction to ABAP Prorgamming

    4/72

    Introduction to ABAP Programming

    Composition %nvironment:Provides a robust environment for design/

    deployment/ and running of composite applications that comply with a service&oriented architecture.

    Developer Stu!io:6ffers a convenient user interface and rich functionality for

    developing >,== applications.

    &isual Composer: Allows composing model&based business applications in a

    fle-ible way/ without manual coding.

    SAP Solution Manager:Application management solution facilitates technical

    support for distributed systems.

    Applications

    %nterprise Search:Celps business users navigate critical business information

    by enabling seamless/ secure access to SAP and non&SAP information andprocesses.

    Duet:=nables seamless access to SAP business processes and data via

  • 8/12/2019 Introduction to ABAP Prorgamming

    5/72

    Introduction to ABAP Programming

    Another (a" o !eining SAP NetWeaver)

    SAP 9et8eaver is a set of capabilities that are provided by different SAP productsconstructed to wor5 with each other to ma5e applications wor5 together/ build new

    applications on top of e-isting applications and lower the Total 3ost of 6wnership(T36$. T36 is about all the different e-penses involved in owning and running anenterprise application.

    The figure above depicts that the core capabilities of SAP 9et8eaver are consists of thefollowing four layers:

    People Integration Information Integration

    Process Integration

    Application Platform

    D

  • 8/12/2019 Introduction to ABAP Prorgamming

    6/72

    Introduction to ABAP Programming

    People Integration

    People Integration means to bring people together and help them wor5 more efficiently.

    Information Integration means to bring information from different locations and have itma5e sense in the conte-t what a user do everyday.

    Process Integration

    Processes Integration means coordinating the flow of wor5 across departments/ divisionsand between companies.

    Application Platorm

    Application Platform is called the SAP Application Server (SAP AS$. SAP AS isfoundation for the entire SAP software stac5. It is the engine behind the scene of SAP9et8eaver that drives all SAPEs Applications and Tools. It provides a platform for9et8eaver components (=nterprise Portal etc.$ and ABAP and >ava applications.

    Composite Application *rame(or+

    3omposite Application ramewor5 (SAP 3A$ is modeling and developmentenvironment for creating composite applications. 3omposite applications are applicationsbuilt out of services provided by other applications.

    #ie C"cle Management

    The SAP 2ifecycle

  • 8/12/2019 Introduction to ABAP Prorgamming

    7/72

    Introduction to ABAP Programming

    SAP Application Server

    SAP Application Server (SAP AS$ is foundation for the entire SAP software stac5. It isthe engine behind the scene of SAP 9et8eaver that drives all SAPEs Applications and

    Tools. It provides a platform for 9et8eaver components (=nterprise Portal etc$.

    SAP systems are used for mapping business processes or business applications. Theseapplications should be implemented independent of the hardware environment used(operating system/ database$ to the greatest e-tent possible. or this/ the SAP ApplicationServer provides two runtime environments: the ABAP runtime environment (AS ABAP$and a >ava runtime environment (AS >AHA$. Both application servers wor5 on differentdata (different database schemas$ and are lin5ed together by allowing mutual accessthrough the >ava 3onnector (>3o$.

    Application Server ABAP

    The Application Server ABAP provides the ABAP runtime environment that is a virtualmachine for ABAP programs independent of the hardware/ operating system and database system. igure below shows a simplified overview of the main AS ABAPcomponents.

    AS ABAP can be used by user or by software/ including the remaining components ofSAP 9et8eaver. 7ser can access it using user interfaces that are available in the form of

    "

  • 8/12/2019 Introduction to ABAP Prorgamming

    8/72

    Introduction to ABAP Programming

    web browser or SAP )7Is installed on des5top P3s. Software components generallyaccess it through the networ5/ for which two protocols are used: CTTP+CTTPS+S

  • 8/12/2019 Introduction to ABAP Prorgamming

    9/72

    Introduction to ABAP Programming

    Server Page (>SP$ as it is coded in CT

  • 8/12/2019 Introduction to ABAP Prorgamming

    10/72

    Introduction to ABAP Programming

    /ava Script

    >avaScript programs are e-ecuted by >avaScript processor. Hariables of the script can belin5ed to data ob4ects of an ABAP program. 7se of >avaScript on AS ABAP hasnegligible significance. There is no dedicated editor for >avaScript programs in the ABAP

    8or5benchK the CL_JAVA_SCRIPTsystem class provides an interface to the >avaScript=ngine.

    b.ect Services

    6b4ect Services provide global services/ which ABAP 6b4ects language elements cannotprovide themselves/ to applications written in ABAP 6b4ects. These 6b4ect Servicesinclude: A Persistence Service/ A Transaction Service/ and A Fuery Service.

    Persistence #a"er

    The persistence layer is the software layer in which persistence data is held in a database.=ach AS ABAP accesses a central database on which its entire dataset is stored. Thismeans that not only the application types/ but also all administrative data/ customi'ingsettings and ABAP source codes.

    The central database can be accessed by ABAP programs through the !atabase interaceof AS ABAP. This interface ma5es AS ABAP independent from the database system thatis actually used. The database interface is subdivided into an 6pen SF2 interface andSF2 interface.

    pen S0# is a sunset of SF2 reali'ed by ABAP statements and includes the ;ata

  • 8/12/2019 Introduction to ABAP Prorgamming

    11/72

    Introduction to ABAP Programming

    Internet 3ommunication

  • 8/12/2019 Introduction to ABAP Prorgamming

    12/72

    Introduction to ABAP Programming

    AS ABAP Processes

    The SAP runtime system consists of a number of parallel processes that wor5 together.The following graphic illustrates the most important processes of application server

    ABAP.

    AS ABAP Processes

    In addition to several wor5 processes whose number and type are determined at thestartup of AS ABAP/ each ABAP application server contains a dispatcher/ a gateway/I3< and a message server.

    Dispatcher

    The dispatcher is the lin5 between the wor5 processes and the users logged onto theABAP application server (that is/ the SAP )7Is of the users$. Its tas5 is to receivereuests from the SAP )7I and direct them to a free wor5 process. In the same way/ itdirects screen output bac5 to the appropriate user. If all the wor5 processes are occupiedthe reuests are stored in the dispatcher ueue.

    Wor+ Processes

    8or5 processes are software components that e-ecute an application. =ach wor5 processis lin5ed to a memory area containing the conte-t of the application being run. Theconte-t contains the current data for the application program. There are the followingtypes of wor5 process:

    ,

  • 8/12/2019 Introduction to ABAP Prorgamming

    13/72

    Introduction to ABAP Programming

    Dialog:ulfill all reuests for the e-ecution of dialog steps triggered by an active

    user. =very dispatcher reuires at least two dialog wor5 processes.

    Update:=-ecute update reuests. At least one update wor5 process per SAP

    system and you can have more than one per dispatcher.

    Background (batch):=-ecute programs that run without interacting with the user.

    Lou need at least two bac5ground wor5 processes for each SAP system. Lou canconfigure more than one bac5ground wor5 process for each dispatcher.

    Enqueue:Administers the loc5 table in the shared memory. The loc5 table

    contains the logical database loc5s of the ABAP stac5 of the SAP system. 6nlyone enueue wor5 process is needed for each system.

    Spool:Pass seuential data flows on to printers. =very SAP system reuires at

    least one spool wor5 processK you can also have more than one spool wor5process per dispatcher.

    Internet Communication Manager

    The Internet 3ommunication

  • 8/12/2019 Introduction to ABAP Prorgamming

    14/72

    Introduction to ABAP Programming

    Memor" rgani2ation o AS ABAP

    AS ABAP is the system in which an ABAP programs runs. rom software point of view/the application layer of an AS ABAP is spread across at least one/ but usually several/

    application servers. If an AS ABAP has several application servers/ they are usually alsoinstalled on several machines/ whose operating systems donEt have to be identical.ThereforeK in application layer there is

  • 8/12/2019 Introduction to ABAP Prorgamming

    15/72

    Introduction to ABAP Programming

    AS Memor" rgani2ation

    The memory areas of an application server that can be accessed in an ABAP program areas follows:

    Shared

  • 8/12/2019 Introduction to ABAP Prorgamming

    16/72

    Introduction to ABAP Programming

    A call seuence is formed if you can return from called program to the calling program.This is always the case when you call an ABAP program with SUBMIT AND RETURN

    or CALL TRANSACTION. 6nly programs of a call seuence have common access to

    data in the ABAP memory/ and this is primarily for data transfer during program calls.8hen the first program of a call seuence is terminated/ the corresponding ABAP

    memory is also released.

    'oll Area

    8ith each call via SUBMITor CALL TRANSACTIONor LEAVE TRANSACTIONof an

    ABAP program in main session/ an internal session is opened. A memory area called a*oll Area is assigned to the internal session/ in which the data and ob4ects of an ABAPprogram are stored while it is e-ecuted. This is the actual memory of an ABAP Program.8ith program calls/ a ma-imum of nine internal sessions can be stac5ed as a callseuence in a main session. In main session/ only the internal session of the program thatis 4ust running e-ists in am active version. All memory content of previous programs is

    saved on the stac5.

    Technically each internal session is divided into a Program =-ecution Area (PA$ and a*oll Area. The PA is further common memory area of the application server in whichthe unchangeable data (bytecodes$ of t he programs that are currently running there isstored. 6nly the roll area is individually reserved for an internal session and contains itschangeable data.

    An internal session will e-ist for as long as its first program/ the main program/ ise-ecuted. The additional loaded programs and their data also remain loaded until the endof the internal session.

    All programs of an internal session have 4oint access to anonymous data ob4ects andinstances of classes created with CREATE. 8ithin internal session/ references to ob4ects

    can be copied from one program to procedures of another program.

    6n G1&bit platform/ an internal session can theoretically reuire up to 1TB of memory.6n 0,&bit platforms/ the theoretical ma-imum limit is 1)B.

    G

  • 8/12/2019 Introduction to ABAP Prorgamming

    17/72

    Introduction to ABAP Programming

    ABAP3 A Practical Intro!uction

    Change an! $ransport S"stem 4C$S5

    The SAP 9et8eaver repository is the central place where development components inthe ABAP 8or5bench are stored. These components include all of the: process models/data models/ business ob4ect models/ business ob4ects/ and all data and their relationships.The repository also includes the ABAP ;ictionary.

    The 3TS is the central tool for managing changes to repository ob4ects that you ma5e inthe ABAP 8or5bench. The 3TS records all changes in transport+change reuests. 8henyou have finished your wor5 in ABAP 8or5bench/ or have reached a certain stage/ youcan release the reuest. The change reuest is then used to copy the changes from thisclient to other clients or systems. This automatic procedure is 5nown as a transport.Transports of changes by the 3TS allow you to develop in one environment/ test yourdevelopment wor5 in a test environment/ and then/ if the tests are successful/ use itproductively. This ma5es sure that productive operations are not placed at ris5 by faultysettings or program errors.

    3TS enable you to define transport layer as an attribute of a pac5age. The transport layerrefers to the transport path a pac5age should ta5e in a system landscape. The usuallandscape has a least three layers:

    The transport layer by itself does not transport anything. Lou need a transport+changereuest to get something transported.

    A change reuest can be created in two ways:

    "

  • 8/12/2019 Introduction to ABAP Prorgamming

    18/72

    Introduction to ABAP Programming

    . 8hen you create or modify ob4ects in the ABAP 8or5bench/ a window appearsas5ing you to assign the ob4ect to an e-isting change reuest (6wn reuests$ or tocreate a new change reuest (3reate reuest$. See Pac5age 3reation Topic.

    ,. Through Transport 6rgani'er (S=#!$.

    Creating a 'e6uest in the $ransport rgani2er:

    . To start application server/ follow the path Start &M Programs &M SAP9etweaver ".# ABAP Trial Hersion &M 9SP &M Start Application Server.Select3reate (G$ to create new transport reuest.

    ,. 2og on as a B37S=*.

  • 8/12/2019 Introduction to ABAP Prorgamming

    19/72

    Introduction to ABAP Programming

    0. =nter S=#! transaction code in the te-t field of standard toolbar to open theTransport 6rgani'er.

    1. Select the 3reate (G$ function from the toolbar of Transport 6rgani'er tocreate new transport reuest.

    D. Select 8or5bench reuest and clic5 continue.G. 3reate *euest dialog will appear/ enter short description of the change

    reuest. And 3lic5 Save.

    !

  • 8/12/2019 Introduction to ABAP Prorgamming

    20/72

    Introduction to ABAP Programming

    ". This will open up the ;isplay *euest 8indow/ where you can see the changereuest in hierarchal order. Lou can use it now during ob4ect creations.

    ,#

  • 8/12/2019 Introduction to ABAP Prorgamming

    21/72

    Introduction to ABAP Programming

    Pac+ages

    Pac5ages are used to organi'e development ob4ects (programs/ tables/ screens/ BAPIs/function modules/ types/ and so on$ and handle their connection to the ABAP software

    logistics (3hange and Transport System$. All ob4ects that can be changed using ABAP8or5bench (*epository 6b4ects$ are part of pac5age. =very AS ABAP contains apredefined pac5age named NT

  • 8/12/2019 Introduction to ABAP Prorgamming

    22/72

    Introduction to ABAP Programming

    Note: Values like pplication ! So"t#are component is de$eloped b% s%stem administrator

    #hen s%stem is created&

    Creating Package

    Pac5age can be created in two ways:

    a$ In the navigation area of 6b4ect 9avigator (S=#$/ choose the ob4ect typePac5age from the ob4ect list and enter the name of the pac5age in the input fieldbelow. 3hoose =nter. If the specified pac5age does not already e-ist/ the systembranches to a dialog for creating a pac5age.

    b$ 3all the pac5age builder (S=, or SPA3OA)=$. =nter Pac5age 9ame and push3reate button.

    . =nter the following properties in 3reate Pac5age dialog.

    a$ Pac5age: Q

  • 8/12/2019 Introduction to ABAP Prorgamming

    23/72

    Introduction to ABAP Programming

    ,. After selecting Save you will be prompted for a transport reuest.

    0. If you have already created transport reuest/ push 6wn *euests button or select the3reate button to create new one.

    1. In new create reuest dialog enter short description.

    Note: 'n a real#orld de$elopment proect %ou #ill al#a%s use a transport requestthat is created in the *ransport +rganizer (SE,-) and paste this into the dialog #ith

    ,0

  • 8/12/2019 Introduction to ABAP Prorgamming

    24/72

    Introduction to ABAP Programming

    the header .rompt "or transportable /orkbench 0equest1 i" %ou ust need a transport

    request #ithout an% particular properties1 %ou can do it the #a% #e do it here&

    D. Pressing the Save button opens another dialog window and we are done withtransport reuest.

    G. 3lic5ing 3ontinue will bring Pac5age Builder: 3hange Pac5age 8indow. 3hec5 the

    Pac5age 3hec5 as Server. This ensures that only ob4ects declared in the pac5ageinterface of the pac5age can be addressed from other transportable pac5ages. 3lic5Save button on standard toolbar and close the Pac5age Builder.

    ,1

  • 8/12/2019 Introduction to ABAP Prorgamming

    25/72

    Introduction to ABAP Programming

    Creating 8ello Worl! Program in Pac+age

    . =nter S=# in te-t field of standard toolbar to open 6b4ect 9avigator.,. Select Pac5age from 6b4ect 2ist and type Q

  • 8/12/2019 Introduction to ABAP Prorgamming

    26/72

    Introduction to ABAP Programming

    G. 3reate 6b4ect ;irectory =ntry dialog appears/ clic5 save to continue. The 6b4ect;irectory is a directory of all the *epository 6b4ects that ma5e up the SAP System.8hen you create an ob4ect/ the corresponding ob4ect directory entry is also created.

    ". 9e-t dialog prompt for transport reuest. The transport reuest our pac5age belongsto is already in the relevant field. Again 3onfirm it.

    ,G

  • 8/12/2019 Introduction to ABAP Prorgamming

    27/72

    Introduction to ABAP Programming

    . 9e-t the ABAP =ditor is appear/ where you write code. 3lic5 Les if you wanted tochec5 the uic5 start.

    !. To configure the new ABAP =ditor go to 7tilities Settingsront&=nd =ditor

    (9ew$.

    #. Lou can also double clic5 the program name to open ABAP =ditor.Lou can see theframewor5 predefined by the ABAP 8or5bench. This synta- consists of a few linesof comments/ and also contains an initial statement named *eport.

    ,"

  • 8/12/2019 Introduction to ABAP Prorgamming

    28/72

    Introduction to ABAP Programming

    . To change the program. )o to the change mode by pressing the respective button:Below the report&statement enter:

    ,. To format the source code. ABAP =ditor uses the Pretty Painter. To configure it go to7tilitiesSettingsPretty Painter. 3hec5 Indent and 3onvert 7ppercase

    +2owercase.

    0. 3lic5 the Pretty Painter button in the ABAP =ditor and the format of statements

    changes.

    ,

  • 8/12/2019 Introduction to ABAP Prorgamming

    29/72

    Introduction to ABAP Programming

    1. To chec5 the syntactic corrections/ select 3hec5 from the conte-t menu of the

    program name in ob4ect list. 6r 3hec5 button from standard toolbar.

    D. The error&free program must be activated. Select Activate function . ;uring Theerror&free source code is converted to byte code that is stored in the database. Afteractivation program will be visible to every user using SystemServices

    *eporting.

    G. To run the program we press the icon: or =-ecute;irect from conte-t menu

    of program name or by pressing .

    ". The e-pected %Cello 8orld output appears in a special screen.

    9ote: ABAP Programs can be e-ecuted by two ways. 7sing the =-ecute function ortransaction codes (SA0 and S=0$. SA0 can be used only to e-ecute or run a program.It is more recommended to use by unctional 3onsultants+7sers of the program to reducethe ris5 of mista5enly modification or deletion of the program. S=0 is use to display anABAP =ditor screen where transaction is not limited only to program e-ecution but alsoto display or modify the program code. SA0 can be used also by ABAPers to e-ecutethe program. Also to call the program from other program the use the S7B

  • 8/12/2019 Introduction to ABAP Prorgamming

    30/72

    Introduction to ABAP Programming

    statement. 8ith addition A9; *=T7*9 specify the system returns to the caller after thecalled program is terminated.

    SA9 Call

    S%9 Call

    ABAP programs can also be called through transaction codes (transaction maintenanceS=!0$. To call transactions from other program use the statement 3A22T*A9SA3TI69 R. and to abort the calling transaction use 2=AH= T*A9SA3TI69.

    . To display the %Cello 8orld% is message bo- change the code to:

    0#

  • 8/12/2019 Introduction to ABAP Prorgamming

    31/72

    Introduction to ABAP Programming

    As a result a dialog window greets the world. Instead of EIE try =/ for type message.

    utput (ith $"pe ;Idata types means that these data types are incomplete or generic

    and it is reuired to use the LENGTH addition to specify their length/ otherwise

    you cannot use them to declare data types and data ob4ects. The other types ?/ )/

    (/ and $are not generic and complete/ you donEt need to specify LENGTHwhen

    declare a data ob4ect or data type. In fact/ specifying length in this is forbidden.

    ;ata ob4ects that are declared using one of these eight data types are referred to asstatic data ob4ects because the utili'ed memory space is statically (duringdeclaration$.

    D0

  • 8/12/2019 Introduction to ABAP Prorgamming

    54/72

    Introduction to ABAP Programming

    Data $"pe #engthStan!ar!

    #engthInitial &alue Meaning

    Numeric Data $"pes

    i 1 bytes # Integer

    f bytes # loating pointp &G bytes bytes # Pac5ed number

    Character Data $"pes

    c & GDD0Dcharacters

    character UR.ETe-t ield(Alpha numeric$

    n & GDD0Dcharacters

    character # R #9umeric Te-tield (9umeric

    characters$

    d characters U########;ate ield(ormat:

    LLLL

  • 8/12/2019 Introduction to ABAP Prorgamming

    55/72

    Introduction to ABAP Programming

    #e(erence Data &ypes

    *eference types describe data ob4ects (reference variables$ that contain references toother ob4ects. There are types of data references (references to data ob4ects$ and ob4ectreferences (references to instances of classes$.

    DD

  • 8/12/2019 Introduction to ABAP Prorgamming

    56/72

    Introduction to ABAP Programming

    Deining Data $"pes

    There are two ways to define data types in ABAP:

    Bound ;ata Type Independent ;ata Type

    Bound Data &ype

    The data statement DATAcreates a bound data type. That is a type defined only for that

    particular data ob4ect and canEt be used for other data ob4ects.

    DATA @ TYPE 9 LENGTH VALUE H!!"#.

    The above statement declares@data ob4ect of type 9with length of ,# characters.

    9ow these properties i.e. type and length is 4ust associated or bound with data ob4ect@. If we try the following declarative statement.

    DATA $>$ TYPE @ VALUE W!9"@#.

    Lou will get an error saying that type@is un5nown. This shows that the properties

    li5e type and length is bound to@and you canEt use the TYPEaddition to@ to

    define data ob4ects of type@.

    The LIKE5eyword is used to solve the above problem. or e-ample the following line is

    e-ecuted without any errors.

    DATA $>$ LIKE @ VALUE W!9"@#.

    The above line says that $>$ is a data ob4ect having same properties as that of@.

    LIKErefers to predefined data ob4ects. But the problem with this method is we are

    creating data ob4ects even for the purpose of defining data types i.e. LIKE similar to

    TYPEalso allocates memory space. As a result/ this would consume a lot of memory.

    or this reason ABAP provides an independent data types.

    )ndependent Data &ypes

    Independent data types act as a template for data ob4ects/ similar to classes that can beused for template for ob4ects. The TYPES5eyword is used to define an independent data

    types. The TYPES5eyword creates data type and does not allocate memory space. The

    synta- of TYPES is almost identical to the DATA statement but without data ob4ect

    specific additions li5e length and value etc.

    DG

  • 8/12/2019 Introduction to ABAP Prorgamming

    57/72

    Introduction to ABAP Programming

    The TYPESstatement for an independent character&li5e data type te-t of length ,# would

    be as follows:

    TYPES $>$ TYPE 9 LENGTH .

    To declare data ob4ects of type te-t:

    DATA $>$ TYPE $>$ VALUE W!9"@#.DATA $>$ TYPE $>$ VALUE $" ABAP#.

    This means/ that t-t and t-t, are of type te-t which in turn of type c and having length of,#.

    8ith so many different ways to declare data types/ the uestion arises as to when youshould use which optionV

    It is good programming style to create a self&defined data type only as anindependent type.

    7se LIKE addition whenever your declaration is directly li5ed to a data ob4ect.

    =-amples of this include au-iliary variables in procedures that must have thesame type as interface parameters or their components. This 5eeps your programvalid even if the data type of the data ob4ects changes.

    In all other cases/ you should use the TYPE addition to directly reference

    appropriate independent data types.

    D"

  • 8/12/2019 Introduction to ABAP Prorgamming

    58/72

    Introduction to ABAP Programming

    %lementar" Data $"pes 7sage

    *umeric Data &ypes

    Data $"pe i:i is a complete type/ used for integers/ having si'e of 1&bytes. 6ftenused for inde- or count variables. The default value is #.

    DATA 9"7$ TYPE ? VALUE .

    Data $"pe :f is a data type for binary floating point numbers. f is a complete

    type. It is having &bytes of si'e. It is consists of three components: the J+& sign/ aG&digit mantissa and the e-ponent.

  • 8/12/2019 Introduction to ABAP Prorgamming

    59/72

    Introduction to ABAP Programming

    DATA $>$ _!?7 TYPE 9 LENGTH .$>$_!?7 + ABAP 5'"'1@@?7 ? )7.

    Data $"pe n: Type n is a special case of type c for numeric characters/ but not a

    numeric data type. n is also incomplete data type. ;ata ob4ects of this type canonly contain numbers/ but these numbers can not be directly used to carry outcalculations. Typical use areas can be IP codes/ Phone 9umbers/ P.6 Bo-numbers etc.

    DATA 5"$1!_9"( TYPE 7 LENGTH .5"$1!_9"( + #.

    Data $"pe !: d is data type for date information in the format/ YYYYMMDD. d is a

    complete type. If data ob4ect of type d is used in the position of operands where anumerical value is e-pected/ the date is regarded as a number that corresponds tothe number of days that have been passed since . 6ther operations

    utili'e the character nature.

    DATA $"(14 TYPE (.$"(14 + 4-(1$@.$"(14 + $"(14 .

    The 4-(1$@system field provides the system date/ after the calculation/ it

    assign the date of day after tomorrow.

    Data $"pe t:t is a data type for time information in the format/ HHMMSS. It is

    complete data type. . If data ob4ect of type d is used in the position of operands

    where a numerical value is e-pected/ the time is regarded as a number thatcorresponds to the number of seconds that have been passed since midnight. 6ther operations utili'e the character nature.

    DATA 7"& TYPE $.7"& + 4-?$.7"& + 7"& /.

    The 4-?$system field provides the current time/ and then one hour is

    added to the now data ob4ect.

    Data $"pe : - is a data type used for storing byte strings of fi-ed length. It isincomplete data type. Type - data ob4ects can generally be used for byte&li5econtent where the fi-ed length is important.

    DATA %> TYPE > LENGTH /.%> + F/0AB#.

    D!

  • 8/12/2019 Introduction to ABAP Prorgamming

    60/72

    Introduction to ABAP Programming

    Data $"pe string:Type string is a data type that can be used for any characters

    strings of variable length. The LENGTHaddition is not allowed with string data

    typeK however you can use theVALUEaddition to initiali'e a string data ob4ect.

    DATA $>$_$' TYPE $'?7.

    Data $"pe string:-string is a data type that can be used for any byte string of

    variable length. The LENGTHandVALUEand addition is not allowed with -string

    data type.

    DATA $>$_>$' TYPE >$'?7.

    G#

  • 8/12/2019 Introduction to ABAP Prorgamming

    61/72

    Introduction to ABAP Programming

    Comple Data $"pes

    3omple- data types can be structured types or table types.

    Structured Data &ype

    Structured data type is consists of a seuence of other data types. The data ob4ect of astructured data type is called structure. The units that ma5e up a structured type are calledstructure components (fields$. The components of the structure can be elementary datatypes/ a structure/ an internal table or a reference data type. Structures are used especiallyto define the data at the interface of module pools and screens and to define the types offunction module parameters.

    There are lat/ nested and deep structures. A flat structure only references elementarytypes. A nested structure references at least one further structure/ but not a table type. A

    deep structure references at least one table type.

    The BEGIN OFand END OFstatements define the beginning and end of a structure as a

    bound or independent type:

    DATA* BEGIN OF $'9$'_71@,

    $'9$_9"@5 TYPE;LIKE ,$'9$_9"@5 TYPE;LIKE ,

    $'9$_9"@57 TYPE;LIKE

    END OF $'9$'_71@.

    TYPES* BEGIN OF $'9$'_71@,

    $'9$_9"@5 TYPE ,$'9$_9"@5 TYPE ,

    $'9$_9"@57 TYPE

    END OF $'9$'_71@.

    The addition of BEGIN OFand END OFstatements define the beginning and end of a

    structure called $'9$'_71@. The colon and the commas indicate that we are

    dealing with several DATAand TYPESstatements. All the statements that lie in&between

    G

  • 8/12/2019 Introduction to ABAP Prorgamming

    62/72

    Introduction to ABAP Programming

    declare the components of the structure. A component that is structured itself is referredto as a substructure. A structure that contains substructures is called nested structure.

    The component of a structure can be accessed with structure component (&$. or nestedstructures/ you must concatenate the structure names to access internal components.

    G,

  • 8/12/2019 Introduction to ABAP Prorgamming

    63/72

    Introduction to ABAP Programming

    The program produces the following out put.

    or the street/ we created a separate structured type $'$_$'9$with components

    71@ and 7". or the address/ we declare a structure 1(('_$'9$ as a data

    ob4ect (everything we discussed for DATA also holds true for CLASS-DATA/ for

    declaration of static attributes.$ and we declare the $'$ component with type

    $'$_$'9$. The substructure 9?$4_$'9$ consists of two components

    ?59"(and 71@.

    Lou can integrate the components of a structure into another structure using theINCLUDEstatement as:

    DATA BEGIN OF $'9$_,INCLUDE STRUCTURE $'9$_ AS 71@

    G0

  • 8/12/2019 Introduction to ABAP Prorgamming

    64/72

    Introduction to ABAP Programming

    6RENAMING WITH SUFFIX ))?>8.DATA END OF $'9$_.

    TYPES BEGIN OF $'9$_,

    INCLUDE TYPE $'9$_ AS 71@6RENAMING WITH SUFFIX ))?>8.

    TYPES END OF $'9$_.

    The INCLUDEstatement is not an addition to the TYPESor DATAstatements. Instead/ it

    interrupts the chained statement that must be restarted afterwards.

    The components of $'9$_will be transferred as components into the $'9$_

    structure. They can either be addressed commonly under the name 71@/ or individually

    by their component names. The RENAMING addition can be used to avoid namingconflicts.

    G1

  • 8/12/2019 Introduction to ABAP Prorgamming

    65/72

    Introduction to ABAP Programming

    The program produces the following out put.

    All the components are allocated at the same level. 9aming conflicts between the namecomponents are avoided by the use of different endings. This type of structure definitionavoids comple- nested structures with long name chains.

    &able &ypes

    Table types represent the second comple- data type. The data ob4ects of table types areinternal tables. Internal tables are dynamic data ob4ects li5e stringsK internal tables areinternally managed by references. An internal table consists of a dynamic seuence oflines of the same data type (it can be thin5 of an arrays in >ava or 3W.9et$. The table type

    GD

  • 8/12/2019 Introduction to ABAP Prorgamming

    66/72

    Introduction to ABAP Programming

    describes the line type/ the table category and a table 5ey. The following synta- can beused to declare the internal tables.

    DATA $12_71@ TYPE;LIKE STANDARD;SORTED;HASHED TABLEOF (1$1_$45;(1$1_"239$

    WITH 6NON-8UNIQUE KEY 9"!9"!7.

    TYPES $12_71@ TYPE STANDARD;SORTED;HASHED TABLEOF (1$1_$45WITH 6NON-8UNIQUE KEY 9"!9"!7.

    The 5eywords STANDARD/ SORTEDand HASHEDdefine the table category.

    S$ANDA'D $able:is managed internally by a table inde-. Access is possible via tableinde- or table 5ey. 8ith a 5ey access/ the response time is directly dependent on thenumber of table entries. The 5ey of a standard table is always non&uniue. This table

    category is suited best whenever the individual entries can be accessed using the inde-.

    S'$%D $able:is managed internally by means of a table inde-/ too. They are alwayssorted by the table 5ey and can be accessed via the table inde- or the table 5ey. 8ith a5ey access/ the response time is logarithmically dependent on the number of table entries/because the table is accessed via a binary search. The 5ey of sorted tables can be uniueor non&uniue. This table category is suited whenever the table must already be sortedwhen it is filled.

    8AS8%D $able: is managed internally by a hash algorithm. Cashed tables can beaccessed only via the table 5ey. The response time is constant/ independent of the numberof table entries. The 5ey of hashed tables is always uniue. This table category is suitedwhenever the 5ey accesses represent the central operation on the table entries.

    The (1$1_$45 and (1$1_"239$ represent the line type. The internal table can

    contain any number of lines of the specified line type. Thus/ line type is fi-ed duringdeclaration/ but not the number of lines. Lou can use any line type/ elementary types/reference types/ structures and even other internal tables.

    The table 5ey is reuired for the identification of table rows. An internal table has auniue or non&uniue table 5ey that can be defined by listing its components.

    =-ample below demonstrates the usage of internal table.

    GG

  • 8/12/2019 Introduction to ABAP Prorgamming

    67/72

    Introduction to ABAP Programming

    After e-ecuting the loop will display five message bo-es as:

    G"

  • 8/12/2019 Introduction to ABAP Prorgamming

    68/72

    Introduction to ABAP Programming

    =-ample above declares a standard table 1''14whose line type is elementary data type

    i and whose 5ey consists of the DEFAULT KEY. DEFAULT KEY is build from all

    columns of the internal table that have a character&type type (9/ (/ $/ 7/ >/ $'?7/

    >$'?7$. TheAPPENDstatement appends a new line to the end of the inde-ed internal

    table. The 4-?7(>is a system field (System fields are filled according to the conte-t

    by system runtime$ gets the particular record number. It acts li5e 2oop Iteration 3ounter.

    'eerence Data $"pes

    *eference types can contain a reference to other data ob4ects or to instances of classes.Those data ob4ects are referred to as reference variables. ;epending on the type of ob4ectthat is referenced/ we spea5 of data reference variables or ob4ect reference variables thatcan either contain data references or ob4ect references. The following synta- can be usedto declare the reference data types.

    DATA ')_:1'?12! TYPE ;LIKE REF TO(1$1_$45;(1$1_"239$.

    G

  • 8/12/2019 Introduction to ABAP Prorgamming

    69/72

    Introduction to ABAP Programming

    TYPES ')_:1'?12! TYPE REF TO (1$1_$45.

    DATA "23_') TYPE REF TO 9!1;?7$')19.TYPES "23_') TYPE REF TO 9!1;?7$')19.

    The first two statements create the reference variable for data reference. 9e-t twostatements create an ob4ect reference for class or interface. All of the data ob4ects that youdefine in the declaration part of a program using statements such as DATAare created

    statically/ and already e-ist when you start the program. To create a data ob4ectdynamically during a program/ you need a reference variable and the followingstatement:

    CREATE DATA ')_:1'?12! TYPE ;LIKE(1$1_$45;(1$1_"239$.

    CREATE DATA ')_:1'?12! TYPE (1$1_$45.

    The statements create a reference variable in the internal session of the current ABAPprogram. After the statement/ the data reference in the data reference variable points tothe ob4ect.

    The ob4ect component selector (-$ can be used to access the components of the

    reference variable. The dereferencing operator (-$ can be used to access the entire data

    ob4ects that is referenced.

    The following statements allow you to place a data reference to an e-isting data ob4ect in

    a reference variable:

    GET REFERENCE OF (1$1_"239$ INTO ')_:1'?12!.

    =-ample below demonstrates the usage of reference variable and ob4ect references.

    G!

  • 8/12/2019 Introduction to ABAP Prorgamming

    70/72

    Introduction to ABAP Programming

    The program produces the following results.

    The declaration section introduces the "23_') is an ob4ect reference to 9! class/

    while (1$1_') and (1$1_') are reference variables to "23_') and ?

    respectively.

    CREATE OBJECT statement allocates the reference "23_') which enable us to

    access its attribute :1'. The GET REFERENCE OF statement gets the reference of

    "23_')and places it into the (1$1_')reference variable.

    "#

  • 8/12/2019 Introduction to ABAP Prorgamming

    71/72

    Introduction to ABAP Programming

    CREATE DATAstatement creates a data ob4ect (1$1_')dynamically. 6n ne-t line

    through dereferencing operator (-$ we access the :1' attribute of "23_')

    ((1$1_')is pointing to "23_')$ and assign to (1$1_'). After e-ecution it is

    clear that both "23_')and (1$1_')are pointing to same memory location.

    1eneric Data $"pes

    The generic data types allow the dynamic programming. By generic we mean that thedata type is determined during runtime. Table below lists the predefined generic types inthe first column/ while the second column describes the types they comprise. Lou canassign a data ob4ect with a type from the second column to a formal parameter r fieldsymbol (ield symbols are placeholders or symbolic names for other data ob4ects. ieldsymbols are similar to dereferenced pointers in 3$ that is typed with a generic type fromthe first column.

    1eneric $"pe $"pes Comprise!any/ data All data types

    cli5ec/ d/ n/ t/ string/ and flat structures containingcharacter li5e components

    cseuence c and string (te-t li5e types$

    -seuence - and -string (byte li5e types$

    any table All table types

    sorted table Sorted tables

    hashed table Cashed tables

    inde- table Standard and Sorted tables

    standard table/ table Standard tables

    numeric i (b/s$/ p / f (numeric types$

    c/ n/ p/ -3orresponding built&in types with generic lengthsand decimal places

    simplec/ d/ f/ i (b/s$/ n/ p/ t/ string/ -/ -string/ and flatstructures containing character li5e components

    If table type is defined using the TLP=S statement or if it is defined in the ABAP;ictionary without specifying a 5ey/ this table type is also generic type.

    *lat an! Deep Data $"pes

    All data types in which the content of their data ob4ects represents actual wor5ing dataare referred to as flat data types. Thus all elementary data types of fi-ed length are flatdata types.

    All data types in which content of their data ob4ects are references that point to wor5ingdata in different locations of the memory are referred to as deep data types. Thusreference types and dynamic data ob4ects (strings and internal tables$ are deep data types.

    "

  • 8/12/2019 Introduction to ABAP Prorgamming

    72/72

    Introduction to ABAP Programming

    In assignment between deep data ob4ectsK for assignments between reference variables/reference semantics applies i.e. only the references are copied/ but not the referencedob4ects. or assignment between dynamic data ob4ects (strings and internal tables$/ valuesemantics applies i.e. the referenced ob4ect is copied and a new reference is created.

    The memory reuirement for deep data ob4ects is combination of a constant reuirementfor the reference ( bytes$ and a dynamic reuirement for actual ob4ects.