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: 

Dynamic typing error

Former Member
0 Kudos

Hi *,

I'm trying to build a generic application to check values into any table.

But I'm facing the following problem:

FIELD-SYMBOLS: <fstable> TYPE table,

<fscond> TYPE table,

<fs_line> TYPE ANY,

<dyn_wa> TYPE any,

<dyn_field> TYPE any.

data: tipo(20) TYPE c VALUE '/FRE/SUBST_ASSMT'.

data: dy_line type ref to data.

ASSIGN it_data TO <fstable> CASTING TYPE (tipo).

create data dy_line TYPE (tipo)."like line of <fstable>.

assign dy_line->* to <dyn_wa> CASTING TYPE (tipo).

LOOP at <fstable> INTO <dyn_wa>.

---> if <dyn_wa>-subst_c = '0'.

--> endif.

do.

assign component sy-index of structure <dyn_wa> to <dyn_field>.

if sy-subrc <> 0.

exit.

endif.

enddo.

ENDLOOP.

It's clear that since the variable is untyped I can not perform this check. SE80 says that there is no structure, therefore no component.

Let's say, I've got a table, MARA and I want to check if a field is 0, and then later on I have to check if MARC has field 'X' to 0... I want to reuse the code.

Any ideas how can achieve that?

Any help will be apprecitad,

Isidoro!

2 REPLIES 2

former_member194669
Active Contributor
0 Kudos

Hi,

Check this code,


  call function 'LVC_FIELDCATALOG_MERGE'
    exporting
      i_structure_name = p_table
    changing
      ct_fieldcat      = i_fcat
    exceptions
      others           = 1.
  if sy-subrc = 0.
    loop at i_fcat assigning <fcat>.
      <fcat>-tabname = p_table.
    endloop.
    call function 'LVC_FIELDCAT_COMPLETE'
      changing
        ct_fieldcat = i_fcat
      exceptions
        others      = 1.
  else.
    write: 'Error building field catalog'.
    stop.
  endif.

  call method cl_alv_table_create=>create_dynamic_table
    exporting
      it_fieldcatalog = i_fcat
    importing
      ep_table        = i_content.
  if sy-subrc = 0.
    assign i_content->* to <ptab>.
  else.
    write: 'Error creating internal table'.
    stop.
  endif.

  create data dref1 type (p_table).
  assign dref1->* to <xtab>.

  field-symbols : <l_f3> type any,
                  <l_f4> type any.

  
  loop at <ptab> assigning <xtab>.
     read table i_fcat assigning <fcat> with key
                                  tabname = p_table
                                  fieldname = 'SUBST_C'.
    if sy-subrc eq 0.
     assign component <fcat>-col_id of structure <xtab> to <l_f3>.
     if <l_f3> is initial.
                               " Do your code here         
     endif.
    endif.
  endloop.


aRs

Former Member
0 Kudos

Hi,

Your solution is not bad, actually I like it, but I solved the problem in a different way. Have a look at:

FIELD-SYMBOLS: <fstable> TYPE table,

<fscond> TYPE table,

<fs_line> TYPE ANY,

<dyn_wa> TYPE any,

<dyn_field> TYPE any.

*

data: lt_wheres TYPE rsds_twhere,

lrt_cond TYPE STANDARD TABLE OF rsds_range,

lrs_cond LIKE LINE OF lrt_cond.

data: dy_line type ref to data.

DATA: lr_rtti_struc TYPE REF TO cl_abap_structdescr.

DATA: lt_comp TYPE cl_abap_structdescr=>component_table.

DATA: ls_comp LIKE LINE OF lt_comp.

data: campos type DDFIELDS,

ls_campos LIKE LINE OF campos.

DATA: index TYPE i VALUE '1'.

*Assign the dynamic structures.

ASSIGN it_data TO <fstable>.

create data dy_line like line of <fstable>.

assign dy_line->* to <dyn_wa>.

*get the description of the elements from DDIC

lr_rtti_struc ?= cl_abap_structdescr=>DESCRIBE_BY_DATA_REF( dy_line ).

lr_rtti_struc->GET_DDIC_FIELD_LIST( EXPORTING P_INCLUDING_SUBSTRUCTRES = 'X'

RECEIVING P_FIELD_LIST = campos ).

LOOP at campos INTO ls_campos.

if ls_campos-fieldname = 'SUBST_CTRL'.

index = sy-tabix.

endif.

ENDLOOP.

LOOP at <fstable> INTO <dyn_wa>.

do.

assign component sy-index of structure <dyn_wa> to <dyn_field>.

if sy-subrc <> 0.

exit.

endif.

if sy-index = index.

if <dyn_field> = '3'.

WRITE / 'OK!