Sometimes, there is a need to check palindrome of a number provided by user. In that case we program to check palindrome in ABAP. It is not a question that is merely asked in an interview but an important keyword that is used in day to day programming.

Introduction

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

Program to Check Palindrome- Image Illustration

ABAP Program

PARAMETERS: lv_data1(10) type c.
Data : lv_data2(10) type c.
CALL FUNCTION 'STRING_REVERSE'
  EXPORTING
    string          =  lv_data1
    lang            = sy-langu
 IMPORTING
   RSTRING         = lv_data2
* EXCEPTIONS
*   TOO_SMALL       = 1
*   OTHERS          = 2
          .
IF lv_data1 EQ lv_data2.
Write: 'Palindrome Number'.
Else.
  Write: 'Not a Palindrome Number'.
ENDIF.

Explanation

In the program mentioned above, we have implemented following step by step:

  1. Initially, we have defined a parameter lv_data1 of type i.e. character of length 10. This parameter will be used to take the input.
  2. Later, we have declared a variable lv_data2 of type i.e. character of length 10. This variable will be used to store the reverse value of input string.
  3. Now, we will call a function module ‘STRING_REVERSE’ that will give us the reversed string.
  4. If the original string and reverse string are same, then output will be ‘Palindrome Number’ else it will be ‘Not a Palindrome Number’.

Leave a comment

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Translate »