Tuesday, March 1, 2022

4.Internal Table

Internal Tables

  1. Internal tables are collection of records.
  2. Internal tables are temporary tables. ie.. The data in the internal table will not save any where in the SAP.
  3. Internal table are dynamic in memory allocation. so no need to provide size for internal table during declaration.
  4. The scope of the internal table is only within the program.
  5. Storing or retrieving of data from internal table are always record by record.

Syntax for internal table declaration.

  SYNTAX :-  data: <internal_table_name> like table of <workarea_name>.

                        DATA: it_emp LIKE TABLE OF wa_emp.

Note:
        Database -> Internal Table -> Workarea.

ITAB vs DB.Tables.

  1. Internal table are temporary memory location.
  2. Internal table are specific to program. ie we cannot access it outside the program.
  3. Internal table are dynamic in memory allocation.
--------------
  1. Database table are permanent memory location.
  2. Database tables are accessed any from in the SAP.
  3. Size of the db tables are must be specified during declaration.
Note:
        Syntax of accessing the fields from work_area.
            <work_area - field name>
            Ex: wa_emp-ename.

Note:
        Append is the keyword used to transfer the data from workarea to internal table .
        Syntax: Append <work_area> to <internal_table>.

Object 1.

Fill internal table manually.

*&--------------------------------------
*& Report ZITAB_OBJ1
*&--------------------------------------
REPORT zitab_obj1.

"declaration
DATABEGIN OF emp,
      eid(10TYPE c,
      ename(25TYPE c,
      eadd(35TYPE c,
      END OF emp.

DATA employee LIKE TABLE OF emp.

"Filling data.
emp-eid '1'.
emp-ename 'raju'.
emp-eadd 'pune'.
APPEND emp TO employee.

emp-eid '2'.
emp-ename 'ramu'.
emp-eadd 'hyadrabad'.
APPEND emp TO employee.

emp-eid '3'.
emp-ename 'ravi'.
emp-eadd 'bangalore'.
APPEND emp TO employee.

"diaplay data
LOOP AT employee INTO emp.
  WRITE:/ emp-eidemp-enameemp-eadd.
ENDLOOP.

Note:
        Syntax for select query:

        SELECT <field1>, <field2>, <field3>..... 
            FROM <db_table> 
            INTO TABLE <itab>
            WHERE <cond>.

Object 2:

To display the company code, company names and city.

*&------------------------------------
*& Report ZITAB_OBJ2
*&------------------------------------
REPORT zitab_obj2.

"Declaration
DATABEGIN OF wa,
  bukrs(4TYPE c,
  butxt(25TYPE c,
  ort01(25TYPE c,
  END OF wa.

DATA itab LIKE TABLE OF wa.

"Filling itab using select query
SELECT bukrsbutxtort01
  FROM t001
  INTO TABLE @itab.

"Display output
LOOP AT itab INTO wa.
  WRITE:/ wa-bukrswa-butxtwa-ort01.
ENDLOOP.

Object 3:

To display the customer numbers, Customer names, Cities and Countries.

*&------------------------------------
*& Report ZITAB_OBJ3
*&------------------------------------
REPORT zitab_obj3.

"Declaration
DATABEGIN OF wa,
        kunner(10TYPE c,
        name1(35TYPE c,
        ort01(35TYPE c,
        land1(3TYPE c,
      END OF wa.

DATA itab LIKE TABLE OF wa.

"Logic
SELECT kunnrname1ort01land1
  FROM kna1
  INTO TABLE @itab.

"Display output
LOOP AT itab INTO wa.
  WRITE:/ wa-kunnerwa-name1wa-ort01wa-land1.
ENDLOOP.

Note:
  1. Domain is the collection of data type and length.
  2. Data Element is the collection of domain with short description.
Note: 
  1. Syntax for declaring the field
    • DATA <field_name>(length) TYPE <data_type>.
    • DATA <field_name> TYPE <data_element>.
    • DATA <field_name>(length) TYPE <data_type>-<field_name>
    • DATA bukrs(4) TYPE c.
    • DATA bukrs TYPE bukrs.
    • DATA bukrs TYPE T001-bukrs.

Object 4:

To display  the company codes, company names, cities.

*&------------------------------------
*& Report ZITAB_OBJ4
*&------------------------------------
REPORT zitab_obj4.

Select-Option

  • Select-Option is the keyword used to accept different type of inputs like
    • single value 
    • multiple single value
    • single range
    • multiple range inputs.
  • Syntax for select option.
    •  SELECT-OPTION <name of the select option> for <variable>.
    • DATA var TYPE T001-bukrs.
    • SELECT-OPTION so_bukrs FOR var.
  • Syntax for select option in select query.
                SELECT <field1>, <field2>, <field3>... 
                        FROM <db_table> 
                        INTO TABLE <itab> 
                        WHERE <field> IN <select_option>.

Object 5:

based on the given company codes display the company codes, company name, cities.

*&------------------------------------
*& Report ZITAB_OBJ5
*&------------------------------------
REPORT zitab_obj5.

Note:
        The order of the fields in the workarea as well as the order of the fields in the select query must be same otherwise sometimes it leads to dump.

Object 6:

Based on the given customer no display the customer number, customer names, cities.

*&------------------------------------
*& Report ZITAB_OBJ6
*&------------------------------------
REPORT zitab_obj6.

Parameter:

  • Parameter is the keyword which accepts single value as input at run time.
  • Syntax
    • PARAMETER <name> TYPE <data_type> p_bukrs T001-bukrs.
    • PARAMETER p_bukrs TYPE T001-bukrs.
    • Syntax for parameter in select query.
                        SELECT <field1>, <field2>...
                                FROM <db_table>
                                INTO TABLE <itab>
                                WHERE <field_name> = <parameter>.

    Difference between parameter and select option.

    1. Parameter is the keyword which accepts the single value at runtime.
    2. Variable declared as parameter wont fetch any data from database, if executed without input.
    3. Parameter stores values in internal tables.
    4. There is no selection table concept in parameter.
    5. = operator is used in select query where condition.
    6. Radio button, Check box are created using parameter.
    ------------------
    1. Select option is the keyword which accept the single value, multiple single value, single range, multiple range.
    2. Variable declared as select option fetch entire data from database, if executed without input.
    3. Select option stores values in internal table.
    4. It create selection table with 4 column. SIGN, OPTION, LOW, HIGH.
    5. IN operator is used in select query where condition.
    6. Dropbox can be created using select option.

    Types of internal tables.

    There are 3 types of internal tables are there
    1. Standard internal table
    2. Sorted internal table
    3. Hashed internal table



















    No comments:

    Post a Comment

    15.Modern Syntax ( 7.4/7.5 Syntax )