Subscribe

RSS Feed (xml)



Powered By

Skin Design:
Free Blogger Skins

Powered by Blogger

Showing posts with label Userexits/BADIs. Show all posts
Showing posts with label Userexits/BADIs. Show all posts

Thursday, February 3, 2011

Picking material description from custom table in the SAP Sales Order (VA01 and VA02) using enhancement framework

This scenario would work from ECC6.0 onwards.

In Enhancement Framework, we can add our own Code at particular points.

While debugging the standard SAP program, we have to decide at which place we would need to write our own code. There we need to check whether enhancement can be implemented.

Requirement: In Sales Order (VA01 & VA02), we have to pick the Material Description from Custom Table.

While debugging it is found that the code needs to be written in the FORM USEREXIT_MOVE_FIELD_TO_VBAP. Now click on Enhance button as shown below.

It shows the screen as below :

Then it shows the Screen as below:

""" indicates we can write our code here.

Now Right click on """"""""""""" and select Enhancement Implementation -> Create.




Select Code.

Now click on Create button in the above screen. Another Screen appears as shown below:

In the above screen, click on Create Composite Implementation and the following Screen appears.

Then click on Continue button (Green tick).

In the below Screen, Select the Enhancement Implementation which we have created now and click on Continue button.

Now here we can write our own code as shown below:

Code:

ENHANCEMENT 315 ZSD_EI_BOQDESC. "active version
* Modification Done By : Sajid Shaik.
* Date : 08.06.2009
* Requirement Given by : Avinash Gyale
* Requirement : Material Description should be fetched from BOQ based on the Plant and Boq Type 'Erection or Civil'.
* : This should work only for Order type ZCO1 - Civil & Order type ZER1 - Erection

DATA : VAR_ARKTX TYPE VBAP-ARKTX,
VAR_MAKTX
TYPE ZBOQ_ITEM-MAKTX,
VAR_TENDERID
TYPE ZBOQ_ITEM-TENDERID,
VAR_LENGTH
TYPE INT4.

IF ( SY-TCODE EQ 'VA01' OR SY-TCODE EQ 'VA02' ) AND ( VBAK-AUART EQ 'ZCO1' OR VBAK-AUART EQ 'ZER1' ) AND VBAP-WERKS IS NOT INITIAL.
CLEAR : VAR_ARKTX,VAR_MAKTX,VAR_TENDERID .

IF VBAK-AUART EQ 'ZCO1'.
SELECT SINGLE TENDERID FROM ZBOQ_HEADER INTO VAR_TENDERID WHERE WERKS EQ VBAP-WERKS AND TYPE EQ '3'.
IF SY-SUBRC NE 0.
ENDIF.
ELSEIF VBAK-AUART EQ 'ZER1'.
SELECT SINGLE TENDERID FROM ZBOQ_HEADER INTO VAR_TENDERID WHERE WERKS EQ VBAP-WERKS AND TYPE EQ '2'.
IF SY-SUBRC NE 0.
ENDIF.
ENDIF.

SELECT SINGLE MAKTX FROM ZBOQ_ITEM INTO VAR_MAKTX WHERE TENDERID EQ VAR_TENDERID.
IF SY-SUBRC NE 0.
ENDIF.
VAR_LENGTH =
STRLEN( VAR_MAKTX ).

IF VAR_LENGTH LE 40.
VAR_ARKTX = VAR_MAKTX(VAR_LENGTH).
ELSE.
VAR_ARKTX = VAR_MAKTX(
40).
ENDIF.
IF VAR_ARKTX IS NOT INITIAL.
VBAP-ARKTX = VAR_ARKTX.
ENDIF.
ENDIF.

ENDENHANCEMENT.

Then Save and Activate it.

OUTPUT :

Before Enhancement Implementation

After Enhancement Implementation

Setting the screen elements as mandatory in the transaction DP95 using Enhancement Framework

Scenario:

In this scenario, we would set the fields ‘Sales’ and ‘Order’ as Mandatory in the transaction DP95. Following are the technical attributes of these fields (go to technical details by clicking on F1 on the fields)

Screen field names – so_vbeln-low(Sales) and so_aufnr-low (Order).

Go to system à status

Double click on Program RVPKMASS.

Click on “Spiral Button” or ProgramàEnhance

Click on “Spiral Button” or ProgramàEnhance

Edit à enhancement operationsàShow implicit enhancement

Place the cursor on the enhancement point and create the enhancement is as shown below screen. Enhancement implementationàcreate

Create the New Enhancement is as shown in below screen.

Select the appropriate enhancement and click on continue.

Place the below code in the enhancement spot.

At selection-screen output.
Loop at screen.
If screen-name = 'so_vbeln-low'.
Screen-required = '1'.
Modify screen.
Endif.
If screen-name = 'so_aufnr-low'.
Screen-required = '1'.
Modify screen.
Endif.

Endloop.

Click on Save, Check and Activate.

OUTPUT:-

Scenario on Enhancement Framework

Restrict users (sales persons) to view or change Sales order data - Using Enhancement framework:

Source Code Enhancement is one of the enhancement technologies available under Enhancement Framework. Implementing this technology is also called as Source Code Plug-In. Technically the source code plug-in implementations are stored in a separate include program and not as part of the original source program.

There are two types of Source Code enhancements possible.

  • Implicit enhancement option
  • Explicit enhancement option

Example Scenario:

One sales person can’t see or change another sales person’s sales orders.

In my program, I have used following users.

Sales person1 (user 1): lz8xzf Owner for Sales order no: 174.

Sales person2 (user 2): lzn4rm

Steps to Implement the Implicit enhancement option:

Step1: Go to SE38 and Open include MV45AFZB

Step2: In order to implement any of these Source code enhancements, you need to be in ‘change Enhancement mode’ (the spiral icon available in the editor).

Step3: Go to EDIT option in the menu and choose Enhancement Operations -> Show implicit Enhancement Options

All Implicit Enhancement option will be displayed. All yellow lines indicate Implicit Enhancement options. In ABAP programs, implicit enhancement options are predefined at the following places:

Begin/End of an include.

Begin/End of Method/Function Module/Form Routine

End of a structure

End of Private/Protected/Public Section of a local class

Step4: Place the cursor on the yellow line and choose

Enhancement implementation à Create.

Step5: Give Implementation name and then create.

Step6: Here Editor will be enabled to write the code. Write your own code save and activate it.

Step 7: Once the development is completed you can test the scenario.

When Sales person (lzn4rm) tries to Open Sales order no 174, it gives error message ’Access Denied’.

Note: Sales order 174 is created by another sales person (lz8xzf).

Restrict the modification of Delivery item texts - Using Implicit enhancement technique

1. Go to transaction code - VL02N + press enter

2 .Goto->Item->texts

Now you can see the item texts in editable mode

Note:

To make it non editable you need to enhance the code .

First you need to debug the application and find the exact place where you need to add the functionality

You must be knowing that each and every subroutine and method (not modules )will be having implicit enhancement options at the beginning and at the end .

In this particular case we have to enhance the subroutine

PERFORM TEXT_CONTROL_EINGABEBEREIT.

3. Go to this subroutine and then Program –> Enhance

4 .Then follow Edit ->Enhancement Operations -> Show implicit enhancement Options


5 .Now you can see

6 . Go to implicit enhancement option at the end of the form and do right click -> Enhancement Implementation -> Create

7 .Now it will ask for Enhancement type

We have to implement code and it will look like this

Here you can write the custom code for modifying the functionality

8. Include name LV70TFT3

ENHANCEMENT 4 ZTEXT_MODIF_BLOCK. "active version
call method gv_text_editor->set_readonly_mode
exporting
readonly_mode = gv_text_editor->true
exceptions
error_cntl_call_method =
1
invalid_parameter =
2
others = 3.

ENDENHANCEMENT.

9. Activate the code and check VL02N




BADI implementation for transaction FB60

Aim: To create a BADI implementation for FB60 transaction, that does not allow user to create duplication reference for Vendor Invoice Creation.

Step1:

Keep a break point in CALL METHOD cl_exithandler=>get_class_name_by_interface” line inside the get_instance method of the class cl_exithandler in Class builder (SE24).

Step2:

Now execute FB60 transaction, you will see the debugger that you set in SE24 transaction. Double click on the changing parameter “EXIT_NAME”. Press F8 sequentially and make a note of the exit names.

Step3:

After you see FB60 just continue with the Vendor Invoice creation and in mean time note all the Exit names that you come through in the debugger.

Step4:

Give the values for all mandatory fields and press Enter.

Step5:

You will get the screen like this and press F9 for Simulate Document Posting.

Step6:

You will get the screen as below.

Step7:

Save it.

The BADI’s triggered is as follows.

Before SCREEN1

  • BADI_FDCB_SUBBAS01

  • BADI_LAYER

  • BADI_FDCB_SUBBAS02

  • PPA_CUST_BADI

  • BADI_FDCB_SUBBAS03

  • WRF_PREPAY_INVOICE

  • BADI_FDCB_SUBBAS04

  • BADI_FDCB_SUBBAS05

  • ADDR_LANGU_TO_VERS

  • ADDR_PRINTFORM_SHORT

  • BADI_MATN1

Before 2nd Screen:

  • PPA_CUST_BADI

  • FAGL_PERIOD_CHECK

  • FI_TRANS_DATE_DERIVE

  • ADJ_NETDAYS

  • FAGL_SEGMENT_BS_ACC

  • FAGL_DERIVE_SEGMENT

  • FAGL_DERIVE_PSEGMENT

  • CHECK_COBL_ADDON

  • PPA_CUST_BADI

  • SD_COND_ACCESS_A

After Save Button Pressed:

  • FI_RES_ITEM_CURRENCY

  • AC_QUANTITY_GET

  • BADI_PRKNG_NO_UPDATE

  • FM_POP_CORE

  • FMRI

  • FMRE_BUS_PROCESS

  • FAGL_SET_SEGMENT

  • FI_SL_BADI_DOCSELECT

  • FI_SL_BADI_POPER

  • EXIT_XFMPR1_001

  • BUAVC_CHECK_RESTRICT

  • UKM_R3_ACTIVATE

  • UKM_R3_ACTIVATE

  • CO_DOCUMENT_INFO

Step 8 :

Search for the “I_COBL” field inside any of the methods inside the BADI classes.

Shortcut : Once you got the parameter. Goto se19 in create implementation block under classic BADI enter the BADI names one by one and find out weather implementation can be created or not. After doing this you will have very less BADI’s now goto SE24 and add cl_ex_(BADI NAME) and check for methods that have the parameter I_COBL.

Press ‘Display’ button.

Press ‘Parameters’ button.


Step9:

After finding the BADI and method in which you want to implement the code. Goto SE19 and create implementation for that particular BADI.

Step10:

Press ‘Create Implementation’ button and press ‘Enter’.

Step11:

Enter implementation short text and give the ‘Filter Type’ also.

Step12:

Click on interface tab.

Step13:

Double click on the method in which you want to write code as decided. You will see the following.

Press ‘Yes’ button and Save it.

Step14:

Write the following code in the method.

method IF_EX_FAGL_DERIVE_SEGMENT~GET_SEGMENT.
data lt type COBL .

select SINGLE XBLNR from bkpf into lt WHERE XBLNR = i_COBL-xblnr.
if sy-subrc eq 0.
MESSAGE E015(Z1018_SALESORDER_MSG).
ENDIF.
endmethod.

Step15:

Save and activate the code and come back.

Step16:

Activate the Implementation and go to FB60 and try to create Vendor Invoice Creation with the same reference as ‘100’.