Richard E. Grosso (Appellant) appeals from an order of the Court of Common Pleas of Huntingdon County (common pleas court) which sua sponte dismissed Appellant’s complaint against William J. Love, Superintendent and C. Shea, Inmate Accountant (Commonwealth) as frivolous, time-barred, and repetitious. We vacate and remand.
Appellant, while an inmate at the State Correctional Institution at Huntingdon (SCI-Huntingdon), swallowed a coin during a family visit in June 1989. As a result, Appellant was transported to a local hospital and incurred over $1200 in hospital costs. Upon returning to SCI-Huntingdon, Appellant received a misconduct report. A hearing examiner found Appellant guilty of the misconduct and sanctioned him to thirty days of *44restricted confinement, a loss of six months visiting privileges, as well as liability for the $1200 in hospital costs. Thereafter, prison officials deducted these costs from Appellant’s inmate account, without Appellant’s authorization.
Appellant filed a civil rights action alleging violation of his due process and equal protection rights in the United States District Court for the Middle District of Pennsylvania (District Court) naming the hearing examiner, the inmate account supervisor and the Commissioner of SCI-Huntingdon as defendants. The District Court dismissed Appellant’s complaint and issued an adverse ruling certifying that an appeal would be frivolous.
Appellant was released on parole, and in April 1990, Appellant returned to SCI-Hun-tingdon as a parole violator and SCI-Hun-tingdon again deducted monies from his inmate account to fulfill Appellant’s unsatisfied 1989 hospital bills. Appellant completed his sentence, but in 1991, Appellant again returned to SCI-Huntingdon to serve a sentence on new criminal convictions. As before, SCI-Huntingdon deducted funds from Appellant’s inmate account to satisfy Appellant’s 1989 hospital bill.
In 1994, Appellant filed another action in the District Court alleging various constitutional violations for SCI-Huntingdon’s actions of deducting money from his inmate account in order to satisfy his June 1989 hospital payments. In January 1995, the District Court found no arguable basis in law in Appellant’s complaint and dismissed it.
In January 1995, Appellant filed the present action in the common pleas court, once again challenging SCI-Huntingdon’s deduction of funds from his inmate account in order to fulfill his June 1989 hospital payments. The common pleas court granted Appellant in forma •pauperis status but sua sponte dismissed Appellant’s complaint as frivolous, time-barred, and repetitious (res judicata).
On appeal before this Court,1 Appellant argues that the common pleas court erred in dismissing his complaint as SCI-Huntingdon’s actions of withdrawing funds from Appellant’s prisoner account constitutes a continuing violation of Appellant’s due process and equal protection rights. Even though Appellant’s argument may be flawed, we hold that the common pleas court erroneously dismissed Appellant’s complaint.
The Commonwealth asserts that Pa. R.C.P. No. 240(j) applies to this case and that the common pleas court correctly invoked it to properly dismiss this action. We disagree. First, the common pleas court decision contains no assertion or implication that the Appellant’s complaint was dismissed pursuant to Rule 240(j) and second, even if the common pleas court had specifically invoked Rule 240(j), it would have done so in error.
Pa.R.C.P. No. 240(j)2 states:
If, simultaneous with the commencement of an action or proceeding or the taking of an appeal, a party has filed a petition for leave to proceed in forma pauperis, the court prior to acting upon the petition may dismiss the action, proceeding or appeal if the allegation of poverty is untrue or if it is satisfied that the action, proceeding or appeal is frivolous. (Emphasis added.)
In this case, the common pleas court granted Appellant in forma pauperis status and then dismissed the action. In doing so, the common pleas court lost its opportunity to dismiss a case due to frivolousness under Rule 240(3) as it dismissed the action after granting Appellant’s in forma pauperis status. Rule 240(j) specifically states that a court may dismiss an action for frivolousness if the court does so “prior to acting upon the petition.” As the common pleas court acted upon Appellant’s in forma pauperis petition and then dismissed the action, Rule 240(j) does not apply to this case.3
*45The common pleas court also dismissed Appellant’s complaint because it was time-barred and repetitious (res judicata). However, both statute of limitations and res judicata are affirmative defenses and as such are waived if not raised in a responsive pleading under the heading “New Matter.” Pa.R.C.P. Nos. 1030 and 1032.4
As the common pleas court dismissed the action before the Commonwealth filed an answer, it is unclear whether the Commonwealth would have asserted these defenses in the new matter section or would have waived the right to do so.5 As such, the common pleas court acted prematurely in dismissing this case. The procedure is to allow the parties to pursue the litigation in accordance with the Pennsylvania Rules of Civil Procedure and not to promote undue and improper judicial intervention.6
We hold that the common pleas court in this case committed a manifest abuse of discretion by sun sponte dismissing Appellant’s complaint. We order that the common pleas court reinstate this case and that the Commonwealth file either preliminary objections and/or an answer. Further, for purposes of allowing the Commonwealth the proper time to file either preliminary objections or an answer, we order that the date the common pleas court reinstates this case, is the date that the time limit to file responsive pleadings will begin to run.
Accordingly, we vacate and remand this case to the common pleas court to act consistent with this opinion.
ORDER
AND NOW, this 2nd day of November, 1995, the order of the Court of Common Pleas of Huntingdon County in the above-captioned matter is hereby vacated and the case is remanded to the common pleas court to act consistent with the aforementioned opinion.
Jurisdiction relinquished.
.Oar scope of review of a trial court's decision is limited to determining whether constitutional rights have been violated, or whether the trial court abused its discretion or committed an error of law. Mann v. City of Philadelphia, 128 Pa.Cmwlth. 499, 563 A.2d 1284 (1989), appeal denied, 525 Pa. 622, 577 A.2d 892 (1990).
. This rule was amended, effective January 1, 1992, with the addition of Pa.R.C.P. No. 240(j).
. We must note that the brief common pleas court decision does not explain why it found Appellant’s complaint frivolous, but rather, simply labeled it as such. In order for this Court to *45properly review trial court decisions, the opinion should contain an explanation as to why a trial court ruled in the way it did.
. See also Sewickley Valley Hospital v. Commonwealth, Department of Public Welfare, 121 Pa.Cmwlth. 337, 550 A.2d 1351 (1988), appeal denied, 524 Pa. 614, 569 A.2d 1372 (1989).
. As it would be improper for the Commonwealth to raise both res judicata and statute of limitations issues in preliminary objections, the only option remaining would be to raise these two affirmative defenses in the New Matter. Pa. R.C.P. No. 1028. See also Button v. Button, 378 Pa.Superior Ct. 142, 548 A.2d 316 (1988).
.However, an objection to lack of subject matter jurisdiction can never be waived and may be raised at any stage of the proceedings by the parties or, sua sponte by a court. Commonwealth v. Pikur Enterprises, Inc., 142 Pa.Cmwlth. 114, 596 A.2d 1253 (1991).