As of December 1, 2020, Focal Point is retired and repurposed as a reference repository. We value the wealth of knowledge that's been shared here over the years. You'll continue to have access to this treasure trove of knowledge, for search purposes only.
Join the TIBCO Community TIBCO Community is a collaborative space for users to share knowledge and support one another in making the best use of TIBCO products and services. There are several TIBCO WebFOCUS resources in the community.
From the Home page, select Predict: WebFOCUS to view articles, questions, and trending articles.
Select Products from the top navigation bar, scroll, and then select the TIBCO WebFOCUS product page to view product overview, articles, and discussions.
Request access to the private WebFOCUS User Group (login required) to network with fellow members.
Former myibi community members should have received an email on 8/3/22 to activate their user accounts to join the community. Check your Spam folder for the email. Please get in touch with us at community@tibco.com for further assistance. Reference the community FAQ to learn more about the community.
DEFINE FILE CAR
NUM/A16='0110110011111001';
-* Remove trailing '0's
TRIM1/A16V= TRIMV('T',NUM,16,'0',1,'A16V');
-* Remove last character, which will be a '1'
TRIM2/A16V= SUBSTV(16,TRIM1,1,LENV(TRIM1,'I2')-1,'A16V');
-* Remove trailing '0's
TRIM3/A16V= TRIMV('T',TRIM2,16,'0',1,'A16V');
-* Length will be position of penultimate 1.
PLACE/I2=LENV(TRIM3,'I2');
END
TABLE FILE CAR
PRINT COUNTRY NUM TRIM1 TRIM2 TRIM3 PLACE
END
(Edit: Changed length 15 to 16 because, as Tony pointed out, I cannot count early in the morning!)This message has been edited. Last edited by: Alan B,
Alan. WF 7.705/8.007
Posts: 1451 | Location: Portugal | Registered: February 07, 2007
Alan, shouldn't the lengths be 16 and not 15? (early morning)
Getit,
I did think about using GETTOK and setting the delimiter to '0' especially as the GETTOK allows search from end using -1 for the last and -2 for the second to last etc. But in the string supplied the second to last would actually be '' as there are two 0s together. The second to last 1 would need -3 and that would return 11111
So, depending upon your file type the only thing that I can think of that may help is the POSITION attribute within a MFD (mas). From the DS help files -
Here's another way to find the second to last occurance of the 1. The key to this techniaue is to reverse the string and then use POSIT to find the position of the second to last 1. This is probably not the best solution but it works.
DEFINE FILE CAR ORGNUM/A16='0110110011111001'; REVNUM/A16=REVERSE(16,ORGNUM,'A16'); FSTONE/I2 =POSIT(REVNUM,16,'1',1,'I2'); NUMTWO/A16=SUBSTR(16,REVNUM,FSTONE+1,16,16-FSTONE,'A16'); SECONE/I2 =POSIT(NUMTWO,16,'1',1,'I2'); THEPOSITION/I2=(16-(FSTONE+SECONE))+1; END TABLE FILE CAR PRINT ORGNUM REVNUM FSTONE NUMTWO SECONE THEPOSITION AS 'The Second 1 is,Located at Position' BY COUNTRY WHERE RECORDLIMIT EQ 1 END
Thanks!
Mickey
FOCUS/WebFOCUS 1990 - 2011
Posts: 995 | Location: Gaithersburg, MD, USA | Registered: May 07, 2003
I did not test either of the solutions, but what if the original number has only one "1" pe "0000000010" or "010000000" or "1"....
You can test this by first converting the number from binary to decimal. If the decimal number is 2^0 till 2^15 than the binary number only holds one "1" and the other tests can be passed.
Just a thought...
Frank
prod: WF 7.6.10 platform Windows, databases: msSQL2000, msSQL2005, RMS, Oracle, Sybase,IE7 test: WF 7.6.10 on the same platform and databases,IE7
Posts: 2387 | Location: Amsterdam, the Netherlands | Registered: December 03, 2006