Quantcast
Channel: SCN : All Content - ABAP Development
Viewing all articles
Browse latest Browse all 8332

ZUJE_MASS_USER_MGMT

$
0
0

*&---------------------------------------------------------------------*

*& Report  ZUJE_MASS_USER_MGMT

*&

*& Version: 10.0 SP3 and higher

*&

*&---------------------------------------------------------------------*

*& Created By: Rich Heilman  SAP Labs, LLC

*& Created On: 10/11/2011

*&---------------------------------------------------------------------*

REPORT  zuje_mass_user_mgmt.



TYPE-POOLS: abap, vrm.



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

*       CLASS lcl_application DEFINITION

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

CLASS lcl_application DEFINITION FINAL.



  PUBLIC SECTION.



    CONSTANTS: lc_comma TYPE char01 VALUE ',',

               lc_pipe TYPE char01 VALUE '|',

               lc_tab TYPE char10 VALUE 'TAB'.



    TYPES: BEGIN OF t_appldim,

            appl_id TYPE uj_appl_id,

            dimension TYPE uj_dim_name,

          END OF t_appldim.



    TYPES: BEGIN OF t_appldimmembers,

            appl_id TYPE uj_appl_id,

            dimension TYPE uj_dim_name,

            member TYPE uj_dim_member,

          END OF t_appldimmembers.



    CLASS-METHODS: file_f4 RETURNING value(r_file) TYPE string,

                   directory_f4 RETURNING value(r_path) TYPE string,

                   get_initial_directory RETURNING value(r_path) TYPE string,

                   set_delimiter_listbox,

                   set_delimiter,

                   export_users_to_file,

                   import_users_from_file,

                   export_teams_to_file,

                   import_teams_from_file,

                   export_team_assign_to_file,

                   import_team_assign_from_file,

                   export_task_profiles_to_file,

                   import_task_profiles_from_file,

                   export_data_profiles_to_file,

                   import_data_profiles_from_file,

                   export_tap_assign_to_file,

                   import_tap_assign_from_file,

                   export_dap_assign_to_file,

                   import_dap_assign_from_file,

                   get_bpc_component_version,

                   check_bpc_component_is_valid RETURNING value(r_valid) TYPE abap_bool,

                   get_environment_data IMPORTING i_environment_id TYPE uj_appset_id

                                        EXCEPTIONS environment_not_found

                                                   uj_exception_error.



  PRIVATE SECTION.



    CLASS-DATA: lv_environment_id TYPE uja_s_appset_info-appset_id.

    CLASS-DATA: lv_delimiter TYPE string.

    CLASS-DATA: lv_release TYPE saprelease.

    CLASS-DATA: lv_splevel TYPE sappatchlv.

    CLASS-DATA: ls_environment_info TYPE uja_s_appset_info.



    CLASS-DATA: lt_appl_info TYPE uja_t_appl_info.

    CLASS-DATA: lt_appl_dim TYPE TABLE OF t_appldim.

    CLASS-DATA: lt_members TYPE TABLE OF t_appldimmembers.

    CLASS-DATA: lt_teams_list TYPE uje_t_teamdetail.

    CLASS-DATA: lt_users_list TYPE uje_t_user.

    CLASS-DATA: lt_user_detail TYPE uje_t_userinfo_detail.

    CLASS-DATA: lt_task_profiles TYPE uje_t_task_prof_detail.

    CLASS-DATA: lt_data_access_profiles TYPE uje_t_mbr_prof_app.

    CLASS-DATA: lt_systasks TYPE uje_t_role_tskasg.



    CLASS-DATA: lo_uje_exception TYPE REF TO cx_uje_exception.

    CLASS-DATA: lo_context TYPE REF TO if_uj_context.

    CLASS-DATA: lt_alv_messages TYPE uj0_t_message.



    CLASS-METHODS: set_global_context,

                   render_alv,

                   add_exception_to_message_table

                           IMPORTING io_exception TYPE REF TO cx_uj_static_check,

                   add_message_to_message_table

                           IMPORTING i_msgid TYPE symsgid

                                     i_msgty TYPE symsgty

                                     i_msgno TYPE symsgno

                                     i_message TYPE bapi_msg,

                   upload IMPORTING i_filepath TYPE any

                          RETURNING value(rt_strtab) TYPE stringtab,

                   download IMPORTING i_filepath TYPE any

                                     it_datatab TYPE STANDARD TABLE,

                   user_is_valid IMPORTING i_user_id TYPE any

                                 RETURNING value(r_boolean) TYPE abap_bool,

                   team_is_valid IMPORTING i_team_id TYPE any

                                 RETURNING value(r_boolean) TYPE abap_bool,

                   tprofile_is_valid IMPORTING i_profile_id TYPE any

                                     RETURNING value(r_boolean) TYPE abap_bool,

                   dprofile_is_valid IMPORTING i_profile_id TYPE any

                                     RETURNING value(r_boolean) TYPE abap_bool,

                   task_is_valid IMPORTING i_task_id TYPE any

                                 RETURNING value(r_boolean) TYPE abap_bool,

                   nw_user_exists IMPORTING i_user_id TYPE any

                                  RETURNING value(r_boolean) TYPE abap_bool.



ENDCLASS.                    "lcl_application DEFINITION



SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.

PARAMETERS: p_export RADIOBUTTON GROUP grp1 DEFAULT 'X' USER-COMMAND chk.

PARAMETERS: p_import RADIOBUTTON GROUP grp1.

SELECTION-SCREEN END OF BLOCK b1.

SELECTION-SCREEN BEGIN OF BLOCK b2 WITH FRAME TITLE text-002.

PARAMETERS: p_env  TYPE uja_appset_info-appset_id.

PARAMETERS: p_file TYPE string LOWER CASE.

PARAMETERS: p_delmt TYPE char10 AS LISTBOX VISIBLE LENGTH 20

                       DEFAULT lcl_application=>lc_comma"delimiter

SELECTION-SCREEN END OF BLOCK b2.

SELECTION-SCREEN BEGIN OF BLOCK b3 WITH FRAME TITLE text-003.

PARAMETERS: p_eusers RADIOBUTTON GROUP grp2 MODIF ID exp.

PARAMETERS: p_eteams RADIOBUTTON GROUP grp2 MODIF ID exp.

PARAMETERS: p_eteama RADIOBUTTON GROUP grp2 MODIF ID exp.

PARAMETERS: p_etprof RADIOBUTTON GROUP grp2 MODIF ID exp.

PARAMETERS: p_edprof RADIOBUTTON GROUP grp2 MODIF ID exp.

PARAMETERS: p_etprfa RADIOBUTTON GROUP grp2 MODIF ID exp.

PARAMETERS: p_edprfa RADIOBUTTON GROUP grp2 MODIF ID exp.

SELECTION-SCREEN END OF BLOCK b3.

SELECTION-SCREEN BEGIN OF BLOCK b4 WITH FRAME TITLE text-004.

PARAMETERS: p_iusers RADIOBUTTON GROUP grp3 MODIF ID imp.

PARAMETERS: p_iteams RADIOBUTTON GROUP grp3 MODIF ID imp.

PARAMETERS: p_iteama RADIOBUTTON GROUP grp3 MODIF ID imp.

PARAMETERS: p_itprof RADIOBUTTON GROUP grp3 MODIF ID imp.

PARAMETERS: p_idprof RADIOBUTTON GROUP grp3 MODIF ID imp.

PARAMETERS: p_itprfa RADIOBUTTON GROUP grp3 MODIF ID imp.

PARAMETERS: p_idprfa RADIOBUTTON GROUP grp3 MODIF ID imp.

SELECTION-SCREEN END OF BLOCK b4.



INITIALIZATION.



  p_file = lcl_application=>get_initial_directory( ).

  lcl_application=>set_delimiter_listbox( ).

  lcl_application=>get_bpc_component_version( ).



  IF lcl_application=>check_bpc_component_is_valid( ) = abap_false.

    MESSAGE i001(00) WITH 'BPC Component version must be 800'.

  ENDIF.



AT SELECTION-SCREEN OUTPUT.



  LOOP AT SCREEN.

    IF p_export = abap_true AND screen-group1 = 'IMP'.

      screen-active = '0'.

    ENDIF.

    IF p_import = abap_true AND screen-group1 = 'EXP'.

      screen-active = '0'.

    ENDIF.

    MODIFY SCREEN.

  ENDLOOP.



AT SELECTION-SCREEN.

  CASE abap_true.

    WHEN p_export.

      CLEAR: p_iusers, p_iteams, p_iteama, p_itprof,

             p_idprof, p_itprfa, p_idprfa.

    WHEN p_import.

      CLEAR: p_eusers, p_eteams, p_eteama, p_etprof,

             p_edprof, p_etprfa, p_edprfa.

  ENDCASE.



  IF sy-ucomm <> 'CHK'.

    IF lcl_application=>check_bpc_component_is_valid( ) = abap_false.

      MESSAGE e001(00) WITH 'BPC Component version must be 800'.

    ENDIF.

    IF p_env IS INITIAL.

      MESSAGE e001(00) WITH 'Please enter an Environment Id'.

    ENDIF.

    IF p_file IS INITIAL.

      MESSAGE e001(00) WITH 'Please enter a valid directory or file'.

    ENDIF.

    IF p_delmt IS INITIAL.

      MESSAGE e001(00) WITH 'Please specify a delimiter'.

    ENDIF.

  ENDIF.



AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.



  CASE abap_true.

    WHEN p_exportp_file = lcl_application=>directory_f4( ).

    WHEN p_importp_file = lcl_application=>file_f4( ).

  ENDCASE.



START-OF-SELECTION.



  lcl_application=>set_delimiter( ).



  lcl_application=>get_environment_data(

              EXPORTING  i_environment_id p_env

              EXCEPTIONS environment_not_found  = 1 ).

  IF sy-subrc <> 0.

    RETURN.

  ENDIF.



  CASE abap_true.

    WHEN p_euserslcl_application=>export_users_to_file( ).

    WHEN p_iuserslcl_application=>import_users_from_file( ).

    WHEN p_eteamslcl_application=>export_teams_to_file( ).

    WHEN p_iteamslcl_application=>import_teams_from_file( ).

    WHEN p_eteamalcl_application=>export_team_assign_to_file( ).

    WHEN p_iteamalcl_application=>import_team_assign_from_file( ).

    WHEN p_etproflcl_application=>export_task_profiles_to_file( ).

    WHEN p_itproflcl_application=>import_task_profiles_from_file( ).

    WHEN p_edproflcl_application=>export_data_profiles_to_file( ).

    WHEN p_idproflcl_application=>import_data_profiles_from_file( ).

    WHEN p_etprfalcl_application=>export_tap_assign_to_file( ).

    WHEN p_itprfalcl_application=>import_tap_assign_from_file( ).

    WHEN p_edprfalcl_application=>export_dap_assign_to_file( ).

    WHEN p_idprfalcl_application=>import_dap_assign_from_file( ).

  ENDCASE.



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

*       CLASS lcl_application IMPLEMENTATION

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

CLASS lcl_application IMPLEMENTATION.



  METHOD file_f4.



    DATA: lt_file_table TYPE filetable.

    DATA: ls_file_table LIKE LINE OF lt_file_table.



    DATA: lv_rc TYPE sy-subrc.



    cl_gui_frontend_services=>file_open_dialog(

      CHANGING

        file_table = lt_file_table

        rc         = lv_rc ).

    CLEAR ls_file_table .

    READ TABLE lt_file_table INTO ls_file_table INDEX 1.

    IF sy-subrc  = 0.

      r_file = ls_file_table-filename.

    ENDIF.



  ENDMETHOD.                                                "file_f4



  METHOD directory_f4.



    cl_gui_frontend_services=>directory_browse(

        CHANGING

          selected_folder      = r_path

        EXCEPTIONS

          OTHERS               = 4 ).



  ENDMETHOD.                    "directory_f4



  METHOD upload.



    cl_gui_frontend_services=>gui_upload(

          EXPORTING

            filename = i_filepath

          CHANGING

            data_tab = rt_strtab

          EXCEPTIONS

            OTHERS   = 19 ).

    IF sy-subrc <> 0.

      MESSAGE i001(00) WITH 'File not found, check file path and name'.

    ENDIF.



    DELETE rt_strtab WHERE table_line IS INITIAL.



  ENDMETHOD.                    "upload



  METHOD download.



    DATA: lt_datatab TYPE stringtab.

    DATA: ls_datatab LIKE LINE OF lt_datatab.



    FIELD-SYMBOLS: <ls_data> TYPE any.

    FIELD-SYMBOLS: <lv_field> TYPE any.



* Convert table to delimited string table

    LOOP AT it_datatab ASSIGNING <ls_data>.

      CLEAR ls_datatab.

      DO.

        ASSIGN COMPONENT sy-index

                         OF STRUCTURE <ls_data> TO <lv_field>.

        IF sy-subrc <> 0.

          EXIT.

        ENDIF.

        IF ls_datatab IS INITIAL.

          ls_datatab = <lv_field>.

        ELSE.

          CONCATENATE ls_datatab <lv_field>

                          INTO ls_datatab SEPARATED BY lcl_application=>lv_delimiter.

        ENDIF.

      ENDDO.

      APPEND ls_datatab TO lt_datatab.

    ENDLOOP.



    cl_gui_frontend_services=>gui_download(

       EXPORTING

         filename = i_filepath

       CHANGING

         data_tab = lt_datatab

       EXCEPTIONS

         OTHERS   = 24 ).

    IF sy-subrc <> 0.

      MESSAGE i001(00)

          WITH 'File not downloaded, check file path and name'.

    ENDIF.



  ENDMETHOD.                    "download



  METHOD get_initial_directory.



    cl_gui_frontend_services=>get_desktop_directory(

      CHANGING

        desktop_directory    = r_path ).

    cl_gui_cfw=>flush( ).



    CONCATENATE r_path '\*.csv' INTO r_path.



  ENDMETHOD.                    "get_initial_directory



  METHOD export_users_to_file.



    TYPES: BEGIN OF t_output,

            user_id TYPE uje_user-user_id,

           END OF t_output.



    DATA: ls_users TYPE uje_s_userinfo.



    DATA: lt_output TYPE TABLE OF t_output.

    DATA: ls_output LIKE LINE OF lt_output.



    REFRESH lt_output.

    LOOP AT lcl_application=>lt_users_list INTO ls_users.

      ls_output-user_id = ls_users-user_id.

      APPEND ls_output TO lt_output.

    ENDLOOP.



* Download table

    lcl_application=>download(

                    EXPORTING i_filepath = p_file

                              it_datatab = lt_output ).



  ENDMETHOD.                    "export_users_to_file



  METHOD import_users_from_file.



    DATA: lv_user_id TYPE uj_user_id.

    DATA: lv_message TYPE uj0_s_message-message.



    DATA: lt_users TYPE uje_t_user_id.

    DATA: ls_users LIKE LINE OF lt_users.



    DATA: lt_strtab TYPE stringtab.

    DATA: ls_strtab LIKE LINE OF lt_strtab.



    lt_strtab = lcl_application=>upload( p_file ).



    LOOP AT lt_strtab INTO ls_strtab.



      lv_user_id = ls_strtab"should only be the user id



      IF lcl_application=>nw_user_exists( lv_user_id ) = abap_false.

        CONCATENATE 'User ID' lv_user_id

                    'does not exist as a NetWeaver user in SU01'

                            INTO lv_message SEPARATED BY space.

        add_message_to_message_table( i_msgid = `00` i_msgty = `E` i_msgno = `001`

                                      i_message = lv_message ).

        CONTINUE"Skip, do not process

      ENDIF.



* Check if user already exists, if so, issue warning and continue.

      IF lcl_application=>user_is_valid( lv_user_id ) = abap_true.

        CONCATENATE 'User ID' lv_user_id

                    'has already been added to environment' lv_environment_id

                            INTO lv_message SEPARATED BY space.

        add_message_to_message_table( i_msgid = `00` i_msgty = `W` i_msgno = `001`

                                      i_message = lv_message ).

        CONTINUE"Skip, do not process

      ENDIF.



      TRY.

          CLEAR ls_users. REFRESH lt_users.

          ls_users = lv_user_id.

          APPEND ls_users TO lt_users.



          cl_uje_user=>add_users(

                        EXPORTING i_appset_id = lcl_application=>lv_environment_id

                                  it_users = lt_users ).

          CONCATENATE 'User ID' lv_user_id

                      'has been added successfully'

                              INTO lv_message SEPARATED BY space.

          add_message_to_message_table( i_msgid = `00` i_msgty = `S` i_msgno = `001`

                                        i_message = lv_message ).



        CATCH cx_uje_exception INTO lo_uje_exception.

          add_exception_to_message_table( lo_uje_exception ).

          CONCATENATE 'User ID'  lv_user_id

                      'not added due to error'

                               INTO lv_message SEPARATED BY space.

          add_message_to_message_table( i_msgid = `00` i_msgty = `E` i_msgno = `001`

                                        i_message = lv_message ).

      ENDTRY.



    ENDLOOP.



    lcl_application=>render_alv( ).



  ENDMETHOD.                    "create_users_from_file



  METHOD export_teams_to_file.



    TYPES: BEGIN OF t_output,

            team_id TYPE uje_s_team-team_id,

            description TYPE uje_s_team-description,

           END OF t_output.

    DATA: ls_teams TYPE uje_s_teamdetail.



    DATA: lt_output TYPE TABLE OF t_output.

    DATA: ls_output LIKE LINE OF lt_output.



    REFRESH lt_output.

    LOOP AT lcl_application=>lt_teams_list INTO ls_teams.

      MOVE-CORRESPONDING ls_teams TO ls_output.

      APPEND ls_output TO lt_output.

    ENDLOOP.



* Download table

    lcl_application=>download( EXPORTING i_filepath = p_file

                                         it_datatab = lt_output ).



  ENDMETHOD.                    "export_teams_to_file



  METHOD import_teams_from_file.



    DATA: lv_message TYPE uj0_s_message-message.



    DATA: lt_team TYPE uje_t_team.

    DATA: ls_team TYPE uje_s_team.



    DATA: lt_strtab TYPE stringtab.

    DATA: ls_strtab LIKE LINE OF lt_strtab.



    lt_strtab = lcl_application=>upload( p_file ).



    LOOP AT lt_strtab INTO ls_strtab.



      CLEAR ls_team. REFRESH lt_team.

      SPLIT ls_strtab AT lcl_application=>lv_delimiter INTO ls_team-team_id

                                  ls_team-description.

      APPEND ls_team TO lt_team.



      TRY.

* Check if team is already a valid team, if so, update.

          IF lcl_application=>team_is_valid( ls_team-team_id ) = abap_false.

            cl_uje_team=>create_teams(

             EXPORTING i_appset_id = lcl_application=>lv_environment_id

                       it_teams = lt_team ).

          ELSE.

            cl_uje_team=>update_teams(

             EXPORTING i_appset_id = lcl_application=>lv_environment_id

                       it_teams = lt_team ).

          ENDIF.



          CONCATENATE 'Team' ls_team-team_id

                       'has been created/updated successfully'

                           INTO lv_message SEPARATED BY space.

          add_message_to_message_table( i_msgid = `00` i_msgty = `S` i_msgno = `001`

                                        i_message = lv_message ).

        CATCH cx_uje_exception INTO lo_uje_exception.

          add_exception_to_message_table( lo_uje_exception ).

          CONCATENATE 'Team' ls_team-team_id

                      'not created/updated due to error'

                            INTO lv_message SEPARATED BY space.

          add_message_to_message_table( i_msgid = `00` i_msgty = `E` i_msgno = `001`

                                        i_message = lv_message ).

      ENDTRY.



    ENDLOOP.



    lcl_application=>render_alv( ).



  ENDMETHOD.                    "create_teams_from_file



  METHOD export_team_assign_to_file.



    TYPES: BEGIN OF t_user_assign,

            user_id TYPE uje_s_user_team-user_id,

            team_id TYPE uje_s_user_team-team_id,

            teamleader TYPE uje_s_user_team-teamleader,

           END OF t_user_assign.



    DATA: lt_team_assign TYPE TABLE OF t_user_assign.

    DATA: ls_team_assign LIKE LINE OF lt_team_assign.



    DATA: ls_user_team TYPE uje_s_team.

    DATA: ls_user_detail LIKE LINE OF lt_user_detail.



* Loop through users, then through assigned teams,

* check table for team leader and set flag.

    LOOP AT lcl_application=>lt_user_detail INTO ls_user_detail.

      CLEAR ls_team_assign.

      ls_team_assign-user_id = ls_user_detail-user_id.

      LOOP AT ls_user_detail-teams INTO ls_user_team.

        ls_team_assign-team_id = ls_user_team-team_id.

        READ TABLE ls_user_detail-leading_teams

                 TRANSPORTING NO FIELDS

                      WITH KEY team_id = ls_user_team-team_id.

        IF sy-subrc = 0.

          ls_team_assign-teamleader  = abap_true.

        ENDIF.

        APPEND ls_team_assign TO lt_team_assign.

      ENDLOOP.

    ENDLOOP.



* Download table

    lcl_application=>download( EXPORTING i_filepath = p_file

                                         it_datatab = lt_team_assign ).



  ENDMETHOD.                    "export_team_assign_to_file



  METHOD import_team_assign_from_file.



    TYPES: BEGIN OF t_user_assign,

            user_id TYPE uje_s_user_team-user_id,

            team_id TYPE uje_s_user_team-team_id,

            teamleader TYPE uje_s_user_team-teamleader,

           END OF t_user_assign.



    DATA: lv_message TYPE uj0_s_message-message.



    DATA: lt_user_team TYPE uje_t_user_team.

    DATA: ls_user_team TYPE uje_s_user_team.



    DATA: ls_team_assign TYPE uje_s_user_team.



    DATA: lt_messages TYPE uj0_t_message.

    DATA: ls_alv_messages LIKE LINE OF lt_alv_messages.



    DATA: lt_strtab TYPE stringtab.

    DATA: ls_strtab LIKE LINE OF lt_strtab.



    DATA: ls_user_list TYPE uje_s_userinfo.

    DATA: ls_teams_list LIKE LINE OF lt_teams_list.



    DATA: lt_users TYPE uje_t_user_action.

    DATA: ls_users LIKE LINE OF lt_users.



    DATA: lt_teams TYPE uje_t_team.

    DATA: ls_teams TYPE uje_s_team.



    lt_strtab = lcl_application=>upload( p_file ).



    LOOP AT lt_strtab INTO ls_strtab.



      SPLIT ls_strtab AT lcl_application=>lv_delimiter INTO ls_team_assign-user_id

                                  ls_team_assign-team_id

                                  ls_team_assign-teamleader.



      CLEAR ls_user_team.

      ls_user_team-user_id = ls_team_assign-user_id.

      ls_user_team-team_id = ls_team_assign-team_id.

      ls_user_team-teamleader = ls_team_assign-teamleader.

      TRANSLATE ls_user_team-teamleader USING 'YXyX1XxXN n 0 '. "Translate to X or space

      APPEND ls_user_team TO lt_user_team.



      IF lcl_application=>team_is_valid( ls_team_assign-team_id ) = abap_false.

        CONCATENATE 'Team' ls_team_assign-team_id 'does not yet exist.'

                    'No user assigments done.'

                          INTO lv_message SEPARATED BY space.

        add_message_to_message_table( i_msgid = `00` i_msgty = `E` i_msgno = `001`

                                      i_message = lv_message ).

        lcl_application=>render_alv( ).

        RETURN.

      ENDIF.



      IF lcl_application=>user_is_valid( ls_team_assign-user_id ) = abap_false.

        CONCATENATE 'User' ls_team_assign-user_id 'does not yet exist.'

                    'No user assigments done.'

                          INTO lv_message SEPARATED BY space.

        add_message_to_message_table( i_msgid = `00` i_msgty = `E` i_msgno = `001`

                                      i_message = lv_message ).

        lcl_application=>render_alv( ).

        RETURN.

      ENDIF.



    ENDLOOP.



* Loop through existing teams, all updates for each team

* will be done at one time.

    LOOP AT lcl_application=>lt_teams_list INTO ls_teams_list.



* Check that there is data for team assignment from file, otherwise skip

      READ TABLE lt_user_team TRANSPORTING NO FIELDS

                        WITH KEY team_id = ls_teams_list-team_id.

      IF sy-subrc <> 0.

        CONTINUE.

      ENDIF.



* Add existing team details to table.

      CLEAR ls_teams. REFRESH lt_teams.

      MOVE-CORRESPONDING ls_teams_list TO ls_teams.

      APPEND ls_teams TO lt_teams.



* Add existing users to table

      REFRESH lt_users.

      LOOP AT ls_teams_list-users INTO ls_user_list.

        ls_users-user_id = ls_user_list-user_id.

        READ TABLE ls_teams_list-team_leaders

                     TRANSPORTING NO FIELDS

                              WITH KEY user_id = ls_user_list-user_id.

        IF sy-subrc = 0.

          ls_users-is_leader = abap_true.

        ENDIF.

        APPEND ls_users TO lt_users.

      ENDLOOP.



* add new user to table, if already exists, update leader flag

      LOOP AT lt_user_team INTO ls_user_team

                       WHERE team_id = ls_teams_list-team_id.

        READ TABLE lt_users INTO ls_users

                           WITH KEY  user_id = ls_user_team-user_id.

        IF sy-subrc = 0.

          ls_users-is_leader = ls_user_team-teamleader.

          ls_users-action = 'M'.

          MODIFY lt_users FROM ls_users INDEX sy-tabix.

        ELSE.

          CLEAR ls_users.

          ls_users-user_id = ls_user_team-user_id.

          ls_users-is_leader = ls_user_team-teamleader.

          ls_users-action = 'I'.

          APPEND ls_users TO lt_users.

        ENDIF.

      ENDLOOP.



* now update the user/team assignments

      TRY.

          cl_uje_team=>update_teams(

                       EXPORTING i_appset_id = lcl_application=>lv_environment_id

                                 it_teams = lt_teams

                                 it_users = lt_users ).

          CONCATENATE 'Team' ls_teams_list-team_id 'user assignments'

                      'have been updated successfully'

                           INTO lv_message SEPARATED BY space.

          add_message_to_message_table( i_msgid = `00` i_msgty = `S` i_msgno = `001`

                                        i_message = lv_message ).

        CATCH cx_uje_exception INTO lo_uje_exception.

          add_exception_to_message_table( lo_uje_exception ).

          CONCATENATE 'Team' ls_teams_list-team_id 'user assignments'

          'not updated due to error'

               INTO lv_message SEPARATED BY space.

          add_message_to_message_table( i_msgid = `00` i_msgty = `E` i_msgno = `001`

                                        i_message = lv_message ).

      ENDTRY.



    ENDLOOP.



    lcl_application=>render_alv( ).



  ENDMETHOD.                    "import_team_assign_from_file



  METHOD export_task_profiles_to_file.



    TYPES: BEGIN OF t_output,

            identifier TYPE char01, " Row Identifer

            profile TYPE uj_profile_id,

            values TYPE string,

           END OF t_output.



    DATA: lt_output TYPE TABLE OF t_output.

    DATA: ls_output LIKE LINE OF lt_output.



    DATA: ls_task_profiles LIKE LINE OF lcl_application=>lt_task_profiles.



    DATA: ls_tasks TYPE uje_s_task_info.

    DATA: ls_users TYPE uje_s_userinfo.

    DATA: ls_teams TYPE uje_s_team.



    LOOP AT lcl_application=>lt_task_profiles INTO ls_task_profiles.



* Write Header row

      CLEAR ls_output.

      ls_output-identifier = 'H'.

      ls_output-profile  = ls_task_profiles-profile_id.

      ls_output-values = ls_task_profiles-description.

      APPEND ls_output TO lt_output.



* Write task assigments

      CLEAR ls_output.

      ls_output-identifier = 'K'.

      ls_output-profile  = ls_task_profiles-profile_id.

      LOOP AT ls_task_profiles-tasks INTO ls_tasks.

        ls_output-values = ls_tasks-task_id.

        APPEND ls_output TO lt_output.

      ENDLOOP.



* Write User Assignment

      CLEAR ls_output.

      ls_output-identifier = 'U'.

      ls_output-profile  = ls_task_profiles-profile_id.

      LOOP AT ls_task_profiles-users INTO ls_users.

        ls_output-values = ls_users-user_id.

        APPEND ls_output TO lt_output.

      ENDLOOP.



* Write Team Assignement

      CLEAR ls_output.

      ls_output-identifier = 'T'.

      ls_output-profile  = ls_task_profiles-profile_id.

      LOOP AT ls_task_profiles-teams INTO ls_teams.

        ls_output-values = ls_teams-team_id.

        APPEND ls_output TO lt_output.

      ENDLOOP.



    ENDLOOP.



* Download table

    lcl_application=>download( EXPORTING i_filepath = p_file

                                         it_datatab = lt_output ).



  ENDMETHOD.                    "export_task_profiles_to_file



  METHOD import_task_profiles_from_file.



    TYPES: BEGIN OF t_input,

            identifier TYPE char01, " Row Identifer

            profile TYPE uj_profile_id,

            values TYPE string,

           END OF t_input.



    TYPES: BEGIN OF t_task_profile,

            profile TYPE uje_s_profile,

            task_info TYPE uje_t_task_info,

            users_asin TYPE uje_t_api_user_id,

            teams_asin TYPE uje_t_api_team_id,

           END OF t_task_profile.



    DATA: lt_task_profile TYPE TABLE OF t_task_profile.

    DATA: ls_task_profile LIKE LINE OF lt_task_profile.



    DATA: lv_last_profile TYPE uj_profile_id.



    DATA: ls_users_asin TYPE uje_s_api_user_id.

    DATA: ls_teams_asin TYPE uje_s_api_team_id.

    DATA: ls_teams_list LIKE LINE OF lt_teams_list.



    DATA: lt_task_info TYPE  uje_t_task_info.

    DATA: ls_task_info LIKE LINE OF lt_task_info.



    DATA: lt_strtab TYPE stringtab.

    DATA: ls_strtab LIKE LINE OF lt_strtab.



    DATA: lt_input TYPE TABLE OF t_input.

    DATA: ls_input LIKE LINE OF lt_input.



    DATA: lt_tasks TYPE uje_t_task_id.

    DATA: ls_tasks LIKE LINE OF lt_tasks.



    DATA: lt_profs TYPE uje_t_profile_action.

    DATA: ls_profs LIKE LINE OF lt_profs.



    DATA: lt_teams TYPE uje_t_team.

    DATA: ls_teams LIKE LINE OF lt_teams.



    DATA: lt_users TYPE uje_t_user_id.

    DATA: ls_users LIKE LINE OF lt_users.



    DATA: lv_message TYPE uj0_s_message-message.

    DATA: lv_object_id TYPE string.



    DATA: lo_task_profile_mgr TYPE REF TO cl_uje_profile_task.



* Upload file

    lt_strtab = lcl_application=>upload( p_file ).



* Rip import file into internal table

    LOOP AT lt_strtab INTO ls_strtab.

      CLEAR ls_input.

      SPLIT ls_strtab AT lcl_application=>lv_delimiter INTO ls_input-identifier

                                  ls_input-profile

                                  ls_input-values.

      APPEND ls_input TO lt_input.

    ENDLOOP.



* Build profile table containing all associated data

    SORT lt_input STABLE ASCENDING BY profile identifier values.



    LOOP AT lt_input INTO ls_input.



      IF ls_input-profile <> lv_last_profile

          AND lv_last_profile IS NOT INITIAL.

        APPEND ls_task_profile TO lt_task_profile.

        CLEAR ls_task_profile.

      ENDIF.



* Based on record identifier

      CASE ls_input-identifier.

        WHEN 'H'" Header

          ls_task_profile-profile-profile_id  = ls_input-profile.

          ls_task_profile-profile-description = ls_input-values.

        WHEN 'K'" Task info

          ls_task_info-task_id = ls_input-values.

          IF lcl_application=>task_is_valid( ls_task_info-task_id ) = abap_false.

            CONCATENATE 'Task ID' ls_task_info-task_id  'is not valid.'

                        'No task profile updates done.'

                                INTO lv_message SEPARATED BY space.

            add_message_to_message_table( i_msgid = `00` i_msgty = `E` i_msgno = `001`

                                          i_message = lv_message ).

            lcl_application=>render_alv( ).

            RETURN.

          ENDIF.

          APPEND ls_task_info TO ls_task_profile-task_info.

        WHEN 'U'" Users Assignments

          ls_users_asin  = ls_input-values.

          IF lcl_application=>user_is_valid( ls_users_asin ) = abap_false.

            CONCATENATE 'User' ls_users_asin  'does not exist.'

                        'No task profile updates done.'

                                INTO lv_message SEPARATED BY space.

            add_message_to_message_table( i_msgid = `00` i_msgty = `E` i_msgno = `001`

                                          i_message = lv_message ).

            lcl_application=>render_alv( ).

            RETURN.

          ENDIF.

          APPEND ls_users_asin  TO ls_task_profile-users_asin.

        WHEN 'T'" Team Assignments

          ls_teams_asin  = ls_input-values.

          IF lcl_application=>team_is_valid( ls_teams_asin ) = abap_false.

            CONCATENATE 'Team' ls_teams_asin 'does not exist.'

                        'No task profile updates done.'

                                INTO lv_message SEPARATED BY space.

            add_message_to_message_table( i_msgid = `00` i_msgty = `E` i_msgno = `001`

                                          i_message = lv_message ).

            lcl_application=>render_alv( ).

            RETURN.

          ENDIF.

          APPEND ls_teams_asin  TO ls_task_profile-teams_asin.

      ENDCASE.



      lv_last_profile = ls_input-profile.



      AT LAST.

        APPEND ls_task_profile TO lt_task_profile.

      ENDAT.



    ENDLOOP.



* Now for each profile, call API to create/update

    LOOP AT lt_task_profile INTO ls_task_profile.



      REFRESH lt_tasks.

      LOOP AT ls_task_profile-task_info INTO ls_task_info.

        CLEAR ls_tasks.

        ls_tasks = ls_task_info-task_id.

        APPEND ls_tasks TO lt_tasks.

      ENDLOOP.



      TRY.

* Create the task profile.

          lv_object_id = ls_task_profile-profile-profile_id.

          lo_task_profile_mgr ?= cl_uje_user_mgr=>create_obj(

                       i_appset_id = lcl_application=>lv_environment_id

                       i_object_id = lv_object_id

                       i_object_type = 'CL_UJE_PROFILE_TASK' ).

          IF lcl_application=>tprofile_is_valid( ls_task_profile-profile-profile_id ) = abap_false.

            lo_task_profile_mgr->create(

                          EXPORTING i_task_prof_desc = ls_task_profile-profile-description

                                    it_tasks = lt_tasks ).

          ELSE.

            lo_task_profile_mgr->update(

                           EXPORTING i_task_prof_desc = ls_task_profile-profile-description

                                     it_tasks = lt_tasks ).

          ENDIF.



* Assign users

          LOOP AT ls_task_profile-users_asin INTO ls_users_asin.



            CLEAR ls_users. REFRESH lt_users.

            ls_users = ls_users_asin-user_id.

            APPEND ls_users TO lt_users.



            CLEAR ls_profs. REFRESH lt_profs.

            ls_profs-profile_id = ls_task_profile-profile-profile_id.

            ls_profs-action = 'I'.

            APPEND ls_profs TO lt_profs.



            TRY.

                cl_uje_user=>update_users(

                  EXPORTING i_appset_id = lcl_application=>lv_environment_id

                            it_users = lt_users

                            it_task_profs = lt_profs ).

              CATCH cx_uje_exception INTO lo_uje_exception.

                add_exception_to_message_table( lo_uje_exception ).

                CONCATENATE 'Task Profile' ls_task_profile-profile-profile_id

                            'not created/updated due to error'

                                 INTO lv_message SEPARATED BY space.

                add_message_to_message_table( i_msgid = `00` i_msgty = `E` i_msgno = `001`

                                              i_message = lv_message ).

            ENDTRY.



          ENDLOOP.



* Assign teams

          LOOP AT ls_task_profile-teams_asin INTO ls_teams_asin.



            REFRESH lt_teams.

            READ TABLE lt_teams_list INTO ls_teams_list

                            WITH KEY team_id = ls_teams_asin-team_id.

            IF sy-subrc = 0.

              MOVE-CORRESPONDING ls_teams_list TO ls_teams.

              APPEND ls_teams TO lt_teams.

            ENDIF.



            CLEAR ls_profs. REFRESH lt_profs.

            ls_profs-profile_id = ls_task_profile-profile-profile_id.

            ls_profs-action = 'I'.

            APPEND ls_profs TO lt_profs.



            TRY.

                cl_uje_team=>update_teams(

                             EXPORTING i_appset_id = lcl_application=>lv_environment_id

                                       it_teams = lt_teams

                                       it_task_profs = lt_profs ).

              CATCH cx_uje_exception INTO lo_uje_exception.

                add_exception_to_message_table( lo_uje_exception ).

                CONCATENATE 'Task Profile' ls_task_profile-profile-profile_id

                            'not created/updated due to error'

                                 INTO lv_message SEPARATED BY space.

                add_message_to_message_table( i_msgid = `00` i_msgty = `E` i_msgno = `001`

                                              i_message = lv_message ).

            ENDTRY.

          ENDLOOP.



          CONCATENATE 'Task Profile' ls_task_profile-profile-profile_id

                      'has been created/updated successfully'

                           INTO lv_message SEPARATED BY space.

          add_message_to_message_table( i_msgid = `00` i_msgty = `S` i_msgno = `001`

                                        i_message = lv_message ).



        CATCH cx_uje_exception INTO lo_uje_exception.

          add_exception_to_message_table( lo_uje_exception ).

          CONCATENATE 'Task Profile' ls_task_profile-profile-profile_id

                      'not created/updated due to error'

                           INTO lv_message SEPARATED BY space.

          add_message_to_message_table( i_msgid = `00` i_msgty = `E` i_msgno = `001`

                                        i_message = lv_message ).

      ENDTRY.



    ENDLOOP.



* Display ALV

    lcl_application=>render_alv( ).



  ENDMETHOD.                    "import_task_profiles_from_file



  METHOD export_data_profiles_to_file.



    TYPES: BEGIN OF t_output,

            identifier TYPE char01, " Row Identifer

            profile TYPE uj_profile_id,

            values TYPE string,

           END OF t_output.



    DATA: lt_output TYPE TABLE OF t_output.

    DATA: ls_output LIKE LINE OF lt_output.



    DATA: lt_data_prof_det TYPE uje_t_mbr_prof_det.

    DATA: ls_data_prof_det LIKE LINE OF lt_data_prof_det.



    DATA: lt_users TYPE uje_t_user.

    DATA: ls_users LIKE LINE OF lt_users.



    DATA: lt_teams TYPE uje_t_team.

    DATA: ls_teams LIKE LINE OF lt_teams.



    DATA: ls_data_access_profiles TYPE uje_s_mbr_prof_app.

    DATA: ls_cube_acc TYPE uje_s_cubeacc_det.

    DATA: ls_dimacc_det TYPE uje_s_dimacc_det.

    DATA: ls_mbracc_det  TYPE uje_s_mbracc_det.

    DATA: ls_member TYPE uje_s_mbr.



    DATA: ls_cube_matrix_acc TYPE uje_s_cubeacc_matrix_det.

    DATA: ls_dimensions TYPE uj_dim_name.

    DATA: ls_rights TYPE uje_s_dimacc_matrix_det.

    DATA: ls_members TYPE uj_dim_member.



    DATA: lo_profile_dao TYPE REF TO cl_uje_profile_dao.

    DATA: lo_data_access_profile_mgr TYPE REF TO cl_uje_profile_memaccess.



    CREATE OBJECT lo_profile_dao

      EXPORTING

        i_appset_id = lcl_application=>lv_environment_id.



    CREATE OBJECT lo_data_access_profile_mgr

      EXPORTING

        i_appset_id = lcl_application=>lv_environment_id.



    LOOP AT lcl_application=>lt_data_access_profiles INTO ls_data_access_profiles.



      REFRESH: lt_data_prof_det.

      lo_data_access_profile_mgr->get_details(

                 EXPORTING

                       i_profile_id       = ls_data_access_profiles-profile_id

                 IMPORTING

                       et_mbr_prof_detail = lt_data_prof_det ).



      REFRESH: lt_users, lt_teams.

      lo_profile_dao->get_details( EXPORTING i_profile_id = ls_data_access_profiles-profile_id

                                             i_profile_class = `MBR`

                                   IMPORTING et_users = lt_users

                                             et_teams = lt_teams ).



      CLEAR ls_data_prof_det.

      READ TABLE lt_data_prof_det INTO ls_data_prof_det

                     WITH KEY profile_agr_name = ls_data_access_profiles-profile_id. "Should only be 1 row

      IF sy-subrc <> 0.

      ENDIF.



* Write Header row

      CLEAR ls_output.

      ls_output-identifier = 'H'.

      ls_output-profile  = ls_data_prof_det-profile_agr_name.

      ls_output-values  = ls_data_prof_det-description.

      APPEND ls_output TO lt_output.



* Write Member detail data.

      LOOP AT lt_data_prof_det INTO ls_data_prof_det.



        CLEAR ls_output.

        ls_output-identifier = 'M'.

        ls_output-profile  = ls_data_access_profiles-profile_id.



        IF ls_data_prof_det-cube_acc IS NOT INITIAL.

          LOOP AT ls_data_prof_det-cube_acc INTO ls_cube_acc.

            LOOP AT ls_cube_acc-dimacc_det INTO ls_dimacc_det.

              LOOP AT ls_dimacc_det-mbracc_det INTO ls_mbracc_det.

                LOOP AT ls_mbracc_det-member INTO ls_member.

                  CONCATENATE ls_dimacc_det-dimension

                              ls_cube_acc-application_id

                             "ls_cube_acc-matrix   " Not needed

                              ls_member-mbr_id

                              ls_mbracc_det-rwd

                                 INTO ls_output-values SEPARATED BY lcl_application=>lv_delimiter.

                  APPEND ls_output TO lt_output.

                ENDLOOP.

              ENDLOOP.

            ENDLOOP.

          ENDLOOP.

        ENDIF.



      ENDLOOP.



* Write User and Team assignments.

      LOOP AT lt_users INTO ls_users.

        CLEAR ls_output.

        ls_output-identifier = 'U'.

        ls_output-profile  = ls_data_access_profiles-profile_id.

        ls_output-values = ls_users-user_id.

        APPEND ls_output TO lt_output.

      ENDLOOP.



      LOOP AT lt_teams INTO ls_teams.

        CLEAR ls_output.

        ls_output-identifier = 'T'.

        ls_output-profile  = ls_data_access_profiles-profile_id.

        ls_output-values = ls_teams-team_id.

        APPEND ls_output TO lt_output.

      ENDLOOP.



    ENDLOOP.



* Download table

    lcl_application=>download( EXPORTING i_filepath = p_file

                                         it_datatab = lt_output ).



  ENDMETHOD.                    "export_mem_profiles_to_file



  METHOD import_data_profiles_from_file.



    TYPES: BEGIN OF t_input,

            identifier TYPE char01, " Row Identifer

            profile TYPE uj_profile_id,

            values TYPE string,

           END OF t_input.



    TYPES: BEGIN OF t_dataacc_profile,

            profile TYPE uje_s_profile,

            dataacc TYPE uje_t_memaccess,

            users_asin TYPE uje_t_api_user_id,

            teams_asin TYPE uje_t_api_team_id,

           END OF t_dataacc_profile.



    DATA: lt_dataacc_profile TYPE TABLE OF t_dataacc_profile.

    DATA: ls_dataacc_profile LIKE LINE OF lt_dataacc_profile.



    DATA: lv_last_profile TYPE uj_profile_id.



    DATA: lt_dataaccess TYPE uje_t_memaccess.

    DATA: ls_dataaccess LIKE LINE OF lt_dataaccess.



    DATA: lt_strtab TYPE stringtab.

    DATA: ls_strtab LIKE LINE OF lt_strtab.



    DATA: lt_input TYPE TABLE OF t_input.

    DATA: ls_input LIKE LINE OF lt_input.



    DATA: lt_data_prof TYPE uje_t_mbr_prof_det.

    DATA: ls_data_prof TYPE uje_s_mbr_prof_det.



    DATA: lt_profs TYPE uje_t_profile_action.

    DATA: ls_profs LIKE LINE OF lt_profs.



    DATA: lt_teams TYPE uje_t_team.

    DATA: ls_teams LIKE LINE OF lt_teams.



    DATA: lt_users TYPE uje_t_user_id.

    DATA: ls_users LIKE LINE OF lt_users.



    DATA: ls_users_asin TYPE uje_s_api_user_id.

    DATA: ls_teams_asin TYPE uje_s_api_team_id.

    DATA: ls_cubeacc TYPE uje_s_cubeacc_det.

    DATA: ls_dimacc_det TYPE uje_s_dimacc_det.

    DATA: ls_dataacc_det TYPE uje_s_mbracc_det.

    DATA: ls_member_list TYPE uje_s_mbr.

    DATA: ls_teams_list LIKE LINE OF lt_teams_list.



    DATA: lv_message TYPE uj0_s_message-message.



* Upload file

    lt_strtab = lcl_application=>upload( p_file ).



* Rip import file into internal table

    LOOP AT lt_strtab INTO ls_strtab.

      CLEAR ls_input.

      SPLIT ls_strtab AT lcl_application=>lv_delimiter INTO ls_input-identifier

                                  ls_input-profile

                                  ls_input-values.

      APPEND ls_input TO lt_input.

    ENDLOOP.



* Build profile table containing all associated data

    SORT lt_input STABLE ASCENDING BY profile identifier values.



    LOOP AT lt_input INTO ls_input.



      IF ls_input-profile <> lv_last_profile

          AND lv_last_profile IS NOT INITIAL.

        APPEND ls_dataacc_profile TO lt_dataacc_profile.

        CLEAR ls_dataacc_profile.

      ENDIF.



* Based on record identifier

      CASE ls_input-identifier.

        WHEN 'H'" Header

          ls_dataacc_profile-profile-profile_id = ls_input-profile.

          ls_dataacc_profile-profile-description = ls_input-values.

        WHEN 'M'" Data Access info

          ls_dataaccess-profile_id = ls_input-profile.

          SPLIT ls_input-values AT lcl_application=>lv_delimiter INTO ls_dataaccess-dimension

                                            ls_dataaccess-application_id

                                            ls_dataaccess-member

                                            ls_dataaccess-rwd.

* Check APPLICATION_ID

          READ TABLE lcl_application=>lt_appl_info

                 TRANSPORTING NO FIELDS

                      WITH KEY application_id = ls_dataaccess-application_id.

          IF sy-subrc <> 0.

            CONCATENATE 'Application ID' ls_dataaccess-application_id

                       'not valid for this Application Set'

                           INTO lv_message SEPARATED BY space.

            add_message_to_message_table( i_msgid = `00` i_msgty = `E` i_msgno = `001`

                                          i_message = lv_message ).

            CONCATENATE 'Data Access Profile' ls_dataacc_profile-profile-profile_id

                       'not created/updated due to error'

                           INTO lv_message SEPARATED BY space.

            add_message_to_message_table( i_msgid = `00` i_msgty = `E` i_msgno = `001`

                                          i_message = lv_message ).

          ENDIF.



* Check DIMENSION

          READ TABLE lcl_application=>lt_appl_dim

               TRANSPORTING NO FIELDS

                       WITH KEY appl_id  = ls_dataaccess-application_id

                               dimension = ls_dataaccess-dimension.

          IF sy-subrc <> 0.

            CONCATENATE 'Dimension' ls_dataaccess-dimension

                        'not valid for Application'

                         ls_dataaccess-application_id

                            INTO lv_message SEPARATED BY space.

            add_message_to_message_table( i_msgid = `00` i_msgty = `E` i_msgno = `001`

                                          i_message = lv_message ).

            CONCATENATE 'Data Access Profile'

                        ls_dataacc_profile-profile-profile_id

                        'not created/updated due to error'

                            INTO lv_message SEPARATED BY space.

            add_message_to_message_table( i_msgid = `00` i_msgty = `E` i_msgno = `001`

                                          i_message = lv_message ).

          ENDIF.



* Check MEMBER

          READ TABLE lcl_application=>lt_members

               TRANSPORTING NO FIELDS

                      WITH KEY appl_id   = ls_dataaccess-application_id

                               dimension = ls_dataaccess-dimension

                               member    = ls_dataaccess-member.

          IF sy-subrc <> 0 AND ls_dataaccess-member <> '[ALL]'.

            CONCATENATE 'Member' ls_dataaccess-member

                       'not valid for Dimension' ls_dataaccess-dimension

                           INTO lv_message SEPARATED BY space.

            add_message_to_message_table( i_msgid = `00` i_msgty = `E` i_msgno = `001`

                                          i_message = lv_message ).

            CONCATENATE 'Data Access Profile' ls_dataacc_profile-profile-profile_id

                       'not created/updated due to error'

                           INTO lv_message SEPARATED BY space.

            add_message_to_message_table( i_msgid = `00` i_msgty = `E` i_msgno = `001`

                                          i_message = lv_message ).

          ENDIF.

          APPEND ls_dataaccess TO ls_dataacc_profile-dataacc.

        WHEN 'U'" Users Assignments

          ls_users_asin  = ls_input-values.

          IF lcl_application=>user_is_valid( ls_users_asin ) = abap_false.

            CONCATENATE 'User' ls_users_asin  'does not exist.'

                        'No data access profile updates done.'

                            INTO lv_message SEPARATED BY space.

            add_message_to_message_table( i_msgid = `00` i_msgty = `E` i_msgno = `001`

                                          i_message = lv_message ).

          ENDIF.

          APPEND ls_users_asin  TO ls_dataacc_profile-users_asin.

        WHEN 'T'" Team Assignments

          ls_teams_asin  = ls_input-values.

          IF lcl_application=>team_is_valid( ls_teams_asin ) = abap_false.

            CONCATENATE 'Team' ls_teams_asin 'does not exist.'

                        'No data access profile updates done.'

                            INTO lv_message SEPARATED BY space.

            add_message_to_message_table( i_msgid = `00` i_msgty = `E` i_msgno = `001`

                                          i_message = lv_message ).

          ENDIF.

          APPEND ls_teams_asin  TO ls_dataacc_profile-teams_asin.

      ENDCASE.



      lv_last_profile = ls_input-profile.



      AT LAST.

        APPEND ls_dataacc_profile TO lt_dataacc_profile.

      ENDAT.



    ENDLOOP.



* If any message during check, then render now, and do not process anything.

    IF lt_alv_messages IS NOT INITIAL.

      lcl_application=>render_alv( ).

      RETURN.

    ENDIF.



* Now for each profile, call API to create/update

    LOOP AT lt_dataacc_profile INTO ls_dataacc_profile.



      CLEAR ls_data_profREFRESH lt_data_prof.

      ls_data_prof-profile_agr_name = ls_dataacc_profile-profile-profile_id.

      ls_data_prof-description = ls_dataacc_profile-profile-description.



      LOOP AT ls_dataacc_profile-dataacc INTO ls_dataaccess.



        CLEAR ls_member_list.

        CLEAR ls_dataacc_det.

        CLEAR ls_dimacc_det.

        CLEAR ls_cubeacc.



        ls_member_list-mbr_id = ls_dataaccess-member.

        APPEND ls_member_list TO ls_dataacc_det-member.

        ls_dataacc_det-rwd = ls_dataaccess-rwd.

        APPEND ls_dataacc_det TO ls_dimacc_det-mbracc_det.

        ls_dimacc_det-dimension = ls_dataaccess-dimension.



        ls_cubeacc-application_id = ls_dataaccess-application_id.

        APPEND ls_dimacc_det TO ls_cubeacc-dimacc_det.



        APPEND ls_cubeacc TO ls_data_prof-cube_acc.



      ENDLOOP.



      APPEND ls_data_prof TO lt_data_prof.



* Determine if the data access profile is new, call correct API.

      TRY.

          IF lcl_application=>dprofile_is_valid( ls_dataacc_profile-profile-profile_id ) = abap_false.

            cl_uje_profile_memaccess=>create_mbr_profiles(

                    EXPORTING i_appset_id = lcl_application=>lv_environment_id

                              it_mbr_prof_det = lt_data_prof ).

          ELSE.

            cl_uje_profile_memaccess=>update_mbr_profiles(

                    EXPORTING i_appset_id = lcl_application=>lv_environment_id

                              it_mbr_prof_det = lt_data_prof ).

          ENDIF.



* Assign users

          LOOP AT ls_dataacc_profile-users_asin INTO ls_users_asin.



            CLEAR ls_users. REFRESH lt_users.

            ls_users = ls_users_asin-user_id.

            APPEND ls_users TO lt_users.



            CLEAR ls_profs. REFRESH lt_profs.

            ls_profs-profile_id = ls_dataacc_profile-profile-profile_id.

            ls_profs-action = 'I'.

            APPEND ls_profs TO lt_profs.



            TRY.

                cl_uje_user=>update_users(

                  EXPORTING i_appset_id = lcl_application=>lv_environment_id

                            it_users = lt_users

                            it_mbr_profs = lt_profs ).

              CATCH cx_uje_exception INTO lo_uje_exception.

                add_exception_to_message_table( lo_uje_exception ).

                CONCATENATE 'Data Access Profile' ls_dataacc_profile-profile-profile_id

                            'not created/updated due to error'

                                 INTO lv_message SEPARATED BY space.

                add_message_to_message_table( i_msgid = `00` i_msgty = `E` i_msgno = `001`

                                              i_message = lv_message ).

            ENDTRY.



          ENDLOOP.



* Assign teams

          LOOP AT ls_dataacc_profile-teams_asin INTO ls_teams_asin.



            REFRESH lt_teams.

            READ TABLE lt_teams_list INTO ls_teams_list

                            WITH KEY team_id = ls_teams_asin-team_id.

            IF sy-subrc = 0.

              MOVE-CORRESPONDING ls_teams_list TO ls_teams.

              APPEND ls_teams TO lt_teams.

            ENDIF.



            CLEAR ls_profs. REFRESH lt_profs.

            ls_profs-profile_id = ls_dataacc_profile-profile-profile_id.

            ls_profs-action = 'I'.

            APPEND ls_profs TO lt_profs.



            TRY.

                cl_uje_team=>update_teams(

                             EXPORTING i_appset_id = lcl_application=>lv_environment_id

                                       it_teams = lt_teams

                                       it_mbr_profs = lt_profs ).

              CATCH cx_uje_exception INTO lo_uje_exception.

                add_exception_to_message_table( lo_uje_exception ).

                CONCATENATE 'Data Access Profile' ls_dataacc_profile-profile-profile_id

                            'not created/updated due to error'

                                 INTO lv_message SEPARATED BY space.

                add_message_to_message_table( i_msgid = `00` i_msgty = `E` i_msgno = `001`

                                              i_message = lv_message ).

            ENDTRY.

          ENDLOOP.



          CONCATENATE 'Data Access Profile' ls_dataacc_profile-profile-profile_id

                      'has been created/updated successfully'

                          INTO lv_message SEPARATED BY space.

          add_message_to_message_table( i_msgid = `00` i_msgty = `S` i_msgno = `001`

                                        i_message = lv_message ).

        CATCH cx_uje_exception INTO lo_uje_exception.

          add_exception_to_message_table( lo_uje_exception ).

          CONCATENATE 'Data Access Profile' ls_dataacc_profile-profile-profile_id

                      'not created/updated due to error'

                          INTO lv_message SEPARATED BY space.

          add_message_to_message_table( i_msgid = `00` i_msgty = `E` i_msgno = `001`

                                      i_message = lv_message ).

      ENDTRY.



    ENDLOOP.



* Display ALV

    lcl_application=>render_alv( ).



  ENDMETHOD.                    "import_mem_profiles_from_file



  METHOD export_tap_assign_to_file.



    TYPES: BEGIN OF t_output,

             identifier TYPE char01, " Row Identifer

             profile TYPE uj_profile_id,

             id TYPE uj_user_id"User ID or Team ID

            END OF t_output.



    DATA: lt_output TYPE TABLE OF t_output.

    DATA: ls_output LIKE LINE OF lt_output.



    DATA: ls_task_profiles LIKE LINE OF lcl_application=>lt_task_profiles.



    DATA: ls_tasks TYPE uje_s_task_info.

    DATA: ls_users TYPE uje_s_userinfo.

    DATA: ls_teams TYPE uje_s_team.



    LOOP AT lcl_application=>lt_task_profiles INTO ls_task_profiles.



* Write User Assignment

      CLEAR ls_output.

      ls_output-identifier = 'U'.

      ls_output-profile  = ls_task_profiles-profile_id.

      LOOP AT ls_task_profiles-users INTO ls_users.

        ls_output-id  = ls_users-user_id.

        APPEND ls_output TO lt_output.

      ENDLOOP.



* Write Team Assignement

      CLEAR ls_output.

      ls_output-identifier = 'T'.

      ls_output-profile  = ls_task_profiles-profile_id.

      LOOP AT ls_task_profiles-teams INTO ls_teams.

        ls_output-id  = ls_teams-team_id.

        APPEND ls_output TO lt_output.

      ENDLOOP.



    ENDLOOP.



* Download table

    lcl_application=>download( EXPORTING i_filepath = p_file

                                         it_datatab = lt_output ).



  ENDMETHOD.                    "export_tap_assign_to_file



  METHOD import_tap_assign_from_file.



    TYPES: BEGIN OF t_input,

            identifier TYPE char01, "Identifer, U or T

            profile TYPE uj_profile_id,

            id TYPE uj_user_id"User ID or Team ID

           END OF t_input.



    TYPES: BEGIN OF t_task_profile,

            profile TYPE uje_s_profile,

            users_asin TYPE uje_t_api_user_id,

            teams_asin TYPE uje_t_api_team_id,

           END OF t_task_profile.



    DATA: lt_task_profile TYPE TABLE OF t_task_profile.

    DATA: ls_task_profile LIKE LINE OF lt_task_profile.



    DATA: lt_strtab TYPE stringtab.

    DATA: ls_strtab LIKE LINE OF lt_strtab.



    DATA: lt_input TYPE TABLE OF t_input.

    DATA: ls_input LIKE LINE OF lt_input.



    DATA: lt_profs TYPE uje_t_profile_action.

    DATA: ls_profs LIKE LINE OF lt_profs.



    DATA: lt_teams TYPE uje_t_team.

    DATA: ls_teams LIKE LINE OF lt_teams.



    DATA: lt_users TYPE uje_t_user_id.

    DATA: ls_users LIKE LINE OF lt_users.



    DATA: ls_users_asin TYPE uje_s_api_user_id.

    DATA: ls_teams_asin TYPE uje_s_api_team_id.

    DATA: ls_teams_list LIKE LINE OF lt_teams_list.



    DATA: lv_last_profile TYPE uj_profile_id.

    DATA: lv_message TYPE uj0_s_message-message.



* Upload file

    lt_strtab = lcl_application=>upload( p_file ).



* Rip import file into internal table

    LOOP AT lt_strtab INTO ls_strtab.

      CLEAR ls_input.

      SPLIT ls_strtab AT lcl_application=>lv_delimiter INTO ls_input-identifier

                                  ls_input-profile

                                  ls_input-id.

      APPEND ls_input TO lt_input.

    ENDLOOP.



* Build profile table containing all associated data

    SORT lt_input STABLE ASCENDING BY profile identifier id.



    LOOP AT lt_input INTO ls_input.



      IF ls_input-profile <> lv_last_profile

          AND lv_last_profile IS NOT INITIAL.

        APPEND ls_task_profile TO lt_task_profile.

        CLEAR ls_task_profile.

      ENDIF.



      IF lcl_application=>tprofile_is_valid( ls_input-profile ) = abap_false.

        CONCATENATE 'Profile' ls_input-profile 'does not yet exist.'

                    'No task profile assigments done.'

                       INTO lv_message SEPARATED BY space.

        add_message_to_message_table( i_msgid = `00` i_msgty = `E` i_msgno = `001`

                                    i_message = lv_message ).

      ENDIF.



      CASE ls_input-identifier.



        WHEN 'T'.

          IF lcl_application=>team_is_valid( ls_input-id ) = abap_false.

            CONCATENATE 'Team' ls_input-id 'does not yet exist.'

                        'No task profile assigments done.'

                          INTO lv_message SEPARATED BY space.

            add_message_to_message_table( i_msgid = `00` i_msgty = `E` i_msgno = `001`

                                        i_message = lv_message ).

          ENDIF.

          ls_task_profile-profile-profile_id  = ls_input-profile.

          APPEND ls_input-id TO ls_task_profile-teams_asin.





        WHEN 'U'.

          IF lcl_application=>user_is_valid( ls_input-id ) = abap_false.

            CONCATENATE 'User' ls_input-id 'does not yet exist.'

                        'No task profile assigments done.'

                           INTO lv_message SEPARATED BY space.

            add_message_to_message_table( i_msgid = `00` i_msgty = `E` i_msgno = `001`

                                        i_message = lv_message ).

          ENDIF.

          ls_task_profile-profile-profile_id  = ls_input-profile.

          APPEND ls_input-id TO ls_task_profile-users_asin.

      ENDCASE.



      lv_last_profile = ls_input-profile.



      AT LAST.

        APPEND ls_task_profile TO lt_task_profile.

      ENDAT.



    ENDLOOP.



* If there are errors, render, and do not process anything

    IF lt_alv_messages IS NOT INITIAL.

      lcl_application=>render_alv( ).

      RETURN.

    ENDIF.



* UPdate teams and uses with the assignments.

    LOOP AT lt_task_profile INTO ls_task_profile.



* Assign users

      LOOP AT ls_task_profile-users_asin INTO ls_users_asin.



        CLEAR ls_users. REFRESH lt_users.

        ls_users = ls_users_asin-user_id.

        APPEND ls_users TO lt_users.



        CLEAR ls_profs. REFRESH lt_profs.

        ls_profs-profile_id = ls_task_profile-profile-profile_id.

        ls_profs-action = 'I'.

        APPEND ls_profs TO lt_profs.



        TRY.

            cl_uje_user=>update_users(

              EXPORTING i_appset_id = lcl_application=>lv_environment_id

                        it_users = lt_users

                        it_task_profs = lt_profs ).

            CONCATENATE 'User' ls_users_asin-user_id 'task profile assignments'

                        'have been updated successfully'

                           INTO lv_message SEPARATED BY space.

            add_message_to_message_table( i_msgid = `00` i_msgty = `S` i_msgno = `001`

                                          i_message = lv_message ).

          CATCH cx_uje_exception INTO lo_uje_exception.

            add_exception_to_message_table( lo_uje_exception ).

            CONCATENATE 'User' ls_users_asin-user_id 'task profile assignments'

                        'not updated due to error'

                           INTO lv_message SEPARATED BY space.

            add_message_to_message_table( i_msgid = `00` i_msgty = `E` i_msgno = `001`

                                          i_message = lv_message ).

        ENDTRY.



      ENDLOOP.



* Assign teams

      LOOP AT ls_task_profile-teams_asin INTO ls_teams_asin.



        REFRESH lt_teams.

        READ TABLE lt_teams_list INTO ls_teams_list

                        WITH KEY team_id = ls_teams_asin-team_id.

        IF sy-subrc = 0.

          MOVE-CORRESPONDING ls_teams_list TO ls_teams.

          APPEND ls_teams TO lt_teams.

        ENDIF.



        CLEAR ls_profs. REFRESH lt_profs.

        ls_profs-profile_id = ls_task_profile-profile-profile_id.

        ls_profs-action = 'I'.

        APPEND ls_profs TO lt_profs.



        TRY.

            cl_uje_team=>update_teams(

                         EXPORTING i_appset_id = lcl_application=>lv_environment_id

                                   it_teams = lt_teams

                                   it_task_profs = lt_profs ).

            CONCATENATE 'Team' ls_teams_asin-team_id 'task profile assignments'

                       'have been updated successfully'

                          INTO lv_message SEPARATED BY space.

            add_message_to_message_table( i_msgid = `00` i_msgty = `S` i_msgno = `001`

                                          i_message = lv_message ).

          CATCH cx_uje_exception INTO lo_uje_exception.

            add_exception_to_message_table( lo_uje_exception ).

            CONCATENATE 'Team' ls_teams_asin-team_id 'task profile assignments'

                        'not updated due to error'

                           INTO lv_message SEPARATED BY space.

            add_message_to_message_table( i_msgid = `00` i_msgty = `E` i_msgno = `001`

                                          i_message = lv_message ).

        ENDTRY.

      ENDLOOP.



      CONCATENATE 'Task Profile' ls_task_profile-profile-profile_id

                  'assignments have been updated successfully'

                       INTO lv_message SEPARATED BY space.

      add_message_to_message_table( i_msgid = `00` i_msgty = `S` i_msgno = `001`

                                    i_message = lv_message ).



    ENDLOOP.



    lcl_application=>render_alv( ).



  ENDMETHOD.                    "import_tap_assign_from_file



  METHOD export_dap_assign_to_file.



    TYPES: BEGIN OF t_output,

            identifier TYPE char01, "Identifer, U or T

            profile TYPE uj_profile_id,

            id TYPE uj_user_id"User ID or Team ID

           END OF t_output.



    DATA: lt_output TYPE TABLE OF t_output.

    DATA: ls_output LIKE LINE OF lt_output.



    DATA: lt_users TYPE uje_t_user.

    DATA: ls_users LIKE LINE OF lt_users.



    DATA: lt_teams TYPE uje_t_team.

    DATA: ls_teams LIKE LINE OF lt_teams.



    DATA: ls_data_access_profiles TYPE uje_s_mbr_prof_app.



    DATA: lo_profile_dao TYPE REF TO cl_uje_profile_dao.



    CREATE OBJECT lo_profile_dao

      EXPORTING

        i_appset_id = lcl_application=>lv_environment_id.



    LOOP AT lcl_application=>lt_data_access_profiles INTO ls_data_access_profiles.



      REFRESH: lt_users, lt_teams.

      lo_profile_dao->get_details( EXPORTING i_profile_id = ls_data_access_profiles-profile_id

                                             i_profile_class = `MBR`

                                   IMPORTING et_users = lt_users

                                             et_teams = lt_teams ).



* Write User and Team assignments.

      LOOP AT lt_users INTO ls_users.

        CLEAR ls_output.

        ls_output-identifier = 'U'.

        ls_output-profile  = ls_data_access_profiles-profile_id.

        ls_output-id = ls_users-user_id.

        APPEND ls_output TO lt_output.

      ENDLOOP.



      LOOP AT lt_teams INTO ls_teams.

        CLEAR ls_output.

        ls_output-identifier = 'T'.

        ls_output-profile  = ls_data_access_profiles-profile_id.

        ls_output-id = ls_teams-team_id.

        APPEND ls_output TO lt_output.

      ENDLOOP.



    ENDLOOP.



* Download table

    lcl_application=>download( EXPORTING i_filepath = p_file

                                         it_datatab = lt_output ).



  ENDMETHOD.                    "export_map_assign_to_file



  METHOD import_dap_assign_from_file.



    TYPES: BEGIN OF t_input,

            identifier TYPE char01, " Row Identifer

            profile TYPE uj_profile_id,

            values TYPE string,

           END OF t_input.



    TYPES: BEGIN OF t_dataacc_profile,

            profile TYPE uje_s_profile,

            users_asin TYPE uje_t_api_user_id,

            teams_asin TYPE uje_t_api_team_id,

           END OF t_dataacc_profile.



    DATA: lt_dataacc_profile TYPE TABLE OF t_dataacc_profile.

    DATA: ls_dataacc_profile LIKE LINE OF lt_dataacc_profile.



    DATA: lv_last_profile TYPE uj_profile_id.



    DATA: lt_dataaccess TYPE uje_t_memaccess.

    DATA: ls_dataaccess LIKE LINE OF lt_dataaccess.



    DATA: lt_strtab TYPE stringtab.

    DATA: ls_strtab LIKE LINE OF lt_strtab.



    DATA: lt_input TYPE TABLE OF t_input.

    DATA: ls_input LIKE LINE OF lt_input.



    DATA: lt_profs TYPE uje_t_profile_action.

    DATA: ls_profs LIKE LINE OF lt_profs.



    DATA: lt_teams TYPE uje_t_team.

    DATA: ls_teams LIKE LINE OF lt_teams.



    DATA: lt_users TYPE uje_t_user_id.

    DATA: ls_users LIKE LINE OF lt_users.



    DATA: ls_users_asin TYPE uje_s_api_user_id.

    DATA: ls_teams_asin TYPE uje_s_api_team_id.

    DATA: ls_teams_list LIKE LINE OF lt_teams_list.



    DATA: lv_message TYPE uj0_s_message-message.



* Upload file

    lt_strtab = lcl_application=>upload( p_file ).



* Rip import file into internal table

    LOOP AT lt_strtab INTO ls_strtab.

      CLEAR ls_input.

      SPLIT ls_strtab AT lcl_application=>lv_delimiter INTO ls_input-identifier

                                  ls_input-profile

                                  ls_input-values.

      APPEND ls_input TO lt_input.

    ENDLOOP.



* Build profile table containing all associated data

    SORT lt_input STABLE ASCENDING BY profile identifier values.



    LOOP AT lt_input INTO ls_input.



      IF ls_input-profile <> lv_last_profile

          AND lv_last_profile IS NOT INITIAL.

        APPEND ls_dataacc_profile TO lt_dataacc_profile.

        CLEAR ls_dataacc_profile.

      ENDIF.



* Based on record identifier

      CASE ls_input-identifier.

        WHEN 'U'" Users Assignments

          ls_users_asin  = ls_input-values.

          IF lcl_application=>user_is_valid( ls_users_asin-user_id ) = abap_false.

            CONCATENATE 'User' ls_users_asin  'does not exist.'

                        'No data access profile updates done.'

                            INTO lv_message SEPARATED BY space.

            add_message_to_message_table( i_msgid = `00` i_msgty = `E` i_msgno = `001`

                                          i_message = lv_message ).

          ENDIF.

          ls_dataacc_profile-profile-profile_id = ls_input-profile.

          APPEND ls_users_asin  TO ls_dataacc_profile-users_asin.

        WHEN 'T'" Team Assignments

          ls_teams_asin  = ls_input-values.

          IF lcl_application=>team_is_valid( ls_teams_asin-team_id ) = abap_false.

            CONCATENATE 'Team' ls_teams_asin 'does not exist.'

                        'No data access profile updates done.'

                            INTO lv_message SEPARATED BY space.

            add_message_to_message_table( i_msgid = `00` i_msgty = `E` i_msgno = `001`

                                          i_message = lv_message ).

          ENDIF.

          ls_dataacc_profile-profile-profile_id = ls_input-profile.

          APPEND ls_teams_asin  TO ls_dataacc_profile-teams_asin.

      ENDCASE.



      lv_last_profile = ls_input-profile.



      AT LAST.

        APPEND ls_dataacc_profile TO lt_dataacc_profile.

      ENDAT.



    ENDLOOP.



* If any message during check, then render now, and do not process anything.

    IF lt_alv_messages IS NOT INITIAL.

      lcl_application=>render_alv( ).

      RETURN.

    ENDIF.



* Now for each profile, call API to create/update

    LOOP AT lt_dataacc_profile INTO ls_dataacc_profile.



* Assign users

      LOOP AT ls_dataacc_profile-users_asin INTO ls_users_asin.



        CLEAR ls_users. REFRESH lt_users.

        ls_users = ls_users_asin-user_id.

        APPEND ls_users TO lt_users.



        CLEAR ls_profs. REFRESH lt_profs.

        ls_profs-profile_id = ls_dataacc_profile-profile-profile_id.

        ls_profs-action = 'I'.

        APPEND ls_profs TO lt_profs.



        TRY.

            cl_uje_user=>update_users(

              EXPORTING i_appset_id = lcl_application=>lv_environment_id

                        it_users = lt_users

                        it_mbr_profs = lt_profs ).

            CONCATENATE 'User' ls_users_asin-user_id 'data access profile assignments'

                        'have been updated successfully'

                           INTO lv_message SEPARATED BY space.

            add_message_to_message_table( i_msgid = `00` i_msgty = `S` i_msgno = `001`

                                          i_message = lv_message ).

          CATCH cx_uje_exception INTO lo_uje_exception.

            add_exception_to_message_table( lo_uje_exception ).

            CONCATENATE 'User' ls_users_asin-user_id 'data access profile assignments'

                        'not updated due to error'

                           INTO lv_message SEPARATED BY space.

            add_message_to_message_table( i_msgid = `00` i_msgty = `E` i_msgno = `001`

                                          i_message = lv_message ).

        ENDTRY.



      ENDLOOP.



* Assign teams

      LOOP AT ls_dataacc_profile-teams_asin INTO ls_teams_asin.



        REFRESH lt_teams.

        READ TABLE lt_teams_list INTO ls_teams_list

                        WITH KEY team_id = ls_teams_asin-team_id.

        IF sy-subrc = 0.

          MOVE-CORRESPONDING ls_teams_list TO ls_teams.

          APPEND ls_teams TO lt_teams.

        ENDIF.



        CLEAR ls_profs. REFRESH lt_profs.

        ls_profs-profile_id = ls_dataacc_profile-profile-profile_id.

        ls_profs-action = 'I'.

        APPEND ls_profs TO lt_profs.



        TRY.

            cl_uje_team=>update_teams(

                         EXPORTING i_appset_id = lcl_application=>lv_environment_id

                                   it_teams = lt_teams

                                   it_mbr_profs = lt_profs ).

            CONCATENATE 'Team' ls_teams_asin-team_id 'data access profile assignments'

                        'have been updated successfully'

                           INTO lv_message SEPARATED BY space.

            add_message_to_message_table( i_msgid = `00` i_msgty = `S` i_msgno = `001`

                                          i_message = lv_message ).

          CATCH cx_uje_exception INTO lo_uje_exception.

            add_exception_to_message_table( lo_uje_exception ).

            CONCATENATE 'Team' ls_teams_asin-team_id 'data access profile assignments'

                        'not updated due to error'

                           INTO lv_message SEPARATED BY space.

            add_message_to_message_table( i_msgid = `00` i_msgty = `E` i_msgno = `001`

                                          i_message = lv_message ).

        ENDTRY.



      ENDLOOP.



      CONCATENATE 'Data Access Profile' ls_dataacc_profile-profile-profile_id

                  'has been updated successfully'

                      INTO lv_message SEPARATED BY space.

      add_message_to_message_table( i_msgid = `00` i_msgty = `S` i_msgno = `001`

                                    i_message = lv_message ).



    ENDLOOP.



* Display ALV

    lcl_application=>render_alv( ).



  ENDMETHOD.                    "import_map_assign_from_file



  METHOD set_global_context.



    DATA: ls_user  TYPE uj0_s_user.

    DATA: lv_value TYPE uj_string.



    DATA: lo_srv_mgr_dao TYPE REF TO cl_uja3_svrmgr_dao.



* GEt the system admin user id

    CREATE OBJECT lo_srv_mgr_dao.

    lo_srv_mgr_dao->read_sysadmin_id( IMPORTING e_sysadmin_id = lv_value ).

    ls_user-user_id = lv_value.



* Set the context

    TRY.

        cl_uj_context=>set_cur_context(

                        EXPORTING  i_appset_id = lcl_application=>lv_environment_id

                                   is_user     = ls_user ).

      CATCH cx_uj_obj_not_found .

    ENDTRY.



* Get it

    lo_context = cl_uj_context=>get_cur_context( ).

* Set user to system admin

    lo_context->switch_to_srvadmin( ).



  ENDMETHOD.                    "set_global_context



  METHOD set_delimiter_listbox.



* set delimiter listbox.

    DATA: lt_vrm_values TYPE vrm_values.

    DATA: ls_vrm_values LIKE LINE OF lt_vrm_values.

    DATA: lv_name TYPE vrm_id  VALUE 'P_DELMT'.



    REFRESH lt_vrm_values.



    ls_vrm_values-key = lcl_application=>lc_comma.

    ls_vrm_values-text = 'Comma'.

    APPEND ls_vrm_values TO lt_vrm_values.



    ls_vrm_values-key = lcl_application=>lc_tab.

    ls_vrm_values-text = 'Tab'.

    APPEND ls_vrm_values TO lt_vrm_values.



    ls_vrm_values-key = lcl_application=>lc_pipe.

    ls_vrm_values-text = 'Pipe'.

    APPEND ls_vrm_values TO lt_vrm_values.



    CALL FUNCTION 'VRM_SET_VALUES'

      EXPORTING

        id     = lv_name

        values = lt_vrm_values.



  ENDMETHOD.                    "set_delimiter_listbox



  METHOD set_delimiter.



    IF p_delmt = lcl_application=>lc_tab.

      lcl_application=>lv_delimiter = cl_abap_char_utilities=>horizontal_tab.

    ELSE.

      lcl_application=>lv_delimiter = p_delmt.

    ENDIF.



  ENDMETHOD.                    "set_delimiter



  METHOD render_alv.



    TYPE-POOLS: icon.



    TYPES: BEGIN OF t_alv,

            icon    TYPE icon-id,

            msgid   TYPE uj0_s_message-msgid,

            msgty   TYPE uj0_s_message-msgty,

            msgno   TYPE uj0_s_message-msgno,

            message TYPE uj0_s_message-message,

           END OF t_alv.



    DATA: lt_alv TYPE TABLE OF t_alv.

    DATA: lo_table     TYPE REF TO cl_salv_table.

    DATA: lo_columns   TYPE REF TO cl_salv_columns_table.

    DATA: lo_column    TYPE REF TO cl_salv_column_table.

    DATA: lo_functions TYPE REF TO cl_salv_functions.



    FIELD-SYMBOLS: <ls_alv> LIKE LINE OF lt_alv,

                   <ls_alv_messages> LIKE LINE OF lt_alv_messages.



    IF lt_alv_messages IS INITIAL.

      RETURN.

    ENDIF.



* Convert messages from API to ALV output

    LOOP AT lt_alv_messages ASSIGNING <ls_alv_messages>.

      APPEND INITIAL LINE TO lt_alv ASSIGNING <ls_alv>.

      MOVE-CORRESPONDING <ls_alv_messages> TO <ls_alv>.

      CASE <ls_alv>-msgty.

        WHEN 'E'. WRITE icon_message_error_small AS ICON TO <ls_alv>-icon.

        WHEN 'W'. WRITE icon_message_warning_small AS ICON TO <ls_alv>-icon.

        WHEN 'I'. WRITE icon_message_information_small  AS ICON TO <ls_alv>-icon.

        WHEN 'S'. WRITE icon_checked AS ICON TO <ls_alv>-icon.

      ENDCASE.

    ENDLOOP.



* Show messages

    TRY.

        cl_salv_table=>factory( IMPORTING r_salv_table  = lo_table

                                 CHANGING t_table       = lt_alv ).

      CATCH cx_salv_msg.

    ENDTRY.



    lo_functions = lo_table->get_functions( ).

    lo_functions->set_all( abap_true ).



    TRY.

        lo_columns = lo_table->get_columns( ).

        lo_column ?= lo_columns->get_column( 'ICON' ).

        lo_column->set_icon( abap_true ).

        lo_column ?= lo_columns->get_column( 'MSGNO' ).

        lo_column->set_leading_zero( abap_true ).

      CATCH cx_salv_not_found.

    ENDTRY.



    lo_table->display( ).



  ENDMETHOD.                    "render_alv



  METHOD get_environment_data.



    DATA: ls_uja_appl_info TYPE uja_s_appl_info.

    DATA: lt_uja_appl_dim TYPE uja_t_appl_dim.

    DATA: ls_uja_appl_dim LIKE LINE OF lt_uja_appl_dim.



    DATA: ls_members LIKE LINE OF lt_members.

    DATA: ls_appl_dim  LIKE LINE OF lt_appl_dim.



    DATA: lt_appl_list TYPE uja_t_appl_id.

    DATA: ls_appl_list LIKE LINE OF lt_appl_list.



    DATA: lo_appset_dao TYPE REF TO cl_uja_appset_dao.

    DATA: lo_application_dao TYPE REF TO cl_uja_application_dao.

    DATA: lo_dim TYPE REF TO cl_uja_dim.

    DATA: lo_data_access_profile_mgr TYPE REF TO cl_uje_profile_memaccess.



    DATA: lt_member_list TYPE uja_t_dim_member.

    DATA: ls_member_list LIKE LINE OF lt_member_list.



    DATA: lv_message TYPE uj0_s_message-message.



    lcl_application=>lv_environment_id  i_environment_id.



    TRY.



* Get the appset info, need the prefix

        CREATE OBJECT lo_appset_dao

          EXPORTING

            i_appset_id = lcl_application=>lv_environment_id.



        lo_appset_dao->get_appset_info(

              EXPORTING

                  i_appset_id    = lcl_application=>lv_environment_id

              IMPORTING

                  es_appset_info = lcl_application=>ls_environment_info ).



* Get the list of applications for this appset, need the application prefixes

        lo_appset_dao->get_appl_list(

              IMPORTING

                  et_appl_list = lt_appl_list ).



      CATCH cx_uj_db_error.

* Do not raise exception here

    ENDTRY.



* Check environment to make sure it is valid

    IF lcl_application=>ls_environment_info IS INITIAL.

      CONCATENATE 'Environment' lcl_application=>lv_environment_id 'does not exist.'

                  INTO lv_message SEPARATED BY space.

      add_message_to_message_table( i_msgid = `00` i_msgty = `E` i_msgno = `001`

                                    i_message = lv_message ).

      lcl_application=>render_alv( ).

      RAISE environment_not_found .

    ENDIF.



    lcl_application=>set_global_context( ).



* Loop applications, get application info, add to internal table

    LOOP AT lt_appl_list INTO ls_appl_list.



      TRY.



          CREATE OBJECT lo_application_dao

            EXPORTING

              i_appset_id = lcl_application=>lv_environment_id.



          lo_application_dao->get_application_info(

                EXPORTING

                  i_application_id = ls_appl_list

                IMPORTING

                  es_appl_info = ls_uja_appl_info ).



          APPEND ls_uja_appl_info TO lcl_application=>lt_appl_info.



* Get dimension list for each application

          lo_application_dao->get_dim_list(

                 EXPORTING

                   i_application_id = ls_appl_list

                 IMPORTING

                   et_appl_dim = lt_uja_appl_dim ).

          LOOP AT lt_uja_appl_dim INTO ls_uja_appl_dim.

            ls_appl_dim-appl_id = ls_appl_list.

            ls_appl_dim-dimension = ls_uja_appl_dim-dimension.

            COLLECT ls_appl_dim INTO lcl_application=>lt_appl_dim.

          ENDLOOP.



* Get members for each dimension

          LOOP AT lt_uja_appl_dim INTO ls_uja_appl_dim.

            CREATE OBJECT lo_dim

              EXPORTING

                i_appset_id = lcl_application=>lv_environment_id

                i_dimension = ls_uja_appl_dim-dimension.



            REFRESH lt_member_list.

            lo_dim->get_member_list(

                   IMPORTING

                        et_member lt_member_list  ).



            LOOP AT lt_member_list INTO ls_member_list.

              ls_members-appl_id = ls_appl_list.

              ls_members-dimension = ls_uja_appl_dim-dimension.

              ls_members-member = ls_member_list.

              COLLECT ls_members INTO lcl_application=>lt_members.

            ENDLOOP.



          ENDLOOP.



        CATCH: cx_uj_db_error, cx_uja_admin_error, cx_uj_static_check.

          lv_message = 'CX_UJ* Exception occured when reading environment metadata'.

          add_message_to_message_table( i_msgid = `00` i_msgty = `E` i_msgno = `001`

                                        i_message = lv_message ).

          lcl_application=>render_alv( ).

          RAISE uj_exception_error .

      ENDTRY.



    ENDLOOP.



    TRY.



        cl_uje_user=>get_all_user_details(

                   EXPORTING i_appset_id = lcl_application=>lv_environment_id

                   IMPORTING et_user_details = lcl_application=>lt_users_list ).



        cl_uje_team=>get_all_team_details(

                    EXPORTING i_appset_id = lcl_application=>lv_environment_id

                    IMPORTING et_teams = lcl_application=>lt_teams_list ).



        cl_uje_user=>get_all_user_details2(

                   EXPORTING i_appset_id = lcl_application=>lv_environment_id

                   IMPORTING et_users = lcl_application=>lt_user_detail ).



        cl_uje_profile_task=>get_all_task_profiles(

                    EXPORTING i_appset_id = lcl_application=>lv_environment_id

                    IMPORTING et_task_profiles = lt_task_profiles ).



      CATCH cx_uje_exception INTO lo_uje_exception.

        add_exception_to_message_table( lo_uje_exception ).

        lv_message = 'CX_UJE Exception occured when reading environment metadata'.

        add_message_to_message_table( i_msgid = `00` i_msgty = `E` i_msgno = `001`

                                      i_message = lv_message ).

        lcl_application=>render_alv( ).

        RAISE uj_exception_error .

    ENDTRY.



    TRY.



        CREATE OBJECT lo_data_access_profile_mgr

          EXPORTING

            i_appset_id = lcl_application=>lv_environment_id.



        lo_data_access_profile_mgr->get_all_mbr_profiles(

            EXPORTING

              i_appset_id     = lcl_application=>lv_environment_id

            IMPORTING

              et_mbr_profiles = lcl_application=>lt_data_access_profiles ).



      CATCH cx_uj_static_check.

        lv_message = 'CX_UJ* Exception occured when reading environment metadata'.

        add_message_to_message_table( i_msgid = `00` i_msgty = `E` i_msgno = `001`

                                      i_message = lv_message ).

        lcl_application=>render_alv( ).

        RAISE uj_exception_error .

    ENDTRY.



    CALL FUNCTION 'UJE_API_GET_ROLE_TSKASG'

      IMPORTING

        et_taskasgn = lcl_application=>lt_systasks.



  ENDMETHOD.                    "get_supporting_Data



  METHOD user_is_valid.



    READ TABLE lcl_application=>lt_users_list

              TRANSPORTING NO FIELDS

                         WITH KEY user_id = i_user_id.

    IF sy-subrc = 0.

      r_boolean = abap_true.

    ELSE.

      r_boolean = abap_false.

    ENDIF.



  ENDMETHOD.                    "user_id_valid



  METHOD team_is_valid.



    READ TABLE lcl_application=>lt_teams_list

               TRANSPORTING NO FIELDS

                          WITH KEY team_id = i_team_id.

    IF sy-subrc = 0.

      r_boolean = abap_true.

    ELSE.

      r_boolean = abap_false.

    ENDIF.



  ENDMETHOD.                    "team_id_valid



  METHOD tprofile_is_valid.



    READ TABLE lcl_application=>lt_task_profiles

               TRANSPORTING NO FIELDS

                        WITH KEY profile_id = i_profile_id.

    IF sy-subrc = 0.

      r_boolean = abap_true.

    ELSE.

      r_boolean = abap_false.

    ENDIF.



  ENDMETHOD.                    "tprofile_is_valid



  METHOD dprofile_is_valid.



    READ TABLE lcl_application=>lt_data_access_profiles

               TRANSPORTING NO FIELDS

                      WITH KEY profile_id = i_profile_id.

    IF sy-subrc = 0.

      r_boolean = abap_true.

    ELSE.

      r_boolean = abap_false.

    ENDIF.



  ENDMETHOD.                    "dprofile_is_valid



  METHOD task_is_valid.



    READ TABLE lcl_application=>lt_systasks

               TRANSPORTING NO FIELDS

                        WITH KEY task_id = i_task_id.

    IF sy-subrc = 0.

      r_boolean = abap_true.

    ELSE.

      r_boolean = abap_false.

    ENDIF.



  ENDMETHOD.                    "task_is_valid



  METHOD nw_user_exists.



    DATA: lv_bname TYPE bapibname-bapibname.

    DATA: ls_return TYPE bapiret2.



    lv_bname = i_user_id.

    CALL FUNCTION 'BAPI_USER_EXISTENCE_CHECK'

      EXPORTING

        username = lv_bname

      IMPORTING

        return   = ls_return.

    IF ls_return-number = '088'" Success message

      r_boolean = abap_true.

    ELSEIF ls_return-number = '124'" Error message

      r_boolean = abap_false.

    ENDIF.



  ENDMETHOD.                    "nw_user_exists



  METHOD get_bpc_component_version.



    DATA: ls_cvers TYPE cvers.



    CALL FUNCTION 'UPG_GET_SINGLE_COMPREL'

      EXPORTING

        iv_component = `CPMBPC`

      IMPORTING

        ev_version   = ls_cvers

      EXCEPTIONS

        OTHERS       = 4.

    IF sy-subrc = 0.

      lv_release = ls_cvers-release.

      lv_splevel = ls_cvers-extrelease.

    ENDIF.



  ENDMETHOD.                    "get_bpc_component_version



  METHOD check_bpc_component_is_valid.



    IF lcl_application=>lv_release <> '800'" BPC NW 10.0

      r_valid = abap_false.

    ELSE.

      r_valid = abap_true.

    ENDIF.



  ENDMETHOD.                    "check_BPC_component_version



  METHOD add_exception_to_message_table.



    FIELD-SYMBOLS: <ls_message> TYPE uj0_s_message.



    APPEND INITIAL LINE TO lt_alv_messages ASSIGNING <ls_message>.

    <ls_message>-msgid   = io_exception->if_t100_message~t100key-msgid.

    <ls_message>-msgty   = 'E'.

    <ls_message>-msgno   = io_exception->if_t100_message~t100key-msgno.

    <ls_message>-msgv1   = io_exception->if_t100_message~t100key-attr1.

    <ls_message>-msgv2   = io_exception->if_t100_message~t100key-attr2.

    <ls_message>-msgv3   = io_exception->if_t100_message~t100key-attr3.

    <ls_message>-msgv4   = io_exception->if_t100_message~t100key-attr4.

    <ls_message>-message = io_exception->get_text( ).



  ENDMETHOD.                    "add_exception_to_message_table



  METHOD add_message_to_message_table.



    FIELD-SYMBOLS: <ls_message> TYPE uj0_s_message.



    APPEND INITIAL LINE TO lt_alv_messages ASSIGNING <ls_message>.

    <ls_message>-msgid = i_msgid.

    <ls_message>-msgty = i_msgty.

    <ls_message>-msgno = i_msgno.

    <ls_message>-message = i_message.



  ENDMETHOD.                    "add_message_to_message_table



ENDCLASS.                    "lcl_application IMPLEMENTATION


Viewing all articles
Browse latest Browse all 8332

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>