How to determine if string is numeric?

 3 Replies
 1 Subscribed to this topic
 17 Subscribed to this forum
Sort:
Author
Messages
Woozy
Veteran Member
Posts: 709
Veteran Member

    Hi All,

    It seems like I've done this before, but I can't remember how to do it.  I have a string field that may or may not be numeric.  How do I determine if it is numeric so I can redefine it and output the numeric value?  When I try just redefining the string as numeric in the WS, it returns the numeric as empty and throws the "Illegal character in numeric field" error when I try to reference it.

    Thanks!  Kelly

     

     

    Kelly Meade
    J. R. Simplot Company
    Boise, ID
    Woozy
    Veteran Member
    Posts: 709
    Veteran Member
      Never Mind! Of course, as soon as I posted this, I found an acceptable answer.

      First, I created a redefine in the WS:

      02 ZJ302-VAL-IN-STR PIC X(9) VALUE SPACES.
      02 ZJ302-VAL-OUT-NBR REDEFINES ZJ302-VAL-IN-STR.

      Then I used the 2000-JUSTIFY-OBJECT

      MOVE INPUT-STRING TO JSTWS-STR.
      MOVE 9 TO JSTWS-STR-LEN.
      MOVE 9 TO JSTWS-STR-OUT-LEN.
      SET JSTWS-NUMERIC TO TRUE.
      PERFORM 2000-JUSTIFY-OBJECT.


      This returns JSTWS-STR-OUT and either JSTWS-ERROR (if it is not numeric) or JRTWS-NO-ERROR (if it is numeric), so I can then go:

      IF (JRTWS-NO-ERROR)
      MOVE JSTWS-STR-OUT TO ZJ302-VAL-IN-STR
      MOVE ZJ302-VAL-OUT-NBR TO OUTPUT-NUMBER


      Thanks to my old friend Jim Herb and his post on a similar issue in this thread: https://www.lawsonguru.co...-lawson-api-listing/
      Kelly Meade
      J. R. Simplot Company
      Boise, ID
      jaherb
      Veteran Member
      Posts: 164
      Veteran Member

        Happy Friday, Kelly !   

        Vijay S
        Veteran Member
        Posts: 174
        Veteran Member

          Here is something I got from my previous codes.

          Attachments