INSPECTing a string in COBOL & updating the string

This is a Mainframe COBOL forum - you can post your queries on Mainframe COBOL, VS COBOL II, COBOL/370 , Enterprise COBOL

Moderators: dbzTHEdinosauer, Moderator Group

Post Reply
goldyroshan
Active Member
Posts: 67
Joined: Thu Apr 05, 2012 1:29 am
Location: WI, USA

INSPECTing a string in COBOL & updating the string

Post by goldyroshan » Wed Apr 03, 2013 11:03 pm

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.

NicC
Active Member
Posts: 650
Joined: Sun Jul 24, 2011 5:27 pm
Location: Down on the pig farm

Post by NicC » Wed Apr 03, 2013 11:50 pm

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).
Regards
Nic

goldyroshan
Active Member
Posts: 67
Joined: Thu Apr 05, 2012 1:29 am
Location: WI, USA

Post by goldyroshan » Thu Apr 04, 2013 1:50 am

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.
Logically yours,
:-) GRS :-)

William Collins
Active Member
Posts: 732
Joined: Thu May 24, 2012 4:07 am

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

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

DikDude
Moderator
Posts: 1001
Joined: Fri Jul 22, 2011 8:39 am
Location: usa

Post by DikDude » Fri Apr 05, 2013 2:18 am

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.
Have a good one

goldyroshan
Active Member
Posts: 67
Joined: Thu Apr 05, 2012 1:29 am
Location: WI, USA

Post by goldyroshan » Mon Apr 08, 2013 10:01 pm

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.
Logically yours,
:-) GRS :-)

DikDude
Moderator
Posts: 1001
Joined: Fri Jul 22, 2011 8:39 am
Location: usa

Post by DikDude » Mon Apr 08, 2013 11:12 pm

You're welcome. I believe the all 9's is the better choice :)
Have a good one

Post Reply

FREE TUTORIALS

Tutorials
Free tutorials from mainframegurukul
  • JCL Tutorial
    Covers all important JCL concepts.
  • Cobol Tutorial
    This tutorials covers all Cobol Topics from STRING to COMP-3.
  • DB2 Tutorial
    DB2 Tutorial focuses on DB2 COBOL Programming.
  • SORT Tutorial
    This Tutorial covers all important aspects of DFSORT with examples
  • CICS Tutorial
    This CICS tutorial covers CICS concepts and CICS Basics, CICS COBOL Programming.
Interview
Mainframe Interview questions



Other References
Mainframe Tools and others