Thursday, 2 October 2014

PeopleCode-Update Statement

Local  Record &REC ;
Local String &UPDSTRING;


Function getUpdateString(&REC As Record) Returns string;

For &COUNT = 1 To &REC.FieldCount;

&UPDSTRING = "Update %TABLE(:1) set ";

&UPDSTRING = &UPDSTRING | &REC.GetField(&COUNT).Name | " = ";
&UPDSTRING = &UPDSTRING | &REC.GetField(&COUNT).Value | " ";


End-For;

 &UPDSTRING = &UPDSTRING | " where %KeyEqual(:1)";
 Return &UPDSTRING;
End-Function;

-------------------------------------------------------------

Local Record &REC;
Local Sql   &SQL , SQL_UP ;


&REC = CreateRecord(Record.PSOPRDEFN);

&SQL = CreateSQL("%SELECTALL(:1) WHERE OPRID =:2", &REC, &USERID);
&SQL_UP = CreateSQL("%Update(:1)");
While &SQL.Fetch(&REC)

&SQL_UP.EXECUTE(&REC);
End-While;
&SQL_UP.CLOSE();

No comments:

Post a Comment