Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Updating Purchase Requisition Line item with Fixed Vendor

former_member755502
Participant
0 Kudos
2,937


Hi,

I have a requirement where existing Purchase Requisition line items need to be updated with "Fixed Vendor" (EBAN-FLIEF). I have chosen the BAPI - "BAPI_PR_CHANGE" for the same. The BAPI works fine for most the purchase requisition line items except where we have line items with contract. In those cases, the BAPI gives preference to existing "Vendor" found as per the "Contract" and doesnt update it with the "Vendor" supplied through the BAPI. The error that I get for those line items is "Vendor XXXXXXXXXX in agreement differs from fixed vendor"

Code snippet -

DATA : lit_bapiret2_tab1 TYPE STANDARD TABLE OF bapiret2,
            lit_pritem        TYPE STANDARD TABLE OF bapimereqitemimp,
            lit_pritemx       TYPE STANDARD TABLE OF bapimereqitemx.

DATA : lw_pritem  TYPE bapimereqitemimp,
             lw_pritemx TYPE bapimereqitemx,
             lw_file    TYPE gty_file,
             lw_bapiret2 TYPE bapiret2.

LOOP AT git_final ASSIGNING <lf_final>.      "Internal table with all Purchase Requisition number and line item number

REFRESH : lit_bapiret2_tab1,
                    lit_pritem,
                    lit_pritemx.


CLEAR : lw_pritem,
               lw_pritemx.

lw_pritem-preq_item = <lf_final>-qtc_bnfpo.
lw_pritem-fixed_vend = <lf_final>-new_lifnr. "New FIxed Vendor

APPEND lw_pritem TO lit_pritem.

lw_pritemx-preq_item = <lf_final>-qtc_bnfpo.
lw_pritemx-fixed_vend = abap_true.

APPEND lw_pritemx TO lit_pritemx.

CALL FUNCTION 'BAPI_PR_CHANGE'
          EXPORTING
            number  = <lf_final>-qtc_banfn
          TABLES
            return  = lit_bapiret2_tab1
            pritem  = lit_pritem
            pritemx = lit_pritemx.

READ TABLE lit_bapiret2_tab1 INTO lw_bapiret2
WITH KEY type = lc_type_e.

IF sy-subrc NE 0.

     CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
            EXPORTING
              wait   = abap_true
            IMPORTING
              return = lw_bapiret2.

ELSE.

     "Capture Error Message

ENDIF.

ENDLOOP.

As I understand, I need to update EBAN-VRTYP as "BLANK, EBAN-KONNR as "BLANK" and EBAN-KTPNR as "BLANK" too along with EBAN-FLIEF with the new Vendor value for those line items. But I do not know the BAPI which can help me with this. The BAPI BAPI_PR_CHANGE has "TABLES" paramteres "PRITEMEXP" and "PRITEMSOURCE" with fileds "DOC_CAT" (EBAN-VRTYP), "AGGREMENT" (EBAN-KONNR) and "AGMT_ITEM" (EBAN-KTPNR) but they are all return structures. Hence they dont help in updating the fields I am intereted in. Though this update is possible manually through ME52N transaction.

Kindly, help me with the BAPI or any other means to achieve this.

Regards,

Sambaran

1 ACCEPTED SOLUTION

raymond_giuseppi
Active Contributor
0 Kudos
780

Look better/again at parameter PRITEM, you should find AGREEMENT, AGMT_ITEM, etc.

Regards,

Raymond

13 REPLIES 13

raymond_giuseppi
Active Contributor
0 Kudos
781

Look better/again at parameter PRITEM, you should find AGREEMENT, AGMT_ITEM, etc.

Regards,

Raymond

0 Kudos
780

Thanks Raymond for your response. Yes, indeed PRITEM has AGREEMENT and AGMT_ITEM but it doesnt have "Document Category" i.e. EBAN-VRTYP. I was under the impression that "Doc_Cat" or EBAN-VRTYP is also important for this update but I will give your suggestion a try.

0 Kudos
780

Hi Raymmond,

I tried your suggestion but it doesnt work though I dont get the old error but I get a new one - "Please enter document number and item together".

I used the following test program -

DATA : lit_bapiret2_tab1 TYPE STANDARD TABLE OF bapiret2,
             lit_pritem             TYPE STANDARD TABLE OF bapimereqitemimp,
             lit_pritemx           TYPE STANDARD TABLE OF bapimereqitemx.

DATA : lw_pritem  TYPE bapimereqitemimp,
            lw_pritemx TYPE bapimereqitemx,
            lw_pritemexp TYPE bapimereqitem.

PARAMETERS : p_banfn TYPE banfn,
                            p_bnfpo TYPE bnfpo,
                            p_lifnr TYPE lifnr.

lw_pritem-preq_item = p_bnfpo.
lw_pritem-fixed_vend = p_lifnr.
lw_pritem-agreement = ''.
lw_pritem-agmt_item = ''.

APPEND lw_pritem TO lit_pritem.

lw_pritemx-preq_item = p_bnfpo.
lw_pritemx-fixed_vend = 'X'.
lw_pritemx-agreement = 'X'.
lw_pritemx-agmt_item = 'X'.

APPEND lw_pritemx TO lit_pritemx.

CALL FUNCTION 'BAPI_PR_CHANGE'
  EXPORTING
    number                      = p_banfn
*   PRHEADER                    =
*   PRHEADERX                   =
*   VERSIONS                    =
*   TESTRUN                     =
* IMPORTING

*   PRHEADEREXP                 =
TABLES
   return                      = lit_bapiret2_tab1
   pritem                      = lit_pritem
   pritemx                     = lit_pritemx

*   PRITEMEXP                   =
*   PRITEMSOURCE                =
*   PRACCOUNT                   =
*   PRACCOUNTPROITSEGMENT       =
*   PRACCOUNTX                  =
*   PRADDRDELIVERY              =
*   PRITEMTEXT                  =
*   PRHEADERTEXT                =
*   EXTENSIONIN                 =
*   EXTENSIONOUT                =
*   PRVERSION                   =
*   PRVERSIONX                  =
*   ALLVERSIONS                 =

          .

READ TABLE lit_bapiret2_tab1 TRANSPORTING NO FIELDS
WITH KEY type = 'E'.

IF sy-subrc EQ 0.
  BREAK-POINT.
ENDIF.

Let me know if I am missing anything.

JL23
Active Contributor
0 Kudos
780

It does not make sense to have a fixed vendor that is different from the vendor of the agreement.

This is a hard error 06555

*--- Lieferant im Vertrag drin ----------------------------------------*

     IF ekko-lifnr NE space.

       IF comim-flief NE space AND comim-flief NE ekko-lifnr.

         SET CURSOR FIELD 'EBAN-FLIEF'.

         mmpur_metafield mmmfd_fixed_vend.

         MESSAGE e555 WITH ekko-lifnr.

       ENDIF.

0 Kudos
780

Thanks Jurgen for your response. But let me provide more information about the change we are trying to implement. We are trying unify POs with multiple vendors to a PO with one new vendor. Here, the POs under considerarion are unprocessed POs. To be able to do so, we are first identifying those POs which are not processed at all (mostly latest POs) then cancelling them in the system. After that, we are updating the corresponding sales orders and purchase requisitions. And eventually, we are generating new POs referencing these newly updated PRs (using ME59N transaction). Now, the query is related to the PR update. All these changes are done through programs except the last step of creation of new POs. Let me know if you have any further query or if you can suggest any alternative to achieve this PR update part.

JL23
Active Contributor
0 Kudos
780

Before you do anything per program you should try whether this is possible using the online transactions. This approach can give you immediately the information whether you missed something in your program or if it is not possible at all.

The normal way from a PR to a PO is via a source assignment.

A source can be an agreement, an info record, a fixed vendor .

If you just enter a new fixed vendor into a PR without removing or exchanging the assignment to an outline agreement, then you created contradictory information, hence you get this error.


0 Kudos
780

I agree with you. I tried doing it using ME52N and it works. I can remove the agreement details from the PR line item along with the vendor it is associated with and can update the new vendor for which info-record and sourcelist (as Fixed Vendor) already being created in the system. I want to achieve the same through ABAP program.

JL23
Active Contributor
0 Kudos
780

if you do not want the reference to the contract, then you need to empty those fields. Raymond gave you already the hint where to do this.

0 Kudos
780

Hi Jurgen,

As I mentioned in my reply to Raymond - the suggestion he gave didnt work as expected.

JL23
Active Contributor
0 Kudos
780

I see this much different. He gave you a hint where to look, you changed your coding and the error was gone.  So this was a very helpful answer from my point of view.

You are actually a step further but you get stuck with another error. ""Please enter document number and item together"."

How do you understand this error?

I understand that either the PO number is missing and the PO item number is there, or the other way around, that you just entered a PO number but missed the PO item number.

0 Kudos
780

Yes indeed Raymond's hint was useful. However, now with the current error I tried hardcoding values directly in the structures but still it is not resolving the issue. I dont think any value is missing.

Code snippet -

lw_bapimereqheader-preq_no = '1040015163'.


lw_pritem-preq_item = '00003'.
lw_pritem-fixed_vend = '0000095281'.
lw_pritem-agreement = abap_false.
lw_pritem-agmt_item = abap_false.

APPEND lw_pritem TO lit_pritem.

lw_pritemx-preq_item = '00003'.
lw_pritemx-preq_itemx = abap_true.
lw_pritemx-fixed_vend = abap_true.
lw_pritemx-agreement = abap_true.
lw_pritemx-agmt_item = abap_true.

APPEND lw_pritemx TO lit_pritemx.

CALL FUNCTION 'BAPI_PR_CHANGE'
  EXPORTING
    number  = lw_bapimereqheader-preq_no
  TABLES
    return  = lit_bapiret2_tab
    pritem  = lit_pritem
    pritemx = lit_pritemx.

0 Kudos
780

This message is related to agreement number/item number :

AGMT_ITEM is numeric, so I will suppose error get triggered by  AGREEMENT EQ SPACE AND AGMT_ITEM IS NOT INITIAL (here value space and not the expected zero?) try to initialize to 00000 and not space (Hint: Perform some where-used on error message from SE91 when you din't understand such message)

Regards,

Raymond

former_member755502
Participant
0 Kudos
780

Hi All,

Thanks to everyone for your suggestion. What I was trying to achieve, I managed to achieve that using the BAPI BAPI_REQUISITION_CHANGE.