0% found this document useful (0 votes)
45 views

All About Update Function Module With Real Time Example

Update Fm
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
45 views

All About Update Function Module With Real Time Example

Update Fm
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 32
“Made By Rahul Sharma Sap Abap Assoriate Consultant Update Function Module -is a Fm which as the processing type ‘Update Module’ inthe properties ta, ‘whenever we create a Fm through se37 we need to set the radiobutton update function module, ‘Regular Function Module - Whenever we want to run the Fm inthe same system we always eeste regular or normal FM. Remote Function module - whenever we want tal the Fm from external system we always use RFC M. ‘egwhenever we want to alla normal FM or Regular Fm we have a syntax CALL FUNCTION IFC syntax-allfunetion destination Update Syntax all function IN UPDATE TASK. ep ewe jSoSe nniew IMP Point - During program execution when the system reaches the statement CALL FUNCTION name ‘of the Function Module IN Update Task, The function module snot executed immediately means ‘that it wll not go inside FM immediately as we seein Regular Function Module “Made By Rahul Sharma Sap Abap Assoriate Consultant 10, CALL FUNCETOS '2UPDATE_TARLE' 18 UPCATE TASK hi BXPORFING 12 ‘yBeLN = _vseny, a 16, CORO WORE (REPORT ZOFOATE_ me fe ba eye CT 4 Hi) covers wore. INTHE ABOVE SCREENSHOT PRESS FS AND THE STMT. NOT GONE INSIDE. © REPORT ZUEDATE_ FM. PARAMETERS: P_VBELW TYPE VBELN VA Update Function Module Executes ina Special Work Proces that i called as Update work proces. Made By Rahul Sharma Sap Abap Assoriate Consultant ‘work process each and every taskis assigned to 3 work pracess and one work process can hancle only ‘one work a task 50, whenever we are gong for an FM in an update task at that time this FM wll not run, Update FM will run ona Special Werk Process it means a dedeated work proces wl be assigned toa Function Module ‘thats called an Update Work Process. (0), At wat time this Update work process wil rigger? ie wll be triggered by the COMMIT WORK Statement. ‘once commit work executes then and only wil go inside Update FM ‘The Purpose ofthe Update Function Module eto bundle database changes ina Single LUW (Logiel Unit ‘of Work). it means we can commit al the changes at once or roll them back all at once. Ife want to see the work process we can check through sm50 (igh¥ esky) tis handled by abasis consultant. ‘We can check update process through sm13 ode, Real Time Bxample- when we create Sales Order Or purchase order in background so many tables will ‘get Updated tke vbak, vbap, varkvbrp et. so sap willnot update table 1 a atime , what sap has done it vl est check if all data is correct then they write the logic in update FM to update all table at once. Ifthere is any problem commit work wil not execute, If iis not execute none ofthe table wil get Update. this is how things work if we doe write logic in update Fm, ifyou have 10 tables twill update 2 if some eror comes in 3 tables will ot update it. ts wrong to work like this. in eal world tables are interlinked with each other. if 1 table got updated 9 tables get aed then its data inconsistency. ‘rom performance perspective als is very useful beeause we updating all things at once instead of ‘one by one. if any error comes we can rollback everything together, fine commit al hings together. How To Enable an Update FM Debugging if we run our update FM normally and do commit work t wil go inside but we wll not be able tos It if you put a break point in update FM it willaso net stop at your code there Sap will Execute In Background. But sometimes there may be cases where we need to debug our update FM aso so how toenable that. Lets see how normal Update FM works. ‘Made By Rahul Sharma Sap Abap Assoriate Consultant ‘we put a breakpoint in update FM. 2 _s.eeeesrnenscinnen “Made By Rahul Sharma Sap Abap Assoriate Consultant we see there Is no record in table curently now. ° =]< Gi @e@ oii 5B now lets see Feat FUNCTION °UCDATE TAGLES IN UPDATE TASK a) Sram = pynnN. Je) 34 conmere osx, works ike ok til commit work, but ft wil nt trigger our fm has al It did't stop anywhere lets see table entries in 11 rable, “Made By Rahul Sharma Sap Abap Assoriate Consultant Incerted successfully. 0 let's see how to enable the update FM debugger. o- —_]- wiaeeanmi nann a : oe neport P0PonT= ‘go to settings > change debugger Profile Settings there we can see the update debugting checkbox we should select it. “Made By Rahul Sharma — as inser tenors? ap ord ob at ede stone Cit tae at socket (De te Cath (Fn RE coy seen ets ara as Cee excaston (lower sc Ace | ceasRanewoteAemaen Coe Anna Peet Bases ho, and save it lets see how it will work now, Sap Abap Assoriate Consultant “Made By Rahul Sharma Sap Abap Assoriate Consultant (© Lae stscaeg te sen oot WD rypenere to searcn Se HS ‘we will see message update debugging has been triggered. 0 jee oe) VALUE (EVBELN) TYPE a 5 | ~ _— peecr smote veews, a FROM, ul sme, is inet ie van VENK 170 GDATA(GS_VEAR) u TERE ELM 8 UPYBELE 1s | 1s ooane- agin ~ os_vaak-vBEIN. o) | tetorcnne meoar = os_name cron 2) | ETUPERTE EMout > GS-VaAe Ent, > | tscpoonte anor ~ Gs_yan Som 24, | aiseRr exapue vpOATE FROM Ls_UeDATE. Itstop atFM now. we can check now Is value. a “Made By Rahul Sharma Sap Abap Assoriate Consultant lateryou can remove iif you dont need it. ‘Creation of Update Function Module Requirement store the no. of ales order created fora particular steps: 2). write the lope insertable in update FM. 2) trough VAOI tcode we wil call Update Fn. te intable. |. Create a table with columns Date, Count. © oem Ofee EG Utne Eomonrt Sette oO —J«8 eee san none “Made By Rahul Sharma Sap Abap Assoriate Consultant |WE WILL CREATE 2 DOMAIN FOR COUNT FIELD OR YOU CAN USE PREEXISTING DATA ELEMENT. ‘SAVE IT IN THE LOCAL OBJECT AND ACTIVATE IT, YOU CAN INCREASE THE LENGTH DEPENDING ON THE ‘REQUIREMENT. NOW CREATE DATA ELEMENT. cea cement Gi Got Utes Curomert Stn oC) from . MODIFY from table . now let's write the code inthe FM. 5 “Made By Rahul Sharma Sap Abap Assoriate Consultant 9 | DATA Iva update TYPE 254 order_count, tip | uwa_veoare-tRoar = F expan. ‘when we wll inser the recordin rtable or a particular date our counter wil aways be 1 second time ‘onwards counter wll increase by +1. ig | 7 ceesteemes ty cor tras asa agi pera now fist time fora particular date it wil insert the record our counter wil be 1, when it inserts the record the second time fora particular date our counter will be Increased by 1, which wil be 2 16 “Made By Rahul Sharma Sap Abap Assoriate Consultant % “nay ins fen erate sd, 22 am epee sone = coe ‘Now we willl ths Fm while creating the sales order. _as we know we can create sales order through va01 t-code. CC )«geeeicnki® v “Made By Rahul Sharma Sap Abap Assoriate Consultant H Create Sales Orders according tothe data avallable atthe header level (VBAK) and atthe Item level (ea), ‘Whenever we clickon the save button our sales order will be created, now when we go for save atthe ‘ume of save we need to update our table also which s asd_order_count. For that we have written our logic in our update FM. ‘Whenever we want to add our own functionality to Sap Functionality we need to take help of ‘enhancement and modification. ‘we need to add our fm to sap logic to update stable. ‘we will use USER_EXIT here. they are only available in the SD module. INCLUDE MVA5AFZZ is one ofthe most important include programs where USER_EXIT for sales orders Is present. let's go to MVaSAFZZ and check which user_exits fulfill our requirement. “Made By Rahul Sharma Sap Abap Assoriate Consultant \serexit_save_document flfiling our requirement sap provided the document also, ‘as we can see this userextis called before commit (clearly writen in ine no. 260 provided by sap). ‘Sap also glves the documentation of what we need todo a sample code, update fm. Let's puta break: point inthe user exit and save our a0 sales order let's check how the system i 9 “Made By Rahul Sharma Sap Abap Assoriate Consultant ey a i fecooe oe thes e soomea® io sed, SEEUSUEEURDEDG I {stops at this break point. 20 “Made By Rahul Sharma Sap Abap Assoriate Consultant SELES 1) Paes | © Cwadwert Bam Eeotoveoeumert Sinetron] AT Sho |/ eS SepoaeT ET NNSNNN NNN N NNN oe aa on In debugging at vbak table we are getting data, Sales Doc. No, and Document Dat, ‘we are only seeing the number the data not saved In tables yet because we haven't performed ‘commit yet, lets check vbak, vbap table. ‘Suppose if we write our logic in wserexit_save_document ike modify stmt. ‘the data willsave in table but your vbak, vbap table is not updated with ‘new sales order there will be data inconsistency, lke when you are going, t0:do.commit and some error occurs in our sale order the data will be Inconsistent. that why we wil write the logic In our update Fm after ‘commiting then and only it wil rigger [As we know we can directly write code in user_ext because it is a modification include provided by a “Made By Rahul Sharma Sap Abap Assoriate Consultant ‘sap by using acess key provided by basis team, if we dont have any acess key we can use implct ‘enhancement to write logic in our user_exit {goto edt> enhancement Operations > show implicit Enhancement. pom [ae] ea are ‘testes cise fe wih be changed 2 eee a “Made By Rahul Sharma Sap Abap Assoriate Consultant ‘ight click-> click on enhancement operations then create implementation Cl Ermine a Evarer reer one, soe oe £ & 288 i é HH ee RIASEEEEEES t 3 -ygegeeasaas i 3 ick on create an implementation. Stent mire ERAT) es {lve the description and enhancement name and save It inthe local abject. ‘as we can soe implicit enhancement was inserted succesfully. a “Made By Rahul Sharma Sap Abap Assoriate Consultant ENENCEMENT 1 QUPDATE COUNT. “inactive ve: perdat = vaRK-enoar Date was coming in vbak structure erdatfeld shown In debugging. put breakpoint inf ets see how system behaving. 2 “Made By Rahul Sharma Sap Abap Assoriate Consultant joseninnior os 25 “Made By Rahul Sharma Sap Abap Assoriate Consultant SERGE Sawsm © Dumopue Sina slomon amine eu ‘ets enable update debueging.. eS a ee gee) oe ee Co SRG S Paws © Qader “aoes Ecaten boee or 6 a ———— |For) fom eiemsuepocwe NM nfo) _——————————— {lek on Update debugging and Save I. ‘twill let you get through all updated FM so keep pressing {7 and stop at our FM 26 “Made By Rahul Sharma Sap Abap Assoriate Consultant 15 | seuecr srwote zcoune rot asd order_count i TNO data (lv count) MHERE erdat £9 dp_erdat. is syne 2p 1 ‘count wy | ease tf | aves = 1 20 | exore 22, | Awa_update-zeount = 1¥ count. ‘now let's check our stable, 07 eas renew Biplane Relat noe t Find Gham ‘now let's change the date through debugging and checking the data. \Note:-never do this in realtime. ” “Made By Rahul Sharma Sap Abap Assoriate Consultant © Goecey eet Ga Sete Ue) Ewan Sr eb ° *) eens socmat pante was cancees”sesived ten sets NE (tse dtucoen ts ben eared se this message update debugging again trigger. ‘we can check the dump in st22 ene snoeinn ow 2

You might also like