Focal Point
[SOLVED] Specific word in a alpha field

This topic can be found at:
https://forums.informationbuilders.com/eve/forums/a/tpc/f/7971057331/m/8237068096

October 18, 2018, 01:15 PM
YKK
[SOLVED] Specific word in a alpha field
Hi

I need to define a field that will look for the word Rush in a comment field and will equal 1 if it does and 0 if it does not

I am not trying to find only the record with Rush in it but just show which record have and which don't

Problem is that comment field can show " Please ship rush ", " this order is rush ", " Rush order " and so on as these comment are not always enter by the same user

This is something I never did before and help would be greatly appreciated

Thank you.

This message has been edited. Last edited by: FP Mod Chuck,


7.6. / Win 7 / Excel
October 18, 2018, 01:19 PM
BabakNYC
Assuming you're running 8.2xx, try the POSITION function and count the ones that have a value not equal to 0.

https://webfocusinfocenter.inf.../source/position.htm


In this example I'm flagging the records that have 'GER' in the field COUNTRY.
  

TABLE FILE CAR
PRINT COUNTRY CAR
COMPUTE GER_IN_COUNTRY/I2=POSITION('GER', COUNTRY); NOPRINT
COMPUTE RECORDS_WITH_GER/I2=IF GER_IN_COUNTRY NE 0 THEN 1 ELSE 0;
END

This message has been edited. Last edited by: BabakNYC,


WebFOCUS 8206, Unix, Windows
October 18, 2018, 01:43 PM
MartinY
And since the case may be important

TABLE FILE CAR
PRINT COUNTRY CAR
COMPUTE GER_IN_COUNTRY/I2=POSITION('GER', UPCASE(10, COUNTRY, 'A10')); NOPRINT
COMPUTE RECORDS_WITH_GER/I2=IF GER_IN_COUNTRY NE 0 THEN 1 ELSE 0;
END



WF versions : Prod 8.2.04M gen 33, Dev 8.2.04M gen 33, OS : Windows, DB : MSSQL, Outputs : HTML, Excel, PDF
In Focus since 2007
October 18, 2018, 02:09 PM
jfr99
There's also "CONTAINS" ...

TABLE FILE CAR
PRINT MODEL
BY COUNTRY
BY CAR
END
-*
TABLE FILE CAR
PRINT MODEL
BY COUNTRY
BY CAR
WHERE MODEL CONTAINS 'AUTO' OR 'III'
END


You would still need to deal with mixed case values.


WebFocus 8.201M, Windows, App Studio
October 18, 2018, 02:26 PM
BabakNYC
MartinY has a point. I'd upcase the values before checking.

FYI, there's now a simplified UPPER(fieldname) function that's slightly easier than UPCASE.

  
TABLE FILE CAR
PRINT COUNTRY CAR
COMPUTE GER_IN_COUNTRY/I2=POSITION('GER', UPPER(COUNTRY)); NOPRINT
COMPUTE RECORDS_WITH_GER/I2=IF GER_IN_COUNTRY NE 0 THEN 1 ELSE 0;
END


Regarding CONTAINS, I agree that's another way of approaching the issue. You could also use LIKE. Many ways to get to the same outcome.


WebFOCUS 8206, Unix, Windows
October 18, 2018, 02:45 PM
MartinY
quote:
there's now a simplified UPPER(fieldname) function that's slightly easier than UPCASE

Old habits Smiler


WF versions : Prod 8.2.04M gen 33, Dev 8.2.04M gen 33, OS : Windows, DB : MSSQL, Outputs : HTML, Excel, PDF
In Focus since 2007
October 21, 2018, 08:38 AM
dhagen
The REGEX function returns 1 or 0 based on match:

This does a case insensitive search for the word "imports".

DEFINE FILE GGPRODS
IMP/I5 = REGEX(VENDOR_NAME,'(?i)\bimports\b');
END
TABLE FILE GGPRODS
PRINT *  IMP
END  



"There is no limit to what you can achieve ... if you don’t care who gets the credit." Roger Abbott