Back Up

Using Features Specific to Dynamic 4GL

This code generates a new screen from the data in the company table and creates a new file. The function generateForms() is added to the .per file.

Note:
Indicates that the line would normally continue on the same line.

DATABASE pb

GLOBALS "globals.4gl"

FUNCTION generateForms()

  DEFINE i SMALLINT
  DEFINE l_buffer CHAR(80)
  DEFINE l_writeBuffer CHAR(80)

  CALL channel::open_file ("f1", "frmlistcontact.per", "w")
  CALL channel::set_delimiter ("f1", "")

  # Header
  CALL channel::write ("f1", "-- Generated screen - DO NOT EDIT")
  CALL channel::write ("f1", "DATABASE formonly")
  CALL channel::write ("f1", "")
  CALL channel::write ("f1", "SCREEN")
  CALL channel::write ("f1", "{")
  CALL channel::write ("f1", "<p align=\"right\">")
  CALL channel::write ("f1", "<big><font face=\"Arial\" 
    color=\"#0000FF\">")
  CALL channel::write ("f1", "<strong>List of contacts
    </strong></font></big></p>")
  CALL channel::write ("f1", "<HR>")
  CALL channel::write ("f1", "<I>Company</I> [c001                ]")
  CALL channel::write ("f1", "<HR>")
  CALL channel::write ("f1", "<TABLE border=\"0\" 
    CELLSPACING=\"0\" CELLPADDING=\"0\"> <TR>")
  CALL channel::write ("f1", "    <td bgcolor=\"#00FFFF\">
    <font face=\"Arial\" color=\"#0000FF\">Id&nbsp;&nbsp;
    </font></td>")
  CALL channel::write ("f1", "    <td bgcolor=\"#00FFFF\">
    <font face=\"Arial\" color=\"#0000FF\">Contact&nbsp;&nbsp;
    </font></td>")
  CALL channel::write ("f1", "    <td bgcolor=\"#00FFFF\">
    <font face=\"Arial\" color=\"#0000FF\">Phone number&nbsp;
    &nbsp;</font></td>")
  CALL channel::write ("f1", "    <td bgcolor=\"#00FFFF\">
    <font face=\"Arial\" color=\"#0000FF\">Fax number&nbsp;&nbsp;
    </font></td>")
  CALL channel::write ("f1", "    <td bgcolor=\"#00FFFF\">
    <font face=\"Arial\" color=\"#0000FF\">E-mail&nbsp;&nbsp;
    </font></td>")
 
  FOR i = 1 TO 10
    CALL channel::write ("f1", "</TR> <TR>")
    CALL channel::write ("f1", "<TD>[f001  ]</TD>")
    CALL channel::write ("f1", "<TD>[f002             ]</TD>")
    CALL channel::write ("f1", "<TD>[f003              ]</TD>")
    CALL channel::write ("f1", "<TD>[f004               ]</TD>")
    CALL channel::write ("f1", "<TD>[f005                   ]</TD>")
  END FOR

  CALL channel::write ("f1", "</TR> </TABLE>")
  CALL channel::write ("f1", "}")
  CALL channel::write ("f1", "END")
  CALL channel::write ("f1", "")
  CALL channel::write ("f1", "ATTRIBUTES")
  CALL channel::write ("f1", "c001 = formonly.company_name, include=(")

  # Include section from table
  PREPARE sqlStatement FROM "SELECT com_name FROM company ORDER BY com_name"
  DECLARE sqlCursor CURSOR FOR sqlStatement 
  OPEN sqlCursor
  FETCH sqlCursor INTO l_buffer
  WHILE status <> NOTFOUND
    LET l_writeBuffer = "\"", l_buffer CLIPPED, "\","
    CALL channel::write ("f1", l_writeBuffer CLIPPED)
    FETCH sqlCursor INTO l_buffer
  END WHILE

  FREE sqlStatement
  FREE sqlCursor

  # Tail
  CALL channel::write ("f1", "\"\"")
  CALL channel::write ("f1", ");")
  CALL channel::write ("f1", "f001 = formonly.contact_id;")
  CALL channel::write ("f1", "f002 = formonly.contact_name;")
  CALL channel::write ("f1", "f003 = formonly.contact_tel;")
  CALL channel::write ("f1", "f004 = formonly.contact_fax;")
  CALL channel::write ("f1", "f005 = formonly.contact_email;")
  CALL channel::write ("f1", "END")
  CALL channel::write ("f1", "")
  CALL channel::write ("f1", "INSTRUCTIONS")
  CALL channel::write ("f1", "DELIMITERS \"  \"")
  CALL channel::write ("f1", "SCREEN RECORD scr[10] (")
  CALL channel::write ("f1", "  formonly.contact_id,")
  CALL channel::write ("f1", "  formonly.contact_name,")
  CALL channel::write ("f1", "  formonly.contact_tel,")
  CALL channel::write ("f1", "  formonly.contact_fax,")
  CALL channel::write ("f1", "  formonly.contact_email)")
  CALL channel::write ("f1", "END")
  CALL channel::write ("f1", "")
  CALL channel::CLOSE ("f1")

  RUN "fglform frmlistcontact.per" RETURNING i
  
END FUNCTION                              

When the generateForms() function is called, this source generates a new form using channels and a call to the form compiler, fglform.

The result of the modification is the following:

Include