ABAP – Utils

class ZCL_HR_UTILS definition
public
create public .

public section.

data GV_VARIA type XFLAG .
data GC_AGGREG type I value ‘1’ ##NO_TEXT.
data GC_EXPORT type I value ‘2’ ##NO_TEXT.
data GC_FILTER type I value ‘3’ ##NO_TEXT.
data GC_LAYOUT type I value ‘4’ ##NO_TEXT.
data GC_SORT type I value ‘5’ ##NO_TEXT.
data GC_SUBTOT type I value ‘6’ ##NO_TEXT.
data GC_GROUPV type I value ‘7’ ##NO_TEXT.
data GC_ALL type I value ‘8’ ##NO_TEXT.
data GC_DEFAULT type I value ‘9’ ##NO_TEXT.
data GC_LABEL type C value ‘L’ ##NO_TEXT.
data GC_FLOW type C value ‘F’ ##NO_TEXT.
data GC_HEADER type C value ‘H’ ##NO_TEXT.
data GT_ALV_HEADER type ZHR_TT_PA_UTILS_ALV_HEAD .
data GS_ALV_HEADER type ZHR_S_PA_UTILS_ALV_HEAD .
data GC_DOUBL type CHAR20 value ‘DOUBLE_CLICK’ ##NO_TEXT.
data GC_AFTCO type CHAR20 value ‘AFTER_SALV_FUNCTION’ ##NO_TEXT.
data GT_LOCEVT type ZHR_TT_PA_UTILS_LOCAL_EV .
data GS_LOCEVT type ZHR_S_PA_UTILS_LOCAL_EV .
data GC_TRUE type XFLAG value ‘X’ ##NO_TEXT.
data GC_FALSE type XFLAG value ” ##NO_TEXT.
protected section.

methods ADD_ALV_HEADER_LINE
importing
!CP_TYPE type C
!CP_ROW type I
!CP_COL type I
!CP_TEXT type TEXT200 .
methods BDC_DYNPRO
importing
!I_PROGRAM type ANY
!I_DYNPRO type ANY
changing
!CT_BDCDATA type BDCDATA_TAB .
methods BDC_FIELD
importing
!I_FNAM type ANY
!I_FVAL type ANY
changing
!CT_BDCDATA type BDCDATA_TAB .
methods BDC_INSERT
importing
!I_TCODE type TCODE
changing
!CT_BDCDATA type BDCDATA_TAB .
methods BDC_PROCESS_MENU
importing
!I_PERNR type PERNR_D
!I_INFTY type ANY
!I_SUBTY type ANY
!I_OKCODE type ANY
changing
!CT_BDCDATA type BDCDATA_TAB .
methods CREATE_ALV_OBJECT
changing
!CT_OUTPUT type TABLE
!CR_SALV type ref to CL_SALV_TABLE .
methods DISPLAY_ALV
changing
!CR_SALV type ref to CL_SALV_TABLE .
methods ENABLE_COLS
importing
!CP_CNAME type LVC_FNAME
!CP_ACTIV type ABAP_BOOL
changing
!CR_SALV type ref to CL_SALV_TABLE .
methods FIX_KEYCOL
importing
!CP_ACTIV type ABAP_BOOL
changing
!CR_SALV type ref to CL_SALV_TABLE .
methods GET_HIRE_FIRE
importing
!IP_PERNR type PERNR_D
!IP_BEGDA type BEGDA
!IP_ENDDA type ENDDA
changing
!CP_HIREDATE type HIREDATE
!CP_FIREDATE type FIREDATE .
methods GET_REF
importing
!I_DATA type ANY
returning
value(E_REF) type ref to DATA .
methods GET_SELECTED_LINES
changing
!CT_INDEX type SALV_T_ROW
!CR_SALV type ref to CL_SALV_TABLE .
methods HANDLE_EVENT_ON_AFTER_COMM
for event AFTER_SALV_FUNCTION of CL_SALV_EVENTS_TABLE
importing
!E_SALV_FUNCTION .
methods HANDLE_EVENT_ON_DOUBLE_CLICK
for event DOUBLE_CLICK of CL_SALV_EVENTS_TABLE
importing
!ROW
!COLUMN .
methods HANDLE_EVENT_ON_USER_COMMAND
for event ADDED_FUNCTION of CL_SALV_EVENTS
importing
!E_SALV_FUNCTION .
methods REGISTER_EVENT
changing
!CR_SALV type ref to CL_SALV_TABLE
!CR_EVENTS type ref to CL_SALV_EVENTS_TABLE .
methods SET_ALV_TITLE
importing
!IP_TITLE type LVC_TITLE
changing
!CR_SALV type ref to CL_SALV_TABLE .
methods SET_COLOR_COLUMN
importing
!IP_CNAME type LVC_FNAME optional
!IP_COL_CELL type LVC_FNAME optional
changing
!CR_SALV type ref to CL_SALV_TABLE .
methods SET_COLTEXTS
importing
!CP_CNAME type LVC_FNAME
!CP_TEXT type TEXT40
changing
!CR_SALV type ref to CL_SALV_TABLE .
methods SET_COL_COLOR
importing
!CP_CNAME type LVC_FNAME
!CP_COLOR type LVC_S_COLO
changing
!CR_SALV type ref to CL_SALV_TABLE .
methods SET_DECIMALS
importing
!CP_CNAME type LVC_FNAME
!CP_DECS type LVC_DECMLS
changing
!CR_SALV type ref to CL_SALV_TABLE .
methods SET_DEFAULT_LAYOUT
changing
!CR_SALV type ref to CL_SALV_TABLE .
methods SET_FILTER
importing
!CR_SALV type ref to CL_SALV_TABLE
!I_COLNAME type LVC_FNAME
!I_VALUE type SALV_DE_SELOPT_LOW
!I_OPTION type SALV_DE_SELOPT_OPTION
!I_SIGN type SALV_DE_SELOPT_SIGN .
methods SET_FUNCTIONS
importing
!CP_GROUP type I
!CP_ACTIV type ABAP_BOOL
changing
!CR_SALV type ref to CL_SALV_TABLE .
methods SET_KEYCOL
importing
!CP_CNAME type LVC_FNAME
!CP_ACTIV type ABAP_BOOL
changing
!CR_SALV type ref to CL_SALV_TABLE .
methods SET_LAYOUT_VARIANT
importing
!CS_VAR type SLIS_VARI
!IV_REPID type REPID optional
changing
!CR_SALV type ref to CL_SALV_TABLE .
methods SET_SELCOL
changing
!CR_SALV type ref to CL_SALV_TABLE .
methods SET_STATUS
importing
!CP_STATUS type PFSTATUS
changing
!CR_SALV type ref to CL_SALV_TABLE .
methods SET_SORT
importing
!CR_SALV type ref to CL_SALV_TABLE
!I_COLNAME type LVC_FNAME .
private section.
ENDCLASS.

CLASS ZCL_HR_UTILS IMPLEMENTATION.

* —————————————————————————————+
* | Instance Protected Method ZCL_HR_UTILS->ADD_ALV_HEADER_LINE
* +————————————————————————————————-+
* | [—>] CP_TYPE TYPE C
* | [—>] CP_ROW TYPE I
* | [—>] CP_COL TYPE I
* | [—>] CP_TEXT TYPE TEXT200
* +————————————————————————————–

METHOD ADD_ALV_HEADER_LINE.

gs_alv_header-type = cp_type.
gs_alv_header-col = cp_col.
gs_alv_header-row = cp_row.
gs_alv_header-text = cp_text.
APPEND gs_alv_header TO gt_alv_header.

ENDMETHOD.

* —————————————————————————————+
* | Instance Protected Method ZCL_HR_UTILS->BDC_DYNPRO
* +————————————————————————————————-+
* | [—>] I_PROGRAM TYPE ANY
* | [—>] I_DYNPRO TYPE ANY
* | [<–>] CT_BDCDATA TYPE BDCDATA_TAB
* +————————————————————————————–

METHOD BDC_DYNPRO.

* local variables
DATA: ls_bdcdata TYPE bdcdata.
* —

ls_bdcdata-program = i_program.
ls_bdcdata-dynpro = i_dynpro.
ls_bdcdata-dynbegin = ‘X’.

APPEND ls_bdcdata TO ct_bdcdata.

ENDMETHOD.

* —————————————————————————————+
* | Instance Protected Method ZCL_HR_UTILS->BDC_FIELD
* +————————————————————————————————-+
* | [—>] I_FNAM TYPE ANY
* | [—>] I_FVAL TYPE ANY
* | [<–>] CT_BDCDATA TYPE BDCDATA_TAB
* +————————————————————————————–

METHOD BDC_FIELD.

* local variables
DATA: ls_bdcdata TYPE bdcdata.
* —

ls_bdcdata-fnam = i_fnam.
ls_bdcdata-fval = i_fval.

APPEND ls_bdcdata TO ct_bdcdata.

ENDMETHOD.

* —————————————————————————————+
* | Instance Protected Method ZCL_HR_UTILS->BDC_INSERT
* +————————————————————————————————-+
* | [—>] I_TCODE TYPE TCODE
* | [<–>] CT_BDCDATA TYPE BDCDATA_TAB
* +————————————————————————————–

METHOD BDC_INSERT.

CALL FUNCTION ‘BDC_INSERT’
EXPORTING
tcode = i_tcode
TABLES
dynprotab = ct_bdcdata
EXCEPTIONS
internal_error = 1
not_open = 2
queue_error = 3
tcode_invalid = 4.
IF sy-subrc EQ 0.
ELSE. “#EC NEEDED
ENDIF.

ENDMETHOD.

* —————————————————————————————+
* | Instance Protected Method ZCL_HR_UTILS->BDC_PROCESS_MENU
* +————————————————————————————————-+
* | [—>] I_PERNR TYPE PERNR_D
* | [—>] I_INFTY TYPE ANY
* | [—>] I_SUBTY TYPE ANY
* | [—>] I_OKCODE TYPE ANY
* | [<–>] CT_BDCDATA TYPE BDCDATA_TAB
* +————————————————————————————–

METHOD BDC_PROCESS_MENU.

REFRESH ct_bdcdata.
CALL METHOD bdc_dynpro
EXPORTING
i_program = ‘SAPMP50A’
i_dynpro = ‘1000’
CHANGING
ct_bdcdata = ct_bdcdata.

CALL METHOD bdc_field
EXPORTING
i_fnam = ‘RP50G-PERNR’
i_fval = i_pernr
CHANGING
ct_bdcdata = ct_bdcdata.

CALL METHOD bdc_field
EXPORTING
i_fnam = ‘RP50G-CHOIC’
i_fval = i_infty
CHANGING
ct_bdcdata = ct_bdcdata.

CALL METHOD bdc_field
EXPORTING
i_fnam = ‘RP50G-SUBTY’
i_fval = i_subty
CHANGING
ct_bdcdata = ct_bdcdata.
CALL METHOD bdc_field
EXPORTING
i_fnam = ‘BDC_OKCODE’
i_fval = i_okcode
CHANGING
ct_bdcdata = ct_bdcdata.

ENDMETHOD.

* —————————————————————————————+
* | Instance Protected Method ZCL_HR_UTILS->CREATE_ALV_OBJECT
* +————————————————————————————————-+
* | [<–>] CT_OUTPUT TYPE TABLE
* | [<–>] CR_SALV TYPE REF TO CL_SALV_TABLE
* +————————————————————————————–

METHOD CREATE_ALV_OBJECT.

* local variables
DATA: lr_columns TYPE REF TO cl_salv_columns,
lr_layout TYPE REF TO cl_salv_layout,
lr_display TYPE REF TO cl_salv_display_settings,
ls_key TYPE salv_s_layout_key.
* —

TRY.
cl_salv_table=>factory(
IMPORTING
r_salv_table = cr_salv
CHANGING
t_table = ct_output ).
CATCH cx_salv_msg. “#EC NO_HANDLER
ENDTRY.

CHECK cr_salv IS NOT INITIAL.

* column width optimization
lr_columns = cr_salv->get_columns( ).
CALL METHOD lr_columns->set_optimize( abap_true ).

lr_display = cr_salv->get_display_settings( ).
lr_display->set_striped_pattern( cl_salv_display_settings=>true ).
*
lr_layout = cr_salv->get_layout( ).
ls_key-report = sy-cprog.
lr_layout->set_key( ls_key ).
lr_layout->set_default( abap_true ). ” allow preset

* init flag
CLEAR: gv_varia.

ENDMETHOD.

* —————————————————————————————+
* | Instance Protected Method ZCL_HR_UTILS->DISPLAY_ALV
* +————————————————————————————————-+
* | [<–>] CR_SALV TYPE REF TO CL_SALV_TABLE
* +————————————————————————————–

METHOD DISPLAY_ALV.

* local variables
DATA: lr_header TYPE REF TO cl_salv_form_layout_grid.
DATA: lr_label TYPE REF TO cl_salv_form_label.
DATA: lr_flow TYPE REF TO cl_salv_form_layout_flow.
DATA: lr_head TYPE REF TO cl_salv_form_header_info. “#EC NEEDED
* —

CHECK cr_salv IS NOT INITIAL.

* create header
IF lines( gt_alv_header ) IS NOT INITIAL.
CREATE OBJECT lr_header.
LOOP AT gt_alv_header INTO gs_alv_header.
CASE gs_alv_header-type.
WHEN gc_label.
lr_label = lr_header->create_label( row = gs_alv_header-row
column = gs_alv_header-col ).
lr_label->set_text( gs_alv_header-text ).
WHEN gc_flow.
lr_flow = lr_header->create_flow( row = gs_alv_header-row
column = gs_alv_header-col ).
lr_flow->create_text( text = gs_alv_header-text ).
WHEN gc_header.
lr_head = lr_header->create_header_information( row = gs_alv_header-row
column = gs_alv_header-col
text = gs_alv_header-text ).
ENDCASE.
ENDLOOP.
cr_salv->set_top_of_list( lr_header ).
cr_salv->set_top_of_list_print( lr_header ).
ENDIF.

* in case of no selected layout variant, take the default one
IF gv_varia IS INITIAL.
CALL METHOD set_default_layout
CHANGING
cr_salv = cr_salv.
ENDIF.

* output alv
cr_salv->display( ).

ENDMETHOD.

* —————————————————————————————+
* | Instance Protected Method ZCL_HR_UTILS->ENABLE_COLS
* +————————————————————————————————-+
* | [—>] CP_CNAME TYPE LVC_FNAME
* | [—>] CP_ACTIV TYPE ABAP_BOOL
* | [<–>] CR_SALV TYPE REF TO CL_SALV_TABLE
* +————————————————————————————–

METHOD ENABLE_COLS.

* local variables
DATA: lr_columns TYPE REF TO cl_salv_columns,
lr_column TYPE REF TO cl_salv_column,
lv_stext TYPE scrtext_s, “#EC NEEDED
lv_mtext TYPE scrtext_m, “#EC NEEDED
lv_ltext TYPE scrtext_l. “#EC NEEDED
* —

CHECK cr_salv IS NOT INITIAL.
lr_columns = cr_salv->get_columns( ).
TRY.
CALL METHOD lr_columns->get_column
EXPORTING
columnname = cp_cname
RECEIVING
value = lr_column.
CALL METHOD lr_column->set_visible( cp_activ ).
CATCH cx_salv_not_found. “#EC NO_HANDLER
ENDTRY.

ENDMETHOD.

* —————————————————————————————+
* | Instance Protected Method ZCL_HR_UTILS->FIX_KEYCOL
* +————————————————————————————————-+
* | [—>] CP_ACTIV TYPE ABAP_BOOL
* | [<–>] CR_SALV TYPE REF TO CL_SALV_TABLE
* +————————————————————————————–

METHOD FIX_KEYCOL.

* local variables
DATA: lr_columns TYPE REF TO cl_salv_columns_table.
* —

CHECK cr_salv IS NOT INITIAL.
lr_columns = cr_salv->get_columns( ).
TRY.
CALL METHOD lr_columns->set_key_fixation( cp_activ ).
CATCH cx_salv_not_found. “#EC NO_HANDLER
ENDTRY.

ENDMETHOD.

* —————————————————————————————+
* | Instance Protected Method ZCL_HR_UTILS->GET_HIRE_FIRE
* +————————————————————————————————-+
* | [—>] IP_PERNR TYPE PERNR_D
* | [—>] IP_BEGDA TYPE BEGDA
* | [—>] IP_ENDDA TYPE ENDDA
* | [<–>] CP_HIREDATE TYPE HIREDATE
* | [<–>] CP_FIREDATE TYPE FIREDATE
* +————————————————————————————–

METHOD GET_HIRE_FIRE.

* local variables
DATA: lt_dates TYPE TABLE OF hida,
ls_dates TYPE hida.
* —

REFRESH: lt_dates.
CALL FUNCTION ‘HR_ENTRY_DATE’
EXPORTING
persnr = ip_pernr
TABLES
entry_dates = lt_dates
EXCEPTIONS
entry_date_not_found = 1
pernr_not_assigned = 2
OTHERS = 3.
IF sy-subrc EQ 0.
ELSE. “#EC NEEDED
ENDIF.

SORT lt_dates BY begda DESCENDING.
LOOP AT lt_dates INTO ls_dates WHERE begda LE ip_endda AND
( ( stat2 EQ 3 AND
infty EQ ‘0000’ )
OR
infty EQ ‘0041’ ).
cp_hiredate = ls_dates-begda.
EXIT.
ENDLOOP.

REFRESH lt_dates.
CALL FUNCTION ‘HR_LEAVING_DATE’
EXPORTING
persnr = ip_pernr
TABLES
leaving_dates = lt_dates
EXCEPTIONS
leaving_date_not_found = 1
pernr_not_assigned = 2
OTHERS = 3.
IF sy-subrc EQ 0.
ELSE. “#EC NEEDED
ENDIF.

SORT lt_dates BY begda ASCENDING.
LOOP AT lt_dates INTO ls_dates WHERE begda GE ip_begda AND
( ( stat2 NE 3 AND
infty EQ ‘0000’ )
OR
infty EQ ‘0041’ ).
cp_firedate = ls_dates-begda.
EXIT.
ENDLOOP.

ENDMETHOD.

* —————————————————————————————+
* | Instance Protected Method ZCL_HR_UTILS->GET_REF
* +————————————————————————————————-+
* | [—>] I_DATA TYPE ANY
* | [<-()] E_REF TYPE REF TO DATA
* +————————————————————————————–

METHOD GET_REF.

GET REFERENCE OF i_data INTO e_ref.

ENDMETHOD.

* —————————————————————————————+
* | Instance Protected Method ZCL_HR_UTILS->GET_SELECTED_LINES
* +————————————————————————————————-+
* | [<–>] CT_INDEX TYPE SALV_T_ROW
* | [<–>] CR_SALV TYPE REF TO CL_SALV_TABLE
* +————————————————————————————–

METHOD GET_SELECTED_LINES.

* local variables
DATA: lr_selections TYPE REF TO cl_salv_selections.
* —

CHECK cr_salv IS NOT INITIAL.
CALL METHOD cr_salv->get_selections
RECEIVING
value = lr_selections.
CALL METHOD lr_selections->get_selected_rows
RECEIVING
value = ct_index.

ENDMETHOD.

* —————————————————————————————+
* | Instance Protected Method ZCL_HR_UTILS->HANDLE_EVENT_ON_AFTER_COMM
* +————————————————————————————————-+
* | [—>] E_SALV_FUNCTION LIKE
* +————————————————————————————–

METHOD HANDLE_EVENT_ON_AFTER_COMM.

READ TABLE gt_locevt INTO gs_locevt
WITH KEY event = gc_aftco.
IF sy-subrc IS INITIAL.
PERFORM (gs_locevt-form) IN PROGRAM (gs_locevt-repid)
USING e_salv_function.
ENDIF.

ENDMETHOD.

* —————————————————————————————+
* | Instance Protected Method ZCL_HR_UTILS->HANDLE_EVENT_ON_DOUBLE_CLICK
* +————————————————————————————————-+
* | [—>] ROW LIKE
* | [—>] COLUMN LIKE
* +————————————————————————————–

METHOD HANDLE_EVENT_ON_DOUBLE_CLICK.

READ TABLE gt_locevt INTO gs_locevt
WITH KEY event = gc_doubl.
IF sy-subrc IS INITIAL.
CALL METHOD (gs_locevt-form)
CHANGING
i_row = row
i_col = column.
ENDIF.

ENDMETHOD.

* —————————————————————————————+
* | Instance Protected Method ZCL_HR_UTILS->HANDLE_EVENT_ON_USER_COMMAND
* +————————————————————————————————-+
* | [—>] E_SALV_FUNCTION LIKE
* +————————————————————————————–

METHOD HANDLE_EVENT_ON_USER_COMMAND.

READ TABLE gt_locevt INTO gs_locevt
WITH KEY event = e_salv_function.
IF sy-subrc IS INITIAL.
PERFORM (gs_locevt-form) IN PROGRAM (gs_locevt-repid).
ENDIF.

ENDMETHOD.

* —————————————————————————————+
* | Instance Protected Method ZCL_HR_UTILS->REGISTER_EVENT
* +————————————————————————————————-+
* | [<–>] CR_SALV TYPE REF TO CL_SALV_TABLE
* | [<–>] CR_EVENTS TYPE REF TO CL_SALV_EVENTS_TABLE
* +————————————————————————————–

METHOD REGISTER_EVENT.

IF cr_events IS INITIAL.
cr_events = cr_salv->get_event( ).

SET HANDLER handle_event_on_double_click FOR cr_events.
SET HANDLER handle_event_on_user_command FOR cr_events.
SET HANDLER handle_event_on_after_comm FOR cr_events.
ENDIF.

ENDMETHOD.

* —————————————————————————————+
* | Instance Protected Method ZCL_HR_UTILS->SET_ALV_TITLE
* +————————————————————————————————-+
* | [—>] IP_TITLE TYPE LVC_TITLE
* | [<–>] CR_SALV TYPE REF TO CL_SALV_TABLE
* +————————————————————————————–

METHOD SET_ALV_TITLE.

* local variables
DATA: lr_display TYPE REF TO cl_salv_display_settings.
* —

lr_display = cr_salv->get_display_settings( ).
lr_display->set_list_header( ip_title ).

ENDMETHOD.

* —————————————————————————————+
* | Instance Protected Method ZCL_HR_UTILS->SET_COLOR_COLUMN
* +————————————————————————————————-+
* | [—>] IP_CNAME TYPE LVC_FNAME(optional)
* | [—>] IP_COL_CELL TYPE LVC_FNAME(optional)
* | [<–>] CR_SALV TYPE REF TO CL_SALV_TABLE
* +————————————————————————————–

METHOD SET_COLOR_COLUMN.

* local variables
DATA: lr_columns TYPE REF TO cl_salv_columns_list,
lr_column TYPE REF TO cl_salv_column. “#EC NEEDED
* —

CHECK cr_salv IS NOT INITIAL.
lr_columns = cr_salv->get_columns( ).

IF NOT ip_cname IS INITIAL.
* set single col color
TRY.
lr_columns->set_color_column( ip_cname ).
CATCH cx_salv_not_found. “#EC NO_HANDLER
CATCH cx_salv_data_error. “#EC NO_HANDLER
ENDTRY.
ELSE.
* set row colors
CHECK cr_salv IS NOT INITIAL.
lr_columns = cr_salv->get_columns( ).
TRY.
lr_columns->set_color_column( ip_col_cell ).
CATCH cx_salv_data_error. “#EC NO_HANDLER
ENDTRY.

ENDIF.

ENDMETHOD.

* —————————————————————————————+
* | Instance Protected Method ZCL_HR_UTILS->SET_COLTEXTS
* +————————————————————————————————-+
* | [—>] CP_CNAME TYPE LVC_FNAME
* | [—>] CP_TEXT TYPE TEXT40
* | [<–>] CR_SALV TYPE REF TO CL_SALV_TABLE
* +————————————————————————————–

METHOD SET_COLTEXTS.

* local variables
DATA: lr_columns TYPE REF TO cl_salv_columns,
lr_column TYPE REF TO cl_salv_column,
lv_stext TYPE scrtext_s,
lv_mtext TYPE scrtext_m,
lv_ltext TYPE scrtext_l,
lv_len TYPE i.
* —

CHECK cr_salv IS NOT INITIAL.
lr_columns = cr_salv->get_columns( ).
TRY.
CALL METHOD lr_columns->get_column
EXPORTING
columnname = cp_cname
RECEIVING
value = lr_column.
lv_stext = lv_mtext = lv_ltext = cp_text.
DESCRIBE FIELD cp_text LENGTH lv_len IN CHARACTER MODE.
IF lv_len LE 10.
CALL METHOD lr_column->set_short_text( lv_stext ).
ELSE.
CALL METHOD lr_column->set_short_text( ” ).
ENDIF.
IF lv_len LE 20.
CALL METHOD lr_column->set_medium_text( lv_mtext ).
ELSE.
CALL METHOD lr_column->set_medium_text( ” ).
ENDIF.
CALL METHOD lr_column->set_long_text( lv_ltext ) .
CATCH cx_salv_not_found. “#EC NO_HANDLER
ENDTRY.

ENDMETHOD.

* —————————————————————————————+
* | Instance Protected Method ZCL_HR_UTILS->SET_COL_COLOR
* +————————————————————————————————-+
* | [—>] CP_CNAME TYPE LVC_FNAME
* | [—>] CP_COLOR TYPE LVC_S_COLO
* | [<–>] CR_SALV TYPE REF TO CL_SALV_TABLE
* +————————————————————————————–

METHOD SET_COL_COLOR.

* local variables
DATA: lr_columns TYPE REF TO cl_salv_columns_table,
lr_column TYPE REF TO cl_salv_column_table.
* —

CHECK cr_salv IS NOT INITIAL.
lr_columns = cr_salv->get_columns( ).
TRY.
lr_column ?= lr_columns->get_column( cp_cname ).
CALL METHOD lr_column->set_color( cp_color ).
CATCH cx_salv_not_found. “#EC NO_HANDLER
ENDTRY.

ENDMETHOD.

* —————————————————————————————+
* | Instance Protected Method ZCL_HR_UTILS->SET_DECIMALS
* +————————————————————————————————-+
* | [—>] CP_CNAME TYPE LVC_FNAME
* | [—>] CP_DECS TYPE LVC_DECMLS
* | [<–>] CR_SALV TYPE REF TO CL_SALV_TABLE
* +————————————————————————————–

METHOD SET_DECIMALS.

* local variables
DATA: lr_columns TYPE REF TO cl_salv_columns,
lr_column TYPE REF TO cl_salv_column,
lv_stext TYPE scrtext_s, “#EC NEEDED
lv_mtext TYPE scrtext_m, “#EC NEEDED
lv_ltext TYPE scrtext_l. “#EC NEEDED
* —

CHECK cr_salv IS NOT INITIAL.
lr_columns = cr_salv->get_columns( ).
TRY.
CALL METHOD lr_columns->get_column
EXPORTING
columnname = cp_cname
RECEIVING
value = lr_column.
CALL METHOD lr_column->set_decimals( cp_decs ).
CATCH cx_salv_not_found. “#EC NO_HANDLER
ENDTRY.

ENDMETHOD.

* —————————————————————————————+
* | Instance Protected Method ZCL_HR_UTILS->SET_DEFAULT_LAYOUT
* +————————————————————————————————-+
* | [<–>] CR_SALV TYPE REF TO CL_SALV_TABLE
* +————————————————————————————–

METHOD SET_DEFAULT_LAYOUT.

* local variables
DATA: lr_layout TYPE REF TO cl_salv_layout,
ls_key TYPE salv_s_layout_key,
ls_layout TYPE salv_s_layout.
* —

CHECK cr_salv IS NOT INITIAL.
lr_layout = cr_salv->get_layout( ).
ls_key-report = sy-repid.
lr_layout->set_key( ls_key ).
* get default layout and use ist
ls_layout = lr_layout->get_default_layout( ).
lr_layout->set_initial_layout( ls_layout-layout ).

ENDMETHOD.

* —————————————————————————————+
* | Instance Protected Method ZCL_HR_UTILS->SET_FILTER
* +————————————————————————————————-+
* | [—>] CR_SALV TYPE REF TO CL_SALV_TABLE
* | [—>] I_COLNAME TYPE LVC_FNAME
* | [—>] I_VALUE TYPE SALV_DE_SELOPT_LOW
* | [—>] I_OPTION TYPE SALV_DE_SELOPT_OPTION
* | [—>] I_SIGN TYPE SALV_DE_SELOPT_SIGN
* +————————————————————————————–

METHOD SET_FILTER.

* local variables
DATA: lr_filters TYPE REF TO cl_salv_filters,
lr_filter TYPE REF TO cl_salv_filter.
* —

CHECK cr_salv IS NOT INITIAL.

lr_filters = cr_salv->get_filters( ).

CALL METHOD lr_filters->clear( ).

lr_filters->add_filter( columnname = i_colname
sign = i_sign
option = i_option
low = i_value ).

* lr_filter = lr_filters->get_filter( i_colname ).
*
* lr_filter->add_selopt( sign = i_sign
* option = i_option
* low = i_value ).

ENDMETHOD.

* —————————————————————————————+
* | Instance Protected Method ZCL_HR_UTILS->SET_FUNCTIONS
* +————————————————————————————————-+
* | [—>] CP_GROUP TYPE I
* | [—>] CP_ACTIV TYPE ABAP_BOOL
* | [<–>] CR_SALV TYPE REF TO CL_SALV_TABLE
* +————————————————————————————–

METHOD SET_FUNCTIONS.

* local variables
DATA: lr_functions TYPE REF TO cl_salv_functions_list.
* —

* 1 aggregation
* 2 export
* 3 filter
* 4 layout
* 5 sorting
* 6 sum
* 7 display
* 8 activate all function
* 9 default-buttons

CHECK cr_salv IS NOT INITIAL.
lr_functions = cr_salv->get_functions( ).
CASE cp_group.
WHEN gc_aggreg. lr_functions->set_group_aggregation( cp_activ ).
WHEN gc_export. lr_functions->set_group_export( cp_activ ).
WHEN gc_filter. lr_functions->set_group_filter( cp_activ ).
WHEN gc_layout. lr_functions->set_group_layout( cp_activ ).
WHEN gc_sort. lr_functions->set_group_sort( cp_activ ).
WHEN gc_subtot. lr_functions->set_group_subtotal( cp_activ ).
WHEN gc_groupv. lr_functions->set_group_view( cp_activ ).
WHEN gc_all. lr_functions->set_all( cp_activ ).
WHEN OTHERS. lr_functions->set_default( cp_activ ).
ENDCASE.

ENDMETHOD.

* —————————————————————————————+
* | Instance Protected Method ZCL_HR_UTILS->SET_KEYCOL
* +————————————————————————————————-+
* | [—>] CP_CNAME TYPE LVC_FNAME
* | [—>] CP_ACTIV TYPE ABAP_BOOL
* | [<–>] CR_SALV TYPE REF TO CL_SALV_TABLE
* +————————————————————————————–

METHOD SET_KEYCOL.

* local variables
DATA: lr_columns TYPE REF TO cl_salv_columns_table,
lr_column TYPE REF TO cl_salv_column_table.
* —

CHECK cr_salv IS NOT INITIAL.
lr_columns = cr_salv->get_columns( ).
TRY.
lr_column ?= lr_columns->get_column( cp_cname ).
CALL METHOD lr_column->set_key( cp_activ ).
CATCH cx_salv_not_found. “#EC NO_HANDLER
ENDTRY.

ENDMETHOD.

* —————————————————————————————+
* | Instance Protected Method ZCL_HR_UTILS->SET_LAYOUT_VARIANT
* +————————————————————————————————-+
* | [—>] CS_VAR TYPE SLIS_VARI
* | [—>] IV_REPID TYPE REPID(optional)
* | [<–>] CR_SALV TYPE REF TO CL_SALV_TABLE
* +————————————————————————————–

METHOD SET_LAYOUT_VARIANT.

* local variables
DATA: lr_layout TYPE REF TO cl_salv_layout,
ls_key TYPE salv_s_layout_key,
ls_alv_repid TYPE repid.

* —
IF iv_repid IS SUPPLIED.
ls_alv_repid = iv_repid.
ELSE.
ls_alv_repid = sy-repid.
ENDIF.

CHECK cr_salv IS NOT INITIAL.
lr_layout = cr_salv->get_layout( ).
ls_key-report = ls_alv_repid.
lr_layout->set_key( ls_key ).
lr_layout->set_save_restriction( if_salv_c_layout=>restrict_none ).
lr_layout->set_initial_layout( cs_var ).

gv_varia = ‘X’.

ENDMETHOD.

* —————————————————————————————+
* | Instance Protected Method ZCL_HR_UTILS->SET_SELCOL
* +————————————————————————————————-+
* | [<–>] CR_SALV TYPE REF TO CL_SALV_TABLE
* +————————————————————————————–

METHOD SET_SELCOL.

* local variables
DATA: lr_selections TYPE REF TO cl_salv_selections.
* —

CHECK cr_salv IS NOT INITIAL.
CALL METHOD cr_salv->get_selections
RECEIVING
value = lr_selections.
CALL METHOD lr_selections->set_selection_mode
EXPORTING
value = if_salv_c_selection_mode=>cell.

ENDMETHOD.

* —————————————————————————————+
* | Instance Protected Method ZCL_HR_UTILS->SET_SORT
* +————————————————————————————————-+
* | [—>] CR_SALV TYPE REF TO CL_SALV_TABLE
* | [—>] I_COLNAME TYPE LVC_FNAME
* +————————————————————————————–

METHOD set_sort.

* local variables
DATA: lr_sorts TYPE REF TO cl_salv_sorts.
* —

CHECK cr_salv IS NOT INITIAL.

lr_sorts = cr_salv->get_sorts( ).

lr_sorts->add_sort( i_colname ).

ENDMETHOD.

* —————————————————————————————+
* | Instance Protected Method ZCL_HR_UTILS->SET_STATUS
* +————————————————————————————————-+
* | [—>] CP_STATUS TYPE PFSTATUS
* | [<–>] CR_SALV TYPE REF TO CL_SALV_TABLE
* +————————————————————————————–

METHOD SET_STATUS.

cr_salv->set_screen_status(
pfstatus = cp_status
report = sy-repid
set_functions = cr_salv->c_functions_all ).

ENDMETHOD.
ENDCLASS.

ZHR_TT_PA_UTILS_ALV_HEAD

ZHR_S_PA_UTILS_ALV_HEAD

TYPE 1 Type CHAR 1 0
COL 1 Type INT4 10 0
ROW 1 Type INT4 10 0
TEXT 1 Type CHAR200 CHAR 200 0 Textfeld Laenge 200

ZHR_TT_PA_UTILS_LOCAL_EV

ZHR_S_PA_UTILS_LOCAL_EV

EVENT 1 Type CHAR20 CHAR 20 0 Char 20
FORM 1 Type CHAR100 CHAR 100 0 Charakter 100
REPID 1 Type SYREPID CHAR 40 0 ABAP-Programm, aktuelles Rahmenprogramm

Comments are closed