2014 May 14 4:21 PM
Hi Team, I need a help on a topic in ABAP where I need to compare all fields of 2 different Work Areas and for any discrepancy in a particular field.
I need to highlight in a different color.
It would not be advisable to compare each field of both Work Areas as numbers of fields are more than 40. Please suggest.
I have attached a sample over here. Thanks in advance.
2014 May 15 9:22 AM
I just made this report for you.....
REPORT ztest_gb1.
DATA: wa_1 TYPE t001,
wa_2 TYPE t001.
DATA: rf_descr_ref TYPE REF TO cl_abap_typedescr.
FIELD-SYMBOLS: <fs1> TYPE any,
<fs2> TYPE any.
START-OF-SELECTION.
SELECT * FROM t001 INTO wa_1
UP TO 1 ROWS.
ENDSELECT.
wa_2 = wa_1.
*forcefully changing variable to test
wa_2-stceg = '1'.
DO.
* Assign every field of this structure subsequently to the untyped
*fieldsymbol.
* BREAK-POINT.
ASSIGN COMPONENT sy-index OF STRUCTURE wa_1 TO <fs1>.
IF sy-subrc NE 0.
EXIT.
ENDIF.
ASSIGN COMPONENT sy-index OF STRUCTURE wa_2 TO <fs2>.
IF sy-subrc NE 0.
EXIT.
ENDIF.
IF <fs1> NE <fs2>.
* mismatch found.
CALL METHOD cl_abap_typedescr=>describe_by_data
EXPORTING
p_data = <fs1>
RECEIVING
p_descr_ref = rf_descr_ref.
WRITE: / sy-index, rf_descr_ref->type_kind,
rf_descr_ref->absolute_name.
ENDIF.
ENDDO.
It should give an output like
14 C
\TYPE=STCEG
Hi Team, I need a help on a topic in ABAP where I need to compare all fields of 2 different Work Areas and for any discrepancy in a particular field.
I need to highlight in a different color.
It would not be advisable to compare each field of both Work Areas as numbers of fields are more than 40. Please suggest.
I have attached a sample over here. Thanks in advance.
2014 May 14 5:14 PM
Abishek,
Instead of comparing all the fields, all the time just check if wa1 = wa2 (assuming the structure of wa1 and wa2 are the same).
if they are not the same then create a subroutine where you check all the 40 fields. This way you will only end up comparing only if the work areas are not same.
Thanks,
Vikram.M
2014 May 14 5:58 PM
2014 May 14 6:35 PM
Alpesh, I am wondering why dont you want to compare the work areas directly but assigning the components of WA to FS and then comparing the FS?
2014 May 14 8:56 PM
2014 May 14 10:53 PM
vikram, would you be able to find the difference cells if you compare the whole structure? That was the main requirement as you may see.
Alpesh's answer is correct if the structures are the same (meaning both structures belong to the same table). If they were not the same, but hold in particular some common fields, then one need to use some RTTI methods. But I suppose this is not the case.
Abhishek, please close the thread if your requirement is answered.
2014 May 15 8:42 AM
Hello Everyone..
Thanks for your reply but just to update that structure of both work areas are same.
I just need to compare each field of both WA.
e.g. wa1-bukrs = 100 and wa2-bukrs = 200
then I want to highlight wa2-bukrs in my final output of ALV.
and this comparison will applicable for more than 40 fields.
So need your guidance.
2014 May 15 8:52 AM
you already had the solution written here, by some reason it is hidden now.
DO.
ASSIGN COMPONENT sy-index of strcutre wa_1 to <lv_field1>
if ( sy-subrc <> 0 ).
exit
endif.
ASSIGN COMPONENT sy-index of strcutre wa_2 to <lv_field2>
if ( sy-subrc <> 0 ).
exit
endif.
if <lv_field1> <> <lv_field2>.
* this field is different between the structures - do your own logic (e.g. find sy-index's position of the field in fieldcatalog, if it was not changed and highlight the field, or whatever you would like to do). If you need to find the real name of the fieldname in structrue, use e.g. FM DDIF_FIELDINFO_GET, where you can find sy-index's position and the name of the column.
endif.
ENDDO.
2014 May 15 9:05 AM
2014 May 15 9:22 AM
I just made this report for you.....
REPORT ztest_gb1.
DATA: wa_1 TYPE t001,
wa_2 TYPE t001.
DATA: rf_descr_ref TYPE REF TO cl_abap_typedescr.
FIELD-SYMBOLS: <fs1> TYPE any,
<fs2> TYPE any.
START-OF-SELECTION.
SELECT * FROM t001 INTO wa_1
UP TO 1 ROWS.
ENDSELECT.
wa_2 = wa_1.
*forcefully changing variable to test
wa_2-stceg = '1'.
DO.
* Assign every field of this structure subsequently to the untyped
*fieldsymbol.
* BREAK-POINT.
ASSIGN COMPONENT sy-index OF STRUCTURE wa_1 TO <fs1>.
IF sy-subrc NE 0.
EXIT.
ENDIF.
ASSIGN COMPONENT sy-index OF STRUCTURE wa_2 TO <fs2>.
IF sy-subrc NE 0.
EXIT.
ENDIF.
IF <fs1> NE <fs2>.
* mismatch found.
CALL METHOD cl_abap_typedescr=>describe_by_data
EXPORTING
p_data = <fs1>
RECEIVING
p_descr_ref = rf_descr_ref.
WRITE: / sy-index, rf_descr_ref->type_kind,
rf_descr_ref->absolute_name.
ENDIF.
ENDDO.
It should give an output like
14 C
\TYPE=STCEG
2014 May 15 9:31 AM
THANKS A LOT guys..you made it easy for me.
Closing this thread with smile
| User | Count |
|---|---|
| 3 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |