Application Development and Automation 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: 
Read only

User exit code!

Former Member
0 Likes
1,428

Hello all,

I am trying to modify 'ROUTE' field in VBAP in the exit 'userexit_document_save'. It is modifying the xvbap table but when the sales order is created that value is overwritten somewhere. Please suggest.

Here is the code


    DATA: ls_xvbpa LIKE xvbpa,
          lf_aland LIKE tvst-aland,
          lf_azone LIKE tvst-azone,
          lf_lland LIKE trolz-lland,
          lf_lzone LIKE trolz-lzone,
          ls_vbadr LIKE vbadr,
          ls_xvbap LIKE xvbap,
          ls_tvst LIKE tvst,
          lv_route LIKE trolz-route.

    LOOP AT xvbap INTO ls_xvbap.
      IF NOT ls_xvbap-vstel IS INITIAL.
        SELECT SINGLE * FROM tvst
          INTO ls_tvst
         WHERE vstel EQ ls_xvbap-vstel.

        IF sy-subrc = 0.
          lf_aland = ls_tvst-aland.
          lf_azone = ls_tvst-azone.
        ENDIF.
      ENDIF.
      READ TABLE xvbpa INTO ls_xvbpa WITH KEY vbeln = ls_xvbap-vbeln
                                              posnr = ls_xvbap-posnr
                                              parvw = 'Q1'.

      IF sy-subrc = 0.
        CALL FUNCTION 'SD_ADDRESS_GET'
          EXPORTING
            fif_address_number      = ls_xvbpa-adrnr
          IMPORTING
            fes_address             = ls_vbadr
          EXCEPTIONS
            address_not_found       = 1
            address_type_not_exists = 2
            no_person_number        = 3
            OTHERS                  = 4.

        IF sy-subrc <> 0.
          MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
                  WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
        ELSE.
          lf_lland = ls_vbadr-land1.
          lf_lzone = ls_vbadr-lzone.
        ENDIF.
      ENDIF.

      CALL FUNCTION 'SD_ROUTE_DETERMINATION'
        EXPORTING
          i_aland             = lf_aland
          i_azone             = lf_azone
          i_lland             = lf_lland
          i_lzone             = lf_lzone
        IMPORTING
          e_route             = lv_route
        EXCEPTIONS
          no_route_found      = 1
          departure_error     = 2
          destination_error   = 3
          invalid_generic_key = 4
          customer_exit_error = 5
          OTHERS              = 6.

      IF sy-subrc <> 0.
        MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
                WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
      ELSE.
        ls_xvbap-route = lv_route.
        MODIFY xvbap FROM ls_xvbap TRANSPORTING route.

      ENDIF.
    ENDLOOP.

Thanks,

1 ACCEPTED SOLUTION
Read only

Manohar2u
Active Contributor
0 Likes
1,245

xvbap is the input to your routine. So try to change VBAP or check any different structure in scope.

Becos after you modity again the data will be resetted in the main program.

Regds

Manohar

10 REPLIES 10
Read only

Manohar2u
Active Contributor
0 Likes
1,246

xvbap is the input to your routine. So try to change VBAP or check any different structure in scope.

Becos after you modity again the data will be resetted in the main program.

Regds

Manohar

Read only

Former Member
0 Likes
1,245

When you update the XVBAP internal table, you should set the update indicator. The field is XVBAP-UPDKZ. I think it's 'U' for update, 'D' for delete.

However, I think there is another userexit specifically used for route determination change. I'll check.

Read only

Former Member
0 Likes
1,245

If you look in txn CMOD or SMOD, check enhancement 0VRF0001. It uses function module EXIT_SAPL0VRF_001. It is used to manipulate route determination for SD.

The function module if fully documented.

Read only

Former Member
0 Likes
1,245

Manohar and Norman,

Thanks for all your replies.

Norman...I cant use the exit EXIT_SAPL0VRF_001 because my req. is to re-determine the route based on a partner addition. So after you add a partner to the item, this code will not execute.

And I tried with UPDKZ indicator with I and U. It didnt work. Any more ideas.

Manohar,

Can I modify vbap directly in that user exit. Direct update is not a good idea though.

Thanks,

Read only

0 Likes
1,245

hi

you can update directly..no issues...

Cheers,

Abdul Hakim

Read only

Former Member
0 Likes
1,245

Hello all,

I tried updating vbap directly...but it didnt work.

Read only

0 Likes
1,245

Could you plz paste your code here...

Cheers,

Abdul Hakim

Read only

Former Member
0 Likes
1,245

Is there a reason why you are using USEREXIT_SAVE_DOCUMENT instead of USEREXIT_SAVE_DOCUMENT_PREPARE?

Does the route get redetermined after USEREXIT_SAVE_DOCUMENT_PREPARE?

I ask because the original intent for USEREXIT_SAVE_DOCUMENT was to save data in OTHER tables. Usually the internal tables are manipulated in USEREXIT_SAVE_DOCUMENT_PREPARE.

Read only

Former Member
0 Likes
1,245

pls try in the USEREXIT_SAVE_DOCUMENT_PREPARE?.

Read only

Former Member
0 Likes
1,245

Norman and Niranjan,

You are correct. I did the same and worked.

Thanks,