SAP R/3 форум ABAP консультантов
Russian ABAP Developer's Club

Home - FAQ - Search - Memberlist - Usergroups - Profile - Log in to check your private messages - Register - Log in - English
Blogs - Weblogs News

Display Information about OS Files on a Path



 
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> Connect to External system, Unix и Perl
View previous topic :: View next topic  
Author Message
admin
Администратор
Администратор



Joined: 01 Sep 2007
Posts: 1640

PostPosted: Wed Aug 20, 2008 9:57 am    Post subject: Display Information about OS Files on a Path Reply with quote

Code:
* Source Name is  ZFILEINFO
REPORT ZFILEINFO line-size 132 line-count 65.
DATA: SAP_YES(1)  VALUE 'X'
    , SAP_NO(1)   VALUE ' '
    , SRT(1)      VALUE 'T'
    , NO_CS       VALUE ' '            " no MUST_ContainString
    , ALL_GEN     VALUE '*'    " generic filename shall select all
    , STRLEN      LIKE SY-FDPOS
    .
parameters: dirname like epsf-epsdirnam
    default '/data/KOD/Outbound/TO_UPPS/Archive'
lower case.
data: parm2(75) value '*'.
data: parm3(10).
data: filename(70).

DATA: BEGIN OF FILE_LIST OCCURS 100,
        DIRNAME(75) TYPE C, " name of directory. (possibly truncated.)
        NAME(75)    TYPE C, " name of entry. (possibly truncated.)
        TYPE(10)    TYPE C,            " type of entry.
        LEN(8)      TYPE P,            " length in bytes.
        OWNER(8)    TYPE C,            " owner of the entry.
        MTIME(6)    TYPE P, " last modification date, seconds since 1970
        MODE(9)     TYPE C, " like "rwx-r-x--x": protection mode.
        USEABLE(1)  TYPE C,
        SUBRC(4)    TYPE C,
        ERRNO(3)    TYPE C,
        ERRMSG(40)  TYPE C,
        MOD_DATE    like sy-datum,
        MOD_TIME(8) TYPE C,            " hh:mm:ss
        SEEN(1)     TYPE C,
        CHANGED(1)  TYPE C,
      END OF FILE_LIST.
data: begin of file.
        include structure file_list.
data: end of file.
refresh file_list.
perform fill_file_list using dirname parm2 parm3.
loop at file_list.
  if file_list-name co ' .'.
    delete file_list index syst-tabix.
  endif.
endloop.
loop at file_list.
  concatenate file_list-dirname '/' file_list-name into filename.
  write: / filename,
           file_list-mod_date,
           file_list-mod_time.
endloop.

*---------------------------------------------------------------------*
*       FORM FILL_FILE_LIST                                           *
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
*  -->  A_DIR_NAME                                                    *
*  -->  A_GENERIC_NAME                                                *
*  -->  A_MUST_CS                                                     *
*---------------------------------------------------------------------*
FORM FILL_FILE_LIST USING A_DIR_NAME A_GENERIC_NAME A_MUST_CS.

  DATA: ERRCNT(2) TYPE P VALUE 0.
  IF A_DIR_NAME IS INITIAL.
*    MESSAGE E220.     " 'Place cursor on valid line !'.
  ENDIF.

  CALL 'C_DIR_READ_FINISH'             " just to be sure
      ID 'ERRNO'  FIELD FILE_LIST-ERRNO
      ID 'ERRMSG' FIELD FILE_LIST-ERRMSG.

  CALL 'C_DIR_READ_START' ID 'DIR'    FIELD A_DIR_NAME
                          ID 'FILE'   FIELD A_GENERIC_NAME
                          ID 'ERRNO'  FIELD FILE-ERRNO
                          ID 'ERRMSG' FIELD FILE-ERRMSG.
  IF SY-SUBRC <> 0.
*   message i204 with sy-subrc 'C_DIR_READ_START'
*                     ' ' a_dir_name.
*   message i204 with sy-subrc 'C_DIR_READ_START...'
*                    file-errno file-errmsg.
*    MESSAGE E204 WITH FILE_LIST-ERRMSG FILE-ERRMSG.
  ENDIF.

  DO.
    CLEAR FILE.
    CALL 'C_DIR_READ_NEXT'
      ID 'TYPE'   FIELD FILE-TYPE
      ID 'NAME'   FIELD FILE-NAME
      ID 'LEN'    FIELD FILE-LEN
      ID 'OWNER'  FIELD FILE-OWNER
      ID 'MTIME'  FIELD FILE-MTIME
      ID 'MODE'   FIELD FILE-MODE
      ID 'ERRNO'  FIELD FILE-ERRNO
      ID 'ERRMSG' FIELD FILE-ERRMSG.
    FILE-DIRNAME = A_DIR_NAME.
    MOVE SY-SUBRC TO FILE-SUBRC.
    CASE SY-SUBRC.
      WHEN 0.
        CLEAR: FILE-ERRNO, FILE-ERRMSG.
        CASE FILE-TYPE(1).
          WHEN 'F'.                    " normal file.
*            PERFORM FILENAME_USEABLE USING FILE-NAME FILE-USEABLE.
          WHEN 'f'.                    " normal file.
*            PERFORM FILENAME_USEABLE USING FILE-NAME FILE-USEABLE.
          WHEN OTHERS. " directory, device, fifo, socket,...
            MOVE SAP_NO  TO FILE-USEABLE.
        ENDCASE.
        IF FILE-LEN = 0.
          MOVE SAP_NO TO FILE-USEABLE.
        ENDIF.
      WHEN 1.
        EXIT.
      WHEN OTHERS.                     " SY-SUBRC >= 2
        ADD 1 TO ERRCNT.
        IF ERRCNT > 10.
          EXIT.
        ENDIF.
        IF SY-SUBRC = 5.
          MOVE: '???' TO FILE-TYPE,
                '???' TO FILE-OWNER,
                '???' TO FILE-MODE.
        ELSE.
*         ULINE.
*         WRITE: / 'C_DIR_READ_NEXT', 'SUBRC', SY-SUBRC.
        ENDIF.
        MOVE SAP_NO TO FILE-USEABLE.
    ENDCASE.
    PERFORM P6_TO_DATE_TIME_TZ(RSTR0400) USING FILE-MTIME
                                               FILE-MOD_TIME
                                               FILE-MOD_DATE.
*   * Does the filename contains the requested pattern?
*   * Then store it, else forget it.
    IF A_MUST_CS = NO_CS.
      MOVE-CORRESPONDING FILE TO FILE_LIST.
      APPEND FILE_LIST.
    ELSE.
      IF FILE-NAME CS A_MUST_CS.
        MOVE-CORRESPONDING FILE TO FILE_LIST.
        APPEND FILE_LIST.
      ENDIF.
    ENDIF.
  ENDDO.

  CALL 'C_DIR_READ_FINISH'
      ID 'ERRNO'  FIELD FILE_LIST-ERRNO
      ID 'ERRMSG' FIELD FILE_LIST-ERRMSG.
  IF SY-SUBRC <> 0.
    WRITE: / 'C_DIR_READ_FINISH', 'SUBRC', SY-SUBRC.
  ENDIF.
  IF SRT = 'T'.
    SORT FILE_LIST BY MTIME DESCENDING NAME ASCENDING.
  ELSE.
    SORT FILE_LIST BY NAME ASCENDING MTIME DESCENDING.
  ENDIF.

ENDFORM.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> Connect to External system, Unix и Perl All times are GMT + 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


All product names are trademarks of their respective companies. SAPNET.RU websites are in no way affiliated with SAP AG.
SAP, SAP R/3, R/3 software, mySAP, ABAP, BAPI, xApps, SAP NetWeaver and any other are registered trademarks of SAP AG.
Every effort is made to ensure content integrity. Use information on this site at your own risk.