Useful Function Modules in SAP ABAP
1)
Pop
up Message as Screen with YES / No Buttons :
Code :
data: g_res(1) type c.
clear : g_res.
call function 'K_KKB_POPUP_RADIO2'
exporting
i_title = 'You want to Enter-New Reason Code?'
i_text1 = 'YES'
i_text2 = 'NO'
i_default = 'NO'
importing
i_result = g_res
exceptions
cancel = 1.
output :
2
) Information message as Displayed as Table ( List of Points we can display in
Screen ).
clear wa_tab.
wa_tab-text = 'Use of Create'.
append wa_tab to i_tab .
clear wa_tab.
wa_tab-text = '• To Insert the Records.'.
append wa_tab to i_tab .
call function 'POPUP_WITH_TABLE_DISPLAY_OK'
exporting
endpos_col = 100
endpos_row = 10
startpos_col = 2
startpos_row = 2 "6
titletext = text-001
* IMPORTING
* CHOISE =
tables
valuetab = i_tab
exceptions
break_off = 1
others = 2.
3 ) To get the Previous Month Date By
Passing Current Month Date
------------------------------------------------
call function 'FIRST_DAY_IN_PERIOD_GET'
l_edate type sy-datum ,
l_year type bkpf-gjahr ,
l_month type t009b-poper .
*& To get the Fiscal year's month start date
----------------------------------------------------
call function 'HR_E_NUM_OF_DAYS_OF_MONTH'
exporting
p_fecha = sy-datum
importing
number_of_days = lv_noday.
date = sy-datum
days = 1
months = 02
years = 00
signum = '-'
importing
calc_date = calc_date.
persk = ipsyst-persk
langu = sy-langu
IMPORTING
persk_text = lv_ptext.
TITEL = 'Information Message'
TEXTLINE1 = lv_mess "textline1
* TEXTLINE2 = ' '
START_COLUMN = 3
START_ROW = 6
.
13) & functionality to convert date from external to internal format
Example:
TRY.
CALL METHOD cl_abap_datfm=>conv_date_ext_to_int
EXPORTING
im_datext = wa_upload-valfr “Type Char 10
IMPORTING
ex_datint = date_out. “type d
* Catch all possible exceptions
CATCH
cx_abap_datfm_no_date cx_abap_datfm_invalid_date cx_abap_datfm_format_unknown cx_abap_datfm_ambiguous .
ENDTRY.
14) POPUP Message WITH Continue Button
15) Function module to Remove Junk / Strange Values from a String in sap ABAP
Data lv_string type string.
Clear :lv_string.
call function 'SCP_REPLACE_STRANGE_CHARS'
Code :
data: g_res(1) type c.
clear : g_res.
call function 'K_KKB_POPUP_RADIO2'
exporting
i_title = 'You want to Enter-New Reason Code?'
i_text1 = 'YES'
i_text2 = 'NO'
i_default = 'NO'
importing
i_result = g_res
exceptions
cancel = 1.
output :
types : begin of t_tab ,
text(120) type c,
end of t_tab.
text(120) type c,
end of t_tab.
data :i_tab type standard table of t_tab ,
wa_tab type t_tab.
refresh : i_tab[].wa_tab type t_tab.
clear wa_tab.
wa_tab-text = 'Use of Create'.
append wa_tab to i_tab .
clear wa_tab.
wa_tab-text = '• To Insert the Records.'.
append wa_tab to i_tab .
call function 'POPUP_WITH_TABLE_DISPLAY_OK'
exporting
endpos_col = 100
endpos_row = 10
startpos_col = 2
startpos_row = 2 "6
titletext = text-001
* IMPORTING
* CHOISE =
tables
valuetab = i_tab
exceptions
break_off = 1
others = 2.
Data :
v_date type d,
call function 'OIL_GET_PREV_MONTH'
exporting
i_date = sy-datum
importing
e_date = v_date.
i_date = sy-datum
importing
e_date = v_date.
4
) To get the Current Month Begin Date
and End Date
data : l_date type d,
l_date1 type d,
l_date2 type d.
l_date2 type d.
CALL FUNCTION 'HR_JP_MONTH_BEGIN_END_DATE'
EXPORTING
iv_date = l_date
IMPORTING
ev_month_begin_date = l_date1
ev_month_end_date = l_date2.
EXPORTING
iv_date = l_date
IMPORTING
ev_month_begin_date = l_date1
ev_month_end_date = l_date2.
5) To Show the Progress Indicator in
the Selection Screen
call function 'SAPGUI_PROGRESS_INDICATOR'
exporting
percentage = 10
text = 'Data is Processing...'.
percentage = 10
text = 'Data is Processing...'.
6) Function Module to Check the File Extension
Data : l_extension(4) TYPE c .
CALL FUNCTION 'TRINT_FILE_GET_EXTENSION'
EXPORTING
filename = p_fname
uppercase = 'X'
IMPORTING
extension = l_extension.
IF ( extension NE 'XLSX' AND extension NE 'XLS' ).
MESSAGE 'Invalid file format.File extension should be .xls / .xlsx' TYPE 'E'.
ENDIF.
7) To get Start Date and End date
Based on Month as a Input ( Calendar Month )EXPORTING
filename = p_fname
uppercase = 'X'
IMPORTING
extension = l_extension.
IF ( extension NE 'XLSX' AND extension NE 'XLS' ).
MESSAGE 'Invalid file format.File extension should be .xls / .xlsx' TYPE 'E'.
ENDIF.
data :l_sdate type sy-datum ,
l_edate type sy-datum ,
l_year type bkpf-gjahr ,
l_month type t009b-poper .
*& To get the Calendar month start date l_edate type sy-datum ,
l_year type bkpf-gjahr ,
l_month type t009b-poper .
------------------------------------------------
call function 'FIRST_DAY_IN_PERIOD_GET'
exporting
i_gjahr = l_year
i_periv = 'K4'
i_poper = l_month
importing
e_date = l_sdate.
*& To get the Calendar month end date
------------------------------------------------
call function 'LAST_DAY_IN_PERIOD_GET'
exporting
i_gjahr = l_year
i_periv = 'K4'
i_poper = l_month
importing
e_date = l_edate.
i_gjahr = l_year
i_periv = 'K4'
i_poper = l_month
importing
e_date = l_sdate.
*& To get the Calendar month end date
------------------------------------------------
call function 'LAST_DAY_IN_PERIOD_GET'
exporting
i_gjahr = l_year
i_periv = 'K4'
i_poper = l_month
importing
e_date = l_edate.
8) To get Start Date and End date
Based on Month as a Input ( fiscal Month )
data :l_sdate type sy-datum ,l_edate type sy-datum ,
l_year type bkpf-gjahr ,
l_month type t009b-poper .
*& To get the Fiscal year's month start date
----------------------------------------------------
call function 'FIRST_DAY_IN_PERIOD_GET'
exporting
i_gjahr = l_year
i_periv = 'V3'
i_poper = l_month
importing
e_date = l_sdate.
*& To get the Fiscal year's month end date
----------------------------------------------------
call function 'LAST_DAY_IN_PERIOD_GET'
exporting
i_gjahr = l_year
i_periv = 'V3'
i_poper = l_month
importing
e_date = l_edate.
exporting
i_gjahr = l_year
i_periv = 'V3'
i_poper = l_month
importing
e_date = l_sdate.
*& To get the Fiscal year's month end date
----------------------------------------------------
call function 'LAST_DAY_IN_PERIOD_GET'
exporting
i_gjahr = l_year
i_periv = 'V3'
i_poper = l_month
importing
e_date = l_edate.
9) Function module to get No.Of Days in Month
Data : lv_noday type p,call function 'HR_E_NUM_OF_DAYS_OF_MONTH'
exporting
p_fecha = sy-datum
importing
number_of_days = lv_noday.
10) To Calculate 2 Months prior/before Date
Data : calc_date type
d.
call function
'RP_CALC_DATE_IN_INTERVAL'
exportingdate = sy-datum
days = 1
months = 02
years = 00
signum = '-'
importing
calc_date = calc_date.
11) Function module to get employee Grade Description + SAP ABAP HR
Data :
lv_ptext TYPE t503t-ptext.
CALL FUNCTION 'HRWPC_RFC_PERSK_TEXT_GET'
EXPORTINGpersk = ipsyst-persk
langu = sy-langu
IMPORTING
persk_text = lv_ptext.
11) Function module to display a text in a POP-UP Window
CALL FUNCTION 'POPUP_TO_DISPLAY_TEXT'
EXPORTINGCALL FUNCTION 'POPUP_TO_DISPLAY_TEXT'
TITEL = 'Information Message'
TEXTLINE1 = lv_mess "textline1
* TEXTLINE2 = ' '
START_COLUMN = 3
START_ROW = 6
.
13) & functionality to convert date from external to internal format
Example:
Input date format : 20.10.2016
Expecting Output date format :20161020TRY.
CALL METHOD cl_abap_datfm=>conv_date_ext_to_int
EXPORTING
im_datext = wa_upload-valfr “Type Char 10
IMPORTING
ex_datint = date_out. “type d
* Catch all possible exceptions
CATCH
cx_abap_datfm_no_date cx_abap_datfm_invalid_date cx_abap_datfm_format_unknown cx_abap_datfm_ambiguous .
ENDTRY.
14) POPUP Message WITH Continue Button
call function 'POPUP_TO_DISPLAY_TEXT'
exporting
titel = 'Information'
textline1 = lv_mess "textline1
* TEXTLINE2 = ' '
start_column = 3
start_row = 6.
exporting
titel = 'Information'
textline1 = lv_mess "textline1
* TEXTLINE2 = ' '
start_column = 3
start_row = 6.
Clear :lv_string.
call function 'SCP_REPLACE_STRANGE_CHARS'
exporting
intext = lv_string
importing
outtext = lv_string.
intext = lv_string
importing
outtext = lv_string.
Comments
Post a Comment