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: 

about the change of alv

Former Member
0 Kudos

hi, expert,

how to judge if the value in alv is changed.

or how to get the internal table in current alv after changed

best regards,

Kevin

1 ACCEPTED SOLUTION

Former Member
0 Kudos

For getting the data from the current ALV ( after changing ) to your internal table, you have to set the editable mode for a particular field while populating your field catalogue. The Changes will automatically reflect in your inernal table.

6 REPLIES 6

Former Member
0 Kudos

You can make use of the following system field.

System Field : sy-datarDescription : At PAI, contains "X" if at least one input field of a screen has been changed by a user or by further data transfer, otherwise initial.

Former Member
0 Kudos

HI,

Refer to the link.

This may help.

Regards

Sumit Agarwal

0 Kudos

it seem doesn't work

how to realize it.

Former Member
0 Kudos

For getting the data from the current ALV ( after changing ) to your internal table, you have to set the editable mode for a particular field while populating your field catalogue. The Changes will automatically reflect in your inernal table.

0 Kudos

i am creating alv with class.

i know what you said.

but how to get the changd value or get the current internal table with function or class method.

0 Kudos

Check out this code:


*&---------------------------------------------------------------------*
*& Report  ZTEST_SOURAV22
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT  ztest_sourav22.

*----------------------------------------------------------------------*
*       CLASS main DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS main DEFINITION.
  PUBLIC SECTION.
    DATA: i_sbook TYPE STANDARD TABLE OF sbook INITIAL SIZE 0,
          i_sbook_old TYPE STANDARD TABLE OF sbook INITIAL SIZE 0.

    METHODS:constructor,
            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,
            check_changed_data.
  PROTECTED SECTION.


  PRIVATE SECTION.
    TYPE-POOLS: icon.
    DATA:container TYPE REF TO cl_gui_custom_container,
          oref_alv TYPE REF TO cl_gui_alv_grid,
          wa_layout TYPE lvc_s_layo,
          i_fieldcatalog TYPE lvc_t_fcat.
    METHODS:get_field_catalog,get_layout.
ENDCLASS.                    "main DEFINITION
*----------------------------------------------------------------------*
*       CLASS main IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS main IMPLEMENTATION.
  METHOD constructor.

    SELECT * FROM sbook INTO TABLE i_sbook
      UP TO 50 ROWS.
    i_sbook_old[] = i_sbook[].

    CREATE OBJECT container
      EXPORTING
*       parent                      =
        container_name              = 'CONT1'
*       style                       =
*       lifetime                    = lifetime_default
        repid                       = sy-repid
        dynnr                       = '0100'
*       no_autodef_progid_dynnr     =
      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 oref_alv
      EXPORTING
*        i_shellstyle      = 0
*        i_lifetime        =
         i_parent          = container
*        i_appl_events     = space
*        i_parentdbg       =
*        i_applogparent    =
*        i_graphicsparent  =
*        i_name            =
*        i_fcat_complete   = space
      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.

    CALL METHOD me->get_field_catalog.
    CALL METHOD me->get_layout.

    CALL METHOD oref_alv->set_table_for_first_display
      EXPORTING
*       i_buffer_active               =
*       i_bypassing_buffer            =
*       i_consistency_check           =
*       i_structure_name              =
*       is_variant                    =
*       i_save                        =
*       i_default                     = 'X'
        is_layout                     = wa_layout
*       is_print                      =
*       it_special_groups             =
*       it_toolbar_excluding          =
*       it_hyperlink                  =
*       it_alv_graphics               =
*       it_except_qinfo               =
*       ir_salv_adapter               =
      CHANGING
        it_outtab                     = i_sbook
        it_fieldcatalog               = i_fieldcatalog
*       it_sort                       =
*       it_filter                     =
      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.
    SET HANDLER me->handle_toolbar FOR oref_alv.
    SET HANDLER me->handle_user_command FOR oref_alv.

    CALL METHOD oref_alv->set_toolbar_interactive.

  ENDMETHOD.                    "constructor
  METHOD get_layout.
    wa_layout-cwidth_opt = 'X'.
  ENDMETHOD.                    "get_layout
  METHOD get_field_catalog.
    FIELD-SYMBOLS: <lf1> TYPE lvc_s_fcat.

    CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
      EXPORTING
*       I_BUFFER_ACTIVE              =
        i_structure_name             = 'SBOOK'
        i_client_never_display       = 'X'
*       I_BYPASSING_BUFFER           =
        i_internal_tabname           = 'I_SBOOK'
      CHANGING
        ct_fieldcat                  = i_fieldcatalog
      EXCEPTIONS
        inconsistent_interface       = 1
        program_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.

    LOOP AT i_fieldcatalog ASSIGNING <lf1>.
      IF <lf1>-fieldname = 'SMOKER'.
        <lf1>-edit = 'X'.  " REUSE_ALV_GRID_DISPLAY
      ENDIF.
    ENDLOOP.
  ENDMETHOD.                    "get_field_catalog
  METHOD handle_toolbar.
    DATA: l_toolbar  TYPE stb_button.
    CLEAR l_toolbar.
* append an icon to show booking table
    CLEAR l_toolbar.
    MOVE 'SAVE' TO l_toolbar-function.
    MOVE icon_system_save TO l_toolbar-icon.
    MOVE 'Save' TO l_toolbar-quickinfo.
    MOVE 'Save' TO l_toolbar-text.
    MOVE ' ' TO l_toolbar-disabled.
    APPEND l_toolbar TO e_object->mt_toolbar.

  ENDMETHOD.                    "handle_toolbar
  METHOD handle_user_command.
    CASE e_ucomm.
      WHEN 'SAVE'.
        IF i_sbook[] <> i_sbook_old[].
          MESSAGE i001(00) WITH 'You have changed some data'.
        ENDIF.
    ENDCASE.
  ENDMETHOD.                    "user_command
  METHOD CHECK_CHANGED_DATA.

    CALL METHOD oref_alv->check_changed_data
*      IMPORTING
*        e_valid   =
*      CHANGING
*        c_refresh = 'X'
        .


  ENDMETHOD.
ENDCLASS.                    "main IMPLEMENTATION

START-OF-SELECTION.

  DATA: oref_main TYPE REF TO main.
  CREATE OBJECT oref_main.

  CALL SCREEN 0100.
*&---------------------------------------------------------------------*
*&      Module  STATUS_0100  OUTPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE status_0100 OUTPUT.
  SET PF-STATUS 'S0100'.
*  SET TITLEBAR 'xxx'.

ENDMODULE.                 " STATUS_0100  OUTPUT
*&---------------------------------------------------------------------*
*&      Module  USER_COMMAND_0100  INPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE user_command_0100 INPUT.
  DATA: ok_code TYPE syucomm.
  CASE ok_code.
    WHEN 'BACK'.

      SET SCREEN 00.
      LEAVE SCREEN.
    WHEN 'SAVE'.  
" Check this part if the button is SAP standard function key
       CALL METHOD oref_main->CHECK_CHANGED_DATA.
        IF oref_main->i_sbook[] ne oref_main->i_sbook_old[].
          MESSAGE i001(00) WITH 'You have changed some data'.
        ENDIF.

  ENDCASE.
ENDMODULE.                 " USER_COMMAND_0100  INPUT

Edited by: Sourav Bhaduri on Sep 19, 2008 8:35 PM