Working with Business Objects in SAP获取BO方法及属性.docx

上传人:b****4 文档编号:3497876 上传时间:2022-11-23 格式:DOCX 页数:19 大小:696.62KB
下载 相关 举报
Working with Business Objects in SAP获取BO方法及属性.docx_第1页
第1页 / 共19页
Working with Business Objects in SAP获取BO方法及属性.docx_第2页
第2页 / 共19页
Working with Business Objects in SAP获取BO方法及属性.docx_第3页
第3页 / 共19页
Working with Business Objects in SAP获取BO方法及属性.docx_第4页
第4页 / 共19页
Working with Business Objects in SAP获取BO方法及属性.docx_第5页
第5页 / 共19页
点击查看更多>>
下载资源
资源描述

Working with Business Objects in SAP获取BO方法及属性.docx

《Working with Business Objects in SAP获取BO方法及属性.docx》由会员分享,可在线阅读,更多相关《Working with Business Objects in SAP获取BO方法及属性.docx(19页珍藏版)》请在冰豆网上搜索。

Working with Business Objects in SAP获取BO方法及属性.docx

WorkingwithBusinessObjectsinSAP获取BO方法及属性

BySwetabhShukla,Infosys

BusinessObjecttypecontainsmethods,attributesandeventswhichgiveacomponentbasedviewofanyBusinessProcess. 

ForexamplewehaveaPurchaseOrderbusinessprocess.Thisprocessincludesvarioussmallfunctionalities.ItwillhaveprocessofchangingPurchaseordersbaseduponrequirements,functionalitytoretrievethedetailsofpurchaseorderetc.Eachofthesefunctionalitiesisencapsulatedinsideamethod.ThemethodcancallthefunctionmodulespresentinR3systemorcanhavethereowncodetoexecutesomefunctionality.SoifweconsiderPurchaseOrderasaBusinessObjectthenitwillbeidentifiedbykeyfieldPurchaseOrdernumber.Eachpurchaseorderbusinessobjectbaseduponkeyfieldpurchaseordernumberisdifferent.It’ssobecauseeachpurchaseorderisdifferentandwillcontaindifferentdetails. 

Sothemethodscontainbusinessfunctionality.AttributesarejustlikepropertiesoftheBusinessobject. ForexampleforanypurchaseorderPurchasingGroup,PurchasingOrganizationetcareattributes. 

Technicallywecansaythatbusinessobjecttypesarejustlikeanytemplate.AtruntimeweinstantiateorcreateruntimeobjectsforanyBO(BusinessObject)typebaseduponthekeyfieldswepass.TworuntimeBusinessobjectsofsameBOtypearedifferentfromeachotherbaseduponthekeyfieldswepass.SothekeyfieldisthedifferentiatingfactorfortwoormoreruntimebusinessobjectsofsameBOtype. 

ToBrowseforBOopentcodeSWO2(Path->Tools->ABAPWorkbench->Overview->BusinessObjectBrowser). 

                      

 

YoucanexpandthenodesandcancheckvariousbusinessobjectsinBOR.YoucandoubleclickontheBOnodeanditwilltakeyoutoBOdisplay(SWO1).   

1           WorkingwithBusinessObjectinourprograms 

ForcreatingaBusinessObjectanditsattributestherearemanyalreadyexistingtutorials.  SointhistutorialwewillnotdiscusscreationofBOanditsattributes.

1.1          TocreateinstanceofaBO

TocreateaninstanceofBOweneedtohavethekeyfieldsofthatBO.KeyfieldswillbeusedtouniquelyidentifytheBO.WecanusetheFM'SWO_CREATE'tocreateaninstanceofBOinanyreportprogram. 

DATA:

i_objtypeTYPEswo_objtyp,

i_objkeyTYPEswo_typeid,

objectTYPEswo_objhnd.

i_objtype=

i_objkey=

CALLFUNCTION'SWO_CREATE'

EXPORTING

objtype=i_objtype

objkey=i_objkey

IMPORTING

object=object.

Thevariable‘object’willholdruntimeinstanceoftheobjecttype.

 Theotherwayistousethemacrosdefinedininclude 

INCLUDE.

DATA:

i_objtypeTYPEswo_objtyp,

i_objkeyTYPEswo_typeid,

objectTYPEswc_object.

*CreateinstanceofObjecttype

swc_create_objectobjecti_objtypei_objkey.

 InternallythemacrocallstheFMSWO_CREATE.SoyoucaneithergofordirectFMcallorthemacrocall.

1.2          Container 

BasicallythetermContainerisusedwithreferencetoBusinessObjectsandWorkflows.TheContaineractuallyholdsimportandexportparametersassociatedwithanymethodofBusinessObjectatruntime.WheneverwearecallinganymethodofBusinessObjectweneedtopopulatecontainerforimportparametersandafterthemethodgetsexecuteditreturnsthevalues(exportparameters)inContainer. 

BusinessObjectcontaineristechnicallyoftypeSWCONTstructure. 

 

Here‘ELEMENT’willbenameofthevariable/internaltablewhichcontainerholdsand‘VALUE’willhavecorrespondingvalue.Formultilinevariableorinternaltables,thecontainerwillholdmultiplevalueswithsameelementname. 

1.2.1          LetstakeanexampletocheckwhatContaineris 

Forexamplelet’screateaBusinessObject‘ZSWE1’withonlyonemethod‘READ’.WewilldiscussthecreationofBOinverybrief. 

KeyfieldwillbePurchaseOrdernumber(EKKO_EBELN)forBO. 

MethodREADwilltakePurchaseOrdernumberasinputandwillgiveallthePurchaseLineitemsinitinaninternaltable. 

Step1:

CreateBOZSWE1fortestpurpose.Youcangiveitanyname. 

 

Step2:

NowcreateamethodREAD

                           

 

Savethemethod.Nowwewillcreatetheparametersofthemethod. 

ImportParameters

PurchaseDocument

EKKO-EBELN

ExportParameter

ITEM

EKKO-EBELP(multiline)

 PurchasingDocumentwillbeaimportparameteroftypeEKKO_EBELN.

ITEMwillbeaexportparameteroftypeEKKO_EBELPandwillbeamultilinevariable(internaltable) 

 

SavethemethodandthenClickontheProgrambuttontoimplementthemethod.Inthemethodjustreadallebeln(Purchaselineitems)correspondingtoPOnumberintointernaltableITEMandpassitontocontainerinthemethod.Checkthesnapshotbelow. 

 

CheckthewholecodeoftheBOprogramhere.  

*****ImplementationofobjecttypeZSWE1*****

INCLUDE.

BEGIN_DATAOBJECT."Donotchange..DATAisgenerated

*onlyprivatemembersmaybeinsertedintostructureprivate

DATA:

"beginofprivate,

"todeclareprivateattributesremovecommentsand

"insertprivateattributeshere...

"endofprivate,

BEGINOFKEY,

PURCHASINGDOCUMENTLIKEEKKO-EBELN,

ENDOFKEY.

END_DATAOBJECT."Donotchange..DATAisgenerated

BEGIN_METHODREADCHANGINGCONTAINER.

DATA:

PURCHASINGDOCUMENTTYPEEKKO-EBELN,

ITEMTYPEEKPO-EBELPOCCURS0.

SWC_GET_ELEMENTCONTAINER'PurchasingDocument'PURCHASINGDOCUMENT.

selectebelpintotableitemfromekpo

whereebeln=PURCHASINGDOCUMENT.

SWC_SET_TABLECONTAINER'Item'ITEM.

END_METHOD. 

Step1:

SavethechangesandmakethestatusoftheBOtoimplementedfortestingpurpose.AlsogeneratetheBO. 

Step2:

Nowlet’stesttheBO.ForthisputabreakpointinthemethodREADattheselectquery.AlsotakeanyPOnumberwhichwillhavemultiplelineitems.YoucancheckEKKOandEKPOtables.InmycaseIamtakingPO‘4200000017’.InmyR3systemthisparticularPOcontains4lineitemsinEKPOtable.Let’sputabreakpointandcheckthemethod. 

 

Step3:

ExecutetheBOwithkey‘4200000017’ 

 

Executethemethodwithimportparameteras‘420000017’ 

 

Itwilltakeyoutodebuggingmode.Nowcheckthecontainer. 

IndebugmodebeforetheselectstatementtheCONTAINERwillholdonlyimportvariable 

 

NowexecutethelaststatementinthemethodandseethecontentsofCONTAINER(justbeforeexitingthemethod. 

 

SowehaveseenhowtheCONTAINERholdsvalueswhileweareworkingwithBusinessObjectsatruntime. 

1.2.2          SomecommonmacrosdefinedinincludeforworkingwithContainers 

Functionality

Macro

TowriteasinglelinevariableinContainer

SWC_SET_ELEMENT

ToreadasinglelinevariablefromContainer

SWC_GET_ELEMENT

TowriteamultilinevariableorinternaltableinContainer

SWC_SET_TABLE

ToreadamultilinevariableorinternaltablefromContainer

SWC_GET_TABLE

Toclearthecontainer

SWC_CLEAR_CONTAINER

Furtheryoucanchecktheincludeformoremacros.Alsocheckthemacros.Thesemacroscallsomespecificfunctionmodulesthatyoucanusedirectlyinyourcode. 

1.3          CallingaBOMethod/Attributeinreportprograms 

WecancreateainstanceofBOmethodusingFM  'SWO_CREATE'ormacro‘SWC_CREATE_OBJECT’. 

FirstofallletsconsideraBO'BUS1001006'  (StandardMaterial).Wewillcallthemethod‘DISPLAY’.ForthiswewillinstantiatetheBOwithkey‘ZSHUKSWE20’(materialnumber). 

TocallamethodorattributeofanyBOwecanusetheFM 'SWO_INVOKE'.WehavetotakecarewhilewecallthisFM.Supposeifwewanttocallanattributedefinedinthemethod,thenweneedtopopulatetheimportparameter ACCESS with ‘G’.IfweneedtocallthemethodoftheBOthenweneedtopopulatetheimportparameter ACCESS with ‘C’. 

Letscreateareportprogramandcheckstepbystep.Wewillfetchdetailsofattribute“MATERIALTYPE”ofBO'BUS1001006' 

*&---------------------------------------------------------------------*

*&ReportZSWET_BO1

*&

*&---------------------------------------------------------------------*

*&TogetattributesofBOinstanceinreport

*&

*&---------------------------------------------------------------------*

REPORTzswet_bo1.

PARAMETERS:

p_busobj(10)TYPEcDEFAULT'BUS1001006',

p_key(70)TYPEcDEFAULT'ZSHUKSWE20',

p_attr(32)TYPEcDEFAULT'MATERIALTYPE',

p_accessTYPEcDEFAULT'G'."Tocallmethodput'C'

DATA:

i_objtypeTYPEswo_objtyp,

i_objkeyTYPEswo_typeid,

i_elementTYPEswo_verb.

DATAobjectTYPEswo_objhnd.

DATAverbTYPEswo_verb.

DATAreturnTYPEswotreturn.

DATAlt_containerTYPESTANDARDTABLEOFswcont.

DATAlineTYPEswcont.

i_objtype=p_busobj.

i_element=p_attr.

i_objkey=p_key.

*Instantiatethebusinessobject.i.egiveitakeyandcreateit.

CALLFUNCTION'SWO_CREATE'

EXPORTING

objtype=i_objtype

objkey=i_objkey

IMPORTING

object=object.

*Returnattribute.

CALLFUNCTION'SWO_INVOKE'

EXPORTING

access=p_access

object=object

verb=i_element

IMPORTING

return=return

verb=verb

TABLES

container=lt_container.

*TheattributevalueisinthecontainerreturnedfromFM.

IFreturn-code=0.

LOOPATlt_containerINTOline.

WRITE:

/'AttributeMATERIALTYPEis:

',

line-value.

ENDLOOP.

ENDIF. 

Letsexecutethereportandseetheoutput:

 

NowletsseehowtocallamethodofBO.TheMethodDISPLAYwilldisplaythematerialpassedinBOcontainer.

*&---------------------------------------------------------------*

*&ReportZSWET_BO1

*&

*&---------------------------------------------------------------*

*&Tocallmethodwithimportparameters

*&

*&---------------------------------------------------------------*

REPORTz

展开阅读全文
相关搜索

当前位置:首页 > 工程科技 > 信息与通信

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1