George:

As mentioned earlier, doing a "OCONV('RecordKey', 'TFileName;X;;0')" will either return a null string if the item doesn't exist or the RecordKey if it does exist. This seems simple enough. However, I'm running UD v7.2.7.

2 Dev (0)-> BPTEST CRT OCONV('BILL.TEST', 'TVOC;X;;0') ; END

Compiling Unibasic: SAVEDLISTS\BpTest_506878981 in mode 'p'.
compilation finished

2 Dev (0)-> AE VOC BILL.TEST
Top of New "BILL.TEST" in "VOC".
*--: FI
Filed "BILL.TEST" in file "VOC" empty record created.
2 Dev (0)-> BPTEST CRT OCONV('BILL.TEST', 'TVOC;X;;0') ; END

Compiling Unibasic: SAVEDLISTS\BpTest_507019381 in mode 'p'.
compilation finished
BILL.TEST

After converting from D3 this is a really cool feature, and works in BASIC where:

READV DoesExist FROM SOMEFILE, SOMEID, 0 ELSE NULL

...sets DoesExist to 1 if it exists and to 0 if it doesn't.

This should resolve your issue.  HTH,

Bill

------------------------------------------------------------------------
George Gallen said the following on 10/11/2010 1:13 PM:
If you a 'C' instead of using 'X' TRANS returns the @ID if the read
    was unsuccessful, my only problem with this was that on occaision
    my data was the same as the @ID, so I couldn't differential between
    the bad read response from TRANS and a good read with data = @ID

I suppose, I could read the whole record, and only if data = @ID
    do a second read wouldn't be too expensive, since it's quite a
    minority of the time that would happen.

But either way, 'X' or 'C', unless I actually do an OPEN/READ it will
    require a double TRANS to clarify.

George

-----Original Message-----
From: [email protected] [mailto:u2-users-
[email protected]] On Behalf Of Rick Nuckolls
Sent: Monday, October 11, 2010 4:06 PM
To: U2 Users List
Subject: Re: [U2] Stumped with TRANS...

I do not think that there is a way to test the result of a TRANS to
discover if the read succeeded or was not found.  So, that would leave
the slightly flawed options of a) calling a subroutine or b) using the
itype below (though it does have a problem with a record id of "", or a
value in F1 of 'not found').  What did you want to happen if the record
is not on file?

I doubt that you would, in practice, find much penalty for doing the
TRANS twice on the same record.

Example for a dictionary:

TRANS(transfile, @ID,@ID,'X'); IF @ = '' THEN 'not found' ELSE TRANS(
transfile, @ID, F1,'X')

For Basic:

VALUE = TRANS("TRANSFILE", id, 1, "X")
IF VALUE = "" THEN
        IF  TRANS("TRANSFILE", id, 0, "X") = "" THEN
                VALUE = "not found"
        END
END

But ultimately, either one is flawed if the key is blank.
Is there some reason why you do not want to open the file to named
common?

COMMON /MYSUB/ MYTIME, MYFILE
IF (MYTIME # @TIME ) THEN
        *  new program execution
        OPEN '','TRANSFILE' TO MYFILE ELSE ....
        MYTIME = @TIME
END

(Just as I am about to send this, I see a similar suggestion from Mark
Eastwood.)

Rick Nuckolls
Lynden Inc

_______________________________________________
U2-Users mailing list
[email protected]
http://listserver.u2ug.org/mailman/listinfo/u2-users
_______________________________________________
U2-Users mailing list
[email protected]
http://listserver.u2ug.org/mailman/listinfo/u2-users

Reply via email to