简体   繁体   中英

BTP - GET_USER_ALIAS returns empty value

Hi I made my first Hello World in BTP and it didn't show my user alias...

Why?

ABAP 代码

CLASS zpo_hello_world DEFINITION
  PUBLIC
  FINAL
  CREATE PUBLIC.

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


CLASS zpo_hello_world IMPLEMENTATION.
  METHOD if_oo_adt_classrun~main.
  out->write( |Hello World ! ({ cl_abap_context_info=>get_user_alias( ) })| ).

  ENDMETHOD.

ENDCLASS.

Some of the methods in cl_abap_context_info can only be used in a cloud environment.

cl_abap_context_info=>
New Method Old Environemnt
ET_SYSTEM_DATE SYST-DATUM
GET_SYSTEM_TIME SYST-UZEIT
GET_USER_TECHNICAL_NAME SYST-UNAME
GET_USER_LANGUAGE_ABAP_FORMAT SYST-LANGU
GET_USER_LANGUAGE_ISO_FORMAT ISO format for language
GET_USER_TIME_ZONE SYST-TZONE
GET_USER_ALIAS Alias of user master data (Cloud)
GET_SYSTEM_URL URL of the system (Cloud)
GET_USER_FORMATTED_NAME BAPI_USER_GET_DETAIL
GET_USER_DESCRIPTION BAPI_USER_GET_DETAIL
GET_USER_BUSINESS_PARTNER_ID Business-Partner-ID of the user (Cloud)

(seehere )

Thus means if you run On-Premise those methods will not return any value as far as I know.

But I just saw that you are using the BTP abap cloud example. I've also tested it here it seems that there no alias is set for the users.

You can verify your user with the get_user_business_partner_id -method which is only valid in cloud.

  METHOD if_oo_adt_classrun~main.
    TRY.
        out->write( |Hello World { cl_abap_context_info=>get_user_business_partner_id( ) }| ).
      CATCH cx_abap_context_info_error.
    ENDTRY.
  ENDMETHOD.

I'm not sure weather you can set a user alias with transaction SU1 due there is no SAP Gui support I guess.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM