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: 

Fields enable/disable based on dropdown value in OOALV Report

Former Member
0 Kudos
1,941

Hi Gurus,

I have developed a OOABAP report which contain a dropdown fields with 3 values A,B and C. So when A get selected and press enter then few fields will get enabled and when B is selected then some other combination of fields should get enabled.

My issue is when i am selecting A or B or C for first time it is working fine and the required fields are getting enabled, but it is not working when i am selecting second time any other values(A or B or C) after that. I have tried using refresh_table_display method also but is not working.

Please help in fixing this issue. Please find the attached below.

REPORT zsd_maintain_mfn.
TABLES: zsd_mfn, abap, icon.
DATA : lt_mfn TYPE STANDARD TABLE OF zsd_mfn,
       ls_mfn TYPE zsd_mfn.

TYPES: BEGIN OF ty_alv_out,

          priority TYPE zsd_mfn-priority,  

          kunag TYPE zsd_mfn-kunag,       

          kunwe TYPE zsd_mfn-kunwe,       

          ecust TYPE zsd_mfn-ecust,

          name1 TYPE zsd_mfn-name1,

          mpn TYPE zsd_mfn-mpn,

          mfn TYPE zsd_mfn-mfn,

          drop_down_handle TYPE int4,

          celltab          TYPE lvc_t_styl,

          color_line(4),

         END OF ty_alv_out.



*DATA gt_alv_out       TYPE TABLE OF ty_alv_out.



DATA:BEGIN OF gt_alv_out OCCURS 0,

         priority TYPE zsd_mfn-priority,  

          kunag TYPE zsd_mfn-kunag,        

          kunwe TYPE zsd_mfn-kunwe,        

          ecust TYPE zsd_mfn-ecust,

          name1 TYPE zsd_mfn-name1,

          mpn TYPE zsd_mfn-mpn,

          mfn TYPE zsd_mfn-mfn,

          drop_down_handle TYPE int4,

          celltab          TYPE lvc_t_styl,

          color_line(4),

END OF gt_alv_out.



DATA:gs_alv_out LIKE LINE OF gt_alv_out.





DATA g_grid           TYPE REF TO cl_gui_alv_grid. "alv grid

DATA gt_fieldcat      TYPE lvc_t_fcat. "fieldcatalog

DATA gs_layout        TYPE lvc_s_layo. "layout

DATA ok_code          LIKE sy-ucomm. "ok code

DATA g_splitter       TYPE REF TO cl_gui_splitter_container. "splitter

DATA g_contnr_top     TYPE REF TO cl_gui_container. "container - top

DATA g_contnr_bot     TYPE REF TO cl_gui_container. "container - bottom

DATA g_html           TYPE REF TO cl_dd_document. "html for alv commentary

DATA gv_header        TYPE sdydo_text_element. "alv header

DATA gt_exclude       TYPE ui_functions. "alv toolbar buttons

DATA gv_mode          TYPE string.

DATA gv_error         TYPE boolean.

DATA gt_mfn_del     TYPE TABLE OF zsd_mfn.

DATA gs_mfn         TYPE zsd_mfn.

DATA:lx_fieldcat LIKE LINE OF gt_fieldcat. 

DATA lv_priority   TYPE zpriority.  

DATA gt_changed_rows  TYPE TABLE OF int4.

DATA gs_stable        TYPE lvc_s_stbl.



*----------------------------------------------------------------------*

*       CLASS lcl_events DEFINITION

*----------------------------------------------------------------------*

*

*----------------------------------------------------------------------*

CLASS lcl_events DEFINITION.

  PUBLIC SECTION.

* Method to implement user commands

    METHODS handle_user_command

    FOR EVENT user_command OF cl_gui_alv_grid

    IMPORTING e_ucomm.

* Add new functional buttons to the ALV toolbar

    METHODS handle_toolbar FOR EVENT toolbar OF cl_gui_alv_grid

    IMPORTING e_object e_interactive.

    METHODS handle_data_changed

    FOR EVENT data_changed OF cl_gui_alv_grid

    IMPORTING er_data_changed.

ENDCLASS.                    "lcl_events DEFINITION

*---------------------------------------------------------------------*

*       MAIN                                                          *

*---------------------------------------------------------------------*

CALL SCREEN 100.

*----------------------------------------------------------------------*

*       CLASS lcl_events IMPLEMENTATION

*----------------------------------------------------------------------*

*

*----------------------------------------------------------------------*

CLASS lcl_events IMPLEMENTATION.

  METHOD handle_user_command.

    PERFORM handle_user_command USING e_ucomm.

  ENDMETHOD.                    "handle_user_command

  METHOD handle_toolbar.

 

    AUTHORITY-CHECK OBJECT 'ZMFN'

    ID 'ACTVT' FIELD '02'.

    IF sy-subrc EQ 0.

      PERFORM handle_toolbar USING e_object e_interactive .

    ENDIF.

  ENDMETHOD .                    "handle_toolbar

  METHOD handle_data_changed.

    IF er_data_changed IS NOT INITIAL.

      PERFORM handle_data_changed USING er_data_changed.

    ENDIF.

  ENDMETHOD.                    "handle_data_changed



ENDCLASS.                    "lcl_events IMPLEMENTATION

*&---------------------------------------------------------------------*

*&      Form  handle_user_command

*&---------------------------------------------------------------------*

*       text

*----------------------------------------------------------------------*

*      -->I_UCOMM    text

*----------------------------------------------------------------------*

FORM handle_user_command USING i_ucomm TYPE syucomm.

  DATA lt_index_rows    TYPE lvc_t_row.

  DATA lt_row_no        TYPE lvc_t_roid.

  DATA ls_row_no        TYPE lvc_s_roid.

  DATA lv_row_count     TYPE i.

  DATA ls_alv_out       TYPE ty_alv_out.

  DATA lt_alv_copy      TYPE TABLE OF ty_alv_out.

  DATA lv_valid(1).

  DATA lv_answer(1).

  DATA ls_row_info   TYPE lvc_s_row.

  DATA ls_col_info   TYPE lvc_s_col.

  DATA ls_row_id     TYPE lvc_s_roid.

  DATA lv_lines      TYPE i.



  g_grid->check_changed_data( IMPORTING e_valid = lv_valid ).

  g_grid->get_scroll_info_via_id( IMPORTING es_row_info = ls_row_info

                                            es_col_info = ls_col_info

                                            es_row_no   =  ls_row_id ).

  CASE i_ucomm .

    WHEN 'EDIT'.

      g_grid->refresh_table_display( ).

      IF g_grid->is_ready_for_input( ) EQ 0.

        CALL METHOD g_grid->set_ready_for_input

          EXPORTING

            i_ready_for_input = 1.

      ELSE.

        IF g_grid->is_ready_for_input( ) EQ 1.

          CALL METHOD g_grid->set_ready_for_input

            EXPORTING

              i_ready_for_input = 0.

        ENDIF.

      ENDIF.

    WHEN 'ADD'.

      g_grid->refresh_table_display( ).

      ls_alv_out-drop_down_handle = 1.

      DESCRIBE TABLE gt_alv_out LINES lv_lines.

      ls_row_id-row_id = lv_lines.

      APPEND ls_alv_out TO gt_alv_out.

      CLEAR ls_alv_out.

    WHEN 'DEL'.

      g_grid->get_selected_rows( IMPORTING et_index_rows = lt_index_rows

                                           et_row_no     = lt_row_no ).

      IF lt_row_no[] IS NOT INITIAL.

        CALL FUNCTION 'POPUP_TO_CONFIRM'

          EXPORTING

            text_question  = text-020

          IMPORTING

            answer         = lv_answer

          EXCEPTIONS

            text_not_found = 1

            OTHERS         = 2.

        IF lv_answer <> '1'.

          LEAVE LIST-PROCESSING.

        ELSEIF lv_answer = '1'.

          LOOP AT lt_row_no INTO ls_row_no.

            READ TABLE gt_alv_out INTO ls_alv_out INDEX ls_row_no-row_id.

            IF sy-subrc EQ 0.

              MOVE-CORRESPONDING ls_alv_out TO gs_mfn.

              APPEND gs_mfn TO gt_mfn_del.

              CLEAR ls_alv_out.

            ENDIF.

          ENDLOOP.

* now delete the records

          LOOP AT gt_mfn_del INTO gs_mfn.

            DELETE gt_alv_out WHERE ecust = gs_mfn-ecust

            AND name1 = gs_mfn-name1

            AND mpn = gs_mfn-mpn

            AND mfn = gs_mfn-mfn.

          ENDLOOP.

          g_grid->refresh_table_display( ).

        ENDIF.

      ENDIF.

    WHEN 'COPY'.

      g_grid->get_selected_rows( IMPORTING et_index_rows = lt_index_rows

                                           et_row_no     = lt_row_no ).

      IF lt_row_no[] IS NOT INITIAL.

        LOOP AT lt_row_no INTO ls_row_no.

          READ TABLE gt_alv_out INTO ls_alv_out INDEX ls_row_no-row_id.

          IF sy-subrc EQ 0.

            APPEND ls_alv_out TO lt_alv_copy.

            CLEAR ls_alv_out.

          ENDIF.

        ENDLOOP.

        DESCRIBE TABLE gt_alv_out LINES lv_lines.

        ls_row_id-row_id = lv_lines.

        LOOP AT lt_alv_copy INTO ls_alv_out.

          CLEAR ls_alv_out-celltab.

          APPEND ls_alv_out TO gt_alv_out.

          CLEAR ls_alv_out.

        ENDLOOP.

        CLEAR lt_alv_copy[].

        g_grid->refresh_table_display( ).

      ENDIF.

    WHEN 'REPL'.

      g_grid->get_selected_rows( IMPORTING et_index_rows = lt_index_rows

                                           et_row_no     = lt_row_no ).

      IF lt_row_no[] IS NOT INITIAL.

        LOOP AT lt_row_no INTO ls_row_no.

          READ TABLE gt_alv_out INTO ls_alv_out INDEX ls_row_no-row_id.

          IF sy-subrc EQ 0.

            DELETE gt_alv_out INDEX sy-tabix.

            APPEND ls_alv_out TO lt_alv_copy.

            MOVE-CORRESPONDING ls_alv_out TO gs_mfn.

            APPEND gs_mfn TO gt_mfn_del.

            CLEAR ls_alv_out.

          ENDIF.

        ENDLOOP.

        DESCRIBE TABLE gt_alv_out LINES lv_lines.

        ls_row_id-row_id = lv_lines.

        LOOP AT lt_alv_copy INTO ls_alv_out.

          CLEAR ls_alv_out-celltab.

          APPEND ls_alv_out TO gt_alv_out.

          CLEAR ls_alv_out.

        ENDLOOP.

        CLEAR lt_alv_copy[].

        g_grid->refresh_table_display( ).

      ENDIF.

    WHEN 'SAVE'.

      PERFORM update_data.

  ENDCASE.



  g_grid->refresh_table_display( ).



  g_grid->set_scroll_info_via_id( EXPORTING

             is_col_info = ls_col_info

            is_row_no   =  ls_row_id ).



ENDFORM.                    "handle_user_command

*&---------------------------------------------------------------------*

*&      Form  handle_toolbar

*&---------------------------------------------------------------------*

*       text

*----------------------------------------------------------------------*

*      -->PR_DATA_CHANGED  text

*----------------------------------------------------------------------*

FORM handle_toolbar USING i_object TYPE REF TO cl_alv_event_toolbar_set

                              i_interactive.



  DATA: ls_toolbar TYPE stb_button.

  DEFINE build_toolbar.

    move &1 to ls_toolbar-function.

    move &2 to ls_toolbar-icon.

    move &3 to ls_toolbar-text.

    move 0 to ls_toolbar-butn_type.

    append ls_toolbar to i_object->mt_toolbar.

    clear ls_toolbar.

  END-OF-DEFINITION.

  build_toolbar: 'EDIT' icon_change ''.

  IF g_grid->is_ready_for_input( ) EQ 1.

    build_toolbar: 'ADD'  icon_insert_row '',

                   'DEL'  icon_delete_row '',

                   'COPY' icon_copy_object 'Copy',

                   'REPL' icon_replace 'Edit Line',

                   'SAVE' icon_system_save 'Save'.

  ENDIF.

ENDFORM.                    "handle_toolbar



*&---------------------------------------------------------------------*

*&      Form  HANDLE_DATA_CHANGED

*&---------------------------------------------------------------------*

*       text

*----------------------------------------------------------------------*

*      -->PR_DATA_CHANGED  text

*----------------------------------------------------------------------*

FORM handle_data_changed  USING pr_data_changed TYPE REF TO cl_alv_changed_data_protocol.

  DATA lv_ecust      TYPE kunnr.

  DATA lv_name1   TYPE name1.

  DATA ls_good_cells TYPE lvc_s_modi.

  DATA lt_celltab    TYPE lvc_t_styl.

  DATA ls_row_info   TYPE lvc_s_row.

  DATA ls_col_info   TYPE lvc_s_col.

  DATA ls_row_id     TYPE lvc_s_roid.



  FIELD-SYMBOLS <fs_alv_out>    TYPE ty_alv_out.

  FIELD-SYMBOLS <fs_any>        TYPE any.



  DEFINE get_cell_value.

    call method pr_data_changed->get_cell_value

      exporting

        i_row_id    = &1

        i_fieldname = &2

      importing

        e_value     = &3.

  END-OF-DEFINITION.

  DEFINE modify_cell.

    call method pr_data_changed->modify_cell

      exporting

        i_row_id    = &1

        i_fieldname = &2

        i_value     = &3.

    read table gt_alv_out assigning <fs_alv_out>

    index &1.

    if sy-subrc eq 0.

      assign component &2 of structure <fs_alv_out> to <fs_any>.

      <fs_any> = &3.

    endif.

  END-OF-DEFINITION.



  CLEAR gv_error.



  LOOP AT pr_data_changed->mt_good_cells INTO ls_good_cells.

    APPEND ls_good_cells-row_id TO gt_changed_rows.

    CASE ls_good_cells-fieldname.



 

      WHEN 'PRIORITY'.

        CLEAR lt_celltab[].

**        CLEAR:lx_fieldcat.

**        SORT gt_fieldcat[] BY fieldname.

        get_cell_value ls_good_cells-row_id ls_good_cells-fieldname lv_priority.

        IF lv_priority EQ 'A'.

 

          PERFORM fill_celltab USING 'RW' lv_priority

                                 CHANGING lt_celltab.



        ELSEIF lv_priority = 'B'.

          PERFORM fill_celltab USING 'RW' lv_priority

                               CHANGING lt_celltab.



        ELSEIF lv_priority = 'C'.

          PERFORM fill_celltab USING 'RW' lv_priority

                                CHANGING lt_celltab.



        ENDIF.

        modify_cell ls_good_cells-row_id 'PRIORITY' lv_priority.

        modify_cell ls_good_cells-row_id 'CELLTAB' lt_celltab.



        g_grid->refresh_table_display( EXPORTING i_soft_refresh = 'X' ).

        ls_col_info-fieldname = 'PRIORITY'.

        ls_row_id-row_id = ls_good_cells-row_id.

* set scroll bar to current row being edited

        g_grid->set_scroll_info_via_id( EXPORTING

*        IS_ROW_INFO =

            is_col_info = ls_col_info

            is_row_no   =  ls_row_id  ).



        CLEAR:lv_priority,ls_good_cells,ls_col_info,ls_row_id.

 

      WHEN 'ECUST'.

        CLEAR: lv_ecust, lv_name1.

        get_cell_value ls_good_cells-row_id ls_good_cells-fieldname lv_ecust.

        CHECK lv_ecust IS NOT INITIAL.

        CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'

          EXPORTING

            input  = lv_ecust

          IMPORTING

            output = lv_ecust.



        PERFORM get_customer_name USING lv_ecust lv_name1.

        IF sy-subrc EQ 0.

          modify_cell ls_good_cells-row_id 'NAME1' lv_name1.

        ELSE.

          CALL METHOD pr_data_changed->add_protocol_entry

            EXPORTING

              i_msgid     = '0K'

              i_msgno     = '000'

              i_msgty     = 'E'

              i_msgv1     = text-001

              i_msgv2     = lv_ecust

              i_fieldname = ls_good_cells-fieldname

              i_row_id    = ls_good_cells-row_id.

        ENDIF.

    ENDCASE.

  ENDLOOP.

  PERFORM display_alv.

ENDFORM.                    " HANDLE_DATA_CHANGED



*&---------------------------------------------------------------------*

*&      Form  GET_CUSTOMER_NAME

*&---------------------------------------------------------------------*

*       text

*----------------------------------------------------------------------*

*      -->KUNNR      text

*      -->NAME1      text

*----------------------------------------------------------------------*

FORM get_customer_name USING kunnr TYPE kunnr name1 TYPE name1.

  SELECT SINGLE name1 FROM kna1 INTO name1

                      WHERE kunnr = kunnr.

ENDFORM.                    " GET_CUSTOMER_NAME



*&---------------------------------------------------------------------*

*&      Form  display_alv

*&---------------------------------------------------------------------*

*       text

*----------------------------------------------------------------------*

FORM display_alv.

  DATA container        TYPE REF TO cl_gui_custom_container.

  DATA lr_event_handler TYPE REF TO lcl_events.



  CREATE OBJECT lr_event_handler.

  CREATE OBJECT container

    EXPORTING

      container_name = 'CONT'.

  CREATE OBJECT g_splitter

    EXPORTING

      parent  = container

      rows    = 1

      columns = 1.



  g_contnr_top = g_splitter->get_container( row = 1 column = 1 ).

  CREATE OBJECT g_grid

    EXPORTING

      i_parent = g_contnr_top.



  CREATE OBJECT g_html

    EXPORTING

      style = 'ALV_GRID'.



* Display the ALV grid

* Build the fieldcatalog

*  IF gt_changed_rows[] IS INITIAL.

  PERFORM build_fcat.

*  ENDIF.

  PERFORM set_drdn_table.   

  PERFORM exclude_tb_functions.

  SET HANDLER lr_event_handler->handle_toolbar FOR g_grid .



  gs_layout-stylefname = 'CELLTAB'.

  gs_layout-sel_mode = 'A'.

  gs_layout-info_fname = 'COLOR_LINE'.



  CALL METHOD g_grid->set_table_for_first_display

    EXPORTING

      is_layout                     = gs_layout

      it_toolbar_excluding          = gt_exclude

    CHANGING

      it_outtab                     = gt_alv_out[]

      it_fieldcatalog               = gt_fieldcat

    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.



 

  CALL METHOD g_grid->set_frontend_fieldcatalog

    EXPORTING

      it_fieldcatalog = gt_fieldcat.



CALL METHOD g_grid->refresh_table_display( ).

 





  CALL METHOD g_grid->set_ready_for_input

    EXPORTING

      i_ready_for_input = 1.



  CALL METHOD g_grid->register_edit_event

    EXPORTING

      i_event_id = cl_gui_alv_grid=>mc_evt_enter. "register enter event



  CALL METHOD g_grid->register_edit_event

    EXPORTING

      i_event_id = cl_gui_alv_grid=>mc_evt_modified. "register enter event



  SET HANDLER lr_event_handler->handle_user_command FOR g_grid.

  SET HANDLER lr_event_handler->handle_data_changed FOR g_grid.





ENDFORM.                    "display_alv



*&---------------------------------------------------------------------*

*&      Form  BUILD_FCAT

*&---------------------------------------------------------------------*

*       text

*----------------------------------------------------------------------*



FORM build_fcat .



  DEFINE build_alv_fcat.

    lx_fieldcat-fieldname  = &1.

    lx_fieldcat-tabname    = 'GT_ALV_OUT'.

    if &2 is not initial.

      lx_fieldcat-ref_table  = &2.

    else.

      lx_fieldcat-seltext  = &3.

      lx_fieldcat-coltext  = &3.

    endif.

    if &4 is not initial.

      lx_fieldcat-edit = 'X'.

    else.

      lx_fieldcat-edit = space.

    endif.

     if &1 eq 'PRIORITY'.

      lx_fieldcat-drdn_field = 'DROP_DOWN_HANDLE'.

      lx_fieldcat-edit = 'X'.

      lx_fieldcat-outputlen = 5.

    else.

      lx_fieldcat-outputlen = 20.

    endif.

     append lx_fieldcat to gt_fieldcat.

    clear lx_fieldcat.

  END-OF-DEFINITION.
  CLEAR gt_fieldcat[].

build_alv_fcat: 'PRIORITY' 'ZSD_MFN' 'Priority' 'X',                                           'KUNAG'   'ZSD_MFN' 'Sold-to party' '',   

                   'KUNWE'   'ZSD_MFN' 'Ship-to party' '',        

                   'ECUST'   'ZSD_MFN' 'End customer number'       '',

                   'NAME1'   'ZSD_MFN' 'Customer Name'             '',

                   'MPN'     'ZSD_MFN' 'Marketing Part Number'     'X' ,

                   'MFN'     'ZSD_MFN' 'Manufacturing Part Number' 'X' .



ENDFORM.                    " BUILD_FCAT

*&---------------------------------------------------------------------*

*&      Form  exclude_tb_functions

*&---------------------------------------------------------------------*

*       text

*----------------------------------------------------------------------*

FORM exclude_tb_functions .

  DATA ls_exclude TYPE ui_func.

  DEFINE build_exclude_itab.

    ls_exclude = &1.

    append ls_exclude to gt_exclude.

  END-OF-DEFINITION.

* exclude all the toolbar buttons except the download to excel

  build_exclude_itab: cl_gui_alv_grid=>mc_fc_loc_undo,

                      cl_gui_alv_grid=>mc_fc_loc_copy_row,

                      cl_gui_alv_grid=>mc_fc_loc_delete_row,

                      cl_gui_alv_grid=>mc_fc_loc_append_row,

                      cl_gui_alv_grid=>mc_fc_loc_move_row,

                      cl_gui_alv_grid=>mc_fc_loc_copy,

                      cl_gui_alv_grid=>mc_fc_loc_cut,

                      cl_gui_alv_grid=>mc_fc_loc_paste,

                      cl_gui_alv_grid=>mc_fc_loc_paste_new_row,

                      cl_gui_alv_grid=>mc_fc_check,

                      cl_gui_alv_grid=>mc_fc_refresh,

                      cl_gui_alv_grid=>mc_fc_minimum,

                      cl_gui_alv_grid=>mc_fc_maximum,

                      cl_gui_alv_grid=>mc_fc_views,

                      cl_gui_alv_grid=>mc_fc_sum,

                      cl_gui_alv_grid=>mc_fc_graph,

                      cl_gui_alv_grid=>mc_fc_average,

                      cl_gui_alv_grid=>mc_fc_find,

                      cl_gui_alv_grid=>mc_fc_info,

                      cl_gui_alv_grid=>mc_fc_loc_insert_row.

ENDFORM.                    "exclude_tb_functions



*&---------------------------------------------------------------------*

*&      Module  PBO_100  OUTPUT

*&---------------------------------------------------------------------*

*       text

*----------------------------------------------------------------------*

MODULE pbo_100 OUTPUT.

* Display the titlebar and application toolbar buttons

  SET TITLEBAR 'ZSD_MFN'.

  SET PF-STATUS 'MAIN'.

  PERFORM init_data.

* Display the ALV grid

  PERFORM display_alv.

ENDMODULE.                 " PBO_100  OUTPUT



*&---------------------------------------------------------------------*

*&      Form  init_data

*&---------------------------------------------------------------------*

*       text

*----------------------------------------------------------------------*

FORM init_data.

*  TYPES: BEGIN OF ty_cust_name,

*         kunnr  TYPE kunnr,

*         name1  TYPE name1,

*         END OF ty_cust_name.



  DATA lt_mfn         TYPE TABLE OF zsd_mfn.

  DATA ls_mfn         TYPE zsd_mfn.

*  DATA lt_cust_name   TYPE TABLE OF ty_cust_name.

*  DATA ls_cust_name   TYPE ty_cust_name.

  DATA ls_alv_out     TYPE ty_alv_out.

  DATA lt_celltab     TYPE lvc_t_styl.



  DATA:lt_f4 TYPE lvc_t_f4,  

       wa_f4 LIKE LINE OF lt_f4.



*  DEFINE get_customer_name.

*    read table lt_cust_name into ls_cust_name

*    with key kunnr = &1.

*    &2 = ls_cust_name-name1.

*    clear ls_cust_name.

*  END-OF-DEFINITION.

*

  CLEAR gt_alv_out[].

  SELECT * FROM zsd_mfn INTO TABLE lt_mfn.

*  IF sy-subrc EQ 0.

*    SELECT kunnr name1 FROM kna1 INTO TABLE lt_cust_name

*      FOR ALL ENTRIES IN lt_mfn

*      WHERE kunnr = lt_mfn-ecust.



  LOOP AT lt_mfn INTO ls_mfn.

    MOVE-CORRESPONDING ls_mfn TO ls_alv_out.

*      get_customer_name ls_mfn-ecust ls_alv_out-name1.

    ls_alv_out-drop_down_handle = 1.

    APPEND ls_alv_out TO gt_alv_out.

    CLEAR: ls_alv_out.

  ENDLOOP.

*  ENDIF.

 

  CREATE OBJECT g_grid

    EXPORTING

      i_parent = g_contnr_top.



* Set editable cells to ready for input initially

  CALL METHOD g_grid->set_ready_for_input

    EXPORTING

      i_ready_for_input = 1.



  CLEAR wa_f4.

  wa_f4-fieldname = 'PRIORITY'.

  wa_f4-register = 'X'.

  wa_f4-getbefore = 'X'.

  wa_f4-chngeafter = 'X'.

  APPEND wa_f4 TO lt_f4.



  CALL METHOD g_grid->register_f4_for_fields

    EXPORTING

      it_f4 = lt_f4.

*End OF Change

ENDFORM.                    "init_data

*&---------------------------------------------------------------------*

*&      Module  PAI_100  INPUT

*&---------------------------------------------------------------------*

*       text

*----------------------------------------------------------------------*

MODULE pai_100 INPUT.

  DATA lv_answer(1).

  DATA lv_exit TYPE abap_bool.

  DATA:w_valid TYPE char1.

*  IF gt_changed_rows[] IS NOT INITIAL.

*    CALL FUNCTION 'POPUP_TO_CONFIRM'

*      EXPORTING

*        text_question  = text-021

*      IMPORTING

*        answer         = lv_answer

*      EXCEPTIONS

*        text_not_found = 1

*        OTHERS         = 2.

*    IF lv_answer <> '1'.

*      lv_exit = abap_false.

*    ELSE.

*      lv_exit = abap_true.

*    ENDIF.

*  ELSE.

*    lv_exit = abap_true.

*  ENDIF.

*  CHECK lv_exit = abap_true.



* CALL METHOD g_grid->check_changed_data

*IMPORTING

*e_valid = w_valid.





  CASE ok_code.

    WHEN 'BACK'.

      LEAVE TO SCREEN 0.

    WHEN 'EXIT'.

      LEAVE TO SCREEN 0.

  ENDCASE.

ENDMODULE.                 " PAI_100  INPUT

*&---------------------------------------------------------------------*

*&      Form  update_data

*&---------------------------------------------------------------------*

*       text

*----------------------------------------------------------------------*

FORM update_data.



  DATA ls_alv_out     LIKE LINE OF gt_alv_out.

  DATA lv_row_num     TYPE int4.

  DATA lt_ecmpn       TYPE TABLE OF zsd_ecmpn.

  DATA ls_ecmpn       TYPE zsd_ecmpn.

  DATA lv_valid       TYPE c.

  DATA lt_index_rows  TYPE lvc_t_row.

  DATA ls_index_rows  LIKE LINE OF lt_index_rows.



  g_grid->check_changed_data( IMPORTING e_valid = lv_valid ).



  IF lv_valid IS NOT INITIAL.

    SORT gt_changed_rows ASCENDING.

    DELETE ADJACENT DUPLICATES FROM gt_changed_rows.

    IF gt_changed_rows[] IS NOT INITIAL OR gt_mfn_del[] IS NOT INITIAL.

      LOOP AT gt_changed_rows INTO lv_row_num.

        READ TABLE gt_alv_out INTO ls_alv_out

        INDEX lv_row_num.

        MOVE-CORRESPONDING ls_alv_out TO ls_mfn.

        APPEND ls_mfn TO lt_mfn.

        CLEAR ls_mfn.

      ENDLOOP.

      IF gv_error EQ abap_false.

        LOOP AT gt_mfn_del INTO ls_mfn.

          DELETE zsd_mfn FROM ls_mfn.

        ENDLOOP.

        MODIFY zsd_mfn FROM TABLE lt_mfn.

        IF sy-subrc EQ 0.

          CLEAR: gt_mfn_del[], gt_changed_rows[].

          MESSAGE 'Changes have been saved'(004) TYPE 'S'.

          PERFORM init_data.

        ENDIF.

      ENDIF.

    ENDIF.

    CLEAR ls_mfn.

  ELSE.

    MESSAGE 'No changes made'(003) TYPE 'I'.



  ENDIF.

ENDFORM.                    "update_data

*&---------------------------------------------------------------------*

*&      Form  SET_DRDN_TABLE

*&---------------------------------------------------------------------*

*       text

*----------------------------------------------------------------------*



FORM set_drdn_table .



  DATA: lt_dropdown TYPE lvc_t_drop,

         ls_dropdown TYPE lvc_s_drop.



  ls_dropdown-handle = '1'.

  ls_dropdown-value = 'A'.

  APPEND ls_dropdown TO lt_dropdown.



  ls_dropdown-handle = '1'.

  ls_dropdown-value = 'B'.

  APPEND ls_dropdown TO lt_dropdown.



  ls_dropdown-handle = '1'.

  ls_dropdown-value = 'C'.

  APPEND ls_dropdown TO lt_dropdown.



  CALL METHOD g_grid->set_drop_down_table

    EXPORTING

      it_drop_down = lt_dropdown.



ENDFORM.                    " SET_DRDN_TABLE

*&---------------------------------------------------------------------*

*&      Form  FILL_CELLTAB

*&---------------------------------------------------------------------*

*       text

*----------------------------------------------------------------------*



FORM fill_celltab  USING value(p_mode)

                         value(p_priority)

                   CHANGING pt_celltab TYPE lvc_t_styl.



  DATA: ls_celltab TYPE lvc_s_styl,

        l_mode TYPE raw4.



  l_mode = cl_gui_alv_grid=>mc_style_enabled.



  IF p_priority EQ 'A'.

    CLEAR ls_celltab.

    ls_celltab-fieldname = 'PRIORITY'.

    ls_celltab-style = l_mode.

    INSERT ls_celltab INTO TABLE pt_celltab.

    ls_celltab-fieldname = 'KUNAG'.

    ls_celltab-style = cl_gui_alv_grid=>mc_style_disabled.

    INSERT ls_celltab INTO TABLE pt_celltab.

    ls_celltab-fieldname = 'KUNWE'.

    ls_celltab-style = l_mode.

    INSERT ls_celltab INTO TABLE pt_celltab.

    ls_celltab-fieldname = 'ECUST'.

    ls_celltab-style = l_mode.

    INSERT ls_celltab INTO TABLE pt_celltab.

    ls_celltab-fieldname = 'NAME1'.

    ls_celltab-style = cl_gui_alv_grid=>mc_style_disabled.

    INSERT ls_celltab INTO TABLE pt_celltab.

    ls_celltab-fieldname = 'MPN'.

    ls_celltab-style = l_mode.

    INSERT ls_celltab INTO TABLE pt_celltab.

    ls_celltab-fieldname = 'MFN'.

    ls_celltab-style = l_mode.

    INSERT ls_celltab INTO TABLE pt_celltab.



  ELSEIF  p_priority EQ 'B' .

    CLEAR ls_celltab.

    ls_celltab-fieldname = 'PRIORITY'.

    ls_celltab-style = l_mode.

    INSERT ls_celltab INTO TABLE pt_celltab.

    ls_celltab-fieldname = 'KUNAG'.

    ls_celltab-style = l_mode.

    INSERT ls_celltab INTO TABLE pt_celltab.

    ls_celltab-fieldname = 'KUNWE'.

    ls_celltab-style = cl_gui_alv_grid=>mc_style_disabled.

    INSERT ls_celltab INTO TABLE pt_celltab.

    ls_celltab-fieldname = 'ECUST'.

    ls_celltab-style = l_mode.

    INSERT ls_celltab INTO TABLE pt_celltab.

    ls_celltab-fieldname = 'NAME1'.

    ls_celltab-style = cl_gui_alv_grid=>mc_style_disabled.

    INSERT ls_celltab INTO TABLE pt_celltab.

    ls_celltab-fieldname = 'MPN'.

    ls_celltab-style = l_mode.

    INSERT ls_celltab INTO TABLE pt_celltab.

    ls_celltab-fieldname = 'MFN'.

    ls_celltab-style = l_mode.

    INSERT ls_celltab INTO TABLE pt_celltab.

  ELSE.

    CLEAR ls_celltab.

    ls_celltab-fieldname = 'PRIORITY'.

    ls_celltab-style = l_mode.

    INSERT ls_celltab INTO TABLE pt_celltab.

    ls_celltab-fieldname = 'KUNAG'.

    ls_celltab-style = cl_gui_alv_grid=>mc_style_disabled.

    INSERT ls_celltab INTO TABLE pt_celltab.

    ls_celltab-fieldname = 'KUNWE'.

    ls_celltab-style = cl_gui_alv_grid=>mc_style_disabled.

    INSERT ls_celltab INTO TABLE pt_celltab.

    ls_celltab-fieldname = 'ECUST'.

    ls_celltab-style = l_mode.

    INSERT ls_celltab INTO TABLE pt_celltab.

    ls_celltab-fieldname = 'NAME1'.

    ls_celltab-style = cl_gui_alv_grid=>mc_style_disabled.

    INSERT ls_celltab INTO TABLE pt_celltab.

    ls_celltab-fieldname = 'MPN'.

    ls_celltab-style = l_mode.

    INSERT ls_celltab INTO TABLE pt_celltab.

    ls_celltab-fieldname = 'MFN'.

    ls_celltab-style = l_mode.

    INSERT ls_celltab INTO TABLE pt_celltab.
  ENDIF.
ENDFORM.                    " FILL_CELLTAB
<br>

Thanks and Regards,

Ajay

5 REPLIES 5

former_member156446
Active Contributor
0 Kudos
288

Looks like your lt_celltab is same for all rows in gt_alv_out[], it should be different for each row. Since in one row you can fill A and B and other row you could fille B and C only.

0 Kudos
288

Hi Jai,

IT_CELLTAB is different actually for each row. When 'A' is selected it is enabling 'KUNWE' and 'ECUST' and when 'B' is selected it is enabling 'KUNAG' and 'ECUST' and when C is selected only 'ECUST' is getting enabled. Other's fields like 'PRIORITY' 'MFN' and 'MPN' are enabled for all rows.

Please provide your inputs how to fix this issue.

Regards,
Ajay

0 Kudos
288

its hard to say, since your code has most Ztable cannot really make a copy and work on it. You need to figure out .. after refresh_table output table actually would change. so make sure celltab has all the values you like to.

0 Kudos
288

Hi jay,

Thanks for your time and response.

I checked what you said like internal table gt_alv_out has exactly same fields characteristics what i needed after refresh_table statement but still it's not getting reflected in output. Don't know what is the issue. Any other guess...

Please find the custom table structure below.

Inline image 1

Former Member
0 Kudos
288

HI gurus,

Any help for the above issue will be really helpful and appreciated.

It's little urgent.

Regards,
Ajay