The term "grammar" goes back to a Greek word which may be translated as "the art of writing". But later this word acquired a much wider sense and come to embrace the whole of the study of language. Now it's often used as a synonym of linguistics.
Oxford Dictionary of Linguistics defines grammar as any systematic account of the structure of a language; the patterns that it describes; the branch of linguistics concerned with such patterns. Grammar is characterized by the highest degree of abstraction: it only deals with general notion such as the abstract notions of tense, number, case, etc.
The study of grammar reduces to that of morphology and syntax - the two spheres where system relations between linguistic units are realized.
Morphology studies the forms of words, the grammatical structure of words and the categories realized by them.
Syntax studies the combinations of words in word groups and sentences. It is the study of grammatical relations between words and other units within sentence.