Search
A number of problems SQLRPGLE: Operating Systems
Obicn
A number of problems SQLRPGLE
SQLRPGLE I wrote a small procedure, a function is to extract all the data PF, assign variables, and then use variables to update or insert data to another PF. But now encountered two problems:
1. Operational procedures, If you want to CLRPFM first two PF, Tip: MEMBER in use. Must
才行re-write-off landing, which is why? ?
2. Code may be a problem, I implementation procedures, he> --- Variables statement
0001.00 DVXHEMPID S 3A
0002.00 DVXHNAME S 15A
0003.00 DVXHJOB S 10A
0004.00 DISEXIST S 5S 0
-- Cursor statement
0005.00 C / EXEC SQL
0006.00 C + DECLARE C1 CURSOR FOR SELECT XHEMPID, XHNAME, XHJOB FROM XHZQ
0007.00 C / END-EXEC
-- Open cursor
0008.00 C / EXEC SQL
0009.00 C + OPEN C1
0010.00 C / END-EXEC
-- When there is no wrong time to assign the cursor in the value of variables
0011.00 C DOW SQLCOD = 0
0012.00 C / EXEC SQL
0013.00 C + FETCH C1 INTO: VXHEMPID,: VXHNAME,: VXHJOB
0014.00 C / END-EXEC
--- VXHEMPID variables used as a keyword to find the existence of records
0015.00 C / EXEC SQL
0016.00 C + SELECT COUNT (*) INTO: ISEXIST FROM XHZQ1 WHERE XHEMPID1 =: VXHEMPID
-- If there is no record> 0017.00 C / END-EXEC
0018.00 C IF ISEXIST = 0
0019.00 C / EXEC SQL
0020.00 C + INSERT INTO XHZQ1 (XHEMPID1, XHNAME1, XHJOB1)
0021.00 C + VALUES (: VXHEMPID,: VXHNAME,: VXHJOB)
0022.00 C / END-EXEC
0023.00 C ENDIF
-- If the existence of updated records
0024.00 C IF ISEXIST = 1
0025.00 C / EXEC SQL
0026.00 C + UPDATE XHZQ1
0027.00 C + SET XHNAME1 =: VXHNAME,
0028.00 C + XHJOB1 =: VXHJOB
0029.00 C / END-EXEC
0030.00 C ENDIF
-- We will continue to read a record
0031.00 C / EXEC SQL
0032.00 C + FETCH C1 INTO: VXHEMPID,: VXHNAME,: VXHJOB
0033.00 C / END-EXEC
0034.00 C ENDDO
-- Close cursor
0035.00 C / EXEC SQL
0036.00 C + CLOSE C1
0037.00 C / END-EXEC
-- Submitted by the changes
0038.00 C / EXEC SQL
COMMIT 0039.00 C +
0040.00 C / END-EXEC
-- End
0041.00 C RETURN
SQLRPGLE I wrote a small procedure, a function is to extract all the data PF, assign variables, and then use variables to update or insert data to another PF. But now encountered two problems:
1. Operational procedures, If you want to CLRPFM first two PF, Tip: MEMBER in use. Must
才行re-write-off landing, which is why? ?
2. Code may be a problem, I implementation procedures, he> --- Variables statement
0001.00 DVXHEMPID S 3A
0002.00 DVXHNAME S 15A
0003.00 DVXHJOB S 10A
0004.00 DISEXIST S 5S 0
-- Cursor statement
0005.00 C / EXEC SQL
0006.00 C + DECLARE C1 CURSOR FOR SELECT XHEMPID, XHNAME, XHJOB FROM XHZQ
0007.00 C / END-EXEC
-- Open cursor
0008.00 C / EXEC SQL
0009.00 C + OPEN C1
0010.00 C / END-EXEC
-- When there is no wrong time to assign the cursor in the value of variables
0011.00 C DOW SQLCOD = 0
0012.00 C / EXEC SQL
0013.00 C + FETCH C1 INTO: VXHEMPID,: VXHNAME,: VXHJOB
0014.00 C / END-EXEC
--- VXHEMPID variables used as a keyword to find the existence of records
0015.00 C / EXEC SQL
0016.00 C + SELECT COUNT (*) INTO: ISEXIST FROM XHZQ1 WHERE XHEMPID1 =: VXHEMPID
-- If there is no record> 0017.00 C / END-EXEC
0018.00 C IF ISEXIST = 0
0019.00 C / EXEC SQL
0020.00 C + INSERT INTO XHZQ1 (XHEMPID1, XHNAME1, XHJOB1)
0021.00 C + VALUES (: VXHEMPID,: VXHNAME,: VXHJOB)
0022.00 C / END-EXEC
0023.00 C ENDIF
-- If the existence of updated records
0024.00 C IF ISEXIST = 1
0025.00 C / EXEC SQL
0026.00 C + UPDATE XHZQ1
0027.00 C + SET XHNAME1 =: VXHNAME,
0028.00 C + XHJOB1 =: VXHJOB
0029.00 C / END-EXEC
0030.00 C ENDIF
-- We will continue to read a record
0031.00 C / EXEC SQL
0032.00 C + FETCH C1 INTO: VXHEMPID,: VXHNAME,: VXHJOB
0033.00 C / END-EXEC
0034.00 C ENDDO
-- Close cursor
0035.00 C / EXEC SQL
0036.00 C + CLOSE C1
0037.00 C / END-EXEC
-- Submitted by the changes
0038.00 C / EXEC SQL
COMMIT 0039.00 C +
0040.00 C / END-EXEC
-- End
0041.00 C RETURN
Xuguopeng back in :2003-10-28 17:15:05 | UPDATE is indeed a problem, I found, he records all changed. . . . . . | ISEXIST in the value of this variable is the keyword XHZQ1 inside certainly is the> ? - Chiao back in :2003-10-28 17:07:20 | You confirm this, the cursor can update, I had to write such a procedure that the cursor is not updated. To study the reasons for not using CHAIN solution. | I think the idea you have not understood it. UPDATE 1, the SQL UPDATE is the use? No WHERE? This is to update all records! Another IF ISEXIST = 1 ISEXIST best into a> 0, will be a wider application, you can not guarantee that the> Xuguopeng back in :2003-10-28 19:54:41 UPDATE resolved to be> Xuguopeng back in :2003-10-28 19:20:51 | Sure enough no-chiao expected. . . . . . . | WHERE CURRENT OF C1 with the update is not> . . . . . Records, the records of the two impenetrable, depressed ~ ~ - Chiao back in :2003-10-28 15:09:57 | First ask a few questions | 1. Look at this very terrible headache for people code, write code to increase attention to the Notes, which is to cultivate the habit. 2. Many of the problems before the proposal put forward their best to make it clear why, we should first draw a flow chart, or use false language to write some processes. Programming logic does not think such mistakes Caiguai. LOCK spent WRKACTJOB or WRKUSRJOB or WRKOBJLCK look at how LOCK living. Analysis is the existence of the order or COMMIT? If you withdraw from the process is abnormal, look JOBLOG Not updated MSG depends> Wildfish back in :2003-10-28 15:17:39 Oh, I suggest using pure rpg, there would not have this problem, and the speed faster, particularly in the large volume of data and in particular the time. Generally speaking, sqlrpgle, we are in the application of statistics, there are too many linkages, but is not recommended. Unless rarely used functions. | Xuguopeng back in :2003-10-28 16:11:51 | 2 is the eldest brother said, but did not find it very simple> I know RPG more convenient, I just want to test, RPG I have done successfully. The process is about: | 1. XHZQ, with the cursor to the data from VXHEMPID put out, VXHNAME, VXHJOB Inside 2. Variables, and then judge the records of the word XHZQ1 whether it exists, and if it exists,> 3. Cycle read and update all records XHZQ1. It's that simple to you to help me look at the Ppoint back in :2003-10-31 13:36:20 | My experience is that using less cursor, trouble! | You of this situation, two can be a SQL statement, you may just want to look cursor usage? 1, UPDATE FILE1 SET FLDX = = VALUEY VALUEX WHERE FLDY 2, INSERT INTO FILE2 VALUES (XXX) WHERE NOT EXISTS (SELECT * FROM FILE1 WHERE FLDY = VALUEY) In addition, SELECT COUNT (*) INTO behind the variables: ISEXIST behind must add an indicator variable, or if the record has been found to be wrong, I encountered before. SQLCODE variables determine the existence of records and the results of the comparative ease of use error, you can try to use. You recommend a book, good, "DB2 Database Design and Programming 400" Xuguopeng back in :2003-10-31 14:10:05 | I understand that, but would like to test the use of the cursor. I have already cited the SQLCOD ah, but I> ISEXIST behind the increase indicator? ? I also wrote back ISEXIST = 0 if what ah? Learn from the valuable experience ~ ~ ~ | Ppoint back in :2003-10-31 17:37:45 | SELECT COUNT (*) INTO: ISEXIST [b]: IND [/ b] | : IND is the indicator variables role as WRITE statements indicator of the same mistakes. SQLCOD = 100 is the most commonly used in the SELECT UPDATE DELETE, or FETCH retrieval has been available to the last line. In SELECT UPDATE DELETE INSERT statement with the best after error handling: SELECT WHEN SQLCOD <0 EXSR SQLERROR WHEN SQLCOD = 100 EXSR SQLNOROW WHEN SQLCOD> 0 OR SQLWN0 <> * BLANKS EXSR SQLWARNING ENDSL Xuguopeng back in :2003-10-31 19:47:59 | ~ ~ Thank you advise you said: IND variables instructions, I still do not quite understand this point, can give an example? | SQLCOD is SQLSTATE = 100 ='02000 'bar, which is not found in the end retrieval of data mean? Also SQLWN0 <> * BLANKS what is the meaning of this? ? SQLWN0? Is global variables? ? Xiaofeizhu back in :2003-11-01 17:16:36 | I understand the purpose of the indicator variables MONMSG similar role, it is wrong if it has no definition, will be entered exception handling, and the definition of the procedures that you will make mistakes in the handling, it is this definition process will continue> Therefore, in the best definition COUNT after, to prevent accidental interruption. | SQLWNO is WARNING NO, not used. I generally use C + WHENEVER SQLERROR GOTO XXXTAG To monitor SQL error, error handling XXXTAG is SQL statements labeling, followed by dealing with the aftermath of mistakes. Xuguopeng back in :2003-11-01 17:21:03 | SQLERROR is that the global variables? Can be directly invoked? ? |
www.obicn.com
|
