Skip to Content
author's profile photo Former Member
Former Member

How to regenerate additional rows after user clicks enter?

Hi all,

I am outputing the data through internal table(contains two fields 'Country' and 'Test')using ALV Classes.

My requirement is user can add another row.And

after appending another row user will enter country(say India) against the country

field and clicks enter.Then the program has to fetch all the tests(say 'test1' and 'test2' are there

for India) described for India from the database table and refresh the screen

with this additonal 2 rows(India, Test1 and India,Test2).

Can anyone please let me know how to do it?Remember I am using ALV Classes.

Thanks,

Balaji.

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

3 Answers

  • author's profile photo Former Member
    Former Member
    Posted on Nov 18, 2007 at 08:33 PM

    Hi Balaji,

    I think ALV is not the best way to do this kind of requirements. ALV is for reporting purpose. So, i suggest you to use Dialog Programming with Table Control.

    Regards,

    Satish

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Nov 19, 2007 at 08:02 PM

    Hello Balaji

    The sample report <b>ZUS_SDN_ALVGRID_EDITABLE_7</b> shows you how to implement your requirements using ALV lists. Procedure:

    1. Add a new row.

    2. Enter value '003' in column "Sort Key" of new row.

    3. Push ENTER button.

    The report will add two additional rows to the ALV list and modify the first added row:

    - '003' & 'K1'

    - '003' & 'K2'

    - '003' & 'K3'

    *&---------------------------------------------------------------------*
    *& Report  ZUS_SDN_ALVGRID_EDITABLE_7
    *&
    *&---------------------------------------------------------------------*
    *&
    *&
    *&---------------------------------------------------------------------*
    
    REPORT  zus_sdn_alvgrid_editable_7.
    
    
    TYPE-POOLS: abap.
    
    DATA:
      gd_repid         TYPE syrepid,
      gd_okcode        TYPE ui_func,
    *
      gs_layout        TYPE lvc_s_layo,
      gt_fcat          TYPE lvc_t_fcat,
      go_docking       TYPE REF TO cl_gui_docking_container,
      go_grid          TYPE REF TO cl_gui_alv_grid.
    
    
    TYPES: BEGIN OF ty_s_outtab.
    INCLUDE TYPE knb1.
    TYPES: END OF ty_s_outtab.
    types: ty_t_outtab    type standard table of ty_s_outtab
                          with default key.
    
    DATA:
    **  gs_outtab        TYPE ty_s_outtab,
      gt_outtab        TYPE STANDARD TABLE OF ty_s_outtab
                       WITH DEFAULT KEY.
    
    
    
    *---------------------------------------------------------------------*
    *       CLASS lcl_eventhandler DEFINITION
    *---------------------------------------------------------------------*
    *
    *---------------------------------------------------------------------*
    CLASS lcl_eventhandler DEFINITION.
    
      PUBLIC SECTION.
    
        CLASS-METHODS:
          handle_data_changed
            FOR EVENT data_changed OF cl_gui_alv_grid
            IMPORTING
              er_data_changed
              e_onf4
              e_onf4_before
              e_onf4_after
              e_ucomm
              sender,
    
          handle_data_changed_finished
            FOR EVENT data_changed_finished OF cl_gui_alv_grid
            IMPORTING
              e_modified
              et_good_cells,
    
          handle_user_command
            FOR EVENT user_command OF cl_gui_alv_grid
            IMPORTING
              e_ucomm,
    
    
          handle_toolbar
            FOR EVENT toolbar OF cl_gui_alv_grid
            IMPORTING
              e_object
              e_interactive.
    
    
    ENDCLASS.                    "lcl_eventhandler DEFINITION
    
    
    *---------------------------------------------------------------------*
    *       CLASS lcl_eventhandler IMPLEMENTATION
    *---------------------------------------------------------------------*
    *
    *---------------------------------------------------------------------*
    CLASS lcl_eventhandler IMPLEMENTATION.
    
      METHOD handle_data_changed.
    *   define local data
    
        cl_gui_cfw=>set_new_ok_code( 'REFRESH' ).
    
      ENDMETHOD.                    "handle_data_changed
    
      METHOD handle_data_changed_finished.
    *   define local data
        DATA:
          ls_outtab      TYPE ty_s_outtab,
          ls_cell        TYPE lvc_s_modi.
    
    
      ENDMETHOD.                    "handle_data_changed_finished
    
      METHOD handle_user_command.
    
      ENDMETHOD.                    "handle_user_command
    
      METHOD handle_toolbar.
    *   define local data
        DATA:
          ls_button    TYPE stb_button.
    
        ls_button-function  = 'DEFAULT'.
        ls_button-icon      = icon_mass_change.
        ls_button-quickinfo = 'Set default value for column'.
        APPEND ls_button TO e_object->mt_toolbar.
    
      ENDMETHOD.                    "handle_toolbar
    
    ENDCLASS.                    "lcl_eventhandler IMPLEMENTATION
    
    
    
    
    START-OF-SELECTION.
    
    
      SELECT * FROM knb1 INTO TABLE gt_outtab UP TO 20 ROWS
        WHERE bukrs = '1000'.
    
    
    
    
    
    * Create docking container
      CREATE OBJECT go_docking
        EXPORTING
          parent                      = cl_gui_container=>screen0
          ratio                       = 90
        EXCEPTIONS
          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 ALV grid
      CREATE OBJECT go_grid
        EXPORTING
          i_parent          = go_docking
        EXCEPTIONS
          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.
    
    
    
    * Build fieldcatalog
      PERFORM build_fieldcatalog.
    
      PERFORM set_layout.
    
      SET HANDLER:
        lcl_eventhandler=>handle_toolbar               FOR go_grid,
        lcl_eventhandler=>handle_data_changed          FOR go_grid,
        lcl_eventhandler=>handle_data_changed_finished FOR go_grid.
    
    
    
    * Display data
      CALL METHOD go_grid->set_table_for_first_display
        EXPORTING
          is_layout       = gs_layout
        CHANGING
          it_outtab       = gt_outtab
          it_fieldcatalog = gt_fcat
        EXCEPTIONS
          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.
    
      go_grid->set_toolbar_interactive( ).
    
      CALL METHOD go_grid->register_edit_event
        EXPORTING
          i_event_id = cl_gui_alv_grid=>mc_evt_enter
        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.
    
    
    * Link the docking container to the target dynpro
      gd_repid = syst-repid.
      CALL METHOD go_docking->link
        EXPORTING
          repid                       = gd_repid
          dynnr                       = '0100'
    *      CONTAINER                   =
        EXCEPTIONS
          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.
    
    
    * ok-code field = GD_OKCODE
      CALL SCREEN '0100'.
    * Flow logic (no elements on screen):
    *  PROCESS BEFORE OUTPUT.
    *    MODULE STATUS_0100.
    **
    *  PROCESS AFTER INPUT.
    *    MODULE USER_COMMAND_0100.
    
    
    END-OF-SELECTION.
    
    *&---------------------------------------------------------------------*
    *&      Module  STATUS_0100  OUTPUT
    *&---------------------------------------------------------------------*
    *       text
    *----------------------------------------------------------------------*
    MODULE status_0100 OUTPUT.
      SET PF-STATUS 'STATUS_0100'.
    *  SET TITLEBAR 'xxx'.
    
      CALL METHOD go_grid->refresh_table_display
    *      EXPORTING
    *        IS_STABLE      =
    *        I_SOFT_REFRESH =
        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.
    
    ENDMODULE.                 " STATUS_0100  OUTPUT
    
    *&---------------------------------------------------------------------*
    *&      Module  USER_COMMAND_0100  INPUT
    *&---------------------------------------------------------------------*
    *       text
    *----------------------------------------------------------------------*
    MODULE user_command_0100 INPUT.
    
      TRANSLATE gd_okcode TO UPPER CASE.
    
    * Fetch changes on ALV grid
      go_grid->check_changed_data( ).
    
      CASE gd_okcode.
        WHEN 'BACK' OR
             'END'  OR
             'CANC'.
          SET SCREEN 0. LEAVE SCREEN.
    
        WHEN 'REFRESH'.
          PERFORM refresh_outtab.
    
        WHEN OTHERS.
      ENDCASE.
    
    
    
    
    
      CLEAR: gd_okcode.
    
    ENDMODULE.                 " USER_COMMAND_0100  INPUT
    
    
    *&---------------------------------------------------------------------*
    *&      Form  BUILD_FIELDCATALOG_KNB1
    *&---------------------------------------------------------------------*
    *       text
    *----------------------------------------------------------------------*
    *  -->  p1        text
    *  <--  p2        text
    *----------------------------------------------------------------------*
    FORM build_fieldcatalog .
    * define local data
      DATA:
        ls_fcat        TYPE lvc_s_fcat.
    
    
    
      CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
        EXPORTING
    *     I_BUFFER_ACTIVE              =
          i_structure_name             = 'KNB1'
    *     I_CLIENT_NEVER_DISPLAY       = 'X'
    *     I_BYPASSING_BUFFER           =
    *     I_INTERNAL_TABNAME           =
        CHANGING
          ct_fieldcat                  = gt_fcat
        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.
    
    
    
    
      " Set required fields editable
      LOOP AT gt_fcat INTO ls_fcat
                      WHERE ( fieldname = 'ZUAWA'  OR
                              fieldname = 'BUSAB' ).
        ls_fcat-edit    = abap_true.
    
        MODIFY gt_fcat FROM ls_fcat.
      ENDLOOP.
    
      DELETE gt_fcat WHERE ( fieldname = 'ZINRT' ).
    
    
    ENDFORM.                    " BUILD_FIELDCATALOG
    
    
    *&---------------------------------------------------------------------*
    *&      Form  SET_LAYOUT
    *&---------------------------------------------------------------------*
    *       text
    *----------------------------------------------------------------------*
    *  -->  p1        text
    *  <--  p2        text
    *----------------------------------------------------------------------*
    FORM set_layout .
    
      CLEAR: gs_layout.
    
      gs_layout-cwidth_opt = abap_true.
      gs_layout-zebra      = abap_true.
    
    **  gs_layout-stylefname = 'CELLTAB'.
    
    ENDFORM.                    " SET_LAYOUT
    
    *&---------------------------------------------------------------------*
    *&      Form  REFRESH_OUTTAB
    *&---------------------------------------------------------------------*
    *       text
    *----------------------------------------------------------------------*
    *  -->  p1        text
    *  <--  p2        text
    *----------------------------------------------------------------------*
    FORM refresh_outtab .
    * define local data
      DATA:
        ld_idx       TYPE i,
        ls_outtab    TYPE ty_s_outtab,
        ls_tmp       TYPE ty_s_outtab,
        lt_tmp       TYPE ty_t_outtab.
    
      " Simulate selection of data depending on value of ZUAWA
      ls_tmp-zuawa = '003'.
      ls_tmp-busab = 'K1'.  APPEND ls_tmp TO lt_tmp.
      ls_tmp-busab = 'K2'.  APPEND ls_tmp TO lt_tmp.
      ls_tmp-busab = 'K3'.  APPEND ls_tmp TO lt_tmp.
    
    " Note: should be more elaborated than this simplified refresh routine...
      LOOP AT gt_outtab INTO ls_outtab
                        WHERE ( zuawa = '003'
                        AND     busab IS INITIAL ).
        ld_idx = syst-tabix.
    
        LOOP AT lt_tmp INTO ls_tmp.
          ls_outtab-busab = ls_tmp-busab.
    
          IF ( syst-tabix = 1 ).
            MODIFY gt_outtab FROM ls_outtab INDEX ld_idx.
          ELSE.
            APPEND ls_outtab TO gt_outtab.
          ENDIF.
        ENDLOOP.
    
    
      ENDLOOP.
    
    ENDFORM.                    " REFRESH_OUTTAB
    

    Regards

    Uwe

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member Uwe Schieferstein

      Hi Uwe,

      Thanks for your solution,which helped me a lot.Can you also please let me know about the code when the user deletes the row.

      Requirement is same as the previous.Here user can also delete the row,which has to updated in the database table.How to handle when the row is deleted??

      Please I need it uregently

      Thanks,

      Balaji

  • Posted on Nov 20, 2007 at 07:54 PM

    Hello Balaji

    I would use a simplified approach by storing the PBO output before displaying the editable ALV list. As soon as the user wants to save the data (enter 'SAVE' in command window) the report compares the PBO data with the current PAI data.

    To see the effect simply add a single row as previously described (resulting in three new rows) and delete two other rows. Inserted and deleted rows will be displayed afterwards.

    *&---------------------------------------------------------------------*
    *& Report  ZUS_SDN_ALVGRID_EDITABLE_7
    *&
    *&---------------------------------------------------------------------*
    *&
    *&
    *&---------------------------------------------------------------------*
    
    REPORT  zus_sdn_alvgrid_editable_7.
    
    
    TYPE-POOLS: abap.
    
    INCLUDE <icon>.  " NOTE: replace by TYPE-POOLS: icon. on >= 6.20
    
    DATA:
      gd_repid         TYPE syrepid,
      gd_okcode        TYPE sy-ucomm,
    *
      gs_layout        TYPE lvc_s_layo,
      gt_fcat          TYPE lvc_t_fcat,
      go_docking       TYPE REF TO cl_gui_docking_container,
      go_grid          TYPE REF TO cl_gui_alv_grid.
    
    
    TYPES: BEGIN OF ty_s_outtab.
    INCLUDE TYPE knb1.
    TYPES: END OF ty_s_outtab.
    TYPES: ty_t_outtab    TYPE STANDARD TABLE OF ty_s_outtab
                          WITH DEFAULT KEY.
    
    DATA:
      gt_outtab        TYPE ty_t_outtab,
      gt_outtab_pbo    TYPE ty_t_outtab.
    
    
    
    *---------------------------------------------------------------------*
    *       CLASS lcl_eventhandler DEFINITION
    *---------------------------------------------------------------------*
    *
    *---------------------------------------------------------------------*
    CLASS lcl_eventhandler DEFINITION.
    
      PUBLIC SECTION.
    
        CLASS-METHODS:
          handle_data_changed
            FOR EVENT data_changed OF cl_gui_alv_grid
            IMPORTING
              er_data_changed
              e_onf4
              e_onf4_before
              e_onf4_after
              e_ucomm
              sender,
    
          handle_data_changed_finished
            FOR EVENT data_changed_finished OF cl_gui_alv_grid
            IMPORTING
              e_modified
              et_good_cells,
    
          handle_user_command
            FOR EVENT user_command OF cl_gui_alv_grid
            IMPORTING
              e_ucomm,
    
    
          handle_toolbar
            FOR EVENT toolbar OF cl_gui_alv_grid
            IMPORTING
              e_object
              e_interactive.
    
    
    ENDCLASS.                    "lcl_eventhandler DEFINITION
    
    
    *---------------------------------------------------------------------*
    *       CLASS lcl_eventhandler IMPLEMENTATION
    *---------------------------------------------------------------------*
    *
    *---------------------------------------------------------------------*
    CLASS lcl_eventhandler IMPLEMENTATION.
    
      METHOD handle_data_changed.
    *   define local data
    
    **    cl_gui_cfw=>set_new_ok_code( 'REFRESH' ). " not possible on 4.6c
        CALL METHOD cl_gui_cfw=>set_new_ok_code
          EXPORTING
            new_code = 'REFRESH'
    *      IMPORTING
    *        RC       =
            .
    
    
      ENDMETHOD.                    "handle_data_changed
    
      METHOD handle_data_changed_finished.
    *   define local data
        DATA:
          ls_outtab      TYPE ty_s_outtab,
          ls_cell        TYPE lvc_s_modi.
    
    
      ENDMETHOD.                    "handle_data_changed_finished
    
      METHOD handle_user_command.
    
      ENDMETHOD.                    "handle_user_command
    
      METHOD handle_toolbar.
    *   define local data
        DATA:
          ls_button    TYPE stb_button.
    
        ls_button-function  = 'DEFAULT'.
        ls_button-icon      = icon_mass_change.
        ls_button-quickinfo = 'Set default value for column'.
        APPEND ls_button TO e_object->mt_toolbar.
    
      ENDMETHOD.                    "handle_toolbar
    
    ENDCLASS.                    "lcl_eventhandler IMPLEMENTATION
    
    
    
    
    START-OF-SELECTION.
    
    
      SELECT * FROM knb1 INTO TABLE gt_outtab UP TO 20 ROWS
        WHERE bukrs = '1000'.
    
      gt_outtab_pbo = gt_outtab.  " store PBO data
    
    
    
    * Create docking container
      CREATE OBJECT go_docking
        EXPORTING
          parent                      = cl_gui_container=>screen0
          ratio                       = 90
        EXCEPTIONS
          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 ALV grid
      CREATE OBJECT go_grid
        EXPORTING
          i_parent          = go_docking
        EXCEPTIONS
          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.
    
    
    
    * Build fieldcatalog
      PERFORM build_fieldcatalog.
    
      PERFORM set_layout.
    
      SET HANDLER:
        lcl_eventhandler=>handle_toolbar               FOR go_grid,
        lcl_eventhandler=>handle_data_changed          FOR go_grid,
        lcl_eventhandler=>handle_data_changed_finished FOR go_grid.
    
    
    
    * Display data
      CALL METHOD go_grid->set_table_for_first_display
        EXPORTING
          is_layout       = gs_layout
        CHANGING
          it_outtab       = gt_outtab
          it_fieldcatalog = gt_fcat
        EXCEPTIONS
          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.
    
      go_grid->set_toolbar_interactive( ).
    
      CALL METHOD go_grid->register_edit_event
        EXPORTING
          i_event_id = cl_gui_alv_grid=>mc_evt_enter
        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.
    
    
    * Link the docking container to the target dynpro
      gd_repid = syst-repid.
      CALL METHOD go_docking->link
        EXPORTING
          repid                       = gd_repid
          dynnr                       = '0100'
    *      CONTAINER                   =
        EXCEPTIONS
          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.
    
    
    * ok-code field = GD_OKCODE
      CALL SCREEN '0100'.
    * Flow logic (no elements on screen):
    *  PROCESS BEFORE OUTPUT.
    *    MODULE STATUS_0100.
    **
    *  PROCESS AFTER INPUT.
    *    MODULE USER_COMMAND_0100.
    
    
    END-OF-SELECTION.
    
    *&---------------------------------------------------------------------*
    *&      Module  STATUS_0100  OUTPUT
    *&---------------------------------------------------------------------*
    *       text
    *----------------------------------------------------------------------*
    MODULE status_0100 OUTPUT.
      SET PF-STATUS 'STATUS_0100'.
    *  SET TITLEBAR 'xxx'.
    
      CALL METHOD go_grid->refresh_table_display
    *      EXPORTING
    *        IS_STABLE      =
    *        I_SOFT_REFRESH =
        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.
    
    ENDMODULE.                 " STATUS_0100  OUTPUT
    
    *&---------------------------------------------------------------------*
    *&      Module  USER_COMMAND_0100  INPUT
    *&---------------------------------------------------------------------*
    *       text
    *----------------------------------------------------------------------*
    MODULE user_command_0100 INPUT.
    
      TRANSLATE gd_okcode TO UPPER CASE.
    
    * Fetch changes on ALV grid
      go_grid->check_changed_data( ).
    
      CASE gd_okcode.
        WHEN 'BACK' OR
             'END'  OR
             'CANC'.
          SET SCREEN 0. LEAVE SCREEN.
    
        WHEN 'REFRESH'.
          PERFORM refresh_outtab.
    
        WHEN 'SAVE'.
          PERFORM save_data.
    
        WHEN OTHERS.
      ENDCASE.
    
    
    
    
    
      CLEAR: gd_okcode.
    
    ENDMODULE.                 " USER_COMMAND_0100  INPUT
    
    
    *&---------------------------------------------------------------------*
    *&      Form  BUILD_FIELDCATALOG_KNB1
    *&---------------------------------------------------------------------*
    *       text
    *----------------------------------------------------------------------*
    *  -->  p1        text
    *  <--  p2        text
    *----------------------------------------------------------------------*
    FORM build_fieldcatalog .
    * define local data
      DATA:
        ls_fcat        TYPE lvc_s_fcat.
    
    
    
      CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
        EXPORTING
    *     I_BUFFER_ACTIVE              =
          i_structure_name             = 'KNB1'
    *     I_CLIENT_NEVER_DISPLAY       = 'X'
    *     I_BYPASSING_BUFFER           =
    *     I_INTERNAL_TABNAME           =
        CHANGING
          ct_fieldcat                  = gt_fcat
        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.
    
    
    
    
      " Set required fields editable
      LOOP AT gt_fcat INTO ls_fcat
                      WHERE ( fieldname = 'ZUAWA'  OR
                              fieldname = 'BUSAB' ).
        ls_fcat-edit    = abap_true.
    
        MODIFY gt_fcat FROM ls_fcat.
      ENDLOOP.
    
      DELETE gt_fcat WHERE ( fieldname = 'ZINRT' ).
    
    
    ENDFORM.                    " BUILD_FIELDCATALOG
    
    
    *&---------------------------------------------------------------------*
    *&      Form  SET_LAYOUT
    *&---------------------------------------------------------------------*
    *       text
    *----------------------------------------------------------------------*
    *  -->  p1        text
    *  <--  p2        text
    *----------------------------------------------------------------------*
    FORM set_layout .
    
      CLEAR: gs_layout.
    
      gs_layout-cwidth_opt = abap_true.
      gs_layout-zebra      = abap_true.
    
    **  gs_layout-stylefname = 'CELLTAB'.
    
    ENDFORM.                    " SET_LAYOUT
    
    *&---------------------------------------------------------------------*
    *&      Form  REFRESH_OUTTAB
    *&---------------------------------------------------------------------*
    *       text
    *----------------------------------------------------------------------*
    *  -->  p1        text
    *  <--  p2        text
    *----------------------------------------------------------------------*
    FORM refresh_outtab .
    * define local data
      DATA:
        ld_idx       TYPE i,
        ls_outtab    TYPE ty_s_outtab,
        ls_tmp       TYPE ty_s_outtab,
        lt_tmp       TYPE ty_t_outtab.
    
      " Simulate selection of data depending on value of ZUAWA
      ls_tmp-zuawa = '003'.
      ls_tmp-busab = 'K1'.  APPEND ls_tmp TO lt_tmp.
      ls_tmp-busab = 'K2'.  APPEND ls_tmp TO lt_tmp.
      ls_tmp-busab = 'K3'.  APPEND ls_tmp TO lt_tmp.
    
    
      LOOP AT gt_outtab INTO ls_outtab
                        WHERE ( zuawa = '003'
                        AND     busab IS INITIAL ).
        ld_idx = syst-tabix.
    
        LOOP AT lt_tmp INTO ls_tmp.
          ls_outtab-busab = ls_tmp-busab.
    
          IF ( syst-tabix = 1 ).
            MODIFY gt_outtab FROM ls_outtab INDEX ld_idx.
          ELSE.
            APPEND ls_outtab TO gt_outtab.
          ENDIF.
        ENDLOOP.
    
    
      ENDLOOP.
    
    
    
    ENDFORM.                    " REFRESH_OUTTAB
    
    
    *&---------------------------------------------------------------------*
    *&      Form  SAVE_DATA
    *&---------------------------------------------------------------------*
    *       text
    *----------------------------------------------------------------------*
    *  -->  p1        text
    *  <--  p2        text
    *----------------------------------------------------------------------*
    FORM save_data .
    * define local data
      DATA:
        ls_outtab    TYPE ty_s_outtab,
        ls_pbo       TYPE ty_s_outtab,
        lt_insert    TYPE ty_t_outtab,
        lt_delete    TYPE ty_t_outtab.
    
    " Compare PBO with PAI -> find deleted records
      LOOP AT gt_outtab_pbo INTO ls_pbo.
    
        READ TABLE gt_outtab INTO ls_outtab
             WITH KEY table_line = ls_pbo.
        IF ( syst-subrc NE 0 ).
          APPEND ls_outtab TO lt_delete.
        ENDIF.
    
      ENDLOOP.
    
    
    " Compare PAI with PBO data -> find new records
      LOOP AT gt_outtab INTO ls_outtab.
    
        READ TABLE gt_outtab_pbo INTO ls_pbo
             WITH KEY table_line = ls_outtab.
        IF ( syst-subrc NE 0 ).
          APPEND ls_outtab TO lt_insert.
        ENDIF.
      ENDLOOP.
    
      CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
        EXPORTING
          i_structure_name = 'KNB1'
          i_grid_title     = 'New Records'
        TABLES
          t_outtab         = lt_insert
        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.
    
      CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
        EXPORTING
          i_structure_name = 'KNB1'
          i_grid_title     = 'Deleted Records'
        TABLES
          t_outtab         = lt_delete
        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.
    
    
      gt_outtab_pbo = gt_outtab.  " do not forget !!!
    
    ENDFORM.                    " SAVE_DATA

    Regards

    Uwe

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.