Search This Blog

Showing posts with label Application Engine. Show all posts
Showing posts with label Application Engine. Show all posts

Saturday, December 13, 2014

Application Engine: State Record

State Record:

1. The record that ends with '_AET' is identified as State Record.
2. Used in Application Engine program.
3. As name itself says 'state' meaning we get to know the state of data (snapshot) that is passed through the program.
4. quite useful in restart logic, where if a process goes to NoSuccess, after correction we can restart the program from the point where it got abend.
5. State Record can by derived work record or a physical record.
6. When a program is designed for Restart enabled logic, then it would be ideal to have state record type as physical record as it stores the data to the database before the abend.
7. In case of Derived work record, during restart failure the fields would be initialized to default values.
8. There can be 200 state records but only one of them can be primary record.
9. While passing parameters to State record, if it is primary one then no need to mention the record.field format. we can directly assign to the field using %select and %bind variables.
10.To refer fields in the State record, use %BINDS.
11.It should contain Process instance as the first and the only Key field.
12.We can also share the data of one state record from one AE program to another.
13.State Record contains only one row of data for each process instance.
14.Along with passing data, we can also have other fields to store the flag values. Flag values usage helps us in Parallel processing.
15.To set values in the State record, use %SELECT.

Snapshot of Sample State Record shown below.

Friday, December 12, 2014

How to run COBOL from Application Engine using CreateProcessRequest()



Before running a Cobol , we need to make sure that the process definition is created.
When running from AE, make sure you pass runcontrolID and Process Type along with other required parameters.
 We can also use Remotecall procedure to call COBOL procedure from AE.

Sample Code:

Local ProcessRequest &ProcessRequest;
&ProcessRequest= CreateProcessRequest();

/* Set all the Required Properties */
/* Enter the RunControlID
&ProcessRequest.RunControlID = STATERECORD_AET.RUN_CNTL_ID;
&ProcessRequest.ProcessType = "COBOL SQL";
&ProcessRequest.ProcessName = "";
/* Schedule the Process */
&ProcessRequest.Schedule();

Wednesday, November 26, 2014

How to create PDF file through AE using Java Class

The example mentioned below will give basic insights on how to create PDF file through Application Engine using Java classes.
Other way is to use BI Publisher and call the report definition and then publish the report.

To start with, firstly the Appserver/Classes path should contain the JAR file starting with itext.
Write the java code in AE to create PDF file.

Below is the sample code:
/* Create a Document object */
Local JavaObject &Obj_CreateiTextTable = CreateJavaObject("com.lowagie.text.Document");

/* Cretae PDF Writer object */
Local JavaObject &obj_writePDFoutput = GetJavaClass("com.lowagie.text.pdf.PdfWriter").getInstance(&Obj_CreateiTextTable, CreateJavaObject("java.io.FileOutputStream", "/ TESTPDF11262014.pdf", True));
&Obj_CreateiTextTable.open(); /*open the document for writing */
 /* Array with 3 columns */
Local JavaObject &Obj_myPDFTable = CreateJavaObject("com.lowagie.text.pdf.PdfPTable", 3);
 /* Add data to each cell */
&Obj_myPDFTable.addCell("Emp ID");
&Obj_myPDFTable.addCell("Name");
&Obj_myPDFTable.addCell("Address");
&Obj_myPDFTable.addCell("EE1256");
&Obj_myPDFTable.addCell("John");
&Obj_myPDFTable.addCell("Main Street");
 /* Add Table to Document */
&Obj_CreateiTextTable.add(&Obj_myPDFTable);
&Obj_CreateiTextTable.close();  /* close the document */


Output Snapshot:

Friday, July 26, 2013

SQL.Fetch: object isn't open on a select

Usually, you come across this error when there are erroneous rows while loading data through Component Interface (CI).

You might be using any of the sql class functions to loop through the data and then inserting each row.  When an error occurs the CI closes the SQL object which is open. Thus subsequent rows will not get processed.

This is a problem as the subsequent rows which are valid are not getting inserted.
Now that we identified the cause for the issue, lets try to fix this issue.

Below is one such approach which helps in resolving the issue.

Resolution:
1. Create a standalone rowset and fill it with all the rows which needs to be inserted.

2. Now loop through the rowset and load the data through CI.

3. For error row, CI fails while saving. At this point , call the Cancel function as the current transaction is invalid.

4. After Successful cancellation of erroneous row , CI will move on to next row in the loop.

This way , we can avoid/skip error rows and proceed with insertion of other valid rows.
Hope this post is useful..

Thursday, June 27, 2013

Understanding Restart in AE


Understanding Restart in AE

Application Engine programs save to the database (perform a commit) only when an entire program successfully completes. You must set individual commits where appropriate.

At the section level, you can set a commit after each step in a section. At the step level, you can require or defer commits for individual steps, or you can increase the commit frequency within a step to N iterations of a looping action, such as a Do Select of Do While, within a step.

The commit level that you select affects how restart works in a program. Each time Application Engine issues a commit with restart enabled, it records the current state of the program. The recording of the current state that Application Engine performs is referred to as a checkpoint.

Using the restart feature enables you to perform commits more often in a program. Restart reduces the overall effect on other users and processes while the background program is running because it reduces the number of rows that are locked by the program. Fewer rows allows multiple instances of the program to run concurrently (parallel processing), which may be useful for high-volume solutions.

With restart, if a failure occurs at any point in the process, the user can restart the program and expect the program to behave as follows:

    Ignore the steps that have already completed up to the last successful commit.

    Begin processing at the next step after the last successful commit.

The ability for Application Engine to remember completed steps depends on a record called AERUNCONTROL, which is keyed by process instance.

When a program runs, each time Application Engine issues a commit it also saves all of the information required for a program restart in the AERUNCONTROL record.

Reference : Peopletools 8.53

Monday, June 10, 2013

%DateIn and %Dateout Meta Variables

%Datein  resolves to to_date('2013-06-10','YYYY-MM-DD')              
%Dateout resolves to to_char(date,'YYYY-MM-DD')

Easy way to remember , when to use %Datein and %Dateout.
Lets consider a simple database table below. 

TableName: EMP_ACTION







To retrieve data for a particular date , we use WHERE criteria to filter rows.
So in this case date coulmn is filtered as of particular Date.
Similary, only Date Value should be inserted into the column of Date data type.

In both the cases,  %Datein can be used, since it resolves into Date data type.

To format the date output, we use to_char(date,format). So in this case we use %Dateout

Sending multiple attachments through mail from App Engine

The below code will send multiple attachments through the mail.

AE Peoplecode:

import PT_MCF_MAIL:*; // Inlcude the App package

/**** Send Mail ****/

Local PT_MCF_MAIL:MCFOutboundEmail &email = create PT_MCF_MAIL:MCFOutboundEmail();

&email.From = ""; // when set to null, the email configured at server level will send mail

SQLExec("select URL from psurldefn where url_id = "URLid which stores the recipients list", &Email_To);
&email.Recipients = &Email_To;

&email.Subject = Place the Subject of the mail here;

Local string &plain_text = "Report Description";
Local PT_MCF_MAIL:MCFBodyPart &text = create PT_MCF_MAIL:MCFBodyPart();
&text.Text = &plain_text;

&File_name_path = Place the full path ( like /...../filename.pdf')
&file_name_email = Name of the attached filename (filename.pdf)
&File_name_path2 = Place the full path ( like /...../filename2.pdf')
&file_name_email2 = Name of the attached filename (filename2.pdf)


Local PT_MCF_MAIL:MCFBodyPart &attach1 = create PT_MCF_MAIL:MCFBodyPart();
Local PT_MCF_MAIL:MCFBodyPart &attach2 = create PT_MCF_MAIL:MCFBodyPart();

&attach1.SetAttachmentContent(&File_name_path, %FilePath_Absolute, &file_name_email, "Report Description", "", "");
&attach2.SetAttachmentContent(&File_name_path2, %FilePath_Absolute, &file_name_email2, "Report Description 2 ", "", "");

Local PT_MCF_MAIL:MCFMultipart &mp = create PT_MCF_MAIL:MCFMultipart();
&mp.AddBodyPart(&text);
&mp.AddBodyPart(&attach1);
&mp.AddBodyPart(&attach2);
&email.MultiPart = &mp ;

Local integer &res = &email.Send();

Local boolean &done;

Evaluate &resp
When %ObEmail_Delivered
   /* every thing ok */
   &done = True;
   Break;
  
When %ObEmail_NotDelivered
   /*-- Check &email.InvalidAddresses, &email.ValidSentAddresses
and &email.ValidUnsentAddresses */
   &done = False;
   Break;
  
When %ObEmail_PartiallyDelivered
   /* Check &email.InvalidAddresses, &email.ValidSentAddresses
and &email.ValidUnsentAddresses; */
   &done = True;
   Break;
  
When %ObEmail_FailedBeforeSending
   /* Get the Message Set Number, message number;
Or just get the formatted messages from &email.ErrorDescription,
&email.ErrorDetails;*/
  
   &done = False;
   Break;
End-Evaluate;

Sunday, June 9, 2013

Sending mail through App Engine program

Below code sends mail through App engine program.  The code uses the PT_MCF_MAIL package to send mail with attachment.

AE Peoplecode:

import PT_MCF_MAIL:*; // Inlcude the App package

/**** Send Mail ****/

Local PT_MCF_MAIL:MCFOutboundEmail &email = create PT_MCF_MAIL:MCFOutboundEmail();

&email.From = ""; // when set to null, the email configured at server level will send mail

SQLExec("select URL from psurldefn where url_id = "URLid which stores the recipients list", &Email_To);
&email.Recipients = &Email_To;

&email.Subject = Place the Subject of the mail here;

Local string &plain_text = "Report Description";
Local PT_MCF_MAIL:MCFBodyPart &text = create PT_MCF_MAIL:MCFBodyPart();
&text.Text = &plain_text;

&File_name_path = Place the full path ( like /...../filename.pdf')
&file_name_email = Name of the attached filename (filename.pdf)

Local PT_MCF_MAIL:MCFBodyPart &attach1 = create PT_MCF_MAIL:MCFBodyPart();
&attach1.SetAttachmentContent(&File_name_path, %FilePath_Absolute, &file_name_email, "Report Description", "", "");

Local PT_MCF_MAIL:MCFMultipart &mp = create PT_MCF_MAIL:MCFMultipart();
&mp.AddBodyPart(&text);
&mp.AddBodyPart(&attach1);
&email.MultiPart = &mp ;

Local integer &res = &email.Send();

Local boolean &done;

Evaluate &resp
When %ObEmail_Delivered
   /* every thing ok */
   &done = True;
   Break;
  
When %ObEmail_NotDelivered
   /*-- Check &email.InvalidAddresses, &email.ValidSentAddresses
and &email.ValidUnsentAddresses */
   &done = False;
   Break;
  
When %ObEmail_PartiallyDelivered
   /* Check &email.InvalidAddresses, &email.ValidSentAddresses
and &email.ValidUnsentAddresses; */
   &done = True;
   Break;
  
When %ObEmail_FailedBeforeSending
   /* Get the Message Set Number, message number;
Or just get the formatted messages from &email.ErrorDescription,
&email.ErrorDetails;*/
  
   &done = False;
   Break;
End-Evaluate;

Monday, April 1, 2013

App Engine: Do-Select with Re-Select option

Few pointers on using Do-Select with Re-Select option

For each iteration of the loop, Application Engine opens a cursor and fetches the
first row.

Your program processes the first row returned from the Select statement.
The cursor is reopened for each iteration of the loop.

With this type of Fetch statement, you typically want some aspect of the loop to
eventually cause the Select statement to return no rows.

Otherwise, there is no mechanism in place by which to exit the loop. This type of

Do Select is restartable.

For new Application Engine programs that you develop, by default, the commit
values at the section and the step level are turned off.

No commits occur during the program run, except for the implicit commit that occurs after the successful completion of the program.

For row-based processing, commit after every N iterations of the main fetch loop
that drives the process.

One technique for accomplishing this is to have a processed flag that you check
in the Where clause of the Do Select action,and you perform an update inside the loop (and before the commit) to set the flag to Y on each row that you fetch.