WIthout having an ABAP system at hand to test this, but I guess, this has a lot to do with how ABAP deals with strings and spaces at the end of a string.
Trailing Blanks in Character String Processing
In ABAP a ' ' (1 space) and a '' (no space) both lead to an empty space of length 0.
That's different in SQL and SQLPlus, which I'd say is the reason for the difference you described here.
One option to deal with this could be to check for the length of your string at the beginning of the AMDP and set it to 1 space only in the procedure.