[MAC] Mini ABAP "Course"
- WRITE, DO, IF
Hello Hello,
welcome to MAC - an easily digestible "course" about ABAP coding. This course contains the necessary knowledge you need to have in order to succeed in *the WOV CODING challenge* that is coming (check it at the bottom of this page).
So once again, I'm glad you're here. No more words needed.
Let's have fun. :)
Regards,
P.S.
I'm not your supervisor here. I'm in this challenge with you as a Learner. Your instructor is the Founder of ABAP Academy Ladislav Rydzyk.
He is the best of the best (Créme de la Créme).
If you don't believe just ask hundreds of his co-workers and graduated students. Till now, I didn't meet anybody who says something bad about him as a professional but also as a person.
Are You Ready to Start?
"It's sounds good but I don't have time!"
I know, you might say, "I don't have time for that, Tom!". And Yes, I can understand that we're living in a busy world ...
BUT
Don't you find 20 minutes of your precious time to discover whether you can enjoy coding?
To be precise, 20 minutes and 8 seconds :).
That's all you need to commit.
Are you ready to start?
For you guys who said YES. Let's Begin :)
What Do I Need Before Start?
You need only sanbox for practicing => SAP system with developer rights
If you don't have one, here's the ABAPeditor [FREE] web based SAP system, which has every functionality you need in this course.
Lecture #1: Hello World
Say Hello :)
Generally, a "Hello, World!" is a very simple program in most programming languages, and is often used to illustrate the basic syntax of a programming language [1].
It is often the first program written by people learning to code. It can also be used as a sanity test to make sure that computer software intended to compile or run source code is correctly installed, and that the operator understands how to use it [2].
So, How can you do it in ABAP?
Ladislav's explaining different variations in the video.
Time to watch 5:36
Here is Program Outline, so you can easily copy & paste it into ABAPeditor.
*&---------------------------------------------------------------------*
*& Report <your_prefix>_LIB_BASIC_01_WRITE
*&
*&---------------------------------------------------------------------*
*& Description:
*& Demonstration of WRITE statement
*&
*& Technical description:
*& - Hello World basic output using a non-translatable technique
*&
*& More Information:
*& - http://help.sap.com/saphelp_470/helpdata/en/9f/db9e2335c111d1829f0000e829fbfe/content.htm
*&
*&---------------------------------------------------------------------*
*& Change log:
*& Date Author Action
*&
*&---------------------------------------------------------------------*
*REPORT <your_prefix>_LIB_BASIC_01_WRITE.
*-----------------------------------*
* DECLARATIONS
*-----------------------------------*
* MAIN LOGIC
*------------------------*
* Hello World
WRITE 'Hello World'.
" Non-translatable way
" Output "Hello World" using hardcoded text
" Output "Hello World" using hardcoded text in new line
" Output "Hello World" using chained hardcoded text
Lecture #2: WRITE - additional rules
Outputting on the screen have many rules,
here are the most frequent ones.
Time to watch 6:18
Here is Program Outline, so you can easily copy & paste it into ABAPeditor.
*&---------------------------------------------------------------------*
*& Report <your_prefix>_LIB_BASIC_01a_WRITEADD
*&
*&---------------------------------------------------------------------*
*& Description:
*& Demonstration of WRITE statement
*&
*& Technical description:
*& - Using additional frequently used WRITE options
*-----------------------------------*
* DECLARATIONS
*-----------------------------------*
* MAIN LOGIC
*------------------------*
* Additional WRITE options
format color = col_heading.
WRITE: / 'Additional WRITE options'. skip.
FORMAT COLOR = col_background.
WRITE: / 'WRITE {[AT] [/][pos][(len|*|**)]} dobj [UNDER other_dobj] [NO-GAP]'.
" Display string starting from position 20
" Display string starting from position of 'Hello World' string
" Display 16 characters long string starting from position 20 -> Output: "WRITE /20(16)"He"
" Display part of string variable; Starting from position 14, displaying 10 characters
" Display part of character variable; Starting from position 14, displaying 10 characters
SKIP. "Skip one line (New Line)
ULINE. "create horizontal line
Lecture #3: IF statement
You don't need to be a mathematical genius to start Coding.
But One thing you need to handle ... Conditions.
Time to watch 5:50
Here is Program Outline, so you can easily copy & paste it into ABAPeditor.
*&---------------------------------------------------------------------*
*& Report <your_prefix>_LIB_BASIC_04_CONDITIONS
*&
*&---------------------------------------------------------------------*
*& Description:
*& Control Program Flow Logic
*&
*& Technical description:
*&
*& More Information:
*&
*&---------------------------------------------------------------------*
*& Change log:
*& Date Author Action
*& xxx-xx-xx ABAP_ACADEMY Created
*&
*&---------------------------------------------------------------------*
*REPORT <your_prefix>_lib_basic_04_conditions.
*----------------------------------*
" DECLARATIONS
*----------------------------------*
" MAIN LOGIC
*-----------------------------*
" IF - ELSEIF - ELSE statement
FORMAT COLOR = col_heading.
WRITE: / 'IF - ELSEIF - ELSE statement'. SKIP.
FORMAT COLOR = col_background.
WRITE: / 'Current Time: ', sy-uzeit.
" Say hello to user
" Say: "Have a good morning USERNAME", when it is morning
" Say: "Hey, have a good day USERNAME", when it is day time
" Say: "Have a good night. Do not work too much ;)", when it is already evening or night
Lecture #4: DO cycle
What about repetition? What if you need to repeatedly do some operation? The answer in the video.
Time to watch 2:24
Here is Program Outline, so you can easily copy & paste it into ABAPeditor.
*&---------------------------------------------------------------------*
*& Report <your_prefix>_LIB_BASIC_05_CYCLES
*&
*&---------------------------------------------------------------------*
*& Description:
*& ABAP Cycles
*&
*& Technical description:
*&
*& More Information:
*&
*&---------------------------------------------------------------------*
*& Change log:
*& Date Author Action
*&
*&
*&---------------------------------------------------------------------*
*REPORT <your_prefix>_LIB_BASIC_05_CYCLES.
*-----------------------------------*
* DECLARATIONS
CONSTANTS:
gc_number_of_rows TYPE i VALUE 10.
CONSTANTS:
BEGIN OF gc_cycle_colour,
do_x_times TYPE i VALUE 4,
do_endless TYPE i VALUE 3,
inner_do_x_times TYPE i VALUE 7,
while TYPE i VALUE 6,
END OF gc_cycle_colour.
DATA:
gv_mod_result TYPE i.
*-----------------------------------*
* MAIN LOGIC
*-----------------------------*
" DO x TIMES Cycle
FORMAT COLOR = col_heading.
WRITE: / 'DO x TIMES Cycle'. SKIP.
FORMAT COLOR = col_background.
SKIP.
ULINE.
Congratulation
You're ready Now.
Check the CODING CHALLENGE below.