Quantcast
Channel: ABAP Development
Viewing all articles
Browse latest Browse all 948

Screen process with ABAP OO

$
0
0

At last I have find time to write this . If you find anything wrong pls let me know.

 

As all you know screen process in ABAP has two main block PBO ( Process before output ) and PAI ( Process after input ). All screen has this block.

For dialog program I used this.

 

So we can declare a parent screen object for all screen which we use in program.

Definition:

CLASS lcl_screen DEFINITION ABSTRACT.   PUBLIC SECTION.
METHODS : constructor                IMPORTING                  i_dynnr TYPE sy-dynnr.
 * All screen process     METHODS : pbo ABSTRACT,               pai ABSTRACT                IMPORTING                  fcode TYPE sy-ucomm                RETURNING value(r_fcode) TYPE sy-ucomm,               free ABSTRACT.
 * Exit-command     METHODS : exit_command                IMPORTING                  fcode TYPE sy-ucomm.
 * Screen static methods     CLASS-METHODS : get_screen                      IMPORTING                        i_dynnr TYPE sy-dynnr                      RETURNING value(r_screen) TYPE REF TO lcl_screen.     CLASS-METHODS : del_screen                      IMPORTING                        i_dynnr TYPE sy-dynnr.
PRIVATE SECTION.     DATA : screen TYPE sy-dynnr.     TYPES : BEGIN OF lst_screen,              screen TYPE REF TO lcl_screen,             END OF lst_screen.     CLASS-DATA : t_screen TYPE STANDARD TABLE OF lst_screen.     CONSTANTS : c_class_name TYPE string VALUE 'LCL_SCREEN'.
ENDCLASS.                    "lcl_screen DEFINITION

Implementation

CLASS lcl_screen IMPLEMENTATION.   METHOD constructor.     screen = i_dynnr."Which screen   ENDMETHOD.                    "constructor   METHOD exit_command.     CASE fcode.       WHEN 'EXIT'.         LEAVE PROGRAM.     ENDCASE.   ENDMETHOD.                    "exit_command   METHOD get_screen.     DATA : ls_screen TYPE lst_screen,            lv_type TYPE string.     READ TABLE t_screen           INTO ls_screen       WITH KEY screen->screen = i_dynnr.     IF sy-subrc NE 0.       CONCATENATE c_class_name                   i_dynnr              INTO lv_type         SEPARATED BY '_'.       CREATE OBJECT ls_screen-screen TYPE (lv_type)         EXPORTING           i_dynnr = i_dynnr.       APPEND ls_screen           TO t_screen.     ENDIF.     r_screen ?= ls_screen-screen.   ENDMETHOD.                    "get_screen   METHOD del_screen.     DATA : ls_screen TYPE lst_screen,            lv_type TYPE string.     READ TABLE t_screen           INTO ls_screen       WITH KEY screen->screen = i_dynnr.     IF sy-subrc NE 0.
 * Screen doesnt exist       RETURN.     ENDIF.     ls_screen-screen->free( ).     DELETE t_screen      WHERE screen->screen = i_dynnr.   ENDMETHOD.                    "del_screen
ENDCLASS.                    "lcl_screen IMPLEMENTATION

In get_screen method, to decide which screen object will be created, logic is all screen object start with LCL_SCREEN_ and last 4 character is screen number. If screen object is not created, we create object and adding it to object table then returning screen object. If it is created just returning the object.

 

lets create our first screen :

9000.JPG

And screen module is:

 MODULE pbo OUTPUT.   lcl_screen=>get_screen( sy-dynnr )->pbo( ).
 ENDMODULE.                 " PBO  OUTPUT
MODULE pai INPUT.   gv_okcode = lcl_screen=>get_screen( sy-dynnr )->pai( gv_okcode ).
 ENDMODULE.                 " PAI  INPUT
MODULE exit_command INPUT.   lcl_screen=>get_screen( sy-dynnr )->exit_command( gv_okcode ).
 ENDMODULE.                 " EXIT_COMMAND  INPUT

Now lets create screen 9000 object

Definition

CLASS lcl_screen_9000 DEFINITION INHERITING FROM lcl_screen FINAL.   PUBLIC SECTION.     METHODS : pbo REDEFINITION,               pai REDEFINITION,               free REDEFINITION.   PRIVATE SECTION.
 * Screen 9000 methods     METHODS : set_exclude                RETURNING value(rt_ex) TYPE status_excl_fcode_tt.
 ENDCLASS.                    "lcl_screen_9000 DEFINITION

Implementation

CLASS lcl_screen_9000 IMPLEMENTATION.   METHOD pbo.     DATA : lt_ex TYPE status_excl_fcode_tt.     lt_ex = set_exclude( ).     SET PF-STATUS 'STATUS_9000' EXCLUDING lt_ex.     SET TITLEBAR '9000'.   ENDMETHOD.                    "pbo   METHOD set_exclude.     DATA : lv_ex TYPE fcode.     lv_ex = 'SAVE'.     APPEND lv_ex         TO rt_ex.   ENDMETHOD.                    "set_exclude   METHOD pai.     CASE fcode.       WHEN 'BACK'.           LEAVE TO SCREEN 0.     ENDCASE.   ENDMETHOD.                    "pai   METHOD free.
 * If we declare global object data, we can clear or refresh here!   ENDMETHOD.                    "free
 ENDCLASS.                    "lcl_screen_9000 IMPLEMENTATION

As you can see screen releated methods can be declare in screen object.

like set_exclude method.

 

If a method is global for all screen we can add to lcl_screen for example POPUP_TO_CONFIRM function. we can add this method to lcl_screen

 

TYPES : ty_text(400) TYPE c.     METHODS : call_popup                IMPORTING                  i_title TYPE text60                  i_text  TYPE ty_text                RETURNING value(r_answer) TYPE char1.
METHOD call_popup.     CALL FUNCTION 'POPUP_TO_CONFIRM'       EXPORTING         titlebar       = i_title         text_question  = i_text       IMPORTING         answer         = r_answer       EXCEPTIONS         text_not_found = 1         OTHERS         = 2.     IF sy-subrc <> 0.
 * Implement suitable error handling here     ENDIF.   ENDMETHOD.                    "call_popup

Now we can use this method in all screen.

 

METHOD pai.     CASE fcode.       WHEN 'BACK'.
IF call_popup( i_title = text-006                           i_text  = text-007 ) EQ '1'.           LEAVE TO SCREEN 0.         ENDIF.     ENDCASE.   ENDMETHOD.                    "pai

If we need to create ALV object in one screen we can add this to screen like, or picture element. Just we need to do declare screen object inherited from lcl_screen.

 

I hope you like it.

Have a nice day.


Viewing all articles
Browse latest Browse all 948

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>