Vous êtes sur la page 1sur 10

1.

BAPI- How to Use Standard BAPI


_________________________________________________________________________________
Business Scenario: Suppose in an Organization for some Maintenance activity they need a Grinder Machine . It
might be the case that the Machine is already there and they can reserve the machine for some day(why
reservation of the machine like in a big org they can have multiple maintenance activities and some of them
may need the same machine) but what if the Machine is not there. That time the Org takes the decision to get it
from Vendors for which the Purchasing dept should raise a Purchase requisition ,then Purchase order and at last
the vendor supplies the goods.
In SAP R/3 the issue can be replicated by Creating a Reservation(Tx-MB21) which says that there is a
requirement for some material and then they go to Tx-ME51N and Create the Purchase Requisition and then Pur
Order . This all needs front end interaction with the SAP GUI.
Here the Org can take the Decision that when ever there is any requirement for a Material the Purchase
Requisition should generate automatically and also the Purchase Order by some background job.
In such case we can use the Standard BAPI: 'BAPI_PR_CREATE' to generate the Purchase Requisition from the
Reservation .
_________________________________________________________________________________
Step1. Go to Tx- MB21 to create a reservation of material.

[http://4.bp.blogspot.com/-Tj5JftmShx4/U6LjYZybJ8I/AAAAAAAAJZk/3JiGKj0Ba8U/s1600/1.JPG]

Step2. Provide the details and click on Create Button.

[http://1.bp.blogspot.com/-OFcoVxQDNh4/U6LjaXcvomI/AAAAAAAAJag/uumw2NTDnSQ/s1600/2.JPG]

Step3. Provide the cost center and Material number, quantity, plant and storage location. It signifies that this plant needs
material for the Maintenance activity.

[http://1.bp.blogspot.com/-_OB02E6un6M/U6Ljaj8mz4I/AAAAAAAAJaQ/HJpg3SRrjzM/s1600/3.JPG]

Step4. Save it.

[http://2.bp.blogspot.com/-5s2mosQHoCg/U6Ljb1FKy2I/AAAAAAAAJaY/7TCPgkOPGYA/s1600/4.JPG]

Step5. Teh Reservation Number is generated.

[http://1.bp.blogspot.com/-tFcvvhoFsC8/U6Ljc_WXDZI/AAAAAAAAJao/SSG-GO2pevI/s1600/5.JPG]

Step6. The Reservations are stored in the Table: RESB.

[http://1.bp.blogspot.com/-fYjMV2XQcfo/U6LjdLSPiSI/AAAAAAAAJa0/yU77cdjkduo/s1600/6.JPG]

Step7. Then the User Run the Tx: ME51N to cretae a purchase requisition for the required material quantity .

[http://4.bp.blogspot.com/-zEeiJci7LZE/U6LjdgYzybI/AAAAAAAAJbY/1ij7E0pZoPM/s1600/7.JPG]

Step8. Pur Req- Doc type is NB. Provides the material number and quantity and creates a purchase requisition.

[http://1.bp.blogspot.com/-qfla2Em1FRw/U6Ljd1fXapI/AAAAAAAAJbQ/QXUyfBkldzI/s1600/8.JPG]

Step9. The below Pur Requisition is generated which can be displayed in ME53N.

[http://4.bp.blogspot.com/-wJoYtoVIBVI/U6LjedkBMoI/AAAAAAAAJbM/5wAkRqep8vc/s1600/9.JPG]

Step10. Lets Automate the process by Using BAPI fm. The Bapi: BAPI_PR_CRETAE can be used to create the bapi in
background.

[http://3.bp.blogspot.com/--YyY7zVTTZ4/U6LjYh0FQYI/AAAAAAAAJbI/q6lFA3eseuc/s1600/11.JPG]

Step11. Create a message class to show our message.

[http://4.bp.blogspot.com/-spIGor3hy9w/U6LjYsH_uWI/AAAAAAAAJaA/xnsorkdce4w/s1600/10.JPG]

_________________________________________________________________________________
Step12. Below report creates the Purchase requisition for the selected Reservation.
REPORT zres_pr_create MESSAGE-ID ZPR_CRT.
TYPE-POOLS : slis.
DATA :
lt_resb TYPE TABLE OF resb.
START-OF-SELECTION.
SELECT * FROM resb INTO TABLE lt_resb WHERE bdter = sy-datum. " Get all reservation
" created on the current date
SORT lt_resb BY rsnum rspos.
END-OF-SELECTION.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program
= sy-cprog
i_callback_pf_status_set = 'FM_STATUS'

i_callback_user_command = 'CRT_PR'
i_structure_name
= 'RESB'
i_grid_title
= 'Showing Todays Material Reservation'
TABLES
t_outtab
= lt_resb.
*&---------------------------------------------------------------------*
*&
Form FM_status
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
FORM fm_status USING rt_extab TYPE slis_t_extab.
SET PF-STATUS 'STATUS_PR' EXCLUDING rt_extab. " Create Pf status for appl toolbar Button
ENDFORM.
"fm_status
*&---------------------------------------------------------------------*
*&
Form crt_pr
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
*
-->R_UCOMM
text
*
-->RS_SELFIELD text
*----------------------------------------------------------------------*
FORM crt_pr USING r_ucomm LIKE sy-ucomm
rs_selfield TYPE slis_selfield.
DATA : it_resb TYPE TABLE OF resb,
ls_resb TYPE resb,
pos
TYPE rspos .
DATA : ls_hdr
TYPE bapimereqheader,
ls_hdr_x
TYPE bapimereqheaderx,
pr_num
TYPE bapimereqheader-preq_no,
t_ret
TYPE TABLE OF bapiret2,
s_ret
TYPE bapiret2,
t_pritm
TYPE TABLE OF bapimereqitemimp,
s_pritm
TYPE bapimereqitemimp,
t_pritmx
TYPE TABLE OF bapimereqitemx,
s_pritmx
TYPE bapimereqitemx.
IF rs_selfield-sel_tab_field = '1-RSNUM'. " CHeck if the User Single-click on the Reservation No.
LOOP AT lt_resb INTO ls_resb WHERE rsnum = rs_selfield-value . " Read the Reservation Value
APPEND ls_resb TO it_resb.
CLEAR ls_resb.
ENDLOOP.
** The Reservation Records are Ready in the Internal Table it_resb**
** FILL Header ****
ls_hdr-pr_type = 'NB'. " Pur Requisition Document type
ls_hdr_x-pr_type = 'X'.
****fill item***
LOOP AT it_resb INTO ls_resb .
pos
= 10 + ls_resb-rspos - 1.
s_pritm-preq_item
= pos.
s_pritm-pur_group
= '011'.
" pur group

s_pritm-preq_name = 'SHIPPING'. " requisitioner name


s_pritm-material
= ls_resb-matnr. " material Number
s_pritm-plant
= ls_resb-werks. " plant number
s_pritm-store_loc
= ls_resb-lgort. " storage loc
s_pritm-quantity
= ls_resb-bdmng. " quantity
s_pritm-unit
= ls_resb-meins. " unit
s_pritm-deliv_date
= sy-datum + 10 . " delivery date of goods
s_pritm-reserv_no
= ls_resb-rsnum. " reservation number
APPEND s_pritm TO t_pritm.
CLEAR : ls_resb, s_pritm.
*****fill item text ***
s_pritmx-preq_item
= pos.
s_pritmx-preq_itemx = 'X'.
s_pritmx-pur_group
= 'X'.
s_pritmx-preq_name = 'X'.
s_pritmx-material
= 'X'.
s_pritmx-plant
= 'X'.
s_pritmx-store_loc
= 'X'.
s_pritmx-quantity
= 'X'.
s_pritmx-unit
= 'X'.
s_pritmx-deliv_date = 'X'.
APPEND s_pritmx TO t_pritmx.
CLEAR s_pritmx.
ENDLOOP.
CASE r_ucomm.
WHEN 'CRT_PR'. " Fcode when the user clicks on the Appl Tool Bar Button "Create Pur Req" .
CALL FUNCTION 'BAPI_PR_CREATE' " Call this bapi and pass the values
EXPORTING
prheader = ls_hdr
prheaderx = ls_hdr_x
IMPORTING
number = pr_num
TABLES
return = t_ret " return message is store in this table
pritem = t_pritm
pritemx = t_pritmx.
IF sy-subrc = 0.
READ TABLE t_ret INTO s_ret WITH KEY type = 'S'.
IF sy-subrc = 0.
MESSAGE I000 WITH s_ret-message_v1 rs_selfield-value.
COMMIT WORK.
ENDIF.
ELSE.
ROLLBACK WORK.
ENDIF.
ENDCASE.
ENDIF.
ENDFORM. "CRT_PR

_________________________________________________________________________________
Step13. Create the PF status with below application tool bar Button.

[http://1.bp.blogspot.com/-XvOPCHEhYwA/U6LjZJf0PGI/AAAAAAAAJbE/sZlOUTylvY8/s1600/12.JPG]

Step14. Run the report and we can see all the Reservations created for the current date.

[http://2.bp.blogspot.com/-YT3pNTCdSVQ/U6LjZZtd7aI/AAAAAAAAJaw/A2IGbbZ8k-Q/s1600/13.JPG]

Step15. Select any one and click on the Button Cretae Pur Requisition.

[http://4.bp.blogspot.com/-TU6fUZb7WRU/U6LjZhToi2I/AAAAAAAAJaI/s0U7w4P42TA/s1600/14.JPG]

Step16. The BAPI is executed and the Pur Req. is generated which can be viewed in Tx- ME53N.

[http://2.bp.blogspot.com/-yW4R5zdwyVY/U6LjaDwD2aI/AAAAAAAAJbU/KwJlJP0KycA/s1600/15.JPG]

_________________________________________________________________________________
Posted 19th June 2014 by S Prasad
0

View comments

No comments yet

Add a comment

Vous aimerez peut-être aussi