View previous topic :: View next topic |
Author |
Message |
Sarangadhar Beginner
Joined: 14 Oct 2004 Posts: 130 Topics: 43 Location: virtual village
|
Posted: Wed Sep 05, 2007 2:03 pm Post subject: TRIM in COBOL |
|
|
I need a DB2 TRIM equivalent of COBOl.
Below is the value in question:
I would like to trim the leading and trailing spaces which results into
Is there a simple way of doing this in COBOL? _________________ Thanks |
|
Back to top |
|
 |
CICS Guy Intermediate
Joined: 30 Apr 2007 Posts: 292 Topics: 3
|
Posted: Wed Sep 05, 2007 2:30 pm Post subject: |
|
|
Is it just one space in front and one in back? Or an unknown number at either end?
Where do you want to put this value, into an area that pads trailing spaces?
Into a small array with an ODO value that gives the correct shortened length? |
|
Back to top |
|
 |
Sarangadhar Beginner
Joined: 14 Oct 2004 Posts: 130 Topics: 43 Location: virtual village
|
Posted: Wed Sep 05, 2007 3:33 pm Post subject: |
|
|
spaces at front and at back are known.
I dont want to pad any spaces. I would like to move it to a numeric value to perform numeric check. As numeric check fails what the spaces are padded, I would like to move it to numeric variable and perform numeric on it.
Requirement:
we will receive numeric item thru a alphanumeric field. there may be trailing and leading spaces around it. I would like to remove those, but i dont want to remove embedded spaces. _________________ Thanks |
|
Back to top |
|
 |
CICS Guy Intermediate
Joined: 30 Apr 2007 Posts: 292 Topics: 3
|
Posted: Wed Sep 05, 2007 3:49 pm Post subject: |
|
|
Arg!
If you have the Enterprise COBOL, just us the intrinsic function NUMVAL......
Oh, oops, no, you have a "numeric item" with "embedded spaces"...BUZZ, wrong answer, imbedded spaces are not "numeric"....
Your requirement needs to be more fully expanded upon..... Just try just explaining what your needs are and let the extensive available talent help provide a potential solution? |
|
Back to top |
|
 |
Sarangadhar Beginner
Joined: 14 Oct 2004 Posts: 130 Topics: 43 Location: virtual village
|
Posted: Wed Sep 05, 2007 4:01 pm Post subject: |
|
|
Okay, lemmi me write ny requirement here:
I'll receive amount value thru a character field.
if the input field is defined as PIC X(10) and the value comming thru input is 1234, then remaining 6 places are padded with spaces.
1. I can't perform numeric check as there are spaces padded
2. If I move to a numeric field, no right justification happens.
here is the program:
01 PGM-NAME.
10 VAR1 PIC X(5) VALUE "333".
10 VAR11 PIC X(9) VALUE "33 3 ".
10 VAR5 PIC 9(12).
PROCEDURE DIVISION.
0000-MAIN.
MOVE VAR1 TO VAR5 .
DISPLAY 'VAR5 =' VAR5 .
MOVE VAR11 TO VAR5 .
DISPLAY 'VAR66=' VAR5 .
output
VAR5 =0000000333 0
VAR66=00033 3 0 _________________ Thanks |
|
Back to top |
|
 |
CICS Guy Intermediate
Joined: 30 Apr 2007 Posts: 292 Topics: 3
|
Posted: Wed Sep 05, 2007 4:42 pm Post subject: |
|
|
Sarangadhar wrote: | VAR5 =0000000333 0
VAR66=00033 3 0 | OK....
If you want:
VAR5 =000000000333
VAR66=000000000333
in both cases, look at the intrinsic function NUMVAL..... |
|
Back to top |
|
 |
Sarangadhar Beginner
Joined: 14 Oct 2004 Posts: 130 Topics: 43 Location: virtual village
|
Posted: Wed Sep 05, 2007 5:08 pm Post subject: |
|
|
Hi,
I dont want to remove the spaces in between the value, if any.
in 2nd case - I want the VAR66 to be 00000000033 3.
If source system accidentally inserts a space in between, I want to catch it. _________________ Thanks |
|
Back to top |
|
 |
CICS Guy Intermediate
Joined: 30 Apr 2007 Posts: 292 Topics: 3
|
Posted: Thu Sep 06, 2007 3:04 am Post subject: |
|
|
Sarangadhar wrote: | in 2nd case - I want the VAR66 to be 00000000033 3.
| Does not make sense, to move that to a 9(12) field is garbage....
What does the embedded blank represent? |
|
Back to top |
|
 |
sriramla Beginner
Joined: 22 Feb 2003 Posts: 74 Topics: 1
|
Posted: Thu Sep 06, 2007 10:48 am Post subject: |
|
|
You may want to do this:
1. Use INSPECT command with TALLYING FOR LEADING / TRAILING SPACES option to get the starting and ending positions of your actual input. For example if your input is coming as X(10) with 2 leading spaces, 3 trailing spaces then use the above INSPECT command to identify the positions 3 to 7 as your 'actual' data to be processed.
2. Next ,use the INSPECT again for X(3:7) to identify are there any spaces. If yes, then your data is not good. Perform appropriate error handling.
Note that I've considered only numbers and spaces in the input. If there are alphabets or multiple decimal points etc then you need special logic to handle them. |
|
Back to top |
|
 |
Sarangadhar Beginner
Joined: 14 Oct 2004 Posts: 130 Topics: 43 Location: virtual village
|
Posted: Thu Sep 06, 2007 6:26 pm Post subject: |
|
|
Sriramla,
INSPECT doesn't have TRAILING SPACES.
CICS Guy,
I dont want to remvoe the spaces that are embedded in between the value. Wanted to remove only trailing spaces. _________________ Thanks |
|
Back to top |
|
 |
CICS Guy Intermediate
Joined: 30 Apr 2007 Posts: 292 Topics: 3
|
Posted: Thu Sep 06, 2007 6:32 pm Post subject: |
|
|
Sarangadhar wrote: | I dont want to remvoe the spaces that are embedded in between the value. Wanted to remove only trailing spaces. | OK, only trailing spaces? Sarangadhar wrote: | I would like to trim the leading and trailing spaces | It can be done, but YOU have to make YOUR requirements understandable... |
|
Back to top |
|
 |
Sarangadhar Beginner
Joined: 14 Oct 2004 Posts: 130 Topics: 43 Location: virtual village
|
Posted: Thu Sep 06, 2007 6:53 pm Post subject: |
|
|
sorry for the change...
in fact, leading spaces can be removed. but i am okay if not. But i surely need to remove the trailing spaces.
if you have both the processes, please let me know. For now, I am in the need of removing the trailing spaces. _________________ Thanks |
|
Back to top |
|
 |
sriramla Beginner
Joined: 22 Feb 2003 Posts: 74 Topics: 1
|
Posted: Fri Sep 07, 2007 10:00 am Post subject: |
|
|
For trailing spaces, use FUNCTION REVERSE with INSPECT LEADING. |
|
Back to top |
|
 |
Sarangadhar Beginner
Joined: 14 Oct 2004 Posts: 130 Topics: 43 Location: virtual village
|
Posted: Fri Sep 07, 2007 11:12 am Post subject: |
|
|
many Thanks Sriramla..
it worked.. excellent.. _________________ Thanks |
|
Back to top |
|
 |
|
|