‎2009 Aug 24 10:27 PM
Hi,
I'm about to create a class with a simple method that should compare 2 internal tables and return the rows that differ from the MASTER table.
All the import tables are of type ANY. (table structure like MARA.)
Any pointers what I can do in order to get the append to work. It crashes with the error "You attempted to access an unassigned field symbol
(data segment 32775)."
method compare2.
Local variables
field-symbols: <wa1> type any,
<wa2> type any,
<i_diff23> type standard table.
refresh: i_diff.
loop at i_master assigning <wa1>.
read table i_slave with key table_line = <wa1> transporting no fields.
check sy-subrc <> 0.
append <wa1> to <i_diff23> assigning <wa1>.
endloop.
i_diff = <i_diff23>.
endmethod.
Br, Martin
‎2009 Aug 25 5:53 AM
Hello Martin,
Befor going for access of any field symbol you need to assign some reference either from data object or from variables.
In current case for every field symbol in code you can put IS ASSIGNED statement around it to avoid dumps.
IF <wa> IS ASSIGNED.
........process..
ENDIF.
Hope this helps!
Thanks,
Augustin.
‎2009 Aug 24 10:45 PM
Hi,
The statement
loop at i_master assigning <wa1>.
wiil lead toa dump because the field-symbol <WA1> has no defined structure.
Do as follows:-
Create a varaible of type data.
DATA : gv_obj TYPE REF TO DATA.
CREATE DATA gv_obj LIKE LINE OF i_master.
ASSIGN gv_obj->* TO <wa1>.
* NOW <WA1> HAS THE SAME STRUCTURE AS I_MASTERSimilarly you should define one more field symbol and assign the structure of i_slave to it.
and then read i_slave into that field -symbol.
Regards,
Ankur Parab
‎2009 Aug 25 4:30 AM
Hello Martin
Assuming that you two itabs have the same line structure you may have a look at my Wiki posting
[Comparing Two Internal Tables - A Generic Approach|https://wiki.sdn.sap.com/wiki/display/Snippets/ComparingTwoInternalTables-AGeneric+Approach]
Regards
Uwe
‎2009 Aug 25 5:53 AM
Hello Martin,
Befor going for access of any field symbol you need to assign some reference either from data object or from variables.
In current case for every field symbol in code you can put IS ASSIGNED statement around it to avoid dumps.
IF <wa> IS ASSIGNED.
........process..
ENDIF.
Hope this helps!
Thanks,
Augustin.
‎2009 Aug 25 6:08 AM
Hi,
I can see in debug mode that everthing works just fine until APPEND.
I just want to add my structure into a table of type ANY or something...
check sy-subrc 0.
append <wa1> to <i_diff23> assigning <wa1>.
Br,
martin
‎2009 Aug 25 6:28 AM
Hello Martin,
You can try following code:
DATA DIFF TYPE REF TO DATA.
CREATE DATA DIFF LIKE TABLE OF <wa1>.
ASSIGN DIFF->* to <diff23>.
Now you can remove assigning <wa1> from your APPEND statement.
<wa1> and <diff23> are now having same strucutre.
Also, Make sure you use IS ASSIGNED before accessing any field symbol.
Thanks,
Augustin.
‎2009 Aug 25 6:52 AM
Hi,
Change my code to :
method compare2.
Local variables
field-symbols: <wa1> type any,
<wa2> type any,
<i_diff23> type standard table.
data: l_sy_subrc type sy-subrc.
data diff type ref to data.
create data diff like table of <wa1>. <<<<<<<<<<< ERROR <WA1> not assign...
assign diff->* to <i_diff23>.
refresh: i_diff.
loop at i_master assigning <wa1>.
read table i_slave with key table_line = <wa1> transporting no fields.
l_sy_subrc = sy-subrc.
if l_sy_subrc <> 0.
if <wa1> is assigned.
if <i_diff23> is assigned.
append <wa1> to <i_diff23>.
endif.
endif.
endif.
endloop.
if <i_diff23> is assigned.
i_diff = <i_diff23>.
endif.
endmethod.
‎2009 Aug 25 7:01 AM
Hello Martin,
Check Ankur's post above for creating <wa1>.
Thanks,
Augustin.