|
 |
|
|
| |
|
Fujitsu [
return
] |
|
From |
Message |
seastm
8/26/2005 19:05:30
|
Subject: Removing blank spaces
Message: I am new to Cobol and I need help with removing spaces.
if I have a field that contains data that is formatted like this: ^^^###^^^^##^###C
how would I get the contents to look this way:
########C
|
dmpmap0307
8/26/2005 20:37:31
| RE: Removing blank spaces
Message: Assuming I interpreted your question correctly, I submit the following which has worked for me in the past:
INPUT FIELD DEFINITION:
05 FIELD-GROUP-IN.
10 FILLER PIC XX.
10 DATA-1ST-IN PIC XXX.
10 FILLER PIC XXX.
10 DATA-2ND-IN PIC XX.
10 FILLER PIC X.
10 DATA-3RD-IN PIC XXX.
OUTPUT FIELD DEFINITION:
05 FIELD-GROUP-OUT.
10 DATA-1ST-OUT PIC XXX.
10 DATA-2ND-OUT PIC XX.
10 DATA-3RD-OUT PIC XXX.
PROCEDURE DIVISION MOVES:
MOVE DATA-1ST-IN TO DATA-1ST-OUT
MOVE DATA-2ND-IN TO DATA-2ND-OUT
MOVE DATA-3RD-IN TO DATA-3RD-OUT.
Your data should now be converted to new format.
Hopefully your question is answered. Please let me know if I can be of more assistance.
David
|
donfnelson
8/27/2005 15:44:55
| RE: Removing blank spaces
Message: He probably means that the input has variable numbers of
blanks. Something like this might work (this dumb system
eliminates leading spaces so the indentation goes away):
01 Input-field PIC X(20).
01 Output-field PIC X(20).
01 In-pointer PIC 99 COMP.
01 Out-pointer PIC 99 COMP.
...
MOVE SPACES TO Output-field
MOVE 1 TO Out-pointer
PERFORM VARYING In-pointer FROM 1 BY 1
UNTIL In-pointer > 20
IF Input-field (In-pointer: 1) NOT = SPACE
MOVE Input-field (In-pointer: 1) TO
OUTPUT-field (Out-pointer: 1)
ADD 1 TO Out-pointer
END-IF
ADD 1 TO In-pointer
END-PERFORM
|
screenio
8/27/2005 16:14:38
| RE: Removing blank spaces
Message: While the solution dmpmap0307 posted would work, it presumes that the problem was as trivial as the single example posted, which seems unlikely, as the solution would have been obvious.
I suspect that the question being asked was more generic and the actual layout of the text with embedded spaces was variable in nature.
In this case, there are two basic approaches that come to mind.
First:
A loop proceedure which scans each byte in the field, and if it finds a NON space, moves that character to an output array, and then incriments the pointer to the output array.
At first this seems rather brute force, but upon inspection you will find its usually faster and more efficient than other solutions.
Note that if you have many such fields to fix, you may want to write a subroutine which is called
with three fields, 1) the source field, 2) the length of the source field, and 3) the target field. Upon return, pass back the target field length, and use reference modification to extract the data" MOVE TARGET-FIELD (1:FIELD-LENGTH) TO ...
Second, there are elaborate schemes using STRING or STRING, such as:
UNSTRING source-field DELIMITED ALL SPACE INTO
TARGET (1) TARGET(2) ...
STRING TARGET(1) TARGET (2) ... DELIMITED SIZE INTO ....
You will note that there are all sorts of conditions you must handle separately such as leading spaces, varying number of non-space groups, etc.
And upon getting that all completed you will find it much more complex and less efficient than a "brute force" byte scan.
|
| |
| P 1 Next Page >> | | | |
|
|
|
[ Go to Top of Page ]
|
|
 |
|
COBOL Forums |
Do you need COBOL help?
Let the COBUG members help you.
Post your issues!
|
 |
|
New Local User Group |
Welcome! COBOL User Group - Trivandrum (CUGTVM), India
|
 |
|
COBOL Jobs |
Here are references to a wealth of
COBOL job resources.
|
 |
|
Job and Resume Matchmaker! |
Employers submit your COBOL job openings.
Job seekers submit your resumes.
|
 |
|