12-09-2008 10:18 AM
12-09-2008 10:20 AM
REPORT zhashed_table .
types: begin of t_foo,
field1 type char2,
field2 type char2,
field3 type char2,
field4 type i,
end of t_foo.
data: lt_foo type HASHED TABLE OF t_foo
WITH UNIQUE KEY field1 field2 field3.
data: ls_foo like line of lt_foo.
FIELD-SYMBOLS: like LINE OF lt_foo.
Must assign it to use it.
assign ls_foo to .
clear .
-field1 = 'AB'.
-field2 = 'CD'.
-field3 = 'EF'.
-field4 = '2'.
insert into table lt_foo.
clear .
-field1 = 'AB'.
-field2 = 'CD'.
-field3 = 'EF'.
-field4 = '2'.
insert into table lt_foo.
If sy-subrc ne 0.
write:/ ' this is the duplidate key'.
endif.
12-09-2008 10:24 AM
*---Internal Table Declaration
data it_fieldmaster type standard table of zhdmsfieldmaster.
*---Work Area Declaration
data wa_fieldmaster like line of it_fieldmaster.
*---Variable Declaration
data: v_string type string.
*---field symbol Declaration
field-symbols: <f1> type any.
concatenate 'wa_fieldmaster-' udffieldname into v_string.
condense v_string no-gaps.
assign (v_string) to <f1>.
<f1> = udffieldvalue.
wa_fieldmaster-functionalareaid = functionalareaid.
append wa_fieldmaster to it_fieldmaster.
insert into zhdmsfieldmaster values wa_fieldmaster.
12-09-2008 10:25 AM
Hi
u can create a Dynamic Internal table .Just chek out this program .
type-pools : abap.
field-symbols: <dyn_table> type standard table,
<dyn_wa>,
<dyn_field>.
data: dy_table type ref to data,
dy_line type ref to data,
xfc type lvc_s_fcat,
ifc type lvc_t_fcat.
selection-screen begin of block b1 with frame.
parameters: p_table(30) type c default 'T001'.
selection-screen end of block b1.
start-of-selection.
perform get_structure.
perform create_dynamic_itab. *********Creates a dyanamic internal table*********
perform get_data.
perform write_out.
form get_structure.
data : idetails type abap_compdescr_tab,
xdetails type abap_compdescr.
data : ref_table_des type ref to cl_abap_structdescr.
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.
assign dy_table->* to <dyn_table>.
Create dynamic work area and assign to FS
create data dy_line like line of <dyn_table>.
assign dy_line->* to <dyn_wa>.
endform.
form get_data.
Select Data from table.
select * into table <dyn_table>
from (p_table).
endform.
Write out data from table.
loop at <dyn_table> into <dyn_wa>.
do.
assign component sy-index
of structure <dyn_wa> to <dyn_field>.
if sy-subrc <> 0.
exit.
endif.
if sy-index = 1.
write:/ <dyn_field>.
else.
write: <dyn_field>.
endif.
enddo.
endloop.
it wud help
12-10-2008 7:43 AM