4 Replies Latest reply: Nov 30, 2011 12:15 PM by Ralf1234 RSS

    Return Value in a SUBroutine

      is ther any possibility to declare an own Sub like:


      sub isACoolName(name)

      //return -1 or 0



      and then use it in if expressions: if isACoolName('JanUlrich') then .... ??


      and how does such an return statemant have to look like?



        • Return Value in a SUBroutine
          Kaushik Solanki



              Try this.


          sub isACoolName(name)

          isACoolName =1




          Kaushik Solanki

            • Return Value in a SUBroutine

              okey, thanks. But i still got a problem with writing the return value into a variable or use it in another way.


              things like this:

              a = isACoolName('test');


              a = call isACoolName("test");


              dont seem to work.


              thanks for your input!





                • Return Value in a SUBroutine
                  Angus Monro



                  You can't return values from subroutines.  You might like try using a $-sign expansion, though.  e.g.


                  SET isACoolName=('$1'='janulrich');


                  LET a=$(isACoolName('John'));

                    • Return Value in a SUBroutine

                      Managing return values from SUB are possible in this way:


                      1) define a INLINE table VAR - it is used like a collection in VB or JavaScript
                      LOAD * INLINE [ Name, Val, Dummy_Var, 42 ]

                      2) create service functions to add or delete records in VAR
                      return values in SUBs can be stored in VAR with an Var_Add() or you can store directly with an LOAD * INLINE
                      Name, Val, ReturnVal, $(xyValue)

                      3) in main-pgm use LOOKUP to read the content of the Variable


                      - initial effort to create service routines
                      - not very transparent


                      - array() are possible
                      - unlimited record structure as you can create more fields in VAR  Inline
                      - the INLINE table is a normal table which can be used in your app to display your VAR-records