Passing internal tables as ref parameters to a class method

public section.
 
  types:
    begin of ty_s_example,
             example_key type char10,
             value       type string,
           end of ty_s_example .
  types:
    ty_t_example type standard table of ty_s_example with key example_key .
 
  methods MY_METHOD
    importing
      !IR_EXAMPLE_TAB type ref to TY_T_EXAMPLE .
 
 
  method my_method.
    data: lt_example_table type ty_t_example.
 
    loop at ir_example_tab->* assigning field-symbol(<ls_line>).
      <ls_line>-value = 'sample'.
    endloop.
  endmethod.
 
report zmru_r_test_ref.
 
data(go_example) = new zmru_test( ).
 
data(gt_example) = value zmru_test=>ty_t_example(
                      ( example_key = '10' value = 'XXXX' )
                      ( example_key = '20' value = 'YYYY' )
                   ).
 
go_example->my_method( ref #( gt_example ) ).
FS_EDIDD  Instance Attribute        Private        Type Ref To        DATA                                                                    
IDOCNUM   Instance Attribute        Private        Type        EDI_DOCNUM        
FS_ITEM   Instance Attribute        Private        Type Ref To        DATA                                                                    
SEGNAM    Instance Attribute        Private        Type        CHAR27        
STAT      Instance Attribute        Private        Type        BDIDOCSTAT
 
 types: begin of t_fieldnames,
    fieldname type char27,
  end of t_fieldnames,
  ty_fieldnames type standard table of t_fieldnames with empty key.
 
  types:
    t_edidd type standard table of edidd with default key .
 
method constructor.
 
  data lo_data type ref to data.
 
  assign it_edidd->* to field-symbol(<fs_edidd>).
 
  " binding import parameters to the class attributes
  get reference of <fs_edidd> into fs_edidd.
  idocnum = iv_docnum.
  segnam  = iv_segnam.
 
  " casting to passed type iv_segnam (segment name = segment type)
  data(lo_struct) = cast cl_abap_structdescr( cl_abap_structdescr=>describe_by_name( iv_segnam ) ).
  create data lo_data type handle lo_struct.
  assign lo_data->* to field-symbol(<fs_item>).
 
  get reference of <fs_item> into fs_item.
 
endmethod.
 
method some_method1.
field-symbols <fs_edidd> type table.
  field-symbols <fs_wa_edidd> type line of t_edidd.
 
  assign fs_edidd->* to <fs_edidd>.
  loop at <fs_edidd> assigning <fs_wa_edidd>.
   case <fs_wa_edidd>-segnam.
    when segnam.                                " z.B. 'E1BPMEPOITEM'
 
     assign fs_item->* to field-symbol(<fs_item>).
     move <fs_wa_edidd>-sdata to <fs_item>.
     assign component iv_fieldname of structure <fs_item>  " getting value of E1BPMEPOITEM-PO_UNIT_ISO (e.g.)
      to field-symbol(<fs_uom>).
     check <fs_uom> is assigned.                           " is segment E1BPMEPOITEM-PO_UNIT_ISO (e.g.) in IDoc exist?
 
     if <fs_uom> is not initial.                   " UoM is not empty so we checking it in T006 Table
       data(l_clause) = iv_spalte && ' = <fs_uom>'.
       select single * from t006 into lt_t006 where (l_clause).
       if sy-subrc <>
         fill_idoc_status( errno = '60' msgty = 'E' msgv1 = 'Das Feld ' && iv_fieldname && ' enthält'
                           msgv2 = 'ungültige SAP-Mengeneinheit.' msgv3 = 'Position:#' && <fs_wa_edidd>-segnum ).
         ch_stat = stat. " returning filled Class-Attribute (idoc status - error message)
         rv_is_correct = abap_false.
         return.
       endif.
     endif.
   endcase.
  endloop.
endmethod.
 
method some_method2.
  rv_is_empty = abap_false.
 
  field-symbols: <fs_edidd>        type table,
                 <fs_wa_edidd>     type line of t_edidd,
                 <fs_fieldnames>   type table,
                 <fs_wa_fieldname> type t_fieldnames.
 
  assign iv_fieldnames->* to <fs_fieldnames>.
 
  assign fs_edidd->* to <fs_edidd>.
  loop at <fs_edidd> assigning <fs_wa_edidd>.
    case <fs_wa_edidd>-segnam.
      when segnam.                                " z.B. 'E1BPMEPOITEM'
 
        assign fs_item->* to field-symbol(<fs_item>).
        move <fs_wa_edidd>-sdata to <fs_item>.
 
        data(l_lines) = lines( <fs_fieldnames> ).
        loop at <fs_fieldnames> assigning <fs_wa_fieldname>.
 
          assign component <fs_wa_fieldname>-fieldname of structure <fs_item>  " getting value of E1BPMEPOITEM-PO_UNIT_ISO (e.g.)
           to field-symbol(<fs_uom>).
          check <fs_uom> is assigned.                                  " is segment E1BPMEPOITEM-PO_UNIT_ISO (e.g.) in IDoc exist?
 
          if <fs_uom> is initial.                                      " current UoM is empty
            subtract 1 from l_lines.                                   " so we decrease ("bestrafen") the counter
          endif.
        endloop.
 
        if 0 = l_lines. " means all UoMs in passed segment are empty - error.
          fill_idoc_status( errno = '60' msgty = 'E' msgv1 = 'Die Position ' && <fs_wa_edidd>-segnum && ' enthält'
                            msgv2 = 'keine SAP-Mengeneinheiten.' msgv3 = 'Erster Feldname:' && <fs_wa_fieldname>-fieldname ).
          ch_stat = stat. " returning filled Class-Attribute (idoc status - error message)
          rv_is_empty = abap_true.
          return.
        endif.
 
    endcase.
  endloop.
 
endmethod.

Добавить комментарий



All fields are required. Your email address will not be published.