Preface – This post is part of the ABAP Programs series.
Program to check vowel or consonant in ABAP or in any other computer language utilizes its ASCII values. ASCII stands for American Standard Code for Information Interchange. It is defined to represent every character on electronic communication in an encoded form. You can find list of all ASCII characters here.
Table of Contents
Steps to check vowel or consonant in a program
To find whether a character is vowel or not we have two steps:
- Get ASCII of the character using Function Module URL_ASCII_CODE_GET and compare the ASCII code with 65, 69, 73, 79, 85 (A, E, I, O, U) and 97, 101, 105, 111, 117 (a,e,i,o,u).
- Directly compare the character with a set of characters as shown in program below:Program to check vowel or consonant in ABAP
PARAMETERS: p_inp type c. IF p_inp CA 'A,E,I,O,U'. Write: 'A Vowel'. ELSE. Write: 'A Consonant'. ENDIF.
Lines mentioned below have line by line code explanation:
- In first line we have defined a parameter p_inp of type c. So, it takes only one character as input.
- In this line, we have compared the input using ABAP keyword “CA”. It is compared with vowels i.e. a, e, i, o and u.
- If the above line is successful then it is a vowel and thus ‘A Vowel’ is printed as output.
- If the second line is not successful then it is not a vowel and thus ‘A Consonant’ is printed as output.