1,485 pts.
 AS400
Fstdt      if   e             disk                                      Dnam              s             10a                                     Ddept             s              3a                                     C/exec sql                                                              C+ SELECT NAME, BRANCH INTO :nam, :dept FROM stdt WHERE STDID < 10      C+                                                                      C/end-exec                                                              C                   seton                                            lr Hai all ..!  I have this code .. But i'm not getting the output.. how can i get the result..? orelse what is the error here ..?

Software/Hardware used:
ASKED: November 18, 2011  1:35 PM
UPDATED: March 6, 2012  6:26 PM

Answer Wiki:
I guess, You should be having more than one record with Condition STDID < 10. In this case, You should be building Cursor and Retrieve the Data from Cursor. Sample Code will be like below example. <pre> D SqlStmt S 100A /Free SqlStmt = 'SELECT NAME, BRANCH FROM stdt WHERE STDID < 10' ; Exec Sql Prepare DYNSQL From :SqlStmt ; Exec Sql Declare Cursor1 CURSOR for DYNSQL ; Exec Sql Open Cursor1 ; Exec Sql Fetch From Cursor1 into :nam, :dept ; Dow SqlCod >= 0 ; Select ; When SqlCod = 100 ; When SqlCod = 0 ; Other ; EndSl ; Exec Sql Fetch From Cursor1 into :nam, :dept ; EndDo ; /End-Free </pre> SqlCod - 0 means Record Read successfully. SqlCod - 100 means End Of File have reached. Code has been written in Free Format RPGLE, You can use the similar code in Fixed Format RPGLE. Pradeep.
Last Wiki Answer Submitted:  November 18, 2011  1:48 pm  by  deepu9321   3,370 pts.
All Answer Wiki Contributors:  deepu9321   3,370 pts.
To see all answers submitted to the Answer Wiki: View Answer History.


Discuss This Question:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _


 

A Small Correction to the Code,

Select ;                     
     When SqlCod = 100 ;          
               Leave ; 
     When SqlCod = 0 ;
               //Perform the Required Operation
     Other ;                      
EndSl ;

If you still not getting the Result, You can check for the SqlCod, That will help you in Resolving this problem.

Pradeep.
 3,370 pts.

 

Output ..Your program doesn’t have any output commands.
Sorry but I can’t resist:this paraphrase: “we don ned no stinkin output”

Fstdt if e disk
Dnam s 10a
Ddept s 3a
C/exec sql
C+ SELECT NAME, BRANCH INTO :nam, :dept FROM stdt WHERE STDID < 10
C+
C/end-exec
C NAM DSPLY
C DEPT DSPLY
C seton lr

Of course as discussed in another response.this will fail if more than one record qualify. If you call this program it will now show you the results.
Phil

 44,150 pts.

 

Also, since there is no program I/O for the STDT file, the F-spec for it can be deleted.

But Phil is right — the program doesn’t have any output defined. If you don’t code output, don’t expect output. So far, all that happens is some set of rows is selected — as coded, it needs to be a single-row set. Now the program needs to do something with those rows.

Tom

 107,995 pts.

 

Thanks Pradeep .

I’m having more than one record that STDID < 10.
But the Output Shows only one record….
Isn’t possible read all those records which is STDID < 10.

Surey.

 1,485 pts.

 

The fetch will get the next row from the cursor
So putting the fetch in a loop will allow you to get and process each step
Pradeep’s code with his admendments should read and process all rows except if there is an error.

NOTE: This SQL requires a cursor but it doesn’t need to be Dynamic. Dynamic is needed when the actuall SQL command is created as a string and loaded programmatically.
Phil

 44,150 pts.

 

Can you post your SQL statements (I’m assuming you’ve modified what you previously posted)?

 5,670 pts.

 

But the Output Shows only one record….

If you need to retrieve more than a single row at a time, use a multiple-row FETCH to fetch a block at a time into an array. Otherwise, you will need to loop through individual rows. If you loop and you also want to hold the values from each row, then you’ll have to store the values in an array (or some kind of repeating structure) after you fetch each row.

Tom

 107,995 pts.

 

Hi Splat..

Fstdt if e disk
Dnam s 10a
Ddept s 3a
C/exec sql
C+ SELECT NAME, BRANCH INTO :nam, :dept FROM stdt WHERE STDID < 10
C+
C/end-exec
C nam dsply
C dept dsply
C seton lr

this is my code. …

 1,485 pts.

 

See Tom’s answer just above – he’s got the right of it (as is usual).

 5,670 pts.

 

@Sureyz:

Why do you have the F-spec for STDT in the program? Your program doesn’t do anything with it, so the line should be removed. All it does is add overhead.

Tom

 107,995 pts.

 

And note that the SQL might be changed to { WHERE STDID = :i } and put inside a { for i = 1 to 9 } loop. With i defined as a basic integer, the dsply statements could display values as the loop progressed.

(But the F-spec still should be deleted.)

Tom

 107,995 pts.

 

Yes Tom..
I got it .. thanks

and thanks to all..

Surey.

 1,485 pts.