必须从生产主表中删除记录

时间:2013-08-11 02:34:56

标签: ibm-midrange rpg

此代码是一个清除程序。我们希望清除那些从未订购过任何东西的客户(如果某人是'潜在'客户,他们会保留记录。)

这将首先在测试环境中运行但最终不会生产。我们将创建临时文件作为备份。我不知道怎么做删除。我认为此时需要:如果找不到订单实体,请将记录写入TRCMASAC文件

C                   IF        NOT %FOUND(OEORH4)
C                   WRITE     TRCMASRR
 * Delete? file name or format name

以下是代码:

FXRCMASAC  IF   E             DISK                            
  * Order Header file - Keyed by Company and entity number     
FOEORH4    IF   E           K DISK                            
FTRCMA1    UF A E           K DISK                                 
 * Customer Keycode BI file                                        
FZRCST1    IF   E           K DISK                                 
 * Output file - Customers who have no Keycode  - VRCSTKBI PF      
FVRCST1    UF A E           K DISK                                 
 * Address  Master file - xDRESSAD PF                              
FXDRES1    IF   E           K DISK                                 
 * Output file - Address  - ZDRESSAD PF                            
FZDRES1    UF A E           K DISK                                 

 *-----------------------------------------------------------------
 * Calculation Specification                                       
 *-----------------------------------------------------------------
 * Step 1                                                          
C                   READ      xRCMASAC                             
C                   DOW       NOT %EOF                             
 *                                                                 
 * Check the record does not exist in order header file            
C                   EXSR      CHKORH_SR                            
C                   READ      xRCMASAC                           
C                   ENDDO                                        

 * Step 2 and 3                                                  
C     *LOVAL        SETLL     TRCMA1                             
C                   READ(N)   TRCMA1                             
C                   DOW       NOT %EOF                           
 * limit number of records for test                              
c     counta        ifge      9000                               
C                   EVAL      *INLR = *ON                        
c                   leave                                        
c                   endif                                        
c     countz        ifge      9000                               
C                   EVAL      *INLR = *ON                        
c                   leave                                        
c                   endif                                        
 * Check the record does not exist in stock header file          
C                   EXSR      CHKCUS_SR                          
 *                                                               
C                   EXSR      CHKADR_SR                               
 *                                                                    
 * Read the next record                                               
C                   READ(N)   TRCMA1                                  
C                   ENDDO                                             

 *-----------------------------------------------------------------   
 * End of the Program                                                 
 *-----------------------------------------------------------------   
C                   EVAL      *INLR = *ON                             

 *-----------------------------------------------------------------   
 * Check the order header entity                                      
 *-----------------------------------------------------------------   
C     CHKORH_SR     BEGSR                                             
 *                                                                    
C     ORHKEY        CHAIN     OEORH4                                  
 * If the order entity is notfound, write the rec into TRCMASAC file  
C                   IF        NOT %FOUND(OEORH4)                      
C                   WRITE     TRCMASRR                           
C                   ENDIF                                           
 *                                                                  
C                   ENDSR                                           
 *----------------------------------------------------------------- 
 * Check the customer keycode entity                                
 *----------------------------------------------------------------- 
C     CHKCUS_SR     BEGSR                                           
 *                                                                  
C     ORHKEY        CHAIN     ZRCST1                                
 * If the order entity is found, write the rec into VRCSTKBI file   
C                   IF        %FOUND(ZRCST1)                        
C                   WRITE     VRCSTKRR                              
c                   add       1             countz            500   
C                   ENDIF                                           
 *                                                                  
C                   ENDSR                                           

 *----------------------------------------------------------------- 
 * Check the address entity for records of never ordered            
C     CHKADR_SR     BEGSR                                         
 *                                                                
C     ACENT#        CHAIN     ADRES1                              
 * If the order entity is found, write the rec into ZDRESSRR file 
C                   IF        %FOUND(ADRES1)                      
C                   WRITE     ZDRESSRR                            
c                   add       1             counta            500 
C                   ENDIF                                         
 *                                                                
C                   ENDSR                                         

 *----------------------------------------------------------------
 * Program Initialization Subroutine                              
 *----------------------------------------------------------------
C     *INZSR        BEGSR                                         
 *                                                                
 * ORDER HEADER KEYLIST                                           
C     ORHKEY        KLIST                                         
C                   KFLD                    ACCOM#                
C                   KFLD                    ACENT#                

c                   z-add     0             counta               
c                   z-add     0             countz               
 *                                                               
 * Clear TRCMASAC file data                                      
C     *LOVAL        SETLL     TRCMA1                             
C                   READ      TRCMA1                             
C                   DOW       NOT %EOF                           
C                   DELETE    TRCMASRR                           
 * Read the next record                                          
C                   READ      TRCMA1                             
C                   ENDDO                                        
 *                                                               
 * Clear VRCSTKBI file data                                      
C     *LOVAL        SETLL     VRCST1                             
C                   READ      VRCST1                             
C                   DOW       NOT %EOF                           
C                   DELETE    VRCSTKRR                           
 * Read the next record                                          
C                   READ      VRCST1                             

C                   ENDDO                      
 *                                             
 * Clear ZDRESSAD file data                    
C     *LOVAL        SETLL     ZDRES1           
C                   READ      ZDRES1           
C                   DOW       NOT %EOF         
C                   DELETE    ZDRESSRR         
 * Read the next record                        
C                   READ      ZDRES1           
C                   ENDDO
 *
C                   ENDSR

1 个答案:

答案 0 :(得分:2)

是的,在您将副本写入TRCMASRR后,您将删除该记录:

C                   DELETE    OEORH4R

您需要删除记录格式名称,而不是文件名。在上面的代码中,我假设OEORH4中的记录格式名称为OEORH4R

我的猜测是,您还希望删除与您要删除的客户记录相关的所有地址等。否则你最终会有“孤儿”......

此外,在*INZSR我建议您以更有效的方式清除文件。像这样制作TRCMA1VRCST1ZDRES1 USROPN个文件:

FTRCMA1    UF A E           K DISK  USROPN
FVRCST1    UF A E           K DISK  USROPN
FZDRES1    UF A E           K DISK  USROPN

然后使用QCMDEXC执行CLRPFM *LIBL/TRCMA1CLRPFM *LIBL/VRCST1CLRPFM *LIBL/ZDRES1。当然,之后你必须OPEN这三个文件。

这比单独删除每条记录要快,并且根据文件的设置方式也可能有其他一些好处。