ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

Character field lengths

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

  • Character field lengths

    Hi,
    I have a character field of 30 positions where only the first 10 are used.
    When checking the field, the string used is only the length of the known data and this has raised questions from others.
    So, if the character data I'm looking for is 10 positions long in a field of 30 positions (left justified), does it matter if my string value is 10 or 30?
    Everyday's a school day, what grade are you in?

  • #2
    What do you mean by "checking the field", Redvan? What is this string value you mention?

    Comment


    • redvan
      redvan commented
      Editing a comment
      Checking the field for a specific value, IE: if fld01 = '1234567890' do something.... compared to, if fld01 = '1234567890____________________' do something....
      Last edited by redvan; April 5, 2022, 06:59 AM. Reason: System removed the blanks from my example making it unclear so I replaced the blanks with underscore.

  • #3
    As ted Holt mentions, your questions are not clear.
    Are you concerned about moving the data to another field, and what length it should be ?

    If you are confident the data is no more than 10, you can work with just pos 1 - 10. But what if it changes in the future, so that more positions are used ? How much coding will need to change ?

    Comment


    • #4
      On other sites, you can do a 'Reply' to a specific users post but not here. Is that the 'Quote' feature?
      I tried comment on Ted Holts post but it disappeared.

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

      Comment


      • #5
        If you compare two character values (usually a variable and a literal or two variables) of different lengths, the system will treat it as if the shorter value is padded with trailing blanks. In your case, comparing a 30-byte variable with a 10-byte literal is like comparing to the same literal with an additional 20 blanks added to the end of it.

        In your case, you don't have to make the literal 30 bytes long. Ten bytes are enough for the comparison.

        Comment

        Working...
        X