Page 1 of 1

Field with embedded spaces.

PostPosted: Tue Jul 09, 2013 4:25 pm
by thecabbb
I have a 5 byte field. Want to eliminate all records which have embedded spaces. The space can be at leading or trailing or anywhere at middle. The file have millions of records.
Please provide an efficient way to achieve this in cobol.

Re: Field with embedded spaces.

PostPosted: Tue Jul 09, 2013 4:31 pm
by Akatsukami
INSPECT the field TALLYING spaces. If the count is greater than zero, do not write the record.

Re: Field with embedded spaces.

PostPosted: Tue Jul 09, 2013 5:25 pm
by NicC
An alternative would be to drop the unwanted records before your program even starts by running the data through your sort product.

Re: Field with embedded spaces.

PostPosted: Tue Jul 09, 2013 5:40 pm
by c62ap90
Reference Modification would work.

IF  field (1:1) = SPACE
OR  field (2:1) = SPACE
OR  field (3:1) = SPACE
OR  field (4:1) = SPACE
OR  field (5:1) = SPACE
    <bypass logic>
END-IF

Re: Field with embedded spaces.

PostPosted: Tue Jul 09, 2013 11:26 pm
by BillyBoyo
Just sub-defining the field will also do it.

01  a-nice-name.
    05  FILLER PIC X.
        88  a-nice-name-byte-1-blank-ign value space. 
    05  FILLER PIC X.
        88  a-nice-name-byte-2-blank-ign value space. 
    05  FILLER PIC X.
        88  a-nice-name-byte-3-blank-ign value space. 
    05  FILLER PIC X.
        88  a-nice-name-byte-4-blank-ign value space. 
    05  FILLER PIC X.
        88  a-nice-name-byte-5-blank-ign value space. 


If this is all your program is doing, or the data is already going through a SORT somewhere handy, then SORT will be a good solution.

  OMIT COND=(1,5,SS,EQ,C' ')


Re: Field with embedded spaces.

PostPosted: Tue Jul 09, 2013 11:52 pm
by c62ap90
Darn, the
OMIT COND=(1,5,CH,SS,C' ')
did not work for me.

...+....10...+....20...+....30...+....40...+....50...+....60...+....70...+....80...+....
SYNCSORT FOR Z/OS  1.4.0.1R    U.S. PATENTS: 4210961, 5117495   (C) 2010 SYNCSORT INC. 
                                                      z/OS   1.13.0                     
SYNCSORT LICENSED FOR CPU SERIAL NUMBER 671A7, MODEL 2827 707             LICENSE/PRODUC
SYSIN :                                                                                 
    SORT FIELDS=(1,5,CH,A)                                                             
    OMIT COND=(1,5,CH,SS,C' ')                                                         
                      *                                                                 
WER251A  INCLUDE/OMIT INVALID COND                                                     
WER211B  SYNCSMF  CALLED BY SYNCSORT; RC=0000                                           
WER449I  SYNCSORT GLOBAL DSM SUBSYSTEM ACTIVE                                           
************************************************************ End of Data ***************

Re: Field with embedded spaces.

PostPosted: Wed Jul 10, 2013 12:23 am
by BillyBoyo
Thanks c62ap90, that's cos I bloopered it. I'll update the original as well to avoid the confusion.

Should be:
  OPTION COPY
  OMIT COND=(1,5,SS,EQ,C' ') 
                                             
//SORTIN   DD *
12345
1 345
123 5
1234
12  5
 2345


Output is:



The SS is a "field type". Here it will find one (or more) blanks in positions 1,5.

Another use of SS is to test the same field for multiple values, which can simplify things by removing an OR or two.

  OPTION COPY
  OMIT COND=(1,5,SS,EQ,C'12345,1 345, 2345')
                                             
//SORTIN   DD *
12345
1 345
123 5
1234
12  5
 2345


Output is:

123 5 
1234   
12  5 

Re: Field with embedded spaces.

PostPosted: Wed Jul 10, 2013 4:36 pm
by c62ap90
Thanks for the correction BillyBoyo. Tested well now.