Joins

Embed Size (px)

DESCRIPTION

joins

Citation preview

  • ABAP @ ARJUN, Igrow Soft

    Select with JOINS SELECT WITH JOINS:

    1. This statement is used to fetch the data simultaneously from multiple

    tables.

    2. That means the multiple tables must be joined using one or two fields.

    3. There should be at least one common field between tables.

    4. There are two types of joins.

    INNER JOIN:

    1. In this join only the matching records between the tables will be fetched.

    2. The unmatched records are not selected.

    OUTER JOIN:

    1. In this join all the records from the first table or left table will be selected

    first.

    2. If there are any matching records from second, third tables, then the data

    will be displayed.

    3. Suppose if there are no matching records, the data will be displayed as

    blank from second and third tables.

    SYNTAX:

    Select T1~F1

    T1~F2

    T2~F1

    T2~F2

    T3~F1

  • ABAP @ ARJUN, Igrow Soft

    T3~F2

    INTO TABLE FROM T1 AS

    T2 as on T1~F1 =T2~F1

    T3 as on T2~F1 = T3~F1

    where .

    ZCUST_DATA ZCUST_BANKDATA

    CNO CNAME CITY

    CNO BANKID BANKNAME 1001 AAA HYD

    1001 CITY01 CITYBANK

    1002 BBB BLORE

    1001 SBI01 SBI 1003 CCC CHENNAI

    1001 SBH01 SBH

    1003 ICICI01 ICICI

    1003 HDFC01 HDFC

    INNER JOIN OUTPUT OUTERJOIN OUTPUT

    CNO CNAME BANKID BANKNAME

    CNO CNAME BANKID BANKNAME

    1001 AAA CITY01 CITYBANK

    1001 AAA CITY01 CITYBANK

    1001 AAA SBI01 SBI

    1001 AAA SBI01 SBI

    1001 AAA SBH01 SBH

    1001 AAA SBH01 SBH

    1003 CCC ICICI01 ICICI

    1002 BBB - -

    1003 CCC HDFC01 HDFC

    1003 CCC ICICI01 ICICI

    1003 CCC HDFC01 HDFC

    Joined on ZCUST_DATA~CNO

    =

    ZCUST_BANKDATA~CNO

  • ABAP @ ARJUN, Igrow Soft

    Ex on JOINS with 2 Tables

    TYPES : BEGIN OF ty_mara_makt,

    matnr TYPE mara-matnr,

    mtart TYPE mara-mtart,

    mbrsh TYPE mara-mbrsh,

    meins TYPE mara-meins,

    spras TYPE makt-spras,

    maktx TYPE makt-maktx,

    END OF ty_mara_makt.

    DATA : i_mara_makt TYPE TABLE OF ty_mara_makt .

    DATA : wa_mara_makt TYPE ty_mara_makt .

    SELECT mara~matnr

    mara~mtart

    mara~mbrsh

    mara~meins

    makt~spras

    makt~maktx

    INTO TABLE i_mara_makt

    FROM mara AS mara INNER JOIN makt AS makt

    ON mara~matnr = makt~matnr

    WHERE mara~mtart = 'FERT'

    AND makt~spras = 'EN' .

  • ABAP @ ARJUN, Igrow Soft

    LOOP AT i_mara_makt INTO wa_mara_makt.

    WRITE : / wa_mara_makt-matnr ,

    wa_mara_makt-mtart COLOR 6,

    wa_mara_makt-mbrsh ,

    wa_mara_makt-meins ,

    wa_mara_makt-spras COLOR 1,

    wa_mara_makt-maktx COLOR 1 .

    ENDLOOP.

    The output is :

  • ABAP @ ARJUN, Igrow Soft

    Ex on JOINS with 3 Tables

  • ABAP @ ARJUN, Igrow Soft

    The output is :

  • ABAP @ ARJUN, Igrow Soft

    SelectFor All Entries:

    1. This statement is used to replace select with joins.

    2. Because JOINS statement cannot be used for more than three

    tables.

    3. If we use more than three tables it puts heavy load on the

    Database, because the data has to be selected by comparing

    each table in the database server.

    4. So it takes the long time for execution.

    5. In such cases we go for SELECT FOR ALL ENTRIES.

    6. This statement will never put load on the database. Because

    only two tables (Internal table and database tables) are

    compared.

    SYNTAX:

    Select F1 F2 F3..

    From

    Into table Where .

    If ITAB1[] is not initial.

    Select F1 F2 F3..

    From

    Into table

    For all entries in

    Where F1 = AND F2 = .

    Endif.

  • ABAP @ ARJUN, Igrow Soft

    7. The prerequisite for the above statement is, the first ITAB should

    be checked whether it has any data.

    8. Suppose if it has data, then for all entries statement will execute

    based on the condition and only matching records will be

    selected.

    9. Suppose if first ITAB is empty then for all entries statement will

    fail and all the records will be selected, irrespective of condition.

    Finally the first ITAB should be checked for any records using below

    statement.

    If ITAB1[] is not initial. Select ... ... For all entries in . Endif.

    Ex on SelectFor All Entries

    Develop a material master report to display material details along

    with description details

  • ABAP @ ARJUN, Igrow Soft

  • ABAP @ ARJUN, Igrow Soft

    Save->Act->Test.

    Second way: As per performance, this is a good stmtBcoz we are using

    Binary Search.

    Save->Act->Test.

  • ABAP @ ARJUN, Igrow Soft

    Third Way: In Real Time, we always move the data into Final Int.Table

    Save->Act->Test.

  • ABAP @ ARJUN, Igrow Soft

    SELECTION SCREEN:

    An input screen to a program or report is called selection screen.

    We can design the selection screen using the following statements.

    PARAMETERS:

    SYNTAX:

    1. Parameters : type .

    2. Parameters : type obligatory.

    3. Parameters : as checkbox.

    4. Parameters : radiobuttongroup ,

    radiobuttongroup

    default X,

    radiobuttongroup .

    5. Parametrs : (length) type .

  • ABAP @ ARJUN, Igrow Soft

    Note: Whenever a checkbox or radio button is selected on the

    selection screen, the character X will be stored internally in the

    parameter variable.

    SELECT-OPTIONS:

    This statement is used to create two input fields so that the user

    can enter a range of values.

    In addition to that he can also enter

    i. Multiple single values (1, 7, 13, 98,257.)

    ii. Multiple ranges (1-10, 27-30.)

    iii. Exclude single values (3, 10, 15)

    iv. Exclude ranges (11-15, 95-99.. )

    All these options are available when you click on multiple selection or

    extension box multiple selection.

    Syntax:

    Select-options for .

    Select-options for No Intervals.

    Select-options for No-Extension.

    Select-options for No Intervals

    No- Extension.

    NOTE:

    Whenever we use select-options we should use IN instead of

    = or EQ in the where condition of a select statement.

  • ABAP @ ARJUN, Igrow Soft

    SELECT-OPTIONS INTERNAL TABLE:

    Whenever we declare select-options, by default an internal table will

    be created with four fields, using old syntax i.e. occurs 0 with

    headerline.

    The 4 fields are:

    SIGN: Stores sign of numbers entered on selection-screen.

    The signs are:

    I - including (only specified values will be selected).

    E- Excluding ( only specified value will be excluded).

    By default I is stored.

    OPTION: Stores relational operator between the numbers.

    i. The operators are: BT, NB, EQ, NE, LT, LE, GT, and GE.

    ii. By default BT is stored..

    LOW: Stores lower value from the range entered on selection screen.

    HIGH: Stores higher value from the range entered on selection screen.

  • ABAP @ ARJUN, Igrow Soft

    SELECTION SCREEN MISCELLANEOUS COMMANDS:

    Ex on selection-screen commands:

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

    Select-options: s_kunnr for kna1-kunnr.

    Selection-screen uline.

  • ABAP @ ARJUN, Igrow Soft

    Parameters: p_land1 type kna1-land1.

    Selection-screen skip.

    Parameters: p_matnr type mara-matnr.

    Selection-screen end of block b1.

    Selection-screen begin of block b2 with frame title text-002.

    Selection-screen begin of line.

    Selection-screen comment 2(15) text-003.

    Parameters: p_lifnr type lfa1-lifnr.

    Selection-screen comment 30(10) text-004.

    Parameters: p_land2 type lfa1-land1.

    Selection-screen end of line.

    Selection-screen end of block b2.

  • ABAP @ ARJUN, Igrow Soft

    Modularization

    It is a technique of dividing a main program into smaller programs or

    modules for better reusability and readability.

    In real time, every program must be divided into modules.

    In Abap, Modularization is implemented using following techniques.

    1.Include Programs

    2.Function Modules

    3.Subroutines

    4.Classes

    5.Macros These are

    Include Programs:

    These are sub programs which are used for reusability purpose.

    These programs cannot be executed independently.

    Theses must be inserted in Main programs for execution.

    This program does not contain any parameter interface i.e.

    No importing, Exporting Parameters.

    Syntax :

    INCLUDE

  • ABAP @ ARJUN, Igrow Soft

    Ex on INCLUDE program :

    Include z_modularization_top.

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

    Select-options: s_kunnr for kna1-kunnr.

    Parameters: p_land1 type kna1-land1.

    Selection-screen end of block b1.

    Include zmodularization_getdata.

    Include zmodularization_dispdata.

    Tables kna1

    Data: i_mara type table of mara

    Data: wa_mara type mara.

    Select * from mara Into table i_mara

    Where kunnr in s_kunnr and

    land1 = p_land1

    Loop at I_KNA1 INTO WA_KNA1 .

    WRITE : /

    ENDLOOP .

  • ABAP @ ARJUN, Igrow Soft