This will not work because the subreport is not yet executed when the report header is rendered.
Using the command WhileReadingRecords is not allowed with shared variables.
It will not be possible to write the content of the shared variables to the header. Consider writing it in a section below the subreport.