Fv60 sap transaction code for where used

Migration of Susses Factors

*&---------------------------------------------------------------------*
* & Report ZHR_SF_DATA
*&---------------------------------------------------------------------*
*  ___  _____  ___  _  _  ____  ____  ____  ###                 ###
* / __) (_) / __) () /) (_ \ (_ _) (_ _) ### = ooO ========= Ooo = ###
* ((__) (_) (((__) () ___ / _) (_) (### \ (o o) // ###
* \___)(_____)\___)(_)\_)(__)  (____) (__)  ----------(_)----------
*&---------------------------------------------------------------------*
******************************* MREGOTZ ****************** ********
************************************************************************
* & H PROGRAM NAME: ZHR_SF_DATA
* & H TRANSACTION CODE: ZHR_SF_DATA
* & H PROGRAM TITLE: Sap Successfactors DATA
* & H ZWECK: Gets various HR data for Successfactors
* & H AUTHOR: Regotz Michel
* & H DATE: 05/01/2017
* & H REQUIREMENTS: Swisscom specific
* & H SAP MODULE: HR-PY
*&H
* & H Company / Department: Swisscom AG
* & H Phone: +41 79 322 04 86 (mobile)
* & H E-Mail: [email protected]
*&H
************************************************************************
* & D Description: Simplifies comparison of succesfactors data
* & D ------------------------------------------------ --------------------
* & D Service: Easier comparison of succesfactors
* & D ------------------------------------------------ --------------------
* & D tables: zhr_sf_data
* & D ------------------------------------------------ --------------------
* & D processing: structure of an ALV
* & D Displays the ALV
************************************************************************
* & C Change history:
* & C ------------------------------------------------ --------------------
* & C Developer | Date | Description
* & C ------------------------------------------------ --------------------
* & C Michel Regotz | 05/16/2017 | Going live
* & C ------------------------------------------------ --------------------
* & C | |
* & C ------------------------------------------------ --------------------
* & C | |
* & C ------------------------------------------------ --------------------
* & C | |
************************************************************************
REPORT zhr_sf_data. "MESSAGE-ID zhr_lv_cockpit.
"Required for the GET PERAS command
NODES: person, group, peras.
"Table of the personnel number for GET PERAS
TABLES: pernr, pa0000.
"The following infotypes are used for data selection in the report
INFOTYPES: 0000, 0001, 0002, 0006, 0007, 0008, 0016, 0017, 0014, 0028, 0036, 0040, 0041, 0048, 0050, 0105, 0315.
"=======================================================================
"Data declaration
"=======================================================================
*-----------------------------------------------------------------------
* Start of data declarations for table ZHR_LV_COCKPIT
*-----------------------------------------------------------------------
* Get values
*-----------------------------------------------------------------------
DATA: gs_pa0000 TYPE pa0000.
DATA: gt_pa0000 TYPE TABLE OF pa0000.
DATA: gs_pa0001 TYPE pa0001.
DATA: gt_pa0001 TYPE TABLE OF pa0001.
DATA: gs_pa0002 TYPE pa0002.
DATA: gt_pa0002 TYPE TABLE OF pa0002.
DATA: gs_pa0006 TYPE pa0006.
DATA: gt_pa0006 TYPE TABLE OF pa0006.
DATA: gs_pa0008 TYPE pa0008.
DATA: gt_pa0008 TYPE TABLE OF pa0008.
DATA: gs_pa0028 TYPE pa0028.
DATA: gt_pa0028 TYPE TABLE OF pa0028.
DATA: gs_pa0040 TYPE pa0040.
DATA: gt_pa0040 TYPE TABLE OF pa0040.
DATA: gs_t526 TYPE t526.
DATA: gt_t526 TYPE TABLE OF t526.

DATA: gt_data_1 TYPE TABLE OF zhr_sf_data_1.
DATA: gs_data_1 TYPE zhr_sf_data_1.
DATA: gt_data_2 TYPE TABLE OF zhr_sf_data_2.
DATA: gs_data_2 TYPE zhr_sf_data_2.
DATA: gt_data_3 TYPE TABLE OF zhr_sf_data_3.
DATA: gs_data_3 TYPE zhr_sf_data_3.
DATA: gt_data_4 TYPE TABLE OF zhr_sf_data_4.
DATA: gs_data_4 TYPE zhr_sf_data_4.
DATA: gt_data_5 TYPE TABLE OF zhr_sf_data_5.
DATA: gs_data_5 TYPE zhr_sf_data_5.
DATA: gt_data_6 TYPE TABLE OF zhr_sf_data_6.
DATA: gs_data_6 TYPE zhr_sf_data_6.
DATA: gt_data_7 TYPE TABLE OF zhr_sf_data_7.
DATA: gs_data_7 TYPE zhr_sf_data_7.
DATA: gt_data_8 TYPE TABLE OF zhr_sf_data_8.
DATA: gs_data_8 TYPE zhr_sf_data_8.
DATA: gt_data_9 TYPE TABLE OF zhr_sf_data_9.
DATA: gs_data_9 TYPE zhr_sf_data_9.
DATA: gt_data_10 TYPE TABLE OF zhr_sf_data_10.
DATA: gs_data_10 TYPE zhr_sf_data_10.
DATA: gt_data_11 TYPE TABLE OF zhr_sf_data_11.
DATA: gs_data_11 TYPE zhr_sf_data_11.
DATA: gt_data_12 TYPE TABLE OF zhr_sf_data_12.
DATA: gs_data_12 TYPE zhr_sf_data_12.
DATA: gt_data_13 TYPE TABLE OF zhr_sf_data_13.
DATA: gs_data_13 TYPE zhr_sf_data_13.
DATA: gf_date TYPE sy-datum.
DATA: gt_result_tab TYPE TABLE OF swhactor,
gt_result_objec TYPE TABLE OF objec,
gt_result_struc TYPE TABLE OF struc,
gs_rs_tab TYPE swhactor,
gs_rs_objec TYPE objec,
gs_rs_struc TYPE struc,
gf_objid_p TYPE objid,
gf_objid TYPE objid,
gf_count TYPE i,
gf_vorge TYPE char40,
gf_vorge_pernr TYPE p_pernr,
gf_vorge_mail TYPE comm_id_long.
DATA: gf_sbjkt TYPE sbjkt.
"Table for the .CSV conversion
TYPES truxs_t_text_data (4096) TYPE c OCCURS 0.
DATA: outtab_csv TYPE truxs_t_text_data.
DATA: gs_outtab_csv LIKE LINE OF outtab_csv.
"Choose Big Version path to save CSV
DATA: ld_filename TYPE string,
ld_path TYPE string,
ld_fullpath TYPE string,
ld_result TYPE i,
gd_file TYPE c.
"=======================================================================
"Data declaration for ALV
"=======================================================================
*-----------------------------------------------------------------------
* Start of data declarations for the ALV
*-----------------------------------------------------------------------
* Copy this block to the data declarations of the ABAP program
* The handler definition for double-click is also a declaration
*-----------------------------------------------------------------------
DATA go_alv TYPE REF TO cl_salv_table.
DATA go_functions TYPE REF TO cl_salv_functions_list.
DATA: go_columns TYPE REF TO cl_salv_columns_table,
go_column TYPE REF TO cl_salv_column_table.
DATA: gs_color TYPE lvc_s_colo.
DATA go_display TYPE REF TO cl_salv_display_settings.
DATA go_events TYPE REF TO cl_salv_events_table.
DATA: go_layout TYPE REF TO cl_salv_layout,
gf_variant TYPE slis_vari,
gs_key TYPE salv_s_layout_key.
DATA: go_selections TYPE REF TO cl_salv_selections.
DATA: go_err_salv TYPE REF TO cx_salv_msg.
DATA: go_err_salv_exist TYPE REF TO cx_salv_existing.
DATA: go_err_wrong_call TYPE REF TO cx_salv_wrong_call.
DATA: gf_string TYPE string.
DATA: go_func TYPE REF TO cl_salv_functions_list.
"=======================================================================
"Selection screen for ALV
"=======================================================================
*-----------------------------------------------------------------------
* Selection
*-----------------------------------------------------------------------
"Selection
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-010.
PARAMETERS p1 RADIO BUTTON GROUP 1.
PARAMETERS p2 RADIO BUTTON GROUP 1.
PARAMETERS: p3 RADIOBUTTON GROUP 1.
PARAMETERS: p4 RADIOBUTTON GROUP 1.
PARAMETERS: p5 RADIO BUTTON GROUP 1.
PARAMETERS: p6 RADIO BUTTON GROUP 1.
PARAMETERS: p7 RADIOBUTTON GROUP 1.
PARAMETERS: p8 RADIOBUTTON GROUP 1.
PARAMETERS: p9 RADIOBUTTON GROUP 1.
PARAMETERS: p10 RADIO BUTTON GROUP 1.
PARAMETERS: p11 RADIOBUTTON GROUP 1.
PARAMETERS: p12 RADIO BUTTON GROUP 1.
PARAMETERS: p13 RADIOBUTTON GROUP 1.
* PARAMETERS: p13 RADIOBUTTON GROUP 1.
SELECTION-SCREEN END OF BLOCK b1.
"Download selection
SELECTION-SCREEN BEGIN OF BLOCK b2 WITH FRAME TITLE text-020.
"Here you can enter the XLS
PARAMETERS: p_file TYPE rlgrap-filename.
PARAMETERS: p_csv AS CHECKBOX.
PARAMETERS: p_ini AS CHECKBOX.
SELECTION-SCREEN END OF BLOCK b2.
"Description
SELECTION-SCREEN BEGIN OF BLOCK b3 WITH FRAME TITLE text-030.
SELECTION-SCREEN COMMENT 1 (75) text-031.
SELECTION-SCREEN END OF BLOCK b3.
*=======================================================================
* INITIALIZATION
* =========================================== pnpbegda ====== ========================
INITIALIZATION.
pnpbegda = sy-date.
p_csv = 'X'.
IF sy-uname = 'REGOTZ M'.
p_file = 'C: \ Users \ RegotzM \ Desktop \ D1_Sätze.CSV'.
ENDIF.
*=======================================================================
* START OF SELECTION
*=======================================================================
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
PERFORM f4_help.
*=======================================================================
* START OF SELECTION
*=======================================================================
START-OF-SELECTION.
"Date from the selection
gf_date = pn-endda.

GET peras.
"Logic
IF p1 = 'X'.
PERFORM read_data.
ELSEIF p2 = 'X'.
PERFORM read_data2.
ELSEIF p3 = 'X'.
PERFORM read_data3.
ELSEIF p4 = 'X'.
PERFORM read_data4.
ELSEIF p5 = 'X'.
PERFORM read_data5.
ELSEIF p6 = 'X'.
PERFORM read_data6.
ELSEIF p7 = 'X'.
PERFORM read_data7.
ELSEIF p8 = 'X'.
PERFORM read_data8.
ELSEIF p9 = 'X'.
PERFORM read_data9.
ELSEIF p10 = 'X'.
PERFORM read_data10.
ELSEIF p11 = 'X'.
PERFORM read_data11.
ELSEIF p12 = 'X'.
PERFORM read_data12.
ELSEIF p13 = 'X'.
PERFORM read_data13.
ENDIF.

END-OF-SELECTION.
*=======================================================================
* Output
*=======================================================================
IF p1 = 'X'.
PERFORM show_alv.
IF p_csv = 'X'.
PERFORM download_csv.
ENDIF.
ELSEIF p2 = 'X'.
PERFORM show_alv2.
IF p_csv = 'X'.
PERFORM download_csv2.
ENDIF.
ELSEIF p3 = 'X'.
PERFORM show_alv3.
IF p_csv = 'X'.
PERFORM download_csv3.
ENDIF.
ELSEIF p4 = 'X'.
PERFORM show_alv4.
IF p_csv = 'X'.
PERFORM download_csv4.
ENDIF.
ELSEIF p5 = 'X'.
PERFORM show_alv5.
IF p_csv = 'X'.
PERFORM download_csv5.
ENDIF.
ELSEIF p6 = 'X'.
PERFORM show_alv6.
IF p_csv = 'X'.
PERFORM download_csv6.
ENDIF.
ELSEIF p7 = 'X'.
PERFORM show_alv7.
IF p_csv = 'X'.
PERFORM download_csv7.
ENDIF.
ELSEIF p8 = 'X'.
PERFORM show_alv8.
IF p_csv = 'X'.
PERFORM download_csv8.
ENDIF.
ELSEIF p9 = 'X'.
PERFORM show_alv9.
IF p_csv = 'X'.
PERFORM download_csv9.
ENDIF.
ELSEIF p10 = 'X'.
PERFORM show_alv10.
IF p_csv = 'X'.
PERFORM download_csv10.
ENDIF.
ELSEIF p11 = 'X'.
PERFORM show_alv11.
IF p_csv = 'X'.
PERFORM download_csv11.
ENDIF.
ELSEIF p12 = 'X'.
PERFORM show_alv12.
IF p_csv = 'X'.
PERFORM download_csv12.
ENDIF.
ELSEIF p13 = 'X'.
PERFORM show_alv13.
IF p_csv = 'X'.
PERFORM download_csv13.
ENDIF.
ENDIF.

*=======================================================================
* FORM READ DATA
*=======================================================================
*=======================================================================
* Basic import
*=======================================================================
*&---------------------------------------------------------------------*
* & Form READ_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -> p1 text
* <- p2 text
*----------------------------------------------------------------------*
FORM read_data.
**************************************************************************
* IT0000
**************************************************************************
PROVIDE * FROM p0000 BETWEEN gf_date AND gf_date.
"*********************************************************************
"* Employment
"*********************************************************************
gs_data_1-status = p0000-stat2.
IF gs_data_1-status = '3'.
gs_data_1-status = 'ACTIVE'.
ELSE.
gs_data_1-status = 'INACTIVE'.
ENDIF.
ENDPROVIDE.
"***********************************************************************
"* PNR
"***********************************************************************
gs_data_1-pernr = pernr-pernr.
OVERLAY gs_data_1-pernr WITH '0000000000'.
"***********************************************************************
"* USERID
"***********************************************************************
SELECT SINGLE usrid FROM pa0105 INTO gs_data_1-userid
WHERE pernr = pernr-pernr
AND begda <= gf_date
AND endda> = gf_date
AND subty = 'Z003'.
**************************************************************************
* IT0002
**************************************************************************
PROVIDE * FROM p0002 BETWEEN gf_date AND gf_date.
"First name
gs_data_1-vorna = p0002-vorna.
"Surname
gs_data_1-nachn = p0002-nachn.
ENDPROVIDE.
"***********************************************************************
"* EMAIL
"***********************************************************************
SELECT SINGLE usrid_long FROM pa0105 INTO gs_data_1-mail
WHERE pernr = pernr-pernr
AND begda <= gf_date
AND endda> = gf_date
AND subty = '0010'.
**************************************************************************
* IT0001 Supervisor Manager
**************************************************************************
PROVIDE * FROM p0001 BETWEEN gf_date AND gf_date.
"Read organizational structure
CALL FUNCTION 'RH_STRUC_GET'
EXPORTING
act_otype = 'S'
act_objid = p0001-plans
act_wegid = 'S_UP' "also possible 'O-O-S-P' or 'A002'
act_plvar = '01'
act_begda = p0001-begda
act_endda = p0001-endda
TABLES
result_tab = gt_result_tab
result_objec = gt_result_objec
result_struc = gt_result_struc
EXCEPTIONS
no_plvar_found = 1
no_entry_found = 2
OTHERS = 3.
"Identify managers
IF sy-subrc = 0.
LOOP AT gt_result_struc INTO gs_rs_struc WHERE otype = 'O'.
"Check link B012 between organizational unit and position
IF gf_vorge IS INITIAL.
SELECT SINGLE sobid FROM hrp1001 INTO gf_objid
WHERE otype = 'O'
AND objid = gs_rs_struc-objid
AND plvar = '01'
AND subty = 'B012'
AND begda <= gf_date
AND endda> = gf_date
AND sclas = 'S'.
"Check link between position and person A002
IF gf_objid IS NOT INITIAL AND gf_objid <> p0001-plans ..
SELECT SINGLE sobid FROM hrp1001 INTO gf_objid_p
WHERE otype = 'S'
AND objid = gf_objid
AND plvar = '01'
AND subty = 'A008'
AND begda <= gf_date
AND endda> = gf_date
AND sclas = 'P'.
ENDIF.
IF gf_objid_p IS NOT INITIAL. "NEW
EXIT.
ENDIF.
ENDIF.
ENDLOOP.
ELSE.
"Don't do anything
ENDIF.
ENDPROVIDE.
gs_data_1-manager = gf_objid_p.
IF gf_objid_p IS INITIAL.
gs_data_1-manager = 'NO_MANAGER'.
ENDIF.
CLEAR: gt_result_tab, gt_result_objec, gt_result_struc,
gs_rs_tab, gs_rs_objec, gs_rs_struc,
gf_objid_p, gf_objid, gf_vorge, gf_vorge_pernr,
gf_vorge_mail.

"**************************************************************************
"* HR (clerk)
"**************************************************************************
PROVIDE * FROM p0001 BETWEEN gf_date AND gf_date.
SELECT SINGLE * FROM t526 INTO gs_t526
WHERE works = p0001-sbmod AND
sachx <= p0001-sachp.
IF gs_t526-usrid IS NOT INITIAL.
CLEAR: gs_data_1-hr.
SELECT SINGLE pernr FROM pa0105 INTO gs_data_1-hr
WHERE subty = 'Z003' AND
usrid = gs_t526-usrid AND
begda <= gf_date AND
endda> = gf_date.
IF gs_data_11-relay IS INITIAL.
gs_data_1-hr = gs_t526-sachn.
ENDIF.
ELSE.
gs_data_1-hr = gs_t526-sachn.
ENDIF.
CLEAR: gs_t526.
ENDPROVIDE.
"**************************************************************************
"* Time Zone
"**************************************************************************
gs_data_1-tzone = 'Europe / Zurich'.
"**************************************************************************
"* Hire date
"**************************************************************************
"***************************************************************************
"** IT0001
"***************************************************************************
* PROVIDE * FROM p0001 BETWEEN gf_date AND gf_date.
*    "**************************************************************************
* "* Hire Date
*    "**************************************************************************
* IF p_ini = 'X'.
* SELECT * FROM pa0000 INTO TABLE gt_pa0000
* WHERE pernr = pernr-pernr.
* SORT gt_pa0000 BY endda DESCENDING.
* LOOP AT gt_pa0000 INTO gs_pa0000.
* CASE gs_pa0000-massn.
* WHEN '01' OR '06' OR '51' OR '50' OR '20' OR '12' OR '13'.
* "Event Date
* CONCATENATE
* gs_pa0000-begda + 4 (2) '/'
* gs_pa0000-begda + 6 (2) '/'
* gs_pa0000-begda (4)
* INTO gs_data_1-hired.
* EXIT.
* WHEN OTHERS.
* CLEAR: gs_pa0000.
* ENDCASE.
* ENDLOOP.
* CLEAR: gs_pa0000.
* ELSE.
* SELECT SINGLE * FROM pa0001 INTO gs_pa0001
* WHERE pernr = pernr-pernr AND
* begda <= gf_date AND
* endda> = gf_date.
* CONCATENATE
* gs_pa0001-begda + 4 (2) '/'
* gs_pa0001-begda + 6 (2) '/'
* gs_pa0001-begda (4)
* INTO gs_data_1-hired.
* CLEAR: gs_pa0001.
* ENDIF.
* ENDPROVIDE.
* CLEAR: gs_pa0001, gt_pa0001, gt_pa0000, gs_pa0000.

CONCATENATE
gf_date + 6 (2) '/'
gf_date + 4 (2) '/'
gf_date (4)
INTO gs_data_1-hired.


"**************************************************************************
"* Default Local
"**************************************************************************
gs_data_1-zzhr_local = 'en_US'.
**************************************************************************
* Insert in table
**************************************************************************
APPEND gs_data_1 TO gt_data_1.
CLEAR gs_data_1.
END SHAPE. "READ_DATA

*=======================================================================
* FORM SHOW_ALV
*=======================================================================
*&---------------------------------------------------------------------*
* & Form show_alv
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM show_alv.
*-----------------------------------------------------------------------
* Start of ALV output
*-----------------------------------------------------------------------
* Copy this block to the end of the processing block
* of the ABAP program
*-----------------------------------------------------------------------
"**************************************************************************
"* Create an instance of the class cl_salv_table
"**************************************************************************
TRY.
cl_salv_table => factory (
EXPORTING list_display = if_salv_c_bool_sap => false
r_container = cl_gui_custom_container => default_screen
IMPORTING r_salv_table = go_alv
CHANGING t_table = gt_data_1).
CATCH cx_salv_msg INTO go_err_salv.
* Show mistakes
gf_string = go_err_salv-> get_text ().
MESSAGE gf_string TYPE 'E'.
ENDTRY.
"**************************************************************************
"* Activate optimal column width
"**************************************************************************
"Get instance for columns
go_columns = go_alv-> get_columns ().
"Optimize column width
go_columns-> set_optimize (abap_true). "just an 'X'
"**************************************************************************
"* Activate selection mode
"**************************************************************************
"Get an instance of the selection object
go_selections = go_alv-> get_selections ().
"Set selection mode
go_selections-> set_selection_mode (if_salv_c_selection_mode => row_column).
"**************************************************************************
"* Set all standard functions to active
"**************************************************************************
"Get instance for functions Function keys (sorting, filtering, Excel export, etc.)
go_functions = go_alv-> get_functions ().
"Activate all standard functions
go_functions-> set_all (abap_true). "just an 'X'
"**************************************************************************
"* Define all standard display options
"**************************************************************************
"Title and / or striped pattern
go_display = go_alv-> get_display_settings ().
"Title
go_display-> set_list_header (value = text-001).
"Stripe pattern
go_display-> set_striped_pattern (abap_true).
"***************************************************************************
"* Define all standard layout options
"***************************************************************************
"Get an instance of the layout get layout object
go_layout = go_alv-> get_layout ().
"set layout save restriction
"1. Set Layout Key .. Unique key identifies the Differenet ALVs
gs_key-report = sy-repid.
go_layout-> set_key (gs_key).
"2. Remove Save layout the restriction.
go_layout-> set_save_restriction (if_salv_c_layout => restrict_none).
"Store default layout set initial layout
gf_variant = '/ DEFAULT'.
go_layout-> set_initial_layout (gf_variant).
*  "***************************************************************************
* "* Incorporate double-click event.
*  "***************************************************************************
* "Read events and register handlers for double-click
* go_events = go_alv-> get_event ().
* SET HANDLER lcl_event_handler => on_double_click FOR go_events.
*  "**************************************************************************
* "* Extend the toolbar with your own functions
*  "**************************************************************************
* TRY.
* "Provide new function for the ALV
* go_functions-> add_function (
* name = 'NFUNC'
* icon = '@ L1 @' "Any ICON from table ICON
* text = 'ZHR_LV_COCKPIT_VIEW edit'
* tooltip = 'added function'
* position = if_salv_c_function_position => right_of_salv_functions).
* CATCH cx_salv_existing INTO go_err_salv_exist.
* " Show mistakes
* gf_string = go_err_salv_exist-> get_text ().
* MESSAGE gf_string TYPE 'E'.
* CATCH cx_salv_wrong_call INTO go_err_wrong_call.
* " Show mistakes
* gf_string = go_err_wrong_call-> get_text ().
* MESSAGE gf_string TYPE 'E'.
* ENDTRY.
"**************************************************************************
"* Register the event to handle the button click
"**************************************************************************
* "Get the object for the possible ALV events
* go_events = go_alv-> get_event ().
* "Create object for event handling ...
* CREATE OBJECT go_event_handler.
** EXPORTING
** ir_salv = go_alv
** it_cockpit = gt_cockpit.
*
* "... and register with the maintenance view call
* SET HANDLER go_event_handler-> handle_toolbar_click FOR go_events.
"**************************************************************************
"* Install traffic light
"*************************************************************************
* "Install traffic light
* "1. Get the lines
* go_columns = go_alv-> get_columns ().
* "2. Get say in which column a traffic light function should be stored.
* go_columns-> set_exception_column (value = 'LIGHT').
* TRY.
* go_column? = go_columns-> get_column ('LIGHT').
* go_column-> set_medium_text ('STATUS').
* go_column-> set_long_text ('STATUS').
* go_column-> set_short_text ('STATUS').
* CATCH cx_salv_not_found. "#EC NO_HANDLER
* ENDTRY.
"***************************************************************************
"* Register the event to handle the button click
"***************************************************************************
** Get the object for the possible ALV events
* go_events = go_alv-> get_event ().
** Create object for event handling ...
* CREATE OBJECT go_event_handler
* EXPORTING
* cr_salv = go_alv
* it_sflight = gt_sflight.
** ... and register with the ALV events
* SET HANDLER go_event_handler-> handle_toolbar_click FOR go_events.
"**************************************************************************
"* Trigger ALV display
"**************************************************************************
"Show list
go_alv-> display ().
"**************************************************************************
"* Extend the toolbar with your own functions. A container is required for this
"**************************************************************************
Call "carrier screen" for container (otherwise it will not find a container)
WRITE: space.

END SHAPE. "show_alv
*&---------------------------------------------------------------------*
* & Form download_csv
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM download_csv.
****************************************************************
* Convert data
****************************************************************
CALL FUNCTION 'SAP_CONVERT_TO_CSV_FORMAT'
EXPORTING
i_field_seperator = ';'
TABLES
i_tab_sap_data = gt_data_1
CHANGING
i_tab_converted_data = outtab_csv
EXCEPTIONS
conversion_failed = 1
OTHERS = 2.
IF sy-subrc <> 0.
* MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
* WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
WRITE: 'Error', sy-subrc, 'when converting to .CSV format!'.
ENDIF.
****************************************************************
* Save data
****************************************************************
DATA: l_filename TYPE string.
l_filename = p_file.
"Insert header
gs_outtab_csv = 'STATUS; USERID; USERNAME; FIRSTNAME; LASTNAME; EMAIL; MANAGER; HR; TIMEZONE; HIREDATE; DEFAULT_LOCALE'.
INSERT gs_outtab_csv INTO outtab_csv INDEX 1.
"Download
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
filename = l_filename
TABLES
data_tab = outtab_csv
EXCEPTIONS
OTHERS = 1.
IF sy-subrc <> 0.
* MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
* WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
WRITE: 'Error', sy-subrc, 'when saving the .CSV file!'.
ENDIF.
END SHAPE. "download_csv

*&---------------------------------------------------------------------*
* & Form f4_help
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM f4_help.
* Dialog screen for saving the data
CALL METHOD cl_gui_frontend_services => file_save_dialog
EXPORTING
* window_title = ''
default_extension = 'CSV'
default_file_name = 'D1_Sätze'
initial_directory = 'c: \ temp \'
CHANGING
filename = ld_filename
path = ld_path
fullpath = ld_fullpath
user_action = ld_result.
p_file = ld_fullpath.
END SHAPE. "f4_help
*=======================================================================
* Person info import
*=======================================================================
*&---------------------------------------------------------------------*
* & Form READ_DATA2
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -> p1 text
* <- p2 text
*----------------------------------------------------------------------*
FORM read_data2.
"***********************************************************************
"* PNR
"***********************************************************************
gs_data_2-pernr = pernr-pernr.
**************************************************************************
* IT0002
**************************************************************************
PROVIDE * FROM p0002 BETWEEN gf_date AND gf_date.
"*********************************************************************
"* Country, place, date of death
"*********************************************************************
CONCATENATE p0002-gbdat + 6 (2) '/' p0002-gbdat + 4 (2) '/' p0002-gbdat (4)
INTO gs_data_2-gbdat.
"gs_data_2-gblnd = p0002-gblnd.
SELECT SINGLE iso FROM zhr_sf_data_iso INTO gs_data_2-gblnd
WHERE country = p0002-gblnd.
* gs_data_2-gbort = p0002-gbort.
gs_data_2-death = ''.
ENDPROVIDE.
"***********************************************************************
"* Global PNR
"***********************************************************************
gs_data_2-gpernr = pernr-pernr.
**************************************************************************
* Insert in table
**************************************************************************
APPEND gs_data_2 TO gt_data_2.
CLEAR gs_data_2.
END SHAPE. "READ_DATA2
*&---------------------------------------------------------------------*
* & Form SHOW_ALV2
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -> p1 text
* <- p2 text
*----------------------------------------------------------------------*
FORM show_alv2.
*-----------------------------------------------------------------------
* Start of ALV output
*-----------------------------------------------------------------------
* Copy this block to the end of the processing block
* of the ABAP program
*-----------------------------------------------------------------------
"**************************************************************************
"* Create an instance of the class cl_salv_table
"**************************************************************************
TRY.
cl_salv_table => factory (
EXPORTING list_display = if_salv_c_bool_sap => false
r_container = cl_gui_custom_container => default_screen
IMPORTING r_salv_table = go_alv
CHANGING t_table = gt_data_2).
CATCH cx_salv_msg INTO go_err_salv.
* Show mistakes
gf_string = go_err_salv-> get_text ().
MESSAGE gf_string TYPE 'E'.
ENDTRY.
"**************************************************************************
"* Activate optimal column width
"**************************************************************************
"Get instance for columns
go_columns = go_alv-> get_columns ().
"Optimize column width
go_columns-> set_optimize (abap_true). "just an 'X'
"**************************************************************************
"* Activate selection mode
"**************************************************************************
"Get an instance of the selection object
go_selections = go_alv-> get_selections ().
"Set selection mode
go_selections-> set_selection_mode (if_salv_c_selection_mode => row_column).
"**************************************************************************
"* Set all standard functions to active
"**************************************************************************
"Get instance for functions Function keys (sorting, filtering, Excel export, etc.)
go_functions = go_alv-> get_functions ().
"Activate all standard functions
go_functions-> set_all (abap_true). "just an 'X'
"**************************************************************************
"* Define all standard display options
"**************************************************************************
"Title and / or striped pattern
go_display = go_alv-> get_display_settings ().
"Title
go_display-> set_list_header (value = text-001).
"Stripe pattern
go_display-> set_striped_pattern (abap_true).
"***************************************************************************
"* Define all standard layout options
"***************************************************************************
"Get an instance of the layout get layout object
go_layout = go_alv-> get_layout ().
"set layout save restriction
"1. Set Layout Key .. Unique key identifies the Differenet ALVs
gs_key-report = sy-repid.
go_layout-> set_key (gs_key).
"2. Remove Save layout the restriction.
go_layout-> set_save_restriction (if_salv_c_layout => restrict_none).
"Store default layout set initial layout
gf_variant = '/ DEFAULT'.
go_layout-> set_initial_layout (gf_variant).
*  "***************************************************************************
* "* Incorporate double-click event.
*  "***************************************************************************
* "Read events and register handlers for double-click
* go_events = go_alv-> get_event ().
* SET HANDLER lcl_event_handler => on_double_click FOR go_events.
*  "**************************************************************************
* "* Extend the toolbar with your own functions
*  "**************************************************************************
* TRY.
* "Provide new function for the ALV
* go_functions-> add_function (
* name = 'NFUNC'
* icon = '@ L1 @' "Any ICON from table ICON
* text = 'ZHR_LV_COCKPIT_VIEW edit'
* tooltip = 'added function'
* position = if_salv_c_function_position => right_of_salv_functions).
* CATCH cx_salv_existing INTO go_err_salv_exist.
* " Show mistakes
* gf_string = go_err_salv_exist-> get_text ().
* MESSAGE gf_string TYPE 'E'.
* CATCH cx_salv_wrong_call INTO go_err_wrong_call.
* " Show mistakes
* gf_string = go_err_wrong_call-> get_text ().
* MESSAGE gf_string TYPE 'E'.
* ENDTRY.
"**************************************************************************
"* Register the event to handle the button click
"**************************************************************************
* "Get the object for the possible ALV events
* go_events = go_alv-> get_event ().
* "Create object for event handling ...
* CREATE OBJECT go_event_handler.
** EXPORTING
** ir_salv = go_alv
** it_cockpit = gt_cockpit.
*
* "... and register with the maintenance view call
* SET HANDLER go_event_handler-> handle_toolbar_click FOR go_events.
"**************************************************************************
"* Install traffic light
"*************************************************************************
* "Install traffic light
* "1. Get the lines
* go_columns = go_alv-> get_columns ().