简体   繁体   English

如何在 OO ABAP 中使用具有 3 个不同单选按钮的动态 SALV

[英]How can I use dynamic SALV with 3 different raditobutton in OO ABAP

I have to do Batch program for 3 different info types (0014,0015,2010).我必须为 3 种不同的信息类型(0014,0015,2010)做批处理程序。

First step, I have a parameter that is reading the .xls file in a selection screen and 3 different radio buttons for each info type.第一步,我有一个在选择屏幕中读取.xls文件的参数,以及每种信息类型的 3 个不同的单选按钮。 I want to display a different ALV as when I execute the program with selected radio button.当我使用选定的单选按钮执行程序时,我想显示不同的 ALV。 For example, I want to see 0014 if I selected 0014's radio button.例如,如果我选择了 0014 的单选按钮,我想查看0014 The same situation for others.其他人的情况也一样。

I can do what I want with one way.我可以用一种方式做我想做的事。 That's way is using Perform which have parameters tables and using .那就是使用具有参数tables的 Perform 并using .

But I cannot do it with OO ABAP.但我不能用 OO ABAP 做到这一点。 It means using SALV and CLASS/Method style.这意味着使用 SALV 和 CLASS/Method 样式。 Anyone can guide me?任何人都可以指导我吗?

*------------DEFINITION-------- * - - - - - - 定义 - - - -

class lcl_report definition.

  public section.
    types: begin of ty_list_14,
             pernr(8)     type c,
             begda(10)    type c,
             endda(10)    type c,
             lgart(5)     type c,
             betrg(9)     type c,
             anzhl        type i,
             message(200) type c,
             durum(5)     type c,
           end of ty_list_14.
    data: gt_list_14 type standard table of ty_list_14,
          gs_list_14 like line of gt_list_14.

    methods:
      check_filename,
      file_operations,
      display_alv.

  private section.
    data: mo_alv  type ref to cl_salv_table.

    data: gt_rows type salv_t_row,
          gs_rows type i.

    data: it_raw type truxs_t_text_data.

    data: v_strln   type i,
          offset    type i,
          extension type string.

    data: i_0014       type table of p0014 initial size 1,
          w_0014       type p0014,
          l_bapireturn type bapireturn1.

    data: filename type string.

    methods:
      create_alv,
      selection_rows,
      alv_properties,
      upload_file,
      create_record_i0014.

    methods :
      on_user_command for event added_function of cl_salv_events
        importing e_salv_function.

endclass.

*------------IMPLEMENTATION-------- * - - - - - - 执行 - - - -

class lcl_report implementation.

  method display_alv.
    me->create_alv( ).
    me->selection_rows( ).
    me->alv_properties( ).
  endmethod.

  method file_operations.
    me->upload_file( ).
  endmethod.

  method create_alv.

    data: lo_events type ref to cl_salv_events_table.
    try.
        cl_salv_table=>factory(
          importing
            r_salv_table   = mo_alv
          changing
            t_table        = gt_list_14[]

        ).

      catch cx_salv_msg.
    endtry.

    lo_events = mo_alv->get_event( ).
    set handler go_report->on_user_command for lo_events.

 mo_alv->display( ).
  endmethod.
  method selection_rows .

    data: lo_selection type ref to cl_salv_selections.

    try.
        "Soldan seçim kutularını ekrana getirir.
        lo_selection = mo_alv->get_selections( ).
        lo_selection->set_selection_mode( if_salv_c_selection_mode=>row_column ).

      catch cx_salv_not_found.
    endtry.
  endmethod.
  method check_filename.
    v_strln = strlen( p_file ).

    if v_strln le 4.
      message text-003 type 'E'.
    else.
      offset = v_strln - 1.
      do v_strln times.
        if p_file+offset(1) eq '.'.
          extension = p_file+offset.
          shift extension left deleting leading '.'.
          exit.
        endif.
        subtract 1 from offset.
      enddo.
      if extension ne 'xls'  and
         extension ne 'XLS'  and
         extension ne 'xlsx' and
         extension ne 'XLSX' and
         extension ne 'txt'  and
         extension ne 'TXT'.
        message text-003 type 'E'.
      endif.
    endif.
  endmethod.
  
  method create_record_i0014.

    data: lv_begda type begda,  
          lv_endda type endda.  

    loop at gt_rows into gs_rows.
      read table gt_list_14 into gs_list_14 index gs_rows.

      call function 'CONVERSION_EXIT_ALPHA_INPUT'
        exporting
          input  = gs_list_14-pernr
        importing
          output = gs_list_14-pernr.

      call function 'CONVERSION_EXIT_QNTY1_INPUT'
        exporting
          input  = gs_list_14-betrg
        importing
          output = gs_list_14-betrg.


      clear: lv_begda, lv_endda.
      
      concatenate gs_list_14-begda+6(4) 
                  gs_list_14-begda+3(2) 
                  gs_list_14-begda(2)   
                  into lv_begda.
      concatenate gs_list_14-endda+6(4)
                  gs_list_14-endda+3(2)
                  gs_list_14-endda(2)
                  into lv_endda.
  
      move-corresponding gs_list_14 to w_0014.

      w_0014-infty = '0014'.
      w_0014-begda = lv_begda.
      w_0014-endda = lv_endda.
      w_0014-lgart = gs_list_14-lgart.
      w_0014-betrg = gs_list_14-betrg.
      w_0014-anzhl = gs_list_14-anzhl.
      append w_0014 to i_0014.

      call function 'BAPI_EMPLOYEE_ENQUEUE'
        exporting
          number = w_0014-pernr
        importing
          return = l_bapireturn.

      call function 'HR_INFOTYPE_OPERATION'
        exporting
          infty     = '0014'
          number    = w_0014-pernr
          record    = w_0014
          operation = 'INS'
        importing
          return    = l_bapireturn.
     
      gs_list_14-message = l_bapireturn-message.
     
      if l_bapireturn-type eq 'E'.
        gs_list_14-durum = '@5C@'.
      elseif l_bapireturn-type eq 'W'.
        gs_list_14-durum = '@5D@'.
      elseif l_bapireturn-type eq 'S' or
             l_bapireturn-type is initial.
        gs_list_14-durum = '@5B@'.
        gs_list_14-message = text-033.
      endif.
      
      call function 'BAPI_EMPLOYEE_DEQUEUE'
        exporting
          number = w_0014-pernr
        importing
          return = l_bapireturn.
      
      modify gt_list_14 from gs_list_14 index gs_rows.
      clear: gs_list_14, w_0014.
      refresh i_0014.
    endloop.

  endmethod.
  method on_user_command.
    data: lo_selection type ref to cl_salv_selections.
    
    lo_selection = mo_alv->get_selections( ).
    gt_rows = lo_selection->get_selected_rows( ).

    case e_salv_function.
      when '&AKTAR'.
        me->create_record_i0014( ).
    endcase.

    mo_alv->refresh( ).
  endmethod.
endclass.

You need create a field-symbol like Excel table structure and set this field-symbol in the SALV.您需要创建一个字段符号,如 Excel 表结构,并在 SALV 中设置此字段符号。

See this post to know how to create the field-symbol.请参阅这篇文章以了解如何创建字段符号。

Create a structure from a dynamically assigned <itab> 从动态分配的 <itab> 创建结构

Best regards.此致。

Sebastian塞巴斯蒂安

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

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