SAP R/3 форум ABAP консультантов
Russian ABAP Developer's Club

Home - FAQ - Search - Memberlist - Usergroups - Profile - Log in to check your private messages - Register - Log in - English
Blogs - Weblogs News

Customer Enhancement of BAPI



 
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> Interfaces | Интерфейсы
View previous topic :: View next topic  
Author Message
admin
Администратор
Администратор



Joined: 01 Sep 2007
Posts: 1639

PostPosted: Thu Oct 25, 2007 12:08 pm    Post subject: Customer Enhancement of BAPI Reply with quote

http://help.sap.com/saphelp_nw04/helpdata/en/6b/3f6d286d0711d396a50004ac96334b/frameset.htm

Example for Developing the BAPI Function Module with Customer Enhancement

Code:
FUNCTION BAPI_TRAVELAGENCY_CREATE .

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

*"*"Local interface:

*" IMPORTING

*" VALUE(AGENCYDATA_IN) LIKE BAPISADTIN

*" STRUCTURE BAPISADTIN

*" EXPORTING

*" VALUE(AGENCYNUMBER) LIKE BAPISADETA-AGENCYNUM

*" TABLES

*" EXTENSIONIN STRUCTURE BAPIPAREX OPTIONAL

*" RETURN STRUCTURE BAPIRET2 OPTIONAL

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


* global buffer is t_sbuspart, t_stravelag

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

* length of name field for extension table in extension structure

CONSTANTS:

C_LENSTRUC TYPE I VALUE 30.


* work areas for the table extension structures

DATA:

WA_BAPI_TE_SA LIKE BAPI_TE_SA,

WA_BAPI_TE_SP LIKE BAPI_TE_SP.


* clear workareas for database tables

CLEAR T_SBUSPART.

CLEAR T_STRAVELAG.

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

* perform authority checks

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

* check the incoming data of SAP parameter AGENCYDATA_IN

PERFORM CHECK_AGENCYDATA_IN TABLES RETURN

USING AGENCYDATA_IN.

CLEAR RETURN.

LOOP AT RETURN WHERE TYPE = 'E' OR TYPE = 'A'.

EXIT.

ENDLOOP.

IF RETURN-TYPE = 'E' OR RETURN-TYPE = 'A'.

EXIT.

ENDIF.

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

* Here a customer exit should be provided to check all data

* including the EXTENSIONIN parameter.

* This exit should be realized with the new exit technology,

* however this technology is still under construction.

* This example will be extended as soon as this technology is

* available.

* The Exit should have the following parameters:

* -> All BAPI-parameters: AGENCYDATA_IN, EXTENSIONIN

* <- RETURN

* The function module should pass the RETURN parameter from

* the exit to the client. 'E' means that the client can

* 'commit' the BAPI call, if there is an 'A' message in the

* RETURN parameter, the client should 'rollback work'.

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

* get the missing id's STRAVELAG-ID & SBUSPART-BUSPARTNUM

CALL FUNCTION 'NUMBER_GET_NEXT'

EXPORTING

NR_RANGE_NR = '01'

OBJECT = 'SBUSPID'

QUANTITY = '1'

IMPORTING

NUMBER = AGENCYNUMBER

EXCEPTIONS

INTERVAL_NOT_FOUND = 1

NUMBER_RANGE_NOT_INTERN = 2

OBJECT_NOT_FOUND = 3

QUANTITY_IS_0 = 4

QUANTITY_IS_NOT_1 = 5

INTERVAL_OVERFLOW = 6

OTHERS = 7.

IF SY-SUBRC <> 0.

RETURN-TYPE = 'E'.

RETURN-ID = 'BCTRAIN'.

RETURN-NUMBER = '601'.

RETURN-MESSAGE_V1 = TEXT-500.

APPEND RETURN.

EXIT.

ENDIF.

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

* Before adding data to the buffer, subscribe the function module

* to delete this buffer in case of 'rollback work' by the client.

CALL FUNCTION 'BUFFER_SUBSCRIBE_FOR_REFRESH'

EXPORTING

NAME_OF_DELETEFUNC = 'SAGENCY_REFRESH_BUFFER'.

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

* Fill global buffer for table STRAVELAG.

MOVE-CORRESPONDING AGENCYDATA_IN TO T_STRAVELAG.

T_STRAVELAG-AGENCYNUM = AGENCYNUMBER.

APPEND T_STRAVELAG.

* Fill global buffer for table SBUSPART.

T_SBUSPART-BUSPARTNUM = AGENCYNUMBER.

T_SBUSPART-CONTACT = T_STRAVELAG-NAME.

T_SBUSPART-CONTPHONO = T_STRAVELAG-TELEPHONE.

T_SBUSPART-BUSPATYP = 'TA'.

APPEND T_SBUSPART.

* Collect the appended fields of tables STRAVELAG & SBUSPART.

LOOP AT EXTENSIONIN.

CASE EXTENSIONIN-STRUCTURE.

WHEN 'BAPI_TE_SA'.

MOVE EXTENSIONIN+C_LENSTRUC TO WA_BAPI_TE_SA.

* check if table entry to extension entry exist. for that

* we fill the internal given number into the extension table.

MOVE AGENCYNUMBER TO WA_BAPI_TE_SA-AGENCYNUM.

READ TABLE T_STRAVELAG

WITH KEY AGENCYNUM = AGENCYNUMBER.

CATCH SYSTEM-EXCEPTIONS CONVERSION_ERRORS = 1.

MOVE-CORRESPONDING WA_BAPI_TE_SA TO T_STRAVELAG.

ENDCATCH.

IF SY-SUBRC <> 0.

RETURN-TYPE = 'E'.

RETURN-ID = 'BCTRAIN'.

RETURN-NUMBER = '888'.

RETURN-MESSAGE_V1 = TEXT-800.

RETURN-MESSAGE_V2 = SY-TABIX.

RETURN-MESSAGE_V3 = TEXT-900.

APPEND RETURN.

EXIT.

ENDIF.

MODIFY T_STRAVELAG INDEX SY-TABIX.

WHEN 'BAPI_TE_SP'.

MOVE EXTENSIONIN+C_LENSTRUC TO WA_BAPI_TE_SP.

MOVE AGENCYNUMBER TO WA_BAPI_TE_SP-BUSPARTNUM.:

READ TABLE T_SBUSPART

WITH KEY BUSPARTNUM = AGENCYNUMBER.

CATCH SYSTEM-EXCEPTIONS CONVERSION_ERRORS = 1.

MOVE-CORRESPONDING WA_BAPI_TE_SP TO T_SBUSPART.

ENDCATCH.

IF SY-SUBRC <0> All BAPI-parameters: AGENCYDATA_IN, EXTENSIONIN and the id

* AGENCYNUMBER.

* Nothing comes back!

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

* assume that everything is O.K., fill return parameters

RETURN-TYPE = 'S'.

RETURN-ID = 'BCTRAIN'.

RETURN-NUMBER = '603'.

RETURN-MESSAGE_V1 = TEXT-600.

RETURN-MESSAGE_V2 = T_STRAVELAG-AGENCYNUM.

RETURN-MESSAGE_V3 = TEXT-400.

APPEND RETURN.

ENDFUNCTION.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> Interfaces | Интерфейсы All times are GMT + 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


All product names are trademarks of their respective companies. SAPNET.RU websites are in no way affiliated with SAP AG.
SAP, SAP R/3, R/3 software, mySAP, ABAP, BAPI, xApps, SAP NetWeaver and any other are registered trademarks of SAP AG.
Every effort is made to ensure content integrity. Use information on this site at your own risk.