midrange.com code scratchpad
Name:
Recieve Journal Entry for IFS Object
Scriptlanguage:
Plain Text
Tabwidth:
4
Date:
08/10/2012 01:36:54 pm
IP:
Logged
Description:
Exit program called by operating system when journal
entries are added to a journal. This occurs because
an IFS folder is journaled and each time files are
added to a folder. Command RCVJRNE runs in a submitted
job and sets up what needs to captured and the exit
program.
RCVJRNE JRN(EPINS) EXITPGM(XBGETJRNE) JRNCDE((B))
ENTTYP(JT) ENTFMT(*TYPE1)

This was originaly written by Alan Campin
Code:
  1.       * ---------------------------------------------------------------                             
  2.       * Module.: XV0015_M01           Project.....:                                                 
  3.       * Author.: A. Campin            Date written: 11/21/2006                                      
  4.       * Purpose: Exit program called by operating system when journal                               
  5.       *            entries are added to a journal. This occurs because                              
  6.       *            an IFS folder is journaled and each time files are                               
  7.       *            added to a folder. Command RCVJRNE runs in a submitted                           
  8.       *            job and sets up what needs to captured and the exit                              
  9.       *            program.                                                                         
  10.       *            RCVJRNE JRN(EPINS) EXITPGM(XBGETJRNE) JRNCDE((B))                                
  11.       *               ENTTYP(JT) ENTFMT(*TYPE1)                                                     
  12.       * ---------------------------------------------------------------                             
  13.       * Called by: Operating System.                                                                
  14.       * ---------------------------------------------------------------                             
  15.       * Revision history:                                                                           
  16.       *  Project # Pgmr    Date    Desc                                                             
  17.       *            AGC  07/18/2007 Add code in ProcessRequest to ignore                             
  18.       *                              blank file name. We end up with a JT                           
  19.       *                              when a folder is journaled so we want to                       
  20.       *                              ignore blank file names.                                       
  21.       *                            Also change logic on GetPathPieces to look                       
  22.       *                              for a period in the file name. In this way                     
  23.       *                              we can find if a file name was passed.                         
  24.       * End Revision History                                                                        
  25.       * ---------------------------------------------------------------                             
  26.      H Option(*Srcstmt:*Nodebugio)                                                                  
  27.      H DftActGrp(*No) ActGrp(*Caller)                                                               
  28.      H Debug                                                                                        
  29.                                                                                                     
  30.       // E-Pins File Name Control                                                                   
  31.      FVXbEpFile IF A E           K Disk                                                             
  32.                                                                                                     
  33.       /Copy *Libl/QCopyBks,CB_StdType                                                               
  34.                                                                                                     
  35.       /Copy *Libl/QCopyBks,Cb_Std_Con                                                               
  36.                                                                                                     
  37.      D ProgramEntrance...                                                                           
  38.      D                 PR                  ExtPgm('XBGETJRNE')                                      
  39.      D  PR_InJournalEntry...                                                                        
  40.      D                                     LikeDs(TD_JournalEntry)                                  
  41.      D  PR_InRunStatus...                                                                           
  42.      D                                     LikeDs(TD_RunStatus)                                     
  43.                                                                                                     
  44.      D ProcessRequest...                                                                            
  45.      D                 PR                                                                           
  46.                                                                                                     
  47.      D GetPathPieces...                                                                             
  48.      D                 PR                                                                           
  49.      D   PR_InFullPath...                                                                           
  50.      D                              256A   Varying                                                  
  51.      D                                     Const                                                    
  52.      D   PR_OutPath...                                                                              
  53.      D                              256A   Varying                                                  
  54.      D   PR_OutFileName...                                                                          
  55.      D                              128A   Varying                                                  
  56.      D*--------------------------------------------------                                           
  57.      D* Procedure name: Submit_Job                                                                  
  58.      D* Purpose:        Submit job to process received file                                         
  59.      D* Returns:                                                                                    
  60.      D* Parameter:      Path => Path Name                                                           
  61.      D* Parameter:      File_Name => File Name to Process                                           
  62.      P* Parameter:      Process_Type => Action Required                                             
  63.      P*--------------------------------------------------                                           
  64.      D Submit_Job      PR                                                                           
  65.      D  Path                         20A                                                            
  66.      D  File_Name                    30A                                                            
  67.      D  Process_Type                  5A                                                            
  68.                                                                                                     
  69.                                                                                                     
  70.      D  cNoEntry...                                                                                 
  71.      D                 c                   '0'                                                      
  72.      D  cSingleEntry...                                                                             
  73.      D                 c                   '1'                                                      
  74.      D  cBlockEntry...                                                                              
  75.      D                 c                   '2'                                                      
  76.      D  cReceiveChangedEnd...                                                                       
  77.      D                 c                   '3'                                                      
  78.      D  cBeginBlockMode...                                                                          
  79.      D                 c                   '8'                                                      
  80.      D  cEndReceiveJournalEntry...                                                                  
  81.      D                 c                   '9'                                                      
  82.                                                                                                     
  83.        // *Type One Journal Entry                                                                   
  84.      D TD_JournalEntry...                                                                           
  85.      D                 ds                  Qualified                                                
  86.      D                                     Based(StdNulPtr)                                         
  87.      D   EntryLength...                                                                             
  88.      D                                5s 0                                                          
  89.      D   SequenceNumber...                                                                          
  90.      D                               10s 0                                                          
  91.      D   JournalCode...                                                                             
  92.      D                                     Like(Stdchr)                                             
  93.      D   EntryType...                                                                               
  94.      D                                2a                                                            
  95.      D   Date...                                                                                    
  96.      D                                6a                                                            
  97.      D   Time...                                                                                    
  98.      D                                6s 0                                                          
  99.      D   JobName...                                                                                 
  100.      D                                     Like(StdNam)                                             
  101.      D   UserName...                                                                                
  102.      D                                     Like(StdNam)                                             
  103.      D   JobNumber...                                                                               
  104.      D                                6s 0                                                          
  105.      D   ProgramName...                                                                             
  106.      D                                     Like(StdNam)                                             
  107.      D   NamePlusLibrary...                                                                         
  108.      D                               20a                                                            
  109.      D     ObjectName...                                                                            
  110.      D                                     Like(StdNam)                                             
  111.      D                                     Overlay(NamePlusLibrary)                                 
  112.      D     ObjectLibrary...                                                                         
  113.      D                                     Like(StdNam)                                             
  114.      D                                     Overlay(NamePlusLibrary:                                 
  115.      D                                             *Next          )                                 
  116.      D     FileId...                                                                                
  117.      D                               16a   Overlay(NamePlusLibrary)                                 
  118.      D   MemberName...                                                                              
  119.      D                                     Like(StdNam)                                             
  120.      D   Count_Relative...                                                                          
  121.      D                               10s 0                                                          
  122.      D   IndicatorFlag...                                                                           
  123.      D                                     Like(StdChr)                                             
  124.      D   CommitCycleId...                                                                           
  125.      D                               10s 0                                                          
  126.      D   InCompleteData...                                                                          
  127.      D                                     Like(StdChr)                                             
  128.      D   MinimizedEntry...                                                                          
  129.      D                                     Like(StdChr)                                             
  130.      D   Reserved1...                                                                               
  131.      D                                6a                                                            
  132.                                                                                                     
  133.      D TD_RunStatus...                                                                              
  134.      D                 ds                  Qualified                                                
  135.      D                                     Based(StdNulPtr)                                         
  136.      D    Control...                                                                                
  137.      D                                     Like(StdChr)                                             
  138.      D    Available...                                                                              
  139.      D                                     Like(StdChr)                                             
  140.      D    WhatPassed...                                                                             
  141.      D                                     Like(StdChr)                                             
  142.                                                                                                     
  143.      D LastSequenceUsed...                                                                          
  144.      D                 s             10p 0 DtaAra(XVLASTSEQ)                                        
  145.                                                                                                     
  146.      D ProgramEntrance...                                                                           
  147.      D                 pi                                                                           
  148.      D   InJournalEntry...                                                                          
  149.      D                                     LikeDs(TD_JournalEntry)                                  
  150.      D   InRunStatus...                                                                             
  151.      D                                     LikeDs(TD_RunStatus)                                     
  152.                                                                                                     
  153.       /Free                                                                                         
  154.                                                                                                     
  155.        // Return if dummy entry. For some reason, OS calls twice. Once                              
  156.        //   real and once empty data.                                                               
  157.        If InRunStatus.Control = cNoEntry;                                                           
  158.          Return;                                                                                    
  159.        EndIf;                                                                                       
  160.                                                                                                     
  161.        // Get last sequence number and see if this number has been                                  
  162.        //  processed before.                                                                        
  163.        In *Lock LastSequenceUsed;                                                                   
  164.                                                                                                     
  165.        // Protect against sequence number being reset. For unknown                                  
  166.        //  reasons, IBM resets sequence numbers back when creating                                  
  167.        //  a new journal receiver.                                                                  
  168.        If InJournalEntry.SequenceNumber < LastSequenceUsed;                                         
  169.          LastSequenceUsed = InJournalEntry.SequenceNumber - 1;                                      
  170.        EndIf;                                                                                       
  171.                                                                                                     
  172.        If InJournalEntry.SequenceNumber > LastSequenceUsed;                                         
  173.          LastSequenceUsed = InJournalEntry.SequenceNumber;                                          
  174.          Out LastSequenceUsed;                                                                      
  175.        Else;                                                                                        
  176.          Unlock LastSequenceUsed;                                                                   
  177.          Return;                                                                                    
  178.        EndIf;                                                                                       
  179.                                                                                                     
  180.        ProcessRequest();                                                                            
  181.                                                                                                     
  182.        Return;                                                                                      
  183.                                                                                                     
  184.       /End-Free                                                                                     
  185.       * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -                         
  186.       * ProcessRequest                                                                              
  187.       *   Process Request.                                                                          
  188.       *   Input       - None.                                                                       
  189.       *   Out         - None.                                                                       
  190.       *   Returns     - None.                                                                       
  191.       * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -                         
  192.      P ProcessRequest...                                                                            
  193.      P                 B                                                                            
  194.      D                 PI                                                                           
  195.                                                                                                     
  196.      D GetPathAPI...                                                                                
  197.      D                 PR                  ExtProc('Qp0lGetPathFromFileID')                         
  198.      D                                     Like(StdPtr)                                             
  199.      D  PR_OutPathName...                                                                           
  200.      D                              256A                                                            
  201.      D  PR_InPathSize...                                                                            
  202.      D                                     Like(StdInt)                                             
  203.      D                                     Value                                                    
  204.      D  PR_InFileId...                                                                              
  205.      D                               16A                                                            
  206.                                                                                                     
  207.      D ProgramName...                                                                               
  208.      D                 s                   Like(StdNam)                                             
  209.      D w_Path...                                                                                    
  210.      D                 s            256A                                                            
  211.      D FolderPath...                                                                                
  212.      D                 s            256A   Varying                                                  
  213.      D FileName...                                                                                  
  214.      D                 s            128A   Varying                                                  
  215.      D Result...                                                                                    
  216.      D                 s                   Like(StdPtr)                                             
  217.      D Path_Name       S             20A                                                            
  218.      D File_Name       S             30A                                                            
  219.      D Process_Type    S              6A                                                            
  220.      D p_w_Path        S               *   Inz(%Addr(w_Path))                                       
  221.      D f_Path...                                                                                    
  222.      D                 s            256A                                                            
  223.                                                                                                     
  224.       /Free                                                                                         
  225.                                                                                                     
  226.        // Get full path from File Id.                                                               
  227.        Result = GetPathAPI(w_Path               :                                                   
  228.                            %Size(w_Path)        :                                                   
  229.                            InJournalEntry.FileId);                                                  
  230.        // If result is null, then it did not find the file. In                                      
  231.        //  other words, it is processing a file that is no longer                                   
  232.        //  in the folder.                                                                           
  233.        If Result = *Null;                                                                           
  234.          Return;                                                                                    
  235.        EndIf;                                                                                       
  236.                                                                                                     
  237.        f_Path = %Str(p_w_Path );                                                                    
  238.        GetPathPieces(%TrimR(f_Path):                                                                
  239.                      FolderPath    :                                                                
  240.                      FileName      );                                                               
  241.                                                                                                     
  242.        // Ignore anything with a blank file name. JT entry created when                             
  243.        //   IFS folder is journaled the first time.                                                 
  244.        If FileName = *Blanks;                                                                       
  245.          Return;                                                                                    
  246.        EndIf;                                                                                       
  247.                                                                                                     
  248.        // Only do this processing when we have a valid file name                                    
  249.        // Ignore any entries that have no file name                                                 
  250.        // Test if file name already received                                                        
  251.        Path_Name = FolderPath;                                                                      
  252.        File_Name = FileName;                                                                        
  253.        SetLL File_Name VXbEpFile;                                                                   
  254.        If Not %Equal(); // New file                                                                 
  255.          Process_Type = 'PARSE';                                                                    
  256.        Else; // Duplicate File                                                                      
  257.          Process_Type = 'REJECT';                                                                   
  258.        EndIf;                                                                                       
  259.                                                                                                     
  260.        Submit_Job (Path_Name                                                                        
  261.                  : File_Name                                                                        
  262.                  : Process_Type);                                                                   
  263.        Return;                                                                                      
  264.                                                                                                     
  265.       /End-Free                                                                                     
  266.      P                 E                                                                            
  267.       * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -                         
  268.       * GetPathPieces                                                                               
  269.       *   Extract pieces from full path name.                                                       
  270.       *   Input       - Full Path Name.                                                             
  271.       *   Out         - Path to file.                                                               
  272.       *                 File Name.                                                                  
  273.       *   Returns     - None.                                                                       
  274.       * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -                         
  275.      P GetPathPieces...                                                                             
  276.      P                 B                                                                            
  277.      D                 PI                                                                           
  278.      D   InFullPath...                                                                              
  279.      D                              256A   Varying                                                  
  280.      D                                     Const                                                    
  281.      D   OutPath...                                                                                 
  282.      D                              256A   Varying                                                  
  283.      D   OutFileName...                                                                             
  284.      D                              128A   Varying                                                  
  285.                                                                                                     
  286.      D Position...                                                                                  
  287.      D                 s                   Like(StdInt)                                             
  288.      D PeriodSeen...                                                                                
  289.      D                 s                   Like(StdLgl)                                             
  290.      D                                     Inz(cFalse)                                              
  291.      D File_Length     S              5I 0                                                          
  292.       /Free                                                                                         
  293.                                                                                                     
  294.        // Note: This code assumes that a file has a period in it.                                   
  295.        //         If it doesn't, this is going to work.                                             
  296.        For Position = %Len(InFullPath) DownTo 1;                                                    
  297.          If %Subst(InFullPath:Position:1) = '/';                                                    
  298.            Leave;                                                                                   
  299.          EndIf;                                                                                     
  300.          If %Subst(InFullPath:Position:1) = '.';                                                    
  301.            PeriodSeen = cTrue;                                                                      
  302.          EndIf;                                                                                     
  303.        EndFor;                                                                                      
  304.                                                                                                     
  305.        If PeriodSeen;                                                                               
  306.          File_Length = %Len(InFullPath);                                                            
  307.          OutFileName = %Subst(InFullPath                 :                                          
  308.                               Position + 1               :                                          
  309.                               File_Length - Position);                                              
  310.          OutPath     = %Subst(InFullPath :                                                          
  311.                               1          :                                                          
  312.                               Position   );                                                         
  313.        Else;                                                                                        
  314.          OutFileName = *Blanks;                                                                     
  315.          OutPath     = InFullPath;                                                                  
  316.        EndIf;                                                                                       
  317.                                                                                                     
  318.        Return;                                                                                      
  319.                                                                                                     
  320.       /End-Free                                                                                     
  321.      P                 E                                                                            
  322.                                                                                                     
  323.      P*--------------------------------------------------                                           
  324.      P* Procedure name: Submit_Job                                                                  
  325.      P* Purpose:        Submit job to process received file                                         
  326.      P* Returns:                                                                                    
  327.      P* Parameter:      Path => Path Name                                                           
  328.      P* Parameter:      File_Name => File Name to Process                                           
  329.      P* Parameter:      Process_Type => Action Required                                             
  330.      P*--------------------------------------------------                                           
  331.      P Submit_Job      B                                                                            
  332.      D Submit_Job      PI                                                                           
  333.      D  Path                         20A                                                            
  334.      D  File_Name                    30A                                                            
  335.      D  Process_Type                  5A                                                            
  336.                                                                                                     
  337.      D Execute_Command...                                                                           
  338.      D                 PR                  ExtPgm('QCMDEXC')                                        
  339.       // Command Name to Process                                                                    
  340.      D  Command_Name                256A   Options(*VARSIZE)                                        
  341.   |  D                                     Const                                                    
  342.       // Length of command to process                                                               
  343.      D  Command_Length...                                                                           
  344.      D                               15P 5 Const                                                    
  345.                                                                                                     
  346.       // Work fields and constants                                                                  
  347.       // User Id                                                                                    
  348.      D User_Id         S             10A   Inz(*User)                                               
  349.                                                                                                     
  350.       // Command Name to Process                                                                    
  351.      D  Command        S            256A   Varying                                                  
  352.                                                                                                     
  353.       // Length of command to process                                                               
  354.      D  Command_Length...                                                                           
  355.      D                 S             15  5                                                          
  356.                                                                                                     
  357.      D Rejection_Reason...                                                                          
  358.      D                 S              3A                                                            
  359.                                                                                                     
  360.      D Command_S       C                   'SBMJOB JOBQ(EPINS) JOBD(EPINSJOBD)-                     
  361.      D                                      JOB('                                                   
  362.       // Job Name for Process Invoices                                                              
  363.      D Invoice         C                   'EPINSINV)'                                              
  364.                                                                                                     
  365.       // Command to call Invoice Parse program                                                      
  366.      D Command_I       C                   ' CMD(CPEPINVC PATH('                                    
  367.                                                                                                     
  368.       // Job Name for Process Payments                                                              
  369.      D Payments        C                   'EPINSPAY)'                                              
  370.                                                                                                     
  371.       // Job Name for Reject File                                                                   
  372.      D Reject          C                   'EPINSRJCT)'                                             
  373.                                                                                                     
  374.       // Command to call Cash Receipts Parse program                                                
  375.      D Command_C       C                   ' CMD(ASEPCASH PATH('                                    
  376.                                                                                                     
  377.       // Command to call Reject entire file program                                                 
  378.      D Command_R       C                   ' CMD(XBEPRJCT PATH('                                    
  379.      D Command_R1      C                   ' REASON('                                               
  380.                                                                                                     
  381.       // Keyword for File Name                                                                      
  382.      D File            C                   ' FILE('                                                 
  383.                                                                                                     
  384.      D Quote           C                   x'7D'                                                    
  385.                                                                                                     
  386.       // Rejection Reasons                                                                          
  387.      D Duplicate       C                   'DUP'                                                    
  388.      D Unknown_File_Type...                                                                         
  389.      D                 C                   'UNK'                                                    
  390.       /Free                                                                                         
  391.        Command = Command_S;                                                                         
  392.                                                                                                     
  393.        If Process_Type = 'PARSE';                                                                   
  394.          // Test if Invoice or Payment                                                              
  395.          Select;                                                                                    
  396.          When %SubSt(File_Name : 1 : 4) = 'INVC'; // Invoice Data                                   
  397.            Command = Command + Invoice + Command_I;                                                 
  398.          When %SubSt(File_Name : 1 : 4) = 'PYMT'; // Payment Data                                   
  399.            Command = Command + Payments + Command_C;                                                
  400.          Other;   // Unknown file type                                                              
  401.            Command = Command + Reject + Command_R;                                                  
  402.            Rejection_Reason = Unknown_File_Type;                                                    
  403.          EndSl;                                                                                     
  404.                                                                                                     
  405.          EpName = File_Name;                                                                        
  406.          EpCCtD = %Dec(%Date);                                                                      
  407.          EpCCtT = %Dec(%Time);                                                                      
  408.          EpCCtU = User_Id;                                                                          
  409.          Write XbEpFileR;                                                                           
  410.        Else; // Reject entire file                                                                  
  411.          Command = Command + Reject + Command_R;                                                    
  412.          Rejection_Reason = Duplicate;                                                              
  413.        EndIf;                                                                                       
  414.                                                                                                     
  415.        Command = Command + Quote + %Trim(Path) + Quote + ')' +                                      
  416.            File + Quote + %Trim(File_Name) + Quote  + ')';                                          
  417.        If Rejection_Reason <> *Blank;                                                               
  418.          Command = Command + Command_R1 + Rejection_Reason + ')';                                   
  419.        EndIf;                                                                                       
  420.                                                                                                     
  421.        Command = Command + ')';                                                                     
  422.        Execute_Command (Command : %Len(Command));                                                   
  423.        Return;                                                                                      
  424.       /End-Free                                                                                     
  425.      P Submit_Job      E                                                                             
© 2004-2019 by midrange.com generated in 0.013s valid xhtml & css