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.
Showing results for 
Search instead for 
Did you mean: 


Former Member
0 Kudos

My scenaio is like ths :

If The company has 4 brands of product and according to their sales policy customer must order all 4 brands then only they accept the sales order.

In VA01 when we create sales order, when we enter material in 2nd creen, If all 4 brand is entered then only we can proceed for next step , if one of the brand is missing it will give error mease as ' all brand is not orderd'.


Can anybody explain me how to do with coding as material will be entered in table control in VA01.

I got suggestion like :

During runtime of the sales order application all

the details with respect to Sales Order are available

in XVBAK, XVBAP, XVBKD, XVBPA, XVBFA etc... In order to

accomplish your requirement you need to scan through all

the items available in XVBAP and then if the requirement

is met you can proceed further otherwise issue the message

All brands are not ordered.

But can I know what are XVBAK, XVBAP, XVBKD, XVBPA, XVBFA .

Can anybody explain me with simple coding ?




Former Member
0 Kudos

Hi Naresh,

Xvbap contains all data which are meant to be transferred to VBAP on saving..similarly on all cases...just remove the 'X' and you get the tabl to which the data is suppose to be updated

Consider the following need to check for four brand in item...right?i am giving you a sample code as can use a different logic but the basic idea remains the same...

in the user exit.....userexit_save_document_prepare

All item are stored in XVBAP which is seen in the table control

in the item level...

data : workarea type vbap.

data : flag1 type c,

flag2 type c,

flag3 type c,

flag4 type c.

clear : workarea,flag1,flag2,flag3,flag4.

Loop at XVBAP into workarea. * take each item

case Xvbap-brand(whichever field ou require for the brand)

Assume ONE/TWO/THREE/FOUR are your required brands

when 'ONE'.

flag1 = X.

when 'TWO'.

flag2 = X.

when 'THREE'.

flag3 = X.

when FOUR.

flag4 = X.



*check if any of the flag is not set..means that brand is missing.

if flag1 is initial or

flag2 is initial or

flag3 is initial or

flag4 is initial.

messsage 'all 4 brands not mentioned' type 'E'.



each line item will come one by one i guess....

so you will have to check for each line item instead of doing the loop as in the above statement to set the flags and finally in userexit_save_document_prepare raise an error message by

(1) direct error statement

(2) call function POP_UP_TO_CONFIRM or similar ones to inform the user to correct the errors

Pls check and revert

Reward if helpful



Former Member
0 Kudos

Hi Naresh,

XVBAK - Same Structure as VBAK (Sales Order Header) plus some extra fields, Please refer to the Include VBAKDATA

XVBAP - Based on VBAPVB (Document Structure for XVBAP/YVBAP). Please refer to the include VBAPDATA

Similarly you can refer to the includes VBKDDATA, VBPADATA, VBFADATA etc...

Sample Code for checking whether all four brands are ordered or not.

Let us assume that XVBAP has got 10 items and then proceed further.

TYPES: BEGIN OF ty_mara,
        matnr TYPE mara-matnr,
       END OF ty_mara.

DATA:  i_mara TYPE TABLE OF ty_mara,
       w_mara TYPE ty_mara.

DATA: w_xvbap TYPE vbapvb.

DATA: v_cnt TYPE sy-tabix.

CONSTANTS: c_cnt_brands TYPE c VALUE '4'.

IF i_mara[] IS INITIAL.

  CLEAR w_mara.
  w_mara-matnr = 'LAPTOP'.
  APPEND w_mara TO i_mara.
  CLEAR w_mara.
  w_mara-matnr = 'KEYBOARD'.
  APPEND w_mara TO i_mara.
  CLEAR w_mara.
  w_mara-matnr = 'HARDDISK'.
  APPEND w_mara TO i_mara.
  CLEAR w_mara.
  w_mara-matnr = 'MOUSE'.
  APPEND w_mara TO i_mara.


LOOP AT xvbap INTO w_xvbap.

  READ TABLE i_mara INTO w_mara WITH TABLE KEY matnr = w_xvbap-matnr.
  IF sy-subrc = 0.
    v_cnt = v_cnt + 1.


IF v_cnt < c_cnt_brands.
  MESSAGE i000(0) WITH 'All four Brands are not ordered'.

Reward accordingly.

Thanks and Regards,

Maddineni Bharath.