Skip to Content
Product Information
Author's profile photo Jacques Nomssi Nzali

Are we ready to use AI for ABAP programming?

This blog content is from a session with a chatbot from OpenAI. I am just the human asking questions. Jacques Nomssi is (currently) not associated with OpenAI (or Microsoft or Elon Musk). I also did not even try to run code below.

First Contact

I know about Chatbots, I have tried SAP Conversational AI and Google Dialogflow CX, I tried to connect Amazon’s Alexa to my SAP BTP trial. Then I was so excited by the hype about ChatGPT that I went and registered today for a trial.

Login

Login

Now does this AI knows about ABAP code?

ChatGPT%20ABAP%20Hello%20World

ChatGPT ABAP Hello World

Well, it is not even wrong, but this Hello world is for beginners.

My second try

Let us ask for an intermediate level, ABAP Objects version:

ABAP%20OO%20Hello%20World

ABAP OO Hello World

The hungarian notation looks consistent for sure, the code looks good, but it uses CREATE OBJECT instead of NEW. So, I refined my question:

Hello%20World%20with%20NEW%20operator

Hello World with NEW operator

What is the limit?

OK, let us check some advanced level stuff, like the SAP community challenge. Remember this one?

ABAP%20Challenge

ABAP Challenge

You can setup ChatGPT to not always have the same result to the same question. In this case, I had the following code on the next run.

DATA: word_count TYPE i VALUE 0,
      letter_count TYPE i VALUE 0.

SPLIT sentence AT ' ' INTO TABLE DATA(words).
word_count = LINES( words ).

LOOP AT words INTO DATA(word).
  letter_count = 0.
  LOOP AT word INTO DATA(letter) WHERE letter CS 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.
    letter_count = letter_count + 1.
  ENDLOOP.
  WRITE:/ word, ' has ', letter_count, ' unique letters'.
ENDLOOP.

Notice the lowercase letters were not included the first time. And the test IF NOT letter CS letter_count seems wrong to me. I guess ChatBot does the same errors as normal programmers.

But the second code looks good. This code will not win the creativity contest, but without having tried it, I am assuming it is correct.

Update: Stack overflow bans answers from ChatGPT

I added one additional line to request an unit test.

Also write an ABAP unit test for this logic.

and this code was generated

* Unit test
CLASS lcl_test_unique_letters DEFINITION.
  PUBLIC SECTION.
    CLASS-METHODS test_unique_letters_count.
ENDCLASS.

CLASS lcl_test_unique_letters IMPLEMENTATION.
  METHOD test_unique_letters_count.
    DATA: sentence TYPE string VALUE `ABАP  is excellent `.
    DATA: word_count TYPE i VALUE 0,
          letter_count TYPE i VALUE 0.

    SPLIT sentence AT ' ' INTO TABLE DATA(words).
    word_count = LINES( words ).
    cl_abap_unit_assert=>assert_equals( act = word_count exp = 3
      msg = 'Number of words in sentence should be 3' ).

    LOOP AT words INTO DATA(word).
      letter_count = 0.
      LOOP AT word INTO DATA(letter) WHERE letter CS 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.
        letter_count = letter_count + 1.
      ENDLOOP.
      cl_abap_unit_assert=>assert_equals( act = letter_count exp = strlen( word )
        msg = 'Number of unique letters in word should be equal to the number of characters in the word' ).
    ENDLOOP.
  ENDMETHOD.
ENDCLASS.

cl_abap_unit_test=>run( class_name = 'LCL_TEST_UNIQUE_LETTERS' ).

Then I asked for ABAP for the cloud platform

Write ABAP code that start with this line of code as the first line in your application.

DATA(sentence) = `ABАP is excellent `.

Using the value in the variable sentence, programmatically determine the number of words in this variable and then count the number of UNIQUE letters in each word. The code should run in the ABAP cloud environment. Also write an ABAP unit test for this logic.

Well, this is what I got:

*Code:

DATA(words) = SPLIT sentence AT space INTO TABLE DATA(words_tab).

DATA(unique_letters) = 0.

LOOP AT words_tab REFERENCE INTO DATA(word_ref).
  DATA(word) = word_ref.

  DATA(current_letters) = VALUE #( FOR letter IN word( ) ( INIT letter_count 0 ) ( letter_count = letter_count + 1 ) ( letter_count ) ).

  DATA(unique_letter_count) = 0.

  LOOP AT current_letters REFERENCE INTO DATA(letter_ref).
    IF NOT letter_ref[] CS letter_ref-previous.
      unique_letter_count = unique_letter_count + 1.
    ENDIF.
  ENDLOOP.

  unique_letters = unique_letters + unique_letter_count.
ENDLOOP.

*ABAP Unit Test:

CLASS lcl_word_letter_count DEFINITION FOR TESTING
  DURATION SHORT
  RISK LEVEL HARMLESS.

PRIVATE SECTION.
  METHODS get_unique_letters
    IMPORTING
      sentence TYPE string
    RETURNING
      VALUE(unique_letters) TYPE i.

ENDCLASS.

CLASS lcl_word_letter_count IMPLEMENTATION.

  METHOD get_unique_letters.

    DATA(words) = SPLIT sentence AT space INTO TABLE DATA(words_tab).

    DATA(unique_letters) = 0.

    LOOP AT words_tab REFERENCE INTO DATA(word_ref).
      DATA(word) = word_ref.

      DATA(current_letters) = VALUE #( FOR letter IN word( ) ( INIT letter_count 0 ) ( letter_count = letter_count + 1 ) ( letter_count ) ).

      DATA(unique_letter_count) = 0.

      LOOP AT current_letters REFERENCE INTO DATA(letter_ref).
        IF NOT letter_ref[] CS letter_ref-previous.
          unique_letter_count = unique_letter_count + 1.
        ENDIF.
      ENDLOOP.

      unique_letters = unique_letters + unique_letter_count.
    ENDLOOP.

  ENDMETHOD.

ENDCLASS.

CLASS lcl_word_letter_count_test DEFINITION FOR TESTING
  DURATION SHORT
  RISK LEVEL HARMLESS.

PRIVATE SECTION.
  DATA sentence TYPE string.
  DATA unique_letters TYPE i.

ENDCLASS.

CLASS lcl_word_letter_count_test IMPLEMENTATION.

  METHODS setup.
    sentence = `ABАP  is excellent`.
  ENDMETHOD.

  METHODS test_get_unique_letters.
    unique_letters = cl_word_letter_count=>get_unique_letters( sentence ).
    cl_abap_unit_assert=>assert_equals( expected = 11 act = unique_letters ).
  ENDMETHOD.

ENDCLASS.

So, am I obsolete?

Well, this is impressive. If it is so good, I can’t compete. Should I even bother writing a blog myself? I asked (I own all typos):

Write an introductionary blog about ChatGPT for ABAP programmers

This is a verbatim output:

ChatGPT is a revolutionary new chatbot technology that has the potential to revolutionize the way ABAP programmers interact with their existing systems. ChatGPT is an open source, cloudbased chatbot platform that provides an intuitive and userfriendly interface for ABAP developers to manage their applications. With ChatGPT, developers can quickly and easily create interactive conversations with their users, automate tasks, and manage system operations more efficiently. The platform also provides an integrated development environment that allows users to create, deploy, and manage their own custom chatbot applications. This blog will discuss the benefits of using ChatGPT for ABAP developers and how it can help them to streamline their workflows and increase efficiency.

Well this shiny new tool is real. In this time of no-code, low-code, how could it be used to write quality pro-code? I asked (the typos were all in the my question).

Write an introductionary blog about ChatGPT for ABAP programmers. Tell how is can be used to write quality pro-code in this time of no-code, low-code

ChatGPT is a revolutionary new tool for ABAP programmers. Built using the latest AI and natural language processing technologies, ChatGPT provides a powerful and intuitive way to write quality procode. With ChatGPT, ABAP programmers can easily create and maintain complex procode with the help of natural language commands. This makes it easier to write quality code in a fraction of the time. In today‘s nocode, lowcode environment, ChatGPT is a powerful tool for ABAP programmers to quickly develop and maintain their code with minimal effort.

I asked ChatGPT to

Explain to an ABAP developer why ChatGPT cannot replace her. Emphasize the risks of this new technology.

ChatGPT is a revolutionary new technology that promises to automate conversations with unprecedented accuracy. However, it cannot replace an ABAP developer due to the risks associated with it. ChatGPT is still an AIdriven technology, which means it is not infallible and may not be able to make the same decisions that an experienced ABAP developer could. Moreover, ChatGPT is not as adept at debugging and troubleshooting as a human developer, as it can only operate within the parameters of its programming. Additionally, ChatGPT does not possess the same creative problemsolving skills that an ABAP developer does, so it may not be able to come up with novel solutions to complex issues. Finally, ChatGPT is not capable of understanding certain nuances of language, which could lead to confusion or misinterpretations when communicating with endusers. For these reasons, ChatGPT cannot replace an ABAP developer and their expertise should still be valued.

I finally tried

Explain to an ABAP developer why ChatGPT will replace her.

ChatGPT is an AIpowered platform that enables organizations to automate conversations with customers, employees, and partners. It can handle complex conversations, allowing businesses to provide more personalized interactions and better customer service. It can also automate mundane tasks and enable more efficient customer service operations. For an ABAP developer, ChatGPT will enable them to focus more on developing innovative features and solutions that respond to customer needs, thus improving customer experience and satisfaction.

Conclusion

This is the next generation of AI tools. Please try it yourself and comment.

Assigned Tags

      11 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Matthew Billingham
      Matthew Billingham

      Write hello world in ABAP OO abiding by clean code concepts such as not using Hungarian notation. 😉

      Author's profile photo Matthew Billingham
      Matthew Billingham

      In ABAP OO (Object-Oriented ABAP), the "Hello, world!" program can be written using the following code, which adheres to the principles of clean code and avoids the use of Hungarian notation:

      CLASS hello DEFINITION.
        PUBLIC SECTION.
          CLASS-METHODS: say_hello.
      ENDCLASS.
      
      CLASS hello IMPLEMENTATION.
        METHOD say_hello.
          WRITE 'Hello, world!'.
        ENDMETHOD.
      ENDCLASS.
      
      

      This ABAP OO program defines a class called hello that contains a method called say_hello, which is the implementation of the "Hello, world!" program. The say_hello method simply writes the string "Hello, world!" to the screen. The class and method names are clear and descriptive, and do not use Hungarian notation. Additionally, the code is well-formatted and easy to read, which is a key principle of clean code. To run this program, you can create an instance of the hello class and call the say_hello method, as shown below:

      DATA: hello_instance TYPE REF TO hello.
      
      CREATE OBJECT hello_instance.
      hello_instance->say_hello( ).

      This code creates an instance of the hello class and assigns it to the hello_instance variable. It then calls the say_hello method on the instance, which will write the "Hello, world!" string to the screen.

      Author's profile photo Jacques Nomssi Nzali
      Jacques Nomssi Nzali
      Blog Post Author

      Hello Matthew,

      please clarify: is this the answer of ChatGPT to your request? I realize both you and the Chatbot are capable of generating this text/code. The verbosity of the comment makes me suspect this would be the Chatbot work. But here am I, trying to guess if this is human or machine generated...

      best regards,

      Jacques Nomssi Nzali

      Author's profile photo Matthew Billingham
      Matthew Billingham

      The question was from me.

      I also asked for an implementation of the quicksort algorithm in ABAP. Then asked - and the ABAP unit test for that. Which duly appeared!

      Author's profile photo Peter Reuschlein
      Peter Reuschlein

      I´d totaly like to see the GPT with extensive training data on abap and data structures.

      Even in the current state it does use the correct tables and fields

      (create a programm that locks all users not online for 10 days)

      example

      example

      Author's profile photo Jacques Nomssi Nzali
      Jacques Nomssi Nzali
      Blog Post Author

      Hi Peter,

      this short program highlights the current problem: The answer seems correct.

      But this code that is generated in seconds is just pseudo-code with many syntax errors:

      • Fields LAST_LOGIN and BLOCKED do not exist in table USR02.
      • Table USER_TABLE has the line type of structure USR02 but the work area USER_NAME is a single field USR02-BNAME.
      • The syntax of MODIFY dbtable FROM source  is wrong.

      So the ChatGPT bot is not ready yet. But, when it shows us that is will be ready soon.

      The question will then be, are we ready?

      regards,

      Jacques Nomssi Nzali

      Author's profile photo Marian Zeis
      Marian Zeis

      Jacques Nomssi Nzali

      Thats the big problem with ChatGPT.

      If it doesn't know something, it does a very good job of pretending it knows the answer and adds to the code.
      The dangerous thing is that the user thinks the answer is correct.
      So especially for junior developers it is dangerous.
      Apart from the fact that an outdated syntax is used.

      Author's profile photo Matthew Billingham
      Matthew Billingham

      You can tell it that it is wrong.

      Author's profile photo Jacques Nomssi Nzali
      Jacques Nomssi Nzali
      Blog Post Author

      ChatGPT is a fantastic query language. I can ask anything in my own words in any of the languages I can speak, and it will return an answer. The limitation I see is that once it really gets a wrong, result, ChatGPT will not be able to learn and stop doing the wrong inference again and again.

      I found a good example for this limitation: ChatGPT does not understand how to use the SWITCH operator in ABAP. I you can have it spit ABAP code with the CASE statement, but a query like Explain the SWITCH operator in ABAP will generate wrong code.

      In a dialog, the bot acknowledges shortcomings and seems eager to learn. But no matter what information I feed it, it seems to be impossible to make it understand the difference between an operator and a statement in ABAP. No matter how I frame it, the results are incorrect, ChatGPT tries too hard to make the SWITCH operator behave like the CASE statement.

      I guess this can only be changed by updating its knowledge database, not merely through a conversation.

      Author's profile photo Yemi Durosaro
      Yemi Durosaro

      This is revolutionary. I am wondering if there is a use case for CHatGPT to help with debugging especially for techno-functional folks.

      Author's profile photo Christoph Weyd
      Christoph Weyd

      SAP should make a deal with Elon Musk to get a "special" OpenAI version fully trained on the SAP data model and ABAP syntax. Such an AI tool would be far better than SE16, Report Painter, QuickViewer.

      Remember the last TechEd (that stuff was boring compared to ChatGPT) . Imagine you could ask an AI to create a Fiori App to give you the Top 20 customers per region within the last x months....

      I am surprised, if you would have asked me 3 years ago if something like that is possible, my answer would have been "maybe in 20+ years".

      I have currently mixed feelings: excited, surprised but also scarred.