midrange.com code scratchpad
Name:
User Condition Handler
Scriptlanguage:
Plain Text
Tabwidth:
4
Date:
02/25/2010 04:26:04 pm
IP:
Logged
Description:
User Condition Handler Example Code
Code:
  1.      /*============================================================================================= 
  2.      /*   Notes                                                                                      
  3.      /*============================================================================================= 
  4.                                                                                                      
  5.      /* Compile with ACTGRP('SVS9999')                                                               
  6.                                                                                                      
  7.      /*============================================================================================= 
  8.      /*   Control Specifications                                                                     
  9.      /*============================================================================================= 
  10.                                                                                                      
  11.      H NoMain                                                                                        
  12.      H BndDir('MCSERV')                                                                              
  13.      H Option(*NODEBUGIO)                                                                            
  14.      H ExtBinInt                                                                                     
  15.                                                                                                      
  16.      /*============================================================================================= 
  17.      /*   File Specifications                                                                        
  18.      /*============================================================================================= 
  19.                                                                                                      
  20.                                                                                                      
  21.      /*============================================================================================= 
  22.      /*   Prototype Specifications                                                                   
  23.      /*============================================================================================= 
  24.                                                                                                      
  25.       /Include QRpgCbSrc,SVS9999                                                                     
  26.       /Include QRpgCbSrc,SETJMP.H                                                                    
  27.                                                                                                      
  28.      /*============================================================================================= 
  29.      /*   Data Specifications                                                                        
  30.      /*============================================================================================= 
  31.                                                                                                      
  32.      /*--------------------------------------------------------------------------------------------- 
  33.      /*   Data Structure Specifications                                                              
  34.      /*--------------------------------------------------------------------------------------------- 
  35.                                                                                                      
  36.                                                                                                      
  37.      /*--------------------------------------------------------------------------------------------- 
  38.      /*   Array Specifications                                                                       
  39.      /*--------------------------------------------------------------------------------------------- 
  40.                                                                                                      
  41.                                                                                                      
  42.      /*--------------------------------------------------------------------------------------------- 
  43.      /*   Indicator Specifications                                                                   
  44.      /*--------------------------------------------------------------------------------------------- 
  45.                                                                                                      
  46.                                                                                                      
  47.      /*--------------------------------------------------------------------------------------------- 
  48.      /*   Standalone Data Specifications                                                             
  49.      /*--------------------------------------------------------------------------------------------- 
  50.                                                                                                      
  51.                                                                                                      
  52.      /*--------------------------------------------------------------------------------------------- 
  53.      /*   Constant Specifications                                                                    
  54.      /*--------------------------------------------------------------------------------------------- 
  55.                                                                                                      
  56.                                                                                                      
  57.      /*############################################################################################# 
  58.      /*   userConditionHandler001 - User Condition Handler                                           
  59.      /*############################################################################################# 
  60.                                                                                                      
  61.      P userConditionHandler001...                                                                    
  62.      P                 B                   Export                                                    
  63.                                                                                                      
  64.      /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 
  65.      /* Procedure Interface                                                                          
  66.      /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 
  67.                                                                                                      
  68.      D userConditionHandler001...                                                                    
  69.      D                 PI                                                                            
  70.      D  condition                    12A                                        Error Condition      
  71.      D  userChBase                     *                                        User Data            
  72.      D  result                       10I 0                                      Result               
  73.      D  newCondition                 12A                                        New Condition        
  74.                                                                                                      
  75.      /*============================================================================================= 
  76.      /* Procedure Prototype Specifications                                                           
  77.      /*============================================================================================= 
  78.                                                                                                      
  79.      D userConditionHandlerExit...                                                                   
  80.      D                 PR                  ExtProc(userCH.exitProc)                                  
  81.      D                                 *   Value                                User Data            
  82.                                                                                                      
  83.      /*============================================================================================= 
  84.      /* Procedure Data Specifications                                                                
  85.      /*============================================================================================= 
  86.                                                                                                      
  87.       /Include QRpgCbSrc,DQUSec                                                                      
  88.                                                                                                      
  89.       /Define RCVPM2                                                                                 
  90.       /Include QRpgCbSrc,DQMhRcvPm                                                                   
  91.                                                                                                      
  92.       /Include QRpgCbSrc,SetJmp.H                                                                    
  93.                                                                                                      
  94.                                                                                                      
  95.      /*--------------------------------------------------------------------------------------------- 
  96.      /* Procedure Data Structure Specifications                                                      
  97.      /*--------------------------------------------------------------------------------------------- 
  98.                                                                                                      
  99.      D userCH          DS                  Based(userCHBase)                                         
  100.      D                                     Qualified                                                 
  101.      D  errorBase                      *                                                             
  102.      D  exitProc                       *   ProcPtr                                                   
  103.      D  exitData                       *                                                             
  104.      D  jumpPointBase                  *                                                             
  105.                                                                                                      
  106.      D jumpPoint       DS                  LikeDs(jmpBufferTemplate)                                 
  107.      D                                     Based(userCH.jumpPointBase)                               
  108.                                                                                                      
  109.      /*--------------------------------------------------------------------------------------------- 
  110.      /* Procedure Array Specifications                                                               
  111.      /*--------------------------------------------------------------------------------------------- 
  112.                                                                                                      
  113.                                                                                                      
  114.      /*--------------------------------------------------------------------------------------------- 
  115.      /* Procedure Indicator Specifications                                                           
  116.      /*--------------------------------------------------------------------------------------------- 
  117.                                                                                                      
  118.                                                                                                      
  119.      /*--------------------------------------------------------------------------------------------- 
  120.      /* Procedure Standalone Data Specifications                                                     
  121.      /*--------------------------------------------------------------------------------------------- 
  122.                                                                                                      
  123.                                                                                                      
  124.      /*--------------------------------------------------------------------------------------------- 
  125.      /* Procedure Constant Specifications                                                            
  126.      /*--------------------------------------------------------------------------------------------- 
  127.                                                                                                      
  128.                                                                                                      
  129.      /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 
  130.      /* Procedure Code                                                                               
  131.      /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 
  132.                                                                                                      
  133.       /Free                                                                                          
  134.                                                                                                      
  135.        usec_Base = userCH.ErrorBase;                                                                 
  136.        result = 20;                                                       // percolate condition     
  137.                                                                                                      
  138.        If usec_Base <> *NULL;                                             // check for structure     
  139.           If usec_Provided >= usec_Avail_Static;                          // check struct size       
  140.              result = 10;                                                 // handle condition        
  141.                                                                                                      
  142.              If usec_Provided > usec_Avail_Static;                        // find size of error      
  143.                 usec_Data_Length = usec_Provided - usec_Avail_Static;     // message data            
  144.                                                                                                      
  145.              Else;                                                        // struct too small for    
  146.                 usec_Data_Length = 0;                                     //  available data         
  147.                 usec_Avail_Static = usec_Provided;                                                   
  148.              EndIf;                                                                                  
  149.           EndIf;                                                                                     
  150.        EndIf;                                                                                        
  151.                                                                                                      
  152.        If result = 20;                                                    // percolate condition     
  153.           Return;                                                                                    
  154.        EndIf;                                                                                        
  155.                                                                                                      
  156.        usec_Data_Base = usec_Base + usec_Avail_Static;                                               
  157.        RcvPM2_Data_Length = usec_Data_Length;                                                        
  158.                                                                                                      
  159.        /Include QRpgCbSrc,ZQMhRcvPm                                                                  
  160.                                                                                                      
  161.        RcvPM_Msg_Type = '*EXCP';                                          // Get Exception Mesg      
  162.        RcvPM_Msg_Action = '*SAME';                                                                   
  163.        usec_Msg_Id = *BLANKS;                                                                        
  164.                                                                                                      
  165.        For RcvPm_C_Stack_Counter = 1 to 10;                                                          
  166.        /Include QRPGCBSRC,CQMHRCVPM                                                                  
  167.                                                                                                      
  168.           If usec_Msg_Id = *BLANKS;                                                                  
  169.              If RcvPM2_Avail > 0;                                                                    
  170.                 Leave;                                                                               
  171.              EndIf;                                                                                  
  172.                                                                                                      
  173.           Else;                                                                                      
  174.              Leave;                                                                                  
  175.           EndIf;                                                                                     
  176.        EndFor;                                                                                       
  177.                                                                                                      
  178.        If RcvPM2_Return > 8 or RcvPM2_Avail > 0;                          // Message found           
  179.           usec_Msg_Id = RcvPM2_Msg_Id;                                                               
  180.           usec_Available = RcvPM2_Data_Avail;                                                        
  181.                                                                                                      
  182.           If RcvPM2_Data_Length > 0 and rcvPM2_Data_Avail > 0;                                       
  183.              %SubSt(usec_Data : 1 : usec_Data_Length) =                                              
  184.                 %SubSt(RcvPM2_Data : 1 : RcvPM2_Data_Length);                                        
  185.           EndIf;                                                                                     
  186.                                                                                                      
  187.           If userCH.ExitProc <> *NULL;                                    // Exit Procedure Exists   
  188.              userConditionHandlerExit(userCH.ExitData);                   //  Run Exit Procedure     
  189.           EndIf;                                                                                     
  190.                                                                                                      
  191.           If userCH.JumpPointBase <> *NULL;                               // Jump Point Exists       
  192.              RcvPM_Msg_Action = '*OLD';                                   // Handle Exception        
  193.              rcvPM_Msg_Key = rcvPM2_Msg_Key;                                                         
  194.              /Include QRPGCBSRC,CQMHRCVPM                                                            
  195.                                                                                                      
  196.              /Include QRpgCbSrc,LQMhRcvPm                                                            
  197.                                                                                                      
  198.              longJmp(jumpPoint : 1);                                      // Return to setjmp (GOTO) 
  199.           EndIf;                                                                                     
  200.                                                                                                      
  201.        Else;                                                              // No messages found       
  202.           result = 20;                                                    // percolate condition     
  203.        EndIf;                                                                                        
  204.                                                                                                      
  205.        /Include QRpgCbSrc,LQMhRcvPm                                                                  
  206.                                                                                                      
  207.        Return;                                                                                       
  208.                                                                                                      
  209.       /End-Free                                                                                      
  210.                                                                                                      
  211.      P userConditionHandler001...                                                                    
  212.      P                 E                                                                             
  213.                                                                                                      
  214.        //=========================================================================================== 
  215.  
  216. SETJMP.H Copybook
  217.  
  218.       /If Defined(SETJMP_H)                                                                          
  219.       /Eof                                                                                           
  220.       /EndIf                                                                                         
  221.                                                                                                      
  222.       /Define SETJMP_H                                                                               
  223.                                                                                                      
  224.      /*============================================================================================= 
  225.      /*   Notes                                                                                      
  226.      /*============================================================================================= 
  227.                                                                                                      
  228.      /* Signal related functions, structures and constants were left out of this copybook.           
  229.                                                                                                      
  230.      /*============================================================================================= 
  231.      /*   Prototype Specifications                                                                   
  232.      /*============================================================================================= 
  233.                                                                                                      
  234.      D longjmp         PR                  ExtProc('longjmp')                                        
  235.      D  placeHolder                        LikeDs(jmpBufferTemplate)            Program Stack        
  236.      D                               10I 0 Value                                User Data            
  237.                                                                                                      
  238.      D setJmp          PR            10I 0 ExtProc('__setjmp')                                       
  239.      D placeHolder                         LikeDS(jmpBufferTemplate)            Program Stack        
  240.                                                                                                      
  241.      /*============================================================================================= 
  242.      /*   Data Specifications                                                                        
  243.      /*============================================================================================= 
  244.                                                                                                      
  245.                                                                                                      
  246.      /*--------------------------------------------------------------------------------------------- 
  247.      /*   Data Structure Specifications                                                              
  248.      /*--------------------------------------------------------------------------------------------- 
  249.                                                                                                      
  250.      D jmpBufferTemplate...                                                                          
  251.      D                 DS                  Template                                                  
  252.      D                                 *                                        Invocation Pointer   
  253.      D                                 *                                        Libl Pointer         
  254.      D                               10I 0                                                           
  255.                                                                                                      
  256.      /*--------------------------------------------------------------------------------------------- 
  257.      /*   Array Specifications                                                                       
  258.      /*--------------------------------------------------------------------------------------------- 
  259.                                                                                                      
  260.                                                                                                      
  261.      /*--------------------------------------------------------------------------------------------- 
  262.      /*   Indicator Specifications                                                                   
  263.      /*--------------------------------------------------------------------------------------------- 
  264.                                                                                                      
  265.                                                                                                      
  266.      /*--------------------------------------------------------------------------------------------- 
  267.      /*   Standalone Data Specifications                                                             
  268.      /*--------------------------------------------------------------------------------------------- 
  269.                                                                                                      
  270.                                                                                                      
  271.      /*--------------------------------------------------------------------------------------------- 
  272.      /*   Constant Specifications                                                                    
  273.      /*--------------------------------------------------------------------------------------------- 
  274.                                                                                                      
  275.  
  276.  
© 2004-2019 by midrange.com generated in 0.011s valid xhtml & css