+++> 1. SAP BW - ABAP Overview - Part 1

Overview of ABAP

  • ABAP is a 4th generation language
  • ABAP has no versions, it is called as ABAP or ABAP/4
  • SAP R/2 is the first ERP product in market by SAP, which worked based on Main frames. Under R/2 we can find ABAP language, which is designed based on COBOL.
  • Next ERP product from SAP is R/3, this worked based on RDBMS concept. ABAP language in R/3 is designed based on C Language. This product is database independent & platform independent.
  • SAP R/3 architecture is a 3 tier architecture, designed based on Client & server architecture. While working with R/3, between Client & server we can find the Application server.





  • The Complete ABAP Language is executed in Application server.
  • Client is group of user IDS
Example: SAP AG
SAP R/3
Client 000(Master Client)
By copying client 000, admin will create below clients
   1. Development Client - To design the objects
   2. Quality/Test Client - For quality check of designed objects
   3. Production Client - Real time business runs. Under production client, we can find end users of the company.

ABAP Workbench Tools
  1. Repository Browser (SE80) - It works like directory for storing SAP objects
  2. Dictionary (SE11) - For creating Database related activities. Like Tables, Structures, Domains, data elements etc.
  3. ABAP Editor (SE38) - For designing Programs in ABAP Language
  4. Function Builder (SE37) - For creating Functions in ABAP
  5. Screen Painter (SE51) & Menu painter (SE41) - For designing applications in R/3.
All together we will call these as BOR - Business Object Repository

Dictionary (SE11)
Dictionary Objects:
  1. Tables
  2. Views
  3. Data Types
  4. Type Groups
  5. Domain
  6. Search help
  7. Lock Objects

Table:
  • Table will be defined with a set of fields, with their data types & length.
  • Whenever a table is activated, a physical table will be created in the DB with the same structure.
  • To create a Table, provide the details of Delivery & maintainance, Technical Settings & Fields.
  • Delivery & Maintainance will have Delivery Class
  • Delivery Class specified about Type of Table. Like Application Table, Custom table etc
  • Technical settings have Data Class & Size Category
  • Data Class specifies the Type of data the table holds.
  • Like: Master data, transaction data & control data
  • Size Category is to define the size of the table
  • Fields of the table are nothing but the columns of the table.
  • The fields are maintained with a reference type. The reference type specifies the characteristics of the field, like data type, length, description etc. Here data elements are used as a reference for the fields.
  • Screens to create the table:



Data Element Creation
  • Using data element, field labels will be maintained for a field.
  • Data element internally refers a domain for the technical attributes of the particular field.


How to Learn SAP BW ABAP With Basic Programming Scenarios
Go to Transaction Code SE38 ( ABAP Initial Program)--> Provide the Program name

(ZB12_DATA_TYPES_1) ----> Click On Create

*&---------------------------------------------------------------------*



*& Report  ZB12_DATA_TYPES_1
*&
*&---------------------------------------------------------------------*
REPORT  ZB12_DATA_TYPES_1.
* DATA TYPES
* 1. CHAR TYPE
* DECLARTION.

DATA : VAR1,
      VAR2 TYPE C,
      VAR3(5) TYPE C,
      VAR4 LIKE VAR3,
      VAR5(10) TYPE C VALUE 'WELCOME'.



* DATA ASSIGNMENT

    BREAK-POINT.

      VAR1 = 'AB'.
      VAR2 = 'ZY'.
      MOVE 'OBJECTS' TO VAR3.
      MOVE 'MYPROGRAM' TO VAR4.

*
*WRITE:/ VAR1, VAR2, VAR3, VAR4, VAR5.
WRITE:/ 'V1:', VAR1, 'V2:', VAR2, 'V3:', VAR3,'V4:', VAR4,
       'V5:', VAR5.
skip.
* 2. NUM TEXT

DATA : NVAR1 TYPE N,
       NVAR2(10) TYPE N,
       NVAR3 LIKE NVAR2,
       NVAR4(10) TYPE N VALUE '9999999999'.

       BREAK-POINT.
  NVAR1 = 123.
  NVAR2 = 560037.
  MOVE 9739007054 TO NVAR3.

  MOVE '767867878' TO NVAR4.
  WRITE:/ NVAR1,
        / NVAR2,
        / NVAR3,
        / NVAR4.

skip 2.
* 3. date.

   data : dat1 type d,    " yyyymmdd
          dat2 like dat1,
          dat3 type sy-datum.

    dat1 = '20130112'. "yyyymmdd

    dat2 = sy-datum.
    dat3 = sy-datum.
    write:/ dat1,
          / dat2,
          / dat3.

*4. time

* DEFINE VARIABLES
 data : time1 type t,
        time2  like time1,
        time3 type sy-uzeit.

*FILL OR POPULATE VARAIBLES WITH DATA
  time1 = '091058'. " HH:MM:SS
  TIME2 = SY-UZEIT.
  TIME3 = SY-UZEIT.
SKIP.
* OUT PUT THE DATA
  WRITE:/ TIME1,
        / TIME2,
        / TIME3,
        / SY-PAGNO.

*dATA TYPE : i - INTEGER  " ctrl + <  to comment the code
*            P - PACKed
*            f  -float

    data : lv_int type i,
           lv_pack1 type p,
           lv_pack2 type p decimals 2,
           lv_float type f.


    lv_int  = '130.58'.
    lv_pack1 = '130.58'.
    lv_pack2 = '130.58'.
    lv_float = '130.58'.

    skip 2.
    write:/ lv_int,
          / lv_pack1,
          / lv_pack2,
          / lv_float.

* varaibles referring to table fields and info objects

 data : lv_matno type mara-matnr,  " table- field
        lv_matno1 type matnr .     " data element

 data : lv_fiscper type /BI0/OIFISCPER,
        lv_calmonth type /BI0/OICALMONTH,
        lv_week type /BI0/OICALWEEK.

*&---------------------------------------------------------------------*
*& Report  ZB12_DATA_OBJECTS_2
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT  ZB12_DATA_OBJECTS_2.

* varaible

data : plant(4) type c value '3000'.  " modifica\\able object

constants : c_plant(4) type c value '1111', " non modif
            c_comp_code(4) type c value '1000',
            c_pur_org type ekko-ekorg value '3000',
            c_plant1 type marc-werks value '1000'.


write:/ 'value of plant:', plant, c_plant.
skip.
plant = '1000'.

* c_plant = '5555'.
write: plant, c_plant.

*&---------------------------------------------------------------------*
*& Report  ZB12_STRCCUTURES_3
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT  ZB12_STRCCUTURES_3.
* define strcurtre
* 1.
DATA : BEGIN OF LS_MATERIAL, " IT WILL HAVE ONLY REQUIRED FIELDS

        MATNR TYPE MARA-MATNR,
        MTART TYPE MARA-MTART,
        MBRSH TYPE MARA-MBRSH,
        WERKS TYPE MARC-WERKS,

       END OF LS_MATERIAL.


*2
DATA : LS_MARA TYPE MARA.  " ALL THE COMPENENTS OF MARA ARE ASSIGN TO LS_MARA

* EXAMPLE

* DEFINITION
  DATA : BEGIN OF LS_EMP,

         EMP_NO(5) TYPE C,
         NAME(20) TYPE C,
         DESIG(20) TYPE C,
         END OF LS_EMP.
* POPULATE DATA TO STRCUTEU


LS_EMP-EMP_NO = 'A1000'.
LS_EMP-NAME   = 'RAMA'.
LS_EMP-DESIG  = 'CONSULTANT'.

***

* LS_EMP-EMP_NO = 'A1001'.
* LS_EMP-NAME   = 'PRATAP'.
* LS_EMP-DESIG  = 'SR.CONSULTANT'.

* * PRINT THE DATA
WRITE:/ LS_EMP.

WRITE:/ LS_EMP-EMP_NO, LS_EMP-NAME, LS_EMP-DESIG.
*
DATA : LS_EMPMAST LIKE LS_EMP.
*  DA
DATA : BEGIN OF LS_EMPDETAILS,
       EMP LIKE LS_EMP,
       DEPT(5) TYPE C,
       SAL TYPE P,

      END OF LS_EMPDETAILS.

LS_EMPDETAILS-EMP-EMP_NO = 'C120'.
LS_EMPDETAILS-EMP-NAME   = 'RAJEEV'.
LS_EMPDETAILS-EMP-DESIG  = 'CONSULTA'.
LS_EMPDETAILS-DEPT       = 'SAP BI'.
LS_EMPDETAILS-SAL        = '10000'.

*WRITE:/ LS_EMPDETAILS.
SKIP.

WRITE:/ LS_EMPDETAILS-EMP-EMP_NO, LS_EMPDETAILS-EMP-NAME, LS_EMPDETAILS-EMP-DESIG,
       LS_EMPDETAILS-DEPT, LS_EMPDETAILS-SAL.

* 3
DATA : BEGIN OF LS_DATA.
       INCLUDE STRUCTURE MARC.
DATA : LS_EMPLOYEE LIKE LS_EMP,
      LV_COUNTER TYPE SY-TABIX,
      RECNO TYPE I.
DATA : END OF LS_DATA.

*&---------------------------------------------------------------------*
*& Report  ZB12_STRCCUTURES_4
*&
*&---------------------------------------------------------------------*

REPORT  ZB12_STRCCUTURES_4.

* DEFINE STRCUTER
DATA : LS_KNA1 TYPE KNA1.
DATA : BEGIN OF LS_CUST,
         KUNNR TYPE KUNNR,
         LAND1 TYPE LAND1_GP,
         NAME1 TYPE NAME1_GP,
         ORT01 TYPE ORT01_GP,
         ADRNR TYPE ADRNR,
      END OF LS_CUST.



* 1 SELECCT SINGLE
*       SELECT SINGLE *
*       FROM KNA1
*       INTO LS_KNA1
*       WHERE KUNNR = '0000000001'.
*       IF SY-SUBRC = 0.
*        WRITE:/ LS_KNA1-KUNNR, LS_KNA1-LAND1.
*       ELSE.
*
*         WRITE: 'NO MATCHING RECORD'.
*       ENDIF.




*       SELECT SINGLE *
*       FROM KNA1
*       INTO LS_KNA1
*       WHERE LAND1 = 'US'.
*       IF SY-SUBRC = 0.
*        WRITE:/ LS_KNA1-KUNNR, LS_KNA1-LAND1.
*       ELSE.
*         WRITE: 'NO MATCHING RECORD'.
*       ENDIF.
*      SELECT SINGLE *
*       FROM KNA1
*       INTO LS_KNA1
*       WHERE LAND1 = 'US' AND
*             ORT01 = 'Chicago'.
*       IF SY-SUBRC = 0.
*        WRITE:/ LS_KNA1-KUNNR, LS_KNA1-LAND1.
*       ELSE.
*         WRITE: 'NO MATCHING RECORD'.
*       ENDIF.


*      SELECT SINGLE *
*       FROM KNA1
*       INTO corresponding fields of LS_cust
*       WHERE LAND1 = 'US' AND
*             ORT01 = 'Chicago'.
*       IF SY-SUBRC = 0.
*        WRITE:/ LS_cust-KUNNR, LS_cust-LAND1.
*       ELSE.
*         WRITE: 'NO MATCHING RECORD'.
*       ENDIF.


*    SELECT SINGLE kunnr land1 name1 ort01 adrnr
*    FROM KNA1
*       INTO  LS_cust
*       WHERE LAND1 = 'US' AND
*             ORT01 = 'Chicago'.
*       IF SY-SUBRC = 0.
*        WRITE:/ LS_cust-KUNNR, LS_cust-LAND1.
*       ELSE.
*         WRITE: 'NO MATCHING RECORD'.
*       ENDIF.


*2. select
*       SELECT *
*       FROM KNA1
*       INTO  LS_kna1
*       WHERE LAND1 = 'US' AND
*             ORT01 = 'Chicago'.
*              IF SY-SUBRC = 0
*              WRITE:/ LS_kna1-KUNNR, LS_kna1-LAND1.
*             ELSE.
*               WRITE: 'NO MATCHING RECORD'.
*             ENDIF.
*       endselect.

*3. select

data : lv_land1 type LAND1_GP.
  select single land1
  from kna1
  into lv_land1
  where kunnr = '0000000001'.

if sy-subrc = 0.
write:/ lv_land1.
else.
write:/ ' no data'.
endif.

 data : lv_name1 type NAME1_GP.
*&---------------------------------------------------------------------*
*& Report  ZB12_TYPES_5
*&
*&---------------------------------------------------------------------*

REPORT  ZB12_TYPES_5.
TYPE-POOLS ZB12.

* types -- is used to define datatype
 data : fname type zb12_name,
        lname type zb12_name,
        mname type zb12_name.

  FNAME = 'RAMA'.
  LNAME = 'KRISHNA'.
  MNAME = 'A'.

DATA : SUPP_ADDR TYPE ZB12_ADDRESS,
        BP_ADDR TYPE ZB12_ADDRESS,
        SOLD_TO_ADDR TYPE ZB12_ADDRESS.

*     SUPP_ADDR-HNO = '751'.
*     SUPP_ADDR-STREET = '1ST CROSS'.
*     SUPP_ADDR-CITY = 'MARATHAHALLI'.
*     SUPP_ADDR-PIN = 560037.
*     BP_ADDR-HNO = '752'.
*     BP_ADDR-STREET = '2ND CROSS'.
*     BP_ADDR-CITY = 'MARATHAHALLI'.
*     BP_ADDR-PIN = 560037.
*     SOLD_TO_ADDR-HNO = '951'.
*     SOLD_TO_ADDR-STREET = '4TH CROSS'.
*     SOLD_TO_ADDR-CITY = 'MARATHAHALLI'.
*     SOLD_TO_ADDR-PIN = 560037.
*



  break-point.

Type Group

*&---------------------------------------------------------------------*

REPORT  ZB12_TYPES_6.
TYPE-POOLS : ZB12.
DATA : MANG_ADDR TYPE  ZB12_ADDRESS.

*&---------------------------------------------------------------------*
*& Report  ZB12_BRANCHING_STAT_IF_7
*&
*&---------------------------------------------------------------------*
REPORT  ZB12_BRANCHING_STAT_IF_7.

parameters :  p_amt type p,
             p_curr(3) type c.

data : lv_amt type p.
break-point.
IF p_curr = 'EUR'.
  LV_AMT = p_amt * 60.
ELSEIF p_curr = 'USD'.
 LV_AMT = p_amt * 50.
ELSEIF p_curr = 'GBP'.
   LV_AMT = p_amt * 70.
ELSEIF p_curr = 'YEN'.
 LV_AMT = p_amt * 8.
ELSE.
 LV_AMT = p_amt * 1.
ENDIF.
*case p_curr.
*  when 'EUR'.
**    LV_AMT = p_amt * 60.
*  WHEN 'USD'.
*    LV_AMT = p_amt * 50.
*  WHEN 'GBP'.
*    LV_AMT = p_amt * 70.
*  WHEN 'YEN'.
*    LV_AMT = p_amt * 8.
*  WHEN OTHERS.
*    LV_AMT = p_amt * 1.
*ENDCASE.

WRITE:/ 'Entered amt:', p_amt,
     / 'Curr:', p_curr,
     / ' Local amt:', lv_amt.

*&---------------------------------------------------------------------*
*& Report  ZB12_BRANCHING_STAT_IF_8
*&
*&---------------------------------------------------------------------*

REPORT  ZB12_BRANCHING_STAT_IF_8.

PARAMETERS : P_ORG TYPE EKKO-EKORG,
            P_PLANT TYPE MARC-WERKS,
            P_MAT TYPE MARA-MATNR,
            P_BASIC TYPE P.


DATA : LV_SEL_PRICE TYPE P.
IF P_ORG > '0001' AND P_ORG <= '1000'.
  IF P_PLANT = 'BANG'.
    LV_SEL_PRICE  = P_BASIC * 2.
  ELSEIF P_PLANT = 'MANG'.
   LV_SEL_PRICE  = P_BASIC * 3.
  ELSEIF P_PLANT = 'MYS'.
   LV_SEL_PRICE  = P_BASIC * 4.
  ELSE.

   LV_SEL_PRICE  = P_BASIC * 1.
  ENDIF.
ELSEIF P_ORG > '1000' AND P_ORG <= '2000'.
     IF P_PLANT = 'HYD'.
    LV_SEL_PRICE  = P_BASIC * 2.
  ELSEIF P_PLANT = 'VIJ'.
   LV_SEL_PRICE  = P_BASIC * 3.
  ELSEIF P_PLANT = 'VZJ'.
   LV_SEL_PRICE  = P_BASIC * 4.
  ELSE.
   LV_SEL_PRICE  = P_BASIC * 1.
  ENDIF.
ELSE.
ENDIF.


WRITE:/ P_BASIC,
      / LV_SEL_PRICE.

*&---------------------------------------------------------------------*
*& Report  ZB12_LOOPING_DO_WHILE_9
*&
*&---------------------------------------------------------------------*

REPORT  ZB12_LOOPING_DO_WHILE_9.

*do - WILL ENTER THE LOOP THE CHECK FOR THE CONDITION

*  DO 10 TIMES.
*   WRITE:/ 'WELCOME'.
*  ENDDO.


*PARAMETERS: P_VAR TYPE I.
*DATA : LV_COUNTER TYPE I.

*  DO.
*  LV_COUNTER = SY-INDEX.
*  WRITE:/ SY-INDEX, 'WELCOME'.
*   IF P_VAR = LV_COUNTER.
*    EXIT.
*   ENDIF.
*  ENDDO.
*  WRITE:/ ' VALUE OF INDEX NO OUTSIDE LOOP:', SY-INDEX.
*EXAMPLE1 : PRINT SQUARE OF NUMBERS.
*PARAMETERS: NUM TYPE I.
*DATA : N1 TYPE I,
*       N2 TYPE I.
*  N1 = 1.
*  DO NUM TIMES.
*   N2 = N1 * N1.
*   WRITE:/ N1, N2.
*   N1 = N1 + 1.
*  ENDDO.

* WHILE -  WILL CHECK  THE CONDITIONA AND IF IT IS TRUE THEN IT WILL ENTER THE LOOP/.


  DATA :  M1 TYPE I.
  M1 = 1.
  WHILE M1 <= 10.
   WRITE:/ SY-INDEX, 'WELCOME'.
   M1 =  M1 + 1.
  ENDWHILE.
 BREAK-POINT.


*&---------------------------------------------------------------------*
*& Report  ZB12_LOOPING_DO_WHILE_10
*&
*&---------------------------------------------------------------------*

REPORT  ZB12_LOOPING_DO_WHILE_10.
parameters: p_value type p.
data: n type i,
     d type i.


     n = 1.
     while n < p_value.
     write n.
     skip.
     n = n + 1.
     d = d - 1.

     do d times.
     write n.
     enddo.
     if n = p_value.
     write n.
     exit.
     endif.
     endwhile.


*&---------------------------------------------------------------------*
*& Report  ZB12_STRING_FUNCTIONS_11
*&
*&---------------------------------------------------------------------*

REPORT  ZB12_STRING_FUNCTIONS_11.
*1. Shift - > shift will move the contenet of char string.

  data: var1 type string,
        var2 type string,
        var3 type string.

        var1 = 'ABAP'.
        var2 = 'WELCOME'.
        var3 = 'HARDWORK'.

           WRITE:/ VAR1.

           SHIFT VAR1.  " IT WILL MOVE THE CONTENT OF VAR1 TO ONE CHAR LEFT

           WRITE:/ VAR1.


           SKIP.
           WRITE:/ VAR2.
           SHIFT VAR2 RIGHT BY 2 PLACES.
           WRITE:/ VAR2.
           SKIP.
           WRITE:/ VAR3.
           SHIFT VAR3 CIRCULAR BY 4 PLACES.
           WRITE:/ VAR3.


*2 REPLACE. - ITWILL REPLACE SPECIFIC SET OF CHAR BY ANOTHER SET OF CHARS

 DATA : TEXT1 TYPE STRING,
        TEXT2 TYPE STRING.
        TEXT1 = 'abcdefghabcdefgh'.
        TEXT2 = 'abcdefghabcdefghabcdefgh'.
*       replace 'bc' in text1 with 'xy'.
       write:/ text1.
       replace 'ef' in text1 with 'xyz'.
       write:/ text1.
       skip.
       write:/ text2.
       replace all occurrences of 'gh' in text2 with 'yy'.
       write:/ text2.



*3. translate - will translate to lowwer case and upper case.

  data : text6 type string,
         text7 type string,
         text8 type string.
         text6 = 'abcdefgh'.
         text7 = 'ABCDEFGH'.
         TEXT8 = 'AbcDEhgH'.
         translate text6 to upper case.
         translate text7 to lower case.
         translate text8 to upper case.


* 4. overlay - fun will overlay the char string with other char string only blank places.

data : text9 type string,
       text10 type string.


       text9 = 'A   P Y'.
       text10 = 'ZBABZ'.
       WRITE:/ TEXT9, TEXT10.
       SKIP.
       OVERLAY TEXT9 WITH TEXT10.
       WRITE:/ TEXT9, TEXT10.

*5. STRING LENGHT- STRLNG -- IT GET NO OF CHARS IN A CHAR STRING


  DATA : LV_TEXT1 TYPE STRING,
         LV_TEXT2 TYPE STRING,
         LV_COUNT TYPE I,
         LV_COUNT1 TYPE I.

         LV_TEXT1 = 'WELCOME'.

         LV_TEXT2 = 'ABAP OBJECTS'.

         LV_COUNT = strlen( LV_TEXT1 ).

         LV_COUNT1 = strlen( LV_TEXT2 ).


*6  CONCATENATE - WILL MERGE MORE THAN ONE CHAR STRING INTO ONE CHAR STRING.

         DATA: FNAME TYPE  STRING,
               MNAME TYPE STRING,
               LNAME TYPE STRING,
               FULLNAME TYPE STRING.

           FNAME = 'MURALI'.
           MNAME = 'DHAR'.
           LNAME = 'REDDY'.

*            CONCATENATE FNAME  MNAME LNAME INTO FULLNAME.
*
*      CONCATENATE FNAME  MNAME LNAME INTO FULLNAME separated BY SPACE.


*      CONCATENATE FNAME  MNAME LNAME INTO FULLNAME separated BY '$'.

      CONCATENATE FNAME  MNAME LNAME INTO FULLNAME separated BY ''.

*7. CONDENSE - WILL REMOVE THE BLACE SPACES.


     DATA : LV_VAR1 TYPE STRING,
            LV_VAR2 TYPE STRING.

            LV_VAR1 = ' WELCOME ALL'.

            LV_VAR2 = ' ABAP OBJECTS'.

            WRITE:/ LV_VAR1, LV_VAR2.

            CONDENSE LV_VAR1.

            CONDENSE LV_VAR2 NO-GAPS.

            WRITE:/ LV_VAR1, LV_VAR2.

* 8 - SPLIT. WILL SPLIT THE CONTENT OF CHAR STRING INTO MANY OBJECTS.


  DATA : LV_STRING TYPE STRING,
         LV_SORG TYPE STRING,
         LV_DCHAN TYPE STRING,
         LV_DIV TYPE STRING.
         LV_STRING = '1000$ABC$120'.
       SPLIT LV_STRING AT '$' INTO LV_SORG LV_DCHAN LV_DIV.
         WRITE:/  LV_STRING,
                  LV_SORG,
                  LV_DCHAN,
                  LV_DIV.

* 9. OFFSET. - TO READ THE SPECFI CHAR.

      DATA : LV_DATE TYPE D,

             LV_CALMONTH TYPE /BI0/OICALMONTH,
             LV_FISCPER TYPE /BI0/OIFISCPER,
             LV_MONTH(2) TYPE N,
             LV_YEAR(4) TYPE N,
             LV_DAY(2) TYPE N.

             LV_DATE = SY-DATUM. "YYYYMMDD

             LV_YEAR = LV_DATE+0(4).

             LV_MONTH = LV_DATE+4(2).

             LV_DAY = LV_DATE+6(2).



          CONCATENATE  LV_YEAR LV_MONTH INTO LV_CALMONTH.

            CONCATENATE LV_YEAR '0' LV_MONTH  INTO LV_FISCPER.

    WRITE:/ LV_DATE,
          / LV_YEAR,
          / LV_MONTH,
          / lv_calmonth,
          / LV_FISCPER.

           BREAK-POINT.


*&---------------------------------------------------------------------*
*& Report  ZB12_DB_STATEMENTS_12
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT  ZB12_DB_STATEMENTS_12.

*
*TABLES : MARA.


* 1. INSERT - WILL ADD A RECORD TO DB STATEMTN.

DATA : LS_MARA TYPE MARA.



*LS_MARA-MATNR = '13'.
*
*CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
*  EXPORTING
*    INPUT         =  LS_MARA-MATNR
* IMPORTING
*  OUTPUT        =  LS_MARA-MATNR
*          .
*
*
**LS_MARA-ERSDA = '11'.
*LS_MARA-ERNAM = 'MURALI'.
*LS_MARA-AENAM = 'MURALI'.
*LS_MARA-MTART = 'ROH'.
*LS_MARA-MBRSH = 'M'.
*
*INSERT MARA FROM LS_MARA.
*
*IF SY-SUBRC = 0.
*
*  WRITE:/ 'RECORD ADDED'.
*
*ELSE.
*
*    WRITE:/ 'RECORD NOT ADDED'.
*
*ENDIF.



* 2 A .UPDATE - WILL UPDATE THE CHAMGES TO EXITSING RECORD




*LS_MARA-MATNR = '000000000000000014'.
*LS_MARA-ERNAM = 'MURALI'.
*LS_MARA-AENAM = 'KRISHNA'.
*LS_MARA-MTART = 'FERT'.
*LS_MARA-MBRSH = 'E'.
*
*
*UPDATE MARA FROM LS_MARA.
*
*IF SY-SUBRC = 0.
*
*  WRITE:/ 'RECORD UPDATED'.
*
*ELSE.
*
*    WRITE:/ 'RECORD NOT UPDATED'.
*
*ENDIF.



*2 B update mara set mtart = 'FERT'
*                 MBRSH = 'E'
*           WHERE AENAM = 'MURALI'.
*IF SY-SUBRC = 0.
*
*  WRITE:/ 'RECORD UPDATED'.
*
*ELSE.
*
*    WRITE:/ 'RECORD NOT UPDATED'.
*
*ENDIF.


* update mara set matnr = '000000000000000009'
*                 mtart = 'FERT'
*           WHERE matnr = '000000000000000013'.
*IF SY-SUBRC = 0.
*
*  WRITE:/ 'RECORD UPDATED'.
*
*ELSE.
*
*    WRITE:/ 'RECORD NOT UPDATED'.
*
*ENDIF.


*3. MODIFY - IF  EXISTING REC MODIFY WILL WORK LIKE UPDATE IF IT IS NEW REC
*              IT WILL WORK LIKE INSERT.


*LS_MARA-MATNR = '000000000000000013'.
*LS_MARA-AENAM = 'MURALI'.
*LS_MARA-MTART = 'FERT'.
*LS_MARA-MBRSH = 'E'.
*
*MODIFY  MARA FROM LS_MARA.
*
*IF SY-SUBRC = 0.
*
*  WRITE:/ 'RECORD UPDATED'.
*
*ELSE.
*
*    WRITE:/ 'RECORD NOT UPDATED'.
*
*ENDIF.




*4. DELETE



DELETE FROM MARA WHERE AENAM = 'MURALI' AND
                      MTART = 'ROH'.
IF SY-SUBRC = 0.

 WRITE:/ 'RECORD DEELTED'.

ELSE.

   WRITE:/ 'RECORD NOT DEELTED'.

ENDIF.





BREAK-POINT.



INTERNALTABLES WITH HEADER LINE

*&---------------------------------------------------------------------*
*& Report  ZB12_INTERNAL_TABLES_OCCURS_13
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT  ZB12_INTERNAL_TABLES_OCCURS_13.


* definition of internal table.


data : begin of ls_emp occurs 0,

      empno(4) type c,
      empname(20) type c,
      dept(10) type c,

      end of ls_emp.

      ls_emp-empno = '3000'.
      ls_emp-empname = 'murali'.
      ls_emp-dept = 'java'.

      append ls_emp to ls_emp.
      clear ls_emp.


      ls_emp-empno = '3003'.
      ls_emp-empname = 'pratap'.
      ls_emp-dept = 'sap'.

      append ls_emp to ls_emp.
      clear ls_emp.

      ls_emp-empno = '2000'.
*       ls_emp-empname = 'murali'.
      ls_emp-dept = 'main'.

      append ls_emp to ls_emp.
      clear ls_emp.


      ls_emp-empno = '5401'.
      ls_emp-empname = 'rajeev'.
      ls_emp-dept = 'dotn'.

      append ls_emp to ls_emp.
      clear ls_emp.


       ls_emp-empno = '5403'.
      ls_emp-empname = 'venu'.
      ls_emp-dept = 'sap'.

      append ls_emp.
      clear ls_emp.


      ls_emp-empno = '2403'.
      ls_emp-empname = 'kavitha'.
      ls_emp-dept = 'sap'.

     insert ls_emp into ls_emp index 2.
      clear ls_emp.


      ls_emp-empno = '4403'.
      ls_emp-empname = 'srini'.
      ls_emp-dept = 'java'.

     insert ls_emp into ls_emp .



      break-point.


*&---------------------------------------------------------------------*
*& Report  ZB12_ITAB_READ_LOOP_14
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT  ZB12_ITAB_READ_LOOP_14.


data : begin of ls_emply occurs 0,

      empno(4) type c,
      empname(20) type c,
      dept(10) type c,
      sal type p,


      end of ls_emply.

      ls_emply-empno = '3000'.
      ls_emply-empname = 'murali'.
      ls_emply-dept = 'java'.
      ls_emply-sal = '1200'.

      append ls_emply to ls_emply.

      clear ls_emply.


      ls_emply-empno = '4200'.
      ls_emply-empname = 'vijay'.
      ls_emply-dept = 'sap'.
      ls_emply-sal = '1300'.

       append ls_emply to ls_emply.

      clear ls_emply.

      ls_emply-empno = '3200'.
      ls_emply-empname = 'krisna'.
      ls_emply-dept = 'sap'.
      ls_emply-sal = '1400'.

       append ls_emply to ls_emply.


      clear ls_emply.



       ls_emply-empno = '4203'.
      ls_emply-empname = 'vijaya'.
      ls_emply-dept = 'java'.
      ls_emply-sal = '1300'.

       append ls_emply to ls_emply.

      clear ls_emply.

      ls_emply-empno = '5203'.
      ls_emply-empname = 'yesyeskar'.
      ls_emply-dept = 'main'.
      ls_emply-sal = '1500'.

       append ls_emply to ls_emply.

      clear ls_emply.


      ls_emply-empno = '5203'.
      ls_emply-empname = 'preethi'.
      ls_emply-dept = 'sap'.
      ls_emply-sal = '1200'.

       append ls_emply to ls_emply.

      clear ls_emply.


      ls_emply-empno = '5250'.
      ls_emply-empname = 'ranga'.
      ls_emply-dept = 'java'.
      ls_emply-sal = '1400'.

       append ls_emply to ls_emply.

      clear ls_emply.

      ls_emply-empno = '6700'.
      ls_emply-empname = 'pandu'.
      ls_emply-dept = 'main'.
      ls_emply-sal = '1400'.

       append ls_emply to ls_emply.

      clear ls_emply.



        ls_emply-empno = '5200'.
      ls_emply-empname = 'vijay'.
      ls_emply-dept = 'main'.
      ls_emply-sal = '1300'.

       append ls_emply to ls_emply.

      clear ls_emply.


* * read statement - will fetch or read a single record from itab.

* * index based
*  key based

*   1.

*  read table ls_emply into ls_emply index 3.

*  read table ls_emply into ls_emply index 5.
*
*  if sy-subrc = 0.
*
*    write:/ ls_emply-empno, ls_emply-empname, ls_emply-dept,
*            ls_emply-sal.
*
*
*  else.
*
*   write:/ 'no matching index'.
*  endif.



*Key based read

*   read table ls_emply into ls_emply with key
*              empname = 'preethi'.

*   read table ls_emply into ls_emply with key
*              empname = 'vijay'
*              dept = 'main'.
*
*
*               if sy-subrc = 0.
*
*    write:/ ls_emply-empno, ls_emply-empname, ls_emply-dept,
*            ls_emply-sal.
*
*
*  else.
*
*   write:/ 'no matching index'.
*  endif.


*loop statemmet will read all records of internal table


   clear ls_emply.
*  loop at ls_emply into ls_emply.
*
*
*   write:/ ls_emply-empno, ls_emply-empname, ls_emply-dept,
*           ls_emply-sal.
*
*
*  clear ls_emply.
*  endloop.



** loop with index filter



*
*loop at ls_emply into ls_emply from 2 to 4.
*
*
*   write:/ sy-tabix, ls_emply-empno, ls_emply-empname, ls_emply-dept,
*           ls_emply-sal.
*
*
*  clear ls_emply.
*  endloop.



*loop at ls_emply into ls_emply from 3.
*
*
*   write:/ sy-tabix, ls_emply-empno, ls_emply-empname, ls_emply-dept,
*           ls_emply-sal.
*
*
*  clear ls_emply.
*  endloop.



*loop at ls_emply into ls_emply to 3.
*
*
*   write:/ sy-tabix, ls_emply-empno, ls_emply-empname, ls_emply-dept,
*           ls_emply-sal.
*
*
*  clear ls_emply.
*  endloop.


*Loop with key based.


*
*loop at ls_emply into ls_emply where dept = 'sap'.
*
*
*   write:/ sy-tabix, ls_emply-empno, ls_emply-empname, ls_emply-dept,
*           ls_emply-sal.
*
*
*  clear ls_emply.
*  endloop.




*loop at ls_emply into ls_emply where dept = 'sap' or
*                                     dept = 'java'.
*
*
*   write:/ sy-tabix, ls_emply-empno, ls_emply-empname, ls_emply-dept,
*           ls_emply-sal.
*
*
*  clear ls_emply.
*  endloop.

loop at ls_emply into ls_emply where dept = 'sap' or
                                    dept = 'main'.


  write:/ sy-tabix, ls_emply-empno, ls_emply-empname, ls_emply-dept,
          ls_emply-sal.


 clear ls_emply.
 endloop.


REPORT ZB12_ITAB_MODIFY_15.

data : begin of ls_emply occurs 0,

      empno(4) type c,
      empname(20) type c,
      dept(10) type c,
      sal type p,


      end of ls_emply.

      ls_emply-empno = '3000'.
      ls_emply-empname = 'murali'.
      ls_emply-dept = 'java'.
      ls_emply-sal = '1200'.

      append ls_emply to ls_emply.

      clear ls_emply.

      ls_emply-empno = '4200'.
      ls_emply-empname = 'vijay'.
      ls_emply-dept = 'sap'.
      ls_emply-sal = '1300'.

       append ls_emply to ls_emply.

      clear ls_emply.

      ls_emply-empno = '3200'.
      ls_emply-empname = 'krisna'.
      ls_emply-dept = 'sap'.
      ls_emply-sal = '1400'.

       append ls_emply to ls_emply.


      clear ls_emply.

      ls_emply-empno = '3000'.
      ls_emply-empname = 'murali'.
      ls_emply-dept = 'sap'.
      ls_emply-sal = '1500'.

      append ls_emply to ls_emply.

      clear ls_emply.


       ls_emply-empno = '4203'.
      ls_emply-empname = 'vijaya'.
      ls_emply-dept = 'java'.
      ls_emply-sal = '1300'.

       append ls_emply to ls_emply.

      clear ls_emply.



      ls_emply-empno = '5203'.
      ls_emply-empname = 'yesyeskar'.
      ls_emply-dept = 'main'.
      ls_emply-sal = '1500'.

       append ls_emply to ls_emply.

      clear ls_emply.


      ls_emply-empno = '5203'.
      ls_emply-empname = 'preethi'.
      ls_emply-dept = 'sap'.
      ls_emply-sal = '1200'.

       append ls_emply to ls_emply.

      clear ls_emply.



      ls_emply-empno = '5250'.
      ls_emply-empname = 'ranga'.
      ls_emply-dept = 'java'.
      ls_emply-sal = '1400'.

       append ls_emply to ls_emply.

      clear ls_emply.

      ls_emply-empno = '6700'.
      ls_emply-empname = 'pandu'.
      ls_emply-dept = 'main'.
      ls_emply-sal = '1400'.

       append ls_emply to ls_emply.

      clear ls_emply.



        ls_emply-empno = '5200'.
      ls_emply-empname = 'vijay'.
      ls_emply-dept = 'main'.
      ls_emply-sal = '1300'.

       append ls_emply to ls_emply.

      clear ls_emply.


      ls_emply-empno = '4543'.
      ls_emply-empname = 'prasana'.
      ls_emply-dept = 'sap'.
      ls_emply-sal = '1500'.

       append ls_emply to ls_emply.

      clear ls_emply.


*
*read table ls_emply into ls_emply index 2.
*
*if sy-subrc = 0 .
*
*
*  ls_emply-sal = ls_emply-sal * 2.
*
*  modify ls_emply from ls_emply.
*
*  if sy-subrc = 0.
*
*   write:/ 'record modified'.
*
*  endif.
*
* endif.



*loop at ls_emply into ls_emply.
*
* write:/ ls_emply-empno, ls_emply-empname, ls_emply-dept, ls_emply-sal.
*
* ls_emply-sal = ls_emply-sal * 2.
*
* modify ls_emply from ls_emply.
*
* write:/ ls_emply-empno, ls_emply-empname, ls_emply-dept, ls_emply-sal.
*
*
* clear ls_emply.
*
*endloop.


data : lv_index type i.



*loop at ls_emply into ls_emply.
*
*   lv_index = sy-tabix.
*
* write:/ ls_emply-empno, ls_emply-empname, ls_emply-dept, ls_emply-sal.
*
* ls_emply-sal = ls_emply-sal * 2.
*
* modify ls_emply from ls_emply index lv_index.
*
* write:/ ls_emply-empno, ls_emply-empname, ls_emply-dept, ls_emply-sal.
*
*
* clear ls_emply.
*
*endloop.




*Modify with key based.


loop at ls_emply into ls_emply.


ls_emply-sal = ls_emply-sal * 2.

modify ls_emply from ls_emply transporting sal
                    where empno = ls_emply-empno and
                          dept  = ls_emply-dept.


write:/ ls_emply-empno, ls_emply-empname, ls_emply-dept, ls_emply-sal.


clear ls_emply.

endloop.

      break-point.

      break-point.