Technology Blog Posts by SAP
cancel
Showing results for 
Search instead for 
Did you mean: 
Eric_Li1
Advisor
Advisor
3,436

For further study and own fun.

1. ADT to create class with Implementing the business logic.

 

Sample Code

CLASS zcl_test_apj_exe 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_exe IMPLEMENTATION.
 --input parameters
  METHOD if_apj_dt_exec_object~get_parameters.

ENDMETHOD.

  METHOD if_apj_rt_exec_object~execute.

ENDMETHOD.

-- Getting the actual parameter values
-- Implement the job execution

ENDCLASS.
 CLASS zcl_apj_demo_class DEFINITION PUBLIC FINAL CREATE PUBLIC .

  PUBLIC SECTION.
    INTERFACES if_apj_rt_run.
    INTERFACES if_apj_dt_defaults.

    TYPES:
      BEGIN OF ty_name_range,
        sign   TYPE c LENGTH 1,
        option TYPE c LENGTH 2,
        low    TYPE c LENGTH 50,
        high   TYPE c LENGTH 50,
      END OF ty_name_range.
    TYPES: ty_name_ranges TYPE STANDARD TABLE OF ty_name_range WITH EMPTY KEY.

    "! <p class="shorttext synchronized" lang="en">Numbers available</p>
    DATA numbers_available TYPE abap_bool VALUE abap_true.
    "! <p class="shorttext synchronized" lang="en">Numbers</p>
    DATA numbers TYPE RANGE OF i.
    "! <p class="shorttext synchronized" lang="en">Names available</p>
    DATA names_available TYPE abap_bool VALUE abap_true.
    "! <p class="shorttext synchronized" lang="en">Names</p>
    DATA names TYPE ty_name_ranges.
    "! <p class="shorttext synchronized" lang="en">Some text</p>
    DATA text TYPE c LENGTH 255.
    "! <p class="shorttext synchronized" lang="en">Public attribute which is not used on the selection screen</p>
    DATA another_public_attribute TYPE c LENGTH 10.
ENDCLASS.

 

2. ADT to create job catalog entry as SAPJ/SE80 is no longer be used any more;

    Define header, section, group, parameters in ADT.

 

--Header Check class sample
CLASS zcl_test_apj_chk DEFINITION
  PUBLIC
  FINAL
  CREATE PUBLIC .

  PUBLIC SECTION.
    INTERFACES if_apj_jt_check_20.
ENDCLASS.


CLASS zcl_test_apj_chk IMPLEMENTATION.
METHOD if_apj_jt_check_20~check_and_adjust.
ENDMETHOD.
ENDCLASS.

 

More Methods:

more_methoids.png

 

--Define potential search help in parameters

@AccessControl.authorizationCheck: #NOT_REQUIRED

@ObjectModel.dataCategory: #VALUE_HELP

@EndUserText.label: 'Test Plant CDS view'

@Search.searchable: true

define view entity zcl_test_apj_table 
as select from zcl_apj_table {...}

 

3. ADT to create job template as SAPJ/SE80 is no longer be used any more;

 

Sample Code
--https://help.sap.com/docs/ABAP_PLATFORM_NEW/b5670aaaa2364a29935f40b16499972d/1f04ad22db0147b99ebc476708b749b6.html?version=202310.002

CLASS zcl_test_apj_simple_obj_gen DEFINITION
  PUBLIC
  FINAL
  CREATE PUBLIC .

  PUBLIC SECTION.
    INTERFACES if_oo_adt_classrun.
  PROTECTED SECTION.
  PRIVATE SECTION.
ENDCLASS.


CLASS zcl_test_apj_simple_obj_gen IMPLEMENTATION.

  METHOD if_oo_adt_classrun~main.

    CONSTANTS lc_catalog_name      TYPE cl_apj_dt_create_content=>ty_catalog_name  VALUE 'ZTEST_MY_SIMPLE_JOB'.
    CONSTANTS lc_catalog_text      TYPE cl_apj_dt_create_content=>ty_text          VALUE 'My first simple application job'.
    CONSTANTS lc_class_name        TYPE cl_apj_dt_create_content=>ty_class_name    VALUE 'ZCL_TEST_APJ_SIMPLE'.

    CONSTANTS lc_template_name     TYPE cl_apj_dt_create_content=>ty_template_name VALUE 'ZTEST_MY_SIMPLE_JOB_TEMPL'.
    CONSTANTS lc_template_text     TYPE cl_apj_dt_create_content=>ty_text          VALUE 'My first simple job template'.

    CONSTANTS lc_transport_request TYPE cl_apj_dt_create_content=>ty_transport_request VALUE 'Y11K900361'.
    CONSTANTS lc_package           TYPE cl_apj_dt_create_content=>ty_package           VALUE 'Z_D028092_APJ_MAIN'.

    DATA(lo_dt) = cl_apj_dt_create_content=>get_instance( ).

    " Create job catalog entry (corresponds to the former report incl. selection parameters)
    " Provided implementation class iv_class_name shall implement two interfaces:
    " - if_apj_dt_exec_object to provide the definition of all supported selection parameters of the job
    "   (corresponds to the former report selection parameters) and to provide the actual default values
    " - if_apj_rt_exec_object to implement the job execution
    TRY.
        lo_dt->create_job_cat_entry(
            iv_catalog_name       = lc_catalog_name
            iv_class_name         = lc_class_name
            iv_text               = lc_catalog_text
            iv_catalog_entry_type = cl_apj_dt_create_content=>class_based
            iv_transport_request  = lc_transport_request
            iv_package            = lc_package
        ).
        out->write( |Job catalog entry created successfully| ).

      CATCH cx_apj_dt_content INTO DATA(lx_apj_dt_content).
        out->write( |Creation of job catalog entry failed: { lx_apj_dt_content->get_text( ) }| ).
    ENDTRY.

    " Create job template (corresponds to the former system selection variant) which is mandatory
    " to select the job later on in the Fiori app to schedule the job
    DATA lt_parameters TYPE if_apj_dt_exec_object=>tt_templ_val.

    NEW zcl_test_apj_simple( )->if_apj_dt_exec_object~get_parameters(
      IMPORTING
        et_parameter_val = lt_parameters
    ).

    TRY.
        lo_dt->create_job_template_entry(
            iv_template_name     = lc_template_name
            iv_catalog_name      = lc_catalog_name
            iv_text              = lc_template_text
            it_parameters        = lt_parameters
            iv_transport_request = lc_transport_request
            iv_package           = lc_package
        ).
        out->write( |Job template created successfully| ).

      CATCH cx_apj_dt_content INTO lx_apj_dt_content.
        out->write( |Creation of job template failed: { lx_apj_dt_content->get_text( ) }| ).
        RETURN.
    ENDTRY.

  ENDMETHOD.

ENDCLASS.

 

4. Setup authorizations 

Find out how to set up the authorizations for the Application Jobs app.

The authorizations for application jobs are the same as for classic batch jobs if you use the default concept. For more information, see 101146 Information published on SAP site.

You can switch to the new authorization concept for application jobs by following the description in 3190922 Information published on SAP site.

5. Maintain application jobs via a released API

   You can use the CL_APJ_RT_API class to maintain application jobs. You can do the following and more:

  • schedule an application job

  • retrieve the status of an application job

  • cancel an application job

  • delete an application job

joboperation9.png

6. Maintain application job logs

 

Sample Code
CLASS zcl_test_write DEFINITION
  PUBLIC
  FINAL
  CREATE PUBLIC .

  PUBLIC SECTION.
    INTERFACES if_oo_adt_classrun.
  PROTECTED SECTION.
  PRIVATE SECTION.
ENDCLASS.


CLASS zcl_test_write IMPLEMENTATION.
  METHOD if_oo_adt_classrun~main.

    TRY.
        " Create a new Application Log
        DATA(l_log) = cl_bali_log=>create( ).

        " Add a header to the log
        l_log->set_header( header = cl_bali_header_setter=>create( object = 'ZOBJECT'
                                                                   subobject = 'ZSUBOBJECT'
                                                                   external_id = 'External ID' ) ).

        " Add a message as item to the log
        DATA(l_message) = cl_bali_message_setter=>create( severity = if_bali_constants=>c_severity_error
                                                          id = 'PO'
                                                          number = '000' ).
        l_log->add_item( item = l_message ).

        " Add a second message, this time from system fields SY-MSGID, ...
        MESSAGE ID 'ZTEST' TYPE 'S' NUMBER '058' INTO DATA(l_text).

        l_log->add_item( item = cl_bali_message_setter=>create_from_sy( ) ).

        " Add a free text to the log

        DATA(l_free_text) = cl_bali_free_text_setter=>create( severity = if_bali_constants=>c_severity_error
                                                              text = 'Some Error Text' ).

        l_log->add_item( item = l_free_text ).

        " Add an exception to the log
        DATA: i TYPE i.
        TRY.
            i = 1 / 0.
          CATCH cx_sy_zerodivide INTO DATA(l_ref).
        ENDTRY.

        DATA(l_exception) = cl_bali_exception_setter=>create( severity = if_bali_constants=>c_severity_error
                                                              exception = l_ref ).
        l_log->add_item( item = l_exception ).

        " Save the log into the database
        cl_bali_log_db=>get_instance( )->save_log( log = l_log ).

      CATCH cx_bali_runtime INTO DATA(l_runtime_exception).
        out->write( l_runtime_exception->get_text(  ) ).
    ENDTRY.

  ENDMETHOD.
ENDCLASS.

 

7. Notification and exceptions

 

CLASS zcl_ntf DEFINITION PUBLIC FINAL CREATE PUBLIC.
  PUBLIC SECTION.
    INTERFACES IF_APJ_RT_JOB_NOTIF_EXIT.
ENDCLASS.


CLASS zcl_ntf IMPLEMENTATION.
  METHOD if_apj_rt_job_notif_exit~notify_jt_start.
  ENDMETHOD.


  METHOD if_apj_rt_job_notif_exit~notify_jt_end.
  ENDMETHOD.
ENDCLASS.

 

8. Define your own APP with report, setup sematic objects, mapping target etc.

 

Some others interesting ones:

What is the scope of the Application Job App F1240?
In Detail it was asked: Is it meant to show all the jobs which could be seen in SM37 or is there a limitation to the jobs which it can see?

Yes there is a limitation. As the name indicates the Fiori App F1240 will only display jobs of the type "Application Job" it will not display any other type of jobs. Therefore NO - F1240 will not show the same information like SM37. One major aspect for this is that F1240 will only depict the application jobs that are allowed to be seen by cloud customers and partners and will hide all SAP proprietary jobs which must not be exposed to cloud customers. SM37 by its architecture and nature can NOT differentiate such jobs and therefore will always show every job - event those that are SAP confidential and proprietary. Therefore this view will not be exposed in any cloud environment.

After adding Application "(F1204) Application Jobs" to a custom business role I cannot schedule my Application Job. Is this an error?
NO, most likely this behaviour is the correct and the expected one. F1240 is by default a READ-ONLY application that will only display all jobs of type "Application Job" scheduled in the current client by ALL users. By architecture the application does not deliver any S_START authorizations and therefore by default the scheduling of any application job is not possible. The application does offer a restriction type via which the customer administrator can maintain enhanced authorizations which allow the abortion of any application job of any user in the system. Example: maintaining restrictions with an asterisk "*" the Business User that will receive this particular customer Business Role will be allowed to abort every application job of ever business user in the system.

If you wonder, why in your particular system you just access for your testing/development this same application is assigned to a Business User - but this user is able to also create and schedule new application jobs, than the reasoning is in all likelihood the following:

if to a Business Role arbitrary other Business Catalogs / App Authorizations Variants are assigned the authorizations of these artefacts are also merged into the role
even though F1240 does not provide any S_START authorization → any other application F???? can contain S_START authorization
the user is able to schedule the jobs, because he received valid S_START authorizations via any arbitrary F????
I am working in a cloud environment (e.g. S/4 HANA Public Cloud, IBP, Steampunk...) and when I open SM37 I can see more jobs compared to application F1240. Is this an error?
NO. In cloud environments the access for customers and partners to particular content in transaction SM37 is prohibited and must not be shared with customer and partner users. SM37 is capable to display classic background jobs ([BC-SRV-BTC] SM36/ JOB_OPEN JOB_CLOSE interfaces ...), Technical Jobs ([BC-SRV-BTC-JR] SJOBREPO - strictly prohibited for external exposure, SAP proprietary jobs) and Application Jobs ([BC-SRV-APS-APJ] Reuse-UIs; F1240; external communication scenarios ...). These are three diverse frameworks with divers user groups and diverse use cases demanding diverse feature sets (even when they share some technological assets and the same DB persistence). Therefore the access to SM37 is solely granted to SAP employees and solely via SAP Support scenarios as classic SAP GUI transaction access.

I have scheduled a job via the interfaces JOB_OPEN / JOB_CLOSE and alike, but they do not show up in Fiori Application F1240 - Application Jobs. Is this an error?
NO. You have used the interfaces to schedule classic background jobs and not an application job. Classic Jobs are to be monitored in the transaction SM37. F1240 does only show Application Jobs and not classic background jobs.

Can I use any existing API which works on Background Jobs also with Application Jobs? - Example: BP_JOB_COPY / BP_JOB_CREATE / BP_JOB_MODIFY
It is not allowed to use any API that was designed for classic background processing (SM36/SM37) for application jobs (nor technical jobs). Application Jobs and Technical Jobs are designed as superior layer above the classic background processing and therefore are only allowed to be accessed via dedicated released APIs that take the new and independent framework specifics into account. Using other APIs can lead to error situations which are not covered by our support and development teams and can only be solved by removing such erroneous calls.

And funny questions:

How to delete application jobs in transaction SM37?
Check SAP Note: 3002849.
To enable this, the setting to delete Application Jobs must be activated in the system by using the report BTC_OPTIONS_SET, Option: Delete Application Jobs from SM37.Note: In SM37 application jobs appear under their technical job names. You can retrieve the technical name of an application job from the Job Scheduling Fiori App by adding the column 'Job ID' to the job overview.

Eric_Li_2-1735213546696.png

Eric_Li_3-1735213586139.png

 

 

 

Useful SAP Notes and links:

SAP Note 2829891 - Application Jobs in On Premise systems;

SAP Note 3373331 - Application Jobs in OnPremise - FAQ;

SAP Note 3441346 - Enable 'Maintain Job Users' app for OnPremise

SAP Note 3438433 - Show technical users in the 'Maintain Job Users' app

SAP Note 3002849 - Application jobs cannot be deleted in SM37

SAP Note 2832889 - Application jobs must not be changed in SM36 or SM37 Message no. BT895

Creating a Job Catalog Entry and a Job Template in ADT

Working with Application Job Catalog Entries | SAP Help Portal

ABAP Cloud Application Jobs: Overcoming Key Challe... - SAP Community

Classes and Interfaces of the Application Log API | SAP Help Portal

 

 

 

 

 

1 Comment