Skip to Content
0
Former Member
Dec 13, 2011 at 05:08 PM

Fetch data from 50 tables with single query

45 Views

Hi,

I am having a requirement where I should fetch the records count in a table, since there are close to 50 tables I have written below code, which is working fine with out WHERE clause, but going to short dump if I use a where clause.

IF NOT p_sel_opt IS INITIAL.
    LOOP AT p_sel_opt INTO wa_sel_opt .
      ASSIGN wa_sel_opt-low TO <fval>.
      ASSIGN  p_fieldname TO <field>.
      IF <field> IS ASSIGNED AND <fval> IS ASSIGNED.
        SELECT COUNT(*)  FROM (p_tabname) WHERE <FIELD>  = <fval>  .
        IF sy-subrc = 0.
          wa_fi_bukrs-bukrs = <fval>.
          wa_fi_bukrs-table =  p_tabname.
          wa_fi_bukrs-count = sy-dbcnt.
          APPEND wa_fi_bukrs TO it_fi_bukrs.
          CLEAR wa_fi_bukrs.
        ENDIF.
      ENDIF.
    ENDLOOP.
  ENDIF.

Reason it is giving is

<field>

is not availble in the data base tables . what can I do to the above query for that to work.

Thanks,

Varun