HI All,
Is there any COBOL built-in function to trim spaces at the starting and ending of a variable.. please let me know.
COBOL built-in function to trim spaces.
- Robert Sample
- Global Moderator
- Posts: 1900
- Joined: Fri Jun 28, 2013 1:22 am
- Location: Dubuque Iowa
Re: COBOL built-in function to trim spaces.
This question is one that you can answer for yourself by simply consulting the Enterprise COBOL Language Reference manual -- it has a section on intrinsic functions that discusses each of them in detail. Please learn to read the manuals before posting questions on this -- or any -- forum.
And the answer to your question is no, COBOL has no function to trim spaces. This is because COBOL does not have strings like languages such as C or Java. COBOL has variables. Variables are (almost always) fixed length and if there are not enough characters provided for the length of the variable, COBOL automatically fills the rest of the variable with spaces. So a trim function would be useless for COBOL since if trailing spaces were removed, they would be added right back to ensure the variable is the correct length. And since COBOL has a JUSTIFIED RIGHT clause, those spaces could be on the front or back of the variable.
The only COBOL variables that are not fixed length are variables in the LINKAGE SECTION or FILE SECTION that are defined with OCCURS DEPENDING ON. Variables defined in WORKING-STORAGE with OCCURS DEPENDING ON are defined at their maximum length so they can have trailing spaces as well.
And the answer to your question is no, COBOL has no function to trim spaces. This is because COBOL does not have strings like languages such as C or Java. COBOL has variables. Variables are (almost always) fixed length and if there are not enough characters provided for the length of the variable, COBOL automatically fills the rest of the variable with spaces. So a trim function would be useless for COBOL since if trailing spaces were removed, they would be added right back to ensure the variable is the correct length. And since COBOL has a JUSTIFIED RIGHT clause, those spaces could be on the front or back of the variable.
The only COBOL variables that are not fixed length are variables in the LINKAGE SECTION or FILE SECTION that are defined with OCCURS DEPENDING ON. Variables defined in WORKING-STORAGE with OCCURS DEPENDING ON are defined at their maximum length so they can have trailing spaces as well.
Re: COBOL built-in function to trim spaces.
Thanks for the detailed explanation. I did search for this in the manual but was not sure if I have missed something in that search. Wanted to make sure that I have not missed something.Robert Sample wrote: ↑Fri Sep 28, 2018 3:55 pmAnd the answer to your question is no, COBOL has no function to trim spaces. This is because COBOL does not have strings like languages such as C or Java. COBOL has variables. Variables are (almost always) fixed length and if there are not enough characters provided for the length of the variable, COBOL automatically fills the rest of the variable with spaces. So a trim function would be useless for COBOL since if trailing spaces were removed, they would be added right back to ensure the variable is the correct length. And since COBOL has a JUSTIFIED RIGHT clause, those spaces could be on the front or back of the variable.
The only COBOL variables that are not fixed length are variables in the LINKAGE SECTION or FILE SECTION that are defined with OCCURS DEPENDING ON. Variables defined in WORKING-STORAGE with OCCURS DEPENDING ON are defined at their maximum length so they can have trailing spaces as well.
Thanks,
Create an account or sign in to join the discussion
You need to be a member in order to post a reply
Create an account
Not a member? register to join our community
Members can start their own topics & subscribe to topics
It’s free and only takes a minute