ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

Numeric fields

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

  • #16
    Your program is neither STRSQL nor RUNQRY. In your program you converted the number with %EditC (which is an RPG function).
    I have no idea what your problem is if you see the same number in STRSQL as 10-.
    But if you really want to format your number in STRSQL, you can use the SQL scalar function VARCHAR_FORMAT.
    The VARCHAR_FORMAT function returns a character string representation of the first argument in the format indicated by the optional format-string.

    Comment


    • #17
      But is it not possible in this program itself to write in y7fld in such a way that when we do RUNQRY or STRSQL on that y7 file then we should see it like '-10' If yes, then please advise what changes in this program should be made to achieve the same result?


      Thanks...

      Comment


      • #18
        This comes back to my earlier question, what are you trying to achieve?

        You mention you want RUNQRY to display the value as -10. I don't believe query has a method to alter the way negative numbers are displayed by default. You'd have to ask IBM to modify their program but I would think it highly unlikely they would do that.

        You mention you want STRSQL to display the value as -10. Same comments as above really though Barbara has mentioned how you can format the number using SQL functions. However, why don't you use SQL via ACS as that formats it the way you want?

        All through this thread however you've been mentioning RPG code. I don't know what this has to do with RUNQRY or STRSQL. However, absolutely nowhere in your code have you mentioned how you are displaying the values of the variables. If you are viewing the info in debug, then again, debug is IBM software and it has chosen to display the result in the way it does. If it's not how you like it, then you'd need to ask IBM to change their code. Again, I think that would be highly unlikely. But, maybe you're writing this to a display file? If that's the case, then we can assist in specifying edit codes in the display file to give leading negative signs and no leading zeros.

        But we don't really know what you're trying to achieve so without something more specific it's difficult to give advice you are after.

        Comment


        • #19
          Thanks, but I am not sure what changes in my program should I make so that all negative numbers stored in this 'y7fld' should be displayed by putting '-' sign in front of them not after them when someone does RUNQRY on this file or use SQL query to see the value of 'y7fld' field.



          Thanks...

          Comment


          • #20
            The only way to do that would be to make it a character field in the file which doesn't make sense if it is a numeric field. You cannot control how other programs display a numeric field - that is up to those programs. Those programs may have options to change how a field is displayed but you cannot control that from your program.

            Comment


            • #21
              So, after all these posts we've finally found out what you are really after. You want query (and STRSQL) to display the negative before the number rather than after.
              The answer to that question is you can't. How a number is displayed on screen is completely up to the tool you are using. In the case of RUNQRY, IBM have chosen to put the negative sign after the number when it is displayed. There is absolutely nothing you can do to change this behaviour as it's RUNQRY that is displaying it that way. It has nothing whatsoever to do with how the data is stored in the file so your programming attempts have been pointless. As I mentioned previously, if you want this behaviour changed in RUNQRY, you'd have to ask IBM to change RUNQRY so it displays the negative sign before the number.

              Comment


              • #22
                As previously mentioned, Client Access Query displays the negative sign before the number:

                SELECT Negative_Number From MyTable
                -10
                -8
                -7
                -22


                I use that tool quite a bit. I almost never use green screen query.
                Last edited by MFisher; January 20, 2022, 04:20 PM.

                Comment

                Working...
                X