Docstoc

WRITE

Document Sample
WRITE Powered By Docstoc
					Report Layout


   Report Heading
                       Report Title

                    Column Heading




  Report Body
Standard Page Heading


      Standard Page Heading




      Execute
      Report Statement : Standard Heading

REPORT <Report Name> [NO STANDARD PAGE HEADING].




REPORT ztest1 NO STANDARD PAGE HEADING.
No Standard Page Heading



        Execute
WRITE …Column Number…


WRITE: 10 ‘Hello’, 50 ‘World’.
       Report Statement : Line Size



REPORT <Report Name> [LINE-SIZE no. of columns].



REPORT ztest LINE-SIZE 255 .
                                      sy-linsz
Exercise
  Column : 50   Column : 170
       WRITE Statement


* Write data
WRITE ‘Hello World’.
WRITE: ‘OK’ , ‘Test data’.
WRITE: /15(10) ‘ABCDEFGHIJKLMNOPQ’.
WRITE /20 ‘Test data’.
       Breaking to a New Line


* Write data
WRITE: / ‘First Line’, ‘Data 1’,
        / ‘Second Line’,‘Data 2’,
   /(20) ‘Third Line’,‘Data 3’,
   /35 ‘Fourth Line’,‘Data 4’.

             sy-colno
              Exercise
Column : 50
Line : 1            Column : 170
                    Line : 2
           Creating Lists
   ABAP statement that create list
       WRITE
       ULINE
       SKIP
   The complete report list will appears
    automatically at the end of the
    processing block
               List Buffer

Dialog WP             Local Memory
                        User Context

   TaskHandler
                        Memory Space
   ABAP Processor


   Dynpro Processor     List Buffer
                                       WRITE,SKIP,ULINE

    DB Interface
Inserting Blank Lines(SKIP)
*Skip Statement
SKIP.
WRITE: ‘Hello World’, sy-linno.
SKIP.
WRITE: ‘Test 1’.
SKIP 5.
WRITE: ‘Test 2’.
SKIP TO LINE 20.
WRITE ‘This is line 20’.
         NEW-LINE

WRITE ‘Hello World’.
NEW-LINE.
WRITE ‘OK’.

            =

WRITE ‘Hello World’.
WRITE / ‘OK’.
       Exercise



Column : 50       Column : 170
Line : 5          Line : 7
Inserting Horizontal Lines(ULINE)
* Uline
WRITE: ‘Hello World’.
ULINE /1(20).
WRITE: /(20) sy-uline.
WRITE: / sy-vline, 20 sy-vline.
ULINE /(20).
WRITE: / ‘This is an underline’.
ULINE.
Frame Example
           Frame


ULINE: /1(45).
WRITE: /1 sy-vline, 'Column #1',
        15 sy-vline, 'Column #2',
        30 sy-vline, 'Column #3',
        45 sy-vline.
ULINE /(45).
           Exercise I


                        sy-uzeit
sy-datum



   20             55          80
             80
   FORMAT Statement

FORMAT [COLOR <color>].
       [COLOR OFF].
      FORMAT Statement

FORMAT COLOR 1.
WRITE: / ‘Hello World’, ‘Test’ COLOR 7.
FORMAT COLOR OFF.
                 FORMAT COLOR
FORMAT   COLOR   col_heading.      “color   1
FORMAT   COLOR   col_normal.       “color   2
FORMAT   COLOR   col_total.        “color   3
FORMAT   COLOR   col_key.          “color   4
FORMAT   COLOR   col_positive.     “color   5
FORMAT   COLOR   col_negative.     “color   6
FORMAT   COLOR   col_group.        “color   7
FORMAT   COLOR   col_background.   “color   0
Color Using Example
Exercise I
                 Text Symbol


                               REPORT ztest.
                               WRITE: text-001,
                                       text-002.
 Text Element
   Text Symbols
   Text Symbol     Text
         001        Text 1

         002        Text 2
Text Symbol

              WRITE: /   text-001.
              WRITE: /   text-001.
              WRITE: /   text-001.
              WRITE: /   text-001.
              WRITE: /   text-001.
                  CONSTANTS


* Constant variable
CONSTANTS ctext TYPE string VALUE ‘Hello World’.
WRITE / ctext.
WRITE / ctext.
WRITE / ctext.
WRITE / ctext.
WRITE / ctext.
Text Symbol : Language Translation
Text Symbol : Language Translation
      Options of the WRITE Statement


* Write Syntax
WRITE var   [NO-ZERO]
            [NO-SIGN]
            [NO-GROUPING]
            [NO-GAP]
            [DECIMALS no of decimals]
  Suppressing Zero With Blanks (NO-ZERO)



* No Zero
DATA: number(10) TYPE N VALUE 23.
WRITE: number, number NO-ZERO.
 Suppressing Number(+ / -) Sign


* No Sign
DATA: v_integer TYPE i VALUE -1.
WRITE: v_integer, v_integer NO-SIGN.
            NO-GROUPING

* No grouping
DATA: v_integer TYPE i VALUE 120000.
WRITE: v_integer, v_integer NO-GROUPING.
             NO-GAP


* No gap
WRITE: ‘Hello’ NO-GAP, ‘World’.
                  DECIMALS


* Decimals
DATA: v_pack TYPE P DECIMALS 4 VALUE ‘1234.5678’.
WRITE: v_pack, v_pack DECIMALS 2.
             Formatting Options


* Format options of WRITE statement
* LEFT-JUSTIFIED for Numeric data
* RIGHT-JUSTIFIED for Character data
* CENTERED                          tmp1
DATA tmp1(20) VALUE ‘test’.
                                     test
WRITE: tmp1 CENTERED.
STRLEN Built-in Function


DATA: tmp(20) VALUE ‘Test String’,
       count TYPE i.
count = strlen( tmp ).
WRITE count.
              Include Program
   You can create a program with program type include program
    in the program attribute
   Include program do not have to have an introductory statement
   During the syntax check and during program generation by the
    ABAP compiler, the INCLUDE statement is replaced by the
    source text of the defined include program

REPORT ztest1.
INCLUDE zinclude1.      Include Program : ZINCLUDE1
                         DATA   tmp(10).
  …                      DATA   tmp1 TYPE i.
                         DATA   tmp2 TYPE p.          REPORT ztest2.
                         DATA   tmp3.
                                                      INCLUDE zinclude1.
                                                        …
Flow Control in ABAP
       Flow Control in ABAP



 Branching ==> IF, CASE.
 Looping   ==> DO, WHILE.
        IF Statement

IF <Condition>.
   <Statement Block>
ELSEIF <Condition>.
   <Statement Block>
ELSEIF <Condition>.
   <Statement Block>
ELSE.
   <Statement Block>
ENDIF.
               IF Statement
IF sy-mandt = ‘100’.
    WRITE: / ‘This is Production Client’.
ELSEIF sy-mandt = ‘800’ or sy-mandt = ‘805’.
    WRITE: / ‘This is Training Client’.
    WRITE / sy-mandt.
ELSE.
    WRITE: / ‘This is Test Client’.
ENDIF.
      CASE Statement
CASE <field>.
 WHEN <value1>.
    <Statement Block>
 WHEN <value2>.
    <Statement Block>
 ...
 WHEN OTHERS.
    <Statement Block>
ENDCASE.
            CASE Statement
CASE sy-mandt.
 WHEN ‘100’.
   WRITE: / ‘This is Production Client’.
 WHEN ‘800’ or ‘805’.
   WRITE: / ‘This is Training Client’.
   WRITE / sy-mandt.
 WHEN OTHERS.
   WRITE: / ‘This is Test Client’.
ENDCASE.
  DO Statement

DO.            Loop Counter


WRITE sy-index.
IF sy-index = 3.
   EXIT.
ENDIF.
WRITE: sy-index.
ENDDO.
 DO Statement

                 Loop Counter
DO 10 TIMES.
 WRITE / sy-index.
ENDDO.
    WHILE Statement


DATA: count TYPE i value 1.
WHILE count <> 4.    Loop Counter

 WRITE: sy-index.
 count = count + 1.
ENDWHILE.
                WHILE sy-index <> 4.
                 WRITE: sy-index.
                ENDWHILE.
  Logical Expressions
>,GT
<,LT
>=, =>, GE
<=, =<, LE
=, EQ
<>, ><, NE
BETWEEN <value1> AND <value2>
IS INITIAL
Arithmetic Operators
+ , - , * , / , **
DIV
MOD

     Example :
     9 / 2 = 4.5
     9 DIV 2 = 4.0
     9 MOD 2 = 1
     2 ** 4 = 16
    ABAP : Data Retrieval
   Open SQL (SELECT)
     SAP System : 3 Tier Client/Server
SAP GUI       SAP GUI         SAP GUI   Presentation
                                        Server




                        SAP
                        Application
                        Server



                        DB Server
          SAP SYSTEM (3 Tier Architecture)
                                       SAP GUI            SAP GUI

Presentation Layer
(Windows based)



                        SAP Instance
Application Layer
                                              Dispatcher                         M
(Windows Server/UNIX)
                         Request                                          SAP Buffer
                          Queue
                                                                         (Shared Mem)

                                   D      D      B    V      S      E
                                                                                 G



                                                                        Oracle
Database Layer
                                                                        Informix
(Windows Server/UNIX)
                                                                        DB2
                                   Database Server
                                                                        MS SQL Server
                                                                        MaxDB
     SAP System : Dialog Processing
                                                       SAP GUI
                                                                                                                    Report zpsm1.
                                                                                                                    Tables customers.
                                                  Request
                                                                            List                                    Select single * from customers
                                                             Generate Screen(List)                                                  where id = 1.
                                                      1       11                                                    Write: / customers-name.
Application Server                       Send Request

Store request to queue
            3                                 Dispatcher
                             Send List        2        Search for free WP                        SAP Buffer
                               10
      Request                                         Check Program in Program Buffer                                                8
                                                                                                      Program
       Queue Send request to WP                             6                                                                   Execute ABAP
                         4                                                                                                      statement
                                                                                                         …
                                D            D              D …                    B
                                                                                                         User Context
                                                                5                                            Area

                                         9                    Roll in                      7

                                         SQL Request                                   Load&Generate Program
Database Server
                                                                                         Report zpsm1.
                                                                                         Tables customers.
                                    customers                       REPOSRC
                                                                                         Select single * from customers
                                                                                                         where id = 1.
                                                                                         Write: / customers-name.
Dialog Work Process Architecture
   Dialog Work Process               Local Memory
                                        User Context
          TaskHandler

                                        Memory Space
         ABAP Processor


       DYNPRO Processor
                                        List Buffer


          DB Interface
                 Result Set Memory




                    Database Server
         Open SQL
   SELECT ...
Data Objects : Tables Structure
Memory Space
    Variable             Structure


Constants       <Field-symbols>
                                  Internal Table

 Tables Structure
                       DB Interface
SAP Application Server

        Dialog WP                 Local Memory
                                   Memory Space
                  TaskHandler

           ABAP Processor
                   DYNPRO
                                   List Buffer
           DB Interface

                     Result Set


         ~ 32 KB in length
Database Server


                                                  Data   Data
                           Data       Data
           Data
                  Example Tables in DB

                                                 customers
spfli                                             id   name       city

carrid   connid   cityfrom   cityto   distance
                                                  1    John    New York
 LH      0400        LA        NY       100       2    Peter   Singapore
 LH      0402       BK         NY       540       3    David    London
 SQ      0110       SQ         BK       250
Example Tables in DB
sflight
carrid   connid     fldate   price


 LH      0400     20010101     150

 LH      0400     20010110     145

 LH      0400     20010228     130

 SQ      0110     20010226      75
         SELECT Overview
SELECT <Column List>  Which Columns?
 FROM <table>         Which Table?
  INTO <destination> Where to place?
   WHERE <condition> Which Lines?
         SELECT Statement
   Select multiple records from database

            SELECT * FROM customers.
             …
            ENDSELECT.



   Select single record from database

           SELECT SINGLE * FROM customers WHERE id = 1.
           …
spfli-carrid   spfli-connid spfli-cityfrom spfli-cityto

     SELECT Multiple Records : SPFLI
    TABLES spfli.
    SELECT * FROM spfli.
     WRITE: / spfli-carrid, spfli-connid,
              spfli-cityfrom, spfli-cityto.
    ENDSELECT.
sflight-carrid sflight-connid sflight-fldate sflight-price

    SELECT Multiple Records : SFLIGHT
  TABLES sflight.
  SELECT * FROM sflight.
   WRITE: / sflight-carrid, sflight-connid,
            sflight-fldate, sflight-price.
  ENDSELECT.
                Exercise

CUSTOMERS-ID   CUSTOMERS-NAME   CUSTOMERS-CITY
    SELECT Multiple Records : CUSTOMERS

TABLES customers.
SELECT * FROM customers.
 WRITE: / customers-id, customers-name, customers-city.
ENDSELECT.
            Dialog WP
Dialog WP                Local Memory
                            User Context
   TaskHandler
                            Memory Space
   ABAP Processor


   DYNPRO Processor
                           List buffer


     DB Interface
            Result Set




    Database
    SELECT Statement Working Steps
1. Transform open SQL to DB SQL and return result set
into result set work area
  DB Interface
   SELECT * FROM customers.       SELECT * FROM customers;
    …
   ENDSELECT.
                                               sy-subrc = 0


2. Loop with data in result set and transfer each record to
work area in memory space
 ABAP Processor
                                  Table Structure in Memory
   SELECT * FROM customers.       Space
    …
   ENDSELECT.
  Select Multiple Records : SPFLI
TABLES spfli.
SELECT * FROM spfli.
  WRITE: / spfli-carrid, spfli-connid,
           spfli-cityfrom,spfli-cityto.
ENDSELECT.
     SELECT Statement Working Steps
1. Transform open SQL to DB SQL and return result set
into result set work area
  DB Interface
   SELECT * FROM spfli.           SELECT * FROM spfli;
    …
   ENDSELECT.
                                               sy-subrc = 0


2. Loop with data in result set and transfer each record to
work area in memory space
 ABAP Processor
                                  Table Structure in Memory
   SELECT * FROM spfli.           Space
    …
   ENDSELECT.
    SELECT Multiple Records : CUSTOMERS

TABLES customers.
SELECT * FROM customers.
 WRITE: / customers-id, customers-name, customers-city.
ENDSELECT.
      SELECT INTO Table Structure
TABLES customers.
SELECT * FROM customers INTO customers.
 WRITE: / customers-id, customers-name, customers-city.
ENDSELECT.
  SELECT … INTO Work Area
DATA wa LIKE customers.
SELECT * FROM customers INTO wa.
  WRITE: / wa-id, wa-name, wa-city.
ENDSELECT.
Table TRBAT
     SELECT … FROM …
TABLES trbat.
SELECT * FROM trbat .
     WRITE: / trbat-function.
ENDSELECT.
     SELECT Statement : No Data Found

1. Transform open SQL to DB SQL and return result set
into result set work area (If no data found in DB table)
  DB Interface
   SELECT * FROM trbat.        SELECT * FROM trbat;
    …
   ENDSELECT.
                                        sy-subrc > 0


2. Go to statement after ENDSELECT

 ABAP Processor
  SELECT * FROM trbat.
   …
  ENDSELECT.
      SELECT … FROM …
TABLES trbat.
SELECT * FROM trbat .
      WRITE: / trbat-function.
ENDSELECT.
IF sy-subrc <> 0.
 WRITE: / ‘No data found!!!’.
ENDIF.
   SELECT Multiple Records
TABLES customers.
SELECT * FROM customers.
  WRITE: / customers-id, customers-name,
             customers-city.
ENDSELECT.
IF sy-subrc <> 0.
  WRITE: / ‘No Data Found’.
ENDIF.
               Exercise I




               customers-name   customers-city
customers-id
SELECT with WHERE Clause
   Loop Processing with Restriction
TABLES customers.
SELECT * FROM customers
 WHERE city = ‘Bangkok’.
    WRITE: / customers-id, customers-name.
ENDSELECT.
IF sy-subrc <> 0.
  WRITE / ‘no data’.
ENDIF.
 Loop Processing with Restriction
TABLES spfli.
SELECT * FROM spfli
  WHERE cityfrom = ‘FRANKFURT’.
    WRITE: / spfli-carrid, spfli-cityto.
ENDSELECT.
IF sy-subrc <> 0.
  WRITE / ‘no data’.
ENDIF.
          Select With Range
TABLES sflight.
SELECT * FROM sflight
 WHERE price BETWEEN 100 AND 1000.
  WRITE: / sflight-carrid, sflight-connid,
             sflight-price.
ENDSELECT.
      SELECT … With IN List
TABLES sflight.
SELECT * FROM sflight
 WHERE price IN ( 100, 1000 ).
   WRITE: / sflight-carrid, sflight-connid,
             sflight-price.
ENDSELECT.
     SELECT … With Template
TABLES customers.
SELECT * FROM customers
  WHERE name LIKE ‘_r%’.
 WRITE: / customers-id,customers-name.
ENDSELECT.
Select Single Record
        Select Single Record
TABLES customers.
SELECT SINGLE *
  FROM customers
     WHERE id = 1.
IF sy-subrc = 0.
  WRITE: / customers-id, customers-name,
            customers-city, customers-discount.
ELSE.
   WRITE: / ‘Data not found’.
ENDIF.
Select Column List
     bkpf-belnr bkpf-gjahr

   Select * : Example




SELECT *
      bkpf-belnr bkpf-gjahr

Select Column : Using Structure
     SELECT …* FROM …
TABLES customers.
SELECT * FROM customers.
 WRITE: / customers-id, customers-name,
           customers-city.
ENDSELECT.
IF sy-subrc <> 0.
 WRITE: / ‘No data found’.
ENDIF.
customers-id customers-name customers-city

      Reading Selected Column
   DATA: BEGIN OF wa,              1
         id   LIKE customers-id,
         name LIKE customers-name,
         city LIKE customers-city,
         END OF wa.

   SELECT id name city           2
     INTO wa
      FROM customers.
     WRITE: / wa-id, wa-name , wa-city.
   ENDSELECT.
   IF sy-subrc <> 0.
      WRITE / ‘No Data found’.
   ENDIF.
               Exercise I

               ห้ ามใช้ SELECT *




                customers-name     customers-city
customers-id
ABAP : Inner Join
Flight Data Model
Flight Data Model
                        Tables Join
Question: Select carrid, connid and cityto from spfli
         and fldate,price from sflight where carrid = ‘LH’

spfli-carrid   spfli-connid sflight-fldate spfli-cityto sflight-price


                                                     ้
เงื่อนไข : ให้ แสดงข้ อมูลเฉพาะสายการบิน ‘LH’ เท่ านัน
           Open SQL – Inner Join
TABLES: spfli,sflight.
SELECT spfli~carrid spfli~connid sflight~fldate spfli~cityto sflight~price
 INTO (spfli-carrid, spfli-connid, sflight-fldate, spfli-cityto, sflight-price)
     FROM spfli INNER JOIN sflight
        ON spfli~carrid = sflight~carrid AND
               spfli~connid = sflight~connid
          WHERE spfli~carrid = ‘LH’.
  WRITE: / spfli-carrid, spfli-connid, sflight-fldate,
         spfli-cityto, sflight-price.
ENDSELECT.
        Open SQL – Inner Join
TABLES: A,B.               A-a B-b B-c
SELECT A~a B~b B~c
  INTO (A-a,B-b,B-c)
     FROM A INNER JOIN B
        ON A~b = B~b.              Table : B
 WRITE: / A-a,B-b,B-c.
                                         b     c
ENDSELECT.
             Table : A                   b1    c1
                a          b             b2    c2
               a1          b1            b3    c3
               a2          b2
      SELECT INNER JOIN Working Steps

1. Transform open SQL to DB SQL and return result set
into result set work area
                                  SELECT A.a, B.b, B.c
   DB Interface
   SELECT A~a B~b B~c
                                   FROM A,B
    ….                              WHERE A.b = B.b;
   FROM A INNER JOIN B
    …
   ENDSELECT.                                  sy-subrc = 0


2. Loop with data in result set and transfer each record to
work area in memory space
 ABAP Processor
   SELECT A~a B~b B~c           Tables Structure in Memory
    …                           Space
   ENDSELECT.
                  Open SQL – Inner Join
                 Table : A                    Table : B
Database
                     a             b              b             c
 Server
                     a1            b1             b1            c1
                     a2            b2             b2            c2
                                                  b3            c3

Application Server        Single Result Table(Result set)   1

             2
  Select …                   A~a        B~b       B~c
     inner join..             a1         b1        c1
  Endselect.                  a2         b2        c2
    Open SQL – Alias Table Name
TABLES: spfli,sflight.
SELECT a~carrid a~connid b~fldate a~cityto b~price
 INTO (spfli-carrid, spfli-connid, sflight-fldate,
        spfli-cityto, sflight-price)
  FROM spfli AS a INNER JOIN sflight AS b
    ON a~carrid = b~carrid and
         a~connid = b~connid
      WHERE a~carrid = ‘LH’.
 WRITE: / spfli-carrid, spfli-connid, sflight-fldate, spfli-cityto,
          sflight-price.
ENDSELECT.
Exercise : Sale Document
                                         Document Number
                                           (VBAK-VBELN)
                                           ‘0000004970’




VBAK-VBELN VBAK-ERDAT VBAK-KUNNR VBAP-MATNR VBAP-NETWR
  Open SQL – Inner Join > 2 Tables
                                     Table : C
TABLES: A,B,C.         A-a B-c C-y
SELECT A~a B~c C~y                        x       y
  INTO (A-a,B-c,C-y)                      …       ...
     FROM A INNER JOIN B
       ON A~b = B~b                  Table : B
        INNER JOIN C
                                         b       c
         ON C~x = B~c.
 WRITE: / A-a,B-c,C-y.
                                         …       ...
ENDSELECT.                               …       ...
            Table : A                    …       …
                a           b
                …           …
Flight Data Model
SFLIGHT-CARRID SFLIGHT-CONNID SFLIGHT-FLDATE SBOOK-BOOKID SBOOK-CUSTOMID SCUSTOM-NAME SBOOK-LUGGWEIGHT




        Open SQL – Inner Join > 2 Tables
   REPORT ZINNERJOIN02 NO STANDARD PAGE HEADING.
   TABLES: sflight,sbook,scustom.
   SELECT a~carrid a~connid a~fldate
           b~bookid b~customid c~name b~luggweight
    INTO (sflight-carrid,sflight-connid,sflight-fldate,
         sbook-bookid,sbook-customid,scustom-name,sbook-luggweight)
      FROM sflight AS a INNER JOIN sbook AS b
        ON a~carrid = b~carrid AND
           a~connid = b~connid AND
           a~fldate = b~fldate
        INNER JOIN scustom AS c
          ON c~id = b~customid.
     WRITE: / sflight-carrid,sflight-connid,sflight-fldate,
               sbook-bookid,sbook-customid,scustom-name,sbook-luggweight.
   ENDSELECT.
        Exercise : Sale Document



Document Number
 (VBAK-VBELN)
       =
  ‘0000004970’




        VBAK-VBELN VBAK-ERDAT KNA1-NAME1 VBAP-MATNR VBAP-NETWR
Flight Data Model
               Flight Information : Inner Join
SFLIGHT-CARRID SCARR-CARRNAME SFLIGHT-CONNID SFLIGHT-FLDATE SBOOK-BOOKID SBOOK-CUSTOMID SCUSTOM-NAME SBOOK-LUGGWEIGHT
Internal Table
  Data Objects : Internal Table
Memory Space
    Variable                 Structure


Constants           <Field-symbols>
                                         Internal Table


 Tables Structure
Structure
          INTERNAL TABLE
    wa (Structure)
          id      name     city
     ‘00000000’


Internal Table                             Header Line
    tab (Internal Table)
          id      name     city
     ‘00000000’




                            Table Bodies
             Structure
DATA:    BEGIN OF wa,
         id   LIKE customers-id,
         name LIKE customers-name,
         city LIKE customers-city,
         END OF wa.
wa-id = 1.
wa-name = ‘John’.
wa-city = ‘Bangkok’.
WRITE: / wa-id, wa-name.
    INTERNAL TABLE
DATA: BEGIN OF tab OCCURS 10,
      id   LIKE customers-id,
      name LIKE customers-name,
      city LIKE customers-city,
      END OF tab.
     INTERNAL TABLE
DATA: BEGIN OF tab OCCURS 0,
      id   LIKE customers-id,
      name LIKE customers-name,
      city LIKE customers-city,
      END OF tab.
  USING ABAP DICTIONARY STRUCTURE

DATA: BEGIN OF tab OCCURS 0.
      INCLUDE STRUCTURE customers.
DATA END OF tab.
        INTERNAL TABLE USING LIKE

DATA tab LIKE customers OCCURS 0 WITH HEADER LINE.


                                           Header Line
    tab (Internal Table)
           id      name          city
      ‘00000000’

                          8 KB

                            Table Bodies
         Append And Read Data
DATA tab LIKE customers OCCURS 0 WITH HEADER LINE.
tab-id = 1.
tab-name = ‘John’.
tab-city = ‘Bangkok’.
APPEND tab.
tab-id = 2.
tab-name = ‘Peter’.
tab-city = ‘London’.
APPEND tab.
LOOP AT tab.
  WRITE: / tab-id, tab-name, tab-city.
ENDLOOP.
  Reading Data From Internal Table
DATA tab LIKE customers OCCURS 0 WITH HEADER LINE.
SELECT * FROM customers INTO TABLE tab.
IF sy-subrc = 0.
  LOOP AT tab.
   WRITE: / tab-id, tab-name,tab-city.
 ENDLOOP.
ELSE.
   WRITE: / ‘No Data’.
ENDIF.
Access Database Without Internal Table
Access Database Using Internal Table
     BKPF-BELNR BKPF-GJAHR


Access Database Using Internal Table
SELECT <Column>… ENDSELECT
 Dialog WP                    Local Memory
                                Memory Space
    TaskHandler
                                WA Structure

                                 3 | David
    ABAP Processor

                          2    List buffer
    DYNPRO Processor
                                00000001 John
                                00000002 Peter
                                00000003 David
     DB Interface

             Result Set

                  1

     Database
SELECT …INTO TABLE …
Dialog WP                    Local Memory
                              Memory Space
   TaskHandler
                                                  2
   ABAP Processor                Internal Table


                         1
   DYNPRO Processor           List buffer


    DB Interface

            Result Set




    Database
       customers-id      customers-name


Reading Data From Internal Table
                                    1
DATA: BEGIN OF tab OCCURS 0,
      id     LIKE customers-id,
      name   LIKE customers-name,
      END OF tab.

                                                2
SELECT id name FROM customers INTO TABLE tab.

IF sy-subrc = 0.

  LOOP AT tab.                  3

   WRITE: / tab-id, tab-name.
  ENDLOOP.
ELSE.
   WRITE: / ‘No Data’.
ENDIF.
Exercise I : Change


   Using Internal Table
    SORTING INTERNAL TABLE (SORT)

DATA tab LIKE customers OCCURS 0 WITH HEADER LINE.
…
SORT tab BY name.
SORT tab BY name ASCENDING
            city DESCENDING.
      INTERNAL TABLE PROCESSING
...
LOOP AT tab.
 WRITE: / tab-d, tab-name.
ENDLOOP.

LOOP AT tab WHERE city = ‘Bangkok’.
 WRITE: / tab-id, tab-name.
ENDLOOP.
LOOP AT tab FROM 1 TO 10.
 WRITE: / sy-tabix ,tab-id, tab-name.
ENDLOOP.      Record Pointer
      Internal Table Template Condition
DATA tab LIKE customers OCCURS 0 WITH HEADER LINE.
...
LOOP AT tab WHERE name CP ‘+r*’.
...
            Reading Single Record
DATA tab LIKE customers OCCURS 0 WITH HEADER LINE.
...
SORT tab BY name city.
READ TABLE tab
     WITH KEY name = ‘John’
                   city    = ‘Bangkok’
             BINARY SEARCH.
IF sy-subrc = 0.
    WRITE: / tab-id, tab-name, tab-city, tab-telephone.
ENDIF.
 Reading Single Record using Index
...
READ TABLE tab INDEX 3.
IF sy-subrc = 0.
    WRITE: / tab-id, tab-name.
ENDIF.
  DELETING Data in INTERNAL TABLE
DATA tab LIKE sflight OCCURS 0 WITH HEADER LINE.


         CLEAR tab.
         REFRESH tab.
         FREE tab.
    SPFLI-CARRID   SCARR-CARRNAME     SPFLI-CONNID



      SELECT … INNER JOIN
TABLES: scarr,spfli.
SELECT spfli~carrid scarr~carrname spfli~connid
 INTO (spfli-carrid, scarr-carrname, spfli~connid)
   FROM spfli INNER JOIN scarr
      ON spfli~carrid = scarr~carrid.
 WRITE: / spfli-carrid, scarr-carrname , spfli~connid.
ENDSELECT.
    SPFLI-CARRID   SCARR-CARRNAME    SPFLI-CONNID



   Inner Join using Internal Table
DATA: BEGIN OF tab OCCURS 0,
      carrid    LIKE spfli-carrid,
      carrname LIKE scarr-carrname,
      connid    LIKE spfli-connid,
      END OF tab.
SELECT spfli~carrid scarr~carrname spfli~connid
  INTO TABLE tab
   FROM spfli INNER JOIN scarr
      ON spfli~carrid = scarr~carrid.
…
LOOP AT tab.
  WRITE: / tab-carrid,tab-carrname,tab-connid.
ENDLOOP.
Exercise : Using Internal Table
                                         Document Number
                                          (VBAK-VBELN)
                                                =
                                           ‘0000004970’




VBAK-VBELN VBAK-ERDAT VBAK-KUNNR VBAP-MATNR VBAP-NETWR
Event-driven Programming
Application Driven Programming
 REPORT ztest.
 DATA: today TYPE D.
 today = ‘19991231’.
 today = today + 1.
 WRITE: / today.
Event-Driven Programming
 DATA tmp TYPE i.
 AT LINE-SELECTION.
   WRITE: / ‘This is ’.
   WRITE: ‘Detail List’.
 START-OF-SELECTION.
   WRITE: / ‘This is ’.
   WRITE: / ‘Basic List’.
            Events
   START-OF-SELECTION.
   AT LINE-SELECTION.
   INITIALIZATION.
   AT SELECTION-SCREEN.
AT LINE-SELECTION Event
   (Drill-down Report)
        SAP System : Dialog Processing
                                                       SAP GUI
                                                                                                                              Report zpsm1.
                                                                                                                              Tables customers.
                                                  Request
                                                                               List                                           Select single * from
                                                                 Generate Screen(List)                                         customers where id = 1.
                                                       1             11                                                       Write: / customers-name.
Application Server                       Send Request

Store request to queue
            3                                  Dispatcher
                             Send List        2        Search for free WP                              SAP Buffer
                               10
      Request                                         Check Program in Program Buffer                                                      8
                                                                                                             Program
       Queue Send request to WP                                  6                                                                      Execute ABAP
                         4                                                                                                              statement
                                                                     Roll in                                 …
                                D            D              D          5   …          B
                                                                                                               User Context
                                                                                                                   Area
                                                            Roll out                                          ..
                                         9                  12                               7
                                         SQL Request                                      Load&Generate Program
Database Server
                                                                                             Report zpsm1.
                                                                                             Tables customers.
                              customers                                        D010S         Select single * from
                                                                                                 customers where id = 1.
                                                                                             Write: / customers-name.
Dialog Work Process Architecture
   Dialog Work Process               Local Memory
                                        User Context
         TaskHandler

                                        Memory Space
        ABAP Processor


       DYNPRO Processor
                                        List Buffer


          DB Interface
                 Result Set Memory




                  Server

                    Database Server
                Dialog Processing : Roll Out
                                                       SAP GUI
                                                                                                                           Report zpsm1.
                                                                                                                           Tables customers.
                                                  Request
                                                                               List                                        Select single * from
                                                                 Generate Screen(List)                                      customers where id = 1.
                                                       1             11                                                    Write: / customers-name.
Application Server                       Send Request

Store request to queue
            3                                  Dispatcher
                             Send List        2        Search for free WP                              SAP Buffer
                               10
      Request                                         Check Program in Program Buffer                                                   8
                                                                                                             Program
       Queue Send request to WP                                  6                                                                   Execute ABAP
                         4                                                                                                           statement
                                                                     Roll in                                 …
                                D            D              D          5   …          B                                 User
                                                                                                                ..     Context
                                                            Roll out                                                     Area
                                         9                  12                               7
                                         SQL Request                                      Load&Generate Program
Database Server
                                                                                             Report zpsm1.
                                                                                             Tables customers.
                              customers                                        D010S         Select single * from
                                                                                                 customers where id = 1.
                                                                                             Write: / customers-name.
           AT LINE-SELECTION
START-OF-SELECTION.
 WRITE: ‘Basic List’.
AT LINE-SELECTION.
 WRITE: ‘Detail List’.
                         Double
     WRITE, ULINE         Click

      (Basic list)
         AT LINE-SELECTION


1. Double Click                2. Choose Button




                  3. Hotspot
 Navigating Between Lists

                   Exit                         Detail list 20

ABAP Editor



                              Detail list 2


                                                          Cancel
                   Detail list 1

      Basic list                              Back
Runtime Error : Detail List > 20
    Detail List and SY-LSIND
                                         Detail list : 2
START-OF-SELECTION.                       SY-LSIND = 2
 WRITE: ‘Basic List’.
AT LINE-SELECTION.
  CASE sy-lsind.
                                         Detail list : 1
    WHEN 1.                               SY-LSIND = 1
      WRITE: ‘Detail List :’,sy-lsind.
    WHEN 2.
      WRITE: ‘Detail List :’,sy-lsind.
  ENDCASE.                                Basic list
            At Line Selection
TABLES customers.
START-OF-SELECTION.
  SELECT * FROM customers.
     WRITE: / customers-name .
  ENDSELECT.
AT LINE-SELECTION.
   WRITE: ‘You Choose :’ , customers-name.
  At Line Selection(Hide Statement)
TABLES customers.                              List Buffer
START-OF-SELECTION.                            John
  SELECT * FROM customers.                     Peter
                                               David
      WRITE: / customers-name.
      HIDE customers-name.
  ENDSELECT.                               HIDE area of list level 1
AT LINE-SELECTION.                         line Field name        Value
   WRITE: ‘You Choose :’,customers-name.   1
                                           2
                                                 customers-name
                                                 customers-name
                                                                   John
                                                                   Peter
                                           3    customers-name    David
                         Hide Area in List
Application Server
                     Dialog WP                     Local Memory
                                                     Memory Space
                        TaskHandler
                                                      Customers Structure

                                                       3 | David | ....
                      ABAP Processor

                                                     List buffer
                      DYNPRO Processor                  Basic List
                                                         John
                                                         Peter       HIDE area of list level 1
                                                                     line Field name             Value
                        DB Interface                     David       1    customers-name         John
                                                                     2    customers-name         Peter
                               Result Set Memory                     3    customers-name         David




 Database Server
                      Database
    At Line Selection(Hide Statement)
                                      Detail List
    Basic List
     John                                 You choose : Peter
     Peter                                                               5
     David
                                                                  At Line-selection
        1
SY-LILLI = 2
                                                                              4
                   HIDE area of list level 1           Customers Structure
               2
                   line Field name          Value      3 | Peter | ....
                   1     customers-name      John
                   2     customers-name      Peter
                                                        3
                   3    customers-name      David
   At Line Selection(Hide Statement)
TABLES customers.                             List Buffer
START-OF-SELECTION.                            00000001 John
                                               00000002 Peter
  SELECT * FROM customers.                     00000003 David
    WRITE: / customers-id,customers-name.
    HIDE: customers-id,customers-name.
  ENDSELECT.                              HIDE area of list level 1
                                          line Field name       Value
AT LINE-SELECTION.                        1     customers-id    00000001
                                          1     customers-name   John
   WRITE: ‘You Choose :’ , customers-id,  2      customers-id   00000002
                                          2     customers-name    Peter
          customers-name.                 …
    At Line Selection(Hide Statement)
    Basic List                            Detail List
                                          You choose : 00000002 Peter
     00000001 John
     00000002 Peter                                                               5
     00000003 David

                                                                           At Line-selection
        1
SY-LILLI = 2
                                                                                       4
                      HIDE area of list level 1                 Customers Structure
               2
                      line Field name           Value            2 | Peter | ....
                      …     …                     …
                      2     customers-id         00000002
                      2     customers-name        Peter          3
                      3    customers-id          00000003
                      …
                                                                          ZATLINE4



                          At Line Selection
TABLES: spfli,sflight.                                        Basic List (SPFLI)
START-OF-SELECTION.
  SELECT * FROM spfli.
     WRITE: / spfli-carrid, spfli-connid, spfli-cityto.
     HIDE: spfli-carrid, spfli-connid.
  ENDSELECT.
AT LINE-SELECTION.
   SELECT * FROM sflight WHERE carrid = spfli-carrid          Detail List (SFLIGHT)
                                 AND connid = spfli-connid.
    WRITE: / spfli-carrid, spfli-connid,sflight-fldate.
   ENDSELECT.
Exercise : Flight Information
         Basic List
              SCARR




                      Drill-down Level 1
                                  SPFLI
                                      Good Program
DATA: BEGIN OF tab_spfli OCCURS 0,                 AT LINE-SELECTION.
      carrid LIKE spfli-carrid,                     CASE sy-lsind.
      connid LIKE spfli-connid,                      WHEN 1.
      cityto LIKE spfli-cityto,                        SELECT carrid connid fldate
      END OF tab_spfli.                                 INTO TABLE tab_sflight
DATA: BEGIN OF tab_sflight OCCURS 0,                      FROM sflight
      carrid LIKE sflight-carrid,                           WHERE carrid = tab_spfli-carrid AND
      connid LIKE sflight-connid,                                  connid = tab_spfli-connid.
      fldate LIKE sflight-fldate,                      LOOP AT tab_sflight.
      END OF tab_sflight.                               WRITE: / tab_sflight-carrid,tab_sflight-connid,
                                                                    tab_sflight-fldate.
START-OF-SELECTION.                                    ENDLOOP.
 SELECT carrid connid cityto                        ENDCASE.
    FROM spfli
      INTO TABLE tab_spfli.
 IF sy-subrc = 0.
   LOOP AT tab_spfli.
     WRITE: / tab_spfli-carrid,tab_spfli-connid,
               tab_spfli-cityto.
     HIDE: tab_spfli-carrid,tab_spfli-connid.
   ENDLOOP.
 ELSE.
   WRITE: / 'No data found'.
 ENDIF.
Exercise : Sale Document
   Basic List
         VBAK




                   Drill-down Level 1
                                VBAP
Selection Screen
           Selection Screen
   PARAMETERS Statement
   SELECT-OPTIONS Statement
PARAMETERS
                  PARAMETERS
PARAMETERS: tmp1(10) TYPE c,
            tmp2(10) TYPE c LOWER CASE,
            tmp3 LIKE sy-datum DEFAULT sy-datum,
            tmp4 TYPE d DEFAULT '19991231',
            tmp5 TYPE i,
            tmp6 TYPE p DECIMALS 2,
            tmp7(5) TYPE n,
            airline1(3),
            airline2 LIKE spfli-carrid.
DATA id LIKE customers-id.

START-OF-SELECTION.
 WRITE: / tmp1,tmp2,tmp3,tmp4,tmp5,tmp6,tmp7,airline1,airline2,id.
     PARAMETERS Example
TABLES customers.
PARAMETERS pid LIKE customers-id.
START-OF-SELECTION.
  SELECT SINGLE *
     FROM customers
        WHERE id = pid.
  IF sy-subrc = 0.
    WRITE: / customers-name.
  ELSE.
    WRITE: / ‘No data found’.
  ENDIF.
                       Selection-Text
   By default , the System displays the name of the selection as text on
    the Selection Screen
   You Should use the Text element/Selection texts function to store a
    text line for each Selection Criterion.
 PARAMETERS : Check box

PARAMETERS tmp AS CHECKBOX DEFAULT ‘X’.
PARAMETERS : Radio Button
PARAMETERS: test1 RADIOBUTTON GROUP grp1,
            test2 RADIOBUTTON GROUP grp1.
RADIOBUTTON : SAP ECC 6.0
 Required Field with PARAMETERS

PARAMETERS tmp LIKE sy-datum OBLIGATORY.
ABAP Exercise

				
DOCUMENT INFO
Shared By:
Categories:
Tags:
Stats:
views:0
posted:1/24/2013
language:Unknown
pages:168