Net.Data Verwaltung und Programmierung für OS/2, Windows NT und UNIX


Anhang D. Net.Data-Beispielmakro

Diese Beispielmakroanwendung zeigt eine Liste von Mitarbeiternamen an, aus der der Anwendungsbenutzer zusätzliche Informationen zu einem bestimmten Mitarbeiter abrufen kann, indem er den Namen des Mitarbeiters in der Liste auswählt. Das Makro verwendet die SQL-Sprachumgebung, um die Tabelle EMPLOYEE nach den Mitarbeiternamen und Informationen zu einem bestimmten Mitarbeiter abzufragen.



%{************************ Sample Macro *****************************
*   FileName = sqlsamp1.d2w                                         *
*   Description:                                                    *
*     This Net.Data macro file queries...                           *
*         - The EMPLOYEE table to create a selection list of        *
*          employees for display at a browser                       *
*         - The EMPLOYEE table to obtain additional information     *
*               about an individual employee                        *
*                                                                   *
********************************************************************%}
%{***************************************************************************
*   Include for global DEFINEs -                                            *
****************************************************************************%}
%INCLUDE "sqlsamp1.hti"                                                     *
%{****************************************************************************
*  Function:  queryDB              Language Environment: SQL                *
*  Description: Queries the table designated by the variable myTable and    *
*  creates a selection list from the result.  The value of the variable     *
*  myTable is specified in the include file sqlsamp1.hti.                   *
****************************************************************************%}
%FUNCTION(DTW_SQL) queryDB() {
 SELECT * FROM $(myTable)
%MESSAGE {
    -204:  {<p><b>ERROR -204: Table $(myTable) not found. </b>
   <p>Be sure the correct include file is being used.</b>
    %} : exit
    +default: "WARNING $(RETURN_CODE)" : continue
    -default: "Unexpected ERROR $(RETURN_CODE)" : exit
%}

%REPORT {
<select name=emp_name>
   %ROW{
<option>$(V2)
%}
</select>
%}
%}

%{****************************************************************************
*  Function: fname         Language Environment: SQL                         *
*  Description: Queries the table designated by the variable myTable for     *
*               additional information about the employee identified by the  *
*               variable emp_name.                                           *
******************************************************************************%}
%FUNCTION(DTW_SQL) fname(){
SELECT EMPNME, PHONENO, JOB FROM $(myTable) WHERE EMPNME='$(emp_name)'
%MESSAGE {
  -204: "Error -204: Table not found "
  -104: "Error -104: Syntax error"
   100: "Warning 100: No records" : continue
  +default: "Warning $(RETURN_CODE)" : continue
  -default: "Unexpected SQL error" : exit
%}
%}


%{***************************************************************************
*  HTML block: INPUT            Title: Dynamic Query Selection              *
*                                                                           *
*  Description: Queries the EMPLOYEE table to create a selection list of    *
*               the employees for display at the browser                    *
****************************************************************************%}
%HTML(INPUT){
<html>
<head>
<title>Generate Employee Selection List</title>
</head>
<body>
<h3>$(exampleTitle)</h3>
<p>This example queries a table and uses the result to create
a selection list using a <em>%REPORT</em> block.
<hr>
<form method="post" action="report">
@queryDB()<input type="submit" value="Select Employee">
</form>
<hr>
</body>
</html>
%}

%{***************************************************************************
*  HTML block:    REPORT                                                    *
*  Description: Queries the EMPLOYEE table to obtain additional information *
*               about an individual employee                                *
****************************************************************************%}
%HTML(REPORT){
<html>
<head>
<title>Obtain Employee Information</title>
</head>
<body>
<h3>You selected employee name = $(emp_name)</h3>
<p>Here is the information for that employee:
<PRE>
@fname()
</PRE>
<hr><a href="input">Return to previous page</a>
</body>
</html>
%}

%{     End of Net.Data macro 1 %}
===========================================================================
%{**************************** Include File *********************************
*   FileName = sqlsamp1.hti                                                 *
*   Description:                                                            *
*     This include file provides global DEFINEs for the sqlsamp1.d2w        *
*     Net.Data macro.                                                       *
****************************************************************************%}
%define {
    emp_name   =""
    reposition = sign
 exampleTitle = "Sample Macro"
    myTable = "MRZ.EMPLOYEE"
%}

%{     End of include file  %}



[ Seitenanfang | Vorherige Seite | Nächste Seite | Inhaltsverzeichnis | Index ]