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] DECODE statement with a LOOP statement

Read-Only Read-Only Topic
Go
Search
Notify
Tools
[SOLVED] DECODE statement with a LOOP statement
 Login/Join
 
Platinum Member
posted
I am trying to build a DECODE statement from a string to sort my data. I need to loop through the string and for each data in quotes give it an counter number that start with 1. Can someone please point me in the right direction on how to figure this out.

string: &TC_V1 = 'CA' 'ALC' 'BAL'

Below is what I would like the DECODE statement to look like:

  
SORT/I2 = DECODE DACODE('CA' 1 'ALC' 2 'BAL' 3)

This message has been edited. Last edited by: <Kathryn Henning>,


Prod: WebFOCUS 7.7.03: Win 2008 & AIX hub/Servlet Mode; sub: AS/400 JDE; mostly Self Serve; DBs: Oracle, JDE, SQLServer; various output formats
 
Posts: 121 | Location: California | Registered: June 19, 2008Report This Post
Virtuoso
posted Hide Post
You could try something like:
-* How many items are there?
-* Remove quotes to get a shorter string, which can then be used to calculate the number of items in the string
-SET &SHORT_STRING = STRREP (&TC_V1.LENGTH, &TC_V1, 1, '''', 0, 'X', &TC_V1.LENGTH,'A&TC_V1.LENGTH');
-SET &SHORT_STRING = TRUNCATE(&SHORT_STRING);

-SET &NUM_ITEMS = (&TC_V1.LENGTH-&SHORT_STRING.LENGTH)/2;

-SET &DECODE_ITEMS = ' ';
-SET &CNTR=1;
-REPEAT :LOOP &NUM_ITEMS TIMES
-SET &ITEM = GETTOK(&TC_V1,&TC_V1.LENGTH,&CNTR, ' ',&TC_V1.LENGTH, 'A&TC_V1.LENGTH');
-SET &DECODE_ITEMS = &DECODE_ITEMS | TRUNCATE(&ITEM) | ' ' | &CNTR | ' ';
-SET &CNTR=&CNTR+1;
-:LOOP
-SET &DECODE_ITEMS = TRUNCATE(&DECODE_ITEMS);
-TYPE &DECODE_ITEMS
.
.
.
SORT/I2 = DECODE DACODE(&DECODE_ITEMS);
.
.
.


Alan.
WF 7.705/8.007
 
Posts: 1451 | Location: Portugal | Registered: February 07, 2007Report This Post
Platinum Member
posted Hide Post
Alan,

This worked perfectly!!!

Thanks,
prodrigu


Prod: WebFOCUS 7.7.03: Win 2008 & AIX hub/Servlet Mode; sub: AS/400 JDE; mostly Self Serve; DBs: Oracle, JDE, SQLServer; various output formats
 
Posts: 121 | Location: California | Registered: June 19, 2008Report 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] DECODE statement with a LOOP statement

Copyright © 1996-2020 Information Builders