‎2005 Aug 02 4:45 PM
Hello everybody,
could any tell me how to create a dynamic db table from se38, i need the code.
Thanks in advance
srikanth.
‎2005 Aug 02 4:47 PM
‎2005 Aug 02 4:49 PM
Dynamic Internal Table Example.....
report zrich_0003
no standard page heading.
type-pools: slis.
field-symbols: <dyn_table> type standard table,
<dyn_wa>.
data: alv_fldcat type slis_t_fieldcat_alv,
it_fldcat type lvc_t_fcat.
selection-screen begin of block b1 with frame title text-001.
parameters: p_check type c.
selection-screen end of block b1.
start-of-selection.
perform build_dyn_itab.
perform build_report.
loop at <dyn_table> into <dyn_wa>.
write:/ <dyn_wa>.
endloop.
************************************************************************
* Build_dyn_itab
************************************************************************
form build_dyn_itab.
data: index(3) type c.
data: new_table type ref to data,
new_line type ref to data,
wa_it_fldcat type lvc_s_fcat.
* Create fields
clear index.
do 10 times.
index = sy-index.
clear wa_it_fldcat.
concatenate 'Field' index into
wa_it_fldcat-fieldname .
condense wa_it_fldcat-fieldname no-gaps.
wa_it_fldcat-datatype = 'CHAR'.
wa_it_fldcat-intlen = 5.
append wa_it_fldcat to it_fldcat .
enddo.
* Create dynamic internal table and assign to FS
call method cl_alv_table_create=>create_dynamic_table
exporting
it_fieldcatalog = it_fldcat
importing
ep_table = new_table.
assign new_table->* to <dyn_table>.
* Create dynamic work area and assign to FS
create data new_line like line of <dyn_table>.
assign new_line->* to <dyn_wa>.
endform.
*********************************************************************
* Form build_report
*********************************************************************
form build_report.
data: fieldname(20) type c.
data: fieldvalue(5) type c.
data: index(3) type c.
field-symbols: <fs1>.
do 10 times.
index = sy-index.
* Set up fieldname
concatenate 'FIELD' index into
fieldname .
condense fieldname no-gaps.
* Set up fieldvalue
concatenate 'FLD' index into
fieldvalue.
condense fieldvalue no-gaps.
assign component fieldname of structure <dyn_wa> to <fs1>.
<fs1> = fieldvalue.
enddo.
* Append to the dynamic internal table
append <dyn_wa> to <dyn_table>.
endform.
Regards,
Rich Heilman
‎2005 Aug 02 5:11 PM
Hi Rich,
Yesterday i had an interview in abap and the interviewer asked me how to create a database table in se38 during runtime.so that is the question?.
cheers
srikanth.
‎2005 Aug 02 5:18 PM
Wow, I would say that the interviewer doesn't know what he is talking about. I don't see any reason why you would have to create a database table at runtime. Now there are many uses for creating a dynamic internal table at runtime, which I have shown above.
Does anyone else know of a specific reason why someone would want to create a database table at runtime?
Regards,
Rich Heilman
‎2005 Aug 02 5:18 PM
The only way you can do that is by using open sql statements of the underlying database. Alternatively, you may be able to use some function modules like DB_CREATE_TABLE.
Srinivas
‎2005 Aug 02 5:19 PM
Hi,
I suppose that this FM can create a database table. I have never used ii.
FM 'DD_CREATE_TABLE'
Svetlin
‎2005 Aug 02 5:23 PM
There are some instances where SAP creates the DD tables on the fly. This is particularly true with condition tables, infostructures etc. as the fields of these tables are defined in configuration by a consultant.
Unless this company which interviewed him is involved in some product like that, I don't see why a normal ABAPer would require to create a DB table on the fly.
Srinivas
‎2005 Oct 27 10:06 PM
I believe that I've seen (but cannot find an example) of cases where tables are dropped and then re-created. I think this is done to avoid long run times and the possibilities of SQL errors if all data in a large user table has to be deleted before being re-populated.
This was done using native SQL, but I guess FMs could also be used.
Rob
‎2005 Nov 16 11:37 AM
‎2005 Nov 16 11:37 AM
‎2005 Oct 27 5:32 PM
Thanks in advance, is there the possibility to read from
an external database like SQL/server or ORACLE ?
‎2005 Oct 27 6:11 PM
‎2005 Oct 27 6:21 PM
You could create TEMPORARY TABLES using Native SQL statements. But, there is really no point to "clog up" DB server space or processing time when the ABAP language supports such a wonderful data object like... the internal table (which resides outside of the DB server).
I would guess that was the answer that the interviewer was looking to get.