Solved

Peoplecode CreateRecord() ignoring a field ?

Posted on 2011-02-16
4
2,495 Views
Last Modified: 2012-05-11
I am using the following code...

&FILE = "E:\PIGCODE\DATA\" | PW_BDGT_AET.FILENAME;

&MYFILE = GetFile(&FILE, "U", %FilePath_Absolute);

&REC = CreateRecord(Record.PW_BDGT_TMP);

&SQL = CreateSQL("%Insert(:1)");

If Not &MYFILE.IsOpen Then

 Error ("TEST: failed file open");

Else

 If Not &MYFILE.SetFileLayout(FileLayout.PW_BDGT_TMP) Then

 Error ("TEST: failed SetFilelayout");

 Else

 &FRS = &MYFILE.ReadRowset();

 While &FRS <> Null

 &FRS.GetRow(1).PW_BDGT_TMP.CopyFieldsTo(&REC);

 &SQL.execute(&REC);

 &FRS = &MYFILE.ReadRowset();

 End-While;

 End-If;

 &MYFILE.Close();

End-If;

Open in new window


The resulting error is a SQL error...


SQL error. Function: SQL.Execute

 Error Position: 0

 Return: 8604 - [Microsoft][SQL Native Client]Invalid character value for cast specification (SQLSTATE 22005) 0

 Statement: INSERT INTO PS_PW_BDGT_TMP (BUSINESS_UNIT,ACCOUNT,DEPTID,PRODUCT,LINE_DESCR,MONETARY_AMOUNT) VALUES (:1,:2,:3,:4,:5,:6)

 Original Statement: %Insert(:1)



Here's the problem, the table PS_PW_BDGT_TMP has 7 fields in it's record definition, NOT 6.  This of course means that after the first field on the insert statement, all the field data types are off which cause the INSERT statement to fail.



Any thoughts or ideas ?  Thanks!



- Flynn
0
Comment
Question by:Flynnster
  • 2
4 Comments
 
LVL 5

Assisted Solution

by:simonpaul64
simonpaul64 earned 500 total points
ID: 34916194
Check the definition of the file layout - there may be some difference there between the file layout definition and the record definition. If you created the filelayout based on an old version of the record (with 6 fields) you need to update the filelayout as PS won't do that for you.
0
 

Accepted Solution

by:
Flynnster earned 0 total points
ID: 34916252
Hey Simon :)

Well, I just solved this dilemma.  The record and the file layout of the record were created relatively speaking at the same time and there was no difference between the two, to address your suggestion.

Someone over at IT-Toolbox suggested looping through the field names of the record object to see if it was actually the CreateRecord function that wasn't doing it's job.  Come to find out, it was pulling all seven fields as it should.  Then, I went and used pplcode to read each line of data into another file, to show me exactly what it was getting.  First thing I noticed, it was receiving all seven fields, so that was not the culprit.  What I did not was that the final and seventh field was a monetary field in nature, yet for any field value of zero, the accountants had it set to translate to a hyphen instead of a zero (WTF?).  I realized it was expecting a numeric value, not char, and that this could have caused the cast issue that SQL Server returned as an error.  So I quickly converted all seventh field hyphens to zeros, and VOILA, it worked!

Lesson Learned :  It's allways the end users who are at fault :)

- Flynn
0
 
LVL 5

Expert Comment

by:simonpaul64
ID: 34916264
LOL - glad you found it!
0

Featured Post

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

I wrote this interesting script that really help me find jobs or procedures when working in a huge environment. I could I have written it as a Procedure but then I would have to have it on each machine or have a link to a server-related search that …
I have a large data set and a SSIS package. How can I load this file in multi threading?
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Viewers will learn how the fundamental information of how to create a table.

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question