SAP Virtual/Onsite Trainings

Document Categories:

What's New?

Contribute?

Sample Specs

What's Hot?

Web Dynpro for ABAP Tutorials 


Join the Mailing List
Enter name and email address below:
Name:
Email:
Subscribe  Unsubscribe 

Create and Delete Folder in Frontend system using Class CL_GUI_FRONTEND_SERVICES

By Prasanna, Infosys

Procedure:

1.     Create Selection Screen with two radio buttons “Create Folder” and “Delete Folder”

And parameters to specify path for creating and deleting the folder.

2.     Give path and folder name in the selection screen

3.     Creating folder select the “Create Folder” Radio Button

4.     Deleting folder select the “Delete Folder” Radio Button  

REPORT ZFOLDER_PGM.
* Selection Screen Declarations
SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001.
PARAMETERS: P_CR RADIOBUTTON GROUP RGB1 USER-COMMAND UCO
                                    MODIF ID MOD DEFAULT 'X',
            P_DR RADIOBUTTON GROUP RGB1 MODIF ID MOD,
            P_CDIR TYPE STRING,
            P_DDIR TYPE STRING.
SELECTION-SCREEN END OF BLOCK B1.

* Data declarations
  DATA: RESULT TYPE CHAR1,
        RC TYPE I,
        STRIPPED_NAME TYPE STRING,
        V_STRING TYPE STRING.

************************************
* At Selection-Screen Output Event
************************************

AT SELECTION-SCREEN OUTPUT.

* Create Folder Checkbox Checked, Don’t display the “Path to Delete Folder” parameter
  IF P_CR = 'X'.
    LOOP AT SCREEN.
      IF SCREEN-NAME = 'P_DDIR' OR
        SCREEN-NAME = '%_P_DDIR_%_APP_%-TEXT'.
        SCREEN-INPUT = 0.
        SCREEN-INVISIBLE = 1.
        MODIFY SCREEN.
      ENDIF.
    ENDLOOP.
  ELSE.

* Delete Folder Checkbox Checked, Don’t display the “Path to Create Folder” parameter
    LOOP AT SCREEN.
      IF SCREEN-NAME = 'P_CDIR' OR
        SCREEN-NAME = '%_P_CDIR_%_APP_%-TEXT'.
        SCREEN-INPUT = 0.
        SCREEN-INVISIBLE = 1.
        MODIFY SCREEN.
      ENDIF.
    ENDLOOP.
  ENDIF.

************************************
* Start of Selection Event
************************************

START-OF-SELECTION.

  IF P_CR = 'X'”Create folder radio button is checked.

*   Clear result variable
    CLEAR RESULT.

*     Get the folder name
  CALL FUNCTION 'SO_SPLIT_FILE_AND_PATH'
    EXPORTING
      FULL_NAME     = P_CDIR
    IMPORTING
      STRIPPED_NAME = STRIPPED_NAME
    EXCEPTIONS
      X_ERROR       = 1
      OTHERS        2.

*   Check if the folder name exists under the specified directory
*    which you want to create

    CALL METHOD CL_GUI_FRONTEND_SERVICES=>DIRECTORY_EXIST
      EXPORTING
        DIRECTORY            = P_CDIR
      RECEIVING
        RESULT               = RESULT
      EXCEPTIONS
        CNTL_ERROR           = 1
        ERROR_NO_GUI         = 2
        WRONG_PARAMETER      = 3
        NOT_SUPPORTED_BY_GUI = 4
        OTHERS               5.

*    If the folder name already exists then display a message.
    IF RESULT = 'X'.

      CLEAR V_STRING.
      CONCATENATE 'ALREADY CONTAINS A FOLDER NAMED'
                  STRIPPED_NAME
                  INTO V_STRING SEPARATED BY SPACE.

      MESSAGE V_STRING TYPE 'I'.
      LEAVE LIST-PROCESSING.

*   If the folder name is not exist in the specified directory
    ELSE.

*     Clear return code
      CLEAR RC.

*      Create a new folder under the specified directory
      CALL METHOD CL_GUI_FRONTEND_SERVICES=>DIRECTORY_CREATE
        EXPORTING
          DIRECTORY                = P_CDIR
        CHANGING
          RC                       = RC
        EXCEPTIONS
          DIRECTORY_CREATE_FAILED  = 1
          CNTL_ERROR               = 2
          ERROR_NO_GUI             = 3
          DIRECTORY_ACCESS_DENIED  = 4
          DIRECTORY_ALREADY_EXISTS = 5
          PATH_NOT_FOUND           = 6
          UNKNOWN_ERROR            = 7
          NOT_SUPPORTED_BY_GUI     = 8
          WRONG_PARAMETER          = 9
          OTHERS                   10.

      IF RC = 0.

        CLEAR V_STRING.
        CONCATENATE 'CREATED FOLDER NAMED'
                    STRIPPED_NAME
                    INTO V_STRING SEPARATED BY SPACE.

        MESSAGE V_STRING TYPE 'I'.
      ENDIF.

    ENDIF.

  ELSE.  "Delete folder radio button is checked.

*   Clear result variable

    CLEAR RESULT.

*     Get the folder name
  CALL FUNCTION 'SO_SPLIT_FILE_AND_PATH'
    EXPORTING
      FULL_NAME     = P_DDIR
    IMPORTING
      STRIPPED_NAME = STRIPPED_NAME
    EXCEPTIONS
      X_ERROR       = 1
      OTHERS        2.

*   Check if the folder name exists under the specified directory
*    which you want to create

    CALL METHOD CL_GUI_FRONTEND_SERVICES=>DIRECTORY_EXIST
      EXPORTING
        DIRECTORY            = P_DDIR
      RECEIVING
        RESULT               = RESULT
      EXCEPTIONS
        CNTL_ERROR           = 1
        ERROR_NO_GUI         = 2
        WRONG_PARAMETER      = 3
        NOT_SUPPORTED_BY_GUI = 4
        OTHERS               5.

    IF RESULT <> 'X'.

      CLEAR V_STRING.

      CONCATENATE 'THERE IS NO FOLDER NAMED'
                  STRIPPED_NAME
                  INTO V_STRING SEPARATED BY SPACE.

      MESSAGE V_STRING TYPE 'I'.
      LEAVE LIST-PROCESSING.

*    If the folder name exist, delete that folder from the
*     specified directory

    ELSE.

*     Clear return code
      CLEAR RC.

*      Delete folder from the specified directory
      CALL METHOD CL_GUI_FRONTEND_SERVICES=>DIRECTORY_DELETE
        EXPORTING
          DIRECTORY               = P_DDIR
        CHANGING
          RC                      = RC
        EXCEPTIONS
          DIRECTORY_DELETE_FAILED = 1
          CNTL_ERROR              = 2
          ERROR_NO_GUI            = 3
          PATH_NOT_FOUND          = 4
          DIRECTORY_ACCESS_DENIED = 5
          UNKNOWN_ERROR           = 6
          NOT_SUPPORTED_BY_GUI    = 7
          WRONG_PARAMETER         = 8
          OTHERS                  9.
      IF RC = 0.
        CLEAR V_STRING.

        CONCATENATE 'DELETED FOLDER NAMED'
                    STRIPPED_NAME
                    INTO V_STRING SEPARATED BY SPACE.

        MESSAGE V_STRING TYPE 'I'.
        LEAVE LIST-PROCESSING.

      ENDIF.
    ENDIF.
  ENDIF.

Click here to continue...

Please send us your feedback/suggestions at webmaster@SAPTechnical.COM 

HomeContribute About Us Privacy Terms Of Use • Disclaimer • SafeCompanies: Advertise on SAPTechnical.COM | Post JobContact Us  

Graphic Design by Round the Bend Wizards

footer image footer image