‎2020 Jun 02 12:30 PM
pr.txtHi Guys,
I am new to BAPI , I have created an PR using 'BAPI_PR_CREATE', but i got an runtime error ." In FM you can spectific only fields of spectific length and under PR header
Please help me on this issue..
I have pasted my piece of code here:-
‎2020 Jun 02 12:48 PM
Hello divsmart
Here are my comments to your code.
DATA: wa_header TYPE bapimereqheader-preq_no VALUE '0010000004',
wa_headerx TYPE bapimereqheaderx-preq_no VALUE 'X',The WA_HEADER and WA_HEADERX should be defined as structures.
DATA: wa_header TYPE bapimereqheader,
wa_headerx TYPE bapimereqheaderx.In these structures, you should provide any required and important information that is relevant for the whole PR document creation. You should not provide the PR document number, in most cases (unless the number range for this document type is defined as external). The document's number will be generates automatically by the system.
You have defined the item structures correctly. Also, the internal tables for items are fine.
it_item TYPE TABLE OF bapimereqitemimp,
wa_item TYPE bapimereqitemimp,
it_itemx TYPE TABLE OF bapimereqitemx,
wa_itemx TYPE bapimereqitemx,
**Assign the value for item's...
wa_item-preq_item = '10'.
wa_item-pur_group = 'WIN'.
wa_item-material = 'E001789'.
wa_item-plant = '1000'.
wa_item-store_loc = '9000'.
wa_item-preq_item = 'X'.
wa_item-pur_group = 'X'.
wa_item-material = 'X'.
wa_item-plant = 'X'.
wa_item-store_loc = 'X'.However, you're not adding the item structures to item tables after the structures are filled.
You need to use the APPEND or INSERT statements. For example:
APPEND wa_item TO it_item.Additionally, you're assigning the information about the modified fields the the incorrect structure. You're using the WA_ITEM structure, when you should be using the WA_ITEMX structure instead.
The PREQ_ITEM field of the WA_ITEMX structure should have the item number for which this structure holds the information.
wa_itemx-preq_item = '10'.
wa_itemx-pur_group = 'X'.
wa_itemx-material = 'X'.
wa_itemx-plant = 'X'.
wa_itemx-store_loc = 'X'.
APPEND wa_itemx TO it_itemx.If you want to get the number of the created document, you need to uncomment the NUMBER parameter of the function. If you want to get more details about the header of the document - then the PRHEADEREXP parameter.
CALL FUNCTION 'BAPI_PR_CREATE'
EXPORTING
prheader = wa_header
prheaderx = wa_headerx
* TESTRUN =
IMPORTING
NUMBER = lv_number
prheaderexp = wa_doc
TABLES
return = it_return
pritem = it_item
pritemx = it_itemx.
* PRITEMEXP =
* PRITEMSOURCE =
* PRACCOUNT =
* PRACCOUNTPROITSEGMENT =
* PRACCOUNTX =
* PRADDRDELIVERY =
* PRITEMTEXT =
* PRHEADERTEXT =
* EXTENSIONIN =
* EXTENSIONOUT =
* PRVERSION =
* PRVERSIONX =
* ALLVERSIONS =NUMBER is of type BANFN and PRHEADEREXP is a structure of type BAPIMEREQHEADER.
DATA:
lv_number TYPE banfn,
wa_doc TYPE bapimereqheader.Here is another example of how to use the BAPI: https://answers.sap.com/answers/7128805/view.html
Kind regards,
Mateusz‎2020 Jun 02 12:37 PM
Putting you code as a commend so it's clearly visible:
TABLES: eban.
DATA: wa_header TYPE bapimereqheader-preq_no VALUE '0010000004',
wa_headerx TYPE bapimereqheaderx-preq_no VALUE 'X',
* wa_doc TYPE bapimereqheader-pr_type VALUE 'NS',
it_item TYPE TABLE OF bapimereqitemimp,
wa_item TYPE bapimereqitemimp,
it_itemx TYPE TABLE OF bapimereqitemx,
wa_itemx TYPE bapimereqitemx,
it_return TYPE TABLE OF bapiret2,
wa_return TYPE bapiret2.
**Assign the value for item's...
wa_item-preq_item = '10'.
wa_item-pur_group = 'WIN'.
wa_item-material = 'E001789'.
wa_item-plant = '1000'.
wa_item-store_loc = '9000'.
wa_item-preq_item = 'X'.
wa_item-pur_group = 'X'.
wa_item-material = 'X'.
wa_item-plant = 'X'.
wa_item-store_loc = 'X'.
BREAK-POINT.
CALL FUNCTION 'BAPI_PR_CREATE'
EXPORTING
prheader = wa_header
prheaderx = wa_headerx
* TESTRUN =
* IMPORTING
* NUMBER =
* prheaderexp = wa_doc
TABLES
return = it_return
pritem = it_item
pritemx = it_itemx.
* PRITEMEXP =
* PRITEMSOURCE =
* PRACCOUNT =
* PRACCOUNTPROITSEGMENT =
* PRACCOUNTX =
* PRADDRDELIVERY =
* PRITEMTEXT =
* PRHEADERTEXT =
* EXTENSIONIN =
* EXTENSIONOUT =
* PRVERSION =
* PRVERSIONX =
* ALLVERSIONS =
WRITE: / 'TYPE : ' ,wa_return-type,
/'Id :' , wa_return-id,
/'Message : ' , wa_return-message.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
* EXPORTING
* WAIT =
IMPORTING
return = wa_return.
‎2020 Jun 02 12:40 PM
Hello divsmart
The obvious error here is that you don't fill up it_item or it_itemx internal tables and pass them empty to BAPI_PR_CREATE. You just maintain work area of the table i.e. wa_item structure.
Moreover you are using wa_item instead of wa_itemx in:
wa_item-preq_item = 'X'.
wa_item-pur_group = 'X'.
wa_item-material = 'X'.
wa_item-plant = 'X'.
wa_item-store_loc = 'X'.Best regards
Dominik Tylczynski
‎2020 Jun 02 12:48 PM
Hello divsmart
Here are my comments to your code.
DATA: wa_header TYPE bapimereqheader-preq_no VALUE '0010000004',
wa_headerx TYPE bapimereqheaderx-preq_no VALUE 'X',The WA_HEADER and WA_HEADERX should be defined as structures.
DATA: wa_header TYPE bapimereqheader,
wa_headerx TYPE bapimereqheaderx.In these structures, you should provide any required and important information that is relevant for the whole PR document creation. You should not provide the PR document number, in most cases (unless the number range for this document type is defined as external). The document's number will be generates automatically by the system.
You have defined the item structures correctly. Also, the internal tables for items are fine.
it_item TYPE TABLE OF bapimereqitemimp,
wa_item TYPE bapimereqitemimp,
it_itemx TYPE TABLE OF bapimereqitemx,
wa_itemx TYPE bapimereqitemx,
**Assign the value for item's...
wa_item-preq_item = '10'.
wa_item-pur_group = 'WIN'.
wa_item-material = 'E001789'.
wa_item-plant = '1000'.
wa_item-store_loc = '9000'.
wa_item-preq_item = 'X'.
wa_item-pur_group = 'X'.
wa_item-material = 'X'.
wa_item-plant = 'X'.
wa_item-store_loc = 'X'.However, you're not adding the item structures to item tables after the structures are filled.
You need to use the APPEND or INSERT statements. For example:
APPEND wa_item TO it_item.Additionally, you're assigning the information about the modified fields the the incorrect structure. You're using the WA_ITEM structure, when you should be using the WA_ITEMX structure instead.
The PREQ_ITEM field of the WA_ITEMX structure should have the item number for which this structure holds the information.
wa_itemx-preq_item = '10'.
wa_itemx-pur_group = 'X'.
wa_itemx-material = 'X'.
wa_itemx-plant = 'X'.
wa_itemx-store_loc = 'X'.
APPEND wa_itemx TO it_itemx.If you want to get the number of the created document, you need to uncomment the NUMBER parameter of the function. If you want to get more details about the header of the document - then the PRHEADEREXP parameter.
CALL FUNCTION 'BAPI_PR_CREATE'
EXPORTING
prheader = wa_header
prheaderx = wa_headerx
* TESTRUN =
IMPORTING
NUMBER = lv_number
prheaderexp = wa_doc
TABLES
return = it_return
pritem = it_item
pritemx = it_itemx.
* PRITEMEXP =
* PRITEMSOURCE =
* PRACCOUNT =
* PRACCOUNTPROITSEGMENT =
* PRACCOUNTX =
* PRADDRDELIVERY =
* PRITEMTEXT =
* PRHEADERTEXT =
* EXTENSIONIN =
* EXTENSIONOUT =
* PRVERSION =
* PRVERSIONX =
* ALLVERSIONS =NUMBER is of type BANFN and PRHEADEREXP is a structure of type BAPIMEREQHEADER.
DATA:
lv_number TYPE banfn,
wa_doc TYPE bapimereqheader.Here is another example of how to use the BAPI: https://answers.sap.com/answers/7128805/view.html
Kind regards,
Mateusz‎2020 Jun 03 5:57 AM
Hi Mateusz,
Thanks for your swift response , Now my BAPI working fine & all data's are upload as per my requirment..
Your are great!!! Rewards point as 10...
Regards,
Senthil.G
‎2020 Jun 03 7:09 AM
Thanks. I'm glad it worked out.
Kind regards,‎2020 Jun 02 12:56 PM
Dominik Tylczynski. Thanks for response...
I have changed the 'wa_itemx' as below.
wa_itemx-preq_item = 'X'.wa_itemx-pur_group = 'X'. wa_itemx-material = 'X'. wa_itemx-plant = 'X'. wa_itemx-store_loc = 'X'. but 'My Error is in PR Header' as mentioned above 'In FM you can spectific only fields of spectific length and under PR header... ' Please help...
‎2020 Jun 02 2:10 PM
Hello divsmart
Please use the "Comment" option to ask or add additional information to the question/answer.
Kind regards,