fbpx

Leverage ChatGPT in SAP ABAP to speed up development

DeveloperOnaComputerScreen.jpg

Developers are expensive. A challenge most managers have is to manage costs, especially human costs of Developers. The average salary of an SAP ABAP developer is approximately $130,000 per year (Jan 2023). It becomes important for managers to get the most productivity from their teams especially in this challenging global economic environment. Meanwhile, SAP ABAP developers are constantly looking for ways to make their development cycles faster, more efficient, and more cost-effective.

ChatGPT is the latest Artificial Intelligence (AI) tool that has created a lot of excitement in the tech community. It is a natural language processing (NLP) tool that can be used to automatically generate SAP ABAP code from natural language input. This tool can help SAP ABAP developers improve their development cycles by reducing the time spent on manual coding and providing them with a more intuitive way to create code creating a win-win solution for both managers and developers.

Usecases of ChatGPT code generation in SAP ABAP

There are several usecases where ChatGPT can be used. Some of the usecases are

  1. Create sample data
  2. Validate input
  3. Read data from a table

Here are some prompts for these usecases that will show you the power of leveraging ChatGPT into your ABAP development process.

Create Sample Data in ABAP with ChatGPT

Prompt:

create a json sample for 3 employees with name, city, country and email.
ChatGPT Output:
ChatGPT Json sample
Since we did not specify that it was ABAP code, ChatGPT chose the language as Perl, and output the Json object with the example we asked for. Now, lets generate this json with ABAP code.
Updated prompt to ChatGPT:
create a json sample for 3 employees with name, city, country and email in ABAP.

ChtGPT Json sample in ABAP

In this example, we define variables for the name, city, country, and email of each employee. We then create an internal table employees_table to hold the JSON string data, and concatenate the JSON key-value pairs for each employee into a single string employee_data. Finally, we append the JSON string data to the employees_table, concatenate the lines of the table into a single string, and store the result in the variable employees.

This will produce the JSON string we showed above.

Validate sample data with ChatGPT

Next, we look at the prompt for the validation of sample data that ChatGPT created. This is an important step, since ChatGPT is an AI tool that leverages machine learning from the information available on the web. The code it produces can have errors, and it is always best to cross check the code it creates.

Prompt:

what is the output of the above json with ABAP?
Output:
ChatGPT JSON sample validation
Read sample data from a table in ABAP with ChatGPT
To select the employee data from the JSON into an internal table in ABAP, we can use the cl_trex_json_deserializer class to parse the JSON string and convert it to an ABAP data object. Here is the sample prompt:
select the above ABAP json into a table. show an ABAP script to read the data from that table
ChatGPT Output:
In this example, we first define a table type ty_employee to hold the employee data. We then use the cl_trex_json_deserializer class to parse the JSON string and convert it to an ABAP data object. We extract the employee data from the JSON by accessing the “employees” key and looping over the array of employees. For each employee, we extract the name, city, country, and email fields and append them to the employee_table. Finally, we output the employee data to the console using a WRITE statement.Chat GPT Json data table in ABAP

Conclusion

ChatGPT is a powerful tool that can be leveraged to speed up SAP ABAP development. Developers and even non-technical people such as Business Analysts can use it to generate code quickly to speed up their development processes.

Share this post

submit to reddit
scroll to top