07-03-2007 10:52 AM
Dear All,
I was able to generate internal table and even able to read the data from a data base table into dynamic internal table.
But I would like to manipulate the data in the internal table, für example I would like to update few fields and display it in the List.
Now how di Modify dynamic internal table..
I have attached the code below which I am using right now.
REPORT Z_DYN_TABLE
field-symbols: type standard table.
data: dy_table type ref to data,
dy_line type ref to data,
xfc type lvc_s_fcat,
ifc type lvc_t_fcat.
Parameters : P_BEGDA like P0001-BEGDA default '20071001',
P_INFTY like P0001-INFTY default 'P0001'.
START-OF-SELECTION.
to get the srurcute
perform get_structure using l_f_table.
perform create_dynamic_itab .
assign dy_table->* to BUT now I have to modify few fields from the dynamic internal table, how do I do it.
END-OF-SELECTION.
form get_structure using p_table.
data : idetails type abap_compdescr_tab,
xdetails type abap_compdescr.
data : ref_table_des type ref to cl_abap_structdescr.
clear : ifc[], dy_table.
Get the structure of the table.
ref_table_des ?=
cl_abap_typedescr=>describe_by_name( p_table ).
idetails[] = ref_table_des->components[].
loop at idetails into xdetails.
clear xfc.
xfc-fieldname = xdetails-name .
xfc-datatype = xdetails-type_kind.
xfc-inttype = xdetails-type_kind.
xfc-intlen = xdetails-length.
xfc-decimals = xdetails-decimals.
append xfc to ifc.
endloop.
endform.
form create_dynamic_itab.
Create dynamic internal table and assign to FS
call method cl_alv_table_create=>create_dynamic_table
exporting
it_fieldcatalog = ifc
importing
ep_table = dy_table.
endform.
*&----
*
*& Form get_data
*&----
*
form get_data tables p_table
using p_pernr
p_infty.
clear : p_table, p_table[].
CALL FUNCTION 'HR_READ_INFOTYPE'
EXPORTING
PERNR = P_PERNR
INFTY = p_infty
BEGDA = p_datum
ENDDA = p_datum
TABLES
INFTY_TAB = p_table
EXCEPTIONS
INFTY_NOT_FOUND = 1
OTHERS = 2.
Endform.
07-03-2007 11:00 AM
Hi
U need to use the field-symbols, a code like this:
FIELD-SYMBOLS: <WA> TYPE ANY,
<FIELD> TYPE ANY.
LOOP AT <DYN_TABLE> ASSIGNING <WA>.
LOOP AT IFC INTO XFC.
ASSIGN COMPONENT XFC-FIELDNAME OF STRUCTURE <WA> TO <FIELD>.
CASE XFC-FIELDNAME.
WHEN '......'. <FIELD> = .....
WHEN '......'. <FIELD> = .....
..............................
ENDCASE.
ENDLOOP.
ENDLOOP.
Max
07-03-2007 10:59 AM
Hello Sharanabasappa
The procedure for manipulating dynamic internal table is quite straigthforward.
FIELD-SYMBOLS:
<ls_struc> TYPE any,
<ld_fld> TYPE any.
LOOP AT <dyn_table> ASSIGNING <ls_struc>.
" Now there are different way to access the structure fields:
" (1) Using component index
DO.
ASSIGN COMPONENT syst-index OF STRUCTURE <ls_struc> TO <ld_fld>.
IF ( syst-subrc ne 0 ).
EXIT.
ENDIF.
ENDDO.
" (2) Using component names
LOOP AT lt_fcat INTO ls_fcat. " fieldcatalog for creating dynamic itab
ASSIGN COMPONENT ls_fcat-fieldname OF STRUCTURE <ls_struc> TO <ld_fld>.
IF ( syst-subrc ne 0 ).
EXIT.
ENDIF.
...
ENDLOOP.
" NOTE: There is no MODIFY required becaue we are working with field symbols.
ENDLOOP.
Regards
Uwe
07-03-2007 11:00 AM
Hi
U need to use the field-symbols, a code like this:
FIELD-SYMBOLS: <WA> TYPE ANY,
<FIELD> TYPE ANY.
LOOP AT <DYN_TABLE> ASSIGNING <WA>.
LOOP AT IFC INTO XFC.
ASSIGN COMPONENT XFC-FIELDNAME OF STRUCTURE <WA> TO <FIELD>.
CASE XFC-FIELDNAME.
WHEN '......'. <FIELD> = .....
WHEN '......'. <FIELD> = .....
..............................
ENDCASE.
ENDLOOP.
ENDLOOP.
Max
07-03-2007 11:00 AM
You can use <b>field symbols</b> for this purpose.
create a <b>work area</b> by declaring it <b>like line of dynamic internal table</b>. then you can use field symbols for field variable by <b>assigning the name</b> of the field from <b>wa</b> to the field symbol, i.e for which the data of the field is to be modified.
This should be done inside the loop of dyn.int.tab into wa.
there after modifying the value in wa with the help of field symbols you can update the dyn.int.tab just like any other internal table using <b>wa</b>.
If you need exact code then give me some time.
Regards
Vijai
Reward if useful
07-03-2007 11:43 AM
CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
EXPORTING
I_STRUCTURE_NAME = DB_TABLE
CHANGING
CT_FIELDCAT = FCAT1[].
CALL METHOD CL_ALV_TABLE_CREATE=>CREATE_DYNAMIC_TABLE
EXPORTING
IT_FIELDCATALOG = FCAT1[]
IMPORTING
EP_TABLE = DYN_ITAB.
ASSIGN DYN_ITAB->* TO <DISP_TABLE>.
CREATE DATA WA LIKE LINE OF <DISP_TABLE>.
ASSIGN WA->* TO <WA>.
MODIFY <dyn_table> FROM <dyn_wa>.
update (DB_TABLE) from table <dyn_table>.
reward points if it is usefull ....
Girish
07-04-2007 12:18 PM
07-04-2007 12:30 PM
Hi,
u can modify dynamic internal table by using this piece of code.u hav to use field symbol for this.
form modify_data .
LOOP AT <dyn_table> INTO <dyn_wa>.
get the column value
ASSIGN COMPONENT p_fl1 OF STRUCTURE <dyn_wa> TO <fs5>.
CHECK sy-subrc = 0.
Modify the value...
<fs5> = p_value.
Modify the internal table.
MODIFY <dyn_table> FROM <dyn_wa>.
ENDLOOP.
Here p_fl1 is a field u want to modify and p_value is a value u want to give to that field for modification.
Reward if it useful.
Regards,
Swati Garg