Add new fields to Billing Document(VF01,VF02,VF03) Header simplified
The Setup
This blog will guide you step by step how to add custom fields to SAP GUI transaction Create Billing document(VF01), Change Billing document (VF02) and Display Billing document (VF03). For the purpose of this exercise, we will create custom tab where we embed a custom field ‘External document number’.
Prerequisite:
– Customer is allowed to add only one custom tab on billing document header(as far as I researched).
– Global Trading Management must be deactivated.
*To activate/Deactivate Global Trading Management, go to transaction WB2B_CUS or view V_TWGTA from SM30. Uncheck Global Trade Management Active or change Add-Ons Active as Inactive and Enhancement as Not Active.
1. Create append structure in VBRK(billing document header) table.
Go to SE11 and click on Append Structure.
In this exercise we will name the append structure ‘ZZVBRK_CUSTOM_FIELDS’ and add field ZZ1_EXT_DOCNUM. Optionally, you can create your own data element, domain to change the lable and data type.
Active the append structure. It may take a while to complete the dependincy check and complie.
2. Create a subscreen
To add a custom tab, we must create a custom Dynpro. Go to SE38 and first create a executable program. In this exerscise, we will name it ZBILLHEAD_CUSTOM.
Create custom screen and number it 9001(custom name space). Make sure to select subscreen.
Click Layout button and we are going to define the custom field on this custom subscreen. From the left side pane, drag and drop Text element and name it ‘External Document_Number’ for both name and text.
Again from the left side pane, drag and drop the input box and palce it next to the text lable. Name it VBRK-ZZ1_EXT_DOCNUM(your custom field in VBRK). No need to fill in the text
Save the change and exit the layout view.
In the logic flow of screnn, uncomment STATUS_9001 and create this module in the main program ZBILLHEAD_CUSTOM. Add below code. This will regulate the screen input, display the field as non-editable field when it’s VF03.
Save and activate the program and screen.
3. Call subscreen from enhancement
Now that we defined the screen, we need to add logic to call this screen when user accesses VF01,VF02,VF03. Go to program MV60AF0C_CUST_HEAD_ACTIVATE from SE38. Navigate to beginning of form CUST_HEAD_ACTIVATE and display implicit enhancement point(swirl icon).
The line that shows with grey arrow is where customer can insert custom logic in the standard SAP program such as MV60AF0C_CUST_HEAD_ACTIVATE. You can also see that the button has changed and Create/Change/Replace buttons are available.
Click on Create button and choose Code and name the enhancement as ZVBRK_HEAD_CUSTFIELDS.
Now the enhancement block is created in the standard MV60AF0C_CUST_HEAD_ACTIVATE and only in the block can the code be added. Add below code in the editable part. gs_cust_tab-head_caption will be the title of the tab. Set the custom program we created in the previous step to gs_cust_tab-head_program and customer screen number to gs_cust_tab-head_dynpro. In line 16~18, we are activating this custom tab in the transaction.
  LOOP AT SCREEN.
    IF screen-name = 'TABSTRIP_TAB06'.
      gs_cust_tab-head_caption = 'Bill header custom fields'.
      gs_cust_tab-head_program = 'ZBILLHEAD_CUSTOM'.
      gs_cust_tab-head_dynpro = '9001'.
      IF gs_cust_tab-head_dynpro IS NOT INITIAL.
        screen-active = 1.
        screen-invisible = 0.
        MODIFY SCREEN.
        tabstrip_tab06 = gs_cust_tab-head_caption.
        "Optionally, add logic to modify the value
      ENDIF.
    ENDIF.
  ENDLOOP.
Save and activate the enhancement.
4. Testing
Go to VF01 or VF02 and go to billing document header. You should be able to find a tab ‘Bill header custom fields’.
Try entering value and save. You can see the value being registered in the backend table.
No custom logic was added to handle the user input value. How does the value being handled and updated in the VBRK?
This is luckily handled automatically by standard logic. When save is pressed in VF01, VF02, program SAPMV60A screen 6101 is called and module cust_head_get_data is processed.
Within cust_head_get_data calles form VBRK_BEARBEITEN which is responsible for updating the backend table VBRK.