Let $X$ be an $\mathbb{R}^d$-valued special semimartingale on a probability space $(\Omega, \mathscr{F}, (\mathscr{F}_t)_{0\leq t \leq T},P)$ with decomposition $X = X_0 + M + A$ and $\Theta$ the space of all predictable, $X$-integrable processes $\theta$ such that $\int\theta dX$ is in the space $\mathscr{J}^2$ of semimartingales. If $H$ is a random variable in $\mathscr{L}^2$, we prove, under additional assumptions on the process $X$, that $H$ can be written as the sum of an $\mathscr{F}_0$-measurable random variable $H_0$, a stochastic integral of $X$ and a martingale part orthogonal to $M$. Moreover, this decomposition is unique and the function mapping $H$ with its decomposition is continuous with respect to the $\mathscr{L}^2$-norm. Finally, we deduce from this continuity that the subspace of $\mathscr{L}^2$ generated by $\int\theta dX$, where $\theta\in \Theta$, is closed in $\mathscr{L}^2$, and we give some applications of this result to financial mathematics.