Posted: Fri Oct 19, 2007 6:40 pm Post subject: BAPI_RESERVATION_CREATE
This abap program have similiar functionality as transaction code 'MB21'. It make use of the ABAP BAPI functions 'BAPI_RESERVATION_CREATE'. It have more AUTHORITY-CHECK than 'MB21'. The purpose is to avoid changing the SAP standard program.
Code:
REPORT ZRES_311.
tables : RESB,
T001W,
MARA.
** Internal tables for BAPI call
data: begin of gm_header.
include structure BAPIRKPFC.
data: end of gm_header.
data: begin of gm_item occurs 0.
include structure BAPIRESBC.
data: end of gm_item.
data: begin of zreturn occurs 0.
include structure BAPIRETURN.
data: end of zreturn.
DATA: AUTH_FLG(1).
PARAMETERS X_BDTER LIKE RESB-BDTER DEFAULT SY-DATUM.
PARAMETERS X_WERKS LIKE RESB-WERKS.
PARAMETERS X_BWART LIKE RESB-BWART.
PARAMETERS X_REC01 LIKE RESB-UMLGO.
PARAMETERS X_ISS01 LIKE RESB-UMLGO.
SKIP.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 16(10) TEXT-010.
SELECTION-SCREEN COMMENT 37(10) TEXT-020.
SELECTION-SCREEN END OF LINE.
SKIP.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 05(10) TEXT-040.
PARAMETERS X_M01 LIKE RESB-MATNR.
SELECTION-SCREEN COMMENT 35(01) TEXT-050.
PARAMETERS X_Q01 LIKE RESB-ERFMG.
SELECTION-SCREEN END OF LINE.
SKIP.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 05(10) TEXT-040.
PARAMETERS X_M02 LIKE RESB-MATNR.
SELECTION-SCREEN COMMENT 35(01) TEXT-050.
PARAMETERS X_Q02 LIKE RESB-ERFMG.
SELECTION-SCREEN END OF LINE.
SKIP.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 05(10) TEXT-040.
PARAMETERS X_M03 LIKE RESB-MATNR.
SELECTION-SCREEN COMMENT 35(01) TEXT-050.
PARAMETERS X_Q03 LIKE RESB-ERFMG.
SELECTION-SCREEN END OF LINE.
SKIP.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 05(10) TEXT-040.
PARAMETERS X_M04 LIKE RESB-MATNR.
SELECTION-SCREEN COMMENT 35(01) TEXT-050.
PARAMETERS X_Q04 LIKE RESB-ERFMG.
SELECTION-SCREEN END OF LINE.
SKIP.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 05(10) TEXT-040.
PARAMETERS X_M05 LIKE RESB-MATNR.
SELECTION-SCREEN COMMENT 35(01) TEXT-050.
PARAMETERS X_Q05 LIKE RESB-ERFMG.
SELECTION-SCREEN END OF LINE.
SKIP.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 05(10) TEXT-040.
PARAMETERS X_M06 LIKE RESB-MATNR.
SELECTION-SCREEN COMMENT 35(01) TEXT-050.
PARAMETERS X_Q06 LIKE RESB-ERFMG.
SELECTION-SCREEN END OF LINE.
SKIP.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 05(10) TEXT-040.
PARAMETERS X_M07 LIKE RESB-MATNR.
SELECTION-SCREEN COMMENT 35(01) TEXT-050.
PARAMETERS X_Q07 LIKE RESB-ERFMG.
SELECTION-SCREEN END OF LINE.
SKIP.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 05(10) TEXT-040.
PARAMETERS X_M08 LIKE RESB-MATNR.
SELECTION-SCREEN COMMENT 35(01) TEXT-050.
PARAMETERS X_Q08 LIKE RESB-ERFMG.
SELECTION-SCREEN END OF LINE.
SKIP.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 05(10) TEXT-040.
PARAMETERS X_M09 LIKE RESB-MATNR.
SELECTION-SCREEN COMMENT 35(01) TEXT-050.
PARAMETERS X_Q09 LIKE RESB-ERFMG.
SELECTION-SCREEN END OF LINE.
SKIP.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 05(10) TEXT-040.
PARAMETERS X_M10 LIKE RESB-MATNR.
SELECTION-SCREEN COMMENT 35(01) TEXT-050.
PARAMETERS X_Q10 LIKE RESB-ERFMG.
SELECTION-SCREEN END OF LINE.
PERFORM AUTHORITY_CHECK.
PERFORM GM_DATA.
* CHECK WHETHER TABLE IS EMPTY
IF GM_ITEM[] is initial.
FORMAT COLOR COL_NEGATIVE.
WRITE: / 'All Material are EMPTY'.
ELSEIF AUTH_FLG = 'X'.
FORMAT COLOR COL_NEGATIVE.
WRITE: / 'Please obtain all your necessary Authorization'.
ELSE.
PERFORM BAPI_CREATE_311.
ENDIF.
FORM AUTHORITY_CHECK.
CLEAR AUTH_FLG.
FORMAT COLOR COL_NEGATIVE.
AUTHORITY-CHECK OBJECT 'M_MRES_WWA'
ID 'ACTVT' FIELD '03'
ID 'WERKS' FIELD X_WERKS.
IF SY-SUBRC NE 0.
AUTH_FLG = 'X'.
WRITE:/ 'You are not authorised for Plant :', X_WERKS.
ENDIF.
AUTHORITY-CHECK OBJECT 'M_MRES_BWA'
ID 'ACTVT' FIELD '03'
ID 'BWART' FIELD X_BWART.
IF SY-SUBRC NE 0.
AUTH_FLG = 'X'.
WRITE:/ 'You are not authorised for Movement Type :', X_BWART.
ENDIF.
AUTHORITY-CHECK OBJECT 'M_MSEG_LGO'
ID 'ACTVT' FIELD '03'
ID 'BWART' FIELD X_REC01.
IF SY-SUBRC NE 0.
AUTH_FLG = 'X'.
WRITE:/ 'You are not authorised for Storage Location :', X_REC01.
ENDIF.
AUTHORITY-CHECK OBJECT 'M_MSEG_LGO'
ID 'ACTVT' FIELD '03'
ID 'BWART' FIELD X_ISS01.
IF SY-SUBRC NE 0.
AUTH_FLG = 'X'.
WRITE:/ 'You are not authorised for Storage Location :', X_ISS01.
ENDIF.
IF X_M01 <> SPACE.
GM_ITEM-MATERIAL = X_M01.
GM_ITEM-QUANTITY = X_Q01.
PERFORM AUTHORITY_MARA.
TRANSLATE GM_ITEM TO UPPER CASE.
APPEND GM_ITEM.
ENDIF.
IF X_M02 <> SPACE.
GM_ITEM-MATERIAL = X_M02.
GM_ITEM-QUANTITY = X_Q02.
PERFORM AUTHORITY_MARA.
TRANSLATE GM_ITEM TO UPPER CASE.
APPEND GM_ITEM.
ENDIF.
IF X_M03 <> SPACE.
GM_ITEM-MATERIAL = X_M03.
GM_ITEM-QUANTITY = X_Q03.
PERFORM AUTHORITY_MARA.
TRANSLATE GM_ITEM TO UPPER CASE.
APPEND GM_ITEM.
ENDIF.
IF X_M04 <> SPACE.
GM_ITEM-MATERIAL = X_M04.
GM_ITEM-QUANTITY = X_Q04.
PERFORM AUTHORITY_MARA.
TRANSLATE GM_ITEM TO UPPER CASE.
APPEND GM_ITEM.
ENDIF.
IF X_M05 <> SPACE.
GM_ITEM-MATERIAL = X_M05.
GM_ITEM-QUANTITY = X_Q05.
PERFORM AUTHORITY_MARA.
TRANSLATE GM_ITEM TO UPPER CASE.
APPEND GM_ITEM.
ENDIF.
IF X_M06 <> SPACE.
GM_ITEM-MATERIAL = X_M06.
GM_ITEM-QUANTITY = X_Q06.
PERFORM AUTHORITY_MARA.
TRANSLATE GM_ITEM TO UPPER CASE.
APPEND GM_ITEM.
ENDIF.
IF X_M07 <> SPACE.
GM_ITEM-MATERIAL = X_M07.
GM_ITEM-QUANTITY = X_Q07.
PERFORM AUTHORITY_MARA.
TRANSLATE GM_ITEM TO UPPER CASE.
APPEND GM_ITEM.
ENDIF.
IF X_M08 <> SPACE.
GM_ITEM-MATERIAL = X_M08.
GM_ITEM-QUANTITY = X_Q08.
PERFORM AUTHORITY_MARA.
TRANSLATE GM_ITEM TO UPPER CASE.
APPEND GM_ITEM.
ENDIF.
IF X_M09 <> SPACE.
GM_ITEM-MATERIAL = X_M09.
GM_ITEM-QUANTITY = X_Q09.
PERFORM AUTHORITY_MARA.
TRANSLATE GM_ITEM TO UPPER CASE.
APPEND GM_ITEM.
ENDIF.
IF X_M10 <> SPACE.
GM_ITEM-MATERIAL = X_M10.
GM_ITEM-QUANTITY = X_Q10.
PERFORM AUTHORITY_MARA.
TRANSLATE GM_ITEM TO UPPER CASE.
APPEND GM_ITEM.
ENDIF.
ENDFORM.
FORM AUTHORITY_MARA.
FORMAT COLOR COL_NEGATIVE.
CLEAR MARA.
SELECT SINGLE * FROM MARA WHERE MATNR = GM_ITEM-MATERIAL.
AUTHORITY-CHECK OBJECT 'Z:EXTWG'
ID 'ACTVT' FIELD '03'
ID 'EXTWG' FIELD MARA-EXTWG.
IF SY-SUBRC NE 0.
AUTH_FLG = 'X'.
WRITE:/ 'You are not authorised for this Parts :',
MARA-MATNR, MARA-EXTWG.
ENDIF.
FORMAT COLOR OFF.
ENDFORM.
*---------------------------------------------------------------------*
* FORM bapi_create_311 *
*---------------------------------------------------------------------*
* ........ *
*---------------------------------------------------------------------*
form bapi_create_311.
data: RES_NO like BAPIRKPFC-RES_NO,
TLINES TYPE I.
DESCRIBE TABLE ZRETURN LINES TLINES.
IF TLINES GT 0.
format color col_negative.
write : / 'Update Failed.', zreturn-message(200), 255 ' '.
ELSE.
format color col_normal.
WRITE : / RES_NO,
'Reservation created successfully ', 255 ' '.
ENDIF.
FORMAT COLOR OFF.
* Delay
CALL FUNCTION 'FMCT_WAIT_FOR_UPDATE'
EXPORTING
I_SEC = 4.
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 cannot 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.