ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

Returning value in command

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

  • Returning value in command

    Is there a way to take a command parameter value, lookup it up in a file either through a CL or RPG or some other way, and have a value returned to another parameter.

    I'm not talking about a prompt override program using a key parm but instead just a simple straightforward command where they enter a dozen parameter values and then look up the last one to retrieve a value and display it in another parameter.

    To better understand what I'm trying to accomplish;
    I have a command where a user can enter values for a new task and one of the parameters they have to enter is the requestor of the task. I want to take this requestor name and look it up in file to see if an email address is on file for it. If not, I want to force the user to enter one for the requestor or, if it is found to be on file display it.

    I can use a validity checking program for the majority of this but I'm not sure how to return the address, or if it's even possible.

    Red.
    Everyday's a school day, what grade are you in?

  • #2
    Re: Returning value in command

    sounds best solved by using a program and screen.
    Hunting down the future ms. Ex DeadManWalks. *certain restrictions apply

    Comment


    • #3
      Re: Returning value in command

      DeadMan,
      Yeah, that would solve the problem but most enter the command positionally on a cmd line as they're so used to it by now. Changing it all over to a HLL application I don't think would fly too well.

      Thank for the suggestion though,
      Red.
      Everyday's a school day, what grade are you in?

      Comment


      • #4
        Re: Returning value in command

        Originally posted by redvan View Post
        ...but most enter the command positionally on a cmd line as they're so used to it by now.
        The 'Return value' of a *CMD needs to go into a variable. It technically needs a memory address where the 'return value' can be stored, so a variable fits the need. If you need a value somehow returned to the display screen, you might need to use something like:
        Code:
        sndpgmmsg   msgid( CPF9897 )  msgf( QCPFMSG )  +
                      msgdta( &myRtnVal )
        The SNDPGMMSG defaults should be sufficient to return the value to the message line of a screen that handles a command line. Or perhaps the Display Long Text (QUILNGTX) API would be better if the message line isn't appropriate.

        For a HLL, use the QMHSNDPM API to replace SNDPGMMSG.
        Tom

        There are only two hard things in Computer Science: cache invalidation, naming things and off-by-one errors.

        Why is it that all of the instruments seeking intelligent life in the universe are pointed away from Earth?

        Comment


        • #5
          Re: Returning value in command

          Originally posted by redvan
          I want to take this requestor name and look it up in file to see if an email address is on file for it. If not, I want to force the user to enter one for the requestor or, if it is found to be on file display it.
          Hi, Red.

          I don't know a way to do exactly what you're trying to do, but since the users run your command from a command line, here's an alternative that might work.

          You could add another, optional parameter to the command for the requester's email address. Let's call it REQEMAIL for this example.

          The CPP (command-processing program) looks for the task requester's email address in the database table. If it is not found, it checks to see if the user entered an email address for the requester in REQEMAIL. If REQEMAIL has an email address, then the program keeps running.

          If not, the CPP program sends an escape message that tells the user that no email address is on file for the requester, so the user must fill in the REQEMAIL parm.

          Since it's an escape message, the command stays on the command line, where the user can prompt it with F4 and fill in the REQEMAIL parm.

          Comment


          • #6
            Re: Returning value in command

            Here's a simple CL program that has a parm coming in that it uses for a "lookup". If the "lookup" fails, it keeps asking for a value that makes the "lookup" succeed. In this case, the parm is supposed to be a user profile name and the "lookup" is just the RTVUSRPRF command:
            Code:
            pgm    ( +
                     &lookup      +
                   )
            
               dcl   &lookup      *char    10
            
            
               dcl   &jobusr      *char    10
               dcl   &bad_lookup  *lgl            value( '1' )
            
               dcl   &Keyvar      *char   255
               dcl   &Reply       *char     4
            
            
               dowhile   ( &bad_lookup )
            
                  chgvar            &bad_lookup             '0'
            
               /* Do some lookup stuff for user (or whatever) here... */
                  rtvusrprf   &lookup
                  monmsg    ( cpf2200 cpf0001 ) exec( do )
                     chgvar         &bad_lookup             '1'
                  enddo
            
               /* Test lookup results... */
                  if ( &bad_lookup )  do
                     sndpgmmsg   msg( 'Try again:' ) topgmq( *EXT ) +
                                   msgtype( *INQ ) keyvar( &Keyvar )
                     rcvmsg      pgmq( *SAME ) msgkey( &Keyvar ) rmv( *NO ) +
                                   msg( &lookup )
                  enddo
                  else  +
                     sndpgmmsg   msg( &lookup ) topgmq( *EXT )
            
               enddo
            
               return
            
            endpgm
            After some quick thought, I figured that SNDPGMMSG could be replaced by SNDUSRMSG. That makes it a little simpler. That part would then look this way:
            Code:
                  if ( &bad_lookup )  do
                     sndusrmsg   msg( 'Try again:' ) +
                                   msgtype( *INQ ) tomsgq( *EXT ) msgrpy( &lookup )
                  enddo
            A user could cancel the program or shut off the workstation. But as far as the programming goes, it keeps asking until a user profile name is entered that doesn't cause an error. Some escape value could be coded if desired.
            Tom

            There are only two hard things in Computer Science: cache invalidation, naming things and off-by-one errors.

            Why is it that all of the instruments seeking intelligent life in the universe are pointed away from Earth?

            Comment

            Working...
            X