11-16-2006 7:47 AM
Hi guyz.
Its very urgent.
I have dynamic internal table which contains all the data like KUNNR,KDGRP and some Quantity fields. Now I want to read the table based on some fields like KUNNR. Also I want to modify the table based on those fields.
Iam waiting for a quick reply.
Thanks & Regards.
Harish.
11-16-2006 7:59 AM
Take a look at this blog
/people/rich.heilman2/blog/2005/07/27/dynamic-internal-tables-and-structures--abap
LOOP AT ITAB ASSIGNING <FS_TAB>.
ASSIGN COMPONENT 'KUNNR' OS STRUCTURE <FS_TAB> TO <FS_ANY>.
Now you have the value of KUNNR in <FS_ANY>
Process the data.
ENDLOOP.
Regards,
Ravi
Note - Please mark all the helpful answers
11-16-2006 7:59 AM
Take a look at this blog
/people/rich.heilman2/blog/2005/07/27/dynamic-internal-tables-and-structures--abap
LOOP AT ITAB ASSIGNING <FS_TAB>.
ASSIGN COMPONENT 'KUNNR' OS STRUCTURE <FS_TAB> TO <FS_ANY>.
Now you have the value of KUNNR in <FS_ANY>
Process the data.
ENDLOOP.
Regards,
Ravi
Note - Please mark all the helpful answers
11-16-2006 8:42 AM
Hi Ravi,
Thx for your time.
But I want to read the dynamic internal table with READ statement and also using with KEY. Then I want to modify that internal table. As the dynamic internal table doesn't contain any structure, I can't read with the key. So is there some way to convert the dynamic internal table into static or can we read and modify the dynamic internal table directly.
Thanks & Regards.
Harish.
11-16-2006 8:45 AM
A dynamic internal table is always dynamic and cannot be converted into static table. And because its dynamic, you cannot use a READ statement with a WHERE clause.
You have to loop at the table and check the value one by one and then do the processing, I don't think you have a option.
Regards,
Ravi
Note - Please mark all the helpful answers
11-16-2006 10:40 AM
Not the best approach, but just give a try,
I just made some changes to the code posted by Rich in his weblog,
REPORT zkb_dynamic_itab.
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 'SCARR'.
SELECTION-SCREEN END OF BLOCK b1.
START-OF-SELECTION.
PERFORM get_structure.
PERFORM create_dynamic_itab.
PERFORM get_data.
PERFORM read_data_from_dyntable USING 'JL'.
&----
*& Form get_structure
&----
text
----
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. "get_structure
&----
*& Form create_dynamic_itab
&----
text
----
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. "create_dynamic_itab
&----
*& Form get_data
&----
text
----
FORM get_data.
Select Data from table.
SELECT * INTO CORRESPONDING FIELDS OF TABLE <dyn_table>
FROM (p_table).
ENDFORM. "get_data
&----
*& Form read_data_from_dyntable
&----
text
----
-->P_P_CARRID text
----
FORM read_data_from_dyntable USING p_carrid TYPE s_carr_id.
FIELD-SYMBOLS: <l_dyn_wa> TYPE ANY,
<l_dyn_field> TYPE ANY.
DATA: l_dy_line TYPE REF TO data.
DATA: li_results TYPE match_result_tab,
lw_results TYPE match_result.
CREATE DATA l_dy_line LIKE LINE OF <dyn_table>.
ASSIGN l_dy_line->* TO <l_dyn_wa>.
ASSIGN COMPONENT 2 OF STRUCTURE <l_dyn_wa> TO <l_dyn_field>.
<l_dyn_field> = p_carrid.
Reading the data
FIND ALL OCCURRENCES OF <l_dyn_field>
IN TABLE <dyn_table>
RESULTS li_results.
READ TABLE li_results INTO lw_results INDEX 1.
READ TABLE <dyn_table> INTO <dyn_wa> INDEX lw_results-line.
WRITE:/ <dyn_wa>.
Modifying the data
ASSIGN COMPONENT 5 OF STRUCTURE <dyn_wa> TO <l_dyn_field>.
<l_dyn_field> = 'http://www.jal.com'.
WRITE:/ <dyn_wa>.
ENDFORM. " read_data_from_dyntable
Thanks
Kathirvel