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: 

How to add partner function via USEREXIT_SAVE_DOCUMENT_PREPARE?

former_member230666
Participant
0 Kudos
1,166

Hi Expert,

May i seek for your advice on how to add a new partner function via USEREXIT_SAVE_DOCUMENT_PREPARE without causing any update termination? The requirement is to check if there is no 'RE Bill-to party" maintained in a sales order under header partner function, then the program needs to automatically search the bill-to party via table KNVP that belongs to the sold-to party. Hope you are able to advice me. Thanks in advance.

Steps taken by me.

1. Create a new include program in user exit USEREXIT_SAVE_DOCUMENT_PREPARE.

2. My programming logic is as below:

READ TABLE xvbpa WITH KEY parvw = 'RE'.

lv_kunnr = xvbpa-kunnr.

IF sy-subrc <> 0.

   

    SELECT SINGLE kunn2 parvw Into (lv_kunn2, lv_parvw)

        FROM knvp

         WHERE kunnr = lv_kunnr

            AND   vkorg = xvbak-vkorg

            AND   vtweg = xbvak-vtweg

            AND   spart  = xbvak-spart

            AND   parvw = 'RE'.

   

    IF sy-subrc = 0.

        CLEAR: xvbpa.

        xvbpa-parvw = lv_parvw.

        xvbpa-kunnr = lv_kunn2.

        xvbpa-updkz = 'I'.

        APPEND xvbpa.

    ENDIF.

ENDIF.

Blocking point:

1. Whenever I save the sales document, there will be an update termination. I've tried to debug into the update termination, but i cannot understand
    what does it mean and i also could not find out why there is an update termination.

Regards,

Shawn

15 REPLIES 15

Former Member
0 Kudos
224

HI Try using 'BP' as partner function instead of using 'RE'.....

Regards

Amit

former_member187748
Active Contributor
0 Kudos
224

Hi Shawn,

have you checked your records, because as far as i know, this will happens when your data

have duplicate entries.

Use transaction SM13, to trace out the problem point.

0 Kudos
224

Hi Sanjeev,

This is the error message that i got in SM13. "The ABAP/4 Open SQL array insert results in duplicate database records.". I've checked that there is no duplicate records in XVBPA. Perhaps will it be ok for you to advice me further on how to check? Thanks.

0 Kudos
224

Hi Shawn,

as i told you these type of errors arises, when you wants to update an existing key fields,

it could be in any form, if after implementing the matters shown in this thread,

still you get the same error, then i will sujjest you to go through this link which

briefed about the same matters you are struggling for.

Short dump SAPSQL ARRAY INSERT DUPREC in delivery processing - ERP SCM - SCN Wiki

atul_mohanty
Active Contributor
0 Kudos
224

Hi - what is the value of  lv_parvw you are passing ?

reachdebopriya
Active Participant
0 Kudos
224

Hi Shawn,

Instead of updating xvbpa, update VBPA directly as below:

READ TABLE xvbpa WITH KEY parvw = 'RE'.

lv_kunnr = vbpa-kunnr.

IF sy-subrc <> 0.

  

    SELECT SINGLE kunn2 parvw Into (lv_kunn2, lv_parvw)

        FROM knvp

         WHERE kunnr = lv_kunnr

            AND   vkorg = vbak-vkorg

            AND   vtweg = vbak-vtweg

            AND   spart  = vbak-spart

            AND   parvw = 'RE'.

  

    IF sy-subrc = 0.

        CLEAR: xvbpa.

        vbpa-parvw = lv_parvw.

        vbpa-kunnr = lv_kunn2.

        vbpa-updkz = 'I'.

        APPEND vbpa.

    ENDIF.

ENDIF.

BR,

Debopriya Ghosh

0 Kudos
224

Hi Debopriya Ghosh,

VBPA cannot be append as it is a structure.

Regards,

Shawn

0 Kudos
224

Hi Shawn,

You can populate the XVBPA structure with function module "VIEW_XVBPA_FILL".

You have to pass the following values to the FM:

COMWA-KUNNR <- the changed partner code

COMWA-PARVW <- parter role

COMWA-VBELN, COMWA-POSNR <- Salesorder and item: just fill it with VBAK-VBELN,VBAP-POSNR

Apend the internal table XVBPA in the userexit.

Try to update XVBPA & XVBADR table both and check if it works. If this also does not work, check if the updation of tables works in UPDATE MODE like calling a Function in Update Task.

BR,

Debopriya Ghosh

Former Member
0 Kudos
224

Hi,

- Please use the conversion routine for the partner function - PARVW

-  XVBPA is the work area of the VBPA table. You have to be filled all the fields, where as you are appending the values, instead of modifying!

better to do it this way!

Loop at XVBpa.

ENDLOOP.

* getting wrong

IF sy-subrc = 0.

        CLEAR: xvbpa.

        xvbpa-parvw = lv_parvw.

        xvbpa-kunnr = lv_kunn2.

        xvbpa-updkz = 'I'.

        APPEND xvbpa.

    ENDIF.

ENDIF.

0 Kudos
224

Hi Kiran,

Do you mean that i need to feel in all the columns in xvbpa?

Regards,

Shawn

0 Kudos
224

Hi Kiran,

as i have sujjested him to check in SM13, he has got the message

This is the error message that i got in SM13. "The ABAP/4 Open SQL array insert results in duplicate database records."


Isn't he is trying to modify any existing key field.

0 Kudos
224

Hi Shwan,

The user-exit is not triggering item by item! The data is available in internal tables( XVBAP,XVBAK..ETC)

I understand that you want add the partner function to the existing sales order, am right?

try this below code.

LOOP AT XVBPA WHERE PARVW = RE.

l_tabix = sy-tabix.

lv_kunnr = xvbpa-kunnr.

IF sy-subrc <> 0.

  

    SELECT SINGLE kunn2 parvw Into (lv_kunn2, lv_parvw)

        FROM knvp

         WHERE kunnr = lv_kunnr

            AND   vkorg  =  xvbak-vkorg

            AND   vtweg = xvbak-vtweg

            AND   spart  = xvbak-spart

            AND   parvw = 'RE'.

  

    IF sy-subrc = 0.

        CLEAR: xvbpa.

        xvbpa-parvw = lv_parvw.

        vxbpa-kunnr = lv_kunn2.

        xvbpa-updkz = 'I'.

        modify xvbap index l_tabix.

    ENDIF.

ENDIF.

0 Kudos
224

Hi Sanjeev,

Yes, you are right. It is a duplicate record and i've also checked the customize setting for the partner function. In the settings it does not allow to have more than 1 partner for bill-to party. Therefore instead of using updkz = 'I', the logic should check if there is an existing partner for bill-to party in the sales document. If it exist then the flag for updkz should be "updkz = 'U'".

Former Member
0 Kudos
224

Hi,

You need to fill vbeln & posnr fields as well in XVBPA. The primary keys of VBPA are "VBELN", "POSNR" & "PARVW". it is dumping because you are only filling "PARVW" ;  i.e while updating values in table VBPA  the itab XVBPA contains

VBELN     POSNR     PARVW

                                  RE

                                  RE

which contains  duplicate entries w.r.t primary keys.

iIdeally, it should be ( if veln is  1111 , then)

VBELN  POSNR  PARVW

1111        10         RE

1111        20        RE

* Remove the clear XVBPA statement.

Regards,

DPM

nabheetscn
Active Contributor
0 Kudos
224

Hi Shawn

Can you please check in debugging how are partners details assigned. You want to default partners but you have only filled the parvw etc. Please check what values are in VBELN/POSNR and append the same

Nabheet