Local class - global class
Hi Friends,
Can a local class make friend with global class???
for example i have a local class in se38 editor and this local class should access the private attribute of global class which is there in se24.
Deepak
HI Deepak
Yo can define your ABAP Unit test class as a friend of the global class to be tested in the local class definition include of your global class. So, you have to add a line of code like
CLASS <name of global class to be tested> DEFINITION LOCAL FRIENDS <name of local ABAP Unit class> in the include where the definition of local ABAP Unit Class is in. Then you can call the private methods of your global class in the local abap unit class methods.
just refer these links
http://help.sap.com/saphelp_nw2004s/helpdata/en/ec/d9ab291b0b11d295400000e8353423/content.htm
local class -> global class
Regards Rk
Similar Messages
-
Export global classes to a local file
Hi,
is it possible to export a global class with all of its attributes, types, methods and more to a local file for archiving purposes?
We are currently using ECC 6.0, btw.
MichaelSure, via [SAPlink|http://code.google.com/p/saplink/]
Regards
Marcin -
How to export local class to global class in abap ?
is there any report that can export local class to a global class ?
thanks !Hi,
you can go to SE24 and there you can create a new class with reference to the class already created and your new class will have the same properties as your local class. -
Create Global Class Definition using Local Class Source Code
I would like to be able to automate the creation of global class definitions using source code that is defined in a text file (one example: convert a local class def to a global class def).
Does SAP deliver this functionality? (I'm already aware of the various classes that can be used to create global classes and how those classes can be implemented in a program to generate new classes. I'm hoping to avoid having to create a custom solution.)
Thanks in advance!We have a winner!
Thanks Rich!
It's not a 100% solution - I was hoping to be able to generate global classes/interfaces using source code alone, without requiring user intervention.
It <i>is</i> however, a 90-95% solution because debugging SE24 reveals that by using a combination of the FM's SCAN_ABAP_OBJECTS_CLASSES & SEO_CLIF_MULTI_IMPORT, I should be able to <u>quickly</u> put together that custom application that I was trying to avoid.
I knew about the existance of SEO_CLIF_MULTI_IMPORT but I did not know about SCAN_ABAP_OBJECTS_CLASSES. I'm very happy to learn that I'm not going to have to write a parser! -
Local class as a friend of a global class
Hi guys,
I'm just wondering if I could make a local class which is defined in the local section of a global class to its friend. I need this to check private attriutes and methods with abap unit.
Regards ChristianHi Christian,
Yo can define your ABAP Unit test class as a friend of the global class to be tested in the local class definition include of your global class. So, you have to add a line of code like
CLASS in the include where the definition of local ABAP Unit Class is in. Then you can call the private methods of your global class in the local abap unit class methods.
Regards,
Sükrü -
Download Global Class attributes
Hi...
I want to download the global class attributes into an excel. when i checked the menu there is no such option.. Is that possible to do.. Can anyone guide me...
Thanks in advance.
Kalpanashri Rajendran.Hi,
Assuming you are asking specifically about the global class "Attributes" and not all information about the global class itself. To get the "Attributes" in a spreadsheet you can try this work-around:
1. Run transaction SE84 Repository Info System.
2. Expand the "Class Library" branch.
3. Double-click the "Attributes" node.
4. Enter your global class name and run the search.
5. Once the list of attributes is displayed, choose menu path System -> List -> Save -> Local File.
6. Choose "Spreadsheet" format in the popup.
7. Give a file path and name for your spreadsheet.
8. You should now have a spreadsheet with all the "Attributes" of your global class.
Best Regards,
Jamie -
Event handling in global class (abap object)
Hello friends
I have 1 problem regarding events in abap object... how to handel an event in global class in se24 .
Regards
Reema jain.
Message was edited by:
Reema JainHello Reema
The following sample report shows how to handle event in principle (see the § marks)..
The following sample report show customer data ("Header"; KNB1) in the first ALV list and sales areas ("Detail"; KNVV) for the selected customer (event double-click) in the second ALV list.
*& Report ZUS_SDN_TWO_ALV_GRIDS
REPORT zus_sdn_two_alv_grids.
DATA:
gd_okcode TYPE ui_func,
go_docking TYPE REF TO cl_gui_docking_container,
go_splitter TYPE REF TO cl_gui_splitter_container,
go_cell_top TYPE REF TO cl_gui_container,
go_cell_bottom TYPE REF TO cl_gui_container,
go_grid1 TYPE REF TO cl_gui_alv_grid,
go_grid2 TYPE REF TO cl_gui_alv_grid,
gs_layout TYPE lvc_s_layo.
DATA:
gt_knb1 TYPE STANDARD TABLE OF knb1,
gt_knvv TYPE STANDARD TABLE OF knvv.
"§1. Define and implement event handler method
" (Here: implemented as static methods of a local class)
* CLASS lcl_eventhandler DEFINITION
CLASS lcl_eventhandler DEFINITION.
PUBLIC SECTION.
CLASS-METHODS:
handle_double_click FOR EVENT double_click OF cl_gui_alv_grid
IMPORTING
e_row
e_column
es_row_no
sender.
ENDCLASS. "lcl_eventhandler DEFINITION
* CLASS lcl_eventhandler IMPLEMENTATION
CLASS lcl_eventhandler IMPLEMENTATION.
METHOD handle_double_click.
* define local data
DATA:
ls_knb1 TYPE knb1.
CHECK ( sender = go_grid1 ).
READ TABLE gt_knb1 INTO ls_knb1 INDEX e_row-index.
CHECK ( ls_knb1-kunnr IS NOT INITIAL ).
CALL METHOD go_grid1->set_current_cell_via_id
EXPORTING
* IS_ROW_ID =
* IS_COLUMN_ID =
is_row_no = es_row_no.
* Triggers PAI of the dynpro with the specified ok-code
CALL METHOD cl_gui_cfw=>set_new_ok_code( 'DETAIL' ).
ENDMETHOD. "handle_double_click
ENDCLASS. "lcl_eventhandler IMPLEMENTATION
START-OF-SELECTION.
SELECT * FROM knb1 INTO TABLE gt_knb1
WHERE bukrs = '1000'.
* Create docking container
CREATE OBJECT go_docking
EXPORTING
parent = cl_gui_container=>screen0
ratio = 90
EXCEPTIONS
OTHERS = 6.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
* Create splitter container
CREATE OBJECT go_splitter
EXPORTING
parent = go_docking
rows = 2
columns = 1
* NO_AUTODEF_PROGID_DYNNR =
* NAME =
EXCEPTIONS
cntl_error = 1
cntl_system_error = 2
OTHERS = 3.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
* Get cell container
CALL METHOD go_splitter->get_container
EXPORTING
row = 1
column = 1
RECEIVING
container = go_cell_top.
CALL METHOD go_splitter->get_container
EXPORTING
row = 2
column = 1
RECEIVING
container = go_cell_bottom.
* Create ALV grids
CREATE OBJECT go_grid1
EXPORTING
i_parent = go_cell_top
EXCEPTIONS
OTHERS = 5.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
"§2. Set event handler (after creating the ALV instance)
SET HANDLER: lcl_eventhandler=>handle_double_click FOR go_grid1. " Or:
" SET HANDLER: lcl_eventhandler=>handle_double_click FOR all instances.
CREATE OBJECT go_grid2
EXPORTING
i_parent = go_cell_bottom
EXCEPTIONS
OTHERS = 5.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
* Display data
gs_layout-grid_title = 'Customers'.
CALL METHOD go_grid1->set_table_for_first_display
EXPORTING
i_structure_name = 'KNB1'
is_layout = gs_layout
CHANGING
it_outtab = gt_knb1
EXCEPTIONS
OTHERS = 4.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
gs_layout-grid_title = 'Customers Details (Sales Areas)'.
CALL METHOD go_grid2->set_table_for_first_display
EXPORTING
i_structure_name = 'KNVV'
is_layout = gs_layout
CHANGING
it_outtab = gt_knvv " empty !!!
EXCEPTIONS
OTHERS = 4.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
* Link the docking container to the target dynpro
CALL METHOD go_docking->link
EXPORTING
repid = syst-repid
dynnr = '0100'
* CONTAINER =
EXCEPTIONS
OTHERS = 4.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
* NOTE: dynpro does not contain any elements
CALL SCREEN '0100'.
* Flow logic of dynpro (does not contain any dynpro elements):
*PROCESS BEFORE OUTPUT.
* MODULE STATUS_0100.
*PROCESS AFTER INPUT.
* MODULE USER_COMMAND_0100.
END-OF-SELECTION.
*& Module STATUS_0100 OUTPUT
* text
MODULE status_0100 OUTPUT.
SET PF-STATUS 'STATUS_0100'. " contains push button "DETAIL"
* SET TITLEBAR 'xxx'.
* Refresh display of detail ALV list
CALL METHOD go_grid2->refresh_table_display
* EXPORTING
* IS_STABLE =
* I_SOFT_REFRESH =
EXCEPTIONS
OTHERS = 2.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
ENDMODULE. " STATUS_0100 OUTPUT
*& Module USER_COMMAND_0100 INPUT
* text
MODULE user_command_0100 INPUT.
CASE gd_okcode.
WHEN 'BACK' OR
'END' OR
'CANC'.
SET SCREEN 0. LEAVE SCREEN.
* User has pushed button "Display Details"
WHEN 'DETAIL'.
PERFORM entry_show_details.
WHEN OTHERS.
ENDCASE.
CLEAR: gd_okcode.
ENDMODULE. " USER_COMMAND_0100 INPUT
*& Form ENTRY_SHOW_DETAILS
* text
* --> p1 text
* <-- p2 text
FORM entry_show_details .
* define local data
DATA:
ld_row TYPE i,
ls_knb1 TYPE knb1.
CALL METHOD go_grid1->get_current_cell
IMPORTING
e_row = ld_row.
READ TABLE gt_knb1 INTO ls_knb1 INDEX ld_row.
CHECK ( syst-subrc = 0 ).
SELECT * FROM knvv INTO TABLE gt_knvv
WHERE kunnr = ls_knb1-kunnr.
ENDFORM. " ENTRY_SHOW_DETAILS
Regards
Uwe -
Using container from another global class
There are two global classes being used by me in a program - Class A and Class B.
Class A contains the container to display ALV.
Class B contains the logic to display ALV.
class B is used as attribute class in Class A.
How is that I can use the container from Class A from class B?Like this?
class A ...
public section.
methods: get_container returining value(ref_cont) type ref to ...,
constructor.
private section.
data ref_container type ref to....
endclass.
class A impl...
method get_container.
ref_cont = me->ref_container.
endmethod.
method constructor.
create object ref_container ....
endmethod.
endclass.
class B ...
public section.
methods: constructor,
display alv.
private section.
data ref_alv type ref to....
data ref_A type ref to A.
endclass.
class B impl...
method constructor.
data lr_container type ref to ...
if ref_A is not bound.
create object ref_A.
endif.
"get container from class A
lr_container = ref_A->get_container( ).
create object ref_alv
exporting
container = lr_container
endmethod.
method display_alv.
call method ref_alv->set_table_for_first_display...
endmethod.
endclass.
If storing container's reference under local LR_CONTAINER in class B constructor causes not displaying ALV, you will have to store this under class B attribute. Alternative would be directly indicating the container reference as parent to ALV by calling functional method like
create object ref_alv
exporting
container = ref_A->get_container( )
this will however work in recent releases of SAP NW AS.
Regards
Marcin -
Hi all,
I have a global class (created in SE24 - Class builder) and need to use constants and types in its methods, that are defined in an include.
In functional development we just put a "INCLUDE includename." in the function group top-include.
Where can I put that include in the global class?
I tried the "local types" source file, but it doesnt accept the constant definitions inside my include.hi, Frank Besler
If you want to add global (constant)value and type definantion, you can add them in the LXXXXTOP file, the XXXX is the function group name.
if you don't want all of the defination added only one file, you can create a file, named LXXXXFYYY, XXXX is still function group, YYY is the random string you set.
and add the 'include LXXXXFYYY' into the SAPLXXXX. (XXXX is still function group name). SAPLXXXX is the main program for the function group, you can find its name in the 'Attributes' tab 'Program name' fields in se37.
click the SAPLXXXX, you can see a example like this:
* System-defined Include-files. *
INCLUDE LATSVTOP. " Global Data
INCLUDE LATSVUXX. " Function Modules
* User-defined Include-files (if necessary). *
* INCLUDE LATSVF... " Subprograms
* INCLUDE LATSVO... " PBO-Modules
* INCLUDE LATSVI... " PAI-Modules
* add your include file here
include LATSVF01.
Please aware the your include file name can't be set random, you must follow the rule, otherwise the compile will failed. -
Hii,
How to create an internal table in Global class of Abap object.
please reply me.
regards.
Reema jainHello Reema,
Follow these steps :-
 Go to transaction SE24.
 Enter the name of the global class you want to create, with Y or Z at the beginning.
 Press Create pushbutton.
 A dialog window shown above will appear. Check the radiobutton : Class.
 Press Enter.
 Another dialog window shown above will appear. Enter the description for the class.
 Select from the Instantiation listbox whether you want to create the class as PUBLIC/PROTECTED/PRIVATE/ABSTRACT.
 Check the radiobutton for Usual ABAP Class.
 Check the checkbox for Final.
 Press Save pushbutton
Enter the package name or save it as Local object.
 Go to the tab-page : Methods.
 Enter the details for the method mention name, type of method(instance/static), in which visibility section the method will reside and a short description of the method.
 Check off/uncheck the checkbox to ensure that the method will be implemented
Click the pushbutton for Parameters to navigate to the screen to enter parameters for the method.
<b>Here you can give the name of an internal table with associated type TABLE</b>
Rewards points if helpful
Thanks,
Sachin -
Access global data of report in global class methods?
Hi all,
I have defined one global class in SE24 and i am using methods of this class in report program.
Can i access global data of my report program in class methods directly without declaring it as IMPORT
parameter?
Thanks,
ApitaHi,
Well, now you did confuse me: first you asked about using global data of a report program in global class (created in SE24), and the answer is: no, you can't directly access the global data of another program in a method of global class (yes, you should pass them via importing parameters), and you shouldn't even consider using indirect means of doing so via special form of ASSIGN statement reserved for internal use by SAP. The ASSIGN will not work if someone reuses the global class elsewhere in the system without loading your report. Don't ever program such atrocious dependencies in global class...
And now you ask about the use "in method implementation in report program"..? Just to be sure - you can't program the implementation of a global class method in a report program.
You can program a local class inheriting from a global class and redefine/re-implement methods of such global super-class in a report program. Global data of report program, including the selection screen, would be directly accessible to such local class. It would still not be a good idea to use this access:
Conversely, within an encapsulated unit, that is, within a class, you should avoid accessing more global data directly. Within methods, you should generally modify attributes of the class only. Write access to global data outside the class is not recommended. Accessing data in this way should only be done using specially marked methods, if at all. The use of methods of a class should not evoke any side effects outside the class itself.
cheers
Jānis
Message was edited by: Jānis B -
Hi everybody.
I want export a global class (SE24, Object Builder) to a local class in a INCLUDE, but unfortunally the Object Builder has no export function.
Does anybody know a way to change a global class to a local class?
Thx.There's no easy way. I'm at a bit of a loss why you'd want to replace a global class witha local class that you include in your programs. What do you gain?
But if you insist, you can always cut and paste the public/private/protected sections of your class (making suitable modifications and assuming you're not on an old SAP version), and then you'd have to cut and paste the method implementations in as well.
Printing a class to a the spool is a fairly good way of getting all its details. Another alternative is to search these forums for where the includes that actually make up the class are - it should be fairly simple to write a program that would take that source code and construct local classes from it. But I still don't see the point. -
Export global classes into program
Hello,
it is possible to import local classes from program into
class builder.
I would like to export global classes into program. Is there such a thing (4.6C)?
Thank you, in advance for your responses.
Best regards
SergejSure, via [SAPlink|http://code.google.com/p/saplink/]
Regards
Marcin -
Error while usind Private Method of a global class
HI All..
I created a global class (ZLINE_GLOBAL) which has TOT_DATA private method. I have to call this private method in my report, I know that using Friend class we can do this.
But it is not working and showing the same error " METHOD "TOT_DATA" is unknown or Private or Public..
code i tried is
CLASS c2 DEFINITION DEFERRED.
CLASS ZLINE_GLOBAL DEFINITION FRIENDS c2.
PUBLIC SECTION.
METHODS : m1.
PRIVATE SECTION.
METHODS: m2.
ENDCLASS.
CLASS ZLINE_GLOBAL IMPLEMENTATION .
METHOD m1.
WRITE : 'Public Method C1'.
ENDMETHOD. "M1
METHOD m2.
WRITE : 'Private Method C1'.
ENDMETHOD.
ENDCLASS.
CLASS c2 DEFINITION FRIENDS ZLINE_GLOBAL. "my friends are here, allow them access to my (C2's) private components
PUBLIC SECTION.
METHODS :m3.
ENDCLASS.
CLASS c2 IMPLEMENTATION.
METHOD m3.
DATA : obj TYPE REF TO ZLINE_GLOBAL.
CREATE OBJECT obj.
CALL METHOD obj->TOT_DATA. "here Iam calling Private method of global class
ENDMETHOD. "M3
ENDCLASS.
START-OF-SELECTION.
DATA obj_c2 TYPE REF TO c2.
CREATE OBJECT obj_c2.
obj_c2->m3( ).
can anybody help me on this..
MurthyHi Murthy,
Replace TOT_DATA with M2, you do not have any method by name "TOT_DATA" in your code.
CLASS c2 DEFINITION DEFERRED.
CLASS ZLINE_GLOBAL DEFINITION FRIENDS c2.
PUBLIC SECTION.
METHODS : m1.
PRIVATE SECTION.
METHODS: m2.
ENDCLASS.
CLASS ZLINE_GLOBAL IMPLEMENTATION .
METHOD m1.
WRITE : 'Public Method C1'.
ENDMETHOD. "M1
METHOD m2.
WRITE : 'Private Method C1'.
ENDMETHOD.
ENDCLASS.
CLASS c2 DEFINITION FRIENDS ZLINE_GLOBAL. "my friends are here, allow them access to my (C2's) private components
PUBLIC SECTION.
METHODS :m3.
ENDCLASS.
CLASS c2 IMPLEMENTATION.
METHOD m3.
DATA : obj TYPE REF TO ZLINE_GLOBAL.
CREATE OBJECT obj.
CALL METHOD obj->M2. "here Iam calling Private method of global class
ENDMETHOD. "M3
ENDCLASS.
START-OF-SELECTION.
DATA obj_c2 TYPE REF TO c2.
CREATE OBJECT obj_c2.
obj_c2->m3( ).
Regards,
Chen -
Creation of Material using BDC Session method & global class
Hi
Creation of Material using BDC Session method & global class by using oops.
can anyone plz help me outHi,
it looks like it's not possible to call this BAPI wihtout material number. Here is a quote from BAPI documentation.
When creating material master data, you must transfer the material
number, the material type, and the industry sector to the method. You
must also enter a material description and its language.
Cheers
Maybe you are looking for
-
Problem with NIC and Firewire on MSI 865PE NEO2-PFISR
Hi, I have lots of trouble getting the network adapter on the MSI 865PE NEO2-PFISR to work. The NIC's LED indicators doesnt even light up when I plug in a network cable, and in windows (win 2003 server) it doesnt find the adapter at all. The NIC is d
-
help, i cant clsoe my pages app. i have a blue and white thin box, have tried force quit but then it just pops up again.
-
Connecting to "localhost" on port "21212" failed
I run startinstgui.bat to install WEBAS640SP9 before I downloaded J2sdk-1_4_2_06. I got error message with Connection to SAPinst can not be establish - Connecting to "localhost" on port "21212" failed. I tested with different values - no result. Any
-
Hi, I have created an animation in Keynote and exported it as a flash (SWF). I have opened up the generated html page and copied the <object> code and pasted it into one of my iWeb pages using HTML Snippet. I am using 800x600. The flash runs fine whe
-
When start X11 I get the following error messages: (EE) Error loading keymap /tmp/server-0.xkm (EE) XKB: Failed to load keymap. Loading default keymap instead. I assume this causes not having an appropriate keyboard model and layout set: # setxkbmap