Update and write sample RPGLE program

90 pts.
Tags:
RPGLE
Hi all,
I have two physical files pf1 and pf2 with three field student_id,name,marks. I want to Move the records from PF1 to PF2. If the Student_ID already exists in PF2 just update the record else write a new record in PF2.where student_id is key field in both physical file. Could anyone provide a sample RPGLE code for reference?
1

Answer Wiki

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

If you are looking for help with homework we are happy to help. Provided you show us what you have done. It takes time to learn and do not forget to use debug. It can help you trace what is really going on, line by line of code.

Discuss This Question: 13  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.
  • ToddN2000
    Post your code and let us take a look. Show us you put some effort into it. This is very similar to a question that has already been asked and answered.
    127,920 pointsBadges:
    report
  • rajeshkmr571
    *LOVAL             SETLL    PF1
                              READ     PF1
                              DOW      NOT %EOF(PF1)
                              EVAL      PF2(STUDENT ID FIELD) = PF1(STUDENT ID IELD)
     KEY(ST_ ID)    CHAIN    PF2
                              IF            NOT %FOUND(PF2)
                              WRITE    PF2(REC FORMAT NAME)
                              ELSE 
                              UPDATE PF2(REC FORMAT NAME)
                              ENDIF
                              READ      PF1
                              ENDDO

    THIS IS THE CODE YOU CAN MODIFY AS YOU LIKE.
     
    220 pointsBadges:
    report
  • Splat
    What do you think is going to happen to the data in PF2(STUDENT ID FIELD) when your chain is successful?
    12,845 pointsBadges:
    report
  • ToddN2000
    The code above is close. But maybe it was meant to point you in a direction rather than doing it for you. Try it and report back if you are still having an issue.
    127,920 pointsBadges:
    report
  • nabamita
    HERE IS MY CODE WHICH RUN PERFECTLY


    h option(*nodebugio)                                        
     femp_pf    uf a e           k disk                          
     femp_pf1   if   e           k disk                          
     c     *start        setll     emp_pf                        
     c     *start        setll     emp_pf1                       
     C                   dou       %eof(emp_pf)                  
     c                   read      emp_pf                        
     C                   read      emp_pf1                       
                         
     c                   if        studentid=studentid1          
     c                   eval      marks=marks1                  
     c                   eval      name=name1                    
     c                   update    emp_pfr                       
     c                   else                                    
     c                   eval      studentid=studentid1          
     c                   eval      name=name1                    
     c                   eval      marks=marks1                  
     c                   write     emp_pfr  
     c                   endif                   
     c                   enddo                   
     c                   eval      *inlr=*on         



    BUT WHAT  TO DO IF AFTER UPDATE ANY RECORD BECOME DUPLICATE ,I WANT TO PREVENT DUPLICATE ENTRY. I HAVE USED CHAIN ON KEY FIELD BUT  THEN PROGRAM FALL UNDER INFINITE LOOP .     
    90 pointsBadges:
    report
  • CharlieBrowne

    Obviously it does not run perfectly if it goes into an infinite loop.

    The issue is you are in a DO loop until EOF. But within you loop, you are writing to the file you are checking for EOF. Put your EOF check on the other file that is not getting maintained.

    62,385 pointsBadges:
    report
  • philpl1jb

    This may work with your test data but .. it will only really work where both files have exactly matching records in emp_pf and emp_pf1

    Reading from both each time means that once one gets off they are unlikely to ever match again.   The second file should be accessed using the studentID from the first file .. perhaps like this ..

    Assuming that the key is studentid (studentid1 in emppf1)

    c     *start        setll     emp_pf                        

    C                   dou       %eof(emp_pf)                  

     c                   read      emp_pf                        
     C   studentid chain     emp_pf1                       
                         
     c                   if        %found( emp_pf1)
    ...


    54,090 pointsBadges:
    report
  • NAN4AS400
    Yes 1st get the a record from PF1 and do CHAIN in PF2. If you found the record then u will obviously UPDATE the record. If NOT FOUND then u need to write a new record in PF2. 

    On doing this way You wont get duplicate record created in PF2.  
    105 pointsBadges:
    report
  • philpl1jb
    Historically, or Hysterically the READ - READ logic was used with sequential sources like two card readers. The matching and advancing process was much more complicated then you want to know.
    54,090 pointsBadges:
    report
  • nabamita
    Thanks for all replies. Problem is solved Thanks a lot once again.
    90 pointsBadges:
    report
  • BigKat
    and I don't mind HELPING with homework-type questions, but the student should have tried first, and then posted what they have done and where they are still having difficulty.  That way they can LEARN rather than just getting the answer for class.
    9,410 pointsBadges:
    report
  • joequaye55
    Please help me solve this question.
    1.a scoreboard displays the score of a volleyball match between two teams.the content of memory location 1805h is displayed on the first field and 1806h is displayed on the second field.write a program for an 8085 micro processor to update the scoreboard assuming two keypads control the content of register B and register C independently.
    10 pointsBadges:
    report
  • ToddN2000
    @joequaye55: Sounds like a class assignment. Post you code so far and any errors and we will help straighten it out for you.
    127,920 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.

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

Following

Share this item with your network: