Technical Articles
A curious case of Chat GPT and ABAP
Introduction
I recently came across an interesting and excellent blog series written by Kallol Chakraborty , https://blogs.sap.com/2022/12/20/easy-way-to-write-algorithms-in-abap-series-01/ wherein he is discussing about writing algorithms in ABAP.
Now that Chat GPT is out, we have already seen a lot of use cases where many developers have used Chat GPT to generate code from one language to another. I thought, why not use Chat GPT and see how efficiently it could convert a piece of code to ABAP.
The Prompt
I logged in to leetcode and searched for an algorithm to test this out.
I took the example of grouping anagrams as follows and then, gave the following, as input to Chat GPT for converting it to ABAP
class Solution {
public List<List<String>> groupAnagrams(String[] strs) {
if (strs.length == 0) return new ArrayList();
Map<String, List> ans = new HashMap<String, List>();
int[] count = new int[26];
for (String s : strs) {
Arrays.fill(count, 0);
for (char c : s.toCharArray()) count[c - 'a']++;
StringBuilder sb = new StringBuilder("");
for (int i = 0; i < 26; i++) {
sb.append('#');
sb.append(count[i]);
}
String key = sb.toString();
if (!ans.containsKey(key)) ans.put(key, new ArrayList());
ans.get(key).add(s);
}
return new ArrayList(ans.values());
}
}
The following is the output in ABAP, that I got as a response from Chat GPT.
You can find the video of the prompt I gave, given below.
Now, the generated output is not that far from being accurate with some minor syntax errors which can be fixed by a skilled developer. But what surprised me is the fact that it was able to identify similar syntaxes in ABAP and write that down.
Conclusion
This opens a huge avenue of opportunities where code can be swapped across multiple languages. The possibilities are endless, and I am excited for what the future holds for the ABAP and the developer community as a whole.
This is the code from the screenshot above, so that ABAP developers can check by themselves:
That's the test class:
Below what I would expect from a developer who would convert the java algorithm line by line. That's a code which works, each line is more or less equivalent to the java code:
Hi Sandra,
Thank you for this. The human touch is clearly evident here.
Best Regards,
Prasanth
Thanks a lot Prasanth Padmanabhan Menon for the encouragement and Discussion.
I think you're a little too bit optimistic when you say "the generated output is not that far from being accurate with some minor syntax errors which can be fixed by a skilled developer."
Here is the version of ChatGPT corrected by me with the fewest changes possible:
What the differences are:
To do these fixes, I had to understand the algorithm (from the java code for instance). It was impossible for me to FIRST understand the crazy code generated by ChatGPT.
After that, I had to understand which parts of ChatGPT code correspond to which part of the algorithm, and I could find the minimal changes.
Conclusion: it took me 3x more time to find how to fix the program with minimal changes rather than writing the algorithm from scratch.
But I guess ChatGPT could be trained with ABAP code equivalent to java code and maybe that would result in more reusable code in the future...
Hi Sandra,
You are right that I was a being a bit too optimistic and the minimal changes weren't actually that minimal as you have demonstrated here(The screenshot you have given for the code comparison really puts things in perspective).
But I do believe that the model will definitely become more capable by reading equivalent ABAP code.
Best Regards.
Prasanth
Thank you for your service, Sandra Rossi !
Your experience is pretty much identical to mine as a technical translator, correcting machine translations 20-ish years ago - much slower and more frustrating than just translating from scratch.
(In fact, the manager who gave us the task was so embarrassed by our workload, he threw a party in the Walldorf Party Room in Building 5, with a free bar - and served the drinks himself!)
Machine translation has improved massively ofc, and has its uses providing rough-and-ready information from languages I don't speak.
But it's still:
Given that software, unlike human texts (eg newspapers), can be mission-critical, I'm pretty dubious about this - at present.
Just a personal view.
Best wishes,
Julie.
https://www.theregister.com/2022/12/05/stack_overflow_bans_chatgpt/
If you rely on ChatGPT, then you're going to have very buggy code. Probably best avoided. On the plus side, stupid-criminals are trying to use it as an attack vector.
Frankly, even getting humans to produce good code is a challenge. Having an AI do it, based on a million examples of not very code isn't going to do any better. As Sandra Rossi points out - it requires analysis. ChatGPT doesn't do analysis. It chats in a (scarily) believable way!
Thanks for that very interesting article + Stack Overflow policy about GPT.
There's something I don't see clearly in this article and in Stack Overflow:
I fear that in a very near futuret the questions asked in the forums by beginners would contain stupid code produced by GPT and asking "what is to be fixed". That will make people less and less trying to think, understand and learn, it's why it's important in our answers to not give directly the final code but make people learn how to find by themselves.
I hope these forums would sanction the people who are asking (repeatedly) questions about generated GPT code.
NB: in case you don't find the source easily from The Register article (link at the word "said"):
From my perspective any AI algorithms anyway need human analysis and this is not a surprise if you spend time analysis of your own bugs or the others. In all ways it is good move AI like ChatGPT just started to do the revolution here. Fingers crossed as more such models are in store including ones to defend security threats on such tools. So await cool future ahead of us as for analysis professionals than coders who do work from scratch ? Happy ABAP joined this wagon.
Dear @Prasanth Padmanabhan Menon,
Thanks for checking out my blogpost. 🙂
Yes, I have tried ChatGPT with ABAP. I can say, it's quite good. But I am curious about passing the test cases.
Regards,
Kallol