Focal Point
[solved] REPEAT in MODIFY

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

May 07, 2015, 04:11 PM
Enigma006
[solved] REPEAT in MODIFY
Hello

Below sample code I have works successfully as needed to insert 3 records to database.
Can anyone help in simplifying the code to use only 1 MODIFY statement instead of 3 using REPEAT LOOP?

-:REC1
-SET &FLD1 = 'VAL1';
-SET &FLD2 = 'VAL2';
-SET &FLD3 = 'VAL3';
-GOTO :MODIFY1;
 
-:REC2
-SET &FLD1 = 'VAL1';
-SET &FLD2 = 'VAL4';
-SET &FLD3 = 'VAL5';
-GOTO :MODIFY2;
 
-:REC3
-SET &FLD1 = 'VAL1';
-SET &FLD2 = 'VAL6';
-SET &FLD3 = 'VAL7;
-GOTO :MODIFY3;
 
 
-:MODIFY1
MODIFY FILE TABLE_NAME
FREEFORM FLD1 FLD2 FLD3
MATCH FLD1
	ON MATCH   INCLUDE FLD2 FLD3
	ON NOMATCH INCLUDE FLD2 FLD3
DATA
FLD1='&FLD1', FLD2='&FLD2', FLD3='&FLD3', $
END
-RUN
-GOTO :REC2;
 
 
 
-:MODIFY2
MODIFY FILE TABLE_NAME
FREEFORM FLD1 FLD2 FLD3
MATCH FLD1
	ON MATCH   INCLUDE FLD2 FLD3
	ON NOMATCH INCLUDE FLD2 FLD3
DATA
FLD1='&FLD1', FLD2='&FLD2', FLD3='&FLD3', $
END
-RUN
-GOTO :REC3;
 
 
 
 
-:MODIFY3
MODIFY FILE TABLE_NAME
FREEFORM FLD1 FLD2 FLD3
MATCH FLD1
	ON MATCH   INCLUDE FLD2 FLD3
	ON NOMATCH INCLUDE FLD2 FLD3
DATA
FLD1='&FLD1', FLD2='&FLD2', FLD3='&FLD3', $
END
-RUN
-GOTO :END1;
-:END1  



Please suggest.

Thanks.

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


8.1.05
HTML,PDF,EXL2K, Active, All
May 07, 2015, 06:46 PM
Waz
You should be able to have all three records in the data area.
MODIFY FILE TABLE_NAME
FREEFORM FLD1 FLD2 FLD3
MATCH FLD1
	ON MATCH   INCLUDE FLD2 FLD3
	ON NOMATCH INCLUDE FLD2 FLD3
DATA
FLD1='&FLD1a', FLD2='&FLD2a', FLD3='&FLD3a', $
FLD1='&FLD1b', FLD2='&FLD2b', FLD3='&FLD3b', $
FLD1='&FLD1c', FLD2='&FLD2c', FLD3='&FLD3c', $
END



Waz...

Prod:WebFOCUS 7.6.10/8.1.04Upgrade:WebFOCUS 8.2.07OS:LinuxOutputs:HTML, PDF, Excel, PPT
In Focus since 1984
Pity the lost knowledge of an old programmer!

May 08, 2015, 09:29 AM
Enigma006
quote:
Originally posted by Waz:
You should be able to have all three records in the data area.
MODIFY FILE TABLE_NAME
FREEFORM FLD1 FLD2 FLD3
MATCH FLD1
	ON MATCH   INCLUDE FLD2 FLD3
	ON NOMATCH INCLUDE FLD2 FLD3
DATA
FLD1='&FLD1a', FLD2='&FLD2a', FLD3='&FLD3a', $
FLD1='&FLD1b', FLD2='&FLD2b', FLD3='&FLD3b', $
FLD1='&FLD1c', FLD2='&FLD2c', FLD3='&FLD3c', $
END


hello waz, how would I direct the control to MODIFY? Each set of SET statement values will be replaced by next set if I give them continuously. please provide full code.


8.1.05
HTML,PDF,EXL2K, Active, All
May 08, 2015, 09:58 AM
j.gross
quote:
MODIFY FILE TABLE_NAME
FREEFORM FLD1 FLD2 FLD3
MATCH FLD1
ON MATCH INCLUDE FLD2 FLD3
ON NOMATCH INCLUDE FLD2 FLD3
DATA
FLD1='&FLD1', FLD2='&FLD2', FLD3='&FLD3', $
END


Go review the syntax; INCLUDE (as opposed to UPDATE) operates on entire segments, and does not take a list of fields.
Also, ON MATCH INCLUDE is valid syntax, but rarely appropriate.

If FLD1 is the sole key, you probably need

ON MATCH REJECT
ON NOMATCH INCLUDE 


or maybe

ON MATCH UPDATE FLD2 FLD3
ON NOMATCH INCLUDE  



- Jack Gross
WF through 8.1.05
May 08, 2015, 10:34 AM
Enigma006
quote:
Originally posted by j.gross:
quote:
MODIFY FILE TABLE_NAME
FREEFORM FLD1 FLD2 FLD3
MATCH FLD1
ON MATCH INCLUDE FLD2 FLD3
ON NOMATCH INCLUDE FLD2 FLD3
DATA
FLD1='&FLD1', FLD2='&FLD2', FLD3='&FLD3', $
END


Go review the syntax; INCLUDE (as opposed to UPDATE) operates on entire segments, and does not take a list of fields.
Also, ON MATCH INCLUDE is valid syntax, but rarely appropriate.

If FLD1 is the sole key, you probably need

ON MATCH REJECT
ON NOMATCH INCLUDE 


or maybe

ON MATCH UPDATE FLD2 FLD3
ON NOMATCH INCLUDE  


This is sample code and my main issue is looping the code and not REJECT or UPDATE records.


8.1.05
HTML,PDF,EXL2K, Active, All
May 08, 2015, 11:25 AM
Enigma006
quote:
Originally posted by Waz:
You should be able to have all three records in the data area.
MODIFY FILE TABLE_NAME
FREEFORM FLD1 FLD2 FLD3
MATCH FLD1
	ON MATCH   INCLUDE FLD2 FLD3
	ON NOMATCH INCLUDE FLD2 FLD3
DATA
FLD1='&FLD1a', FLD2='&FLD2a', FLD3='&FLD3a', $
FLD1='&FLD1b', FLD2='&FLD2b', FLD3='&FLD3b', $
FLD1='&FLD1c', FLD2='&FLD2c', FLD3='&FLD3c', $
END


waz, I got it to work. thank you..


8.1.05
HTML,PDF,EXL2K, Active, All
May 08, 2015, 11:26 AM
j.gross
quote:
This is sample code and my main issue is looping the code and not REJECT or UPDATE records.


Then either stack the transactions under DATA, as WAZ indicated,

or you can house the MODIFY in a separate fex (with parameters &FLD1, &FLD2, &FLD3) and EX that once per set of values:

EX my_modify_fex FLD1=aaa,FLD2=bbb,FLD3=ccc
EX my_modify_fex FLD1=ddd,FLD2=eee,FLD3=fff
EX my_modify_fex FLD1=ggg,FLD2=hhh,FLD3=iii

Depends on how you are coming by the transaction sets.


- Jack Gross
WF through 8.1.05
May 09, 2015, 09:41 AM
George Patton
Enigma - You've marked it Solved, so this is just a comment.

When you put the incoming data after the DATA command at the bottom of a simple MODIFY the "looping" you refer to is implied and doesn't need to be explicitly coded. Control branches from before the END statement back up to the first line after the MODIFY FILE command. When the last data line is processed the END statement is invoked and control passes out of the MODIFY.

As Jack says, when the data is outside the MODIFY there are number of approaches - and the one he suggests here (with parameters after the FEX name) is news to me, even though I've been writing MODIFYs for 30 years ...


WebFOCUS 7.7.05 Windows, Linux, DB2, IBM Lotus Notes, Firebird, Lotus Symphony/OpenOffice. Outputs PDF, Excel 2007 (for OpenOffice integration), WP
May 11, 2015, 09:27 AM
j.gross
To spell it out:
-* first.fex
EX SECOND 'aaa','bbb','ccc'
EX SECOND 'ddd','eee','fff'
EX SECOND 'ggg','hhh','iii'

-* second.fex
MODIFY FILE TABLE_NAME
FREEFORM FLD1 FLD2 FLD3
MATCH FLD1
	ON MATCH REJECT 
	ON NOMATCH INCLUDE 
DATA
FLD1='&1', FLD2='&2', FLD3='&3', $
END 


Not that I recommend it -- why force parsing of the MODIFY three times? -- but it answers the original question: How to avoid coding three identical MODIFY procedures.


- Jack Gross
WF through 8.1.05