Every ABAP training material start from concept as i found so far. Most of them are boring and of course, I lost in the sea of document — especially in SAP online help. Fortunately my workmate Alex Yu, a experienced ABAPer, show me an example and drag me out from the mire in just one hour.
It works because I have learned C/C++ before. And start from an example help me to find the similar and difference between C/C++ and ABAP. Hope it also works for you guys.
- With SAP experience
- With programming experience
- Want to create a workable ABAP program
Before Take Action
SE80 -> Utilities -> setting -> ABAP Editor, choose Front-End Editor(New). It may not support by old version.
Go Go Go !
1. T-Code: SE80
Choose Program from the following list.
Pick a name for your program. Assume Z_SCREEN here.
2. Choose “Yes” to create the program if it is not exist in our system.
Deselect the check box “With TOP INCL.”. We do not need it at this scenario.
3. Choose “Module Pool” in the Type below Attributes. Since the default type is Executable program, the program type will change from type 1 to type M.
Choose “Test Program” in the Status.
Press Save Button to continue.
4. Press “Local Object” in the pop up screen
And you will see “Program Z_SCREEN saved” at the status bar.
5. Select Z_SCREEN from left panel and right click to open the context menu. Choose Create -> Screen
6. Input screen number “9000”, continue.
In the attribute tab, input the short description. Such as “First Screen”
In Element List -> General Attr., input “OK_CODE_9000” and press Enter. I will explain why we need it later.
7. Press the “Layout ” button at tool bar (Ctrl+F7)
And you lead you to the Screen Painter.
Choose “Text Field” as marked in bellowing, drag it and input the Name and Text as show below.
Click save and click the “Flow logic” in the tool bar.
8. And you can find we back to here:
“Process before output” means you can do something when creating the screen. And “Process after input” means when you input something or click some bottom, system will response your action.
Check the following URL if you want to get the total picture of ABAP: http://help.sap.com/saphelp_47x200/helpdata/en/54/57fe0c786a11d194c90000e8353423/frameset.htm
9. We will use the default name of module generated by system here.
Remove the star “*” at 2nd line of our code.
Double click STATUS_9000.
System will ask you whether to create Object. Click Yes
Then system pop up a screen to ask where do you want to put PBO module. Since we will put all of our code in main program and do not want to create a lot of include files, we choose the 2nd one (And same as afterward), Z_SCREEN main in program, and continue.
And we active the code in 16 and 17(Remove the * ahead of them), change the default “XXX” as green part showed below. Save.
10. Double Click “GUI9000” in green , click Yes to create it.
Fill in short text “GUI9000” and continue.
11. And we will create 2 buttons in Application Tool bar here.
Click the red part to expand the content.
Input NEXT in the first column and press Enter. Then continue.
Input the information as below: Function text “NEXT”, Info. Test “Next Screen”. Continue.
The following screen is “assign function to function key”. F2 is not recommended. We pick F5 here. Double Click the F5.
And create EXIT button as same as above. Following is the description. And we pick F6 as function key.
12. Let’s move to the next step. Fulfill the following content for BACK button in standard toolbar. press Enter.
13. Let’s Double click STATUS_9000 and back to the code.
Double click “FIRST_SCREEN” in green to create the GUI Title.
14. Let’s create some code to response the action when you click the buttons. As we mentioned before, it should place at “Process after input”
Double click 9000 under screens on the left panel. Find the code at right.
Remove the “*” at the line 5 and double click USER_COMMAND_9000 to create the module. Choose the “main program” at the second line. We will create it here.
Input the code as showed from 29 to 36. ABAP seems not sensitive to capital char. : P But it is a good habit to use capital char. in key words. Key words are showed in blue if you apply the new style of front-end editor.
The syntax is quite easy to understand. I only want to explain why we use ok_code_9000 here. The screen collects your action by function code and function key. They will pass to system then system will response them. So we need clear ok_code_9000 after we receive the action from user.
Try to type or modify the code by yourself. Practice makes excellent.
But we have not declare the ok_code_9000 yet. Add code as showed in line 11. Of course you can create it by double click ok_code_9000 (line 29 in below)
15. Since we call a new screen 9001 as showed in line 32 at our code, we need to create it. Save whenever system request.
Attributes -> Short Description: 2nd Screen.
Element list -> General attr. : OK_CODE_9001, Enter.
Go to layout.
Add a label to show that this is 2nd screen. And we will create 2 buttons instead of using application tool bar in 2nd screen. The button component are marked as red in the left.
Double Click the button and pick a FctCode at the pop up screen. We choose “PREV” here. Close the dialog direct – I don’t know why we do not need to save it.
And create another button, with Fctcode “EXIT”
Save and back to flow logic.
16. Delete the “*”, double click STATUS_9001 to create the module. You must familiar with this process and know what will happen in the next step.
Create PBO module in main program. And also, create GUI status and GUI title.
We won’t create button in application toolbar and we only take “BACK” in this time.
And of course, double click SECOND_SCREEN to create GUI Title. We name it “SECOND_SCREEN”.
17. Back to Screens 9001, create code for our buttons in PAI(Process after input).
Remove the * at line 5, double click USER_COMMAND_9001 to create it in main program.
Create our code from line 56 to line 66. Of course, don’t forget declare ok_code_9001 at line 12.
18. Congratulation, we have finish the program! But just a minute. Since we are creating a program in M type, type = module pool, which means we cannot execute it directly.
So we need to create a T-Code for our program. Select Z_SCREEN from left panel and right click to open the context menu. Choose Create -> Transaction
You can choose to support HTML/Java/Windows.
Save, Local Object.
19. Active all your components if you haven’t do that.
20. Try to run your program through your T-Code: Z_SCREEN !
Some basic information on ABAP:
Find the sample code by this T-code: ABAPDOCU. Just read the sample code and check the usage of key word from above URL.
Pay attention on following topic for further study:
- Internal Table
- Report and interactive report
- SAP Script
- Smart Form