5 How to Create Files
The entry point of the subprogram must be:
SUB REPORT (#1,A$, INTEGER B(*),C)where:
The name of the file where the subprogram is stored is used in the RUN command.
Note:
No command is shown in the following program for selecting the printer to take the output from the report program. It is recommended that you assign the printer using the OUTPUT command.
Example subprogram
! This is a report program to list customer names and addresses ! from the sales analysis data base. Any QUERY THREAD, FIND, or ! SORT (as long as the customer data set is found) may precede ! this program. ! ! variables: ! Buf$ - a buffer for a customer data set record ! Db$ - the data base reference number and name ! i a loop index ! Rptr - an array of record pointers from the workfile ! Sets - an array of sets in the thread used with the FIND ! command that filled the workfile ! Slen - the length of the sets array ! Spos - the position of the customer data set in the thread ! Sts - the status array for the DBGET call ! #l - the file number for the workfile ! SUB Report(#1,Db$,INTEGER Sets(*),Slen) ! INTEGER I,Spos,Sts(1:10) SHORT Rptr(1:10) DIM Buf$[250] ! ! This is the report description section. Rpt1: REPORT HEADER USING Fmt1 Fmt1: IMAGE 27X, "SALES ANALYSIS DATA BASE" PAGE LENGTH 66,2,3 REPORT TRAILER WITH 2 LINES USING Fmt2;"---- TOTAL CUSTOMERS PRINTED",VAL$(WFLEN(1)) Fmt2: IMAGE 10X,K,2X,K PAGE HEADER WITH 5 LINES USING Fmt3 Fmt3: IMAGE 33X, "CUSTOMER LIST", 4/ PAGE TRAILER WITH 2 LINES USING Fmt4;VAL$(NUMPAGE) Fmt4: IMAGE /,70X,"PAGE",K END REPORT DESCRIPTION ! ! If no entries in the workfile, error out. IF WFLEN(1)<1 THEN DISP "--- ERROR... NO ENTRIES HAVE BEEN FOUND" GOTO End END IF ! ! Set the length of the record pointer array to the number ! of sets in the thread (and hence the number of pointers per ! record in the workfile). REDIM Rptr(1:Slen) ! ! Scan the thread for the customer data set (set number 6). ! Spos=0 FOR I=1 TO Slen IF Sets(I)=6 THEN Spos=I NEXT I ! ! If the customer set is not in the thread (and thus not in the ! workfile), error out. IF Spos=0 THEN DISP "--- ERROR... CUSTOMER DATA SET NOT FOUND" GOTO End END IF ! ! Set an exit softkey and output to the printer. ON KEY #8:"EXIT" GOTO End ! ! Rewind the workfile READ #1,1 ! ! ! This is the report execution section BEGIN REPORT Rpt1 ! ! This loop prints customer data for every record in the workfile. FOR I=1 TO WFLEN(L) ! ! Get a record from the workfile and customer set READ #1;Rptr(*) DBGET (Db$,6,4,Sts(*),"@ ",Buf$,Rptr(Spos)) ! ! If a data base error, error out. IF Sts(1) THEN DISP "--- ERROR... DATA BASE ERROR",Sts(1) GOTO End END IF ! ! Print the customer name. DETAIL LINE 1 WITH 6 LINES DETAIL LINE 0 USING "SX,30A";Buf$[11,40] ! ! Print the customer addresses. IF TRIM$(Buf$[41,70])<>"" THEN DETAIL LINE 0 USING "5X,30A";Buf$[41,70] IF TRIM$(Buf$[71,100])<>"" THEN DETAIL LINE 0 USING "5X,3OA";Buf$[71,100] ! ! Print the city, state, and zip. DETAIL LINE 0 USING "5X,33A";TRIM$(Buf$[101,116])&", "&TRIM$(Buf$[117,122])&" "&Buf$[135,142] ! ! Print the customer country and space. DETAIL LINE 0 USING "5X,12A";Buf$[123,134] DETAIL LINE 0 USING "X" NEXT I ! ! End the report END REPORT ! ! Done, stop the report and exit End: STOP REPORT SUBEND