H DFTACTGRP(*NO) BNDDIR('ERPGSDK')                                                             
      **********************************************************************                        
     FCATMST1   IF   E           K DISK    USROPN                                                   
     FCATMST2   IF   E           K DISK    USROPN RENAME(RCATMST:RCATMST2)                          
     FCATSTR1   IF   E           K DISK    USROPN                                                   
      ****************************************************************                              
      * Prototypes                                                   *                              
      ****************************************************************                              
      /COPY QCOPYSRC,P.ERPGSDK                                                                      
      /COPY QCOPYSRC,P.STRING                                                                       
      ****************************************************************                              
     D DftPath         S             64    INZ('/www/erpgsdk/catalog+                               
     D                                          /templates/')                                       
      *                                                                                             
      * Data read in from Web Page                                                                  
     D cat             S                   Like(CMCAT)                                              
      *                                                                                             
      * Work variables                                                                              
     D CatArr          S              5  0 DIM(9999)                                                
      *                                                                                             
     D CatString       S           4096                                                             
     D CatPath         S           1024                                                             
     D CatCount        S             10i 0                                                          
     D LastCat         S              5  0                                                          
     D TempCat         S              5  0                                                          
     D i               S             10i 0                                                          
     D CatKey          S                   Like(CMMAIN) Inz('Y')                                    
     D DidWrite        S               N                                                            
     D WriteFlag       S               N                                                            
      **********************************************************************                        
     C                   callp     #startup                                                         
      *                                                                                             
     C                   EXSR      $Input                                                           
      *                                                                                             
     C                   callp     #setPath(DftPath)                                                
     C                   callp     #loadTemplate('cat0001.erpg')                                    
      *                                                                                             
     C                   EXSR      $First                                                           
      *                                                                                             
     C                   if        (CatCount <= 0)                                                  
     C                   EXSR      $ListCats                                                        
     C                   else                                                                       
     C                   EXSR      $ListSubs                                                        
     C                   endif                                                                      
      *                                                                                             
     C                   callp     #cleanup                                                         
      *                                                                                             
     C                   SETON                                        LR                            
      ****************************************************************                              
      * First                                                        *                              
      ****************************************************************                              
     C     $First        BEGSR                                                                      
      *                                                                                             
     C                   if        (CatCount <= 0)                                                  
     C                   eval      CatString = 'Select a catalog...'                                
     C                   else                                                                       
     C                   OPEN      CATMST1                                                          
      *                                                                                             
     C                   do        CatCount      i                                                  
      *                                                                                             
     C                   if        (i > 1)                                                          
     C                   eval      CatString = %trim(CatString) +                                   
     C                                         '-->'                                                
     C                   endif                                                                      
      *                                                                                             
     C                   eval      TempCat = CatArr(i)                                              
     C     TempCat       CHAIN     CATMST1                                                          
      *                                                                                             
     C                   if        (not %found(CATMST1))                                            
     C                   eval      CMDESC = 'Not Found!'                                            
     C                   endif                                                                      
      *                                                                                             
     C                   eval      CatString = %trim(CatString) +                                   
     C                                       %trim(CMDESC)                                          
     C                   eval      CatPath = %trim(CatPath) +                                       
     C                                       'cat=' +                                               
     C                                       %trim(%editc(CatArr(i):'Z')) +                         
     C                                       '&'                                                    
     C                   enddo                                                                      
      *                                                                                             
     C                   CLOSE     CATMST1                                                          
     C                   endif                                                                      
      *                                                                                             
     C                   callp     #loadSection('first')                                            
     C                   callp     #replaceData('/%catstring%/':CatString)                          
     C                   callp     #writeSection                                                    
      *                                                                                             
     C                   ENDSR                                                                      
      ****************************************************************                              
      * List Main Catalogs                                           *                              
      ****************************************************************                              
     C     $ListCats     BEGSR                                                                      
      *                                                                                             
     C                   OPEN      CATMST2                              99                          
      *                                                                                             
     C                   if        (not *IN99)                                                      
      *                                                                                             
     C     CatKey        SETLL     CATMST2                                                          
     C     CatKey        READE     CATMST2                                                          
      *                                                                                             
     C                   dow       (not %eof(CATMST2))                                              
     C                   EXSR      $CatCheck                                                        
     C                   EXSR      $CatCell                                                         
     C     CatKey        READE     CATMST2                                                          
     C                   enddo                                                                      
      *                                                                                             
     C                   EXSR      $CatLast                                                         
      *                                                                                             
     C                   CLOSE     CATMST2                                                          
     C                   else                                                                       
     C                   callp     #writeThisSec('fileerror')                                       
     C                   endif                                                                      
      *                                                                                             
     C                   ENDSR                                                                      
      ****************************************************************                              
      * List Sub Catalogs                                            *                              
      ****************************************************************                              
     C     $ListSubs     BEGSR                                                                      
      *                                                                                             
     C                   OPEN      CATMST1                              99                          
     C                   OPEN      CATSTR1                              98                          
      *                                                                                             
     C                   if        (not *IN99) and (not *IN98)                                      
      *                                                                                             
     C     LastCat       SETLL     CATSTR1                                                          
     C     LastCat       READE     CATSTR1                                                          
      *                                                                                             
     C                   dow       (not %eof(CATSTR1))                                              
     C                   EXSR      $CatCheck                                                        
      *                                                                                             
     C     CSSUBCAT      CHAIN     CATMST1                                                          
      *                                                                                             
     C                   if        (not %found(CATMST1))                                            
     C                   eval      CMCAT = CSSUBCAT                                                 
     C                   eval      CMDESC = 'Not Found!'                                            
     C                   endif                                                                      
      *                                                                                             
     C                   EXSR      $CatCell                                                         
     C     LastCat       READE     CATSTR1                                                          
     C                   enddo                                                                      
      *                                                                                             
     C                   EXSR      $CatLast                                                         
      *                                                                                             
     C                   CLOSE     CATMST1                                                          
     C                   CLOSE     CATSTR1                                                          
     C                   else                                                                       
     C                   callp     #writeThisSec('fileerror')                                       
     C                   endif                                                                      
      *                                                                                             
     C                   ENDSR                                                                      
      ****************************************************************                              
      * Check for Writing of Catalog Headers                         *                              
      ****************************************************************                              
     C     $CatCheck     BEGSR                                                                      
      *                                                                                             
     C                   if        (not DidWrite)                                                   
     C                   callp     #writeThisSec('catfirst')                                        
     C                   endif                                                                      
      *                                                                                             
     C                   if        (not WriteFlag)                                                  
     C                   callp     #writeThisSec('catlist1')                                        
     C                   endif                                                                      
      *                                                                                             
     C                   ENDSR                                                                      
      ****************************************************************                              
      * Write a Catalog Cell                                         *                              
      ****************************************************************                              
     C     $CatCell      BEGSR                                                                      
      *                                                                                             
     C                   callp     #loadSection('catcell')                                          
     C                   callp     #replaceData('/%catdesc%/':CMDESC)                               
     C                   callp     #replaceData('/%catpath%/':                                      
     C                                        %trim(catpath) +                                      
     C                                        'cat=' +                                              
     C                                        %trim(%editc(CMCAT:'Z')))                             
     C                   callp     #writeSection                                                    
      *                                                                                             
     C                   if        (WriteFlag)                                                      
     C                   callp     #writeThisSec('catlist2')                                        
     C                   endif                                                                      
      *                                                                                             
     C                   eval      DidWrite = *ON                                                   
     C                   eval      WriteFlag = not WriteFlag                                        
      *                                                                                             
     C                   ENDSR                                                                      
      ****************************************************************                              
      * Write End of Catalog Data                                    *                              
      ****************************************************************                              
     C     $CatLast      BEGSR                                                                      
      *                                                                                             
     C                   if        (WriteFlag) and (DidWrite)                                       
     C                   callp     #writeThisSec('catlist2')                                        
     C                   endif                                                                      
      *                                                                                             
     C                   if        (DidWrite)                                                       
     C                   callp     #writeThisSec('catlast')                                         
     C                   endif                                                                      
      *                                                                                             
     C                   ENDSR                                                                      
      ****************************************************************                              
      * Read Input from web page                                     *                              
      ****************************************************************                              
     C     $Input        BEGSR                                                                      
      *                                                                                             
     C                   eval      i = 1                                                            
     C                   eval      cat = #CtoN(#getData('cat':i))                                   
      *                                                                                             
     C                   dow       (cat <> 0)                                                       
     C                   eval      CatCount = (CatCount + 1)                                        
     C                   eval      CatArr(CatCount) = cat                                           
     C                   eval      LastCat = cat                                                    
     C                   eval      i = (i + 1)                                                      
     C                   eval      cat = #CtoN(#getData('cat':i))                                   
     C                   enddo                                                                      
      *                                                                                             
     C                   ENDSR