Pf status & user-command in alv grid

Hi Friends,
I have one query for ALV grid.
Actually my requirement is like that
Whenever the user double click on grid the control moves to transaction 'VA01' tcode.
I also wanted to set the gui status in ALV grid.
How to do it??
Plz tell me in detail.

Very simple....
copy paste this code.... remember I have created a GUI Status called ZALV_STATUS.
So u will have to create this status to run ur program.
U can come back if u have any doubts...
*& Report  Z_ALV_TRAINING_LIST_HOTSPOT
REPORT  Z_ALV_TRAINING_LIST_HOTSPOT.
Type Pools Used  **********
TYPE-POOLS : SLIS.
Internal Tables Declare  ************
DATA : it_document   type standard table of bkpf initial size 0 with header line,
       IT_FIELD_CAT  TYPE SLIS_T_FIELDCAT_ALV,
       it_alv_event  type SLIS_T_EVENT,
       fl_layout     type slis_layout_alv.
Select Data  ***********
start-of-selection.
select * from bkpf into table it_document.
Make Field Catalog  ******
PERFORM MAKE_FIELD_CATALOG.
Make Layout  *********
perform sub_fill_layout.
Make Events Table  *******
perform sub_Fill_alv_event.
Display ALV  *********
PERFORM DISPLAY_ALV_LIST.
*&      Form  make_field_catalog
      text
-->  p1        text
<--  p2        text
FORM MAKE_FIELD_CATALOG .
data : wa type slis_fieldcat_alv.
CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
  EXPORTING
  I_PROGRAM_NAME               =
  I_INTERNAL_TABNAME           =
   I_STRUCTURE_NAME             = 'bkpf'
  I_CLIENT_NEVER_DISPLAY       = 'X'
  I_INCLNAME                   =
  I_BYPASSING_BUFFER           =
  I_BUFFER_ACTIVE              =
  CHANGING
    CT_FIELDCAT                  = it_field_cat
EXCEPTIONS
  INCONSISTENT_INTERFACE       = 1
  PROGRAM_ERROR                = 2
  OTHERS                       = 3
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
        WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
read table it_field_cat into wa index 3.
wa-hotspot = 'X'.
modify it_field_cat index 3 from wa.
ENDFORM.                    " make_field_catalog
*&      Form  display_alv_list
      text
-->  p1        text
<--  p2        text
FORM DISPLAY_ALV_LIST .
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
   I_CALLBACK_PROGRAM             = sy-repid
   I_CALLBACK_PF_STATUS_SET       = 'SET_MY_PF_STATUS'
  I_CALLBACK_USER_COMMAND        = ' '
   IS_LAYOUT                      = fl_layout
   IT_FIELDCAT                    = it_field_cat[]
  IT_SORT                        =
  I_DEFAULT                      = 'X'
   I_SAVE                         = 'X'
  IS_VARIANT                     = '/TEST_VV'
    IT_EVENTS                      = it_alv_event
  TABLES
    T_OUTTAB                       = it_document.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
        WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
ENDFORM.                    " display_alv_list
*&      Form  sub_my_pf_event
      text
-->  p1        text
<--  p2        text
FORM sub_my_pf_event using p_comm type sy-ucomm p_sEL_FIELD TYPE SLIS_SELFIELD.
  read table it_document index p_sel_field-tabindex.
  set parameter id 'BLN' field it_document-belnr.
  set parameter id 'BUK' field it_document-bukrs.
  set parameter id 'GJR' field it_document-gjahr.
  case p_comm.
    when 'PICK'.
      call transaction 'FB03' and skip first screen.
  endcase.
ENDFORM.                    " sub_my_pf_event
*&      Form  sub_Fill_alv_event
      text
-->  p1        text
<--  p2        text
FORM sub_Fill_alv_event .
  data : wa type slis_alv_event.
  wa-name = 'USER_COMMAND'.
  wa-form = 'SUB_MY_PF_EVENT'.
  append wa to it_alv_event.
ENDFORM.                    " sub_Fill_alv_event
*&      Form  sub_fill_layout
      text
-->  p1        text
<--  p2        text
FORM sub_fill_layout .
  fl_layout-f2code = 'PICK'.
  fl_layout-box_fieldname = 'BELNR'.
ENDFORM.                    " sub_fill_layout
*&      Form  SET_MY_PF_STATUS
      text
-->  p1        text
<--  p2        text
FORM SET_MY_PF_STATUS USING    p_rt_extab TYPE slis_t_extab.
SET PF-STATUS 'ZALV_STATUS'.
ENDFORM.                    " SET_MY_PF_STATUS
Plz award points if it was helpful....
Message was edited by:
        Varun Verma

Similar Messages

  • User command in ALV grid

    Hi
    I am displaying the output of a report in the ALV grid.
    I have used REUSE_ALV_LIST_DISPLAY in my code as follows.
    FORM DISPLAY_ALV_LIST.
      CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
      EXPORTING
      I_CALLBACK_PROGRAM = SYREPID
      IS_LAYOUT = FIELDLAYOUT
      I_CALLBACK_USER_COMMAND  = 'USER-COMMAND'
      IT_FIELDCAT = FIELDCATALOG[]
      I_SAVE = 'X'
      IT_EVENTS = EVENTSTAB[]
      TABLES
      T_OUTTAB = ITAB_1
      EXCEPTIONS
      PROGRAM_ERROR = 1
      OTHERS = 2.
    ENDFORM. " DISPLAY_ALV_LIST
    When I try to call a transaction at the user command with sy-ucomm = &IC1 sys gives a message 'Not valid'.
    FORM USER-COMMAND USING UCOMM LIKE SY-UCOMM
                           SELFIELD TYPE SLIS_SELFIELD.
      READ TABLE ITAB_1 INDEX SELFIELD-TABINDEX.
      CHECK SY-SUBRC = 0.
      CASE UCOMM.
        WHEN '&IC1'.
          CASE SELFIELD-SEL_TAB_FIELD.
            WHEN 'ITAB_1-VBELN'.
              SET PARAMETER ID 'VF' FIELD ITAB_1-VBELN.
              CALL TRANSACTION 'VF03' AND SKIP FIRST SCREEN.
            WHEN 'ITAB_1-MATNR'.
              SET PARAMETER ID 'MAT' FIELD ITAB_1-MATNR.
              CALL TRANSACTION 'MM03' AND SKIP FIRST SCREEN.
          ENDCASE.
      ENDCASE.
    ENDFORM.                    "USER_COMMAND
    Kindly let me know what am I missing in the above code. As this FORM USER-COMMAND is at all called during the user-command.
    Regds
    Priya

    the Code what u are given is WRONG , check this one.
    put like this , it will solve ur probs.
      check r_ucomm = '&IC1'.             "User Double Clicked on Some field
      check not rs_selfield-value is initial.
      case rs_selfield-fieldname.
        when 'AUFNR'.
          if rad4 ne 'X'.
            read table  itab_order index rs_selfield-tabindex.
          else.
            read table  itab_order2 index rs_selfield-tabindex.
            itab_order-aufnr = itab_order2-aufnr.
          endif.
          if sy-subrc eq 0.
            set parameter id 'ANR' field  itab_order-aufnr.
            set parameter id 'VGN' field '10'.
            call transaction 'CO14' and skip first screen.
          endif.                            " IF SY-SUBRC EQ 0
      endcase.
    Regards
    Prabhu
    Message was edited by: Prabhu Peram

  • User command in ALv

    how to handle user command in alv grid?
    if we want to select only one row, but we get a table from calling method
    get_selected_rows.
    is there any method or way of getting a single row which is selected?

    Hi,
    This method indeed returns the table but only with the selected rows. Therefore when you select only one row, it will contain only one entry. For this use second parameter of the method ET_ROW_NO as the first one is obsolete. It will contain indexes of the selected rows.
    Note!
    You must use one of the these selection modes (A, C, D) in this case. The default one is B, so you have to change it in layout structure.
    layout_structure-sel_mode = 'A'.  "i.e.
    See possible selection modes [here|http://help.sap.com/saphelp_erp2004/helpdata/en/ef/a2e9eff88311d2b48d006094192fe3/frameset.htm]
    Regards
    Marcin

  • User input in ALV Grid

    Hello All,
    Is it possible to have a user input in ALV grid. I know there can be editable columns/cells but suppose the application demands an input field to be placed in ALV Grid where the user will enter some value.
    Could someone please suggest if this can be done.
    Regards
    Indrajit

    Here's THE definitive way to do it.
    This little proggy demonstrates the following.
    1) Create a DYNAMIC FCAT for an internal table with USER defined fields (i.e non ddic) and colour some columns in the FCAT.
    2) Create a DYNAMIC TABLE.
    3) Define a subclass of CL_GUI_ALV_GRID so you can access some very useful protected methods and attributes - you can get original and changed table IN ROWS which is a lot easier sometimes than messing around with individual
    cells.
    4) Create extra buttons on the toolbar.
    5) Define EVENT handlers including data change so you can get control when the user enters data. YOU DON'T NEED PAI anymore with event handlers.
    6) Call methods in your subclass of CL_GUI_ALV_GRID (you can also call methods in CL_GUI_ALV_GRID by virtue of Inheritance) from methods in your event handler class.
    7) Display an editable Grid.
    This method will work for almost any conditions you need to use.
    I'm sure this covers all the bases -- please reply if any queries.
    Run the program, click on the EDIT button and enter your data. Press ENTER when done.
    All you need to do is copy this code and create one empty screen (SE51) with a custom container called CCONTAINER1  with the following logic in it.
    PROCESS BEFORE OUTPUT.
    MODULE STATUS_0100.
    PROCESS AFTER INPUT.
    MODULE USER_COMMAND_0100.
    (In the program you don't actually do anything in the PAI as the event handler takes care of this)
    Now here's the program
    PROGRAM zdynfieldcat.
    class zcltest definition  deferred.  "For field symbol reference.
    Simple test of dynamic ITAB with user defined (not ddic) fields
    Build dynamic fcat
    Table structure obtained via new RTTI functionality
    use ALV grid to display and edit.
    Create a blank screen 100 with a custom container called CCONTAINER1.
    Define field symbols as these can't be defined in classes
    field-symbols: <dyn_table> type standard table,
                   <g2> type ref to zcltest,
                   <g1> type ref to cl_gui_custom_container,
                   <actual_tab> type standard table,
                   <outtab> type table,
                   <fs1> type ANY,
                   <FS2> TYPE TABLE,
                   <fs3> type table,
                   <fs4> type table,
                   <fs5> type  table.
    class zcltest definition inheriting from cl_gui_alv_grid.
    define this as a subclass so we can access the protected attributes
    of the superclass cl_gui_alv_grid
      public section.
        types:  g4 type ref to cl_gui_custom_container.
        types:  g3  type ref to cl_alv_changed_data_protocol.
        data:   i_parent type g4,
                lr_rtti_struc TYPE REF TO cl_abap_structdescr, "RTTI
        zog like line of lr_rtti_struc->components. "RTTI
        types: struc like zog.
        types: struc1 type table of struc.
        methods:
           constructor
               importing i_parent type g4,
           disp_tab
               importing  p_er_data_changed type g3,
           create_dynamic_fcat
               importing zogt type struc1
               exporting it_fldcat type lvc_t_fcat.
    Protected section.
       data: stab type ref to data,
            wa_it_fldcat type lvc_s_fcat,
            c_index type sy-index.
    endclass.
    class zcltest implementation.
      METHOD constructor.
        CALL METHOD super->constructor
          EXPORTING
            i_appl_events = 'X'
            i_parent      = i_parent.
          endmethod.
      method disp_tab.
    mt_outtab is the data table held as a protected
    attribute in class cl_gui_alv_grid.
        assign me->mt_outtab->* TO <outtab>. "Original data
        assign p_er_data_changed->mp_mod_rows TO <FS1>.
        stab = p_er_data_changed->mp_mod_rows.
        assign p_er_data_changed->mt_inserted_rows to <fs3>.
        assign p_er_data_changed->mt_deleted_rows to <fs4>.
        assign p_er_data_changed->mt_mod_cells to <fs5>.
        assign stab->* TO <fs2>.
    do whatever you want with <outtab>
    contains data BEFORE changes each time.
    Note that NEW (Changed) table has been obtained
    already by  call to form
    check_data USING P_ER_DATA_CHANGED
    TYPE REF TO CL_ALV_CHANGED_DATA_PROTOCOL.
    Entered data is in table defined by <fs2>
    In this method you can compare original and changed data.
    Easier than messing around with individual cells.
    do what you want with data in <fs2> validate / update / merge etc
      endmethod.
      method create_dynamic_fcat.
        loop at zogt into zog.
          c_index = c_index + 1.
          clear wa_it_fldcat.
          wa_it_fldcat-fieldname = zog-name .
          wa_it_fldcat-datatype = zog-type_kind.
          wa_it_fldcat-inttype = zog-type_kind.
          wa_it_fldcat-intlen = zog-length.
          wa_it_fldcat-decimals = zog-decimals.
          wa_it_fldcat-coltext = zog-name.
          wa_it_fldcat-lowercase = 'X'.
          if c_index eq 2.
            wa_it_fldcat-emphasize = 'C411'.
          endif.
          if c_index eq 3.
            wa_it_fldcat-emphasize = 'C511'.
          endif.
          append wa_it_fldcat to it_fldcat .
        endloop.
      endmethod.                    "create_dynamic_fcat
    endclass.                    "zcltest IMPLEMENTATION
    class lcl_grid_event_receiver definition.
      public section.
    note that zcltest inherits all of events etc from
    class cl_gui_alv_grid so specify event handler for
    zcltest.
    methods:
        handle_data_changed
             for event data_changed of zcltest
             importing  er_data_changed,
        toolbar
             for event toolbar of zcltest
             importing e_object
             e_interactive,
        user_command
             for event user_command of zcltest
             importing e_ucomm.
    endclass.
    class lcl_grid_event_receiver implementation.
      method handle_data_changed.
    code whatever required after data entry.
    various possibilites here as you
    can get back Cell(s) changed
    columns or the entire updated table.
    Data validation is also possible here.
    Note here the field sybol <g2> contains our
    instance of  class zcltest so we can now
    call any methods / access
    attributes of that class from this method
    in our event handler class.
        call method <g2>->disp_tab
          EXPORTING
            p_er_data_changed = er_data_changed.
      endmethod.                    "handle_data_changed
      method toolbar.
        data : ls_toolbar type stb_button.
        clear ls_toolbar.
        move 0 to ls_toolbar-butn_type.
        move 'EDIT' to ls_toolbar-function.
        move space to ls_toolbar-disabled.
        move 'Edit' to ls_toolbar-text.
        move icon_change_text to ls_toolbar-icon.
        move 'Click2Edit' to ls_toolbar-quickinfo.
        append ls_toolbar to e_object->mt_toolbar.
        clear ls_toolbar.
        move 0 to ls_toolbar-butn_type.
        move 'UPDA' to ls_toolbar-function.
        move space to ls_toolbar-disabled.
        move 'Update' to ls_toolbar-text.
        move icon_system_save to ls_toolbar-icon.
        move 'Click2Update' to ls_toolbar-quickinfo.
        append ls_toolbar to e_object->mt_toolbar.
        clear ls_toolbar.
        move 0 to ls_toolbar-butn_type.
        move 'EXIT' to ls_toolbar-function.
        move space to ls_toolbar-disabled.
        move 'Exit' to ls_toolbar-text.
        move icon_system_end to ls_toolbar-icon.
        move 'Click2Exit' to ls_toolbar-quickinfo.
        append ls_toolbar to e_object->mt_toolbar.
      endmethod.                    "toolbar
      method user_command.
        case e_ucomm .
          when 'EDIT'. "From Tool bar
            perform set_input.
            perform init_grid.
          when 'UPDA'. "From Tool bar
            perform refresh_disp.
            perform update_table.
          when 'EXIT'. "From Tool bar
            leave program.
        endcase.
      endmethod.                    "user_command
    endclass.                    "lcl_grid_event_receiver IMPLEMENTATION
    program data
    include <icon>.
    define any old internal structure NOT in DDIC
    types: begin of s_elements,
    anyfield1(20) type c,
    anyfield2(20) type c,
    anyfield3(20) type c,
    anyfield4(20) type c,
    anyfield5(11) type n,
    end of s_elements.
    data: wa_element type s_elements,
    wa_data type s_elements.
    Note new RTTI functionality allows field detail
    retrieval at runtime for dynamic tables.
    data:
            grid1 type ref to zcltest,
            grid_handler type ref to lcl_grid_event_receiver,
            c_dec2 type s_elements-anyfield5,
            wa_it_fldcat type lvc_s_fcat,
            it_fldcat type lvc_t_fcat,
            lr_rtti_struc TYPE REF TO cl_abap_structdescr, "RTTI
            lt_comp TYPE cl_abap_structdescr=>component_table,"RTTI
            ls_comp LIKE LINE OF lt_comp, "RTTI
            zog like line of lr_rtti_struc->components,  "RTTI
            struct_grid_lset type lvc_s_layo,
            l_valid type c,
            new_table type ref to data.
            types: struc like zog.
    data:  zogt type table of struc,
            grid_container1 type ref to cl_gui_custom_container,
            g_event_receiver type ref to lcl_grid_event_receiver,
            ok_code like sy-ucomm,
            i4 type int4.
    start-of-selection.
      call screen 100.
    module status_0100 output.
      if grid_container1 is initial.
        create object grid_container1
        exporting
        container_name = 'CCONTAINER1'.
        assign grid_container1 to <g1>.
        create object grid1
         exporting i_parent = grid_container1.
    we need reference to this instance so we can use
    Methods etc of zcltest class and alv (superclass)
    in our event receiver class.
         assign grid1 to <g2>.
        create object grid_handler.
        set handler:
        grid_handler->user_command for grid1,
        grid_handler->toolbar for grid1,
        grid_handler->handle_data_changed for grid1.
    Get the Internal table structure
        lr_rtti_struc ?= cl_abap_structdescr=>describe_by_data( wa_data ).
    Build field catalog just use basic data here
    colour specific columns as well
        zogt[] = lr_rtti_struc->components.
           call method grid1->create_dynamic_fcat
          EXPORTING
            zogt      = zogt
          IMPORTING
            it_fldcat = it_fldcat.
    Create dynamic internal table and assign
    to field symbol.
    Use dynamic field catalog just built.
      call method cl_alv_table_create=>create_dynamic_table
        EXPORTING
          it_fieldcatalog = it_fldcat
        IMPORTING
          ep_table        = new_table.
      assign new_table->* to <dyn_table>.
        perform populate_dynamic_itab.
        perform init_grid.
        perform register_enter_event.
    set off ready for input initially
        i4 = 0.
        call method grid1->set_ready_for_input
          EXPORTING
            i_ready_for_input = i4.
      endif.
    endmodule.                    "status_0100 OUTPUT
    module user_command_0100 input.
    *PAI not needed in OO ALV anymore as User Commands
    are handled as events
    *in method user_command.
    we can also get control if any data was entered
    and the ENTER is pressed by
    raising an event.
    Control then returns to method handle_data_changed.
    endmodule.                    "user_command_0100 INPUT
    form populate_dynamic_itab.
    load up a line of the dynamic table
      c_dec2 = c_dec2 + 11.
      wa_element-anyfield1 = 'Tabbies'.
      wa_element-anyfield2 = 'ger.shepards'.
      wa_element-anyfield3 = 'White mice'.
      wa_element-anyfield4 = 'Any old text'.
      wa_element-anyfield5 = c_dec2.
      append wa_element to <dyn_table>.
    endform.                    "populate_dynamic_itab
    form exit_program.
      call method grid_container1->free.
      call method cl_gui_cfw=>flush.
      leave program.
    endform.                    "exit_program
    form refresh_disp.
      call method grid1->refresh_table_display.
    endform.                    "refresh_disp
    form update_table.
    The dynamic table here is the changed table
    read from the grid
    after user has changed it
    Data can be saved to DB or whatever.
      loop at <dyn_table> into wa_element.
    do what you want with the data here
      endloop.
    switch off edit mode again for next function
      i4 = 0.
      call method grid1->set_ready_for_input
        EXPORTING
          i_ready_for_input = i4.
    endform.                    "update_table
    form set_input.
      i4 = 1.
      call method grid1->set_ready_for_input
        EXPORTING
          i_ready_for_input = i4.
    endform.                    "set_input
    form switch_input.
      if i4 = 1.
        i4 = 0.
      else.
        i4 = 1.
      endif.
      call method grid1->set_ready_for_input
        EXPORTING
          i_ready_for_input = i4.
    endform.                    "switch_input
    form init_grid.
    Enabling the grid to edit mode,
      struct_grid_lset-edit = 'X'. "To enable editing in ALV
      struct_grid_lset-grid_title = 'Jimbos Test'.
       call method grid1->set_table_for_first_display
        EXPORTING
          is_layout       = struct_grid_lset
        CHANGING
          it_outtab       = <dyn_table>
          it_fieldcatalog = it_fldcat.
    endform.                    "init_grid
    form register_enter_event.
      call method grid1->register_edit_event
        EXPORTING
          i_event_id = cl_gui_alv_grid=>mc_evt_enter.
    Instantiate the event or it won't work.
      create object g_event_receiver.
      set handler g_event_receiver->handle_data_changed for grid1.
    endform.                    "register_enter_event
    Have fun with this
    Cheers
    jimbo

  • Problem with User Command in alv report

    Hi
    I have developed a ALV grid report with drill down capability to transaction code for user command. I am having a trouble with this.
    CASE ucomm.
        WHEN '&IC1'.
          CLEAR: wa_import.
          IF selfield-fieldname EQ 'ANLN1'.
            READ TABLE t_import INTO wa_import INDEX selfield-tabindex.
            SET PARAMETER ID 'BUK' FIELD wa_import-bukrs.
            SET PARAMETER ID 'ANl' FIELD wa_import-anln1.
            CALL TRANSACTION 'AW01N'.
          ENDIF.
    here my parameter ids are showing the values but when i call the transaction i am not getting the actual asset numbers.
    Can someone help me out this
    Thanks

    Hi,
    add the AND SKIP FIRST SCREEN...addition..
    CALL TRANSACTION 'AW01N' AND SKIP FIRST SCREEN.
    Thanks
    Naren

  • Using GETGUI command --in ALV grid, how to extract multiple DATA

    Using GETGUI command , I am able to get a single value form the ALV grid. Please explain me how I can read multiple data like rows and columns data from the ALV grid.
    Please be detailed as I already tried selecting the whole block of ALV grid, but I could not help myself.
    Regards
    Srinivas.

    Hi Srinivas,
    You will have to use the concept of Regular expressions for this. We will have to loop through each row/coloumn to do what u desire.
    The ID of an element on grid will be something like GRIDNAME-<ELEMENT NAME>[ROW NO] [COLUMN NO]
    we need to parameterize the row and also the el;ementname changes for each column along with the column number. Please let me know if this much detail is enough. If not i can show u a real time ecatt code snippet on how to play around with grids.
    Regards,
    Justin

  • ALV Grid: event for user return in ALV Grid Control

    Hi developers,
    i'm wanna do something after a user has pressed the return button in a alv grid control. For that i need probably a event. But i can not find a proper event in the documentation. Could one of you guys help me?
    Best regards christian

    Hi Christian
    ALV grid is an encapsulated object, so it seems there is no way, you ought to implement the data_changed event. So if you want to make bulk data input and after trigger the event by pressing the return key, you should make the ALV Grid get your changes after pressing the key but not after a cell change of a modified cell.
    To set this attribute:
    CALL METHOD gr_alvgrid->register_edit_event
         EXPORTING i_event_id = cl_gui_alv_grid=>mc_evt_enter .
    This way "data_changed" event will be triggered whenever you press the return key while editing.
    For some more information you can also refer to the tutorial <a href="https://www.sdn.sap.comhttp://www.sdn.sap.comhttp://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/documents/a1-8-4/an%20easy%20reference%20for%20alv%20grid%20control.pdf">"An Easy Reference for ALV Grid Control"</a>.
    Regards
    *--Serdar <a href="https://www.sdn.sap.com:443http://www.sdn.sap.comhttp://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.sdn.businesscard.sdnbusinesscard?u=qbk%2bsag%2bjiw%3d">[ BC ]</a>

  • At user command in alv's

    how to handle at user commads in alv's?

    Hi Praveen
    Interactive Reports
    As the name suggests, the user can Interact with the report. We can have a drill down into the report data. For example, Column one of the report displays the material numbers, and the user feels that he needs some more specific data about the vendor for that material, he can HIDE that data under those material numbers.
    And when the user clicks the material number, another report (actually sub report/secondary list) which displays the vendor details will be displayed.
    We can have a basic list (number starts from 0) and 20 secondary lists (1 to 21).
    Events associated with Interactive Reports are:
    AT LINE-SELECTION
    AT USER-COMMAND
    AT PF<key>
    TOP-OF-PAGE DURING LINE-SELECTION.
    HIDE statement holds the data to be displayed in the secondary list.
    sy-lisel : contains data of the selected line.
    sy-lsind : contains the level of report (from 0 to 21)
    <u><b>Interactive Report Events:</b></u>
    AT LINE-SELECTION : This Event triggers when we double click a line on the list, when the event is triggered a new sublist is going to be generated. Under this event what ever the statements that are been return will be displayed on newly generated sublist.
    AT PFn: For predefined function keys...
    <u><b>AT USER-COMMAND :</b></u> It provides user functions keys.
    TOP-OF-PAGE DURING LINE-SELECTION :top of page event for secondary list.
    <b>check this sample code</b>
    TYPE-POOLS: slis.                      " ALV Global Types
    DATA :
      gt_user LIKE uinfo OCCURS 0 WITH HEADER LINE. " User info in SM04
    START-OF-SELECTION.
      PERFORM f_read_data.
      PERFORM f_display_data.
    *       Form  F_LIRE_DATA
    FORM f_read_data.
      REFRESH gt_user.
    * Get User's info
      CALL FUNCTION 'THUSRINFO'
           TABLES
                usr_tabl = gt_user.
    * Wait in a task
      PERFORM f_call_rfc_wait.
    ENDFORM.                               " F_READ_DATA
    *      Form  F_DISPLAY_DATA
    FORM f_display_data.
      DEFINE m_sort.
        add 1 to ls_sort-spos.
        ls_sort-fieldname = &1.
        append ls_sort to lt_sort.
      END-OF-DEFINITION.
      DEFINE m_event_exit.
        clear ls_event_exit.
        ls_event_exit-ucomm = &1.
        ls_event_exit-after = 'X'.
        append ls_event_exit to lt_event_exit.
      END-OF-DEFINITION.
      DATA :
        ls_layout     TYPE slis_layout_alv,
        lt_sort       TYPE slis_t_sortinfo_alv,
        ls_sort       TYPE slis_sortinfo_alv,
        lt_event_exit TYPE slis_t_event_exit,
        ls_event_exit TYPE slis_event_exit.
    * Build Sort Table
      m_sort 'ZEIT'.
    * Build Event Exit Table
      m_event_exit '&NTE'.                 " Refresh
      ls_layout-zebra = 'X'.
      ls_layout-colwidth_optimize = 'X'.
      CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
           EXPORTING
                i_callback_program      = sy-cprog
                i_callback_user_command = 'USER_COMMAND'
                is_layout               = ls_layout
                i_structure_name        = 'UINFO'
                it_sort                 = lt_sort
                it_event_exit           = lt_event_exit
           TABLES
                t_outtab                = gt_user.
    ENDFORM.                               " F_DISPLAY_DATA
    *       FORM USER_COMMAND                                             *
    FORM user_command USING i_ucomm     TYPE syucomm
                            is_selfield TYPE slis_selfield.     "#EC CALLED
      CASE i_ucomm.
        WHEN '&NTE'.
          PERFORM f_read_data.
          is_selfield-refresh = 'X'.
          SET USER-COMMAND '&OPT'.         " Optimize columns width
      ENDCASE.
    ENDFORM.                               " USER_COMMAND
    *      Form  F_CALL_RFC_WAIT
    FORM f_call_rfc_wait.
      DATA lv_mssg(80).                                         "#EC NEEDED
    * Wait in a task
      CALL FUNCTION 'RFC_PING_AND_WAIT' STARTING NEW TASK '001'
        PERFORMING f_task_end ON END OF TASK
        EXPORTING
          seconds               = 5        " Refresh time
          busy_waiting          = space
        EXCEPTIONS
          RESOURCE_FAILURE      = 1
          communication_failure = 2  MESSAGE lv_mssg
          system_failure        = 3  MESSAGE lv_mssg
          OTHERS                = 4.
    ENDFORM.                               " F_CALL_RFC_WAIT
    *      Form  F_TASK_END
    FORM f_task_end USING u_taskname.
      DATA lv_mssg(80).                                         "#EC NEEDED
    * Receiving task results
      RECEIVE RESULTS FROM FUNCTION 'RFC_PING_AND_WAIT'
        EXCEPTIONS
          RESOURCE_FAILURE      = 1
          communication_failure = 2  MESSAGE lv_mssg
          system_failure        = 3  MESSAGE lv_mssg
          OTHERS                = 4.
      CHECK sy-subrc EQ 0.
      SET USER-COMMAND '&NTE'.             " Refresh
    ENDFORM.                               " F_TASK_END
    *************** END OF PROGRAM Z_ALV_AUTO_REFRESH *********************
    check this link too
    https://www.sdn.sap.com/irj/sdn/wiki?path=/display/snippets/abap-AddUsercommandfunctionalitytoALVgridreport&
    Reward all helpfull answers
    Regards
    Pavan

  • At line-selection /at user-command in alv

    hai ,
             i used layout-listappend to output 3 alv's in one page .but
    after using layout-listappend i_usercommand in reuse_alv_.. is not working .so i tried to use at line selection . please guide me to solve this problem how to use at line-selection in this prob or is there any other suitable way.

    hi,
    try this code it will help you
    *& Report  ZP_ALV8
    REPORT  zp_alv8.
    TABLES: kna1, mara, vbak, mard.
    TYPE-POOLS: slis.
    **TYPE DECLERATION
    TYPES: BEGIN OF ty_kna1,
             kunnr LIKE kna1-kunnr,
             land1 LIKE kna1-land1,
             name1 LIKE kna1-name1,
             ort01 LIKE kna1-ort01,
           END OF ty_kna1.
    TYPES: BEGIN OF ty_mara,
             matnr LIKE mara-matnr,
             ersda LIKE mara-ersda,
             ernam LIKE mara-ernam,
           END OF ty_mara.
    TYPES: BEGIN OF ty_vbak,
             vbeln LIKE vbak-vbeln,
             erdat LIKE vbak-erdat,
             ernam LIKE vbak-ernam,
           END OF ty_vbak.
    TYPES: BEGIN OF ty_mard,
             matnr LIKE mard-matnr,
             werks LIKE mard-werks,
             lgort LIKE mard-lgort,
          END OF ty_mard.
    **DATA DECLERATION
    DATA: it_kna1 TYPE STANDARD TABLE OF ty_kna1,
          wa_kna1 TYPE ty_kna1.
    DATA: it_mara TYPE STANDARD TABLE OF ty_mara,
          wa_mara TYPE ty_mara.
    DATA: it_vbak TYPE STANDARD TABLE OF ty_vbak,
          wa_vbak TYPE ty_vbak.
    DATA: it_mard TYPE STANDARD TABLE OF ty_mard,
          wa_mard TYPE ty_mard.
    DATA: it_fieldcat_kna1 TYPE slis_t_fieldcat_alv,
          wa_fieldcat_kna1 TYPE slis_fieldcat_alv,
          it_fieldcat_mara TYPE slis_t_fieldcat_alv,
          wa_fieldcat_mara TYPE slis_fieldcat_alv,
          it_fieldcat_vbak TYPE slis_t_fieldcat_alv,
          wa_fieldcat_vbak TYPE slis_fieldcat_alv,
          it_fieldcat_mard TYPE slis_t_fieldcat_alv,
          wa_fieldcat_mard TYPE slis_fieldcat_alv.
    DATA: it_event_kna1 TYPE slis_t_event,
          wa_event_kna1 TYPE slis_alv_event,
          it_event_mara TYPE slis_t_event,
          wa_event_mara TYPE slis_alv_event,
          it_event_vbak TYPE slis_t_event,
          wa_event_vbak TYPE slis_alv_event,
          it_event_mard TYPE slis_t_event,
          wa_event_mard TYPE slis_alv_event.
    DATA: wa_layout TYPE slis_layout_alv,
          it_listheader TYPE slis_t_listheader,
          wa_listheader TYPE slis_listheader.
    selection-screen begin of block b1 with frame title text-001.
    select-options: s_kunnr for kna1-kunnr default '1000' to '1050'.
    selection-screen end of block b1.
    selection-screen begin of block b2 with frame title text-002.
    select-options: s_matnr for mara-matnr default '1' to '100'.
    selection-screen end of block b2.
    **INITIALIZATION
    INITIALIZATION.
      PERFORM layout.
      PERFORM fieldcat_kna1.
      PERFORM fieldcat_mara.
      PERFORM event_kna1.
      PERFORM event_mara.
      PERFORM eventpopulate_kna1.
      PERFORM eventpopulate_mara.
    **START OF SELECTION AND FIRST LIST DISPLAY
    START-OF-SELECTION.
      SELECT kunnr land1 name1 ort01
             FROM kna1
             INTO TABLE it_kna1
             where kunnr in s_kunnr.
           UP TO 10 ROWS.
      SELECT matnr ersda ernam
             FROM mara
             INTO TABLE it_mara
             where matnr in s_matnr.
            UP TO 20 ROWS.
      PERFORM display.
    **FORM LAYOUT
    *&      Form  layout
          text
    -->  p1        text
    <--  p2        text
    FORM layout .
      wa_layout-zebra ='X'.
      wa_layout-get_selinfos      = 'X'.
      wa_layout-key_hotspot = 'X'.
    ENDFORM.                    " layout
    *FIELD CATALOUGE*******************************
    *&      Form  fieldcat_kna1
          text
    -->  p1        text
    <--  p2        text
    FORM fieldcat_kna1 .
      REFRESH it_fieldcat_kna1.
      CLEAR wa_fieldcat_kna1.
      wa_fieldcat_kna1-fieldname = 'KUNNR'.
      wa_fieldcat_kna1-seltext_l = 'CUSTOMER NUMBER'.
      wa_fieldcat_kna1-datatype = 'CHAR'.
      wa_fieldcat_kna1-outputlen = 30.
      wa_fieldcat_kna1-tabname = 'IT_KNA1'.
      wa_fieldcat_kna1-key = 'X'.
      wa_fieldcat_kna1-hotspot = 'X'.
      wa_fieldcat_kna1-col_pos = 1.
      wa_fieldcat_kna1-emphasize = 'C21'.
      APPEND wa_fieldcat_kna1 TO it_fieldcat_kna1.
      CLEAR wa_fieldcat_kna1.
      wa_fieldcat_kna1-fieldname = 'LAND1'.
      wa_fieldcat_kna1-seltext_l = 'COUNTRY CODE'.
      wa_fieldcat_kna1-datatype = 'CHAR'.
      wa_fieldcat_kna1-outputlen = 30.
      wa_fieldcat_kna1-tabname = 'IT_KNA1'.
      wa_fieldcat_kna1-hotspot = 'X'.
      wa_fieldcat_kna1-col_pos = 2.
      wa_fieldcat_kna1-emphasize = 'C31'.
      APPEND wa_fieldcat_kna1 TO it_fieldcat_kna1.
      CLEAR wa_fieldcat_kna1.
      wa_fieldcat_kna1-fieldname = 'NAME1'.
      wa_fieldcat_kna1-seltext_l = 'CUSTOMER NAME'.
      wa_fieldcat_kna1-datatype = 'CHAR'.
      wa_fieldcat_kna1-outputlen = 30.
      wa_fieldcat_kna1-tabname = 'IT_KNA1'.
      wa_fieldcat_kna1-hotspot = 'X'.
      wa_fieldcat_kna1-col_pos = 3.
      wa_fieldcat_kna1-emphasize = 'C71'.
      APPEND wa_fieldcat_kna1 TO it_fieldcat_kna1.
      CLEAR wa_fieldcat_kna1.
      wa_fieldcat_kna1-fieldname = 'ORT01'.
      wa_fieldcat_kna1-seltext_l = 'COUNTRY '.
      wa_fieldcat_kna1-datatype = 'CHAR'.
      wa_fieldcat_kna1-outputlen = 30.
      wa_fieldcat_kna1-tabname = 'IT_KNA1'.
      wa_fieldcat_kna1-hotspot = 'X'.
      wa_fieldcat_kna1-col_pos = 4.
      wa_fieldcat_kna1-emphasize = 'C51'.
      APPEND wa_fieldcat_kna1 TO it_fieldcat_kna1.
      CLEAR wa_fieldcat_kna1.
    ENDFORM.                    " fieldcat_kna1
    *&      Form  fieldcat_kna2
          text
    FORM fieldcat_mara  .
      wa_fieldcat_mara-fieldname = 'MATNR'.
      wa_fieldcat_mara-seltext_l = 'MATERIAL NUMBER'.
      wa_fieldcat_mara-datatype = 'CHAR'.
      wa_fieldcat_mara-outputlen = 30.
      wa_fieldcat_mara-tabname = 'IT_MARA'.
      wa_fieldcat_mara-key = 'X'.
      wa_fieldcat_mara-hotspot = 'X'.
      wa_fieldcat_mara-col_pos = 1.
      wa_fieldcat_mara-emphasize = 'C21'.
      APPEND wa_fieldcat_mara TO it_fieldcat_mara.
      CLEAR wa_fieldcat_mara.
      wa_fieldcat_mara-fieldname = 'ERSDA'.
      wa_fieldcat_mara-seltext_l = 'CREATED ON'.
      wa_fieldcat_mara-datatype = 'CHAR'.
      wa_fieldcat_mara-outputlen = 30.
      wa_fieldcat_mara-tabname = 'IT_MARA'.
      wa_fieldcat_mara-hotspot = 'X'.
      wa_fieldcat_mara-col_pos = 2.
      wa_fieldcat_mara-emphasize = 'C41'.
      APPEND wa_fieldcat_mara TO it_fieldcat_mara.
      CLEAR wa_fieldcat_mara.
      wa_fieldcat_mara-fieldname = 'ERNAM'.
      wa_fieldcat_mara-seltext_l = 'CREATED BY'.
      wa_fieldcat_mara-datatype = 'CHAR'.
      wa_fieldcat_mara-outputlen = 30.
      wa_fieldcat_mara-tabname = 'IT_MARA'.
      wa_fieldcat_mara-hotspot = 'X'.
      wa_fieldcat_mara-col_pos = 3.
      wa_fieldcat_mara-emphasize = 'C61'.
      APPEND wa_fieldcat_mara TO it_fieldcat_mara.
      CLEAR wa_fieldcat_mara.
    ENDFORM.                    "fieldcat_kna2
    *&      Form  FIELDCAT_VBAK
          text
    FORM fieldcat_vbak.
      wa_fieldcat_vbak-fieldname = 'VBELN'.
      wa_fieldcat_vbak-seltext_l = 'SALES ORDER'.
      wa_fieldcat_vbak-datatype = 'CHAR'.
      wa_fieldcat_vbak-outputlen = 30.
      wa_fieldcat_vbak-tabname = 'IT_VBAK'.
      wa_fieldcat_vbak-hotspot = 'X'.
      wa_fieldcat_vbak-col_pos = 3.
      wa_fieldcat_vbak-emphasize = 'C31'.
      APPEND wa_fieldcat_vbak TO it_fieldcat_vbak.
      CLEAR wa_fieldcat_vbak.
      wa_fieldcat_vbak-fieldname = 'ERDAT'.
      wa_fieldcat_vbak-seltext_l = 'CREATED ON'.
      wa_fieldcat_vbak-datatype = 'DATS'.
      wa_fieldcat_vbak-outputlen = 30.
      wa_fieldcat_vbak-tabname = 'IT_VBAK'.
      wa_fieldcat_vbak-hotspot = 'X'.
      wa_fieldcat_vbak-col_pos = 3.
      wa_fieldcat_vbak-emphasize = 'C41'.
      APPEND wa_fieldcat_vbak TO it_fieldcat_vbak.
      CLEAR wa_fieldcat_vbak.
      wa_fieldcat_vbak-fieldname = 'ERNAM'.
      wa_fieldcat_vbak-seltext_l = 'CREATED BY'.
      wa_fieldcat_vbak-datatype = 'CHAR'.
      wa_fieldcat_vbak-outputlen = 30.
      wa_fieldcat_vbak-tabname = 'IT_VBAK'.
      wa_fieldcat_vbak-hotspot = 'X'.
      wa_fieldcat_vbak-col_pos = 3.
      wa_fieldcat_vbak-emphasize = 'C51'.
      APPEND wa_fieldcat_vbak TO it_fieldcat_vbak.
      CLEAR wa_fieldcat_vbak.
    ENDFORM.                    "FIELDCAT_VBAK
    *&      Form  fieldcat_mard
          text
    FORM fieldcat_mard.
      wa_fieldcat_mard-fieldname = 'MATNR'.
      wa_fieldcat_mard-seltext_l = 'MATERIAL NUMBER'.
      wa_fieldcat_mard-datatype = 'CHAR'.
      wa_fieldcat_mard-outputlen = 30.
      wa_fieldcat_mard-tabname = 'IT_MARD'.
      wa_fieldcat_mard-hotspot = 'X'.
      wa_fieldcat_mard-col_pos = 1.
      wa_fieldcat_mard-emphasize = 'C31'.
      APPEND wa_fieldcat_mard TO it_fieldcat_mard.
      CLEAR wa_fieldcat_mard.
      wa_fieldcat_mard-fieldname = 'WERKS'.
      wa_fieldcat_mard-seltext_l = 'PLANT'.
      wa_fieldcat_mard-datatype = 'CHAR'.
      wa_fieldcat_mard-outputlen = 30.
      wa_fieldcat_mard-tabname = 'IT_MARD'.
      wa_fieldcat_mard-hotspot = 'X'.
      wa_fieldcat_mard-col_pos = 2.
      wa_fieldcat_mard-emphasize = 'C61'.
      APPEND wa_fieldcat_mard TO it_fieldcat_mard.
      CLEAR wa_fieldcat_mard.
      wa_fieldcat_mard-fieldname = 'LGORT'.
      wa_fieldcat_mard-seltext_l = 'STORAGE LOCATION'.
      wa_fieldcat_mard-datatype = 'CHAR'.
      wa_fieldcat_mard-outputlen = 30.
      wa_fieldcat_mard-tabname = 'IT_MARD'.
      wa_fieldcat_mard-hotspot = 'X'.
      wa_fieldcat_mard-col_pos = 3.
      wa_fieldcat_mard-emphasize = 'C81'.
      APPEND wa_fieldcat_mard TO it_fieldcat_mard.
      CLEAR wa_fieldcat_mard.
    ENDFORM  .                    "fieldcat_mard
    **FORM DISPLAY
    *&      Form  Display
          text
    -->  p1        text
    <--  p2        text
    FORM display .
      CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_INIT'
        EXPORTING
          i_callback_program = sy-repid
      I_CALLBACK_PF_STATUS_SET       = ' '
       I_CALLBACK_USER_COMMAND        = 'USER_COMMAND'.
      IT_EXCLUDING                   =
      CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_APPEND'
        EXPORTING
          is_layout                        = wa_layout
          it_fieldcat                      = it_fieldcat_kna1
          i_tabname                        = 'IT_KNA1'
         it_events                         = it_event_kna1
      IT_SORT                          =
      I_TEXT                           = ' '
        TABLES
          t_outtab                         = it_kna1
       EXCEPTIONS
         program_error                    = 1
         maximum_of_appends_reached       = 2
         OTHERS                           = 3
      IF sy-subrc <> 0.
        MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
                WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
      ENDIF.
      CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_APPEND'
        EXPORTING
          is_layout                        = wa_layout
          it_fieldcat                      = it_fieldcat_mara
          i_tabname                        = 'IT_MARA'
          it_events                        = it_event_mara
      IT_SORT                          =
      I_TEXT                           = ' '
        TABLES
          t_outtab                         = it_mara
       EXCEPTIONS
         program_error                    = 1
         maximum_of_appends_reached       = 2
         OTHERS                           = 3
      IF sy-subrc <> 0.
        MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
                WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
      ENDIF.
      CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_DISPLAY'
        EXCEPTIONS
          program_error = 1
          OTHERS        = 2.
      IF sy-subrc <> 0.
        MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
                WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
      ENDIF.
    ENDFORM.                    " Display
    **EVENTS FOR KNA1 AND MARA
    *&      Form  EVENT_KNA1
          text
    -->  p1        text
    <--  p2        text
    FORM event_kna1 .
      CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
        EXPORTING
          i_list_type     = 0
        IMPORTING
          et_events       = it_event_kna1
        EXCEPTIONS
          list_type_wrong = 1
          OTHERS          = 2.
      IF sy-subrc <> 0.
        MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
                WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
      ENDIF.
    ENDFORM.                    " EVENT_KNA1
    *&      Form  EVENT_MARA
          text
    -->  p1        text
    <--  p2        text
    FORM event_mara .
      CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
        EXPORTING
          i_list_type     = 0
        IMPORTING
          et_events       = it_event_mara
        EXCEPTIONS
          list_type_wrong = 1
          OTHERS          = 2.
      IF sy-subrc <> 0.
        MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
                WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
      ENDIF.
    ENDFORM.                    " EVENT_MARA
    **POPULATING EVENTS
    *&      Form  eventpopulate_kna1
          text
    -->  p1        text
    <--  p2        text
    FORM eventpopulate_kna1 .
      READ TABLE it_event_kna1 INTO wa_event_kna1 WITH KEY name = 'TOP_OF_PAGE'.
      IF sy-subrc = 0.
        wa_event_kna1-form = 'TOP_OF_PAGE_KNA1'.
        MODIFY it_event_kna1 FROM wa_event_kna1 TRANSPORTING form WHERE name = wa_event_kna1-name.
      ENDIF.
    READ TABLE it_event_kna1 INTO wa_event_kna1 WITH KEY name = 'USER_COMMAND'.
    IF sy-subrc = 0.
       wa_event_kna1-form = 'USER_COMMAND_KNA1'.
       MODIFY it_event_kna1 FROM wa_event_kna1 TRANSPORTING form WHERE name = wa_event_kna1-name.
    ENDIF.
    ENDFORM.                    " eventpopulate_kna1
    *&      Form  eventpopulate_mara
          text
    -->  p1        text
    <--  p2        text
    FORM eventpopulate_mara .
      READ TABLE it_event_mara INTO wa_event_mara WITH KEY name = 'TOP_OF_PAGE'.
      IF sy-subrc = 0.
        wa_event_mara-form = 'TOP_OF_PAGE_MARA'.
        MODIFY it_event_mara FROM wa_event_mara TRANSPORTING form WHERE name = wa_event_mara-name.
      ENDIF.
    READ TABLE it_event_mara INTO wa_event_mara WITH KEY name = 'USER_COMMAND'.
    IF sy-subrc = 0.
       wa_event_mara-form = 'USER_COMMAND_MARA'.
       MODIFY it_event_mara FROM wa_event_mara TRANSPORTING form WHERE name = wa_event_mara-name.
    ENDIF.
    ENDFORM.                    " eventpopulate_mara
    **TOP OF PAGE
    *&      Form  TOP_OF_PAGE_KNA1
          text
    FORM top_of_page_kna1.
    wa_listheader-typ = 'H'.
    wa_listheader-info = 'CUSTOMER DETAILS' .
    APPEND wa_listheader TO it_listheader.
    CLEAR wa_listheader.
      WRITE:/ 'CUSTOMER DETAILS'.
    ENDFORM.                    "TOP_OF_PAGE_KNA1
    *&      Form  TOP_OF_PAGE_MARA
          text
    FORM top_of_page_mara.
    wa_listheader-typ = 'H'.
    wa_listheader-info = 'MATERIAL DETAILS' .
    APPEND wa_listheader TO it_listheader.
    CLEAR wa_listheader.
      WRITE:/ 'MATERIAL DETAILS' .
    ENDFORM.                    "TOP_OF_PAGE_KNA1
    **CODE FOR SECOND LIST DISPLAY FOR VBAK
    *&      Form  USER_COMMAND
          text
         -->UCOMM      text
         -->R_SELFIELD text
    FORM user_command
         USING ucomm LIKE sy-ucomm
               r_selfield TYPE slis_selfield.
    CASE UCOMM.
      when '&IC1'.
        CASE R_SELFIELD-TABNAME.
          WHEN 'IT_KNA1'.
            DATA: CUST(10) TYPE n.
            CUST = r_selfield-value.
             SELECT vbeln erdat ernam
                    FROM vbak
                    INTO TABLE it_vbak
                    WHERE kunnr = cust.
             PERFORM fieldcat_vbak.
             PERFORM display_vbak.
          WHEN 'IT_MARA'.
            DATA: MAT(18) TYPE N.
            MAT = R_selfield-value.
              SELECT matnr werks lgort
                   FROM mard
                   INTO TABLE it_mard
                   WHERE matnr = mat.
            PERFORM fieldcat_mard.
            PERFORM display_mard.
         ENDCASE.
      ENDCASE.
    ENDFORM.                    "USER_COMMAND
    **&      Form  USER_COMMAND_MARA
          text
         -->UCOMM      text
         -->S_SELFIELD text
    *FORM user_command_mara
        USING ucomm LIKE sy-ucomm
              s_selfield TYPE slis_selfield.
    SELECT matnr werks lgort
            FROM mard
            INTO TABLE it_mard
            WHERE matnr = s_selfield-value.
    PERFORM fieldcat_mard.
    PERFORM display_mard.
    *ENDFORM.                    "USER_COMMAND_MARA
    *&      Form  DISPLAY_VBAK
          text
    -->  p1        text
    <--  p2        text
    FORM display_vbak .
    CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
      I_INTERFACE_CHECK                 = ' '
      I_BYPASSING_BUFFER                = ' '
      I_BUFFER_ACTIVE                   = ' '
       I_CALLBACK_PROGRAM                = sy-repid
      I_CALLBACK_PF_STATUS_SET          = ' '
      I_CALLBACK_USER_COMMAND           = ' '
      I_CALLBACK_TOP_OF_PAGE            = ' '
      I_CALLBACK_HTML_TOP_OF_PAGE       = ' '
      I_CALLBACK_HTML_END_OF_LIST       = ' '
      I_STRUCTURE_NAME                  =
      I_BACKGROUND_ID                   = ' '
      I_GRID_TITLE                      =
      I_GRID_SETTINGS                   =
       IS_LAYOUT                         = wa_layout
       IT_FIELDCAT                       = it_fieldcat_vbak
      IT_EXCLUDING                      =
      IT_SPECIAL_GROUPS                 =
      IT_SORT                           =
      IT_FILTER                         =
      IS_SEL_HIDE                       =
      I_DEFAULT                         = 'X'
      I_SAVE                            = ' '
      IS_VARIANT                        =
      IT_EVENTS                         =
      IT_EVENT_EXIT                     =
      IS_PRINT                          =
      IS_REPREP_ID                      =
      I_SCREEN_START_COLUMN             = 0
      I_SCREEN_START_LINE               = 0
      I_SCREEN_END_COLUMN               = 0
      I_SCREEN_END_LINE                 = 0
      I_HTML_HEIGHT_TOP                 = 0
      I_HTML_HEIGHT_END                 = 0
      IT_ALV_GRAPHICS                   =
      IT_HYPERLINK                      =
      IT_ADD_FIELDCAT                   =
      IT_EXCEPT_QINFO                   =
      IR_SALV_FULLSCREEN_ADAPTER        =
    IMPORTING
      E_EXIT_CAUSED_BY_CALLER           =
      ES_EXIT_CAUSED_BY_USER            =
      TABLES
        t_outtab                          = it_vbak
    EXCEPTIONS
       PROGRAM_ERROR                     = 1
       OTHERS                            = 2
    IF sy-subrc <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
             WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
    ENDFORM.                    " DISPLAY_VBAK
    *&      Form  display_mard
          text
    FORM display_mard .
      CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
       EXPORTING
      I_INTERFACE_CHECK              = ' '
      I_BYPASSING_BUFFER             =
      I_BUFFER_ACTIVE                = ' '
         i_callback_program             = sy-repid
      I_CALLBACK_PF_STATUS_SET       = ' '
        i_callback_user_command        = 'USER_COMMAND_MARD'
      I_STRUCTURE_NAME               =
         is_layout                      = wa_layout
         it_fieldcat                    = it_fieldcat_mard
      IT_EXCLUDING                   =
      IT_SPECIAL_GROUPS              =
      IT_SORT                        =
      IT_FILTER                      =
      IS_SEL_HIDE                    =
      I_DEFAULT                      = 'X'
      I_SAVE                         = ' '
      IS_VARIANT                     =
        it_events                      = it_event_mard
      IT_EVENT_EXIT                  =
      IS_PRINT                       =
      IS_REPREP_ID                   =
      I_SCREEN_START_COLUMN          = 0
      I_SCREEN_START_LINE            = 0
      I_SCREEN_END_COLUMN            = 0
      I_SCREEN_END_LINE              = 0
      IR_SALV_LIST_ADAPTER           =
      IT_EXCEPT_QINFO                =
      I_SUPPRESS_EMPTY_DATA          = ABAP_FALSE
    IMPORTING
      E_EXIT_CAUSED_BY_CALLER        =
      ES_EXIT_CAUSED_BY_USER         =
        TABLES
          t_outtab                       = it_mard
    EXCEPTIONS
      PROGRAM_ERROR                  = 1
      OTHERS                         = 2
      IF sy-subrc <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.
    ENDFORM.                    "display_mard
    regards
    prasanth

  • USER-Command  at ALV report.

    Hi Guys,
    I've created one ALV report displaying SALES ORDER created.My requirement is if I click on SALES Document no it should take me into VA03(sales orde display) transaction so that I can see all the data related for that document no. I have used BAPI .

    Hi guys,
    I have written this code but still it is not taking me into VAO3 Transaction. What else I should write?
      CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
           EXPORTING
                I_BUFFER_ACTIVE          = 'X'
               I_BACKGROUND_ID          = 'ALV_BACKGROUND'
                I_CALLBACK_PROGRAM       = L_REPID
               I_CALLBACK_PF_STATUS_SET = L_STATUS
                I_CALLBACK_USER_COMMAND  = L_USER_COMMAND
              I_STRUCTURE_NAME         = 'VBUK'
               IS_LAYOUT                = LF_LAYOUT
                IT_FIELDCAT              = LF_FIELDCAT[]
              IT_EXCLUDING             =
               IT_SPECIAL_GROUPS        = LF_SP_GROUP
              I_DEFAULT                = 'X'
               I_SAVE                   = L_SAVE
               IS_VARIANT               = L_VARIANT
               IT_EVENTS                = LF_EVENTS[]
              I_SCREEN_START_COLUMN    = 0
              I_SCREEN_START_LINE      = 0
              I_SCREEN_END_COLUMN      = 0
              I_SCREEN_END_LINE        = 0
        IMPORTING
              E_EXIT_CAUSED_BY_CALLER  =
              ES_EXIT_CAUSED_BY_USER   =
           TABLES
                T_OUTTAB                 = IT_HEADER .
    FORM L_USER_COMMAND USING vl_ucomm LIKE sy-ucomm     
                      rs_selfield TYPE slis_selfield.
      CASE vl_ucomm.
        WHEN '&IC1'.
          IF rs_selfield-fieldname = 'DOC_NO'
          OR rs_selfield-fieldname = 'SO_KUNNR' .
          SET PARAMETER ID 'AUN' FIELD rs_selfield-VALUE.
            CALL TRANSACTION 'VA03' AND SKIP FIRST SCREEN.
          ENDIF.
        WHEN OTHERS.
       EXIT.
      ENDCASE.
    ENDFORM.

  • Pf status and user-command

    hi
    can any one explain me about pf-status and user-command?  what is the difference between this two and how to display icons in it.
    max reward points for good answer
    thanks
    alka

    Hi alka ritu  ,
    Check the following websites for good documentation o n pf status and user-command
    http://help.sap.com/saphelp_nw04/helpdata/en/9f/dba34635c111d1829f0000e829fbfe/content.htm
    http://help.sap.com/saphelp_nw04/helpdata/en/9f/dba99935c111d1829f0000e829fbfe/content.htm
    1. How to set pf-status
    set pf-status ‘ZZBILSTA’.
    2. How to set pf-status excluding/including single menu items
    You can exclude menus by using exclude :
    set pf-status ‘ZZBILSTA’ excluding ‘PST’.
    Note: Can also be used with include instead of exclude
    3. How to set pf-status excluding/including several menu items
    You have to use an internal table to store the status you wan’t to ex- or include:
    DATA:BEGIN OF I_PF_STATUS_TAB OCCURS 10,
    FCODE,
    END OF I_PF_STATUS_TAB.
    FORM SET_PF_STATUS_POSTER.
    REFRESH I_PF_STATUS_TAB. MOVE ‘PST’ TO I_PF_STATUS_TAB. APPEND I_PF_STATUS_TAB. MOVE ‘ART’ TO I_PF_STATUS_TAB. APPEND I_PF_STATUS_TAB. SET PF-STATUS ‘ZZBILSTA’ EXCLUDING I_PF_STATUS_TAB.
    ENDFORM.
    4. Setting PF status to the (SAP) system default
    set pf-status ‘BASIC’.
    5. How to check for pf-status
    AT USER-COMMAND.
    CASE SY-UCOMM. WHEN ‘ART’. PERFORM STYR_ARTSKONTI. WHEN ‘PST’. PERFORM STYR_POSTER. WHEN ‘BIL’. PERFORM VIS_BILAG. ENDCASE.
    6. Use of SY-PFKEY
    You can use the system variable sy-pfkey to retrieve the name of the current pf status
    USER-COMMAND:
    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.
    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.
    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'.
    http://maxdb.sap.com/currentdoc/94/90ee41c334c717e10000000a155106/content.htm
    cheers!
    gyanaraj
    ****Pls reward points if u find this helpful

  • Not diaplsy buttons on alv grid display

    Hi,
    In the below code,i dont understand where i made a mistake,i used a user command on alv it's working but not display the buttons on a output.Please check the below code and solve it.
    REPORT  Y_ALV_VERSION.
    TYPE-POOLS : SLIS.
    DATA : BEGIN OF ITAB OCCURS 0,
           MATNR LIKE MARC-MATNR,       "Plant Data for Material-Material Number
           WERKS LIKE MARC-WERKS,       "Plant Data for Material-Plant
           EKGRP LIKE MARC-EKGRP,       "Plant Data for Material-Purchasing Group
           END OF ITAB.
    DATA : BEGIN OF ITAB1 OCCURS 0,
           MATNR LIKE MARD-MATNR,       "Storage Location Data for Material-Material Number
           WERKS LIKE MARD-WERKS,       "Storage Location Data for Material-Plant
           LGORT LIKE MARD-LGORT,       "Storage Location Data for Material-Storage Location
           END OF ITAB1.
    DATA : REPID LIKE SY-REPID.
    DATA : V_LINE TYPE SY-TABIX.
    DATA : X_FIELDCAT TYPE SLIS_FIELDCAT_ALV.
    DATA : I_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV.
    DATA : I_FIELDCAT1 TYPE SLIS_T_FIELDCAT_ALV.
    DATA : X_ALV_EVENTS TYPE SLIS_ALV_EVENT.
    DATA : T_ALV_EVENTS TYPE SLIS_T_EVENT.
    DATA : X_ALV_LAYOUT TYPE SLIS_LAYOUT_ALV.
    *********************START-OF-SELECTION***************
    START-OF-SELECTION.
      PERFORM SUB_SELECT_RECORD.
      PERFORM SUB_PREPARE_FIELDCATALOG.
      CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
       EXPORTING
         I_LIST_TYPE           = 0
       IMPORTING
         ET_EVENTS             = T_ALV_EVENTS
    EXCEPTIONS
      LIST_TYPE_WRONG       = 1
      OTHERS                = 2
      IF SY-SUBRC <> 0.
        MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
                WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.
      READ TABLE T_ALV_EVENTS INTO X_ALV_EVENTS WITH KEY NAME = 'USERCOMMAND'.
      IF SY-SUBRC = 0.
        X_ALV_EVENTS-FORM = 'USER_ACTION'.
        MODIFY T_ALV_EVENTS FROM X_ALV_EVENTS INDEX SY-TABIX.
      ENDIF.
      READ TABLE T_ALV_EVENTS INTO X_ALV_EVENTS WITH KEY NAME = 'PF_STATUS_SET'.
      IF SY-SUBRC = 0.
        X_ALV_EVENTS-FORM = 'PF_STATUS'.
        MODIFY T_ALV_EVENTS FROM X_ALV_EVENTS INDEX SY-TABIX.
      ENDIF.
      PERFORM SUB_DETERMINE_ALV_LAYOUT.
      CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
       EXPORTING
      I_INTERFACE_CHECK                 = ' '
      I_BYPASSING_BUFFER                = ' '
      I_BUFFER_ACTIVE                   = ' '
       I_CALLBACK_PROGRAM                = REPID
       I_CALLBACK_PF_STATUS_SET          = 'PF_STATUS'
       I_CALLBACK_USER_COMMAND           = 'USER_COMMAND'
      I_CALLBACK_TOP_OF_PAGE            = ' '
      I_CALLBACK_HTML_TOP_OF_PAGE       = ' '
      I_CALLBACK_HTML_END_OF_LIST       = ' '
      I_STRUCTURE_NAME                  =
      I_BACKGROUND_ID                   = ' '
      I_GRID_TITLE                      =
      I_GRID_SETTINGS                   =
          IS_LAYOUT                         = X_ALV_LAYOUT
          IT_FIELDCAT                       = I_FIELDCAT[]
      IT_EXCLUDING                      =
      IT_SPECIAL_GROUPS                 =
      IT_SORT                           =
      IT_FILTER                         =
      IS_SEL_HIDE                       =
       I_DEFAULT                         = 'X'
       I_SAVE                            = 'A'
      IS_VARIANT                        =
          IT_EVENTS                         = T_ALV_EVENTS
      IT_EVENT_EXIT                     =
      IS_PRINT                          =
      IS_REPREP_ID                      =
      I_SCREEN_START_COLUMN             = 0
      I_SCREEN_START_LINE               = 0
      I_SCREEN_END_COLUMN               = 0
      I_SCREEN_END_LINE                 = 0
      I_HTML_HEIGHT_TOP                 = 0
      I_HTML_HEIGHT_END                 = 0
      IT_ALV_GRAPHICS                   =
      IT_HYPERLINK                      =
      IT_ADD_FIELDCAT                   =
      IT_EXCEPT_QINFO                   =
      IR_SALV_FULLSCREEN_ADAPTER        =
    IMPORTING
      E_EXIT_CAUSED_BY_CALLER           =
      ES_EXIT_CAUSED_BY_USER            =
        TABLES
          T_OUTTAB                          = ITAB
    EXCEPTIONS
      PROGRAM_ERROR                     = 1
      OTHERS                            = 2
      IF SY-SUBRC <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.
    *&      Form  PF_STATUS
          text
         -->RT_EXTAB   text
    FORM PF_STATUS USING RT_EXTAB TYPE SLIS_T_EXTAB.
      SET PF-STATUS 'ALV_PF_STATUS'.  " excluding rt_extab.
    ENDFORM.                    "PF_STATUS
    *&      Form  user_action
          text
         -->R_UCOMM      text
         -->RS_SELFIELD  text
    FORM USER_ACTION USING R_UCOMM LIKE SY-UCOMM
    RS_SELFIELD TYPE SLIS_SELFIELD.
      DATA : OKCODE TYPE SY-UCOMM.
      OKCODE = R_UCOMM.
      CLEAR R_UCOMM.
      V_LINE = RS_SELFIELD-TABINDEX.
      CASE OKCODE.
        WHEN 'PICK'.
          READ TABLE ITAB INDEX V_LINE.
          PERFORM SUB_SELECT_RECORD1.
          PERFORM SUB_PREPARE_FIELDCATALOG1.
          CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
           EXPORTING
      I_INTERFACE_CHECK                 = ' '
      I_BYPASSING_BUFFER                = ' '
      I_BUFFER_ACTIVE                   = ' '
         I_CALLBACK_PROGRAM                = 'REPID'
      I_CALLBACK_PF_STATUS_SET          = 'PF_STATUS-SET'
      I_CALLBACK_USER_COMMAND           = ' '
      I_CALLBACK_TOP_OF_PAGE            = ' '
      I_CALLBACK_HTML_TOP_OF_PAGE       = ' '
      I_CALLBACK_HTML_END_OF_LIST       = ' '
      I_STRUCTURE_NAME                  =
      I_BACKGROUND_ID                   = ' '
      I_GRID_TITLE                      =
      I_GRID_SETTINGS                   =
      IS_LAYOUT                         =
      IT_FIELDCAT                       =
      IT_EXCLUDING                      =
      IT_SPECIAL_GROUPS                 =
      IT_SORT                           =
      IT_FILTER                         =
      IS_SEL_HIDE                       =
      I_DEFAULT                         = 'X'
      I_SAVE                            = ' '
      IS_VARIANT                        =
      IT_EVENTS                         =
      IT_EVENT_EXIT                     =
      IS_PRINT                          =
      IS_REPREP_ID                      =
      I_SCREEN_START_COLUMN             = 0
      I_SCREEN_START_LINE               = 0
      I_SCREEN_END_COLUMN               = 0
      I_SCREEN_END_LINE                 = 0
      I_HTML_HEIGHT_TOP                 = 0
      I_HTML_HEIGHT_END                 = 0
      IT_ALV_GRAPHICS                   =
      IT_HYPERLINK                      =
      IT_ADD_FIELDCAT                   =
      IT_EXCEPT_QINFO                   =
      IR_SALV_FULLSCREEN_ADAPTER        =
    IMPORTING
      E_EXIT_CAUSED_BY_CALLER           =
      ES_EXIT_CAUSED_BY_USER            =
            TABLES
              T_OUTTAB                          = ITAB1
    EXCEPTIONS
      PROGRAM_ERROR                     = 1
      OTHERS                            = 2
          IF SY-SUBRC <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
          ENDIF.
        WHEN 'EXIT'.
          RS_SELFIELD-EXIT = 'X'.
      ENDCASE.
    ENDFORM.                    "user_action
    *&      Form  SUB_PREPARE_FIELDCATALOG
          text
    -->  p1        text
    <--  p2        text
    FORM SUB_PREPARE_FIELDCATALOG .
      X_FIELDCAT-SELTEXT_L = 'MATERIAL'.
      X_FIELDCAT-DATATYPE = 'CHAR'.
      X_FIELDCAT-OUTPUTLEN = 18.
      X_FIELDCAT-FIELDNAME = 'MATNR'.
      X_FIELDCAT-HOTSPOT = 'X'.
      APPEND X_FIELDCAT TO I_FIELDCAT.
      CLEAR X_FIELDCAT.
      X_FIELDCAT-SELTEXT_L = 'PLANT'.
      X_FIELDCAT-DATATYPE = 'CHAR'.
      X_FIELDCAT-OUTPUTLEN = 4.
      X_FIELDCAT-FIELDNAME = 'WERKS'.
      APPEND X_FIELDCAT TO I_FIELDCAT.
      CLEAR X_FIELDCAT.
      X_FIELDCAT-SELTEXT_L = 'PUR.GROUP'.
      X_FIELDCAT-DATATYPE = 'CHAR'.
      X_FIELDCAT-OUTPUTLEN = 4.
      X_FIELDCAT-FIELDNAME = 'EKGRP'.
      X_FIELDCAT-EDIT = 'X'.
      APPEND X_FIELDCAT TO I_FIELDCAT.
      CLEAR X_FIELDCAT.
    ENDFORM.                    " SUB_PREPARE_FIELDCATALOG
    *&      Form  SUB_SELECT_RECORD
          text
    -->  p1        text
    <--  p2        text
    FORM SUB_SELECT_RECORD.
      SELECT MATNR WERKS EKGRP FROM MARC INTO TABLE ITAB UP TO 10 ROWS WHERE WERKS = '1000'.
    ENDFORM.                    " SUB_SELECT_RECORD
    *&      Form  SUB_DETERMINE_ALV_LAYOUT
          text
    -->  p1        text
    <--  p2        text
    FORM SUB_DETERMINE_ALV_LAYOUT .
      X_ALV_LAYOUT-COLWIDTH_OPTIMIZE = 'X'.
      X_ALV_LAYOUT-F2CODE = 'PICK'.
      X_ALV_LAYOUT-WINDOW_TITLEBAR = 'PLANT DATA'.
      X_ALV_LAYOUT-KEY_HOTSPOT = 'X'.
    ENDFORM.                    " SUB_DETERMINE_ALV_LAYOUT
    *&      Form  SUB_PREPARE_FIELDCATALOG1
          text
    -->  p1        text
    <--  p2        text
    FORM SUB_PREPARE_FIELDCATALOG1 .
      X_FIELDCAT-SELTEXT_L = 'MATERIAL'.
      X_FIELDCAT-DATATYPE = 'CHAR'.
      X_FIELDCAT-OUTPUTLEN = 18.
      X_FIELDCAT-FIELDNAME = 'MATNR'.
      X_FIELDCAT-HOTSPOT = 'X'.
      APPEND X_FIELDCAT TO I_FIELDCAT1.
      CLEAR X_FIELDCAT.
      X_FIELDCAT-SELTEXT_L = 'PLANT'.
      X_FIELDCAT-DATATYPE = 'CHAR'.
      X_FIELDCAT-OUTPUTLEN = 4.
      X_FIELDCAT-FIELDNAME = 'WERKS'.
      APPEND X_FIELDCAT TO I_FIELDCAT1.
      CLEAR X_FIELDCAT.
      X_FIELDCAT-SELTEXT_L = 'Storage Location'.
      X_FIELDCAT-DATATYPE = 'CHAR'.
      X_FIELDCAT-OUTPUTLEN = 4.
      X_FIELDCAT-FIELDNAME = 'LGORT'.
      X_FIELDCAT-EDIT = 'X'.
      APPEND X_FIELDCAT TO I_FIELDCAT1.
      CLEAR X_FIELDCAT.
    ENDFORM.                    " SUB_PREPARE_FIELDCATALOG1
    *&      Form  SUB_SELECT_RECORD1
          text
    -->  p1        text
    <--  p2        text
    FORM SUB_SELECT_RECORD1 .
      SELECT MATNR WERKS LGORT FROM MARD INTO TABLE ITAB1 WHERE MATNR = ITAB-MATNR AND WERKS = ITAB-WERKS.
      REFRESH I_FIELDCAT1.
    ENDFORM.                    " SUB_SELECT_RECORD1
    thanks and regards

    Consider this logic.
    DATA:
      g_exclude                  TYPE slis_t_extab.
    *       FORM display_alv_report                                       *
    FORM display_alv_report.
      PERFORM fieldcat_init      USING g_fieldcat[].
      PERFORM build_sort_fields  USING g_sort[].
      PERFORM eventtab_build     USING g_events[]
                                       g_events_ex[].
      PERFORM layout_build       USING g_layout.
      PERFORM exclude_icons.
      PERFORM list_view.
    ENDFORM.                    " display_alv_report.
    *      Form  exclude_icons
    FORM exclude_icons.
      APPEND '&ETA' TO g_exclude.     "Details
    *  APPEND '&OUP' TO g_exclude.     "Sort Up
    *  APPEND '&ODN' TO g_exclude.     "Sort Down
      APPEND '&ILT' TO g_exclude.     "Set Filter
      APPEND '&UMC' TO g_exclude.     "Sum
      APPEND '&RNT_PREV' TO g_exclude.     "Print preview
    *  APPEND '&VEXCEL' TO g_exclude.     "Excel
      APPEND '&AQW' TO g_exclude.     "Word processing
      APPEND '%PC' TO g_exclude.     "Local File
      APPEND '%SL' TO g_exclude.     "Mail recepient
      APPEND '&ABC' TO g_exclude.     "ABC Analysis
      APPEND '&GRAPH' TO g_exclude.     "Graphic
    *  APPEND '&OL0' TO g_exclude.     "Change layout
    *  APPEND '&OAD' TO g_exclude.     "Select layout
      APPEND '&AVE' TO g_exclude.     "Save Layout
      APPEND '&INFO' TO g_exclude.  "Information
    ENDFORM.                    " exclude_icons
    FORM list_view.
      g_repid = sy-repid.
      CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
           EXPORTING
                i_callback_program = g_repid
                is_layout          = g_layout
                it_sort            = g_sort[]
                it_events          = g_events[]
                it_fieldcat        = g_fieldcat[]
                i_save             = g_save
                it_excluding       = g_exclude     "<== Exclude
           TABLES
                t_outtab           = it_work
           EXCEPTIONS
                program_error      = 1
                OTHERS             = 2.
      IF sy-subrc <> 0.
        MESSAGE e208(00) WITH 'Error: ALV Grid'.
      ENDIF.
    ENDFORM.                    " layout_build

  • To display a popup message alongwith ALV grid

    Hi Experts,
    I have a requirement where I need to display data using ALV Grid. Also, in case there are any errors encountered during the data extraction I need to inform the user about it by using either a popup message or a status message stating that he needs to check the error log. To display the error log I have provided a push button which will take the user to another screen where he can see all the errors encountered.
    Can anyone please let me know as to how to accomplish the task of displaying a status message alongwith a ALV grid display?
    Looking forward to your reply.
    -Warm regards,
    Prajakta K.

    use exception handling and pop up.........
    try following in grid..
    *--Exception handling
    ENDIF .
    ENDIF .
    WHEN 'EU' .
    READ TABLE gt_list INDEX ls_selected_row-row_id .
    IF sy-subrc = 0 .
    CALL FUNCTION 'ZPOPUP_CONV_CURR_AND_DISPLAY'
    EXPORTING monun = 'EU'
    quant = gt_list-paymentsum.
    ENDIF .
    ENDCASE .
    ENDFORM .

  • To update an alv grid..

    Hello everyone,
    I have a requirement.
      update button in selection-screen.
    I have an alv grid display and I have to maintain last 2 fields in editable mode in the output and the user will enter the values after executing the report in the output screen and will save it.
    and when he will select  display radiobutton in the selection-screen ,,
    the entries which he entered above has to display ,,( all the entries should display in the output ).
    is it possible ? if yes, then let me know the procedure.
    will be rewarded..

    Hi,
           yes it is possible 
    all u need to do is call a new alv with same funtion modules and pass the updated internal table to these function modules
    i have the same req for 'SAVE' button in menu , u just change it by your radio button in the sample code below
    type-pools : slis.
    types : begin of t_mat,
            matnr type matnr,
            werks type werks_d,
            lgort type lgort_d,
            labst type labst,
            meins type meins,
            maktx type maktx,
            name1 type name1,
            lgobe type lgobe,
            msehl type msehl,
            v_lights type c,
            v_row type c length 4,     "FOR ROW COLOR
            v_col type slis_t_specialcol_alv,
            end of t_mat,
            begin of t_makt,
            matnr type matnr,
            maktx type maktx,
            end of t_makt,
            begin of t_marc,
            matnr type matnr,
            werks type werks_d,
            end of t_marc,
            begin of t_mard,
            matnr type matnr,
            werks type werks_d,
            lgort type lgort_d,
            labst type labst,
            end of t_mard,
            begin of t_t001l,
            werks type werks_d,
            lgort type lgort_d,
            lgobe type lgobe,
            end of t_t001l,
            begin of t_t001w,
            werks type werks_d,
            name1 type name1,
            end of t_t001w.
    types : begin of wa_mat,
            werks type werks,
            end of wa_mat.
    data : flag type i value 0.
    ******VARIABLE DECLARATION********
    data:v_prog_name type sy-repid,      "VARIABLE FOR PROG NAME
         v_grid_title type lvc_title. "VARIABLE FOR GRID TITLE
    *****INTERNAL TABLE DECLARATION***
    data:  it_mat type standard table of t_mat,
           it_marc type standard table of t_marc,
           it_mard type standard table of t_mard,
           it_t001l type standard table of t_t001l,
           it_t001w type standard table of t_t001w,
           it_makt type standard table of t_makt,
           it_fieldcat  type slis_t_fieldcat_alv,
           it_sortinfo   type slis_t_sortinfo_alv,
           it_eventcat   type slis_t_event,
           it_listheader type slis_t_listheader,
           t_color type slis_specialcol_alv.
    data : it_werks type standard table of wa_mat.
    *****WORK AREA DECLARATION*********
    data:  wa_mat type t_mat,
           wa_mard type t_mard,
           wa_t001l type t_t001l,
           wa_t001w type t_t001w,
           wa_makt type t_makt,
           wa_layout type slis_layout_alv.
    data : wa_werks type wa_mat.
    data : wa_variant1          like disvariant,
           wa_variant2          like disvariant.
               Selection-Screen                        *
    selection-screen begin of block plant with frame title text-001.
    select-options:  s_plant for wa_mat-werks,
                     s_stor for wa_mat-lgort.
    parameters     : p_var like disvariant-variant.
    selection-screen end of block plant.
    selection-screen begin of block output with frame title text-002.
    parameter:  p_rb_01 radiobutton group rd1 default 'X',  " list
                p_rb_02 radiobutton group rd1.              " grid
    selection-screen end of block output.
                   Initialization                      *
    perform zf_initialization.
                 At Selection Screen                   *
    at selection-screen on value-request for p_var.
      wa_variant1-report = sy-repid.
      call function 'REUSE_ALV_VARIANT_F4'
        exporting
          is_variant                = wa_variant1
      I_TABNAME_HEADER          =
      I_TABNAME_ITEM            =
      IT_DEFAULT_FIELDCAT       =
         i_save                    = 'A'
       i_display_via_grid        = 'X'
    importing
        e_exit                    = v_exit
         es_variant                = wa_variant2
       exceptions
         not_found                 = 1
         program_error             = 2
         others                    = 3
      if sy-subrc = 0.
        p_var = wa_variant2-variant.
      else.
        clear wa_variant2.
      endif.
    at selection-screen.
      perform zf_validate_sel_screen.
                Start of Selection                     *
    start-of-selection.
      perform zf_get_data.
              End of Selection                         *
    end-of-selection.
      perform zf_display_data.
    *&      Form  zf_initialization
      This will intialize all the variables, work area & subroutines
    -->  p1        text
    <--  p2        text
    form zf_initialization .
      clear :   wa_mat,
                wa_mard,
                wa_t001l,
                wa_t001w,
                wa_makt,
                wa_layout.
      refresh : it_mat,
                it_marc,
                it_mard,
                it_t001l,
                it_t001w,
                it_makt,
                it_fieldcat,
                it_sortinfo,
                it_eventcat,
                it_listheader.
      v_prog_name = sy-repid.
      wa_variant2-report = sy-repid.
      call function 'REUSE_ALV_VARIANT_DEFAULT_GET'
        exporting
          i_save        = 'A'
        changing
          cs_variant    = wa_variant2
        exceptions
          wrong_input   = 1
          not_found     = 2
          program_error = 3
          others        = 4.
      if sy-subrc = 0.
        p_var = wa_variant2-variant.
      else.
        p_var = '/DEFAULT'.
      endif.
    endform.                    " zf_initialization
    *&      Form  zf_validate_sel_screen
      This is to validate the inputs on the selction screen
    -->  p1        text
    <--  p2        text
    form zf_validate_sel_screen .
      if not p_var is initial.
        wa_variant1-report = sy-repid.
        wa_variant1-variant = p_var.
        call function 'REUSE_ALV_VARIANT_EXISTENCE'
          exporting
            i_save        = 'A'
          changing
            cs_variant    = wa_variant1
          exceptions
            wrong_input   = 1
            not_found     = 2
            program_error = 3
            others        = 4.
        if sy-subrc = 0.
          clear wa_variant2.
          move p_var to wa_variant2-variant.
          move sy-repid to wa_variant2-report.
        else.
          message e006. "No such variant exists
        endif.
      else.
        clear wa_variant1.
      endif.
      select werks from marc into wa_mat-werks where werks in s_plant.
        exit.
      endselect.
      if sy-subrc <> 0.
        message e002.
        clear wa_mat.
      endif.
      select lgort from mard into wa_mat-lgort where lgort in s_stor.
        exit.
      endselect.
      if sy-subrc <> 0.
        message e003.
        clear wa_mat.
      endif.
    endform.                    " zf_validate_sel_screen
    *&      Form  zf_get_data
      This will fetch data from the database tables & finally merge them
         into a single internal table, to pass it to alv
    -->  p1        text
    <--  p2        text
    form zf_get_data .
      select matnr werks into table it_marc from marc where werks in s_plant
      if sy-subrc = 0.
        sort it_marc by matnr werks.
      endif.
      if it_marc[] is not initial.
        select matnr maktx into table it_makt from makt
                          for all entries in it_marc
                          where matnr = it_marc-matnr
                            and spras = sy-langu.
        if sy-subrc = 0.
          sort it_makt by matnr.
        endif.
        select matnr werks lgort labst into table it_mard from mard
                                       for all entries in it_marc
                                       where matnr = it_marc-matnr
                                             and werks = it_marc-werks
                                             and lgort in s_stor.
        if sy-subrc = 0.
          sort it_mard by matnr werks lgort.
        endif.
        select werks name1 into table it_t001w from t001w
                           for all entries in it_marc
                           where werks = it_marc-werks.
        if sy-subrc = 0.
          sort it_t001w by werks.
        endif.
      endif.
      if it_mard[] is not initial.
        select werks lgort lgobe into table it_t001l from t001l
                                 for all entries in it_mard
                                 where werks = it_mard-werks
                                   and lgort = it_mard-lgort.
        if sy-subrc = 0.
          sort it_t001l by werks lgort.
        endif.
      endif.
      clear : wa_mat,
              wa_mard,
              wa_t001l,
              wa_t001w,
              wa_makt.
      loop at it_mard into wa_mard.
        wa_mat-matnr = wa_mard-matnr.
        wa_mat-werks = wa_mard-werks.
        wa_mat-lgort = wa_mard-lgort.
        wa_mat-labst = wa_mard-labst.
        read table it_makt into wa_makt with key matnr = wa_mard-matnr
    binary search.
        if sy-subrc = 0.
          wa_mat-maktx = wa_makt-maktx.
        endif.
        read table it_t001l into wa_t001l with key werks = wa_mard-werks
    lgort = wa_mard-lgort binary search.
        if sy-subrc = 0.
          wa_mat-lgobe = wa_t001l-lgobe.
        endif.
        read table it_t001w into wa_t001w with key werks = wa_mard-werks
    binary search.
        if sy-subrc = 0.
          wa_mat-name1 = wa_t001w-name1.
        endif.
        append wa_mat to it_mat.
      endloop.
      sort it_mat by matnr werks lgort.
      loop at it_mat into wa_mat.
        clear t_color.
        if wa_mat-labst < 100.
          wa_mat-v_lights = '1'.
          t_color-fieldname = 'LABST'.
          t_color-color-col = 6.
          append t_color to wa_mat-v_col.
          wa_mat-v_row = 'C610'.
          modify it_mat from wa_mat.
        elseif wa_mat-labst < 1000.
          wa_mat-v_lights = '2'.
          t_color-fieldname = 'LABST'.
          t_color-color-col = 3.
          append t_color to wa_mat-v_col.
          wa_mat-v_row = 'C510'.
          modify it_mat from wa_mat.
        else.
          wa_mat-v_lights = '3'.
          t_color-fieldname = 'LABST'.
          t_color-color-col = 5.
          append t_color to wa_mat-v_col.
          wa_mat-v_row = 'C210'.
          modify it_mat from wa_mat.
        endif.
        clear wa_mat.
      endloop.
    endform.                    " zf_get_data
    *&      Form  zf_display_data
    -->  p1        text
    <--  p2        text
    form zf_display_data .
    *If Internal Table Is Populated Then Only Display Alv Report.
      if not it_mat[] is initial.
    &---Prepare fieldcatalog .
        perform zf_build_fieldcat using it_fieldcat.
    &---Build event catalog.
        perform zf_eventcat using it_eventcat.
    &---Build Listheader for TOP OF PAGE EVENT.
        perform zf_build_listheader using it_listheader.
    &---Build layout.
        perform zf_layout.
    &---Build sorting.
        perform zf_sorting using it_sortinfo.
    &---Initializating Grid Title
        perform zf_build_grid_title.
    IF GRID RADIO button (ALV GRID) IS selected .
        if p_rb_02 is not initial.
    DISPLAY ALV GRID.
          perform zf_display_alv_grid.
        else.
    DISPLAY ALV LIST.
          perform zf_display_alv_list.
        endif.
      else.
    *&---If Table is not Populated ie Records Does not exist
        message s001.
      endif.
    endform.                    " zf_display_data
    *&      Form  ZF_BUILD_FIELDCAT
          text
         -->P_IT_FIELDCAT  text
    form zf_build_fieldcat  using    p_it_fieldcat type slis_t_fieldcat_alv.
    *Declaring Local Variable
      data: l_fieldcat type slis_fieldcat_alv.
      clear l_fieldcat.
    for First field
      l_fieldcat-col_pos     = '1'.          "POSITION OF THE COLUMN.
      l_fieldcat-fieldname   = 'WERKS'.      "FIELD FOR WHICH CATALOG
      l_fieldcat-tabname     = 'IT_MAT'.     "NAME OF INTERNAL TABLE
      l_fieldcat-ref_tabname = 'MARC'.       "FOR F1 & F4 HELP AS REFERNCED
      l_fieldcat-key         = 'X'.          "MAKING FIELD AS KEY FIELD
      l_fieldcat-outputlen   =  4.           "SET THE OUTPUT LENGTH.
      l_fieldcat-seltext_l   = text-003.  "Long text for header.
      l_fieldcat-seltext_m   = text-003.    "Medium text for header.
      l_fieldcat-seltext_s   = text-003.           "Short text for header.
      append l_fieldcat to p_it_fieldcat.
      clear l_fieldcat.
    for Second field
      l_fieldcat-col_pos     = '2'.          "POSITION OF THE COLUMN.
      l_fieldcat-fieldname   = 'LGORT'.      "FIELD FOR WHICH CATALOG
      l_fieldcat-tabname     = 'IT_MAT'.     "NAME OF INTERNAL TABLE
      l_fieldcat-ref_tabname = 'MARD'.       "FOR F1 & F4 HELP AS REFERNCED
      l_fieldcat-key         = 'X'.          "MAKING FIELD AS KEY FIELD
      l_fieldcat-outputlen   =  4.           "SET THE OUTPUT LENGTH.
      l_fieldcat-seltext_l   = text-004.  "Long text for header.
      l_fieldcat-seltext_m   = text-005.    "Medium text for header.
      l_fieldcat-seltext_s   = text-006.           "Short text for header.
      append l_fieldcat to p_it_fieldcat.
      clear l_fieldcat.
    for third field
      l_fieldcat-col_pos     = '3'.          "POSITION OF THE COLUMN.
      l_fieldcat-fieldname   = 'MATNR'.      "FIELD FOR WHICH CATALOG
      l_fieldcat-tabname     = 'IT_MAT'.     "NAME OF INTERNAL TABLE
      l_fieldcat-ref_tabname = 'MARA'.       "FOR F1 & F4 HELP AS REFERNCED
    l_fieldcat-key         = 'X'.          "MAKING FIELD AS KEY FIELD
      l_fieldcat-outputlen   =  18.           "SET THE OUTPUT LENGTH.
      l_fieldcat-seltext_l   = text-007.  "Long text for header.
      l_fieldcat-seltext_m   = text-008.    "Medium text for header.
      l_fieldcat-seltext_s   = text-009.           "Short text for header.
      append l_fieldcat to p_it_fieldcat.
      clear l_fieldcat.
    for fourth field
      l_fieldcat-col_pos     = '4'.          "POSITION OF THE COLUMN.
      l_fieldcat-fieldname   = 'LABST'.      "FIELD FOR WHICH CATALOG
      l_fieldcat-tabname     = 'IT_MAT'.     "NAME OF INTERNAL TABLE
      l_fieldcat-ref_tabname = 'MARD'.       "FOR F1 & F4 HELP AS REFERNCED
      l_fieldcat-outputlen   =  16.           "SET THE OUTPUT LENGTH.
      l_fieldcat-seltext_l   = text-010.  "Long text for header.
      l_fieldcat-seltext_m   = text-011.    "Medium text for header.
      l_fieldcat-seltext_s   = text-012.           "Short text for header.
      l_fieldcat-do_sum = 'X'.
      l_fieldcat-input       = 'X'.          "Making the field editable
      l_fieldcat-edit        = 'X'.
      append l_fieldcat to p_it_fieldcat.
      clear l_fieldcat.
    endform.                    " ZF_BUILD_FIELDCAT
    *&      Form  zf_eventcat
          text
         -->P_IT_EVENTCAT  text
    form zf_eventcat  using    p_it_eventcat type slis_t_event.
      data l_eventcat type slis_alv_event.
      clear l_eventcat.
    *Get all the events.
      call function 'REUSE_ALV_EVENTS_GET'
        exporting
          i_list_type     = 0
        importing
          et_events       = p_it_eventcat
        exceptions
          list_type_wrong = 1
          others          = 2.
      if sy-subrc <> 0.
        message id sy-msgid type sy-msgty number sy-msgno
             with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
      endif.
    TOP-OF-PAGE FORM
      clear l_eventcat.
      read table p_it_eventcat into l_eventcat with key
                              name = slis_ev_top_of_page.
      if sy-subrc = 0.
        move 'ZF_TOP_OF_PAGE' to l_eventcat-form.
        modify p_it_eventcat from l_eventcat index sy-tabix
                                             transporting form.
      endif.
    PF_STATUS_SET FORM
      clear l_eventcat.
      read table p_it_eventcat into l_eventcat with key
                              name = slis_ev_pf_status_set.
      if sy-subrc = 0.
        move 'ZF_PF_STATUS_SET' to l_eventcat-form.
        modify p_it_eventcat from l_eventcat index sy-tabix
                                          transporting form.
      endif.
    USER_COMMAND FORM
      clear l_eventcat.
      read table p_it_eventcat into  l_eventcat with key
                               name = slis_ev_user_command.
      if sy-subrc = 0.
        move 'ZF_USER_COMMAND' to  l_eventcat-form.
        modify p_it_eventcat from l_eventcat index sy-tabix
                                          transporting form.
      endif.
    endform.                    " zf_eventcat
    *&      Form  ZF_BUILD_LISTHEADER
          text
         -->P_IT_LISTHEADER  text
    form zf_build_listheader  using  p_it_listheader type slis_t_listheader.
      data: l_listheader type slis_listheader.
      refresh p_it_listheader.
      clear l_listheader.
      l_listheader-typ = 'H'.   "Header
    l_listheader-key = 'FCIL,INDIA'. "Ignored for "Header" Type
      l_listheader-info = text-013.
      append l_listheader to p_it_listheader.
      clear l_listheader.
      data : lv_date(10) type c .
      write sy-datum to lv_date .
      l_listheader-typ = 'S'.
      l_listheader-key = 'DATE'.
      l_listheader-info = lv_date.
      append l_listheader to p_it_listheader.
      clear l_listheader.
      l_listheader-typ = 'A'.
    l_listheader-key = 'COMMENT'.    " key is ignored
      l_listheader-info = text-014.
      append l_listheader to p_it_listheader.
      clear l_listheader.
      l_listheader-typ = 'S'.
      l_listheader-key = text-016.
    l_listheader-info = 'Input Plant'.
      append l_listheader to p_it_listheader.
      clear l_listheader.
      l_listheader-typ = 'S'.
      l_listheader-key = text-017.
    l_listheader-info = 'Plant'.
      append l_listheader to p_it_listheader.
      select werks from marc into  table it_werks where werks in s_plant.
      sort it_werks by werks.
      delete adjacent duplicates from it_werks comparing werks.
      loop at it_werks into wa_werks.
        clear l_listheader.
        l_listheader-typ = 'S'.
       l_listheader-key = 'X'.
        l_listheader-info = wa_werks-werks.
        append l_listheader to p_it_listheader.
      endloop.
    endform.                    " ZF_BUILD_LISTHEADER
    *&      Form  ZF_LAYOUT
          text
    -->  p1        text
    <--  p2        text
    form zf_layout .
      clear wa_layout.
      wa_layout-zebra = 'X'.
      wa_layout-lights_fieldname = 'V_LIGHTS'.
      wa_layout-lights_tabname   = 'IT_MAT'.
      wa_layout-info_fieldname = 'V_ROW'. " infofield for listoutput
      wa_layout-coltab_fieldname = 'V_COL'. " colors
    endform.                    " ZF_LAYOUT
    *&      Form  ZF_SORTING
          text
         -->P_IT_SORTINFO  text
    form zf_sorting  using    p_it_sortinfo type slis_t_sortinfo_alv.
      data l_sortinfo type slis_sortinfo_alv.
      clear l_sortinfo.
      l_sortinfo-spos = '1'.
      l_sortinfo-fieldname = 'WERKS'.
      l_sortinfo-tabname = 'IT_MAT'.
      l_sortinfo-up = 'X'.
      l_sortinfo-group = 'UL'.              "UNDERLINE AFTER EVERY GROUP
      l_sortinfo-subtot = 'X'.
      append l_sortinfo to p_it_sortinfo.
    endform.                    " ZF_SORTING
    *&      Form  ZF_BUILD_GRID_TITLE
          text
    -->  p1        text
    <--  p2        text
    form zf_build_grid_title .
      v_grid_title = text-015.
    endform.                    " ZF_BUILD_GRID_TITLE
    *&      Form  ZF_DISPLAY_ALV_GRID
          text
    -->  p1        text
    <--  p2        text
    form zf_display_alv_grid .
      call function 'REUSE_ALV_GRID_DISPLAY'
       exporting
      I_INTERFACE_CHECK                 = ' '
      I_BYPASSING_BUFFER                = ' '
      I_BUFFER_ACTIVE                   = ' '
         i_callback_program                = v_prog_name
       i_callback_pf_status_set          = 'ZF_PF_STATUS_SET'
       i_callback_user_command           = 'ZF_USER_COMMAND'
       i_callback_top_of_page            = 'ZF_TOP_OF_PAGE'
      I_CALLBACK_HTML_TOP_OF_PAGE       = ' '
      I_CALLBACK_HTML_END_OF_LIST       = ' '
      I_STRUCTURE_NAME                  =
      I_BACKGROUND_ID                   = ' '
         i_grid_title                      = v_grid_title
      I_GRID_SETTINGS                   =
         is_layout                         = wa_layout
         it_fieldcat                       = it_fieldcat
      IT_EXCLUDING                      =
      IT_SPECIAL_GROUPS                 =
       it_sort                           = it_sortinfo
      IT_FILTER                         =
      IS_SEL_HIDE                       =
      I_DEFAULT                         = 'X'
       i_save                            = 'A'
       is_variant                        = wa_variant2
       it_events                         = it_eventcat
      IT_EVENT_EXIT                     =
      IS_PRINT                          =
      IS_REPREP_ID                      =
      I_SCREEN_START_COLUMN             = 0
      I_SCREEN_START_LINE               = 0
      I_SCREEN_END_COLUMN               = 0
      I_SCREEN_END_LINE                 = 0
      IT_ALV_GRAPHICS                   =
      IT_HYPERLINK                      =
      IT_ADD_FIELDCAT                   =
      IT_EXCEPT_QINFO                   =
      I_HTML_HEIGHT_TOP                 =
      I_HTML_HEIGHT_END                 =
    IMPORTING
      E_EXIT_CAUSED_BY_CALLER           =
      ES_EXIT_CAUSED_BY_USER            =
        tables
          t_outtab                          = it_mat
    exceptions
       program_error                     = 1
       others                            = 2
      if sy-subrc <> 0.
        message id sy-msgid type sy-msgty number sy-msgno
                with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
      endif.
    endform.                    " ZF_DISPLAY_ALV_GRID
    *&      Form  zf_display_alv_list
          text
    -->  p1        text
    <--  p2        text
    form zf_display_alv_list .
      call function 'REUSE_ALV_LIST_DISPLAY'
       exporting
      I_INTERFACE_CHECK              = ' '
      I_BYPASSING_BUFFER             =
      I_BUFFER_ACTIVE                = ' '
         i_callback_program             = v_prog_name
       i_callback_pf_status_set       = 'ZF_PF_STATUS_SET'
       i_callback_user_command        = 'ZF_USER_COMMAND'
      I_STRUCTURE_NAME               =
         is_layout                      = wa_layout
         it_fieldcat                    = it_fieldcat
      IT_EXCLUDING                   =
      IT_SPECIAL_GROUPS              =
       it_sort                        = it_sortinfo
      IT_FILTER                      =
      IS_SEL_HIDE                    =
      I_DEFAULT                      = 'X'
      I_SAVE                         = 'A'
      IS_VARIANT                     = WA_VARIANT2
       it_events                      = it_eventcat
      IT_EVENT_EXIT                  =
      IS_PRINT                       =
      IS_REPREP_ID                   =
      I_SCREEN_START_COLUMN          = 0
      I_SCREEN_START_LINE            = 0
      I_SCREEN_END_COLUMN            = 0
      I_SCREEN_END_LINE              = 0
    IMPORTING
      E_EXIT_CAUSED_BY_CALLER        =
      ES_EXIT_CAUSED_BY_USER         =
        tables
          t_outtab                       = it_mat
       exceptions
         program_error                  = 1
         others                         = 2
      if sy-subrc <> 0.
        message id sy-msgid type sy-msgty number sy-msgno
                with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
      endif.
    endform.                    " zf_display_alv_list
    *&      Form  zf_top_of_page
          text
    -->  p1        text
    <--  p2        text
    form zf_top_of_page .
      call function 'REUSE_ALV_COMMENTARY_WRITE'
        exporting
          it_list_commentary       = it_listheader
         i_logo                   = 'ENJOYSAP_LOGO'
      I_END_OF_LIST_GRID       =
    endform.                    " zf_top_of_page
    *&      Form  zf_pf_status_set
          text
    -->  p1        text
    <--  p2        text
    form zf_pf_status_set using rt_extab type slis_t_extab.
      set pf-status  'ALV_MENU_MAT' excluding  'BACK'.
      case sy-ucomm.
        when 'SAVE'.
    IF flag <> 0.
          set pf-status  'ALV_MENU_MAT' .
    ENDIF.
      endcase.
    endform.                    " zf_pf_status_set
    *&      Form  zf_user_command
          text
    -->  p1        text
    <--  p2        text
    form zf_user_command using r_ucomm like sy-ucomm
                            rs_selfield type slis_selfield.
    sy-ucomm = r_ucomm.
      case r_ucomm.
        when 'SAVE'.
          flag = flag + 1.
          read table it_mat index rs_selfield-tabindex into wa_mat.
          wa_mat-labst = rs_selfield-value.
          if rs_selfield-value < 100.
            wa_mat-v_lights = '1'.
            t_color-fieldname = 'LABST'.
            t_color-color-col = 6.
            wa_mat-v_row = 'C610'.
            clear wa_mat-v_col.
            append t_color to wa_mat-v_col.
          elseif rs_selfield-value < 1000.
            wa_mat-v_lights = '2'.
            t_color-fieldname = 'LABST'.
            t_color-color-col = 3.
            wa_mat-v_row = 'C510'.
            clear wa_mat-v_col.
            append t_color to wa_mat-v_col.
          else.
            wa_mat-v_lights = '3'.
            t_color-fieldname = 'LABST'.
            t_color-color-col = 5.
            wa_mat-v_row = 'C210'.
            clear wa_mat-v_col.
            append t_color to wa_mat-v_col.
          endif.
          modify it_mat from wa_mat index rs_selfield-tabindex.
    IF GRID RADIO button (ALV GRID) IS selected .
          if p_rb_02 is not initial.
           SET PF-STATUS  'ALV_MENU_MAT'.
    DISPLAY ALV GRID.
            perform zf_display_alv_grid.
          else.
           SET PF-STATUS  'ALV_MENU_MAT'.
    DISPLAY ALV LIST.
            perform zf_display_alv_list.
          endif.
          set screen 0.
        when 'BACK'.
          leave screen.
        when others.
          message i004.
      endcase.
       WHEN 'BACK'.
    CASE sy-ucomm.
       WHEN 'BACK'.
         LEAVE SCREEN.
    ENDCASE.
    endform.                    " zf_user_command
    reward points if helpful

  • Regarding user command

    hi,
    how to write the user command on alv report and the output should ne upload into va02,
    My requirement is i have developed a alv report,in that the requiremnt is one pushbutton they want,when they clicked it the output should be upload into va02 transaction.
    Thanks and Regards,

    Hi Ali,
    For user command in alv,
    First set the PF Status of that ALV,
    and in the FM Reuse_alv_grid_display pass the subroutine name fr user command,
    in its parameter  -->      i_callback_user_command           = 'COMM'
    Then to catch the function module you have to write like for eg,
    FORM comm USING ucomm LIKE sy-ucomm selfield TYPE slis_selfield.
      DATA: okcode TYPE sy-ucomm.
      okcode = ucomm.
      CASE okcode.
        WHEN 'REF'.
        CALL FUNCTION 'POPUP_TO_INFORM'
          EXPORTING
            titel         = 'MANSI'
            txt1          = 'CREATED BY'
            txt2          = SY-UNAME
          TXT3          = ' '
          TXT4          = ' '
    That is on that buttons click you can use set parameter id statement to move your
    control from this screen to the required screen.
    Hope it helps you
    Regrds
    Mansi

Maybe you are looking for

  • Why HTML report takes more time than the PDF one?

    Hi, I have created report in Reports 6i. When I run the report on the web with FORMAT = PDF it runs very fast and shows all the pages in 2 minutes. But when I run with FORMAT = HTML it shows the first page in 2 minutes, after that it takes lot of tim

  • Can't get substring to work properly

    I have one field called 'Name', you are supposed to put full name and list it like this, 'Last, First, MI' in this one field separated by a comma, for each name, ex., 'Doe, John A.'. I need to be able to extract the first initial from the last name,

  • Moving Photos in LR 4

    I have installed a new H/D and want to make it a dedicated photo drive and scratch disk for CS5. I moved my cataolog onto the new drive and I had to have LR "point" to the new location in order to open so that's all good now. What's the procedure to

  • Subcontracting GR  (Urgent)

    Hi Experts, How can we segregate subcontracting MIGO with that of Normal purchase Migo. Please give me field and table. Thanks GR

  • Delete third party app icon

    How do i delete third party app icon? pls help