Wednesday, 29 June 2016

Core Data Services - Standard Utilities / Reports

Monday, 8 June 2015

What’s in it for me? Upgrade Project from an ABAPER’s perspective.

Are you an Abaper and about to get into an upgrade project? Are you thinking upgrade is just lots of customizing and basis activity and where do you fit in?  I wonder how many of us must have thought the same way.
Here are some points that will help to get an insight into an upgrade project from an abaper’s point of view.

1.       Old and New: You get to know both, the old system that is very soon going to be phased out and the new upcoming system. What are the challenges your client is facing that prompted him to go for an upgrade and how it will benefit the client in future.

2.       Module independent:  Most of the times (until and unless it a new end-to-end implementation) we work in projects that involve 2 or 3 modules. A technical upgrade includes all modules implemented for a client.  At one time you will be working on an object from finance and controlling and other time you will be busy correcting the syntax of an object from HR module. Not only modules a system upgrade usually impacts other dependent and communicating systems enabling you to understand the SAP processes in a better way.

3.       All aspects of ABAP:   The two old famous transactions ‘SPDD’ and ‘SPAU’ expose you to all aspects of ABAP. Be it the adjusting of data dictionary objects, maintaining translations, implementing OSS notes, adopting modifications to code, user-exits, customer exits, implicit and explicit enhancements. You get to regenerate the ABAP queries, check the workflow settings and sometimes you witness   loss of a piece of code that was added to standard code using access key. An upgrade project just introduces you to all abap has to offer in one go.

4.       Syntax Master: If you are upgrading from a non-Unicode to a Unicode compatible system all you old custom programs will stop working. J  The only option is to go to each and every program and correct the syntax. Although the UCCHECK transaction will help you with the syntax errors and setting the Unicode flag active, still it involves correcting the same error at least hundred times. Thus, by the end of this phase you end up being a syntax master having the syntaxes at your fingertips.

5.       Time to learn and unlearn:  Upgrade project teaches you that it’s time to unlearn the old and start using the new. New syntaxes, new function modules in place of old (GUI_DOWNLOAD and GUI_UPLOAD instead of WS_DOWNLOAD and WS_UPLOAD), new tables, better programming approaches and techniques.  At the end you just end up to be a better programmer. J

6.       Boast it out:  It gives you an opportunity to boast that you have seen both, the old and the new. Once in a while you will be saying to the newbies “You know how it used to be when we were in old system? “ J.

Friday, 5 June 2015

Adding line items automatically through code in VA01 - Sales Order Create


Add a line item automatically when a user clicks on save to sales order in VA01


Link to the original post created in SCN:



Thanks,
Tanmay.

Mandatory Views in Material Master - MM01 and MM02


Sometimes there is a requirement to make certain views mandatory in material master transactions MM01 and MM02. 

Making views mandatory is not possible through customizing in IMG. However , we can achieve the same by writing a small code in customer exit.

Below is the link of the original post on SCN.



Happy Learning.
Tanmay.

Wednesday, 26 December 2012

Constructor in Classes

Usage of Constructors in Classes

There are 2 types of constructors in an ABAP CLASS.
  1.  CONSTRUCTOR: The constructor is a method which is used to initialize the class members or assign value to them. It is called once for each instance of an class or more precisely it is called for each object of a class.
  2. CLASS CONSTRUCTOR: The class constructor is called once for each class irrespective of the number of objects created or instantiated for that class.

Let us look into this concept with the help of an example:

EXAMPLE:

REPORT z_constructor.

*--Class Definition
CLASS l_test DEFINITION.
     PUBLIC SECTION.
         METHODS:  constructor.
         CLASS-METHODS: class_constructor.
ENDCLASS.

*--Class Implementation.
CLASS l_test IMPLEMENTATION.
     METHOD constructor.
        WRITE : / ' inside constructor '.
     ENDMETHOD.
     METHOD class_constructor.
        WRITE : / 'inside class constructor'.
     ENDMETHOD.
ENDCLASS.

*--Report.
*--Declare the reference variables.
DATA  : ob1 TYPE REF TO  l_test,
              ob2 TYPE REF TO  l_test.

START-OF-SELECTION.
CREATE OBJECT ob1.
CREATE OBJECT ob2.

------------------------------------------------------------------------------------------------------------
OUTPUT:

inside class constructor                          <-- from class constructor

inside constructor                                  <-- from constructor for object ob1

inside constructor                                  <-- from constructor for object ob2
------------------------------------------------------------------------------------------------------------

Thursday, 13 December 2012

Declaring Local Class in ABAP Report

In this tutorial we will learn about how to declare local class and use it in a report program.

KEY POINTS:
  • The first step is to give a class definition.
  • Next implement the class and its methods.
  • Declare a reference to the class.
  • Create an object of the class and use it to call the methods of the class.
EXAMPLE:
REPORT  zlocal_class.
*--Class Definition
CLASS l_test DEFINITION.
   PUBLIC SECTION.
*--data declaration
     DATA: info TYPE string.
*--methods
     METHODS:
     constructor     IMPORTING p_balance TYPE dmbtr,
     set_balance    IMPORTNG  p_set TYPE dmbtr,
                           EXPORTING p_amount TYPE dmbtr,
     display.
  PRIVATE SECTION.
    DATA : balance TYPE dmbtr.
ENDCLASS.      " end of class definition
*--Class Implementation
 CLASS l_test IMPLEMENTATION.
    METHOD constructor.
      WRITE: / 'inside constructor'.
       balance  = p_balance.
      WRITE: /  'value'  ,  balance.
    ENDMETHOD.
    METHOD set_balance.
       balance = p_set.
    ENDMETHOD.
   METHOD display.
      WRITE : / ' set the balance'.
      WRITE :  balance.
   ENDMETHOD.
ENDCLASS.

*--Report 
*-- Declare the reference.
 DATA:  test TYPE REF TO  l_test.

*declare a parameter on selection screen.
PARAMETERS: p_val TYPE dmbtr.

START-OF-SELECTION.
*--create object
CREATE OBJECT test 
    EXPORTING 
     p_balance =  40.                          <-- This will be passed to the constructor.

*-- call method set_balance.
CALL METHOD test->set_balance  <-- call the method to set balance.
    EXPORTING
      p_set = p_val.
*-- call method display.
CALL METHOD test->display.        <-- call method display.

  ----------------------------------------------------------------------------------------------------------

INPUT :
 P_VAL  = 500.

OUTPUT:
inside constructor
value 40

set the balance 500
-----------------------------------------------------------------------------------------------------------
Notes :  
  • The method constructor is called when the object is created using CREATE OBJECT statement.
  • The method set_balance s used to set the value or assign the value of parameter to the class attribute balance.
  • The attribute 'balance' is private and hence can only be accessed through class methods.
  • The method display will print the value of balance attribute.

Table Maintenance Generation Events

INTRODUCTION

Table maintenance generation events can help us to perform validations while creating new entries in a table or hiding the fields or assigning default values to table fields.
There are large number of events present which can be used for such purposes.Some of them are :


01  Before saving the data in the database
02  After saving the data in the database
03  Before deleting the data displayed
04  After deleting the data displayed
05  Creating a new entry


15  Before retrieving deleted entries
16  After retrieving deleted entries

21  Fill hidden fields 

In total there are 39 events provided by SAP.

HOW TO USE THESE EVENTS?

Now we will learn how to use these events in some simple steps:

1. Create a table in SE11.
2. Go to Utilities ->Table Maintenance Generator -> Fill Required data of this Screen -> Environment -> Modification -> Events.
3. Select the event.
4. Give the form name and click on the editor icon.
5. Select the include to place your form definition.
6. Within the form write your code . Save and Activate.
7. Now just go to SM35 to maintain your table to witness the events trigger.

EXAMPLE 

Table : Let us take a simple table having fields as employee id  ,  employee name and date on which  entry created.

Requirement : The employee name and date should get automatically populated while creating a new entry.

Table Name : ZTEST_EVENTS

Fields :                           Type 
ZEMPID                        NUMC
ZNAME                        CHAR
ZDATE                          DATS

Now create the Table Maintenance Generator.

Select Event :  05  Creating a new entry.

Give the form name as : CREATE_ENTRY and write the following code.

FORM create_entry.
ztest_events-zname = sy-uname.
ztest-events-zdate   = sy-datum.
ENDFORM.

Save and Activate.

Now if we go to maintain the table and leave name and date as blank , we will see that they are automatically created.

Hence , In this way events can be used.