hexagon logo

External Subroutine question

Hello all,

I will explain what I want to do before asking the question / your help.

I have programs that need to call a subroutine that will have a rev number. Example "Sub_Rev_A.prg"

I have a text file that those programs read and extract the final letter of the name and assign it in a variable with the readline command. So if I have a second sub named "Sub_Rev_B.prg" and the txt file writes B, the B sub will be read instead.

Now the issue I am having is... Those programs will be read only in a read only folder. I noticed that when I start those programs, they search for the sub they had executed in the first run while NOT in read only mode and after that while executing they search for the real version to execute (and execute it correctly).

In the example I gave be4, Main Program is tested with REV A sub, saved and set to read only. It works with Rev A for some time perfectly. Later on, we revise the sub to rev B, change the Txt to B. The program starts, gives an error message that the sub A is not found (we remove the old revisions), procedes to execution, reads the txt, executes sub B. From that point if I reexecute the Main program without closing it runs without error. If I close and reopen it I am getting the same error for Rev A.

No impact on the result of the measurement but each time I am getting an annoying message that I would love to eliminate if possible. Please know that in reality I am talking about hundreds of programs and subs and it is not possible to remove readonly mode each time we revise a sub without performing validation documents etc,

any help is much appreciated! |

PC-Dmis 2017 R2
  • I think if you make sure the variable initially holds a valid subname it won't error.

    On starting execution it's just running a check that the CALLSUB points to a valid location.

    This seems to work for me:

    [B]ASSIGN/MYSUBNUM="1"[/B]
    FPTR =FILE/OPEN,C:\Temp\SubNum.txt,READ
    V1 =FILE/READLINE,FPTR,{mysubnum}
    FILE/CLOSE,FPTR,KEEP
    ASSIGN/MYSUBNUM="SUB"+MYSUBNUM
    CS1 =CALLSUB/MYSUBNUM,C:\Users\Public\Documents\Hexagon\PC-DMIS\2023.1\SubLibrary.PRG:,
    
    
    ​



    Where as this didn't (and I go t the same error you mention)

    [B]ASSIGN/MYSUBNUM=""[/B]
    FPTR =FILE/OPEN,C:\Temp\SubNum.txt,READ
    V1 =FILE/READLINE,FPTR,{mysubnum}
    FILE/CLOSE,FPTR,KEEP
    ASSIGN/MYSUBNUM="SUB"+MYSUBNUM
    CS1 =CALLSUB/MYSUBNUM,C:\Users\Public\Documents\Hexagon\PC-DMIS\2023.1\SubLibrary.PRG:,
    
    
    ​
  • I think if you make sure the variable initially holds a valid subname it won't error.

    On starting execution it's just running a check that the CALLSUB points to a valid location.

    This seems to work for me:

    [B]ASSIGN/MYSUBNUM="1"[/B]
    FPTR =FILE/OPEN,C:\Temp\SubNum.txt,READ
    V1 =FILE/READLINE,FPTR,{mysubnum}
    FILE/CLOSE,FPTR,KEEP
    ASSIGN/MYSUBNUM="SUB"+MYSUBNUM
    CS1 =CALLSUB/MYSUBNUM,C:\Users\Public\Documents\Hexagon\PC-DMIS\2023.1\SubLibrary.PRG:,
    
    
    ​



    Where as this didn't (and I go t the same error you mention)

    [B]ASSIGN/MYSUBNUM=""[/B]
    FPTR =FILE/OPEN,C:\Temp\SubNum.txt,READ
    V1 =FILE/READLINE,FPTR,{mysubnum}
    FILE/CLOSE,FPTR,KEEP
    ASSIGN/MYSUBNUM="SUB"+MYSUBNUM
    CS1 =CALLSUB/MYSUBNUM,C:\Users\Public\Documents\Hexagon\PC-DMIS\2023.1\SubLibrary.PRG:,
    
    
    ​


    I am not sure what is different here from what I am explaining. The idea is to be able to call a sub based on the current rev that is being read from a txt file. I have in readonly the main program and the subprogram rev A. I need to change to rev B the subprogram. I change the txt file to B. I will always get the error message unless I remove readonly in my main program, execute it once, save and put again in readonly mode. In your example, if you go and change the txt file to 2 and change the external subroutine name to 2 in your subprogram, the main program will give you an error on first execution as it will not be able to find sub 1 that is hardcoded to search before real execution.

    Also please test with variable subprograms not subroutines as my example so we can compare Slight smile

    Thanks btw for the support.
  • The main idea is to have a header and a footer on a sub program. All my 1k programs will use this sub for the common code in header and footer. If I need to revise something in the header, I just modify 1 program putting a new rev in the folder and the txt file that will be used to define the current version of the sub. This way I will not modify all 1k programs that are in readonly folders and that can only by modified through validation and PLM system chain
  • This works (All files are set to ReadOnly in Windows)


    
    ASSIGN/MYSUBNUM=1
                ASSIGN/MYSUBFILE="C:\\Users\\Public\\Documents\\Hexagon\\PC-DMIS\\2023.1\\SubLibrary"
    FPTR       =FILE/OPEN,C:\Temp\SubNum.txt,READ
    V1         =FILE/READLINE,FPTR,{mysubnum}
                FILE/CLOSE,FPTR,KEEP
                ASSIGN/MYSUBFILE=MYSUBFILE+MYSUBNUM+".prg"
    CS1        =CALLSUB/MYSUB,MYSUBFILE:,​
    


    I think the key is to initialise MYSUBNUM (or SUBREV in your case) so that the MYSUB file points to a valid .prg before execution


    
    ASSIGN/SUBREV="A"
    FPTR =FILE/OPEN,\\CHLLCM0APPSRV03\GXP_VALIDATED\PCDMIS\DEA\PR ODUCTION\501106682\REV.TXT,READ
    100 =FILE/READLINE,FPTR,{SUBREV}
    FILE/CLOSE,FPTR,KEEP
    ASSIGN/SUBFULLPATH="\\\CHLLCM0APPSRV03\GXP_VALIDATED\PCDM IS\DEA\PRODUCTION\501106682\APS-PDEA-501106682_REV_" +SUBREV +".PRG"
    CSHEADER =CALLSUB/HEADER,SUBFULLPATH:,​​
    
    
    
  • This works (All files are set to ReadOnly in Windows)


    
    ASSIGN/MYSUBNUM=1
    ASSIGN/MYSUBFILE="C:\\Users\\Public\\Documents\\Hexagon\\PC-DMIS\\2023.1\\SubLibrary"
    FPTR =FILE/OPEN,C:\Temp\SubNum.txt,READ
    V1 =FILE/READLINE,FPTR,{mysubnum}
    FILE/CLOSE,FPTR,KEEP
    ASSIGN/MYSUBFILE=MYSUBFILE+MYSUBNUM+".prg"
    CS1 =CALLSUB/MYSUB,MYSUBFILE:,​
    


    I think the key is to initialise MYSUBNUM (or SUBREV in your case) so that the MYSUB file points to a valid .prg before execution


    
    ASSIGN/SUBREV="A"
    FPTR =FILE/OPEN,\\CHLLCM0APPSRV03\GXP_VALIDATED\PCDMIS\DEA\PR ODUCTION\501106682\REV.TXT,READ
    100 =FILE/READLINE,FPTR,{SUBREV}
    FILE/CLOSE,FPTR,KEEP
    ASSIGN/SUBFULLPATH="\\\CHLLCM0APPSRV03\GXP_VALIDATED\PCDM IS\DEA\PRODUCTION\501106682\APS-PDEA-501106682_REV_" +SUBREV +".PRG"
    CSHEADER =CALLSUB/HEADER,SUBFULLPATH:,​​
    
    
    


    You still do not understand what I try to achieve Slight smile When I revise my subprogram I will need to revise my main program also to change the
    ASSIGN/MYSUBNUM=1
    that you put in your program. This beats the point of modifying a program only and not all my 1k programs when I want to change something in the header (add a tracefiled) for example.

    Your method requires modifying the program and the sub program. I want to modify the sub only without touching the mainprogram and logic says that since I am using variables I should be able to do it without error messages which apparently is not the case


  • You still do not understand what I try to achieve Slight smile When I revise my subprogram I will need to revise my main program also to change the
    ASSIGN/MYSUBNUM=1
    that you put in your program. This beats the point of modifying a program only and not all my 1k programs when I want to change something in the header (add a tracefiled) for example.

    Your method requires modifying the program and the sub program. I want to modify the sub only without touching the mainprogram and logic says that since I am using variables I should be able to do it without error messages which apparently is not the case



    I do understand what you're trying to do (I think).

    You're not getting what I'm saying.

    The line...

    ASSIGN/MYSUBNUM=1

    .. .doesn't need changing.

    All it does is have an initial value that will form a valid file name (i.e. one that exists on the system) and contains a subroutine called (in my example) 'MYSUB'


    At execution time, MYSUBNUM becomes whatever is read from the text file (1,2,3 etc) as you up-rev your subroutines.



    To clarify.

    When you start execution, PC-Dmis is looking at that CALLSUB command, and doing a verification that it exists.

    In my case it's looking at the 'MYSUBFILE' assignment. This is made up of MYSUBFILE+MYSUBNUM+".prg"
    So it looks what values they currently hold

    MYSUBFILE = "C:\\Users\\Public\\Documents\\Hexagon\\PC-DMIS\\2023.1\\SubLibrary"
    MYSUBNUM = 1
    ".prg" = ".prg"

    It sticks all those together to get "C:\\Users\\Public\\Documents\\Hexagon\\PC-DMIS\\2023.1\\SubLibrary1.prg" then it checks it contains a subroutine called MYSUB (which it does).

    It doesn't matter that it might not actually be the subroutine program we eventually call, just that it's a valid file / subname when it starts.

    It's then happy to proceed with execution without displaying an error.







  • I do understand what you're trying to do (I think).

    You're not getting what I'm saying.

    The line...

    ASSIGN/MYSUBNUM=1

    .. .doesn't need changing.

    All it does is have an initial value that will form a valid file name (i.e. one that exists on the system) and contains a subroutine called (in my example) 'MYSUB'


    At execution time, MYSUBNUM becomes whatever is read from the text file (1,2,3 etc) as you up-rev your subroutines.



    To clarify.

    When you start execution, PC-Dmis is looking at that CALLSUB command, and doing a verification that it exists.

    In my case it's looking at the 'MYSUBFILE' assignment. This is made up of MYSUBFILE+MYSUBNUM+".prg"
    So it looks what values they currently hold

    MYSUBFILE = "C:\\Users\\Public\\Documents\\Hexagon\\PC-DMIS\\2023.1\\SubLibrary"
    MYSUBNUM = 1
    ".prg" = ".prg"

    It sticks all those together to get "C:\\Users\\Public\\Documents\\Hexagon\\PC-DMIS\\2023.1\\SubLibrary1.prg" then it checks it contains a subroutine called MYSUB (which it does).

    It doesn't matter that it might not actually be the subroutine program we eventually call, just that it's a valid file / subname when it starts.

    It's then happy to proceed with execution without displaying an error.






    That's on me, I did not clearly explain that the rev A or 1 whatever will be changed to B/2. Changed as replaced. It is not possible to have it remain in that folder due to quality policies and risks :S What I am trying to achieve is not possible as the software is not designed to work like this contrary to logic :S Maybe in a future revision this will be implemented.

    Btw, Do you know if there is a way to get rid of those error messages? Deactivate them and stop them showing from Admin menu or something?
  • Can't you just have a dummy routine which doesn't actually do anything as the initial routine?


    ASSIGN/HEADERSUBFILE="C:\TEMP\DUMMY.PRG

    Then rather than just have A or B in the text file, have the full path of the subroutine in there.


    It's never going to get executed, it just has to exist!


    The warnings can't be switched off btw.


    What I am trying to achieve is not possible


    I disagree!
  • Can't you just have a dummy routine which doesn't actually do anything as the initial routine?


    ASSIGN/HEADERSUBFILE="C:\TEMP\DUMMY.PRG

    Then rather than just have A or B in the text file, have the full path of the subroutine in there.


    It's never going to get executed, it just has to exist!


    The warnings can't be switched off btw.



    I disagree!


    Sadly it does not work:




    I created a dummy routine APS-PDEA-501106682.prg having a Header sub in it. I assigned the path variable to it. I search for the rev and change the path to include the rev and use the path variable in my callsub command. I am getting an error.

    The path of the subroutine is hardcoded in the program on last execution, otherwise is 0 like in this example. The second time I am running this program is ok, I have no error. If I change the rev in the txt file and delete the subroutine with the rev number but maintain the dummi routine without the rev number, I will get the error. Try it yourself with the code I provided please.
  • The issue with what you've done there is that the second instance of your Assignment PATH is using SUBREV - which initially holds no value (or 0).

    Change it so the text file contains the full path or the subroutine and not just the REV.

    Change the file READLINE to =FILE/READLINE,FPTR,{MYPATH}

    Delete the ASSIGNG/PATH line just before the CALLSUB

    Change the last line to =CALLSUB/HEADER,MYPATH:,