Code Comments
Programming Forum and web based access to our favorite programming groups.Hello, I'm looking for a solution to validate datas : Suppose you got first-name and want to display error message when you encounter two spaces (and some other characters). For exemple 'MIKE DANIEL ' is good (because there is only one space between Mike and Daniel) but 'MIKE DANIEL ' is not. The problem is trailing spaces. I have tried this : inspect ws-firstname tallying ws-mytally for characters before ' ' but it doesn't works : first-name never validates because of trailing spaces. Anybody has a solution ? Thanks, EB Grenoble France
Post Follow-up to this message"EBille" <billard.eric@free.fr> wrote in message news:1129553966.407455.254520@f14g2000cwb.googlegroups.com > Hello, > I'm looking for a solution to validate datas : > Suppose you got first-name and want to display error message when you > encounter two spaces (and some other characters). > For exemple 'MIKE DANIEL ' is good (because there is only one space > between Mike and Daniel) but 'MIKE DANIEL ' is not. The problem is > trailing spaces. I have tried this : > inspect ws-firstname tallying ws-mytally for characters before ' ' > but it doesn't works : first-name never validates because of trailing > spaces. Anybody has a solution ? I am not the world's greatest COBOL programmer, but I've recently had to solve a similar problem. I used COBOL reference modification and started at the back of the data, reading forward until I found the first non-blank character and then using a loop to the beginning of the field to check for two adjacent spaces. If you can't figure it out, post back. I need to dash off now and don't have time to look for the code, but I'll check back this afternoon and post some code if you need it. -- Mike B
Post Follow-up to this messageOn 17 Oct 2005 05:59:26 -0700, "EBille" <billard.eric@free.fr> wrote: >I'm looking for a solution to validate datas : "datas"? >Suppose you got first-name and want to display error message when you >encounter two spaces (and some other characters). >For exemple 'MIKE DANIEL ' is good (because there is only one space >between Mike and Daniel) but 'MIKE DANIEL ' is not. The problem is >trailing spaces. I have tried this : >inspect ws-firstname tallying ws-mytally for characters before ' ' >but it doesn't works : first-name never validates because of trailing >spaces. Anybody has a solution ? There are several solutions for this, but my favorite is using reference modification loops here.
Post Follow-up to this messageTry this... Move "MIKE DANIEL " to ws-name Unstring ws-name delimited by all spaces INTO First-name Last-name -Murali Mike B wrote: > "EBille" <billard.eric@free.fr> wrote in message > news:1129553966.407455.254520@f14g2000cwb.googlegroups.com > > I am not the world's greatest COBOL programmer, but I've recently had to > solve a similar problem. I used COBOL reference modification and started a t > the back of the data, reading forward until I found the first non-blank > character and then using a loop to the beginning of the field to check for > two adjacent spaces. > > If you can't figure it out, post back. I need to dash off now and don't ha ve > time to look for the code, but I'll check back this afternoon and post som e > code if you need it. > > -- > Mike B
Post Follow-up to this message"EBille" <billard.eric@free.fr> wrote: > Suppose you got first-name and want to display error message when you > encounter two spaces (and some other characters). > For exemple 'MIKE DANIEL ' is good (because there is only one space > between Mike and Daniel) but 'MIKE DANIEL ' is not. The problem is > trailing spaces. I have tried this : > inspect ws-firstname tallying ws-mytally for characters before ' ' > but it doesn't works : first-name never validates because of trailing > spaces. Anybody has a solution ? It's a little more complete than your example, but you can download file NAME.ZIP from my website below under "COBOL Source Files." It was programmed to work using COBOL 74, COBOL 85 or COBOL 2002. -- Judson McClendon judmc@sunvaley0.com (remove zero) Sun Valley Systems http://sunvaley.com "For God so loved the world that He gave His only begotten Son, that whoever believes in Him should not perish but have everlasting life."
Post Follow-up to this messageMike wrote: > howard.brazee@cusys.edu wrote: > > > > You should forgive him, he is French. Data has a plural in French. ;) > > Data *is* plural in english. The singular is datum. Donald ;< )
Post Follow-up to this messageOn 17 Oct 2005 08:23:49 -0700, "Mike" <MPBrede@gmail.com> wrote: > >You should forgive him, he is French. Data has a plural in French. ;) Interesting. We use the Latin in English, where data *is* the plural of datum. While I knew that the French fight the inclusion of foreign words and grammar, but didn't know it went back that far. I suspect it was a retro-fit. Having a consistent grammar is attractive to programmers such as myself. But we're well in the process of forgetting that "data" is plural - people in data processing rarely use the word "datum" and often say "my data indicates that..." But even worse, people in the media rarely use the word "medium". I like the optional plural for "schema" of "schemata". As in "I modified some subschemata in our database".
Post Follow-up to this messageAdding comment inline with CJP prefix.... On Mon, 17 Oct 2005 08:23:49 -0700, Mike wrote: > > Here is a sample I wrote. Serves two purposes. Solves your problem and > I can also get some feedback on my way of writing COBOL. Be kind, > gentle reader. :-) > IDENTIFICATION DIVISION. > PROGRAM-ID. NameTest. > ENVIRONMENT DIVISION. > DATA DIVISION. > WORKING-STORAGE SECTION. > 01 GoodName pic x(20) value 'Daniel Miller'. > 01 BadName pic x(20) value 'Daniel Miller'. > 01 Ptr pic 9(02) value zero. > 01 Ptr2 pic 9(02) value zero. > 01 EndLoopFlag Pic x(01) value '0'. > 88 EndLoop value '1'. > 88 RunLoop value '0'. > 01 DblSpace pic xx value ' '. CJP - Not sure what compiler you use and how it processes in this light....but on MVS, each 01 level starts on a doubleword boundary (8 byte boundary). So your Working storage would take up 24+24+8+8+8+2 = 74 bytes vs. 20+20+2+2+1+2 = 47 bytes Also make sure your pointers are in a format that does not need to be changed in order for the compiler to use them efficiently. On MVS, PIC 9(2) would need to be converted from character to binary, manipulated, then converted back to put it back into the variable. Not horrible items given the program's purpose, but food for thought when writing your programs. Always write with efficiency of the runtime in mind. > PROCEDURE DIVISION. > > If BadName not = space > Perform varying ptr from length of BadName > by -1 > Until EndLoop > if Badname(ptr:1) = space > Continue > else > Set EndLoop to true > End-If > End-perform > CJP I'd write this: CJP Perform varying ptr from length of BadName CJP by -1 CJP Until ptr < 1 CJP or Badname (ptr:1) not = space CJP Continue CJP End-perform CJP You are doing the comparison already in the IF statement so you lose nothing putting it in the PERFORM, but you gain the loss of the ELSE and manipulation of the flag which in THIS case is not really necessary (but handy sometimes). > Set runloop to true > Perform varying ptr2 from ptr > by -1 > Until EndLoop > If BadName(ptr2:2) = DblSpace > Display "Name is rotten at " ptr2 > set EndLoop to True > Else > if ptr2 = 0 > Set EndLoop to true > End-if > End-if > End-perform CJP When ptr2 makes it to 0, the refmod will be attempted first.... CJP Try... CJP Perform varying ptr2 from ptr CJP by -1 CJP Until ptr2 < 1 CJP or BadName(ptr2:2) = Spaces CJP continue CJP End-perform CJP CJP if ptr2 > 0 CJP Display "Name is rotten at " ptr2 CJP End-if CJP CJP Note also, that DblSpace is not necessary in this example as the SPACES word can be use to the same effect. Again a space issue. > End-if > > Display 'End of Run' > Stop Run. CJP: I also like to make flag settings in code rather than rely on VALUE clauses for the initial setting. Again on MVS, you can be set to reuse the working storage so COBOL does not have to reallocate it every time. It is also better documentation as to what is happening in the program if you set data items in the run. Otherwise you need to go back to W-S to figure out what you're initialized to. In a large program, that can be a lot of scrolling to find it out. It is also safer if you have a runtime environment that may reuse the W-S as-is without re-initializing it. Initialize it yourself. I usually only use VALUE clauses for items that I know will not change in the code.
Post Follow-up to this message>> If BadName not = space CJP I'd write this: CJP Perform varying ptr from length of BadName CJP by -1 CJP Until ptr < 1 CJP or Badname (ptr:1) not = space If efficiency is what you require then the initial 'If badname not = spaces' eliminates the need to check for 'ptr < 1' as there is guaranteed to be a non-space character. If efficiency is what you require then your compiler may do better with an OCCURS and an index rather than reference notation.
Post Follow-up to this message"EBille" <billard.eric@free.fr> wrote in message news:1129553966.407455.254520@f14g2000cwb.googlegroups.com... > Hello, > I'm looking for a solution to validate datas : > Suppose you got first-name and want to display error message when you > encounter two spaces (and some other characters). > For exemple 'MIKE DANIEL ' is good (because there is only one space > between Mike and Daniel) but 'MIKE DANIEL ' is not. The problem is > trailing spaces. I have tried this : > inspect ws-firstname tallying ws-mytally for characters before ' ' > but it doesn't works : first-name never validates because of trailing > spaces. Anybody has a solution ? > Thanks, > EB > Grenoble > France move 1 to ws-mytally inspect ws-firstname tallying ws-mytally for characters before ' ' if ws-firstname (ws-mytally:) not = spaces display 'bad name' end-if
Post Follow-up to this messagePowered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.