DSPF programming

pts.
Tags:
AS/400 Display File
Display File
DSPF
RPG/400
Hi Please explain... When i open a screen in update mode how does the value get displayed in the screen and when updated it gets updated in the file.what is the general coding logic used in this case.

Answer Wiki

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

Hi,

Basic logic is :-

read/chain your database file
display your screen
read from your screen
update your database file

e.g.

CHAIN DATABASE
EXFMT SCREEN
UPDATE DATABASE

Regards,

Martin Gilbert.

Discuss This Question: 5  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
  • Thanks for ur response.I have a small clarification.If all fields on the screen is from 1 file chain and then exfmt will work.What if the screen has fields form more than 1 file.
    0 pointsBadges:
    report
  • Gilly400
    Copied from other question.... Hi, As long as all the relevant datafiles have been read or chained, then the fields are filled and will be displayed on the record when you use exfmt. If more than one file needs to be updated, then you'll also need extra updates in your program. This can get tricky when you have the same field names in several files (possibly with different data in each file). Hopefully you won't get yourself into that sort of situation. Regards, Martin Gilbert.
    23,730 pointsBadges:
    report
  • Sloopy
    This is such a basic question that I ought to urge your employers to send you on a programming course; they shouldn't expect to just throw you into RPG programming without some formal training. Regarding Martin's chain-exfmt-update flow, I have to point out (as Martin would, but I am probably a lot less busy than him right now) - you must not hold record locks on an update file across an exfmt operation. What that means is this: When you CHAIN to a file opened for update, the system locks that record so that no-one else can update it until your program has either done an UPDATE (or DELETE) operation, or has released the record using UNLOCK. This is potentially very dangerous if your program waits until a user has finished making some coffee before dealing with the screen. You have a record lock that can last for ages, and other users' programs may start waiting for the locked record. Even your own program could hang up, if when control returns from the screen it starts to do validations while the lock is still being held. In practice, what we do is to use the 'no lock' option on the CHAIN : keylistname CHAIN (N) recordname Now the record is read unlocked. Other programs can get at it. If you have a named data structure in your D-specs, externally defined to the file, the data from the CHAIN will be in that structure. You can now copy that structure to another, and it's that copy structure you use to put data on the screen.
    D formatMM      E DS                  ExtName(MFMAST)                 
    D formatD#      E DS                  ExtName(MFMAST) Prefix( D# : 2 )
    
    Now the chain (including an example of mapping a date field from a 'date' data type to a ddmmyy format for display) :
    C     p_RecID       Chain (N) MM                       
                                                           
     * Existing record - map to the screen :               
                                                           
    C                   If        %Found                   
    C                   Eval      formatD#    = formatMM   
    C                   Monitor                            
    C                   Move      D#MIND        WorkISOdate
    C     *DMY          Move      WorkISOdate   M#MIND     
    C                   On-Error                           
    C                   Clear                   M#MIND     
    C                   EndMon                             
    C                   EndIf                              
    
    The D#xxxx fields are the fields actually shown on the screen. The date shown on the screen is the one in field M#MIND. Note that we are NOT locking the record. After the EXFMT, we do some validation of the data from the screen. If it's all OK, AND data has actually been changed, THEN we update the record. (Note that during the validation, we converted the mapped date from the screen back into the date field D#MIND) :
    C     D#MMID        Chain (E) MM                             
                                                                 
    C                   If        %Found and formatMM <> formatD#
                                                                 
    C                   Time                    CurrStampISO     
    C                   Move      CurrISOdate   D#UDAT           
    C                   Move      CurrISOtime   D#UTIM           
    C                   Move      PGUSER        D#UUSR           
    C                   Move      PGNAME        D#UPGM           
                                                                 
    C                   Eval      formatMM    = formatD#         
    C                   Update (E)MM                             
                                        
    C                   Else            
                                        
    C                   Unlock (E)MFMAST
                                        
    C                   EndIf
    
    Now, this method prevents a lock being kept for more than a fraction of a second. What it does NOT do is prevent your program changing a record back to its original value if another program has changed it since you did the original CHAIN. To prevent that happening, you need to compare the timestamps in the record (so long as your files have been designed to include 'last changed' information!) - if they are the same value but the data in the record is different to that from the screen, then no-one else has changed the data except you. If they are different, then someone else changed the data since you did the first, unlocked, CHAIN. The code to do timestamp checking goes BEFORE the TIME operation in the code sample above. The use of externally-described data structures to hold data from records is extremely useful; and the use of the PREFIX keyword means that if you do have different files with the same field names, you can make the names different in your program by prefixing the field names with letters which identify the actual file the data came from. Regards, Sloopy
    2,195 pointsBadges:
    report
  • Hey for a guy with just few months of programing experience in rpg these are some of the questions that may pop up.If possible can you refer some materials with sample codes for display file programing
    0 pointsBadges:
    report
  • Gilly400
    Another excellent explanation from Sloopy. As you guessed - I don't have enough time to go into things so deeply. Regards, Martin Gilbert.
    23,730 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