Sunday 3 March 2013

Validating Local/Presentation path exist or not in SAP ABAP

Following is the program that checks whether the local path entered is valid or not.

TYPE-POOLS : abap.

Paramaters : p_zloc type rlgrap-filename.

    DATA : lv_dir TYPE string,
           lv_bol TYPE abap_bool,
           lv_string TYPE rlgrap-filename.
    DATA lv_w_string TYPE string.
    DATA : lv_i TYPE i,
                  lv_j TYPE i.

    lv_string   = p_zloc.
    lv_w_string = lv_string.

    DO.
      SEARCH lv_w_string FOR '\'.
      IF sy-subrc EQ 0.
        lv_i = sy-fdpos + 1.
        lv_j = lv_i + lv_j.
        lv_w_string = lv_w_string+lv_i.
      ELSE.
        EXIT.
      ENDIF.
    ENDDO.

    lv_dir = lv_string+0(lv_j).

    CALL METHOD cl_gui_frontend_services=>directory_exist
      EXPORTING
        directory            = lv_dir
      RECEIVING
        result               = lv_bol
      EXCEPTIONS
        cntl_error           = 1
        error_no_gui         = 2
        wrong_parameter      = 3
        not_supported_by_gui = 4
        OTHERS               = 5.
    IF  lv_bol NE 'X'." if lv_bol = 'X' the path is a vlid path
      MESSAGE e000(zh) WITH text-008.
    ENDIF.

No comments:

Post a Comment