Application Development 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: 

ALV program

Former Member
0 Kudos
137

Hi,

I am triyng to make a program for maintain a Z table using ALV... the program i was used as a template is BCALV_EDIT_04 but this program only insert and delete records but not maintain existing records.. please if any have a code or site where i can download it...

Thanks In Advance

Juan

1 ACCEPTED SOLUTION

former_member194669
Active Contributor
0 Kudos
90

Hi,

U need to manage the event DATA_CHANGED: in the report BCALV_EDIT_04

An example of handler class:

CLASS lcl_alv_handler_1100 DEFINITION.

PUBLIC SECTION.

METHODS:

handle_data_changed

FOR EVENT data_changed OF cl_gui_alv_grid

IMPORTING er_data_changed,

ENDCLASS.

10 REPLIES 10

former_member194669
Active Contributor
0 Kudos
91

Hi,

U need to manage the event DATA_CHANGED: in the report BCALV_EDIT_04

An example of handler class:

CLASS lcl_alv_handler_1100 DEFINITION.

PUBLIC SECTION.

METHODS:

handle_data_changed

FOR EVENT data_changed OF cl_gui_alv_grid

IMPORTING er_data_changed,

ENDCLASS.

0 Kudos
90

Thanks a®s...

I figure that... but could u be more specific??

Thanks In Advance

Juan

0 Kudos
90

Hi,


In OO case:
after creating your ALV, you have first to register to teh 'ENTER' event: everytime the user press enter, the event will be triggered:


CALL METHOD gr_alv->register_edit_event
      EXPORTING
        i_event_id = cl_gui_alv_grid=>mc_evt_enter.



Then you have to create the event handler:

CREATE OBJECT gr_alv_handler_1100.
    SET HANDLER gr_alv_handler_1100->handle_data_changed FOR gr_alv.



An example of handler class:

CLASS lcl_alv_handler_1100 DEFINITION.                          "#EC CLAS_FINAL
  PUBLIC SECTION.
    METHODS:
      handle_data_changed                                       "#EC CALLED
         FOR EVENT data_changed OF cl_gui_alv_grid
             IMPORTING er_data_changed,
ENDCLASS.               "LCL_ALV_HANDLER_1100

0 Kudos
90

Thanks again its more clear now... but i am stucked in the:

LOOP AT pr_data_changed->

.

.

.

.

endloop

Thanks In Advance

Juan

0 Kudos
90

Hi,

Simply call this method . This will automatically update your changes in the GRID to your output table


  call method g_grid->check_changed_data
    importing
      e_valid = v_valid.

0 Kudos
90

Hi,

Ok but i need to execute a modify comand to update my z table...

I dont know in which internal is the data changed,... gs_outtab? if so i need to read this table to know which records was modified

Thanks In advance

Juan

0 Kudos
90

Hi,

If you check the program BCALV_EDIT_04


  call method g_grid->set_table_for_first_display
       exporting it_toolbar_excluding  = lt_exclude
                 is_layout             = gs_layout
       changing  it_fieldcatalog       = pt_fieldcat
                 it_outtab             = pt_outtab[].  "<<<< Output table 

Once user press SAVE button In the PAI


*----------------------------------------------------------------------*
* Module Pai INPUT                                                     *
*----------------------------------------------------------------------*
* PAI module                                                           *
*----------------------------------------------------------------------*
module pai input.
  save_ok = ok_code.
  clear ok_code.
  case save_ok.
    when 'EXIT'.
      perform f_exit_program.
    when 'CANC'.
      perform f_exit_program.
    when 'BACK'.
      perform f_exit_program.
    when 'SAVE'.
      perform f_save_data.   "<<< You need to write a perform 
    when 'EVEW'.
      perform f_set_fcode.
      perform f_save_data .
    when 'VADD'.
      perform f_f4_help_fieldname.
  endcase.
endmodule.                               " Pai INPUT

*&---------------------------------------------------------------------*
* Form  f_save_data                                                    *
*&---------------------------------------------------------------------*
* After save                                                           *
*----------------------------------------------------------------------*
form f_save_data .
  data : p_index like sy-index.
  refresh : i_message, i_message1.

  call method g_grid->check_changed_data
    importing
      e_valid = v_valid.

  if not v_valid is initial.
    if save_ok eq 'SAVE'.
     loop at pt_outtab.
         "<<<<< write your statement to update your ZTABLE
     endloop,
   endif.
  endif.
endform.

0 Kudos
90

Thanks a lot...

Could u send me please the complete code of your example to jcdiezdemedina@gmail.com... it seems that the version are differentt.. we are on 4.6c

Thanks In Advance

Juan

0 Kudos
90

Hi,


form save_data.
  data: l_valid type c.
* §7.Check if any errors exist in protocol by using method
*    CHECK_CHANGED_DATA of your ALV Grid instance.

* The method CHECK_CHANGED_DATA checks all new cells syntactically,
* raises event DATA_CHANGED and looks then for any entries
* in the error protocol. If any exist the parameter e_valid
* is initial ('X' in the other case).
*
  call method g_grid->check_changed_data
               importing e_valid = l_valid.

  if l_valid is initial.
    call function 'POPUP_TO_INFORM'
         exporting
              titel = text-i06
              txt1  = text-i07
              txt2  = text-i08
              txt3  = text-i09.

  else.
    perform update_database. "<<< Check this form you need to write your update statements here
    message s000(0k) with text-s01.
  endif.
endform.

0 Kudos
90

Hi,

Ok but i dont think that the best way was to update my z table from outab.. i only need to update the modified records...


* 1.Delete Lines:
*  call method g_verifier->get_deleted_rows
*          importing deleted_rows = lt_del_rows.
*
*  delete sflight from table lt_del_rows.
*
** 2.Insert Lines:
*  call method g_verifier->get_inserted_rows
*          importing inserted_rows = lt_ins_keys.
*
*  loop at lt_ins_keys into l_ins_key.
*    read table gt_outtab into ls_outtab
*     with key carrid = l_ins_key-carrid
*              connid = l_ins_key-connid
*              fldate = l_ins_key-fldate.
*    if sy-subrc eq 0.
*      move-corresponding ls_outtab to ls_sflight.
*      append ls_sflight to lt_instab.
*    endif.
*  endloop.
*
*  insert sflight from table lt_instab.
*

the point 3 modified records is missing jajaja this the code i need...

Thanks In Advance

Juan