Application Development and Automation 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: 
Read only

Fetch data from 50 tables with single query

Former Member
0 Likes
343

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

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

1 REPLY 1
Read only

Former Member
0 Likes
298

replace <field> with (<field>) ok?

but, its better if you construct your where clause.. i dont know the above will work or not.

like

concatenate <FIELD> ' = ' <fval> into s1 separated by space.

and pass where (s1).

check the FM RFC_READ_TABLE. you will get a proper picture

Edited by: Soumyaprakash Mishra on Dec 13, 2011 11:02 PM