ABAP - Riptutorial

Transcription

ABAP#abap

Table of ContentsAbout1Chapter 1: Getting started with ABAP2Remarks2Versions2Examples2Hello World2Hello World in ABAP Objects3Chapter 2: ABAP GRID List Viewer (ALV)Examples44Creating and Displaying an ALV4Optimize ALV Column Width4Hide Columns in an ALV4Rename Column Headings in an ALV4Enable ALV Toolbar Functionality5Enabling Every Other Row Striping in ALV5Setting the Title of a Displayed ALV5Chapter 3: ABAP ObjectsExamplesClass declarationABAP Classes can be declared Globally or Locally. A global class can be used by any object7777Constructor, methods7Method with parameters (Importing, Changing, Exporting)8Method with returning parameter8Inheritance - definition9Information9Class implementation9Inheritance - Abstract and Final Methods and Classes9Information9Class implementation:9Method call example:10

Chapter 4: CommentsExamples1111End of Line11Full Line11Chapter 5: Control Flow apter 6: Data DeclarationExamples131313131515Inline Data Declaration15Single Variable Declaration15Multiple Variable Declaration15Inline Data Declaration in SELECT Statement15Variable Declaration Options15Chapter 7: Dynamic ProgrammingExamples1717Field-Symbols17Data references18RunTime Type Services19Chapter 8: Internal TablesExamples2020Types of Internal tables20Declaration of ABAP Internal Tables20Internal Table Declaration Based on Local Type Definition20

Declaration based on Database Table21Inline Internal Table Declaration21Internal Table with Header Lines Declaration21Read, Write and Insert into Internal TablesChapter 9: Loops2123Remarks23Examples23Internal Table Loop23While Loop23Do Loop23General Commands24Chapter 10: Message Classes/MESSAGE keyword26Introduction26Remarks26Examples26Defining a Message Class26MESSAGE with Predefined Text Symbol26Message without Predefined Message Class26Dynamic Messaging27Passing Parameters to Messages27Chapter 11: Naming Conventions28Syntax28Examples28Local variable28Global variable28Chapter 12: Open SQLExamplesSELECT statementChapter 13: Regular ExpressionsExamplesReplacing292929303030

Searching30Object-Oriented Regular Expressions30Evaluating Regular Expressions with a Predicate Function30Getting SubMatches Using OO-Regular Expressions31Chapter 14: Strings32Examples32Literals32String templates32Concatenating strings32Chapter 15: Template Programs34Syntax34Examples34OO Program with essential event methodsChapter 16: Unit testingExamples343535Structure of a test class35Separate data access from logic35Credits37

AboutYou can share this PDF with anyone you feel could benefit from it, downloaded the latest versionfrom: abapIt is an unofficial and free ABAP ebook created for educational purposes. All the content isextracted from Stack Overflow Documentation, which is written by many hardworking individuals atStack Overflow. It is neither affiliated with Stack Overflow nor official ABAP.The content is released under Creative Commons BY-SA, and the list of contributors to eachchapter are provided in the credits section at the end of this book. Images may be copyright oftheir respective owners unless otherwise specified. All trademarks and registered trademarks arethe property of their respective company owners.Use the content presented in this book at your own risk; it is not guaranteed to be correct noraccurate, please send your feedback and corrections to info@zzzprojects.comhttps://riptutorial.com/1

Chapter 1: Getting started with ABAPRemarksABAP is a programming language developed by SAP for programming business applications inthe SAP environment.Previously only procedural, ABAP is now also an object-oriented language thanks to the ABAPObjects enhancement.VersionsVersionRelease DateABAP 7.502015-10-20ABAP 7.402012-11-29ABAP 7.02006-04-01ABAP 6.402004-04-01ABAP 6.202002-04-01ABAP 6.102001-07-01ABAP 4.6C2001-04-01ABAP 4.6A1999-12-01ABAP 4.51999-03-01ABAP 4.01998-06-01ABAP 3.01997-02-20ExamplesHello WorldPROGRAM zhello world.START-OF-SELECTION.WRITE 'Hello, World!'.Instead of printing to the console, ABAP writes values to a list which will be displayed as soon asthe main logic was executed.https://riptutorial.com/2

Hello World in ABAP ObjectsPROGRAM zhello world.CLASS main DEFINITION FINAL CREATE PRIVATE.PUBLIC SECTION.CLASS-METHODS: start.ENDCLASS.CLASS main IMPLEMENTATION.METHOD start.cl demo output display( 'Hello World!' ).ENDMETHOD.ENDCLASS.START-OF-SELECTION.main start( ).Read Getting started with ABAP online: arted-withabaphttps://riptutorial.com/3

Chapter 2: ABAP GRID List Viewer (ALV)ExamplesCreating and Displaying an ALVThis example portrays the most simple ALV creation using the cl salv table class and noadditional formatting options. Additional formatting options would be included after the TRY ENDTRYblock and before the alv- display( ) method call.All subsequent examples using the ABAP Objects approach to ALV creation will use this exampleas a starting point.DATA: t spfliTYPE STANDARD TABLE OF spfli,alvTYPE REF TO cl salv table,error message TYPE REF TO cx salv msg." Fill the internal table with example dataSELECT * FROM spfli INTO TABLE t spfli." Fill ALV object with data from the internal tableTRY.cl salv table factory(IMPORTINGr salv table alvCHANGINGt table t spfli ).CATCH cx salv msg INTO error message." error handlingENDTRY." Use the ALV object's display method to show the ALV on the screenalv- display( ).Optimize ALV Column WidthThis example shows how to optimize the column width so that column headings and data are notchopped off.alv- get columns( )- set optimize( ).Hide Columns in an ALVThis example hides the MANDT (client) field from the ALV. Note that the parameter passed toget column( ) must be capitalized in order for this to work.alv- get columns( )- get column( 'MANDT' )- set visible( if salv c bool sap false ).Rename Column Headings in an ALVhttps://riptutorial.com/4

The column text may change upon the horizontal resizing of a column. There are three methods toaccomplish this:Method NameMaximum Length of Headingset short text10set medium text20set long text40The following example shows usage of all three. A column object is declared and instantiated as areference to the result of alv- get columns( )- get column( 'DISTID' ). The column name must bein all capital letters. This is so that this method chaining is only called once in its instantiation,instead of being executed every time a column heading is changed.DATA column TYPE REF TO cl salv column.column alv- get columns( )- get column( 'DISTID' ).column- set short text( 'Dist. Unit' ).column- set medium text( 'Unit of Distance' ).column- set long text( 'Mass Unit of Distance (kms, miles)' ).Enable ALV Toolbar FunctionalityThe following method call enables usage of many advanced features such as sorting, filtering, andexporting data.alv- get functions( )- set all( ).Enabling Every Other Row Striping in ALVThis method increases readability by giving consecutive rows alternating background colorshading.alv- get display settings( )- set striped pattern( if salv c bool sap true ).Setting the Title of a Displayed ALVBy default, when an ALV is displayed, the title at the top is just the program name. This methodallows the user to set a title of up to 70 characters. The following example shows how a dynamictitle can be set that displays the number of records displayed.alv- get display settings( )- set list header( Flight Schedule - { lines( t spfli ) }records ).Read ABAP GRID List Viewer (ALV) online: list-https://riptutorial.com/5

viewer--alv-https://riptutorial.com/6

Chapter 3: ABAP ObjectsExamplesClass declarationABAP Classes can be declared Globally or Locally. A globalclass can be used by any object within the ABAP repository.By contrast, a local class can only be used within the scopeit is declared.CLASS lcl abap class DEFINITION.PUBLIC SECTION.PROTECTED SECTION.PRIVATE SECTION.ENDCLASS.CLASS lcl abap class IMPLEMENTATION.ENDCLASS.Constructor, methodsClass implementation:CLASS lcl abap class DEFINITION.PUBLIC SECTION.METHODS: constructor,method1.PROTECTED SECTION.PRIVATE SECTION.METHODS: method2,method3.ENDCLASS.CLASS lcl abap class IMPLEMENTATION.METHOD constructor."LogicENDMETHOD.METHOD method1."LogicENDMETHOD.METHOD method2."Logicmethod3( ).ENDMETHOD.METHOD method3."Logichttps://riptutorial.com/7

ENDMETHOD.ENDCLASS.Method call example:DATA lo abap class TYPE REF TO lcl abap class.CREATE OBJECT lo abap class. "Constructor calllo abap class- method1( ).Method with parameters (Importing, Changing, Exporting)Class implementation:CLASS lcl abap class DEFINITION.PRIVATE SECTION.METHODS method1 IMPORTING iv string TYPE stringCHANGING cv string TYPE stringEXPORTING ev string TYPE string.ENDCLASS.CLASS lcl abap class IMPLEMENTATION.METHOD method1.cv string iv string.ev string 'example'.ENDMETHOD.ENDCLASS.Method call example:method1 (EXPORTING iv string lv stringIMPORTING ev string lv string2CHANGING cv string lv string3).Method with returning parameterClass implementation:CLASS lcl abap class DEFINITION.PRIVATE SECTION.METHODS method1 RETURNING VALUE(rv string) TYPE string.ENDCLASS.CLASS lcl abap class IMPLEMENTATION.METHOD method1.rv string 'returned value'.ENDMETHOD.ENDCLASS.Method call example:lv string method1( ).https://riptutorial.com/8

Note that parameters declared with RETURNING are passed by value only.Inheritance - definitionInformationInheritance allows you to derive a new class from an existing class. You do this usingthe INHERITING FROM addition in theCLASS subclass DEFINITION INHERITING FROM superclass.statement. The new class subclass inherits all of the components of the existing classsuperclass. The new class is called the subclass of the class from which it is derived.The original class is called the superclass of the new class. A class can have morethan one direct subclass, but it may only have one direct superclass.Class implementationCLASS lcl vehicle DEFINITION.ENDCLASS.CLASS lcl vehicle IMPLEMENTATION.ENDCLASS.CLASS lcl car DEFINITION INHERITING FROM lcl vehicle.ENDCLASS.CLASS lcl car IMPLEMENTATION.ENDCLASS.Inheritance - Abstract and Final Methods and ClassesInformationThe ABSTRACT and FINAL additions to the METHODS and CLASS statements allowyou to define abstract and final methods or classes.An abstract method is defined in an abstract class and cannot be implemented in thatclass. Instead, it is implemented in a subclass of the class. Abstract classes cannot beinstantiated.A final method cannot be redefined in a subclass. Final classes cannot havesubclasses. They conclude an inheritance tree.Class implementation:CLASS lcl abstract DEFINITION ABSTRACT.https://riptutorial.com/9

PUBLIC SECTION.METHODS: abstract method ABSTRACT,final method FINALnormal method.ENDCLASS.CLASS lcl abstract IMPLEMENTATION.METHOD final method."This method can't be redefined in child class!ENDMETHOD.METHOD normal method."Some logicENDMETHOD."We can't implement abstract method here!ENDCLASS.CLASS lcl abap class DEFINITION INHERITING FROM lcl abstract.PUBLIC SECTION.METHODS: abstract method REDEFINITION,abap class method.ENDCLASS.CLASS lcl abap class IMPLEMENTATION.METHOD abstract method."Abstract method implementationENDMETHOD.METHOD abap class method."LogicENDMETHOD.ENDCLASS.Method call example:DATA lo class TYPE REF TO lcl abap class.CREATE OBJECT lo class.lo class- abstract method( ).lo class- normal method( ).lo class- abap class method( ).lo class- final method( ).Read ABAP Objects online: tshttps://riptutorial.com/10

Chapter 4: CommentsExamplesEnd of LineAny text following a " character on the same line is commented out:DATA ls booking TYPE flightb. " Commented textFull LineThe * character comments out an entire line. The * must be the first character in the line.* DATA ls booking TYPE flightb. Nothing on this line will be executed.Read Comments online: tps://riptutorial.com/11

Chapter 5: Control Flow StatementsExamplesIF/ELSEIF/ELSEIF lv foo 3.WRITE: / 'lv foo is 3'.ELSEIF lv foo 5.WRITE: / 'lv foo is 5'.ELSE.WRITE: / 'lv foo is neither 3 nor 5'.ENDIF.CASECASE lv foo.WHEN 1.WRITE: / 'lv fooWHEN 2.WRITE: / 'lv fooWHEN 3.WRITE: / 'lv fooWHEN OTHERS.WRITE: / 'lv fooENDCASEis 1'.is 2'.is 3'.is something else'.CHECKis a simple statement that evaluates a logical expression and exits the current processingblock if it is false.CHECKMETHOD do something.CHECK iv input IS NOT INITIAL. "Exits method immediately if iv input is initial"The rest of the method is only executed if iv input is not initialENDMETHOD.ASSERTis used in sensitive areas where you want to be absolutely sure, that a variable has aspecific value. If the logical condition after ASSERT turns out to be false, an unhandleable exception(ASSERTION FAILED) is thrown.ASSERTASSERT 1 1. "No Problem - Program continuesASSERT 1 2. "ERRORhttps://riptutorial.com/12

COND/SWITCHand COND offer a special form of conditional program flow. Unlike IF and CASE, theyrespresent different values based on an expression rather than executing statements. That's whythey count as functional.SWITCHCONDWhenever multiple conditions have to be considered, COND can do the job. The syntax is fairlysimple:COND type (WHEN condition THEN value .[ ELSE default throw exception ]).Examples" Set screen element active depending on radio buttonscreen-active COND i(WHEN p radio abap true THEN 1ELSE 0 " optional, because type 'i' defaults to zero)." Check how two operands are related to each other" COND determines its type from rw comparerw compare COND #(WHEN op1 op2 THEN 'LT'WHEN op1 op2 THEN 'EQ'WHEN op1 op2 THEN 'GT').SWITCHis a neat tool for mapping values, as it checks for equality only, thus being shorter than CONDin some cases. If an unexpected input was given, it is also possible to throw an exception. Thesyntax is a little bit different:SWITCHSWITCH type ( variable WHEN value THEN new value .[ ELSE default throw exception ]).Exampleshttps://riptutorial.com/13

DATA(lw language) SWITCH string(sy-languWHEN 'E' THEN 'English'WHEN 'D' THEN 'German'" .ELSE THROW cx sy conversion unknown langu( )).Read Control Flow Statements online: owstatementshttps://riptutorial.com/14

Chapter 6: Data DeclarationExamplesInline Data DeclarationIn certain situations, data declarations can be performed inline.LOOP AT lt sflight INTO DATA(ls sflight).WRITE ls sflight-carrid.ENDLOOP.Single Variable DeclarationDATA begda TYPE sy-datum.Multiple Variable DeclarationDATA: begda TYPE sy-datum,endda TYPE sy-datum.Inline Data Declaration in SELECT StatementWhen using an inline data declaration inside of a SELECT.ENDSELECT block or SELECT SINGLEstatement, the @ character must be used as an escape character for the DATA(lv cityto)expression. Once the escape character has been used, all further host variables must also beescaped (as is the case with lv carrid below).DATA lv carrid TYPE s carr id VALUE 'LH'.SELECT SINGLE cityto FROM spfliINTO @DATA(lv cityto)WHERE carrid @lv carridANDconnid 2402.WRITE: / lv cityto.Outputs BERLIN.Variable Declaration OptionsDifferent types of variables may be declared with special options.DATA: lv stringTYPE string, " standard declarationlv charTYPE c," declares a character variable of length 1lv char5(5) TYPE c," declares a character variable of length 5l packed TYPE p LENGTH 10 DECIMALS 5 VALUE '1234567890.123456789'. " evaluates to1,234,567,890.12346https://riptutorial.com/15

Read Data Declaration online: rationhttps://riptutorial.com/16

Chapter 7: Dynamic ProgrammingExamplesField-SymbolsField-Symbols are ABAP's equivalent to pointers, except that Field-Symbols are alwaysdereferenced (it is not possible to change the actual address in memory).DeclarationTo declare a Field-Symbol the keyword FIELD-SYMBOLS must be used. Types can be generic (ANY[. TABLE]) to handle a wide variety of variables.FIELD-SYMBOLS: fs line fs struct TYPE any,TYPE kna1."generic"non-genericAssigningField-Symbols are unassigned on declaration, which means that they are pointing to nothing.Accessing an unassigned Field-Symbol will lead to an exception, and, if uncaught, to a shortdump. Therefore, the state should be checked with IS ASSIGNED:IF fs IS ASSIGNED.*. symbol is assignedENDIF.As they are only references, no real data can be stored inside. So, declared DATA is needed inevery case of use.DATA: w name TYPE string VALUE Max ,w index TYPE iVALUE 1.FIELD-SYMBOLS fs name TYPE any.ASSIGN w name TO fs name . " fs name now gets w name fs name 'Manni'."Changes to fs name now also affect w name* As fs name is generic, it can also be used for numbersASSIGN w index TO fs name . " fs name now refers to w index.ADD 1 TO fs name ."w index gets incremented by oneUnassigningSometimes it could be useful to reset a Field-Symbol. This can be done using UNASSIGN.UNASSIGN fs .* Access on fs now leads to an exception againhttps://riptutorial.com/17

Use for internal tablesField-Symbols may be used to modify internal tables.LOOP AT itab INTO DATA(wa).* Only modifies wa linewa-name1 'Max'.ENDLOOP.LOOP AT itab ASSIGNING FIELD-SYMBOL( fs ).* Directly refers to a line of itab and modifies its values fs -name1 'Max'.ENDLOOP.Attention! Field-Symbols stay assigned even after leaving the loop. If you want to reuse themsafely, unassign them immediately.Data referencesEssential for data references is the addition REFTOafter TYPE.Dynamic Creation of StructuresIf the type of a structure should be decided on runtime, we can define our target structure asreference to the generic type data.DATA wa TYPE REF TO data.To give wa a type we use the statement CREATEDATA.The addition TYPE can be specified by:Reference:CREATE DATA wa TYPE kna1 Static checks are active so it's not possible to create an unknown typeName:CREATE DATA wa TYPE (lw name as string) The parentheses are needed and lw name as string contains the types name asstring. If the type was not found, an exception of type CX SY CREATE DATA ERROR will bethrownFor instancing dynamically created types the HANDLE addition can be specified. HANDLE receives anobject which inherits from CL ABAP DATADESCR.CREATE DATA dref TYPE HANDLE obj obj can be created using the RunTime Type Services because dref is still a datareference, it has to be dereferenced (- *) to be used ashttps://riptutorial.com/18

datacontainer (normally done via Field-Symbols)RunTime Type ServicesRunTime Type Services (short: RTTS) are used either for: creating types (RunTime Type Creation; short: RTTC) analysing types (RunTime Type Identification; short: RTTI)ClassesCL ABAP TYPEDESCR --CL ABAP DATADESCR --CL ABAP ELEMDESCR --CL ABAP REFDESCR --CL ABAP COMPLEXDESCR --CL ABAP STRUCTDESCR --CL ABAP TABLEDESCR --CL ABAP OBJECTDESCR --CL ABAP CLASSDESCR --CL ABAP INTFDESCRCL ABAP TYPEDESCR is the base class. It implements the needed methods for describing:DESCRIBE BY DATADESCRIBE BY NAMEDESCRIBE BY OBJECT REFDESCRIBE BY DATA REFRead Dynamic Programming online: ogramminghttps://riptutorial.com/19

Chapter 8: Internal TablesExamplesTypes of Internal tablesDATA: TABLE NAME TYPE SORTED STANDARD HASHED TABLE OF TYPE NAME WITH UNIQUE NON-UNIQUE KEY FIELDS FOR KEY .Standard TableThis table has all of the entries stored in a linear fashion and records are accessed in a linear way.For large table sizes, table access can be slow.Sorted TableRequires the addition WITH UNIQUE NON-UNIQUE KEY. Searching is quick due to performing a binarysearch. Entries cannot be appended to this table as it might break the sort order, so they arealways inserted using the INSERT keyword.Hashed TableRequires the addition WITH UNIQUE NON-UNIQUE KEY. Uses a proprietary hashing algorithm to maintainkey-value pairs. Theoretically searches can be as slow as STANDARD table but practically they arefaster than a SORTED table taking a constant amount of time irrespective of the size of the table.Declaration of ABAP Internal TablesInternal Table Declaration Based on LocalType Definition" Declaration of typeTYPES: BEGIN OF ty flightb,idTYPE fl id,datTYPE fl date,seatnoTYPE fl seatno,firstname TYPE fl fname,lastname TYPE fl lname,fl smoke TYPE fl smoker,classfTYPE fl class,classbTYPE fl class,classeTYPE fl class,mealTYPE fl meal,serviceTYPE fl service,discoutTYPE fl discnt,END OF lty flightb.https://riptutorial.com/20

" Declaration of internal tableDATA t flightb TYPE STANDARD TABLE OF ty flightb.Declaration based on Database TableDATA t flightb TYPE STANDARD TABLE OF flightb.Inline Internal Table DeclarationRequires ABAP version 7.4TYPES t itab TYPE STANDARD TABLE OF i WITH EMPTY KEY.DATA(t inline) VALUE t itab( ( 1 ) ( 2 ) ( 3 ) ).Internal Table with Header Lines DeclarationIn ABAP there are tables with header lines, and tables without header lines. Tables with headerlines are an older concept and should not be used in new development.Internal Table: Standard Table with / without header lineThis code declares the table i compc all with the existing structure of compc str.DATA: i compc all TYPE STANDARD TABLE OF compc str WITH HEADER LINE.DATA: i compc all TYPE STANDARD TABLE OF compc str.Internal Table: Hashed Table with / without header lineDATA: i map rules c TYPE HASHED TABLE OF /bic/ansdomm0100 WITH HEADER LINEDATA: i map rules c TYPE HASHED TABLE OF /bic/ansdomm0100Declaration of a work area for tables without a headerA work area (commonly abbreviated wa) has the exact same structure as the table, but cancontain only one line (a WA is a structure of a table with only one dimension).DATA: i compc all line LIKE LINE OF i compc all.Read, Write and Insert into Internal TablesRead, write and insert into internal tables with a header line:" Read from table with header (using a loop):https://riptutorial.com/21

LOOP AT i compc all.CASE i compc all-ftype.WHEN 'B'.i compc bil i compc all.header line i compc allAPPEND i compc bil.i compc bil" . more WHENsENDCASE.ENDLOOP.""""Loop over table i compc all and assign header lineRead cell ftype from header line from table i compc allBill-to customer number transformationAssign header line of table i compc bil with content of" Insert header line of table i compc bil into tableReminder: Internal tables with header lines are forbidden in object oriented contexts.Usage of internal tables without header lines is always recommended.Read, write and insert into internal tables without a header line:" Loop over table i compc all and assign current line to structure i compc all lineLOOP AT i compc all INTO i compc all line.CASE i compc all line-ftype." Read column ftype from current line (which asassigned into i compc all line)WHEN 'B'." Bill-to customer number transformationi compc bil line i compc all line." Copy structureAPPEND i compc bil line TO i compc bil. " Append structure to table" more WHENs .ENDCASE.ENDLOOP." Insert into table with Header:INSERT TABLE i sap knb1." insert into TABLE WITH HEADER: insert tableheader into it's contentinsert i sap knb1 line into table i sap knb1. " insert into HASHED TABLE: insert structurei sap knb1 line into hashed table i sap knb1APPEND p t errorlog line to p t errorlog." insert into STANDARD TABLE: insert structure /wa p t errorlog line into table p t errorlog lineRead Internal Tables online: ableshttps://riptutorial.com/22

Chapter 9: LoopsRemarksWhen looping over internal tables, it is generally preferable to ASSIGN to a field symbol rather thanloop INTO a work area. Assigning field symbols simply updates their reference to point to the nextline of the internal table during each iteration, whereas using INTO results in the line of the tablebeing copied into the work area, which can be expensive for long/wide tables.ExamplesInternal Table LoopLOOP AT itab INTO wa.ENDLOOP.FIELD-SYMBOLS fs LIKE LINE OF itab.LOOP AT itab ASSIGNING fs .ENDLOOP.LOOP AT itab ASSIGNING FIELD-SYMBOL( fs ).ENDLOOP.LOOP AT itab REFERENCE INTO dref.ENDLOOP.LOOP AT itab TRANSPORTING NO FIELDS.ENDLOOP.Conditional LoopingIf only lines that match a certain condition should be taken into the loop, addition WHERE can beadded.LOOP AT itab INTO wa WHERE f1 'Max'.ENDLOOP.While LoopABAP also offers the conventional WHILE-Loop which runs until the given expression evaluates tofalse. The system field sy-index will be increased for every loop step.WHILE condition.* do somethingENDWHILEDo Loophttps://riptutorial.com/23

Without any addition the DO-Loop runs endless or at least until it gets explicitly exited from inside.The system field sy-index will be increased for every loop step.DO.* do something. get it?* call EXIT somewhereENDDO.The TIMES addition offers a very convenient way to repeat code (amount represents a value of type i).DO amount TIMES.* do several timesENDDO.General CommandsTo break loops, the command EXIT can be used.DO.READ TABLE itab INDEX sy-index INTO DATA(wa).IF sy-subrc 0.EXIT. "Stop this loop if no element was foundENDIF." some codeENDDO.To skip to the next loop step, the command CONTINUE can be used.DO.IF sy-index MOD 1 0.CONTINUE. " continue to next even indexENDIF." some codeENDDO.The CHECK statement is a CONTINUE with condition. If the condition turns out to be false, CONTINUE willbe executed. In other words: The loop will only carry on with the step if the condition is true.This example of CHECK .DO." some codeCHECK sy-index 10." some codeENDDO. is equivalent to .DO." some codeIF sy-index 10.https://riptutorial.com/24

CONTINUE.ENDIF." some codeENDDO.Read Loops online: ://riptutorial.com/25

Chapter 10: Message Classes/MESSAGEkeywordIntroductionThe MESSAGE statement may be used to interrupt program flow to display short messages to theuser. Messages content may be defined in the program's code, in the program's text symbols, orin an independent message class defined in SE91.RemarksThe maximum length of a message, including parameters passed to it using &, is 72 characters.ExamplesDefining a Message ClassPROGRAM zprogram MESSAGE-ID sabapdemos.System-defined message may be stored in a message class. The MESSAGE-ID token defines themessage class sabapdemos for the entire program. If this is not used, the message class must bespecified on each MESSAGE call.MESSAGE with Predefined Text SymbolPROGRAM zprogram MESSAGE-ID za.MESSAGE i000 WITH TEXT-i00.A message will display the text stored in the text symbol i00 to the user. Since the message typeis i (as seen in i000), after the user exits the dialog box, program flow will continue from the pointof the MESSAGE call.Although the text did not come from the message class za, a MESSAGE-ID must be specified.Message without Predefined Message ClassPROGRAM zprogram.MESSAGE i050(sabapdemos).It may be inconvenient to define a message class for the entire program, so it is possible to definethe message class that the message comes from in the MESSAGE statement itself. This example willdisplay message 050 from the message class sabapdemos.https://riptutorial.com/26

Dynamic MessagingDATA: msgid TYPE sy-msgid VALUE 'SABAPDEMOS',msgty TYPE sy-msgty VALUE 'I',msgno TYPE sy-msgno VALUE '050'.MESSAGE ID mid TYPE mtype NUMBER num.The MESSAGE call above is synonymous to the call MESSAGEi050(sapdemos).Passing Parameters to MessagesThe & symbol may be used in a message to allow parameters to be passed to it.Ordered ParametersMessage 777 of class sabapdemos:Message with type &1 &2 in event &3Calling this message with three parameters will return a message using the parameters:MESSAGE i050(sabapdemos) WITH 'E' '010' 'START-OF-SELECTION .This message will be displayed as Message with type E 010 in event START-OF-SELECTION. Thenumber next to the & symbol designates the order in which the parameters are displayed.Unordered ParametersMessage 888 of class sabapdemos:& & & &The calling of this message is similar:MESSAGE i050(sabapdemos) WITH 'param1' 'param2' 'param3' 'param4'.This will output param1param2 param3 param4.Read Message Classes/MESSAGE keyword om/27

Chapter 11: Naming ConventionsSyntax Characters, numbers and can be use for variable name.Two character using for variable state and object type.Local variables start with L.Global variables start with G.Function input parameter start with I (import).Function output parameter start with E (export).Structures symbol is S.Table symbol is T.ExamplesLocal variabledata: lv temp type string.data: ls temp type sy.data: lt temp type table of sy.Global variabledata: gv temp type string.data: gs temp type sy.data: gt temp type table of sy.Read Naming Conventions online: ventionshttps://riptutorial.com/28

Chapter 12: Open SQLExamplesSELECT statementSELECT is an Open-SQL-statement for reading data from one or several database tables intodata objects.1. Selecting All Records* This returns all records into internal table lt mara.SELECT * FROM maraINTO lt mara.2. Selecting Single Record* This returns single record if table consists multiple records with same key.SELECT SINGLE * INTO TABLE lt maraFROM maraWHERE matnr EQ '400-500'.3. Selecting Distinct Records* This returns records with distinct values.SELECT DISTINCT * FROM maraINTO TABLE lt maraORDER BY matnr.4. Aggregate Functions* This puts the number of records present in table MARA into th

ABAP is a programming language developed by SAP for programming business applications in the SAP environment. Previously only procedural, ABAP is now also an object-oriented language thanks to the ABAP Objects enhancement. Versions Version Release Date ABAP 7.50 2015-10-20 ABAP 7.40 2012-11-29 ABAP 7.0 2006-04-01 ABA