Академический Документы
Профессиональный Документы
Культура Документы
snippets of
code
Some helpful pieces of Code
1
1. FM for getting values from a SET:
For getting the values of a given set, you can first call the FM G_SET_GET_ID_FROM_NAME to get the ID
of the set. Further you can call the FM G_SET_GET_ALL_VALUES, passing to it the set ID received from
the above called FM, to populate the required internal table with values of the set. Also, to view the
values in a set, you can open the transaction GS03 and to create a set you can go to transaction GS01.
Following is an example piece of code for the same:
=====================================================================================
* Local Dictionary
CONSTANTS lc_setname TYPE char13 VALUE 'ZK4_CONT_DISP'.
CLEAR l_set_id.
REFRESH i_set_values.
2
2. Filling a RANGE from an Internal Table:
For filling a range from an internal table following is a sample piece of code:
Here we are creating a range for all the data in the internal table I_SET_VALUES. In the below example
the range will contain data of field CAUSRICH of table ZK4_HEAD and hence declared correspondingly.
The internal table I_SET_VALUES also has the data of CAUSIRICH field of table ZK4_HEAD.
=====================================================================================
* Local Dictionary
IF <fs_set_values> IS ASSIGNED.
UNASSIGN <fs_set_values>.
ENDIF.
IF <fs_set_values>-from EQ <fs_set_values>-to.
wa_zk4_cont_disp-option = lc_eq."EQ
ELSE.
wa_zk4_cont_disp-option = lc_bt."BT
ENDIF.
IF <fs_set_values> IS ASSIGNED.
UNASSIGN <fs_set_values>.
ENDIF.
3
3. F4 Search help for DIRECTORIES on PRESENTATION server
To create a F4 search help for the Directories present on the PRESENTATION SERVER (Local
Directories on your system) you can call the method DIRECTORY_BROWSE of class
CL_GUI_FRONTEND_SERVICES. This method should be called under the event:
AT SELECTION-SCREEN ON VALUE-REQUEST. Following is a sample piece of code for your reference
where P_DIR_P is an input parameter, which will contain the input Directory.
==================================================================================
*&---------------------------------------------------------------------*
*& Form F_F4_DIR_PRES
*&---------------------------------------------------------------------*
FORM f_f4_dir_pres.
IF sy-subrc EQ 0.
p_dir_p = l_dir.
ENDIF
*------------------------------------------------------------------------*
4
4. F4 Search help for FILES on PRESENTATION server
To create a F4 search help for the Files present on the PRESENTATION SERVER (Local Files on your
system) you can call the method FILE_OPEN_DIALOG of class CL_GUI_FRONTEND_SERVICES. This
method should be called under the event: AT SELECTION-SCREEN ON VALUE-REQUEST. Following is
a sample piece of code for your reference where P_FILE_P is an input parameter, which will contain
the input File. Only if the input Directory (P_DIR_P) is enhanced, the F4 help will be created for Files.
==================================================================================
*&---------------------------------------------------------------------*
*& Form F_F4_FILE_PRES
*&---------------------------------------------------------------------*
* For creating F4 search help for Files on Presentation Server
*----------------------------------------------------------------------*
FORM f_f4_file_pres.
CLEAR : l_file,l_rc,l_temp_dir,wa_line.
l_temp_dir = p_dir_p.
5
error_no_gui = 3
not_supported_by_gui = 4
OTHERS = 5.
IF sy-subrc EQ 0.
IF l_rc = 1.
READ TABLE l_file INDEX 1 INTO wa_line.
IF wa_line-filename IS NOT INITIAL.
*---------------------------------------------------------------------------*
6
5. F4 Search help for PATH+FILENAME on PRESENTATION server
To create a F4 search help for PATH + FILENAME together in one input parameter, present on the
PRESENTATION SERVER, you can call the FM F4_FILENAME. This Function module should be called
under the event: AT SELECTION-SCREEN ON VALUE-REQUEST. Following is a sample piece of code for
your reference where P_PATH_F is an input parameter, which will contain the input path and filename.
==================================================================================
* Subroutine for F4 search help for PATH & FILE on Presentation Server.
PERFORM f_f4_path_file_pres.
*&---------------------------------------------------------------------*
*& Form F_F4_PATH_FILE_PRES
*&---------------------------------------------------------------------*
FORM f_f4_path_file_pres .
* Constants
CONSTANTS lc_pfile TYPE dynfnam VALUE 'P_PATH_F'.
ENDFORM. ”F_F4_PATH_FILE_PRES
*-----------------------------------------------------------------------*
7
6. FM for checking existence of a PATH/DIR on PRESENTATION server
To check the existence of a PATH/ DIRECTORY on the presentation server, entered by the user, you can
call the method DIRECTORY_EXIST of the class CL_GUI_FRONTEND_SERVICES. Following is a sample
piece of code for your reference where P_DIR_P is the input parameter containing the Path/ Directory
name. The Result parameter of the method returns ‘X’ when Directory exists otherwise returns Blank.
=====================================================================================
*&---------------------------------------------------------------------*
*& Form F_CHECK_DIR_PRES
*&---------------------------------------------------------------------*
* For checking input Directory's existence on Presentation server.
*----------------------------------------------------------------------*
FORM f_check_dir_pres .
CLEAR:l_dir, fl_flag.
l_dir = p_dir_p.
CALL METHOD cl_gui_frontend_services=>directory_exist
EXPORTING
directory = l_dir
RECEIVING
result = fl_flag
EXCEPTIONS
cntl_error = 1
error_no_gui = 2
wrong_parameter = 3
not_supported_by_gui = 4
OTHERS = 5.
*-------------------------------------------------------------------*
8
7. FM for checking existence of FILE on PRESENTATION server
To check the existence of a FILE on the presentation server, entered by the user, you can call the
method FILE_EXIST of the class CL_GUI_FRONTEND_SERVICES. Following is a sample piece of code for
your reference where P_DIR_P is the input parameter containing the Path/ Directory name and P_FILE_P
is the input file whose existence is to be checked. The Result parameter of the method returns ‘X’ when
the File exists otherwise it returns Blank.
=====================================================================================
*&---------------------------------------------------------------------*
*& Form F_CHECK_FILE_PRES
*&---------------------------------------------------------------------*
* For checking input File's existence on Presentation server.
*----------------------------------------------------------------------*
FORM f_check_file_pres .
CLEAR: fl_flag,l_file.
l_len = STRLEN( p_dir_p ).
l_len = l_len - 1.
9
CALL METHOD cl_gui_frontend_services=>file_exist
EXPORTING
file = l_file
RECEIVING
result = fl_flag
EXCEPTIONS
cntl_error = 1
error_no_gui = 2
wrong_parameter = 3
not_supported_by_gui = 4
OTHERS = 5.
*------------------------------------------------------------------*
10
8. F4 Search help for PATH/DIRECTORY on APPLICATION server
To create a F4 search help for the Directory or Path present on the APPLICATION SERVER (i.e. Directories
on SAP system) you can call the Function Module /SAPDMC/LSM_F4_SERVER_FILE. This method should
be called under the event: AT SELECTION-SCREEN ON VALUE-REQUEST. Following is a sample piece of
code for your reference where P_DIR_A is an input parameter, which will contain the input Directory.
=====================================================================================
*&---------------------------------------------------------------------*
*& Form F_F4_DIR_APPL
*&---------------------------------------------------------------------*
* For creating F4 search help for Directory/Path on Application Server
*----------------------------------------------------------------------*
FORM f_f4_dir_appl .
IF sy-subrc = 0.
* Do nothing.
ENDIF.
*----------------------------------------------------------------------*
11
9. F4 Search help for files on APPLICATION Server
To create a F4 search help for the Files present on the APPLICATION SERVER (i.e. Files on SAP system)
you can call the Function Module /SAPDMC/LSM_F4_SERVER_FILE. This method should be called under
the event: AT SELECTION-SCREEN ON VALUE-REQUEST. Following is a sample piece of code for your
reference where P_DIR_A is the input directory whose files you want to display as search help.
=====================================================================================
*&---------------------------------------------------------------------*
*& Form F_F4_FILE_APPL
*&---------------------------------------------------------------------*
* For creating F4 search help for Files on Application Server
*----------------------------------------------------------------------*
FORM f_f4_file_appl .
* Local Dictionary
DATA : l_file TYPE rlgrap-filename,
l_len TYPE i.
CLEAR l_file.
IF sy-subrc = 0.
l_len = STRLEN( p_dir_a ).
l_len = l_len + 1.
p_file_a = l_file+l_len(*).
ENDIF.
12
ELSE.
* Error message:'Si prega di selezionare Directory prima'(Please select
directory first).
MESSAGE S208(00) WITH text-004 DISPLAY LIKE 'E'.
ENDIF.
*----------------------------------------------------------------------*
13
10. FM for checking existence of a PATH/DIR on APPLICATION server
To check the existence of a PATH/ DIRECTORY on the Application server, entered by the user, you can
call the method PFL_CHECK_DIRECTORY. Following is a sample piece of code for your reference where
P_DIR_A is the input parameter containing the Path/ Directory name.
====================================================================================
*&---------------------------------------------------------------------*
*& Form F_CHECK_DIR_APPL
*&---------------------------------------------------------------------*
* For checking input Directory's existence on Presentation server.
*----------------------------------------------------------------------*
FORM f_check_dir_appl .
IF sy-subrc NE 0.
* Error message:'Directory doesnot exist'.
MESSAGE e208(00) WITH text-003.
ENDIF.
*----------------------------------------------------------------------*
14
11. For checking the existence of a FILE on APPLICATION server
To check the existence of a FILE on the Application server following is a sample piece of code for your
reference where P_FILE_A is the input parameter containing the File Name and P_DIR_A contains the
Directory name.
=====================================================================================
*&---------------------------------------------------------------------*
*& Form F_CHECK_FILE_APPL
*&---------------------------------------------------------------------*
* For checking input File's existence on Presentation server.
*----------------------------------------------------------------------*
FORM f_check_file_appl .
CLEAR l_len.
l_len = STRLEN( p_dir_a ).
l_len = l_len - 1.
15
ELSE.
CLOSE DATASET l_file.
ENDIF.
*-------------------------------------------------------------------*
16
12. FM for checking the EXTENSION of an input file
To check the extension of an input file whether it is CSV or XLS etc., you can call the FM
TRINT_FILE_GET_EXTENSION. You can call this FM inside the event: AT SELECTION-SCREEN. Following is
a sample piece of code for your reference where P_FILE_P is the input parameter, containing the FILE
NAME with File Extension which is passed to the FM. Also ‘X’ is passed to the Exporting Parameter
UPPER CASE, to convert the extension of the input file to Upper case to avoid conflicts.
=====================================================================================
AT SELECTION-SCREEN.
*&---------------------------------------------------------------------*
*& Form F_CHECK_FILE_EXT
*&---------------------------------------------------------------------*
* For checking the extension of the input file whether it is CSV or not.
*----------------------------------------------------------------------*
FORM f_check_file_ext.
CLEAR l_ext.
ENDFORM. ”F_CHECK_FILE_EXT
*-------------------------------------------------------------------------*
17