Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Object Oriented ALV - Editable

Former Member
0 Likes
2,216

hi, Could anyone advice me please....as I'm trying to modify and save the values after displaying in ALV...but value which i'm modifying is not reflecting in ALV, it is displaying the old value....this problem is occuring only when I change the value for the first time...and prob is not occuring from second time....please correct me...


*&---------------------------------------------------------------------*
*&      Form  display_alv
*&---------------------------------------------------------------------*
FORM display_alv .
  IF w_grid IS INITIAL.
    CREATE OBJECT W_DOCK_CONTAINER
        RATIO          = '95'
    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 OBJECT W_GRID
        I_PARENT          =  W_DOCK_CONTAINER
      EXCEPTIONS
        ERROR_CNTL_CREATE = 1
        ERROR_CNTL_INIT   = 2
        ERROR_CNTL_LINK   = 3
        ERROR_DP_CREATE   = 4
        others            = 5.
    IF SY-SUBRC <> 0.
      MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
                 WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.

    PERFORM prepare_field_catalog CHANGING w_lvc_t_fcat.

    PERFORM prepare_layout CHANGING w_lvc_layo.

    W_DISVARIANT-REPORT = SY-REPID.

    CALL METHOD W_GRID->SET_TABLE_FOR_FIRST_DISPLAY
  EXPORTING
        IS_VARIANT                    = W_DISVARIANT
        I_SAVE                        = 'A'
        IS_LAYOUT                     = W_LVC_LAYO
      CHANGING
        IT_OUTTAB                     = I_YIBRK_EARNINGS[]
        IT_FIELDCATALOG               = W_LVC_T_FCAT
      EXCEPTIONS
        INVALID_PARAMETER_COMBINATION = 1
        PROGRAM_ERROR                 = 2
        TOO_MANY_LINES                = 3
        others                        = 4.
    IF SY-SUBRC <> 0.
      MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
                 WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
  ELSE.
*-- refresh table
    CALL METHOD W_GRID->refresh_table_DISPLAY
*      EXPORTING
         EXCEPTIONS
           finished = 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.
  ENDIF.
ENDFORM.                    " display_alv

*&---------------------------------------------------------------------*
*&      Module  USER_COMMAND_9500  INPUT
*&---------------------------------------------------------------------*
MODULE USER_COMMAND_9500 INPUT.
  CASE SY-UCOMM.
    WHEN 'BACK'.                              " BACK BUTTON
      SET SCREEN 0.
      LEAVE SCREEN.
    WHEN 'EXIT' OR 'CANCEL'.                  " EXIT AND CANCEL BUTTON
      LEAVE PROGRAM.
    WHEN 'SUBMIT'.                            "SUBMIT
      PERFORM submit_data.
    WHEN 'SAVE'.                              "SAVE
      PERFORM save_data.
  ENDCASE.
ENDMODULE.                 " USER_COMMAND_9500  INPUT
*&---------------------------------------------------------------------*
*&      Form  save_data
*&---------------------------------------------------------------------*
FORM save_data.
*-- if data changes
  CALL METHOD W_GRID->REGISTER_EDIT_EVENT
    EXPORTING
      I_EVENT_ID = cl_gui_alv_grid=>mc_evt_enter    " modified
    EXCEPTIONS
      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.                    " save_data
*&---------------------------------------------------------------------
*

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
975
use this method in ur user_command subroutine and checkout if it works

call method w_grid->check_changed_data
4 REPLIES 4
Read only

Former Member
0 Likes
976
use this method in ur user_command subroutine and checkout if it works

call method w_grid->check_changed_data
Read only

Former Member
0 Likes
975

Hi

Send me the code within perform submit_data

You have call the grid method check_changed_data on save .Which will raise the data_changed event of cl_alv_gui_grid.

METHOD HANDLE_DATA_CHANGED.

DATA : ROW_ID TYPE I,

FIELDNAME TYPE LVC_FNAME,

DATE1 TYPE I,

DATE2 TYPE I,

DATE3 TYPE I.

DATA : LV_VALUE TYPE I,

LV_VAL(10) TYPE N,

LV_VAL1 TYPE N.

DATA : COUNTER TYPE I VALUE 1,

COUNT TYPE I,

LS_DEL_ROW TYPE LVC_S_MOCE.

data : lv_eff_dt type /CPC/TCTMBRHST-CONTMBREFFDATE.

GV_FLAG = 'X'.

CLEAR ERROR_DATA.

SORT GT_PRICE_DATA BY COUNTER.

DATA : FS LIKE TABLE OF GT_PRICE_DATA.

FIELD-SYMBOLS :

<FS1> TYPE ANY,

<FS3> TYPE ANY,

<FS2> LIKE GS_PRICE_DATA.

CREATE DATA NEW_LINE LIKE LINE OF GT_PRICE_DATA.

ASSIGN NEW_LINE->* TO <GS_PRICE_DATA>.

CLEAR VAR.

*****Check for Inserted and Modified Rows

LOOP AT ER_DATA_CHANGED->MT_MOD_CELLS INTO LS_MOD_CELLS.

ASSIGN COMPONENT LS_MOD_CELLS-FIELDNAME OF STRUCTURE

<GS_PRICE_DATA>

TO <FS1>.

See the above method

Please reward if useful.

Read only

Former Member
0 Likes
975

Hi,

To modify database or ztable from the ALV grid,you need to do the following:

---You have to modify the field Catalog fields (fields that you want to make editable).Set the field EDIT as 'X'.For example if you want to make the field below editable:

ls_fcat-fieldname = 'CARRID'.

...

...

<b>ls_fcat-edit = 'X'.</b>

APPEND ls_fcat TO pt_fieldcat.

---Call the method below before you call the set_table_for_first_display/refresh_table_display.

<b>CALL METHOD ALV_GRID_INSTANCE->set_ready_for_input

EXPORTING

i_ready_for_input = 0. ( For Display ) and ('1' for Edit )</b>

After this put the set_table_for_first_display/refresh_table_display.

Now if the ALV data has changed,and you want to change the database or ztable,then in your pf status give a function code for SAVE button in the GUI.

In the PAI of the screen,in user command module write the following:

<b>WHEN 'SAVE'.

call method gr_alvgrid->check_changed_data

importing e_valid = l_valid.

if l_valid = 'X'.

MODIFY spfli FROM TABLE itab_spfli.

endif.</b>

(l_valid is a flag.

<b>DATA:l_valid type c.</b>

If you want to check if the user has entered any value on the grid, use the Method : CALL METHOD gr_alvgrid->check_changed_data.

This method returns a flag l_valid which can be checked to see if the data on the ALV grid has been changed or not.)

Regards,

Beejal

**Reward if this helps

Read only

Former Member
0 Likes
975

Hi all , Thanks for your valuable advices....points rewarded...

Thanks ...