The first 5 characters entered will be moved to FOO. If fewer than 5 characters are entered then they will be placed in the left hand positions of FOO and the remaining characters (to the right) will be filled with spaces. If the user enters more than 5 charcters then only the first 5 are moved.
So to use your example if the user typed "yes" then FOO would contain "yesbb"
Best thing to do is try it!
Edit in response to updated question... I think your problem is that the condition needed to terminate the loop is set in the beginning of the loop body and not at the end. Here are a couple of commonly used techniques to solve this problem:
Pre loop read
DISPLAY 'Enter a 5 digit zip code' ACCEPT ZIP PERFORM ZIP-LOOKUP UNTIL ZIP = done. ... ... ZIP-LOOKUP. EXEC SQL SELECT * INTO :ZIP-RECORD FROM ZBANK.ZIPCODE WHERE ZIP = :ZIP END-EXEC. PERFORM PRINT-H1. PERFORM PRINT-L1. * Now get next zip code or 'done' DISPLAY 'Enter a 5 digit zip code' ACCEPT ZIP .
Guard against setting terminating condition within the loop
PERFORM ZIP-LOOKUP UNTIL ZIP = done. ... ... ZIP-LOOKUP. DISPLAY 'Enter a 5 digit zip code' ACCEPT ZIP IF ZIP NOT = DONE EXEC SQL SELECT * INTO :ZIP-RECORD FROM ZBANK.ZIPCODE WHERE ZIP = :ZIP END-EXEC PERFORM PRINT-H1 PERFORM PRINT-L1 END-IF .
Either one of the above should solve your problem. However, I would suggest trying to update your coding style to include COBOL-85 constructs. The first example above might be coded as follows:
DISPLAY 'Enter a 5 digit zip code' ACCEPT ZIP PERFORM UNTIL ZIP = done EXEC SQL SELECT * INTO :ZIP-RECORD FROM ZBANK.ZIPCODE WHERE ZIP = :ZIP END-EXEC PERFORM PRINT-H1 PERFORM PRINT-L1 DISPLAY 'Enter a 5 digit zip code' ACCEPT ZIP END-PERFORM .
The ZIP-LOOKUP paragraph has been in-lined into the PERFORM statement. For short sections of code I find this style much more readable. Also notice single sentence paragraphs (only one period at the end of a paragraph). When COBOL-85 scope terminators are used (eg. END-xxx) the need for mulitple sentences per paragraph goes away - and in fact - they should be avoided.
Another COBOL construct that you could make use of here is the 88 LEVEL
. You could use it as follows:
01 ZIP-RECORD. 02 ZIP PIC X(5). 88 DONE VALUE 'done '. ... ...
You no longer need donevar
at all. Replace your original test:
IF ZIP = DONE
with:
IF DONE
The above will be true whenever the variable ZIP
contains the value "donebb". One advantage of
doing this (other than saving one variable declaration) is that a single 88 LEVEL
name can be assigned
several values, as in:
01 ZIP-RECORD. 02 ZIP PIC X(5). 88 DONE VALUE 'done ', 'quit ', 'stop '.
When the user enters any one of done
, quit
or stop
the 88 level name DONE
evaluates to true.
Finally, I presume this is just a skeleton of the program and that the finished version will be checking for I/O errors, bad SQL codes and do basic ZIP code validation. If not, you can expect a lot of trouble down the road.
COBOL Reference material
Unfortunately there are very few good up to date resources for learning COBOL. However, one of the books I would recommend is Advanced Cobol 3rd Edition by DeWard Brown. This book provides many examples and explanations regarding COBOL program development. It also identifies whether a construct is rarely used, obsolete or essential. This is good to know since you should be developing new code using modern COBOL programming techniques (I continue to see a lot of new COBOL developed using pre-COBOL 85 coding practice - and it is horrible).
An open source guide is the OpenCOBOL Programmers Guide. This targets OpenCOBOL but much of it is applicable to any flavour of COBOL.
Finally, there are several vendors guides and manuals, many of which are available on the internet. For example Enterprise COBOL for z/OS Language Reference and Enterprise COBOL for z/OS Programming guide are freely available. Microfocus COBOL guides are also available. Search any you will find...