2008 Jun 19 5:31 PM
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
2008 Jun 19 5:49 PM
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
2008 Jun 19 5:49 PM
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.
2008 Jun 19 5:55 PM
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
| User | Count |
|---|---|
| 6 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |