COBOL, unlike C or similar languages, requires variables to be fixed in length (except for OCCURS DEPENDING ON in LINKAGE SECTION or in an 01 under an FD). If you define a variable as PIC X(10) and it is in WORKING-STORAGE, it will contain 10 characters -- always. They may be spaces, or LOW-VALUES, or HIGH-VALUES, or printing characters, or non-printing characters -- but there will always be 10 characters in the variable. Accordingly, when you say
I can have spaces at the last and I don't want them.
what do you want them to be if not spaces? They will exist, they will be characters, and they cannot be removed -- period. This is the way COBOL is.