Additional Blogs by Members
cancel
Showing results for 
Search instead for 
Did you mean: 
Former Member
0 Kudos
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:

method READ_LONG_TEXT .

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.

DATA: C_OBJECT(10)  TYPE C    VALUE 'PUT_YOUR_TEXT_ID_HERE'.  

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.

 CALL FUNCTION 'READ_TEXT'

   EXPORTING

      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'

   IMPORTING

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

   TABLES LINES = t_tlines

   EXCEPTIONS

      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

      WRONG_ACCESS_TO_ARCHIVE = 7.

  append s_tlines-tdline to ltext2.

endmethod.


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:

YCL_AS_FIRST=>READ_LONG_TEXT( C_ID = 'PUT_YOUR_ID_HERE' ).

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.

3 Comments