abap reports - classical

Upload: arvindkalika

Post on 04-Apr-2018

222 views

Category:

Documents


1 download

TRANSCRIPT

  • 7/30/2019 ABAP Reports - Classical

    1/44

    ABAP Training

    Day 2 Reports

  • 7/30/2019 ABAP Reports - Classical

    2/44

    Objectives

    Program Types

    Understand Report statement

    Understand Write statement

    Understand Conditional statements

    Understand System Fields

    Reports - Contents

  • 7/30/2019 ABAP Reports - Classical

    3/44

    Any customer-developed program should begin with Y or Z asa first character.

    A statement is a sequence of words that ends with a period.

    Transaction Code : SE38

    Menu Path: Tools > ABAP Workbench > ABAP Editor

    Reports - Creating an ABAP / 4 Program

  • 7/30/2019 ABAP Reports - Classical

    4/44

    4 Hexaware Technologies. All rights reserved.

    Report

    Initial screen of ABAP Editor

    4

  • 7/30/2019 ABAP Reports - Classical

    5/44

    5 Hexaware Technologies. All rights reserved.

    Report

    Type E run on its own

    Can be started it in the R/3 system without a

    transaction code

    Can be executed in background

    Type M ( Module pool)

    Program cannot run on its own and can be called via

    a transaction code

    5

  • 7/30/2019 ABAP Reports - Classical

    6/44

    6 Hexaware Technologies. All rights reserved.

    Report

    Type I( Include program )

    Contains the program code that can be used by

    different programs

    It modularizes the source code which consists of

    several different, logically related parts

    Readability is improved and thus easy

    maintenance

    Type F( Function Group)

    non-executable

    container for function modules

    can have its own screens

    6

  • 7/30/2019 ABAP Reports - Classical

    7/44

    7 Hexaware Technologies. All rights reserved.

    Report

    Type K(Class Definition )

    non-executable

    container for classes

    Type J(Interface Definition )

    non-executable

    container for Interface

    7

  • 7/30/2019 ABAP Reports - Classical

    8/44

    8 Hexaware Technologies. All rights reserved.

    Report

    Type S(Interface Definition )

    non-executable

    container for subroutines

    cannot have its own screens.

    8

  • 7/30/2019 ABAP Reports - Classical

    9/44

    9 Hexaware Technologies. All rights reserved.

    Variants

    A variant is an interface to the selection screen.

    If you want to run the same report program with the same selections atregular intervals (for example, for monthly sales statistics), you wouldnot want to enter the same values each time. ABAP/4 offers you apossibility to combine the desired values for all these selections in oneselection set. Such a selection set is called a variant.

    You can create as many different selection sets as you like for eachreport program and they remain assigned only to the report program inquestion.

    9

  • 7/30/2019 ABAP Reports - Classical

    10/44

    10 Hexaware Technologies. All rights reserved.

    INITIALIZATION Point before the selection screen is

    displayed

    AT SELECTION-SCREEN Point after processing user input on theselection screen while the selection

    screen

    is still active

    START-OF-SELECTION Point after processing the selectionscreen

    GET Point at which the logical database offers aline of the database table .

    END-OF-SELECTION Point after processing all lines offered bythe logical database.

    10

  • 7/30/2019 ABAP Reports - Classical

    11/44

    11 Hexaware Technologies. All rights reserved.

    AT SELECTION-SCREEN ON .

    AT SELECTION-SCREEN ON END OF .

    AT SELECTION-SCREEN ON VALUE-REQUEST FOR

    .

    AT SELECTION-SCREEN ON HELP-REQUEST FOR .

    AT SELECTION-SCREEN ON RADIOBUTTON GROUP.

    AT SELECTION-SCREEN ON BLOCK .

    AT SELECTION-SCREEN OUTPUT.

    11

  • 7/30/2019 ABAP Reports - Classical

    12/44

    12 Hexaware Technologies. All rights reserved.

    GET

    The most important event for report programs with an attached logical

    database is the moment at which the logical database program has reada line from a database table . To start a processing block at this event,use the GET statement as follows:

    Syntax

    GET .

    After this statement, you can work with the current line of the databasetable . The data is provided in the table work area

    Variants of GET event are :

    GET FIELDS ...

    GET LATE .

    12

  • 7/30/2019 ABAP Reports - Classical

    13/44

    13 Hexaware Technologies. All rights reserved.

    End of Selection

    To define a processing block after the system has read and processedall database tables of a logical database, use the keyword END-OF-SELECTION.

    13

  • 7/30/2019 ABAP Reports - Classical

    14/44

    14 Hexaware Technologies. All rights reserved.

    Report Statements - REPORT

    14

    REPORT StatementLINE-SIZE - Specifies, in columns, the width of the list to bedisplayed.

    LINE-COUNT - Specifies the no. of lines per page

    MESSAGE-ID - Allows the use of the Message statement without

    explicitly specifying the message id.

    NO STANDARD PAGE HEADING - suppresses the default headerfor the list displayed from your report by default.

    Example :

    REPORT ZTEST LINE-SIZE 250 LINE-COUNT 65(5).WRITE / Width of the Line Statement.

  • 7/30/2019 ABAP Reports - Classical

    15/44

    15 Hexaware Technologies. All rights reserved.

    Report Statements - WRITE

    15

    WRITE Statement

    Example :

    DATA: WORD(16) TYPE C VALUE '0123456789ABCDEF.

    WRITE AT / WORD. "new lineWRITE AT 5 WORD. "column 5WRITE AT (10) WORD. "output length 10WRITE AT /5(10) WORD. "new line, column 5, length 10

    ATpl positionandlengthspecification, beforethefieldoption formattingoption

    ASCHECKBOX output ascheckboxASSYMBOL output assymbol

    ASICON output asicon

    ASLINE output asline

  • 7/30/2019 ABAP Reports - Classical

    16/44

    16 Hexaware Technologies. All rights reserved.

    Report Statements - WRITE

    16

    Other Options

    NO-ZERONO-SIGNDECIMALS dROUND r

    DD/MM/YYYYNO-GAP

  • 7/30/2019 ABAP Reports - Classical

    17/44

    17 Hexaware Technologies. All rights reserved.

    Report Statements

    17

    NEW-PAGEUse the NEW-PAGE statement to create a page break inyour list. Page breaks allow you to make the page layout ofyour list more user-friendly.

    This statement creates a page break if a preceding

    statement wrote output to the screen or printer.

    SKIPUse the SKIP statement to create a line feed. To create

    several line feeds, specify the desired number behind SKIP.SKIP 5

    This line creates five line feeds.

  • 7/30/2019 ABAP Reports - Classical

    18/44

    18 Hexaware Technologies. All rights reserved.

    Report Statements

    ULINEUse the ULINE statement to create a line feed first and then draw a

    horizontal line. This statement also helps to make lists easier to read.

    SY-ULINEContains a horizontal line with length 255. Can be used when creating

    the list.

    SY-VLINE

    Contains a vertical line (|). Can be used when creating the list

    18

  • 7/30/2019 ABAP Reports - Classical

    19/44

    19 Hexaware Technologies. All rights reserved.

    Report Statements

    19

    MOVE Statement

    Use MOVE statement to assign values to variables.

    MOVE f TO g.

    Moves the contents of field f to field g. Field f remains

    unchanged. This statement is equivalent to:g = f.

    Multiple assignments likeNUMBER = FIVE = 5.are also possible. ABAP/4 executes them from right to left.

  • 7/30/2019 ABAP Reports - Classical

    20/44

    20 Hexaware Technologies. All rights reserved.

    Report Statements

    MOVE Statement

    MOVE TO .

    This is same as an assignment statement.

    S_AEDAT = I. Is equivalent to

    MOVE I TO S_AEDAT.

    MOVE +(length) TO +(length)

    Data Variable

    Beginning within the field. The first position is offset 0.

    Size in Characters

    Example :

    DATA : FIELD1(10) TYPE C VALUE ABCDEFGHIJ,

    FIELD2(10) TYPE C VALUE 1234567890.

    MOVE FIELD1+ 3(4) TO FIELD2+1(4).

    Result : FIELD2 is 1DEFG67890

    20

  • 7/30/2019 ABAP Reports - Classical

    21/44

    21 Hexaware Technologies. All rights reserved.

    Report - Operands

    Basic Arithmetic Operations

    ABAP/4 supports the four basic arithmetic operations, as well as powercalculation. You can specify the following arithmetic operators in amathematical expression:

    + Addition

    - Subtraction

    * Multiplication

    / DivisionDIV Integer division

    MOD Remainder of integer division

    ** Exponentiation

    21

  • 7/30/2019 ABAP Reports - Classical

    22/44

    22 Hexaware Technologies. All rights reserved.

    Report - Operands

    22

    = , EQ Equal to. , >< , NE Not Equal to.> , GT Greater than.< , LT Less than.>= , => , GE Greater than or equal to

  • 7/30/2019 ABAP Reports - Classical

    23/44

    23 Hexaware Technologies. All rights reserved.

    Report Statements - IF

    23

    IF Statement

    Used for case distinction.Depending on whether the logicalexpression logexp is true or not, this statement triggers the

    execution of various sections of code enclosed by IF andENDIF. There are three different types:

    1) IF logexp.processing1ENDIF.

    2) IF logexp.processing1ELSE.processing2ENDIF.

  • 7/30/2019 ABAP Reports - Classical

    24/44

    24 Hexaware Technologies. All rights reserved.

    Report Statements - CASE

    24

    CASE Statement

    To execute different statement blocks depending on the contentsof particular data fields, you use the CASE statement as follows:

    CASE .

    WHEN .

    WHEN .

    ......

    WHEN OTHERS.

    ENDCASE.

  • 7/30/2019 ABAP Reports - Classical

    25/44

    25 Hexaware Technologies. All rights reserved.

    Report Statements - CASE

    25

    Example :

    DATA: TXT1 VALUE 'X',

    TXT2 VALUE 'Y',

    TXT3 VALUE 'Z',

    STRNG VALUE 'A'.

    CASE STRNG.

    WHEN TEXT1.

    WRITE: / 'String is', TXT1.

    WHEN TEXT2.

    WRITE: / String is, TXT2.

    WHEN OTHERS.WRITE: / String is not, TXT1, TXT2, TXT3.

    ENDCASE.

    Output :String is not X Y Z

  • 7/30/2019 ABAP Reports - Classical

    26/44

    26 Hexaware Technologies. All rights reserved.

    Report Statements - WHILE

    26

    WHILE StatementRepeats the processing enclosed between the WHILE and

    ENDWHILE statements as long as the logical expression logexp is true.Checks

    the condition before each loop pass. If it is no longertrue, processing resumes after ENDWHILE.

    You can use the CONTINUE statement to leave the current loop passprematurely and skip to the next loop pass.

    Example :

    WHILE NUMBER SEARCH_ME.ADD 1 TO TRIES.

    NUMBER = ( MIN + MAX ) / 2.

    IF NUMBER > SEARCH_ME.

    MAX = NUMBER - 1.

    ENDIF.

    ENDWHILE.

  • 7/30/2019 ABAP Reports - Classical

    27/44

    27 Hexaware Technologies. All rights reserved.

    Report Statements - DO

    27

    DO Statement Repeats the processing enclosed by the DO and ENDDO statements untilthe

    loop is terminated by EXIT, STOP or REJECT. You can use the CONTINUE statement to end the current loop passprematurely

    and continue with the next loop pass. The system field SY-INDEX counts the number of loop passes, starting from1.

    You can nest DO loops. When the processing leaves a DO loop, the value ofSY-INDEX belonging to the outer DO loop is restored.

    Example :DO.

    WRITE: / 'SY-INDEX - Begin:', (3) SY-INDEX.

    IF SY-INDEX = 10.

    EXIT.

    ENDIF.' ' -

  • 7/30/2019 ABAP Reports - Classical

    28/44

    28 Hexaware Technologies. All rights reserved.

    Report Statements

    To terminate the processing of a loop, use one of the followingkeywords.

    Keyword Purpose

    CONTINUE Terminating a Loop Pass Unconditionally

    CHECK Terminating a Loop Pass Conditionally

    EXIT Terminating a Loop Entirely

    28

  • 7/30/2019 ABAP Reports - Classical

    29/44

    29 Hexaware Technologies. All rights reserved.

    Report Statement - CONTINUE

    Example for terminating a Loop Pass Unconditionally

    To terminate a loop pass immediately without any condition, use theCONTINUE statement as follows:

    DO 4 TIMES.

    IF SY-INDEX = 2.CONTINUE.

    ENDIF.

    WRITE SY-INDEX.

    ENDDO.

    This produces the following output:

    1 3 4

    Here, the system terminates the second loop pass without processing theWRITE statement.

    29

  • 7/30/2019 ABAP Reports - Classical

    30/44

    30 Hexaware Technologies. All rights reserved.

    Report Statement - CHECK

    Example for terminating a Loop Pass Conditionally

    To terminate a loop pass conditionally, use the CHECK statement asfollows:

    SyntaxCHECK .

    DO 4 TIMES.CHECK SY-INDEX BETWEEN 2 and 3.WRITE SY-INDEX.

    ENDDO.

    This produces the following output:

    2 3Here, the system terminates the first and the fourth loop pass without

    processing the WRITE statement because SY-INDEX does not fallbetween 2 and 3.

    30

  • 7/30/2019 ABAP Reports - Classical

    31/44

    31 Hexaware Technologies. All rights reserved.

    Report Statement - EXIT

    Example for terminating a Loop Entirely

    To terminate a loop entirely without any condition, use the EXITstatement as follows:

    SyntaxEXIT.

    DO 4 TIMES.IF SY-INDEX = 3.

    EXIT.ENDIF.

    WRITE SY-INDEX.ENDDO.

    This produces the following output:1 2

    Here, the system terminates the entire loop processing in the third looppass without processing the WRITE statement or the fourth loop pass.

    31

  • 7/30/2019 ABAP Reports - Classical

    32/44

    32 Hexaware Technologies. All rights reserved.

    Report - System Fields

    32

    GeneralSY-UNAME - Logon name of the userSY-DATUM - Current dateSY-UZEIT - Current timeSY-TABIX - Current line of an internal tableSY-INDEX - Number of loop passes

    ListsSY-TITLE - Report title from text elementsSY-LINCT - Number of lines from the REPORT statementSY-LINSZ - Line width from the REPORT statementSY-SROWS - Number of lines in the current window

    SY-SCOLS - Number of columns in the current windowSY-PAGNO - Number of current pageSY-LINNO - Number of current lineSY-COLNO - Number of current column

    During creation of the list, the system fills the last three system fields

    continuously.

  • 7/30/2019 ABAP Reports - Classical

    33/44

    33 Hexaware Technologies. All rights reserved.

    Report - System Fields

    33

    Interactive Reporting

    SY-CUROW - Cursor position (line)SY-CUCOL - Cursor position (column)SY-CPAGE - Number of the current pageSY-STACO - First displayed column of the list on displaySY-STARO - First displayed line of the list on displaySY-LSIND - Index of the displayed list levelSY-LISTI - Index of the selected list levelSY-LILLI - Number of the selected lineSY-LISEL - Contents of the selected line

  • 7/30/2019 ABAP Reports - Classical

    34/44

    34 Hexaware Technologies. All rights reserved.

    34

    String Processing

    Concatenating Character Strings (CONCATENATE) Condensing Field Contents (CONDENSE) Converting to Upper/Lower Case and Substituting Characters (TRANSLATE) Overlaying Character Fields (OVERLAY) Replacing Field Contents (REPLACE)

    Searching for Character Strings (SEARCH) Shifting (SHIFT) 1. Shifting a Field String by a Given Number of Positions

    2. Shifting a Field String According to the First or Last Character3. Shifting a Field String up to a Given String

    Splitting Character Strings (SPLIT)

    Obtaining the Length of a Character String (STRLEN)

  • 7/30/2019 ABAP Reports - Classical

    35/44

    35 Hexaware Technologies. All rights reserved.

    Clear / Refresh / Free

    CLEAR

    This statement restores an internal table to the state it was inimmediately after you declared it. This means that the table containsno lines. However, the memory already occupied by the memory upuntil you cleared it remains allocated to the table. If you want toaddress the body of the table in a comparison, you must place twobrackets ([ ]) after the table name.

    REFRESH This always applies to the body of the table. As with the CLEARstatement, the memory used by the table before you initialized itremains allocated. To release the memory space, use the statement.

    FREE .

    You can use FREE to initialize an internal table and release its memoryspace without first using the REFRESH or CLEAR statement. LikeREFRESH, FREE works on the table body, not on the table work area.After a FREE statement, you can address the internal table again. Itstill occupies the amount of memory required for its header (currently256 bytes). When you refill the table, the system has to allocate newmemory space to the lines.

    35

  • 7/30/2019 ABAP Reports - Classical

    36/44

    36 Hexaware Technologies. All rights reserved.

    CLEAR/REFRESH

    CLEAR ITAB.

    If ITAB is an internal table without a header line, the entire table isdeleted together with all its entries.

    If, however, ITAB is an internal table with a header line, only thesubfields in the table header entry are reset to their initial values.

    To delete the entire internal table together with all its entries, youcan use CLEAR ITAB[ ] or REFRESH ITAB.

    NOTE:

    CLEAR f. Clears the field contents

    36

  • 7/30/2019 ABAP Reports - Classical

    37/44

    37 Hexaware Technologies. All rights reserved.

    All these structures begin withAT and end with ENDAT. Thesequence of statements which lies between them is then executedif a control break occurs.

    AT NEW f. / AT END OF f.

    f is a sub-field of an internal table processed with LOOP.

    The sequence of statements which follow it is executed if thesub-field f or a sub-field in the current LOOP line defined (onthe left) before f has a different value than in the preceding (ATNEW) or subsequent (AT END OF) table line.

    AT FIRST. / AT LAST.

    Executes the appropriate sequence of statements once duringthe first (AT FIRST) or last (AT LAST) loop pass.

    37

    Report - Control Break With Internal Tables

  • 7/30/2019 ABAP Reports - Classical

    38/44

    38 Hexaware Technologies. All rights reserved.

    AT FIRSTStatements are executed before any records are processed while

    looping at Internal table.

    Example :LOOP AT itab.

    AT FIRST.

    WRITE : SY-ULINE.

    ENDAT.

    ENDLOOP.

    38

    Report - Control Break With Internal Tables

  • 7/30/2019 ABAP Reports - Classical

    39/44

    39 Hexaware Technologies. All rights reserved.

    AT LASTStatements are executed after all records are processed while

    looping at Internal table.

    Example :

    LOOP AT itab.

    AT LAST.

    WRITE : SY-ULINE.

    ENDAT.

    ENDLOOP.

    39

    Report - Control Break With Internal Tables

  • 7/30/2019 ABAP Reports - Classical

    40/44

    40 Hexaware Technologies. All rights reserved.

    AT NEW Statements are executed at the beginning of a group of records

    containing the same value for ..

    Example :

    LOOP AT itab.

    AT NEW I_LIFNR.

    WRITE : SY-ULINE

    ENDAT.

    ENDLOOP.

    40

    Report - Control Break With Internal Tables

  • 7/30/2019 ABAP Reports - Classical

    41/44

    41 Hexaware Technologies. All rights reserved.

    AT END OF Statements are executed at the end of a group of records

    containing the same value for .

    Example :

    LOOP AT itab.AT END OF I_LIFNR.

    WRITE : SY-ULINE.

    ENDAT.

    ENDLOOP.

    Note :AT NEW and AT END OF make sense only for a

    sorted table.

    41

    Report - Control Break With Internal Tables

    R S i

  • 7/30/2019 ABAP Reports - Classical

    42/44

    42 Hexaware Technologies. All rights reserved.

    SUM Statement

    SUM.

    SUM calculates the control totals of all fields of type I , F and P and

    places them in the LOOP output area (header line of the internal table or

    an explicitly specified work area).

    You can use the SUM statement both at the end and the beginning of a

    control group

    Example:LOOP AT itab.

    AT LAST.SUM.WRITE : itab-fld1.ENDAT.

    ENDLOOP.Prints the sum of values of fld1 in all rows of itab.Fld1 should be a numeric type field

    42

    Report - Summation

    R S i

  • 7/30/2019 ABAP Reports - Classical

    43/44

    43 Hexaware Technologies. All rights reserved.

    COLLECT StatementCOLLECT [wa INTO] itab.

    COLLECT is used to summate entries in an internal table.

    COLLECT = APPEND, if no entries with the same key exists

    = Adds the numeric values to their corresponding field

    values, if an entry with same key exists

    Used to create summarized tables.

    43

    Report - Summation

    Report - Summation

  • 7/30/2019 ABAP Reports - Classical

    44/44

    COLLECT Statement Example

    Timesheets per employee per dayINT_EMPTMSHT EMPNO(char), EDATE(date), HOURS(integer)

    Total time per employee for the whole period under consideration

    INT_TMSHTSUM EMPNO(char),HOURS(integer)

    INT_EMPTMSHT

    1000 20040102 5

    1000 20040103 7

    1001 20040103 8

    1001 20040106 3

    Report Summation

    INT_TMSHTSUM

    1000 12

    1001 8