PARSE

The PARSE function analyzes a data object and validates it against the metadata of a component type. The resulting data structure is available to the calling map for further processing.

The input to the PARSE function is any data that can be processed as a text blob, for example, the result of a functional map invocation, a GET function, or a RUN map.

Syntax
PARSE (general_expression)
Meaning
PARSE (data_to_parse)
Returns
A mapped data object in a work file

Examples

The data structure that results from the PARSE function is available to the calling map. When you use a RUN map to parse data, the resulting data structure is available to the RUN map rather than to the calling map. By using the PARSE function instead of the RUN map implementation, you have fewer maps to configure and maintain.

The following examples:
  1. Receive an input document from the SPE adapter
  2. Extract the data objects from the document envelope
  3. Return a response

Example 1: RUN map implementation

In this example, the DEENVELOPE map calls the RUN map named DUMPRESPONSE to extract the data from the document.

The DUMPRESPONSE map has two input cards:
  • SpeResponse (Response global XSD)
  • Test Root (text root)
The output card of the DUMPRESPONSE map has the following rule:
=WriteDocument(Document:sequence:Documents:sequence:SpeResponse, 
TestRoot;
TEXT(INDEX(Document:sequence:Documents:sequence:SpeResponse))) + "<NL>"
The DEENVELOPE map has two input cards:
  • DataIn (text root)
  • Test Root (text root)
The DEENVELOPE map has two output cards:
  • DOCOUTPUT:
    = RUN ("DumpResponse", ECHOIN( 1 , Deenvelope ) + ECHOIN( 2 , TestRoot ) + " -OE1" )
  • DEENVELOPE:
    =VALID(GET("SPE", "-DURL jdbc:derby://localhost:1527/spe2 
    -DBUSER derbyuser -DBPSWD derbypw 
    -DBDRIVER org.apache.derby.jdbc.ClientDriver -DENV", DataIn),
    FAIL ("SPE Deenvelope failed: " + LASTERRORMSG() ))
    
    /*
    =VALID(GET("SPE", "-DURL jdbc:db2://bobdb9.bcr.ibm.com:50000/spetest  
    -DBDRIVER com.ibm.db2.jcc.DB2Driver  -DBUSER spetest  -DBPSWD Seer5r12  
    -DENV  -T ", DataIn),
    FAIL ("SPE Deenvelope failed: " + LASTERRORMSG() ))
    */
    
    /*
    =VALID(GET("SPE", "-DURL jdbc:db2://localhost:60000/SPETEST 
    -DBDRIVER  com.ibm.db2.jcc.DB2Driver -DBUSER fred -DBPSWD org13asd  
    -DENV -T ", DataIn),
    FAIL ("SPE Deenvelope failed: " + LASTERRORMSG() ))
    */

Example 2: PARSE function implementation

In this example, a single map uses the PARSE function to perform the processing of the two maps in Example 1.

The DEENVELOPE_PARSE map has two input cards:
  • DataIn (text root)
  • Test Root (text root)
The DEENVELOPE_PARSE map has two output cards:
  • RESPONSEINFO:
    = WriteDocument( Document:sequence:Documents:sequence:SpeResponse, 
    TestRoot, 
    TEXT( INDEX( Document:sequence:Documents:sequence:SpeResponse ) ) ) + "<NL>"
    
    = "Response - Status: " + Status:sequence:SpeResponse + ", 
    Advanced status: " + AdvancedStatus:sequence:SpeResponse + "<NL>"
  • SPERESPONSE (Response Global XSD):
    =PARSE( VALID(GET("SPE", "-DURL jdbc:derby://localhost:1527/spe2 
    -DBUSER derbyuser -DBPSWD derbypw 
    -DBDRIVER org.apache.derby.jdbc.ClientDriver -DENV", DataIn),
    FAIL ("SPE Deenvelope failed: " + LASTERRORMSG() )) )