Focal Point
[CLOSED] separating a string of data by position and assigning to the same field

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

April 04, 2013, 01:43 PM
kitten
[CLOSED] separating a string of data by position and assigning to the same field
I have a field in a file with a format of A36V. the first 4 characters is an ID. The remaining characters are assigned TAG. A TAG is 4 characters long. So after the first 4 characters, every 4 characters there after represents a TAG. I want to assign the tags to a new field called TAG. So if the string has 16 characters then there is an ID with 3 TAGS, and these tags should be in three separate rows in the TAG column. My first thought was a define but that will not work. Does anyone have any suggestions on how to separate this string of data.

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


WebFOCUS 7.6.2, MS Windows Server/______, Excel, PDF, HTML
April 04, 2013, 02:17 PM
Rao D
Since you mentioned ID will have 4 character length and TAG also 4 character length.

Read you string to a variable and divide the length by 4 . According to your example with 16 characters 16/4 = 4 so try to loop based on the output (in this case 4 times and use the below function
SUBSTR(length, source_string, start, end, sublength, output)

In that using a counter try to increment the start and end positions each time in the loop.


WebFOCUS - ver8201
[ReportingServers: Windows 64bit;
Client: tomcat and IIS on windows 2012
AppStudio

April 04, 2013, 02:29 PM
Francis Mariani
I would use an alternate master, one that has an OCCURS clause. Here's an example, though I can't manage to get it to work with an AnV field.

testdata1.ftm:
ENGLAND   AAAA12349876ABCDWXYZ
ENGLAND   ABCDOPQR6789ASDFZXCVTHATFLEA9812
FRANCE    CCCC987656781234QWRT
ITALY     DEFG98341278

testdata1.mas:
FILE=TESTDATA1, SUFFIX=FIX, $
SEGNAME=TESTDATA1
  FIELDNAME=COUNTRY     , ALIAS=COUNTRY     , USAGE=A10, ACTUAL=A10, $
  FIELDNAME=COUNTRY_DATA, ALIAS=COUNTRY_DATA, USAGE=A36, ACTUAL=A36, $

testdata1_occ.mas:
FILE=TESTDATA1_OCC, SUFFIX=FIX, $
SEGNAME=TESTDATA1
  FIELDNAME=COUNTRY     , ALIAS=COUNTRY     , USAGE=A10, ACTUAL=A10, $
  FIELDNAME=ID          , ALIAS=ID          , USAGE=A04, ACTUAL=A04, $
  FIELDNAME=COUNTRY_DATA, ALIAS=COUNTRY_DATA, USAGE=A32, ACTUAL=A32, $
SEGNAME=TAGS, PARENT=TESTDATA1, POSITION=COUNTRY_DATA, OCCURS=VARIABLE, $
  FIELDNAME=TAG         , ALIAS=TAG         , USAGE=A04, ACTUAL=A04, $

testdata1.fex:
SET BYDISPLAY=ON
SET PAGE=NOLEAD
-RUN

FILEDEF TESTDATA1 DISK test/testdata1.ftm
-RUN

TABLE FILE TESTDATA1
PRINT
COUNTRY_DATA
BY COUNTRY
END
-RUN

FILEDEF TESTDATA1_OCC DISK test/testdata1.ftm
-RUN

TABLE FILE TESTDATA1_OCC
PRINT
TAG
BY COUNTRY
BY ID
END
-RUN



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
April 04, 2013, 02:33 PM
Danny-SRL
Kitten,

Example. Your field is CATSLOVENICEGREY. Is this what you want to see:
  
ID    TAG
CATS  LOVE
      NICE
      GREY

But then a question: are you going to want to display other fields?


Daniel
In Focus since 1982
wf 8.202M/Win10/IIS/SSA - WrapApp Front End for WF

April 05, 2013, 10:38 AM
kitten
Yes Danny that is what I'd like to see and yes I want to display other fields.


WebFOCUS 7.6.2, MS Windows Server/______, Excel, PDF, HTML
April 05, 2013, 12:18 PM
Francis Mariani
Try my suggestion.


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
April 05, 2013, 01:01 PM
kitten
Thanks Francis, I haven't started yet, but I'll let you know how it goes.


WebFOCUS 7.6.2, MS Windows Server/______, Excel, PDF, HTML
April 06, 2013, 11:22 AM
George Patton
Francis, as always, is dead on.

OCCURS is the way to go.


WebFOCUS 7.7.05 Windows, Linux, DB2, IBM Lotus Notes, Firebird, Lotus Symphony/OpenOffice. Outputs PDF, Excel 2007 (for OpenOffice integration), WP