Focal Point Banner
Community Center Education Summit Technical Support User Groups
Let's Get Social!

Facebook Twitter LinkedIn YouTube
Focal Point    Focal Point Forums  Hop To Forum Categories  WebFOCUS/FOCUS Forum on Focal Point     Dividing one input-field into several lines of output according to a given separator
Go
New
Search
Notify
Tools
Reply
  
Dividing one input-field into several lines of output according to a given separator
 Login/Join
 
<Stahl>
posted
Hi,

I have a input-field like this :

CC:5675634349,Z. Zidane,5000,00&CC:4757676439,DAVID BECKHAM,10000,00&EC:4545,FIGO&

The &-sign is to be interpreted as a separator.

Now I want to produce a output like this (3 lines for this example):

CC: 5675634349,Z. Zidane,5000,00
CC:4757676439,DAVID BECKHAM,10000,00
EC:4545,FIGO

Does anybody know how to solve this problem?
Thanks for any advice!
Stahl
 
Reply With QuoteReport This Post
<ineuxf>
posted
Here you will find my solution using CTRAN and GETTOK:

-SET &ECHO=ALL;
-RUN

-* create a file with your test conditions: Ampersand as a delimiter
DEFINE FILE CAR
INFIELD/A80 WITH COUNTRY=
'CC: 567,Z. Zidane,5000,00&|CC: 39,DAVID BECKHAM,100,00&|EC:4545,FIGO&|';
END
TABLE FILE CAR
PRINT
COUNTRY
INFIELD
IF RECORDLIMIT IS 1
ON TABLE HOLD AS HOLDCAR
END

-* Solution with CTRAN and GETTOK
SET STYLEMODE = FIXED
SET PANEL = 145
DEFINE FILE HOLDCAR
-* Ampersand is a reserved sign for Focus Dialog Manager variables.
-* Therefore change Ampersand & to # with the CTRAN function
CHGFIELD/A80 = CTRAN (80,INFIELD,38,35,'A80');
-* pick up the string up to the next # as a new field.
FLD1/A80 = GETTOK(CHGFIELD,80,1,'#',80,'A80');
FLD2/A80 = GETTOK(CHGFIELD,80,2,'#',80,'A80');
FLD3/A80 = GETTOK(CHGFIELD,80,3,'#',80,'A80');
END
TABLE FILE HOLDCAR
"view from HOLDCAR"
PRINT
INFIELD OVER
CHGFIELD OVER
FLD1 OVER
FLD2 OVER
FLD3
BY COUNTRY NOPRINT
END
-EXIT

Result:

PAGE 1

view from HOLDCAR
INFIELD CC: 567,Z. Zidane,5000,00&CC: 39,DAVID BECKHAM,100,00&EC:4545,FIGO&
CHGFIELD CC: 567,Z. Zidane,5000,00#CC: 39,DAVID BECKHAM,100,00#EC:4545,FIGO#
FLD1 CC: 567,Z. Zidane,5000,00
FLD2 CC: 39,DAVID BECKHAM,100,00
FLD3 EC:4545,FIGO


Best regards

Udo from Germany
 
Reply With QuoteReport This Post
<Stahl>
posted
Thanks a lot, Udo. This works fine!
Best regards
Sonja from Germany
 
Reply With QuoteReport This Post
<WFUser>
posted
A much cleaner and easier solution would be to create master file using SUFFIX=DFIX as follows:

FILE=AMPTEST,SUFFIX=DFIX,$
SEGNAME=AMPTEST,$
FIELDNAME=DELIMITER, ALIAS=&, USAGE=A1, ACTUAL=A1 ,$
FIELDNAME= FIELD1 ,,A50 ,A50 ,$
FIELDNAME= FIELD2 ,,A50 ,A50 ,$
FIELDNAME= FIELD3 ,,A50 ,A50 ,$

Then just FILEDEF the text file and PRINT the fields using OVER AS '' if you wan them under each other.
 
Reply With QuoteReport This Post
  Powered by Social Strata  
 

Focal Point    Focal Point Forums  Hop To Forum Categories  WebFOCUS/FOCUS Forum on Focal Point     Dividing one input-field into several lines of output according to a given separator

Copyright © 1996-2018 Information Builders, leaders in enterprise business intelligence.