THOSE FARMERS who have been lobbying and demonstrating here in Washington deserve a measure of sympathy. They never fully realized that their friends in the Senate were setting them up, in one of the more cynical operations of the current season, with a farm bill that was guaranteed never to be law. The farmers knew that the bill was inflationary, but they wanted it, and for a time they thought they were going to get it. They overlooked the political truth that most voters are not farmers. If the House had not defeated the bill, President Carter would certainly have vetoed it.

The demonstrators let it turn into an adversary issue. That was their basic mistake. They did not entirely intend it to turn out that way. But the demonstrations became a campaign against the cities, against the consumers, against Washington and, ultimately, against Mr. Carter.

The sad thing about this whole episode is that there's another approach, a far more promising one. Much of the farmers' basic argument is not in dispute. They say that the prices for their grain last summer were intolerably low. That's true. They say that long periods of low prices will drive small producers out of farming and leave it to corporations with the financial resources to ride out the long cycles. That's probably true, as well. The farmers worry that the other 96 percent of the population has forgotten where the groceries come from and no longer understands that everybody has an interest in a strong farm economy.

What ought the country do in response? Things are happening already. It's important to note that prices for the major grain crops have risen by 40 percent since the low point late last summer. Chances are better than even that there will be further increases before next fall. One of the reasons is that the Carter administration is wisely building up the country's reserves of grain. That supports current prices by taking some of the surplus off the market. But unlike the other methods of supporting prices, this one also benefits consumers. Those reserves will be a shock absorber against future shortages and price increases.

The farm bill was beaten in the House because of its immediate and direct inflationary implications. It would have had a sharp impact on both the cost of food and the federal deficit. But the greater damage would have come a little later. That bill would have destroyed the strategy of building reserves. Suppose that, with the vital American reserves deliberately run down, the world again suffered a series of droughts and bad harvests abroad like those that began in 1972. The first effect would have been another drastic increase in food prices, as in 1973. But shortly the farmers themselves would suffer, just as they have done since 1974, with crop prices coming off an unsustainable peak - leaving the farmers struck with high land costs, high taxes and high rents. Then the farmers would be back in town, demonstrating again as they have done this winter.

The instability of the agricultural markets seems to be getting worse. As each country is increasingly tied into a world system, markets here in the United States repond more sharply to the fluctuations of weather and harvests everywhere else. The ups and downs of the dollar increase this unpredictability. If the present policy of reserve-building does not adequately smooth out the surges and drops, there will be strong case for further protection to farmers.

In the aftermath of the House vote on the farm bill, some of the farmers bitterly conclude that they have seen beaten and rejected by their government. That's wrong. This country is prepared to pay equitable prices for the farm production that is an essential part of its national prosperity. The only question is how to do it most effectively. The answers do not necessarily pit the people who grow corn against the people who eat cornflakes.