Error in AS/400 code?

2465 pts.
Tags:
AS/400
SQLRPGLE
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?

Answer Wiki

Thanks. We'll let you know when a new response is added.

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.

Discuss This Question: 12  Replies

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • deepu9321
    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,870 pointsBadges:
    report
  • philpl1jb
    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
    50,465 pointsBadges:
    report
  • TomLiotta
    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
    125,585 pointsBadges:
    report
  • Sureyz
    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.
    2,465 pointsBadges:
    report
  • philpl1jb
    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
    50,465 pointsBadges:
    report
  • Splat
    Can you post your SQL statements (I'm assuming you've modified what you previously posted)?
    7,425 pointsBadges:
    report
  • TomLiotta
    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
    125,585 pointsBadges:
    report
  • Sureyz
    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. ...
    2,465 pointsBadges:
    report
  • Splat
    See Tom's answer just above - he's got the right of it (as is usual).
    7,425 pointsBadges:
    report
  • TomLiotta
    @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
    125,585 pointsBadges:
    report
  • TomLiotta
    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
    125,585 pointsBadges:
    report
  • Sureyz
    Yes Tom.. I got it .. thanks and thanks to all.. Surey.
    2,465 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following