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:
- TESTSRV/QSRVSRC member SRV1:
- STRPGMEXP PGMLVL( *CURRENT ) SIGNATURE("VERSION1")
- EXPORT SYMBOL( proc1 )
- EXPORT SYMBOL( proc2 )
- ENDPGMEXP
-
- TESTSRV/QRPGLESRC member PROTO:
- D proc1 pr
- D msg 25a varying const
- D proc2 pr
- D msg 25a varying const
-
- TESTSRV/QRPGLESRC member SRV1:
- H nomain
- /copy proto
- P proc1 b export
- D proc1 pi
- D msg 25a varying const
- /free
- dsply ('proc1 : caller says ' + msg);
- /end-free
- P proc1 e
-
- P proc2 b export
- D proc2 pi
- D msg 25a varying const
- /free
- dsply ('proc2 : caller says ' + msg);
- /end-free
- P proc2 e
-
- TESTSRV/QRPGLESRC member TESTPGM1:
- H dftactgrp(*no) actgrp(*new) bnddir('TESTSRV/BND')
- /copy proto
- /free
- proc1('calling proc1');
- proc2('calling proc2');
- return;
-
- ADDLIBLE TESTSRV
- CRTRPGMOD TESTSRV/SRV1
- CRTSRVPGM TESTSRV/SRV1
- CRTBNDDIR TESTSRV/BND
- ADDBNDDIRE TESTSRV/BND OBJ((TESTSRV/SRV1))
- CRTBNDRPG TESTSRV/TESTPGM1
-
- CALL TESTPGM1
- DSPLY proc1 : caller says calling proc1
- DSPLY proc2 : caller says calling proc2
-
- Edit the binder source, add a *CURRENT block and reverse the order of proc1 and proc2.
- STRPGMEXP PGMLVL( *CURRENT ) SIGNATURE("VERSION2")
- EXPORT SYMBOL( proc2 )
- EXPORT SYMBOL( proc1 )
- ENDPGMEXP
- STRPGMEXP PGMLVL( *PRV ) SIGNATURE("VERSION1")
- EXPORT SYMBOL( proc1 )
- EXPORT SYMBOL( proc2 )
- ENDPGMEXP
-
- DLTSRVPGM TESTSRV/SRV1
- CRTSRVPGM TESTSRV/SRV1
-
- CALL TESTPGM1 /* it's not calling the procedures it thinks it is */
- DSPLY proc2 : caller says calling proc1
- DSPLY proc1 : caller says calling proc2
-
- 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.
- STRPGMEXP PGMLVL( *CURRENT ) SIGNATURE("VERSION2")
- EXPORT SYMBOL( proc2 )
- EXPORT SYMBOL( proc1 )
- ENDPGMEXP
-
- DLTSRVPGM TESTSRV/SRV1
- CRTSRVPGM TESTSRV/SRV1
-
- CALL TESTPGM1 /* no more silent error */
- Program signature violation.
- Error found on CALL command.
-
|
|
|