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

SAP BW - ABAP Overview - Part 2


  
Go to Transaction Code SE38 ( ABAP Initial Program)--> Provide the Program name

(ZB12_ITAB_WITH_EXP_HL_15) ----> Click On Create

  
*&---------------------------------------------------------------------*
*& Report  ZB12_ITAB_WITH_EXP_HL_15


 INTERNALTABLES WITHOUTHEADERLINE


REPORT  ZB12_ITAB_WITH_EXP_HL_15.


* 2. internal table without HL

* define itab
types : begin of ls_vendor,

        lifnr type lfa1-lifnr,
        name type  lfa1-name2,
        purg  type ekko-ekorg,
        pay  type p,

       end of ls_vendor.

data : it_vendor type ls_vendor occurs 0,

      wa_vendor like line of it_vendor.


*poopulate data

wa_vendor-lifnr  = '1005'.
wa_vendor-name  = 'murali'.
wa_vendor-purg  = '1000'.
wa_vendor-pay   = '5000'.


append wa_vendor to it_vendor.
clear wa_vendor.


wa_vendor-lifnr  = '1008'.
wa_vendor-name  = 'krishna'.
wa_vendor-purg  = '1000'.
wa_vendor-pay   = '2000'.


append wa_vendor to it_vendor.
clear wa_vendor.

wa_vendor-lifnr  = '0102'.
wa_vendor-name  = 'vijay'.
wa_vendor-purg  = '3000'.
wa_vendor-pay   = '1300'.


append wa_vendor to it_vendor.
clear wa_vendor.


wa_vendor-lifnr  = '3008'.
wa_vendor-name  = 'praveen'.
wa_vendor-purg  = '1000'.
wa_vendor-pay   = '2500'.


append wa_vendor to it_vendor.
clear wa_vendor.




wa_vendor-lifnr  = '5003'.
wa_vendor-name  = 'ranga'.
wa_vendor-purg  = '3000'.
wa_vendor-pay   = '1200'.

insert wa_vendor into it_vendor index 2.

clear wa_vendor.

* readingthe data from internal table

read table it_vendor into wa_vendor index 2.

if sy-subrc = 0.

 write:/ wa_vendor-lifnr, wa_vendor-name, wa_vendor-purg, wa_vendor-pay.
endif.


clear wa_vendor.

loop at it_vendor into wa_vendor.

write:/ wa_vendor-lifnr, wa_vendor-name, wa_vendor-purg, wa_vendor-pay.

clear wa_vendor.

endloop.

break-point.


*&---------------------------------------------------------------------*
*& Report  ZB12_ITAB_READ_LOOP_16
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT  ZB12_ITAB_READ_LOOP_16.

* define internal table
types : begin of ls_emp,

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


      end of ls_emp.

data : it_emp type ls_emp occurs 0,  " body
      wa_emp like line of  it_emp.   " HL or wa


* Poopulatuing data




      wa_emp-empno = '3000'.
      wa_emp-empname = 'yeseskar'.
      wa_emp-dept = 'java'.
      wa_emp-sal = '1200'.

      append wa_emp to it_emp.

       clear wa_emp.


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

       append wa_emp to it_emp.

      clear wa_emp.

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

       append wa_emp to it_emp.


      clear wa_emp.

       wa_emp-empno = '3000'.
      wa_emp-empname = 'murali'.
      wa_emp-dept = 'dot'.
      wa_emp-sal = '1200'.

      append wa_emp to it_emp.

       clear wa_emp.

      wa_emp-empno = '3000'.
      wa_emp-empname = 'murali'.
      wa_emp-dept = 'as400'.
      wa_emp-sal = '1200'.

      append wa_emp to it_emp.

       clear wa_emp.



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

       append wa_emp to it_emp.

      clear wa_emp.



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

       append wa_emp to it_emp.

      clear wa_emp.

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

       append wa_emp to it_emp.

      clear wa_emp.

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

       append wa_emp to it_emp.

      clear wa_emp.

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

       append wa_emp to it_emp.

      clear wa_emp.



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

       append wa_emp to it_emp.

      clear wa_emp.

loop at it_emp into wa_emp.


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

 clear wa_emp.
 endloop.

write:/'*****************'.

sort it_emp by empno empname descending  dept .

loop at it_emp into wa_emp.


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


 clear wa_emp.
 endloop.


      break-point.


*&---------------------------------------------------------------------*
*& Report  ZB12_ITAB_EXP_HL_MODIFY_17


REPORT  ZB12_ITAB_EXP_HL_MODIFY_17.



TYPES: BEGIN OF LS_MAT,

        MATNO TYPE MARA-MATNR,
        EKORG TYPE EKKO-EKORG,
        WERKS TYPE MARC-WERKS,
        MTART TYPE MARA-MTART,
        BPRICE TYPE P,
        SPRICE TYPE P,

      END OF LS_MAT.


DATA : IT_MAT TYPE LS_MAT OCCURS 0,
      WA_MAT LIKE LINE OF IT_MAT.


  WA_MAT-MATNO = 'M001'.
  WA_MAT-EKORG =  '1000'.
  WA_MAT-WERKS = 'BANG'.
  WA_MAT-MTART = 'FERT'.
  WA_MAT-BPRICE = '1200'.
  WA_MAT-SPRICE = '1200'.

  APPEND WA_MAT TO IT_MAT.

  CLEAR WA_MAT.

  WA_MAT-MATNO = 'M201'.
  WA_MAT-EKORG =  '1100'.
  WA_MAT-WERKS = 'BANG'.
  WA_MAT-MTART = 'ROH'.
  WA_MAT-BPRICE = '1201'.
  WA_MAT-SPRICE = '1201'.

  APPEND WA_MAT TO IT_MAT.

CLEAR WA_MAT.

    WA_MAT-MATNO = 'M301'.
  WA_MAT-EKORG =  '1900'.
  WA_MAT-WERKS = 'MANG'.
  WA_MAT-MTART = 'FERT'.
  WA_MAT-BPRICE = '1000'.
  WA_MAT-SPRICE = '1000'.

  APPEND WA_MAT TO IT_MAT.
CLEAR WA_MAT.


    WA_MAT-MATNO = 'M002'.
  WA_MAT-EKORG =  '2000'.
  WA_MAT-WERKS = 'HYD'.
  WA_MAT-MTART = 'FERT'.
  WA_MAT-BPRICE = '1205'.
  WA_MAT-SPRICE = '1205'.

  APPEND WA_MAT TO IT_MAT.
CLEAR WA_MAT.


  WA_MAT-MATNO = 'M122'.
  WA_MAT-EKORG =  '2000'.
  WA_MAT-WERKS = 'VIJ'.
  WA_MAT-MTART = 'ROH'.
  WA_MAT-BPRICE = '1000'.
  WA_MAT-SPRICE = '1000'.

  APPEND WA_MAT TO IT_MAT.
CLEAR WA_MAT.


     WA_MAT-MATNO = 'M345'.
  WA_MAT-EKORG =  '2001'.
  WA_MAT-WERKS = 'VIJ'.
  WA_MAT-MTART = 'FERT'.
  WA_MAT-BPRICE = '1100'.
  WA_MAT-SPRICE = '1100'.

  APPEND WA_MAT TO IT_MAT.
CLEAR WA_MAT.



     WA_MAT-MATNO = 'M222'.
  WA_MAT-EKORG =  '2020'.
  WA_MAT-WERKS = 'VZJ'.
  WA_MAT-MTART = 'FERT'.
  WA_MAT-BPRICE = '1001'.
  WA_MAT-SPRICE = '1001'.

  APPEND WA_MAT TO IT_MAT.
CLEAR WA_MAT.



     WA_MAT-MATNO = 'M121'.
  WA_MAT-EKORG =  '2000'.
  WA_MAT-WERKS = 'VIJ'.
  WA_MAT-MTART = 'ROH'.
  WA_MAT-BPRICE = '1000'.
  WA_MAT-SPRICE = '1000'.

  APPEND WA_MAT TO IT_MAT.
CLEAR WA_MAT.


     WA_MAT-MATNO = 'M122'.
  WA_MAT-EKORG =  '2000'.
  WA_MAT-WERKS = 'VIJ'.
  WA_MAT-MTART = 'FOOD'.
  WA_MAT-BPRICE = '1500'.
  WA_MAT-SPRICE = '1500'.

  APPEND WA_MAT TO IT_MAT.
 CLEAR WA_MAT.



     WA_MAT-MATNO = 'M123'.
  WA_MAT-EKORG =  '1900'.
  WA_MAT-WERKS = 'MYS'.
  WA_MAT-MTART = 'FOOD'.
  WA_MAT-BPRICE = '1000'.
  WA_MAT-SPRICE = '1000'.

  APPEND WA_MAT TO IT_MAT.
  CLEAR WA_MAT.


  SORT IT_MAT BY MATNO.

  LOOP AT IT_MAT INTO WA_MAT.

     WRITE:/ WA_MAT-MATNO, WA_MAT-EKORG, WA_MAT-WERKS, WA_MAT-MTART,
         WA_MAT-BPRICE, WA_MAT-SPRICE.

    IF WA_MAT-MATNO = 'M001'.

     STOP.
  
    ENDIF.

  
   IF  WA_MAT-MATNO = 'M122'.

*     EXIT.

*     CONTINUE.

  
   ENDIF.


    IF WA_MAT-EKORG >= '1000' AND WA_MAT-EKORG < '2000'.

         CASE WA_MAT-WERKS .

         WHEN 'BANG'.

              IF WA_MAT-MTART = 'FERT'.

                 WA_MAT-SPRICE = WA_MAT-BPRICE * 2.


              ELSEIF WA_MAT-MTART = 'ROH'.

                WA_MAT-SPRICE = WA_MAT-BPRICE * 2.

              ELSEIF WA_MAT-MTART = 'FOOD'.

                WA_MAT-SPRICE = WA_MAT-BPRICE * 2.

              ELSE.

                WA_MAT-SPRICE = WA_MAT-BPRICE * 2.

              ENDIF.

         WHEN 'MANG'.

           IF WA_MAT-MTART = 'FERT'.

                 WA_MAT-SPRICE = WA_MAT-BPRICE * 3.


              ELSEIF WA_MAT-MTART = 'ROH'.

                WA_MAT-SPRICE = WA_MAT-BPRICE * 3.

              ELSEIF WA_MAT-MTART = 'FOOD'.

                WA_MAT-SPRICE = WA_MAT-BPRICE * 3.

              ELSE.

                WA_MAT-SPRICE = WA_MAT-BPRICE * 3.

              ENDIF.



         WHEN 'MYS'.

           IF WA_MAT-MTART = 'FERT'.

                 WA_MAT-SPRICE = WA_MAT-BPRICE * 4.


              ELSEIF WA_MAT-MTART = 'ROH'.

                WA_MAT-SPRICE = WA_MAT-BPRICE * 4.

              ELSEIF WA_MAT-MTART = 'FOOD'.

                WA_MAT-SPRICE = WA_MAT-BPRICE * 4.

              ELSE.

                WA_MAT-SPRICE = WA_MAT-BPRICE * 4.

              ENDIF.



         WHEN OTHERS.

         ENDCASE.

    ELSEIF WA_MAT-EKORG >= '2000' AND WA_MAT-EKORG < '3000'.

        CASE WA_MAT-WERKS.

        WHEN 'HYD'.

          IF WA_MAT-MTART = 'FERT'.

                 WA_MAT-SPRICE = WA_MAT-BPRICE * 5.


              ELSEIF WA_MAT-MTART = 'ROH'.

                WA_MAT-SPRICE = WA_MAT-BPRICE * 5.

              ELSEIF WA_MAT-MTART = 'FOOD'.

                WA_MAT-SPRICE = WA_MAT-BPRICE * 5.

              ELSE.

                WA_MAT-SPRICE = WA_MAT-BPRICE * 5.

              ENDIF.




        WHEN 'VIJ'.


            IF WA_MAT-MTART = 'FERT'.

                 WA_MAT-SPRICE = WA_MAT-BPRICE * 6.


              ELSEIF WA_MAT-MTART = 'ROH'.

                WA_MAT-SPRICE = WA_MAT-BPRICE * 6.

              ELSEIF WA_MAT-MTART = 'FOOD'.

                WA_MAT-SPRICE = WA_MAT-BPRICE * 6.

              ELSE.

                WA_MAT-SPRICE = WA_MAT-BPRICE * 6.

              ENDIF.

        WHEN 'VZJ'.


           IF WA_MAT-MTART = 'FERT'.

                 WA_MAT-SPRICE = WA_MAT-BPRICE * 7.


              ELSEIF WA_MAT-MTART = 'ROH'.

                WA_MAT-SPRICE = WA_MAT-BPRICE * 7.

              ELSEIF WA_MAT-MTART = 'FOOD'.

                WA_MAT-SPRICE = WA_MAT-BPRICE * 7.

              ELSE.

                WA_MAT-SPRICE = WA_MAT-BPRICE * 7.

              ENDIF.


        WHEN OTHERS.

        ENDCASE.


* delete - used to deelte a record from internal.

*Index based

*delete it_mat index 2.


* deelete a record based on key

*delete it_mat where EKORG = '2000'.

*delete it_mat where EKORG = '2000' and
*                    mtart = 'FERT'.

*
*delete it_mat where EKORG = '2000' and
*                    mtart = 'FERT' OR
*                    MTART = 'ROH'.

*delete it_mat where EKORG <> '2000'.  " NE


* CLEAR

*CLEAR WA_MAT.  " THIS CLEAR WILL DELETE RECORD FROM HL OR WA.
*
*CLEAR IT_MAT[] " THIS CLEAR WILL DELETE RECORDS FROM BODY.


* FREE IT_MAT. " DELETE ALL RECORDS OF BODY AND DEALLOCATE MEMORY.

* REFRESH IT_MAT. " DELETE ALL RECORDS OF BODY AND WILL NOT DEALLOCATE MEMORY.



* DATA : LV_NUM TYPE I.
*
** DESCRIBE - WILL GIVE NO OF RECORDS OF INTERNAL TABLE
** SY-TFILL
* DESCRIBE TABLE IT_MAT LINES LV_NUM.
*
* IF LV_NUM > 1.
*
*   WRITE:/ 'nO OF RECORDS IN IT_MAT:', LV_NUM.
*
* ENDIF.

IF NOT IT_MAT[] IS INITIAL.

 WRITE:/ 'DATA IS AVAIBLE'.

ENDIF.


      ELSE.


    ENDIF.


    MODIFY IT_MAT FROM WA_MAT.

  WRITE:/ WA_MAT-MATNO, WA_MAT-EKORG, WA_MAT-WERKS, WA_MAT-MTART,
         WA_MAT-BPRICE, WA_MAT-SPRICE.

   CLEAR WA_MAT.
  ENDLOOP.


  WRITE:/ ' DATA PROCESSING FINISHED'.


 Report  ZB12_ITAB_TYPES_18


REPORT  ZB12_ITAB_TYPES_18.


* standard internal tables.

*TYPES : BEGIN OF LS_MAT,
*        MATNR TYPE MATNR,
*        MTART TYPE MTART,
*        MBRSH TYPE MBRSH,
*        END OF LS_MAT.
*
*DATA : IT_MAT TYPE STANDARD TABLE OF LS_MAT WITH NON-UNIQUE DEFAULT KEY,
*       WA_MAT LIKE LINE OF IT_MAT.
*
*
*WA_MAT-MATNR = 'M001'.
*WA_MAT-MTART = 'FERT'.
*WA_MAT-MBRSH = 'M'.
*
*APPEND WA_MAT TO IT_MAT.
*
*CLEAR WA_MAT.
*
*
*WA_MAT-MATNR = 'M005'.
*WA_MAT-MTART = 'ROH'.
*WA_MAT-MBRSH = 'E'.
*
*APPEND WA_MAT TO IT_MAT.
*
*CLEAR WA_MAT.
*
*
*WA_MAT-MATNR = 'M001'.
*WA_MAT-MTART = 'FERT'.
*WA_MAT-MBRSH = 'M'.
*
*APPEND WA_MAT TO IT_MAT.
*
*CLEAR WA_MAT.
*
*WA_MAT-MATNR = 'M003'.
*WA_MAT-MTART = 'ROH'.
*WA_MAT-MBRSH = 'E'.
*
*APPEND WA_MAT TO IT_MAT.
*
*CLEAR WA_MAT.
*
*
*WA_MAT-MATNR = 'M009'.
*WA_MAT-MTART = 'FOOD'.
*WA_MAT-MBRSH = 'F'.
*
*APPEND WA_MAT TO IT_MAT.
*
*CLEAR WA_MAT.
*
*
*
*WA_MAT-MATNR = 'M009'.
*WA_MAT-MTART = 'FOOD'.
*WA_MAT-MBRSH = 'F'.
*
*APPEND WA_MAT TO IT_MAT.
*
*CLEAR WA_MAT.
*
*WA_MAT-MATNR = 'M021'.
*WA_MAT-MTART = 'FERT'.
*WA_MAT-MBRSH = 'M'.
*
*APPEND WA_MAT TO IT_MAT.
*
*CLEAR WA_MAT.
*
*
*
*WA_MAT-MATNR = 'M009'.
*WA_MAT-MTART = 'FOOD'.
*WA_MAT-MBRSH = 'F'.
*
*APPEND WA_MAT TO IT_MAT.
*
*CLEAR WA_MAT.


* DELETE DUPLICATE RECORDS FROM STANDARD INTERNAL.
* PRE REQUISTE BEFORE DELETE DUPLIATE YOU NEED TO SORT THE DATA.

*SORT IT_MAT BY MATNR MTART MBRSH.
*
*DELETE adjacent DUPLICATES from IT_MAT comparing MATNR MTART MBRSH.
*break-point.


* USE BINARY SEACH FOR STANDARD INTERNAL TABLE
* PRE REQUISTE BEFORE READ WITH BINARY SEACH ...DATA SHOULD BE SORT.

*READ TABLE IT_MAT INTO WA_MAT WITH KEY MATNR = 'M009'.

*READ TABLE IT_MAT INTO WA_MAT WITH KEY MATNR = 'M009' BINARY SEARCH.
*
*IF SY-SUBRC = 0.
*
* WRITE:/ WA_MAT-MATNR, WA_MAT-MTART, WA_MAT-MBRSH.
*ENDIF.


*LOOP AT IT_MAT INTO WA_MAT.
*
* WRITE:/ WA_MAT-MATNR, WA_MAT-MTART, WA_MAT-MBRSH.
*
*ENDLOOP.


 * 2. SORTED INTERNAL TABLE


*TYPES : BEGIN OF LS_MAT,
*        MATNR TYPE MATNR,
*        MTART TYPE MTART,
*        MBRSH TYPE MBRSH,
*        END OF LS_MAT.
*
*DATA : IT_MAT TYPE SORTED TABLE OF LS_MAT WITH NON-UNIQUE DEFAULT KEY,
*       WA_MAT LIKE LINE OF IT_MAT.


*WA_MAT-MATNR = 'M001'.
*WA_MAT-MTART = 'FERT'.
*WA_MAT-MBRSH = 'M'.
*
*APPEND WA_MAT TO IT_MAT.
*
*CLEAR WA_MAT.
*
*WA_MAT-MATNR = 'M001'.
*WA_MAT-MTART = 'FERT'.
*WA_MAT-MBRSH = 'M'.
*
*APPEND WA_MAT TO IT_MAT.
*
*CLEAR WA_MAT.
*
*
*
*WA_MAT-MATNR = 'M005'.
*WA_MAT-MTART = 'FOOH'.
*WA_MAT-MBRSH = 'M'.
*
*APPEND WA_MAT TO IT_MAT.
*
*CLEAR WA_MAT.
*
*
*
*WA_MAT-MATNR = 'M008'.
*WA_MAT-MTART = 'FERT'.
*WA_MAT-MBRSH = 'M'.
*
*
*INSERT WA_MAT INTO IT_MAT INDEX 4.
* CLEAR WA_MAT.
*
*
*WA_MAT-MATNR = 'M006'.
*WA_MAT-MTART = 'FERT'.
*WA_MAT-MBRSH = 'M'.
*
*
*INSERT WA_MAT INTO IT_MAT INDEX 5.
* CLEAR WA_MAT.



* INSERT STSATEMTN BASED ON KEY. - WILL WORK JUST ADD A RECORD
*
*WA_MAT-MATNR = 'M001'.
*WA_MAT-MTART = 'FERT'.
*WA_MAT-MBRSH = 'M'.
*
*INSERT WA_MAT INTO TABLE IT_MAT.
*
*CLEAR WA_MAT.
*
*WA_MAT-MATNR = 'M005'.
*WA_MAT-MTART = 'FERT'.
*WA_MAT-MBRSH = 'M'.
*
*INSERT WA_MAT INTO TABLE IT_MAT.
*
*CLEAR WA_MAT.
*
*WA_MAT-MATNR = 'M003'.
*WA_MAT-MTART = 'FOOH'.
*WA_MAT-MBRSH = 'M'.
*
*INSERT WA_MAT INTO TABLE IT_MAT.
*
*CLEAR WA_MAT.
*
*
*WA_MAT-MATNR = 'M009'.
*WA_MAT-MTART = 'FOOH'.
*WA_MAT-MBRSH = 'M'.
*
*INSERT WA_MAT INTO TABLE IT_MAT.
*
*CLEAR WA_MAT.
*
*
*WA_MAT-MATNR = 'M002'.
*WA_MAT-MTART = 'FOOH'.
*WA_MAT-MBRSH = 'M'.
*
*INSERT WA_MAT INTO TABLE IT_MAT.
*
*CLEAR WA_MAT.


*TYPES : BEGIN OF LS_MAT,
*        MATNR TYPE MATNR,
*        MTART TYPE MTART,
*        MBRSH TYPE MBRSH,
*        END OF LS_MAT.
*
*DATA : IT_MAT TYPE SORTED TABLE OF LS_MAT WITH UNIQUE KEY MATNR MTART MBRSH,
*       WA_MAT LIKE LINE OF IT_MAT.
*
*WA_MAT-MATNR = 'M001'.
*WA_MAT-MTART = 'FERT'.
*WA_MAT-MBRSH = 'M'.
*
*APPEND WA_MAT TO IT_MAT.
*
*CLEAR WA_MAT.
*
*WA_MAT-MATNR = 'M002'.
*WA_MAT-MTART = 'FERT'.
*WA_MAT-MBRSH = 'M'.
*
*APPEND WA_MAT TO IT_MAT.
*
*CLEAR WA_MAT.

BREAK-POINT.



*3. Hashed Table

TYPES : BEGIN OF LS_MAT_h,
       MATNR TYPE MATNR,
       MTART TYPE MTART,
       MBRSH TYPE MBRSH,
       END OF LS_MAT_h.

DATA : IT_MAT_h TYPE hashed TABLE OF LS_MAT_h WITH UNIQUE KEY matnr,
      WA_MAT_h LIKE LINE OF IT_MAT_h.


WA_MAT_h-MATNR = 'M001'.
WA_MAT_h-MTART = 'FERT'.
WA_MAT_h-MBRSH = 'M'.

insert WA_MAT_h INTO table IT_MAT_h.

CLEAR WA_MAT_h.



WA_MAT_h-MATNR = 'M009'.
WA_MAT_h-MTART = 'FERT'.
WA_MAT_h-MBRSH = 'M'.

insert WA_MAT_h INTO table IT_MAT_h.

CLEAR WA_MAT_h.



WA_MAT_h-MATNR = 'M003'.
WA_MAT_h-MTART = 'ROH'.
WA_MAT_h-MBRSH = 'M'.

insert WA_MAT_h INTO table IT_MAT_h.

CLEAR WA_MAT_h.



WA_MAT_h-MATNR = 'M007'.
WA_MAT_h-MTART = 'FOOD'.
WA_MAT_h-MBRSH = 'E'.

insert WA_MAT_h INTO table IT_MAT_h.

CLEAR WA_MAT_h.


WA_MAT_h-MATNR = 'M003'.
WA_MAT_h-MTART = 'ROH'.
WA_MAT_h-MBRSH = 'M'.

insert WA_MAT_h INTO table IT_MAT_h.

CLEAR WA_MAT_h.


* HASHED TABLE - READ.... WITH TABLE KEY

*READ TABLE IT_MAT_H INTO WA_MAT_H WITH TABLE KEY MATNR = 'M003'.
*
*IF SY-SUBRC = 0 .
*
*  WRITE:/ WA_MAT_H-MATNR, WA_MAT_H-MBRSH, WA_MAT_H-MTART.
*ENDIF.


*READ TABLE IT_MAT_H INTO WA_MAT_H WITH KEY MTART = 'FERT'.
*
*IF SY-SUBRC = 0 .
*
*  WRITE:/ WA_MAT_H-MATNR, WA_MAT_H-MBRSH, WA_MAT_H-MTART.
*ENDIF.


LOOP AT IT_MAT_H INTO WA_MAT_H.

WRITE:/ WA_MAT_H-MATNR, WA_MAT_H-MBRSH, WA_MAT_H-MTART.

ENDLOOP.


  BREAK-POINT.




*&---------------------------------------------------------------------*
*& Report  ZB12_ITAB_TYPES_MOVE_19
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT  ZB12_ITAB_TYPES_MOVE_19.

*1. MOVE THE DATA FROM ONE ITAB TO ONTHER ITAB WHEN BOTH DEFINITIOANS ARE SAME.



TYPES : BEGIN OF LS_MAT,
       MATNR TYPE MATNR,
       MTART TYPE MTART,
       MBRSH TYPE MBRSH,
       END OF LS_MAT.

DATA : IT_MAT TYPE STANDARD TABLE OF LS_MAT WITH NON-UNIQUE DEFAULT KEY,
      WA_MAT LIKE LINE OF IT_MAT.


DATA : IT_MAT1 TYPE STANDARD TABLE OF LS_MAT,
      WA_MAT1 LIKE LINE OF IT_MAT1.


WA_MAT-MATNR = 'M001'.
WA_MAT-MTART = 'FERT'.
WA_MAT-MBRSH = 'M'.

APPEND WA_MAT TO IT_MAT.

CLEAR WA_MAT.


WA_MAT-MATNR = 'M005'.
WA_MAT-MTART = 'ROH'.
WA_MAT-MBRSH = 'E'.

APPEND WA_MAT TO IT_MAT.

CLEAR WA_MAT.


WA_MAT-MATNR = 'M001'.
WA_MAT-MTART = 'FERT'.
WA_MAT-MBRSH = 'M'.

APPEND WA_MAT TO IT_MAT.

CLEAR WA_MAT.

WA_MAT-MATNR = 'M003'.
WA_MAT-MTART = 'ROH'.
WA_MAT-MBRSH = 'E'.

APPEND WA_MAT TO IT_MAT.

CLEAR WA_MAT.


WA_MAT-MATNR = 'M009'.
WA_MAT-MTART = 'FOOD'.
WA_MAT-MBRSH = 'F'.

APPEND WA_MAT TO IT_MAT.

CLEAR WA_MAT.



WA_MAT-MATNR = 'M009'.
WA_MAT-MTART = 'FOOD'.
WA_MAT-MBRSH = 'F'.

APPEND WA_MAT TO IT_MAT.

CLEAR WA_MAT.

WA_MAT-MATNR = 'M021'.
WA_MAT-MTART = 'FERT'.
WA_MAT-MBRSH = 'M'.

APPEND WA_MAT TO IT_MAT.

CLEAR WA_MAT.



WA_MAT-MATNR = 'M009'.
WA_MAT-MTART = 'FOOD'.
WA_MAT-MBRSH = 'F'.

APPEND WA_MAT TO IT_MAT.

CLEAR WA_MAT.
*
*
* A) MOVE ALL THE  DATA FROMONE ITAB TO OTHER ITAB.
*
*
*  IT_MAT1[] = IT_MAT[].
*
* B) MOVE SPECIFIC DATA BASED ON INDEX NO.


APPEND LINES OF IT_MAT FROM 2 TO 3 TO IT_MAT1.

INSERT LINES OF IT_MAT FROM 5 TO 6 INTO IT_MAT1 INDEX 2.

BREAK-POINT.
*2. TWO INTERNAL TABLE FIELD NAMES ARE SAME BUT FIELD SEQUENCE IS DIFFERENT.


*TYPES : BEGIN OF LS_ITAB,
*        MATNR TYPE MATNR,
*        MTART TYPE MTART,
*        MBRSH TYPE MBRSH,
*        END OF LS_ITAB.
*
*DATA : IT_TAB TYPE STANDARD TABLE OF LS_ITAB,
*       WA_TAB LIKE LINE OF IT_TAB.
*
*
*TYPES : BEGIN OF LS_ITAB1,
*
*        MATNR TYPE MATNR,
*        MBRSH TYPE MBRSH,
*        MTART TYPE MTART,
*
*        END OF LS_ITAB1.
*
*DATA : IT_TAB2 TYPE STANDARD TABLE OF LS_ITAB1,
*       WA_TAB2 LIKE LINE OF IT_TAB2.
*
*
*
*
*WA_TAB-MATNR = 'M001'.
*WA_TAB-MTART = 'FERT'.
*WA_TAB-MBRSH = 'M'.
*
*APPEND WA_TAB TO IT_TAB.
*
*CLEAR WA_TAB.
*
*
*WA_TAB-MATNR = 'M005'.
*WA_TAB-MTART = 'ROH'.
*WA_TAB-MBRSH = 'E'.
*
*APPEND WA_TAB TO IT_TAB.
*
*CLEAR WA_TAB.
*
*
*WA_TAB-MATNR = 'M001'.
*WA_TAB-MTART = 'FERT'.
*WA_TAB-MBRSH = 'M'.
*
*APPEND WA_TAB TO IT_TAB.
*
*CLEAR WA_TAB.
*
*WA_TAB-MATNR = 'M003'.
*WA_TAB-MTART = 'ROH'.
*WA_TAB-MBRSH = 'E'.
*
*APPEND WA_TAB TO IT_TAB.
*
*CLEAR WA_TAB.
*
*
*WA_TAB-MATNR = 'M009'.
*WA_TAB-MTART = 'FOOD'.
*WA_TAB-MBRSH = 'F'.
*
*APPEND WA_TAB TO IT_TAB.
*
*CLEAR WA_TAB.
*
*
*
*WA_TAB-MATNR = 'M009'.
*WA_TAB-MTART = 'FOOD'.
*WA_TAB-MBRSH = 'F'.
*
*APPEND WA_TAB TO IT_TAB.
*
*CLEAR WA_TAB.
*
*WA_TAB-MATNR = 'M021'.
*WA_TAB-MTART = 'FERT'.
*WA_TAB-MBRSH = 'M'.
*
*APPEND WA_TAB TO IT_TAB.
*
*CLEAR WA_TAB.
*
*
*
*WA_TAB-MATNR = 'M009'.
*WA_TAB-MTART = 'FOOD'.
*WA_TAB-MBRSH = 'F'.
*
*APPEND WA_TAB TO IT_TAB.
*
*CLEAR WA_TAB.
*
*
**IT_TAB2[] = IT_TAB[]. " THIS WONT WORK BEACUSE WE HAVE DIFFERNT STRCURE.
*
*
**SOLU: NEED TO READ EACH RECORD OF ITAB AND MOVE TO ONE WA TO OTHER ITAB WA AND ADD A RECORD.
*
*
*LOOP AT IT_TAB INTO WA_TAB.
*
* MOVE-CORRESPONDING WA_TAB TO WA_TAB2.
*
* APPEND WA_TAB2 TO IT_TAB2.
*
* CLEAR : WA_TAB2, WA_TAB.
*
*ENDLOOP.


*
**MOVE DATA FROMONE ITAB TO OTHER ITAB.
*
*
*  IT_MAT1[] = IT_MAT[].

*2. TWO INTERNAL TABLE FIELD NAMES ARE SAME BUT FIELD SEQUENCE IS DIFFERENT.


*TYPES : BEGIN OF LS_ITAB,
*        MATNR TYPE MATNR,
*        MTART TYPE MTART,
*        MBRSH TYPE MBRSH,
*        END OF LS_ITAB.
*
*DATA : IT_TAB TYPE STANDARD TABLE OF LS_ITAB,
*       WA_TAB LIKE LINE OF IT_TAB.
*
*
*TYPES : BEGIN OF LS_ITAB1,
*
*        MATNR TYPE MATNR,
*        MBRSH TYPE MBRSH,
*        MTART TYPE MTART,
*
*        END OF LS_ITAB1.
*
*DATA : IT_TAB2 TYPE STANDARD TABLE OF LS_ITAB1,
*       WA_TAB2 LIKE LINE OF IT_TAB2.
*
*
*
*
*WA_TAB-MATNR = 'M001'.
*WA_TAB-MTART = 'FERT'.
*WA_TAB-MBRSH = 'M'.
*
*APPEND WA_TAB TO IT_TAB.
*
*CLEAR WA_TAB.
*
*
*WA_TAB-MATNR = 'M005'.
*WA_TAB-MTART = 'ROH'.
*WA_TAB-MBRSH = 'E'.
*
*APPEND WA_TAB TO IT_TAB.
*
*CLEAR WA_TAB.
*
*
*WA_TAB-MATNR = 'M001'.
*WA_TAB-MTART = 'FERT'.
*WA_TAB-MBRSH = 'M'.
*
*APPEND WA_TAB TO IT_TAB.
*
*CLEAR WA_TAB.
*
*WA_TAB-MATNR = 'M003'.
*WA_TAB-MTART = 'ROH'.
*WA_TAB-MBRSH = 'E'.
*
*APPEND WA_TAB TO IT_TAB.
*
*CLEAR WA_TAB.
*
*
*WA_TAB-MATNR = 'M009'.
*WA_TAB-MTART = 'FOOD'.
*WA_TAB-MBRSH = 'F'.
*
*APPEND WA_TAB TO IT_TAB.
*
*CLEAR WA_TAB.
*
*
*
*WA_TAB-MATNR = 'M009'.
*WA_TAB-MTART = 'FOOD'.
*WA_TAB-MBRSH = 'F'.
*
*APPEND WA_TAB TO IT_TAB.
*
*CLEAR WA_TAB.
*
*WA_TAB-MATNR = 'M021'.
*WA_TAB-MTART = 'FERT'.
*WA_TAB-MBRSH = 'M'.
*
*APPEND WA_TAB TO IT_TAB.
*
*CLEAR WA_TAB.
*
*
*
*WA_TAB-MATNR = 'M009'.
*WA_TAB-MTART = 'FOOD'.
*WA_TAB-MBRSH = 'F'.
*
*APPEND WA_TAB TO IT_TAB.
*
*CLEAR WA_TAB.
*




*3. TWO INTERNAL TABLE FIELD NAMES DIFFERNT BUT DATA IS SAME.

TYPES : BEGIN OF LS_ITAB,
       MATNR TYPE MATNR,
       MTART TYPE MTART,
       MBRSH TYPE MBRSH,
       END OF LS_ITAB.

DATA : IT_TAB TYPE STANDARD TABLE OF LS_ITAB,
      WA_TAB LIKE LINE OF IT_TAB.
*
*
TYPES : BEGIN OF LS_ITAB3,

       MATNO TYPE MATNR,
       MIND TYPE MBRSH,
       MTYP TYPE MTART,

       END OF LS_ITAB3.

DATA : IT_TAB3 TYPE STANDARD TABLE OF LS_ITAB3,
      WA_TAB3 LIKE LINE OF IT_TAB3.



WA_TAB-MATNR = 'M001'.
WA_TAB-MTART = 'FERT'.
WA_TAB-MBRSH = 'M'.

APPEND WA_TAB TO IT_TAB.

CLEAR WA_TAB.


WA_TAB-MATNR = 'M005'.
WA_TAB-MTART = 'ROH'.
WA_TAB-MBRSH = 'E'.

APPEND WA_TAB TO IT_TAB.

CLEAR WA_TAB.


WA_TAB-MATNR = 'M001'.
WA_TAB-MTART = 'FERT'.
WA_TAB-MBRSH = 'M'.

APPEND WA_TAB TO IT_TAB.

CLEAR WA_TAB.

WA_TAB-MATNR = 'M003'.
WA_TAB-MTART = 'ROH'.
WA_TAB-MBRSH = 'E'.

APPEND WA_TAB TO IT_TAB.

CLEAR WA_TAB.


WA_TAB-MATNR = 'M009'.
WA_TAB-MTART = 'FOOD'.
WA_TAB-MBRSH = 'F'.

APPEND WA_TAB TO IT_TAB.

CLEAR WA_TAB.



WA_TAB-MATNR = 'M009'.
WA_TAB-MTART = 'FOOD'.
WA_TAB-MBRSH = 'F'.

APPEND WA_TAB TO IT_TAB.

CLEAR WA_TAB.

WA_TAB-MATNR = 'M021'.
WA_TAB-MTART = 'FERT'.
WA_TAB-MBRSH = 'M'.

APPEND WA_TAB TO IT_TAB.

CLEAR WA_TAB.



WA_TAB-MATNR = 'M009'.
WA_TAB-MTART = 'FOOD'.
WA_TAB-MBRSH = 'F'.

APPEND WA_TAB TO IT_TAB.

CLEAR WA_TAB.


* MOVE ALL RECORDS OF ONE TAB TO OTNER TAB.

*LOOP AT IT_TAB INTO WA_TAB.
*
*   WA_TAB3-MATNO  =  WA_TAB-MATNR.
*   WA_TAB3-MTYP   =  WA_TAB-MTART .
*   WA_TAB3-MIND   =  WA_TAB-MBRSH .
*
*   APPEND WA_TAB3 TO IT_TAB3.
*
*ENDLOOP.

* WHEN YOU WANT TO MOVE SPECIFIC DATA

*LOOP AT IT_TAB INTO WA_TAB WHERE MTART = 'FERT'.
*
*   WA_TAB3-MATNO  =  WA_TAB-MATNR.
*   WA_TAB3-MTYP   =  WA_TAB-MTART .
*   WA_TAB3-MIND   =  WA_TAB-MBRSH .
*
*   APPEND WA_TAB3 TO IT_TAB3.
*
*ENDLOOP.

 BREAK-POINT.









  • GET THE DATA FROM BASE TABLES.

 *&---------------------------------------------------------------------*
*& Report  ZB12_ITAB_TYPES_FETCH_20
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT  ZB12_ITAB_TYPES_FETCH_20.


* DEFINE ITAB.

TYPES : BEGIN OF LS_PO_HEAD,

         EBELN TYPE EBELN,
         BUKRS TYPE BUKRS,
         BSART TYPE ESART,
         AEDAT TYPE ERDAT,
         LIFNR TYPE ELIFN,
         EKORG TYPE EKORG,
         EKGRP TYPE BKGRP,

       END OF LS_PO_HEAD.


DATA : IT_PODATA TYPE STANDARD TABLE OF LS_PO_HEAD,
      WA_PODATA LIKE LINE OF IT_PODATA, " OR

      WA_PO TYPE LS_PO_HEAD.


* TO FETCH THE DATA FROM DB TABLE  USE SELECCT.

* 1. SELECT *


SELECT    EBELN
         BUKRS
         BSART
         AEDAT
         LIFNR
         EKORG
         EKGRP
FROM EKKO
INTO TABLE IT_PODATA
WHERE EKORG = '3000'.

IF SY-SUBRC = 0.

 SORT IT_PODATA BY EBELN.

ENDIF.

* TO PTINT THE DATA OF ITAB NEED TO READ ALL THE RECORDS OF ITAB USING LOOP.


LOOP AT IT_PODATA INTO WA_PODATA.

WRITE:/ WA_PODATA-EBELN,  WA_PODATA-BUKRS,
          WA_PODATA-BSART ,
          WA_PODATA-AEDAT,
          WA_PODATA-LIFNR,
          WA_PODATA-EKORG,
          WA_PODATA-EKGRP.

ENDLOOP.




*&---------------------------------------------------------------------*
*& Report  ZB12_ITAB_TYPES_FETCH_21
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT  ZB12_ITAB_TYPES_FETCH_21 LINE-SIZE 300.


* DEFINE ITAB.

TYPES : BEGIN OF LS_PO_HEAD,

         EBELN TYPE EBELN,
         BUKRS TYPE BUKRS,
         BSART TYPE ESART,
         AEDAT TYPE ERDAT,
         LIFNR TYPE ELIFN,
         EKORG TYPE EKORG,
         EKGRP TYPE BKGRP,

       END OF LS_PO_HEAD.


DATA : IT_PODATA TYPE STANDARD TABLE OF LS_PO_HEAD,
      WA_PODATA LIKE LINE OF IT_PODATA, " OR

      WA_PO TYPE LS_PO_HEAD.


*2 INTAB


TYPES : BEGIN OF LS_PODTL,

         EBELN TYPE EBELN,   " EKKO
         BUKRS TYPE BUKRS,
         BSART TYPE ESART,
         AEDAT TYPE ERDAT,
         LIFNR TYPE ELIFN,
         EKORG TYPE EKORG,
         EKGRP TYPE BKGRP,

         EBELP TYPE EBELP,    "EKPO
         MATNR TYPE MATNR,
         KTMNG TYPE KTMNG,
         MENGE TYPE BSTMG,
         MEINS TYPE BSTME,
         BPRME TYPE BBPRM,

       END OF LS_PODTL.

DATA : IT_FINAL TYPE STANDARD TABLE OF LS_PODTL,
       WA_FINAL LIKE LINE OF IT_FINAL.


* TO FETCH THE DATA FROM DB TABLE  USE SELECCT.

* 1. SELECT *


SELECT    EBELN
         BUKRS
         BSART
         AEDAT
         LIFNR
         EKORG
         EKGRP
FROM EKKO
INTO TABLE IT_PODATA
WHERE BUKRS = '3000'.

IF SY-SUBRC = 0.

 SORT IT_PODATA BY EBELN.

ENDIF.

SELECT *
FROM EKPO
INTO CORRESPONDING FIELDS OF TABLE IT_FINAL
WHERE BUKRS = '3000'.


IF SY-SUBRC = 0.

 SORT IT_FINAL BY EBELN EBELP.

ENDIF.


LOOP AT IT_FINAL INTO WA_FINAL.

READ TABLE IT_PODATA INTO WA_PODATA WITH KEY EBELN = WA_FINAL-EBELN.

 IF SY-SUBRC = 0.

   WA_FINAL-BSART = WA_PODATA-BSART .
   WA_FINAL-LIFNR = WA_PODATA-LIFNR .
   WA_FINAL-EKORG = WA_PODATA-EKORG .
   WA_FINAL-EKGRP = WA_PODATA-EKGRP.

   MODIFY IT_FINAL FROM WA_FINAL.

 ENDIF.

   WRITE:/ WA_FINAL-EBELN,
          WA_FINAL-EBELP ,
         WA_FINAL-BUKRS ,
         WA_FINAL-BSART ,
         WA_FINAL-AEDAT ,
         WA_FINAL-LIFNR ,
         WA_FINAL-EKORG ,
         WA_FINAL-EKGRP ,
         WA_FINAL-MATNR ,
         WA_FINAL-KTMNG ,
         WA_FINAL-MENGE ,
         WA_FINAL-MEINS ,
         WA_FINAL-BPRME .


  CLEAR : WA_FINAL, WA_PODATA.
 ENDLOOP.

 *&---------------------------------------------------------------------*
*& Report  ZB12_ITAB_TYPES_FETCH_22.
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT  ZB12_ITAB_TYPES_FETCH_22 LINE-SIZE 300.


* DEFINE ITAB.


TYPES : BEGIN OF LS_final,

         EBELN TYPE EBELN,   " EKKO
         BUKRS TYPE BUKRS,
         BSART TYPE ESART,
         AEDAT TYPE ERDAT,
         LIFNR TYPE ELIFN,
         EKORG TYPE EKORG,
         EKGRP TYPE BKGRP,

         EBELP TYPE EBELP,    "EKPO
         MATNR TYPE MATNR,
         KTMNG TYPE KTMNG,
         MENGE TYPE BSTMG,
         MEINS TYPE BSTME,
         BPRME TYPE BBPRM,

       END OF LS_final.

DATA : IT_FINAL TYPE STANDARD TABLE OF LS_final,
       WA_FINAL LIKE LINE OF IT_FINAL.

TYPES : BEGIN OF LS_item,

         EBELN TYPE EBELN,
         EBELP TYPE EBELP,    "EKPO
         MATNR TYPE MATNR,
         KTMNG TYPE KTMNG,
         MENGE TYPE BSTMG,
         MEINS TYPE BSTME,
         BPRME TYPE BBPRM,

       END OF LS_item.


DATA : IT_item TYPE STANDARD TABLE OF LS_item,
      WA_item LIKE LINE OF IT_item.


*1



select    EBELN
         BUKRS
         BSART
         AEDAT
         LIFNR
         EKORG
         EKGRP

from ekko
into table it_final
where bukrs = '3000'.

if sy-subrc = 0.

sort it_final by ebeln.

endif.

select    EBELN
         EBELP
         MATNR
         KTMNG
         MENGE
         MEINS
         BPRME
from ekpo
into table it_item
where bukrs = '3000'.

if sy-subrc = 0.

 sort it_item by ebeln ebelp.

endif.

DATA : LV_COUNTER TYPE I,
       LV_NUM TYPE EKPO-EBELP,
       LV_HEAD TYPE EKKO-EBELN.

LV_HEAD = '3000000000'.

LOOP AT IT_FINAL INTO WA_FINAL.

    LV_COUNTER = 1.



    IF WA_FINAL-EBELN > LV_HEAD.


    LOOP AT IT_ITEM INTO WA_ITEM WHERE EBELN = WA_FINAL-EBELN.

    IF LV_COUNTER = 1.

             WA_FINAL-EBELP    =    WA_ITEM-EBELP.
             WA_FINAL-MATNR    =    WA_ITEM-MATNR.
             WA_FINAL-KTMNG    =    WA_ITEM-KTMNG.
             WA_FINAL-MENGE    =    WA_ITEM-MENGE.
             WA_FINAL-MEINS    =    WA_ITEM-MEINS.
             WA_FINAL-BPRME    =    WA_ITEM-BPRME.

     MODIFY IT_FINAL FROM WA_FINAL.

     CLEAR  : WA_FINAL-EBELP,
              WA_FINAL-MATNR,
              WA_FINAL-KTMNG,
              WA_FINAL-MENGE,
              WA_FINAL-MEINS,
              WA_FINAL-BPRME.


    ELSE.

             WA_FINAL-EBELP    =    WA_ITEM-EBELP.
             WA_FINAL-MATNR    =    WA_ITEM-MATNR.
             WA_FINAL-KTMNG    =    WA_ITEM-KTMNG.
             WA_FINAL-MENGE    =    WA_ITEM-MENGE.
             WA_FINAL-MEINS    =    WA_ITEM-MEINS.
             WA_FINAL-BPRME    =    WA_ITEM-BPRME.

     APPEND WA_FINAL TO IT_FINAL .

   CLEAR  :   WA_FINAL-EBELP,
              WA_FINAL-MATNR,
              WA_FINAL-KTMNG,
              WA_FINAL-MENGE,
              WA_FINAL-MEINS,
              WA_FINAL-BPRME.


    ENDIF.


    LV_COUNTER = LV_COUNTER + 1.



  ENDLOOP.

 LV_HEAD = WA_ITEM-EBELN.
 LV_NUM = WA_ITEM-EBELP.

 CLEAR WA_ITEM.
 CLEAR LV_COUNTER.

 ELSE.

   EXIT.

 ENDIF.

ENDLOOP.


break-point.


*&---------------------------------------------------------------------*
*& Report  ZB12_ITAB_TYPES_FETCH_23
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT  ZB12_ITAB_TYPES_FETCH_23 LINE-SIZE 300.


TYPES : BEGIN OF LS_join,

         EBELN TYPE EBELN,   " EKKO
         BUKRS TYPE BUKRS,
         BSART TYPE ESART,
         AEDAT TYPE ERDAT,
         LIFNR TYPE ELIFN,
         EKORG TYPE EKORG,
         EKGRP TYPE BKGRP,

         EBELP TYPE EBELP,    "EKPO
         MATNR TYPE MATNR,
         KTMNG TYPE KTMNG,
         MENGE TYPE BSTMG,
         MEINS TYPE BSTME,
         BPRME TYPE BBPRM,

       END OF LS_join.

DATA : IT_join TYPE STANDARD TABLE OF LS_join,
       WA_join LIKE LINE OF IT_join.


*3.  select with inner join


 SELECT A~EBELN
        A~BUKRS
        A~BSART
        A~AEDAT
        A~LIFNR
        A~EKORG
        A~EKGRP

        B~EBELP
        B~MATNR
        B~KTMNG
        B~MENGE
        B~MEINS
        B~BPRME

  FROM EKKO AS A INNER JOIN EKPO AS B
  ON A~EBELN = B~EBELN
  INTO TABLE IT_JOIN
  WHERE A~BUKRS = '3000'.

  IF SY-SUBRC = 0.

   SORT IT_JOIN BY EBELN EBELP.
  ENDIF.


  LOOP AT IT_JOIN INTO WA_JOIN.

   WRITE:/ WA_JOIN-EBELN ,
        WA_JOIN-BUKRS ,
        WA_JOIN-BSART ,
        WA_JOIN-AEDAT ,
        WA_JOIN-LIFNR ,
        WA_JOIN-EKORG ,
        WA_JOIN-EKGRP ,

        WA_JOIN-EBELP ,
        WA_JOIN-MATNR ,
        WA_JOIN-KTMNG ,
        WA_JOIN-MENGE ,
        WA_JOIN-MEINS ,
        WA_JOIN-BPRME.

  ENDLOOP.




*&---------------------------------------------------------------------*
*& Report  ZB12_ITAB_TYPES_FETCH_24
*&


REPORT  ZB12_ITAB_TYPES_FETCH_24.


TYPES: BEGIN OF LS_EKKO,

      EBELN TYPE EBELN,
      LIFNR TYPE LIFNR,
      EKORG TYPE EKORG,
      EKGRP TYPE EKGRP,

      END OF LS_EKKO.

DATA : IT_EKKO TYPE STANDARD TABLE OF LS_EKKO,
      WA_EKKO LIKE LINE OF IT_EKKO.


TYPES: BEGIN OF LS_EKPO,

      EBELN TYPE EBELN,
      EBELP TYPE EBELP,
      MATNR TYPE MATNR,
      WERKS TYPE EWERK,
      MENGE TYPE BSTMG,
      NETPR TYPE BPREI,

      END OF LS_EKPO.

DATA : IT_EKPO TYPE STANDARD TABLE OF LS_EKPO,
      WA_EKPO LIKE LINE OF IT_EKPO.


PARAMETERS : P_BSTYP TYPE EBSTYP.


*1.
    SELECT EBELN LIFNR EKORG EKGRP
    FROM EKKO
    INTO TABLE IT_EKKO
    WHERE BSTYP = P_BSTYP.

    IF SY-SUBRC = 0 .

     SORT IT_EKKO BY EBELN.
    ENDIF.


* * SELECT ....FOR ALL ENTERIS

* PRE REQUESTISTES

* 1 . INTERNAL TABLE SHOULD NOT BE INIITAL
* 2.  IN WHERE CONDITION USE ALL PRIMARY KEY FIELDS



IF NOT IT_EKKO[] IS INITIAL.

SELECT EBELN EBELP MATNR WERKS MENGE NETPR
FROM EKPO
INTO TABLE IT_EKPO FOR ALL ENTRIES IN IT_EKKO
WHERE EBELN = IT_EKKO-EBELN.

IF SY-SUBRC = 0.

  SORT IT_EKPO BY EBELN EBELP.
ENDIF.

ENDIF.



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


TYPES: BEGIN OF LS_IHPA,
      PARVW TYPE PARVW,
      PARNR TYPE I_PARNR,
     END OF LS_IHPA.

     DATA : IT_IHPA TYPE STANDARD TABLE OF LS_IHPA,
            WA_IHPA LIKE LINE OF IT_IHPA.

DATA : IT_IHPA1 TYPE STANDARD TABLE OF LS_IHPA,
            WA_IHPA1 LIKE LINE OF IT_IHPA1.


 SELECT PARVW PARNR
 FROM IHPA
 INTO TABLE IT_IHPA
 WHERE PARVW = 'AG'.

 IF SY-SUBRC = 0.

  SORT IT_IHPA BY PARVW PARNR.
 ENDIF.

DELETE adjacent DUPLICATES FROM IT_IHPA COMPARING PARVW PARNR.


* SELECT dISCTICT

SELECT DISTINCT PARVW PARNR
FROM IHPA
INTO TABLE IT_IHPA1
WHERE PARVW =  'AG'.

IF SY-SUBRC = 0.

  SORT IT_IHPA BY PARVW PARNR.
 ENDIF.

 BREAK-POINT.




*&---------------------------------------------------------------------*
*& Report  ZB12_ITAB_PO_DETAILS_25
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT  ZB12_ITAB_PO_DETAILS_25 LINE-SIZE 500.



TYPES: BEGIN OF LS_final,

         EBELN TYPE EBELN,   " EKKO
         BUKRS TYPE BUKRS,
         BSART TYPE ESART,
         AEDAT TYPE ERDAT,
         LIFNR TYPE ELIFN,
         EKORG TYPE EKORG,
         EKGRP TYPE BKGRP,

         EBELP TYPE EBELP,    "EKPO
         MATNR TYPE MATNR,
         KTMNG TYPE KTMNG,
         MENGE TYPE BSTMG,
         MEINS TYPE BSTME,
         BPRME TYPE BBPRM,


         ETENR TYPE EETEN,   " EKET
         EINDT TYPE EINDT,
         SLFDT TYPE SLFDT,
         LPEIN TYPE LPEIN,
         BANFN TYPE BANFN,

         land1 type lfa1-land1,
         name1 type lfa1-name1,
         ort01 type lfa1-ort01,

         maktx type makt-maktx,

       END OF LS_final.

DATA : IT_final TYPE STANDARD TABLE OF LS_final,
       WA_final LIKE LINE OF IT_final.


DATA : IT_DUMMY TYPE STANDARD TABLE OF LS_final,
      WA_DUMMY LIKE LINE OF IT_DUMMY.

TYPES :  BEGIN OF LS_LFA1,

          LIFNR TYPE LFA1-LIFNR,
          land1 type lfa1-land1,
          name1 type lfa1-name1,
          ort01 type lfa1-ort01,
        END OF LS_LFA1.

 DATA : IT_LFA1 TYPE STANDARD TABLE OF LS_LFA1,
       WA_LFA1 LIKE LINE OF IT_LFA1.



TYPES :  BEGIN OF LS_MAKT,
         MATNR TYPE MAKT-MATNR,
         maktx type makt-maktx,
        END OF LS_MAKT.

 DATA : IT_MAKT TYPE STANDARD TABLE OF LS_MAKT,
       WA_MAKT LIKE LINE OF IT_MAKT.


SELECT   A~EBELN
         A~BUKRS
         A~BSART
         A~AEDAT
         A~LIFNR
         A~EKORG
         A~EKGRP

         B~EBELP
         B~MATNR
         B~KTMNG
         B~MENGE
         B~MEINS
         B~BPRME


         C~ETENR
         C~EINDT
         C~SLFDT
         C~LPEIN
         C~BANFN

         FROM ( ( EKKO AS A INNER JOIN EKPO AS B
           ON A~EBELN = B~EBELN ) INNER JOIN EKET AS C
                    ON B~EBELN = C~EBELN AND
                       B~EBELP = C~EBELP )
         INTO TABLE IT_FINAL
         WHERE A~EKORG  = '3000'.

         IF SY-SUBRC = 0.

          SORT IT_FINAL BY EBELN EBELP ETENR.

         ENDIF.

         IT_DUMMY[] = IT_FINAL[].

IF IT_DUMMY[] IS NOT INITIAL.

SORT IT_DUMMY BY LIFNR.

DELETE ADJACENT DUPLICATES FROM IT_DUMMY comparing LIFNR.

SELECT LIFNR LAND1 NAME1 ORT01
FROM LFA1
INTO TABLE IT_LFA1 FOR ALL ENTRIES IN IT_DUMMY
WHERE LIFNR = IT_DUMMY-LIFNR.

IF SY-SUBRC = 0.

          SORT IT_LFA1 BY LIFNR.

ENDIF.

 REFRESH IT_DUMMY[].

 IT_DUMMY[] = IT_FINAL[].

 SORT IT_DUMMY BY MATNR.

 DELETE adjacent DUPLICATES FROM IT_DUMMY COMPARING MATNR.

SELECT MATNR MAKTX
FROM MAKT
INTO TABLE IT_MAKT FOR ALL ENTRIES IN IT_DUMMY
WHERE MATNR = IT_DUMMY-MATNR AND
      SPRAS = 'EN'.

IF SY-SUBRC = 0.

  SORT IT_MAKT BY MATNR.

ENDIF.


ENDIF.

REFRESH IT_DUMMY.

CLEAR : WA_FINAL,
           WA_LFA1,
           WA_MAKT.

LOOP AT IT_FINAL INTO WA_FINAL.


   READ TABLE IT_LFA1 INTO WA_LFA1 WITH KEY LIFNR = WA_FINAL-LIFNR
                                              BINARY SEARCH.
      IF SY-SUBRC = 0 .

        WA_FINAL-LAND1 = WA_LFA1-LAND1.
        WA_FINAL-NAME1 = WA_LFA1-NAME1.
        WA_FINAL-ORT01 = WA_LFA1-ORT01.

      ENDIF.

   READ TABLE IT_MAKT INTO WA_MAKT WITH KEY MATNR = WA_FINAL-MATNR
                                                  BINARY SEARCH.

     IF SY-SUBRC = 0.

      WA_FINAL-MAKTX = WA_MAKT-MAKTX.

     ENDIF.

   MODIFY IT_FINAL FROM WA_FINAL.




  WRITE:/ WA_FINAL-EBELN,
         WA_FINAL-BUKRS,
         WA_FINAL-BSART,
         WA_FINAL-AEDAT,
         WA_FINAL-LIFNR,
         WA_FINAL-LAND1,
         WA_FINAL-NAME1,
         WA_FINAL-ORT01,
         WA_FINAL-EKORG,
         WA_FINAL-EKGRP,

         WA_FINAL-EBELP,
         WA_FINAL-MATNR,
         WA_FINAL-MAKTX,
         WA_FINAL-KTMNG,
         WA_FINAL-MENGE,
         WA_FINAL-MEINS,
         WA_FINAL-BPRME,


         WA_FINAL-ETENR,
         WA_FINAL-EINDT,
         WA_FINAL-SLFDT,
         WA_FINAL-LPEIN,
         WA_FINAL-BANFN,
         WA_FINAL-LAND1,
         WA_FINAL-NAME1,
         WA_FINAL-ORT01.


   CLEAR : WA_FINAL,
           WA_LFA1,
           WA_MAKT.

ENDLOOP.


*&---------------------------------------------------------------------*
*& Report  ZB12_ITAB_SELECTIONS_26
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT  ZB12_ITAB_SELECTIONS_26.

tables : ekko.


selection-screen : begin of block b1 with frame title text-001.

*parameters : p_comp type ekko-bukrs default '3000',  " default value
*
*             p_ekorg type ekko-ekorg default '3000'.

parameters : p_comp type ekko-bukrs obligatory,      " to make mandatory field
           p_ekorg type ekko-ekorg default '3000'.

*             p_ekorg type ekko-ekorg default '3000' no-display. " hidethe parameter

selection-screen : end of block b1.


selection-screen : begin of block b3 with frame title text-001.

parameters :  a as checkbox.


selection-screen : end of block b3.

selection-screen : begin of block b2 with frame title text-001.

*select-options : s_aedat for ekko-aedat default '19950101' to '20001231'.
*select-options : s_aedat for ekko-aedat obligatory .
*select-options : s_aedat1 for ekko-aedat no-display .
select-options : s_aedat1 for ekko-aedat.
select-options : s_aedat for ekko-aedat no-extension no intervals .

selection-screen : end of block b2.
break-point.





TYPES : BEGIN OF LS_join,

         EBELN TYPE EBELN,   " EKKO
         BUKRS TYPE BUKRS,
         BSART TYPE ESART,
         AEDAT TYPE ERDAT,
         LIFNR TYPE ELIFN,
         EKORG TYPE EKORG,
         EKGRP TYPE BKGRP,

         EBELP TYPE EBELP,    "EKPO
         MATNR TYPE MATNR,
         KTMNG TYPE KTMNG,
         MENGE TYPE BSTMG,
         MEINS TYPE BSTME,
         BPRME TYPE BBPRM,

       END OF LS_join.

DATA : IT_join TYPE STANDARD TABLE OF LS_join,
       WA_join LIKE LINE OF IT_join.


*3.  select with inner join


 SELECT A~EBELN
        A~BUKRS
        A~BSART
        A~AEDAT
        A~LIFNR
        A~EKORG
        A~EKGRP

        B~EBELP
        B~MATNR
        B~KTMNG
        B~MENGE
        B~MEINS
        B~BPRME

  FROM EKKO AS A INNER JOIN EKPO AS B
  ON A~EBELN = B~EBELN
  INTO TABLE IT_JOIN
  WHERE A~BUKRS = p_comp and
        A~ekorg = p_ekorg and
        a~aedat IN S_AEDAT.

  IF SY-SUBRC = 0.

   SORT IT_JOIN BY EBELN EBELP.
  ENDIF.


  LOOP AT IT_JOIN INTO WA_JOIN.

   WRITE:/ WA_JOIN-EBELN ,
        WA_JOIN-BUKRS ,
        WA_JOIN-BSART ,
        WA_JOIN-AEDAT ,
        WA_JOIN-LIFNR ,
        WA_JOIN-EKORG ,
        WA_JOIN-EKGRP ,

        WA_JOIN-EBELP ,
        WA_JOIN-MATNR ,
        WA_JOIN-KTMNG ,
        WA_JOIN-MENGE ,
        WA_JOIN-MEINS ,
        WA_JOIN-BPRME.

  ENDLOOP.