Object-Based Code to avoid use of SQLEXEC

251 0 0
                                        

Object–Based Code to avoid use of SQLEXEC

Below code can be used to avoid use of SQLExec.

SQLExec Code:

SQLExec to copy a row from ORD_HDR to ORD_HDR_EXT.

&ORD_NO = &NEW_ORD_NO;

SQLExec("select %timeout(order_dt), training_loc, vendor_cd, order_status, status_dt, deliver_method from ps_ord_hdr

where order_nbr = :1", &ORD_NO, &ORD_DT, &TRAIN_LOC,&VEND_CD, &ORD_STAT, &STAT_DT, &SHIP_VIA);

SQLExec("delete from ps_ord_hdr_ext where order_nbr = :1", &ORD_NO);

SQLExec("insert into ps_ord_hdr_ext (order_nbr, order_dt,training_loc, vendor_cd, order_status, status_dt,

deliver_method) values(:1,%datein(:2),:3,:4,:5,:6,:7)",&ORD_NO, &ORD_DT, &TRAIN_LOC, &VEND_CD, &ORD_STAT, &STAT_DT,&SHIP_VIA);

Same logic using Object Based code:

Local Record &REC1, &REC2;

&REC1 = GetRecord(RECORD.ORD_HDR);

&REC2 = CreateRecord(RECORD.ORD_HDR_EXT);

&REC1.ORD_NO = &NEW_ORD_NO;

&REC1.SelectByKey();

&REC1.CopyFieldsTo(&REC2);

&REC2.Delete();

&REC2.Insert();

PeopleCodeWhere stories live. Discover now