7-Basics of Interactive Reporting -Selection Screens

59
ITB258 - ABAP Programming Lecture 6 Basics of Interactive Reporting Selection Screens

description

7-Basics of Interactive Reporting -Selection Screens

Transcript of 7-Basics of Interactive Reporting -Selection Screens

  • ITB258 - ABAP Programming

    Lecture 6

    Basics of Interactive Reporting

    Selection Screens

  • ITN258 - ABAP Programming

    Lecture 6

    Basics of Interactive Reporting

    Selection Screens

  • Objectives

    To introduce readers to Interactive Reporting

    what are interactive lists

    basic & secondary lists

    the HIDE statement

    event control

    AT LINE-SELECTION

    SY-LSIND

    AT PF

    AT USER-COMMAND

    system fields for secondary lists

    To introduce the reader to concepts associated with the creation and use of Selection Screens in ABAP reportsthe SELECT-OPTIONS statementSelection tables Formatting the selection screenSelection texts, Lines, Comments, Frames, the PARAMETERS statementRadio button groups, Checkboxesexecuting reports with Variants
  • Interactive Reporting

  • Non-Interactive Reporting

    Non-interactive reporting involves the production of static lists. Here the user is forced to accept the level of detail provided on the list and often must wade through a lot of uninteresting pages of data to get to the data that is relevant.

    2.unknown
  • Interactive Reporting

    Interactive

    List

    Secondary

    List

    Report

    Transaction

    Interactive reporting on the other hand can be used to present summary detail at the highest level and allow th e user to drill down interactively, online, to see more detailed information.

    Further interactive reporting allows the user to spawn other reports or to start dialog programs from the current report.

    Interactive reporting is a common application in ABAP.

  • Non-Interactive vs
    Interactive Lists

    Non-Interactive

    static structure

    single, extensive and detailed list

    user searches through the list to find the relevant parts

    Interactive

    user selectively retrieves and presents data

    select lines, enter commands from menus, function keys or pushbuttons, type input

    detailed information presented in secondary lists

    ability to call transactions or other reports

  • Interactive Reports are
    Event Driven

    REPORT ZSAPTEST.

    *Basic List

    START-OF-SELECTION.

    GET

    END-OF-SELECTION.

    TOP-OF-PAGE.

    END-OF-PAGE.

    *Secondary Lists

    AT LINE-SELECTION.

    AT USER-COMMAND.

    AT PF.

    TOP-OF-PAGE DURING

    LINE-SELECTION.

    As with other report programs in ABAP interactive reports are event driven. As well as the events associated with static reports there are a set of events used to display the secondary lists.

  • The Basic List

    output of the data created while processing either

    START-OF-SELECTION

    GET

    by default a basic list has a standard page header

    if TOP-OF-PAGE / END-OF-PAGE event occurs

    system writes data to page header / page footer and then displays basic list data on the output screen

    system field SY-LSIND = 0

    The Basic list is the initial list displayed by an ABAP program. The data displayed in the basic list comes from select statements in the START-OF-SELECTION event or GET statements in the GET events.

    Basic lists have a standard page header. If TOP-OF-PAGE and/or BOTTOM-OF-PAGE events are coded the list header and footer are produced from here.

    The system variable SY-LSIND keeps track of the current list level. At the basic list level SY-LSIND has a value of 0. When the user drills down to a lower level the value of SY-LSIND is incremented. As the user moves back up the levels towards the basic list the vale of SY-LSIND is decremented.

  • Secondary Lists

    basic list + up to 20 secondary lists can exist in parallelon moving to (next) secondary list

    current list added to memory area

    SY-LSIND incremented by one

    using back or exit

    logically superior list is displayed again

    SY-LSIND decremented by one

    no standard heading for secondary lists
  • Basic

    List

    SY-LSIND = 0

    1. Secondary

    List

    SY-LSIND = 1

    2. Secondary

    List

    SY-LSIND = 2

    3. Secondary

    List

    SY-LSIND = 2

    choose

    choose

    choose

    REPORT ZSAPTEST.

    WRITE: / Basic List.

    AT LINE-SELECTION.

    CASE SY-LSIND.

    WHEN 1.

    :

    WHEN 2.

    :

    WHEN 3.

    SY-LSIND = SY-LSIND-1.

    :

    This slide illustrates the use of SY-LSIND in controlling the list level. The normal system behaviour is to increment the value of SY-LSIND when the user double clicks on a list line and to decrement SY-LSIND when the user moves towards the basic list level (by clicking on the Green Arrow Back icon).

    The AT LINE-SELECTION event has been used here to detect the user double clicking on a list line (the method used to drill down to a lower list level).

    In order for the program to know which level to display a CASE statement which tests the value of SY-LSIND is used.

    Note that in the block of code for WHEN 3 the program manipulates the value of SY-LSIND itself. The code subtracts one from the current value of SY-LSIND. When the user clicks on the Green Arrow Back icon the system will further decrement the value of SY-LSIND and the user is returned to list level 1. This is useful when we do not want to make the user have to backtrack through each higher level of the list to return to the basic list.

  • Page Headers for Secondary Lists

    On secondary lists

    system does not display a standard page header

    does not trigger the TOP-OF-PAGE event

    TOP-OF-PAGE DURING LINE-SELECTION

    triggered for each secondary list

    to create different page headers for each secondary list you must program a processing block for each value of SY-LSIND

    To produce custom page headers for each level of the secondary list it is necessary to code the TOP-OF-PAGE DURING LINE-SELECTION event. (The system does not produce page headers automatically for secondary lists.)

    A CASE statement should be used to produce the appropriate page header for each list level.

    See program ZRAL7001 for an example.

  • The HIDE Statement

    HIDE

    stores the contents of in relation to the current output line in the HIDE area

    not necessary for to appear on current line

    place the HIDE statement immediately after the output statement for

    user selection of a line for which HIDE fields are available fills the variables in the program with the values stored

    The mechanism that allows drilling down to secondary lists is the HIDE statement.

    HIDE stores the contents of in the so called hide area. There is a one to one correspondence between the screen row and the hide area row. When the user double clicks on a screen row the values in the hide area for that row are made available. Thus we can write a select statement for the secondary list along the lines of

    SELECT INTO

    FROM

    WHERE = .

    HIDE: .

    ENDSELECT.

  • X

    CARRID CONNID CITYFROM CITYTO

    AA0016New York Denver

    LH0400Frankfurt New York

    LH0357 Rome Frankfurt

    :

    CARRID CONNID

    AA0016

    LH0400

    LH0357

    :

    HIDE Area

    REPORT ZSAPTEST.

    GET SPFLI.

    WRITE: / SPFLI-CARRID, SPFLI-CONNID

    SPFLI-CITYFROM, SPFLI-CITYTO.

    HIDE: SPFLI-CARRID, SPFLI-CONNID.

    This slide illustrates the one to one correspondence between rows on the screen and in the hide area.

    Note that if you do something like sorting the rows on the screen the correspondence between rows on the screen and rows in the hide area is lost. (If you sort rows on the screen make sure to hide the sorted values as well.)

  • AT Events Processing

    AT LINE-SELECTION

    processed when user double clicks on a valid line

    AT USER-COMMAND

    processed when user

    presses a function key in the list

    makes an entry in the command field

    function code stored in system field SY-UCOMM

    AT PF

    processed when user presses a function key with code PF (in the range 0 to 99)

    There are a set of events that can be used to detect a user action in an interactive report.

    The AT LINE-SELECTION event is processed when the user double clicks on a line of a list.

    The AT USER-COMMAND is triggered when the user clicks on a toolbar pushbuton, makes a selection from a menu, or presses a function key.

    The AT PF event is triggered when the user presses a function key with code PFnn where nn is in the range 0 to 99.

    The value of the function code selected by the user action is stored in a system variable called SY-UCOMM. The value of this variable is tested in a CASE statement in events processing for the AT USER-COMMAND and AT PFnn events listed above. For AT LINE-SELECTION the value of SY-LSIND is used to determine the appropriate action.

  • AT LINE-SELECTION

    AT LINE-SELECTION

    determine what action to take by checking the current list level in the report

    code the appropriate action

    AT LINE-SELECTION.

    CASE SY-LSIND.

    WHEN 1.

    Select * from Sflight

    Where Carrid

    WHEN 2.

    Select * from Sbook

    Where

    ENDCASE.

  • AT USER-COMMAND

    AT USER-COMMAND

    determine what action to take by checking the current function code value stored in SY-UCOMM

    code the appropriate action

    AT USER-COMMAND.

    CASE SY-UCOMM.

    WHEN SORT.

    Perform Sort_List.

    WHEN DELE.

    Perform Del_Record.

    ENDCASE.

  • System Fields & Interactive Reports

    SY-CUROW

    cursor position (line)

    SY-CUCOL

    cursor position (column)

    SY-CPAGE

    number of current page

    SY-LSIND

    index of the displayed list level

    SY-LISEL

    contents of the selected line

    There are several system variables that are useful when processing interactive lists.

  • Selection Screens

  • Selection Screens

    Used to allow the user to control the database selections of the report Allows interactive

    assignment of values to variables

    with the PARAMETERS statement

    determine selection criteria for database fields

    single values, range of values, sets of values, ...

    with the SELECT-OPTIONS statement

  • The parameters Keyword

    PARAMETERS: P1 TYPE P,

    P2(6) TYPE C DEFAULT ITB255.

    PARAMETERS TYPE [DEFAULT ].

    P1

    P2

    ITB255

    Selection Screen

    X

  • Basic Form of select-options

    SELECT-OPTIONS FOR .

    creates a selection table which is attached to database column or internal table field .

    the name , like variable names, can be up to 8 characters only

    cannot be of type f (floating point)

  • REPORT ZSAPTEST.

    TABLES: SFLIGHT.

    SELECT-OPTIONS: AIRLINE FOR SFLIGHT-CARRID,

    CONN FOR SFLIGHT-CONNID.

    multiple selection screen

  • Multiple Selection Screen

  • Multiple Selection Screen

    icon on the main screen takes the user to the multiple selection screen

    allows creation of more complex selection criteria

    pushbutton saves an extended selection

    the arrow icon on the main screen turns to green indicating that the selection criteria is more complex than shown in the To and From fields

    pushbutton allows the user to enter selection criteria that can be excluded from the resulting set

  • is an internal table with 4 fields

    SIGN OPTION LOW HIGH

    IEQ

    ENE

    LT

    GT

    LE

    GE

    BT

    NB

    CP

    NP

  • and Database Selections

    If the contains more than one line

    form the union of sets defined on the lines that have SIGN = I

    subtract the union of sets defines on the lines that have SIGN = E

    select the resulting set

    If contains only lines with SIGN = E

    select all data outside the set specified in these lines

  • Assigning Default Values to Selection Criteria

    SELECT-OPTIONS FOR

    DEFAULT [TO ]

    OPTION SIGN .

    and may be

    literals (enclosed in single quotes)

    names of fields whose contents should be used as default values

    may be one of

    EQ,NE,GE,LE,GT,LT,CP,NP for single selections

    BT,NB for interval selections

    may be either I or E

  • REPORT ZSAPTEST.

    TABLES: SFLIGHT.

    SELECT-OPTIONS: AIRLINE FOR SFLIGHT-CARRID

    DEFAULT AA TO LH

    OPTION NB

    SIGN I.

  • Assigning Default Values to Selection Criteria

    REPORT ZSAPTEST.

    TABLES: SPFLI, SFLIGHT, SBOOK.

    SELECT-OPTIONS:AIRLINE FOR SPFLI-CARRID,

    CONN FOR SPFLI-CONNID.

    INITIALIZATION.

    MOVE LH TO AIRLINE-LOW.

    MOVE UA TO AIRLINE-HIGH.

    MOVE I TO AIRLINE-SIGN.

    MOVE BT TO AIRLINE-OPTION.

    APPEND AIRLINE.

    CLEAR AIRLINE.

    MOVE 0400 TO CONN-LOW.

    MOVE I TO CONN-SIGN.

    MOVE EQ TO CONN-OPTION.

    APPEND CONN.

  • Restricting the Selection Screen to One Line

    SELECT-OPTIONS FOR NO-EXTENSION .

    right arrow does not appear on the selection screen

    user cannot access the multiple succession screen

    REPORT ZSAPTEST.

    TABLES: SFLIGHT.

    SELECT-OPTIONS AIRLINE

    FOR SFLIGHT-CARRID

    NO-EXTENSION.

  • Restricting the Selection Screen to Single Value Selection

    SELECT-OPTIONS FOR NO INTERVALS .

    TO field does not appear on the selection screen

    user can access the multiple succession screen

    REPORT ZSAPTEST.

    TABLES: SFLIGHT.

    SELECT-OPTIONS AIRLINE

    FOR SFLIGHT-CARRID

    NO INTERVALS.

  • Further Selection Screen Options

    NO-DISPLAY

    suppresses display of selection screen criterion

    LOWER CASE

    enables acceptance of upper & lower case letters

    OBLIGATORY

    makes selection for FROM field mandatory

    MEMORY ID

    uses default values from SAP memory for FROM field

    MODIF ID

    assigns fields of a selection criterion to a modification group

    MATCHCODE OBJECT

    assigns a matchcode object to the FROM & TO fields of a selection criterion

  • Selection Tables in WHERE Conditions

    WHERE IN

    is a database column (without a prefix)

    is the selection table atached to

    REPORT ZSAPTEST.

    TABLES: SFLIGHT.

    SELECT-OPTIONS AIRLINE FOR SFLIGHT-CARRID.

    SELECT * FROM SFLIGHT

    WHERE CARRID IN AIRLINE.

  • Checkboxes on the
    Selection Screen

    PARAMETERS

    AS CHECKBOX ...

    parameter

    is created with type C length 1

    options TYPE & LIKE are not allowed

    valid values for

    are (false) and X (true)

    PARAMETERS: A AS CHECKBOX,

    B AS CHECKBOX DEFAULT X.

    A

    B

    x

  • Checkboxes on the Selection Screen

    REPORT ZSAPTEST.

    TABLES: SPFLI, SFLIGHT, SBOOK.

    SELECT-OPTIONS:SDEPART FOR SPFLI-DEPTIME,

    PARAMETERS:CURRENCY LIKE SFLIGHT-CURRENCY,

    LUGGAGE AS CHECKBOX.

    Dep.Time

    Price

    to

    to

    Show Luggage Weight

  • Radiobuttons on the
    Selection Screen

    PARAMETERS

    RADIOBUTTON GROUP ...

    parameter

    is created with type C length 1

    can use LIKE option but must refer to a dictionary object of type C length 1

    string of max length 4

    must assign at least 2 parameters to each group

    user click on radiobutton

    respective parameter is activated, ie, assigned X

    only one parameter in each group can be activated

  • Radiobuttons on the Selection Screen

    PARAMETERS: DISCOUNT RADIOBUTTON GROUP R1,

    ECONOMY RADIOBUTTON GROUP R1,

    BUSINESS RADIOBUTTON GROUP R1,

    FIRST RADIOBUTTON GROUP R1

    DEFAULT X.

    DISCOUNT

    ECONOMY

    BUSINESS

    FIRST

  • Formatting the Selection Screen

    SELECTION-SCREEN statement allows

    insertion of texts/comments

    underlines

    insertion of blank lines

    SELECTION-SCREEN BEGIN OF BLOCK

    combine logically related fields

    draw a box around them using WITH FRAME

  • Formatting the Selection Screen

    SELECTION-SCREEN BEGIN OF LINE

    COMMENT

    POSITION

    SELECTION-SCREEN END OF LINE.

    REPORT ZSAPTEST.

    TABLES: SPFLI, SFLIGHT, SBOOK.

    SELECTION-SCREEN: BEGIN OF LINE,

    COMMENT 1(11) TEXT-002,

    POSITION 33.

    PARAMETERS: PRICE LIKE SFLIGHT-PRICE OBLIGATORY.

    SELECTION-SCREEN: COMMENT 55(8) TEXT-003,

    POSITION 65.

    PARAMETERS: CURRENCY LIKE SFLIGHT-CURRENCY OBLIGATORY.

    SELECTION-SCREEN END OF LINE.

  • Formatting the Selection Screen

    SELECTION-SCREEN SKIP .

    leaves blank lines on the selection screen

    SELECTION-SCREEN ULINE

    draws an underline on the selection screen

  • Formatting the Selection Screen

    SELECTION-SCREEN BEGIN OF BLOCK

    WITH FRAME

    TITLE title

    SELECTION-SCREEN END OF BLOCK .

    REPORT ZSAPTEST.

    TABLES: SPFLI, SFLIGHT, SBOOK.

    SELECTION-SCREEN BEGIN OF BLOCK SPFLI

    WITH FRAME TITLE TEXT-001.

    SELECT-OPTIONS CARR FOR SPFLI-CARRID DEFAULT LH.

    SELECT-OPTIONS CITY FOR SPFLI-CITYFROM

    DEFAULT BERLIN.

    SELECT-OPTIONS DEPART FOR SPFLI-DEPTIME

    DEFAULT 100000 TO 130000.

    SELECTION-SCREEN END OF BLOCK SPFLI.

  • Formatting Selection Text

    default text on the selection screen

    PARAMETERS

    SELECT-OPTIONS

    more explanative text

    Text Maintenance Selection Texts

    SELECT-OPTIONS BEGIN OF LINE COMMENT ...

  • Checking the Selection Screen

    AT SELECTION-SCREEN

    ON

    ON RADIOBUTTON GROUP

    ON BLOCK

    REPORT ZSAPTEST MESSAGE-ID ....

    TABLES: SPFLI, SFLIGHT, SBOOK.

    SELECT-OPTIONS SPRICE FOR SFLIGHT-PRICE.

    ...

    AT SELECTION-SCREEN ON SPRICE.

    IF SPRICE-LOW LT 500.

    MESSAGE E001. no flight available at that price

    ENDIF.

    ...

  • Reports & Variants

    Variant

    set of values for all parameters and select-options

    when a report is executed with a variant the fields of the selection screen are filled with the values of the chosen variant

    Creating a Variant

    execute the report & fill in the selection screen

    GoTo Variants Save as Variant

    Enter a name and short description for the variant

    Fill in Variant Attributes as required

  • Save as Variant

  • Setting Attributes of a Variant

    Variant Attributes

    protected

    only creator can change it

    do not display variant

    Field Attributes

    protected

    cannot be changed by the user when the report is run

    invisible

    does not show the user the parameter/select-options variable

    other selection screen items shuffle up to leave no gap

    variable

    variant field takes the current value of the named variable

    variable is defined in the data dictionary

  • Running a Report With a Variant

    Execute the report

    Click on the 'Get Variant' button of the selection screen

    Select a variant from the next dialog box

  • Running a Report With a Variant

    System Services Reporting

    Click on

    select a variant from the next dialog box

  • Running a Report With a Variant

    SUBMIT USING

    SELECTION-SET

  • Conclusion

    Interactive Reporting

    non-static view of data for the user

    user selectively retrieves and displays data

    additional clearly structured information can be presented to the user in secondary lists or windows

    up to 20 secondary lists may exist

    secondary lists generated by special events

    AT LINE-SELECTION, AT USER-COMMAND, AT PF

    SY-LSIND contains index of current list level

  • Conclusion

    Interactive Lists

    to save data for the secondary list use HIDE

    system stores field names and field contents per line (SY-LISEL)

    at an interactive event the values stored in HIDE area are placed back into the original fields

    generally better performance through interactive lists

    only lines relevant to the user are selected and displayed as they are required

  • Conclusion

    This lecture examined methods of providing the user with some measure of control over database selections via the provision of a selection screenPARAMETERS statement

    defines a variable which can hold a single value

    AS CHECKBOX

    provides a yes/no type selection

    RADIOBUTTON GROUP

    provides a one of the following type selection

  • Conclusion

    SELECT-OPTIONS

    defines an internal table which holds selection conditions

    internal table has 4 attributes

    SIGN, OPTION, LOW, HIGH

    rows of the internal table can be specified

    via the DEFAULT clause in the program (one row)

    via the INITIALIZATION event in the program (many rows)

    dynamically at runtime

  • Conclusion

    selection screen can be formatted with

    lines, comments, frames

    selection text can be maintained through the Text Attributes screenvariants provide a method of storing commonly used selection conditionsreports can be executed with a variant from the workbench or from a program
  • Related Reading

    Textbook

    Ch 3.4 - Interactive Reports

    On-Line Help

    R/3 LibraryBC..ABAP Workbench

    BC ABAP Users Guide

    Running ABAP Programs

    Directly Executable Programs Executable Reports and Logical Databases

    Directly Executable Programs Features and Maintenance of Logical Databases

    ABAP User Interfaces

    Lists Interactive Lists

  • Related Reading

    Textbook

    Ch 3.2 Standard Reports, pp99-112

    On Line Help

    R/3 LibraryBC ABAP Workbench

    BC ABAP Users Guide

    ABAP User Interfaces Selection Screens

    Working With Selection Screens, Defining Selection Screens, Calling Selection Screens, Using Selection Criteria in Programs, Presetting Selection Criteria in Variants

  • Pre-Reading

    Textbook

    Ch 3.4.2 - The User Interface for Lists

    defining a GUI status

    AT USER-COMMAND

    AT PK