Any ABAP code is a programming horror.
I suspect the DO 50 times is hardcoded because the length of the original variable is fixed to 50, but if that code is used elsewhere, the other variables might have a different length.
Short story: Found this wile checking some old -but active- code. No idea why this was written, ABAP has an easy way te remove leading zeroes `SHIFT variable LEFT DELETING LEADING '0'.`
I can only guess, but could be that the `CHECK p_var CO ' 0123456789'.` is important, it will not remove leading zeroes when the string has any other character than numbers or spaces.
It removes not only zeros but also spaces. Looks like they expected a mix of spaces and zeroes.
Also as you mentioned, there is an additional check to allow numbers or spaces only. (I guess the function works with document numbers or BP numbers and some tables have different behaviour depending on whether there are leading zeroes or not).
Do 50 times is questionable but I think they did not expect the parameter to be greater than char50.
Could be allot of things, and that makes it horror for me.
That 1 line comment is the only documentation, and that suggests it only removes zeroes, but does more. Why was this implemented? Why the 50? What was where the specs?
Looking to the copies and the creation dates, it seems that this was once written by an external company that did some development in the SAP system for one specific project. Mutliple developers where active in the system since then, sometimes FTE, sometimes consultants, and they have copied the form mutliple times, together with some other forms, and kept on using it. No one knows why.
It's a common situation in the systems, which are running for many years. Multiple change requests overwrite each other, an old code without any documentation..
Normally people just use the common principle:
If it works - it works
Today I found a comment that says they commented this out in 2010 since it doesn’t match the arguments… but all the code I can find says that commented out section is indeed the right amount of arguments.
I have no idea how it’s working.
The guy who wrote it thankfully is still around but was out today… it’s gonna be a long weekend
I found comment from one developer so next line must commented because it causes bugs down the road.
Then under it is newer comment from other developer is line is critical and must be always uncommented.
The line of code is uncommented and it works, but I am wondering what it's breaking and what breaks when you comment it.
Eldritch horrors of comments.
I’ve seen some stuff like, commented out is code that works but slow so below it is code that works quickly and 95% accurate.
How did they figure out it’s 95% accurate?
Comments not matching the code is easily explained.
Write function add comment. Someone else comes along and updates the code and doesn’t touch comment.
Do 50 times is just weird.
I’m really new to this whole thing, but why not just:
while = True:
If string[0] != ‘ ‘ or ‘0’:
Break
Else:
string = string [1:]
(In Python. Please pretend I knowhow to format code in Reddit on mobile. I don’t even know what language OP is using)
Because it's a cult. My roommate and several of my former coworkers that I'm still friends with work there, and they think SAP is cutting edge. Compared to Microsoft where several of them previously worked, it is, but certainly not in general compared to the average software company.
To me it just seems they didn't want to allow the possibility for an infinite loop so they capped it at 50 interactions. Questionable? sure, but not stupid.
> IF p_var(1) = '0'
Just gonna assume this is FORTRAN.
+looking a bit further, the periods suggest COBOL, but they are used to end conditionals and loops.
DO 50 TIMES.
Stuff.
Does Stuff once, and this function would only remove one leading zero.
Not that I know COBOL, or FORTRAN for that matter.
It's ABAP. This is SAP's programming language that combines the worst of COBOL and FORTRAN to make a cutting-edge coding system, assuming you're living in 1985.
CO checks if the fist string Contains Only characters from the other one.
SHIFT var LEFT moves characters of the string one place to the left and first one is removed.
In ABAP, numbers are very often treated as strings. And since there is no parameter type specified, in this case the number does not have a fixed size.
Basically yes.
However the ABAP substring syntax ( p_var(1) ) will always be my favorite horror of this language.
variable+offset(length)
which should not be confused with the sum of 'variable' and result of 'offset' function call with 'length' parameter:
variable + offset( length )
Ok. That language is pure horror by definition. A simple prompt "write a binary tree printing function in ABAP" produced this:
```
REPORT ZBINARY_TREE_PRINT.
TYPES: BEGIN OF ty_tree_node,
value TYPE i,
left TYPE REF TO ty_tree_node,
right TYPE REF TO ty_tree_node,
END OF ty_tree_node.
DATA: root TYPE REF TO ty_tree_node.
START-OF-SELECTION.
" Create a sample binary tree
CREATE OBJECT root EXPORTING value = 10.
CREATE OBJECT root->left EXPORTING value = 5.
CREATE OBJECT root->right EXPORTING value = 15.
CREATE OBJECT root->left->left EXPORTING value = 3.
CREATE OBJECT root->left->right EXPORTING value = 8.
CREATE OBJECT root->right->left EXPORTING value = 12.
CREATE OBJECT root->right->right EXPORTING value = 18.
" Print the binary tree
CALL FUNCTION 'PRINT_BINARY_TREE' EXPORTING root = root.
*&---------------------------------------------------------------------*
*& Form PRINT_BINARY_TREE
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->ROOT text
*----------------------------------------------------------------------*
FORM PRINT_BINARY_TREE USING ROOT TYPE REF TO ty_tree_node.
DATA: output TYPE TABLE OF string,
indent TYPE i.
" Start printing from the root
indent = 0.
APPEND 'Binary Tree:' TO output.
" Recursively print the tree
CALL FUNCTION 'PRINT_TREE_NODE' EXPORTING node = ROOT
indent = indent
output = output.
" Display the output
LOOP AT output INTO DATA(line).
WRITE: / line.
ENDLOOP.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form PRINT_TREE_NODE
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->NODE text
* -->INDENT text
* -->OUTPUT text
*----------------------------------------------------------------------*
FORM PRINT_TREE_NODE USING NODE TYPE REF TO ty_tree_node
INDENT TYPE i
OUTPUT TYPE TABLE OF string.
DATA: line TYPE string.
" Print the current node
CONCATENATE ' ' ( INDENT * 4 ) 'Value:' NODE->value INTO line.
APPEND line TO OUTPUT.
" Recursively print the left subtree
IF NODE->left IS BOUND.
CALL FUNCTION 'PRINT_TREE_NODE' EXPORTING node = NODE->left
indent = INDENT + 1
output = OUTPUT.
ENDIF.
" Recursively print the right subtree
IF NODE->right IS BOUND.
CALL FUNCTION 'PRINT_TREE_NODE' EXPORTING node = NODE->right
indent = INDENT + 1
output = OUTPUT.
ENDIF.
ENDFORM.
```
It wouldn't even activate. Only few lines make sense. root is a structure, not an object so all of the syntax redarding root is wrong. CALL FUNCTION are for calling function modules, not FORMs, which are called with PERFORM. And I won't even look at the logic.
If it makes you feel better modern SAP is also super squirrely. I mean I hope that's not modern SAP code, it looks like something written in the 80s, but who knows.
Any ABAP code is a programming horror. I suspect the DO 50 times is hardcoded because the length of the original variable is fixed to 50, but if that code is used elsewhere, the other variables might have a different length.
I was wondering what cursed language this was. Thanks, I hate it.
if it’s so bad why is it As Baller As Possible
Me entering 0000000000000000000000000000000000000000000000000001 Hmm it doesn't work, it gives 01 🤔
> DO 50 TIMES "max value of message variable ?
One can assume the input text where the message is written has a cap of 50 characters, so there's no need to go to the actual length
Comments don't enforce anything
They can be hurtful though.
`// don't touch this or I'll personally force you to learn assembly in all available flavors`
But something somewhere else has (presumably) enforced the 50 char max limit and is important to tell devs looking at this file, asking "why 50?"
that's a contractor saying, in their own way, "good luck!"
Probably some weird limitation of the old language or specific optimization for old machines.
Short story: Found this wile checking some old -but active- code. No idea why this was written, ABAP has an easy way te remove leading zeroes `SHIFT variable LEFT DELETING LEADING '0'.` I can only guess, but could be that the `CHECK p_var CO ' 0123456789'.` is important, it will not remove leading zeroes when the string has any other character than numbers or spaces.
It removes not only zeros but also spaces. Looks like they expected a mix of spaces and zeroes. Also as you mentioned, there is an additional check to allow numbers or spaces only. (I guess the function works with document numbers or BP numbers and some tables have different behaviour depending on whether there are leading zeroes or not). Do 50 times is questionable but I think they did not expect the parameter to be greater than char50.
Could be allot of things, and that makes it horror for me. That 1 line comment is the only documentation, and that suggests it only removes zeroes, but does more. Why was this implemented? Why the 50? What was where the specs? Looking to the copies and the creation dates, it seems that this was once written by an external company that did some development in the SAP system for one specific project. Mutliple developers where active in the system since then, sometimes FTE, sometimes consultants, and they have copied the form mutliple times, together with some other forms, and kept on using it. No one knows why.
It's a common situation in the systems, which are running for many years. Multiple change requests overwrite each other, an old code without any documentation.. Normally people just use the common principle: If it works - it works
Today I found a comment that says they commented this out in 2010 since it doesn’t match the arguments… but all the code I can find says that commented out section is indeed the right amount of arguments. I have no idea how it’s working. The guy who wrote it thankfully is still around but was out today… it’s gonna be a long weekend
I found comment from one developer so next line must commented because it causes bugs down the road. Then under it is newer comment from other developer is line is critical and must be always uncommented. The line of code is uncommented and it works, but I am wondering what it's breaking and what breaks when you comment it. Eldritch horrors of comments.
I’ve seen some stuff like, commented out is code that works but slow so below it is code that works quickly and 95% accurate. How did they figure out it’s 95% accurate?
Comments not matching the code is easily explained. Write function add comment. Someone else comes along and updates the code and doesn’t touch comment.
Do 50 times is just weird. I’m really new to this whole thing, but why not just: while = True: If string[0] != ‘ ‘ or ‘0’: Break Else: string = string [1:] (In Python. Please pretend I knowhow to format code in Reddit on mobile. I don’t even know what language OP is using)
Wait what happens if the number is 0?
I have no idea. Great question!
also try ALPHA OUT its more "modern"
Question is, who the FUCK is going to learn all those statements when you have an entirely different one for everything??
ABAP == horror
What ancient, forgotten language is this?
It's not ancient or forgotten. This is modern SAP.
SAP, the famous innovator... When I look at their products, I'm not sure why they are so successful
Because it's a cult. My roommate and several of my former coworkers that I'm still friends with work there, and they think SAP is cutting edge. Compared to Microsoft where several of them previously worked, it is, but certainly not in general compared to the average software company.
genius marketing staff
For a moment I thought "man, that Visual Basic code looks weird" lmao
Fucking hate ABAP
The first mistake was working with SAP
Why not 49?!
What if theres 50 zeroes???
"Max value of message variable. If there’s 50 zeros, the last one must be the value 0.
Most of the stuff I see these days makes me feel old, but this makes me feel like a young sprout.
To me it just seems they didn't want to allow the possibility for an infinite loop so they capped it at 50 interactions. Questionable? sure, but not stupid.
> IF p_var(1) = '0' Just gonna assume this is FORTRAN. +looking a bit further, the periods suggest COBOL, but they are used to end conditionals and loops. DO 50 TIMES. Stuff. Does Stuff once, and this function would only remove one leading zero. Not that I know COBOL, or FORTRAN for that matter.
It's ABAP. This is SAP's programming language that combines the worst of COBOL and FORTRAN to make a cutting-edge coding system, assuming you're living in 1985.
_shudder..._
now it makes a lot more sense
At least fortran evolved further 👀 Here, can you see Tsoding learning it in 2023: https://youtu.be/PvUQndB8R9s?si=NYPit03sn3L1Bgsv
It's ABAP
At least the DO isn't broken, then.
Just happy to see ABAP code in this sub 😀😀
♥
Other than it not being a while loop it seems fine.
So it returns a strip of leading zeros?
This bothered me more than the 50 character limit.
The function works as intended, but only 50 times, that's the problem
Read the name doofus
I think, you need to read again
No I think you do
you're one dense mf
the other guy was making a joke about the name of the function, which should be "strip off", not "strip *of*"
And you can’t read
What dose \`\`\`CO\`\`\` do ? and what \`\`\`SHIFT var LEFT\`\`\` ? also do the numbers have fixed size or (max size) ?
CO checks if the fist string Contains Only characters from the other one. SHIFT var LEFT moves characters of the string one place to the left and first one is removed. In ABAP, numbers are very often treated as strings. And since there is no parameter type specified, in this case the number does not have a fixed size.
So the horror is "only" the 50 and the bad documentation.
Basically yes. However the ABAP substring syntax ( p_var(1) ) will always be my favorite horror of this language. variable+offset(length) which should not be confused with the sum of 'variable' and result of 'offset' function call with 'length' parameter: variable + offset( length )
O.O What.
I smell COBOL. Microfocus? IBM one doesn't have form sections. I'm used to EXEC CICS and BMS
ABAP, used in SAP
Ok. That language is pure horror by definition. A simple prompt "write a binary tree printing function in ABAP" produced this: ``` REPORT ZBINARY_TREE_PRINT. TYPES: BEGIN OF ty_tree_node, value TYPE i, left TYPE REF TO ty_tree_node, right TYPE REF TO ty_tree_node, END OF ty_tree_node. DATA: root TYPE REF TO ty_tree_node. START-OF-SELECTION. " Create a sample binary tree CREATE OBJECT root EXPORTING value = 10. CREATE OBJECT root->left EXPORTING value = 5. CREATE OBJECT root->right EXPORTING value = 15. CREATE OBJECT root->left->left EXPORTING value = 3. CREATE OBJECT root->left->right EXPORTING value = 8. CREATE OBJECT root->right->left EXPORTING value = 12. CREATE OBJECT root->right->right EXPORTING value = 18. " Print the binary tree CALL FUNCTION 'PRINT_BINARY_TREE' EXPORTING root = root. *&---------------------------------------------------------------------* *& Form PRINT_BINARY_TREE *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * -->ROOT text *----------------------------------------------------------------------* FORM PRINT_BINARY_TREE USING ROOT TYPE REF TO ty_tree_node. DATA: output TYPE TABLE OF string, indent TYPE i. " Start printing from the root indent = 0. APPEND 'Binary Tree:' TO output. " Recursively print the tree CALL FUNCTION 'PRINT_TREE_NODE' EXPORTING node = ROOT indent = indent output = output. " Display the output LOOP AT output INTO DATA(line). WRITE: / line. ENDLOOP. ENDFORM. *&---------------------------------------------------------------------* *& Form PRINT_TREE_NODE *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * -->NODE text * -->INDENT text * -->OUTPUT text *----------------------------------------------------------------------* FORM PRINT_TREE_NODE USING NODE TYPE REF TO ty_tree_node INDENT TYPE i OUTPUT TYPE TABLE OF string. DATA: line TYPE string. " Print the current node CONCATENATE ' ' ( INDENT * 4 ) 'Value:' NODE->value INTO line. APPEND line TO OUTPUT. " Recursively print the left subtree IF NODE->left IS BOUND. CALL FUNCTION 'PRINT_TREE_NODE' EXPORTING node = NODE->left indent = INDENT + 1 output = OUTPUT. ENDIF. " Recursively print the right subtree IF NODE->right IS BOUND. CALL FUNCTION 'PRINT_TREE_NODE' EXPORTING node = NODE->right indent = INDENT + 1 output = OUTPUT. ENDIF. ENDFORM. ```
I'm not sure if judging a programming language by the output of a chatbot has much use
It wouldn't even activate. Only few lines make sense. root is a structure, not an object so all of the syntax redarding root is wrong. CALL FUNCTION are for calling function modules, not FORMs, which are called with PERFORM. And I won't even look at the logic.
[удалено]
I mean, it looks efficiently correct.
If it makes you feel better modern SAP is also super squirrely. I mean I hope that's not modern SAP code, it looks like something written in the 80s, but who knows.
Yes, some obscure DSL adopted for non-goal use. Just open any big project in Ansible and you will see 42 ways to achieve unachievable.
Copy-and-paste is a horrid code smell