With "Mary Hartman, Mary Hartman" coming to the end of a successful two-year run, it seems clear that ABC's new comedy, "Soap," will capture the attention of all those who get worked up about what they imagine to be sex on television.

By the time "Soap" goes on the air in September, there should be a lively debate. Whatever else that debate does, it is likely to make "Soap" the most widely watched television comedy in years.

It's difficult to describe "Soap." Susan Harris, its creator and writer, first described it to me last winter as a form of comedy drama. After seeing two episodes of it recently, my impression is that it's more like farce.

If that impression is correct, then the people who will probably get worked up over what they imagine "Soap" is should brush up on their Shakespeare and remember the plots of Restoration comedies. Then they will understand how sex was and is employed in farce.

It usually consisted of a lot of men and women opening and closing doors, hiding behind screens, or trying to avoid detection under sofas or beds.

That's not quite what it is in "Soap." Harris has a lot of jokes at the expense of adultery, homosexuality or a mother leaving by the back door of a young tennis teacher's apartment while her daughter is knocking on the front door.

Watching it in Los Angeles last month in an audience composed of ABC affiliate representatives and their wives, my impression was that nearly all of them were laughing outrageously at sex being used in the furtherance of farce.

But a large number of people have some obsession about what they think is too much sex on television. They see it everywhere. What fantasies they must enjoy.

In a conversation the other day, Norman Lear recalled that in the eight years he has been involved with "All in the Faimly," the problem with network program monitors has never been about Archie's racial and ethnic slurs. It has always been about sex, or what these individuals imagined was sex.

He recalled that in the first episode, questions were raised about Mike and Gloria going upstairs to bed on Sunday morning while Archie registered his strong disapproval.

Lear said he told the program practices people: "I don't consider that a young married couple wanting to make love at any time constitutes sex as that word is used in the expression 'sex and violence.'"

There is a strong tendency on the part of many television critics to try to make the medium reflect the world not as it is but as they would like it to be.

That can be very misguided - and nowhere is this more true than in the area of sex. It is misguided, especially when their attacks are leveled at sex in comedy or farce, because so much of our humor, from infancy on, is based on sex.

One of the strongest expressions of childhood laughter is often produced by bathroom humor. If you saw "American Graffiti" in the company of children and adults, you will remember that one of the movie's biggest laughs came when the tee-agers "mooned" their backsides.

Before the angry letters and postcards start coming in, I assure you that I am not advocating "mooning" on television screens or anything much more explicit than Farrah Fawcett-Majors wearing a wet T-shirt.

What I am suggesting is that television comedy be permitted to reflect the degree to which humor in our society - or any other, for that matter - is derived from our perceptions about sex.

Thanks, in the main, to Norman Lear, we have come a long way in television comedy toward recognizing the relationship between laughter and sex. It would be a pity if we allowed the clock to be turned back. That would not be funny at all.