Blog

  • SAP CRM (Customer Relationship Management)

    Preface – This post is part of the ABAP Beginner series.

    SAP CRM (Customer Relationship Management)

    SAP CRM is nothing but the way businesses interact with their customers. Traditionally, this is done by automating and integrating your customer related activities such as sales and marketing, and customer service. But in today’s time, the CRM activities go beyond that and provide functionalities like personalization, e-commerce, social media, collaboration and more. New CRM softwares store all customer information from their contacts to social media activities. This information can be used to dramatically improve the business. CRM benefits are huge from increasing sales revenue, customer loyalty to lower costs and better customer related activities.

    The SAP CRM application is a software which targets small and large sized businesses in all the sectors.

    SAP CRM Architecture:

    The following are the key components in the SAP CRM architecture:

    • SAP ERM Server (CRM Enterprise, CRM Middleware and Adapter)
    • SAP ECC – used for backend
    • SAP BI – is used for reporting
    • SAP SCM – used to better the capabilities of CRM
    • Mobile and handheld devices
    • Internet
    • Enterprise portal

    SAP CRM

    The Adapter is mainly used for handheld devices and the internet. The CRM Enterprise is used for telephone and email services.

    The SAP ECC and CRM are closely related to each other and need to synchronise in some areas like sales, customer master records, organisational model, etc.

    Some of the important Transaction codes of the CRM module are:

    CRMD_ORDER -> Transaction processing

    R3As -> Start initial load

    CRM_DNO_MONITOR -> Transaction monitor

    SMOEAC -> Administration console

    PPOMA_CRM -> Change organizational model

    R3AM1 -> Monitor Objects

    Some of the important tables of the CRM module are:

    BUT000 -> General Data

    BUT020 -> Addresses

    BUT050 -> BP relationships/role definitions: General data

    BNKA -> Bank master data

    ADR2 -> Telephone numbers

  • SAP MM (Material Management)

    Preface – This post is part of the ABAP Beginner series.

    SAP MM (Material Management)

    SAP MM: Material management is a module of SAP which as the name suggests deals with material management and inventory management. It ensures that there is never a shortage of materials in the supply chain process of the organization. It also helps the organization to complete the purchasing of goods in a timely manner and in a cost effective way. It incorporates other modules like Sales and Distribution, Production Planning, Plant Maintenance, Project Systems, Warehouse Management which are based on Materials Management module.

    The process of material management is as follows:

    1. Determination of requirement: Determines what materials and services are required for the organization.
    2. Source Determination: Determines who can fulfil the requirement.
    3. Vendor Selection: After gathering the requirements, direct contact is made with the suppliers and a suppliers is chosen who can satisfy the requirements.
    4. Purchasing Order (PO): The purchasing department is informed about the products needed. When that request is approved, the purchase order is created and assigned to the supplier.
    5. Order Monitoring: Order monitoring is tracking of dates and the goods from the time of ordering to the time the goods are delivered. It is done to ensure that there are no discrepancies and if any, they can be handled beforehand.
    6. Goods Receipt: The goods are received and are checked for quality and condition.
    7. Invoice Verification: Reconciliation of the invoice and purchase order is done. It means the invoice received is checked for cost, quantity and quality.
    8. Payment: The vendor is paid.

    SAP MM

    Some of the important Transaction Codes for Material Management are as follows:

    MM01 -> For creation of material

    MM02 -> For change of material

    MM03 -> For display purposes

    ME51N -> Creation of purchase requisition

    ME41 -> creation of RFQ

    A few of the basic tables in SAP MM modules are:

    MARA -> general data, material type

    MLAN -> Sales data, Tax Indicator, Tax

    MAKT -> Short texts, descriptions

    EBAN -> Purchase Requisition

    EKES -> Vendor Confirmations

     

     

     

     

  • SAP SD (SALES AND DISTRIBUTION)

    Preface – This post is part of the ABAP Beginner series.

    SAP SD (SALES AND DISTRIBUTION)

    SAP SD (Sales and Distribution) is used to manage shipping, billing, selling and transportation of products and services. It is closely integrated to material management module of SAP and manages customer relationship from requesting the product from the vendor to the billing of the product. It allows organisations to manage customer and product related data.
    Following is the Sales and Distribution Cycle:
    SAP SD
    In an SD cycle, SD first generates a sales cost and the customer places the order. The goods are then picked up from the warehouse and delivered to the customer with an invoice which is then settled. Each step in SD module generates transactions in other modules such as, a sales order in the SD module generates a link to check product availability in Material management, a credit check or a tax calculation to FICO.
    SD follows the Order-to-cash cycle process which involves a set of business processes from receiving to fulfilling customer requests for products and services.

    Some of the important tables in SAP SD module are:

    KNA1 -> Customer Master: General Data
    KNB1 -> Customer Master: Company Code Data
    KNB1 -> Customer payment history
    VBUK -> Header status and administrative data
    VBUP -> Item Status

    Some of the important Transaction codes for SAP SD are as follows:

    VS00 -> Master Data
    VC00 -> Sales Support
    VA00 -> Sales
    VL00 -> Shipping
    VT00 -> Transportation
    VF00 -> Billing
  • ABAP Report Events: What are the events of Classical Reports?

    Preface – This post is part of the ABAP Beginner series.

    Events in ABAP

    ABAP is an event driven Programming language. ABAP Report Events are used to handle different kinds of events during runtime. It starts with the event name, followed by the programming codes belonging to that event.

    It is advisable to use Comment line to declare the end of an event, since Events do not have a closing Keyword and it ends as soon any other Event starts.

    There are different kinds of events in ABAP, SAP has categorized these events together.

    Categories of Events in ABAP:

    There are three categories of Events in ABAP:

     

    Event Category

     

    Explanation

     

    Events in the Category

     

    Program Constructor Events

     

    Except Pool programs it occurs in every programs.

     

    LOAD-OF-PROGRAM

     

    Reporting Events

     

    These events occur only in Executable Reports.

     

    INITIALIZATION

    START-OF-SELECTION

    END-OF-SELECTION (obsolete)

     

    Selection Screen Events

     

    These events occur during Selection Screen Processing

     

    AT SELECTION-SCREEN OUTPUT

    AT SELECTION-SCREEN

     

    List Events

     

    These events occur during Classical List Processing [List can be a table or consecutive Write statements, etc.]

     

    TOP-OF-PAGE

    END-OF-PAGE

    AT-LINE-SELECTION

    AT USER-COMMAND

    AT PFnn

    SET USER-COMMAND

     

    Events in Classical Report:

    Classical Reports have following events:

    • LOAD-OF-PROGRAM : First event fired, loads program in memory
    • INITIALIZATION: Initialize variable
    • START-OF-SELECTION : Actual Business Logic (After START-OF-SELECTION)
    • END-OF-SELECTION : To end above
    • AT SELECTION-SCREEN : To validate Multiple Input fields (After Initialization and before START-OF-SELECTION) (After
    • AT SELECTION-SCREEN OUTPUT: To manipulate Dynamic screen
    • AT SELECTION-SCREEN ON
    • AT SELECTION-SCREEN ON END OF
    • AT SELECTION-SCREEN ON BLOCK
    • AT SELECTION-SCREEN ON RADIOBUTTON GROUP
    • AT SELECTION-SCREEN ON VALUE REQUEST
    • TOP-OF-PAGE : To print heading
    • END-OF-PAGE: To print footer

    Programming Guidelines:

    1. Never use Selection Screen Events in Function Module
    2. Use LOAD-OF-SCREEN to load default values  for the type of Reports executed via SUBMIT or using a transaction code
    3. Use INITIALIZATION to load default values  for the executable type of Reports
    4. It is advised not to specify an event more than once [Except AT-SELECTION-SCREEN & GET event, all other can be specified multiple times.]
    5. If you are not specifying any event name, still specify START-OF-SELECTION to improve readability
    6. After every execution of events NEW-LINE event is executed automatically

    Ref: https://www.gotothings.com/abap/what-are-classical-reports.htm

    https://www.sapnuts.com/courses/core-abap/classical-reports/classical-report-events.html

  • Type Casting in ABAP Class

    Preface – This post is part of the ABAP Programs series.

    Type Casting in ABAP Class

    Note: If you are searching for basic type casting/conversion of ABAP variable in Reports/Program, click here.

    Prerequisite:

    1. You must have a basic Idea of local class and instance/reference of class.

    2. Inheritance and Polymorphism concept

    Note: Parent Class is also called base class and Child class is also called Sub class.

    What is Static and Dynamic Type?

    Before we talk about type casting, we need to know what are static Type and Dynamic type. Each reference variable has a dynamic type and a static type.

    Suppose we have a class C1 and its child class C2.

    So, in our program we will write following code to make reference and create object.

    DATA: obj1 TYPE REF TO C1.

    Here obj1 is our reference variable and C1 is the Static Type.

    Thus anything that comes after TYPE REF TO is a static type because the object obj1 is pointing to fixed or static type [here class C1].

    Now, in our code, we proceed as below:

    CREATE OBJECT obj1.

    In this line we actually point to the class C1 using our object obj1. This pointing is called Dynamic Type and it is pointing to C1 same as the static type above.

    We can also write following code:

    CREATE OBJETC obj1 TYPE C2.

    In this line we are pointing to child class C2 of C1. This pointing is defined at runtime and called as Dynamic Type, and this time it is not same as the static type.

    Thus we conclude that Dynamic type is defined at runtime of the program while static type is declared with the declaration of reference variable. Static type can be same as Dynamic type or less specific than it [it means, it can just point to the parents and not all the child unlike the dynamic type which can].

    What is a Type casting?

    Type Casting in ABAP is just like casting in other computer languages. It is one way of inheriting the properties from either base/parent class or sub/child class into one another. It is used to cast one data type, class or Interface into another data type, class or interface.

    For data type casting, refer here.

    Definition:

    Type casting is a process of converting reference of class or interface to another, given both the class are from same hierarchy i.e. either one of them must be a parent class and the other a child class.

    Syntax:

    Destination_Ref = | ?= Source_Ref.

    Some questions for you:

    Why do we need Type casting?

    How to achieve a type casting?

    Example of Type casting

    What are types of Type Casting?

    Some Basic rules of type casting.

  • Delete Duplicates in ABAP

    Preface – This post is part of the ABAP Programs series.

    To delete duplicates in ABAP either from a string or an internal table, we need to use ABAP statement “DELETE ADJACENT DUPLICATES FROM”. In this article, we have taken an example, which implements deletion of duplicate data when two strings are merged. This process also involves internal table.

    Introduction

    DELETE ADJACENT DUPLICATES FROM <Internal Table> COMPARING <field name>.

    Using the ABAP statement mentioned above, we can compare values of a column of any table/ internal table and delete the duplicates. Once the duplicates are deleted, we get unique values from a string/ internal table.

    SPLIT <variable> AT ‘,’ INTO TABLE <internal table>.

    Using the ABAP statement mentioned above, we can divide a string in to a form of internal table where each data is separated by comma ‘,’.

     

    Delete Duplicates in ABAP
    Delete Duplicates in ABAP – Image Illustration

    ABAP Program to Delete duplicates

    DATA : lv_string       TYPE string,
           lv_string2      TYPE string,
           lv_string_final TYPE string.
    TYPES: BEGIN OF ty_data,
             auth TYPE c,
           END OF ty_data.
    DATA: ls_user  TYPE ty_data,
          ls_user2 TYPE ty_data,
          lt_user2 TYPE TABLE OF ty_data,
          lt_user  TYPE TABLE OF ty_data.
    lv_string = 'a,b,c,a'.
    lv_string2 = 'd,b,c,a'.
    SPLIT lv_string AT ',' INTO TABLE lt_user.
    SPLIT lv_string2 AT ',' INTO TABLE lt_user2.
    LOOP AT lt_user2 ASSIGNING FIELD-SYMBOL(<fs_field>).
      INSERT  <fs_field> INTO TABLE lt_user.
    ENDLOOP.
      SORT lt_user BY auth.
      DELETE ADJACENT DUPLICATES FROM lt_user COMPARING auth.
      IF sy-subrc = 0.
        LOOP AT lt_user ASSIGNING FIELD-SYMBOL(<fs_user_table>).
            IF lv_string_final IS INITIAL.
              lv_string_final = <fs_user_table>-auth.
            ELSE.
              CONCATENATE  lv_string_final <fs_user_table>-auth INTO lv_string_final SEPARATED BY ','.
            ENDIF.
        ENDLOOP.
      ENDIF.
    WRITE lv_string_final.​

    Explanation

    Here, we have written program which tIn the above program, following steps have been implemented:

    1. Initially, we have defined variables: lv_string, lv_string2 and lv_string_final of type string. These variables will be used to feed two input strings and save the merged the string.
    2. Now, we have defined a structure with one field. We have created this so that we can use this field to perform duplicate deletion.
    3. Again, we have defined variables: ls_user, ls_user2, lt_user2 and lt_user. These are the work areas (ls) and internal tables (lt). These will be used to store data line by line from the strings defined in step 01 above.
    4. Now, we will feed some default data in form of strings i.e. lv_string = ‘a,b,c,a’ and lv_string2 = ‘d,b,c,a’. These variables do contain duplicate data.
    5. Here, we converted the strings into internal table.
    6. Then, we deleted duplicates from the internal table created above.
    7. Then, we have again concatenated the new internal table data i.e. unique data into a string divided by comma ‘,’.
    8. In the end, we have printed the string as output.
  • ODATA in ABAP

    Preface – This post is part of the SAP ABAP OData Tutorial series.

    In this article we have just mentioned imported keys related to ODATA in ABAP. To learn OData in detail view our OData tutorial here.

    Index

    • What is ODATA? Why we need it?
    • How to Create an ODATA Service?
    • Exploring ODATA
    • CRUD Operation via ODATA
    • Calling CLASS, FM in ODATA
    • Checking your Service: CRUD

     

    Exploring ODATA

    • Data Model
    • Entity Types
    • Association
    • Entity Sets
    • Vocabularies
    • Service Implementation
    • Runtime Artifacts
    • Service Maintenance

     

    What is ODATA

    • ODATA stands for Open Data.
    • It was created by Microsoft
    • Based on REST API.

    Definition:

    ODATA is the representation of Data in form of XML/JSON.

    • XML for ios based device, JSON for Android based device.

     

    Why ODATA

    • To communicate between different Interfaces

     

    How to create ODATA

    • Go to SEGW.
    • Create a new project
    • Import a DDIC Structure
    • Redefine the methods
    • Generate your ODATA
    • Register your Service

     

    Data Model

    • A Data model can be anything : A table, A structure, A View.
    • When we import a DDIC structure, its Entity Types, Entity Sets, Service Implementation, Runtime Artifacts are created automatically.
    • A Data Model is the one that decides on which fields the CRUD operations will be performed

     

    Runtime Artifacts

    • DPC& DPC_EXT
    • MPC & MPC_EXT
    • The mentioned above are four classes generated by SAP. We only redefine methods of EXT classes, because the codes written in DPC and MPC are provided by SAP, and will override our codes once ODATA is generated.
    • In DPC_EXT we perform CRUD operations
    • IN MPC_EXT we write annotations.
    • Annotations are the extra functionality we want to achieve that is not provided by SAP by default.

     

     

    Operations in ODATA

    • CRUD Operation
    • Same codes that we write in ABAP report will be written here
    • Calling FM & Class
    • Same codes that we write in ABAP report will be written here
    • Taking Data from Frontend:
    • io_data_provider->read_entry_data(IMPORTINGes_data=wa_entity).
    • SendingData to Fronend:
    • et_entitysetor er_entity.

     

    Check your Service via Service Maintenance

    1.To read all files just open your entity and click GET and press Execute

    2.To read one file -Write the primary keys in bracket just after the URI as mentioned here: (ACQ_ID=’NEW1′,BUKRS=’7070′).

    3.To Create, you need to read one file. After reading, click USE AS REQUEST. Change the values of primary keys and other fields you want, click POST Radio Button, remove the Primary keys from URI and click Execute.

    4.To Update Perform Step 02, Click Use as request, just change the fields other than primary keys, Click PUT Radio Button, and Execute.

    5.To Delete, perform Step 02. Click Delete Radio Button, Execute.

     

    What’s Next?

    • Association
    • Vocabularies
    • MPC_EXT
    • Mapping : CDS Views
    • Batch Operation
    • Function Import
    • SICF : Getting your Service Link
    • Whitelisting your Service

     

    Reference:

  • Constructor Program in ABAP

    Preface – This post is part of the ABAP Programs series.

    TYPE-POOLS truxs.
    PARAMETERS p_file TYPE rlgrap-filename.
    TYPES : BEGIN OF t_tab,
              workstream TYPE char50,
              task       TYPE zci_task,
              task_type  TYPE char50,
            END OF t_tab.
    DATA : t_upload1  TYPE STANDARD TABLE OF ZDEMO_TEST2,
           wa_upload1 TYPE ZDEMO_TEST2.
    
    AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
      CALL FUNCTION 'F4_FILENAME'
        EXPORTING
          field_name = 'P_FILE'
        IMPORTING
          file_name  = p_file.
    
    START-OF-SELECTION.
      CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'
        EXPORTING
          i_tab_raw_data       = it_type
          i_filename           = p_file
        TABLES
          i_tab_converted_data = t_upload[]
        EXCEPTIONS
          conversion_failed    = 1
          OTHERS               = 2.
      IF sy-subrc <> 0.
        MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
                WITH sy-msgv1 sy-msgv2 .
      ENDIF.
    
    CALL FUNCTION 'UPLOAD_XLS_FILE_2_ITAB'
      EXPORTING
        i_filename       = p_file
      tables
        e_itab           = t_upload1
     EXCEPTIONS
       FILE_ERROR       = 1
       OTHERS           = 2
              .
    IF sy-subrc <> 0.
     Implement suitable error handling here
    ENDIF.
    
    
    END-OF-SELECTION.
      DATA : ls_cc_impl TYPE ZDEMO_TEST2,
             lt_cc_impl TYPE STANDARD TABLE OF  ZDEMO_TEST2.
      LOOP AT t_upload1 INTO wa_upload1.
        ls_cc_impl-mandt = sy-mandt.
        ls_cc_impl-INCIDENT                  = wa_upload1-INCIDENT.
        APPEND ls_cc_impl TO lt_cc_impl.
      ENDLOOP.
      MODIFY ZDEMO_TEST2 FROM TABLE lt_cc_impl.
    
    CLASS cl_grand DEFINITION.
      PUBLIC SECTION.
        CLASS-DATA v_test TYPE char40.
        CLASS-METHODS class_constructor.
        METHODS constructor.
        DATA a type i.
        CLASS-DATA b TYPE i.
    ENDCLASS.                    "cl_grand DEFINITION
    
    *----------------------------------------------------------------------*
    *       CLASS cl_grand IMPLEMENTATION
    *----------------------------------------------------------------------*
    *
    *----------------------------------------------------------------------*
    CLASS cl_grand IMPLEMENTATION.
      METHOD class_constructor.
        v_test = 'Static Constructor - Grand Parent'.
        b = 30.
        WRITE: /3 v_test.
      ENDMETHOD.                    "class_constructor
      METHOD constructor.
        a = 30.
        v_test = 'Instance Constructor - Grand Parent'.
        WRITE: /3 v_test.
      ENDMETHOD.
    ENDCLASS.                    "cl_grand IMPLEMENTATION
    
    *----------------------------------------------------------------------*
    *       CLASS cl_parent DEFINITION
    *----------------------------------------------------------------------*
    *
    *----------------------------------------------------------------------*
    CLASS cl_parent DEFINITION INHERITING FROM cl_grand.
      PUBLIC SECTION.
        CLASS-METHODS class_constructor.
        METHODS constructor.
    
    ENDCLASS.                    "cl_parent DEFINITION
    
    *----------------------------------------------------------------------*
    *       CLASS cl_parent IMPLEMENTATION
    *----------------------------------------------------------------------*
    *
    *----------------------------------------------------------------------*
    CLASS cl_parent IMPLEMENTATION.
      METHOD class_constructor.
        v_test = 'Static Constructor - Parent'.
        b = 20.
        WRITE: /3 v_test.
      ENDMETHOD.                    "class_constructor
      METHOD constructor .
    *    data a type i.
    
        super->constructor( ).
        a = 20.
        v_test = 'Instance Constructor -Parent'.
        WRITE: /3 v_test.
      ENDMETHOD.
    ENDCLASS.                    "cl_parent IMPLEMENTATION
    
    *----------------------------------------------------------------------*
    *       CLASS cl_child DEFINITION
    *----------------------------------------------------------------------*
    *
    *----------------------------------------------------------------------*
    CLASS cl_child DEFINITION INHERITING FROM cl_parent.
      PUBLIC SECTION.
        CLASS-METHODS class_constructor.
        METHODS constructor.
    *    DATA a.
    ENDCLASS.                    "cl_child DEFINITION
    
    *----------------------------------------------------------------------*
    *       CLASS cl_child IMPLEMENTATION
    *----------------------------------------------------------------------*
    *
    *----------------------------------------------------------------------*
    CLASS cl_child IMPLEMENTATION.
      METHOD class_constructor.
        v_test = 'Static Constructor - Child'.
        WRITE: /3 v_test.
        b = 10.
      ENDMETHOD.                    "class_constructor
      METHOD constructor.
        data a type i.
    a = 10.
        super->constructor( ).
    
        v_test = 'Instance Constructor - Child'.
        WRITE: /3 v_test.
      ENDMETHOD.
    ENDCLASS.                    "cl_child IMPLEMENTATION
    START-OF-SELECTION.
    DATA obj_child TYPE REF TO cl_child.
    CREATE OBJECT obj_child.
    data: a type i,
          b type i.
    a = obj_child->a.
    write a.
    
    write sy-uname.
    delete from ztms_score .
    delete from ztms_ans .
    TYPES: BEGIN OF TY_DATA, "user defined type
           ID TYPE N ,
           NAME TYPE CHAR20,
           SALARY TYPE I,
          END OF TY_DATA.
    DATA : ITAB TYPE TABLE OF TY_DATA. "internal table
    DATA : WA TYPE TY_DATA. "work area
    
    WA-ID = 1.
    WA-NAME = 'Sapnuts'.
    WA-SALARY = 5000.
    COLLECT WA INTO ITAB. "collect
    CLEAR WA.
    
    WA-ID = 2.
    WA-NAME = 'SAPabap'.
    WA-SALARY = 50000.
    COLLECT WA INTO ITAB. "collect
    CLEAR WA.
    
    WA-ID = 1.
    WA-NAME = 'Sapnuts'.
    WA-SALARY = 15000.
    COLLECT WA INTO ITAB. "collect
    CLEAR WA.
    
    LOOP AT ITAB INTO WA.
      WRITE:/ WA-ID, WA-NAME, WA-SALARY. "loop and display data
    ENDLOOP.
    **delete from ztms_score .
    **delete from ztms_ans .
    delete from ztms_user .
    delete from ztms_set .
    delete from ztms_ques .
    

     

  • Casting in ABAP Program

    Preface – This post is part of the ABAP Programs series.

    CLASS a1 DEFINITION.
    PUBLIC SECTION.
    DATA: num1 TYPE i VALUE 100.
    METHODS:m1.
    ENDCLASS.
    
    CLASS a1 IMPLEMENTATION.
    METHOD m1.
    WRITE: 'a1:',num1.
    ENDMETHOD.
    ENDCLASS.
    
    CLASS b1 DEFINITION INHERITING FROM a1.
    PUBLIC SECTION.
    METHODS:m2, m1 REDEFINITION.
    ENDCLASS.
    
    CLASS b1 IMPLEMENTATION.
    METHOD m1.
    num1 = num1 .
    WRITE: 'b1:',num1.
    ENDMETHOD.
    
    METHOD m2.
    WRITE: 'M2 in class b1'.
    ENDMETHOD.
    ENDCLASS.
    
    START-OF-SELECTION.
    
    DATA: a TYPE REF TO a1.
    DATA: b TYPE REF TO b1.
    *data: c type REF TO c1.
    
    
    ****************************************************************
    CREATE OBJECT b.
    a = b. "upcasting
    CALL METHOD a->m1( ).
    *call METHOD a->m2( ). " we can't access the own sub class methods using super class ref.
    NEW-LINE.
    
    b ?= a. " down casting
    CALL METHOD b->m1( ).
    NEW-LINE.
    CALL METHOD b->m2( ).
    
    *****************************************************************
    " error null ref
    create OBJECT a.
    b ?= a. "down casting still its giving dump
    call METHOD b->m1( ).
    
    *****************************************************************
    
    CREATE OBJECT a.
    TRY.
     b ?= a. "u r attempted to use a 'NULL' object reference dump
    CATCH cx_sy_move_cast_error.
     CALL METHOD b->m1( ).
    ENDTRY.
    
    *****************************************************************
    
    CREATE OBJECT a.
    CREATE OBJECT b.
    TRY.
     b ?= a.
    CATCH cx_sy_move_cast_error.
     CALL METHOD b->m1( ).
     call METHOD b->m2( ).
    ENDTRY.
    
    
    
    
    CLASS lcl_shape DEFINITION.
      PUBLIC SECTION.
        METHODS draw.
    ENDCLASS.
    
    CLASS lcl_circle DEFINITION INHERITING FROM lcl_shape.
      PUBLIC SECTION.
        METHODS: draw REDEFINITION,
          calc_area.
    ENDCLASS.
    
    CLASS lcl_shape IMPLEMENTATION.
      METHOD draw.
        WRITE :/ 'Drawing any Shape'.
      ENDMETHOD.
    ENDCLASS.
    
    CLASS lcl_circle IMPLEMENTATION.
      METHOD draw.
        WRITE :/ 'Drawing specific shape: Circle'.
      ENDMETHOD.
    
      METHOD calc_area.
        WRITE :/ 'Area Of Crcle = 2iiR'.
      ENDMETHOD.
    ENDCLASS.
    
    START-OF-SELECTION.
      DATA : o_cir TYPE REF TO lcl_circle.
      CREATE OBJECT o_cir.
      CALL METHOD o_cir->draw( ). " calls subclass Draw() method
      CALL METHOD o_cir->calc_area( ).
      ULINE.
      "--------- Narrow cast(Upcast)---------------"
      DATA : o_shp TYPE REF TO lcl_shape.
      o_shp = o_cir. "  Narrow cast(Upcast)
      CALL METHOD o_shp->draw( ). " calls sub class Draw() method
      "call METHOD o_shp->calc_area( ) . " compilation error
      ULINE.
    
      "---------- Widening Cast(Downcast) -----------"
    
      DATA : o_cir1 TYPE REF TO lcl_circle.
    
      " o_cir1 = o_shp. "  complilation error
      o_cir1 ?= o_shp.  " Widening Cast(Downcast)
      CALL METHOD o_cir1->draw( ). " calls subclass Draw() method
      CALL METHOD o_cir1->calc_area( ).
    
    CLASS a1 DEFINITION.
    PUBLIC SECTION.
    DATA: num1 TYPE i VALUE 100.
    METHODS:m1.
    ENDCLASS.
    
    CLASS a1 IMPLEMENTATION.
    METHOD m1.
    WRITE: 'a1:',num1.
    ENDMETHOD.
    ENDCLASS.
    
    CLASS b1 DEFINITION INHERITING FROM a1.
    PUBLIC SECTION.
    METHODS:m2, m1 REDEFINITION.
    ENDCLASS.
    
    CLASS b1 IMPLEMENTATION.
    METHOD m1.
    num1 = num1 .
    WRITE: 'b1:',num1.
    ENDMETHOD.
    
    METHOD m2.
    WRITE: 'M2 in class b1'.
    ENDMETHOD.
    ENDCLASS.
    
    START-OF-SELECTION.
    
    DATA: parent TYPE REF TO a1.
    DATA: child TYPE REF TO b1.
    *data: c type REF TO c1.
    
    
    ****************************************************************
    CREATE OBJECT child.
    parent = child. "upcasting
    CALL METHOD parent->m1( ).
    CALL METHOD child->m1( ).
    CALL METHOD child->m2( ).
    *call METHOD a->m2( ). " we can't access the own sub class methods using super class ref.
    NEW-LINE.
    
    child ?= parent. " down casting
    CALL METHOD child->m1( ).
    NEW-LINE.
    CALL METHOD child->m2( ).
    
    ******************************************************************
    *" error null ref
    *create OBJECT a.
    *b ?= a. "down casting still its giving dump
    *call METHOD b->m1( ).
    
    ******************************************************************
    *
    CREATE OBJECT a.
    TRY.
     b ?= a. "u r attempted to use a 'NULL' object reference dump
    CATCH cx_sy_move_cast_error.
     CALL METHOD b->m1( ).
    ENDTRY.
    
    ******************************************************************
    *
    CREATE OBJECT a.
    CREATE OBJECT b.
    TRY.
     b ?= a.
    CATCH cx_sy_move_cast_error.
     CALL METHOD b->m1( ).
     call METHOD b->m2( ).
    ENDTRY.
    
    ******** Unique Values******************
     
    DATA : lv_string       TYPE string,
           lv_string2      TYPE string,
           lv_string_final TYPE string.
    TYPES: BEGIN OF ty_data,
             auth TYPE c,
           END OF ty_data.
    DATA: ls_user  TYPE ty_data,
          ls_user2 TYPE ty_data,
          lt_user2 TYPE TABLE OF ty_data,
          lt_user  TYPE TABLE OF ty_data.
    lv_string = 'a,b,c,a'.
    lv_string2 = 'd,b,c,a'.
    SPLIT lv_string AT ',' INTO TABLE lt_user.
    SPLIT lv_string2 AT ',' INTO TABLE lt_user2.
    LOOP AT lt_user2 ASSIGNING FIELD-SYMBOL(<fs_field>).
      INSERT  <fs_field> INTO TABLE lt_user.
    ENDLOOP.
      SORT lt_user BY auth.
      DELETE ADJACENT DUPLICATES FROM lt_user COMPARING auth.
      IF sy-subrc = 0.
        LOOP AT lt_user ASSIGNING FIELD-SYMBOL(<fs_user_table>).
            IF lv_string_final IS INITIAL.
              lv_string_final = <fs_user_table>-auth.
            ELSE.
              CONCATENATE  lv_string_final <fs_user_table>-auth INTO lv_string_final SEPARATED BY ','.
            ENDIF.
        ENDLOOP.
      ENDIF.
    WRITE lv_string_final.

     

  • Editable ALV Program in ABAP

    Preface – This post is part of the ABAP Programs series.

    Introduction

    ALV in ABAP enables users to view data in a tabular format. We can even make it editable. In this article, we will explore the same.

    Editable ALV Program in ABAP

    ************************************************************************
    *   INTERNAL TABLES
    ************************************************************************
    
    DATA: lt_mapping  TYPE STANDARD TABLE OF zBarry_emp,
          lt_fieldcat TYPE lvc_t_fcat.
    
    ************************************************************************
    *   WORK AREAS
    ************************************************************************
    DATA: ls_fieldcat TYPE lvc_s_fcat,
          ls_mapping  TYPE zBarry_emp,
          lw_layout   TYPE lvc_s_layo.
    
    ************************************************************************
    *   REFERENCE OBJECT
    ************************************************************************
    DATA:  r_container TYPE REF TO cl_gui_custom_container,
           r_grid      TYPE REF TO cl_gui_alv_grid.
    
    
    ************************************************************************
    *   Field symbol
    ************************************************************************
    
    FIELD-SYMBOLS: <ls_fieldcat>   TYPE lvc_s_fcat.
    
    ************************************************************************
    *   START-OF-SELECTION.
    ************************************************************************
    START-OF-SELECTION.
      SELECT *
        FROM zBarry_emp
        INTO TABLE lt_mapping
        UP TO 20 ROWS.
    
    * Call screen 200
      CALL SCREEN 200.
    
    MODULE status_0200 OUTPUT.
      SET PF-STATUS 'PF-STATUS'.
      SET TITLEBAR 'TITLE'.
    
      CREATE OBJECT r_container
        EXPORTING
          container_name = 'CUSTOM_1'.
    
      CREATE OBJECT r_grid
        EXPORTING
          i_parent = r_container.
    
    
    * create Field Catalog
      ls_fieldcat-fieldname = 'EMP_FNAME'.
      ls_fieldcat-tabname   = 'zBarry_emp'.
      ls_fieldcat-seltext   = 'Employee Name'.
      ls_fieldcat-edit      = 'X'.
      APPEND ls_fieldcat TO lt_fieldcat.
      CLEAR ls_fieldcat.
    
      ls_fieldcat-fieldname = 'EMP_LNAME'.
      ls_fieldcat-tabname   = 'zBarry_emp'.
      ls_fieldcat-seltext   = 'Employee Last Name'.
      ls_fieldcat-edit      = 'X'.
    *ls_fieldcat-hotspot   = 'X'.
      APPEND ls_fieldcat TO lt_fieldcat.
      CLEAR ls_fieldcat.
    
      CALL METHOD r_grid->set_table_for_first_display
        EXPORTING
    *     I_BUFFER_ACTIVE               =
    *     I_BYPASSING_BUFFER            =
    *     I_CONSISTENCY_CHECK           =
          i_structure_name              = 'zBarry_emp'
    *     IS_VARIANT                    =
          i_save                        = 'A'
          i_default                     = abap_true
          is_layout                     = lw_layout
    *     IS_PRINT                      =
    *     IT_SPECIAL_GROUPS             =
    *     IT_TOOLBAR_EXCLUDING          =
    *     IT_HYPERLINK                  =
    *     IT_ALV_GRAPHICS               =
    *     IT_EXCEPT_QINFO               =
    *     IR_SALV_ADAPTER               =
        CHANGING
          it_outtab                     = lt_mapping
          it_fieldcatalog               = lt_fieldcat
    *     IT_SORT                       =
    *     IT_FILTER                     =
        EXCEPTIONS
          invalid_parameter_combination = 1
          program_error                 = 2
          too_many_lines                = 3
          OTHERS                        = 4.
      IF sy-subrc <> 0.
    * Implement suitable error handling here
      ENDIF.
    
    
    
    
    ENDMODULE.
    
    *&---------------------------------------------------------------------*
    *&      Module  USER_COMMAND_0200  INPUT
    *&---------------------------------------------------------------------*
    *       text
    *----------------------------------------------------------------------*
    MODULE user_command_0200 INPUT.
    
      CASE sy-ucomm.
        WHEN 'BACK' OR 'EXIT' OR 'CANCEL'.
          LEAVE PROGRAM.
          LEAVE TO SCREEN 0.
        WHEN 'SAVE'.
          DATA: lt_t_row TYPE lvc_t_row,
                ls_t_row LIKE LINE OF lt_t_row
                .
          FIELD-SYMBOLS: <fs_changed_data> LIKE LINE OF lt_mapping.
          CALL METHOD r_grid->check_changed_data.
          CALL METHOD r_grid->get_selected_rows
            IMPORTING
              et_index_rows = lt_t_row.   " Indexes of Selected Rows
    
          LOOP AT lt_t_row INTO ls_t_row.
    
            READ TABLE lt_mapping ASSIGNING <fs_changed_data> INDEX ls_t_row-index.
            IF sy-subrc = 0.
              MODIFY zBarry_emp FROM  <fs_changed_data>.
            ENDIF.
          ENDLOOP.
      ENDCASE.
    ENDMODULE.