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.

Steps to check vowel or consonant in a program:

To find whether a character is vowel or not we have two steps:

  1. 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).
  2. 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.
    

     

Explanation:

Lines mentioned below have line by line code explanation:

  1. In first line we have defined a parameter p_inp of type c. So, it takes only one character as input.
  2. 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.
  3. If the above line is successful then it is a vowel and thus ‘A Vowel’ is printed as output.
  4. If the second line is not successful then it is not a vowel and thus ‘A Consonant’ is printed as output.

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 »