Wednesday, 1 June 2016

Move-corresponding


  • Move-corresponding  : corresponding fields we can pass from one work area to another.
  • Syntax

           Move-corresponding  <Source work Area > TO <Destination Work Area>

Ex :

Steps

  1. Go to transaction code SE38.
  2. Enter the program name Z or Y<program name>.
  3. Select attribute type as Executable program.
  4. Click on Save.


Source Code




REPORT  ZTOT_SUB NO STANDARD PAGE HEADING.




TYPES BEGIN OF TY_VBRP,
        VBELN TYPE VBRP-VBELN,
        POSNR TYPE VBRP-POSNR,
        MATNR TYPE VBRP-MATNR,
        ARKTX TYPE VBRP-ARKTX,
        NETWR TYPE VBRP-NETWR,
        END OF TY_VBRP.


DATA WA_VBRP TYPE TY_VBRP,
       IT_VBRP TYPE TABLE OF TY_VBRP.

DATA WA_TEMP TYPE VBRP,
       IT_TEMP TYPE TABLE OF VBRP.

SELECT-OPTIONS S_VBELN FOR WA_VBRP-VBELN.


SELECT VBELN POSNR MATNR ARKTX   NETWR FROM VBRP INTO TABLE IT_VBRP
WHERE
  VBELN IN S_VBELN.


LOOP AT IT_VBRP INTO WA_VBRP.

    MOVE-CORRESPONDING  WA_VBRP TO WA_TEMP.


  WRITE / WA_VBRP-VBELN WA_VBRP-POSNR WA_VBRP-MATNR ,
WA_VBRP-ARKTX WA_VBRP-NETWR.

   APPEND WA_TEMP TO IT_TEMP.

   CLEAR WA_TEMP WA_VBRP .


ENDLOOP.


ULINE.


LOOP AT IT_TEMP INTO WA_TEMP.

  WRITE / WA_TEMP-VBELN WA_TEMP-MATNR.

ENDLOOP.


  • Save->check->Activate->Execute.

Input


Output





Move

  • Move : we can move the content of one work area into another work area if only exact structure of both work area’s are matching.
  • Syntax
              MOVE <Source work Area > TO <Destination Work Area>

Ex :

Steps

  1. Go to transaction code SE38.
  2. Enter the program name Z or Y<program name>.
  3. Select attribute type as Executable program.
  4. Click on Save

Source Code


REPORT  ZTOT_SUB NO STANDARD PAGE HEADING.



TYPES BEGIN OF TY_VBRP,
        VBELN TYPE VBRP-VBELN,
        POSNR TYPE VBRP-POSNR,
        MATNR TYPE VBRP-MATNR,
        ARKTX TYPE VBRP-ARKTX,
        NETWR TYPE VBRP-NETWR,
        END OF TY_VBRP.


DATA WA_VBRP TYPE TY_VBRP,
       IT_VBRP TYPE TABLE OF TY_VBRP.

DATA WA_TEMP TYPE TY_VBRP,
       IT_TEMP TYPE TABLE OF TY_VBRP.

SELECT-OPTIONS S_VBELN FOR WA_VBRP-VBELN.


SELECT VBELN POSNR MATNR ARKTX   NETWR FROM VBRP INTO TABLE IT_VBRP
WHERE
  VBELN IN S_VBELN.


LOOP AT IT_VBRP INTO WA_VBRP.

    MOVE WA_VBRP TO WA_TEMP.



  WRITE / WA_VBRP-VBELN WA_VBRP-POSNR WA_VBRP-MATNR ,
WA_VBRP-ARKTX WA_VBRP-NETWR.

   APPEND WA_TEMP TO IT_TEMP.

   CLEAR WA_TEMP WA_VBRP .


ENDLOOP.


ULINE.


LOOP AT IT_TEMP INTO WA_TEMP.

  WRITE / WA_TEMP-VBELN WA_TEMP-MATNR.

ENDLOOP.



Input



Output





On change of


On change of

  • On change of similar to AT New . But it is not a control break statement.
  • It can be used within the loop or outside loop, even while , do loop also.
  • Syntax
      On change of <work_area-fieldname>.
       --------------
       ---------------
      ------- --------
     EndOn.


Ex :

Steps

  1. Go to transaction code SE38.
  2. Enter the program name Z or Y<program name>.
  3. Select attribute type as Executable program.
  4. Click on Save.



Source Code

REPORT  ZTOT_SUB NO STANDARD PAGE HEADING.


TYPES BEGIN OF TY_VBRP,
        VBELN TYPE VBRP-VBELN,
        POSNR TYPE VBRP-POSNR,
        MATNR TYPE VBRP-MATNR,
        ARKTX TYPE VBRP-ARKTX,
        NETWR TYPE VBRP-NETWR,
        END OF TY_VBRP.


DATA WA_VBRP TYPE TY_VBRP,
       IT_VBRP TYPE TABLE OF TY_VBRP.

DATA TOTAL TYPE VBRP-NETWR VALUE 0.

DATA SUB TYPE VBRP-NETWR VALUE 0.
SELECT-OPTIONS S_VBELN FOR WA_VBRP-VBELN.


SELECT VBELN POSNR MATNR ARKTX   NETWR FROM VBRP INTO TABLE IT_VBRP
WHERE
  VBELN IN S_VBELN.


LOOP AT IT_VBRP INTO WA_VBRP.

AT FIRST.

  WRITE /20 'SALES ORDER ITEM DETAILS' COLOR 4.

ENDAT.



AT NEW VBELN.
  ULINE.
  WRITE 'NEW BILL DOC : ' COLOR WA_VBRP-VBELN.

ENDAT.
  WRITE / WA_VBRP-VBELN WA_VBRP-POSNR WA_VBRP-MATNR ,
WA_VBRP-ARKTX WA_VBRP-NETWR.

TOTAL  TOTAL  +  WA_VBRP-NETWR.

SUB SUB + WA_VBRP-NETWR.

ON CHANGE OF WA_VBRP-VBELN.

  WRITE /60  'SUB-TOTAL' COLOR '='SUB.
  CLEAR SUB.
ENDON.

AT LAST.

  WRITE /50 'TOTAL' COLOR '='TOTAL.
ENDAT.

ENDLOOP.

  • Save ->check -> activate->Execute.

Input


Output



Control Break Statements

Control Break Statements
  • 4 types
  1. AT First.
  2. AT Last.
  3. AT new.
  4. AT end of.

AT First.

  • Inside the loop if you want to perform certain action at first  , then use At First .
  • Syntax
     AT First.
      ------------
      -----------
      -----------
   ENDAT.

Ex : Top of page.

AT Last.


    • Inside the loop if you want to perform certain action at last  , then use At Last .
    • Syntax
        AT Last.
          ------------
          -----------
          -----------
         ENDAT.

    Ex : footer.



    AT new.

    • Inside the  loop if you want to perform certain action on every beginning of new field  , then use At new .
    • Syntax

        AT  NEW <field-name>.
          ------------
          -----------
          -----------
        ENDAT.


    AT end of

    • Inside the  loop if you want to perform certain action on every end of new field  , then use At end of .
    • Syntax

        AT  END of  <field-name>.
          ------------
          -----------
          -----------
        ENDAT.


    Ex :

    Steps


    1. Go to transaction code SE38.
    2. Enter the program name Z or Y<program name>.
    3. Select attribute type as Executable program.
    4. Click on Save.

    Source Code



    REPORT  ZTOT_SUB NO STANDARD PAGE HEADING.


    TYPES BEGIN OF TY_VBRP,
            VBELN TYPE VBRP-VBELN,
            POSNR TYPE VBRP-POSNR,
            MATNR TYPE VBRP-MATNR,
            ARKTX TYPE VBRP-ARKTX,
            NETWR TYPE VBRP-NETWR,
            END OF TY_VBRP.


    DATA WA_VBRP TYPE TY_VBRP,
           IT_VBRP TYPE TABLE OF TY_VBRP.

    DATA TOTAL TYPE VBRP-NETWR VALUE 0.

    DATA SUB TYPE VBRP-NETWR VALUE 0.
    SELECT-OPTIONS S_VBELN FOR WA_VBRP-VBELN.


    SELECT VBELN POSNR MATNR ARKTX   NETWR FROM VBRP INTO TABLE IT_VBRP
    WHERE
      VBELN IN S_VBELN.


    LOOP AT IT_VBRP INTO WA_VBRP.

    AT FIRST.

      WRITE /20 'SALES ORDER ITEM DETAILS' COLOR 4.

    ENDAT.

    AT NEW VBELN.
      ULINE.
      WRITE 'NEW BILL DOC : ' COLOR WA_VBRP-VBELN.

    ENDAT.
      WRITE / WA_VBRP-VBELN WA_VBRP-POSNR WA_VBRP-MATNR ,
    WA_VBRP-ARKTX WA_VBRP-NETWR.

    TOTAL  TOTAL  +  WA_VBRP-NETWR.

    SUB SUB + WA_VBRP-NETWR.

    AT END OF VBELN.

      WRITE /60  'SUB-TOTAL' COLOR '='SUB.
      CLEAR SUB.
    ENDAT.

    AT LAST.

      WRITE /50 'TOTAL' COLOR '='TOTAL.
    ENDAT.

    ENDLOOP.





    Input



    Output


    Tuesday, 31 May 2016

    Object Orientation



    Definitions of Some object Oriented Concepts ( Terms ).

    • Encapsulation :
    1. Objects restrict the visibility of their resources (attributes and methods ) to other users.
    2. Every object has an interface, which determines how other objects can interact with it.
    3. The implementation of the object is encapsulated, that is, invisible outside the object itself.

    • Classes :
    1. Class is a section of source code that contains data and provides services into a Single Unit.
    2. The data from the attributes and the services are known as methods.
    3. Encapsulation is supported through Classes.
    4. Global Class is an ABAP object which can be accessed via SAP Class Builder, T-code for SAP Class Builder is SE24.
    5. Local classes are classes that are available in ABAP programs, we can access them via ABAP editor SE38.

    • Objects :
    1. From a technical point of view, objects are run-time instances of a class.
    2. We can create any number of objects based on a single class.
    3. Each instance(object) of a class has a unique identity and its own set of values for its attributes.
    • Polymorphism :
    1. Identical ( identically-named ) methods behave differently in different classes.
    2. object-oriented programming contains constructions called interfaces. They enable you to address methods with the same name in different objects.
    3. Although the form of address is always the same, the implementation of the method is specific to a particular class.
    4. Method overwriting: Same method name with the same signature can exist in 2 or more classes.
    5. Method overloading: Inside the class, 2 or more methods can have the same but different signatures.
    • Inheritance :
    1. We can use an existing class to drive a new class. Derived classes inherit the data and methods of the superclass.
    2. However, they can overwrite existing methods, and also add new ones.
    Object-Oriented Approach - key features
    • Better Programming Structure.
    • Real-world entities can be modeled very well.
    • Stress on data security and access.
    • Reduction in code redundancy.
    • Data encapsulation and abstraction.
                                 more information..................


    Field symbols


    • Field symbols are pointers in C.
    • They are used to store the address of variable.
    • Used to increase the performance .
    • Syntax :
                     Field symbols :  <fs> [typing].
    • Assigning  is the keyword to assign the field symbol to variable.

    Ex :

    Steps :

    1. Go to transaction code SE38.
    2. Enter the program name Z or Y<program name>
    3. Select attribute type as Executable program.
    4. Click on Save.

    Source Code


    REPORT  ZFIELDSYMBOL3.

    DATA IT_MAKT TYPE  TABLE OF MAKT.

    FIELD-SYMBOLS <FS> TYPE MAKT.


    SELECT-OPTIONS S_MATNR FOR <FS>-MATNR.

    SELECT FROM MAKT INTO TABLE IT_MAKT WHERE MATNR IN S_MATNR.


    LOOP AT IT_MAKT ASSIGNING <FS>.


    WRITE / <FS>-MATNR <FS>-SPRAS <FS>-MAKTX.
    ENDLOOP.



    Input


    Output



    For all entries


    • Syntax
    ... FOR ALL ENTRIES IN itab WHERE ... col operator itab-comp ...

    • If the addition FOR ALL ENTRIES is specified before the language element WHERE of the SELECT statement, the components comp of the internal table itab specified there can be used in sql_cond as the operands of comparisons with relational operators.
    • The specified component comp must be compatible with the column col.
    • The internal table itab can have a structured or an elementary row type. For an elementary row type, the pseudo component table_line must be specified for comp.

    Note


    1. Check the for all entries table  is not empty  or not.
    2. Write all key field in selection criteria.
    3. Data type and length of for all entries matching field should be match for both the table.
    Ex :

    Steps

    1. Go to transaction code SE38.
    2. Enter the program name Z or Y<program name>
    3. Select attribute type as Executable program.
    4. Click on Save.

    Source Code




    REPORT  ZFORALLENTRIES.

    TYPESBEGIN OF TY_SA,
           VBELN TYPE VBAK-VBELN,
           ERDAT TYPE VBAK-ERDAT,
           ERNAM TYPE VBAK-ERNAM,
           NETWR TYPE VBAK-NETWR,
           VKORG TYPE VBAK-VKORG,
           POSNR TYPE VBAP-POSNR,
           MATNR TYPE VBAP-MATNR,
           END OF TY_SA.


    TYPES BEGIN OF TY_MAT,
            MATNR TYPE MAKT-MATNR,
            MAKTX TYPE MAKT-MAKTX,
            END OF TY_MAT.

    TYPES BEGIN OF TY_SO,
           VBELN TYPE VBAK-VBELN,
           ERDAT TYPE VBAK-ERDAT,
           ERNAM TYPE VBAK-ERNAM,
           NETWR TYPE VBAK-NETWR,
           VKORG TYPE VBAK-VKORG,
           POSNR TYPE VBAP-POSNR,
           MATNR TYPE VBAP-MATNR,
           MAKTX TYPE MAKT-MAKTX,
          END OF TY_SO.

     DATA WA_SA TYPE TY_SA,
            IT_SA TYPE SORTED TABLE OF TY_SA WITH  NON-UNIQUE KEY ERNAM,
            WA_MAT TYPE TY_MAT,
            IT_MAT TYPE TABLE OF TY_MAT,
            WA_SO TYPE TY_SO,
            IT_SO TYPE TABLE OF TY_SO.


    SELECT-OPTIONS S_VBELN FOR WA_SA-VBELN.


    SELECT A~VBELN
           A~ERDAT
           A~ERNAM
           A~NETWR
           VKORG
           POSNR
           MATNR  INTO TABLE IT_SA FROM VBAK AS A INNER JOIN VBAP AS B
           ON B~VBELN A~VBELN WHERE A~VBELN IN S_VBELN  .


      IF IT_SA  IS NOT INITIAL.

        SELECT MATNR MAKTX FROM MAKT INTO TABLE IT_MAT FOR ALL ENTRIES IN IT_SA

          WHERE MATNR IT_SA-MATNR AND  SPRAS 'EN'.


      ENDIF.



    LOOP AT IT_SA INTO WA_SA.
      WA_SO-VBELN WA_SA-VBELN.
      WA_SO-ERDAT  WA_SA-ERDAT.
      WA_SO-ERNAM    WA_SA-ERNAM.
      WA_SO-NETWR  WA_SA-NETWR.
      WA_SO-VKORG WA_SA-VKORG.
      WA_SO-POSNR  WA_SA-POSNR.
      WA_SO-MATNR  WA_SA-MATNR.

     CLEAR WA_MAT.
      READ TABLE   IT_MAT  INTO WA_MAT WITH  KEY MATNR WA_SA-MATNR BINARY SEARCH.
     IF SY-SUBRC 0.
      WA_SO-MAKTX WA_MAT-MAKTX.

     ENDIF.


      APPEND WA_SO TO IT_SO.


    ENDLOOP.



    LOOP AT IT_SO INTO WA_SO.

      WRITE / WA_SO-VBELN ,
                WA_SO-ERDAT,
                WA_SO-ERNAM,
                WA_SO-NETWR,
                WA_SO-VKORG,
                WA_SO-POSNR,
                WA_SO-MATNR,
                WA_SO-MAKTX.

    ENDLOOP.

    Input


    Output


    Left Outer Join


    • In Left Outer Join , we can fetch similar records from  2 or more tables as well as  all the records from the left hand side table.
    • Keyword : Left Outer Join
    • Suppose  TABA and TABB are two tables, then
               



    Ex :

    Steps:

    1. Go to transaction code SE38.
    2. Enter the program name Z or Y<program name>
    3. Select attribute type as Executable program.
    4. Click on Save.


    Source Code


    TYPES BEGIN OF T_STR,
            VBELN TYPE VBAP-VBELN,
            POSNR TYPE VBAP-POSNR,
            MATNR TYPE VBAP-MATNR,
            MAKTX TYPE MAKT-MAKTX,
          END OF T_STR.

    DATA ITAB TYPE TABLE OF T_STR,
           WA TYPE T_STR.


    SELECT-OPTIONS P_VBELN FOR WA-VBELN.

    SELECT VBELN
           POSNR
           A~MATNR
           MAKTX
           INTO TABLE ITAB
           FROM VBAP AS A LEFT OUTER JOIN  MAKT AS ON B~MATNR A~MATNR
           WHERE VBELN in P_VBELN .

     LOOP AT ITAB INTO WA.
       WRITE / WA-VBELN WA-POSNR WA-MATNR WA-MAKTX.
     ENDLOOP.





    Save -> Check->Activate ->Execute.

    Input


    Output




    Inner Join


    • With an inner join, you only get the records of the cross-product for which there is an entry in all tables used in the view.
    • Keyword  : Inner Join .
    • Suppose  TABA and TABB are two tables, then

    •  Inner join result will be

       
    Ex :

    Steps

    1. Go to transaction code SE38.
    2. Enter the program name Z or Y<program name>
    3. Select attribute type as Executable program.
    4. Click on Save.

    Source Code


    TYPES BEGIN OF T_STR,
            VBELN TYPE VBAP-VBELN,
            POSNR TYPE VBAP-POSNR,
            MATNR TYPE VBAP-MATNR,
            MAKTX TYPE MAKT-MAKTX,
          END OF T_STR.

    DATA ITAB TYPE TABLE OF T_STR,
           WA TYPE T_STR.


    SELECT-OPTIONS P_VBELN FOR WA-VBELN.

    SELECT VBELN
           POSNR
           A~MATNR
           MAKTX
           INTO TABLE ITAB
           FROM VBAP AS A INNER JOIN MAKT AS ON B~MATNR A~MATNR
           WHERE VBELN in P_VBELN AND SPRAS 'EN'.

     LOOP AT ITAB INTO WA.
       WRITE / WA-VBELN WA-POSNR WA-MATNR WA-MAKTX.
     ENDLOOP.






    Save -> Check -> Activate -> Execute.

    Input



    Output





    Internal Table with header Line




    • Syntax 

             DATA: <Internal table name> like <table structure/ structure name > occurs 0 with header line.
      

                                                   OR
       

            DATA : <Internal table name> like standard table of <structure name> with header line.
             

    Ex 1 :


    Data: itab like mara occurs 0 with header line.
    or
    Data :itab like standard table of ekko with header line.

    Ex 2:

    Steps :

    1. Go to transaction code SE38.
    2. Enter the program name Z or Y<program name>.
    3. Select attribute type as Executable program.
    4. Click on Save.

    Source Code



    TYPES BEGIN OF TY_MAT,
            NAME(12TYPE C,
            AGE TYPE I,
            PLACE(20TYPE C,
            END OF TY_MAT.

    DATAIT_MAT TYPE TABLE OF TY_MAT WITH HEADER LINE.


    IT_MAT-NAME 'MANI'.
    IT_MAT-AGE  23.
    IT_MAT-PLACE 'BANGALORE'.

    APPEND IT_MAT .

    CLEAR IT_MAT.

    IT_MAT-NAME 'RAHUL'.

    IT_MAT-PLACE 'CHENAI'.

    APPEND IT_MAT .

    CLEAR IT_MAT.



    LOOP AT IT_MAT .

      WRITE / IT_MAT-NAME ,IT_MAT-AGE ,IT_MAT-PLACE.

    ENDLOOP.




    Save ->check->activate->execute.

    Output



    Ex 3 :

    Steps :

    1. Go to transaction code SE38.
    2. Enter the program name Z or Y<program name>.
    3. Select attribute type as Executable program.
    4. Click on Save.

    Source Code


    TYPES BEGIN OF TY_MAT,
            MATNR TYPE MAKT-MATNR,
            SPRAS TYPE MAKT-SPRAS,
            MAKTX TYPE MAKT-MAKTX,
            END OF TY_MAT.

    DATAIT_MAT TYPE TABLE OF TY_MAT WITH HEADER LINE.


    SELECT-OPTIONS S_MATNR FOR IT_MAT-MATNR.


    SELECT MATNR SPRAS MAKTX FROM MAKT INTO TABLE IT_MAT
      WHERE MATNR IN  S_MATNR.


    LOOP AT IT_MAT .

      WRITE / IT_MAT-MATNR IT_MAT-SPRAS IT_MAT-MAKTX.

    ENDLOOP.




    Save -> Check -> Activate-> Execute.


    Input


    Output




    Ex 4:


    Steps :


    1. Go to transaction code SE38.
    2. Enter the program name Z or Y<program name>.
    3. Select attribute type as Executable program.
    4. Click on Save.

    Source Code


    DATA BEGIN OF TY_VBAK OCCURS 0,
            VBELN TYPE VBAK-VBELN,
            ERDAT TYPE VBAK-ERDAT,
            ERNAM TYPE VBAK-ERNAM,
            NETWR TYPE  VBAK-NETWR,
           END OF TY_VBAK.

    SELECT-OPTIONS S_VBELN FOR TY_VBAK-VBELN.


    SELECT VBELN
           ERDAT
           ERNAM
           NETWR FROM VBAK INTO TABLE TY_VBAK[] WHERE VBELN IN S_VBELN.


      LOOP AT TY_VBAK  .

        WRITE / TY_VBAK-VBELN TY_VBAK-ERDAT TY_VBAK-ERNAM TY_VBAK-NETWR.

      ENDLOOP.




    Input


    Output