sponsored links

Collapse

Announcement

Collapse
No announcement yet.

exsr with variable sr to call

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • exsr with variable sr to call

    Hello everyone,

    I have to ask a (maybe) stupid thing, but I never did it and I don't know if it's possible to do. I have to read a field value and execute a subroutine whose name is the field value.

    Example:

    select
    when myField = 'subABC'
    exsr subABC
    when myField = 'subQWERTY'
    exsr subQWERTY

    ... etc ...

    endsl


    Is there a way to write something like this?
    exsr myFieldValue

    Thank you so much!!

  • #2
    I don't think you can with subroutines. But I think you can with subprocedures: https://www.itjungle.com/2010/03/31/fhg033110-story01/

    Comment


    • JonBoy
      JonBoy commented
      Editing a comment
      Yup. And in fact there is a way to use APIs to make the thing dynamic - but given that the OP was looking at calling subroutines then this is a valid and pretty easy way to do it. In addition to the article you listed I also did a couple of other articles for IBM Systems mag that cover a similar approach but is completely data driven.

      These are the links: https://authory.com/JonParisAndSusan...r-Calculations
      and: https://authory.com/JonParisAndSusan...e-Calculations

      Sorry about the source formatting. We've been able to save the articles from extinction but have not yet had time to do all the formatting.

  • #3
    Thank you so much for these really interesting answers, I will study them also to solve other kind of problems. Unfortunately the first thing I can understand is that my question wasn't so stupid as I hoped.... The goal "simply" was to use a variable instead of a constant in EXSR operation.

    Comment


    • #4
      Basically you can not usually do what you were asking for in a compiled language. Scripting languages like Python, PHP, node.js, etc. usually have an ability to do this kind of thing but not compiled languages like C, C++, COBOL, RPG, etc.

      If you have any questions please feel free to holler - I've written a number of things using techniques like these.

      Comment

      Working...
      X