ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

3 byte input filed on display and same field as 4 byte output field

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

  • 3 byte input filed on display and same field as 4 byte output field

    We have a 4 byte alphanumeric filed on a screen that the users want changed to a 3 byte input field, but return to the screen a 4 byte field. This is because the 1st byte is always zero and they don't want to have to enter it, but when the display refreshes, they want to see the 4 bytes.
    Any ideas?
    Thanks,
    John
    p.s. Having a hard time logging in to CODE400.com, anyone else?
    John M. Mauro
    Software Engineer
    nThrive

  • #2
    Re: 3 byte input filed on display and same field as 4 byte output field

    Too bad it's not a numeric field or I would suggest using the EDTMSK DDS keyword. You could leave the field as 4 characters and have the users enter the 3 that they want, then in the code append a leading zero if 3 characters were entered.

    Comment


    • #3
      Re: 3 byte input filed on display and same field as 4 byte output field

      I don't understand why they have to enter the leading zero?! If the field is character, then in the RPG program, convert it to numeric with %DEC(), in that case leading zeros, decimal places, etc are not required... they don't have to type them. If the field is numeric, then they can just hit field exit (or field +/field -) so that it's not necessary to type the leading zero... I don't think you're gaining much by eliminating that first space.

      But, if you do want to eliminate it, it's easy enough to do. Just have a separate field name, and copy the data over.

      Comment


      • #4
        Re: 3 byte input filed on display and same field as 4 byte output field

        Originally posted by Brian Rusch View Post
        Too bad it's not a numeric field or I would suggest using the EDTMSK DDS keyword. You could leave the field as 4 characters and have the users enter the 3 that they want, then in the code append a leading zero if 3 characters were entered.
        Thanks Brian. I too wish it were a numeric field as it would be easier
        I don't understand why the users need to have a four byte field returned after they entered 3 byte, but I don't make the decisions

        Happy Holidays.
        John M. Mauro
        Software Engineer
        nThrive

        Comment


        • #5
          Re: 3 byte input filed on display and same field as 4 byte output field

          Is there ever a case where only two characters would be entered? Or one? That is, is it always just a single leading zero?
          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


          • #6
            Re: 3 byte input filed on display and same field as 4 byte output field

            The intend is to let the users enter three consecutive bytes in the 4 byte field.
            If the enter 131 in the first three bytes and leave the four byte blank, I will return 0131.
            If they enter a blank in byte 1 an then 131 in the remaining three bytes, I return 0131.
            If they enter any other pattern ( ex: 1_31, 13_1) we return an error message saying "NO CAN DO".
            John M. Mauro
            Software Engineer
            nThrive

            Comment


            • #7
              Re: 3 byte input filed on display and same field as 4 byte output field

              because its character could you use a variable named myzeros and inz('0000') When enter pressed get # of digits mylength = %len(%trim(mydumbfield));
              then just substring in the leading zeros mydumbfield = %subst(myzeros:1:4-mylength) + %trim(mydumbfiled)

              if %check('0123456789':mydumbfield) > *zeros
              bad data
              endif

              friggen %check -- they named it that cause I have to check every time if its greater than *zeros or *zeros ....


              what issues are you having logging in?
              Last edited by jamief; December 11, 2014, 06:17 AM.
              All my answers were extracted from the "Big Dummy's Guide to the As400"
              and I take no responsibility for any of them.

              www.code400.com

              Comment


              • #8
                Re: 3 byte input filed on display and same field as 4 byte output field

                I do not think what you want to do is possible with DDS. The closest to what you want is to set the field to Right adjust Zero Fill, CHECK(RZ). Using this means they would need to use a field exit on the field. After some testing I also found that the field is not always displayed Zero filled if you have less that 3 characters entered however. Another possibility which may work better is to use a 3 byte input only field and to display the result in a 4 byte output field next to it. Other than experimenting with the display API's I think those are you best options at this point.

                Comment


                • #9
                  Re: 3 byte input filed on display and same field as 4 byte output field

                  Originally posted by jamief View Post
                  because its character could you use a variable named myzeros and inz('0000') When enter pressed get # of digits mylength = %len(%trim(mydumbfield));
                  then just substring in the leading zeros mydumbfield = %subst(myzeros:1:4-mylength) + %trim(mydumbfiled)
                  Or just do
                  Code:
                  EVALR mydumbfield = myzeros + %trim(mydumfield)

                  Comment


                  • #10
                    Re: 3 byte input filed on display and same field as 4 byte output field

                    EVAL Field4 = '0' + %subst(Field4:2:3)

                    Comment


                    • #11
                      Re: 3 byte input filed on display and same field as 4 byte output field

                      Always more than one way to skin the proverbial cat:

                      Code:
                      EXEC SQL SET :MYDUMFIELD = RIGHT('0000' || TRIM(:MYDUMFIELD),4);

                      Comment


                      • #12
                        Re: 3 byte input filed on display and same field as 4 byte output field

                        Or, for a numeric value in a char field you can do this:

                        Code:
                        Field = %editc( %dec(field:4:0): 'X');

                        Comment

                        Working...
                        X