Tutorial Chapter 7: Array Display |
Since this is a function that could be used by other programs that reference the customer table, the function will be compiled into a library. The library can then be linked into any program, and the function called.
The function will always return store_num and store_name. If the FOREACH fails, or returns no rows, the calling program will have a store_num of zero and a NULL store_name returned.
fgl2p -o cust_lib.42x cust_lib.4gl
Since a library has no MAIN function, we will need to create a small stub program if we want to test the library function independently. This program contains the minimal functionality to test the function.
The module cust_stub.4gl calls the library function display_custarr in cust_lib.4gl.
01 SCHEMA custdemo 02 03 MAIN 04 DEFINE store_num LIKE customer.store_num, 05 store_name LIKE customer.store_name 06 07 DEFER INTERRUPT 08 CONNECT TO "custdemo" 09 CLOSE WINDOW SCREEN 10 11 CALL display_custarr() 12 RETURNING store_num, store_name 13 DISPLAY store_num, store_name 14 15 DISCONNECT CURRENT 16 17 END MAIN
Now we can compile the form file and the test program, and link the library, and then test to see if it works properly.
fglform manycust.per fgl2p -o test.42r cust_stub.4gl cust_lib.42x fglrun test.42r