197 was meant to provide for borderline cases where the offence and the sphere of duty are so intermeshed so as to be difficult to seperate the grossly illegal from purely legitimate functions. It was meant to protect honest public servants from being harassed and prosecuted for things that have a great nexus with their duty.
However to know whether an act of a PUblic Servant falls within duty it is pertinent to examine whether the PS could have said that It happenned in course of my duty.
Bribery, Rape things like that can never be in the course of a person's duty.
However acting in private defence shooting - a dreaded criminal back who already had a reward on its head - can be said to be legitimately within course of his duty though killing otherwise never is.