Skip to Content

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.

Add comment
10|10000 characters needed characters exceeded

  • Follow
  • Get RSS Feed

5 Answers

  • Best Answer
    author's profile photo
    Former Member
    Posted on Aug 23, 2007 at 10:06 AM

    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

    Add comment
    10|10000 characters needed characters exceeded

  • author's profile photo
    Former Member
    Posted on Aug 23, 2007 at 10:15 AM

    Hi,

    Go through the standard program <b>BCALV_TEST_GRID_EDITABLE</b>

    Regards,

    Azaz Ali.

    Add comment
    10|10000 characters needed characters exceeded

  • Posted on Aug 23, 2007 at 10:39 AM

    Consider a scenario for table controls;

    At time of validation for field,If the validation fails and error mesasge is displayed

    then all the fields are in display only mode and the field on which error had occured is in input mode and this situation should remains until the error is corrected.

    I have exactly the same requirement but using ALV grid.

    Add comment
    10|10000 characters needed characters exceeded

  • Posted on Aug 23, 2007 at 10:41 AM

    Consider a scenario for table controls;

    At time of validation for field,If the validation fails and error mesasge is displayed

    then all the fields are in display only mode and the field on which error had occured is in input mode and this situation should remains until the error is corrected.

    I have exactly the same requirement but using ALV grid.

    Add comment
    10|10000 characters needed characters exceeded

  • author's profile photo
    Former Member
    Posted on Aug 23, 2007 at 12:06 PM

    Hi all

    Here's some code to demo the above requirement

    I've got a Grid here where you can edit only cols 2,4 and 6.

    To use create a blank screen with a custom container CCONTAINER1 and (optionally a GUI status if you want the standard SAP buttons on the TOP of the screen).

    Here's the code

    Program ZJIMBOTESTX.

    <b>INCLUDE ZZJIMBOXX_INCL</b>.

    • Include contains the class definition and other data

    • shown at the end of this code.

    TABLES : SPFLI.

    TYPES: BEGIN OF s_elements.

    INCLUDE STRUCTURE spfli..

    TYPES: END OF s_elements.

    DATA:

    t_elements TYPE TABLE OF s_elements, "refers to our ITAB

    my_line TYPE s_elements.

    START-OF-SELECTION.

    CALL SCREEN 100.

    END-OF-SELECTION.

    MODULE status_0100 OUTPUT.

    CREATE OBJECT z_object

    EXPORTING z_object = z_object.

    CALL METHOD z_object->build_dynamic_structures

    EXPORTING

    my_line = my_line

    calling_program = sy-repid

    IMPORTING

    dy_table = dy_table

    CHANGING

    it_fldcat = it_fldcat.

    • Here before displaying you can change the field catalog to

    • adjust your own column names.

    *col_name col-nr 'your name' output length.

    col_name 2 'Carrier' 5.

    col_name 3 'Flt' 4.

    col_name 4 'Dep Ctry' 8.

    col_name 5 'Dep City' 8.

    col_name 6 'Airport' 6.

    • fill dynmic table and display

    PERFORM populate_dynamic_itab.

    CALL METHOD z_object->display_grid

    EXPORTING

    g_outtab = <dyn_table>

    g_fldcat = it_fldcat

    CHANGING

    it_fldcat = it_fldcat

    gt_outtab = <dyn_table>.

    SET PF-STATUS '0001'.

    SET TITLEBAR '000'.

    ENDMODULE.

    MODULE user_command_0100 INPUT.

    CASE sy-ucomm.

    WHEN 'BACK'.

    LEAVE PROGRAM.

    WHEN 'EXIT'.

    LEAVE PROGRAM.

    WHEN 'RETURN'.

    LEAVE PROGRAM.

    WHEN OTHERS.

    ENDCASE.

    ENDMODULE.

    FORM populate_dynamic_itab.

    ASSIGN dy_table->* TO <dyn_table>.

    CREATE DATA dy_line LIKE LINE OF <dyn_table>.

    ASSIGN dy_line->* TO <dyn_wa>.

    SELECT *

    UP TO 200 rows

    FROM SPFLI

    INTO CORRESPONDING FIELDS OF TABLE <dyn_table>.

    • save a copy (original table). Use same fcat as ist table.

    • create 2nd Dyn table to hold original data

    CALL METHOD cl_alv_table_create=>create_dynamic_table

    EXPORTING

    it_fieldcatalog = it_fldcat

    IMPORTING

    ep_table = dy_table.

    ASSIGN dy_table->* TO <orig_table>.

    CREATE DATA dy_line LIKE LINE OF <orig_table>.

    ASSIGN dy_line->* TO <dyn_wa>.

    <orig_table> = <dyn_table>.

    ENDFORM.

    FORM DATA_CHANGED

    USING

    changed_tab

    inserted_tab

    deleted_tab

    modified_cells_tab.

    ENDFORM.

    FORM process.

    • Orig table is in dynamic table <orig_table>

    • ALV GRID changed table is in <dyn_table>.

    Loop AT <orig_table> INTO <dyn_wa>.

    • Do what you want

    • end

    ENDLOOP.

    ENDFORM.

    FORM refresh.

    • change data for example delete some lines.

    *DELETE <dyn_table> from 1 to 16.

    CALL METHOD z_object->refresh_grid.

    ENDFORM.

    FORM dubbelklik

    USING

    e_row TYPE lvc_s_row

    e_column TYPE lvc_s_col

    es_row_no TYPE lvc_s_roid.

    SET TITLEBAR '001'.

    i_gridtitle = 'Grid Title Changed'.

    CALL METHOD z_object->change_title

    EXPORTING

    i_gridtitle = i_gridtitle.

    PERFORM refresh.

    CALL METHOD z_object->set_cursor

    EXPORTING

    row_id = e_row

    column_id = e_column

    row_no = es_row_no.

    ENDFORM.

    Also you'll need this INCLUDE program (Data and Class definition)

    • ZZJIMBOXX_INCL.

    • Generic ALV class etc for use as INCLUDE Jimbo 2007.

    DEFINE col_name.

    READ TABLE it_fldcat INTO wa_it_fldcat INDEX &1.

    wa_it_fldcat-coltext = &2.

    wa_it_fldcat-outputlen = &3.

    modify it_fldcat from wa_it_fldcat index &1.

    END-OF-DEFINITION.

    DEFINE toolbar_funcs.

    CLEAR ls_toolbar.

    MOVE 0 TO ls_toolbar-butn_TYPE.

    MOVE &1 TO ls_toolbar-function.

    MOVE SPACE TO ls_toolbar-disabled.

    MOVE &2 TO ls_toolbar-icon.

    MOVE &3 TO ls_toolbar-quickinfo.

    APPEND ls_toolbar TO e_object->mt_toolbar.

    END-OF-DEFINITION.

    INCLUDE <icon>.

    FIELD-SYMBOLS :

    <fs1> TYPE STANDARD TABLE,

    <fs0> TYPE STANDARD TABLE,

    <dyn_table> TYPE STANDARD TABLE,

    <orig_table> TYPE STANDARD TABLE,

    <dyn_wa> TYPE ANY.

    CLASS zcl_alv_test DEFINITION DEFERRED.

    DATA:

    z_object TYPE REF TO zcl_alv_test, "Instantiate our class

    it_fldcat TYPE lvc_t_fcat,

    i_gridtitle TYPE lvc_title,

    wa_it_fldcat TYPE lvc_s_fcat,

    new_table TYPE REF TO DATA,

    dy_table TYPE REF TO DATA,

    inserted_tab TYPE lvc_t_moce,

    deleted_tab TYPE LVC_T_MOCE,

    changed_tab TYPE REF TO DATA,

    is_layout TYPE LVC_S_LAYO,

    modified_cells_tab TYPE LVC_T_MODI,

    dy_line TYPE REF TO DATA.

    CLASS zcl_alv_test DEFINITION.

    PUBLIC SECTION.

    METHODS:

    constructor

    IMPORTING

    z_object TYPE REF TO zcl_alv_test,

    display_grid

    IMPORTING

    g_outtab TYPE STANDARD TABLE

    g_fldcat TYPE lvc_t_fcat

    CHANGING

    it_fldcat TYPE lvc_t_fcat

    GT_OUTTAB TYPE STANDARD TABLE,

    change_title

    IMPORTING

    i_gridtitle TYPE lvc_title,

    refresh_grid,

    set_cursor

    IMPORTING

    row_id TYPE lvc_s_row

    column_id TYPE lvc_s_col

    row_no TYPE lvc_s_roid,

    build_dynamic_structures

    IMPORTING

    my_line TYPE ANY

    calling_program TYPE sy-repid

    EXPORTING

    dy_table TYPE REF TO DATA

    CHANGING

    it_fldcat TYPE lvc_t_fcat .

    PRIVATE SECTION.

    *

    • Attributes

    *

    DATA:

    lr_rtti_struc TYPE REF TO cl_abap_structdescr,

    zog LIKE LINE OF lr_rtti_struc->components,

    zogt LIKE table of zog,

    struct_grid_lset TYPE lvc_s_layo,

    e_row TYPE lvc_s_row,

    e1_row TYPE i,

    e_value TYPE c,

    e1_col TYPE i,

    e_column TYPE lvc_s_col,

    es_rowid TYPE lvc_s_roid,

    es_row_id TYPE LVC_S_ROW,

    es_col_id TYPE LVC_S_COL,

    es_row_no TYPE lvc_s_roid,

    grid_container1 TYPE REF TO cl_gui_custom_container,

    grid1 TYPE REF TO cl_gui_alv_grid,

    ls_layout TYPE kkblo_layout,

    lt_fieldcat_wa TYPE kkblo_fieldcat,

    gt_outtab TYPE REF TO DATA,

    l_mode TYPE raw4,

    celltab TYPE lvc_t_styl,

    wa_celltab TYPE lvc_s_styl,

    lt_fieldcat TYPE kkblo_t_fieldcat,

    l_tabname TYPE slis_tabname,

    ls_toolbar TYPE stb_button,

    caller TYPE sy-repid,

    g_outtab1 TYPE REF TO DATA,

    g_fldcat1 TYPE REF TO DATA.

    *

    • Event Receivers - These methods are entered

    • when the specified event occurs

    *

    EVENTS: before_user_command.

    METHODS:

    on_user_command

    FOR EVENT before_user_command OF cl_gui_alv_grid

    IMPORTING

    e_ucomm

    sender,

    on_toolbar

    FOR EVENT toolbar OF cl_gui_alv_grid

    IMPORTING

    e_object

    e_interactive,

    on_dubbelklik

    FOR EVENT double_click OF cl_gui_alv_grid

    IMPORTING

    e_row

    e_column

    es_row_no,

    handle_data_changed

    FOR EVENT data_changed OF cl_gui_alv_grid

    IMPORTING

    er_data_changed,

    handle_data_changed_finished

    FOR EVENT data_changed_finished OF cl_gui_alv_grid

    IMPORTING

    e_modified

    et_good_cells,

    *

    • Rest of the methods

    *

    process,

    dubbelklik

    IMPORTING

    e_row TYPE lvc_s_row

    e_column TYPE lvc_s_col

    es_row_no TYPE lvc_s_roid,

    return_structure

    IMPORTING

    my_line TYPE ANY,

    create_dynamic_fcat

    EXPORTING

    it_fldcat TYPE lvc_t_fcat,

    create_dynamic_table

    IMPORTING

    it_fldcat TYPE lvc_t_fcat

    EXPORTING

    dy_table TYPE REF TO DATA,

    download_to_excel,

    refresh.

    ENDCLASS. "zcl_alv_test DEFINITION

    *

    • Implementation definition

    *

    CLASS zcl_alv_test IMPLEMENTATION.

    *

    • Constructor

    • create our reference / instance to cl_gui_alv_grid

    *

    METHOD constructor.

    CREATE OBJECT grid_container1

    EXPORTING

    container_name = 'CCONTAINER1'.

    CREATE OBJECT grid1

    EXPORTING

    i_parent = grid_container1.

    *

    • Set event handlers

    *

    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.

    CALL METHOD grid1->register_edit_event

    EXPORTING

    i_event_id = cl_gui_alv_grid=>mc_evt_enter.

    ENDMETHOD. "constructor

    *

    • Rest of the methods

    *

    METHOD on_dubbelklik.

    CALL METHOD me->dubbelklik

    EXPORTING

    e_row = e_row

    e_column = e_column

    es_row_no = es_row_no.

    ENDMETHOD. "on_dubbelklik

    *

    METHOD set_cursor.

    CALL METHOD grid1->set_current_cell_via_id

    EXPORTING

    is_row_id = row_id

    is_column_id = column_id

    is_row_no = row_no.

    ENDMETHOD.

    METHOD handle_data_changed.

    call method grid1->get_current_cell

    IMPORTING

    e_row = e1_row

    e_value = e_value

    e_col = e1_col

    es_row_id = es_row_id

    es_col_id = es_col_id

    es_row_no = es_row_no.

    changed_tab = er_data_changed->mp_mod_rows.

    inserted_tab = er_data_changed->mt_inserted_rows.

    deleted_tab = er_data_changed->mt_deleted_rows.

    modified_cells_tab = er_data_changed->mt_mod_cells.

    PERFORM data_changed IN PROGRAM (caller) IF FOUND

    USING changed_tab

    inserted_tab

    deleted_tab

    modified_cells_tab.

    ENDMETHOD. "handle_data_changed

    METHOD handle_data_changed_finished.

    ENDMETHOD. "handle_data_changed_finished

    METHOD return_structure.

    lr_rtti_struc ?= cl_abap_structdescr=>DESCRIBE_BY_DATA( my_line ).

    zogt[] = lr_rtti_struc->components.

    ENDMETHOD. "return_structure

    METHOD create_dynamic_fcat.

    LOOP AT zogt INTO zog.

    CLEAR wa_it_fldcat.

    wa_it_fldcat-fieldname = zog-name .

    wa_it_fldcat-dataTYPE = zog-TYPE_kind.

    wa_it_fldcat-intTYPE = zog-TYPE_kind.

    wa_it_fldcat-intlen = zog-length.

    wa_it_fldcat-decimals = zog-decimals.

    wa_it_fldcat-coltext = zog-name.

    wa_it_fldcat-lowercase = 'X'.

    case sy-tabix.

    When 2.

    wa_it_fldcat-edit = 'X'.

    When 4.

    wa_it_fldcat-edit = 'X'.

    when 6.

    wa_it_fldcat-edit = 'X'.

    when others.

    wa_it_fldcat-edit = ' '.

    endcase.

    APPEND wa_it_fldcat TO it_fldcat .

    ENDLOOP.

    ENDMETHOD. "create_dynamic_fcat

    METHOD download_to_excel.

    assign g_outtab1->* to <fs0>.

    assign g_fldcat1->* to <fs1>.

    CALL FUNCTION 'LVC_TRANSFER_TO_KKBLO'

    EXPORTING

    it_fieldcat_lvc = <fs1>

    • is_layout_lvc = m_cl_variant->ms_layout

    is_tech_complete = ' '

    IMPORTING

    es_layout_kkblo = ls_layout

    et_fieldcat_kkblo = lt_fieldcat.

    LOOP AT lt_fieldcat INTO lt_fieldcat_wa.

    CLEAR lt_fieldcat_wa-tech_complete.

    IF lt_fieldcat_wa-tabname IS initial.

    lt_fieldcat_wa-tabname = '1'.

    MODIFY lt_fieldcat FROM lt_fieldcat_wa.

    ENDIF.

    l_tabname = lt_fieldcat_wa-tabname.

    ENDLOOP.

    CALL FUNCTION 'ALV_XXL_CALL'

    EXPORTING

    i_tabname = l_tabname

    is_layout = ls_layout

    it_fieldcat = lt_fieldcat

    i_title = sy-title

    TABLES

    it_outtab = <fs0>

    EXCEPTIONS

    fatal_error = 1

    no_display_possible = 2

    others = 3.

    IF sy-subrc <> 0.

    message id sy-msgid TYPE 'S' number sy-msgno

    with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

    ENDIF.

    ENDMETHOD. "download_to_excel

    METHOD change_title.

    CALL METHOD grid1->set_gridtitle

    EXPORTING

    i_gridtitle = i_gridtitle.

    ENDMETHOD. "CHANGE_TITLE

    METHOD create_dynamic_table.

    CALL METHOD cl_alv_table_create=>create_dynamic_table

    EXPORTING

    it_fieldcatalog = it_fldcat

    IMPORTING

    ep_table = dy_table.

    ENDMETHOD. "create_dynamic_table

    METHOD build_dynamic_structures.

    caller = calling_program.

    CALL METHOD me->return_structure

    EXPORTING

    my_line = my_line.

    CALL METHOD me->create_dynamic_fcat

    IMPORTING

    it_fldcat = it_fldcat.

    CALL METHOD me->create_dynamic_table

    EXPORTING

    it_fldcat = it_fldcat

    IMPORTING

    dy_table = dy_table.

    ENDMETHOD. "build_dynamic_structures

    METHOD display_grid.

    GET REFERENCE OF g_outtab INTO g_outtab1.

    GET REFERENCE OF g_fldcat INTO g_fldcat1.

    struct_grid_lset-grid_title = 'TEST ALV USE generic class'.

    struct_grid_lset-zebra = 'X '.

    • struct_grid_lset-ctab_fname = 'T_CELLCOLORS'.

    • struct_grid_lset-stylefname = 'CELLTAB'.

    • CALL METHOD grid1->set_ready_for_input "sets WHOLE GRID editable in one step

    • EXPORTING

    • i_ready_for_input = '1'.

    CALL METHOD grid1->set_table_for_first_display

    EXPORTING

    is_layout = struct_grid_lset

    CHANGING

    it_outtab = gt_outtab

    it_fieldcatalog = it_fldcat.

    ENDMETHOD. "display_grid

    METHOD on_user_command.

    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.

    ENDCASE.

    ENDMETHOD. "on_user_command

    METHOD on_toolbar.

    • customize this section with your own Buttons

    • When a button is pressed method ON_USER_COMMAND is entered

    toolbar_funcs 'EXIT' icon_system_end 'Click2exit'.

    toolbar_funcs 'SAVE' icon_system_save 'Savedata'.

    toolbar_funcs 'EDIT' icon_toggle_display_change 'Edit data'.

    toolbar_funcs 'PROC' icon_businav_process 'Process'.

    toolbar_funcs 'EXCEL' icon_xxl 'Excel'.

    toolbar_funcs 'REFR' icon_refresh 'Refresh'.

    ENDMETHOD. "on_toolbar

    METHOD refresh_grid.

    CALL METHOD cl_gui_cfw=>flush.

    CALL METHOD grid1->refresh_table_display.

    ENDMETHOD. "refresh_grid

    METHOD refresh.

    PERFORM refresh IN PROGRAM (caller) IF FOUND.

    ENDMETHOD. "refresh

    METHOD process.

    PERFORM process IN PROGRAM (caller) IF FOUND.

    ENDMETHOD. "process

    METHOD dubbelklik.

    perform dubbelklik IN PROGRAM (caller) IF FOUND

    USING e_row

    e_column

    es_row_no.

    ENDMETHOD. "dubbelklik

    ENDCLASS. "zcl_alv_test IMPLEMENTATION

    This should work for ANY table you want to define. Just ensure that the structure you use is defined in these variables

    t_elements TYPE TABLE OF s_elements, "refers to our ITAB

    my_line TYPE s_elements.

    You don't have to worry about creating the table or fieldcatalog --it's all done dynamically in the class.

    All your code needs to do is populate your data table and handle processing when the use selects a cell or presses a toolbar button.

    Have fun.

    Cheers

    jimbo

    Add comment
    10|10000 characters needed characters exceeded