Preface – This post is part of the ABAP Programs series.
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.
Table of Contents
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- 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:
- Initially, we have defined a parameter lv_data1 of type c i.e. character of length 10. This parameter will be used to take the input.
- Later, we have declared a variable lv_data2 of type c i.e. character of length 10. This variable will be used to store the reverse value of input string.
- Now, we will call a function module ‘STRING_REVERSE’ that will give us the reversed string.
- If the original string and reverse string are same, then output will be ‘Palindrome Number’ else it will be ‘Not a Palindrome Number’.
0 Comments