Anda di halaman 1dari 6

11/23/2016

BuildinganSAPQuerywithABAPCodeSAPBlogs

GetStarted

Solutions

Partner

Support

About

Community

Training

Community

Developer

Blogs

BuildinganSAPQuerywith
ABAPCode
November20,2015

| 548Views |

AmitDiwane
morebythisauthor

ABAPDevelopment
abap | coding | extra | infoset | query/report | sap | sq01 | sq02

share
0

share
0

tweet

share
0

Follow

ABAPcodeisusedwithSAPquerytooltoenhancethequeryoutput.
YoucanwritedownthecodeundertheExtrastabfortheInfosetin
theSQ02Tcode.

https://blogs.sap.com/2015/11/20/buildingansapquerywithabapcode/

1/6

11/23/2016

BuildinganSAPQuerywithABAPCodeSAPBlogs

YouwillfindvariouscodingeventswhicharesimilartoclassicalABAP
report.

Thecodewritteninthiscodeareaistransmittedtotheauto
generatedqueryreport.Youcanwritedownyourcodeinvarious
codingsectionaspertheuseofthem.
DATASection:

GlobalDataDeclarationwillgounderthisEvent.
INITIALIZATIONSection:

Asthenamesuggestsitisusedtoinitializethevariablewithinitial
values.
ATSELECTIONSCREENOUTPUT:

Thiseventistriggeredbeforethedisplayofselectionscreen.
STARTOFSELECTION:

Thiseventistriggeredbeforestartinganydatabaseaccesses.
UsuallyDatafetchinglogicgoesunderit.
RECORDProcessing:

CorrespondstotheGETcodingwithInfosetswithoutalogical

database.Asthereisnohierarchicalviewofthedata,allthejointablesare
addressed.
ENDOFSELECTION:

TheENDOFSELECTIONcodeconsistsoftwoparts( Beforelist
output and Afterlistoutput ).Thefirstpartisprocessedbeforethelistis
outputandthesecondpartafterwards.Itistherightsectiontodo

https://blogs.sap.com/2015/11/20/buildingansapquerywithabapcode/

2/6

11/23/2016

BuildinganSAPQuerywithABAPCodeSAPBlogs

aggregatedcalculationsandactionsthatcanonlybedonewhendatafrom
alltheselectedrecordshasbeenextracted.
However,thereisaproblemwhenqueriesusecodeintheENDOF
SELECTIONsectionincombinationwiththeSapListViewerformat.In
short,thecodeisneverreached.
FreeCoding:

Thecodeunderthiseventisexecutedafteralltheeventsaretriggered.

Logictoputextrafieldinthequeryoutput:
LetyouwantadatefieldtobefetchfromaBtableandhastobe
addedtoyourqueryoutput.
DefineaStructureinDATAEvent:
data:beginofty_dateoccurs0,
datelikeBdate,
endofty_date.
Thelogictofetchthevaluesforthisfieldwillgoundertherecord
processingevent.
InRecordProcessingEventwritedownthefollowingcode:
CLEARty_date.
CLEARv_date.
SelectdatefromBintotablety_date.Youcanmention
yourconditionalsowithwhereclause
SortTablety_dateBYdateDESCENDING.
ReadTablety_dateINDEX1.
v_date=ty_datedate.
GeneratetheInfoset.
Changestothequery:
1.RunSQ01inanothersession.
2.OpenyourQueryinchangemodeandselectthefieldgroupinwhichhasthe
addedextrafield.
3.Selectextrafield.
4ClickonbasiclisttoselectthatfieldinyourO/plist.
https://blogs.sap.com/2015/11/20/buildingansapquerywithabapcode/

3/6

11/23/2016

BuildinganSAPQuerywithABAPCodeSAPBlogs

5.ClickonTestbutton,andseeifyouaregettingdesiredresult.

PerformingOperationsonthefinaloutputtabledata:
Youllfindtable%G00withfinaldatatobedisplayed.
EnterthefollowingABAPcodeunderDataSection:
data:strtypestring.
fieldsymbols:<G00>typetable.
fieldsymbols:<G00_WA>typeany.
EnterthebelowABAPcodeunderENDOFSELECTION(afterlist)
Event:
str=%g00[].
ASSIGN(str)TO<G00>.
loopat<G00>assigning<G00_WA>.
dowhateveryoulikehere.
endloop.
Youcanputyourownlogicinsidethelooptoperform..

AlertModerator

6Comments
YoumustbeLoggedontocommentorreplytoapost.

DuraisamyDhanaraj
May8,2016at7:31am

HiAmit,

Iwanttoaddtheconditionagainstthefieldsintheloop.Howtodothat?

Loopat<G00>assigning<G00)WA>
https://blogs.sap.com/2015/11/20/buildingansapquerywithabapcode/

4/6

11/23/2016

BuildinganSAPQuerywithABAPCodeSAPBlogs

Endloop.

AmitDiwane Postauthor
May10,2016at9:53am

YoucanwritedownthecodeundertheENDOF
SELECTION(afterlistevent)byLoopingonthetableG00.

DuraisamyDhanaraj
May23,2016at5:57am

HiAmit,

Thanksforyourreply.Igottheanswer.

regards,
Sam

DuraisamyDhanaraj
May23,2016at5:59am

veryusefuldocument.Iusedthisdocumentformanytimes..insteadofkeep
rememberingthings,Irememberthiskindofdocument,soIcanuseit,
wheneveritsrequired.

FrederickDaCostaRamos
June2,2016at4:44pm

HiAmit,thanksforyourexplanation.ImfunctionalconsultantandImused
tocreateinfoset/queries.IhaveanissuenowthatIneedtosummarize
(collect)theresultoftheinfosetIcreated.HowcanIdoit?HowcanIrefer
totheinternaltabletheinfosetcreatesduringruntimeandsummarizeit

https://blogs.sap.com/2015/11/20/buildingansapquerywithabapcode/

5/6

11/23/2016

BuildinganSAPQuerywithABAPCodeSAPBlogs

beforeislistedinthereportresult?BestRegardsandthanksifyouhave
timetosaveme

AmitDiwane Postauthor
June3,2016at5:12am

HelloFrederick,

TheresultsetfortheinfosetqueriesisinG00Internaltable.
Youcanconsultwiththeabapertomakechangestothedatain
thisfinaltable.Forruntimemodificationtothefinaloutputdata
ofthequerywegenerallywritedownthecode.

Pleaseletmeknowifyouneedmoreinformationonsame.

Share & Follow

Privacy

TermsofUse

LegalDisclosure

https://blogs.sap.com/2015/11/20/buildingansapquerywithabapcode/

Copyright

Trademark

Sitemap

Newsletter

6/6

Anda mungkin juga menyukai