on 02-21-2005 3:34 PM
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Brian,
you are an absolute gentleman.
Tomorrow, at work, I shall test this, and provided success is reached I'll make a blog 'Creating your first OO ABAP Class' and credit it to your good self.
I have the book by the way (well it's three books), probably about time I opened it and had a look.
Thanks for getting me started, this is much appreciated.
Tomas.
It reminds me about first English book I read. After 2 pages I gave up. And then I went to the school library one afternoon. There the librarian was reading out of a book about 20 pages to a group of children. I went back everyday! Afterwards I took that book home, and it the first English book I read. It then turned out not to be so difficult. All that was needed was that first "help" to just feel confident that I can do it. Read nearly the whole school library through as child.
Thanks Brian, you really gave me a good headstart, much appreciated.
I'll keep going on my own and only come back if I get really stuck.
Mean time, for everyone else, this thread became a blog !
/people/tomas.altman/blog/2005/02/22/how-to-create-your-first-oo-abap-class-for-a-bsp
and by the way, for anyone reading this having their first go at putting re-useable functionality into abap classes, you might want to know how to call a class from a BSP and in the call pass the exporting parameters to the method and get back the importing parameters from the method into your BSP... well here's how:
Y_YOUR_CLASS=>YOUR_METHOD(
Exporting:
Attribute = Attribute
Attribute = Attribute
Importing:
Attribute = Attribute
).
Tomas.
At this point it might be added that one should not go much further without gaining some basic knowledge about OO, especially the difference between classes and objects.
As I trained two of my workmates earlier this week in WebAS-technology, dealing with all the OO and MVC stuff, this was one of the points I had to explain really thoroughly, as they got confused by the different selectors, <b>=></b> being used for classes and <b>-></b> being used for objects.
This topic is so vast, one could write a book about it ... glad a lot of people already did, so grab yourself the nearest one and give it a go
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Thomas,
many thanks for your speedy reply.
The SAP Help link you post is in the same section as the one I posted, and although it gives a very nice overview it doesn't have a get you started end to end example.
I think I have checked all the OO-Abap blogs and not found the information I am looking for.
I'll keep hunting and check your next weblog to see what I can gleen there.
When I get the answer I'll make a beginners guide to creating Abap classes.
Thanks,
Tomas.
Although both of the following links focus on local classes as opposed to global ones, you might still find them interesting:
http://www.sapgenie.com/abap/OO/
http://www.futureobjects.de/content/intro_oo_e.html
The were originally posting in the following ABAP thread:
User | Count |
---|---|
101 | |
13 | |
13 | |
11 | |
11 | |
7 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.