midrange.com code scratchpad
Name:
Test scenario to show how it's not possible to change the order of the exports in a service program
Scriptlanguage:
Plain Text
Tabwidth:
4
Date:
10/04/2012 09:09:31 pm
IP:
Logged
Description:
Demonstrating how the order of exports can never be changed in a service program, not even by using *CURRENT and *PRV blocks.
Code:
  1. TESTSRV/QSRVSRC member SRV1:
  2.      STRPGMEXP PGMLVL( *CURRENT ) SIGNATURE("VERSION1")
  3.        EXPORT SYMBOL( proc1 )                          
  4.        EXPORT SYMBOL( proc2 )                          
  5.      ENDPGMEXP                                       
  6.  
  7. TESTSRV/QRPGLESRC member PROTO:
  8.      D proc1           pr                               
  9.      D   msg                         25a   varying const
  10.      D proc2           pr                               
  11.      D   msg                         25a   varying const
  12.  
  13. TESTSRV/QRPGLESRC member SRV1:
  14.      H nomain                                           
  15.       /copy proto                                       
  16.      P proc1           b                   export       
  17.      D proc1           pi                               
  18.      D   msg                         25a   varying const
  19.       /free                                             
  20.           dsply ('proc1 : caller says ' + msg);         
  21.       /end-free                                         
  22.      P proc1           e                                
  23.      
  24.      P proc2           b                   export       
  25.      D proc2           pi                               
  26.      D   msg                         25a   varying const
  27.       /free                                             
  28.           dsply ('proc2 : caller says ' + msg);         
  29.       /end-free                                         
  30.      P proc2           e                                  
  31.  
  32. TESTSRV/QRPGLESRC member TESTPGM1:
  33.      H dftactgrp(*no) actgrp(*new) bnddir('TESTSRV/BND') 
  34.       /copy proto                                        
  35.       /free                                              
  36.              proc1('calling proc1');                     
  37.              proc2('calling proc2');                     
  38.              return;                                     
  39.  
  40. ADDLIBLE TESTSRV
  41. CRTRPGMOD TESTSRV/SRV1
  42. CRTSRVPGM TESTSRV/SRV1
  43. CRTBNDDIR TESTSRV/BND
  44. ADDBNDDIRE TESTSRV/BND OBJ((TESTSRV/SRV1))
  45. CRTBNDRPG TESTSRV/TESTPGM1
  46.  
  47. CALL TESTPGM1
  48.      DSPLY  proc1 : caller says calling proc1
  49.      DSPLY  proc2 : caller says calling proc2
  50.  
  51. Edit the binder source, add a *CURRENT block and reverse the order of proc1 and proc2.
  52.      STRPGMEXP PGMLVL( *CURRENT ) SIGNATURE("VERSION2")
  53.        EXPORT SYMBOL( proc2 )                          
  54.        EXPORT SYMBOL( proc1 )                          
  55.      ENDPGMEXP                                       
  56.      STRPGMEXP PGMLVL( *PRV ) SIGNATURE("VERSION1")
  57.        EXPORT SYMBOL( proc1 )                          
  58.        EXPORT SYMBOL( proc2 )                          
  59.      ENDPGMEXP                                       
  60.  
  61. DLTSRVPGM TESTSRV/SRV1
  62. CRTSRVPGM TESTSRV/SRV1
  63.  
  64. CALL TESTPGM1  /* it's not calling the procedures it thinks it is */
  65.      DSPLY  proc2 : caller says calling proc1
  66.      DSPLY  proc1 : caller says calling proc2
  67.  
  68. To prevent this silent error, if it's _really_ necessary to change the order, change the binder source like this, just changing the signature. That will force old programs to get a signature violation.
  69.      STRPGMEXP PGMLVL( *CURRENT ) SIGNATURE("VERSION2")
  70.        EXPORT SYMBOL( proc2 )                          
  71.        EXPORT SYMBOL( proc1 )                          
  72.      ENDPGMEXP                                       
  73.  
  74. DLTSRVPGM TESTSRV/SRV1
  75. CRTSRVPGM TESTSRV/SRV1
  76.  
  77. CALL TESTPGM1 /* no more silent error */
  78.      Program signature violation. 
  79.      Error found on CALL command. 
  80.  
© 2004-2019 by midrange.com generated in 0.007s valid xhtml & css