‎2021 Mar 22 3:53 PM
Hey there,
I want to make a program printing the numbers 1 to 100 without using any numbers or loops.
I also made a recursive function in ABAP.
But i have no clue hot to get 0 and 1 without using numbers in ABAP.
May you have an idea?
//example in Javascript
const one = +true; // This would return 1 (Unary and boolean operator)
const zero = +false; // This would return 0 (Unary and boolean operator)
// Using string operations apending 1 and 0 and 0 to form "100"
const hundredInString = one.toString() + zero.toString() + zero.toString();
// To save the day for not using the loop, we are using recursion
function.const printInRecursion = (index) => {
if (index <= parseInt(hundredInString)) {
console.log(index);
printInRecursion(index + one);
}
return
}
printInRecursion(parseInt(one))
‎2021 Mar 22 4:05 PM
calculate the length of an empty string with STRLEN to get 0.
Edit: You can also take advantage of SY-SUBRC or other system variables.
‎2021 Mar 22 6:51 PM
Excellent.
Ask Basis to set up instance 001.
DATA(one) = sy-sysid.
‎2021 Mar 22 4:06 PM
Cool, that sounds like fun! 🙂
How about something that counts something, would that be ok... like strlen?
DATA(zero) = strlen( '' ).
DATA(one) = strlen( 'a' ).
‎2021 Mar 22 5:47 PM
Many hundreds of years ago, I was learning to program on my first computer - a ZX81. Memory was limited, so the community worked out ways of conserving it.
A number took maybe 5 bytes. But PI (a keyword) was a constant, with a value encoded in ROM. So for 1 we had PI / PI. And for 0 we had PI - PI. Both of which used less memory. Which is important when you're trying to squeeze 3D Monster Maze into 16K.
From the sublime to the ridiculous
DATA zero TYPE i.
DATA(one) = zero - sign( zero - sign( 2 ) ).
SELECT * FROM a_huge_db_table INTO @data(oh_this_is_utterly_ludicrous).
DATA(one) = lines( oh_this_is_utterly_ludicrous ) / lines( oh_this_is_utterly_ludicrous ).
‎2021 Mar 22 6:49 PM
Bonus points if you know where "Oh, this is utterly ludicrous" comes from.
‎2021 Mar 29 10:34 PM
Function distance() was created for that
DATA(zero) = distance( val1 = abap_true val2 = abap_true ).
DATA(one) = distance( val1 = abap_true val2 = abap_false ).