Focal Point
Parsing a string in WebFocus...

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

May 28, 2007, 07:45 AM
focuzsambit
Parsing a string in WebFocus...
Is there any way in WebFocus, where we can parse the below string taking ~ as the separator.
Note : The number of ~ is fixed.

To Be passed String:
************************************************
IBIC_user=camwbf~FRAMES=|200704*~SPC=~_VVPC=~BAREA_CD_C2=|EUR*~VVPC=~VVPC_DDN=~_AREA=EUR~VVPCFRAME_CHANGED=~SERVICE=~DIR_CD_C2=~IBIF_ex=ccam_allocmangmnt_new~_SERVICE=~AREA=
************************************************

Format In Which I need to convert it in webfcos:
************************************************
IBIC_user=camwbf
FRAMES=|200704*
SPC=
_VVPC=
BAREA_CD_C2=|EUR*
VVPC=
VVPC_DDN=
_AREA=EUR
VVPCFRAME_CHANGED=
SERVICE=
DIR_CD_C2=
IBIF_ex=ccam_allocmangmnt_new
_SERVICE=
AREA=
************************************************


WF Server: 7.1.4 on Z/OS and Linux, ReportCaster
Data: DB2, DB2/UDB, Adabas, SQL Server, Oracle Output: HTML,PDF,Excel2K
WF Client: Servlet, CGI
May 28, 2007, 08:40 AM
lakshmi
Check if this works for you
******************************************


-SET &STR='IBIC_user=camwbf~FRAMES=|200704*~SPC=~_VVPC=~BAREA_CD_C2=|EUR*~VVPC=~VVPC_DDN=~_AREA=EUR~VVPCFRAME_CHANGED=~SERVICE=~DIR_CD_C2=~IBIF_ex=ccam_allocmangmnt_new~_SERVICE=~AREA= ';

-SET &F1 = GETTOK(&STR,&STR.LENGTH,1,'~',20,'A20');
-SET &F2 = GETTOK(&STR,&STR.LENGTH,2,'~',20,'A20');
-SET &F3 = GETTOK(&STR,&STR.LENGTH,3,'~',20,'A20');
-SET &F4 = GETTOK(&STR,&STR.LENGTH,4,'~',20,'A20');
-SET &F5 = GETTOK(&STR,&STR.LENGTH,5,'~',20,'A20');

-SET &F6 = GETTOK(&STR,&STR.LENGTH,6,'~',20,'A20');
-SET &F7 = GETTOK(&STR,&STR.LENGTH,7,'~',20,'A20');
-SET &F8 = GETTOK(&STR,&STR.LENGTH,8,'~',20,'A20');
-SET &F9 = GETTOK(&STR,&STR.LENGTH,9,'~',20,'A20');
-SET &F10 = GETTOK(&STR,&STR.LENGTH,10,'~',20,'A20');
-SET &F11 = GETTOK(&STR,&STR.LENGTH,11,'~',20,'A20');
-SET &F12 = GETTOK(&STR,&STR.LENGTH,12,'~',40,'A40');
-SET &F13 = GETTOK(&STR,&STR.LENGTH,13,'~',20,'A20');
-SET &F14 = GETTOK(&STR,&STR.LENGTH,14,'~',20,'A20');


-TYPE F1: &F1
-TYPE F2: &F2
-TYPE F3: &F3
-TYPE F4: &F4
-TYPE F5: &F5
-TYPE F6: &F6
-TYPE F7: &F7
-TYPE F8: &F8
-TYPE F9: &F9
-TYPE F10: &F10
-TYPE F11: &F11
-TYPE F12: &F12
-TYPE F13: &F13
-TYPE F14: &F14


*********************************
GETTOK is used for Extracting a Substring (Token)

Syntax of GETTOK is

GETTOK(infield, inlen, token_number, 'delim', outlen, outfield)


Thanks

Lakshmi


Lakshmi
WF 713 WinXP/IIS/Apache Self Service
May 28, 2007, 09:07 AM
Alan B
You don't say if you want the output as seperate &vars or not.

If so then Lakshmi's approach, maybe in a loop, would be correct. If you just want to display it in that format somewhere (!), then you could use:
-SET &STRING='IBIC_user=camwbf~FRAMES=|200704*~SPC=~_VVPC=~BAREA_CD_C2=|EUR*~VVPC=~VVPC_DDN=~_AREA=EUR~VVPCFRAME_CHANGED=~SERVICE=~DIR_CD_C2=~IBIF_ex=ccam_allocmangmnt_new~_SERVICE=~AREA=';
-SET &NEWSTRING=STRREP (&STRING.LENGTH,&STRING,1,'~',1,HEXBYT(13,'A1'),&STRING.LENGTH,'A&STRING.LENGTH');
-TYPE &NEWSTRING



Alan.
WF 7.705/8.007
May 29, 2007, 11:09 AM
TexasStingray
focuzsambit,

I created a user written subroutine that would take a string separated by an '&' with the name=value pairs (much like a URL query string) and would return the value for the requested name. It is a dll so it would only work in windows. I would imagine that you could do the same with the '~' if you wanted to extend WebFOCUS. Just an Idea.




Scott

I would recommend using a combination of POSIT and SUBSTR functions (see the USING FUNCTIONS manual), especially since there are a fixed number of ~ characters. say that fixed number is 10.
Then you'll be creating 11 resultant &VARS,
and can -WRITE them each out to a file in the format you want.

If the inbound character string is in a file, then you could write a new MFD for that file using FORMAT DFIX and DELIMITER='~'
and read the 11 variables you define in that MFD and print them out using the OVER command, PRINT var1 OVER var2..etc... if all you want is a report, not an actual output file.

If you need help with the POSIT/SUBSTR, post back and we'll help you. Focus text editing capabilities are sine qua non!
-S




In Focus since 1979///7706m/5 ;wintel 2008/64;OAM security; Oracle db, ///MRE/BID
focuzsambit,

If you are running on windows I would be glad to send you my C Source Code and the DLL I created along with a sample focexec on how to call it. I did not make any changes to it to work with the ~ I just used CTRAN to convert the ~ to an & and then called to user written subroutine. Works great and can be called from dialog manager to create seperate & variables or from a DEFINE or COMPUTE. Below is the output from the sample focexec
 -SET &MYSTRING = 'camwbf~FRAMES=|200704*~SPC=~_VVPC=~BAREA_CD_C2=|EUR*~VVPC=~VVPC_DDN=~_AREA=EUR~VVPCFRAME_CHANGED=~SERVICE=~DIR_CD_C2=~IBIF_ex=ccam_allocmangmnt_new~_SERVICE=~AREA=';
 -SET &MYSTRING = CTRAN(&MYSTRING.LENGTH, &MYSTRING, 126, 38, 'A163');
 -SET &BAREA_CD_C2 = PARMVAL(&MYSTRING.LENGTH, &MYSTRING, 11, 'BAREA_CD_C2', 'A80');
 -SET &_AREA = PARMVAL(&MYSTRING.LENGTH, &MYSTRING, 5, '_AREA', 'A80');
 -SET &IBIF_ex = PARMVAL(&MYSTRING.LENGTH, &MYSTRING, 7, 'IBIF_ex', 'A80');
 -SET &FRAMES = PARMVAL(&MYSTRING.LENGTH, &MYSTRING, 6, 'FRAMES', 'A80');
 -TYPE FRAMES = &FRAMES
 FRAMES = |200704*
 -TYPE BAREA_CD_C2 = &BAREA_CD_C2
 BAREA_CD_C2 = |EUR*
 -TYPE _AREA = &_AREA
 _AREA = EUR
 -TYPE IBIF_ex = &IBIF_ex
 IBIF_ex = ccam_allocmangmnt_new


Just send me a private message if you what it.

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




Scott