When Sens. Edward M. Kennedy (D-Mass.) and Alan Cranston (D-Calif.) failed to force a vote on a bill to impose tough sanctions on South Africa, they knew exactly where to turn.

So did Sen. Mack Mattingly (R-Ga.) when he lost a chance for a vote on a measure to strengthen the president's veto power over spending bills.

And so did other senators in pursuit of a shortcut to votes on trade legislation.

Their target is legislation to raise the national debt ceiling to $2.079 trillion. The current ceiling of $1.824 trillion will be reached early next month. An extension is required so the government can continue to borrow money to pay its bills.

It is an essential but routine bill, basically a bookkeeping action that reflects policy decisions that have already been put into effect.

But, as the debt has mounted under the impact of soaring deficits, legislation allowing more debt has become rich in symbolism, enhancing its value as a vehicle for political posturing. Its value as a home for stray pieces of legislation is also accepted: Since the debt bill is one that Congress invariably passes, attaching unrelated legislation offers some hope to what normally might be doomed legislation.

Riders on issues ranging from balanced-budget requirements to school prayer and antiabortion legislation have been aimed at the debt bill in previous years. At the same time, both Republicans and Democrats try to profit from it while avoiding responsibility for its passage.

Normally, the debt measure is passed in Perils-of-Pauline fashion in the nick of time, after all the political points have been scored, with extraneous matters pared off as the measure works its way through Congress.

But sometimes things get out of control, as they did last year when Treasury Department auctions were postponed and the government came perilously close to exhausting its line of credit.

This year could be the worst yet, some lawmakers fear.

Not only are Democrats poised to pull out all the stops to call attention to the doubling of the debt in Reagan's five years in office, but senators from both parties are pushing unusually heavyweight legislation as riders.

These include a variety of fiscal measures, such as tax increases, spending cuts and institutional reforms to help control deficits, as well as trade restrictions, South Africa sanctions and an assortment of lesser matters.

"We'll have a free-for-all on the debt bill," said Sen. Slade Gorton (R-Wash.), predicting amendments dealing with trade, taxes, South Africa and "everything else that comes down the pike."

Perhaps more significantly, chances are better than usual that some of the riders may prevail, possibly even with the leadership's blessing to overcome obstacles to passage of the debt measure itself.

Pressure for trade legislation is intense, starting with a textile and apparel measure that could be attached to the debt bill if another home for it is not found.

In addition, Sen. Steve Symms (R-Idaho) has a proposal to reopen the budget and cut spending further; Sen. William L. Armstrong (R-Colo.) has several ideas, including one to expand the president's power to rescind, or withhold, spending; Mattingly would give Reagan line-item veto authority to cut individual programs within appropriations bills for a two-year trial period. There has been vague talk of tax proposals, including some preemptive moves on tax reform. Sen. Phil Gramm (R-Tex.) is toying with the idea of proposing a "flat tax" substitute for the graduated income tax as a rider to the debt bill.

And all of this comes nearly a month before Congress must face the debt bill, which leaders plan to back up against the planned Columbus Day recess to enhance the deadline pressures for passage. Many more ideas may float to the surface in the meantime. "Anything that's not already on the calendar will be fair game," said a Senate Republican leadership aide.