Application Development Blog Posts
Learn and share on deeper, cross technology development topics such as integration and connectivity, automation, cloud extensibility, developing at scale, and security.
cancel
Showing results for 
Search instead for 
Did you mean: 
nomssi
Active Contributor
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


Now does this AI knows about ABAP code?


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 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 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 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, cloud-based chatbot platform that provides an intuitive and user-friendly 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 pro-code. With ChatGPT, ABAP programmers can easily create and maintain complex pro-code with the help of natural language commands. This makes it easier to write quality code in a fraction of the time. In today's no-code, low-code 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 AI-driven 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 problem-solving 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 end-users. 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 AI-powered 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.
14 Comments