on 11-30-2012 11:04 AM
Hi experts,
I have to create a method using assistance class.
Where this method contains a select query such as select * from (tab_name) into corresponding values of ITAB.
Now i need to use this method at various stages.
Here i will pass exporting parameter as database table name and import internal table from the method.
So how to pass an database table as a parameter to the method and how to declare for database table in assistance method?
Hi ,
Just Create a Method in Assistance class with having Parameters as Tablename and itab name with importing and exporting Parameters .
In the Method Just write the Below Code.
field-symbols : <fstab> type any table,
<fswa> type any,
<fsfield> type any.
data : ref_rowtype type ref to cl_abap_structdescr,
ref_tabletype type ref to cl_abap_tabledescr.
data : ref_tab type ref to DATA,
ref_wa type ref to DATA.
start-of-selection.
* Dynamic instantiation
ref_rowtype ?= cl_abap_typedescr=>describe_by_name( p_name = p_tab ).
tRY.
call method cl_abap_tabledescr=>create
exporting
p_line_type = ref_rowtype
receiving
p_result = ref_tabletype.
CATCH CX_SY_TABLE_CREATION .
message 'Error in creating internal table' type 'I'.
ENDTRY.
* Create the object
create data ref_wa type handle ref_rowtype.
create data ref_tab type handle ref_tabletype.
* Value assignment (MAPPING DBTABLE STRUCTURE TO FIELDSYMBOLS)
assign ref_wa->* to <fswa>.
assign ref_tab->* to <fstab>.
* Data retrieval
select * from (p_tab) into table <fstab> UP TO 5 ROWS.
and finally loop the <fstab> and move the data to final internal table.
Thanks,
Raghunadh.K
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
you can create a string type variable to pass table name but if you want to query table what you have in paramter then you have to use RTTI and RTTC classes
below link for how to create internal table dynamically.
http://wiki.sdn.sap.com/wiki/display/ABAP/Dynamic+Internal+table
http://scn.sap.com/thread/416161
reward point if find helpful
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
87 | |
10 | |
10 | |
10 | |
7 | |
6 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.