Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Classes

Former Member
0 Likes
753

HI,

what are the difference between local and global classes?

please send me with some docs

rahul

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
569

HI,

Classes

LIKE-Zusatz

Classes are templates for objects. Conversely, you can say that the type of an object is the same as its class. A class is an abstract description of an object. You could say that it is a set of instructions for building an object. The attributes of objects are defined by the components of the class, which describe the state and behavior of objects.

Local and Global Classes

Classes in ABAP Objects can be declared either globally or locally. You define global classes and interfaces in the Class Builder (Transaction SE24) in the ABAP Workbench. They are stored centrally in class pools in the class library in the R/3 Repository. All of the ABAP programs in an R/3 System can access the global classes. Local classes are defined within an ABAP program. Local classes and interfaces can only be used in the program in which they are defined. When you use a class in an ABAP program, the system first searches for a local class with the specified name. If it does not find one, it then looks for a global class. Apart from the visibility question, there is no difference between using a global class and using a local class.

There is, however, a significant difference in the way that local and global classes are designed. If you are defining a local class that is only used in a single program, it is usually sufficient to define the outwardly visible components so that it fits into that program. Global classes, on the other hand, must be able to be used anywhere. This means that certain restrictions apply when you define the interface of a global class, since the system must be able to guarantee that any program using an object of a global class can recognize the data type of each interface parameter.

The following sections describe how to define local classes and interfaces in an ABAP program. For information about how to define local classes and interfaces, refer to the Class Builder section of the ABAP Workbench Tools documentation.

Defining Local Classes

Local classes consist of ABAP source code, enclosed in the ABAP statements CLASS ... ENDCLASS. A complete class definition consists of a declaration part and, if required, an implementation part. The declaration part of a class <class> is a statement block:

CLASS <class> DEFINITION.

...

ENDCLASS.

It contains the declaration for all components (attributes, methods, events) of the class. When you define local classes, the declaration part belongs to the global program data. You should therefore place it at the beginning of the program.

If you declare methods in the declaration part of a class, you must also write an implementation part for it. This consists of a further statement block:

CLASS <class> IMPLEMENTATION.

...

ENDCLASS.

The implementation part of a class contains the implementation of all methods of the class. The implementation part of a local class is a processing block. Subsequent coding that is not itself part of a processing block is therefore not accessible.

Structure of a Class

The following statements define the structure of a class:

A class contains components

Each component is assigned to a visibility section

Classes implement methods

The following sections describe the structure of classes in more detail.

Class Components

The components of a class make up its contents. All components are declared in the declaration part of the class. The components define the attributes of the objects in a class. When you define the class, each component is assigned to one of the three visibility sections, which define the external interface of the class. All of the components of a class are visible within the class. All components are in the same namespace. This means that all components of the class must have names that are unique within the class.

There are two kinds of components in a class - those that exist separately for each object in the class, and those that exist only once for the whole class, regardless of the number of instances. Instance-specific components are known as instance components. Components that are not instance-specific are called static components.

In ABAP Objects, classes can define the following components. Since all components that you can declare in classes can also be declared in interfaces, the following descriptions apply equally to interfaces.

Attributes

Attributes are internal data fields within a class that can have any ABAP data type. The state of an object is determined by the contents of its attributes. One kind of attribute is the reference variable. Reference variables allow you to create and address objects. Reference variables can be defined in classes, allowing you to access objects from within a class.

Instance Attributes

The contents of instance attributes define the instance-specific state of an object. You declare them using the DATA statement.

Static Attributes

The contents of static attributes define the state of the class that is valid for all instances of the class. Static attributes exist once for each class. You declare them using the CLASS-DATA statement. They are accessible for the entire runtime of the class.

All of the objects in a class can access its static attributes. If you change a static attribute in an object, the change is visible in all other objects in the class.

Methods

Methods are internal procedures in a class that define the behavior of an object. They can access all of the attributes of a class. This allows them to change the data content of an object. They also have a parameter interface, with which users can supply them with values when calling them, and receive values back from them The private attributes of a class can only be changed by methods in the same class.

The definition and parameter interface of a method is similar to that of function modules. You define a method <met> in the definition part of a class and implement it in the implementation part using the following processing block:

METHOD <meth>.

...

ENDMETHOD.

You can declare local data types and objects in methods in the same way as in other ABAP procedures (subroutines and function modules). You call methods using the CALL METHOD statement.

Instance Methods

You declare instance methods using the METHODS statement. They can access all of the attributes of a class, and can trigger all of the events of the class.

Static Methods

You declare static methods using the CLASS-METHODS statement. They can only access static attributes and trigger static events.

Special Methods

As well as normal methods, which you call using CALL METHOD, there are two special methods called CONSTRUCTOR and CLASS_CONSTRUCTOR, which are automatically called when you create an object (CONSTRUCTOR) or when you first access the components of a class (CLASS_CONSTRUCTOR).

Events

Objects or classes can use events to trigger event handler methods in other objects or classes. In a normal method call, one method can be called by any number of users. When an event is triggered, any number of event handler methods can be called. The link between the trigger and the handler is not established until runtime. In a normal method call, the calling program determines the methods that it wants to call. These methods must exist. With events, the handler determines the events to which it wants to react. There does not have to be a handler method registered for every event.

The events of a class can be triggered in the methods of the same class using the RAISE EVENT statement. You can declare a method of the same or a different class as an event handler method for the event <evt> of class <class> using the addition FOR EVENT <evt> OF <class>.

Events have a similar parameter interface to methods, but only have output parameters. These parameters are passed by the trigger (RAISE EVENT statement) to the event handler method, which receives them as input parameters.

The link between trigger and handler is established dynamically in a program using the SET HANDLER statement. The trigger and handlers can be objects or classes, depending on whether you have instance or static events and event handler methods. When an event is triggered, the corresponding event handler methods are executed in all registered handling classes.

Instance Events

You declare instance events using the EVENTS statement. An instance event can only be triggered in an instance method.

Static Events

You declare static events using the CLASS-EVENTS statement. All methods (instance and static methods) can trigger static events. Static events are the only type of event that can be triggered in a static method.

See also Triggering and Handling Events.

Types

You can define your own ABAP data types within a class using the TYPES statement. Types are not instance-specific, and exist once only for all of the objects in a class.

Constants

Constants are special static attributes. You set their values when you declare them, and they can then no longer be changed. You declare them using the CONSTANTS statement. Constants are not instance-specific, and exist once only for all of the objects in a class.

Visibility Sections

You can divide the declaration part of a class into up to three visibility areas:

CLASS <class> DEFINITION.

PUBLIC SECTION.

...

PROTECTED SECTION.

...

PRIVATE SECTION.

...

ENDCLASS.

These areas define the external visibility of the class components, that is, the interface between the class and its users. Each component of a class must be assigned to one of the visibility sections.

Public Section

All of the components declared in the public section are accessible to all users of the class, and to the methods of the class and any classes that inherit from it. The public components of the class form the interface between the class and its users.

Protected Section

All of the components declared in the protected section are accessible to all methods of the class and of classes that inherit from it. Protected components form a special interface between a class and its subclasses. Since inheritance is not active in Release 4.5B, the protected section currently has the same effect as the private section.

Private Section

Components that you declare in the private section are only visible in the methods of the same class. The private components are not part of the external interface of the class.

Encapsulation

The three visibility areas are the basis for one of the important features of object orientation - encapsulation. When you define a class, you should take great care in designing the public components, and try to declare as few public components as possible. The public components of global classes may not be changed once you have released the class.

For example, public attributes are visible externally, and form a part of the interface between an object and its users. If you want to encapsulate the state of an object fully, you cannot declare any public attributes. As well as defining the visibility of an attribute, you can also protect it from changes using the READ-ONLY addition.

reward if helpful

vivekanand

2 REPLIES 2
Read only

Former Member
0 Likes
570

HI,

Classes

LIKE-Zusatz

Classes are templates for objects. Conversely, you can say that the type of an object is the same as its class. A class is an abstract description of an object. You could say that it is a set of instructions for building an object. The attributes of objects are defined by the components of the class, which describe the state and behavior of objects.

Local and Global Classes

Classes in ABAP Objects can be declared either globally or locally. You define global classes and interfaces in the Class Builder (Transaction SE24) in the ABAP Workbench. They are stored centrally in class pools in the class library in the R/3 Repository. All of the ABAP programs in an R/3 System can access the global classes. Local classes are defined within an ABAP program. Local classes and interfaces can only be used in the program in which they are defined. When you use a class in an ABAP program, the system first searches for a local class with the specified name. If it does not find one, it then looks for a global class. Apart from the visibility question, there is no difference between using a global class and using a local class.

There is, however, a significant difference in the way that local and global classes are designed. If you are defining a local class that is only used in a single program, it is usually sufficient to define the outwardly visible components so that it fits into that program. Global classes, on the other hand, must be able to be used anywhere. This means that certain restrictions apply when you define the interface of a global class, since the system must be able to guarantee that any program using an object of a global class can recognize the data type of each interface parameter.

The following sections describe how to define local classes and interfaces in an ABAP program. For information about how to define local classes and interfaces, refer to the Class Builder section of the ABAP Workbench Tools documentation.

Defining Local Classes

Local classes consist of ABAP source code, enclosed in the ABAP statements CLASS ... ENDCLASS. A complete class definition consists of a declaration part and, if required, an implementation part. The declaration part of a class <class> is a statement block:

CLASS <class> DEFINITION.

...

ENDCLASS.

It contains the declaration for all components (attributes, methods, events) of the class. When you define local classes, the declaration part belongs to the global program data. You should therefore place it at the beginning of the program.

If you declare methods in the declaration part of a class, you must also write an implementation part for it. This consists of a further statement block:

CLASS <class> IMPLEMENTATION.

...

ENDCLASS.

The implementation part of a class contains the implementation of all methods of the class. The implementation part of a local class is a processing block. Subsequent coding that is not itself part of a processing block is therefore not accessible.

Structure of a Class

The following statements define the structure of a class:

A class contains components

Each component is assigned to a visibility section

Classes implement methods

The following sections describe the structure of classes in more detail.

Class Components

The components of a class make up its contents. All components are declared in the declaration part of the class. The components define the attributes of the objects in a class. When you define the class, each component is assigned to one of the three visibility sections, which define the external interface of the class. All of the components of a class are visible within the class. All components are in the same namespace. This means that all components of the class must have names that are unique within the class.

There are two kinds of components in a class - those that exist separately for each object in the class, and those that exist only once for the whole class, regardless of the number of instances. Instance-specific components are known as instance components. Components that are not instance-specific are called static components.

In ABAP Objects, classes can define the following components. Since all components that you can declare in classes can also be declared in interfaces, the following descriptions apply equally to interfaces.

Attributes

Attributes are internal data fields within a class that can have any ABAP data type. The state of an object is determined by the contents of its attributes. One kind of attribute is the reference variable. Reference variables allow you to create and address objects. Reference variables can be defined in classes, allowing you to access objects from within a class.

Instance Attributes

The contents of instance attributes define the instance-specific state of an object. You declare them using the DATA statement.

Static Attributes

The contents of static attributes define the state of the class that is valid for all instances of the class. Static attributes exist once for each class. You declare them using the CLASS-DATA statement. They are accessible for the entire runtime of the class.

All of the objects in a class can access its static attributes. If you change a static attribute in an object, the change is visible in all other objects in the class.

Methods

Methods are internal procedures in a class that define the behavior of an object. They can access all of the attributes of a class. This allows them to change the data content of an object. They also have a parameter interface, with which users can supply them with values when calling them, and receive values back from them The private attributes of a class can only be changed by methods in the same class.

The definition and parameter interface of a method is similar to that of function modules. You define a method <met> in the definition part of a class and implement it in the implementation part using the following processing block:

METHOD <meth>.

...

ENDMETHOD.

You can declare local data types and objects in methods in the same way as in other ABAP procedures (subroutines and function modules). You call methods using the CALL METHOD statement.

Instance Methods

You declare instance methods using the METHODS statement. They can access all of the attributes of a class, and can trigger all of the events of the class.

Static Methods

You declare static methods using the CLASS-METHODS statement. They can only access static attributes and trigger static events.

Special Methods

As well as normal methods, which you call using CALL METHOD, there are two special methods called CONSTRUCTOR and CLASS_CONSTRUCTOR, which are automatically called when you create an object (CONSTRUCTOR) or when you first access the components of a class (CLASS_CONSTRUCTOR).

Events

Objects or classes can use events to trigger event handler methods in other objects or classes. In a normal method call, one method can be called by any number of users. When an event is triggered, any number of event handler methods can be called. The link between the trigger and the handler is not established until runtime. In a normal method call, the calling program determines the methods that it wants to call. These methods must exist. With events, the handler determines the events to which it wants to react. There does not have to be a handler method registered for every event.

The events of a class can be triggered in the methods of the same class using the RAISE EVENT statement. You can declare a method of the same or a different class as an event handler method for the event <evt> of class <class> using the addition FOR EVENT <evt> OF <class>.

Events have a similar parameter interface to methods, but only have output parameters. These parameters are passed by the trigger (RAISE EVENT statement) to the event handler method, which receives them as input parameters.

The link between trigger and handler is established dynamically in a program using the SET HANDLER statement. The trigger and handlers can be objects or classes, depending on whether you have instance or static events and event handler methods. When an event is triggered, the corresponding event handler methods are executed in all registered handling classes.

Instance Events

You declare instance events using the EVENTS statement. An instance event can only be triggered in an instance method.

Static Events

You declare static events using the CLASS-EVENTS statement. All methods (instance and static methods) can trigger static events. Static events are the only type of event that can be triggered in a static method.

See also Triggering and Handling Events.

Types

You can define your own ABAP data types within a class using the TYPES statement. Types are not instance-specific, and exist once only for all of the objects in a class.

Constants

Constants are special static attributes. You set their values when you declare them, and they can then no longer be changed. You declare them using the CONSTANTS statement. Constants are not instance-specific, and exist once only for all of the objects in a class.

Visibility Sections

You can divide the declaration part of a class into up to three visibility areas:

CLASS <class> DEFINITION.

PUBLIC SECTION.

...

PROTECTED SECTION.

...

PRIVATE SECTION.

...

ENDCLASS.

These areas define the external visibility of the class components, that is, the interface between the class and its users. Each component of a class must be assigned to one of the visibility sections.

Public Section

All of the components declared in the public section are accessible to all users of the class, and to the methods of the class and any classes that inherit from it. The public components of the class form the interface between the class and its users.

Protected Section

All of the components declared in the protected section are accessible to all methods of the class and of classes that inherit from it. Protected components form a special interface between a class and its subclasses. Since inheritance is not active in Release 4.5B, the protected section currently has the same effect as the private section.

Private Section

Components that you declare in the private section are only visible in the methods of the same class. The private components are not part of the external interface of the class.

Encapsulation

The three visibility areas are the basis for one of the important features of object orientation - encapsulation. When you define a class, you should take great care in designing the public components, and try to declare as few public components as possible. The public components of global classes may not be changed once you have released the class.

For example, public attributes are visible externally, and form a part of the interface between an object and its users. If you want to encapsulate the state of an object fully, you cannot declare any public attributes. As well as defining the visibility of an attribute, you can also protect it from changes using the READ-ONLY addition.

reward if helpful

vivekanand

Read only

aris_hidalgo
Contributor
0 Likes
569

[code]

Hi,

Local classes are classes that you define in your programs while global classes are the ones that

are implemented by SAP or the ones that you create using tcode SE24 and can be used by reports, FM's, etc.

I pasted a report I made which uses local classes.

&----


*& Report ZFI_REP_DISBURSE_SUM

*&

*& PROGRAM TYPE : Report

*& RICEF ID :

*& TITLE : Disbursement Summary Report(New version)

*& SAP Module : FI

*& CREATION DATE : 07/20/2007

*& AUTHOR : Aris Hidalgo

*& DESIGNER : Aris Hidalgo

&----


*& DESCRIPTION : Disbursement Summary Report

*& : NOTE: Backed up the original version to

*& : ZFI_REP_DISBURSE_SUM_BACKUP

&----


$*********************************************************************

*$ CHANGE HISTORY

*$----


*$ DATE | T-Num | Description | Reference

    • | | |

$*********************************************************************

REPORT zfi_rep_disburse_sum

NO STANDARD PAGE HEADING

LINE-SIZE 142

MESSAGE-ID zfi.

----


  • SELECTION-SCREEN *

----


SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.

PARAMETERS: p_bukrs TYPE bsak-bukrs OBLIGATORY,

p_gjahr TYPE bkpf-gjahr OBLIGATORY,

p_monat TYPE bkpf-monat OBLIGATORY.

SELECTION-SCREEN END OF BLOCK b1.

SELECTION-SCREEN BEGIN OF BLOCK b2 WITH FRAME TITLE text-002.

PARAMETERS: p_sign TYPE kna1-name1,

p_sgpos TYPE kna1-name1,

p_note TYPE kna1-name1,

p_ntpos TYPE kna1-name1.

SELECTION-SCREEN END OF BLOCK b2.

CLASS lcl_other_routines DEFINITION DEFERRED.

----


  • CLASS lcl_get_data DEFINITION

----


*

----


CLASS lcl_get_data DEFINITION.

PUBLIC SECTION.

TYPES: BEGIN OF t_payr,

zbukr TYPE payr-zbukr,

vblnr TYPE payr-vblnr,

gjahr TYPE payr-gjahr,

lifnr TYPE payr-lifnr,

zaldt TYPE payr-zaldt,

END OF t_payr.

TYPES: BEGIN OF t_bsak,

bukrs TYPE bsak-bukrs,

gjahr TYPE bsak-gjahr,

belnr TYPE bsak-belnr,

monat TYPE bsak-monat,

shkzg TYPE bsak-shkzg,

blart TYPE bsak-blart,

buzei TYPE bsak-buzei,

lifnr TYPE bsak-lifnr,

dmbtr TYPE bsak-dmbtr,

bschl TYPE bsak-bschl,

END OF t_bsak.

TYPES: BEGIN OF t_collect,

blart TYPE bsak-blart,

gjahr TYPE bsak-gjahr,

monat TYPE bsak-monat,

dmbtr TYPE bsak-dmbtr,

END OF t_collect.

TYPES: BEGIN OF t_bsis,

bukrs TYPE bsis-bukrs,

belnr TYPE bsis-belnr,

hkont TYPE bsis-hkont,

gjahr TYPE bsis-gjahr,

buzei TYPE bsis-buzei,

blart TYPE bsis-blart,

monat TYPE bsis-monat,

shkzg TYPE bsis-shkzg,

dmbtr TYPE bsis-dmbtr,

bschl TYPE bsis-bschl,

END OF t_bsis.

TYPES: BEGIN OF t_output,

blart TYPE bsak-blart,

last_year TYPE bsak-dmbtr,

this_year TYPE bsak-dmbtr,

percent1 TYPE prozab,

cum_last_year TYPE bsak-dmbtr,

cum_this_year TYPE bsak-dmbtr,

percent2 TYPE prozab,

description(200) TYPE c,

header(200) TYPE c,

END OF t_output.

TYPES: BEGIN OF t_text,

sort_order TYPE i,

header(200) TYPE c,

description(200) TYPE c,

blart TYPE bsak-blart,

END OF t_text.

METHODS: get_payment_details,

get_additional_data,

process_data,

move_to_output_table

IMPORTING

im_blart TYPE bsak-blart

im_gjahr TYPE bsak-gjahr

im_monat TYPE bsak-monat

im_dmbtr TYPE bsak-dmbtr,

display_data,

fill_text_table.

PROTECTED SECTION.

CLASS-DATA: gt_payr TYPE STANDARD TABLE OF t_payr,

gt_bsak TYPE STANDARD TABLE OF t_bsak,

gt_payments TYPE STANDARD TABLE OF t_bsak,

wa_payments LIKE LINE OF gt_payments,

gt_bsis TYPE STANDARD TABLE OF t_bsis,

wa_bsis LIKE LINE OF gt_bsis,

gt_bsas TYPE STANDARD TABLE OF t_bsis,

gt_output TYPE STANDARD TABLE OF t_output,

wa_output LIKE LINE OF gt_output,

gt_text TYPE STANDARD TABLE OF t_text,

wa_text LIKE LINE OF gt_text,

gt_collect TYPE STANDARD TABLE OF t_collect,

wa_collect LIKE LINE OF gt_collect.

PRIVATE SECTION.

DATA: lv_year TYPE payr-gjahr,

lv_jan TYPE t247-ktx,

lv_pres_month TYPE t247-ktx,

lv_month_range TYPE string,

lv_old_header TYPE t_text-header,

lv_new_header TYPE t_text-header,

lv_sub_lyear TYPE bsak-dmbtr,

lv_gtot_lyear TYPE bsak-dmbtr,

lv_sub_tyear TYPE bsak-dmbtr,

lv_gtot_tyear TYPE bsak-dmbtr,

lv_sub_cum_lyear TYPE bsak-dmbtr,

lv_gtot_cum_lyear TYPE bsak-dmbtr,

lv_sub_cum_tyear TYPE bsak-dmbtr,

lv_gtot_cum_tyear TYPE bsak-dmbtr,

lv_percent1 TYPE prozab,

lv_percent2 TYPE prozab,

lv_gtot_percent1 TYPE prozab,

lv_gtot_percent2 TYPE prozab,

o_lcl_other_routines TYPE REF TO lcl_other_routines.

CONSTANTS: lc_kb TYPE bsak-blart VALUE 'KB',

lc_kd TYPE bsak-blart VALUE 'KD',

lc_k3 TYPE bsak-blart VALUE 'K3',

lc_k4 TYPE bsak-blart VALUE 'K4',

lc_k5 TYPE bsak-blart VALUE 'K5',

lc_k6 TYPE bsak-blart VALUE 'K6',

lc_py TYPE bsak-blart VALUE 'PY',

lc_pf TYPE bsak-blart VALUE 'PF',

lc_pq TYPE bsak-blart VALUE 'PQ',

lc_pj TYPE bsak-blart VALUE 'PJ',

lc_pm TYPE bsak-blart VALUE 'PM',

lc_pt TYPE bsak-blart VALUE 'PT',

lc_p0 TYPE bsak-blart VALUE 'P0',

lc_re TYPE bsak-blart VALUE 'RE',

lc_ps TYPE bsak-blart VALUE 'PS',

lc_pp TYPE bsak-blart VALUE 'PP',

lc_kp TYPE bsak-blart VALUE 'KP',

lc_pu TYPE bsak-blart VALUE 'PU',

lc_pd TYPE bsak-blart VALUE 'PD',

lc_pe TYPE bsak-blart VALUE 'PE',

lc_su TYPE bsak-blart VALUE 'SU',

lc_pc TYPE bsak-blart VALUE 'PC',

lc_p2 TYPE bsak-blart VALUE 'P2',

lc_po TYPE bsak-blart VALUE 'PO',

lc_pw TYPE bsak-blart VALUE 'PW',

lc_pv TYPE bsak-blart VALUE 'PV',

lc_p7 TYPE bsak-blart VALUE 'P7',

lc_pa TYPE bsak-blart VALUE 'PA',

lc_px TYPE bsis-blart VALUE 'PX',

lc_x0 TYPE bsis-blart VALUE 'X0', "Capital Expenditures(CAPEX)

lc_x1 TYPE bsis-blart VALUE 'X1', "Request of payment - Vendor

lc_x2 TYPE bsis-blart VALUE 'X2', "Logistics Fee - Diethelm

lc_x3 TYPE bsis-blart VALUE 'X3', "Logistics Fee - First Pioneer

lc_y1 TYPE bsis-blart VALUE 'Y1', "Profit Share

lc_y2 TYPE bsis-blart VALUE 'Y2', "Dividend Payments

lc_z1 TYPE bsis-blart VALUE 'Z1',

lc_z2 TYPE bsis-blart VALUE 'Z2',

lc_z3 TYPE bsis-blart VALUE 'Z3',

lc_z4 TYPE bsis-blart VALUE 'Z4',

lc_p8 TYPE bsis-blart VALUE 'P8',

lc_p9 TYPE bsis-blart VALUE 'P9'.

CONSTANTS: lc_0020000800 TYPE bsis-hkont VALUE '0020000800',

lc_0060000653 TYPE bsis-hkont VALUE '0060000653',

lc_0020000660 TYPE bsis-hkont VALUE '0020000660',

lc_0020000770 TYPE bsis-hkont VALUE '0020000770'.

CONSTANTS: lc_8000000525 TYPE lfa1-lifnr VALUE '8000000525',

lc_8000001015 TYPE lfa1-lifnr VALUE '8000001015'.

ENDCLASS. "lcl_get_data DEFINITION

----


  • CLASS lcl_other_routines DEFINITION

----


*

----


CLASS lcl_other_routines DEFINITION INHERITING FROM lcl_get_data.

PUBLIC SECTION.

CLASS-DATA: gv_butxt TYPE t001-butxt,

gt_t247 TYPE STANDARD TABLE OF t247,

wa_t247 LIKE LINE OF gt_t247.

METHODS: display_header

IMPORTING

im_flag TYPE flag OPTIONAL

EXPORTING

ex_month_name TYPE t247-ltx

ex_jan TYPE t247-ktx

ex_pres_month TYPE t247-ktx.

ENDCLASS. "lcl_other_routines DEFINITION

----


  • CLASS lcl_get_data IMPLEMENTATION

----


*

----


CLASS lcl_get_data IMPLEMENTATION.

METHOD get_payment_details.

  • Get previous year

lv_year = p_gjahr - 1.

  • Get records from PAYR

SELECT zbukr vblnr gjahr lifnr zaldt

FROM payr

INTO TABLE gt_payr

WHERE zbukr = p_bukrs

AND gjahr IN (lv_year, p_gjahr).

DELETE gt_payr WHERE zaldt+4(2) > p_monat.

SORT gt_payr BY zbukr vblnr gjahr lifnr zaldt.

DELETE ADJACENT DUPLICATES FROM gt_payr COMPARING zbukr vblnr gjahr lifnr zaldt.

IF NOT gt_payr[] IS INITIAL.

  • Get records from BSAK

SELECT bukrs gjahr belnr

monat shkzg blart

buzei lifnr dmbtr

bschl

FROM bsak

INTO TABLE gt_bsak

FOR ALL ENTRIES IN gt_payr

WHERE lifnr = gt_payr-lifnr

AND bukrs = gt_payr-zbukr

AND augdt = gt_payr-zaldt

AND augbl = gt_payr-vblnr

AND gjahr = gt_payr-gjahr.

ENDIF.

DELETE gt_bsak WHERE monat > p_monat.

DELETE gt_bsak WHERE shkzg <> 'H'.

gt_payments[] = gt_bsak[].

IF NOT gt_payments[] IS INITIAL.

CALL METHOD: me->get_additional_data,

process_data.

ELSE.

MESSAGE i000 WITH text-057.

LEAVE LIST-PROCESSING.

ENDIF.

ENDMETHOD. "get_payment_details

METHOD get_additional_data.

  • Get records from BSIS(Open items)

SELECT bukrs belnr hkont gjahr

buzei blart monat shkzg

dmbtr bschl

FROM bsis

INTO TABLE gt_bsis

FOR ALL ENTRIES IN gt_payments

WHERE bukrs = gt_payments-bukrs

AND belnr = gt_payments-belnr

AND gjahr = gt_payments-gjahr.

  • Get records from BSAS(Cleared items)

SELECT bukrs belnr hkont gjahr

buzei blart monat shkzg

dmbtr bschl

FROM bsas

INTO TABLE gt_bsas

FOR ALL ENTRIES IN gt_payments

WHERE bukrs = gt_payments-bukrs

AND belnr = gt_payments-belnr

AND gjahr = gt_payments-gjahr.

DELETE gt_bsis WHERE monat > p_monat.

DELETE gt_bsis WHERE blart <> lc_su AND

blart <> lc_px AND

blart <> lc_pt AND

blart <> lc_p0 AND

blart <> lc_re.

DELETE gt_bsas WHERE monat > p_monat.

DELETE gt_bsas WHERE blart <> lc_su AND

blart <> lc_px AND

blart <> lc_pt AND

blart <> lc_p0 AND

blart <> lc_re.

  • Combine data

APPEND LINES OF gt_bsas TO gt_bsis.

ENDMETHOD. "get_additional_data

METHOD process_data.

FIELD-SYMBOLS: <fs_payments> LIKE LINE OF gt_payments,

<fs_bsis> LIKE LINE OF gt_bsis.

SORT gt_payments ASCENDING BY: bukrs blart gjahr monat.

LOOP AT gt_payments ASSIGNING <fs_payments>.

IF <fs_payments>-blart = lc_pv OR

<fs_payments>-blart = lc_p7.

IF <fs_payments>-lifnr <> lc_8000000525 AND "Request of payment - Vendor

<fs_payments>-lifnr <> lc_8000001015.

CALL METHOD move_to_output_table

EXPORTING

im_blart = lc_x1

im_gjahr = <fs_payments>-gjahr

im_monat = <fs_payments>-monat

im_dmbtr = <fs_payments>-dmbtr.

CONTINUE.

ELSEIF <fs_payments>-lifnr = lc_8000000525. "Diethelm

CALL METHOD move_to_output_table

EXPORTING

im_blart = lc_x2

im_gjahr = <fs_payments>-gjahr

im_monat = <fs_payments>-monat

im_dmbtr = <fs_payments>-dmbtr.

CONTINUE.

ELSEIF <fs_payments>-lifnr = lc_8000001015. "First Pioneer

CALL METHOD move_to_output_table

EXPORTING

im_blart = lc_x3

im_gjahr = <fs_payments>-gjahr

im_monat = <fs_payments>-monat

im_dmbtr = <fs_payments>-dmbtr.

CONTINUE.

ENDIF.

ENDIF.

MOVE-CORRESPONDING <fs_payments> TO wa_collect.

COLLECT wa_collect INTO gt_collect.

ENDLOOP.

  • Process records from BSAK

LOOP AT gt_collect INTO wa_collect.

CALL METHOD move_to_output_table

EXPORTING

im_blart = wa_collect-blart

im_gjahr = wa_collect-gjahr

im_monat = wa_collect-monat

im_dmbtr = wa_collect-dmbtr.

ENDLOOP.

SORT gt_bsis BY bukrs belnr hkont gjahr.

SORT gt_payments BY bukrs gjahr belnr monat shkzg.

DELETE ADJACENT DUPLICATES FROM gt_bsis COMPARING bukrs belnr hkont gjahr.

  • Process records from BSIS and BSAS

LOOP AT gt_bsis ASSIGNING <fs_bsis>.

IF <fs_bsis>-blart = lc_su.

IF <fs_bsis>-hkont = lc_0020000800 OR

<fs_bsis>-hkont = lc_0060000653.

READ TABLE gt_payments ASSIGNING <fs_payments> WITH KEY bukrs = <fs_bsis>-bukrs

gjahr = <fs_bsis>-gjahr

belnr = <fs_bsis>-belnr

monat = <fs_bsis>-monat

shkzg = 'H'

BINARY SEARCH.

IF sy-subrc = 0.

CALL METHOD move_to_output_table

EXPORTING

im_blart = lc_y1

im_gjahr = <fs_payments>-gjahr

im_monat = <fs_payments>-monat

im_dmbtr = <fs_payments>-dmbtr.

CONTINUE.

ENDIF.

ELSEIF <fs_bsis>-hkont = lc_0020000770.

READ TABLE gt_payments ASSIGNING <fs_payments> WITH KEY bukrs = <fs_bsis>-bukrs

gjahr = <fs_bsis>-gjahr

belnr = <fs_bsis>-belnr

monat = <fs_bsis>-monat

shkzg = 'H'

BINARY SEARCH.

IF sy-subrc = 0.

CALL METHOD move_to_output_table

EXPORTING

im_blart = lc_y2

im_gjahr = <fs_payments>-gjahr

im_monat = <fs_payments>-monat

im_dmbtr = <fs_payments>-dmbtr.

CONTINUE.

ENDIF.

ENDIF.

ELSEIF <fs_bsis>-blart = lc_px.

IF <fs_bsis>-hkont = '0020000650' OR

<fs_bsis>-hkont = '0020000651'.

READ TABLE gt_payments ASSIGNING <fs_payments> WITH KEY bukrs = <fs_bsis>-bukrs

gjahr = <fs_bsis>-gjahr

belnr = <fs_bsis>-belnr

monat = <fs_bsis>-monat

shkzg = 'H'

BINARY SEARCH.

IF sy-subrc = 0.

CALL METHOD move_to_output_table

EXPORTING

im_blart = lc_z1

im_gjahr = <fs_payments>-gjahr

im_monat = <fs_payments>-monat

im_dmbtr = <fs_payments>-dmbtr.

CONTINUE.

ENDIF.

ELSEIF <fs_bsis>-hkont BETWEEN '0020000200' AND '0020000320'.

READ TABLE gt_payments ASSIGNING <fs_payments> WITH KEY bukrs = <fs_bsis>-bukrs

gjahr = <fs_bsis>-gjahr

belnr = <fs_bsis>-belnr

monat = <fs_bsis>-monat

shkzg = 'H'

BINARY SEARCH.

IF sy-subrc = 0.

CALL METHOD move_to_output_table

EXPORTING

im_blart = lc_z2

im_gjahr = <fs_payments>-gjahr

im_monat = <fs_payments>-monat

im_dmbtr = <fs_payments>-dmbtr.

CONTINUE.

ENDIF.

ELSEIF <fs_bsis>-hkont BETWEEN '0060001100' AND '0060001114'.

READ TABLE gt_payments ASSIGNING <fs_payments> WITH KEY bukrs = <fs_bsis>-bukrs

gjahr = <fs_bsis>-gjahr

belnr = <fs_bsis>-belnr

monat = <fs_bsis>-monat

shkzg = 'H'

BINARY SEARCH.

IF sy-subrc = 0.

CALL METHOD move_to_output_table

EXPORTING

im_blart = lc_z3

im_gjahr = <fs_payments>-gjahr

im_monat = <fs_payments>-monat

im_dmbtr = <fs_payments>-dmbtr.

CONTINUE.

ENDIF.

ELSEIF <fs_bsis>-hkont = lc_0020000660.

READ TABLE gt_payments ASSIGNING <fs_payments> WITH KEY bukrs = <fs_bsis>-bukrs

gjahr = <fs_bsis>-gjahr

belnr = <fs_bsis>-belnr

monat = <fs_bsis>-monat

shkzg = 'H'

BINARY SEARCH.

IF sy-subrc = 0.

CALL METHOD move_to_output_table

EXPORTING

im_blart = lc_z4

im_gjahr = <fs_payments>-gjahr

im_monat = <fs_payments>-monat

im_dmbtr = <fs_payments>-dmbtr.

CONTINUE.

ENDIF.

ENDIF.

ELSEIF <fs_bsis>-blart = lc_pt OR

<fs_bsis>-blart = lc_p0 OR

<fs_bsis>-blart = lc_re.

IF <fs_bsis>-hkont BETWEEN '0070000001' AND '0070000024'.

READ TABLE gt_payments ASSIGNING <fs_payments> WITH KEY bukrs = <fs_bsis>-bukrs

gjahr = <fs_bsis>-gjahr

belnr = <fs_bsis>-belnr

monat = <fs_bsis>-monat

shkzg = 'H'

BINARY SEARCH.

IF sy-subrc = 0.

CALL METHOD move_to_output_table

EXPORTING

im_blart = lc_x0

im_gjahr = <fs_payments>-gjahr

im_monat = <fs_payments>-monat

im_dmbtr = <fs_payments>-dmbtr.

CONTINUE.

ENDIF.

ELSE.

READ TABLE gt_payments ASSIGNING <fs_payments> WITH KEY bukrs = <fs_bsis>-bukrs

gjahr = <fs_bsis>-gjahr

belnr = <fs_bsis>-belnr

monat = <fs_bsis>-monat

shkzg = 'H'

BINARY SEARCH.

IF sy-subrc = 0.

CALL METHOD move_to_output_table

EXPORTING

im_blart = lc_pt

im_gjahr = <fs_payments>-gjahr

im_monat = <fs_payments>-monat

im_dmbtr = <fs_payments>-dmbtr.

CONTINUE.

ENDIF.

ENDIF.

ENDIF.

ENDLOOP.

ENDMETHOD. "process_data

METHOD move_to_output_table.

CLEAR wa_output.

READ TABLE gt_output INTO wa_output WITH KEY blart = im_blart.

  • If document type is not yet added

IF sy-subrc <> 0.

wa_output-blart = im_blart.

  • Year before the user specified year

IF im_gjahr = lv_year.

IF im_monat = p_monat.

wa_output-last_year = im_dmbtr.

APPEND wa_output TO gt_output.

ENDIF.

ADD im_dmbtr TO wa_output-cum_last_year.

APPEND wa_output TO gt_output.

CLEAR wa_output.

  • User specified year

ELSEIF im_gjahr = p_gjahr.

IF im_monat = p_monat.

wa_output-this_year = im_dmbtr.

APPEND wa_output TO gt_output.

ENDIF.

ADD im_dmbtr TO wa_output-cum_this_year.

APPEND wa_output TO gt_output.

CLEAR wa_output.

ENDIF.

  • If document type has been already added

ELSEIF sy-subrc = 0.

wa_output-blart = im_blart.

  • Year before the user specified year

IF im_gjahr = lv_year.

IF im_monat = p_monat.

wa_output-last_year = im_dmbtr.

MODIFY TABLE gt_output FROM wa_output.

ENDIF.

ADD im_dmbtr TO wa_output-cum_last_year.

MODIFY TABLE gt_output FROM wa_output.

CLEAR wa_output.

  • User specified year

ELSEIF im_gjahr = p_gjahr.

IF im_monat = p_monat.

wa_output-this_year = im_dmbtr.

MODIFY TABLE gt_output FROM wa_output.

ENDIF.

ADD im_dmbtr TO wa_output-cum_this_year.

MODIFY TABLE gt_output FROM wa_output.

CLEAR wa_output.

ENDIF.

ENDIF.

ENDMETHOD. "move_to_output_table

METHOD display_data.

CREATE OBJECT o_lcl_other_routines.

CALL METHOD o_lcl_other_routines->display_header

EXPORTING

im_flag = space

IMPORTING

  • ex_month_name = lv_month

ex_jan = lv_jan

ex_pres_month = lv_pres_month.

  • Write header

SKIP 2.

FORMAT COLOR COL_HEADING.

WRITE:

  • AT /60 lv_month CENTERED, "Month

AT /98 text-005 CENTERED. "Cumulative

WRITE: AT 60 text-006 CENTERED, "Current month

AT /44 text-007 CENTERED, "Last year

AT 63 text-008 CENTERED, "This year

AT 75 text-009 CENTERED, "% Inc/Dec

AT 97 text-010 CENTERED, "Last year(Cumulative)

AT 115 text-011 CENTERED, "This year(Cumulative)

AT 130 text-012 CENTERED, "% Inc/Dec

/ lv_year CENTERED UNDER text-007,

p_gjahr CENTERED UNDER text-008.

CONCATENATE: lv_jan '-' lv_pres_month INTO lv_month_range.

WRITE: lv_month_range CENTERED UNDER text-010,

lv_month_range CENTERED UNDER text-011,

AT 130(15) space COLOR COL_HEADING.

FORMAT COLOR OFF.

SKIP 1.

CALL METHOD me->fill_text_table.

SORT gt_text BY sort_order.

SORT gt_output BY blart.

LOOP AT gt_text INTO wa_text.

lv_new_header = wa_text-header.

IF lv_old_header <> lv_new_header AND

NOT lv_old_header IS INITIAL.

  • Write subtotal

FORMAT COLOR COL_TOTAL INTENSIFIED OFF.

WRITE: / text-054,

AT 40 lv_sub_lyear CURRENCY 'PHP' RIGHT-JUSTIFIED,

AT 59 lv_sub_tyear CURRENCY 'PHP' RIGHT-JUSTIFIED,

AT 78 lv_percent1 RIGHT-JUSTIFIED,

AT 93 lv_sub_cum_lyear CURRENCY 'PHP' RIGHT-JUSTIFIED,

AT 111 lv_sub_cum_tyear CURRENCY 'PHP' RIGHT-JUSTIFIED,

AT 135 lv_percent2 RIGHT-JUSTIFIED.

FORMAT COLOR OFF.

WRITE: sy-uline.

CLEAR: lv_sub_lyear, lv_sub_tyear, lv_percent1,

lv_sub_cum_lyear, lv_sub_cum_tyear, lv_percent2.

ENDIF.

  • Write subcategory

IF lv_old_header <> lv_new_header.

SKIP 2.

WRITE: / wa_text-header COLOR COL_GROUP INTENSIFIED ON.

ENDIF.

lv_old_header = lv_new_header.

WRITE: AT /2 wa_text-description.

CLEAR wa_output.

READ TABLE gt_output INTO wa_output WITH KEY blart = wa_text-blart.

  • Write details

IF sy-subrc = 0.

WRITE: AT 40 wa_output-last_year CURRENCY 'PHP' RIGHT-JUSTIFIED,

AT 59 wa_output-this_year CURRENCY 'PHP' RIGHT-JUSTIFIED.

IF wa_output-last_year <> 0 AND

wa_output-this_year <> 0.

wa_output-percent1 = ( wa_output-this_year - wa_output-last_year ) /

wa_output-last_year.

ENDIF.

WRITE: AT 78 wa_output-percent1 RIGHT-JUSTIFIED.

WRITE: AT 93 wa_output-cum_last_year CURRENCY 'PHP' RIGHT-JUSTIFIED,

AT 111 wa_output-cum_this_year CURRENCY 'PHP' RIGHT-JUSTIFIED.

IF wa_output-cum_last_year <> 0 AND

wa_output-cum_this_year <> 0.

wa_output-percent2 = ( wa_output-cum_this_year - wa_output-cum_last_year ) /

wa_output-cum_last_year.

ENDIF.

WRITE: AT 135 wa_output-percent2 RIGHT-JUSTIFIED.

ADD wa_output-last_year TO: lv_sub_lyear, lv_gtot_lyear.

ADD wa_output-this_year TO: lv_sub_tyear, lv_gtot_tyear.

ADD wa_output-percent1 TO: lv_percent1, lv_gtot_percent1.

ADD wa_output-cum_last_year TO: lv_sub_cum_lyear, lv_gtot_cum_lyear.

ADD wa_output-cum_this_year TO: lv_sub_cum_tyear, lv_gtot_cum_tyear.

ADD wa_output-percent2 TO: lv_percent2, lv_gtot_percent2.

ENDIF.

AT LAST.

  • Write subtotal

FORMAT COLOR COL_TOTAL INTENSIFIED OFF.

WRITE: / text-054,

AT 40 lv_sub_lyear CURRENCY 'PHP' RIGHT-JUSTIFIED,

AT 59 lv_sub_tyear CURRENCY 'PHP' RIGHT-JUSTIFIED,

AT 78 lv_percent1 RIGHT-JUSTIFIED,

AT 93 lv_sub_cum_lyear CURRENCY 'PHP' RIGHT-JUSTIFIED,

AT 111 lv_sub_cum_tyear CURRENCY 'PHP' RIGHT-JUSTIFIED,

AT 135 lv_percent2 RIGHT-JUSTIFIED.

FORMAT COLOR OFF.

WRITE: sy-uline.

  • Write grand total

SKIP 1.

FORMAT COLOR COL_TOTAL INTENSIFIED ON.

WRITE: / text-055,

AT 40 lv_gtot_lyear CURRENCY 'PHP',

AT 59 lv_gtot_tyear CURRENCY 'PHP',

AT 78 lv_gtot_percent1 RIGHT-JUSTIFIED,

AT 93 lv_gtot_cum_lyear CURRENCY 'PHP',

AT 111 lv_gtot_cum_tyear CURRENCY 'PHP',

AT 135 lv_gtot_percent2 RIGHT-JUSTIFIED.

FORMAT COLOR OFF.

WRITE: sy-uline.

SKIP 3.

WRITE: / p_sign UNDER text-010,

/ p_sgpos UNDER text-010,

/ text-056,

/ p_note UNDER text-056,

/ p_ntpos UNDER text-056.

ENDAT.

ENDLOOP.

ENDMETHOD. "display_data

METHOD fill_text_table.

DEFINE fill_text_table.

wa_text-sort_order = &1.

wa_text-header = &2.

wa_text-description = &3.

wa_text-blart = &4.

append wa_text to gt_text.

clear wa_text.

END-OF-DEFINITION.

  • Importation details

fill_text_table '1' text-048 text-013 lc_kb.

fill_text_table '2' text-048 text-014 lc_kd.

fill_text_table '3' text-048 text-015 lc_k3.

fill_text_table '4' text-048 text-016 lc_k4.

fill_text_table '5' text-048 text-017 lc_k6.

fill_text_table '6' text-048 text-018 lc_k5.

  • Finished goods details

fill_text_table '7' text-049 text-019 lc_py.

fill_text_table '8' text-049 text-020 lc_pf.

fill_text_table '9' text-049 text-021 lc_pq.

  • Local production items

fill_text_table '10' text-050 text-022 lc_pj.

fill_text_table '11' text-050 text-023 lc_pm.

  • Local non-production items

fill_text_table '12' text-051 text-024 lc_pt.

fill_text_table '13' text-051 text-058 lc_x0.

fill_text_table '14' text-051 text-025 lc_ps.

  • Payroll transactions

fill_text_table '15' text-052 text-026 lc_pp.

fill_text_table '16' text-052 text-027 lc_kp.

fill_text_table '17' text-052 text-028 lc_pu.

fill_text_table '18' text-052 text-029 lc_pd.

fill_text_table '19' text-052 text-030 lc_pe.

fill_text_table '20' text-052 text-040 lc_y1.

  • Taxes

fill_text_table '21' text-059 text-042 lc_z1.

fill_text_table '22' text-059 text-043 lc_z2.

fill_text_table '23' text-059 text-044 lc_z3.

fill_text_table '24' text-059 text-045 lc_z4.

  • Others

fill_text_table '25' text-053 text-032 lc_pc.

fill_text_table '26' text-053 text-033 lc_p2.

fill_text_table '27' text-053 text-036 lc_x1.

fill_text_table '28' text-053 text-034 lc_po.

fill_text_table '29' text-053 text-035 lc_pw.

fill_text_table '30' text-053 text-037 lc_x2.

fill_text_table '31' text-053 text-038 lc_x3.

fill_text_table '32' text-053 text-039 lc_pa.

fill_text_table '33' text-053 text-041 lc_y2.

fill_text_table '34' text-053 text-046 lc_p8.

fill_text_table '35' text-053 text-047 lc_p9.

ENDMETHOD. "fill_text_table

ENDCLASS. "lcl_get_data IMPLEMENTATION

----


  • CLASS lcl_other_routines IMPLEMENTATION

----


*

----


CLASS lcl_other_routines IMPLEMENTATION.

METHOD display_header.

SELECT SINGLE butxt

FROM t001

INTO gv_butxt

WHERE bukrs = p_bukrs.

CALL FUNCTION 'MONTH_NAMES_GET'

EXPORTING

language = sy-langu

  • IMPORTING

  • RETURN_CODE =

TABLES

month_names = gt_t247

EXCEPTIONS

month_names_not_found = 1

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.

  • Month in parameter

READ TABLE gt_t247 INTO wa_t247 WITH KEY mnr = p_monat.

IF sy-subrc = 0.

ex_month_name = wa_t247-ltx.

ex_pres_month = wa_t247-ktx.

ENDIF.

  • January

READ TABLE gt_t247 INTO wa_t247 WITH KEY mnr = '01'.

IF sy-subrc = 0.

ex_jan = wa_t247-ktx.

ENDIF.

IF im_flag = 'X'.

WRITE: AT /60 gv_butxt,

AT /60 text-003,

AT /60 text-004,

AT 77 ex_month_name,

AT 86 p_gjahr.

ENDIF.

ENDMETHOD. "display_header

ENDCLASS. "lcl_other_routines IMPLEMENTATION

----


  • TOP-OF-PAGE *

----


TOP-OF-PAGE.

DATA: o_lcl_other_routines TYPE REF TO lcl_other_routines.

CREATE OBJECT o_lcl_other_routines.

CALL METHOD o_lcl_other_routines->display_header

EXPORTING

im_flag = 'X'.

----


  • START-OF-SELECTION *

----


START-OF-SELECTION.

DATA: o_lcl_get_data TYPE REF TO lcl_get_data.

CREATE OBJECT o_lcl_get_data.

CALL METHOD o_lcl_get_data->get_payment_details.

----


  • END-OF-SELECTION *

----


END-OF-SELECTION.

CALL METHOD o_lcl_get_data->display_data.

Hope it helps...

P.S. Please award points if it helps...

[/code]