Focal Point Banner


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.


Focal Point    Focal Point Forums  Hop To Forum Categories  WebFOCUS/FOCUS Forum on Focal Point     [SOLVED] Count the number of 1s in a numeric field

Read-Only Read-Only Topic
Go
Search
Notify
Tools
[SOLVED] Count the number of 1s in a numeric field
 Login/Join
 
Platinum Member
posted
If I have a 31 digit field that would have values with 0's and 1s ( Ex: 011100101110101 ). I want to count the 1s in the number field.?

Is it possible.?

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


App Studio Version 8202
windows Platform
SQL Server 2008/2012
 
Posts: 183 | Location: TX | Registered: January 22, 2007Report This Post
Expert
posted Hide Post
Here's an example of how to count a character in a string.

1) Determine the length of the string
2) Convert the 1's to blanks
3) Strip the blanks out of the string
4) Determine the length of the string without the blanks
5) Determine the number of blanks in the string by subtracting the length of the string without the blanks from the length of the string


DEFINE FILE CAR
NUMSTRING/A15 =
IF COUNTRY EQ 'ENGLAND' THEN '011100101110101' ELSE
IF COUNTRY EQ 'FRANCE'  THEN '110100111111000' ELSE
IF COUNTRY EQ 'JAPAN'   THEN '011001100010001' ELSE
IF COUNTRY EQ 'ITALY'   THEN '101010101010010' ELSE
                             '010101101010001';

INSTRLEN/D4 = ARGLEN(15, NUMSTRING, 'D4');
OUTSTR1/A15 = CTRAN(15, NUMSTRING, BYTVAL('1','I3'), BYTVAL(' ','I3'), OUTSTR1);
OUTSTR2/A15 = STRIP(15, OUTSTR1, ' ', OUTSTR2);
OUTSTRLEN/D4 = ARGLEN(15, OUTSTR2, 'D4');
NBR_ONES/D4 = INSTRLEN - OUTSTRLEN;
END

TABLE FILE CAR
PRINT
NUMSTRING
-*INSTRLEN
-*OUTSTR1
-*OUTSTR2
-*OUTSTRLEN
NBR_ONES
END


[SOLVED] Count blanks in a string


Francis


Give me code, or give me retirement. In FOCUS since 1991

Production: WF 7.7.05M, Dev Studio, BID, MRE, WebSphere, DB2 / Test: WF 8.1.05M, App Studio, BI Portal, Report Caster, jQuery, HighCharts, Apache Tomcat, MS SQL Server
 
Posts: 10577 | Location: Toronto, Ontario, Canada | Registered: April 27, 2005Report This Post
Virtuoso
posted Hide Post
create a master that describes this string

the occurs=variable will give the answer

FILENAME=FP, SUFFIX=FIX
SEGNAME=ROOT, OCCURS=VARIABLE
FIELD=CODE,,A1,,$


now you have a database with 31 records either 0 or 1

this can be done with any string
"hello world here I am"
tells you it has 3 times 'e' and 'l' and so on....




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, 2006Report This Post
Virtuoso
posted Hide Post
I tend to use STRREP more:
ONES/I2 = ARGLEN(31,STRREP(31,BINARY,1,'0',0,'X',31,'A31'),'I2');
ZEROS/I2 = ARGLEN(31,STRREP(31,BINARY,1,'1',0,'X',31,'A31'),'I2');


Alan.
WF 7.705/8.007
 
Posts: 1451 | Location: Portugal | Registered: February 07, 2007Report This Post
Platinum Member
posted Hide Post
all methods above are good. my preference is Frank's. But just to throw another flavor at ya..(Yes -repeat here would be better, but I elongated to hsow you logic behind it.)
-REPEAT (looping).
-* INITIALIZE SOME DUMMY VALUE..
-SET &CHK1 =4;
-SET &CHK2 =5;
-SET &CHK3 =6;
-SET &CHK4 =7;
-SET &CHK5 =8;
-* INITIALIZE A HOLDING BUCKET FOR THE VALUE...
-SET &KNTR = 0 ;
-RUN
DEFINE FILE CAR
TST/A31
WITH COUNTRY='1010101010101010101010101010101';
END
TABLE FILE CAR PRINT TST WHERE RECORDLIMIT EQ 1
ON TABLE SAVE AS MYDUMMY
END
-RUN
-READ MYDUMMY NOCLOSE &CHK1 &CHK2 &CHK3 &CHK4 &CHK5 (....to 31)
-SET &KNTR = &KNTR + &CHK1 + &CHK2 + &CHK3 +&CHK4 + &CHK5; (all the way to 31)..
-TYPE &KNTR ;
-READ MYDUMMY NOCLOSE
-EXIT

hope it helps...
Ira


aix-533,websphere 5.1.1,apache-2.0,
wf 538(d), 537 (p),
==============
7.6.11 (t) aix 5312
websphere 6.1.19
apache 2.0
 
Posts: 195 | Registered: October 27, 2006Report This Post
Expert
posted Hide Post
Alan B, I don't see how the combination of ARGLEN and STRREP works to determine the count of a particular character in a string.

This doesn't work:

TABLE FILE CAR
PRINT
MODEL
-*STRREP (inlength, instring, searchlength, searchstring, replength, repstring, outlength, outstring)
COMPUTE ONES/I2 = ARGLEN(24,STRREP(24,MODEL,1,'0',0,'X',24,'A24'),'I2');
COMPUTE ZEROS/I2 = ARGLEN(24,STRREP(24,MODEL,1,'1',0,'X',24,'A24'),'I2');
END


Francis


Give me code, or give me retirement. In FOCUS since 1991

Production: WF 7.7.05M, Dev Studio, BID, MRE, WebSphere, DB2 / Test: WF 8.1.05M, App Studio, BI Portal, Report Caster, jQuery, HighCharts, Apache Tomcat, MS SQL Server
 
Posts: 10577 | Location: Toronto, Ontario, Canada | Registered: April 27, 2005Report This Post
Virtuoso
posted Hide Post
Francis
quote:
If I have a 31 digit field that would have values with 0's and 1s ( Ex: 011100101110101 ). I want to count the 1s in the number field.?


I did not say it worked on model, or anything else other than a field with 1s' and 0s',i.e. a binary type field, which is what was asked for.

However if you use:
TABLE FILE CAR
PRINT
MODEL
-*STRREP (inlength, instring, searchlength, searchstring, replength, repstring, outlength, outstring)
COMPUTE ONES/I2 = ARGLEN(24,STRREP(24,MODEL,1,'1',0,'X',24,'A24'),'I2');
COMPUTE ZEROS/I2 = ARGLEN(24,STRREP(24,MODEL,1,'0',0,'X',24,'A24'),'I2');
COMPUTE TOTAL/I2 = ARGLEN(24,MODEL,'I2');
COMPUTE ACTUAL_ONES/I2 = TOTAL - ONES;
COMPUTE ACTUAL_ZEROS/I2 = TOTAL - ZEROS;
END


It works.

This message has been edited. Last edited by: Alan B,


Alan.
WF 7.705/8.007
 
Posts: 1451 | Location: Portugal | Registered: February 07, 2007Report This Post
Virtuoso
posted Hide Post
quote:
Originally posted by Francis Mariani:
This doesn't work:

But this does: Squeeze out the blanks, then squeeze out the 0's, and compare the lengths:
DEFINE FILE CAR
WARR0/A25=SUBSTR(40,WARRANTY,1,25,25,'A25');
WARR1/A25=STRREP(25,WARR0,1,' ',0,' ',25,'A25');
WARR2/A25=STRREP(25,WARR1,1,'0',0,' ',25,'A25');
LEN0/I2 = ARGLEN(25,WARR0,'I2');
LEN1/I2 = ARGLEN(25,WARR1,'I2');
LEN2/I2 = ARGLEN(25,WARR2,'I2');
ZEROS/I2=LEN1-LEN2;
END

TABLE FILE CAR
PRINT WARR0 WARR1 WARR2 LEN0 LEN1 LEN2 ZEROS
BY CAR 
IF WARRANTY NE ' '
ON TABLE PCHOLD FORMAT WP
END

  PAGE     1
  
  
  CAR               WARR0                      WARR1                      WARR2                      LEN0  LEN1  LEN2  ZEROS      
  ---               -----                      -----                      -----                      ----  ----  ----  -----      
  AUDI              12 MONTHS OR 20000 MILES   12MONTHSOR20000MILES       12MONTHSOR2MILES             24    20    16      4
  DATSUN            12 MONTHS OR 12000 MILES   12MONTHSOR12000MILES       12MONTHSOR12MILES            24    20    17      3
  JAGUAR            12 MONTHS OR 12000 MILES   12MONTHSOR12000MILES       12MONTHSOR12MILES            24    20    17      3
  JENSEN            12000 MILES OR 12 MONTHS   12000MILESOR12MONTHS       12MILESOR12MONTHS            24    20    17      3
  MASERATI          6 MONTHS OR 6000 MILES     6MONTHSOR6000MILES         6MONTHSOR6MILES              22    18    15      3
  PEUGEOT           12 MONTHS ON 12000 MILES   12MONTHSON12000MILES       12MONTHSON12MILES            24    20    17      3
  TOYOTA            12 MONTHS OR 12500 MILES   12MONTHSOR12500MILES       12MONTHSOR125MILES           24    20    18      2
  TRIUMPH           12 MONTHS OR 12000 MILES   12MONTHSOR12000MILES       12MONTHSOR12MILES            24    20    17      3



- Jack Gross
WF through 8.1.05
 
Posts: 1925 | Location: NYC | In FOCUS since 1983 | Registered: January 11, 2005Report This Post
Expert
posted Hide Post
Thanks Alan - I get it.


Francis


Give me code, or give me retirement. In FOCUS since 1991

Production: WF 7.7.05M, Dev Studio, BID, MRE, WebSphere, DB2 / Test: WF 8.1.05M, App Studio, BI Portal, Report Caster, jQuery, HighCharts, Apache Tomcat, MS SQL Server
 
Posts: 10577 | Location: Toronto, Ontario, Canada | Registered: April 27, 2005Report This Post
Platinum Member
posted Hide Post
Thanks for all the answers. I just need to count 0's and 1's so Alans answer works best for me.


App Studio Version 8202
windows Platform
SQL Server 2008/2012
 
Posts: 183 | Location: TX | Registered: January 22, 2007Report This Post
  Powered by Social Strata  

Read-Only Read-Only Topic

Focal Point    Focal Point Forums  Hop To Forum Categories  WebFOCUS/FOCUS Forum on Focal Point     [SOLVED] Count the number of 1s in a numeric field

Copyright © 1996-2020 Information Builders