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: 

IF condition to execute ABAP code; VBAK-VSBED; VBPA-KUNNR; XVBPA/YVBPA

Former Member
0 Kudos

Hi All!

I need some help. I have to change the MV45AFZZ, the FORM USEREXIT_MOVE_FIELD_TO_VBAK. The user exit should write the VBAK-VSBED (shipping condition) from the KNVV-VSBED for the VBPA-KUNNR, PARVW=WE (the ship-to-party partner). The user exit should also permit the modification of VBAK-VSBED directly from VA01 or VA02 (even if the ship-to-party remain the same).

I write down the ABAP code but I need to write a condition in order to execute the modification of VBAK-VSBED:

1. in VA01, for the first time;

2. in VA01 and VA02 if I change the ship-to-party partner.

Now, if I want to change VBAK-VSBED without modifying the ship-to-party, I can not. The user exit overwrite the VBAK-VSBED for the ship-to-party.

The code is:

-


READ TABLE xvbpa WITH KEY parvw = 'WE' .

IF SY-SUBRC = 0.

SELECT SINGLE * FROM knvv WHERE kunnr EQ xvbpa-kunnr and

vkorg EQ xvbak-vkorg and

vtweg EQ xvbak-vtweg and

spart EQ xvbak-spart .

vbak-vsbed = knvv-vsbed.

ENDIF.

-


Any help will be appreciate.

Florina C.

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi,

try this example:

*Table YVBPA should always be filled, when executing VA02, but if it is not, you

*can simple select the Sales Partner from VBPA(in va02 scenario it would be in *DB aldready)

if sy-tcode = 'VA01'.

READ TABLE xvbpa WITH KEY parvw = 'WE' .

IF SY-SUBRC = 0.

SELECT SINGLE * FROM knvv

WHERE kunnr EQ xvbpa-kunnr and

vkorg EQ xvbak-vkorg and

vtweg EQ xvbak-vtweg and

spart EQ xvbak-spart .

vbak-vsbed = knvv-vsbed.

ENDIF.

else if tcode = 'VA02'.

if YVBPA[] is initial.

select single * from vbpa

where vbeln = vbak-vbeln and parvw = 'WE'.

if sy-subrc = 0.

partner_before_change = vbpa-kunnr.

endif.

else.

READ TABLE yvbpa WITH KEY parvw = 'WE' .

if sy-subrc = 0.

partner_before_change = yvbpa-kunnr.

endif.

endif.

READ TABLE xvbpa WITH KEY parvw = 'WE' .

IF SY-SUBRC = 0 and

xvbpa-kunnr <> partner_before_change.

SELECT SINGLE * FROM knvv

WHERE kunnr EQ xvbpa-kunnr and

vkorg EQ xvbak-vkorg and

vtweg EQ xvbak-vtweg and

spart EQ xvbak-spart .

vbak-vsbed = knvv-vsbed.

endif.

endif.

Best Regards,

8 REPLIES 8

Former Member
0 Kudos

Hi

Use the following conditions:

IF sy-TCODE = 'VA01' or VA02'.

for creation the field <b>T180-TRTYP = 'H'</b> or it is changed.

based on above field/s you can place the condition.

reward if useful

regards

Anji

0 Kudos

Thanks Anji!

But if I use VA02 only for changing the VBAK-VSBED (to set a different shipment condition, not the ship-to-party shipment condition)..I can't do it...the system overwrites the ship-to-party shipment condition.

Florina C.

0 Kudos

Maybe there is a SY-* field from where I can know if a certain field is changed. I tried to use XVBPA and YVBPA but YVBPA has no value.

Message was edited by: Florina..grammar issue

Florina Cheta

Former Member
0 Kudos

Hi,

IF SY-TCODE = 'VA01' .
Write the code here for VA01 transaction code ..

ELSEIF SY-TCODE = 'VA02' .
IF SY-DATAR = 'X'.
X if at least one input field on the screen was changed by the user or other data transport, otherwise space.
ENDIF.

ENDIF.

Regards

Sudheer

Former Member
0 Kudos

Hi,

i'm a little confuse with your question.

According to your code, every time you create or change a Sales Order,

vbak-vsbed will be determined by knvv-vsbed for the partner 'WE'.

It doesn´t matter if it is VA01/VA02 that you are runnig.

Want you want is to complement the code for:

a) change the vbak-vsbed "manualy" in va0? transaction ? (and the code you have rewrite the manual entry?)

For this, you must defined in what conditions should the "vbak-vsbed" be determined.

For example, you want to always determine vbak-vsbed, with

knvv-vsbed for the partner 'WE' ? Or just when knvv-vsbed is initial? When should knvv-vsbed be entered manualy and rewrite the previous value determined by 'WE'?

Could you please clarify the question?

Best Regards,

0 Kudos

Thank you all!

Pedro,

I try to clarify my question.

1. When a user creates one order (VA01) and the user modifies not the shipment conditions, I want the system to write vbak-vsbed from the knvv-vsbed of the ship-to-party partner.

2. When a user creates one order (VA01) and the user modifies the shipment conditions, I don't want the system to overwrite vbak-vsbed from the knvv-vsbed of the ship-to-party partner.

If the user tries to change vbak-vsbed in VA02, for the items already written in the order, the route determination (the determination depends on shipping condition also) is not working at all (the system clears the field vbap-route).

What should I do?

Thanks.

0 Kudos

Hi Florina,

I'm having the same problem, did you solved this issue ??

Regards,

D.

Former Member
0 Kudos

Hi,

try this example:

*Table YVBPA should always be filled, when executing VA02, but if it is not, you

*can simple select the Sales Partner from VBPA(in va02 scenario it would be in *DB aldready)

if sy-tcode = 'VA01'.

READ TABLE xvbpa WITH KEY parvw = 'WE' .

IF SY-SUBRC = 0.

SELECT SINGLE * FROM knvv

WHERE kunnr EQ xvbpa-kunnr and

vkorg EQ xvbak-vkorg and

vtweg EQ xvbak-vtweg and

spart EQ xvbak-spart .

vbak-vsbed = knvv-vsbed.

ENDIF.

else if tcode = 'VA02'.

if YVBPA[] is initial.

select single * from vbpa

where vbeln = vbak-vbeln and parvw = 'WE'.

if sy-subrc = 0.

partner_before_change = vbpa-kunnr.

endif.

else.

READ TABLE yvbpa WITH KEY parvw = 'WE' .

if sy-subrc = 0.

partner_before_change = yvbpa-kunnr.

endif.

endif.

READ TABLE xvbpa WITH KEY parvw = 'WE' .

IF SY-SUBRC = 0 and

xvbpa-kunnr <> partner_before_change.

SELECT SINGLE * FROM knvv

WHERE kunnr EQ xvbpa-kunnr and

vkorg EQ xvbak-vkorg and

vtweg EQ xvbak-vtweg and

spart EQ xvbak-spart .

vbak-vsbed = knvv-vsbed.

endif.

endif.

Best Regards,