Tuesday, July 31, 2018

Enhancing Vendor Master


Enhancing Vendor Master

Requirement : Creation of Custom tab and Custom fields in vendor master transactions by using Enhancement spot technique.

Solution :
                1. Creation of custom field in LFB1 using append structure
                2. Go to configuration settings and mention the Tab name and screen names
                3. Implement Enhancement spot 'VENDOR_ADD_DATA'
                                                      Method : CHECK_ADD_ON_ACTIVE
                4. Implement Enhancement spot  'VENDOR_ADD_DATA_CS'
                                                      Method : GET_TAXI_SCREEN
                5. Creation of module pool program for designing of screen along with required fields
                6. Make the required fields editable in change transaction only.

Step 1: Creation of custom field in LFB1 table using Append structure .


Step 2: Go to SPRO transaction --> Financial accounting -- > follow the below path

and click on ' Prepare modification free enhancement in vendor master record ' 



Step 3: Click on ' New entries ' button to create new screen group.


 Step 4: Give meaningful name / name given by functional team and click on ' Label tab pages button  to give the new tab page name.



Step 5: Give the description and name of page as below.




Step 6: Go to SE18 transaction and create new implementation for Enhancement spot 'VENDOR_ADD_DATA'.

Here we have created implementation name as ' ZMM_CHGXXX_VENDORSAQ ' 





Now it will ask for BADI definition name and class name, Provide details as below.


Step 7: Go to SE24 transaction and give class name which we have provided in above step.


Go to method ' Check_add_on_active ' and use below mentioned logic.




(In below code, 'Z3' is our screen group name)
  METHOD IF_EX_VENDOR_ADD_DATA~CHECK_ADD_ON_ACTIVE.
    
IF i_screen_group 'Z3'.
      e_add_on_active 
'X'.
      
ENDIF.
 
 ENDMETHOD.



Step 8: Create implementation for BADI 'VENDOR_ADD_DATA_CS' and also give class name and implementation name (same process as step 6 )




Step 9: Go to SE24 and give class name which we have created in above step.



Go to Method 'Get_taxi_screen '  and write below logic

MODULE status_9001 OUTPUT.
   LOOP AT SCREEN.
  IF sy-tcode EQ 'XK03'.

      CASE screen-group1.
        WHEN 'G1'.
          screen-input = 0.
          MODIFY SCREEN.
      ENDCASE.
    ENDIF.
   ENDLOOP.
ENDMODULE.



Here Z3 --> Screen group name,
ZTAB2 --> Function code/Screen name
'ZMMR_VENDORSAQ -- > module pool program that we need to create

'9001' --> screen number


Step 10: Creation of module pool program with above details.
Program name: ZMMR_VENDORSAQ
Screen number: '9001'

SE51--> Create

 Go to Lay out in the program


 Design the layout with required fields..here in our scenario we required only one field from LFB1 Table

Field name:  ZVENSAQ(vendor SAQ) and group name as 'G1'


 Now we are making this field editable only in change transactions by using below PBO Event

MODULE status_9001 OUTPUT.
   LOOP AT SCREEN
.
  
IF sy-tcode EQ 'XK03'.

      
CASE screen-group1.
        
WHEN 'G1'.
          
screen-input 0.
          
MODIFY SCREEN.
      
ENDCASE.
    
ENDIF.
   ENDLOOP
.
ENDMODULE
.


Testing:
Go to XK03 transaction, find the button which we have created 'Vendor SAQ'.
Click on that button and you will navigate to new screen.




Saturday, April 7, 2018

Enhancing standard data source in BI


Enhancing standard data source in BI



To analyze data in BI(Business intelligence) we are using 'Data source'. Data source is nothing but like Reports in normal ABAP. So data source is a collection of fields along with data.

Requirement: Now Business wants some additional logic like calculations or wants to see the field from some other data sources. In such cases we will do data source enhancement.

Here we are going to enhance Purchase order item data source.

Steps to Enhance a data source:
       1. identify or get the standard data source name from the RSA6
       2. Select data source and click on display button and get the structure name which is available in             field 'Extract structure'.
       3. add new fields in structure by using Append structure. In case of this new fields are                             currency/quantity then we should have reference fields also in the same structure.
       4. Now to add logic for new fields we should create implementation for the Badi                                       'RSU5_SAPI_BADI'

Step by Step in detail:

1. identify or get the standard data source name from the RSA6










Go to required module and find data source based on name and description. in our case for Purchase order item data it is '2LIS_02_ITM'.

























2. Select data source and click on display button and get the structure name which is available in 
field 'Extract structure'.





















3. Add new fields in structure by using Append structure in SE11. In case of this new fields are currency/quantity then we should have reference fields also in the same structure.















Here we have appended new structure 'ZBW_PO_ITEM' with required fields. You can observe that currency fields should have reference field also from same structure.
















4. Now to add logic for new fields we should create implementation for the Badi 'RSU5_SAPI_BADI.
go to SE19 and create implementation for BADI

















There are two methods in interface tab. we need to write our logic in 'DATA_TRANSFORM' method only.
so double click on Data transform method and go to edit screen.This method having multiple parameters as below screen. However, the below parameters are important for us.
 I_DATASOURCE --> Having data source name, based on name required logic will trigger   C_T_DATA           --> Data source complete records, modify this table using our logic



How I implemented in my assignment:
we have created multiple implementations for each module












In our scenario, it is MM Module. below image refers the same.

























now there are multiple data sources in MM module. So when we want to enhance to any data source we are including new method in ZCL_IM_BW_RSU5_SAPI_MM and calling that method from DATA_TRANSFORM method.




















METHOD m_2lis_02_itm.

  
FIELD-SYMBOLS<lfs_data> TYPE mc02m_0itm.
  
TYPESBEGIN OF ty_po,
           zebeln 
TYPE ebeln,
           zbukrs 
TYPE bukrs,
           zstatu 
TYPE estak,
           aedat  
TYPE erdat,
           ernam  
TYPE ernam,
           waers  
TYPE waers,
           inco1  TYPE inco1,
           inco2  
TYPE inco2,
           knumv  TYPE knumv,
           exnum  
TYPE exnum,
           frgzu  
TYPE frgzu,
         
END OF ty_po.

  
TYPESBEGIN OF ty_poreq,
           zbanfn 
TYPE banfn,
           zbnfpo 
TYPE bnfpo,
           zfrgdt 
TYPE frgdt,
         
END OF ty_poreq.

  
DATA lt_po     TYPE STANDARD TABLE OF ty_po,
         lwa_po    
TYPE ty_po,
         lt_data   
TYPE STANDARD TABLE OF mc02m_0itm,
         lwa_data  
TYPE mc02m_0itm,
         lt_poreq  
TYPE STANDARD TABLE OF ty_poreq,
         lwa_poreq 
TYPE ty_poreq.

*  Copy the contents of the data table into a temporary table

  lt_data[] 
c_t_data[].
  IF NOT lt_data IS INITIAL.
    
SELECT ebeln bukrs statu aedat ernam waers inco1 inco2 knumv exnum          frgzu FROM ekko INTO TABLE lt_po
    
FOR ALL ENTRIES IN lt_data
   
WHERE ebeln lt_data-ebeln
   
 AND bukrs lt_data-bukrs.
    IF sy-subrc IS INITIAL.
   
 SORT lt_po BY zebeln.
    ENDIF.
*  Append a record for each purchase document
    
LOOP AT lt_data ASSIGNING <lfs_data>.
      
LOOP AT lt_po INTO lwa_po WHERE zebeln <lfs_data>-ebeln AND
                                      zbukrs 
<lfs_data>-bukrs.
        
IF sy-subrc 0.
          <lfs_data>
-zzstatu lwa_po-zstatu.
          
IF lwa_po-zstatu 'B'.
            <lfs_data>
-zzaupoc 1.
          
ENDIF.

          <lfs_data>
-aedat_po    lwa_po-aedat.
          <lfs_data>
-ernam_po    lwa_po-ernam.
          <lfs_data>
-frgzu       lwa_po-frgzu.
          <lfs_data>
-exnum       lwa_po-exnum.
          <lfs_data>
-knumv       lwa_po-knumv.
          <lfs_data>-ekko_inco1  lwa_po-inco1.
          <lfs_data>
-ekko_inco2  lwa_po-inco2.
          
MOVE <lfs_data>-ebelp TO <lfs_data>-kposn.
        ENDIF.
      
ENDLOOP.
    
ENDLOOP.
  
ENDIF.

*  Transfer back the contents to original table.
  
FREE:c_t_data[].
  c_t_data[] 
lt_data[].




























  METHOD IF_EX_RSU5_SAPI_BADI~DATA_TRANSFORM.
**********************************************************
* To implement an exit for a
* datasource create your own method by copying the
* method _TEMPLATE_DATASOURCE and rename it to the name
* of your datasource. In case you enhance a Business
* Content datasource skip the 0 at the beginning (e.g.
* Datasource 0FI_AR_3 -> Method FI_AR_3
* The method is then called by the Exit Framework
*********************************************************
    
DATAls_oltpsource TYPE rsaot_s_osource,
    lv_data 
TYPE REF TO data,
    lv_method 
TYPE seocmpname.
    
FIELD-SYMBOLS<lt_data> TYPE STANDARD TABLE.
* check BW system
*CHECK _check_bw_system( ) = 'X'.

* check if any data is extracted
    
CHECK c_t_data IS NOT INITIAL.

    
CALL FUNCTION 'RSA1_SINGLE_OLTPSOURCE_GET'
      
EXPORTING
        i_oltpsource   
i_datasource
        i_objvers      
'A'
      
IMPORTING
        e_s_oltpsource 
ls_oltpsource
      
EXCEPTIONS
        no_authority   
1
        not_exist      
2
        inconsistent   
3
        
OTHERS         4.
    
IF sy-subrc <> 0.
      
EXIT.
    
ENDIF.
* create data for Extract Structure
    
CREATE DATA lv_data TYPE TABLE OF (ls_oltpsource-exstruct).
    
ASSIGN lv_data->TO <lt_data>.
    
ASSIGN c_t_data TO <lt_data>.
    
DATA l_method TYPE seocmpname.

    
CONCATENATE 'M_' i_datasource INTO l_method.

    
CHECK c_t_data[] IS NOT INITIAL.

    
SELECT SINGLE cmpname FROM seocompo INTO l_method WHERE
    clsname 
'ZCL_IM_BW_RSU5_SAPI_MM' AND
    cmpname 
l_method.

    
CHECK sy-subrc EQ 0.

    
CALL METHOD (l_method)
      
EXPORTING
        i_updmode    
i_updmode
        i_t_select   
i_t_select
        i_t_fields   
i_t_fields
      
CHANGING
        c_t_data     
c_t_data
        c_t_messages 
c_t_messages.
  
ENDMETHOD.                    "if_ex_rsu5_sapi_badi~data_transfo

Custom routine creation in SAP

                              Sales order pricing   Requirement : In sales order, for one of the condition type, value is populating ...