Thank you Rouzbeh and Andreas for help!
Rouzbeh, thanks to your pointer, I have done everything with library locations, to the best of my knowledge.
Andreas sent me the working component, with my own code and I compared the XML files (the working component and my non-working one) next to each other.
The difference is the following:
Somewhere in the XML file of the working component, there is a place:
<Attributes masterSet="NONE" size="2" >
in my not-working components it is set to
<Attributes masterSet="ALL" size="2" >
When I edit my component to be similar to yours, in that respect, it works.
Why would that make the difference and how to get SAP PA to do this automatically?