ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

display all tables in IFS directory

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • display all tables in IFS directory

    Code:
         H DftActGrp(*No) Option(*SrcStmt : *NoDebugIO)
         D PATHTOLIST      C                   CONST('/home/jamie/')
         D*PATHTOLIST      C                   CONST('/')
         D*
         D* Directory Entry Structure (dirent)
         D*
         D*
         D p_dirent        s               *
         D dirent          ds                  based(p_dirent)
         D   d_reserv1                   16A
         D   d_reserv2                   10U 0
         D   d_fileno                    10U 0
         D   d_reclen                    10U 0
         D   d_reserv3                   10I 0
         D   d_reserv4                    8A
         D   d_nlsinfo                   12A
         D     nls_ccsid                 10I 0 OVERLAY(d_nlsinfo:1)
         D     nls_cntry                  2A   OVERLAY(d_nlsinfo:5)
         D     nls_lang                   3A   OVERLAY(d_nlsinfo:7)
         D     nls_reserv                 3A   OVERLAY(d_nlsinfo:10)
         D   d_namelen                   10U 0
         D   d_name                     640A
    
         D*------------------------------------------------------------
         D* Open a Directory
         D*
         D* DIR *opendir(const char *dirname)
         D*
         D*------------------------------------------------------------
         D opendir         PR              *   EXTPROC('opendir')
         D  dirname                        *   VALUE
    
         D*------------------------------------------------------------
         D* Read Directory Entry
         D*
         D* struct dirent *readdir(DIR *dirp)
         D*
         D*------------------------------------------------------------
         D readdir         PR              *   EXTPROC('readdir')
         D  dirp                           *   VALUE
    
    
         D* a few local variables...
         D dh              S               *
         D PathName        S            256A
         D Name            S            256A
    
    
         C* Step1: Open up the directory.
         c                   eval      PathName= PATHTOLIST + x'00'
         C                   eval      dh = opendir(%addr(PathName))
         C                   if        dh = *NULL
         c                   eval      Msg = 'Cant open directory'
         c                   dsply                   Msg              50
         c                   eval      *INLR = *ON
         c                   Return
         c                   endif
    
         C* Step2: Read each entry from the directory (in a loop)
         c                   eval      p_dirent = readdir(dh)
         c                   dow       p_dirent <> *NULL
    
         C* FIXME: This code can only handle file/dir names 256 bytes long
         C*         because thats the size of "Name"
         c                   if        d_namelen < 256
         c                   eval      Name = %subst(d_name:1:d_namelen)
         c                   movel     Name          dsply_me         52
         c     dsply_me      dsply
         c                   endif
    
         c                   eval      p_dirent = readdir(dh)
         c                   enddo
    
         C* Step3: End Program
         c                   dsply                   Pause             1
         c                   eval      *inlr = *On
    Attached Files
    All my answers were extracted from the "Big Dummy's Guide to the As400"
    and I take no responsibility for any of them.

    www.code400.com

  • #2
    Re: display all tables in IFS directory

    Thanks for your help. I will try to retrieve the RA txt file names using rpgle instead.

    Comment


    • #3
      Re: display all tables in IFS directory

      Let us know how it turns out...I have a couple versions of this animal running now
      so I hope I can be a resource in the future.
      I'm here to chew bubble gum and kick @#%@#%@#%.....and I'm all outta bubble gum !
      Yes I'm talking to you squirrel nuts.

      Comment


      • #4
        Re: display all tables in IFS directory

        This is what is displayed on screen when I run your program.....
        DSPLY .
        DSPLY .
        DSPLY T
        DSPLY T
        DSPLY T
        DSPLY

        the files in the directory are named as follows RA.TXT RA1.TXT and RA2.TXT any suggestions?
        Last edited by franklin@PW; February 14, 2007, 03:09 PM.

        Comment


        • #5
          Re: display all tables in IFS directory

          im hoping you changed this
          D PATHTOLIST C CONST('/home/jamie/')

          not every company is lucky enough to have a jamie
          All my answers were extracted from the "Big Dummy's Guide to the As400"
          and I take no responsibility for any of them.

          www.code400.com

          Comment


          • #6
            Re: display all tables in IFS directory

            Yes the directory is /ediin/edi820/

            Comment


            • #7
              Re: display all tables in IFS directory

              I recreated your directory structure and ran this all is fine.

              PHP Code:
                   D PATHTOLIST      C                   CONST('/ediin/edi820/')

                   
              D*
                   
              DDirectory Entry Structure (dirent)
                   
              D*
                   
              D*
                   
              D p_dirent        s               *
                   
              D dirent          ds                  based(p_dirent)
                   
              D   d_reserv1                   16A
                   D   d_reserv2                   10U 0
                   D   d_fileno                    10U 0
                   D   d_reclen                    10U 0
                   D   d_reserv3                   10I 0
                   D   d_reserv4                    8A
                   D   d_nlsinfo                   12A
                   D     nls_ccsid                 10I 0 OVERLAY
              (d_nlsinfo:1)
                   
              D     nls_cntry                  2A   OVERLAY(d_nlsinfo:5)
                   
              D     nls_lang                   3A   OVERLAY(d_nlsinfo:7)
                   
              D     nls_reserv                 3A   OVERLAY(d_nlsinfo:10)
                   
              D   d_namelen                   10U 0
                   D   d_name                     640A

                   D
              *------------------------------------------------------------
                   
              DOpen a Directory
                   D
              *
                   
              DDIR *opendir(const char *dirname)
                   
              D*
                   
              DNOTEWe are at V3R2so we can't use OPTIONS(*STRING)
                   D*------------------------------------------------------------
                   D opendir         PR              *   EXTPROC('
              opendir')
                   D  dirname                        *   VALUE

                   D*------------------------------------------------------------
                   D* Read Directory Entry
                   D*
                   D* struct dirent *readdir(DIR *dirp)
                   D*
                   D* NOTE: We are at V3R2, so we can'
              use OPTIONS(*STRING)
                   
              D*------------------------------------------------------------
                   
              D readdir         PR              *   EXTPROC('readdir')
                   
              D  dirp                           *   VALUE


                   D
              a few local variables...
                   
              D dh              S               *
                   
              D PathName        S            256A
                   D Name            S            256A


                   C
              Step1Open up the directory.
                   
              c                   eval      PathNamePATHTOLIST x'00'
                   
              C                   eval      dh opendir(%addr(PathName))
                   
              C                   if        dh = *NULL
                   c                   
              eval      Msg 'Cant open directory'
                   
              c                   dsply                   Msg              50
                   c                   
              eval      *INLR = *ON
                   c                   
              Return
                   
              c                   endif

                   
              CStep2Read each entry from the directory (in a loop)
                   
              c                   eval      p_dirent readdir(dh)
                   
              c                   dow       p_dirent <> *NULL

                   C
              FIXMEThis code can only handle file/dir names 256 bytes long
                   C
              *         because thats the size of "Name"
                   
              c                   if        d_namelen 256
                   c                   
              eval      Name = %subst(d_name:1:d_namelen)
                   
              c                   movel     Name          dsply_me         52
                   c     dsply_me      dsply
                   c                   
              endif

                   
              c                   eval      p_dirent readdir(dh)
                   
              c                   enddo

                   C
              Step3End Program
                   c     
              'The End'     dsply                   Pause             1
                   c                   
              eval      *inlr = *On 
              Attached Files
              All my answers were extracted from the "Big Dummy's Guide to the As400"
              and I take no responsibility for any of them.

              www.code400.com

              Comment


              • #8
                Re: display all tables in IFS directory

                DSPLY .
                DSPLY ..
                DSPLY RA2.TXT
                DSPLY RA.TXT
                DSPLY RA1.TXT
                Now it works. I was missing the number 1 after %subst(d_name:1:d_namelen). Now if I only understood what this code is doing. I mean I understand most of it it's just the variables and the directory entry structure that confuses me. Now instead of displaying the contents of the directory to a screen can I use the field called name in my CPYFRMSTMF statement? Can I put the CPYFRMSTMF right in this program or do I have to call a cl program passing the name field as a parm? I'm just learning the powers of RPGLE programming can you tell?

                Comment


                • #9
                  Re: display all tables in IFS directory

                  scan the forum for cmdstring or cmdlength
                  then borrow the code that uses this

                  there will be a call to 'QCMDEXC'

                  you will have to build your cmdstring inside the RPG program using +
                  there are many examples posted...

                  keep us informed.
                  All my answers were extracted from the "Big Dummy's Guide to the As400"
                  and I take no responsibility for any of them.

                  www.code400.com

                  Comment


                  • #10
                    Re: display all tables in IFS directory

                    Ok thanks! I'll keep you posted.

                    Comment


                    • #11
                      Re: display all tables in IFS directory

                      because its v-day and just cause
                      here ya go

                      PHP Code:
                           D PATHTOLIST      C                   CONST('/ediin/edi820/')

                           
                      D*
                           
                      DDirectory Entry Structure (dirent)
                           
                      D*
                           
                      D*
                           
                      D p_dirent        s               *
                           
                      D dirent          ds                  based(p_dirent)
                           
                      D   d_reserv1                   16A
                           D   d_reserv2                   10U 0
                           D   d_fileno                    10U 0
                           D   d_reclen                    10U 0
                           D   d_reserv3                   10I 0
                           D   d_reserv4                    8A
                           D   d_nlsinfo                   12A
                           D     nls_ccsid                 10I 0 OVERLAY
                      (d_nlsinfo:1)
                           
                      D     nls_cntry                  2A   OVERLAY(d_nlsinfo:5)
                           
                      D     nls_lang                   3A   OVERLAY(d_nlsinfo:7)
                           
                      D     nls_reserv                 3A   OVERLAY(d_nlsinfo:10)
                           
                      D   d_namelen                   10U 0
                           D   d_name                     640A

                           D
                      *------------------------------------------------------------
                           
                      DOpen a Directory
                           D
                      *
                           
                      DDIR *opendir(const char *dirname)
                           
                      D*
                           
                      DNOTEWe are at V3R2so we can't use OPTIONS(*STRING)
                           D*------------------------------------------------------------
                           D opendir         PR              *   EXTPROC('
                      opendir')
                           D  dirname                        *   VALUE

                           D*------------------------------------------------------------
                           D* Read Directory Entry
                           D*
                           D* struct dirent *readdir(DIR *dirp)
                           D*
                           D* NOTE: We are at V3R2, so we can'
                      use OPTIONS(*STRING)
                           
                      D*------------------------------------------------------------
                           
                      D readdir         PR              *   EXTPROC('readdir')
                           
                      D  dirp                           *   VALUE


                           D
                      a few local variables...
                           
                      D dh              S               *
                           
                      D PathName        S            256A
                           D Name            S            256A

                           D cmdstring       S            256A
                           D cmdlength       S             15  5
                           D Q               S              1    inz
                      ('''')

                           
                      CStep1Open up the directory.
                           
                      c                   eval      PathNamePATHTOLIST x'00'
                           
                      C                   eval      dh opendir(%addr(PathName))
                           
                      C                   if        dh = *NULL
                           c                   
                      eval      Msg 'Cant open directory'
                           
                      c                   dsply                   Msg              50
                           c                   
                      eval      *INLR = *ON
                           c                   
                      Return
                           
                      c                   endif

                           
                      CStep2Read each entry from the directory (in a loop)
                           
                      c                   eval      p_dirent readdir(dh)
                           
                      c                   dow       p_dirent <> *NULL

                           C
                      FIXMEThis code can only handle file/dir names 256 bytes long
                           C
                      *         because thats the size of "Name"
                           
                      c                   if        d_namelen 256
                           c                   
                      eval      Name = %subst(d_name:1:d_namelen)
                            *
                            *  
                      CPYFRMSTMF FROMSTMF('/ediin/edi820/RAxxx.txt')
                            *  
                      TOMBR('/qsys.lib/jamielib.lib/edi820.file/edi820.mbr')
                            *  
                      MBROPT(*REPLACESTMFCODPAG(*PCASCII)
                            *
                           
                      c                   if        %scan('.TXT' name) > *zeros
                            
                      *
                           
                      c                   eval      cmdstring 'CPYFRMSTMF FROMSTMF(' +
                           
                      c                             Q '/ediin/edi820/' + %trim(name) +
                           
                      c                             Q ') TOMBR(' '/qsys.lib/' +
                           
                      c                             'jamielib.lib/edi820.file/edi820.mbr' +
                           
                      c                             Q ') MBROPT(*REPLACE) STMFCODPAG(*PCASCII)'
                           
                      c                   eval      cmdlength = %len(%trim(cmdstring))
                           
                      c                   call(e)   'QCMDEXC'
                           
                      c                   parm                    cmdstring
                           c                   parm                    cmdlength
                           c                   
                      endif

                           
                      c                   endif

                           
                      c                   eval      p_dirent readdir(dh)
                           
                      c                   enddo

                           C
                      Step3End Program
                           c                   
                      eval      *inlr = *On 
                      Attached Files
                      All my answers were extracted from the "Big Dummy's Guide to the As400"
                      and I take no responsibility for any of them.

                      www.code400.com

                      Comment


                      • #12
                        Re: display all tables in IFS directory

                        This works awesome. Do you know why it writes a blank record to the file?

                        Record# ....5...10...15...20...25.
                        1 10701294826690000000122712
                        2 10701294845350000000086479
                        3 10701294848870000000032569
                        4 10701294826720000000059166
                        5 10701294837060000000649740
                        6 10701294847570000000012154
                        7 10701294825620000000127700
                        8 10701294825640000000012770
                        9 
                        10 10701294826690000000122712
                        11 10701294845350000000086479
                        12 10701294848870000000032569

                        1=Help F2=ON/OFF F=keys F3=Ex

                        Comment


                        • #13
                          Re: display all tables in IFS directory

                          That is the end of file *CHAR it can be identified by its HEX value and removed from the file -- or skiped durring processing....let me know if I can help you with this.

                          jamie
                          All my answers were extracted from the "Big Dummy's Guide to the As400"
                          and I take no responsibility for any of them.

                          www.code400.com

                          Comment


                          • #14
                            Re: display all tables in IFS directory

                            How can I remove it from the file and can I do this step in the same rpgle program as the cpyfrmstmf is being done? Along with the cpyfrmstmf statement I have added more needed statements to the program thanks to you for example (rmvlnk,clrpfm,cpyf) all the commands I would normally do in a cl program. I find this amazing! I am so grateful for you knowledge. I've learned alot. I would also like to do a cpydoc statement in this program so I have a backup copy of the edi 820 text files in case something goes wrong with the upload but when I try to do this command on a command line I get this error message....
                            Bottom
                            Parameters or command
                            ===> CPYDOC FROMDOC(RA.TXT) FROMFLR('/ediin/edi820') TOFLR('/ediin/edisv') ...
                            F3=Exit F4=Prompt F5=Refresh F6=Create
                            F9=Retrieve F10=Command entry F23=More options F24=More keys
                            Folder name not correct. +

                            Comment


                            • #15
                              Re: display all tables in IFS directory

                              lets wait another day to remove that from the file but here is the program with
                              mods to create a backup directory on the IFS and MOVE the file being processed
                              to it.

                              PHP Code:
                              ~
                                   
                              D PATHTOLIST      C                   CONST('/ediin/edi820/')

                                   
                              D*
                                   
                              DDirectory Entry Structure (dirent)
                                   
                              D*
                                   
                              D*
                                   
                              D p_dirent        s               *
                                   
                              D dirent          ds                  based(p_dirent)
                                   
                              D   d_reserv1                   16A
                                   D   d_reserv2                   10U 0
                                   D   d_fileno                    10U 0
                                   D   d_reclen                    10U 0
                                   D   d_reserv3                   10I 0
                                   D   d_reserv4                    8A
                                   D   d_nlsinfo                   12A
                                   D     nls_ccsid                 10I 0 OVERLAY
                              (d_nlsinfo:1)
                                   
                              D     nls_cntry                  2A   OVERLAY(d_nlsinfo:5)
                                   
                              D     nls_lang                   3A   OVERLAY(d_nlsinfo:7)
                                   
                              D     nls_reserv                 3A   OVERLAY(d_nlsinfo:10)
                                   
                              D   d_namelen                   10U 0
                                   D   d_name                     640A

                                   D
                              *------------------------------------------------------------
                                   
                              DOpen a Directory
                                   D
                              *
                                   
                              DDIR *opendir(const char *dirname)
                                   
                              D*
                                   
                              DNOTEWe are at V3R2so we can't use OPTIONS(*STRING)
                                   D*------------------------------------------------------------
                                   D opendir         PR              *   EXTPROC('
                              opendir')
                                   D  dirname                        *   VALUE

                                   D*------------------------------------------------------------
                                   D* Read Directory Entry
                                   D*
                                   D* struct dirent *readdir(DIR *dirp)
                                   D*
                                   D* NOTE: We are at V3R2, so we can'
                              use OPTIONS(*STRING)
                                   
                              D*------------------------------------------------------------
                                   
                              D readdir         PR              *   EXTPROC('readdir')
                                   
                              D  dirp                           *   VALUE


                                   D
                              a few local variables...
                                   
                              D dh              S               *
                                   
                              D PathName        S            256A
                                   D Name            S            256A

                                   D cmdstring       S            256A
                                   D cmdlength       S             15  5
                                   D Q               S              1    inz
                              ('''')

                                   
                              CStep1Open up the directory.
                                   
                              c                   eval      PathNamePATHTOLIST x'00'
                                   
                              C                   eval      dh opendir(%addr(PathName))
                                   
                              C                   if        dh = *NULL
                                   c                   
                              eval      Msg 'Cant open directory'
                                   
                              c                   dsply                   Msg              50
                                   c                   
                              eval      *INLR = *ON
                                   c                   
                              Return
                                   
                              c                   endif

                                   
                              CStep2Read each entry from the directory (in a loop)
                                   
                              c                   eval      p_dirent readdir(dh)
                                   
                              c                   dow       p_dirent <> *NULL

                                   C
                              FIXMEThis code can only handle file/dir names 256 bytes long
                                   C
                              *         because thats the size of "Name"
                                   
                              c                   if        d_namelen 256
                                   c                   
                              eval      Name = %subst(d_name:1:d_namelen)
                                    *
                                    *  
                              CPYFRMSTMF FROMSTMF('/ediin/edi820/RAxxx.txt')
                                    *  
                              TOMBR('/qsys.lib/jamielib.lib/edi820.file/edi820.mbr')
                                    *  
                              MBROPT(*REPLACESTMFCODPAG(*PCASCII)
                                    *
                                   
                              c                   if        %scan('.TXT' name) > *zeros
                                    
                              *
                                   
                              c                   eval      cmdstring 'CPYFRMSTMF FROMSTMF(' +
                                   
                              c                             Q '/ediin/edi820/' + %trim(name) +
                                   
                              c                             Q ') TOMBR(' '/qsys.lib/' +
                                   
                              c                             'jamielib.lib/edi820.file/edi820.mbr' +
                                   
                              c                             Q ') MBROPT(*REPLACE) STMFCODPAG(*PCASCII)'
                                   
                              c                   eval      cmdlength = %len(%trim(cmdstring))
                                   
                              c                   call(e)   'QCMDEXC'
                                   
                              c                   parm                    cmdstring
                                   c                   parm                    cmdlength
                                    
                              *
                                    * 
                              make the backup directory it will only create this directory once
                                    
                              then the program will set %error and continue to run
                                    
                              *
                                   
                              c                   eval      cmdstring 'MD /ediin/backups'
                                   
                              c                   eval      cmdlength = %len(%trim(cmdstring))
                                   
                              c                   call(e)   'QCMDEXC'
                                   
                              c                   parm                    cmdstring
                                   c                   parm                    cmdlength
                                    
                              *
                                    *  
                              now move the document to the backup directory
                                    
                              *  MOV OBJ('/ediin/edi820/RAxxx.TXT'TODIR('/ediin/backups/')
                                    *
                                   
                              c                   eval      cmdstring 'MOV OBJ(' +
                                   
                              c                             Q '/ediin/edi820/' + %trim(name) +
                                   
                              c                             Q ') TODIR(' '/ediin/backups/' +
                                   
                              c                             Q ') '
                                   
                              c                   eval      cmdlength = %len(%trim(cmdstring))
                                   
                              c                   call(e)   'QCMDEXC'
                                   
                              c                   parm                    cmdstring
                                   c                   parm                    cmdlength
                                    
                              *
                                   
                              c                   endif

                                   
                              c                   endif

                                   
                              c                   eval      p_dirent readdir(dh)
                                   
                              c                   enddo

                                   C
                              Step3End Program
                                   c                   
                              eval      *inlr = *On 
                              Attached Files
                              All my answers were extracted from the "Big Dummy's Guide to the As400"
                              and I take no responsibility for any of them.

                              www.code400.com

                              Comment

                              Working...
                              X