I would suggest you do two things.
1. Remove the GETITEM statements from the conditional IF statement. I like it better that way.
Something like this:
rate_imprat_c = dw_rate.GetitemNumber (1, 'imprat_c')
detail_imprat_c = dw_detail.GetitemNumber (i, 'imprat_c')
IF rate_imprat_c<> detail_imprat_c THEN
...
ELSE
...
END IF
2. Debug it step by step and you would be able to see the actual value of each variable