Here's the best explanation I found relating to why your T4 box 39 might not have an amount filled in, even when box 38 has one: Department of Finance – Explanatory Notes Relating to the Income Tax Act [...]. It's a long document, but here's the part I believe relevant, with my emphasis:
Employee Stock Options
Paragraph 110(1)(d) is amended to include a requirement that the
employee [...] exercise the employee’s rights under the stock
option agreement and acquire the securities underlying the agreement
in order for the deduction in computing taxable income to be
available [...] ensures that
only one deduction is available in respect of an employment benefit.
In other words, if employee stock option rights are surrendered to an
employer for cash or an in-kind payment, then (subject to new
subsections 110(1.1) and (1.2)) the employer may deduct the payment
but the employee cannot claim the stock option deduction. Conversely,
where an employer issues securities pursuant to an employee’s exercise
of stock options, the employer can not deduct an amount in respect of
the issuance, but the employee may be eligible to claim a deduction
under paragraph 110(1)(d).
Did you receive real shares based on your participation in the ESPP, or did you get a cash payment for the net value of shares you would have been issued under the plan? From what I can tell, if you opted for a cash payment (or if your plan only allows for such), then the part I emphasized comes into play.
Essentially, if conditions were such that your employer could claim a deduction on their corporate income tax return for the compensation paid to you as part of the plan, then you are not also able to claim a similar deduction on your personal income tax return. The money received in that manner is effectively taxed in your hands the same as any bonus employment income would be; i.e. it isn't afforded tax treatment equivalent to capital gains income.
Your employer and/or ESPP administrator are best able to confirm the conditions which led to no amount in your box 39, but at least based on above you can see there are legitimate cases where box 38 would have an amount while box 39 doesn't.