Registration

Dear SAP Community Member,
In order to fully benefit from what the SAP Community has to offer, please register at:
http://scn.sap.com
Thank you,
The SAP Community team.
Skip to end of metadata
Go to start of metadata


- SAPmvc Main Page

- SAPmvc Page on Google Code


SAPmvc Documentation

Interaction Between SAPmvc Components

Once the model, view and controller objects are instantiated, the following occurs:

The view is registered as a Model's listener. Any changes in model's data result immediately in a broadcast change notification( Optional ), which the view receives.

Note that the model is not aware of the view or the controller, it simply broadcasts change notifications to all views interested listeners or just allows controllers and/or view to access its data.

The controller is bound to the view. This typically means that any user actions that are performed on the view will invoke a registered listener method in the controller class. The controller is given a reference to the underlying model.

Interaction Between SAPmvc Components and User

Once a user interacts with the view, the following actions occur:

The view recognizes the dynpro action ( e.g. pushing a button, request match code or request field help ) in PAI and trigger the appropriate event, thus all event handlers in controller that are listening this event are executed.

The controller access/update the model and call next view if it's necessary. If the model has been modified, it notifies interested views of the change. During the PBO the view trigger the appropriate events and all event handlers in controller that are listening this event are executed. In this moment the controller update the dynpro accessing the data in the model.

Back to Top

SAPmvc Interfaces

SAPmvc Interafaces are used to compound all main Attributes, Methods, Events necessary in MVC classes. SAPmvc has two Interfaces:

  • ZIF_SAPMVC_VIEW - It contains methods and events necessary to control the dynpro. It is implemented in SAPmvc View class and its subclasses.
  • ZIF_SAPMVC_CONTROLLER - It contains atributes and methods necessary to handler the user's interactions with the view. It is implemented in SAPmvc Controller class and its subclasses.


ZIF_SAPMVC_VIEW

This Interface contains methods and events necessary to control the dynpro. It is implemented in SAPmvc View class and its subclasses.

Create the View objects refering to ZIF_SAPMVC_VIEW. e.g.

DATA view TYPE REF TO zif_sapmvc_view.
*---------------------------------------------------------------------*
*      Module  set_view  OUTPUT
*---------------------------------------------------------------------*
MODULE get_view INPUT.
  ...
  TRY.

      "// View Creation
      view = zsapmvc_view=>create_view( repid      = program
                                        dynnr      = dynpro
                                        controller = controller ).

    CATCH zcx_sapmvc INTO exception.
      "// Display Long text message
      msg = exception->get_text( ).
      MESSAGE msg TYPE 'I'.

  ENDTRY.
  ...
ENDMODULE.                 " get_view  INPUT
*---------------------------------------------------------------------*
*      Module  get_view  INPUT
*---------------------------------------------------------------------*
MODULE set_view OUTPUT.
  ...

  "//Get View Instance
  view = zsapmvc_view=>get_view( repid = sy-repid 
			         dynnr = sy-dynnr ).
  ...

ENDMODULE.                 " set_view  OUTPUT	

Events


USER_COMMAND - User Command
PROCESS_AFTER_INPUT - PAI
PROCESS_BEFORE_OUTPUT - PBO
PF_STATUS - PF-Status
TITLEBAR - Titlebar
PROCESS_ON_VALUE_REQUEST - POV
PROCESS_ON_HELP_REQUEST - POH
TABSTRIP_ACTIVE_TAB_GET - Get Active Tabstrip Tab
TABSTRIP_ACTIVE_TAB_SET - Set Active Tabstrip Tab
AT_EXIT_COMMAND - At-User Command

Methods


TRIGGER_USER_COMMAND - Trigger The Event USER_COMMAND
TRIGGER_PAI - Trigger The Event PROCESS_AFTER_INPUT
TRIGGER_PBO - Trigger The Event PROCESS_BEFORE_OUTPUT
TRIGGER_STATUS - Trigger The Event PF_STATUS
TRIGGER_TITLEBAR - Trigger The Event TITLEBAR
TRIGGER_POV - Trigger The Event PROCESS_ON_VALUE_REQUEST
TRIGGER_POH - Trigger The Event PROCESS_ON_HELP_REQUEST
TRIGGER_TABSTRIP_ACTIVE_GET- Trigger The Event TABSTRIP_ACTIVE_TAB_GET
TRIGGER_TABSTRIP_ACTIVE_SET- Trigger The Event TABSTRIP_ACTIVE_TAB_SET
TRIGGER_AT_EXIT_COMMAND- Trigger The Event AT_EXIT_COMMAND
CHANGE_NOTIFICATION - Handle the Event

Back to Top

ZIF_SAPMVC_CONTROLLER


Create the Controller objects refering to ZIF_SAPMVC_CONTROLLER. e.g.

DATA controller TYPE REF TO zif_sapmvc_controller.
*---------------------------------------------------------------------*
*      Module  set_view  OUTPUT
*---------------------------------------------------------------------*
MODULE get_view INPUT.
  ...
  TRY.

      "// Controller and View Creation
      zsapmvc_controller=>create_controller( EXPORTING repid               = program
                                                       dynnr               = dynpro
                                             IMPORTING controller_instance = controller ).

    CATCH zcx_sapmvc INTO exception.
      "// Display Long text message
      msg = exception->get_text( ).
      MESSAGE msg TYPE 'I'.

  ENDTRY.
  ...

ENDMODULE.                 " get_view  INPUT
*---------------------------------------------------------------------*
*      Module  get_view  INPUT
*---------------------------------------------------------------------*
MODULE set_view OUTPUT.
  ...
  "//Get Controller Instance  
  controller = zsapmvc_controller=>get_controller( repid = program 
						   dynnr = dynpro ).
  ...

ENDMODULE.                 " set_view  OUTPUT	


It contains atributes and methods necessary to handler the user's interactions with the view. It is implemented in SAPmvc Controller class and its subclasses.


Attributes


PROGRAM - Program Name
DYNPRO - Screen Number
CONTROLLER_ERROR - Object of Class ZCX_SAPMVC used to Handle SAPmvc Exceptions

Methods


CREATE_MODEL - Create Model Instances
CALL_SCREEN - Call Screen
SET_DYNPRO - Set the actual Screen Number (Internal Use Only)
AT_EXIT_COMMAND - Handle the Event AT_EXIT_COMMAND of Interface ZIF_SAPMVC_VIEW.
USER_COMMAND - Handle the Event USER_COMMAND of Interface ZIF_SAPMVC_VIEW.
PROCESS_AFTER_INPUT - Handle the Event PROCESS_AFTER_INPUT of Interface ZIF_SAPMVC_VIEW.
PROCESS_BEFORE_OUTPUT - Handle the Event PROCESS_BEFORE_OUTPUT of Interface ZIF_SAPMVC_VIEW.
PF_STATUS - Handle the Event PF_STATUS of Interface ZIF_SAPMVC_VIEW.
TITLEBAR - Handle the Event TITLEBAR of Interface ZIF_SAPMVC_VIEW.
PROCESS_ON_VALUE_REQUEST - Handle the Event PROCESS_ON_VALUE_REQUEST of Interface ZIF_SAPMVC_VIEW.
PROCESS_ON_HELP_REQUEST - Handle the Event PROCESS_ON_HELP_REQUEST of Interface ZIF_SAPMVC_VIEW.
TABSTRIP_ACTIVE_TAB_GET - Handle the Event TABSTRIP_ACTIVE_TAB_GET of Interface ZIF_SAPMVC_VIEW.
TABSTRIP_ACTIVE_TAB_SET - Handle the Event TABSTRIP_ACTIVE_TAB_SET of Interface ZIF_SAPMVC_VIEW.

Back to Top

SAPmvc Classes

SAPmvc Classes contains all main Attributes, Methods, Events necessary. SAPmvc has four Classes:

  • ZCX_SAPMVC - This Exception Class is used to handle all SAPmvc errors.
  • ZSAPMVC_MODEL - It contains atributes, methods and events necessary to use MODEL in SAPmvc.
  • ZSAPMVC_VIEW - It contains atributes, methods and events necessary to renders the contents of ZSAPMVC_MODEL and trigger the events that ZSAPMVC_CONTROLLER will handle.
  • ZSAPMVC_CONTROLLER - It contains atributes, methods and events necessary to handle the ZSAPMVC_VIEW events and Control the ZSAPMVC_MODEL instances.

ZSAPMVC_MODEL

It contains atributes, methods and events necessary to use MODEL in SAPmvc. It contain the data and the application rules.

SAPmvc supports nested and compound Models. A compound Model contains one or more Models as component Models. These may contain further Models as components. A number of levels of nesting are therefore possible.
Models that do not contain other Models are referred to as simple Models.

If one or more models has been changed, it notifies interested views of the change. Several Models can notifies the same view and several Views or Controller can access the same Model.


Information

  • All Model class should be create inheriting from Global class ZSAPMVC_MODEL that contains Attributes, Methods and Events important to the processing. Others components can be added to the class.
  • All Model Instance must be created thru the static method CREATE_MODEL as described in USE section.
  • The Static method CREATE_MODEL should be called by method CREATE_MODEL of class ZSAPMVC_CONTROLLER.
  • All Exceptions in class ZSAPMVC_MODEL must be handled thru the Exception class ZCX_SAPMVC.


Attributes


All Attributes of class ZSAPMVC_MODEL are used only internally.

Events


All Events of class ZSAPMVC_MODEL are used only internally.

Methods


CREATE_MODEL - Create and validate the Model( ZSAPMVC_MODEL ) Instance.

Parameter Type

Optional

Parameter Name

Associated Type

Parameter Description

Importing

 

MODEL_REFERENCE

STRING

Name of Model Class inherited from ZSAPMVC_MODEL

Importing

 

REPID

SYREPID

ABAP Program

Returning

 

MODEL_INSTANCE

ZSAPMVC_MODEL Object

Instance of ZSAPMVC_MODEL

Exception

 

ZCX_SAPMVC

 

SAPmvc Exception Class


VIEW_NOTIFICATION - Setup the Data Change Condition, It will be called automatically after the notification through zsapmvc_view=>activate_change_notification. The implementation must be made in subclass method if necessary !

Parameter Type

Parameter Name

Associated Type

Parameter Description

Returning

NOTIFY_VIEW

ABAP_BOOL

To notify view set 'X' to View Notification Indicator.


Back to Top

Use


The Definition

*----------------------------------------------------------------------*
*       CLASS main_model DEFINITION
*----------------------------------------------------------------------*
CLASS main_model DEFINITION INHERITING FROM zsapmvc_model.

  PUBLIC SECTION.
    "// Display CARRID Value POV event
    METHODS value_spfli_carrid
            IMPORTING repid TYPE syrepid
                      dynnr TYPE sydynnr.

    "// Display CARRID Help on POH event
    METHODS help_spfli_carrid.

    "// Select Airline name from table scarr
    METHODS select_airline_name
        IMPORTING i_carrid TYPE s_carr_id
        RETURNING value(r_carrname) TYPE s_carrname
        EXCEPTIONS airline_code_not_found.

  PROTECTED SECTION.
    "// Set Conditions to View Notifications, It will be called 
    "// automatically after the notification through 
    "// zsapmvc_view=>activate_change_notification.
    METHODS view_notification REDEFINITION.

ENDCLASS.                    "main_model DEFINITION

The Implementation

CLASS main_model IMPLEMENTATION.

  METHOD value_spfli_carrid.
    "// Display CARRID Values
    CALL FUNCTION 'F4IF_FIELD_VALUE_REQUEST'
      EXPORTING
        tabname     = 'SPFLI'
        fieldname   = 'CARRID'
        dynpprog    = program
        dynpnr      = dynpro
        dynprofield = 'SPFLI-CARRID'.

  ENDMETHOD.                    "value_spfli_carrid

  METHOD help_spfli_carrid.
    "// Display CARRID help
    CALL FUNCTION 'HELP_OBJECT_SHOW_FOR_FIELD'
      EXPORTING
        doklangu         = sy-langu
        called_for_tab   = 'SPFLI'
        called_for_field = 'CARRID'.

  ENDMETHOD.                    "help_spfli_carrid

  METHOD select_airline_name.

    SELECT SINGLE carrname
      FROM scarr
      INTO r_carrname
      WHERE carrid EQ i_carrid.

    IF NOT sy-subrc IS INITIAL.
      RAISE airline_code_not_found.
    ENDIF.

  ENDMETHOD.                    "select_airline_name

  METHOD view_notification.
    "// Set Conditions to View Notifications
    MOVE 'X' TO notify_view.

  ENDMETHOD.                    "process_timer

ENDCLASS.                    "model IMPLEMENTATION

The Object

*----------------------------------------------------------------------*
*       CLASS main_controller DEFINITION
*----------------------------------------------------------------------*
CLASS main_controller DEFINITION INHERITING FROM zsapmvc_controller.

  PUBLIC SECTION.

    "// Model Object
    DATA model TYPE REF TO main_model.

    "// Create a Model Instance
    METHODS create_model REDEFINITION.

ENDCLASS.                    "main_controller DEFINITION

The Instance Creation

*----------------------------------------------------------------------*
*       CLASS main_controller IMPLEMENTATION
*----------------------------------------------------------------------*
CLASS main_controller IMPLEMENTATION.

  METHOD create_model.

    "// Create an Instance of class 'MAIN_MODEL'
    model ?= zsapmvc_model=>create_model( model_reference = 'MAIN_MODEL'
                                          repid           = sy-repid ).

  ENDMETHOD.                    "CREATE_MODEL

ENDCLASS.                    "main_controller IMPLEMENTATION

The View Notification Implementation

*----------------------------------------------------------------------*
*       CLASS view_notif DEFINITION
*----------------------------------------------------------------------*
CLASS view_notif DEFINITION INHERITING FROM zsapmvc_view.

  PUBLIC SECTION.
    "// Notify view about data changes
    METHODS change_notification REDEFINITION.

ENDCLASS.                    "view_notif DEFINITION

*----------------------------------------------------------------------*
*       CLASS view_notif IMPLEMENTATION
*----------------------------------------------------------------------*
CLASS view_notif IMPLEMENTATION.

  METHOD change_notification.

    MESSAGE 'This is a Model Notification About Data Change !' TYPE 'I'.

  ENDMETHOD.                    "CHANGE_NOTIFICATION

ENDCLASS.                    "view_notif IMPLEMENTATION

The View Notification Activation

  "// Activate the Change Notification every 10 minutes while repeat is equal 'X'
  zsapmvc_view=>activate_change_notification( model_instance = model_instance
                                              view_instance  = view_instance
                                              timeout        = 10
                                              repeat         = 'X' ).


More samples can be found on ZSAPMVC transaction.

Back to Top

ZSAPMVC_VIEW

It contains atributes, methods and events necessary to renders the contents of ZSAPMVC_MODEL and trigger the events handled by ZSAPMVC_CONTROLLER.

Each View has its own instance and can access one or more Model and can be accessed by one or more Controller.

The View methods are called within Modules in PAI and PBO.

The View methods trigger the events handled by event handler of Controller.

Information

  • The class ZSAPMVC_VIEW contains all Methods and Events important to the processing, but if you need to add more components or functionality you should create a new class inheriting from Global class ZSAPMVC_VIEW.
  • All View Instance must be created thru the static method CREATE_VIEW as described in USE section.
  • All Exceptions in class ZSAPMVC_VIEW must be handled thru the Exception class ZCX_SAPMVC.


Attributes


Name

Level

Visibility

Associated Type

Description

PROGRAM

Instance

Protected

SYREPID

Program Name

DYNPRO

Instance

Protected

SYDYNNR

Dynpro Number


Events


ZIF_SAPMVC_VIEW~USER_COMMAND - User Command
ZIF_SAPMVC_VIEW~PROCESS_AFTER_INPUT
ZIF_SAPMVC_VIEW~PROCESS_BEFORE_OUTPUT
ZIF_SAPMVC_VIEW~PF_STATUS
ZIF_SAPMVC_VIEW~TITLEBAR
ZIF_SAPMVC_VIEW~PROCESS_ON_VALUE_REQUEST
ZIF_SAPMVC_VIEW~PROCESS_ON_HELP_REQUEST
ZIF_SAPMVC_VIEW~TABSTRIP_ACTIVE_TAB_GET
ZIF_SAPMVC_VIEW~TABSTRIP_ACTIVE_TAB_SET
ZIF_SAPMVC_VIEW~AT_EXIT_COMMAND

Back to Top

Methods


- SET_VIEW_REFERENCE - Register the Class View name and link to program and Dynpro. This information is used by method CREATE_VIEW during the View instance creation. This method is optional, we can inform the view class reference directly to method CREATE_VIEW.

Use this method only if you have a class inheriting from "ZSAPMVC_VIEW" or its subclasses. Otherwise use the method CREATE_VIEW without view reference thus a new instance of "ZSAPMVC_VIEW" is created.

Parameter Type

Optional

Parameter Name

Associated Type

Parameter Description

Importing

 

DYNNR

SYDYNNR

Screen Number

Importing

 

REPID

SYREPID

Program Name

Importing

 

VIEW_REFERENCE

STRING

View Class Name

Exceptions

 

ZCX_SAPMVC

ZCX_SAPMVC

SAPmvc Class Based Exceptions


Use


"// Register program, dynpro and View Class Reference
zsapmvc_view=>set_view_reference( repid          = program
                                  dynnr          = dynpro
                                  view_reference = 'VIEW_NOTIF' ).


- DELETE_VIEW_REFERENCE - Delete the View reference.

Parameter Type

Optional

Parameter Name

Associated Type

Parameter Description

Importing

 

DYNNR

SYDYNNR

Screen Number

Importing

 

REPID

SYREPID

Program Name

Importing

 

DELETE_ALL

ABAP_BOOL

Delelte all View Instance

Exceptions

 

ZCX_SAPMVC

ZCX_SAPMVC

SAPmvc Class Based Exceptions


- CREATE_VIEW - Create View Instance based on a View Class reference.

Parameter Type

Optional

Parameter Name

Associated Type

Parameter Description

Importing

 

DYNNR

SYDYNNR

Screen Number

Importing

 

REPID

SYREPID

Program Name

Importing

 

CONTROLLER

ZIF_SAPMVC_CONTROLLER

Controller Instance

Importing

X

VIEW_REFERENCE

STRING

View Class Name

Returning

 

VIEW_INSTANCE

ZIF_SAPMVC_VIEW

View Instance

Exceptions

 

ZCX_SAPMVC

ZCX_SAPMVC

SAPmvc Class Based Exceptions


Use


On Dynpro

PROCESS BEFORE OUTPUT.

  MODULE set_view.

  ...

PROCESS AFTER INPUT.
  
  ...


We can create the View Instance using Registered View Reference.

*&---------------------------------------------------------------------*
*&      Module  set_view  OUTPUT
*&---------------------------------------------------------------------*
*       Create View and Controller instance
*----------------------------------------------------------------------*
MODULE set_view OUTPUT.

  ...

  "//View Creation
  TRY.
      view = zsapmvc_view=>create_view( repid      = program
                                        dynnr      = dynpro
                                        controller = controller ).

   CATCH zcx_sapmvc INTO exception.
    "// Display Long text message
    msg = exception->get_text( ).
    MESSAGE msg TYPE 'I'.

  ENDTRY.

  ...

ENDMODULE.                 " set_view  OUTPUT


Or we can create the View Instance through the Controller Method "create_controller" it uses the registered View Reference to create a new instance of View:

*&---------------------------------------------------------------------*
*&      Module  set_view  OUTPUT
*&---------------------------------------------------------------------*
*       Create View and Controller instance
*----------------------------------------------------------------------*
MODULE set_view OUTPUT.
  ...

  TRY.
    "// Controller and View Creation
    zsapmvc_controller=>create_controller( EXPORTING repid               = program
                                                     dynnr               = dynpro
                                           IMPORTING controller_instance = controller
                                                     view_instance       = view ).


    CATCH zcx_sapmvc INTO exception.
      "//Display Long text message
      msg = exception->get_text( ).
      MESSAGE msg TYPE 'I'.
  ENDTRY.

  ...

ENDMODULE.                 " set_view  OUTPUT


Also we can create the View Instance passing the reference name directly to "view_reference" parameter as follow

*&---------------------------------------------------------------------*
*&      Module  set_view  OUTPUT
*&---------------------------------------------------------------------*
*       Create View and Controller instance
*----------------------------------------------------------------------*
MODULE set_view OUTPUT.

  ...
  "//View Creation
  TRY.
    view = zsapmvc_view=>create_view( repid      = program
                                        dynnr      = dynpro
                                        controller = controller ).
                                        view_reference = 'VIEW_NOTIF' ).
     CATCH zcx_sapmvc INTO exception.
      "//Display Long text message
      msg = exception->get_text( ).
      MESSAGE msg TYPE 'I'.

  ENDTRY.

  ...

ENDMODULE.                 " set_view  OUTPUT


- GET_VIEW - Get View Instance.

Parameter Type

Optional

Parameter Name

Associated Type

Parameter Description

Importing

 

DYNNR

SYDYNNR

Screen Number

Importing

 

REPID

SYREPID

Program Name

Returning

 

VIEW_INSTANCE

ZIF_SAPMVC_VIEW

View Instance

Exceptions

 

ZCX_SAPMVC

ZCX_SAPMVC

SAPmvc Class Based Exceptions


Use


On Dynpro

PROCESS BEFORE OUTPUT.
...


PROCESS AFTER INPUT.
  ...

  MODULE get_view.
  ...


On PAI Modules

*&---------------------------------------------------------------------*
*&      Module  get_view  INPUT
*&---------------------------------------------------------------------*
*       Get Controller and View Instance
*----------------------------------------------------------------------*
MODULE get_view INPUT.
  ...

  TRY.
    "// Get View Instnce for actual program and dynpro
    view = zsapmvc_view=>get_view( repid = program dynnr = dynpro ).

    CATCH zcx_sapmvc INTO exception.
      "// Display Long text message
      msg = exception->get_text( ).
      MESSAGE msg TYPE 'E'.

  ENDTRY.

ENDMODULE.                 " get_view  INPUT


- ZIF_SAPMVC_VIEW~CHANGE_NOTIFICATION - Handle the event CHANGE_NOTIFICATION of class ZSAPMVC_MODEL.

Parameter Type

Optional

Parameter Name

Associated Type

Parameter Description

Importing

 

FIELD

DYNFNAM

Name of field Changed in Model


Use


Place here action that will be executed when Model notify the View. This method will be called automatically by Model before activation.

*----------------------------------------------------------------------*
*       CLASS view_notif DEFINITION
*----------------------------------------------------------------------*
CLASS view_notif DEFINITION INHERITING FROM zsapmvc_view.

  PUBLIC SECTION.

    METHODS change_notification REDEFINITION.

ENDCLASS.                    "view_notif DEFINITION

*----------------------------------------------------------------------*
*       CLASS view_notif IMPLEMENTATION
*----------------------------------------------------------------------*
CLASS view_notif IMPLEMENTATION.

  METHOD change_notification.

    "// Place here what to do when Model notify the View 
    MESSAGE 'This a Model Notification About Data Change !' TYPE 'I'.

  ENDMETHOD.                    "CHANGE_NOTIFICATION

ENDCLASS.                    "view_notif IMPLEMENTATION


- ACTIVATE_CHANGE_NOTIFICATION - Active and setup the attributes of the Model Nofication for View Instance.

Parameter Type

Optional

Parameter Name

Associated Type

Parameter Description

Importing

 

MODEL_INSTANCE

ZSAPMVC_MODEL

Model Instance

Importing

 

VIEW_INSTANCE

ZIF_SAPMVC_VIEW

View Instance

Importing

X

TIMEOUT

I

Time to Notification

Importing

X

REPEAT

ABAP_BOOL

Repeat Notification

Exceptions

 

ZCX_SAPMVC

ZCX_SAPMVC

SAPmvc Class Based Exceptions


- DEACTIVATE_CHANGE_NOTIFICATION - Deactive the Model Nofication for actual View Instance.

Parameter Type

Optional

Parameter Name

Associated Type

Parameter Description

Importing

 

MODEL_INSTANCE

ZSAPMVC_MODEL

Model Instance

Importing

 

VIEW_INSTANCE

ZIF_SAPMVC_VIEW

View Instance

Exceptions

 

ZCX_SAPMVC

ZCX_SAPMVC

SAPmvc Class Based Exceptions


- ZIF_SAPMVC_VIEW~TRIGGER_USER_COMMAND - Trigger the Event USER_COMMAND.

Parameter Type

Optional

Parameter Name

Associated Type

Parameter Description

Importing

 

UCOMM

SYUCOMM

Function code triggered in PAI


- ZIF_SAPMVC_VIEW~TRIGGER_POV - Trigger the Event PROCESS_ON_VALUE_REQUEST.

Parameter Type

Optional

Parameter Name

Associated Type

Parameter Description

Importing

 

FIELD

DYNFNAM

Field Name


- ZIF_SAPMVC_VIEW~TRIGGER_POH - Trigger the Event PROCESS_ON_HELP_REQUEST.

Parameter Type

Optional

Parameter Name

Associated Type

Parameter Description

Importing

 

FIELD

DYNFNAM

Field Name


- ZIF_SAPMVC_VIEW~TRIGGER_TABSTRIP_ACTIVE_GET - Trigger the Event TABSTRIP_ACTIVE_TAB_GET.

Parameter Type

Optional

Parameter Name

Associated Type

Parameter Description

Importing

 

UCOMM

DYUCOMM

Function code triggered in PAI


- ZIF_SAPMVC_VIEW~TRIGGER_TABSTRIP_ACTIVE_SET - Trigger the Event TABSTRIP_ACTIVE_TAB_SET.

Parameter Type

Optional

Parameter Name

Associated Type

Parameter Description

Importing

 

UCOMM

DYUCOMM

Function code triggered in PBO


- ZIF_SAPMVC_VIEW~TRIGGER_AT_EXIT_COMMAND - Trigger the Event AT_EXIT_COMMAND.

Parameter Type

Optional

Parameter Name

Associated Type

Parameter Description

Importing

 

UCOMM

DYUCOMM

Function code triggered in PAI


- ZIF_SAPMVC_VIEW~TRIGGER_PAI - Trigger the Event PROCESS_AFTER_INPUT.
- ZIF_SAPMVC_VIEW~TRIGGER_PBO - Trigger the Event PROCESS_BEFORE_OUTPUT.
- ZIF_SAPMVC_VIEW~TRIGGER_STATUS - Trigger the Event PF_STATUS.
- ZIF_SAPMVC_VIEW~TRIGGER_TITLEBAR - Trigger the Event TITLEBAR.

Use


On dynpro

PROCESS BEFORE OUTPUT.

  ...

  MODULE status.

  MODULE process_pbo.

PROCESS AFTER INPUT.

  ...

  CHAIN.
    FIELD: spfli-carrid MODULE process_pai.
  ENDCHAIN.

  MODULE user_command.

  MODULE at_exit_command AT EXIT-COMMAND.

PROCESS ON VALUE-REQUEST.
  FIELD spfli-carrid MODULE value_spfli_carrid.

PROCESS ON HELP-REQUEST.
  FIELD spfli-carrid MODULE help_spfli_carrid.


On PBO Modules

*&---------------------------------------------------------------------*
*&      Module  status  OUTPUT
*&---------------------------------------------------------------------*
*       Set PF-Status and Titlebar
*----------------------------------------------------------------------*
MODULE status OUTPUT.

  view->trigger_status( ).
  view->trigger_titlebar( ).

ENDMODULE.                 " status  OUTPUT

*&---------------------------------------------------------------------*
*&      Module  process_pbo  OUTPUT
*&---------------------------------------------------------------------*
*       General validation on PBO
*----------------------------------------------------------------------*
MODULE process_pbo OUTPUT.

  view->trigger_pbo( ).

ENDMODULE.                 " process_pbo  OUTPUT



On PAI Modules

*&---------------------------------------------------------------------*
*&      Module  process_pai  INPUT
*&---------------------------------------------------------------------*
*       General validation on PAI
*----------------------------------------------------------------------*
MODULE process_pai INPUT.

  view->trigger_pai( ).

ENDMODULE.                 " process_pai  INPUT

*&---------------------------------------------------------------------*
*&      Module  USER_COMMAND_0001  INPUT
*&---------------------------------------------------------------------*
*       Validation of User's actions
*----------------------------------------------------------------------*
MODULE user_command INPUT.

  view->trigger_user_command( ucomm = sy-ucomm ).

ENDMODULE.                 " USER_COMMAND  INPUT

*----------------------------------------------------------------------*
*  MODULE AT_EXIT_COMMAND INPUT
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
MODULE at_exit_command INPUT.

  MOVE: sy-repid TO program,
        sy-dynnr TO dynpro.

  controller = zsapmvc_controller=>get_controller( repid = program dynnr = dynpro ).

  view = zsapmvc_view=>get_view( repid = program dynnr = dynpro ).

  view->trigger_at_exit_command( ucomm = sy-ucomm ).

ENDMODULE.                    "AT_EXIT_COMMAND INPUT

*----------------------------------------------------------------------*
*      MODULE value_spfli_carrid INPUT
*----------------------------------------------------------------------*
*      Always Get the instance of the Controller and Screen before
*      trigger event POV
*----------------------------------------------------------------------*
MODULE value_spfli_carrid INPUT.

  MOVE: sy-repid TO program,
        sy-dynnr TO dynpro.

  controller = zsapmvc_controller=>get_controller( repid = program dynnr = dynpro ).

  view = zsapmvc_view=>get_view( repid = program dynnr = dynpro ).

  view->trigger_pov( EXPORTING field = 'SPFLI-CARRID' ).

ENDMODULE.                    "value_spfli_carrid INPUT

*----------------------------------------------------------------------*
*  MODULE help_spfli_carrid INPUT
*----------------------------------------------------------------------*
*      Always Get the instance of the Controller and Screen before
*      trigger event POH
*----------------------------------------------------------------------*
MODULE help_spfli_carrid INPUT.

  MOVE: sy-repid TO program,
        sy-dynnr TO dynpro.

  controller = zsapmvc_controller=>get_controller( repid = program dynnr = dynpro ).

  view = zsapmvc_view=>get_view( repid = program dynnr = dynpro ).

  view->trigger_poh( EXPORTING field = 'SPFLI-CARRID' ).

ENDMODULE.                    "help_spfli_carrid INPUT


More samples can be found on ZSAPMVC transaction.

Back to Top

ZSAPMVC_CONTROLLER

It contains atributes and methods necessary to handle the user's interactions with the view (ZSAPMVC_VIEW) and get and perform data to model (ZSAPMVC_MODEL).

The Controller methods handle the events of View.

Information

  • The class ZSAPMVC_CONTROLLER contains all Methods to handle the View events, we should inherit the class and implement all necessary methods also we can to add more components or functionality to the inherited class.
  • All Controller Instance must be created thru the static method CREATE_CONTROLLER as described in USE section.
  • All Exceptions in class ZSAPMVC_CONTROLLER must be handled thru the Exception class ZCX_SAPMVC.


Attributes


Name

Level

Alias

Visibility

Associated Type

Description

ZIF_SAPMVC_CONTROLLER~PROGRAM

Instance

PROGRAM

Protected

SYREPID

Program Name

ZIF_SAPMVC_CONTROLLER~DYNPRO

Instance

DYNPRO

Protected

SYDYNNR

Dynpro Number

ZIF_SAPMVC_CONTROLLER~CONTROLLER_ERROR

Instance

CONTROLLER_ERROR

Protected

ZCX_SAPMVC

SAPmvc Exceptions

Back to Top

Methods


- SET_CONTROLLER_REFERENCE - Register the Class Controller name and link to Program and Dynpro. This information is used by method CREATE_CONTROLLER during the Controller instance creation. This method is optional, we can inform the Controller class reference directly to method CREATE_CONTROLLER.

Parameter Type

Optional

Parameter Name

Associated Type

Parameter Description

Importing

 

DYNNR

SYDYNNR

Screen Number

Importing

 

REPID

SYREPID

Program Name

Importing

 

CONTROLLER_REFERENCE

STRING

Controller Class Name

Exceptions

 

ZCX_SAPMVC

ZCX_SAPMVC

SAPmvc Class Based Exceptions


Use


TRY.
    "// Register Program Dynpro and Controller Class Reference
    CASE sy-dynnr.
      WHEN 0001 OR 0002 OR 0003 OR 0014.
        zsapmvc_controller=>set_controller_reference
                                     ( repid                = program
                                       dynnr                = dynpro
                                       controller_reference = 'MAIN_CONTROLLER' ).

      WHEN 0005.
        zsapmvc_controller=>set_controller_reference
                                     ( repid                = program
                                       dynnr                = dynpro
                                       controller_reference = 'ALV_CONTROLLER' ).

      WHEN 0006.
        zsapmvc_controller=>set_controller_reference
                                     ( repid                = program
                                       dynnr                = dynpro
                                       controller_reference = 'TABLE_CONTROL_CONTROLLER' ).

    ENDCASE.

  CATCH zcx_sapmvc INTO exception.
      "// Display Long text message
      msg = exception->get_text( ).
      MESSAGE msg TYPE 'I'.
ENDTRY.


- DELETE_CONTROLLER_REFERENCE - Delete the Controller reference.

Parameter Type

Optional

Parameter Name

Associated Type

Parameter Description

Importing

X

DYNNR

SYDYNNR

Screen Number

Importing

X

REPID

SYREPID

Program Name

Importing

X

DELETE_ALL

ABAP_BOOL

Delete All Controller Instance

Exceptions

 

ZCX_SAPMVC

ZCX_SAPMVC

SAPmvc Class Based Exceptions


- CREATE_CONTROLLER - Create Controller Instance based on a Controller Class reference.

Parameter Type

Optional

Parameter Name

Associated Type

Parameter Description

Importing

 

DYNNR

SYDYNNR

Screen Number

Importing

 

REPID

SYREPID

Program Name

Importing

X

CONTROLLER_REFERENCE

STRING

Controller Class Name

Exporting

 

VIEW_INSTANCE

ZIF_SAPMVC_VIEW

View Instance

Exporting

 

CONTROLLER_INSTANCE

ZIF_SAPMVC_CONTROLLER

Controller Instance

Exceptions

 

ZCX_SAPMVC

ZCX_SAPMVC

SAPmvc Class Based Exceptions


Use


On Dynpro

PROCESS BEFORE OUTPUT.

  MODULE set_view.

  ...

PROCESS AFTER INPUT.
  
  ...


We can create the Controller Instance using Registered Controller Reference.

*&---------------------------------------------------------------------*
*&      Module  set_view  OUTPUT
*&---------------------------------------------------------------------*
*       Create View and Controller instance
*----------------------------------------------------------------------*
MODULE set_view OUTPUT.

  ...

  TRY.
    "// Controller Creation
    zsapmvc_controller=>create_controller( EXPORTING repid               = program
                                                     dynnr               = dynpro
                                           IMPORTING controller_instance = controller ).

   CATCH zcx_sapmvc INTO exception.
    "// Display Long text message
    msg = exception->get_text( ).
    MESSAGE msg TYPE 'I'.

  ENDTRY.

  ...

ENDMODULE.                 " set_view  OUTPUT


Also we can create the Controller Instance passing the reference name directly to "controller_reference" parameter as follow

*&---------------------------------------------------------------------*
*&      Module  set_view  OUTPUT
*&---------------------------------------------------------------------*
*       Create View and Controller instance
*----------------------------------------------------------------------*
MODULE set_view OUTPUT.

  ...

  "// Controller Creation
  TRY.

      CASE sy-dynnr.
        WHEN 0001 OR 0002 OR 0003 OR 0014.

          zsapmvc_controller=>create_controller
                           ( EXPORTING repid                = program
                                       dynnr                = dynpro
                             IMPORTING controller_instance  = controller
                                       controller_reference = 'MAIN_CONTROLLER' ).


        WHEN 0005.

         zsapmvc_controller=>create_controller
                           ( EXPORTING repid                = program
                                       dynnr                = dynpro
                             IMPORTING controller_instance  = controller
                                       controller_reference = 'ALV_CONTROLLER' ).

        WHEN 0006.

         zsapmvc_controller=>create_controller
                           ( EXPORTING repid                = program
                                       dynnr                = dynpro
                             IMPORTING controller_instance  = controller
                                       controller_reference = 'TABLE_CONTROL_CONTROLLER' ).

      ENDCASE.

    CATCH zcx_sapmvc INTO exception.
      "// Display Long text message
      msg = exception->get_text( ).
      MESSAGE msg TYPE 'I'.
  ENDTRY.

  ...

ENDMODULE.                 " set_view  OUTPUT


- GET_CONTROLLER - Get Controller Instance.

Parameter Type

Optional

Parameter Name

Associated Type

Parameter Description

Importing

X

DYNNR

SYDYNNR

Screen Number

Importing

X

REPID

SYREPID

Program Name

Importing

X

CONTROLLER_REFERENCE

STRING

Controller Reference Name

Returning

 

CONTROLLER_INSTANCE

ZIF_SAPMVC_CONTROLLER

Controller Instance

Exceptions

 

ZCX_SAPMVC

ZCX_SAPMVC

SAPmvc Class Based Exceptions


Use


On Dynpro

PROCESS BEFORE OUTPUT.
...


PROCESS AFTER INPUT.
  ...

  MODULE get_view.
  ...


On PAI Modules

*&---------------------------------------------------------------------*
*&      Module  get_view  INPUT
*&---------------------------------------------------------------------*
*       Get Controller and View Instance
*----------------------------------------------------------------------*
MODULE get_view INPUT.
  ...

  TRY.
    "// Get Controller Instance for actual program and dynpro
     controller = zsapmvc_controller=>get_controller( repid = program dynnr = dynpro ).

    CATCH zcx_sapmvc INTO exception.
      "// Display Long text message
      msg = exception->get_text( ).
      MESSAGE msg TYPE 'E'.

  ENDTRY.

ENDMODULE.                 " get_view  INPUT


- ZIF_SAPMVC_CONTROLLER~CREATE_MODEL - Create the Models Instance.

Use


*----------------------------------------------------------------------*
*       CLASS main_controller DEFINITION
*----------------------------------------------------------------------*
* Main Controller Class
*----------------------------------------------------------------------*
CLASS main_controller DEFINITION INHERITING FROM zsapmvc_controller.

  PUBLIC SECTION.

    "// Model Object
    DATA model TYPE REF TO main_model.

    METHODS create_model             REDEFINITION.

ENDCLASS.                    "main_controller DEFINITION

*----------------------------------------------------------------------*
*       CLASS main_controller IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS main_controller IMPLEMENTATION.

  METHOD create_model.

    "// Create Model Instance
    model ?= zsapmvc_model=>create_model( model_reference = 'MAIN_MODEL' 
                                          repid           = sy-repid ).

  ENDMETHOD.                    "CREATE_MODEL

ENDCLASS.                    "main_controller IMPLEMENTATION


- ZIF_SAPMVC_CONTROLLER~AT_EXIT_COMMAND - Handle the event AT-EXIT COMMAND.

Parameter Type

Optional

Parameter Name

Associated Type

Parameter Description

Importing

 

UCOMM

SYUCOMM

Function code triggered in PAI


- ZIF_SAPMVC_CONTROLLER~USER_COMMAND - Handle the event AT-USER COMMAND.

Parameter Type

Optional

Parameter Name

Associated Type

Parameter Description

Importing

 

UCOMM

SYUCOMM

Function code triggered in PAI


- ZIF_SAPMVC_CONTROLLER~PROCESS_AFTER_INPUT - Handle the event PAI for Generics actions.

Parameter Type

Optional

Parameter Name

Associated Type

Parameter Description

Importing

 

DYNNR

SYDYNNR

Screen Number

Importing

 

REPID

SYREPID

Program Name


- ZIF_SAPMVC_CONTROLLER~PROCESS_BEFORE_OUTPUT - Handle the event PBO for Generics actions.

Parameter Type

Optional

Parameter Name

Associated Type

Parameter Description

Importing

 

DYNNR

SYDYNNR

Screen Number

Importing

 

REPID

SYREPID

Program Name


- ZIF_SAPMVC_CONTROLLER~PF_STATUS - Handle the event PF-STATUS.

Parameter Type

Optional

Parameter Name

Associated Type

Parameter Description

Importing

 

DYNNR

SYDYNNR

Screen Number

Importing

 

REPID

SYREPID

Program Name


- ZIF_SAPMVC_CONTROLLER~TITLEBAR - Handle the event TITLEBAR.

Parameter Type

Optional

Parameter Name

Associated Type

Parameter Description

Importing

 

DYNNR

SYDYNNR

Screen Number

Importing

 

REPID

SYREPID

Program Name


- ZIF_SAPMVC_CONTROLLER~PROCESS_ON_HELP_REQUEST - Handle the event POH.

Parameter Type

Optional

Parameter Name

Associated Type

Parameter Description

Importing

 

FIELD

DYNFNAM

Field Name for Value Help


- ZIF_SAPMVC_CONTROLLER~PROCESS_ON_VALUE_REQUEST - Handle the event POV.

Parameter Type

Optional

Parameter Name

Associated Type

Parameter Description

Importing

 

FIELD

DYNFNAM

Field Name for Value Request


- ZIF_SAPMVC_CONTROLLER~TABSTRIP_ACTIVE_TAB_GET - Handle the event TABSTRIP_ACTIVE_TAB_GET to Get active Tab of Tabstrip.

Parameter Type

Optional

Parameter Name

Associated Type

Parameter Description

Importing

 

UCOMM

SYUCOMM

Code of Tabstrip


- ZIF_SAPMVC_CONTROLLER~TABSTRIP_ACTIVE_TAB_SET - Handle the event TABSTRIP_ACTIVE_TAB_SET to Set active Tab of Tabstrip.

Parameter Type

Optional

Parameter Name

Associated Type

Parameter Description

Importing

 

UCOMM

SYUCOMM

Code of Tabstrip


- ZIF_SAPMVC_CONTROLLER~CALL_SCREEN - Call a Screen.

Parameter Type

Optional

Parameter Name

Associated Type

Parameter Description

Importing

 

DYNPRO

DYNNR

Number of the following screen

Importing

 

STARTING_COLUMN

SCRHUSEC

Starting Column

Importing

 

STARTING_LINE

SCRHUSEL

Starting Line

Importing

 

ENDING_COLUMN

SCRHUSEC

Ending Column

Importing

 

ENDING_LINE

SCRHUSEL

Ending Line


Back to Top

Use


*----------------------------------------------------------------------*
*       CLASS main_controller DEFINITION
*----------------------------------------------------------------------*
* Main Controller Class
*----------------------------------------------------------------------*
CLASS main_controller DEFINITION INHERITING FROM zsapmvc_controller.

  PUBLIC SECTION.

    "// Model Object
    DATA model TYPE REF TO main_model.

    METHODS pf_status                REDEFINITION.
    METHODS titlebar                 REDEFINITION.
    METHODS user_command             REDEFINITION.
    METHODS at_exit_command          REDEFINITION.
    METHODS process_after_input      REDEFINITION.
    METHODS process_before_output    REDEFINITION.
    METHODS process_on_value_request REDEFINITION.
    METHODS process_on_help_request  REDEFINITION.

ENDCLASS.                    "main_controller DEFINITION


*----------------------------------------------------------------------*
*       CLASS main_controller IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS main_controller IMPLEMENTATION.

  METHOD pf_status.

    "// Set up PF-Status
    SET PF-STATUS 'STATUS_0001'.

  ENDMETHOD.                    "pf_status

  METHOD titlebar.
    "// Set up TitleBar
    SET TITLEBAR 'TITLE_0001'.

  ENDMETHOD.                    "TITLEBAR

  METHOD user_command.

    CASE ucomm.
      WHEN 'DISPLAY' OR 'OPTIONS'.

        IF spfli-carrid IS NOT INITIAL.

          CALL METHOD model->select_flight_schedule
            EXPORTING
              i_carrid                  = spfli-carrid
            EXCEPTIONS
              flight_schedule_not_found = 1.

        ENDIF.

      WHEN 'SAMPLES'.

        "// Call Screen with "SAMPLES"
        me->call_screen( dynpro = '0014'
                         starting_column = 020
                         starting_line   = 010
                         ending_column   = 045
                         ending_line     = 015 ).
    ENDCASE.

  ENDMETHOD.                    "user_command

  METHOD at_exit_command.

    CASE ucomm.
      WHEN 'EXIT' OR 'CANC'.
        LEAVE PROGRAM.
      WHEN 'CONF'.
        LEAVE TO SCREEN 0.
    ENDCASE.

  ENDMETHOD.                    "AT_EXIT_COMMAND

  METHOD process_after_input.

    IF spfli-carrid IS NOT INITIAL.
      "// Select Airline Codes
      CALL METHOD model->select_airline_name
        EXPORTING
          i_carrid               = spfli-carrid
        RECEIVING
          r_carrname             = scarr-carrname
        EXCEPTIONS
          airline_code_not_found = 1.

      IF sy-subrc IS NOT INITIAL.
        MESSAGE ID 'SU' TYPE 'E' NUMBER 000 WITH 'Airline Code Doesn't Exists!'.
      ENDIF.
    ENDIF.

  ENDMETHOD.                    "process_after_input

  METHOD process_before_output.
    "// Setup SubScreen
    subscreen_options       = me->get_display_options_dynpro( ).
    subscreen_information   = me->get_display_info_dynpro( ).
    subscreen_documentation = me->get_display_doc_dynpro( ).
    subscreen_display       = me->get_display_dynpro( ).
    subscreen_notification  = me->get_display_notify_dynpro( ).

  ENDMETHOD.                    "process_before_output

  METHOD process_on_value_request.

    CASE field.
      WHEN 'SPFLI-CARRID'.
         ...
      WHEN OTHERS.
         ...
    ENDCASE.

  ENDMETHOD.                    "process_on_value_request

  METHOD process_on_help_request.

    CASE field.
      WHEN 'SPFLI-CARRID'.
        "// Diplay Help on POH event
        model->help_spfli_carrid( ).

      WHEN OTHERS.
        ...
    ENDCASE.

  ENDMETHOD.                    "process_on_help_request

ENDCLASS.                    "main_controller IMPLEMENTATION


Back to Top

More samples can be found on ZSAPMVC transaction.

Back to Top

Page Visits