tnt400.com - AS/400 Tips And Techniques

Sponsored by news400.com

This page is a discussion on the mentioned topic.
Most of the answers are in their original posted form, including any technical/spelling/grammatical errors.
No guarantees are expressed or implied. :-)
Comments, corrections, concerns about this tip?

Got another AS/400 question? Ask it here


What's New?
See what's new at Tips-N-Tech.

AS/400 Tips-N-Tech
AS/400 tips, techniques, and FAQ. Updated frequently.
CODEPage/400
All the code samples you can eat! RPG, CL, DDS, etc. etc.
AS/400 FAQs
The official news400.com FAQs.






All AS/400 Tip Categories / AS/400 Programming / RPG and subfiles


Question:

Hi,

I've been attempting to program a sub file and use it with RPG/400. I've got most of what needs to be done, complete, but I've been trying something which doesn't seem to work. I have a field called OPT in my sub file record SFLRCD, and when a certain number, 4, is placed in OPT I want to delete the record which is currently displayed. I've got the READC and the DOWEQ loop done, so it will read through all the records until it finds this one and I'm also subtracting one from the RRN.

The error I receive is 5198, the UPDAT or DELET entry is not valid for the file or record type. Yet, in a text book I have it notes that you can delete from a sub file, but doesn't have an examples.


Books on this subject:
Subfile Programming Essentials
AS/400 Expert : Ready-To-Run RPG/400 Techniques
RPG IV By Example
Answer(s):



You can't delete an individual subfile record. You can delete a whole subfile with the SFLDLT keyword. (You use this only if you already have 24 subfiles (!) in use and you want to put another into use) At my company, when a record is deleted, we update the subfile record with the text "*DELETED*" and protect the option field. Another thing you might try is to rebuild the subfile after a delete is performed, and position the subfile to the record that was before the one that was deleted.




Why not load the subfile from the original file as a page at a time subfile? Sure the subfile will start again at the first page, but a good practice is to have a "position to" field at the top as to where to start loading from the file.




Thank you anyone who has responded I realized I was in error late last night, the book actually does not say you can delete a record in a sub file. damn. > Yet, in a text book I have it notes that you > can delete from a sub file, but doesn't have an examples. So I have devised a method of storing the records in a temp file because the program is actually adding records as it runs, then if the user places a 4 in the OPT field then it will clear the sub file delete the record in the temp file and then reload the sub file with the records in the temp file. I was going to do it with a run-time array, but someone said that may use up to much resources.




You can't delete a subfile record. I always use a READC loop, delete my record from the file and "mark" the subfile record as deleted. You could do this by putting a text "** deleted **" in a text field and/or by protecting your option field so the user can't delete the same record twice. Make a F5=Refesh key to reload your subfile.




You can do it. To do a Delete or update the file you are working on has to be set in the file specs as "update" E.G. (FSPECS) FDATAFILE UF A E DISK To do the delete use this sample code:
      *****************************************************************
      * $PFDLT   Primary File record deletion subroutine
      *****************************************************************
     C     $PFDLT        BEGSR
     C     SVKR          CHAIN     RUPDAT                             47
     C     *IN47         IFEQ
*OFF                                        * If rcd exists then delete
it
     C                   DELETE
RUPDAT                                     C                   MOVE
'Y'           DELF
     C                   ENDIF
     C                   ENDSR
after you do a deletion or a change or add. You need to do a READC on the subfile and then reload the subfile so it will reflec the change.




The basic method is that you delete the record from the file from which the subfile is build, and then reload the subfile. I know that you can update a subfile record but I've never tried to delete a record on it, and I've my doubts that it can be done.




It has been a couple of years since did what you want to do, but, all you need is the READC and then check for the correct value in the OPT1 field. if it is correct then - DELET SFLRCD (DELETE for RPG / ILE). this should not pose any problems. if you can fill the sub-file then you can delete from it. you do not need to subtract anything from RRN either. hope this helps.





Other tips in this category:

Click here to see all categories.

Socket Programming And Timeout Issues
Deleting Duplicate Records From A Table
What are data queues and how to use
Retrieving SMTP Name
RPGLE example for Dynamic Screen Manager API
Calling APIs from CL - with examples!
Compare two strings in RPG character by character
How to search all pgms in QCLSRC for a keyword
Retrieve Database File Description (QDBRTVFD) API
How to redirect the output to STDERR from RPG-IV
Using Multiformat Logical To Join 2 Identical File
D-Spec *LIKE DEFN
RPG: Converting Character to Decimal
Example of ILE RPG CGI Program
Handling ILE RPG Numeric Overflow
Help with Subfile Programming in RPG III
Zoned parameter in ILE RPG
What's the best way to do modulus in CL?
RPG Nesting Source Print Utility
More on changing the SIGNON screen
A silly ILE RPG question
Calling Validation List API From ILE RPG
Soft Coding Module Names
RPG Multidimensional Arrays in Action
Build a Page-Equals-Size Lookup Window
Procedures within an ILE RPG program
Break msg from RPG
Source Debugger for batch jobs
RPGLE debugging
Timing out display sessions in DDS
Building Dynamic Stored Procedures
Put Message in System Log
Dynamic RPGSQL
Randomize function for the AS/400
What's the fastest way to do a simple RPG lookup?
First time Data queue application in RPG
Print file overflow in ILE RPG
Mapping Fields To Arrays in ILE RPG
Named inidicators
STRQMQRY: comparision operator '=' isn't correct?!
DSPDTAARA to an outfile - possible?
PCL ESC codes in RPG
Sharing DB files between two AS/400s
Help: AS/400 subfiles
How do you change the signon screen?
Determining Even/Odd Values in queries
Get day of the week in RPG
Convert UPPERCASE to lowercase
RPG IV help using APIs
Help with data area API
Detecing IFS Files from RPG
SQL in a CL program
Calling AS/400 APIs from ILE RPG
CVTDAT command to convert an *MDY to a *LONGJUL
CPYSPLF Automation
Subfile Window background problem
Using IFS APIs w/ ILE RPG
Packed or unpacked fields?
QRYDFN to source and back
What does the "optimize" parm do?
Determining the calling program
Sockets in RPG?
Sorting a user space
OVRDBF and SECURE() keyword in an ILE environment
RPG record locking
RPG Differences: V2R3 to V3R2 upgrade
Getting the relative record number (RRN)
What is the longest parameter usable in RPG?
A C function that returns a string to an RPG pgm
Problems with ZADD *ZEROS
Can you highlight code in SEU?
Reusing deleted records - OK?
Is there an easy way to change edit codes?
Help - Windowed Subfiles
Logical Files and DDS
AS/400 'machine language' - MI Programming
Library lists and performance
How to use ERRSFL
Updating in CL
Record lock wait time
Message subfile problem
Physical File Joins
CL: Copying User Profiles
Commands and PARM
ILE RPG, RPG IV, vs. RPG/400
RPG and subfiles
Multiple subfiles
Field masking for passwords
SFLMODE keyword in an ILE program
Subfile size
Color coding records in a subfile
MSGLINE in windows
Controlling cursor movement on a display file
API returns error! Why?
Put an RPG Program on the Web
Variable length records in RPG
Differences Between RPG400, RPG IV, and ILE RPG


You are at a news400.com site.
Contact Us | Report Bugs | Submit Comments/Suggestions | Read Site Use Agreement | Read Privacy Policy
Copyright © 2000 Duke Communications International.
This site is best viewed with the latest versions of Netscape or Internet Explorer, 800 x 600 resolution (or higher), and at least 256 colors.
Duke Communications   NEWS/400 | 29th Street Press | Business Finance | DominoPro | Selling AS/400 Solutions | SQL Server Magazine | Windows NT Magazine