Accessing fields on CICS 3270 screens

Once a terminal connection to CICS® has been established, the CclTerminal, CclSession, CclScreen and CclField objects are used to navigate through the screens presented by the CICS server application, reading and updating screen data as required.

The CclScreen object is created by the CclTerminal object and is obtained via the screen method on the CclTerminal object. It provides methods for obtaining general information about the 3270 screen (e.g. cursor position) and for accessing individual fields (by row/column screen position or by index). The following example prints out field contents, then ends the CESN transaction (started above) by returning PF3:
  // Get access to the CclScreen object
  CclScreen* screen = terminal.screen();
  for ( int i=1; i ≤ screen->fieldCount(); i++ ) {
      CclField* field = screen->field(i); // get field by index
      if ( field->textLength > 0 )
          cout << "Field " << i << ": " << field->text();
  }
  // Return PF3 to CICS
  screen->setAID( CclScreen::PF3 );
  terminal.send( &session );
  // Disconnect the terminal from CICS
  terminal.disconnect();
The CclField class provides access to the text and attributes of an individual 3270 field. These can be used in a variety of ways to locate and manipulate information on a 3270 screen:
  for ( int i=1; i ≤ screen->fieldCount(); i++ ) {
      CclField* field = screen->field(i); // get field by index
      // Find unprotected (i.e. input) fields
      if ( field->inputProt() == CclField::unprotect )
          …
      // Find fields containing a specific text string
      if ( strstr(field->text(), "CICS Sign-on") )
          …
      // Find red fields
      if ( field->foregroundColor() == CclField::red )
          …
  }

Note that the string "Sign-on" in the above sample may need to be changed to meet local conventions. For example, an AIX® server may use the string "SIGNON".