Checking landscape information in SAP CRM PPF action conditions using BADI CONTAINER_PPF

In SAP Solution Manager Change Request Management we want to work with different status flows dependent on the landscape (in one process type). Therefore we need to use landscape information in Action schedule (and start) conditions.

With BADI implementation ZLIAC_SYSTROLE_EXIST (BADI Definition CONTAINER_PPF) we have the possibility to check the use of specific system roles. To do this, we simply have to define a condition parameter “ZLIAC_SYSTEM_ROLE_EXISTS_<SYSTEM_ROLE>“. Please have a look at transaction MAINT_ROLES for valid system roles.

In our first use case, we want do differentiate between 3-trier and 5-trier landscapes. To do that, we check for existence of system role “3”. This role will only be used in 5-trier landscapes like “D -> T -> 2 -> 3 -> P”. In 3-trier landscapes like “D -> T -> P”, this role will never be used.


*"----------------------------------------------------------------------
*"Methoden Signatur:
*"  Importing
*"    FLT_VAL TYPE OJ_NAME
*"  Changing
*"    CI_CONTAINER TYPE REF IF_SWJ_PPF_CONTAINER
*"    CI_PARAMETER TYPE REF IF_SWJ_PPF_CONTAINER
*"----------------------------------------------------------------------
method IF_EX_CONTAINER_PPF~MODIFY_CONTAINER.

  TYPE-POOLS: socmt.

  data:
    lv_result          type abap_bool,
    lt_parameter       TYPE SWCONTTAB,
    lv_system_role     type /TMWFLOW/PROJECT_SYSTEM_S-SYSTEM_ROLE,
    ls_object          TYPE sibflporb,
    lv_guid            TYPE crmt_object_guid,
    lv_doc_flow_id     TYPE crmt_doc_flow_id_wrk,
    lv_tasklist        TYPE /tmwflow/tasklist,
    lt_system          TYPE TABLE OF /tmwflow/project_system_s,
    lt_transport       TYPE SOCMT_TRORDHC_TYPE.

  field-symbols:
    <fs_parameter> like line of lt_parameter,
    <fs_transport> like line of lt_transport.

*-------------------------------------------------------------------------

*check if classes are bound
  CHECK: ci_container IS BOUND,
         ci_parameter IS BOUND.

*get all parameters
  CALL METHOD ci_parameter->get_values
    RECEIVING
      values = lt_parameter.

*process every matching parameter "ZLIAC_SYSTEM_ROLE_EXISTS_<SYSTEM_ROLE>". Please have a look at transaction MAINT_ROLES for valid system roles.
  loop at lt_parameter[] assigning <fs_parameter> where element(25) = 'ZLIAC_SYSTEM_ROLE_EXISTS_'.

*Crear result because this is a new run.
    clear lv_result.

*This is the first run. Therefore we have to get some information once.
    if lv_system_role is initial.

*Get Change Document
      CALL METHOD ci_container->get_value
        EXPORTING
          element_name = 'BUSINESSOBJECT'
        IMPORTING
          data         = ls_object.

* Extract GUID
      lv_guid = ls_object-instid.

*Exit if it is no valid context.
      if lv_guid is initial.
        return.
      endif.

*Get assigned tasklist
      CALL METHOD cl_hf_helper=>get_bo_tasklist_of_chng_doc
        EXPORTING
          im_change_document_id = lv_guid
        RECEIVING
          return                = lv_doc_flow_id.

      lv_tasklist = lv_doc_flow_id.

*Exit if it is no valid context.
      if lv_tasklist is initial.
        return.
      endif.

*get systems from tasklist
*If we need more information, we have to use /TMWFLOW/PROJECT_GET or /TMWFLOW/PROJECT_READ to get project id and /TMWFLOW/TRANSPORT_TRACK_GET to get extended system information.
      CALL FUNCTION '/TMWFLOW/TASKLIST_SYSTEMS_GET'
        EXPORTING
          id_tasklist       = lv_tasklist
          id_current_track  = 'X'
        TABLES
          et_project_system = lt_system[]
        EXCEPTIONS
          project_not_found = 1
          OTHERS            = 2.

*Exit if it is no valid context.
      if sy-subrc <> 0.
        return.
      endif.

*get transport requests of change document
      CALL METHOD /tmwflow/cl_transport=>get_chng_doc_transp_req
        EXPORTING
          iv_header_guid = lv_guid
        IMPORTING
          et_transp_req  = lt_transport[].

*We are only interested in transport tracks.
*It is OK if we have no transports yet.
      SORT lt_transport[] by transport_track.
      DELETE ADJACENT DUPLICATES FROM lt_transport[] COMPARING transport_track.

    endif.

*Extract system role to be checked now.
    lv_system_role = <fs_parameter>-element+25(1).

*Check every used transport track.
    LOOP AT lt_transport[] assigning <fs_transport>.

*Is system role used?
      READ TABLE lt_system[]
           WITH KEY transport_track = <fs_transport>-transport_track
                    system_role     = lv_system_role
           TRANSPORTING NO FIELDS.

      check sy-subrc = 0.

*Yes system role is in use!!!
      lv_result = abap_true.
      exit.

    ENDLOOP.

*if there are no transport requests, check all project tracks.
    IF sy-subrc NE 0.

      do 1 times.

*Is system role used?
        READ TABLE lt_system[]
             WITH KEY "transport_track = <fs_transport>-transport_track
                      system_role     = lv_system_role
             TRANSPORTING NO FIELDS.

        check sy-subrc = 0.

*Yes system role could be used!!!
        lv_result = abap_true.
        exit.

      enddo.

    endif.

*set output parameter
    CALL METHOD ci_parameter->set_value
      EXPORTING
        element_name = <fs_parameter>-element
        data         = lv_result.
*            RECEIVING
*              retcode      = lv_subrc.

  endloop.

endmethod.