简体   繁体   English

CL_GUI_ALV_GRID 可编辑字段不刷新

[英]CL_GUI_ALV_GRID editable field not refresh

I have an ALV grid with an editable field, if I check the data entered and display errors, the ALV updates, if I try to change the input data, other times the ALV does not update anymore.我有一个带有可编辑字段的 ALV 网格,如果我检查输入的数据并显示错误,则 ALV 会更新,如果我尝试更改输入数据,其他时候 ALV 不再更新。

The code in the PAI is: PAI 中的代码是:

    ls_layout-cwidth_opt = abap_true.  
    CREATE OBJECT go_alv     
     EXPORTING
      i_parent          = cl_gui_custom_container=>screen0
    EXCEPTIONS
      error_cntl_create = 1
      error_cntl_init   = 2
      error_cntl_link   = 3
      error_dp_create   = 4
      OTHERS            = 5. 

        IF sy-subrc EQ 0.
    
    *   Adapting field catalog
        CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
          EXPORTING
            i_structure_name       = 'ZAMOUNT'
          CHANGING
            ct_fieldcat            = lt_fieldcat.
        IF sy-subrc EQ 0. 
  *     Field catalog specifics       
        LOOP AT lt_fieldcat ASSIGNING <ls_fieldcat>. 
              IF  <ls_fieldcat>-fieldname = 'DMBTR'.
                <ls_fieldcat>-edit = abap_true.
              ENDIF.
    
          ENDLOOP.
        ENDIF.

    *   Show data usig ALV class
        go_alv->set_table_for_first_display(
                  EXPORTING
                    is_layout       = ls_layout
                  CHANGING
                    it_outtab       = gt_out
                    it_fieldcatalog = lt_fieldcat ).
    
          go_alv->set_ready_for_input( EXPORTING
            i_ready_for_input = 1 ).
    
          CALL METHOD go_alv->register_edit_event
            EXPORTING
              i_event_id = cl_gui_alv_grid=>mc_evt_enter.
    
          CALL METHOD go_alv->register_edit_event
            EXPORTING
              i_event_id = cl_gui_alv_grid=>mc_evt_modified.
      ENDIF.

The code in the PBO is: PBO 中的代码是:

        IF go_alv IS NOT INITIAL.

        CALL METHOD go_alv->check_changed_data( ).

        PERFORM check_amounts   TABLES gt_out
                              CHANGING gv_sum_amounts
                                       gv_tot_amount.

       
        CALL METHOD go_alv->refresh_table_display
          EXPORTING
            is_stable      = VALUE #( row = abap_true
                                      col = abap_true )
            i_soft_refresh = 'X'.           
            cl_gui_cfw=>flush( ).

    ENDIF.

In the perform check_amounts I populate a field of the ALV with the errors, if the user modifies the input field and the error is removed in the internal table but it is not shown in the ALV.在执行 check_amounts 中,如果用户修改了输入字段并且错误在内部表中被删除但它没有显示在 ALV 中,我会用错误填充 ALV 的字段。

I also tried to implement the data_change_finished method by calling the refresh inside but I have not solved the anomaly.我也尝试通过调用内部的刷新来实现data_change_finished方法,但我没有解决异常。

Can you help me?你能帮助我吗? Thanks谢谢

I'm not quite sure if I understand your problem but here are some potential issues I see:我不太确定我是否理解您的问题,但这里有一些我看到的潜在问题:

  1. You have your validity checks split up.你有你的有效性检查分开。 On the one hand there is the data_changed event.一方面是 data_changed 事件。 On the other hand you have the check_amounts perform.另一方面,您有 check_amounts 执行。
  • If the data_changed event finds an input error, it'll show you the red outline on your grid.如果 data_changed 事件发现输入错误,它将在网格上显示红色轮廓。 In your internal table ("gt_out") this field will stay the same as before (it'll not update the table with the invalid input.).在您的内部表 ("gt_out") 中,此字段将保持与以前相同(它不会使用无效输入更新表。)。 This might be why you think there should be a message in your grid but there isn't.这可能就是为什么您认为网格中应该有一条消息但没有的原因。
  1. Did you define your own local version for the data_changed event?您是否为 data_changed 事件定义了自己的本地版本? Than the handlers are missing.比处理程序丢失。 When you tried doing the refresh in the data_changed_finished event you definitly need the handler for that.当您尝试在 data_changed_finished 事件中进行刷新时,您肯定需要处理程序。
  • Also you said that you only put the refresh in the method for data_changed_finished.您还说您只将刷新放在 data_changed_finished 的方法中。 You need to put the check_amount perform there too then.你还需要把 check_amount 放在那里。 Otherwise you called the refresh to early.否则,您将刷新称为提早。
  • In the method for data_changed_finished you have the automatically updated table ("gt_out") from the data_changed method.在 data_changed_finished 方法中,您有来自 data_changed 方法的自动更新表(“gt_out”)。 You should be able to update it here and send it to your grid with a refresh.您应该能够在此处更新它并将其发送到您的网格并刷新。
  1. I don't like that you call the check_changed_data method in your PBO.我不喜欢你在 PBO 中调用 check_changed_data 方法。 Because of the register_edit_event calls the data_changed event already triggers when you hit enter or jump to the next field.由于 register_edit_event 调用 data_changed 事件已在您按 Enter 或跳转到下一个字段时触发。 You usually only call this method when you received a seperat user command, that can be fired before the event can be triggered to be sure that you have correct data.您通常仅在收到单独的用户命令时调用此方法,可以在触发事件之前触发该命令以确保您拥有正确的数据。
  • Not 100% sure about this but for your register_edit_event calls, the event id cl_gui_alv_grid=>mc_evt_modified should include the event id cl_gui_alv_grid=>mc_evt_enter already.不是 100% 确定这一点,但对于您的 register_edit_event 调用,事件 id cl_gui_alv_grid=>mc_evt_modified 应该已经包含事件 id cl_gui_alv_grid=>mc_evt_enter。

I'd try to define a local class to handle the data_changed and data_changed_finished events and put the check_amount and refresh in the method for the data_changed_finished event.我会尝试定义一个本地 class 来处理 data_changed 和 data_changed_finished 事件,并将 check_amount 和 refresh 放入 data_changed_finished 事件的方法中。 Maybe some of this helps you?也许其中一些对您有帮助? If you have any questions about any of this, let me know and I can go into more detail.如果您对此有任何疑问,请告诉我,我可以更详细地了解 go。

regards问候

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM