BAPI的使用说明中文版.docx

上传人:b****5 文档编号:6360498 上传时间:2023-01-05 格式:DOCX 页数:19 大小:154.22KB
下载 相关 举报
BAPI的使用说明中文版.docx_第1页
第1页 / 共19页
BAPI的使用说明中文版.docx_第2页
第2页 / 共19页
BAPI的使用说明中文版.docx_第3页
第3页 / 共19页
BAPI的使用说明中文版.docx_第4页
第4页 / 共19页
BAPI的使用说明中文版.docx_第5页
第5页 / 共19页
点击查看更多>>
下载资源
资源描述

BAPI的使用说明中文版.docx

《BAPI的使用说明中文版.docx》由会员分享,可在线阅读,更多相关《BAPI的使用说明中文版.docx(19页珍藏版)》请在冰豆网上搜索。

BAPI的使用说明中文版.docx

BAPI的使用说明中文版

BAPIStepbyStepExample

Abouttheexample

ThisBAPIreadssystemstatusforaproductionorderfromtableJESTandsystemstatustextfromtableTJ02T

 此BAPI是从JEST读取生产订单系统状态和从表TJ02T中读取文本状态

Name

ZGetOrderStatus(bapi名称)

Functiongroup

ZBAPISTATUS(功能组)

Functionmodule:

Z_BAPI_GET_ORDER_STATUS(功能模块)

Importparameters:

ORDER_STATUS_IMPORTtypeZBAPI_ORDER_STATUS_IMPORT:

定义左边变量类型为右

∙AUFNROrdernumber(Keyfield)

∙SPRASLanguage

∙ExcludeInactive-Checkbox-Excludeinactivestatus

Tables

T_BAPISTATtypeZBAPISTAT:

∙OBJNRlikeJEST-OBJNR

∙STATlikeJEST-STAT

∙INACTlikeJEST-INACT

∙TXT04likeTJ02T-TXT04

∙TXT30likeTJ02T-TXT30

Exportparameters

RETURNlikeBAPIRETURN

 Step1:

定义BAPI用到的结构体 

在此步骤里,BAPI中用到功能模块的表和参数均已在这里定义

使用数据类型-结构

定义以下结构:

结构1:

ZBAPI_ORDER_STATUS_IMPORT包含以下字段

∙ORDERIDOrdernumber(Keyfield)订单号

∙SPRASLanguage语言

∙ExcludeInactive-Checkbox-Excludeinactivestatus

结构2:

ZBAPISTAT:

OBJNRlikeJEST-OBJNR

∙STATlikeJ_STAT

∙INACTlikeJ_INACT

∙TXT04likeJ_TXT04

∙TXT30likeJ_TXT30

∙OBJNRlikeJ_OBJNR 

Importantnote:

YouwillhavetodefineastructureforeveryparameterintheBAPI.YoucannotusethesamestructuresusedinexistingapplicationsbecauseBAPIstructuresarefrozenwhenBAPIsarereleasedandthentherearerestrictionsonchangingthem.

你必须为每个BAPI中的参数定义结构,当BAPI被释放后是限制更改他们的,因为bapi会被冻结,所以你不能在存在的应用中使用同一个结构

ZBAPI_ORDER_STATUS_IMPORT–结构1 

ZBAPISTAT---结构2

 

 第二步:

写入功能模块

Importantnotes:

∙每个BAPI必须有他们自己的函数组(功能组)

∙在属性tab里记住选择存取类型是RemoteEnabledmodule,否则功能模块不能通过RFC来invoke它做为一个BAPI来使用

∙输入/输出参数仅仅能被BYVALUE对于RFCenabled的功能模块

∙我们在此仅创建了一个BAPI,但你能创建相关的BAPI在同一模块池中,使得他们能共享全局信息

功能模块的属性设定

输入参数

这里定义功能模块的输入参数为订单输入参数的结构,即是引入结构ZBAPI_ORDER_STATUS_IMPORT做为bapi_order_status_import的参照

 ExportParameters

 Tables

 Code

Notes:

∙ThesubroutineSET_RETURN_MESSAGEisastandardroutineusedforBAPIsthatusetheBAPIRETURNstructure

∙SET_RETURN_MESSAGE子程序是在BAPI中标准的子程序用来使用BAPIRETURN结构

∙在FORMZ_BAPI_GET_ORDER_SYSTEM_STATUS里有个测试是IF1=2,如果这测试结果为真,则信息就显示,但是这个条件永远不会为真,所以我们就不可能在BAPI里显示出这个信息,为什么要包含这个的原因是,为信息创建一个参照,因此…这时SAP标准控制方法,拷贝公司代码层面的代码GetListBAPI.

∙InformZ_BAPI_GET_ORDER_SYSTEM_STATUSthereisatestIF1=2.Ifthetestistrueamessageisdisplayed.Theconditionwillobviouslyneverbetrue,andwewillneverwanttodisplayamessageinaBAPI.Thereasonwhyitisincludedis,thatitcreateareferenceforthemessage,sothattheWHEREUSEDfunctionalitycanbeusedforthemessage.ThisistheSAPstandardwaytohandleit,copiedfromtheCompanyCodeGetListBAPI.

INCLUDELZBAPISTATUSUXX

*****************************************************************

*THISFILEISGENERATEDBYTHEFUNCTIONLIBRARY.*

*NEVERCHANGEITMANUALLY,PLEASE!

*****************************************************************

INCLUDELZBAPISTATUSU02.

"Z_BAPI_GET_ORDER_SYSTEM_STATUS

INCLUDELZBAPISTATUSTOP-Globaldata

FUNCTION-POOLZBAPISTATUS."MESSAGE-IDZ3

Types:

beginofType_tj02t,

istatliketj02t-istat,

txt04liketj02t-txt04,

txt30liketj02t-txt30,

endoftype_tj02t.

DATA:

*DeclarationsforTABLEparameter

T_BAPISTATlikeZBAPISTAToccurs0,

G_BAPISTATlikeZBAPISTAT,

*Tableforobjecttexts

t_tj02ttypetype_tj02toccurs0,

g_tj02ttypetype_tj02t.

*Structureforreturnmessages

DATA:

BEGINOFMESSAGE,

MSGTYLIKESY-MSGTY,

MSGIDLIKESY-MSGID,

MSGNOLIKESY-MSGNO,

MSGV1LIKESY-MSGV1,

MSGV2LIKESY-MSGV2,

MSGV3LIKESY-MSGV3,

MSGV4LIKESY-MSGV4,

ENDOFMESSAGE.

INCLUDELZBAPISTATUSF01-Subroutines

***INCLUDELZBAPISTATUSF01.

*----------------------------------------------------------------------*

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

*&FormSET_RETURN_MESSAGE

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

*ThisroutineisusedforsettingtheBAPIreturnmessage.

*TheroutineisastandardroutineforBAPIsthathandlesthemessage

*structurefortheBAPIRETURNstructure.Ithasbeencopiedfromthe

*BAPICompanyCodeGetlist

*----------------------------------------------------------------------*

*-->P_MESSAGEtext

*<--P_RETURNtext

*----------------------------------------------------------------------*

formSET_RETURN_MESSAGEUSINGVALUE(P_MESSAGE)LIKEMESSAGE

CHANGINGP_RETURNLIKEBAPIRETURN.

CHECKNOTMESSAGEISINITIAL.

CALLFUNCTION'BALW_BAPIRETURN_GET'

EXPORTING

TYPE=P_MESSAGE-MSGTY

CL=P_MESSAGE-MSGID

NUMBER=P_MESSAGE-MSGNO

PAR1=P_MESSAGE-MSGV1

PAR2=P_MESSAGE-MSGV2

PAR3=P_MESSAGE-MSGV3

PAR4=P_MESSAGE-MSGV4

*LOG_NO=''

*LOG_MSG_NO=''

IMPORTING

BAPIRETURN=P_RETURN

EXCEPTIONS

OTHERS=1. 

endform."SET_RETURN_MESSAGE

FUNCTIONZ_BAPI_GET_ORDER_STATUS

FUNCTIONz_bapi_get_order_system_status.

*"----------------------------------------------------------------------

*"*"Localinterface:

*"IMPORTING

*"VALUE(I_AUFNR)TYPEAUFNR

*"VALUE(I_SPRAS)TYPESPRASDEFAULTSY-LANGU

*"VALUE(I_EXCLUDEINACTIVE)TYPECHAR1OPTIONAL

*"EXPORTING

*"VALUE(RETURN)TYPEBAPIRETURN

*"TABLES

*"T_BAPISTATSTRUCTUREZBAPISTAT

*"------------------------------------------------------

**

*"Localinterface:

*"IMPORTING

*"VALUE(I_AUFNR)TYPEAUFNR

*"VALUE(I_SPRAS)TYPESPRASDEFAULTSY-LANGU

*"VALUE(I_EXCLUDEINACTIVE)TYPECHAR1OPTIONAL

*"EXPORTING

*"VALUE(RETURN)TYPEBAPIRET2

*"TABLES

*"T_BAPISTATSTRUCTUREZBAPISTAT

DATA:

l_aufnrLIKEafko-aufnr,

l_objnrLIKEjest-objnr.

********************************************

*Checkiforderexists

********************************************

SELECTSINGLEaufnr

FROMafko

INTOl_aufnr

WHEREaufnr=BAPI_ORDER_STATUS_IMPORT-orderid.

IFsy-subrcNE0.

CLEARmessage.

message-msgty='E'.

message-msgid='Z3'.

message-msgno='000'.

message-msgv1=BAPI_ORDER_STATUS_IMPORT-orderid.

PERFORMset_return_messageUSINGmessage

CHANGINGreturn.

IF1=2.

*Theonlyreasontoincludethisstatement,thatwillobviously

*neverexecute,isthatitwillcreateareferecencesothatyou

*canfindoutwhereaparticularmessageisbeingused.This

*functionalityisusedbytheBAPIsprogrammedbySAP

MESSAGEe000(z3).

ENDIF.

ENDIF.

CHECKreturnISINITIAL.

********************************************

*Readorderstatus

********************************************

CONCATENATE'OR'BAPI_ORDER_STATUS_IMPORT-orderidINTOl_objnr.

IFBAPI_ORDER_STATUS_IMPORT-i_excludeinactive='X'.

SELECTobjnrstatinact

FROMjest

INTOTABLEt_bapistat

WHEREobjnr=l_objnrAND

inact<>'X'.

ELSE.

SELECTobjnrstatinact

FROMjest

INTOTABLEt_bapistat

WHEREobjnr=l_objnr.

ENDIF.

IFsy-subrc<>0.

*Noobjectstatusfound

CLEARmessage.

message-msgty='E'.

message-msgid='Z3'.

message-msgno='001'.

message-msgv1=BAPI_ORDER_STATUS_IMPORT-orderid.

PERFORMset_return_messageUSINGmessage

CHANGINGreturn.

IF1=2.

MESSAGEe001(z3).

ENDIF.

ENDIF.

CHECKreturnISINITIAL.

********************************************

*Readorderstatustexts

********************************************

SELECTistattxt04txt30

FROMtj02t

INTOTABLEt_tj02t

FORALLENTRIESINt_bapistat

WHEREistat=t_bapistat-statAND

spras=BAPI_ORDER_STATUS_IMPORT-i_spras. 

SORTt_tj02tBYistat.

LOOPATt_bapistatINTOg_bapistat.

READTABLEt_tj02t

WITHKEYistat=g_bapistat-statBINARYSEARCH

INTOg_tj02t.

IFsy-subrc=0.

MOVE:

g_tj02t-txt04TOg_bapistat-txt04,

g_tj02t-txt30TOg_bapistat-txt30.

MODIFYt_bapistatFROMg_bapistatTRANSPORTINGtxt04txt30.

ENDIF.

ENDLOOP.

ENDFUNCTION. 

STEP3-CreatetheAPIMethodUsingtheBAPIWIZARD

TheBAPIwizardisusedtoToexposetheremotefunctionmoduleasaBAPI.Thewizardwillgeneratesomeadditionalcode,sothefunctionmoduleisavalidmethodoftheBOR.ThisallowstheBAPitobecalledasaworkflowmethodinadditiontobecalledbyanoutsideprogram.

Note:

EachfunctionmodulecorrespondstoamethodintheBOR

GototheBusinesObjectBuilderSWO1.

YoucaneithercreatethenewObjecttypeasasubtypeofanexistingbusinessobjectorcreateanewbusinessobjectfromscratch.InthisexampleitwouldbeobvioustocreatetheObjecttypeasasubtypeofBUS2005Productionorder.However,toillustratehowtocreateanewObjecttypefromscratch,wewilldothis.

IntheObject/InterfacetypefieldwritethenameofthenewBusinessObject:

ZORDERSTAT.Pressenterandfillintheadditionalfieldsnecessarytocreatetheobjecttype.

Supertype:

Notrelevantbecausewearecreatingourobjectfromscratch

Program.ThisisthenameoftheprogramwherethewizardgeneratescodefortheObjecttype,NOTthefunctionmodulewecraetedearlier.Theprogramnamemustnotbethenameofanexistinbgprogram.

 

 

Pressenterandcreatethenewbusinessobject.Notethatwhenyoucreatethebusinessobjectastandardinterface,anattributeObjectTypeandthemethodsExistenceCheckandDisplayareautomaticallygenerated.Thesecannotbechanged!

 

ThenextstepistoaddtheZ_BAPI_GET_ORDER_STATUSmethodtothebusinessobject.SelectUtillities->APImethods->Addmethodandwritethenameofthefunctionmoduleinthedialogbox.Nextthedialogboxshowbelowwillbeshown.ThisisthestartscreenoftheBAPIwizard.Proceedwithwizardbypressingthe

button.

Afteryouhavefinishedthewizard,tyouwillnoticethattheZGetOrderStatushasbeenaddedtothebusinessobject:

Youcandoubleclickonthemethodtoseeitsproperties.TousethebusinessobjectyoumustchangetheObjecttypestatustoImplemented.UsemenuEdit->Changereleasesstatus->Objecttype->Toimplemented.Noyoucantestthgeobject(PressF8).

Not

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 党团工作 > 入党转正申请

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

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