String Palindrome Program In Cobol
The UNSTRING statement used to separate single string to multiple based on the delimiter provided in the UNSTRING. It needs at least two destination identifier or literals. It can only separate alphabetic and alpha-numeric items. END-STRING, DELIMITED BY, TALLYING, WITH POINTER, ON OVERFLOW and NOT ON OVERFLOW clause is optional in UNSTRING usage.
UNSTRING statement Syntax
Aug 28, 2019 Output: 3 Time complexity: O(n 2) Auxiliary Space: O(n 2) Count All Palindrome Sub-Strings in a String Set 2. This article is contributed by NishantSingh(Pintu).If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. Python Program to Check a Given String is Palindrome or not Example 1 This python program allows the user to enter a string. Next, we used the If statement to check whether the given string is equal to the reverse of that string or not. If it is True, Palindrome string; otherwise, not a palindrome string in Python. The UNSTRING statement used to separate single string to multiple based on the delimiter provided in the UNSTRING. It needs at least two destination identifier or literals. It can only separate alphabetic and alpha-numeric items. END-STRING, DELIMITED BY, TALLYING, WITH POINTER, ON OVERFLOW and NOT ON OVERFLOW clause is optional in UNSTRING usage. Exercise - String 1. Write a program to check if a given string is a Palindrome. A palindrome reads same from front and back e.g.- aba, ccaacc, mom, etc. Write a program to find out the largest and smallest word in the string 'This is an umbrella'.
COUNT IN: COUNT IN clause associated with a particular destination data item. COUNT IN holds the count of no of character passed to the particular destination identifier/data item.
TALLYING:TALLYING clause holds the count of destination strings affected by UNSTRING. TALLYING clause associated with all the destination data items.

Cobol String Replace
UNSTRING Statement Example
In the Data Division, the user has defined the following input record to be acted upon by the UNSTRING statement:
The next two records are defined as receiving fields for the UNSTRING statement. DISPLAY-REC is to be used for printed output. WORK-REC is to be used for further internal processing.
The user has also defined the following fields for use as control fields in the UNSTRING statement.
In the Procedure Division, the user writes the following UNSTRING statement to move subfields of INV-RCD to the subfields of DISPLAY-REC and WORK-REC:
Before the UNSTRING statement is issued, the user places the value 3 in the CHAR-CT (the pointer item), so as not to work with the two control characters at the beginning of INV-RCD. In DBY-1, a period is placed for use as a delimiter, and in FLDS-FILLED (the tallying item) the value 0 is placed. The following data is then read into INV-RCD
When the UNSTRING statement is executed, the following actions take place:
- Positions 3 through 18 (FOUR-PENNY-NAILS) of INV-RCD are placed in
ITEM-NAME, left-justified within the area, and the unused character positions are padded with spaces. The value 16 is placed in CTR-1. - Because ALL SPACES is specified as a delimiter, the five contiguous SPACE characters are considered to be one occurrence of the delimiter.
- Positions 24 through 29 (707890) are placed in INV-NO. The delimiter character / is placed in DLTR-1, and the value 6 is placed in CTR-2.
- Positions 31 through 33 are placed in INV-CLASS. The delimiter is a SPACE, but because no field has been defined as a receiving area for delimiters, SPACE is merely bypassed.
- Positions 35 through 40 (475120) are examined and are placed in M-UNITS.
- The delimiter is a SPACE, but because no receiving field has been defined as a receiving area for delimiters, SPACE is bypassed. The value 6 is placed
in CTR-3. - Positions 42 through 46 (00122) are placed in FIELD-A and right-justified within the area. The leftmost character position is filled with a 0 (zero). The delimiter is a SPACE, but because no field has been defined as a receiving area for delimiters, SPACE is bypassed.
- Positions 48 through 53 (000379) are placed in DISPLAY-DOLS. The period delimiter character is placed in DLTR-2, and the value 6 is placed in CTR-4.
- Because all receiving fields have been acted upon and two characters of data in INV-RCD have not been examined, the ON OVERFLOW exit is taken, and execution of the UNSTRING statement is completed.
At the end of execution of the UNSTRING statement, DISPLAY-REC contains the following data:
CHAR-CT (the pointer field) contains the value 55, and FLD-FILLED (the tallying field) contains the value 6.
COBOL Blog: Click Here IBM Reference:Click Here
STRING AND UNSTRING with examples: TALLYING and COUNT options
String is used to combine two or more strings/variables in to a single string.
Examples:
If you display the ‘name-in’ it shows like ‘ Mahender Reddy G ‘ i.e: it shows the full length of each variable INCLUDING THE SPACES.
So this can be avoided by using the STRING function.

Now NAME-OUT would be ‘mahenderreddyg ‘.
If we want to further modify the output , it can also be done using STRING
Now NAME-OUT would be ‘Mahender Reddy G ‘.
UNSTRING verb is used to unstring/divide the source string into different sub-strings.
If we take the same above example-
NAME-OUT is ‘Mahender Reddy G ‘ and it needs to be divided into first name, last name and initial; it can be done using unstring verb.
Here we have used the delimiter SPACE, but we can use any other delimiter as well.
for ex: if we have a string with name list seperated by commas and we want to exatract each name into an array.
name-in-string is ‘mahender,ramu, robert,phil,Chris’, these can be separated as below
More UNSTRING Examples:
Result:
Example 2:
05 WW-U4-INPUT PIC X(12) VALUE ‘AA BB CC ‘.
* there are 2 spaces in between BB & CC
Result:
For the same ABOVE INPUT VALUE, if we change the Unstring value with ‘DELIMITED BY ALL SPACES Instead of ‘delimited by SPACE.

If More than one delimiter is present in between two strings, then ALL should be used.
Result:
Example 3:
Result:
Note – Count takes Spaces also into consideration.
Example 4: Multiple delimiters by Using OR in Unstring
Example 5: Tallying Option
It gives the count of number of receiving fields. If there are 4 fields in INTO clause then the count would be 4.
In this case WW-TL-1 contains a value of 4.
Note: TALLYING SHOULD BE CODED for the last receiving field.
Example 6:
Here in the below example, Delimiter is spaces and I have given only Two receiving fields
What is the value in WW-U2 after execution? Is it BBB or ‘BBB C’
It is BBB only as delimited by works as below
– First it checks the input string for any given delimiter(in our case it is Space). Once it encounters any delimiter, it extracts that portion of string in to the first receiving field.
– As we have one more receiving field, it further checks for next delimiter and once it finds the next one. It stops there and extracts that portion in to the second string.
– This process gets repeated until it has no more receiving fields.
Example 7: String and Unstring with Pointer:
In the above input example, if the requirement is to get only first name and city into output variables. It can be achieved by using POINTER. But in this case TWO unstring statements are required.

One is to get the first name in to the corresponding field and second one is to get the city.
to get the CITY in to a separate field, move the starting position of string in input filed to a counter and use that in Unstring as below
If we code as below, First name gets populated with the CITY.
Note: We can give only one pointer option in one unstring.