Populating and Retrieving Document Data
This section discusses how to:
Instantiate Documents objects.
Populate document data.
Retrieve document data.
This section provides guidelines for instantiating Document objects, and populating and retrieving document data from document message types.
Memory Management in Message Segments that Use Documents
Following these guidelines when populating or retrieving document data from message segments:
After your code to populate a segment, set the following statement to NULL:
&DOC = null;
Including this statement in your code releases the segment data from memory. If you do not include this statement in your code, data from all segments accumulates in memory.
Start each new segment processing section by setting the following statement to TRUE:
&DOC = &MSG.GetDocument(true)
Including this statement in your code guarantees that only one segment is in memory at a given time.
This section discusses and provides examples for how to:
Instantiate Document objects using package, name, and version.
Instantiate Document objects using document keys.
Instantiate Document objects for document message types.
Instantiating Document Objects Using Package, Name, and Version
You can instantiate a Document object using the CreateDocument built-in function. Using this approach, you use the Create Document built-in function, and then specify the document package name, the document name, and the document version, as shown in the following example:
&DOC = CreateDocument("Purchasing", "PurchaseOrder", "v1");
Instantiating Document Objects Using Document Keys
The following code example shows instantiating a Document object using the a document key. This approach uses the CreateDocumentKey and CreateDocument built-in functions.
First you instantiate a Document Key object, using the CreateDocumentKey built-in function and passing in the document package name, document name, and document version. You then instantiate a Document object using the CreateDocument built-in function, and pass in the document key.
&DOCKEY = CreateDocumentKey("Purchasing", "PurchaseOrder", "v1");
&DOC = CreateDocument(&DOCKEY);
Instantiating Document Objects for Document Message Types
The following example shows how to instantiate a document object when the document is being used as a message type.
&DOC = &MSG.GetDocument();
This section discusses and provides examples for how to:
Populate documents from messages.
Populate document using rowsets.
Populate message segments with documents.
Populating Documents from Messages
The following example shows how to use the CreateMessage built-in function to populate a document from a message:
&MSG = CreateMessage(Operation.PURCHASE_ORDER);
&DOC = &MSG.GetDocument();
Populating Documents Using Rowsets
The following example shows using the CreateMessage built-in function and the Document class to populate a document using a rowset:
Local Message &MSG;
Local Document &DOC;
&MSG = CreateMessage(Operation.PURCHASE_ORDER);
&DOC = &MSG.GetDocument();
/* Get Rowset */
&Rowset = &DOC.GetRowset();
/* populate rowset like any other rowset
/* update document with popualted rowset * /
&nRet = &DOC.UpdateFromRowset(&Rowset);
If (&nRet) = True Then
%IntBroker.Publish(&MSG);
End-If;
Populating Message Segments with Documents
The following example shows code for populating message segments with documents.
After you code to populate a segment, set the following statement to NULL to release memory:
&DOC = null;
Then, set the following statement to TRUE to manage memory and guarantee that only one segment is in memory at a given time:
&DOC = &MSG.GetDocument(true);
If you do not following these coding guidelines, memory will get filled with data from all segments in the message.
The previous statements are in emphasis in the following example:
Declare Function PopulateDocument PeopleCode QE_FLIGHTDATA.QE_ACNUMBER FieldFormula;
Local Document &DOC;
&MSG = CreateMessage(Operation.FLIGHTPLAN_DOC);
/*pass in true to get ownership of the object*/
/
&DOC = &MSG.GetDocument(true);
/*popualte the docment with data */
PopulateDocument(&DOC, 1);
/*create a new segment */
&MSG.CreateNewSegment();
/* null out object to release memory */
&DOC = null;&DOC = &MSG.GetDocument(true);
PopulateDocument(&DOC, 2);
&MSG.CreateNewSegment();&DOC = null;
&DOC = &MSG.GetDocument(true);
PopulateDocument(&DOC, 3);
/* publish segmented Message (3 segments) */
%IntBroker.Publish(&MSG);
This section discusses and provides code examples for how to:
Retrieve document data from the Message object.
Retrieve document data from message segments.
Retrieve document data within a Notification event using message segments
Retrieving Document Data from the Message Object
The following code provides an example of how to retrieve a document from the Message object:
Local Message &MSG;
Local Document &DOC;
Local Primitive &PRIM;
Local Compound &COM, &COM_ID, &COM_BILL, &COM_SHIP, &COM_ITEM;
Local Collection &COL_ITEM;
&MSG = CreateMessage(Operation.PURCHASE_ORDER);
&DOC = &MSG.GetDocument();
&COM = &DOC.DocumentElement;
&COM.GetPropertyByName("LanguageCode").Value = "ENG";
/* Populate TransactionID Compound */
&COM_ID = &COM.GetPropertyByName("TransactionId");
&COM2.GetPropertyByIndex(1).value = "KAC";
&COM2.GetPropertyByIndex(1).value = "12345678";
/* Populate BillTo Compound */
&COM_BILL = &COM.GetPropertyByName("BillTo");
&COM5.GetPropertyByName("name").Value = "RobbyNash";
&COM5.GetPropertyByName("number").Value = 713;
&COM5.GetPropertyByName("street").Value = "High Wind";
&COM5.GetPropertyByName("unit").Value = "";
&COM5.GetPropertyByName("city").Value = "Paia";
&COM5.GetPropertyByName("state").Value = "Maui HI";
&COM5.GetPropertyByName("zipcode").Value = "96779";
/* Populate item_collection Collection (2 rows) */
&COL_ITEM = &COM.GetPropertyByName("item_collection");
&COM_ITEM = &COL_ITEM.CreateItem();
&PRIM = &COM_ITEM.GetPropertyByName("item");
&PRIM.Value = "mast";
&PRIM = &COM_ITEM.GetPropertyByName("sku");
&PRIM.Value = "123322";
&PRIM = &COM_ITEM.GetPropertyByName("price");
&PRIM.Value = 300;
&PRIM = &COM_ITEM.GetPropertyByName("quantity");
&PRIM.Value = 12;
&nRet = &COL_ITEM.AppendItem(&COM_ITEM);
&COM_ITEM = &COL_ITEM.CreateItem();
&COM5.GetPropertyByName("item").Value = "boom";
&COM5.GetPropertyByName("sku").Value = "123334";
&COM5.GetPropertyByName("price").Value = 270;
&COM5.GetPropertyByName("quantity").Value = 10;
&nRet = &COL_ITEM.AppendItem(&COM_ITEM);
%IntBroker.Publish(&MSG);
Retrieving Document Data from Message Segments
The following code example shows an example of retrieving document data from message segments. As discussed elsewhere in this section, the example shows setting the following statement to NULL :
&DOC = Null;
Setting the statement to NULL clears memory between segment loops:
import PS_PT:Integration:INotificationHandler;
class DOCUMENT_TESTER implements PS_PT:Integration:INotificationHandler
method FLIGHTDATA();
method OnNotify(&MSG As Message);
end-class;
/* constructor */
method FLIGHTDATA
end-method;
method OnNotify
/+ &MSG as Message +/
/+ Extends/implements PS_PT:Integration:INotificationHandler.OnNotify +/
/* Variable Declaration */
Local Rowset &rs;
Local Document &DOC;
Local Record &FLIGHTDATA, &REC;
Local integer &i;
/* get each segment of data via a Document and proces it */
For &i = 1 To &MSG.SegmentCount
/* null out object to release memory */
&DOC = Null;
&MSG.GetSegment(&i);
/* pass true to GetDocument method to take ownership of object */&DOC = &MSG.GetDocument( True);
/* process Document data for each segment */
End-For;
end-method;
Retrieving Document Data within a Notification Event Using Message Segments
The following code example demonstrates how to retrieve document data within an Notification event using message segments.
As discussed elsewhere in this section, the example shows setting the following statement to NULL :
&DOC = Null;
Setting the statement to NULL clears memory between segment loops:
For &i = 1 To &MSG.SegmentCount
&DOC = Null;
&MSG.GetSegment(&i);
&DOC = &MSG.GetDocument();
&COM = &DOC.DocumentElement;
&str = &COM.GetPropertyByName("LanguageCode").Value;
&COM_ID = &COM.GetPropertyByName("TransactionId");
&str = &COM_ID.GetPropertyByIndex(2).Value;
&COM_BILL = &COM.GetPropertyByName("BillTo").Value;
&str = &COM_BILL.GetPropertyByName("name").Value;
&COL_ITEM = &COM.GetPropertyByName("item_collecion");
For &j = 1 To &COL_ITEM.count
&COM_ITEM = &COL_ITEM.GetItem(&j);
&str = &COM_ITEM.GetPropertyByName("item").Value;
End-For;
End-For;