09-27-2009 3:39 PM
Hi,
I need to add a field dynamically during runtime. How can i do that? For example consider i have a internal table
DATA: BEGIN OF itab,
id type i,
name (30) type c,
END OF itab.
Now i want to add a field ADDRESS during runtime. After adding the field the internal will be like
DAtA: BEGIN of itab,
id type i,
name(30) type c,
address type c,
END OF itab.
How can i achieve the above requirement?
Thanx in advance.
09-27-2009 6:17 PM
Hi
Use the concept of dynamic internal tables
[Rich Heilman's blog on Dynamic Internal Tables|http://www.sdn.sap.com/irj/scn/weblogs;jsessionid=%28J2EE3417800%29ID0902689750DB20088686594705427604End?blog=/pub/wlg/2071]
Pushpraj
09-27-2009 8:43 PM
search 'field symbol for dynamic tables' in SCN.
and please close the duplicate thread:
09-28-2009 9:35 AM
Hi,
I checked that link. they are passing table structure through a parameter. The parameter will store table name like 'MARA'. it is not altering the table field.
09-28-2009 9:41 AM
Hello SAPPIEN,
AFAIK if you define an internal table statically you cannot alter its structure at runtime. (Members can correct me if i am wrong in this statement) .
So your requirement to add a field to a statically defined int. table structure is not possible.
Alternatively you can try to use a dynamically defined internal table using the method CREATE_DYNAMIC_TABLE of class CL_ALV_TABLE_CREATE.
Further details on SDN.
BR,
Suhas
09-28-2009 12:29 PM
Hi
I checked few links, they creating internal table dynamically but the structure of internal table is static. My need is i want to change the structure of internal table dynamically.
09-28-2009 12:41 PM
I assume this isn't possible due to internal memory management.
You could create a new table with the desired structure, move your data there, and delete the old table.
Thomas
09-28-2009 12:45 PM
Hi All,
You should not assume that i am only asking to insert a field in static internal table created. If it is possible please give me some information to insert a field in dyanamic internal table.
09-28-2009 1:38 PM
Hello,
Check the program BCALV_TABLE_CREATE. I think this should answer your question.
BR,
Suhas
09-28-2009 10:10 AM
hii,
For creating fied dynamically you have to use the class cl_wd_inputfield. you can use the method to create input field of this class. cl_wd_input_field=>new_input_field" method
See class "cl_wd_input_field" for method parameter details.
regards,
Shweta
09-28-2009 10:20 AM
Hello Shweta,
Where did you get this info? How does this help?
Any sample coding for this?
Cheers,
Suhas
09-28-2009 8:31 PM
Hi,
Pls try this code.
DATA: STR_TYPE TYPE REF TO CL_ABAP_STRUCTDESCR,
STR_COMP TYPE CL_ABAP_STRUCTDESCR=>COMPONENT_TABLE,
COMP_TAB TYPE CL_ABAP_STRUCTDESCR=>COMPONENT_TABLE,
NEW_STR TYPE REF TO CL_ABAP_STRUCTDESCR,
NEW_TAB TYPE REF TO CL_ABAP_TABLEDESCR,
COMP LIKE LINE OF COMP_TAB,
DREF TYPE REF TO DATA.
FIELD-SYMBOLS: <ITAB> TYPE ANY TABLE.
TYPES: BEGIN OF STR,
ID TYPE I,
NAME(30) TYPE C,
END OF STR.
STR_TYPE ?= CL_ABAP_TYPEDESCR=>DESCRIBE_BY_NAME( 'STR' ).
STR_COMP = STR_TYPE->GET_COMPONENTS( ).
APPEND LINES OF STR_COMP TO COMP_TAB.
COMP-NAME = 'ADDRESS'.
COMP-TYPE = CL_ABAP_ELEMDESCR=>GET_C( 40 ).
APPEND COMP TO COMP_TAB.
NEW_STR = CL_ABAP_STRUCTDESCR=>CREATE( COMP_TAB ).
NEW_TAB = CL_ABAP_TABLEDESCR=>CREATE(
P_LINE_TYPE = NEW_STR
P_TABLE_KIND = CL_ABAP_TABLEDESCR=>TABLEKIND_STD
P_UNIQUE = ABAP_FALSE ).
CREATE DATA DREF TYPE HANDLE NEW_TAB.
ASSIGN DREF->* TO <ITAB>. "INTERNAL TABLE.
Prasanna.
09-28-2009 11:18 PM
Hi Sappien,
it is not possible to change the structure of an internal table at runtime.
Prasanna shows how to use RTTS Run Time Type Service to create an internal table at runtime.
This is the only possible way.
Pleae do not use method cl_alv_table_create=>create_dynamic_table because it has serious restrictions and unwanted side effects.
Kind regards
Clemens