Harnessing the Power of Message Class for Effective Program Communication

 Welcome back everyone to our Complete SAP ABAP Master Series, We have started Message Class in our last blog, So let’s continue it.


Message Class :-

  • Suppose, I want to open a program in ABAP Editor which does not exist, then the SAP System will automatically generate a message that the Program does not exist.


  • Messages play a very crucial and vital role in SAP.

Types of Messages :-

  1. A(Abort)
  2. E(error)
  3. I(Information)
  4. S(success/status)
  5. W(warning)
  6. X(exit)

Note :- We should always use Message class for writing Messages, Never hard code messages inside the program.


Requirement :-

Let’s understand the importance of Messages through a requirement.

  1. Suppose, I have the below program, I hope you remember the below code, Since we had discussed this program in our previous blogs.



    Now, Once we are trying to execute the program and we provide a wrong input number, then Suppose the Customer wants us to display a message that Order Number does not exist.



    Solution :-

    • Step 1 :- Go to transaction code SE91.

    • Step 2 :- Give a name to message class.

    • Step 3 :- Click on create button.



    • Step 4:- In the Attribute Section, Provide the Short description.



    • Step 5 :- In the Message tab, Choose any Message number and write your message.

    • Step 6 :- Click on save and assign the package.



    • Step 7 :- Go back to program and call the message inside the program.



      Code :-

      ****************************************************
      *Start of Program
      **Declaring the type structure
      TYPES: BEGIN OF ty_header,
               order_no     TYPE  zar_ono,
               order_date   TYPE zar_odate,
               payment_mode TYPE zar_pm,
               total_amount TYPE zar_tc,
               currency     TYPE zar_cur,
             END OF ty_header.
      
      ***Declaring the internal table and work area
      DATA : lt_header type table of ty_header,
             ls_header type ty_header.
      
      *Declaring the Parameter
      PARAMETERS : p_ono type zar_ono.
      
      ****Perform the Select Query.
      Select ORDER_NO
             ORDER_DATE
             PAYMENT_MODE
             TOTAL_AMOUNT
             CURRENCY
           from ZAR_ORDER_HEADER into table
           lt_header where ORDER_NO = p_ono.
        if lt_header is not INITIAL.
      *Displaying the output
          loop at lt_header into ls_header.
          Write : 'The details are : ',
                  ls_header-ORDER_NO,
                  ls_header-ORDER_DATE,
                  ls_header-PAYMENT_MODE,
                  ls_header-TOTAL_AMOUNT,
                  ls_header-CURRENCY.
          endloop.
          else.
      **********************************
      *Writing Message.
            Message E000(ZAR_MSG). "Message type Error
      
        endif.
      *End of Program
      **********************************************************
      
    • Step 8 :- Now execute the code.

    • Step 8 :- Provide a order number which does not exist in Order header table and try to execute it.






Important Points on Message Class :-

  • A message number length is 3(000-999).
  • One can pass values to a message number using &.
  • In a message number, we can pass up to 4 &.
  • Syntax to use a message in a program :
    • MESSAGE E000(<msg class>).
  • In the above syntax - MESSAGE = keyword, E = error message type, 000 is a message number, <msg class> = name of the message class.

Requirement :-

Now, Suppose the Customer wants to see the wrong entered input in the Message.

Solution :-

  • Step 1 :- Go to message class and use & in your message.



  • Step 2 :- back to program and make some changes as shown below.



  • Step 3 :- Now execute the program.



    • You can see the entered the order number in the message.

    Note :- At any place where you want to see the wrong entered value in the message, you can simply provide (&) in the Message class at that place.

    • We can reuse the message written in Message class any number of time, that we want.

Transaction Code For Programs :-

  • One can create own shortcut/transactions to access the applications.

  • The transaction code to create a transaction code is se93.



Steps :-

  • Step 1 :- Go to SE93, provide a name starting with Z or Y and click on create button.



  • Step 2 :- Provide a short description.

  • Step 3 :- Select the radio button ( Program and selection screen ).



  • Step 4 :- Click Enter.

  • Step 5 :- In Program, give the program name.

  • Step 6 :- Enable all checkboxes for GUI support.

  • Step 7 :- Click on save and assign the packages.



  • Now, you can directly call the transaction code ZAR_HEADER_DETAILS.






So, that’s enough for today.

We will discuss about best programming practices in our next blog.

Thanx alot for being a part of this wonderful journey.

Comments

Popular posts from this blog

Understanding Different Types of SAP Function Modules: Normal, RFC, and Update

Mastering ABAP: A Step-by-Step Guide to Function Modules and Groups for Modularized Programming

Introduction to SAP