Skip to Content
author's profile photo Former Member
Former Member

Regarding interactive Events

Hi,

Can anyone explain me the interactive events like AT USER-COMMAND, AT PF, AT LINE_SELECTION with an example

Regards,

Pavankumar.

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

4 Answers

  • Posted on May 27, 2008 at 08:13 AM
    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on May 27, 2008 at 08:15 AM

    Hi,

    List Events in an ABAP Program

    After a user interaction on a list, the ABAP runtime environment checks whether it should process the function code itself (for example, %EX or %PC), or whether it should trigger the relevant event. Unlike normal screens, in which the PAI event is triggered, the runtime environment triggers three special events when list events occur. You can use the corresponding event blocks in your ABAP program to react to the user action. From within the program, you can use the sy-ucomm system field to access the function code. There is no OK_CODE field to be filled here.

    Event Blocks for Function Codes PFnn (Obsolete)

    When the user chooses a function code PFnn (nn can be between 01 and 24), the system always triggers the AT PFnn event. In the standard list status, the function keys Fnn that are not reserved for predefined system functions all have the function code PFnn as long as a corresponding event block is defined in the program.

    AT PFnn

    statements.

    These event blocks are executed when the user chooses the corresponding function key. The position of the cursor in the list is irrelevant.

    If you use these event blocks at all, it should only be for temporary test versions. In production programs, you should only use AT USER-COMMAND with a dialog status of your own to assign function codes to function keys. When you use your own interfaces, the system displays a function text explaining what the function does. This does not happen when you use AT PFnn event blocks.

    Event Block for Function Code PICK

    When the user triggers the function code PICK, AT LINE-SELECTION is always triggered if the cursor is positioned on a list line. The function code PICK is, by default, always linked with function key F2 and hence with the mouse double-click. Consequently, if you have a simple program that does not react to any further user actions, you only need to write this event block.

    AT LINE-SELECTION.

    statements.

    As described in the section Dialog Status for Lists, the function code PICK is always added to the standard list status when you have an AT LINE-SELECTION event in your program.

    If you assign PICK to other function keys or menu entries, AT LINE-SELECTION is also triggered when the user chooses then. You should avoid this for the sake of the semantics.

    Conversely, if you have a more extensive program that does not react to line selection, you should not use the function code PICK. Instead you should assign a different function code to F2, to ensure that as many events as possible trigger the AT USER-COMMAND event.

    Event Block for User-Defined Function Codes

    If the user chooses a function code during list processing that is neither processed by the system, or PICK or PFnn, the system triggers the event AT USER-COMMAND. For this event, you must define your own GUI status for a list. To react to your own function codes in a program, you must define the following event block:

    AT USER-COMMAND.

    statements.

    In this event block, you can use an IF or CASE structure to differentiate between the function codes. They are available in the system field sy-ucomm. There are further system fields that are filled in list events, such as sy-lsind and sy-pfkey, that allow you to make further case distinctions.

    Triggering a List Event from the Program

    You can trigger a list event from the program as follows:

    SET USER-COMMAND fc.

    This statement takes effect after the current list is completed. Before the list is displayed, the event assigned to function code fc is triggered, regardless of the dialog status you are using.

    The effect is the same as when the user chooses the function. In other words, predefined list function codes are trapped and processed by the runtime environment, the function codes PICK and PFnn trigger the AT LINE-SELECTION and AT PFnnevents, and user-defined function codes trigger the AT USER-COMMAND event block.

    Function code PICK triggers an event only if the cursor is located on a list line.

    Using this statement in conjunction with the function codes reserved for system functions, you can call the system functions from the program. For example, you can use SET USER-COMMAND '%SC' to call the Find dialog box directly, or to position the list correctly before it is displayed.

    If you use several SET USER-COMMAND statements while creating a list, the system executes only the last one.

    Examples

    Example for AT LINE-SELECTION.

    REPORT demo_list_at_line_selection.

    START-OF-SELECTION.

    WRITE 'Basic List'.

    AT LINE-SELECTION.

    WRITE: 'Secondary List by Line-Selection',

    / 'sy-ucomm =', sy-ucomm.

    When you run the program, the basic list appears with the standard list status. The detail list shows that sy-ucomm has the value PICK.

    Example for AT PFnn.

    REPORT demo_list_at_pf.

    START-OF-SELECTION.

    WRITE 'Basic List, Press PF5, PF6, PF7, or PF8'.

    AT pf5.

    PERFORM out.

    AT pf6.

    PERFORM out.

    AT pf7.

    PERFORM out.

    AT pf8.

    PERFORM out.

    FORM out.

    WRITE: 'Secondary List by PF-Key Selection',

    / 'sy-lsind =', sy-lsind,

    / 'sy-ucomm =', sy-ucomm.

    ENDFORM.

    After executing the program, the system displays the basic list. The user can press the function keys F5, F6, F7, and F8 to create secondary lists. If, for example, the 14th key the user presses is F6, the output on the displayed secondary list looks as follows:

    Secondary List by PF-Key Selection

    sy-lsind = 14

    sy-ucomm = PF06

    Example of AT USER-COMMAND.

    REPORT demo_list_at_user_command NO STANDARD PAGE HEADING.

    START-OF-SELECTION.

    WRITE: 'Basic List',

    / 'sy-lsind:', sy-lsind.

    TOP-OF-PAGE.

    WRITE 'Top-of-Page'.

    ULINE.

    TOP-OF-PAGE DURING LINE-SELECTION.

    CASE sy-pfkey.

    WHEN 'TEST'.

    WRITE 'Self-defined GUI for Function Codes'.

    ULINE.

    ENDCASE.

    AT LINE-SELECTION.

    SET PF-STATUS 'TEST' EXCLUDING 'PICK'.

    PERFORM out.

    sy-lsind = sy-lsind - 1.

    AT USER-COMMAND.

    CASE sy-ucomm.

    WHEN 'FC1'.

    PERFORM out.

    WRITE / 'Button FUN 1 was pressed'.

    WHEN 'FC2'.

    PERFORM out.

    WRITE / 'Button FUN 2 was pressed'.

    WHEN 'FC3'.

    PERFORM out.

    WRITE / 'Button FUN 3 was pressed'.

    WHEN 'FC4'.

    PERFORM out.

    WRITE / 'Button FUN 4 was pressed'.

    WHEN 'FC5'.

    PERFORM out.

    WRITE / 'Button FUN 5 was pressed'.

    ENDCASE.

    sy-lsind = sy-lsind - 1.

    FORM out.

    WRITE: 'Secondary List',

    / 'sy-lsind:', sy-lsind,

    / 'sy-pfkey:', sy-pfkey.

    ENDFORM.

    When you run the program, the system displays the following basic list with a the page header defined in the program:

    You can trigger the AT LINE-SELECTION event by double-clicking a line. The system sets the status TEST and deactivates the function code PICK. The status TEST contains function codes FC1 to FC5. These are assigned to pushbuttons in the application toolbar. The page header of the detail list depends on the status.

    Here, double-clicking a line no longer triggers an event. However, there is now an application toolbar containing five user-defined pushbuttons. You can use these to trigger the AT USER-COMMAND event. The CASE statement contains a different reaction for each pushbutton.

    For each interactive event, the system decreases the sy-lsind system field by one, thus canceling out the automatic increase. All detail lists now have the same level as the basic list and thus overwrite it. While the detail list is being created, sy-lsind still has the value 1.

    Example of AT USER-COMMAND.

    REPORT demo_list_set_user_command NO STANDARD PAGE HEADING.

    START-OF-SELECTION.

    SET USER-COMMAND 'MYCO'.

    WRITE 'Basic List'.

    AT USER-COMMAND.

    CASE sy-ucomm.

    WHEN 'MYCO'.

    WRITE 'Secondary List from USER-COMMAND,'.

    WRITE: 'sy-lsind', sy-lsind.

    SET USER-COMMAND 'PF05'.

    ENDCASE.

    AT pf05.

    WRITE 'Secondary List from PF05,'.

    WRITE: 'sy-lsind', sy-lsind.

    SET CURSOR LINE 1.

    SET USER-COMMAND 'PICK'.

    AT LINE-SELECTION.

    WRITE 'Secondary List from LINE-SELECTION,'.

    WRITE: 'sy-lsind', sy-lsind.

    SET USER-COMMAND '%SC'.

    This program creates one basic list and three detail lists. When the program starts, the third detail list is displayed immediately, along with a dialog box for searching in the list. The dialog box is displayed by setting the predefined function code %SC. To view the other lists, the user chooses Back.

    Note that in the event AT PF05, the SET CURSOR statement is used to position the cursor on a list line in order to support the function code PICK.

    Reward If Helpfull.

    Naresh

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on May 27, 2008 at 08:46 AM

    hi,

    at user-command: If the user chooses a function code during list processing that is neither processed by the system,

    the system triggers the event AT USER-COMMAND. For this event, you must define your own GUI status for a list.

    at pf: When the user chooses a function code PF<nn> (<nn> can be between 01 and 24), the system always triggers the AT PF<nn> event.

    example for at line-seelction

    data: begin of jtab occurs 0,

    matnr like makt-matnr,

    spras like makt-spras,

    maktg like makt-maktg,

    end of jtab.

    data: begin of itab occurs 0 ,

    matnr like makt-matnr,

    end of itab.

    select matnr from makt into table itab.

    loop at ITAB.

    write: / Itab-matnr, 30 sy-vline.

    hide: Itab-matnr

    endloop.

    at line-selection.

    case sy-lsind.

    when '1'.

    select spras maktg from makt into table jtab where matnr = ITab-matnr.

    loop at jtab.

    write: / jtab-matnr, 20 sy-vline, jtab-spras, 40 sy-vline, jtab-maktg, 60 sy-vline.

    endloop.

    endcase.

    at user-command

    data: begin of jtab occurs 0,

    matnr like makt-matnr,

    spras like makt-spras,

    maktg like makt-maktg,

    end of jtab.

    data: begin of itab occurs 0 ,

    matnr like makt-matnr,

    end of itab.

    select matnr from makt into table itab.

    loop at ITAB.

    write: / Itab-matnr, 30 sy-vline.

    hide: Itab-matnr

    endloop.

    at user-command.

    case sy-ucomm.

    when 'SHOW'.

    select spras maktg from makt into table jtab where matnr = ITab-matnr.

    loop at jtab.

    write: / jtab-matnr, 20 sy-vline, jtab-spras, 40 sy-vline, jtab-maktg, 60 sy-vline.

    endloop.

    endcase.

    thanks and regards,

    reward if useful

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on May 29, 2008 at 06:25 AM

    Events for Interactive lists:

    The following are specific for the context of interactive lists :

    1.AT LINE- SELECTION

    2.AT PF

    3.AT USER-COMMAND

    AT LINE - SELECTION : to allow the user to select a line from the list, define and write a processing block for the AT LINE -SELECTION event in your program :

    syntax :

    AT LINE-SELECTION.

    <STMTS>.

    AT PF <nn> : To allow the user to select an action by pressing afunction key,

    syntax : AT PF <nn>.

    <stmts >.

    <nn> is a number between 1 and 24.

    SY-UCOMM returns the finction code PF<nn>.

    AT USER-COMMAND : To allow your program to react a user action triggering a self-defined function code.

    syntax :

    AT USER-COMMAND.

    <stmts>.

    event occurs whenever a user selects a self defined function code from a self defined user interface.

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.