Show TOC Start of Content Area

Background documentation Validating Logical File Names Entered By the User  Locate the document in its SAP Library structure

There are several steps involved in implementing the complete recommendation for validating physical file names entered by the user.

The steps to perform are:

...

       1.      Define a constant to use for the logical file name. (Mandatory)

       2.      During PBO, call the function module FILE_LOGFILE_ALIAS_PBO. (Mandatory)

       3.      During PAI, call the function module FILE_LOGFILE_ALIAS_PAI. (Mandatory)

       4.      Add a call to function module FILE_LOGFILE_ALIAS_F4. (Mandatory)

       5.      Validate the file name. (Recommended)

See the following sections.

Step 1. Define a Constant Logical File Name to be Used for File Name Validation (Mandatory)

For each parameter for a physical file name in your application create one global constant of type FILEINTERN (logical file name). Set the value of this constant to the logical file name used for file name validation in this context.

Example

CONSTANTS gc_fname TYPE fileintern VALUE 'EXAMPLE_FIN1'.

 

Step 2: During PBO, Call Function Module FILE_LOGFILE_ALIAS_PBO. (Mandatory)

During PBO, call the function module FILE_LOGFILE_ALIAS_PBO. This function module performs the following:

      It checks whether validation for your logical file name is active.

      If validation is active, it will attempt to change the parameter on your screen to be a list box. It fills the list box with the logical file names allowed in this context.

Note

Validation for a logical file name is defined as active if the system administrator has set up the logical file name whitelist to use for validation or maintained aliases.

Example

AT SELECTION-SCREEN OUTPUT.

  CALL FUNCTION 'FILE_LOGFILE_ALIAS_PBO'

    EXPORTING

      ed_logfile_appl   = gc_logfile

      ed_parameter_name = 'PA_FILE'

    CHANGING

      cd_logfile_param  = pa_file.

Note

Some programs provide an input field that can be used for either a physical file name or a logical file name. In such a scenario, you may have to adjust the call above depending on the context. For example, if you do not provide a field name in ed_parameter_name, the field will not be converted to a list box. If cd_logfile_param is empty, the function module will set the hard-coded logical file name as a default.

Step 3: During PAI, Call Function Module FILE_LOGFILE_ALIAS_PAI. (Mandatory)

During PAI, call the function module FILE_LOGFILE_ALIAS_PAI. This function module performs the following:

      It checks whether validation for your logical file name is active.

      If validation is active, and if the user specified or selected a logical file name, the function module checks whether the specified logical file name is allowed in this context. If it is not allowed, it raises the exception EXC_INVALID_FILENAMEwith a corresponding error message. You have to handle this error message according to the context of your application. In most cases, you can use the error message as is.

Note

This call is necessary when loading a variant. In this case, the UI will automatically add an entry to the list box containing the value from the variant. Therefore, even when using a list box, it is possible that the user will select a logical file name which has not been defined as a valid alias.

Example

AT SELECTION-SCREEN.

  CALL FUNCTION 'FILE_LOGFILE_ALIAS_PAI'

    EXPORTING

      ed_logfile_appl            = gc_logfile

    CHANGING

      cd_logfile                 = pa_file

    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.

  ENDIF.

Note

If the parameter pa_file can be used for either physical and logical file names you, only have to call this function module if the specified file name is a logical file name. The recommended procedure is to call the function module FILE_GET_NAME first.

If the result from FILE_GET_NAME is that the content of pa_file is a logical file name, call the function module FILE_LOGFILE_ALIAS_PAI as illustrated above.

If the result from FILE_GET_NAME is that the content of pa_file is not a logical file name, call the function module FILE_VALIDATE_NAME and provide the hard-coded logical file name in the EXPORT parameter logical_filename and the content of pa_file for the CHANGING parameter physical_filename.

Step 4: Add a Call to Function Module FILE_LOGFILE_ALIAS_F4 (Mandatory)

This call is to be used in case the user tries to use the value help for entering a logical file name. This function module performs the following:

      If the validation for your logical file name is active, only the logical file names allowed in this context will be available with the value help. The user will not be able to select a logical file name that he or she is not allowed to use when executing the program.

      If the validation for your logical file name is not active, the function module will start a dialog which allows the user to select any logical file name defined in the system.

Example

AT SELECTION-SCREEN ON VALUE-REQUEST FOR pa_file.

  CALL FUNCTION 'FILE_LOGFILE_ALIAS_F4'

    EXPORTING

      ed_logfile_appl   = gc_logfile

      ed_parameter_name = 'PA_FILE'

    CHANGING

      cd_logical_file   = pa_file.

Note

If the parameter pa_file can be used for either physical and logical file names, you need to decide whether you want to provide value help for a logical file name (in that case use FILE_LOGFILE_ALIAS_F4) or a physical file name (for example, by using cl_gui_frontend_services=>file_open_dialog).

Step 5: Validate the File Name. (Recommended)

Validate the physical file name directly before the OPEN DATASET or related statement.

Example

CALL FUNCTION 'FILE_GET_NAME'

    EXPORTING

      logical_filename  = pa_file

* any parameters defined for that logical file name

    CHANGING

      physical_filename = ld_physfile.

 

CALL FUNCTION 'FILE_VALIDATE_NAME'

    EXPORTING

      logical_filename  = gc_fname

* any parameters defined for that logical file name

    CHANGING

      physical_filename = ld_physfile

    EXCEPTIONS

      OTHERS            = 1.

 

  IF sy-subrc <> 0.

* Implement suitable error handling here, for example,

*    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

*      WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

  ENDIF.

 

  OPEN DATASET ld_physfile

     FOR INPUT IN TEXT MODE ENCODING DEFAULT.

  IF sy-subrc <> 0.

* ...

  ENDIF.

 

 

 

 

 

End of Content Area