Inside the Macy's I.N.C. shop at Herald Square.

J.C. Penney Co. Inc.’s getting some turnaround credit from debt rating agency Standard & Poor’s.

Last week, S&P upgraded Penney’s credit rating to B from CCC-plus with a positive outlook. S&P credit analyst Bob Schultz described the retailer as being in its post-Ron Johnson turnaround, referring to the former chief executive officer’s unsuccessful attempt to remake the chain, which resulted in steep sales declines and big losses.

“We based the upgrade on our view that JCP’s turnaround efforts are sustainable in the challenging U.S. department store environment and have positioned the company to support its current debt burden,” said Schulz.

Penney’s upgrade came as its same-store sales and cash flow improved. In the most recent quarter, same-store sales rose 4.1 percent and gross margin improved 30 basis points, while expenses fell. If any of these performance gains get reversed, S&P could lower the rating again. Even with the upgrade, Schultz stressed that Penney’s still has speculative, or junk, credit score.

The rating for Penney’s could be raised even higher if net sales grow more than 2 percent and gross margins increase about 100 basis points. Positive cash flow would also help position the company to refinance its 2018 maturities and be viewed as favorable towards an upgrade.

While many of Penney’s problems were of its own making, Shultz said competitor Macy’s is struggling with the same challenges all the department stores face.

Macy’s star had been shining brightly and the stock was climbing higher as Penney’s stock slumped over the past few years. Everything seemed to be rolling along until July, when investors started to feel that Macy’s was losing ground. Activist investors went on the attack and suggested the retailer should monetize its real estate and slowing sales caused the stock to slip.

Last month, S&P dropped its crediting rating on Macy’s to BBB from BBB-plus and cited soft holiday sales for the negative outlook. Macy’s has also lost market share to online competition and off-price retailers. S&P doesn’t think Macy’s can overcome the various headwinds facing department store this year. Shultz said, “Macy’s is wrestling with shifting consumer preferences.” Meaning the migration to online shopping and lowered demand for physical stores.

Macy’s could get a revision to a stable outlook if sales grow by 5 percent and margins expand by 100 basis points and debt remains consistent. Any strategic initiatives like real estate transactions could lower its debt levels. Shultz though said that a revision during the next year was unlikely.