String Handling

String handling in cobol is very verbose and requires a lot of typing. Let’s try it.

Tallying all or just specific characters is pretty clear. The replacing keyword is also pretty clear, it replaces specified data in the string with some other data. Whats really worth digging into here is the string concatenation and the splitting. In the STRING statement we pass in the original strings WS-STR2WS-STR3WS-STR1 and we use a DELIMITED BY to tell the string statement how to combine them. If we delimit by SIZE we are telling cobol to add the entire input string to the final string. If we delimit by SPACE we are saying to take the input string up to the first space and omit the rest. The INTO keyword tells us the variable (WS-STRING-DEST) where the resulting concatenated string will be stored. WITH POINTER here manages to count the things in the final string. So somehow putting a pointer to the string counts it as things are concatenated in. I think what happens is it sets a pointer to the beginning and as you push things into the final string it pushes the pointer down several locations which are then stored as a count. The ON OVERFLOW tells cobol what to do if the input strings are too large; here it prints/displays ‘OVERFLOW!’

The string docs on mainframetechhelp are very useful for understanding this section.


Comments

Leave a Reply

Your email address will not be published. Required fields are marked *