23
UNIT 4 – BASIC ABAP LANGUAGE STATEMENTS ABAP RUNTIME ENVIRONMENT AND ABAP LANGUAGE STATEMENTS

Unit 4 - Basic ABAP Language Statements

Embed Size (px)

DESCRIPTION

This lecture notes presents the basic ABAP language statements.

Citation preview

  • UNIT 4 BASIC ABAP LANGUAGE STATEMENTSABAP RUNTIME ENVIRONMENT AND ABAP LANGUAGE STATEMENTS

  • LEARNING OBJECTIVESAt the end of this lecture, students are able toDescribe the components of an ABAP programDescribe the types of and execution methods of ABAP programsDefine elementary and structured data objectsUse basic ABAP statements

  • LECTURE OUTLINEABAP Runtime EnvironmentComponents of an ABAP ProgramStructure of an ABAP ProgramABAP Programs: Types and Execution MethodsBasic ABAP Language ElementsData Types and Data ObjectsBasic ABAP statementsUsing the ABAP DebuggerWorking with StructuresWorking with Internal Tables

  • ABAP RUNTIME ENVIRONMENT

  • COMPONENTS OF AN ABAP PROGRAM

  • STRUCTURE OF AN ABAP PROGRAM

  • ABAP TERMS (NOT KEYWORDS)

  • GENERAL ABAP PROGRAMMING EXECUTION

  • DIALOG TRANSACTION EXECUTION

  • REPORT TRANSACTION EXECUTION

  • LIST PROCESSING EVENTS

  • NON EXECUTABLE PROGRAMSTypes of modularization units called from ABAP programsTypes of modularization units called from ABAP runtime systemsEvent blocks - begin with a event code and ends with next processing block.Dialog Modules-used in PBO and PAI events of Module Pool programs.

  • BASIC ABAP LANGUAGE STATEMENTSDATA TYPES AND DATA OBJECTSBASIC ABAP STATEMENTS

  • DATA TYPES AND OBJECTSThe type of a data object defines its technical attributes.The type of an interface parameter defines the type of the values (actual parameters) that are transferred when the modularization unit is called.

  • LOCAL AND GLOBAL DATA TYPESYou can define data types in an ABAP program (local, keywordTYPES) or in the ABAP Dictionary (global). Using global data types has several advantages:Global types aremanaged centrallyand you can use them in all repository objects. This increases the consistency of the system and significantly reduces the amount of maintenance.

  • DEFINING DATA OBJECTYou can use a predefined ABAP type, a local, or a global type to type a data object.The following predefined ABAP types are complete:dDate (format:YYYYMMDD)tTime (format:HHMMSS)iIntegerfFloating point numberstringString (of variable length)xstringByte sequence (heXadecimal string, of variable length)You must define the length for these predefined types:cCharacternNumeric characterxByte (heXadecimal)pPacked number (= binary coded decimals). You must enter the number of decimal places.For more information on predefined ABAP types, refer to the keyword documentation onTYPESorDATA.You can useLIKEto refer to the type of a predefined data object.

  • DEFINING ELEMENTARY DATA OBJECTS

  • FIXED DATA OBJECTS

  • VALUE ASSIGNMENTSWhen a program is started, the program context is loaded into a storage area of the application server and made available for all the data objects.Every elementary data object is preassigned the type-related initial value, except if you preassigned a different value using theVALUEaddition.Use theMOVEstatement to copy the contents of data objects.Two statements are available for this purpose:MOVEsourceTOtarget.target=source.If the two data objects have different types, the type is automatically converted if there is a conversion rule.TheCLEARstatement resets the contents of a data object to the type-related initial value.

  • CONDITIONAL BRANCHING

  • LOOPS

  • DIALOG MESSAGES

  • SUMMARYAt the end of this lecture, students are able toWhat are the components of an ABAP program?What are the types of ABAP program and its execution methodsWhat are elementary and structured data objects? How to define themList the ABAP statements that you encounter today. Refer to other references on its use.

    An ABAP program contains the following components: Source code : containing the ABAP statements Screens : Consist of the screen layout and associated flow logic. You normally create the layout of a screen using the Screen Painter However, there are special kinds of screens, called selection screens and lists, whose layout and flow logic are designed exclusively using ABAP statements. Interface : contains all of the entries in the menus, the standard toolbar, the application toolbar, and function key settings. It contains titles and statuses. A status is a collection of function key settings and menus. Text elements: are language-specific. They can be translated either directly from the text element maintenance tool, or using a special translation tool. Documentation : is also language-specific. Always write documentation from the users point of view. If you want to document the programming techniques you have used, use comments in the program code instead. Variants : allow you to predefine the values of input fields on the selection screen of a program.ABAP is an event-driven programming language, and as such is suited to processing user dialogs. The source code of an ABAP program consists of two parts: Declarations: Declarations include the statements for global data types and objects, selection screens, and (in ABAP Objects) local classes and interfaces within the program. Processing Blocks(indivisible program units) Each processing block must be programmed as a single entity. There are two basic kinds of processing blocks: Event Blocks: Event blocks are introduced by an event keyword. They are not concluded explicitly, but end when the next processing block starts. Dialog Modules and Procedures: Dialog modules and procedures are introduced and concluded using keywords. The contents of all processing blocks form the processing logic. When you generate the program, these parts are compiled to form the load version. This is interpreted at run time.You assign a dialog transaction to a module pool. The following steps occur when you run a dialog transaction: First, the LOAD-OF-PROGRAM event is triggered. Once this event block has been executed, the ABAP processor passes control to the screen processor. For an example of how to use this new event, refer to the example in the Function Groups and Function Modules unit. The screen processor processes the intial screen specified in the transaction definition. The initial screen can be a selection screen (regardless of the program type). The PROCESS BEFORE OUTPUT event is triggered and control passes to the ABAP processor, which processes the first PBO module. The ABAP processor executes the processing block and returns control to the screen processor. Once all PBO modules have been processed, the contents of any ABAP fields with identically-named corresponding fields on the screen are transported to the relevant screen fields. Then the screen is displayed (screen contents, active title, active status). Once the user has chosen a dialog function (such as ENTER), the contents of the screen fields are transported back to the corresponding identically-named fields in the ABAP program, and the processing blocks that belong to the PROCESS AFTER INPUT event are processed. The system then continues by processing the next screenThe only processing logic that is processed in a dialog transaction are the statements belonging to the LOAD-OF-PROGRAM event and those occurring in the various modules. However, you can also use the statement LEAVE TO LIST-PROCESSING. This makes all of the list processing events available to you.Source: http://help.sap.com/saphelp_nw70/helpdata/en/fc/eb2d67358411d1829f0000e829fbfe/content.htm

    The process is as follows:1.The runtime environment creates theINITIALIZATIONevent and calls the corresponding event block (if it has been defined in the ABAP program).2.If there is a selection screen defined in the program, control returns to the selection screen processor. This generates the corresponding events and calls their event blocks.3.Control then passes to the reporting processor. It creates theSTART-OF-SELECTIONevent and calls the corresponding event block (if it has been defined in the ABAP program).4.The logical database, if you are using one, calls further event blocks at this point.5.The reporting processor creates theEND-OF-SELECTIONevent and calls the corresponding event block (if it has been defined in the ABAP program).6.If the program contains a list description, control now passes to the list processor. The list processor displays the list defined in the ABAP program. It converts user actions on the list into events and calls the corresponding event blocks.7.If a selection screen is declared in the declaration part of the program, the same program is automatically called again after the program is ended (the list is exited).

    Source: http://help.sap.com/saphelp_nw70/helpdata/en/fc/eb2d67358411d1829f0000e829fbfe/content.htmMacros -- If you want to reuse the same set of statements more than once in a program, you can include them in a macro. You can only use a macro within the program in which it is defined.Include Programs -- Include programs allow you to use the same source code in different programs. They are mainly used for modularizing source code and have no parameter interface.Subroutines -- Subroutines are normally called internally i.e. called from the same program in which it is declared. But subroutines can also be called from external programs.Function Modules -- Function Modules are stored in the central library and can be called from any program. Even the function modules(RFC enabled) can be called from non-SAP systems.Methods -- Methods used ABAP object oriented programming

    For detailed information about copying and the conversion rules, refer to the keyword documentation for theMOVEstatement.