SlideShare a Scribd company logo
1 of 17
Algorithm #3

CHANGE and ADD transactions;
Several transactions per master
             record

          Prepared by Perla P. Cosme   1
Recall Algorithm #1
Get_Next_Master
Get_Next_Trans
While NOT (master_key==sentinel AND trans_key==sentinel)
  if (master_key < trans_key)
      { output master record to new master file
          Get_Next_master
       }
       else if (master_key == trans_key)
                { make a change in the master record
                    output master record in new master file
                    Get_Next_Trans
                    Get_Next_Master
                  }
             else
                 { print “no matching record in the master file”
                    Get_Next_Trans
                  }
                             Prepared by Perla P. Cosme                         2
Recall Algorithm #2
Get_Next_Master
Get_Next_Trans
While NOT (master_key==sentinel AND trans_key==sentinel)
  if (master_key < trans_key)
      { output master record to new master file
          Get_Next_master
       }
       else if (master_key == trans_key)
                { make a change in the master record
                    // output master record in new master file
                    Get_Next_Trans
                    //Get_Next_Master
                  }
             else
                 { print “no matching record in the master file”
                    Get_Next_Trans
                  }
                             Prepared by Perla P. Cosme                         3
Think about this ….
If Algorithm #3 is to include ADD transaction on
   the existing CHANGE transaction in the
   Algorithm #2, then when are we allowed to
   ADD or create a record?
b.Master key < transaction key
c. Master key = transaction key
d.Master key > transaction key


                   Prepared by Perla P. Cosme      4
Think about this ….
If Algorithm #3 is to include ADD transaction on
   the existing CHANGE transaction in Algorithm
   #2, then when are we allowed to ADD or
   create a record?
b.Master key < transaction key
c. Master key = transaction key
d.Master key > transaction key

            Why (c)? Justify.

                       Prepared by Perla P. Cosme   5
Justification why the Answer to the
  previous Question cannot be (a)
Let us prove by citing an example:
      MF: 6      7     8

      TF    8
            A
Note: if master key (7) < transaction key (8), and the
  transaction is ADD, you might add a record whose
  primary key is the same as the one you are about to
  create/add.
                     Prepared by Perla P. Cosme          6
Justification why the Answer to the
  previous Question cannot be (b)
Let us show one typical example:
      MF: 3     6     11

      TF:    3     3
             C     A
Note: if master key (3) is equal to transaction key (3),
  you will be creating duplicate records in the master
  file. (The master file should never have duplicates.)

                       Prepared by Perla P. Cosme          7
Question: How should Algorithm #2 look like
 now to reflect the error in adding a record
 when master key = transaction key?




                  Prepared by Perla P. Cosme   8
Get_Next_Master
Get_Next_Trans
While NOT (master_key==sentinel AND trans_key==sentinel)
  if (master_key < trans_key)
      {     output master record to new master file
            Get_Next_master
       }
       else if (master_key == trans_key)
                {Case update_code
                        ‘A’: print “duplicate record”
                             Get_Next_Trans
                        ‘C’: make a change in the master record
                               Get_Next_Trans
                         Default: print “invalid update code”
                               Get_Next_Trans
                }
             else /* no matching record in the master file */
                 { print “no matching record in the master file”
                    Get_Next_Trans
                  }

                                   Prepared by Perla P. Cosme      9
Justification why the Answer to the
       previous Question is (c)
• It is in the third case (i.e., master key >
  transaction key) where we are allowed to add
  a new record. Hence, it will be in such section
  of the algorithm where we are going to
  concentrate making the modifications to
  Algorithm #2 to fit to our new requirements –
  CHANGE and ADD transactions with multiple
  transactions per master record.

                   Prepared by Perla P. Cosme   10
This is the Algorithm
Get_Next_Master                                                          #3 that explicitly
Get_Next_Trans                                                          includes the error-
While NOT (master_key==sentinel AND trans_key==sentinel)                 handling routine
  if (master_key < trans_key)                                           when master key is
      {     output master record to new master file                    equal to transaction
            Get_Next_master                                                      key
       }
       else if (master_key == trans_key)
                {Case update_code
                       ‘A’: print “duplicate record”
                            Get_Next_Trans
                       ‘C’: make a change in the master record
                              Get_Next_Trans
                        Default: print “invalid update code”
                              Get_Next_Trans
                }
             else
                 {     // no matching record in the master file
                       print “no matching record in the master file”
                       Get_Next_Trans
                  }
                                    Prepared by Perla P. Cosme                          11
Get_Next_Master
Get_Next_Trans
While NOT (master_key==sentinel AND trans_key==sentinel)
  if (master_key < trans_key)
      {     output master record to new master file
            Get_Next_master
       }
       else if (master_key == trans_key)
                {Case update_code
                       ‘A’: print “duplicate record”
                                                                       These two (2) lines
                            Get_Next_Trans
                                                                           will still be
                       ‘C’: make a change in the master record
                                                                       maintained but only
                              Get_Next_Trans
                                                                        when the update
                        Default: print “invalid update code”
                                                                           code is C.
                              Get_Next_Trans
                }
             else
                 {     // no matching record in the master file
                       print “no matching record in the master file”
                       Get_Next_Trans
                  }
                                    Prepared by Perla P. Cosme                         12
Get_Next_Master
Get_Next_Trans
While NOT (master_key==sentinel AND trans_key==sentinel)
  if (master_key < trans_key)
      {     output master record to new master file
            Get_Next_master
       }
       else if (master_key == trans_key)
                {Case update_code
                       ‘A’: print “duplicate record”
                            Get_Next_Trans
                                                                   We shall introduce a
                       ‘C’: make a change in the master record
                                                                function called NOMATCH
                              Get_Next_Trans
                                                                    to handle the ADD
                        Default: print “invalid update code”
                                                                   transaction and the
                              Get_Next_Trans
                                                                 succeeding ADD and/or
                }
                                                                 CHANGE transactions on
             else
                                                                 the same newly created
                 {     // no matching record in the master file
                                                                          record.
                       NOMATCH
                  }

                                 Prepared by Perla P. Cosme                       13
Function NOMATCH
Case update_code
 ‘A’: Build new record from transaction record
       new_key = trans_key
       Get_Next_Trans
       while (trans_key != sentinel AND trans_key == new_key)
            Case update_code
               ‘A’: print “duplicate add”                        These are the
                                                                lines that were
               ‘C’: make change in the newly created record
                                                                 retained from
                Default: print “invalid update code”             Algorithm #2.
            Get_Next_Trans
       output new record to new master file
 ‘C’: print “no matching master record for transaction key”
      Get_Next_Trans
  Default : print “invalid update code”
       Get_Next_Trans
                              Prepared by Perla P. Cosme                    14
Let’s simulate the SFO using
            Algorithm #3

We shall use the same example as what we
 presented previously.




                 Prepared by Perla P. Cosme   15
The Third Algorithm
        CHANGE and ADD transactions;
     several transactions per master record



MF     3        6               10            11


TF 3        3        11            11         11   11   18
   C        A        A             C          C    A    A


                 Prepared by Perla P. Cosme                  16
????
     Questions?
     Comments?
Suggestions?  and 
     Open Forum


       Prepared by Perla P. Cosme          17

More Related Content

Viewers also liked (16)

 
3. Scott Eblen
3. Scott Eblen3. Scott Eblen
3. Scott Eblen
 
Diacritice în Linux
Diacritice în LinuxDiacritice în Linux
Diacritice în Linux
 
هـذا هـو مـحـمـد
هـذا هـو مـحـمـدهـذا هـو مـحـمـد
هـذا هـو مـحـمـد
 
1356234 634668914482537500
1356234 6346689144825375001356234 634668914482537500
1356234 634668914482537500
 
نصيحـة
نصيحـةنصيحـة
نصيحـة
 
عـثـمـان إبـن عـفـان
عـثـمـان إبـن عـفـانعـثـمـان إبـن عـفـان
عـثـمـان إبـن عـفـان
 
المبشرون بالجنــة
المبشرون بالجنــةالمبشرون بالجنــة
المبشرون بالجنــة
 
Algorithm 1
Algorithm  1Algorithm  1
Algorithm 1
 
1356209 634668906085350000
1356209 6346689060853500001356209 634668906085350000
1356209 634668906085350000
 
عـثـمـان إبـن عـفـان
عـثـمـان إبـن عـفـانعـثـمـان إبـن عـفـان
عـثـمـان إبـن عـفـان
 
الـفـاروق عـمـر
الـفـاروق عـمـرالـفـاروق عـمـر
الـفـاروق عـمـر
 
الـسـيـرة النبـويـة
الـسـيـرة النبـويـة الـسـيـرة النبـويـة
الـسـيـرة النبـويـة
 
 
من أخلاق النبي المصطفى
من أخلاق النبي المصطفىمن أخلاق النبي المصطفى
من أخلاق النبي المصطفى
 
الـكـلـمـة الـطـيـبـة
الـكـلـمـة الـطـيـبـةالـكـلـمـة الـطـيـبـة
الـكـلـمـة الـطـيـبـة
 

Recently uploaded

CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
giselly40
 

Recently uploaded (20)

Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 

Algorithm 3

  • 1. Algorithm #3 CHANGE and ADD transactions; Several transactions per master record Prepared by Perla P. Cosme 1
  • 2. Recall Algorithm #1 Get_Next_Master Get_Next_Trans While NOT (master_key==sentinel AND trans_key==sentinel) if (master_key < trans_key) { output master record to new master file Get_Next_master } else if (master_key == trans_key) { make a change in the master record output master record in new master file Get_Next_Trans Get_Next_Master } else { print “no matching record in the master file” Get_Next_Trans } Prepared by Perla P. Cosme 2
  • 3. Recall Algorithm #2 Get_Next_Master Get_Next_Trans While NOT (master_key==sentinel AND trans_key==sentinel) if (master_key < trans_key) { output master record to new master file Get_Next_master } else if (master_key == trans_key) { make a change in the master record // output master record in new master file Get_Next_Trans //Get_Next_Master } else { print “no matching record in the master file” Get_Next_Trans } Prepared by Perla P. Cosme 3
  • 4. Think about this …. If Algorithm #3 is to include ADD transaction on the existing CHANGE transaction in the Algorithm #2, then when are we allowed to ADD or create a record? b.Master key < transaction key c. Master key = transaction key d.Master key > transaction key Prepared by Perla P. Cosme 4
  • 5. Think about this …. If Algorithm #3 is to include ADD transaction on the existing CHANGE transaction in Algorithm #2, then when are we allowed to ADD or create a record? b.Master key < transaction key c. Master key = transaction key d.Master key > transaction key Why (c)? Justify. Prepared by Perla P. Cosme 5
  • 6. Justification why the Answer to the previous Question cannot be (a) Let us prove by citing an example: MF: 6 7 8 TF 8 A Note: if master key (7) < transaction key (8), and the transaction is ADD, you might add a record whose primary key is the same as the one you are about to create/add. Prepared by Perla P. Cosme 6
  • 7. Justification why the Answer to the previous Question cannot be (b) Let us show one typical example: MF: 3 6 11 TF: 3 3 C A Note: if master key (3) is equal to transaction key (3), you will be creating duplicate records in the master file. (The master file should never have duplicates.) Prepared by Perla P. Cosme 7
  • 8. Question: How should Algorithm #2 look like now to reflect the error in adding a record when master key = transaction key? Prepared by Perla P. Cosme 8
  • 9. Get_Next_Master Get_Next_Trans While NOT (master_key==sentinel AND trans_key==sentinel) if (master_key < trans_key) { output master record to new master file Get_Next_master } else if (master_key == trans_key) {Case update_code ‘A’: print “duplicate record” Get_Next_Trans ‘C’: make a change in the master record Get_Next_Trans Default: print “invalid update code” Get_Next_Trans } else /* no matching record in the master file */ { print “no matching record in the master file” Get_Next_Trans } Prepared by Perla P. Cosme 9
  • 10. Justification why the Answer to the previous Question is (c) • It is in the third case (i.e., master key > transaction key) where we are allowed to add a new record. Hence, it will be in such section of the algorithm where we are going to concentrate making the modifications to Algorithm #2 to fit to our new requirements – CHANGE and ADD transactions with multiple transactions per master record. Prepared by Perla P. Cosme 10
  • 11. This is the Algorithm Get_Next_Master #3 that explicitly Get_Next_Trans includes the error- While NOT (master_key==sentinel AND trans_key==sentinel) handling routine if (master_key < trans_key) when master key is { output master record to new master file equal to transaction Get_Next_master key } else if (master_key == trans_key) {Case update_code ‘A’: print “duplicate record” Get_Next_Trans ‘C’: make a change in the master record Get_Next_Trans Default: print “invalid update code” Get_Next_Trans } else { // no matching record in the master file print “no matching record in the master file” Get_Next_Trans } Prepared by Perla P. Cosme 11
  • 12. Get_Next_Master Get_Next_Trans While NOT (master_key==sentinel AND trans_key==sentinel) if (master_key < trans_key) { output master record to new master file Get_Next_master } else if (master_key == trans_key) {Case update_code ‘A’: print “duplicate record” These two (2) lines Get_Next_Trans will still be ‘C’: make a change in the master record maintained but only Get_Next_Trans when the update Default: print “invalid update code” code is C. Get_Next_Trans } else { // no matching record in the master file print “no matching record in the master file” Get_Next_Trans } Prepared by Perla P. Cosme 12
  • 13. Get_Next_Master Get_Next_Trans While NOT (master_key==sentinel AND trans_key==sentinel) if (master_key < trans_key) { output master record to new master file Get_Next_master } else if (master_key == trans_key) {Case update_code ‘A’: print “duplicate record” Get_Next_Trans We shall introduce a ‘C’: make a change in the master record function called NOMATCH Get_Next_Trans to handle the ADD Default: print “invalid update code” transaction and the Get_Next_Trans succeeding ADD and/or } CHANGE transactions on else the same newly created { // no matching record in the master file record. NOMATCH } Prepared by Perla P. Cosme 13
  • 14. Function NOMATCH Case update_code ‘A’: Build new record from transaction record new_key = trans_key Get_Next_Trans while (trans_key != sentinel AND trans_key == new_key) Case update_code ‘A’: print “duplicate add” These are the lines that were ‘C’: make change in the newly created record retained from Default: print “invalid update code” Algorithm #2. Get_Next_Trans output new record to new master file ‘C’: print “no matching master record for transaction key” Get_Next_Trans Default : print “invalid update code” Get_Next_Trans Prepared by Perla P. Cosme 14
  • 15. Let’s simulate the SFO using Algorithm #3 We shall use the same example as what we presented previously. Prepared by Perla P. Cosme 15
  • 16. The Third Algorithm CHANGE and ADD transactions; several transactions per master record MF 3 6 10 11 TF 3 3 11 11 11 11 18 C A A C C A A Prepared by Perla P. Cosme 16
  • 17. ???? Questions? Comments? Suggestions?  and  Open Forum Prepared by Perla P. Cosme 17