Академический Документы
Профессиональный Документы
Культура Документы
ABAPFORALLENTRIESWhyyouneedtoincludeKEYfields|ABAPHelp
ZEVOLVING
> Home > Performance FOR ALL ENTRIES Why you need to include KEY fields
10,226 | 3
ABAPFORALLENTRIESishandy,butwouldcreatelotofdatainconsistenciesifyoudontuseitproperly.
Basic
Forsimplestuseof FORALLENTRIES ,youwouldwriteyourSELECTqueryusingtheFORALLENTIRESanduseoneormorefieldsfromthetableinto
WHEREcondition.
IFt_idsISNOTINITIAL.
SELECT*
INTOTABLEt_t100_all
FROMt100
FORALLENTRIESINt_ids
WHEREarbgbLIKE'0%'
ANDmsgnr=t_idsTABLE_LINE.
ENDIF.
Problem
Whenyourtablehasfewkeyfields,yougenerallytendtoselectthem,eventhoughyoudontneedthem.ButwhentherearemanyFieldsyoutendtonotinclude
theminyourtableandsubsequentlyinyourSELECTquery.
Forexample,letsseethisquery:
Incorrect FOR ALL ENTRIES
SELECTryear
drcrk
rpmax
rtcur
racct
rbukrs
rcntr
kokrs
hsl01
hsl02
hsl03
hsl04
hsl05
hsl06
hsl07
hsl08
hsl09
hsl10
hsl11
hsl12
FROMfaglflext
INTOTABLElt_fagl
FORALLENTRIESINlt_skb1
WHEREryearINlr_gjahr
ANDracct=lt_skb1saknr
ANDrbukrs=lt_skb1bukrs.
Sincethisquerydoesnthaveallthekeyfields,youwouldrunintotheissueswhenyouwilltrytoreconcileitwithsomeofthestandardtransactionFAGLB03.
TheissuewillhappenwhenyouhavesamepostingforsameGLusingsameCCindifferentperiods.Inthatcase,systemwouldonlybringoneentryinsteadof
themultiple.Ontheotherhandthestandardtransactionwouldgetyoualltheentrieswouldadifferenttotal.
WhenyoudebugthestdtransactionandreachtoSELECT,youwouldthink,thisisthesamequeryIhave.Thanwhymyquerywontwork.Soyoudownloadthe
datafrombothoftheITABYourprogramandStdtransaction.Youcomparethemandyouwouldnoticefewentriesaredefinitelymissing.Afterfewroundsof
VLOOKUPandCompareinexcel,yousuddenlyrealizethatFORALLENTRIESisdroppingfewentries.Bythetime,youarealreadyexpertinExcel.
TofixthisyouwouldthanrealizethatyouneedtoincludemorekeyfieldsintotheSELECT.NexthurdlewouldbetoexplaintoyourFunctionalcounterpartand
http://zevolving.com/2014/03/abapforallentrieswhyyouneedtoincludekeyfields/
1/4
2/18/2016
ABAPFORALLENTRIESWhyyouneedtoincludeKEYfields|ABAPHelp
youruserswhyitwasnotworking.
Ifthisprogramwasnotdevelopedbyyou,Icanimaginehowmuchyouhatethatpersonwhenyourealizedtherootcause.Asillymistake!Onbrightside,you
arenowExcelexpert
Compare
Letmeshowyouthissimpleexample:
T100 SELECT without SPRAS
TYPES:
BEGINOFty_t100,
arbgbTYPEt100arbgb,
msgnrTYPEt100msgnr,
textTYPEt100text,
ENDOFty_t100.
DATA:t_idsTYPESTANDARDTABLEOFt100msgnr.
DATA:t_t100_allTYPESTANDARDTABLEOFt100.
DATA:t_t100TYPESTANDARDTABLEOFty_t100.
APPEND'001'TOt_ids.
APPEND'002'TOt_ids.
IFt_idsISNOTINITIAL.
SELECTarbgb
msgnr
text"commenttoseemorerecordsaredropping
INTOTABLEt_t100
FROMt100
FORALLENTRIESINt_ids
WHEREarbgbLIKE'0%'
ANDmsgnr=t_idsTABLE_LINE.
WRITE:/'WithoutAllKeyFields',sydbcnt.
ENDIF.
Now,thiscodewithallthekeyfields
T100 with SPRAS (with all key fields)
IFt_idsISNOTINITIAL.
SELECT*
INTOTABLEt_t100_all
FROMt100
FORALLENTRIESINt_ids
WHEREarbgbLIKE'0%'
ANDmsgnr=t_idsTABLE_LINE.
WRITE:/'WithALLKeyFields',sydbcnt.
ENDIF.
IfyoucommentouttheTEXTfieldfromthe1stquery,youwouldseemorerecordsarebeingdropped.Thisisduetothefactthat,DBwouldonlyretainthe
uniquerecords.DBwouldcomparetheentirerecordwithallrecordsandwoulddroptherows.JustlikeDELETEADJACENTDUPLICATESFROMitab
COMPARINGALLFIELDS.
BasedonentriesinsystemwhereIexecutedthis:
http://zevolving.com/2014/03/abapforallentrieswhyyouneedtoincludekeyfields/
2/4
2/18/2016
ABAPFORALLENTRIESWhyyouneedtoincludeKEYfields|ABAPHelp
Conclusion
WhenyouuseFORALLENTRIES,alongwithotherthings,youwoulddefinitelywanttomakesureyouhaveallthekeyfieldsintheinternaltableandyouare
selectingthemaswelltoavoidthedatainconsistencies.
Tags
DataIntegrity
Performance
Naimesh Patel
{263 articles}
I'mSAPABAPConsultantformorethanadecade.IliketoexperimentwithABAPespeciallyOO.IhavebeenSDNTopContributor.
Follow:
Exploreallofhis263articles.
3 Comments
fawcs
bilen Cekic
Naimesh Patel
Comments on this Post are now closed. If you have something important to share, you can always contact me.
http://zevolving.com/2014/03/abapforallentrieswhyyouneedtoincludekeyfields/
3/4
2/18/2016
ABAPFORALLENTRIESWhyyouneedtoincludeKEYfields|ABAPHelp
Subscribe
Keep in touch. We would do great working together.
1400
SubscribetoEmail
Follow@zevolving
your email
ABAPHelpBlog
3,063likes
LikePage
Share
Bethefirstofyourfriendstolikethis
ABAP Help
Follow
+1
+ 1,483
Current Poll
DoyoulikeQualityAssuranceofyourBuild/Design?
YES. I live for it!
I don't mind
NO. I hate it
Vote
View Results
Search
SearchinZevolving
zevolving.comisfoundedbyandmaintainedbyNaimeshPatel.YoucanhelpbysubmittingyourarticlesviaWriteaPost.ThesiteisbuiltonWordpress.
HappyDesigning!
About Subscribe Advertise Licence
Allproductnamesaretrademarksoftheirrespectivecompanies.zevolving.comisnotaffiliatedwithSAPAG.
http://zevolving.com/2014/03/abapforallentrieswhyyouneedtoincludekeyfields/
4/4