A person may be occupied with Torah and mitzvot in a way that is literally not for its own sake, meaning for an ulterior motive, when he directs his intentions toward a goal that is completely not for the sake of Heaven.
Studying Torah is a commandment, but being a Torah scholar is not.
So when a person studies Torah in order to be called a Torah scholar, he is studying with an ulterior motive. When a person wants to acquire the status of a Torah scholar, when he desires any kind of social recognition, whether as a rabbi or a university professor, his motive is not for the sake of Heaven but for his own honor.
Not only with Torah study and with divine service overall, but even with prayer it is possible to serve God with such a motive, and with motives that are even lower than that.
Rabbi Adin Steinsaltz