Tuesday 12 April 2016

Code :- Run AE thru CreateProcessRequest in  PeopleCode

Local ProcessRequest &RQST;

&RQST = CreateProcessRequest();
&RQST.ProcessType = "Application Engine";
&RQST.ProcessName = "POLOADFILE";
&RQST.RunControlID = "POLOAD";
&RQST.Schedule();

If &RQST.Status = 0 Then
   WinMessage("AE Successfully Scheduled", 0);
Else
   WinMessage("There is a problem while Scheduling AE", 0);

End-If;



ArrayS in Peoplecode


Local File &FILE1;
Local string &STRING, &ITEM_ID, &ship_id;
Local array of string &Array;
&FILE1 = GetFile(xyz.txt, "R", %FilePath_Absolute);
&Array = CreateArrayRept("", 0);
If &FILE1.IsOpen Then
   While &FILE1.ReadLine(&STRING);
      &Array = Split(&STRING, Char(9));/*** Define array and make sure the Fields separated by tab space  in xyz.txt file***/
      &ITEM_ID = LTrim(RTrim(&Array [1], " "), " ");
      &ship_id = LTrim(RTrim(&Array [2], " "), " ");
                MessageBox(0, "", 0, 0, "The Processed  item id's are  # " | &ITEM_ID );

   End-While;
End-If;

&FILE1.Close();
/***The string &item_id ( includes 1234,4567 values) which can be used for validations or printing ***/

Tuesday 5 April 2016

Dynamic SQL in SQR with example:

Assume a scenario; SQR generates employee details report based on either Company or pay Group.

 So SQR code would be.
If $Run_Option = ‘P’
Begin-Select
A.EMPLID (+1, 1)
A.NAME (, +5)
 FROM XYZ A
WHERE A.PAYGROUP IN (‘PG’)
End-Select
Else
Begin-Select
B.EMPLID (+1, 1)
B.NAME (, +5)
 FROM XYZ B
WHERE B.COMPANY IN (‘SAP’)
End-Select
End-If
Above code can be tuned by Create dynamic SQL.
If $Run_Option = ‘P’
   LET $WHERE = 'WHERE A.PAYGROUP IN (' || '''' || 'PG' || '''' || ')'
END-IF
IF $Run_Option = ‘C’
   LET $WHERE = 'WHERE A.COMPANY IN (' || '''' || 'SAP' || '''' || ')'
End-If
Begin-Select
EMPLID (+1, 1)
NAME (, +5)
 FROM XYZ A
[$where]
End-Select
If run option is not P and C then there won’t be any where condition. SQR will not give any error. It runs without the Where condition, so all the rows from XYZ table will be Selected.