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] Loop In File

Read-Only Read-Only Topic
Go
Search
Notify
Tools
[SOLVED] Loop In File
 Login/Join
 
Gold member
posted
Hello All,

I have a list of purchase orders on System A (> SQL Where Limit), I want to pull from System B where that PO exists. The file on System B is VERY large, so joining these two together is not an option. We are trying to batch the PO#'s in the where statement with about 500 at a time. Here is as far as we have gotten.

I apologize, but this is our first time trying some looping and reading logic this way:

** This example will send one PO at a time, how would we send say 500 or 1000 at a time in the SQL WHERE statement?

  

-* File 14_build_Invoice.fex

APP PREPENDPATH innermargin
APP HOLD innermargin

TABLE FILE PO_DEAL_COMPLETE
SUM
COMPUTE RANK1/I9 = IF (PONUMB EQ LAST PONUMB) THEN 1 ELSE RANK1 + 1;
BY  LOWEST PO_DEAL_COMPLETE.SEG01.PONUMB
WHERE READLIMIT EQ 100
ON TABLE SET PAGE-NUM NOLEAD
ON TABLE NOTOTAL
ON TABLE HOLD AS HOLD1 FORMAT ALPHA
END


-SET &LIMIT=&LINES;


FILEDEF RESULTS DISK results.ftm (APPEND

-RUN


-REPEAT :ENDLOOP &LIMIT TIMES
-READFILE HOLD1

TABLE FILE INVOICEDET
BY  LOWEST INVOICEDET.INVOICEDET.DDPON
WHERE INVOICEDET.INVOICEDET.DDPON EQ '&PONUMB';
ON TABLE SET PAGE-NUM NOLEAD
ON TABLE NOTOTAL
ON TABLE HOLD AS RESULTS FORMAT ALPHA
END
-RUN
-:ENDLOOP

TABLE FILE RESULTS
PRINT *
END



There was a topic like this back in 2008 that helped us get this far:

LOOP IN FILE

This message has been edited. Last edited by: John C.,


WF 7703 Outputs all
Windows 7 32
DB2 CLI
 
Posts: 59 | Registered: August 09, 2012Report This Post
Virtuoso
posted Hide Post
You can use
WHERE INVOICEDET.INVOICEDET.DDPON IN FILE HOLD1;


I'm not sure how that performs with the entire file's worth of identifiers (probably badly or not at all).

If you create that file in batches of 500 + remainder, that should remedy that part of the issue.

For example, you could write the entire file of ID's to a hold file that includes a record number (1, 2, 3, ..., 1238120398) and copy that file in 500-line batches to an alpha file that you then use for the WHERE IN FILE clause.


WebFOCUS 8.1.03, Windows 7-64/2008-64, IBM DB2/400, Oracle 11g & RDB, MS SQL-Server 2005, SAP, PostgreSQL 11, Output: HTML, PDF, Excel 2010
: Member of User Group Benelux :
 
Posts: 1669 | Location: Enschede, Netherlands | Registered: August 12, 2010Report This Post
Gold member
posted Hide Post
quote:
Originally posted by Wep5622:
You can use
WHERE INVOICEDET.INVOICEDET.DDPON IN FILE HOLD1;


I'm not sure how that performs with the entire file's worth of identifiers (probably badly or not at all).

If you create that file in batches of 500 + remainder, that should remedy that part of the issue.

For example, you could write the entire file of ID's to a hold file that includes a record number (1, 2, 3, ..., 1238120398) and copy that file in 500-line batches to an alpha file that you then use for the WHERE IN FILE clause.


Yeah the way we have it now it works, but not well. We are looking to make the hold files in batches of 500 or 1000 in the IN FILE. We just can't figure out how to systematically do this based on the number of records in the file.

In the futrue we are going to have to use this method a lot, so we need to try and get a working example. Smiler

Thank you!

JC


WF 7703 Outputs all
Windows 7 32
DB2 CLI
 
Posts: 59 | Registered: August 09, 2012Report This Post
Virtuoso
posted Hide Post
Something like this should do it:
-* 1. hold all keys
TABLE FILE PO_DEAL_COMPLETE
  SUM COMPUTE SEQ/I9=SEQ+1;
  BY  LOWEST PO_DEAL_COMPLETE.SEG01.PONUMB
  ON TABLE HOLD AS HOLD0
END
-RUN
-SET &X_LINES=0+&LINES;

-* 2. break into a series of hold files, (&X_SIZE) keys each
-SET &X_SIZE=500;
-SET &X_ITERS = INT ( (&X_LINES + &X_SIZE - 1 ) / &X_SIZE );

-REPEAT LOOP1 FOR &X FROM 1 TO &X_ITERS ;  
-SET &X_HI = &X_SIZE * &X ;
-SET &X_LO = &X_HI + 1 - &X_SIZE ;
TABLEF FILE HOLD0
  PRINT PONUMB
  WHERE ( SEQ GE &X_LO ) AND ( SEQ LE &X_HI );
  ON TABLE HOLD AS &HOLD&X FORMAT ALPHA
END
-LOOP1

-* 3. pull results, combining extracts for each of the respective hold files

TABLE FILE INVOICEDET
  PRINT items_of_interest
  BY  LOWEST INVOICEDET.INVOICEDET.DDPON
  WHERE INVOICEDET.INVOICEDET.DDPON IN FILE 'HOLD1' ;
  ON TABLE HOLD AS RESULTS

-REPEAT LOOP2 FOR &X FROM 2 TO &X_ITERS ;
MORE
FILE INVOICEDET
  WHERE INVOICEDET.INVOICEDET.DDPON IN FILE 'HOLD&X' ;
-LOOP2

END
-RUN

TABLE FILE RESULTS
PRINT *
END

[edited: -REPEAT &LOOP1]

This message has been edited. Last edited by: j.gross,


- Jack Gross
WF through 8.1.05
 
Posts: 1925 | Location: NYC | In FOCUS since 1983 | Registered: January 11, 2005Report This Post
Gold member
posted Hide Post
Jack,

Thank you for the reply! We put your code into the fex and got the following error in the hold file loop logic:

  
 0 NUMBER OF RECORDS IN TABLE=     5076  LINES=   5076
 0 ERROR AT OR NEAR LINE     19  IN PROCEDURE 14_build_invoice.f
 (FOC295) A VALUE IS MISSING FOR: &LOOP1






WF 7703 Outputs all
Windows 7 32
DB2 CLI
 
Posts: 59 | Registered: August 09, 2012Report This Post
Gold member
posted Hide Post
This looked like it worked perfectly. Jack we owe you sir.

  

-* 1. hold all keys
TABLE FILE PO_DEAL_COMPLETE
  SUM COMPUTE SEQ/I9=SEQ+1;
  BY  LOWEST PO_DEAL_COMPLETE.SEG01.PONUMB
  ON TABLE HOLD AS HOLD0
END
-RUN
-SET &X_LINES=0+&LINES;

-* 2. break into a series of hold files, (&X_SIZE) keys each
-SET &X_SIZE=500;
-SET &X_ITERS = INT ( (&X_LINES + &X_SIZE - 1 ) / &X_SIZE );

-REPEAT LOOP1 FOR &X FROM 1 TO &X_ITERS ;
-SET &X_HI = &X_SIZE * &X ;
-SET &X_LO = &X_HI + 1 - &X_SIZE ;
TABLEF FILE HOLD0
  PRINT PONUMB
  WHERE ( SEQ GE &X_LO ) AND ( SEQ LE &X_HI );
  ON TABLE HOLD AS HOLD&X FORMAT ALPHA
END

-LOOP1

-* 3. pull results, combining extracts for each of the respective hold files

TABLE FILE INVOICEDET
  SUM DDPON
  BY  LOWEST INVOICEDET.INVOICEDET.DDPON
  WHERE INVOICEDET.INVOICEDET.DDPON IN FILE 'HOLD1' ;
  ON TABLE HOLD AS RESULTS

-REPEAT LOOP2 FOR &X FROM 2 TO &X_ITERS ;
MORE
FILE INVOICEDET
  WHERE INVOICEDET.INVOICEDET.DDPON IN FILE 'HOLD&X' ;
-LOOP2

END
-RUN

TABLE FILE RESULTS
PRINT *
END


WF 7703 Outputs all
Windows 7 32
DB2 CLI
 
Posts: 59 | Registered: August 09, 2012Report This Post
Virtuoso
posted Hide Post
Your welcome.

I suggest you add
STEP 1
to the second -REPEAT, to ensure that the loop will be skipped if &X_ITERS is 1 (only one "batch" worth of keys).
 
Posts: 1925 | Location: NYC | In FOCUS since 1983 | Registered: January 11, 2005Report This Post
Gold member
posted Hide Post
quote:
Originally posted by j.gross:
Your welcome.

I suggest you add
STEP 1
to the second -REPEAT, to ensure that the loop will be skipped if &X_ITERS is 1 (only one "batch" worth of keys).


Noted, thank you again. Hope you had a great weekend. Going to mark this solved.


WF 7703 Outputs all
Windows 7 32
DB2 CLI
 
Posts: 59 | Registered: August 09, 2012Report 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] Loop In File

Copyright © 1996-2020 Information Builders