Skip to Content
author's profile photo Former Member
Former Member

Creating First Class

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.

Add a comment
10|10000 characters needed characters exceeded

Related questions

2 Answers

  • Best Answer
    Posted on Feb 21, 2005 at 07:28 PM

    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

    Add a comment
    10|10000 characters needed characters exceeded

    • 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 😉

  • Posted on Feb 21, 2005 at 03:56 PM

    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
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.