Showing posts with label Internal Tables. Show all posts
Showing posts with label Internal Tables. Show all posts

Thursday, May 2, 2013

0 Nested Structures in ABAP

Nested Structures in ABAP :


Structure with in the another structure is called nested   structure
We can declare the nested structure in 3 ways
Way1:
*&---------------------------------------------------------------------*
*& Report  ZEBRA7
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT  ZEBRA7 NO STANDARD PAGE HEADING.
*// declare the first structure
data  : begin of stru1,
       stuno 
type i,
      stuname 
type  char10,
     
end of stru1.
*// declare the second structure
data : begin of siva ,
     sivaco 
type char12,
    sivaemp 
type char12.
include structure stru1.
data : end of siva.
*// assign the values to the structure
stru1-stuno = 
239.
stru1-stuname = 
'ram'.
siva-sivaco = 
'local'.
siva-sivaemp = 
'234'.
*//output
write: stru1-stuno, siva-sivaco, siva-sivaemp.
Output:
239   local     234
Way 2:
*&---------------------------------------------------------------------*
*& Report  ZEBRA7
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT  ZEBRA7 NO STANDARD PAGE HEADING.
*// declare
data  : begin of stru1,
       stuno 
type i,
      stuname 
type  char10,
     
end of stru1.

data : begin of emp ,
       empno 
type i,
      empname 
type char12,
      lc_stuct 
like stru1,
 
end of emp.
*// assign
emp-empno = 
100.
emp-empname = 
'REDDY'.
emp-lc_stuct-stuno = 
20.
emp-lc_stuct-stuname = 
'ram'.


*//output
write: emp-empno, emp-empname, emp-lc_stuct-stuno, emp-lc_stuct-stuname.
Output:
100     REDDY     20    ram
Way 3:
*&---------------------------------------------------------------------*
*& Report  ZEBRA7
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT  ZEBRA7 NO STANDARD PAGE HEADING.
*// declare structure
data : begin of emp ,
       empno 
type i,
      empname 
type char12,
      
begin of stru1,
       stuno 
type i,
      stuname 
type  char10,
       
end of stru1,
 
end of emp.
*// assign values to structure
emp-empno         = 
100.
emp-empname       = 
'REDDY'.
emp-stru1-stuno   = 
20.
emp-stru1-stuname = 
'ram'.


*//output
write: emp-empno, emp-empname, emp-stru1-stuno, emp-stru1-stuname.
Output: 100     REDDY     20    ram

Monday, April 15, 2013

0 How to copy one internal table to another in ABAP


Copying an Internal Table into another Internal Table:
If you want to copy the entire contents of one internal table into another in one execution, use the MOVE statement or the assignment operator (=) as follows:
Syntax
MOVE <itab1> TO <itab2>.
This statement is equivalent to:
<itab2> = <itab1>.
Note : above syntax  works only if ITAB2 is Empty
For example if ITAB2 having records at that time we have to use APPEND LINES OF
Syntax :
APPEND LINES OF itab1 TO itab2.

This method of appending lines of one table to another is about 3 to 4 times faster than appending them line by line in a loop. After the APPEND statement, the system field SY-TABIX
contains the index of the last line appended. When you append several lines to a sorted table, you must respect the unique key (if defined), and not violate the sort order. Otherwise, a runtime error will occur.

 

SAP-ABAP Copyright © 2011 - |- Template created by Vishnu - |- Powered by Blogger Templates