Skip to content

Latest commit

 

History

History
125 lines (104 loc) · 5.9 KB

implementing-the-business-logic-99dcde1.md

File metadata and controls

125 lines (104 loc) · 5.9 KB

Implementing the Business Logic

Business logic is ABAP coding that you want to be run within an application job. Usually this coding also defines selection fields. In this context, business logic is implemented in a class. The following development steps require a user with the development role.

Create a class which implements the two interfaces:

  • IF_APJ_DT_EXEC_OBJECT
  • IF_APJ_RT_EXEC_OBJECT

This class is considered the main class per application job. This class needs to be part of a customer-defined software component (not ZLOCAL) in order to be able to transport the class into subsequent systems.

The first interface, IF_APJ_DT_EXEC_OBJECT, contains design-time related methods. Method GET_PARAMETERS( ) is called by the application jobs framework to get all supported selection parameters.

The method GET_PARAMETERS( ) returns two internal tables:

  • The content of the table ET_PARAMETER_DEF determines the parameter section for the job catalog entry, which will refer to this main class.
  • The content of the table ET_PARAMETER_VAL determines the default values for these parameters in the job template, which will refer to the job catalog entry mentioned above.

The second interface, IF_APJ_RT_EXEC_OBJECT, contains runtime related methods. Method EXECUTE() is called by the application jobs framework if a scheduled job will actually be executed. It receives an internal table as parameter. This table is of the same type as the table ET_PARAMETER_VAL of method GET_PARAMETERS(). The method EXECUTE() simply receives the parameters and values, which were stored in the template and which were originally delivered by the method GET_PARAMETERS().

Please refer to the example code for an application jobs main class. Literals are used instead of language-dependent texts in order to simplify the example. For writing application log entries, please refer to Runtime API

Sample Code:

CLASS zcl_test_apj_simple DEFINITION
  PUBLIC
  FINAL
  CREATE PUBLIC .

  PUBLIC SECTION.
    INTERFACES if_apj_dt_exec_object.
    INTERFACES if_apj_rt_exec_object.
  PROTECTED SECTION.
  PRIVATE SECTION.
ENDCLASS.


CLASS zcl_test_apj_simple IMPLEMENTATION.

  METHOD if_apj_dt_exec_object~get_parameters.

    " Return the supported selection parameters here
    et_parameter_def = VALUE #(
      ( selname = 'S_ID'    kind = if_apj_dt_exec_object=>select_option datatype = 'C' length = 10 param_text = 'My ID'                                      changeable_ind = abap_true )
      ( selname = 'P_DESCR' kind = if_apj_dt_exec_object=>parameter     datatype = 'C' length = 80 param_text = 'My Description'   lowercase_ind = abap_true changeable_ind = abap_true )
      ( selname = 'P_COUNT' kind = if_apj_dt_exec_object=>parameter     datatype = 'I' length = 10 param_text = 'My Count'                                   changeable_ind = abap_true )
      ( selname = 'P_SIMUL' kind = if_apj_dt_exec_object=>parameter     datatype = 'C' length =  1 param_text = 'My Simulate Only' checkbox_ind = abap_true  changeable_ind = abap_true )
    ).

    " Return the default parameters values here
    et_parameter_val = VALUE #(
      ( selname = 'S_ID'    kind = if_apj_dt_exec_object=>select_option sign = 'I' option = 'EQ' low = '4711' )
      ( selname = 'P_DESCR' kind = if_apj_dt_exec_object=>parameter     sign = 'I' option = 'EQ' low = 'My Default Description' )
      ( selname = 'P_COUNT' kind = if_apj_dt_exec_object=>parameter     sign = 'I' option = 'EQ' low = '200' )
      ( selname = 'P_SIMUL' kind = if_apj_dt_exec_object=>parameter     sign = 'I' option = 'EQ' low = abap_true )
    ).

  ENDMETHOD.

  METHOD if_apj_rt_exec_object~execute.

    TYPES ty_id TYPE c LENGTH 10.

    DATA s_id    TYPE RANGE OF ty_id.
    DATA p_descr TYPE c LENGTH 80.
    DATA p_count TYPE i.
    DATA p_simul TYPE abap_boolean.

    DATA: jobname   type cl_apj_rt_api=>TY_JOBNAME.
    DATA: jobcount  type cl_apj_rt_api=>TY_JOBCOUNT.
    DATA: catalog   type cl_apj_rt_api=>TY_CATALOG_NAME.
    DATA: template  type cl_apj_rt_api=>TY_TEMPLATE_NAME.

    " Getting the actual parameter values
    LOOP AT it_parameters INTO DATA(ls_parameter).
      CASE ls_parameter-selname.
        WHEN 'S_ID'.
          APPEND VALUE #( sign   = ls_parameter-sign
                          option = ls_parameter-option
                          low    = ls_parameter-low
                          high   = ls_parameter-high ) TO s_id.
        WHEN 'P_DESCR'. p_descr = ls_parameter-low.
        WHEN 'P_COUNT'. p_count = ls_parameter-low.
        WHEN 'P_SIMUL'. p_simul = ls_parameter-low.
      ENDCASE.
    ENDLOOP.

    try.
* read own runtime info catalog
       cl_apj_rt_api=>GET_JOB_RUNTIME_INFO(
                        importing
                          ev_jobname        = jobname
                          ev_jobcount       = jobcount
                          ev_catalog_name   = catalog
                          ev_template_name  = template ).

       catch cx_apj_rt.

    endtry.


    " Implement the job execution

  ENDMETHOD.

ENDCLASS.

Related Information

Creating the Job Catalog Entry

Creating the Job Template

Setting up the Authorizations

Application Logs