Solved

Peoplecode CreateRecord() ignoring a field ?

Posted on 2011-02-16
4
2,530 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Let's review the features of new SQL Server 2012 (Denali CTP3). It listed as below: PERCENT_RANK(): PERCENT_RANK() function will returns the percentage value of rank of the values among its group. PERCENT_RANK() function value always in be…
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.

840 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