Page 1 of 1

INSPECTing a string in COBOL & updating the string

Posted: Wed Apr 03, 2013 11:03 pm
by goldyroshan
I need to check if an alphanumeric field (say Seq No) of length = 8 has any SPACES in it.

e.g.
need to check if Seq No has any spaes [Seq No = 0001234b, where b = blank space],
If a blank space is found in the string, I need the final value as 00001234

Please provide the code snippet for the same.

Posted: Wed Apr 03, 2013 11:50 pm
by NicC
Why should you do it? The process providing the data should ensure it is correct. If it is not then send it back until it is correct. If it is a changed requirement then pass the change along to those who need to participate. Do not fix what should have been correct in the first place (or remember to charge a hefty fee for putting a band-aid on someone else's problem).

Posted: Thu Apr 04, 2013 1:50 am
by goldyroshan
NicC wrote:Why should you do it? The process providing the data should ensure it is correct. If it is not then send it back until it is correct. If it is a changed requirement then pass the change along to those who need to participate. Do not fix what should have been correct in the first place (or remember to charge a hefty fee for putting a band-aid on someone else's problem).
I know, you are right actually. But due to this few of the downstream jobs & few database tables are gettng impacted, so something has to be done to replace this blank space with something.
As of now, I have been asked to replace the entire field (Seq No) with 99999999 whenever this field is not NUMERIC (i.e. whenever it has this blank space), so that atleast the downstream system will know that this was the point were break/fix was applied.

Posted: Thu Apr 04, 2013 2:52 am
by William Collins

Code: Select all

01  a-nice-name.
     05 filler pic x(7).
     05 filler pic x.
        88  sequence-number-has-trailing-blank value space.

01  a-nice-name-for-this.
    05  filler pic x value zero.
    05  a-nice-receiving-name pic x(7).

if sequence-number-has-trailing-blank
    move a-nice-name to a-nice-receiving-name
    move a-nice-name-for-this to a-nice-name
end-if

Posted: Fri Apr 05, 2013 2:18 am
by DikDude
Will the blank only be present in the last character?

Your request mentions that you are interested in ANY blank, but your examnple only shows a blank in the last position.

What if the value should have been 00012345 but is actually 0001234b? I suspect the all 9's would be less likely to cause confusion/problems.

Posted: Mon Apr 08, 2013 10:01 pm
by goldyroshan
Thanks William for the code.

@DikDude - I agree that the problem description is kindof confusing but as of now we have found another workaround for this. Now we won't be checking for blank space at any particular byte, instead if the field is not NUMERIC, will replace the entire field with '99999999' - that will be easier to track in downstream systems.
Thanks to both of u for ur time! Appreciate it.

Posted: Mon Apr 08, 2013 11:12 pm
by DikDude
You're welcome. I believe the all 9's is the better choice :)