on 2020 May 26 9:51 AM
hi i am fresher and learning abap. while going through do and enddo statement. i wanted to create a diamond shaped output.
*
* *
* * *
can anyone help me to create the above output by playing in write statement or do, enddo loop statements.
Request clarification before answering.
Hello karoncdas_31
Maybe something like this?
PARAMETERS: p_size TYPE i.
DATA:
lv_size TYPE i,
lv_size_even TYPE flag,
lv_step_size TYPE i,
lv_number_of_stars TYPE i,
lv_number_of_spaces TYPE i.
lv_size = p_size.
lv_size_even = xsdbool( lv_size MOD 2 = 0 ).
lv_step_size = 1.
lv_number_of_stars = 1.
IF lv_size_even = abap_true.
lv_number_of_stars = 2.
ENDIF.
DO lv_size TIMES.
lv_number_of_spaces = 0.
IF lv_number_of_stars <> lv_size.
lv_number_of_spaces = ( lv_size - lv_number_of_stars ) / 2.
ELSE.
IF lv_size_even = abap_true.
IF lv_step_size = 0.
lv_step_size = -1.
ELSE.
lv_step_size = 0. " double center line
ENDIF.
ELSE.
lv_step_size = -1.
ENDIF.
ENDIF.
WRITE / ' '.
DO lv_number_of_spaces TIMES.
WRITE ' '.
ENDDO.
DO lv_number_of_stars TIMES.
WRITE '*'.
ENDDO.
DO lv_number_of_spaces TIMES.
WRITE ' '.
ENDDO.
lv_number_of_stars = lv_number_of_stars + ( 2 * lv_step_size ). " times two, because from both sides
ENDDO.
Kind regards,You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello Karon
What is it that you do not understand?
As far as the ABAP keywords go, you could paste the code into your ABAP editor, put cursor on any of the keywords and press the F1 button. This will show you the built in ABAP Help. I would strongly encourage you to read it first. It really gives a lot of valuable information, especially if you're new to the language.
Kind regards,REPORT.
WRITE 'Hello world'.
Use the debugger for understanding the logic. It's the same as for any other programming language.
User | Count |
---|---|
6 | |
2 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.