获取当前访问域名

wdr_task=>request->get_header_field(  name = '~server_name'  )

获取当前数据的FPM页面URL

  METHOD get_url.
    DATA:
      lo_fpm            TYPE REF TO if_fpm,
      lo_parameter      TYPE REF TO if_fpm_parameter,
      lt_keys           TYPE STANDARD TABLE OF string WITH DEFAULT KEY,
      ls_host           TYPE icfvirhost,
      lv_url            TYPE string,
      lv_value          TYPE string,
      lv_parameter      TYPE string,
      lv_http           TYPE string,
      ls_runtime_info   TYPE fpm_s_runtime_info,
      lt_servlist       TYPE STANDARD TABLE OF icm_sinfo,
      ls_service        TYPE icfservice,
      lv_protocol       TYPE icmproto,
      lv_sel_hostname   TYPE icfname,
      lv_flag           TYPE boole_d,
      lv_sel_hostnumber TYPE icfhostnum.

    DATA: lv_cccategory TYPE cccategory.
    CONSTANTS: lc_prod  TYPE cccategory VALUE 'P'.


    lo_fpm = cl_fpm=>get_instance( ).
    ls_runtime_info = lo_fpm->get_runtime_info( ).
    lo_parameter = lo_fpm->mo_app_parameter.
    lt_keys = lo_parameter->get_keys( ).
    lv_parameter = 'SKIP_INITIAL_SCREEN=X&FPM_EDIT_MODE=R'.
    lv_flag = abap_false.
    LOOP AT lt_keys INTO DATA(lv_key).
      CHECK lv_key = 'KEY' OR lv_key = 'SAP-WD-CONFIGID' OR lv_key = 'PRJPH' .
      IF lv_key = 'KEY'.
        lv_flag = abap_true.
      ENDIF.
      CLEAR lv_value.
      lo_parameter->get_value( EXPORTING iv_key = lv_key IMPORTING ev_value = lv_value ).
      REPLACE ALL OCCURRENCES OF `/` IN lv_value WITH '%2f'
        IGNORING CASE .
      CONCATENATE lv_key lv_value INTO lv_value SEPARATED BY '='.

      CONCATENATE lv_parameter lv_value INTO lv_parameter SEPARATED BY '&'.

    ENDLOOP.
    IF lv_flag = abap_false.
      lv_parameter = |{ lv_parameter }&KEY={ iv_key }|.
    ENDIF.
    IF ls_runtime_info-application+0(5) = '/RER/'.
      SHIFT ls_runtime_info-application BY 5 PLACES.
    ENDIF.
    SELECT SINGLE * FROM icfservice INTO ls_service WHERE ( icf_name = ls_runtime_info-application
                                                         OR icfaltnme = ls_runtime_info-application ).

    CALL FUNCTION 'ICM_GET_INFO'
      TABLES
        servlist           = lt_servlist
      EXCEPTIONS
        icm_error          = 1
        icm_timeout        = 2
        icm_not_authorized = 3
        OTHERS             = 4.
    IF sy-subrc <> 0.
* Implement suitable error handling here
    ENDIF.

    CALL FUNCTION 'HTTP_GET_HOST'
      EXPORTING
        nodguid       = ls_service-icfnodguid
      IMPORTING
        hostname      = lv_sel_hostname
        hostnumber    = lv_sel_hostnumber
      EXCEPTIONS
        no_valid_guid = 1
        no_valid_host = 2
        OTHERS        = 3.
    IF sy-subrc <> 0.
* Implement suitable error handling here
    ENDIF.

    SELECT SINGLE * FROM icfvirhost INTO ls_host WHERE icf_name = lv_sel_hostname
            AND hostnumber = lv_sel_hostnumber.
    CASE ls_host-protocol.
      WHEN 'HTTP'.
        lv_protocol = 1.
      WHEN 'HTTPS'.
        lv_protocol = 2.
      WHEN OTHERS.
        lv_protocol = 1.
    ENDCASE.

    CALL FUNCTION 'TR_SYS_PARAMS'
      IMPORTING
        system_client_role = lv_cccategory
      EXCEPTIONS
        OTHERS             = 1.

    IF lv_cccategory <> lc_prod.
      lv_protocol = 2.
    ENDIF.

    READ TABLE lt_servlist INTO DATA(ls_servlist) WITH KEY protocol = lv_protocol.
    CONCATENATE ls_servlist-hostname ls_servlist-service INTO lv_http SEPARATED BY ':'.

    IF ls_service-icfaltnme IS NOT INITIAL.
      lv_value = ls_service-icfaltnme.
    ELSE.
      lv_value = ls_service-orig_name.
    ENDIF.
    WHILE ls_service-icfparguid <> ls_host-icfparguid.

      SELECT SINGLE * FROM icfservice INTO ls_service WHERE icfnodguid = ls_service-icfparguid.
      IF sy-subrc <> 0.
        EXIT.
      ELSE.
        CONCATENATE ls_service-orig_name lv_value INTO lv_value SEPARATED BY '/'.
      ENDIF.
    ENDWHILE.
    "CONCATENATE lv_http lv_value INTO lv_url SEPARATED BY '/'.
    CHECK ls_host-icf_name IS NOT INITIAL.

    REPLACE ALL OCCURRENCES OF ls_host-icf_name IN lv_value WITH lv_http
        IGNORING CASE .
    CONCATENATE lv_value lv_parameter INTO lv_url SEPARATED BY '?'.
*    IF sy-uname = 'SAP_TANXH'.
*      IF ls_host-protocol IS NOT INITIAL.
*        lv_url = |{ ls_host-protocol }://{ lv_url }|.
*      ENDIF.
*    ENDIF.
    rv_url = lv_url.
  ENDMETHOD.