Scrutinizing ABAP GenAI example from SAP Sapphire keynote

Scrutinizing ABAP GenAI example from SAP Sapphire keynote

Below is the code example from yesterdays SAP Sapphire Keynote,

ABAP GenAI example

At the point of writing, its not possible to replay the keynote, as it was taken down from YouTube, and not available on the Sapphire Virtual homepage.

But, given a prompt the above code was generated. This happened at the main keynote, the feature was announced 6+ months ago, and this being a keynote I think its okay to look into every detail of it. At a keynote SAP has full control of what to show and how, and I do assume there is a review step as to what goes into the keynote.

On top of this, SAP advocates clean core, clean code, clean everything, so what SAP shows on the keynote I assume SAP certifies as clean.

Lets go,

A: Indentation is off

Indentation in ABAP is typically 2 spaces, looking at line 2 its one space, while line 14 and 15 are actually aligned vertically its still one off. Line 19 and 20 doesn't follow the lines after it inside the IF

B: Hungarian notation mix

Using Hungarian notation or not is a big topic in ABAP. However most agree that mixing both in the same code is bad practice.

C: Parentheses

In line 20, the leftmost and right most parentheses can be removed.

D: Types

Using "TYPE p DECIMALS 2" is not something I've seen very often, and looking in the parameters indicates that the fields are "Decfloat" which is a different type.

This might be an error and worst case cause dumps, might also be okay. I don't have access to a system to verify.

E: lv_error is unused

The variable "lv_error" is unused

F: Comments

Like line 1, adding a comment that the DATA is declared below it, no need to. Add comments where it adds value, don't replicate whats below it

H: CORRESPONDING #

MOVE-CORRESPONDING works, but CORRESPONDING # is more modern, and considered cleaner by some developers

I: Inline declarations

In modern ABAP, variables can be declared inline, increasing readability and also helping make sure the types are correct

J: Line 11?

Line 11 jumps out, as it moves "element attributes" to "result amounts", this might be okay, I guess its used to fill some key fields in the result amounts. But it might risk moving too much depending on the types(which I dont have access to check)

K: Use "-="

The modern subtracting move "-=" can be used to reduce the amount of code


Just put the example into https://playground.abaplint.org, and it will hint the developer with many of the above issues.


So, what about something like the below, did I forget anything?

item_result_amounts = CORRESPONDING #( item_amounts ).
item_result_attributes = CORRESPONDING #( item_attributes ).
item_result_quantities = CORRESPONDING #( item_quantities ).
prcg_element_result_amounts = CORRESPONDING #( prcg_element_attributes ).
active_price_result_amounts = CORRESPONDING #( active_price_amounts ).

DATA(lv_temperature) = item_attributes-yy_temperature_pci.

" when the weather is good, people buy more ice cream, 
" so we reduce the price
IF lv_temperature > 20.
  prcg_element_result_amounts-conditionamount -= 
    ( lv_temperature - 20 ) / 2 ) * 
    ( prcg_element_attributes-conditionamount / 10 ).
ENDIF.        


Martin Grellmann

Experienced full-stack web developer with 20+ yrs in the field. Proficient in React, JavaScript, Node.js, PHP & MySQL. 7 yrs in Linux administration & 3.5 years in business software development, incl. 2.5 yrs in SAP.

8 个月

This is in line with my experience when I use some modern LLM, which deliver very similar results. One difference is perhaps copilot, it can show sources - and that's really helpful.

回复
Micha? B.

SAP ABAP Developer, software architect, clean code enthusiast

8 个月

SAP should be more responsible in showing any code. It started the clean code initiative, but it doesn't support it. I think each and every piece of code (not only AI-generated), that is presented on SAP official events should follow the principles.

Morten Wittrock

SAP integration veteran | Member of the SAP Mentors program | SAP PRESS author | SAP community enthusiast

8 个月

Nitpicking the code is a fun exercise, of course, but for discussing the value of GenAI code generation, I don't think it's that useful. A more interesting question would be: Will using the GenAI output as a starting point get the median ABAP developer to working code of sufficient quality faster than starting from scratch? I think the answer is very likely yes, but I'd really like to hear your take, Lars.

Jelena Perfiljeva

Expert SAP Developer * Chief Nerdess at Boring Enterprise Nerds * SAP Mentor Alumna * Book author * Conference speaker * The First of Her Name * Protector of The ABAP Realm

8 个月

Lars Hvam Petersen Thanks for writing about this! I'm yet to watch the keynote and I guess now someone is editing this out in a hurry. :) (Conspiracy theories ensue!) I usually try very hard to be professional in the code reviews but if this was produced by a human developer, there is a big chance my whole review would be "what is this s*t?" On top of that, this example is probably confusing to the whole US SAP customer base because we measure temperature in Farenheit. And 20 F is very cold. Also, there is a reason that the amount fields have special currency type in SAP. There are a few oddball currencies (JPY is the most notable example) that don't use decimals and the amounts are actually stored using a "factor". I believe all of that complexity still exists in S/4HANA. I get it that some simplification is needed when just showing an example. But that's the result of example being very primitive to begin with.

Ramjee Korada

SAP ABAP(+RAP), Fiori Elements. S4/HANA , BTP Technical Architect , ABAP Cloud , ABAP Push/Messaging Channel

8 个月

Chain statements can be used instead of multiple DATA and Move-Corresponding

要查看或添加评论,请登录

Lars Hvam Petersen的更多文章

  • ABAP and Excel, its never been easier

    ABAP and Excel, its never been easier

    abap2xlsx is an open source project making it easy to read and write Excel files with ABAP. In ABAP its always been a…

    9 条评论
  • ABAP Cloud: Getting rid of those pesky macros

    ABAP Cloud: Getting rid of those pesky macros

    The ABAP Cloud Programming Model does not allow using macros, however lots of old code still use macros, so how do we…

    9 条评论
  • Happy Birthday abapGit, 10 years!

    Happy Birthday abapGit, 10 years!

    The Past On a dark and lonely summer morning, 10 years ago, I did the first commit of something that ended up being…

    19 条评论
  • Not on 756? No function module test framework? No problem!

    Not on 756? No function module test framework? No problem!

    TLDR: Use it standalone on GitHub actions, move the unit tests into the system when its upgraded to 756+ The Function…

  • Stuff I'd like removed from the #ABAP roadmap

    Stuff I'd like removed from the #ABAP roadmap

    SAP provides roadmap information at https://help.sap.

    21 条评论
  • Running abap2UI5 backend in browser

    Running abap2UI5 backend in browser

    abap2UI5 by Lars Kaldewey et al. allows to easily write ui5 applications with backend ABAP code.

    3 条评论
  • Running Scrypt in Rust on ABAP on Raspberry PI Zero

    Running Scrypt in Rust on ABAP on Raspberry PI Zero

    Running ABAP code on a Raspberry PI Zero has been possible for some time. Executing JavaScript on it is slow, running…

    15 条评论

社区洞察

其他会员也浏览了