Net.Data Call Block
Net.Data CGI script provides a function to call application programs.
Net.Data is a server-side scripting language that provides web servers the ability to dynamically generate web pages using data from multiple data sources. The data sources can include relational database management systems such as DB2, and native applications written in programming languages such as RPG and others. The example below is code that uses the DTW_DIRECTCALL function to access an RPG program. The INOUT sepecifies the argument list for I/O variables. OUT denotes the variable ERROUT as output from the program--used to signal to the CGI script an error occurred in processing the data request.
%{ *************** Function Definition block ******************%} %FUNCTION(DTW_DIRECTCALL) ShipOrder( INOUT DEC(7,0) PO_Nbr, DEC(5,0) Seq_Nbr, DEC( 6,0 ) Shp_Dte, CHAR( 20 ) Trk_Nbr, CHAR(1) Shp_Mtd, OUT CHAR(7) ErrOut ) { %exec { /qsys.lib/cgipx010.lib/DRS200RP.PGM %} %}
Calling an RPG program
The program example below is a Net.Data script that gnerates an HTML table using the DTW_SQL function of the script language. The table output in the SQL block will be referenced in the DTW_DIRECTCALL function (highlighted in red). The table will be used as an I/O variable in the argument used for the RPG application program.
%{******** Define Section ********* %} %DEFINE { DTW_HTML_TABLE = "YES" table1 = %TABLE table2 = %TABLE counter = "1" newrow = "0" tablerow = "0" DTW_SET_TOTAL_ROWS="YES" %} %{******** Function Section ********* %} %FUNCTION(DTW_DIRECTCALL) CallRPG( IN DECIMAL( 7,0 ) Vnd_Nbr, CHAR( 12 ) Inv_Nbr, INOUT DTWTABLE tbl ) { %exec { /qsys.lib/cgipx010.lib/VND065RP.PGM %} %} %FUNCTION(DTW_SQL) SHOWPOS (OUT t1) { SELECT WCVEND, WCINVC, WCARTN, WCTRAK FROM VNDWCHPF WHERE WCVEND=$(VND) AND WCINVC='$(INV)' ORDER BY WCVEND, WCINVC, WCARTN %REPORT{ <H2 align="center">Carton Detail for Invoice $( INV ) </H2> <center> <TABLE bgcolor="#191970" border="0" cellspacing="2" cellpadding="2"> <tr> <td>><font color="#ffffff">Vendor Number</font></td> <td><font color="#ffffff">Invoice Number</font><CartonTracking number</font></td> %ROW {<TD bgcolor="#C7C7E0" >$( V1 )</TD> <TD bgcolor="#C7C7E0" >$(V2)</TD> <TD bgcolor="#C7C7E0" >$(V3)</TD> <TD bgcolor="#C7C7E0" ><INPUT TYPE="text" name=trk$(ROW_NUM) size=20 value="$(V4)"</TD> <TD bgcolor="#C7C7E0" ><INPUT TYPE="hidden" NAME=crt$(ROW_NUM) VALUE="$( V3 )"></TD> %} <INPUT TYPE="hidden" NAME=rowtotal VALUE="$(NUM_ROWS)"> <INPUT TYPE="hidden" NAME=Vnd_Nbr VALUE="$( VND )"> <INPUT TYPE="hidden" NAME=Inv_Nbr VALUE="$( INV )"> %} %} %{ ***** Define update table ****** %} %MACRO_FUNCTION getTable() { @DTW_TB_SETCOLS(table2, "4") @DTW_TB_SETN(table2, "Vendor", "1") @DTW_TB_SETN(table2, "Invoice", "2") @DTW_TB_SETN(table2, "Carton", "3") @DTW_TB_SETN(table2, "Tracking Number", "4") %WHILE (counter <= rowtotal) { @DTW_ADD(tablerow , "1", tablerow) @DTW_TB_APPENDROW(table2, "1") @DTW_TB_SETV(table2, Vnd_Nbr , "$(tablerow)", "1") @DTW_TB_SETV(table2, Inv_Nbr , "$(tablerow)", "2") @DTW_TB_SETV(table2, "$(crt$(counter))" , "$(tablerow)", "3") @DTW_TB_SETV(table2, "$(trk$(counter))" , "$(tablerow)", "4") @DTW_ADD(counter, "1", counter) %} %} %{******** HTML Input Section ********* %} %HTML(INPUT) { <script language="JavaScript"> <!-- var new_Win; function carton_dtl() { location.href="PONbr.htm"; } function end_page() { location.href="Finish.htm"; } function new_page() { location.href="PONbr.htm"; } /* Define image objects */ var endOff = new Image( 77, 27 ); endOff.src = "/images/btn_nxt.jpg"; var endOn = new Image( 77, 27); endOn.src = "/images/btn_nxt_on.jpg"; var backOff = new Image( 77, 27 ); backOff.src = "/images/btn_bck.jpg"; var backOn = new Image( 77, 27); backOn.src = "/images/btn_bck_on.jpg"; var enterOff = new Image( 77, 27 ); enterOff.src = "btn_ent.jpg"; var enterOn = new Image( 77, 27); enterOn.src = "btn_ent_on.jpg"; /* Changes image being displayed. */ function highlightButton(placeholder, imageObject) { document.images[placeholder].src = eval( imageObject + ".src") } //-->The end of the section to be hidden </script> </head> <FORM METHOD="POST" ACTION="UPDATE"> @SHOWPOS(table1) <br> <CENTER><INPUT TYPE=submit NAME="submit" VALUE="Update"></CENTER> </FORM> <br> <p align="center"><[<a href="JavaScript:history.go(-2)">Back</a>|<a href="JavaScript:history.go(0)">Reset</a>]</p> %} %{******** HTML Output Section ********* %} %HTML(UPDATE) { <head> <script language="JavaScript"> <!-- var new_Win; function carton_dtl() { location.href="PONbr.htm"; } function end_page() { location.href="Finish.htm"; } function new_page() { location.href="PONbr.htm"; } /* Define image objects */ var endOff = new Image( 77, 27 ); endOff.src = "/images/btn_nxt.jpg"; var endOn = new Image( 77, 27); endOn.src = "/images/btn_nxt_on.jpg"; var backOff = new Image( 77, 27 ); backOff.src = "/images/btn_bck.jpg"; var backOn = new Image( 77, 27); backOn.src = "/images/btn_bck_on.jpg"; var enterOff = new Image( 77, 27 ); enterOff.src = "btn_ent.jpg"; var enterOn = new Image( 77, 27); enterOn.src = "btn_ent_on.jpg"; /* Changes image being displayed. */ function highlightButton(placeholder, imageObject) { document.images[placeholder].src = eval( imageObject + ".src") } //-->The end of the section to be hidden </script> </head> <body TEXT="#000000" LINK="#ffcc00" VLINK="#ff5a00" ALINK="#ff0000" BGCOLOR="#ffffff"> <H2 align="center">Tracking Numbers have been updated for invoice $( Inv_Nbr )</H2> <table align="center" border="0" width="750"> <tr> <td valign="top" width="220"><font face="Verdana,Arial,Helvetica" size="1">Verify the tracking number of each carton labeled for this invoice number.</font><p><font face="Verdana,Arial,Helvetica" size="1">Click on the <strong>BACK</strong> button to return to the previous page, or the <strong>Next</strong> button to proceed.</font> </p> <p> </p> <table border="0" width="100%"> <tr> <td width="50%"><p align="center"><a href="javascript:history.back()" onMouseOver="highlightButton( 'Back', 'backOn' );window.status='Return to previous page';return true;" onMouseOut="highlightButton( 'Back', 'backOff' );window.status=' ';return true;"><img src="/images/btn_bck.jpg" alt="Previous page" width="77" height="27" border="0" name="Back"></a></td> <td width="50%"><p align="center"><a href="javascript:end_page()" onMouseOver="highlightButton( 'Next', 'endOn' );window.status='Finish invoice';return true;" onMouseOut="highlightButton( 'Next', 'endOff' );window.status=' ';return true;"><img src="/images/btn_nxt.jpg" alt="Proceed to next page" width="77" height="27" border="0" name="Next>></a></td> </tr> </table> </td> <td valign="top" width="10"><img src="/images/blu_vert.jpg" width="5" height="250"></td> <td bgcolor="#C7C7E0" valign="center" width="500"><div align="center"> @getTable() @CallRPG(Vnd_Nbr,Inv_Nbr,table2) </center></div></td> </tr> </table> </body> </html> %} %{******** End of Macro ********* %}
The HTML INPUT block of the script will display the table generated by the DTW_SQL block( the function call is @SHOWPOS). The HTML block named UPDATE will get the table, then call the RPG program passing the variables identifying the key fields VND_NBR, INV_NBR, as input prarameters and the table as an I/O parameter.