
259 Cal.App.2d 356 (1968)
SAMUEL A. McDANIEL, Plaintiff and Appellant,
v.
CITY AND COUNTY OF SAN FRANCISCO et al., Defendants and Respondents.
Civ. No. 23813. 
California Court of Appeals. First Dist., Div. Three.  
Feb. 23, 1968.
 McMurray & Tepper and Lloyd E. McMurray for Plaintiff and Appellant.
 Thomas M. O'Connor, City Attorney, and Donald J. Garibaldi, Deputy City Attorney, for Defendants and Respondents. *359
 SALSMAN, J.
 This is an appeal from a judgment denying appellant's petition for a writ of mandate, dissolving the alternative writ, and adjudging appellant indebted to the retirement fund of the City and County of San Francisco in the amount of $4,708.92.
 The facts are not in dispute. Appellant is a cable car gripman on the San Francisco Municipal Railway, a civil service position. For a long time prior to the events in this case, his former wife Zereldia McDaniel had regularly attached his earnings pursuant to a judgment for child support. These attachments were made under the procedure described in Code of Civil Procedure, section 710.
 On April 23, 1964, appellant had been employed by the Municipal Railway for 16 1/2 years and had accumulated $8,238.86 in the city retirement fund. Beginning with that date, the following events occurred:
 (1) April 23, appellant was suspended from his employment for a violation of Municipal Railway rules.
 (2) May 26, he requested a refund of his retirement contributions. The form filled out and signed by him stated: "My service with the City and County of San Francisco terminated 4-23-64. I hereby request refund of the accumulated contributions standing to my credit in the retirement fund."
 (4) June 8, appellant's former wife filed an abstract of judgment and affidavit with the controller's office under Code of Civil Procedure, section 710. The affidavit asserted that $4,872.68 was due her under the judgment.
 (5) June 19, the city's Retirement System, pursuant to appellant's request, submitted to the controller a refund roll for the sum of $8,238.86, payable to appellant.
 (6) June 23, appellant's appeal was filed with the Civil Service Commission.
 (7) June 25, the controller, in response to the abstract of judgment and affidavit filed with him, prepared a warrant in the sum of $4,708.92,  [fn. 1] payable to the superior court, and deposited the warrant with the court. The controller did not notify appellant that a part of the refund of his retirement contributions was being paid into court pursuant to the attachment.
 (8) June 29, appellant called at the offices of the Retirement *360 System. There he learned that a portion of his retirement refund had been sent to the superior court. A warrant for the remainder of his contributions was tendered to him, but he refused to accept it. He informed the clerk in the office that he "... didn't want the money, because my case was being appealed, and chances are I would get reinstated by the railway, and I wanted the money to remain in the Retirement System."
 (9) June 30, the superior court ordered the funds in its possession paid over to the attaching creditor. This payment was made without appellant's knowledge.
 (10) July 8, appellant's attorneys notified the Retirement System of the rescission of his request to withdraw his retirement funds. His attorneys requested prompt action and noted that a levy had been made upon the controller, and that there was danger some of the funds might be paid over under the levy unless speedy action was taken. At the same time appellant notified the Retirement System of his appeal.
 (11) March 22, 1965, the Civil Service Commission ordered appellant reinstated with back pay from the date of his dismissal, less amounts earned while discharged.
 [1a] The respondent city did not pay the back wages ordered by the Civil Service Commission. It asserts that appellant is deficient in his retirement fund contributions because of the money withdrawn by appellant and seized by his creditor, and that this amount should be set off against the amount of back wages found due under the Commission's order.
 On the facts recited, the trial court found that appellant was indebted to the city's retirement fund in the amount of $4,708.92 and that the city was entitled to set off this amount against any back wages due him. Accordingly, the court denied the writ. We conclude that the trial court's judgment is correct, and therefore affirm.
 [2] One of the essential conditions for issuance of the writ of mandate is a showing on the part of the applicant that he has a clear legal right to the performance of the act the writ would compel. (Consumers Salt Co. v. Riggins, 208 Cal. 537, 543 [282 P. 954]; 32 Cal.Jur.2d, Mandamus,  6, p. 122; 3 Witkin, Cal. Procedure (1954) Extraordinary Writs,  40, p. 2520.) [3] Moreover, the writ is an equitable remedy, and will not always issue as a matter of right. (Sutro Heights Land Co. v. Merced Irr. Dist., 211 Cal. 670, 704-705 [296 P. 1088]; Wallace v. Board of Education, 63 Cal.App.2d 611, *361 617 [147 P.2d 8].) [4] The decision whether to grant or deny the writ lies within the sound discretion of the court, and one of the chief considerations in the exercise of that discretion is the effect of the court's order in promoting the ends of justice. (See Bartholomae Oil Corp. v. Superior Court, 18 Cal.2d 726, 730 [117 P.2d 674], and cases cited.) When these fundamental rules are applied to the facts of this case it is clear that appellant does not make the clear and unequivocal showing of a right to the writ contemplated by the law, and that grant of the writ would not accomplish substantial justice.
 Code of Civil Procedure, section 710 establishes a procedure for enforcing money judgments against a debtor to whom money is owed by the state or a political subdivision thereof. Insofar as applicable here, the statute allows the judgment creditor to file an abstract of judgment with the city auditor, together with an affidavit stating the amount due, and thereupon makes it the duty of the auditor to forward to the court which issued the abstract of judgment an amount sufficient to pay the claim, or a part thereof equal to no more than one-half of the debtor's salary or wages owing by the city to the debtor for personal services rendered within 30 days of the levy.
 [5] One of appellant's prime contentions is that the retirement contributions paid into court by the auditor were not monies "owing and unpaid" to him within the meaning of section 710, because petitioner was not entitled to have his retirement contributions paid to him while the appeal from his discharge was pending. We find no merit in this ground of appeal.
 In our opinion, appellant's retirement contributions were "owing and unpaid" from the time of his discharge on May 21, or, at the very latest, from May 26, when he demanded a refund of his contributions in writing. The city had received his contributions over a period of years and was bound to account to him for them if for any reason his pension rights did not mature. (S.F. Charter  165.2(F).) This was an existing and unsatisfied legal liability on the part of the city. (See Department of Water & Power v. Inyo Chemical Co., 16 Cal.2d 744, 751 [108 P.2d 410], and cases cited.) It is true that two days before the controller paid the funds into court, appellant appealed his discharge. But he did not revoke his demand for a refund of his retirement money or notify the *362 Retirement System. A few days after the auditor's payment he called at the office of the Retirement System and learned that some of his funds had been paid over to the court for his wife. At that time he orally notified the clerk in the office that he was rescinding his request for repayment of his retirement funds. But by that time the funds were beyond the control of the city and were in the hands of the court. Appellant cannot fault the city because it complied with his written demand for the return of his money, and at the same time complied with the law by paying a portion of it over to the court pursuant to a lawful levy.
 Appellant's reliance upon Credit Bureau of San Diego, Inc. v. Getty, 61 Cal.App.2d Supp. 823 [142 P.2d 105] is misplaced. In that case a court deposited bail money with the county treasurer. A creditor of the defendant for whom it was deposited attempted to reach it under Code of Civil Procedure, section 710. The court pointed out that the bail money was not money owing by any city or county within the meaning of the statute and that it could not be reached by the statutory procedure. In Credit Bureau of San Diego, Inc. the funds, although in possession of the county, were subject to disposition by the court and not by the board of supervisors. Here, however, all money in the Retirement System is under the control of the city, although the fund is administered by the system as an agency of the city government. As we have already pointed out, the charter itself makes an employee's contributions refundable to him if for any reason he ceases to be a city employee before his pension is due. Thus, the monies requested by appellant after his discharge and before his appeal were clearly monies "due and owing" by the city to the employee.
 [6a] Nevertheless appellant argues that the city breached a statutory duty to notify him that his wife had levied upon his funds. The sum of his argument is that if he had been notified in time he could have taken steps to revoke his claim for a refund before the auditor sent the money to the court, or claim an exemption under Code of Civil Procedure, section 690. (See, e.g., Code Civ. Proc.,  690.23.)perhaps appellant could have successfully contested the claims of his wife and the rights of his children if he had been forewarned. But appellant set the machinery in operation to obtain his money. This began on May 26, when he demanded a refund of his contributions. The creditor's levy arrived on June 8th, but it was not until June 19th, when the Retirement System submitted *363 its roll to the auditor, that the latter was aware of the funds due appellant. Two days later, without any word from appellant, the auditor complied with the court's order and forwarded the funds to the court. The auditor called the court's attention to possible exemptions appellant might claim, and in this respect went further than the law expressly requires. Thereafter the matter was in the hands of the court. Neither the city nor the auditor can be held liable because the court paid out the funds to the creditor before appellant could assert a claim of exemption.
 Although section 710 provides a summary adversary proceeding in the superior court for one whose funds are attached while in the hands of a governmental unit (see Code Civ. Proc.,  690.26), it imposes no duty on the auditor or controller to notify the debtor of the garnishment. The Legislature could have inserted such a requirement in the detailed provisions for proceeding under section 710 if it had so desired, and it may do so at any time. As drafted, however, it is significant that the statute merely requires that the controller or auditor forward the funds to the court, withholding only a wage exemption (Code Civ. Proc.,  710, subd. 2). [7] The purpose of providing a special garnishment procedure in the superior court where governmental units are involved is clearly to shift to the court the burden of adjudicating any claims of exemption which may arise and to insulate the governmental units from liability for wrongful payments to garnishing creditors. [6b] To hold the city and county liable in this case would thus defeat the purpose of section 710. Whether the garnishing judgment creditor or any other person has a duty to notify the judgment debtor of the proceedings in the superior court is a question not properly before us on this appeal.
 [8] We recognize that, under some circumstances, it has been held that a garnishee, who knows that the property levied on is subject to a claim of exemption and that the judgment debtor is ignorant of the levy, has a duty, whenever practicable, to notify the debtor of the garnishment, so that the latter may have the opportunity to claim his exemption if he desires. (Agnew v. Cronin, 148 Cal.App.2d 117, 126 [306 P.2d 527]; Hing v. Lee, 37 Cal.App. 313, 317-318 [174 P. 356]; Harris v. Balk, 198 U.S. 215, 217 [49 L.Ed. 1023, 1024, 25 S.Ct. 625].) But we do not think that rule is applicable where the garnishee is a governmental unit or a public officer and section 710 is involved. *364
 [9] Appellant argues that the alleged setoff has not been properly pleaded. The essence of his objection is that it should have been presented in a separate pleading, either by cross-complaint or counterclaim. (See 2 Witkin, Cal. Procedure (1954) Pleading,  566, p. 1570.) The record shows it was merely included as a part of a paragraph in the answer to the petition for the writ.perhaps it would have been better to describe respondents' setoff in a separate pleading, but no harm has been done by that omission. All of the facts surrounding the claim are fully and clearly set forth in the answer. Appellant was fully informed. He knew exactly what to expect at the hearing. He could not have been better informed by a separate pleading. Aside from a brief reference to the subject in his memorandum of points and authorities accompanying his general demurrer to the answer, he made no reference in the trial court to the claimed defect in the answer. The matter was thereafter fully presented on its merits. Whatever objection might have been urged against the pleading of the setoff vanished at the close of the evidence, because the matter was fully heard under the pleadings presented.
 [10] Appellant contends further that, in this mandamus proceeding, the city is not entitled to set off the amount of his retirement account deficiency against his claim for back wages, because that matter is purely collateral, unrelated to his right to have the city comply with the order of the Civil Service Commission, and thus may not be considered in this case. We do not agree.
 Code of Civil Procedure, section 1109, relating to extraordinary writs, makes the provisions of part 2 of that code applicable to writ proceedings.part 2 includes provisions relating to pleadings in civil actions, and such provisions are therefore fully applicable to writ proceedings unless other rules are specifically made applicable. A respondent's answer to a petition for the writ of mandate should set up any matter of defense relied upon as justification for the circumstances which gave rise to the petition for mandate. (Rittersbacher v. Board of Supervisors, 220 Cal. 535, 542 [32 P.2d 135]; Bank of Italy v. Johnson, 200 Cal. 1, 28 [251 P. 784]; Felice v. City of Inglewood, 84 Cal.App.2d 263 [190 P.2d 317].) Here the city properly asserted its claim to a setoff, and the trial court properly considered it in arriving at its judgment.
 [1b] The doctrine of setoff is described in Code of Civil Procedure, section 440. It reads: "When cross-demands have *365 existed between persons under such circumstances that, if one had brought an action against the other, a counterclaim could have been set up, the two demands shall be deemed compensated, so far as they equal each other, and neither can be deprived of the benefit thereof by the assignment or death of the other." Thus, when cross-demands exist between parties, their claims are paid to the extent they are equal. (Jones v. Mortimer, 28 Cal.2d 627, 633 [170 P.2d 893]; Sunrise Produce Co. v. Malovich, 101 Cal.App.2d 520 [225 P.2d 973].)pursuant to this rule it has been held that an employer may set off his employee's debt against the employee's claim for wages due. (Patterson v. Henderson Tire & Rubber Co., 112 Cal.App. 48 [296 P. 304].) A municipal corporation has the same right as any other creditor to claim a setoff (Corbett v. Widber, 123 Cal. 154, 156 [55 P. 764]; United States v. Munsey Trust Co., 332 U.S. 234 [91 L.Ed. 2022, 67 S.Ct. 1599]), and it has been held that it would be a breach of duty for a public officer to pay an obligation due an individual when the individual owed a like sum to the public body. (See State ex rel. Pratt v. Seattle, 73 Wash. 396 [132 P. 45].) Appellant's ultimate pension rights do not depend upon his contributions to the retirement fund. His full pension may be paid even though his contribution account is deficient. But in fairness to all other members of the Retirement System who are required to contribute their full share to the fund, as well as to the city's taxpayers who underwrite and guarantee the fund's deficiencies, the city should be allowed to set off against appellant's claim for back wages the amount by which his retirement account is deficient.
 The judgment is affirmed.
 Draper, P. J., and Bray, J.,  [fn. *] concurred.
NOTES
[fn. 1]  1. The amount of the warrant was $163.76 less than the amount demanded in the levy because that amount had already been paid into court from other funds due appellant.
[fn. *]  *. Retired Presiding Justice of the Court of Appeal sitting under assignment by the Chairman of the Judicial Council.
