2006 Sep 21 8:39 AM
Hi,
I need to read the table which i will get that dynamically in the program.
some times the table name like * and some times it's like
a 4 digit name.
I have to read the 4 digit table name only.
How can i read taht table only......
Thanks,
srikanth.
2006 Sep 21 8:43 AM
How come your table name can change in a program?
Are you creating customised table or using standard SAP table?
Try to use if/else statement for different selecting of tables, but you must rectify the tables name at first hand.
2006 Sep 21 8:44 AM
2006 Sep 21 8:49 AM
For dynamic table name....
REPORT demo_select_dynamic_database .
DATA wa TYPE scarr.
DATA name(10) TYPE c VALUE 'SCARR'.
SELECT *
INTO wa
FROM (name) CLIENT SPECIFIED
WHERE mandt = '000'.
WRITE: / wa-carrid, wa-carrname.
ENDSELECT.
2006 Sep 21 8:49 AM
2006 Sep 21 8:54 AM
Thanks rajesh..
i will explain you clearly..
iam getting table names in itab-checktable.
It has multiple entries like * ,vbuk etc....
i want to read the table name which is in itab-checktable.
Regards,
srikanth
2006 Sep 21 8:56 AM
Hi ong rukawaw,
My requirement is:
iam getting table names in itab-checktable.
It has multiple entries like *,vbuk,tvak etc....
i want to read the table name which is in itab-checktable.
Regards,
srik
2006 Sep 21 9:02 AM
Hi Jonna,
I am afraid that when you read the table name from itab-checktable, you may need to store in a variable. The problem is we cant use select command to select record from variable.
Message was edited by: ong rukawaw
2006 Sep 21 9:04 AM
My propose solution for you will be as below:
Loop at itab-checktable.
if itab-checktable-tablename = 'vbuk'.
Select * from vbuk...
elseif itab-checktable-tablename = 'tvak'.
Select * from tvak...
endif.
endloop.
Hope it helps you.
2006 Sep 21 9:18 AM
Hi u just combine my previous solution wid this 1.
using earlier solution u r creating a dynaminc databse tab name.
now to create dynamic internal table name.........plz hv a look at http://www.sap-img.com/ab030.htm
I dont hv muc htime ...otherwise i culd hv combined both da solution for u.
so just do.
data : name (10) type c.
name = wa_itab-tabname.
select * into table (dynamic internal table)
from (name).
2006 Sep 21 9:38 AM
Hi Ong rukawaw,
Thanks for your view. It's really very helpful for me.
Regards,
srikanth
2006 Sep 21 9:39 AM
Hi rajesh,
Thanks for ur code.
It helped me alot.
Thanks,
srikanth.J
2006 Sep 21 10:51 AM
Hi srikanth,
Since you want to read table dynamically, thus i would suggeest to use most dynamic method:
DATA ds_table TYPE REF TO data.
DATA descr_struct_ref TYPE REF TO cl_abap_structdescr.
DATA it_fieldcatalog TYPE lvc_t_fcat.
DATA wa_fcat TYPE lvc_s_fcat.
DATA ep_table TYPE REF TO data.
FIELD-SYMBOLS: <my_table> TYPE ANY TABLE,
<LINE_TABLE> TYPE ANY.
FIELD-SYMBOLS: <fs> TYPE ANY.
FIELD-SYMBOLS: <components> TYPE abap_compdescr.
PARAMETERS: p_table TYPE tabname.
PARAMETERS: p_maxrow type i.
* Create reference for structure of the table
* because statement CREATE DATA ref TYPE TABLE OF
* is not allowed in 4.6
CREATE DATA ds_table TYPE (p_table).
ASSIGN ds_table->* TO <fs>.
* cast down
descr_struct_ref ?= cl_abap_typedescr=>describe_by_data( <fs> ).
* build fieldcatalog
LOOP AT descr_struct_ref->components ASSIGNING <components>.
wa_fcat-fieldname = <components>-name.
wa_fcat-ref_table = p_table.
wa_fcat-ref_field = <components>-name.
APPEND wa_fcat TO it_fieldcatalog.
ENDLOOP.
* build a reference for internal table
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = it_fieldcatalog
IMPORTING
ep_table = ep_table
EXCEPTIONS
generate_subpool_dir_full = 1
OTHERS = 2.
* assign refrence to field-symbol
ASSIGN ep_table->* TO <my_table>.
* select dynamically in your table
SELECT * FROM (p_table) INTO TABLE <my_table> UP TO p_maxrow ROWS.
LOOP AT <MY_TABLE> ASSIGNING <LINE_TABLE>.
WRITE:/ <LINE_TABLE>.
ENDLOOP.