Skip to Content
Creating an OO ABAP Class for Reading a Long Text from an Event in a BSP

Start SE80, select Class/Interfaces in that small dropdown listbox

Type in the name of your new class, eg: YCL_FIRST_CLASS

Click on the glasses to create the Class as shown:


Complete the details in the next popup and click SAVE as shown below:


Complete the details of the next popup and enter the name of the package and for this example click on Local Object as shown below:


Double click on the name of your Class on the left and then click Display Change and the click on Methods, you will now have the following screen:


Enter the name of your first method, for this example READ_LONG_TEXT, for Visibility select Public and for Level select Static for this example as shown below:


Click on the Paramters button above the Methods column name. Enter the parameter C_ID with Type IMPORTING and Associated Type THEAD-TDID as shown below:


Click Save and then click Activate and your screen will now look like the one below:


Expand the tree on the left side and under Methods double click on your method READ_LONG_TEXT, the method editor screen will then open up as shown below:


Enter the code for the method, in this case as below:


types: ts_tlines type tline.

types: tt_tlines type table of ts_tlines.

Data: t_tlines type tt_tlines.

Data: s_tlines type ts_tlines.

Data: ltext2 type htmltable.

Data: it_thead type thead.


MOVE:   C_OBJECT TO   it_thead-tdobject,

       notenbr_i style=”mso-spacerun: yes”>  TO   it_thead-tdname,

       C_ID style=”mso-spacerun: yes”>       TO   it_thead-tdid,

       sy-langu style=”mso-spacerun: yes”>   TO   it_thead-tdspras,

       132 style=”mso-spacerun: yes”>        TO it_thead-tdlinesize.



      ID style=”mso-spacerun: yes”>             = it_thead-tdid

      LANGUAGE style=”mso-spacerun: yes”>       = sy-langu

      NAME style=”mso-spacerun: yes”>           = it_thead-tdname

     OBJECT style=”mso-spacerun: yes”>         = ‘YBSMRQ_TXT’


      HEADER style=”mso-spacerun: yes”>         = it_thead

   TABLES LINES = t_tlines


      ID style=”mso-spacerun: yes”>                      = 1

      LANGUAGE style=”mso-spacerun: yes”>                = 2

      NAME style=”mso-spacerun: yes”>                    = 3

      NOT_FOUND style=”mso-spacerun: yes”>               = 4

      OBJECT style=”mso-spacerun: yes”>                  = 5

      REFERENCE_CHECK          = 6


  append s_tlines-tdline to ltext2.


Now, click on the Activate button in the upper menu and now your class will be activated

In your BSP in one of the events, enter this line of code:


Save and activate. Set a break-point just before this method.

13, 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.

This blog was written from information given by Brian Mckellar in one of the BSP forums where the author asked the same question as is covered by the blog.

Hopefully this blog will enable others to get started in the world of OO ABAP and adding classes to applications and calling them from a BSP.

To report this post you need to login first.


You must be Logged on to comment or reply to a post.

  1. Brian McKellar
    Hallo Tomas,

    Two small steps in one day! Not only did you write your first ABAP class, but also your first weblog! Welcome to the club. Of course, for those people that have written many classes, it might be difficult to understand the excitement. But for anybody that has until now until done “plain” ABAP, this is the first step into wonderful world of new possibilities.

    A very minor nit: In the source code you show, “endloop” seems to be a cut-and-paste error.

    While I am at it, let me show you a small trick that a real guru taught me long time ago. Often we would like to call a method with a parameter that can be fed a string, or a character sequence, or even a text literal. The calling sequences would be:

    data: str  type string, c255 type char255.
    class=>method( txt = str ).
    class=>method( txt = c255 ).
    class=>method( txt = ‘hello’ ).
    class=>method( txt = ‘hello again'(001) ).

    Especially this last call passing a text-literal is my favourite. So how to declare the parameter txt in the method so that it will accept all of these different types? The secret is to declare the parameter txt to be importing of type csequence (character sequence) and all four calls will work. If you should ask 10 ABAP experts about it, 11 will not know about it :).


      1. Tomas Altman Post author
        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:

                                   Attribute = Attribute
                                   Attribute = Attribute
                                   Attribute = Attribute



Leave a Reply