openedgeprogress-4glprogress-db

How to validate against item master table


I am creating a custom report screen in which I have a fields item number, item type, prod line and status and there is a condition for item number that is I have to validate it against pt_mstr which from what i understand means that the item number that I enter should be present in pt_mstr. And if it's blank then give an error. I've done the validation for blank with this code

If lvc_part = "" then do: 
{us/bbi/pxmsg.i &msgnum=40 &errorlevel=3} 
Undo mainloop, retry mainloop.
End.

Lvc_part is the variable i declared for item number and mainloop is the loop inside which I'm writing my entire logic. I am getting the general idea for validating item number against pt_mstr but I'm not getting how to put it down as a code. I'm thinking we need to include a find first query to see if the item number is present in pt_mstr or not but I'm not sure. Any leads would be helpful, if you want to know anything regarding the declarations I've used or anything else let me know. Thanks in advance!


Solution

  • You need to add code like this

    IF NOT CAN-FIND (FIRST pt_mstr WHERE pt_mstr.<keyfieldname> = lvc_part) THEN 
        <display error message>
    

    or when it's a index with multiple fields:

    IF NOT CAN-FIND (FIRST pt_mstr WHERE pt_mstr.<keyfieldname1> = lvc_part
                                     AND pt_mstr.<keyfieldname2> = <value>) THEN 
        <display error message>
    

    Most likely you can (and should) leave out the FIRST phrase in the CAN-FIND expression as typically you'd be using a UNIQUE find here.