String Palindrome Program In Cobol

  • To check if a string is a palindrome or not, a string needs to be compared with the reverse of itself. Consider a palindrome string: lol, -index: 0 1 2. Value: l o l- To compare it with the reverse of itself, the following logic is used: 0th character in the char array, string1 is the same as 2nd character in the same string.
  • The string tokenizer class allows an application to break a string into tokens. The StringTokenizer methods do not distinguish among identifiers. It contains a program to reverse a string and to check whether a Entered string is palindrome.NET Core COBOL. Autocad Lisp Steel Sections.
  1. Cobol String Command Example
  2. String Palindrome Program In Cobol In Computer

Palindrome Characters/String/Number are those characters which are same if reversed. 12321, MADAM are some example of Palindromes. To achieve this thing, we need to reverse that string and compare with the old value. The given program implements the same: Program to Check Palindrome- Image Illustration ABAP Program. The string tokenizer class allows an application to break a string into tokens. The StringTokenizer methods do not distinguish among identifiers. It contains a program to reverse a string and to check whether a Entered string is palindrome.NET Core COBOL. – this is a palindrome: “Madam, I’m Adam” – this is not a palindrome: “This man is working hard” So the definition of a palindrome is easy to understand, and to test that a string is a palindrome or not is easy from the standpoint of a reader. Let’s solve it using functional programming instead of imperative programming.

February 26, 2018

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-

Program

Cobol String Command 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:

String Palindrome Program In Cobol In Computer

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.

For Further Reading>