OOP ALV event on standard toolbar

Hi everyone,
I'm using a method SET_TABLE_FOR_FIRST_DISPLAY to create an ALV grid.
After making it editable I get these "Append", "Insert", "Delete" and "Duplicate Row" buttons in the toolbar by default.
Is there a way to override the functionality of these buttons?
My requirement is to make some cells (key fields) editable if a row has been duplicated or a new row has been inserted.
Thanks in advance,
Yasantha

If you implement the toolbar event handler for the class, you can remove icons from the toolbar that you don't want. 
*   Set up event handlers.
    CREATE OBJECT event_receiver.
    SET HANDLER event_receiver->toolbar for g_grid.
METHODS:
      toolbar FOR EVENT toolbar OF cl_gui_alv_grid
              IMPORTING e_object e_interactive.
DATA: ls_toolbar type stb_button.
  LOOP AT p_e_object->mt_toolbar INTO ls_toolbar.
    IF ls_toolbar-function = '&REFRESH' OR
       ls_toolbar-function = '&LOCAL&CUT' OR
       ls_toolbar-function = '&LOCAL&COPY' OR
       ls_toolbar-function = '&LOCAL&PASTE' OR
       ls_toolbar-function = '&LOCAL&APPEND' OR
       ls_toolbar-function = '&LOCAL&INSERT_ROW' OR
       ls_toolbar-function = '&LOCAL&DELETE_ROW' OR
       ls_toolbar-function = '&LOCAL&COPY_ROW'.
       DELETE p_e_object->mt_toolbar.
    ENDIF.
  ENDLOOP.

Similar Messages

  • How to handle events on standard toolbar

    hi, the following code i worte is to load a form and fill data from db table ..but i'm getting only one record and the buttons on standard toolbar like next, previous, first and last are not enabled and not working...what should i do? plz give me the code....
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load       
            Dim SboGuiApi As SAPbouiCOM.SboGuiApi
            Dim sConnectionString As String
            Dim SBO_Application As SAPbouiCOM.Application
            Dim oDICompany As SAPbobsCOM.Company
            Dim ret As Long
            SboGuiApi = New SAPbouiCOM.SboGuiApi
            sConnectionString = Environment.GetCommandLineArgs.GetValue(1)
            sConnectionString = Command()
            SboGuiApi.Connect(sConnectionString)
            SBO_Application = SboGuiApi.GetApplication
            oDICompany = New SAPbobsCOM.Company
            Dim sCookie As String
            sCookie = oDICompany.GetContextCookie()
            Dim conStr As String
            conStr = SBO_Application.Company.GetConnectionContext(sCookie)
            ret = oDICompany.SetSboLoginContext(conStr)
            If Not ret = 0 Then
                Exit Sub 'the operation has failed.           
            End If
            ret = oDICompany.Connect()
            If ret <> 0 Then
                SBO_Application.MessageBox("Failed")
            Else
                SBO_Application.MessageBox("Connected to Database")
            End If
            ' loading(Form)
            Dim oForm As SAPbouiCOM.Form
            Dim creationPackage As SAPbouiCOM.FormCreationParams
            Dim oxmldoc As New Xml.XmlDocument 'u2026when using .netu2019s system.xml
            'create the formcreationparams object
            creationPackage = SBO_Application.CreateObject( _
             SAPbouiCOM.BoCreatableObjectType.cot_FormCreationParams)
            'please note: these parameters override corresponding data in the xml
            creationPackage.UniqueID = "Sales 111"
            creationPackage.FormType = "Sales Order"
            creationPackage.BorderStyle = SAPbouiCOM.BoFormBorderStyle.fbs_Sizable
            'just a sample for an xml string describing a formu2026 same as used for loadbatchactions
            oxmldoc.Load("c:program filessapsap business oneSales Order.srf")
            creationPackage.XmlData = oxmldoc.InnerXml
            'add the form to the sbo application
            oForm = SBO_Application.Forms.AddEx(creationPackage)
            'set the form title and set it visible!
            oForm.Visible = True
            ''''''''''''''''''''''''''''''Data Binding
            '''''''''''binding data from DBDataSource to form items
            Dim oDBDataSource As SAPbouiCOM.DBDataSource
            Dim oItem As SAPbouiCOM.Item
            Dim oEdit As SAPbouiCOM.EditText
            '''''1st edit box
            oItem = oForm.Items.Item("4")
            oEdit = oItem.Specific
            oForm.DataSources.DBDataSources.Add("AACT")
            oEdit.DataBind.SetBound(True, "AACT", "AcctCode")
            ' getting the data sources bound to the form
            oDBDataSource = oForm.DataSources.DBDataSources.Item("AACT")
            oDBDataSource.Query()
            '''''2nd edit box
            oItem = oForm.Items.Item("5")
            oEdit = oItem.Specific
            oForm.DataSources.DBDataSources.Add("AACT")
            oEdit.DataBind.SetBound(True, "AACT", "AcctName")
            ' getting the data sources bound to the form
            oDBDataSource = oForm.DataSources.DBDataSources.Item("AACT")
            oDBDataSource.Query()
            ''''3rd edit box
            oItem = oForm.Items.Item("6")
            oEdit = oItem.Specific
            oForm.DataSources.DBDataSources.Add("AACT")
            oEdit.DataBind.SetBound(True, "AACT", "CurrTotal")
            ' getting the data sources bound to the form
            oDBDataSource = oForm.DataSources.DBDataSources.Item("AACT")
            oDBDataSource.Query()
        End Sub

    You have to enable the menus on toolbar as
    form.EnableMenu(1288, True)
                 form.EnableMenu(1289, True)
                 form.EnableMenu(1290, True)
                 form.EnableMenu(1291, True)
    If zou have the datas as UDO, use
    form.DataBrowser.BrowseBy = "code" - specifies the logic for getting next, previous,... record
    dont forget to take
    ObjectType="your udo name"
    to the form for specify from which UDO will be the datas.
    If you dont have udo, you need enable themenus in toolbar and in menuevent catch the events and create own logic for this.

  • How do I define Field-Catalog and Event-Catalog in OOPs ALV

    Hi All,
    This is the piece of the code on which I'm working upon. This program is giving an exception "No Field-Catalog Found". 
    I'm new to OOPs ALV. Could anybody please tell me how to define the field-catalog and event-catalog in this.
    module PBO output.
          IF g_custom_container IS INITIAL.
              CREATE OBJECT g_custom_container EXPORTING CONTAINER_NAME = 'CCCONTAINER'.
              CREATE OBJECT g_grid             EXPORTING I_PARENT       = g_custom_container.
          CALL METHOD g_grid->set_table_for_first_display
              EXPORTING I_STRUCTURE_NAME = 'IT_MATERIAL'
                        is_layout = layout
              CHANGING IT_OUTTAB         = gt_it_material.
          ENDIF.
      endmodule.
    Regards,
    Saurabh

    hi,
    chk this sampl ceode.
    TYPE-POOLS: slis.
    CLASS lcl_event_receiver DEFINITION DEFERRED.
    TABLES : zmpets_shipactiv, zmpets_chargebk, zmpets_shiphdr.
    DATA : BEGIN OF int_crb OCCURS 0,
           sel TYPE char1,
           icon TYPE icon_d,
           pernr LIKE zmpets_cil-pernr,
           vorna LIKE pa0002-vorna,
           movreason LIKE zmpets_shiphdr-movreason,
           shipdocnum LIKE zmpets_chargebk-shipdocnum,
           createdon LIKE zmpets_chargebk-createdon,
           chargeamount LIKE zmpets_chargebk-chargeamount,
           version LIKE zmpets_shipactiv-version,
           activity LIKE zmpets_shipactiv-activity,
           vendor LIKE zmpets_shiphdr-vendor,
          smtp_addr LIKE adr6-smtp_addr,
           empperid LIKE zmpets_167doc-empperid,
           celltab TYPE lvc_t_styl,
           END OF int_crb.
    DATA : int_crb_ver LIKE int_crb OCCURS 0 WITH HEADER LINE.
    DATA : int_crb_mail LIKE int_crb OCCURS 0 WITH HEADER LINE.
    DATA : int_shipactiv LIKE zmpets_shipactiv OCCURS 0 WITH HEADER LINE.
    DATA: gt_fieldcatalog TYPE lvc_t_fcat.
    DATA : wf_flag TYPE i.
    DATA : wf_res TYPE c.
    DATA : wf_tabix TYPE sy-tabix.
    DATA: BEGIN OF int_sin OCCURS 0,
          shipdocnum LIKE zmpets_chargebk-shipdocnum,
            shipdocnum LIKE zmpets_shipactiv-petsdocnumber,
          END OF int_sin.
    DATA: objpack   LIKE sopcklsti1 OCCURS 2 WITH HEADER LINE.
    DATA: objhead   LIKE solisti1 OCCURS 1 WITH HEADER LINE.
    DATA: objbin    LIKE solisti1 OCCURS 10 WITH HEADER LINE.
    DATA: objtxt    LIKE solisti1 OCCURS 10 WITH HEADER LINE.
    DATA: reclist   LIKE somlreci1 OCCURS 5 WITH HEADER LINE.
    DATA: doc_chng  LIKE sodocchgi1.
    DATA: tab_lines LIKE sy-tabix.
    DATA l_num(3).
    DATA: ok_code            LIKE          sy-ucomm,
          w_repid            LIKE          sy-repid,
          wl_sno             TYPE          i         VALUE 0,
          w_max              TYPE          i         VALUE 100,
          wf_layout          TYPE          lvc_s_layo,
          cont_on_main       TYPE          scrfname   VALUE  'GRID_CONTROL',
          cont_on_dialog     TYPE          scrfname   VALUE 'GRID_CONTROL',
          grid1              TYPE          REF TO cl_gui_alv_grid,
          grid2              TYPE          REF TO cl_gui_alv_grid,
          custom_container1  TYPE          REF TO cl_gui_custom_container,
          custom_container2  TYPE          REF TO cl_gui_custom_container,
          event_receiver     TYPE          REF TO lcl_event_receiver,
          lt_exclude         TYPE          ui_functions,
          ls_celltab         TYPE          lvc_s_styl,
          lt_celltab         TYPE          lvc_t_styl.
    SELECTION-SCREEN BEGIN OF BLOCK b3 WITH FRAME TITLE text-001.
    PARAMETERS : p_cash AS CHECKBOX.
    SELECTION-SCREEN END OF BLOCK b3.
    PERFORM fieldcatalog_init USING gt_fieldcatalog[].
    Selection-Screen----
    SELECTION-SCREEN  BEGIN OF BLOCK b1 WITH FRAME TITLE text-002.
    SELECT-OPTIONS:s_chdate FOR zmpets_chargebk-createdon,
                   s_pernr FOR zmpets_shiphdr-pernr,
                   s_mvrsn FOR zmpets_shiphdr-movreason,
                   s_sin FOR zmpets_chargebk-shipdocnum NO INTERVALS
    NO-EXTENSION.
    SELECTION-SCREEN  END OF BLOCK b1.
    PERFORM f_clear_fields.
    CALL SCREEN 100.
          CLASS lcl_event_receiver DEFINITION
    CLASS lcl_event_receiver DEFINITION.
      PUBLIC SECTION.
        METHODS:
        handle_toolbar
            FOR EVENT toolbar OF cl_gui_alv_grid
                IMPORTING e_object e_interactive,
        handle_user_command
            FOR EVENT user_command OF cl_gui_alv_grid
                IMPORTING e_ucomm.
      PRIVATE SECTION.
    ENDCLASS.                    "lcl_event_receiver DEFINITION
          CLASS lcl_event_receiver IMPLEMENTATION
    CLASS lcl_event_receiver IMPLEMENTATION.
      METHOD handle_toolbar.
    § 2.In event handler method for event TOOLBAR: Append own functions
      by using event parameter E_OBJECT.
        DATA: ls_toolbar  TYPE stb_button.
    append a separator to normal toolbar
        CLEAR ls_toolbar.
        MOVE 3 TO ls_toolbar-butn_type.
        APPEND ls_toolbar TO e_object->mt_toolbar.
        CLEAR ls_toolbar.
    new button -
        MOVE 'PROCESSED' TO ls_toolbar-function.
        MOVE icon_execute_object TO ls_toolbar-icon.
        MOVE 'Process the Record'(110) TO ls_toolbar-quickinfo.
        MOVE ' Process '(200) TO ls_toolbar-text.
        MOVE ' ' TO ls_toolbar-disabled.
        APPEND ls_toolbar TO e_object->mt_toolbar.
      ENDMETHOD.                    "handle_toolbar
      METHOD handle_user_command.
    § 3.In event handler method for event USER_COMMAND: Query your
      function codes defined in step 2 and react accordingly.
        DATA: lt_rows TYPE lvc_t_row.
        CASE e_ucomm.
          WHEN 'PROCESSED'.
            CALL FUNCTION 'POPUP_TO_CONFIRM_STEP'
                     EXPORTING
                      defaultoption        = 'N'
      textline1     = 'Do you want to process the selected documents?'
              TEXTLINE2            = ' '
                       titel                = 'Process Documents'
              START_COLUMN         = 25
              START_ROW            = 6
              CANCEL_DISPLAY       = 'X'
                    IMPORTING
                      answer               = wf_res.
    *--IF THE USER CONFIRMS 'YES',
            IF wf_res = 'J'.
              PERFORM f_modify_activity.
              CALL METHOD grid1->refresh_table_display.
           PERFORM SENDINGMAIL.
            ENDIF.
        ENDCASE.
      ENDMETHOD.                           "handle_user_command
    ENDCLASS.                    "lcl_event_receiver IMPLEMENTATION
    MODULE pbo_100 OUTPUT
    MODULE pbo_100 OUTPUT.
      SET PF-STATUS 'MAIN100'.
      SET TITLEBAR 'MAIN100'.
      w_repid = sy-repid.
      IF custom_container1 IS INITIAL.
    *get the data from charge back table
        PERFORM select_table_chb.
    create a custom container control for our ALV Control
        CREATE OBJECT custom_container1
            EXPORTING
                container_name = cont_on_main
            EXCEPTIONS
                cntl_error = 1
                cntl_system_error = 2
                create_error = 3
                lifetime_error = 4
                lifetime_dynpro_dynpro_link = 5.
        IF sy-subrc NE 0.
    add your handling, for example
          CALL FUNCTION 'POPUP_TO_INFORM'
            EXPORTING
              titel = w_repid
              txt2  = sy-subrc
              txt1  = 'The control could not be created'(510).
        ENDIF.
        CREATE OBJECT grid1
                  EXPORTING i_parent = custom_container1.
    Set a titlebar for the grid control
        wf_layout-grid_title = 'Charge Back'(100).
    allow to select multiple lines
        wf_layout-sel_mode = 'C'.
        wf_layout-stylefname = 'CELLTAB'.
    Exclude all edit functions in this example since we do not need them:
        PERFORM exclude_tb_functions CHANGING lt_exclude.
        CALL METHOD grid1->set_table_for_first_display
                   EXPORTING
                I_BUFFER_ACTIVE               =
                I_CONSISTENCY_CHECK           =
                I_STRUCTURE_NAME              =
                IS_VARIANT                    =
                I_SAVE                        =
                I_DEFAULT                     = 'X'
                     is_layout                     = wf_layout
                IS_PRINT                      =
                IT_SPECIAL_GROUPS             =
                  it_toolbar_excluding          = lt_exclude
                IT_HYPERLINK                  =
                IT_ALV_GRAPHICS               =
              CHANGING
                it_outtab                     = int_crb[]
                it_fieldcatalog               = gt_fieldcatalog.
        CREATE OBJECT event_receiver.
        SET HANDLER event_receiver->handle_user_command FOR grid1.
        SET HANDLER event_receiver->handle_toolbar FOR grid1.
        CALL METHOD grid1->set_toolbar_interactive.
      ENDIF.                               "IF grid1 IS INITIAL
      CALL METHOD cl_gui_control=>set_focus
        EXPORTING
          control = grid1.
    ENDMODULE.                    "pbo_100 OUTPUT
    MODULE pai_100 INPUT
    MODULE pai_100 INPUT.
      CASE ok_code.
        WHEN 'EXIT'.
          PERFORM f_clear_fields.
          LEAVE PROGRAM.
        WHEN 'CANCEL'.
          PERFORM f_clear_fields.
          LEAVE TO SCREEN 0.
        WHEN 'BACK'.
          PERFORM f_clear_fields.
          LEAVE TO SCREEN 0.
      ENDCASE.
      CLEAR ok_code.
    ENDMODULE.                    "pai_100 INPUT
    **&      Form  select_table_chb
          text
    FORM select_table_chb.
      IF p_cash = 'X'.
    *Consider the pending documents also.
    *get the documents which are not processed yet,
    *Doctype -> 06 = Charge Back document type.
        SELECT zmpets_shiphdrpernr pa0002vorna
         zmpets_shiphdrmovreason zmpets_chargebkshipdocnum
         zmpets_chargebkcreatedon zmpets_chargebkchargeamount
         zmpets_shipactivversion zmpets_shipactivactivity
    zmpets_shiphdr~vendor
       adr6~smtp_addr
    zmpets_167doc~empperid
                 INTO CORRESPONDING FIELDS OF TABLE int_crb_ver
                 FROM zmpets_chargebk
                 JOIN zmpets_shiphdr
               ON zmpets_chargebkshipdocnum = zmpets_shiphdrshipdocno
                 JOIN zmpets_shipactiv
         ON zmpets_chargebkshipdocnum = zmpets_shipactivpetsdocnumber
                 JOIN pa0002
                 ON zmpets_shiphdrpernr = pa0002pernr
                    JOIN lfa1
                    ON lfa1lifnr = zmpets_shiphdrvendor
                    JOIN adr6
                    ON adr6addrnumber = lfa1adrnr
                 JOIN zmpets_167doc
                 ON zmpets_167docpernr = pa0002pernr
                           WHERE zmpets_shipactiv~doctype = '06'
                        zmpets_shipactiv~activity NE '30'
                      ZMPETS_CHARGEBK~CREATEDON IN s_chdate
                      AND ZMPETS_SHIPHDR~pernr IN s_pernr
                      AND ZMPETS_SHIPHDR~MOVREASON IN s_mvrsn
                      AND ZMPETS_CHARGEBK~SHIPDOCNUM IN s_sin
                           AND zmpets_chargebk~loekz NE 'X'
                           AND zmpets_shipactiv~loekz NE 'X'
                           AND zmpets_shiphdr~loekz NE 'X'.
        IF sy-subrc <> 0.
    *Message is 'No Pending Documents Available.'.
          MESSAGE s196(zm050).
        ELSE.
          LOOP AT int_crb_ver.
    *Not yet processed. set to red
            int_crb_ver-icon = '@0A@'.
            MODIFY int_crb_ver.
          ENDLOOP.
          PERFORM f_filter_data_pending.
        ENDIF.
      ELSE.
    *Get the document details from pa0002,zmpets_shipactiv,ZMPETS_CHARGEBK
    *table.
    *Consider document type as '01'  during the selection.
    *Doctype -> 06 = Charge Back document type.
        SELECT zmpets_shiphdrpernr pa0002vorna zmpets_shiphdr~movreason
        zmpets_chargebkshipdocnum zmpets_chargebkcreatedon
    zmpets_chargebkchargeamount zmpets_shipactivversion
    zmpets_shipactivactivity zmpets_shiphdrvendor
    *adr6~smtp_addr
    zmpets_167doc~empperid
                 INTO CORRESPONDING FIELDS OF TABLE int_crb_ver
                 FROM zmpets_chargebk
                 JOIN zmpets_shiphdr
                 ON zmpets_chargebkshipdocnum = zmpets_shiphdrshipdocno
                 JOIN zmpets_shipactiv
           ON zmpets_chargebkshipdocnum = zmpets_shipactivpetsdocnumber
                 JOIN pa0002
                 ON zmpets_shiphdrpernr = pa0002pernr
                JOIN lfa1
                    ON lfa1lifnr = zmpets_shiphdrvendor
                    JOIN adr6
                    ON adr6addrnumber = lfa1adrnr
                     JOIN zmpets_167doc
                     ON zmpets_167docpernr = pa0002pernr
                           WHERE zmpets_chargebk~createdon IN s_chdate
                           AND zmpets_shiphdr~pernr IN s_pernr
                           AND zmpets_shiphdr~movreason IN s_mvrsn
                           AND zmpets_chargebk~shipdocnum IN s_sin
                          AND zmpets_shipactiv~activity NE '30'
                           AND zmpets_shipactiv~doctype = '06'
                           AND zmpets_chargebk~loekz NE 'X'
                           AND zmpets_shipactiv~loekz NE 'X'
                           AND zmpets_shiphdr~loekz NE 'X'.
        IF sy-subrc <> 0.
    *Message is 'No Charge Back Documents Available.'.
          MESSAGE s201(zm050).
        ELSE.
          PERFORM f_filter_data.
        ENDIF.
      ENDIF.
    ENDFORM.                    "select_table_chb
    *&      Form  UPDATE_RECORDS
          text
    -->  p1        text
    <--  p2        text
    FORM update_records TABLES p_et_index_rows
                                    STRUCTURE lvc_s_row.
      DATA: ls_selected_line LIKE lvc_s_row,
              lf_row_index TYPE lvc_index.
      LOOP AT p_et_index_rows INTO ls_selected_line.
        lf_row_index = ls_selected_line-index.
      ENDLOOP.
    ENDFORM.                    " UPDATE_RECORDS
    **&      Form  fieldcatalog_init
          text
         -->P_GT_FIELDCATALOG[]  text
    FORM fieldcatalog_init  USING lt_fieldcatalog TYPE lvc_t_fcat.
      DATA: ls_fieldcatalog TYPE lvc_s_fcat.
      CLEAR ls_fieldcatalog.
      ls_fieldcatalog-fieldname = 'SEL'.
      ls_fieldcatalog-tabname  = 'INT_CRB'.
      ls_fieldcatalog-datatype = 'C'.
      ls_fieldcatalog-col_pos  = 1.
      ls_fieldcatalog-edit     = 'X'.
      ls_fieldcatalog-reptext  = 'Select for Processing'.
      ls_fieldcatalog-coltext  = 'Select for Processing'.
      ls_fieldcatalog-seltext  = 'Select for Processing'.
      ls_fieldcatalog-tooltip  = 'Select for Processing'.
      ls_fieldcatalog-checkbox = 'X'.
      ls_fieldcatalog-key = 'X'.
      APPEND ls_fieldcatalog TO lt_fieldcatalog.
      CLEAR ls_fieldcatalog.
      ls_fieldcatalog-fieldname = 'ICON'.
      ls_fieldcatalog-tabname   = 'INT_CRB'.
      ls_fieldcatalog-datatype  = 'CHAR'.
      ls_fieldcatalog-col_pos    = 2.
      ls_fieldcatalog-intlen     = '4'.
      ls_fieldcatalog-reptext   =  'Status'.
      ls_fieldcatalog-coltext   =  'Status'.
      ls_fieldcatalog-seltext   =  'Status'.
      ls_fieldcatalog-tooltip   =  'Status'.
      APPEND ls_fieldcatalog TO lt_fieldcatalog.
      CLEAR ls_fieldcatalog.
      ls_fieldcatalog-fieldname = 'PERNR'.
      ls_fieldcatalog-tabname   = 'INT_CRB'.
      ls_fieldcatalog-datatype  = 'NUMC'.
      ls_fieldcatalog-col_pos   = 2.
      ls_fieldcatalog-intlen    = '8'.
      ls_fieldcatalog-reptext   =  'Employee Number'.
      ls_fieldcatalog-coltext   =  'Employee Number'.
      ls_fieldcatalog-seltext   =  'Employee Number'.
      ls_fieldcatalog-tooltip   =  'Employee Number'.
      ls_fieldcatalog-key = 'X'.
      APPEND ls_fieldcatalog TO lt_fieldcatalog.
      CLEAR ls_fieldcatalog.
      ls_fieldcatalog-fieldname  = 'VORNA'.
      ls_fieldcatalog-tabname    = 'INT_CRB'.
      ls_fieldcatalog-col_pos    =  3 .
      ls_fieldcatalog-datatype   = 'CHAR'.
      ls_fieldcatalog-outputlen      = '20'.
      ls_fieldcatalog-reptext    = 'Employee Name'.
      ls_fieldcatalog-coltext    = 'Employee Name'.
      ls_fieldcatalog-seltext    = 'Employee Name'.
      ls_fieldcatalog-tooltip    = 'Employee Name'.
    ls_fieldcatalog-key      = 'X'.
      APPEND ls_fieldcatalog TO lt_fieldcatalog.
      CLEAR ls_fieldcatalog.
      ls_fieldcatalog-fieldname  = 'MOVREASON'.
      ls_fieldcatalog-tabname    = 'INT_CRB'.
      ls_fieldcatalog-col_pos    =  4.
      ls_fieldcatalog-datatype   = 'NUMC'.
      ls_fieldcatalog-outputlen  = '10'.
      ls_fieldcatalog-reptext    = 'Move Reason'.
      ls_fieldcatalog-coltext    = 'Move Reason'.
      ls_fieldcatalog-seltext    = 'Move Reason'.
      ls_fieldcatalog-tooltip    = 'Move Reason'.
    ls_fieldcatalog-key      = 'X'.
      APPEND ls_fieldcatalog TO lt_fieldcatalog.
      CLEAR ls_fieldcatalog.
      ls_fieldcatalog-fieldname = 'SHIPDOCNUM'.
      ls_fieldcatalog-tabname   = 'INT_CRB'.
      ls_fieldcatalog-datatype  = 'NUMC'.
      ls_fieldcatalog-outputlen = '10'.
      ls_fieldcatalog-col_pos   =  5.
      ls_fieldcatalog-reptext   = 'Shipping Document Number'.
      ls_fieldcatalog-coltext   = 'Shipping Document Number'.
      ls_fieldcatalog-seltext   = 'Shipping Document Number'.
      ls_fieldcatalog-tooltip   = 'Shipping Document Number'.
    ls_fieldcatalog-key = 'X'.
      APPEND ls_fieldcatalog TO lt_fieldcatalog.
      CLEAR ls_fieldcatalog.
      ls_fieldcatalog-fieldname = 'CREATEDON'.
      ls_fieldcatalog-tabname   = 'INT_CRB'.
      ls_fieldcatalog-col_pos   = 6.
      ls_fieldcatalog-datatype  = 'DATS'.
      ls_fieldcatalog-outputlen = '8'.
      ls_fieldcatalog-reptext   = 'Created On'.
      ls_fieldcatalog-coltext   = 'Created On'.
      ls_fieldcatalog-seltext   = 'Created On'.
      ls_fieldcatalog-tooltip   = 'Created On'.
    ls_fieldcatalog-DO_sum      = 'X'.
      APPEND ls_fieldcatalog TO lt_fieldcatalog.
      CLEAR ls_fieldcatalog.
      ls_fieldcatalog-fieldname = 'CHARGEAMOUNT'.
      ls_fieldcatalog-tabname   = 'INT_CRB'.
      ls_fieldcatalog-col_pos   = 7.
      ls_fieldcatalog-datatype  = 'CURR'.
      ls_fieldcatalog-outputlen = '13'.
      ls_fieldcatalog-reptext   = 'Charge Back Amount'.
      ls_fieldcatalog-coltext   = 'Charge Back Amount'.
      ls_fieldcatalog-seltext   = 'Charge Back Amount'.
      ls_fieldcatalog-tooltip   = 'Charge Back Amount'.
    ls_fieldcatalog-DO_sum      = 'X'.
      APPEND ls_fieldcatalog TO lt_fieldcatalog.
      CLEAR ls_fieldcatalog.
    ENDFORM.                    "fieldcatalog_init
    *&      Form  f_modify_activity
    Modify the activity to 79 in zmpets_shipaciv table.
    -->  p1        text
    <--  p2        text
    FORM f_modify_activity .
      REFRESH int_crb_mail.
      int_crb_mail[] = int_crb[].
    *All the document number which is to be processed is stored in
    *the internel table 'INT_SIN'.
      LOOP AT int_crb INTO int_crb.
        IF int_crb-sel ='X'.
          MOVE int_crb-shipdocnum TO int_sin.
          APPEND int_sin.
          CLEAR int_sin.
    *Removing the processed documents.
          DELETE int_crb.
        ENDIF.
        CLEAR int_crb.
      ENDLOOP.
    *Get the details from shipactiv table.
      IF int_sin[] IS NOT INITIAL.
        SELECT * FROM zmpets_shipactiv
            INTO TABLE int_shipactiv
              FOR ALL ENTRIES IN int_sin
                    WHERE petsdocnumber = int_sin-shipdocnum.
    *Modify the activity code, version, actual date and last changed date.
        SORT int_shipactiv BY petsdocnumber version DESCENDING.
        CLEAR wf_tabix.
        LOOP AT int_shipactiv.
          wf_tabix = sy-tabix.
          AT NEW petsdocnumber.
            READ TABLE int_shipactiv INDEX wf_tabix.
            int_shipactiv-activity = '030'.
            int_shipactiv-version = int_shipactiv-version + 1.
            int_shipactiv-actdate = sy-datum.
            int_shipactiv-lastchangedby = sy-uname.
            int_shipactiv-lastchangedt = sy-datum.
    *Modify the data base table
            MODIFY zmpets_shipactiv FROM int_shipactiv.
          ENDAT.
          CLEAR int_shipactiv.
          AT LAST.
    *Message is 'Data Processed Successfully.'.
            MESSAGE s203(zm050).
          ENDAT.
        ENDLOOP.
    *-send mail to the vendor and employee that the shipment is cleared for
        LOOP AT int_crb_mail WHERE sel = 'X'.
          PERFORM f_send_mail.
        ENDLOOP.
        REFRESH int_crb_mail.
       CALL SELECTION-SCREEN 1000.
      ELSE.
    *Message is 'No Data Selected for Processing.'.
        MESSAGE s200(zm050).
      ENDIF.
    ENDFORM.                    " f_modify_activity
    *&      Form  f_clear_fields
          text
    -->  p1        text
    <--  p2        text
    FORM f_clear_fields .
      CLEAR int_crb.
      CLEAR int_crb_ver.
      CLEAR int_sin.
      REFRESH int_crb.
      REFRESH int_crb_ver.
      REFRESH int_sin.
      CLEAR int_shipactiv.
      REFRESH int_shipactiv.
      CLEAR wf_flag.
      CLEAR wf_tabix.
    ENDFORM.                    " f_clear_fields
    *&      Form  f_filter_data
          text
    -->  p1        text
    <--  p2        text
    FORM f_filter_data .
    *Take the latest Version Data.
    *take all the activities, including the activity '30'.
    then put the details in internal table 'INT_CRB'.
      SORT int_crb_ver BY shipdocnum version DESCENDING.
      CLEAR wf_tabix.
      CLEAR int_crb.
      REFRESH int_crb.
      LOOP AT int_crb_ver.
        wf_tabix = sy-tabix.
        AT NEW shipdocnum.
          READ TABLE int_crb_ver INDEX wf_tabix.
          MOVE-CORRESPONDING int_crb_ver TO int_crb.
          APPEND int_crb.
          CLEAR int_crb.
        ENDAT.
      ENDLOOP.
      IF int_crb[] IS INITIAL.
    *Message is 'No Records Available.'.
        MESSAGE s202(zm050).
      ELSE.
        CLEAR wf_tabix.
        LOOP AT int_crb.
          wf_tabix = sy-tabix.
          REFRESH lt_celltab.
          ls_celltab-fieldname = 'SEL'.
          IF int_crb-activity = '030'.
            ls_celltab-style = cl_gui_alv_grid=>mc_style_disabled.
    *status becomes green. ie processed
            int_crb-icon = '@08@'. "Green
          ELSE.
            ls_celltab-style = cl_gui_alv_grid=>mc_style_enabled.
    *status set to red. ie not yet processed
            int_crb-icon = '@0A@'. "Red
          ENDIF.
          INSERT ls_celltab INTO TABLE lt_celltab.
          INSERT LINES OF lt_celltab INTO TABLE int_crb-celltab.
          MODIFY int_crb INDEX wf_tabix.
        ENDLOOP.
      ENDIF.
    ENDFORM.                    " f_filter_data
    *&      Form  f_filter_data
          text
    -->  p1        text
    <--  p2        text
    FORM f_filter_data_pending.
    *Take the latest Version Data.
    *take all the activities, including the activity '30'.
    *then filter it with out the activities '30' and having the lastest
    *version. then put the details in internal table 'INT_CRB'.
      SORT int_crb_ver BY shipdocnum version DESCENDING.
      CLEAR wf_tabix.
      CLEAR int_crb.
      REFRESH int_crb.
      LOOP AT int_crb_ver.
        wf_tabix = sy-tabix.
        AT NEW shipdocnum.
          READ TABLE int_crb_ver INDEX wf_tabix.
          IF int_crb_ver-activity NE '030'.
            MOVE-CORRESPONDING int_crb_ver TO int_crb.
            APPEND int_crb.
            CLEAR int_crb.
          ENDIF.
        ENDAT.
      ENDLOOP.
      IF int_crb[] IS INITIAL.
    *Message is 'No Records Available.'.
        MESSAGE s202(zm050).
      ENDIF.
    ENDFORM.                    " f_filter_data_pending
    *&      Form  EXCLUDE_TB_FUNCTIONS
          text
         <--P_LT_EXCLUDE  text
    FORM exclude_tb_functions CHANGING pt_exclude TYPE ui_functions.
      DATA ls_exclude TYPE ui_func.
      ls_exclude = cl_gui_alv_grid=>mc_fc_loc_copy_row.
      APPEND ls_exclude TO pt_exclude.
      ls_exclude = cl_gui_alv_grid=>mc_fc_loc_delete_row.
      APPEND ls_exclude TO pt_exclude.
      ls_exclude = cl_gui_alv_grid=>mc_fc_loc_append_row.
      APPEND ls_exclude TO pt_exclude.
      ls_exclude = cl_gui_alv_grid=>mc_fc_loc_insert_row.
      APPEND ls_exclude TO pt_exclude.
      ls_exclude = cl_gui_alv_grid=>mc_fc_loc_move_row.
      APPEND ls_exclude TO pt_exclude.
      ls_exclude = cl_gui_alv_grid=>mc_fc_loc_copy.
      APPEND ls_exclude TO pt_exclude.
      ls_exclude = cl_gui_alv_grid=>mc_fc_loc_cut.
      APPEND ls_exclude TO pt_exclude.
      ls_exclude = cl_gui_alv_grid=>mc_fc_loc_paste.
      APPEND ls_exclude TO pt_exclude.
      ls_exclude = cl_gui_alv_grid=>mc_fc_loc_paste_new_row.
      APPEND ls_exclude TO pt_exclude.
      ls_exclude = cl_gui_alv_grid=>mc_fc_loc_undo.
      APPEND ls_exclude TO pt_exclude.
    ENDFORM.                               " EXCLUDE_TB_FUNCTIONS
    *&      Form  f_send_mail
          text
    -->  p1        text
    <--  p2        text
    FORM f_send_mail .
    *store the vendor name, vendor email id , employee name and employee
    *email id in the internal table int_crb
    Creation of the document to be sent
      CLEAR doc_chng.
      REFRESH objpack.
      REFRESH objhead.
      REFRESH  reclist.
      REFRESH objtxt.
    File Name
      doc_chng-obj_name = 'SHIPMENT'.
    Mail Subject
      CONCATENATE 'Shipment Document No.' int_crb_mail-shipdocnum
      'Cleared.'
      INTO doc_chng-obj_descr SEPARATED BY ' '.
    Mail Contents
      objtxt-line = 'Hi,'.
      APPEND objtxt.
      objtxt-line = ' '.
      APPEND objtxt.
      CONCATENATE 'Shipment Document Number ' int_crb_mail-shipdocnum
    ' cleared for move.' INTO objtxt-line SEPARATED BY ' '.
      APPEND objtxt.
      objtxt-line = ' '.
      APPEND objtxt.
      CLEAR  objtxt.
      objtxt-line = 'Regards '.
      APPEND objtxt.
      objtxt-line = ' '.
      APPEND objtxt.
      objtxt-line = 'SAP '.
      APPEND objtxt.
      CLEAR  objtxt.
      APPEND objtxt.
      DESCRIBE TABLE objtxt LINES tab_lines.
      READ TABLE objtxt INDEX tab_lines.
      doc_chng-doc_size = ( tab_lines - 1 ) * 255 + STRLEN(
    objtxt ).
    Creation of the entry for the compressed document
      CLEAR objpack-transf_bin.
      objpack-head_start = 1.
      objpack-head_num = 0.
      objpack-body_start = 1.
      objpack-body_num = tab_lines.
      objpack-doc_type = 'RAW'.
      APPEND objpack.
    Completing the recipient list
    target recipent
      CLEAR reclist.
      reclist-receiver = int_crb_mail-empperid. "employee email ID
      "wf_empperid.
      reclist-express  = 'X'.
      reclist-rec_type = 'U'.
      APPEND reclist.
    copy recipents
    CLEAR reclist.
    reclist-receiver = 'anversha.shahul@'."int_crb_mail-smtp_addr
    reclist-express  = 'X'.
    reclist-rec_type = 'U'.
    reclist-copy     = 'X'.
    APPEND reclist.
    Sending the document
      CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
        EXPORTING
          document_data              = doc_chng
        TABLES
          packing_list               = objpack
          object_header              = objhead
       contents_bin               = objbin
          contents_txt               = objtxt
          receivers                  = reclist
        EXCEPTIONS
          too_many_receivers         = 1
          document_not_sent          = 2
          operation_no_authorization = 4
          OTHERS                     = 99.
      COMMIT WORK.
      SUBMIT rsconn01
                    WITH mode = 'INT'
                    WITH output = ' '
                      AND RETURN.
    ENDFORM.                    " f_send_mail
    rgds
    anver
    pls mark hlpful answers

  • Add Button with ALV  Standard Toolbar.

    Hi,
    Can any one tell me how to add user-defined button with ALV
    Standard toolbar? When I add Pf-status for alv output , standard alv toolbar is not displayed.
    Plz do needful.

    On the toolbar event of your alv grid, all the button as shown in the code below.
    FORM handle_toolbar USING i_object TYPE REF TO cl_alv_event_toolbar_set .
    DATA: ls_toolbar TYPE stb_button.
    CLEAR ls_toolbar.
    MOVE 'EXCH' TO ls_toolbar-function. "#EC NOTEXT
    MOVE 2 TO ls_toolbar-butn_type.
    MOVE icon_calculation TO ls_toolbar-icon.
    MOVE 'Payment in Other Currencies'(202) TO ls_toolbar-quickinfo.
    MOVE ' ' TO ls_toolbar-text.
    MOVE ' ' TO ls_toolbar-disabled. "#EC NOTEXT
    APPEND ls_toolbar TO i_object->mt_toolbar.
    ENDFORM
    CLASS lcl_event_handler DEFINITION .
    PUBLIC SECTION .
    METHODS:
    *To add new functional buttons to the ALV toolbar
    handle_toolbar FOR EVENT toolbar OF cl_gui_alv_grid
    IMPORTING e_object e_interactive ,
    ENDCLASS.
    CLASS lcl_event_handler IMPLEMENTATION .
    *Handle Toolbar
    METHOD handle_toolbar.
    PERFORM handle_toolbar USING e_object e_interactive .
    ENDMETHOD .
    ENDCLASS.
    DATA gr_event_handler TYPE REF TO lcl_event_handler .
    *--Creating an instance for the event handler
    CREATE OBJECT gr_event_handler .
    *--Registering handler methods to handle ALV Grid events
    SET HANDLER gr_event_handler->handle_toolbar FOR gr_alvgrid .
    Hope this helps.
    Thanks,
    Balaji

  • Custom Button in ALV Grid standard toolbar

    Hello Experts,
    I am working on the program in which i have to add custom button to standard toolbar in ALV. I have created the button using the method as below
         data: lr_functions type ref to cl_salv_functions_list.
         lr_functions = gr_table->get_functions( ).
         lr_functions->set_default( abap_true ).
         data: l_text       type string,
               l_icon       type string.
    *    l_text = text-b01.
         l_icon = icon_complete.
         try.
           lr_functions->add_function(
             name     = 'Update Equipment Cost'
             icon     = l_icon
             text     = l_text
             tooltip  = 'Update Equipment Cost'
             position = if_salv_c_function_position=>right_of_salv_functions ).
           catch cx_salv_existing cx_salv_wrong_call.
         endtry.
    I don't understand how to add functionality to this button. I want to design the functionality as when user press button then corresponding values on the screen will be automatically get updated in the table.
    Thanks,
    Avadhut

    Hi Avadhut,
    When you want to add a custom button on ALV - better copy the GUI Status of the standard ALV to your program.  So all the function codes are copied , now you can go to the GUI_STATUS which is copied and you can mention your own function code or you can let the standard function codes as it is. You can copy the GUI of standard ALV from SE80 transaction. Let me know if you need any assistance in doing it.
    Now, if you want to write the code for any of the button on ALV -  then you need to handle it is the class.
    I used CL_SALV_TABLE - if you are using same then the below code gives you an idea of it.
    1. Create a local class in your program
    *       CLASS lcl_alv_events DEFINITION
    CLASS lcl_alv_events DEFINITION FINAL.
       PUBLIC SECTION.
         METHODS: on_user_command FOR EVENT added_function OF cl_salv_events
                                  IMPORTING e_salv_function.
    ENDCLASS.                    "lcl_alv_events DEFINITION
    DATA: gv_event_handler TYPE REF TO lcl_alv_events.
    CREATE OBJECT gv_event_handler.
    * Header object
    CREATE OBJECT gr_header.
    2. Class Implementation
       CLASS lcl_alv_events IMPLEMENTATION.
          METHOD on_user_command.
         CASE e_salv_function.
         **When PROCESS Button is selected
           WHEN '&PROC'.    ***> In my program I added Process button and fcode for it - &PROC
          ***********Write your code here ******************
        ENDCASE.
       ENDMETHOD.
    ENDCLASS.                    "lcl_alv_events IMPLEMENTATION
    3. Calling events
       data: gr_events    TYPE REF TO cl_salv_events_table,
               gr_alv       TYPE REF TO cl_salv_table.
       TRY.
           CALL METHOD cl_salv_table=>factory
             IMPORTING
               r_salv_table = gr_alv
             CHANGING
               t_table      = p_in_tab[].    ***This is my internal table data.
          gr_events = gr_alv->get_event( ).
             SET HANDLER gv_event_handler->on_user_command FOR gr_events.
         CATCH cx_salv_msg INTO lv_msg.                      "#EC NO_HANDLER
         CATCH cx_salv_not_found INTO lv_excep.              "#EC NO_HANDLER
         CATCH cx_salv_data_error.                           "#EC NO_HANDLER
       ENDTRY.
    Regards,
    Rafi

  • ALV List Standard toolbar

    How to display standard toolbar buttons in ALV which are not displayed in REUSE_ALV_GRID_DISPLAY

    HI
    GOOD
    GO THROUGH THIS REPORT
    TYPE-POOLS: SLIS.
    DATA: FIELDCAT           TYPE SLIS_T_FIELDCAT_ALV,
          FIELDCAT_LN        LIKE LINE OF FIELDCAT,
          SORTCAT            TYPE SLIS_T_SORTINFO_ALV,
          SORTCAT_LN         LIKE LINE OF SORTCAT,
          EVENTCAT           TYPE SLIS_T_EVENT,
          EVENTCAT_LN        LIKE LINE OF EVENTCAT,
          LAYOUT             TYPE SLIS_LAYOUT_ALV,
          C_TOP_OF_PAGE      TYPE SLIS_FORMNAME VALUE 'TOP_OF_PAGE',
          W_LIST_TOP_OF_PAGE TYPE SLIS_T_LISTHEADER.
    DATA: COL_POS TYPE I,
          P_LIGNAM TYPE SLIS_FIELDNAME VALUE  'STATUS'.
    ******Declare Data Areas for List Viewer (End)**************
    Other Variables
    DATA: W_DATUM(10) TYPE C. "Convert system Date for Output
    ******Declare Internal Table to Store Selected Data (Begin)*
    DATA: BEGIN OF IREPO OCCURS   0,
            EQUNR LIKE EQUI-EQUNR,
            EQKTX LIKE EQKT-EQKTX, "description
            ERDAT LIKE EQUI-ERDAT,
            ERNAM LIKE EQUI-ERNAM,
            AEDAT LIKE EQUI-AEDAT,
            AENAM LIKE EQUI-AENAM,
            EQART LIKE EQUI-EQART,
            INBDT LIKE EQUI-INBDT,
            ZZ_DESPATCH LIKE EQUI-ZZ_DESPATCH,
            ( ten million other Z fields)
            VKBUR LIKE ILOA-VKBUR, "Sales Office
            SWERK LIKE ILOA-SWERK, "Base Plant
            KOSTL LIKE ILOA-KOSTL, "Cost Centre
            ANLNR LIKE ITOB-ANLNR, "Asset Number
            NAME1 LIKE LFA1-NAME1, "Haulier name
            STATUS TYPE C,         "Is it flagged for deletion?
          END OF IREPO.
    Table for descriptions
    DATA: BEGIN OF IEQKT OCCURS 0,
            EQUNR LIKE EQKT-EQUNR,
            EQKTX LIKE EQKT-EQKTX,
          END OF IEQKT.
    LOD Names - Internal Buffering
    DATA: BEGIN OF VENDLIST OCCURS 0,
             LIFNR LIKE LFA1-LIFNR, "Vendor Number
             NAME1 LIKE LFA1-NAME1, "Vendor Name
          END OF VENDLIST.
    ******Declare Internal Table to Store Selected Data (End)**
    TABLES: EQUI,ILOA.
    *******Selection Screen
    SELECTION-SCREEN BEGIN OF BLOCK BLK1 WITH FRAME TITLE TEXT-001.
    SELECT-OPTIONS: P_EQUNR FOR EQUI-EQUNR,       "Fleet Number
                    P_PLATE FOR EQUI-ZZ_PLATE_NO, "Registration
                    P_EQART FOR EQUI-EQART.       "Truck Type
    PARAMETER: EXCLUDE AS CHECKBOX.               "Exclude Deleted Trucks
    SELECTION-SCREEN END OF BLOCK BLK1.
    SELECTION-SCREEN BEGIN OF BLOCK BLK2 WITH FRAME TITLE TEXT-002.
    SELECT-OPTIONS: P_DESPG    FOR EQUI-ZZ_DESPATCH, "Dgroup
                    P_VKBUR    FOR ILOA-VKBUR,       "Sales Office
                    P_SWERK    FOR ILOA-SWERK.       "Plant
    SELECTION-SCREEN END OF BLOCK BLK2.
    SELECTION-SCREEN BEGIN OF BLOCK BLK3 WITH FRAME TITLE TEXT-003.
    SELECT-OPTIONS: P_HAULER FOR EQUI-ZZ_HAULER.    "Haulier Vendor
    SELECTION-SCREEN END OF BLOCK BLK3.
    *******Select Data into Internal Table (Begin) ***************
    START-OF-SELECTION.
       CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
            EXPORTING
                 TEXT       = 'Reading Truck Master Table' .
    SELECT EQUIEQUNR EQUIEQART EQUIERNAM EQUIERDAT EQUI~AENAM
           EQUIAEDAT EQUIINBDT
            EQUI~ZZ_DESPATCH
            ( ten million custom Z fields )
            EQUI~ZZ_TIMEZONE
           ILOAVKBUR ILOASWERK ILOA~KOSTL
           INTO CORRESPONDING FIELDS OF TABLE IREPO
              FROM ( EQUI INNER JOIN EQUZ ON
                    EQUIEQUNR = EQUZEQUNR )
                  INNER JOIN ILOA ON
                    EQUZILOAN = ILOAILOAN
           WHERE EQUI~EQUNR       IN P_EQUNR "Fleet Number
           AND   EQUI~EQART       IN P_EQART "Truck Type
           AND   EQUI~ZZ_PLATE_NO IN P_PLATE "Registration
           AND   EQUI~ZZ_DESPATCH IN P_DESPG "Despatch Group
           AND   EQUI~ZZ_HAULER   IN P_HAULER"Vendor
           AND   ILOA~SWERK       IN P_SWERK "Plant
           AND   ILOA~VKBUR       IN P_VKBUR."Sales Office
    If successful go and get the descriptions
        IF SY-SUBRC EQ 0.
           CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
                EXPORTING
                TEXT       = 'Reading Descriptions' .
           SELECT EQUNR EQKTX FROM EQKT
                  INTO CORRESPONDING FIELDS OF TABLE IEQKT
                  FOR ALL ENTRIES IN IREPO
                  WHERE EQUNR = IREPO-EQUNR
                  AND   SPRAS = 'EN'.
            SORT IEQKT BY EQUNR.
        ENDIF.
       CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
            EXPORTING
                 TEXT       = 'Check For Deletion Flags' .
      DATA: L_EQUNR LIKE EQUI-EQUNR,
            L_OBJNR LIKE JEST-OBJNR.
    LOOP AT IREPO.
        CONCATENATE 'IE' IREPO-EQUNR INTO L_OBJNR.
    Start off by saying that the Truck is OK
        IREPO-STATUS = '3'.
    Now see if the Truck has been flagged as Inactive e.g. under repair
        PERFORM STATUS_CHECK USING L_OBJNR 'I0320'.
        IF SY-SUBRC EQ 0.
           IREPO-STATUS = '2'. "It's inactive
        ENDIF.
    Now see if the Truck has been flagged for deletion.
        PERFORM STATUS_CHECK USING L_OBJNR 'I0076'.
        IF SY-SUBRC EQ 0.
           IREPO-STATUS = '1'. "It's deleted
        ENDIF.
    MODIFY IREPO.
    CLEAR  IREPO.
    ENDLOOP.
    If exclude is chosen lose deleted items
    IF EXCLUDE = 'X'.
       DELETE IREPO WHERE STATUS = '1'.
    ENDIF.
    Final processing
       CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
            EXPORTING
                 TEXT       = 'Prepare Data for Display' .
      SORT IREPO BY EQUNR.
      LOOP AT IREPO.
    Get Description of Truck
        READ TABLE IEQKT WITH KEY EQUNR = IREPO-EQUNR BINARY SEARCH.
        IF SY-SUBRC EQ 0.
           IREPO-EQKTX = IEQKT-EQKTX.
        ELSE.
           IREPO-EQKTX = 'No Description in Truck Master'.
        ENDIF.
    Get Name of Owner
        READ TABLE VENDLIST WITH KEY LIFNR = IREPO-ZZ_HAULER BINARY SEARCH.
        IF SY-SUBRC NE 0.
           SELECT SINGLE NAME1 FROM LFA1 INTO IREPO-NAME1
                  WHERE LIFNR = IREPO-ZZ_HAULER.
           VENDLIST-LIFNR = IREPO-ZZ_HAULER.
           VENDLIST-NAME1 = IREPO-NAME1.
           APPEND VENDLIST.
           SORT VENDLIST BY LIFNR.
        ELSE.
           IREPO-NAME1 = VENDLIST-NAME1.
        ENDIF.
        MODIFY IREPO.
        CLEAR IREPO.
      ENDLOOP.
    END-OF-SELECTION.
    Select Data into Internal Table (End) ****************
    Build Field Catalogs (Begin)**************************
    Fields with Standard Names
    PERFORM RESETVALUES.
    PERFORM ADDFIELD USING '1' 'EQUI' 'STATUS'. "Traffic Lights
    FIELDCAT_LN-HOTSPOT = 'X'.
    FIELDCAT_LN-KEY     = 'X'.
    PERFORM ADDFIELD USING '2' 'EQUI' 'EQUNR'.  "Fleet Number
    PERFORM ADDFIELD USING '3' 'EQKT' 'EQKTX'.  "Description
    PERFORM ADDFIELD USING '4' 'EQUI' 'ZZ_PLATE_NO'.
    PERFORM ADDFIELD USING '5' 'EQUI' 'EQART'.
    PERFORM ADDFIELD USING '6' 'ILOA' 'SWERK'.
    PERFORM ADDFIELD USING '8' 'ILOA' 'KOSTL'.
    PERFORM ADDFIELD USING '9' 'EQUI' 'ZZ_MINLOADSIZE'.
    PERFORM HIDFIELD USING '10' 'EQUI' 'ERNAM'.
    PERFORM HIDFIELD USING '11' 'EQUI' 'AEDAT'.
    PERFORM HIDFIELD USING '12' 'EQUI' 'AENAM'.
    PERFORM HIDFIELD USING '13' 'EQUI' 'INBDT'.
    ( ten million custom Z fields )
    PERFORM HIDFIELD USING '56' 'EQUI' 'ZZ_TIMEZONE'.
    PERFORM HIDFIELD USING '57' 'ILOA' 'VKBUR'.
    PERFORM HIDFIELD USING '58' 'EQUI' 'ZZ_HAULER'.
    PERFORM HIDFIELD USING '59' 'EQUI' 'ERDAT'.
    Fields with Custom Names
    PERFORM NEWNAME USING 'Haulier Name'.
    FIELDCAT_LN-OUTPUTLEN = '20'.
    PERFORM ADDFIELD USING '7' 'LFA1' 'NAME1'. "Haulier Vendor Name
    PERFORM NEWNAME USING 'Tare Time'.
    PERFORM HIDFIELD USING '54' 'EQUI' 'ZZ_TARE_TIME'.
    PERFORM NEWNAME USING 'Trailer 1'.
    PERFORM HIDFIELD USING '19' 'EQUI' 'ZZ_TRAILER1'.
    PERFORM NEWNAME USING 'Trailer 2'.
    PERFORM HIDFIELD USING '20' 'EQUI' 'ZZ_TRAILER2'.
    PERFORM NEWNAME USING 'Trailer 3'.
    PERFORM HIDFIELD USING '21' 'EQUI' 'ZZ_TRAILER3'.
    Sort Criteria
    PERFORM BUILD_SORTCAT.
    ******Build Event Catalog (Begin)****************************
    PERFORM BUILD_EVENTCAT.
    Magic box for selection criteria & traffic lights for truck status
    PERFORM BUILD_LAYOUT.
    ********Add a header at the top of the report            *******
    PERFORM SET_REPORT_HEADER USING W_LIST_TOP_OF_PAGE[].
    ********Start List Viewer
    PERFORM START_LIST_VIEWER.
    ******Start List Viewer (End)********************************
    ********FORM ROUTINES (Begin)********************************
    Start Values for ALV Field Catalouge
    FORM RESETVALUES.
    FIELDCAT_LN-KEY = SPACE.
    FIELDCAT_LN-DO_SUM = SPACE.
    FIELDCAT_LN-NO_OUT = SPACE.
    FIELDCAT_LN-QFIELDNAME = SPACE.
    FIELDCAT_LN-HOTSPOT = SPACE.
    FIELDCAT_LN-OUTPUTLEN = '0'.
    CLEAR: fieldcat_ln-seltext_l, fieldcat_ln-seltext_m,  
            fieldcat_ln-seltext_s, fieldcat_ln-reptext_ddic.
    ENDFORM.
    Change key values for additional fields
    FORM ADDFIELD USING POSITION TABLE_VALUE FIELD_VALUE.
         FIELDCAT_LN-REF_TABNAME = TABLE_VALUE .
         FIELDCAT_LN-FIELDNAME   = FIELD_VALUE.
         FIELDCAT_LN-COL_POS     = POSITION.
         APPEND FIELDCAT_LN TO FIELDCAT.
         PERFORM RESETVALUES.
    ENDFORM.
    FORM HIDFIELD USING POSITION TABLE_VALUE FIELD_VALUE.
         FIELDCAT_LN-NO_OUT = 'X'.
         FIELDCAT_LN-REF_TABNAME = TABLE_VALUE .
         FIELDCAT_LN-FIELDNAME   = FIELD_VALUE.
         FIELDCAT_LN-COL_POS     = POSITION.
         APPEND FIELDCAT_LN TO FIELDCAT.
         PERFORM RESETVALUES.
    ENDFORM.
    FORM NEWNAME USING NAME.
      FIELDCAT_LN-SELTEXT_L = NAME..
      FIELDCAT_LN-SELTEXT_M = NAME.
      FIELDCAT_LN-SELTEXT_S = NAME.
      FIELDCAT_LN-REPTEXT_DDIC = NAME.
      FIELDCAT_LN-OUTPUTLEN = '10'.
    ENDFORM.
    Sort Criteria
    FORM BUILD_SORTCAT.
    SORTCAT_LN-SPOS = '1'.
    SORTCAT_LN-FIELDNAME = 'EQUNR'. "Truck Number
    SORTCAT_LN-UP = 'X'.
    SORTCAT_LN-DOWN = SPACE.
    SORTCAT_LN-SUBTOT = SPACE.
    APPEND SORTCAT_LN TO SORTCAT.
    ENDFORM.
    FORM BUILD_EVENTCAT.
      EVENTCAT_LN-NAME = C_TOP_OF_PAGE.
      EVENTCAT_LN-FORM = C_TOP_OF_PAGE.
      APPEND EVENTCAT_LN TO EVENTCAT.
    ENDFORM.                               " BUILD_EVENTCAT
    Add an extra button to get an extra button the user can press to
    see what selection criteria they entered
    This info will then appear when the report is printed
    FORM BUILD_LAYOUT.
         LAYOUT-GET_SELINFOS = 'X'.
    Now we want a traffic light to say if the Truck is deleted
    the variable p_lignam contains the name in IREPO which stores the
    value for the traffic light
         LAYOUT-LIGHTS_FIELDNAME = P_LIGNAM.
         LAYOUT-LIGHTS_CONDENSE =  'X'.
    ENDFORM.
    Invoke a custom status (toolbar) in case we want to add any extra
    icons at a later date
    FORM SET_PF_STATUS USING EXTAB TYPE SLIS_T_EXTAB.
      SET PF-STATUS 'STAND' EXCLUDING EXTAB.
    ENDFORM.
    FORM START_LIST_VIEWER.
    DATA: PGM LIKE SY-REPID.
    PGM = SY-REPID.
    CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
         EXPORTING
              I_CALLBACK_PROGRAM       = PGM
              I_CALLBACK_PF_STATUS_SET = 'SET_PF_STATUS'
              I_CALLBACK_USER_COMMAND  = 'USER_COMMAND'
              IS_LAYOUT                = LAYOUT
              IT_FIELDCAT              = FIELDCAT
              IT_SORT                  = SORTCAT
              I_SAVE                   = 'A'
              IT_EVENTS                = EVENTCAT[]
          TABLES
               T_OUTTAB                 = IREPO
          EXCEPTIONS
               PROGRAM_ERROR            = 1
               OTHERS                   = 2.
    ENDFORM.
    *******Process Call Back Events (Begin)**************************
    FORM USER_COMMAND USING UCOMM LIKE SY-UCOMM
                           SELFIELD TYPE SLIS_SELFIELD.
    READ TABLE IREPO INDEX SELFIELD-TABINDEX.
    CHECK SY-SUBRC = 0.
    CASE UCOMM.
    WHEN '&IC1'.
    CASE SELFIELD-SEL_TAB_FIELD.
    WHEN 'IREPO-EQUNR'.
    Set Parameter ID and call ZTM3
    Custom transaction to view Trucks
    SET PARAMETER ID 'EQN' FIELD IREPO-EQUNR.
    CALL TRANSACTION 'ZTM3' AND SKIP FIRST SCREEN.
    ENDCASE.
    ENDCASE.
    ENDFORM.
    *******Process Call Back Events (End)*****************************
    Routine to print out user at the top
    FORM SET_REPORT_HEADER USING LT_TOP_OF_PAGE TYPE SLIS_T_LISTHEADER.
      DATA: LS_LINE TYPE SLIS_LISTHEADER.
      PERFORM CONVERT_DATE.
      CLEAR LS_LINE.
      LS_LINE-TYP  = 'H'.
      LS_LINE-INFO = 'ZT01 : Truck Master Data Report'.
      APPEND LS_LINE TO LT_TOP_OF_PAGE.
      CLEAR LS_LINE.
      LS_LINE-TYP  = 'S'.
      LS_LINE-KEY  = 'Run On :'.
      LS_LINE-INFO = W_DATUM.
      APPEND LS_LINE TO LT_TOP_OF_PAGE.
      LS_LINE-KEY  = 'User Name :'.
      LS_LINE-INFO = SY-UNAME.
      APPEND LS_LINE TO LT_TOP_OF_PAGE.
    ENDFORM.                               " SET_REPORT_HEADER
    FORM CONVERT_DATE.
      CALL FUNCTION 'CONVERT_DATE_TO_EXTERNAL'
           EXPORTING
                DATE_INTERNAL = SY-DATUM
           IMPORTING
                DATE_EXTERNAL = W_DATUM.
    ENDFORM.                               " CONVERT_DATE
    FORM TOP_OF_PAGE.
      CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
           EXPORTING
                IT_LIST_COMMENTARY = W_LIST_TOP_OF_PAGE.
    ENDFORM.                               "TOP_OF_PAGE
    FORM STATUS_CHECK USING OBJNR
                            STATUS.
    This uses reverse logic i.e. subrc = 0 means the status being
    checked (delete / inactive) is active.
    e.g checking for I0076 and subrc = 0 means it's been flagged for
    deletion
      CALL FUNCTION 'STATUS_CHECK'
           EXPORTING
                BYPASS_BUFFER     = 'X'
                OBJNR             = OBJNR
                STATUS            = STATUS
           EXCEPTIONS
                OBJECT_NOT_FOUND  = 1
                STATUS_NOT_ACTIVE = 2
                OTHERS            = 3.
    ENDFORM.                               " STATUS_CHECK
    **********FORM ROUTINES (END)*************************************
    The other thing to note is that below I include a FORM to call a custom
    status (toolbar). I define this in the repositry browser by copying the
    STANDARD status from another ALV report, but you do not need to do this
    unless you want to add some more buttons to the standard toolbar. I now do
    this as a matter of course, as my users tend to want extra buttons e.g.
    'REFRESH'.
    How to add an extra button:-
    Create a new status using the repository browser by copying an existing
    one from an ALV program. Call it something like ZSTANDARD. Then change it by
    adding a new button to the toolbar - give it an icon and a four digit name
    like '&TMP' so the program knows what button the user has pressed.
    (ii) Within your program include a FORM called something like SET_PF_STATUS
    as in my example program below. Make sure the name of this FORM is included
    in the call to the ALV function module, again as in the example below.
    (iii) In the USER_COMMAND form, insert code to deal with the user pressing
    the new button e.g.
    Example of how to deal with users pressing new buttons
    *******Process Call Back Events (Begin)**************************
    FORM user_command USING ucomm LIKE sy-ucomm                        
                           selfield TYPE slis_selfield.                
    CASE ucomm.                                                        
    WHEN '&IC1'.                                                       
    READ TABLE irepo INDEX selfield-tabindex.                          
    CHECK sy-subrc = 0.                                                
    CASE selfield-sel_tab_field.                                       
    WHEN 'IREPO-VBELN'.
         SET PARAMETER ID 'VL' FIELD irepo-vbeln.                      
         CALL TRANSACTION 'VL03' AND SKIP FIRST SCREEN. "Outbound       
    WHEN '&TMP'.                                                       
    We are going to refresh the display so tell the ALV this        
          selfield-refresh = 'X'.                                       
    Isn't that clever!                                              
          PERFORM refresh.  "Subroutine to refresh the screen (for example)
    ENDCASE.                                                            
    ENDFORM.                                                            
    ********Process Call Back Events (End) ****************************
    THANKS
    MRUTYUN

  • How to find function code for buttons on toolbar in oops alv

    Hi experts,
    I want to remove some buttons from toolbar in oops alv, i know the procedure like get function code and pass the value in a table and pass that table to IT_TOOLBAR_EXCLUDING of
    method set_table_for_first_display but I WANT TO KNOW HOW TO FIND FUNCTION CODE FOR BUTTONS ON TOOLBAR IN OOPS ALV

    Hi Prakash,
    -->First you have to set the pf status in your alv program by,
    {FORM pf_status USING rt_extab TYPE slis_t_extab.
      SET PF-STATUS 'FIRST'.
    ENDFORM.                    "PF_STATUS}
    -->Pass this Subroutine name in the Function module, Reuse_alv_grid_display's parameters i.e,
          i_callback_pf_status_set          = 'PF_STATUS'}
    *-->Then doble click on that pf status,
    From the menu bar, select Extras->Adjust Template->List Viewer,
    This will give you the existing statndard gui status of the program*
    ->Then catch that function codes in the User command Parameter of the Function module Reuse.. i.e,
          i_callback_user_command           = 'COMM'
    And make a subroutine of the name 'COMM'i.e,
    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          = ' '
    endcase.
    Hope it helps you
    Regrds
    Mansi

  • Event handling in oops alv

    hi experts,
    event double click.
    when double click  on vbeln it should go to va03 transaction . how would i do that in oops alv.

    hai,
    you can go through code below .
    *& Report  Z_CLARIFY                                                   *
    REPORT  Z_CLARIFY                               .
    DATA: G_GRID TYPE REF TO CL_GUI_ALV_GRID.
    DATA: L_VALID TYPE C,
          V_FLAG,
          V_DATA_CHANGE,
          V_ROW TYPE LVC_S_ROW,
          V_COLUMN TYPE LVC_S_COL,
          V_ROW_NUM TYPE LVC_S_ROID.
    DATA: IT_ROW_NO TYPE LVC_T_ROID,
          X_ROW_NO TYPE LVC_S_ROID.
    DATA:BEGIN OF  ITAB OCCURS 0,
         VBELN LIKE LIKP-VBELN,
         POSNR LIKE LIPS-POSNR,
         CELLCOLOR TYPE LVC_T_SCOL, "required for color
         DROP(10),
         END OF ITAB.
    *The Below Definitions Must.....
    DATA:
    Reference to document
           DG_DYNDOC_ID       TYPE REF TO CL_DD_DOCUMENT,
    Reference to split container
           DG_SPLITTER          TYPE REF TO CL_GUI_SPLITTER_CONTAINER,
    Reference to grid container
           DG_PARENT_GRID     TYPE REF TO CL_GUI_CONTAINER,
    Reference to html container
           DG_HTML_CNTRL        TYPE REF TO CL_GUI_HTML_VIEWER,
    Reference to html container
           DG_PARENT_HTML     TYPE REF TO CL_GUI_CONTAINER.
    "up to here
          CLASS lcl_event_handler DEFINITION
    CLASS LCL_EVENT_HANDLER DEFINITION .
      PUBLIC SECTION .
        METHODS:
    **Hot spot Handler
        HANDLE_HOTSPOT_CLICK FOR EVENT HOTSPOT_CLICK OF CL_GUI_ALV_GRID
                          IMPORTING E_ROW_ID E_COLUMN_ID ES_ROW_NO,
    **Double Click Handler
        HANDLE_DOUBLE_CLICK FOR EVENT DOUBLE_CLICK OF CL_GUI_ALV_GRID
                                         IMPORTING E_ROW E_COLUMN ES_ROW_NO,
        TOP_OF_PAGE FOR EVENT TOP_OF_PAGE              "event handler
                             OF CL_GUI_ALV_GRID
                             IMPORTING E_DYNDOC_ID.
           END_OF_LIST FOR EVENT end_of_list              "event handler
                            OF CL_GUI_ALV_GRID
                            IMPORTING E_DYNDOC_ID.
    ENDCLASS.                    "lcl_event_handler DEFINITION
          CLASS lcl_event_handler IMPLEMENTATION
    CLASS LCL_EVENT_HANDLER IMPLEMENTATION.
    *Handle Hotspot Click
      METHOD HANDLE_HOTSPOT_CLICK .
        CLEAR: V_ROW,V_COLUMN,V_ROW_NUM.
        V_ROW  = E_ROW_ID.
        V_COLUMN = E_COLUMN_ID.
        V_ROW_NUM = ES_ROW_NO.
       MESSAGE I000 WITH V_ROW 'clicked'.
        CLEAR IT_ROW_NO[].
        X_ROW_NO-ROW_ID = V_ROW.
        APPEND X_ROW_NO TO IT_ROW_NO .
        CALL METHOD G_GRID->SET_SELECTED_ROWS
          EXPORTING
            IT_ROW_NO = IT_ROW_NO.
      ENDMETHOD.                    "lcl_event_handler
    *Handle Double Click
      METHOD  HANDLE_DOUBLE_CLICK.
        CLEAR: V_ROW,V_COLUMN,V_ROW_NUM.
        V_ROW  = E_ROW.
        V_COLUMN = E_COLUMN.
        V_ROW_NUM = ES_ROW_NO.
        IF E_COLUMN = 'VBELN'.
          SET PARAMETER ID 'VL' FIELD ITAB-VBELN.
          CALL TRANSACTION 'VL03N' AND SKIP FIRST SCREEN.
        ENDIF.
        IF E_COLUMN = 'POSNR'.
          SET PARAMETER ID 'VL' FIELD ITAB-VBELN.
          CALL TRANSACTION 'VL03N' AND SKIP FIRST SCREEN."
        ENDIF.
      ENDMETHOD.                    "handle_double_click
    METHOD END_OF_LIST.                   "implementation
    Top-of-page event
       PERFORM EVENT_TOP_OF_PAGE USING DG_DYNDOC_ID.
    ENDMETHOD.                            "top_of_page
        METHOD TOP_OF_PAGE.                   "implementation
    Top-of-page event
        PERFORM EVENT_TOP_OF_PAGE USING DG_DYNDOC_ID.
      ENDMETHOD.                            "top_of_page
    ENDCLASS.                    "LCL_EVENT_HANDLER IMPLEMENTATION
    *&             Global Definitions
    DATA:      G_CUSTOM_CONTAINER TYPE REF TO CL_GUI_CUSTOM_CONTAINER,
    "Container1
                G_HANDLER TYPE REF TO LCL_EVENT_HANDLER. "handler
    DATA: OK_CODE LIKE SY-UCOMM,
          SAVE_OK LIKE SY-UCOMM,
          G_CONTAINER1 TYPE SCRFNAME VALUE 'TEST',
          GS_LAYOUT TYPE LVC_S_LAYO.
    data: v_lines type i.
    data: v_line(3) type c.
    *- Fieldcatalog for First and second Report
    DATA: IT_FIELDCAT  TYPE  LVC_T_FCAT,
          X_FIELDCAT TYPE LVC_S_FCAT,
          LS_VARI  TYPE DISVARIANT.
                   START-OF_SELECTION
    START-OF-SELECTION.
      SELECT VBELN
             POSNR
             FROM LIPS
             UP TO 20 ROWS
             INTO CORRESPONDING FIELDS OF TABLE ITAB.
    describe table itab lines v_lines.
    END-OF-SELECTION.
      IF NOT ITAB[] IS INITIAL.
        CALL SCREEN 100.
      ELSE.
       MESSAGE I002 WITH 'NO DATA FOR THE SELECTION'(004).
      ENDIF.
    *&      Form  CREATE_AND_INIT_ALV
          text
    FORM CREATE_AND_INIT_ALV .
      DATA: LT_EXCLUDE TYPE UI_FUNCTIONS.
      "attention.....from here
      "split your container here...into two parts
      "create the container
      CREATE OBJECT G_CUSTOM_CONTAINER
               EXPORTING CONTAINER_NAME = 'SCR100_CUST'.
      "this is for top of page
    Create TOP-Document
      CREATE OBJECT DG_DYNDOC_ID
                       EXPORTING STYLE = 'ALV_GRID'.
    Create Splitter for custom_container
      CREATE OBJECT DG_SPLITTER
                 EXPORTING PARENT  = G_CUSTOM_CONTAINER
                           ROWS    = 2
                           COLUMNS = 1.
    Split the custom_container to two containers and move the reference
    to receiving containers g_parent_html and g_parent_grid
      "i am allocating the space for grid and top of page
      CALL METHOD DG_SPLITTER->GET_CONTAINER
        EXPORTING
          ROW       = 1
          COLUMN    = 1
        RECEIVING
          CONTAINER = DG_PARENT_HTML.
      CALL METHOD DG_SPLITTER->GET_CONTAINER
        EXPORTING
          ROW       = 2
          COLUMN    = 1
        RECEIVING
          CONTAINER = DG_PARENT_GRID.
    CALL METHOD DG_SPLITTER->GET_CONTAINER
       EXPORTING
         ROW       = 2
         COLUMN    = 1
       RECEIVING
         CONTAINER = DG_PARENT_HTML.
    CALL METHOD DG_SPLITTER->GET_CONTAINER
       EXPORTING
         ROW       = 1
         COLUMN    = 1
       RECEIVING
         CONTAINER = DG_PARENT_GRID.
      "you can set the height of it
    Set height for g_parent_html
      CALL METHOD DG_SPLITTER->SET_ROW_HEIGHT
        EXPORTING
          ID     = 1
          HEIGHT = 5.
      "from here as usual..you need to specify parent as splitter part
      "which we alloted for grid
      CREATE OBJECT G_GRID
             EXPORTING I_PARENT = DG_PARENT_GRID.
    Set a titlebar for the grid control
      CLEAR GS_LAYOUT.
      GS_LAYOUT-GRID_TITLE = TEXT-003.
      GS_LAYOUT-ZEBRA = SPACE.
      GS_LAYOUT-CWIDTH_OPT = 'X'.
      GS_LAYOUT-NO_ROWMARK = 'X'.
      GS_LAYOUT-CTAB_FNAME = 'CELLCOLOR'.
      CALL METHOD G_GRID->REGISTER_EDIT_EVENT
        EXPORTING
          I_EVENT_ID = CL_GUI_ALV_GRID=>MC_EVT_ENTER.
      CREATE OBJECT G_HANDLER.
      SET HANDLER G_HANDLER->HANDLE_DOUBLE_CLICK FOR G_GRID.
      SET HANDLER G_HANDLER->HANDLE_HOTSPOT_CLICK FOR G_GRID.
    SET HANDLER G_HANDLER->END_OF_LIST FOR G_GRID.
      SET HANDLER G_HANDLER->TOP_OF_PAGE FOR G_GRID.
      DATA: LS_CELLCOLOR TYPE LVC_S_SCOL. "required for color
      DATA: L_INDEX TYPE SY-TABIX.
      "Here i am changing the color of line 1,5,10...
      "so you can change the color of font conditionally
      LOOP AT ITAB.
        L_INDEX = SY-TABIX.
        IF L_INDEX = 1 OR L_INDEX = 5 OR L_INDEX = 10.
          LS_CELLCOLOR-FNAME = 'VBELN'.
          LS_CELLCOLOR-COLOR-COL = '6'.
          LS_CELLCOLOR-COLOR-INT = '0'.
          LS_CELLCOLOR-COLOR-INV = '1'.
          APPEND LS_CELLCOLOR TO ITAB-CELLCOLOR.
          MODIFY ITAB INDEX L_INDEX TRANSPORTING CELLCOLOR.
          LS_CELLCOLOR-FNAME = 'POSNR'.
          LS_CELLCOLOR-COLOR-COL = '6'.
          LS_CELLCOLOR-COLOR-INT = '0'.
          LS_CELLCOLOR-COLOR-INV = '1'.
          APPEND LS_CELLCOLOR TO ITAB-CELLCOLOR.
          MODIFY ITAB INDEX L_INDEX TRANSPORTING CELLCOLOR.
        ENDIF.
      ENDLOOP.
    setting focus for created grid control
      CALL METHOD CL_GUI_CONTROL=>SET_FOCUS
        EXPORTING
          CONTROL = G_GRID.
    Build fieldcat and set editable for date and reason code
    edit enabled. Assign a handle for the dropdown listbox.
      PERFORM BUILD_FIELDCAT.
      PERFORM  SET_DRDN_TABLE.
    Optionally restrict generic functions to 'change only'.
      (The user shall not be able to add new lines).
      PERFORM EXCLUDE_TB_FUNCTIONS CHANGING LT_EXCLUDE.
    **Vaiant to save the layout
      LS_VARI-REPORT      = SY-REPID.
      LS_VARI-HANDLE      = SPACE.
      LS_VARI-LOG_GROUP   = SPACE.
      LS_VARI-USERNAME    = SPACE.
      LS_VARI-VARIANT     = SPACE.
      LS_VARI-TEXT        = SPACE.
      LS_VARI-DEPENDVARS  = SPACE.
    **Calling the Method for ALV output
      CALL METHOD G_GRID->SET_TABLE_FOR_FIRST_DISPLAY
        EXPORTING
          IT_TOOLBAR_EXCLUDING = LT_EXCLUDE
          IS_VARIANT           = LS_VARI
          IS_LAYOUT            = GS_LAYOUT
          I_SAVE               = 'A'
        CHANGING
          IT_FIELDCATALOG      = IT_FIELDCAT
          IT_OUTTAB            = ITAB[].
      "do these..{
    Initializing document
      CALL METHOD DG_DYNDOC_ID->INITIALIZE_DOCUMENT.
    Processing events
      CALL METHOD G_GRID->LIST_PROCESSING_EVENTS
        EXPORTING
          I_EVENT_NAME = 'TOP_OF_PAGE'
          I_DYNDOC_ID  = DG_DYNDOC_ID.
      "end }
    Set editable cells to ready for input initially
      CALL METHOD G_GRID->SET_READY_FOR_INPUT
        EXPORTING
          I_READY_FOR_INPUT = 1.
    ENDFORM.                               "CREATE_AND_INIT_ALV
    *&      Form  EXCLUDE_TB_FUNCTIONS
          text
         -->PT_EXCLUDE text
    FORM EXCLUDE_TB_FUNCTIONS CHANGING PT_EXCLUDE TYPE UI_FUNCTIONS.
    Only allow to change data not to create new entries (exclude
    generic functions).
      DATA LS_EXCLUDE TYPE UI_FUNC.
      LS_EXCLUDE = CL_GUI_ALV_GRID=>MC_FC_LOC_COPY_ROW.
      APPEND LS_EXCLUDE TO PT_EXCLUDE.
      LS_EXCLUDE = CL_GUI_ALV_GRID=>MC_FC_LOC_DELETE_ROW.
      APPEND LS_EXCLUDE TO PT_EXCLUDE.
      LS_EXCLUDE = CL_GUI_ALV_GRID=>MC_FC_LOC_APPEND_ROW.
      APPEND LS_EXCLUDE TO PT_EXCLUDE.
      LS_EXCLUDE = CL_GUI_ALV_GRID=>MC_FC_LOC_INSERT_ROW.
      APPEND LS_EXCLUDE TO PT_EXCLUDE.
      LS_EXCLUDE = CL_GUI_ALV_GRID=>MC_FC_LOC_MOVE_ROW.
      APPEND LS_EXCLUDE TO PT_EXCLUDE.
      LS_EXCLUDE = CL_GUI_ALV_GRID=>MC_FC_LOC_COPY.
      APPEND LS_EXCLUDE TO PT_EXCLUDE.
      LS_EXCLUDE = CL_GUI_ALV_GRID=>MC_FC_LOC_CUT.
      APPEND LS_EXCLUDE TO PT_EXCLUDE.
      LS_EXCLUDE = CL_GUI_ALV_GRID=>MC_FC_LOC_PASTE.
      APPEND LS_EXCLUDE TO PT_EXCLUDE.
      LS_EXCLUDE = CL_GUI_ALV_GRID=>MC_FC_LOC_PASTE_NEW_ROW.
      APPEND LS_EXCLUDE TO PT_EXCLUDE.
      LS_EXCLUDE = CL_GUI_ALV_GRID=>MC_FC_LOC_UNDO.
      APPEND LS_EXCLUDE TO PT_EXCLUDE.
    ENDFORM.                               " EXCLUDE_TB_FUNCTIONS
    *&      Form  build_fieldcat
          Fieldcatalog
    FORM BUILD_FIELDCAT .
      DATA: L_POS TYPE I.
      L_POS = L_POS + 1.
      X_FIELDCAT-SCRTEXT_M = 'Delivery'(024).
      X_FIELDCAT-FIELDNAME = 'VBELN'.
      X_FIELDCAT-TABNAME = 'IT_FINAL'.
      X_FIELDCAT-COL_POS    = L_POS.
      X_FIELDCAT-NO_ZERO    = 'X'.
      X_FIELDCAT-OUTPUTLEN = '10'.
      X_FIELDCAT-HOTSPOT = 'X'.
      APPEND X_FIELDCAT TO IT_FIELDCAT.
      CLEAR X_FIELDCAT.
      L_POS = L_POS + 1.
      X_FIELDCAT-SCRTEXT_M = 'Item'(025).
      X_FIELDCAT-FIELDNAME = 'POSNR'.
      X_FIELDCAT-TABNAME = 'IT_FINAL'.
      X_FIELDCAT-COL_POS    = L_POS.
      X_FIELDCAT-OUTPUTLEN = '5'.
      APPEND X_FIELDCAT TO IT_FIELDCAT.
      CLEAR X_FIELDCAT.
      L_POS = L_POS + 1.
      X_FIELDCAT-SCRTEXT_M = 'Drop'(025).
      X_FIELDCAT-FIELDNAME = 'DROP'.
      X_FIELDCAT-TABNAME = 'IT_FINAL'.
      X_FIELDCAT-COL_POS    = L_POS.
      X_FIELDCAT-OUTPUTLEN = '5'.
      X_FIELDCAT-EDIT = 'X'.
      X_FIELDCAT-DRDN_HNDL = '1'.
      X_FIELDCAT-DRDN_ALIAS = 'X'.
      APPEND X_FIELDCAT TO IT_FIELDCAT.
      CLEAR X_FIELDCAT.
    ENDFORM.                    " build_fieldcat
    *&      Module  STATUS_0100  OUTPUT
          text
    MODULE STATUS_0100 OUTPUT.
      SET PF-STATUS 'MAIN100'.
      SET TITLEBAR 'MAIN100'.
      IF G_CUSTOM_CONTAINER IS INITIAL.
    **Initializing the grid and calling the fm to Display the O/P
        PERFORM CREATE_AND_INIT_ALV.
      ENDIF.
    ENDMODULE.                 " STATUS_0100  OUTPUT
    *&      Module  USER_COMMAND_0100  INPUT
          text
    MODULE USER_COMMAND_0100 INPUT.
      CASE SY-UCOMM.
        WHEN 'BACK'.
          LEAVE TO SCREEN 0.
      ENDCASE.
    ENDMODULE.                 " USER_COMMAND_0100  INPUT
    there are many such examples
    goto->se38->type bcalv* and press f4, u can see many examples.
    Reward points if helpful.
    Thanks and regards
    Swetha Singh.

  • Handling standard toolbar event in CL_SALV_TABLE

    Hi Experts,
    I have created a ALV report using class CL_SAL_TABLE. I have created some buttons in the application toolbar of ALV by which I can jump to other ALV views. Now my requirement is if I click on the Exit (Shift+F3) button on the standard toolbar at that time, I'd be taken back to the selection screen. Currently both the back and exit button behaves the same way (i.e. set screen 0. leave screen.). I want to change the behaviour for exit button.
    Can anybody help me how to implement that?
    Thanks,
    Mainak

    Hi Mainak,
    Call the screen number that you wish to. (Selection-screen number).
    CASE sy-ucomm.
    WHEN EXIT.
    CALL SCREEN 'xxxx'.

  • Events in oops alv

    hello can anyone tell how we can handle the event hotspot_click in oops alv with some sample code.
    thanks,
    srinu

    CLASS lcl_events DEFINITION.
      PUBLIC SECTION.
        METHODS:
            on_hotspot_click
                FOR EVENT hotspot_click OF cl_gui_alv_grid
                IMPORTING e_row_id.
    ENDCLASS.                    "lcl_events DEFINITION
          CLASS lcl_events_d1001 IMPLEMENTATION                             "Local Class Implementation
    CLASS lcl_events IMPLEMENTATION.
      METHOD on_hotspot_click.
        PERFORM navigate_to_detail_view
                USING e_row_id.
      ENDMETHOD.                  "on_hotspot_click
    ENDCLASS.                  "lcl_events IMPLEMENTATION
    *****Data declaration
    DATA : wa_fieldcat          TYPE lvc_s_fcat.                          "Field Catalog for List Viewer Control - Header Data
    DATA : it_fieldcat          TYPE lvc_t_fcat.                          "Field Catalog table for List Viewer Control - Header Data
    DATA : w_container          TYPE scrfname VALUE 'ALV_CNTR'.           "Grid container for Header Data
    DATA : w_grid               TYPE REF TO cl_gui_alv_grid.              "Grid Instance for Header Data
    DATA : w_custom_container   TYPE REF TO cl_gui_custom_container.      "Container Instance for Header Data
    DATA : w_layout             TYPE lvc_s_layo.                          "ALV control: Layout structure for Header Data
    DATA : w_events             TYPE REF TO lcl_events.                   "Instance for the local class
    DATA : w_okcode_100         TYPE sy-ucomm.
    Call screen 100.
    MODULE status_0100 OUTPUT.
      SET PF-STATUS 'GUI100'.
      SET TITLEBAR  'T01'.
    ENDMODULE.                 " status_0100  OUTPUT
    *&      Module  user_command_0100  INPUT
          text
    MODULE user_command_0100 INPUT.
      w_okcode_100 = sy-ucomm.
      CLEAR sy-ucomm.
      CASE w_okcode_100.
        WHEN 'BACK'.
          LEAVE TO SCREEN 0.
        WHEN 'EXIT'.
          LEAVE PROGRAM.
        WHEN 'CANCEL'.
          LEAVE PROGRAM.
      ENDCASE.
    ENDMODULE.                 " user_command_0100  INPUT
    *&      Module  display_report  OUTPUT
          text
    MODULE display_report OUTPUT.
      IF w_custom_container IS INITIAL.
        CREATE OBJECT w_custom_container
          EXPORTING
            container_name = w_container.
        CREATE OBJECT w_grid
          EXPORTING
            i_parent = w_custom_container.
      ENDIF.
      CREATE OBJECT w_events.
      SET HANDLER w_events->on_hotspot_click FOR w_grid.
      PERFORM fieldcat_header.
      w_layout-grid_title = text-002.
      CALL METHOD w_grid->set_table_for_first_display
        EXPORTING
          is_layout                     = w_layout
        CHANGING
          it_outtab                     = it_result1
          it_fieldcatalog               = it_fieldcat
        EXCEPTIONS
          invalid_parameter_combination = 1
          program_error                 = 2
          too_many_lines                = 3
          OTHERS                        = 4.
      IF sy-subrc <> 0.
        MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
                   WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
      ENDIF.
    ENDMODULE.                 " display_report  OUTPUT

  • Should  Standard Toolbar FIND work on an ALV within a custom container ?

    I have an ALV in a custom container on a screen.
    The FIND and FIND NEXT of the ALV toolbar work fine against the grid.
    Should the FIND and FIND NEXT of the standard toolbar also work against the ALV if they are "activate" in the GUI status?
    If so, what do I call/execute in response to the "FIND" ok-code?
    I've tried calling  the function ALV_POPUP_TO_SEARCH2 and the popup comes up, but it doesn't do anything.
    Please advise at your earliest convenience.
    Thanks
    djh

    Hi Rich,
    Absolutely.  Especially as they can paint the picture, and then blame the techies when their fiction is exposed.
    Similarly, we had a situation where the Expense Report WD was failing, and the functional person ensured that everyone knew it was a technical problem and therefore my fault (with SAP as the popular co-conspirator). 
    Sadly the message above the Java stack messages was "No entry in table T706Z  for argument ' '".  Had the functional check their config and all was well.  No one apologised though......
    Last week at a different site the same thing happened (this time with TA20C) but the funky took one look at it and reviewed their config to solve - so they're not ALL the same.
    Cheers
    Gareth

  • Problem in raising the event DATA_CHANGED in OOP ALV

    Hi experts,
    I am currently having trouble in raising the event 'data_changed' in my OOP ALV . The event is triggered everytime I make changes to my editable cells but when it comes to clicking on the save button, it only calls 'data_changed_finished' and bypasses 'data_changed'.
    I need to call 'data_changed' before the data is saved to do some verification.
    My code is shown below.
    CALL METHOD gr_alvgrid->register_edit_event
         EXPORTING i_event_id = cl_gui_alv_grid=>mc_evt_modified.
    *--functions
        CALL METHOD gr_alvgrid->set_table_for_first_display
        EXPORTING
        is_variant           = s_variant
        i_save               = 'A'
        i_default            = gc_true
        is_layout            = gs_layout
        it_toolbar_excluding = gt_exclude
        CHANGING
        it_outtab            = gt_list
        it_fieldcatalog      = gt_fieldcat
        EXCEPTIONS
        invalid_parameter_combination = 1
        program_error = 2
        too_many_lines = 3
        OTHERS = 4 .
        IF sy-subrc <> 0.
    "raise message
        ENDIF.
    CREATE OBJECT gr_event.
    SET HANDLER gr_event->handle_data_changed FOR gr_alvgrid.
    SET HANDLER gr_event->handle_data_changed_finished FOR gr_alvgrid.
    CALL METHOD gr_alvgrid->set_toolbar_interactive.
    CALL METHOD gr_alvgrid->set_ready_for_input
                  EXPORTING i_ready_for_input = 1.
    In my PAI
    CASE ok_code.
        WHEN 'SAVE'.
    *--->this calls the event 'data_changed_finished' and bypasses  'data_changed'.*                                                     
    *Check if there's data changed.
          CALL METHOD gr_alvgrid->check_changed_data
            IMPORTING
              e_valid = l_valid.
      ENDCASE.
    I checked the sap sample program BCALV_EDIT_04 and I don't see any difference except for register_edit_event but I don't think that I can leave this out in my code . Is there any points i'm missing here?
    Thanks,
    Patrick

    Hi, Spin
    do like below,
    DATA: gr_alvgrid TYPE REF TO cl_gui_alv_grid,
          cc_alv TYPE REF TO cl_gui_custom_container.
    IF cc_alv IS INITIAL. " USE This Condition
      CREATE OBJECT cc_alv
        EXPORTING
          container_name = 'CC_ALV'.
      CREATE OBJECT gr_alvgrid
        EXPORTING
          i_parent = cc_alv.
      CALL METHOD gr_alvgrid->set_table_for_first_display
        EXPORTING
          is_variant                    = s_variant
          i_save                        = 'A'
          i_default                     = gc_true
          is_layout                     = gs_layout
          it_toolbar_excluding          = gt_exclude
        CHANGING
          it_outtab                     = gt_list
          it_fieldcatalog               = gt_fieldcat
        EXCEPTIONS
          invalid_parameter_combination = 1
          program_error                 = 2
          too_many_lines                = 3
          OTHERS                        = 4.
      IF sy-subrc = 0.
        "raise message
      ENDIF.
    ENDIF.
    Please reply if any Issue,
    Thanks and Regard,
    Faisal

  • After F4 Event on OOP ALV.

    Hi;
    Let me describe my problem.
    On a OOP ALV grid there are two fields. One of them is MATNR and the Other is empty.
    A list of material number is listed .When the user press f4 on matnr field and selects a material number and press enter I want to fill the empty field nearby with the description from the makt table.
    How can I do that ? Is it technically possible.
    Would you please suggest me a code sample ?
    Kind regards.
    erkan.

    You may need to use the DATA_CHANGED event in this case.
    When you define your ALV Grid you can specify when this event should be fired, in your case, you may want it to be triggered when the user hits ENTER, so after setting all the handlers, you need to do this.
      call method g_d_grid->set_ready_for_input
        exporting
          i_ready_for_input = 1.
      call method g_d_grid->register_edit_event
        exporting
          i_event_id = cl_gui_alv_grid=>mc_evt_enter
        exceptions
          error      = 1
          others     = 2.
    Then, when you pick a value from the F4 field and hit ENTER afterwards, the DATA_CHANGED event will be fired, and you can set the description in your own handler.
    FORM handle_data_changed USING p_data_changed TYPE REF TO
                                   cl_alv_changed_data_protocol.
      TABLES: t503k,
              t530.
      DATA: ls_mod_cell     TYPE lvc_s_modi,
            lv_value_fecha  TYPE lvc_value,
      DATA: l_wa_listado TYPE gtype_listado.
      LOOP AT p_data_changed->mt_mod_cells INTO ls_mod_cell.
        READ TABLE g_t_listado INTO l_wa_listado INDEX
                                    ls_mod_cell-row_id.
        CALL METHOD p_data_changed->get_cell_value
          EXPORTING
            i_row_id    = ls_mod_cell-row_id
            i_fieldname = 'NIVEL'
          IMPORTING
            e_value     = lv_value_nivel.
    * MODIFY ALV Table accordingly
      CALL METHOD g_d_grid->refresh_table_display
        EXPORTING
    *      IS_STABLE      =
           i_soft_refresh = 'X'
        EXCEPTIONS
           finished       = 1
           OTHERS         = 2

  • Standard toolbar in an ALV output report

    hey guys,
    can i manipulate the standard toolbar (BACK, CANCEL, EXIT) of an ALV output report as in a screen?
    I want to put some codes when the user ticks on the particular button.
    Thanks a lot!
    Regards,
    Mark

    in SE41
    copy Program          SAPLKKBL
            Status             STANDARD
    to ur Program          ZPROGRAM
            Status            ZSTANDARD
    in ur Z program
      CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
       EXPORTING
         i_callback_program                = repid
         i_callback_pf_status_set          = 'SET_PF_STATUS'
         i_callback_user_command           = 'USER_COMMAND'
    below of ur program write these 2FOMS...
    FORM set_pf_status USING rt_extab TYPE slis_t_extab.
    *PF status of program 'SAPLKKBL' is 'STANDARD' is copied for standard
    *options(buttons)
        SET PF-STATUS 'ZLSTANDARD'.
    ENDFORM.                    "set_pf_status
    FORM user_command  USING r_ucomm     LIKE sy-ucomm
                             rs_selfield TYPE slis_selfield.
      CASE sy-ucomm.
        WHEN 'SAVE'.
    *write ur code here
        WHEN 'BACK'.
    *write ur code here
        WHEN 'EXIT'.
    *write ur code here
      ENDCASE.
    ENDFORM.                    "user_command
    Regatds,
    Ramesh.

  • Handling error messages in OOPs ALV

    The question below is foolish.But I am a beginner so please excuse.
    I have successfully displayed an OOPs ALV which displays the material, batch and plant.
    A custom toolbar button(delete batches) has been appended to the standard toolbar.
    Now when I do not select any rows from the ALV  and click the button(delete batches) I have ensured that an error message flahes at the bottom of the screen.
    If I repeat the same procedure without coming out of the program it exits from the program itself. i want to avoid this.
    I want to flash the error message continually without coming out of the program till the user commits the mistake. Please note that I have not used any leave screen commands etc.
    Can someone please help me..
    Thanks in advance

    I assume you have the ON TOOLBAR event regiistered and the ENTER event for example.
    method constructor .
    create object grid_container1
            exporting
    *           container_name = 'CCONTAINER1'.
        container_name = cfname.
        create object  grid1
           exporting
              i_parent = grid_container1.
        set handler z_object->on_user_command for grid1.
        set handler z_object->on_toolbar for grid1.
        set handler z_object->handle_data_changed for grid1.
        set handler z_object->handle_data_changed_finished for grid1.
        set handler z_object->on_dubbelklik for grid1.
        set handler z_object->on_hotspot for grid1.
        call method grid1->register_edit_event
            exporting
               i_event_id = cl_gui_alv_grid=>mc_evt_enter.
      endmethod.
    So the easy way to do this is in your ON USER COMMAND routine when you can check to see if you selected any rows and the issue a popup warnimg message with the standard SAP MESSAGE statement.
    For example in my TEST function here I call a method to get the selected cell.
    If none are selected you can then issue your message and you will then be returned back to your GRID display after the user presses the OK button on the message popup.
    the grid1 object refers to the class cl_gui_alv_grid.
    in your case call a method that gets selected cells rather than selected cell. Use the standard method in cl_gui_alv_grid.
    If nothing selected then issue your message.
    (Note that your method ON DATA CHANGE / ON DATA CHANGED FINISHED might also be entered as well  so insure that you haven't got any coding in these methods that will interfere with processing flow).
    method on_user_command .
    *        FOR EVENT before_user_command OF cl_gui_alv_grid
    *        IMPORTING
    *          e_ucomm
    *          sender
    case e_ucomm.
          when 'EXIT'.
            leave program.
          when 'EXCEL'.
           call method me->download_to_excel.
          when 'SAVE'.
          when 'PROC'.
            call method me->process.
          when 'REFR'.
            call method me->refresh.
            when 'SWITCH'.
            call method me->switch.
           when 'TEST'.
            call method me->get_cell.
           endcase.
    method get_cell .
    break-point 1.
    call method grid1->get_current_cell
    importing
    e_row     = ls_row
    e_value   = ls_value
    e_col     = ls_col
    es_row_id = ls_row_id
    es_col_id = ls_col_id
    es_row_no = ls_row_no.
    endmethod.
    cheers
    jimbo

Maybe you are looking for