PrevPrev Go to previous topic
NextNext Go to next topic
Last Post 09/15/2015 6:09 AM by  Vijay S
How to determine if string is numeric?
 3 Replies
Sort:
You are not authorized to post a reply.
Author Messages
Woozy
Private
Private
Veteran Member
(3487 points)
Veteran Member
Posts:707


Send Message:

--
09/11/2015 11:10 AM

    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
    Private
    Private
    Veteran Member
    (3487 points)
    Veteran Member
    Posts:707


    Send Message:

    --
    09/11/2015 11:25 AM
    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.com/forums/integration/custom/looking-for-lawson-api-listing/
    Kelly Meade
    J. R. Simplot Company
    Boise, ID
    jaherb
    Independent
    Independent
    Veteran Member
    (472 points)
    Veteran Member
    Posts:164


    Send Message:

    --
    09/11/2015 11:39 AM

    Happy Friday, Kelly !   

    Vijay S
    Lawson Developer
    Independent consultant
    Veteran Member
    (389 points)
    Veteran Member
    Posts:167


    Send Message:

    --
    09/15/2015 6:09 AM

    Here is something I got from my previous codes.

    Attachments
    You are not authorized to post a reply.