Showing posts with label ABAP. Show all posts
Showing posts with label ABAP. Show all posts

Thursday, 16 February 2012


ABAP INTERNAL TABLE


Attributes of Internal table:
* Line Type : Data type is normally structure.
* Key :  

                         -Standard Key (Default key)
u                         -User defined key.
* Table Type : It determines how ABAP will access individual table entries.
                      
Types :   Standard table – Indexed 

                Sorted table – Indexed
                Hashed table


Standard table : 

u
     - Have an internal linear index. 
u     - Access uses a linear search.
u     - Access either by key or index.
u     - Always non-unique.
u     - Response time for key access is proportional to number of entries in table
u     - This can filled quickly….no system checks on uniqueness of entries


Sorted table :

u     - Always saved sorted by key.
    u     - Have internal linear index.
u     -  Access either by key or index.
u     -  Table can be unique or non-unique.
u     - Response time for key access is logarithmically proportional to the no. of entries since binary search is used.

Hashed table :

u     -  No internal linear index.
u     -  Access only using key.
u     -  Response time for access is independent of no. of table entries since system accesses the table using hash algorithm.
u     -  Table key must be unique.



Populating Internal Tables:

For filling data into internal table : 

          - APPEND
          - INSERT
          - MODIFY
          - DELETE
          - MOVE
For fetching data from internal table : 
          - loop at <itab> into <wa>.     " fetch the record and holds in "wa"
            Endloop.
          -  Read.

Wednesday, 15 February 2012

ABAP String Manipulation :  String manipulation is the process of manipulating the values to the required format, using various manipulating commands like:



Concatenate
Split
Shift
Condense
Translate
Convert Text
Overlay
Replace
Search


Concatenate : Combines two or more separate strings into one.

       syntax :  CONCATENATE <c1> ... <cn> INTO <c> [SEPARATED BY <s>].

Ex:  DATA: file_path(5VALUE '/tmp/',
        name(8)     VALUE 'MATERIAL',
        ext(4VALUE '.txt',
        file_name(50).
  CONCATENATE  file_path  name  '_'   sy-datum  '_'   sy-uzeit  ext     INTO file_name.
  Write : 'File Name is :', File_name.

  Out Put:   file_name has value “/tmp/MATERIAL_20060222_064430.txt”.


Split : Split a character string into two or more smaller strings.
       syntax : SPLIT <c> AT <del> INTO <c1> ... <cn>.

Ex:          DATA:  file_name(30TYPE C VALUE 'tmp/MATERIAL.txt'
                directory(10)   TYPE C,
                name(12)         TYPE C,
                delimiter(1)     VALUE '/'.
                SPLIT file_name AT delimiter INTO directory name.
                 Write :  'directory : ' ,  directory .
  Out Put: Now directory contains “tmp” and name contains “MATERIAL.txt”.


Shift : Shift the contents of a field, character by character.
       syntax : SHIFT <c> [BY <n> PLACES] [<LEFT/RIGHT/CIRCULAR>].
Ex:       DATA v_cost(10) TYPE c VALUE ‘345.98-’.

              SHIFT v_cost BY 1 PLACES RIGHT CIRCULAR.    
 Out Put: Now v_cost = “-   345.98”.

Condense : Deletes redundant spaces from a string.
       syntax : CONDENSE <c> [NO-GAPS].
Ex:       DATA var(10TYPE c VALUE ' HELLO '.
            CONDENSE var.
            WRITE : var.  
  Out Put:  Now Var will holds the value "HELLO" by deleting initial and ending Blank Spaces.

Translate : Converts characters into upper or lower case, or uses substitution rules to convert all occurrences of one character to another character.
       syntax :  TRANSLATE <c> TO UPPER CASE/LOWER CASE. 
                      TRANSLATE <c> USING <r>.
Ex:       DATA: letters(20TYPE C VALUE 'abcabcabcXabc',
                        change(15TYPE C VALUE 'aXbaYBabZacZB'.
            TRANSLATE letters USING change.
            WRITE : letters.
 Out Put:  letters now contains 'XaZXaZXaZXXaZ'.

Convert Text : Converts strings into a format that can be sorted alphabetically.
       syntax :  CONVERT TEXT <c> INTO SORTABLE CODE <sc>.

field <c> must be of type C and the field <sc> must be of type X with a minimum size of 16 times the size of <c>. 

Ex:       DATA: Var(5TYPE C VALUE 'Hello',
                         Con_text TYPE xstring.
              CONVERT TEXT var INTO SORTABLE CODE Con_txt.
              WRITE : Con_text.

 Out Put:  Now Con_text will holds the value "342E3C3C420109018F08".

Overlay : Overlays one string with another.

       syntax :   OVERLAY <c1> WITH <c2>.

Ex:       DATA: c1(4VALUE 'ABC',
                         c2(4VALUE 'XVYZ'.
            OVERLAY c1 WITH c2 ONLY 'B'.
            WRITE c1.
 Out Put:  Now C1 holds the value "AVC".

Sunday, 12 February 2012

ABAP Data Types





Difference between Type & Like:
* Type : refers to the user defined data types.
Ex:     TYPES : Var1 TYPE i.
        TYPES : Var2 TYPE Var1.
* LIKE  : refers to existing data type of data object.

Ex:     Data : Var1 TYPE i.
        Data : Var2 Like Var1.
Difference Between F & P Data Type:
Float Data Type :  It cannot be declared in Parameters.
Packed Data  Type :  It can be declared in Parameters.