Hi Everybody,
I have created quite a large BSP application with screens and background workflow processes.
The background workflow processes include for example, sending emails and saving and reading long texts.
Currently each of my pages in their initialisation and oninputprocessing events I have lots of send email and read and save text abap code.
I would like to create a class to contain the sending emails and reading and saving long texts functionality so that I don't have to keep repeating pages of the same code and making changes in multiple places when I find an improvement.
But... with creating classes I don't know where to start, I've looked at the blogs, and the sap help doco (http://help.sap.com/saphelp_nw04/helpdata/en/d3/2e974d35c511d1829f0000e829fbfe/frameset.htm) but I have not yet found a 'How to create a class' example from the beginning to the end.
If I try myself I get a bit overwhelmed, in SE80 I go Class Interface create and then I am presented with a screen containing options:
Properties
Interfaces
Friends
Attributes
Methods
Events
Internal Types
Aliases
Constructor
Class Constructor
does a How to Create a Class document/blog exist, and if no, are there anywhere pointers on where to start, if the doco/blog is missing then once I've cracked my first example I'll make a blog.
Thanks for your time,
Tomas.
I see that today is our community day to help Tomas create his first class. There after life becomes easier. So here the 47 easy steps to create your first class.
Let us assume that we attach this problem of "saving a long text" first.
*) Start SE80, select Class/Interfaces in that small dropdown listbox.
*) Type in the name of your new class, ex: ZCL_MY_FIRST_CLASS.
*) Follow all the instructions on screen to create a simple class as $TMP. Don't worry about any options.
*) On the right you have all those tabs. Select Methods.
*) Type in name SAVE_LONG_TEXT, change the following to attributes to PUBLIC and STATIC. (The "why" is described in the documentation, and not important immediately.)
*) Slightly above the name, there is a button called Parameters. Hit once.
*) In the new list that is displayed, enter a parameter. You should will in "text,type,string". Don't set checkboxes.
*) Save and then generate (burning match icon in toolbar).
*) Now we must write some code. Expand tree on left to get to methods, and then your method. Double click.
*) In editor on the right, enter the following code:
DATA: myText TYPE string. myText = text. TRANSLATE myText TO UPPER CASE.
*) Just in case you were wondering, that code does just about nothing. It is just there so that you can see it again in the debugger. Later you can replace this code.
*) Don't panic.
*) Light that match again (control-F3).
*) Now go to your BSP application, in the onX event where you always do you saving.
*) Write this line of code:
ZCL_MY_FIRST_CLASS=>SAVE_LONG_TEXT( text = 'Hello World' ).
*) Save and activate. Set a break-point just before this method.
*) Drink coffee. Read SDN. Do anything, just don't think about testing it. Don't panic.
*) Go! Test it. When you hit the debugger, step into (F5) the method call. See the parameter is suddenly available. Double click on it. Watch it change into upper case.
*) If it did not work, swear (once only!), write us agian.
*) While you wait, consider to read that documentation link.
*) There is a good book, called ABAP Objects by Horst Keller. Take it with you to the beach in summer!
brian
Have you tried the following link from the on-line help:
http://help.sap.com/saphelp_nw04/helpdata/en/ca/c035baa6c611d1b4790000e8a52bed/frameset.htm
It is a nice introduction to the class builder itself. There are several Weblogs on the topic of ABAP OO, but I don't know if there is one that is a tutorial of how to use the class builder or building your first class.
I am writing a weblog right now on how to create an ABAP dialog report as an ABAP OO Class, which I should post later today. Its probably not exactly what you are looking for, but does contain some of the basic concepts.
Add a comment