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

How To Find Differing Columns Between Internal Tables

Former Member
0 Likes
426

All,

I have seen this question arise on the boards before but have been unable to find a good solution. I have two identical structures coming into a function module. For context, this is a BTE that fires when an FI document is modified. It passes in 1 structure with the old header data and 1 structure with the new header data so that you can see what was changed.

I need an efficient way to find which fields have changed (e.g. which fields in the two structures that have different values). We need to fire off a process if certain fields were changed. I was looking for a graceful way to do this without having to hardcode all 100+ field names to compare. Any ideas? I've played around with getting the structure components from CL_ABAP_TYPEDESCR but have been unsuccessful in using the results to loop through and dynamically check each field.

Thanks,

Seth

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
406

You could make a simple compare if they have the same structure.

struct1 = struct2

if the return is false do something like this.


do.
assign component sy-index of structure struct1 to <fs>.
if sy-subrc ne 0.
exit.
endif.
assign component sy-index of structure struct2 to <fs2>.
if sy-subrc ne 0.
exit.
endif.
"Compare each field
enddo.

But again, would only work if the structures are the same.

All,

I have seen this question arise on the boards before but have been unable to find a good solution. I have two identical structures coming into a function module. For context, this is a BTE that fires when an FI document is modified. It passes in 1 structure with the old header data and 1 structure with the new header data so that you can see what was changed.

I need an efficient way to find which fields have changed (e.g. which fields in the two structures that have different values). We need to fire off a process if certain fields were changed. I was looking for a graceful way to do this without having to hardcode all 100+ field names to compare. Any ideas? I've played around with getting the structure components from CL_ABAP_TYPEDESCR but have been unsuccessful in using the results to loop through and dynamically check each field.

Thanks,

Seth

2 REPLIES 2
Read only

Former Member
0 Likes
407

You could make a simple compare if they have the same structure.

struct1 = struct2

if the return is false do something like this.


do.
assign component sy-index of structure struct1 to <fs>.
if sy-subrc ne 0.
exit.
endif.
assign component sy-index of structure struct2 to <fs2>.
if sy-subrc ne 0.
exit.
endif.
"Compare each field
enddo.

But again, would only work if the structures are the same.

Read only

Former Member
0 Likes
406

I was late, my answer was the same:

If structures are identically you may use code like this.

 
  DO.
    ADD 1 TO lv_comp_no.
    ASSIGN COMPONENT lv_comp_no OF STRUCTURE gs_struct1 TO <lfs_value1>.
    IF sy-subrc NE 0.
      EXIT.
    ENDIF.
    ASSIGN COMPONENT lv_comp_no OF STRUCTURE gs_struct2 TO <lfs_value2>.
    IF sy-subrc NE 0.
      EXIT.
    ENDIF.  
    IF <lfs_value1> NE <lfs_value2>.
    ... 
    
   ENDDO.

Kind regards,

Holger

Edited by: Holger Pakirnus on Jun 19, 2008 6:56 PM