Skip to Content
0
Mar 02, 2009 at 08:45 PM

Passing the dynamic internal tables to the calling program

129 Views

Hello,

From my user exit USEREXIT_MOVE_FIELD_TO_VBAP in program MV45AFZZ I am calling a routine to build dynamically an internal table. I get A DUMP in the perform statement. Please see below.

----------------------------------------------------------------------------------------------
*FORM USEREXIT_MOVE_FIELD_TO_VBAP.*

*Global declarations
RANGES: KSCHL      FOR A605-KSCHL,
               KUNNR     FOR A605-KUNNR,
               MATNR     FOR A605-MATNR.

field-symbols: <dyn_table> type standard table,
                     <dyn_wa>,
                     <dyn_field>.

*Internal tables and work areas
data: dy_table type ref to data,
        dy_line  type ref to data,
        xfc type lvc_s_fcat,
        ifc type lvc_t_fcat.

  KSCHL-sign   = 'I'.
  KSCHL-option = 'EQ'.
  KSCHL-low    = 'ZB00'.
  APPEND KSCHL.

  if not vbap-matnr is initial.
    MATNR-sign   = 'I'.
    MATNR-option = 'EQ'.
    MATNR-low    = vbap-matnr.
    APPEND MATNR.
  endif.

  if not vbak-kunnr is initial.
    KUNNR-sign   = 'I'.
    KUNNR-option = 'EQ'.
    KUNNR-low    = vbak-kunnr.
    APPEND KUNNR.
  endif.

perform get_data(ZSD_CARRIER_SELECTION)
                           TABLES KAPPL
                                         KSCHL
                                         KUNNR
                                         MATNR
                          CHANGING <dyn_table>.

*ENDFORM.*

----------------------------------------------------------------------------------------------
*Then in program ZSD_CARRIER_SELECTION*

*Global declarations
RANGES: KSCHL      FOR A605-KSCHL,
               KUNNR     FOR A605-KUNNR,
               MATNR     FOR A605-MATNR.

field-symbols: <dyn_table> type standard table,
                     <dyn_wa>,
                     <dyn_field>.

*Internal tables and work areas
data: dy_table type ref to data,
        dy_line  type ref to data,
        xfc type lvc_s_fcat,
        ifc type lvc_t_fcat.


*FORM get_data  CHANGING dyn_table.*

  select single * into w_t685
  from t685 where KSCHL eq P_KSCHL
              and KOZGF ne space.

  select * into table i_T682I
  from T682I where KVEWE = w_t685-KVEWE
               and KAPPL = w_t685-KAPPL
               and KOZGF = w_t685-KOZGF.

  loop at  i_T682I into W_T682I.
    CONCATENATE 'A' W_T682I-KOTABNR INTO w_dd02l-TABNAME.

    itables-TABNAME = w_dd02l-TABNAME.
    collect itables.
  endloop.

  loop at itables.
    perform get_structure tables ifc
                          using  itables-TABNAME.
  endloop.

  loop at ifc into xfc where key = 'X'.
    clear i_fields.
    i_fields-FIELDNAME = xfc-fieldname.
    i_fields-sign      = 'I'.
    i_fields-option    = 'EQ'.

    if xfc-fieldname = 'KSCHL'.
      i_fields-low = 'ZB00'.
    endif.
    append i_fields.
  endloop.

  call method cl_alv_table_create=>create_dynamic_table
    EXPORTING
      it_fieldcatalog = ifc
    IMPORTING
      ep_table        = dy_table.

  assign dy_table->* to <dyn_table>.

  create data dy_line like line of <dyn_table>.
  assign dy_line->* to <dyn_wa>.

*ENDFORM.*

*FORM get_structure tables ifc type LVC_T_FCAT*
                   *using TABNAME.*

  data : idetails type abap_compdescr_tab,
         xdetails type abap_compdescr.

  data : ref_table_des type ref to cl_abap_structdescr.

* Get the structure of the table.
  ref_table_des ?=
      cl_abap_typedescr=>describe_by_name( TABNAME ).
  idetails[] = ref_table_des->components[].

  select * into table i_dd03l
  from dd03l where tabname = tabname.

  sort i_dd03l by fieldname.

  loop at idetails into xdetails.
    clear xfc.
    xfc-fieldname = xdetails-name .
    xfc-datatype  = xdetails-type_kind.
    xfc-inttype   = xdetails-type_kind.
    xfc-intlen    = xdetails-length.
    xfc-decimals  = xdetails-decimals.

    read table i_dd03l with key fieldname = xfc-fieldname
                                KEYFLAG   = 'X'.
    if sy-subrc = 0.
      xfc-key   = 'X'.
    endif.

    collect xfc into ifc.
  endloop.

*ENFORM.                    "get_structure*

----------------------------------------------------------------------------------------------

Thanks in advance.

Please use code tags in the future when pasting code.

Edited by: Rob Burbank on Mar 2, 2009 4:29 PM