Disable editable field in ALV grid using OOPS

I have following requirements,
Displaying ALV grid output with most of the fields editable.
Validations on data entered for each fields,for error messages
Query :
I want to make all the fields except the field in ERROR in display only mode
similar to case when we do validation of fields in table controls.

HI
check the below links lot of info and examples r there for OOPS
http://www.sapgenie.com/abap/OO/index.htm
http://www.geocities.com/victorav15/sapr3/abap_ood.html
http://www.brabandt.de/html/abap_oo.html
Check this cool weblog:
/people/thomas.jung3/blog/2004/12/08/abap-persistent-classes-coding-without-sql
/people/thomas.jung3/blog/2004/12/08/abap-persistent-classes-coding-without-sql
http://help.sap.com/saphelp_nw04/helpdata/en/c3/225b6254f411d194a60000e8353423/frameset.htm
http://www.sapgenie.com/abap/OO/
http://www.sapgenie.com/abap/OO/index.htm
http://help.sap.com/saphelp_nw04/helpdata/en/c3/225b5654f411d194a60000e8353423/content.htm
http://www.esnips.com/doc/375fff1b-5a62-444d-8ec1-55508c308b17/prefinalppt.ppt
http://www.esnips.com/doc/2c76dc57-e74a-4539-a20e-29383317e804/OO-abap.pdf
http://www.esnips.com/doc/5c65b0dd-eddf-4512-8e32-ecd26735f0f2/prefinalppt.ppt
http://www.allsaplinks.com/
http://www.sap-img.com/
http://www.sapgenie.com/
http://help.sap.com
http://www.sapgenie.com/abap/OO/
http://www.sapgenie.com/abap/OO/index.htm
http://www.sapgenie.com/abap/controls/index.htm
http://www.esnips.com/doc/2c76dc57-e74a-4539-a20e-29383317e804/OO-abap.pdf
http://www.esnips.com/doc/0ef39d4b-586a-4637-abbb-e4f69d2d9307/SAP-CONTROLS-WORKSHOP.pdf
http://www.sapgenie.com/abap/OO/index.htm
http://help.sap.com/saphelp_erp2005/helpdata/en/ce/b518b6513611d194a50000e8353423/frameset.htm
http://www.sapgenie.com/abap/OO/
these links
http://help.sap.com/saphelp_47x200/helpdata/en/ce/b518b6513611d194a50000e8353423/content.htm
For funtion module to class
http://help.sap.com/saphelp_47x200/helpdata/en/c3/225b5954f411d194a60000e8353423/content.htm
for classes
http://help.sap.com/saphelp_47x200/helpdata/en/c3/225b5c54f411d194a60000e8353423/content.htm
for methods
http://help.sap.com/saphelp_47x200/helpdata/en/08/d27c03b81011d194f60000e8353423/content.htm
for inheritance
http://help.sap.com/saphelp_47x200/helpdata/en/dd/4049c40f4611d3b9380000e8353423/content.htm
for interfaces
http://help.sap.com/saphelp_47x200/helpdata/en/c3/225b6254f411d194a60000e8353423/content.htm
For Materials:
1) http://help.sap.com/printdocu/core/Print46c/en/data/pdf/BCABA/BCABA.pdf -- Page no: 1291
2) http://esnips.com/doc/5c65b0dd-eddf-4512-8e32-ecd26735f0f2/prefinalppt.ppt
3) http://esnips.com/doc/2c76dc57-e74a-4539-a20e-29383317e804/OO-abap.pdf
4) http://esnips.com/doc/0ef39d4b-586a-4637-abbb-e4f69d2d9307/SAP-CONTROLS-WORKSHOP.pdf
5) http://esnips.com/doc/92be4457-1b6e-4061-92e5-8e4b3a6e3239/Object-Oriented-ABAP.ppt
6) http://esnips.com/doc/448e8302-68b1-4046-9fef-8fa8808caee0/abap-objects-by-helen.pdf
7) http://esnips.com/doc/39fdc647-1aed-4b40-a476-4d3042b6ec28/class_builder.ppt
8) http://www.amazon.com/gp/explorer/0201750805/2/ref=pd_lpo_ase/102-9378020-8749710?ie=UTF8
1) http://www.erpgenie.com/sap/abap/OO/index.htm
2) http://help.sap.com/saphelp_nw04/helpdata/en/ce/b518b6513611d194a50000e8353423/frameset.htm
Check these sample code
data : begin of it_mara occurs 0,
mark type flag,
matnr type matnr,
mtart type mtart,
meins type meins,
end of it_mara.
data : begin of it_mara1 occurs 0,
mark type flag,
matnr type matnr,
mtart type mtart,
meins type meins,
end of it_mara1.
data : begin of it_mara2 occurs 0,
mark type flag,
matnr type matnr,
mtart type mtart,
meins type meins,
end of it_mara2.
data : t_fieldcat type lvc_t_fcat,
t_fieldcat1 type lvc_t_fcat,
s_fieldcat like line of t_fieldcat.
data : s_layout type lvc_s_layo.
data : control type ref to cl_gui_custom_container,
grid type ref to cl_gui_alv_grid.
data: begin of wa ,
mark type flag,
matnr type matnr,
mtart type mtart,
meins type meins,
end of wa.
class lcl_events_box definition.
public section.
methods :
*Handler_Data_Changed for event Data_Changed of cl_gui_alv_grid
*imporTing er_data_changed,
Handler_User_Command for event User_Command of cl_gui_alv_grid
imporTing e_ucomm,
Handler_ToolBar for event ToolBar of cl_gui_alv_grid
importing E_object E_interactive.
endclass.
class lcl_events_box implementation.
method Handler_user_command.
PERFORM FORM_USERCOMMAND CHANGING E_UCOMM.
endmethod.
method Handler_ToolBar.
PERFORM FORM_TOOLBAR CHANGING E_OBJECT E_INTERACTIVE
E_OBJECT->MT_TOOLBAR.
endmethod.
ENDCLASS.
start-of-selection.
data : w_events type ref to lcl_events_box.
select matnr mtart meins from mara into corresponding fields of table
it_mara.
call screen 100.
*& Module pbo_module OUTPUT
text
MODULE pbo_module OUTPUT.
if GRID is initial.
CREATE OBJECT CONTROL
EXPORTING
CONTAINER_NAME = 'CUST_CTRL'.
CREATE OBJECT GRID
EXPORTING
I_PARENT = CONTROL.
PERFORM BUILD_CATALOG.
PERFORM BUILD_CATALOG1.
PERFORM BUILD_LAYOUT.
CALL METHOD GRID->SET_TABLE_FOR_FIRST_DISPLAY
EXPORTING
IS_LAYOUT = s_layout
CHANGING
IT_OUTTAB = it_mara[]
IT_FIELDCATALOG = t_fieldcat.
CREATE OBJECT W_EVENTS.
SET HANDLER : W_EVENTS->HANDLER_TOOLBAR FOR GRID,
W_EVENTS->HANDLER_USER_COMMAND FOR GRID.
CALL METHOD GRID->SET_TOOLBAR_INTERACTIVE.
ELSE.
call method grid->refresh_table_display.
ENDIF.
ENDMODULE. " pbo_module OUTPUT
*& Form BUILD_CATALOG
FORM BUILD_CATALOG .
S_FIELDCAT-COL_POS = '1'.
S_FIELDCAT-FIELDNAME = 'MARK'.
S_FIELDCAT-CHECKBOX = 'X'.
S_FIELDCAT-eDIT = 'X'.
APPEND S_FIELDCAT TO T_FIELDCAT.
CLEAR S_FIELDCAT.
S_FIELDCAT-COL_POS = '2'.
S_FIELDCAT-FIELDNAME = 'MATNR'.
S_FIELDCAT-SCRTEXT_M = 'MATERIAL'.
APPEND S_FIELDCAT TO T_FIELDCAT.
S_FIELDCAT-COL_POS = '3'.
S_FIELDCAT-FIELDNAME = 'MTART'.
S_FIELDCAT-SCRTEXT_M = 'MATERL TYPE'.
APPEND S_FIELDCAT TO T_FIELDCAT.
S_FIELDCAT-COL_POS = '4'.
S_FIELDCAT-FIELDNAME = 'MEINS'.
S_FIELDCAT-SCRTEXT_M = 'UOM'.
APPEND S_FIELDCAT TO T_FIELDCAT.
ENDFORM. " BUILD_CATALOG
*& Form BUILD_LAYOUT
text
--> p1 text
<-- p2 text
FORM BUILD_LAYOUT .
S_LAYOUT-ZEBRA = 'X'.
S_LAYOUT-CWIDTH_OPT = 'X'.
S_LAYOUT-GRID_TITLE = 'Material Details'.
ENDFORM.
" BUILD_LAYOUT////////////////////////////////////
" USER_COMMAND_0100 INPUT
*& Form FORM_USERCOMMAND
text
<--P_E_UCOMM text
form FORM_USERCOMMAND changing p_e_ucomm.
CASE P_E_UCOMM.
WHEN 'INT1'.
DO.
READ TABLE IT_MARA INDEX SY-INDEX TRANSPORTING MARK MATNR.
IF SY-SUBRC <> 0.
EXIT.
ENDIF.
IF IT_MARA-MARK = 'X'.
read table it_mara into wa TRANSPORTING MATNR MTART MEINS .
MOVE-CORRESPONDING WA TO IT_MARA1.
READ TABLE IT_MARA1 TRANSPORTING MATNR MTART MEINS .
MOVE-CORRESPONDING IT_MARA1 TO IT_MARA2.
APPEND IT_MARA2.
CALL METHOD GRID->SET_TABLE_FOR_FIRST_DISPLAY
EXPORTING
IS_LAYOUT = s_layout
CHANGING
IT_OUTTAB = it_mara2[]
IT_FIELDCATALOG = t_fieldcat1.
SET PARAMETER ID 'MAT' FIELD IT_MARA-MATNR.
CALL TRANSACTION 'MM02'.
. ENDIF.
ENDIF.
ENDDO.
ENDCASE.
endform. " FORM_USERCOMMAND
*& Form FORM_TOOLBAR
text
<--P_E_OBJECT text
<--P_E_INTERACTIVE text
<--P_E_OBJECT_>MT_TOOLBAR text
FORM FORM_TOOLBAR CHANGING P_E_OBJECT TYPE REF TO
CL_ALV_EVENT_TOOLBAR_SET
P_E_INTERACTIVE
MT_TOOLBAR TYPE TTB_BUTTON.
DATA WAL_BUTTON TYPE STB_BUTTON.
*WAL_BUTTON-ICON = ICON_status_reverse.
WAL_BUTTON-TEXT = 'GO'.
WAL_BUTTON-QUICKINFO = 'PROCEED'.
waL_button-FUNCTION = 'INT1'.
WAL_BUTTON-BUTN_TYPE = 0.
WAL_BUTTON-DISABLED = SPACE.
insert WAL_BUTTON INTO P_E_OBJECT->MT_TOOLBAR index 1.
endform. " FORM_TOOLBAR
*& Module PF-STATUS OUTPUT
text
module PF-STATUS output.
set pf-status 'Z7PSTAT'.
endmodule. " PF-STATUS OUTPUT
*& Module USER_COMMAND_0100 INPUT
text
module USER_COMMAND_0100 input.
CASE SY-UCOMM.
WHEN 'BACK'.
LEAVE PROGRAM.
WHEN 'CANCEL'.
LEAVE PROGRAM.
ENDCASE.
endmodule. " USER_COMMAND_0100 INPUT
*& Form BUILD_CATALOG1
text
--> p1 text
<-- p2 text
form BUILD_CATALOG1 .
S_FIELDCAT-COL_POS = '1'.
S_FIELDCAT-FIELDNAME = 'MATNR'.
S_FIELDCAT-SCRTEXT_M = 'MATERIAL'.
APPEND S_FIELDCAT TO T_FIELDCAT1.
S_FIELDCAT-COL_POS = '2'.
S_FIELDCAT-FIELDNAME = 'MTART'.
S_FIELDCAT-SCRTEXT_M = 'MATERL TYPE'.
APPEND S_FIELDCAT TO T_FIELDCAT1.
S_FIELDCAT-COL_POS = '3'.
S_FIELDCAT-FIELDNAME = 'MEINS'.
S_FIELDCAT-SCRTEXT_M = 'UOM'.
APPEND S_FIELDCAT TO T_FIELDCAT1.
endform. " BUILD_CATALOG1
check the below link may be useful for you
http://www.sapdevelopment.co.uk/reporting/alvhome.htm
http://help.sap.com/printdocu/core/Print46c/en/data/pdf/BCSRVALV/BCSRVALV.pdf
Simple ALV report
http://www.sapgenie.com/abap/controls/alvgrid.htm
http://wiki.ittoolbox.com/index.php/Code:Ultimate_ALV_table_toolbox
ALV
1. Please give me general info on ALV.
http://www.sapfans.com/forums/viewtopic.php?t=58286
http://www.sapfans.com/forums/viewtopic.php?t=76490
http://www.sapfans.com/forums/viewtopic.php?t=20591
http://www.sapfans.com/forums/viewtopic.php?t=66305 - this one discusses which way should you use - ABAP Objects calls or simple function modules.
2. How do I program double click in ALV?
http://www.sapfans.com/forums/viewtopic.php?t=11601
http://www.sapfans.com/forums/viewtopic.php?t=23010
3. How do I add subtotals (I have problem to add them)...
http://www.sapfans.com/forums/viewtopic.php?t=20386
http://www.sapfans.com/forums/viewtopic.php?t=85191
http://www.sapfans.com/forums/viewtopic.php?t=88401
http://www.sapfans.com/forums/viewtopic.php?t=17335
4. How to add list heading like top-of-page in ABAP lists?
http://www.sapfans.com/forums/viewtopic.php?t=58775
http://www.sapfans.com/forums/viewtopic.php?t=60550
http://www.sapfans.com/forums/viewtopic.php?t=16629
5. How to print page number / total number of pages X/XX in ALV?
http://www.sapfans.com/forums/viewtopic.php?t=29597 (no direct solution)
6. ALV printing problems. The favourite is: The first page shows the number of records selected but I don't need this.
http://www.sapfans.com/forums/viewtopic.php?t=64320
http://www.sapfans.com/forums/viewtopic.php?t=44477
7. How can I set the cell color in ALV?
http://www.sapfans.com/forums/viewtopic.php?t=52107
8. How do I print a logo/graphics in ALV?
http://www.sapfans.com/forums/viewtopic.php?t=81149
http://www.sapfans.com/forums/viewtopic.php?t=35498
http://www.sapfans.com/forums/viewtopic.php?t=5013
9. How do I create and use input-enabled fields in ALV?
http://www.sapfans.com/forums/viewtopic.php?t=84933
http://www.sapfans.com/forums/viewtopic.php?t=69878
10. How can I use ALV for reports that are going to be run in background?
http://www.sapfans.com/forums/viewtopic.php?t=83243
http://www.sapfans.com/forums/viewtopic.php?t=19224
11. How can I display an icon in ALV? (Common requirement is traffic light icon).
http://www.sapfans.com/forums/viewtopic.php?t=79424
http://www.sapfans.com/forums/viewtopic.php?t=24512
12. How can I display a checkbox in ALV?
http://www.sapfans.com/forums/viewtopic.php?t=88376
http://www.sapfans.com/forums/viewtopic.php?t=40968
http://www.sapfans.com/forums/viewtopic.php?t=6919
Go thru these programs they may help u to try on some hands on
ALV Demo program
BCALV_DEMO_HTML
BCALV_FULLSCREEN_DEMO ALV Demo: Fullscreen Mode
BCALV_FULLSCREEN_DEMO_CLASSIC ALV demo: Fullscreen mode
BCALV_GRID_DEMO Simple ALV Control Call Demo Program
BCALV_TREE_DEMO Demo for ALV tree control
BCALV_TREE_SIMPLE_DEMO
BC_ALV_DEMO_HTML_D0100
<b>Reward all helpfull answers</b>
Regards

Similar Messages

  • Is there any to restrict the no of display fields in alv grid using oops?

    hi,
    i have 100 field in an internal table , and i passed that internal table to set_table_for_first_display, Now my aim is to display only 20 fields among that 100, these twenty may vary based on selection but count of fields should be always 20. Is it possible .....

    Yes!! youhave to prepare the field catalogue dynamically..based upon the selection..get the names of all the fields to be displayed ..take first twenty of them and for the rest of the fields in the internal table which are not in these twenty..mark no_out = 'X'.

  • Display error message in ALV grid  using OOPS

    Hi,
    I have a requirement to display report in ALV. I have created ALV grid using OOPS with three editable cells and 1 button on toolbar. When user enter values in Ediatble cell  and click on the Toolbar button, sales order item should be assigned to contract.
    When the user select  the row and click on toolbar button, a salesorder item should be assigned  to contract and i am using BAPI and fine with BAPI. All the error message should be displayed in a popup and the corresponding failed row  should change its color .
    Once the user identified the failed row, he can edit the value in the ediatble cells and should reprocess in the same screen ( without going back to selection screen).
    To display POP Up, I  am using FM BAL_LOG_CREATE, BAL_LOG_MSG_ADD, BAL_DSP_PROFILE_NO_TREE_GET, BAL_CNTL_CREATE.
    by using above 4 FM , i can display POP UP. but i cannot change the color of the failed row. 
    Once I identified the failed row and reprocess from the same screen , I am successful in processing the failed row, but my error log still has the reprocessed row as failed row because,  error log is not refreshing.
    Please suggest me how to clear error log which was created by using the above FM's and change the color of the failed row .
    Thanks in Advance

    Hi
    Please suggest me how to clear error log which was created by using the above FM's....
    U can use BAL_LOG_REFRESH
    ....and change the color of the failed row
    You need to insert a new field for Colour Attributes in your output table and input its name in the layout structure:
    IS_LAYOUT-INFO_FNAME = <field name for colour>
    The field has to be a CHAR 3 and its value can be -
    > Cxy
    C is a constant
    x is the colour number (from 1 to 9)
    y is intensified (0 = off, 1 = on)
    After changing the value of output table you need to run the method REFRESH_TABLE_DISPLAY for refreshing the output
    Max

  • Sub total in ALV GRID using oops concept

    Hi,
    If Plant (VBAP-WERKS) is not the same for all items on a Sales Order (VBAK-VBELN is the same for al items) then create a separate line on the report for each different plant specified in the line items.  Copy all fields from the original order line except for plant and Net Value.  Net Value should be the total of item Net Values for all items with the same plant in the order.
    Example:
    Data:
    Order----                     Item-             Plant-                                     Net Value---
    123----          010-               3467-                      100.00---
    123----          020-               7865-                      50.00---
    123----          030-               3467-                     80.50---
    Report:
    Order-                     Plant-                  Net Value---
    123-          3467-                  180.50---
    123-          7865-                   50.00----
    I need to dispaly the Report format in ALV Grid using oops concept...
    no need of calling any function modules.
    Regards,
    Nithya

    Hi
    Here is example code
    This is the method to be called:
    get_subtotals
    Use
    Returns the current subtotals of the ALV Grid Control. Having created totals for at least one column, users can calculate at most nine subtotals. The list is sorted by the values of one or several columns (called the subtotals column). If a value is changed in the subtotals column, the subtotal is displayed (this is also referred to as control level change).
    Integration
    Before you access the subtotals value, you use the method get_sort_criteria to get the sort table . One row of this table describes properties of a column in the output table.
    • If the field SUBTOT is set for a column in this table, the column is a subtotals column.
    • The field SPOS then indicates at which level (see below) the subtotal has been calculated.
    • The field FIELDNAME contains the name of the subtotals column in the output table.
    Based on this information, you specifically access the values of the tables passed (using reference variables COLLECT01 to COLLECT09).
    Features
    CALL METHOD <ref. var. to CL_GUI_ALV_GRID>->get_subtotals
    IMPORTING
    EP_COLLECT00 = <reference variable of type REF TO DATA>
    EP_COLLECT01 = <reference variable of type REF TO DATA>
    EP_COLLECT02 = <reference variable of type REF TO DATA>
    EP_COLLECT03 = <reference variable of type REF TO DATA>
    EP_COLLECT04 = <reference variable of type REF TO DATA>
    EP_COLLECT05 = <reference variable of type REF TO DATA>
    EP_COLLECT06 = <reference variable of type REF TO DATA>
    EP_COLLECT07 = <reference variable of type REF TO DATA>
    EP_COLLECT08 = <reference variable of type REF TO DATA>
    EP_COLLECT09 = <reference variable of type REF TO DATA>
    ET_GROUPLEVELS = <ínternal table of type LVC_T_GRPL>.
    In order to access the values of EP_COLLECT00 to EP_COLLECT09, you use ASSIGN to dereference the relevant reference variable in a field symbol of your output table type (see below).
    Parameters
    Meaning
    EP_COLLECT00
    Points to the totals line. Since there is only one totals line which, in addition, has a unique totalling area, no further information is available for this table in table ET_GROUPLEVELS.
    get_subtotals
    EP_COLLECT01 to EP_COLLECT09
    Point to the subtotals line. For each subtotals level, there is one reference variable. Each of these variables points to an internal table that has the type of the output table. EP_COLLECT01 points to the subtotal at the hightest level, while EP_COLLECT02 points to the subtotal at the second highest level, and so on. The levels are derived from the sort priority (field SPOS in the sort table ). The column by which the data was sorted first, is the highest subtotals level.
    ET_GROUPLEVELS
    Manages all indexes for the individual control levels. The fields of the table have the following meaning:
    • INDEX_FROM, INDEX_TO: Rows of the output table for which the subtotal was created
    • LEVEL: Subtotals level (see above)
    • COUNTER: Number of rows for which the subtotal was created
    • COMPRESS: For this subtotals line, the user has hidden the associated rows.
    • COLLECT: Indicates the subtotals table (01-09) in which the values are stored
    For an overview, see Methods of Class CL_GUI_ALV_GRID
    Activities

  • Freeze toolbar while scrolling down in ALV grid using OOPS

    Hi,
    My program is showing few products in ALV grid using OOPS. But If I scroll down to select a product, then I cant see the toolbar on which I have to press a button using selected product. Is there any way to freeze toolbar while scrolling down also.
    As of now I have to scroll up after selecting product and then press the button on toolbar.
    Regards,
    Seema
    Edited by: Seema Naharia on Feb 23, 2012 9:17 AM

    Hi ,
    You may have to set handler for the toolbars. Check class cl_gui_alv_grid for the events toolbar.
    Or just for a try, since your problem is only when scrolling,you can use set_visible_row_count to -1 , so that data will appear in same view without the need to scroll.
    Regards,
    Ramya

  • One editable cell in alv grid using function module

    Hello all,
    Any one have an idea how to make a single editable cell in alv grid using function module, i mean to say
    with out using object oriented programming.
    Regards,
    Prakash

    Hi,
    Using ALV List display it is possible.
    Try this.
    TYPE-POOLS:SLIS.
    DATA: X_FIELDCAT TYPE SLIS_FIELDCAT_ALV.
    DATA: IT_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV.
    DATA:IT_EVENTS TYPE SLIS_T_EVENT.
    data: begin of it_chg occurs 0,
          index type sy-tabix,
          end of it_chg.
    DATA:  X_EVENTS    TYPE SLIS_ALV_EVENT.
    DATA: BEGIN OF ITAB OCCURS 0,
          NAME(10) TYPE C,
          ZTERM TYPE C,
          END OF ITAB.
    PERFORM FILL_TABLE.
    loop at itab where zterm = 'A'.
    it_chg-index = sy-tabix + 3.
    " addition 3 IS FOR FIELD LABELS
    append it_chg.
    clear it_chg.
    endloop.
    DATA:L_POS TYPE I VALUE 1.
    CLEAR: L_POS.
    L_POS = L_POS + 1.
    **fieldcatalog
    X_FIELDCAT-FIELDNAME = 'NAME'.
    X_FIELDCAT-TABNAME = 'ITAB'.
    X_FIELDCAT-COL_POS    = L_POS.
    X_FIELDCAT-OUTPUTLEN = '10'.
    APPEND X_FIELDCAT TO IT_FIELDCAT.
    CLEAR X_FIELDCAT.
    L_POS = L_POS + 1.
    X_FIELDCAT-FIELDNAME = 'ZTERM'.
    X_FIELDCAT-TABNAME = 'ITAB'.
    X_FIELDCAT-COL_POS    = L_POS.
    X_FIELDCAT-OUTPUTLEN = '10'.
    APPEND X_FIELDCAT TO IT_FIELDCAT.
    CLEAR X_FIELDCAT.
    **events
    REFRESH:IT_EVENTS.
    CLEAR:X_EVENTS,IT_EVENTS.
    X_EVENTS-NAME = SLIS_EV_END_OF_LIST.
    X_EVENTS-FORM = 'MODIFY_LIST'.
    APPEND X_EVENTS TO IT_EVENTS.
    CLEAR X_EVENTS.
    END-OF-SELECTION.
    data lv_repid type sy-repid.
    lv_repid = sy-repid.
      CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
        EXPORTING
          I_CALLBACK_PROGRAM = lv_REPID
          IT_FIELDCAT        = IT_FIELDCAT
          IT_EVENTS          = IT_EVENTS
        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 FILL_TABLE
          text
    FORM FILL_TABLE.
      ITAB-NAME = 'AAA'.
      ITAB-ZTERM = 'A'.
      APPEND ITAB.
      clear itab.
      ITAB-NAME = 'ABC'.
      ITAB-ZTERM = 'B'.
      APPEND ITAB.
      clear itab.
      ITAB-NAME = 'TEST'.
      ITAB-ZTERM = 'C'.
      APPEND ITAB.
      clear itab.
      ITAB-NAME = 'BBB'.
      ITAB-ZTERM = 'D'.
      APPEND ITAB.
      clear itab.
      ITAB-NAME = '123'.
      ITAB-ZTERM = 'E'.
      APPEND ITAB.
      clear itab.
      ITAB-NAME = 'GEN'.
      ITAB-ZTERM = 'A'.
      APPEND ITAB.
      clear itab.
      ITAB-NAME = 'ALV'.
      ITAB-ZTERM = 'F'.
      APPEND ITAB.
      clear itab.
      ITAB-NAME = 'ALVTEST'.
      ITAB-ZTERM = 'A'.
      APPEND ITAB.
      clear itab.
    ENDFORM.                    "FILL_TABLE
    *&      Form  MODIFY_LIST
          text
    FORM MODIFY_LIST.
    data: l_lines type i.
    describe table itab lines l_lines.
      L_LINES  = L_LINES + 3.
    "because we have 3 lines extra occupied by lables.
    "if we have header,i mean top of page add the no.of lines
    "how many ever top of page have + 3 for labels.
      DO L_LINES TIMES.
        read table it_chg with key INDEX = sy-index.
        if sy-subrc = 0.
    **This code is for reading the out put line
    **and modify accordinlg to our requiremnet.
    **don't chnage this.
          READ LINE SY-INDEX INDEX SY-LSIND.
          IF SY-SUBRC = 0.
            MODIFY LINE SY-INDEX INDEX SY-LSIND
                       FIELD FORMAT ITAB-NAME INPUT.
          ENDIF.
        ENDIF.
      ENDDO.
    ENDFORM.                    "MODIFY_LIST

  • ALV grid using oops concepts

    HI all,
              Is it necessary to use container for ALV grid using classes.If not then please help me with a sample code.

    REPORT  z_alv_using_oops_conepts MESSAGE-ID z_OOPS.
    TABLES: ekko, ekpo.
    CLASS lcl_event_receiver DEFINITION DEFERRED.
    DATA: ok_code             TYPE sy-ucomm,
          gx_fcat1            TYPE lvc_s_fcat,
          gt_fcat1            TYPE STANDARD TABLE OF lvc_s_fcat,
          gx_fcat2            TYPE lvc_s_fcat,
          gt_fcat2            TYPE STANDARD TABLE OF lvc_s_fcat,
          gx_layout1          TYPE lvc_s_layo,
          gx_layout2          TYPE lvc_s_layo,
          gx_variant          TYPE disvariant,
          g_custom_container1 TYPE REF TO cl_gui_custom_container,
          g_custom_container2 TYPE REF TO cl_gui_custom_container,
          grid1               TYPE REF TO cl_gui_alv_grid,
          grid2               TYPE REF TO cl_gui_alv_grid,
          g_container1        TYPE scrfname VALUE 'MAIN_REPORT_LIST',
          g_container2        TYPE scrfname VALUE 'SECOND_REPORT_LIST',
          gv_event_rec1       TYPE REF TO lcl_event_receiver,
          gv_event_rec2       TYPE REF TO lcl_event_receiver,
          gv_repid            TYPE sy-repid,
          gt_final1           TYPE STANDARD TABLE OF ekko,
          gt_final2           TYPE STANDARD TABLE OF ekpo,
          gt_final3           TYPE STANDARD TABLE OF ekpo,
          gx_final            TYPE ekko,
          gx_final1           TYPE ekpo.
    INITIALIZATION.
      SELECTION-SCREEN                                              *
    SELECTION-SCREEN BEGIN OF BLOCK blk3 WITH FRAME .
    SELECT-OPTIONS:
          s_ebeln             FOR ekko-ebeln obligatory,
          s_ebelp             FOR ekpo-ebelp,
          s_bukrs             FOR ekko-bukrs,
          s_bsart             FOR ekko-bsart.
    SELECTION-SCREEN END OF BLOCK blk3.
    LOCAL CLASSES: Definition
    *===============================================================
    class lcl_event_receiver: local class to
                            define and handle own functions.
    Definition:
    ~~~~~~~~~~~
    CLASS lcl_event_receiver DEFINITION.
      PUBLIC SECTION.
        METHODS:
        hotspot_click1
            FOR EVENT hotspot_click OF cl_gui_alv_grid
                IMPORTING e_row_id
                          e_column_id,
        hotspot_click2
           FOR EVENT hotspot_click OF cl_gui_alv_grid
                IMPORTING e_row_id
                          e_column_id.
      PRIVATE SECTION.
    ENDCLASS.                    "lcl_event_receiver DEFINITION
          CLASS lcl_event_receiver IMPLEMENTATION
    CLASS lcl_event_receiver IMPLEMENTATION.
      METHOD hotspot_click1.
        DATA: lv_tabix TYPE sy-tabix,
              lx_final TYPE ekko.
        READ TABLE gt_final1 INTO gx_final INDEX e_row_id.
        IF sy-subrc = 0.
          gt_final3 = gt_final2.
          DELETE gt_final3 WHERE ebeln NE gx_final-ebeln.
          IF NOT g_custom_container2 IS INITIAL.
            CALL METHOD grid2->refresh_table_display.
            CALL METHOD grid1->refresh_table_display.
          ENDIF.
        ELSE.
          MESSAGE s000 WITH text-003.
          LEAVE LIST-PROCESSING.
        ENDIF.
      ENDMETHOD.                    "hotspot_click1
      METHOD hotspot_click2.
        READ TABLE gt_final3 INTO gx_final1 INDEX e_row_id.
        IF sy-subrc = 0.
          SET PARAMETER ID 'BES' FIELD gx_final-ebeln.
          CALL TRANSACTION 'ME23N' AND SKIP FIRST SCREEN.
        ENDIF.
      ENDMETHOD.                    "button_click1
    ENDCLASS.                    "lcl_event_receiver IMPLEMENTATION
      START-OF-SELECTION                                                 *
    START-OF-SELECTION.
      SELECT * FROM ekko INTO TABLE gt_final1 WHERE ebeln IN s_ebeln
                                              AND   bukrs IN s_bukrs
                                              AND   bsart IN s_bsart.
      IF sy-subrc = 0.
       SELECT * FROM ekpo INTO TABLE gt_final2 FOR ALL ENTRIES IN gt_final1
                                              WHERE ebeln = gt_final1-ebeln
                                               AND ebelp IN s_ebelp.
        IF sy-subrc = 0.
          gt_final3 = gt_final2.
        ENDIF.
      ENDIF.
      PERFORM sub_get_fieldcat CHANGING gt_fcat1.
      PERFORM sub_get_fieldcat CHANGING gt_fcat2.
      END-OF-SELECTION                                                   *
    END-OF-SELECTION.
      PERFORM display_process.
      CALL SCREEN 9000.
    MODULE pbo OUTPUT
    MODULE pbo OUTPUT.
      SET PF-STATUS 'MAIN100'.
      gx_layout1-grid_title = 'Purchase Order Header'.
      gx_layout1-zebra      = 'X'.
      gx_layout1-info_fname = 'COLOR_LINE'.
      gx_layout1-sel_mode   = 'X'.
      gx_layout2-grid_title = 'Purchase Order Items'.
      gx_layout2-zebra      = 'X'.
      gx_layout1-stylefname = 'CB'.
    gs_layout1-excp_led   = gc_check.
    gs_layout1-excp_group = gc_check.
      gv_repid = sy-repid.
      gx_variant-report = gv_repid.
      READ TABLE gt_final1 INTO gx_final INDEX 1.
      IF sy-subrc = 0.
        DELETE gt_final3 WHERE ebeln NE gx_final-ebeln.
      ENDIF.
      IF g_custom_container1 IS INITIAL.
        CREATE OBJECT g_custom_container1
          EXPORTING
            container_name = g_container1.
        CREATE OBJECT grid1
          EXPORTING
            i_parent = g_custom_container1.
        CALL METHOD grid1->set_table_for_first_display
          EXPORTING
            is_layout       = gx_layout1
            is_variant      = gx_variant
            i_save          = 'U'
            i_default       = 'X'
            i_structure_name = 'EKKO'
          CHANGING
            it_outtab       = gt_final1
            it_fieldcatalog = gt_fcat1.
        CALL METHOD cl_gui_control=>set_focus
          EXPORTING
            control = grid1.
      ENDIF.
      IF g_custom_container2 IS INITIAL.
        CREATE OBJECT g_custom_container2
          EXPORTING
            container_name = g_container2.
        CREATE OBJECT grid2
          EXPORTING
            i_parent = g_custom_container2.
        CALL METHOD grid2->set_table_for_first_display
          EXPORTING
            is_layout       = gx_layout2
            is_variant      = gx_variant
            i_save          = 'U'
            i_default       = 'X'
            i_structure_name = 'EKPO'
          CHANGING
            it_outtab       = gt_final3
            it_fieldcatalog = gt_fcat2.
        CALL METHOD cl_gui_control=>set_focus
          EXPORTING
            control = grid2.
      ENDIF.
      CREATE OBJECT gv_event_rec1.
      SET HANDLER gv_event_rec1->hotspot_click1 FOR grid1.
    CREATE OBJECT gv_event_rec2.
      SET HANDLER gv_event_rec1->hotspot_click2 FOR grid2.
      IF gt_final2 IS INITIAL.
        MESSAGE i000 WITH 'No Items exist for the Purchase Order'.
      ENDIF.
    ENDMODULE.                    "PBO OUTPUT
          MODULE PAI INPUT                                              *
    MODULE pai INPUT.
    To react on oi_custom_events:
      CALL METHOD cl_gui_cfw=>dispatch.
      CASE ok_code.
        WHEN 'EXIT'.
          PERFORM exit_program.
          LEAVE PROGRAM.
        WHEN 'BACK'.
          LEAVE TO SCREEN 0.
        WHEN 'CANCEL'.
          LEAVE TO SCREEN 0.
      ENDCASE.
      CLEAR ok_code.
    ENDMODULE.                    "PAI INPUT
          FORM EXIT_PROGRAM                                             *
    FORM exit_program.
      CALL METHOD grid1->free.
      CALL METHOD grid2->free.
      CALL METHOD cl_gui_cfw=>flush.
      IF sy-subrc NE 0.
        CALL FUNCTION 'POPUP_TO_INFORM'
          EXPORTING
            titel = gv_repid
            txt2  = sy-subrc
            txt1  = 'Error in Flush'(009).
      ENDIF.
    ENDFORM.                    "EXIT_PROGRAM
    *&      Form  display_process
          text
    -->  p1        text
    <--  p2        text
    FORM display_process .
      DATA: a LIKE sy-ucomm.
      DO 100 TIMES.
        DO 300 TIMES.
          GET TIME.
        ENDDO.
        a(3) = sy-index.a+3 = '%'.
        CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
          EXPORTING
            percentage = sy-index
            text       = a.
      ENDDO.
    ENDFORM.                    " display_process
    *&      Form  sub_get_fieldcat
          text
         <--P_GT_FCAT1  text
    FORM sub_get_fieldcat  CHANGING lt_fcat  TYPE lvc_t_fcat.
      gx_fcat1-fieldname = 'EBELN'.
      gx_fcat1-tabname   = 'gt_final1'.
      gx_fcat1-hotspot   = 'X'.
      APPEND gx_fcat1 TO lt_fcat.
    ENDFORM.                    " sub_get_fieldcat

  • Enable User Defined toolbar button on click -  editable alv grid using oops

    Hi all,
    I  have created editable alv using  oops concept.
    created 2 user defined toolbar button save and print using method toolbar
      ls_toolbar-text      = 'Print'.                         "#EC NOTEXT
        ls_toolbar-quickinfo = space.
        ls_toolbar-checked   = space.
        APPEND ls_toolbar TO e_object->mt_toolbar.
    requirement is
    initially print button should be disabled, and save enabled
    when i click save button, print button should be enabled.
    I want coding in editable alv oops concept
    kindly help
    regards
    senthil kumar

    Halo Senthil,
    You should call set_toolbar_interactive method of cl_gui_alv_grid in the on_user_command( ie the event handler for event user command) .
    method on_user_command.
    case e_ucomm.
    when 'SAVE'. or whatever your function code is .
    my_save_flag = 'X'.
    call method grid->set_toolbar_interactive.
    endmethod.
    This triggers the toolbar event of the
    cl_gui_alv_grid. Inside the eventhandler method ( ie the on_toolbar method ) you should set the toolbar.
    if my_save_flag = 'X'.
    read table e_object->mt_toolbar
    clear l_toolbar-disabled.
    modify e_object->mt_toolbar.
    endif.
    e_ucomm will not have  the function code if the save button is not in the toolbar area.
    then you can set the my_save_flag in the data_changed event handler of the Cl_gui_alv_grid.
    Regards
    Arshad

  • Editable fields on ALV grid

    hi
    can i make the fields of one of the columns of one of the rows as editable in ALV_GRID FM..?
    if so pls guide me how do i do it..
    after the user edits the data in the field, can i save that in another variable or another internal table? or modify the same internal table?
    pls send me an example code also...
    thanks in advance
    srini

    hi,
    editable alv:
    chk this link.
    http://www.sapdevelopment.co.uk/reporting/alv/alvgrid_editable.htm
    then u can capture the events in USER COMMAND.
    http://www.sapdevelopment.co.uk/reporting/alv/alvgrid_ucomm.htm
    See these threads
    Re: Making selected alv rows editable
    Re: selective edit in ALV grid
    REPORT ZSRI_REPORT6 NO STANDARD PAGE HEADING
    MESSAGE-ID ZZ
    LINE-SIZE 132
    LINE-COUNT 65 .
    TABLES: MARA.
    TYPE-POOLS: SLIS.
    TYPES: BEGIN OF T_MARA,
    MATNR TYPE MARA-MATNR, "Material Number
    ERSDA TYPE MARA-ERSDA, "Creation date
    BRGEW TYPE MARA-BRGEW, "Gross weight
    NTGEW TYPE MARA-NTGEW, "Net weight
    MTART TYPE MARA-MTART, "Material type
    MBRSH TYPE MARA-MBRSH, "Industry Sector
    REC_SEL TYPE C , "checkbox
    END OF T_MARA.
    V A R I A B L E S
    DATA: V_REPID LIKE SY-REPID,
    V_FLAG(1) TYPE C.
    CONSTANTS :
    C_X(1) TYPE C VALUE 'X',
    C_PF_STATUS TYPE SLIS_FORMNAME VALUE 'F_SET_PF_STATUS',
    C_FC_DELETE(6) TYPE C VALUE 'DELETE',
    C_FC_MODIFY(6) TYPE C VALUE 'MODIFY',
    C_USER_COMMAND TYPE SLIS_FORMNAME VALUE 'F_USER_COMMAND',
    C_USER_COMMAND_MODIFY TYPE SLIS_FORMNAME
    VALUE 'F_USER_COMMAND_MODIFY',
    C_ICON_DELETE TYPE ICON-NAME VALUE 'ICON_DELETE', " Icon,Delete'
    C_ICON_CANCEL TYPE ICON-NAME VALUE 'ICON_CANCEL', " Icon,Cancel'
    C_FC_SAVE(4) TYPE C VALUE 'SAVE'.
    *internal table declarations.
    DATA: IT_MARA TYPE STANDARD TABLE OF T_MARA WITH HEADER LINE,
    IT_MODIFY TYPE STANDARD TABLE OF T_MARA WITH HEADER LINE,
    IT_TEMP TYPE STANDARD TABLE OF MARA WITH HEADER LINE,
    *-ALV Internal Tables.
    *--Field Catalog
    IT_FIELDCAT TYPE STANDARD TABLE OF
    SLIS_FIELDCAT_ALV WITH HEADER LINE,
    *--Layout
    WA_LAYOUT TYPE SLIS_LAYOUT_ALV,
    *--Sort
    IT_SORT TYPE SLIS_T_SORTINFO_ALV,
    WA_SORT TYPE SLIS_SORTINFO_ALV ,
    **-Structure for excluding function codes
    WA_EXTAB TYPE SLIS_EXTAB,
    **-To hold function codes to be excluded in ALV toolbar
    IT_EXTAB TYPE SLIS_T_EXTAB.
    *selection screen.
    SELECTION-SCREEN: BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001.
    SELECT-OPTIONS: S_MATNR FOR MARA-MATNR,
    S_ERSDA FOR MARA-ERSDA.
    SELECTION-SCREEN: END OF BLOCK B1.
    *--Radio buttons to select either Display/Delete/Modify
    SELECTION-SCREEN BEGIN OF BLOCK B2 WITH FRAME
    TITLE TEXT-002.
    SELECTION-SCREEN : BEGIN OF LINE.
    SELECTION-SCREEN COMMENT 1(20) TEXT-003.
    PARAMETERS: P_DISP RADIOBUTTON GROUP RAD1 DEFAULT 'X'.
    SELECTION-SCREEN : END OF LINE.
    SELECTION-SCREEN : BEGIN OF LINE.
    SELECTION-SCREEN COMMENT 1(20) TEXT-005.
    PARAMETERS: P_UPD RADIOBUTTON GROUP RAD1.
    SELECTION-SCREEN : END OF LINE.
    SELECTION-SCREEN : BEGIN OF LINE.
    SELECTION-SCREEN COMMENT 1(20) TEXT-004.
    PARAMETERS: P_DEL RADIOBUTTON GROUP RAD1.
    SELECTION-SCREEN : END OF LINE.
    SELECTION-SCREEN END OF BLOCK B2 .
    AT SELECTION-SCREEN.
    PERFORM VALIDATE_SCREEN.
    *start of selection
    START-OF-SELECTION.
    *clear the internal tables to be used.
    CLEAR: IT_MARA,IT_MARA[],
    V_FLAG.
    *get the data
    PERFORM GET_DATA.
    *end of selection
    END-OF-SELECTION.
    IF IT_MARA[] IS INITIAL.
    MESSAGE I000 WITH
    'No Records found for the given Selection Criteria'(012).
    ELSE.
    *do alv process
    V_REPID = SY-REPID.
    *--Sort the Output Fields
    PERFORM SORT_FIELDS.
    *--Build Field catalog for the Output fields
    PERFORM BUILD_FIELDCAT.
    *--Set the Layout for ALV
    PERFORM SET_LAYOUT.
    IF P_DISP = C_X.
    *--Exclude any Buttons on the Appn tool bar
    perform change_default_pf_status.
    MOVE C_FC_DELETE TO WA_EXTAB-FCODE. " DELETE button on ALV
    APPEND WA_EXTAB TO IT_EXTAB.
    MOVE C_FC_MODIFY TO WA_EXTAB-FCODE. " MODIFY button on ALV
    APPEND WA_EXTAB TO IT_EXTAB.
    ELSEIF P_UPD = C_X.
    *--Exclude DELETE Button on the appn tool bar
    MOVE C_FC_DELETE TO WA_EXTAB-FCODE. " DELETE button on ALV
    APPEND WA_EXTAB TO IT_EXTAB.
    ELSEIF P_DEL = C_X.
    *--Exclude MODIFY button on appn tool bar
    MOVE C_FC_MODIFY TO WA_EXTAB-FCODE. " MODIFY button on ALV
    APPEND WA_EXTAB TO IT_EXTAB.
    ENDIF.
    *--Exclude SAVE button for all options
    MOVE 'SAVE' TO WA_EXTAB-FCODE. " SAVE button on ALV
    APPEND WA_EXTAB TO IT_EXTAB.
    *--Display ALV output
    PERFORM LIST_DISPLAY TABLES IT_MARA
    USING C_USER_COMMAND.
    ENDIF.
    *& Form get_data
    FORM GET_DATA .
    SELECT MATNR
    ERSDA
    BRGEW
    NTGEW
    MTART
    MBRSH
    FROM MARA
    INTO TABLE IT_MARA
    WHERE MATNR IN S_MATNR
    AND ERSDA IN S_ERSDA.
    IF SY-SUBRC <> 0.
    *no records selected leave processing
    STOP.
    ENDIF.
    SORT IT_MARA.
    ENDFORM. " get_data
    *& Form sort_fields
    text
    --> p1 text
    <-- p2 text
    FORM SORT_FIELDS .
    CLEAR WA_SORT.
    WA_SORT-FIELDNAME = 'MATNR'.
    WA_SORT-SPOS = '1'.
    WA_SORT-UP = 'X'.
    APPEND WA_SORT TO IT_SORT.
    CLEAR WA_SORT.
    WA_SORT-FIELDNAME = 'ERSDA'.
    WA_SORT-SPOS = '2'.
    WA_SORT-UP = 'X'.
    APPEND WA_SORT TO IT_SORT.
    ENDFORM. " sort_fields
    *& Form build_fieldcat
    text
    --> p1 text
    <-- p2 text
    FORM BUILD_FIELDCAT .
    IT_FIELDCAT-COL_POS = '1'.
    IT_FIELDCAT-FIELDNAME = 'MATNR'.
    IT_FIELDCAT-KEY = 'X'.
    IT_FIELDCAT-OUTPUTLEN = '15'.
    IT_FIELDCAT-SELTEXT_L = 'Material number'(022).
    APPEND IT_FIELDCAT.
    CLEAR IT_FIELDCAT.
    IT_FIELDCAT-COL_POS = '2'.
    IT_FIELDCAT-FIELDNAME = 'ERSDA'.
    IT_FIELDCAT-KEY = 'X'.
    IT_FIELDCAT-OUTPUTLEN = '10'.
    IT_FIELDCAT-SELTEXT_L = 'Created on'(023).
    APPEND IT_FIELDCAT.
    CLEAR IT_FIELDCAT.
    IT_FIELDCAT-COL_POS = '3'.
    IT_FIELDCAT-FIELDNAME = 'BRGEW'.
    IT_FIELDCAT-OUTPUTLEN = '10'.
    IT_FIELDCAT-SELTEXT_L = 'GROSS WEIGHT'(024).
    APPEND IT_FIELDCAT.
    CLEAR IT_FIELDCAT.
    IT_FIELDCAT-COL_POS = '4'.
    IT_FIELDCAT-FIELDNAME = 'NTGEW'.
    IT_FIELDCAT-OUTPUTLEN = '15'.
    IT_FIELDCAT-SELTEXT_L = 'NET WEIGHT'(025).
    APPEND IT_FIELDCAT.
    CLEAR IT_FIELDCAT.
    IT_FIELDCAT-COL_POS = '5'.
    IT_FIELDCAT-FIELDNAME = 'MTART'.
    IT_FIELDCAT-OUTPUTLEN = '3'.
    IT_FIELDCAT-SELTEXT_L = 'Material type'(026).
    APPEND IT_FIELDCAT.
    CLEAR IT_FIELDCAT.
    IT_FIELDCAT-COL_POS = '6'.
    IT_FIELDCAT-FIELDNAME = 'MBRSH'.
    IT_FIELDCAT-OUTPUTLEN = '25'.
    IT_FIELDCAT-SELTEXT_L = 'Industry sector'(027).
    APPEND IT_FIELDCAT.
    CLEAR IT_FIELDCAT.
    IT_FIELDCAT-FIELDNAME = 'REC_SEL'.
    IT_FIELDCAT-NO_OUT = C_X.
    APPEND IT_FIELDCAT.
    CLEAR IT_FIELDCAT.
    ENDFORM. " build_fieldcat
    *& Form list_display
    text
    -->P_IT_MARA text
    -->P_C_USER_COMMAND text
    FORM LIST_DISPLAY TABLES P_IT_MARA
    USING P_USER_COMMAND TYPE SLIS_FORMNAME.
    CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
    EXPORTING
    I_CALLBACK_PROGRAM = V_REPID
    I_CALLBACK_PF_STATUS_SET = C_PF_STATUS
    I_CALLBACK_USER_COMMAND = P_USER_COMMAND
    IS_LAYOUT = WA_LAYOUT
    IT_FIELDCAT = IT_FIELDCAT[]
    IT_EXCLUDING = IT_EXTAB[]
    IT_SORT = IT_SORT[]
    TABLES
    T_OUTTAB = P_IT_MARA
    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. " list_display
    *& Form F_SET_PF_STATUS
    Set PF_STATUS STANDARD modifying the standard toolbar
    by excluding some buttons
    -->P_IT_EXTAB -- TABLE OF EXCLUDING FUNCTIONS
    FORM F_SET_PF_STATUS USING RT_EXTAB TYPE SLIS_T_EXTAB.
    CLEAR : WA_EXTAB,
    IT_EXTAB.
    *--Set the Modified PF status for the ALV.
    SET PF-STATUS 'ALV_STATUS_01' EXCLUDING RT_EXTAB.
    ENDFORM. " SET_PF_STATUS
    *& Form f_user_command
    Handle user action on ALV toolbar
    FORM F_USER_COMMAND USING R_UCOMM LIKE SY-UCOMM
    RS_SELFIELD TYPE SLIS_SELFIELD.
    RS_SELFIELD-REFRESH = C_X.
    IF R_UCOMM = C_FC_DELETE.
    *--User Selected DELETE button.
    PERFORM DELETE_SELECTED_RECORDS.
    ELSEIF R_UCOMM = C_FC_MODIFY.
    *--If user selects MODIFY button.
    PERFORM CHANGE_RECORDS.
    ENDIF.
    ENDFORM. "F_USER_COMMAND
    *& Form POP_UP_CONFIRMATION
    text
    <--P_ANSWER text
    FORM POP_UP_CONFIRMATION
    CHANGING P_ANSWER TYPE C.
    DATA:
    L_TITLE(14) TYPE C, " Title of pop-up
    L_TXT_QUESTION(52) TYPE C, " Text displayed in pop-up
    L_DISP_CANCEL TYPE C, " Display 'Cancel' button?
    L_BTN1 TYPE ICON-NAME, " Icon on button 1
    L_BTN2 TYPE ICON-NAME. " Icon on button 2
    L_TITLE = 'Delete'(017). " delete
    L_TXT_QUESTION = 'Are you sure to delete?'(018).
    L_BTN1 = C_ICON_DELETE.
    L_BTN2 = C_ICON_CANCEL.
    **-Display pop-up asking user for confirmation
    CALL FUNCTION 'POPUP_TO_CONFIRM'
    EXPORTING
    TITLEBAR = L_TITLE
    TEXT_QUESTION = L_TXT_QUESTION
    TEXT_BUTTON_1 = 'Yes'
    ICON_BUTTON_1 = L_BTN1
    TEXT_BUTTON_2 = 'No'
    ICON_BUTTON_2 = L_BTN2
    DEFAULT_BUTTON = '2'
    DISPLAY_CANCEL_BUTTON = 'X'
    IMPORTING
    ANSWER = P_ANSWER
    EXCEPTIONS
    TEXT_NOT_FOUND = 1
    OTHERS = 2.
    IF SY-SUBRC <> 0.
    MESSAGE E000 WITH 'Error executing function module:'(019)
    'POPUP_TO_CONFIRM'.
    ENDIF.
    ENDFORM. "pop_up_confirmation
    *& Form set_layout
    text
    --> p1 text
    <-- p2 text
    FORM SET_LAYOUT .
    IF P_DEL = C_X OR P_UPD = C_X.
    *--Allow Input only if user choose 'UPDATE'/ 'DELETE' radio buttons
    WA_LAYOUT-BOX_FIELDNAME = 'REC_SEL'.
    WA_LAYOUT-BOX_TABNAME = 'IT_MARA'.
    ENDIF.
    *--Display Header based on the user selection
    IF P_DISP = C_X.
    WA_LAYOUT-WINDOW_TITLEBAR =
    'Display '(036).
    ELSEIF P_DEL = C_X.
    WA_LAYOUT-WINDOW_TITLEBAR =
    'Delete '(037).
    ELSEIF P_UPD = C_X.
    WA_LAYOUT-WINDOW_TITLEBAR =
    'Change '(038).
    ENDIF.
    ENDFORM. " set_layout
    *& Form change_default_pf_status
    text
    --> p1 text
    <-- p2 text
    FORM CHANGE_DEFAULT_PF_STATUS .
    MOVE C_FC_DELETE TO WA_EXTAB-FCODE. " DELETE button on ALV
    APPEND WA_EXTAB TO IT_EXTAB.
    MOVE C_FC_MODIFY TO WA_EXTAB-FCODE. " MODIFY button on ALV
    APPEND WA_EXTAB TO IT_EXTAB.
    ENDFORM. " change_default_pf_status
    *& Form f_user_command
    Handle user action on ALV toolbar
    FORM F_USER_COMMAND_MODIFY USING R_UCOMM LIKE SY-UCOMM "#EC *
    RS_SELFIELD TYPE SLIS_SELFIELD.
    DATA : L_ANSWER TYPE C. "#EC *
    IF R_UCOMM = C_FC_SAVE.
    *user selected save button
    READ TABLE IT_MODIFY WITH KEY REC_SEL = 'X'.
    *check if user selected atleast one line.
    IF SY-SUBRC <> 0.
    MESSAGE I000 WITH 'No record(s) Selected to Modify'(016).
    EXIT.
    ENDIF.
    LOOP AT IT_MODIFY WHERE REC_SEL = 'X'.
    *--Check the entered values are valid or not.
    IF NOT ( it_modify-status = 'A' OR
    it_modify-status = 'C' OR
    it_modify-status = 'E' ).
    *--User Entered invalid value for STATUS field,so Display Error Msg
    CLEAR R_UCOMM.
    MESSAGE e000 WITH 'Invalid value '''(031)
    '' for Status in the Record # '(032)
    sy-tabix.
    ENDIF.
    ENDLOOP.
    CLEAR: IT_TEMP,
    IT_TEMP[].
    LOOP AT IT_MODIFY WHERE REC_SEL = 'X'.
    MOVE-CORRESPONDING IT_MODIFY TO IT_TEMP.
    APPEND IT_TEMP.
    CLEAR IT_TEMP.
    ENDLOOP.
    *--start new code
    DATA : IT_TEMP2 LIKE STANDARD TABLE OF MARA WITH HEADER LINE.
    SELECT * FROM MARA
    INTO TABLE IT_TEMP2
    FOR ALL ENTRIES IN IT_TEMP
    WHERE MATNR = IT_TEMP-MATNR.
    IF SY-SUBRC = 0.
    LOOP AT IT_MODIFY WHERE REC_SEL = 'X'.
    READ TABLE IT_TEMP2 WITH KEY MATNR = IT_MODIFY-MATNR.
    IF SY-SUBRC = 0.
    IT_TEMP2-NTGEW = IT_MODIFY-NTGEW.
    IT_TEMP2-BRGEW = IT_MODIFY-BRGEW.
    MODIFY IT_TEMP2 INDEX SY-TABIX.
    ENDIF.
    ENDLOOP.
    ENDIF.
    *modify mara table with the changed values
    MODIFY MARA FROM TABLE IT_TEMP2 .
    *--end new code
    IF SY-SUBRC = 0.
    COMMIT WORK AND WAIT.
    *--Display message with Success in Updating database
    MESSAGE I000 WITH SY-DBCNT
    ' Record(s) has been Updated'(020).
    CLEAR :
    IT_MARA,
    IT_MARA[].
    *get-data again from database.
    PERFORM GET_DATA.
    RS_SELFIELD-REFRESH = C_X.
    ELSE.
    *--Error occurred
    MESSAGE I000 WITH 'Error occured in Modifying the database'(021).
    ENDIF.
    ENDIF.
    ENDFORM. "f_user_command_modify
    *& Form validate_screen
    text
    --> p1 text
    <-- p2 text
    FORM VALIDATE_SCREEN .
    DATA : LV_MATNR LIKE MARA-MATNR.
    *--validate product
    IF NOT S_MATNR[] IS INITIAL.
    SELECT MATNR
    INTO MARA-MATNR
    FROM MARA
    WHERE MATNR IN S_MATNR.
    ENDSELECT.
    IF SY-SUBRC <> 0.
    *--Error
    MESSAGE E000 WITH 'Invalid Material'(034).
    ENDIF.
    ENDIF.
    ENDFORM. " validate_screen
    *& Form delete_records
    text
    --> p1 text
    <-- p2 text
    FORM DELETE_RECORDS .
    LOOP AT IT_MARA.
    MOVE-CORRESPONDING IT_MARA TO IT_TEMP.
    APPEND IT_TEMP.
    CLEAR IT_TEMP.
    ENDLOOP.
    DELETE MARA FROM TABLE IT_TEMP.
    IF SY-SUBRC = 0.
    *--Successfully selected records Deleted.
    COMMIT WORK AND WAIT.
    *--Display Success Message to the user
    MESSAGE I000 WITH SY-DBCNT
    ' Record(s) deleted Successfully'(010).
    ELSE.
    *--Error occured in deletion
    MESSAGE I000 WITH 'Error occured in Deleting the Record(s)'(011).
    ENDIF.
    CLEAR: IT_MARA,
    IT_MARA[],
    IT_TEMP,
    IT_TEMP[].
    V_FLAG = C_X.
    STOP.
    ENDFORM. " delete_records
    *& Form delete_selected_records
    text
    --> p1 text
    <-- p2 text
    FORM DELETE_SELECTED_RECORDS .
    DATA : L_ANSWER(1) TYPE C.
    READ TABLE IT_MARA WITH KEY REC_SEL = C_X.
    IF SY-SUBRC <> 0.
    MESSAGE I000 WITH 'No record(s) Selected to Delete'(013).
    EXIT.
    ELSE.
    *--Ask for delete confirmation
    PERFORM POP_UP_CONFIRMATION
    CHANGING L_ANSWER.
    IF L_ANSWER = '1'. " 'Yes'
    CLEAR: IT_TEMP,
    IT_TEMP[].
    LOOP AT IT_MARA WHERE REC_SEL = 'X'.
    MOVE-CORRESPONDING IT_MARA TO IT_TEMP.
    APPEND IT_TEMP.
    CLEAR IT_TEMP.
    ENDLOOP.
    DELETE MARA FROM TABLE IT_TEMP.
    IF SY-SUBRC = 0.
    *--Successfully selected records Deleted.
    COMMIT WORK AND WAIT.
    *--Display completed work information to the user
    MESSAGE I000 WITH SY-DBCNT
    ' Record(s) deleted Successfully'(014).
    *--Clear the Internal tables
    CLEAR: IT_MARA,
    IT_MARA[].
    *--Reselects entries from Database again & display in ALV
    PERFORM GET_DATA.
    ELSE.
    *--Error occured
    MESSAGE I000 WITH
    'Error occured in Deleting the Record(s)'(015).
    ENDIF.
    ENDIF.
    ENDIF.
    ENDFORM. " delete_selected_records
    *& Form change_records
    text
    --> p1 text
    <-- p2 text
    FORM CHANGE_RECORDS .
    READ TABLE IT_MARA WITH KEY REC_SEL = 'X'.
    *--check user selected at least 1 record to MODIFY or not
    IF SY-SUBRC <> 0.
    MESSAGE I000 WITH 'No record(s) Selected to Modify'(016).
    EXIT.
    ELSE.
    CLEAR : IT_MODIFY,
    IT_MODIFY[].
    LOOP AT IT_MARA WHERE REC_SEL = 'X'.
    IT_MODIFY = IT_MARA.
    APPEND IT_MODIFY.
    CLEAR IT_MODIFY.
    ENDLOOP.
    *--Change PF status for this new ALV list.
    PERFORM CHANGE_PF_STATUS_AGAIN.
    *--Change Field Catalog to make INPUT enabled.
    READ TABLE IT_FIELDCAT WITH KEY FIELDNAME = 'NTGEW'.
    IT_FIELDCAT-INPUT = C_X.
    MODIFY IT_FIELDCAT INDEX SY-TABIX.
    *--Call ALV LIST DISPLAY with this new values.
    PERFORM LIST_DISPLAY TABLES IT_MODIFY
    USING C_USER_COMMAND_MODIFY.
    ENDIF.
    ENDFORM. " change_records
    *& Form change_pf_status_again
    text
    --> p1 text
    <-- p2 text
    FORM CHANGE_PF_STATUS_AGAIN .
    MOVE C_FC_DELETE TO WA_EXTAB-FCODE. " DELETE button on ALV
    APPEND WA_EXTAB TO IT_EXTAB.
    MOVE C_FC_MODIFY TO WA_EXTAB-FCODE. " MODIFY button on ALV
    APPEND WA_EXTAB TO IT_EXTAB.
    ENDFORM. " change_pf_status_again

  • Editable field in ALV GRID/LIST

    Hi All,
    I developed an alv program in which 10 rows is there. In alv grid/list first column is check box. I want 1,5 and 10th row is editable for first column (check box) while rest is not editable. Can you please give solution for same. Please tell me simple method not oops methos
    coz I have taken FM REUSE_ALV_GRID_DISPLAY or REUSE_ALV_LIST_DISPLAY.
    Thanks,
    Rakesh

    goto se38.
    BCALVEDIT*
    press F4
    many examples are there..
    BCALV_GRID_EDIT try this...

  • ALV Grid using OOP

    Hi Friends,
    Let me know how to handle the event raised by clicking the hotspot of an ALV grid that is placed over one splitter container.
    I am explaining the problem in detail:
    (1) I have to display an ALV grid and when any hotspot of that ALV grid is clicked,
         the row-id should be captured and used to fetch corresponding records from  
         child table (primarykey-foreign key relationship) and the resulting grid should be
         displayed on the same screen at the same time and for any further click, the
         child grid is to be refreshed.
    (2) For this, I have created one custom container, placed one splitter container   having two rows & one column over  it and placed the ALV grids over that by getting the corresponding containers of the splitter.
    (3) Now, when the hotspot is clicked the SY-UCOMM is empty (even it is not entering the PAI block if I do not place the back button). So, I am not able to get the row-id of the clicked row & without that, can't proceed any further.
    (4) Rest of the things are working fine and I have tested that also.
    Please help me out as I am new to this field and started  practicing ABAP just a month back.
    Thanks & Regards
    Aditya P. Srivastava

    Hi Aditya
    Here is the complete for the same,
    <b>Some Prerequisites in terms of screen, custom control & flow logic</b>
    <i>Screen Name: 9000, Custom Container name : CONTAINER.
    flow logic in screen 9000
    PROCESS BEFORE OUTPUT.
      MODULE status_9000.
      MODULE init_9000.
    PROCESS AFTER INPUT.
      MODULE user_command_9000.</i>
    <b>
    Here goes the code,</b>
    REPORT  zkb_2alv_grids.
    DATA: i_t000 TYPE TABLE OF t000,
          w_t000 TYPE t000,
          i_tcurr TYPE TABLE OF tcurr.
    Declaration for all the objects required
    DATA: o_container        TYPE REF TO cl_gui_custom_container,
          o_splitter         TYPE REF TO cl_gui_easy_splitter_container,
          o_container_top    TYPE REF TO cl_gui_container,
          o_container_bottom TYPE REF TO cl_gui_container,
          o_salv_table1      TYPE REF TO cl_salv_table,
          o_salv_table2      TYPE REF TO cl_salv_table,
          o_salv_columns     TYPE REF TO cl_salv_columns_table,
          o_salv_column      TYPE REF TO cl_salv_column_table.
    DATA: o_events TYPE REF TO cl_salv_events_table.
    CLASS lcl_handle_events DEFINITION
    CLASS lcl_handle_events DEFINITION.
      PUBLIC SECTION.
        METHODS: on_link_click
                    FOR EVENT link_click
                        OF cl_salv_events_table
                           IMPORTING row column.
    ENDCLASS. "lcl_handle_events DEFINITION
          CLASS lcl_handle_events IMPLEMENTATION
    CLASS lcl_handle_events IMPLEMENTATION.
      METHOD on_link_click.
        READ TABLE i_t000 INTO w_t000 INDEX row.
        SELECT * FROM tcurr
               INTO TABLE i_tcurr
                    WHERE fcurr = w_t000-mwaer.
        o_salv_table2->refresh( ).
      ENDMETHOD.                    "lcl_handle_events
    ENDCLASS.                    "lcl_handle_events IMPLEMENTATION
    START-OF-SELECTION.
      DATA: event_handler TYPE REF TO lcl_handle_events.
    Select Data
      SELECT * FROM t000 INTO TABLE i_t000.
      CALL SCREEN 9000.
    *&      Module  init_9000  OUTPUT
          text
    MODULE init_9000 OUTPUT.
      DATA: lv_cx_salv_msg        TYPE REF TO cx_salv_msg,
            lw_bal_s_msg          TYPE bal_s_msg.
      IF NOT o_container IS BOUND.
    Create a Custom Control
        CREATE OBJECT o_container
        EXPORTING
          container_name              = 'CONTAINER'
          repid                       = sy-repid
          dynnr                       = '9000'
        EXCEPTIONS
          cntl_error                  = 1
          cntl_system_error           = 2
          create_error                = 3
          lifetime_error              = 4
          lifetime_dynpro_dynpro_link = 5
          OTHERS                      = 6.
        IF sy-subrc <> 0.
          MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
          WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
        ENDIF.
    Create splitter control
        CREATE OBJECT o_splitter
        EXPORTING
          parent            = o_container
          orientation       = 0
          sash_position     = 30
          with_border       = 1
        EXCEPTIONS
          cntl_error        = 1
          cntl_system_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.
    Assign the left and right control that were splitted
        o_container_top  = o_splitter->top_left_container.
        o_container_bottom = o_splitter->bottom_right_container.
      ENDIF. " IF NOT o_container IS BOUND.
      TRY.
          CALL METHOD cl_salv_table=>factory
            EXPORTING
              r_container  = o_container_top
            IMPORTING
              r_salv_table = o_salv_table1
            CHANGING
              t_table      = i_t000.
        CATCH cx_salv_msg INTO lv_cx_salv_msg.
          lv_cx_salv_msg->if_alv_message~get_message(
                                RECEIVING
                                    r_s_msg = lw_bal_s_msg ).
          MESSAGE ID     lw_bal_s_msg-msgid
                  TYPE   lw_bal_s_msg-msgty
                  NUMBER lw_bal_s_msg-msgno
                  WITH   lw_bal_s_msg-msgv1 lw_bal_s_msg-msgv2
                         lw_bal_s_msg-msgv3 lw_bal_s_msg-msgv4.
      ENDTRY.
    Column Settings
      o_salv_columns = o_salv_table1->get_columns( ).
      o_salv_column ?= o_salv_columns->get_column( 'MWAER' ).
      o_salv_column->set_cell_type( 5 ).
      o_events = o_salv_table1->get_event( ).
      CREATE OBJECT event_handler.
      SET HANDLER event_handler->on_link_click FOR o_events.
      TRY.
          CALL METHOD cl_salv_table=>factory
            EXPORTING
              r_container  = o_container_bottom
            IMPORTING
              r_salv_table = o_salv_table2
            CHANGING
              t_table      = i_tcurr.
        CATCH cx_salv_msg INTO lv_cx_salv_msg.
          lv_cx_salv_msg->if_alv_message~get_message(
                                RECEIVING
                                    r_s_msg = lw_bal_s_msg ).
          MESSAGE ID     lw_bal_s_msg-msgid
                  TYPE   lw_bal_s_msg-msgty
                  NUMBER lw_bal_s_msg-msgno
                  WITH   lw_bal_s_msg-msgv1 lw_bal_s_msg-msgv2
                         lw_bal_s_msg-msgv3 lw_bal_s_msg-msgv4.
      ENDTRY.
    Display the ALV Grid
      o_salv_table1->display( ).
      o_salv_table2->display( ).
    ENDMODULE.                 " init_9000  OUTPUT
    *&      Module  user_command_9000  INPUT
          text
    MODULE user_command_9000 INPUT.
      CASE  sy-ucomm .
        WHEN 'BACK' OR 'EXIT' OR 'CANC'.
          SET SCREEN 0.
          LEAVE SCREEN.
      ENDCASE.
    ENDMODULE.                 " user_command_9000  INPUT
    *&      Module  status_9000  OUTPUT
          text
    MODULE status_9000 OUTPUT.
      SET PF-STATUS '9000'.
    ENDMODULE.                 " status_9000  OUTPUT
    Regards
    Kathirvel

  • EDIT field in ALV GRID and on SAVE it has to update the DB Table

    Hi Experts,
    I have searched lot of forums...
    But i had not got the exact solution for this...
    I have multiple records that displayed in the ALV output screen and i had modified more than one record and then click on save.
    It has to modify all the lines that i had changed in the EDITABLE FIELD.
    Can any one help me in doing so...
    Sample code will be more help full....
    Thanks in advance,
    Kruthik

    Hi Kruthik
    Check [=> OO ALV Event DATA_CHANGED <= |http://abaptips.com/?p=70], hope you will get idea.
    Please reply in case of any confusion.
    Thanks and Best Regards,
    Faisal

  • Controlling Font size in alv grid using oops

    Hi Experts,
    I have a requirement where i want to change the font size of the grid title bar.
    Is there any way of acheiving this.
    I do see a  method set_title size in the class cl_gui_alv_grid. However it is a protected method and i am not able implement it in my program.
    Any pointers on this would be higly appreciated.
    Thanks and Regards,
    Jey sabith Ebron

    Hi
    I tried and it worked with me.
    The grid title was indeed changed from the the method Set_Title_Size.
    To use the method you have to Create a Local Class Inheriting the Class CL_GUI_ALV_GRID.
    CLASS ZCL_GUI_ALV_GRID DEFINITION INHERITING FROM CL_GUI_ALV_GRID.
      PUBLIC SECTION.
        METHODS TITLE_SIZE.
      PRIVATE SECTION.
    ENDCLASS.                    "ZCL_GUI_ALV_GRID DEFINITION
    Then use the above method in the Implementation part as .
    CLASS ZCL_GUI_ALV_GRID IMPLEMENTATION.
      METHOD TITLE_size.
        ME->SET_TITLE_SIZE( EXPORTING SIZE = 1
                            EXCEPTIONS ERROR = 1  ).
      ENDMETHOD.
    ENDCLASS.
    Now when your reference variable should be
    Data :GRID type ref to ZCL_GUI_ALV_GRID.
    and Create the Object as
    CREATE OBJECT GRID
               EXPORTING I_PARENT = G_CUSTOM_CONTAINER1.
    Before Calling Set_table_for_ first_display, Call the created method
    CALL METHOD GRID->TITLE_SIZE.

  • Disbable button on alv report using oops

    Hi all,
    I have a button to toll bar of alv grid using oops
    based on that when the user clicks on that some action is performed and list is displayed again
    now when the list is diaplyed i need the button that i added to be disabled so that the user cannot click it agin
    i have everything i don't know how to disable the button.
    USING THIS STATMENT  move 'X' to ls_toolbar-disabled WE CAN DISABLE BUT I DON'T WHERE TO PASS IT..
    LOCAL CLASSES: Definition
    *===============================================================
    class lcl_event_receiver: local class to
                            define and handle own functions.
    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)
    *===============================================================
    LOCAL CLASSES: Implementation
    *===============================================================
    class lcl_event_receiver (Implementation)
    class lcl_event_receiver implementation.
      method handle_toolbar.
    append a separator to normal toolbar
        clear ls_toolbar.
        move 3 to ls_toolbar-butn_type.
        append ls_toolbar to e_object->mt_toolbar.
    append an icon to show booking table
        clear ls_toolbar.
        move 'ADD' to ls_toolbar-function.
        move icon_employee to ls_toolbar-icon.
        move 'Show Bookings'(111) to ls_toolbar-quickinfo.
        move 'Add Material'(112) to ls_toolbar-text.
        move '' to ls_toolbar-disabled.
        append ls_toolbar to e_object->mt_toolbar.
      endmethod.
      method handle_user_command.
        case e_ucomm.
          when 'ADD'.
            call method g_grid->get_selected_rows
                     importing et_index_rows = lt_rows.
            call method cl_gui_cfw=>flush.
            if sy-subrc ne 0.
    add your handling, for example
             call function 'POPUP_TO_INFORM'
                  exporting
                       titel = g_repid
                       txt2  = sy-subrc
                       txt1  = 'Error in Flush'(500).
            else.
    *tHIS IS THE PART IAM HAVING PROBLEM WITH
    *class lcl_event_receiver implementation.
    method handle_toolbar.
    *clear : ls_toolbar.
    loop at e_object->mt_toolbar into ls_toolbar WHERE FUNCTION = 'ADD'.
    DELETE e_object->mt_toolbar FROM ls_toolbar.
    move ' ' to ls_toolbar-disabled.
    append ls_toolbar to e_object->mt_toolbar.
    endloop.
    *ENDMETHOD.
    *ENDCLASS.
    ***tHIS IS THE PART
      call method g_grid->refresh_table_display.
            endif.
        endcase.
      endmethod.
    Thanks in advance

    Hi
    hI ALL,
    MY QUESTION IS WHEN method handle_toolbaR WOULD BE TRIGERRED
    first time i have the button enabled and when i press the button its get disabled.This is what i need
    But iam trying to understand how this is working
    Let me know whether iam right or not
    when this piece of code would be triggered
    method handle_toolbar.
        clear ls_toolbar.
        move 3 to ls_toolbar-butn_type.
        append ls_toolbar to e_object->mt_toolbar.
        clear ls_toolbar.
        move 'ADD' to ls_toolbar-function.
        move icon_employee to ls_toolbar-icon.
        move 'Show Bookings'(111) to ls_toolbar-quickinfo.
        move 'Add Material'(112) to ls_toolbar-text.
        move ' ' to ls_toolbar-disabled.
        append ls_toolbar to e_object->mt_toolbar.
        IF FLAG = 'X'.
        LOOP AT e_object->mt_toolbar INTO ls_toolbar.
       if ls_toolbar-function = 'ADD'.
       ls_toolbar-disabled = 'X'.
       MODIFY e_object->mt_toolbar FROM ls_toolbar.
       endif.
       ENDLOOP.
        ENDIF.
    1 ) would this be triggered
    when i call this  call method g_grid->refresh_table_display.
    2)or
    call method g_grid->set_toolbar_interactive
    This is my piece of code
    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.
    class lcl_event_receiver implementation.
      method handle_toolbar.
        clear ls_toolbar.
        move 3 to ls_toolbar-butn_type.
        append ls_toolbar to e_object->mt_toolbar.
        clear ls_toolbar.
        move 'ADD' to ls_toolbar-function.
        move icon_employee to ls_toolbar-icon.
        move 'Show Bookings'(111) to ls_toolbar-quickinfo.
        move 'Add Material'(112) to ls_toolbar-text.
        move ' ' to ls_toolbar-disabled.
        append ls_toolbar to e_object->mt_toolbar.
        IF FLAG = 'X'.
        LOOP AT e_object->mt_toolbar INTO ls_toolbar.
       if ls_toolbar-function = 'ADD'.
       ls_toolbar-disabled = 'X'.
       MODIFY e_object->mt_toolbar FROM ls_toolbar.
       endif.
       ENDLOOP.
        ENDIF.
      endmethod.
      method handle_user_command.
        case e_ucomm.
          when 'ADD'.
            call method g_grid->get_selected_rows
                     importing et_index_rows = lt_rows.
            call method cl_gui_cfw=>flush.
            if sy-subrc ne 0.
            else.
        perform test.
      call method g_grid->refresh_table_display.
           endif.
        endcase.
      endmethod.                           "handle_user_command
    odule status_0100 output.
    SET PF-STATUS 'STATUS'.
      set pf-status 'MAIN100'.
      set titlebar 'HEADER_CHECK'.
    if g_custom_container is initial.
        create object g_custom_container
                 exporting container_name = g_container.
        create object g_grid
                   exporting i_parent = g_custom_container.
    call function 'LVC_FIELDCATALOG_MERGE'
    exporting
    i_structure_name = 'ZTEST'
    changing
    ct_fieldcat = fieldcat
    exceptions
    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.
    g_layout-sel_mode = 'A'.              " TO GET SELECTION BOX
    call method g_grid->set_table_for_first_display
    exporting
       I_BYPASSING_BUFFER            =
       I_BUFFER_ACTIVE               =
       I_CONSISTENCY_CHECK           =
       I_STRUCTURE_NAME              =
       IS_VARIANT                    =
       I_SAVE                        =
       I_DEFAULT                     = 'X'
         is_layout                     = g_layout
       IS_PRINT                      =
       IT_SPECIAL_GROUPS             =
        it_toolbar_excluding          = pt_exclude
       IT_HYPERLINK                  =
       IT_ALV_GRAPHICS               =
      changing
        it_outtab                     =  i_zTEST
        it_fieldcatalog               = fieldcat
       IT_SORT                       =
       IT_FILTER                     =
      exceptions
        invalid_parameter_combination = 1
        program_error                 = 2
        too_many_lines                = 3
        others                        = 4
    create object event_receiver.
        set handler event_receiver->handle_user_command for g_grid.
        set handler event_receiver->handle_toolbar for g_grid.
      call method g_grid->set_toolbar_interactive.
      endif.                               "IF grid1 IS INITIAL
      call method cl_gui_control=>set_focus exporting control = g_grid.
    endmodule.                 " STATUS_0100  OUTPUT
    Thanks
    Suchitra

  • Alv report using oops ABAP

    hi friendz,
    can any one of u give an example, how to build alv report using oops abap ?
    thanks in advance.
    points for sure
    regards,
    Vijaya

    Hi Vijaya,
    I hope the following code upto your requirement.
    *& Report  ZMAT_ALV_GRID                                               *
    REPORT  ZCL_CLASS1.
    TYPES: BEGIN OF T_MARA,
             MATNR TYPE MARA-MATNR,
             MAKTX TYPE MAKT-MAKTX,
             WERKS TYPE MARD-WERKS,
             LGORT TYPE MARD-LGORT,
             LABST TYPE MARD-LABST,
           END OF T_MARA.
    *DATA: IT_MARA TYPE STANDARD TABLE OF T_MARA.
    DATA: IT_MARA TYPE T_MARA OCCURS 0.
    DATA: O_CONT TYPE REF TO CL_GUI_CUSTOM_CONTAINER,
          O_GRID TYPE REF TO CL_GUI_ALV_GRID.
    DATA: X_FLDCAT TYPE LVC_S_FCAT.
    DATA: IT_FLDCAT TYPE LVC_T_FCAT.
    DATA: I_LAYOUT TYPE LVC_S_LAYO.
    DATA: X_SORT TYPE LVC_S_SORT.
    DATA: I_SORT TYPE LVC_T_SORT.
    TABLES: MARA.
    SELECT-OPTIONS: S_MATNR FOR MARA-MATNR.
    PARAMETERS: P_CHK AS CHECKBOX.
    START-OF-SELECTION.
      PERFORM GET_DATA.
      PERFORM GENERATE_FLDCAT.
      PERFORM GENERATE_LAYOUT.
      PERFORM DO_SORT.
      SET SCREEN 100.
    *&      Module  STATUS_0100  OUTPUT
          text
    MODULE STATUS_0100 OUTPUT.
       SET PF-STATUS 'MAIN'.
    SET TITLEBAR 'xxx'.
       PERFORM BUILD_ALV.
    ENDMODULE.                 " STATUS_0100  OUTPUT
    *&      Module  USER_COMMAND_0100  INPUT
          text
    MODULE USER_COMMAND_0100 INPUT.
      CASE SY-UCOMM.
        WHEN 'BACK'.
          LEAVE PROGRAM.
      ENDCASE.
    ENDMODULE.                 " USER_COMMAND_0100  INPUT
    *&      Form  BUILD_ALV
          text
    FORM BUILD_ALV .
    CREATE OBJECT O_CONT
       EXPORTING
          CONTAINER_NAME              = 'MAT_CONTAINER'
       EXCEPTIONS
         CNTL_ERROR                  = 1
         CNTL_SYSTEM_ERROR           = 2
         CREATE_ERROR                = 3
         LIFETIME_ERROR              = 4
         LIFETIME_DYNPRO_DYNPRO_LINK = 5
         others                      = 6.
         CREATE OBJECT O_GRID
           EXPORTING
              I_PARENT          = O_CONT
           EXCEPTIONS
             ERROR_CNTL_CREATE = 1
             ERROR_CNTL_INIT   = 2
             ERROR_CNTL_LINK   = 3
             ERROR_DP_CREATE   = 4
             others            = 5.
    CALL METHOD O_GRID->SET_TABLE_FOR_FIRST_DISPLAY
       EXPORTING
       I_BUFFER_ACTIVE               =
       I_BYPASSING_BUFFER            =
       I_CONSISTENCY_CHECK           =
       I_STRUCTURE_NAME              =
       IS_VARIANT                    =
       I_SAVE                        =
       I_DEFAULT                     = ' '
         IS_LAYOUT                     = I_LAYOUT
       IS_PRINT                      =
       IT_SPECIAL_GROUPS             =
       IT_TOOLBAR_EXCLUDING          =
       IT_HYPERLINK                  =
       IT_ALV_GRAPHICS               =
       IT_EXCEPT_QINFO               =
       CHANGING
         IT_OUTTAB                     = IT_MARA
         IT_FIELDCATALOG               = IT_FLDCAT[]
         IT_SORT                       = I_SORT
       IT_FILTER                     =
      EXCEPTIONS
        INVALID_PARAMETER_COMBINATION = 1
        PROGRAM_ERROR                 = 2
        TOO_MANY_LINES                = 3
        others                        = 4.
    ENDFORM.                    " BUILD_ALV
    *&      Form  GET_DATA
          text
    FORM GET_DATA .
    SELECT A~MATNR
          B~MAKTX
          C~WERKS
          C~LGORT
          C~LABST
    INTO TABLE IT_MARA
    FROM MARA AS A
    INNER JOIN MAKT AS B
    ON BMATNR = AMATNR
    INNER JOIN MARD AS C
    ON CMATNR = AMATNR
    WHERE A~MATNR IN S_MATNR
    AND   B~SPRAS = SY-LANGU.
    ENDFORM.                    " GET_DATA
    *&      Form  GENERATE_FLDCAT
          text
    FORM GENERATE_FLDCAT .
    *CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
      EXPORTING
      I_BUFFER_ACTIVE              =
       I_STRUCTURE_NAME             = 'ZSMARA'
      I_CLIENT_NEVER_DISPLAY       = 'X'
      I_BYPASSING_BUFFER           =
      I_INTERNAL_TABNAME           = ' '
    CHANGING
       CT_FIELDCAT                  = IT_FLDCAT
    EXCEPTIONS
      INCONSISTENT_INTERFACE       = 1
      PROGRAM_ERROR                = 2
      OTHERS                       = 3.
    X_FLDCAT-COL_POS = 1.
    X_FLDCAT-FIELDNAME = 'MATNR'.
    X_FLDCAT-OUTPUTLEN = '18'.
    X_FLDCAT-REPTEXT = 'Material No'.
    APPEND X_FLDCAT TO IT_FLDCAT.
    X_FLDCAT-COL_POS = 2.
    X_FLDCAT-FIELDNAME = 'MAKTX'.
    X_FLDCAT-OUTPUTLEN = '48'.
    X_FLDCAT-REPTEXT = 'Material Desc'.
    X_FLDCAT-TOOLTIP = 'Material Desc'.
    APPEND X_FLDCAT TO IT_FLDCAT.
    X_FLDCAT-COL_POS = 3.
    X_FLDCAT-FIELDNAME = 'WERKS'.
    X_FLDCAT-OUTPUTLEN = '5'.
    X_FLDCAT-REPTEXT = 'Plant'.
    X_FLDCAT-TOOLTIP = 'Plant'.
    APPEND X_FLDCAT TO IT_FLDCAT.
    X_FLDCAT-COL_POS = 4.
    X_FLDCAT-FIELDNAME = 'LGORT'.
    X_FLDCAT-OUTPUTLEN = '5'.
    X_FLDCAT-REPTEXT = 'S.Loc'.
    X_FLDCAT-TOOLTIP = 'S.Loc'.
    APPEND X_FLDCAT TO IT_FLDCAT.
    X_FLDCAT-COL_POS = 5.
    X_FLDCAT-FIELDNAME = 'LABST'.
    X_FLDCAT-OUTPUTLEN = '20'.
    X_FLDCAT-REPTEXT = 'Quantity'.
    X_FLDCAT-TOOLTIP = 'Quantity'.
    X_FLDCAT-DO_SUM = 'X'.
    APPEND X_FLDCAT TO IT_FLDCAT.
    ENDFORM.                    " GENERATE_FLDCAT
    *&      Form  GENERATE_LAYOUT
          text
    FORM GENERATE_LAYOUT .
      I_LAYOUT-ZEBRA = 'X'.
      I_LAYOUT-FRONTEND = 'X'.
      I_LAYOUT-GRID_TITLE = 'ALV GRID USING OOPS'.
      I_LAYOUT-NUMC_TOTAL = 'X'.
    ENDFORM.                    " GENERATE_LAYOUT
    *&      Form  DO_SORT
          text
    FORM DO_SORT .
    X_SORT-FIELDNAME = 'MATNR'.
    X_SORT-UP = 'X'.
    X_SORT-SUBTOT = 'X'.
    IF P_CHK = 'X'.
       X_SORT-EXPA = SPACE.
    ELSE.
       X_SORT-EXPA = 'X'.
    ENDIF.
    APPEND X_SORT TO I_SORT.
    ENDFORM.                    " DO_SORT
    inorder to execute this code perfectly, do the following things.
    1. Create a Graphical Screen 100.
    2. Place a Custom Control on that screen and give name as MAT_CONTAINER.
    3. activate the screen.
    and execute the program.
      if this suits requirement award points.
    satish

Maybe you are looking for