Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Comparing two internal tables: Problem appending diff table.

Former Member
0 Likes
790

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

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
716

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.

7 REPLIES 7
Read only

Former Member
0 Likes
716

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_MASTER

Similarly 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

Read only

uwe_schieferstein
Active Contributor
0 Likes
716

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

Read only

Former Member
0 Likes
717

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.

Read only

0 Likes
716

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

Read only

0 Likes
716

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.

Read only

0 Likes
716

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.

Read only

0 Likes
716

Hello Martin,

Check Ankur's post above for creating <wa1>.

Thanks,

Augustin.