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

Create Purchase Requisition (PR) using BAPI_PR_CREATE



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



Joined: 01 Sep 2007
Posts: 1636

PostPosted: Fri Nov 23, 2007 11:11 pm    Post subject: Create Purchase Requisition (PR) using BAPI_PR_CREATE Reply with quote

Code:
FUNCTION Z_NPIP_PR_CREATE .
*"----------------------------------------------------------------------
*"*"Local Interface:
*" EXPORTING
*" VALUE(NUMBER) LIKE BAPIMEREQHEADER-PREQ_NO
*" TABLES
*" PRITEM STRUCTURE BAPIMEREQITEMIMP
*" PRHEADERTEXT STRUCTURE BAPIMEREQHEADTEXT OPTIONAL
*" RETURN STRUCTURE BAPIRET2 OPTIONAL
*"----------------------------------------------------------------------



DATA : S_HEADER LIKE BAPIMEREQHEADER OCCURS 0 WITH HEADER LINE.
S_HEADER-PR_TYPE = 'NB'.
* S_HEADER-CTRL_IND = 'X'.
* S_HEADER-GENERAL_RELEASE = 'X'.
* S_HEADER-CREATE_IND = 'X'.
* S_HEADER-ITEM_INTVL = 0000.
* S_HEADER-LAST_ITEM = 0000.
* S_HEADER-AUTO_SOURCE = 'X'.
* S_HEADER-MEMORY = 'X'.
APPEND S_HEADER.
*
DATA : S_HEADERX LIKE BAPIMEREQHEADERX OCCURS 0 WITH HEADER LINE.
S_HEADERX-PR_TYPE = 'X'.
* S_HEADER-CTRL_IND = 'X'.
* S_HEADER-GENERAL_RELEASE = 'X'.
* S_HEADER-CREATE_IND = 'X'.
* S_HEADER-ITEM_INTVL = 'X'.
* S_HEADER-LAST_ITEM = 'X'.
* S_HEADER-AUTO_SOURCE = 'X'.
* S_HEADER-MEMORY = 'X'.
*
*
APPEND S_HEADERX.

DATA : S_ITEMX LIKE BAPIMEREQITEMX OCCURS 0 WITH HEADER LINE.
S_ITEMX-MATERIAL = 'X'.
S_ITEMX-PLANT = 'X'.
S_ITEMX-QUANTITY = 'X'.
S_ITEMX-DELIV_DATE = 'X'.

APPEND S_ITEMX.

DATA : S_ITEMEXP LIKE BAPIMEREQITEM OCCURS 0 WITH HEADER LINE.
S_ITEMEXP-DOC_TYPE = 'NB'.

APPEND S_ITEMEXP.

CALL FUNCTION 'BAPI_PR_CREATE'
EXPORTING
PRHEADER = S_HEADER
PRHEADERX = S_HEADERX
* VERSIONS =
* TESTRUN =
IMPORTING
NUMBER = NUMBER
* PRHEADEREXP =
TABLES
RETURN = RETURN
PRITEM = PRITEM
PRITEMX = S_ITEMX
PRITEMEXP = S_ITEMEXP
* PRITEMSOURCE =
* PRACCOUNT =
* PRACCOUNTPROITSEGMENT =
* PRACCOUNTX =
* PRADDRDELIVERY =
* PRITEMTEXT =
PRHEADERTEXT = PRHEADERTEXT
* EXTENSIONIN =
* EXTENSIONOUT =
* PRVERSION =
* PRVERSIONX =
* ALLVERSIONS =
.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
* EXPORTING
* WAIT =
* IMPORTING
* RETURN =
.

ENDFUNCTION.


Example 2
Code:
REPORT  z_datainit_me51n  .

TABLES:eban.
DATA: BEGIN OF itab OCCURS 0,
     NO(5),
     bnfpo LIKE eban-bnfpo,
     bsart LIKE eban-bsart,
     matnr LIKE eban-matnr,
     lgort LIKE eban-lgort,
     menge LIKE eban-menge,
     bednr LIKE eban-bednr,
     lfdat LIKE eban-lfdat,
     TX(132),
     END OF itab.


DATA :

prheader LIKE TABLE OF bapimereqheader WITH HEADER LINE,
prheaderx LIKE TABLE OF bapimereqheaderx WITH HEADER LINE,
PRITEMEXP LIKE TABLE OF BAPIMEREQITEM WITH HEADER LINE,
return LIKE TABLE OF bapiret2 WITH HEADER LINE,
pritem LIKE TABLE OF bapimereqitemimp WITH HEADER LINE,
pritemx LIKE TABLE OF bapimereqitemx WITH HEADER LINE,
PRITEMTEXT LIKE TABLE OF BAPIMEREQITEMTEXT WITH HEADER LINE.


DATA auxfilename LIKE rlgrap-filename.

CALL FUNCTION 'UPLOAD'
 EXPORTING
   filename     = 'C:\PRCREATE.TXT'
   filetype     = 'DAT'
 IMPORTING
   act_filename = auxfilename
 TABLES
   data_tab     = itab.

IF sy-subrc <> 0.
 MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
         WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.


LOOP AT ITAB .

 prheader-pr_type = itab-bsart.
 APPEND prheader.
 CLEAR prheader.

 prheaderx-pr_type = 'X'.
 APPEND prheaderx.
 CLEAR prheaderx.

 pritem-preq_item = itab-bnfpo.
 pritem-material = itab-matnr.
 pritem-plant = '0100'.
 pritem-store_loc = itab-lgort.
 pritem-quantity = itab-menge.
 pritem-trackingno = itab-bednr.
 pritem-deliv_date = itab-lfdat.

 APPEND pritem.
 CLEAR pritem.

 pritemx-PREQ_ITEM = itab-bnfpo.
 pritemx-preq_itemX = 'X'.
 pritemx-material = 'X'.
 pritemx-plant = 'X'.
 pritemx-store_loc = 'X'.
 pritemx-quantity = 'X'.
 pritemx-trackingno = 'X'.
 pritemx-deliv_date = 'X'.
 pritemx-SHORT_TEXT = 'X'.

 APPEND pritemx.
 CLEAR pritemx.

 PRITEMTEXT-PREQ_ITEM = itab-BNFPO.
 PRITEMTEXT-TEXT_ID = 'B01'.
 PRITEMTEXT-TEXT_LINE = ITAB-TX.
 append PRITEMTEXT.
  CLEAR PRITEMTEXT.

ENDLOOP.

CALL FUNCTION 'BAPI_PR_CREATE'
* EXPORTING
*   VERSIONS                    =
*   SKIP_ITEMS_WITH_ERROR       =
*   TESTRUN                     =
* IMPORTING
*   PRNUMBER                    =
 TABLES
   RETURN     =  RETURN
   pritem     =  PRITEM
  PRITEMX     =  PRITEMX
*  PRITEMEXP    =  PRITEMEXP
*   PRITEMSOURCE                =
*   PRACCOUNT                   =
*   PRACCOUNTPROITSEGMENT       =
*   PRACCOUNTX                  =
*   PRADDRDELIVERY              =
  PRITEMTEXT  = PRITEMTEXT
*   PRHEADERTEXT                =
*   PRLIMITS                    =
*   PRCONTRACTLIMITS            =
*   PRSERVICES                  =
*   PRSRVACCESSVALUES           =
*   PRSERVICESTEXT              =
*   EXTENSIONIN                 =
*   EXTENSIONOUT                =
*   ALLVERSIONS                 =
 CHANGING
  PRHEADER   = PRHEADER
  PRHEADERX  = PRHEADERX .


CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.
REFRESH PRITEM.
REFRESH prheader.
REFRESH prheaderx.
REFRESH PRITEMX.
REFRESH PRITEMTEXT.
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 -> ММ 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 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.