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

0 Constants in SAP ABAP

Constants in SAP ABAP :


Constants refers to the fixed values that do not change during the execution of a program. A "constant" is a number, character, or character string that can be used as a value in a program.
A constant can be

a number, like 58 or 1.9

a character, like S or @

a character string, like "this is a SAP"


Using "CONSTANTS" keyword we can declare Constants

Syntax :

CONSTANTS : <Name> TYPE <Data Type> VALUE <' number/character/character string'>


EX :

 *&---------------------------------------------------------------------*
*& Report  ZCONSTANTS
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT  zconstants NO STANDARD PAGE HEADING.

* Declaration Of Constants. *
* Constants: - We can n't change value at run time. *
* Keyword for Constant is 'CONSTANT'. *

** Program Starts *

* Declaring and Assigning values to Constants. *

CONSTANTS : name    TYPE char10  VALUE 'vishnu'.
CONSTANTS : number  TYPE i      VALUE 10.

* Displaying output. *

WRITE : name,
        number.



Friday, April 26, 2013

0 Difference between TYPE and LIKE in ABAP


Difference between TYPE and LIKE in SAP ABAP :


TYPE : It will allocate memory during execution (object type).
       TYPE will improve performance.
       It is used when userdefined object link with SAP system data type.
       TYPE refers to the user defined data types
       TYPE,assign datatype directly to the data object while declaring.
     
LIKE :  Tt will allocate memory immediatly.
        It is when data object link with the other data object.
        LIKE refers to existing data type of data object
        LIKE,you assign the datatype of another object to the declaring data object. The datatype is referenced indirectly.

Thursday, April 25, 2013

0 Formatting options for all Data Types in ABAP


Formatting options for all Data Types in ABAP :



             Option
      Function
LEFT- JUSTIFIED
Output is left-justified.
CENTERED
Output is centered.
RIGHT- JUSTIFIED
Output is right-justified.
UNDER <g>

Output starts directly under field <g>.
NO-GAP
The blank after field <f> is omitted.
USING EDIT MASK <m>
Specifies format template<m>
USING NO EDIT MASK
Deactivates a format template specified in the ABAPDictionary.
NO-ZERO
If a field contains only zeros,these are replaced by blanks. For type C and Nfields, leading zeros are   replaced automatically.
NO-SIGN
The leading sign is not displayed on the screen.
DECIMALS <d>
<d> defines the number of digits after the decimal point.
EXPONENT <e>
In type F fields, the exponent is defined in <e>.
ROUND <r>

Type P fields are multiplied by 10**(-r) and then rounded
CURRENCY <c>
Format according to currency <c> in table TCURX.
UNIT <u>
The number of decimal places is fixed according to unit <u> specified in table T006 for type P fields.



0 Variables in SAP ABAP

Variables in  SAP ABAP :



Variables are named data objects, you can declare variables statically using declarative statements, or dynamically while a program is running. They allow you to store changeable data under a particular name within the memory area of a program.


DATA is a keyword which is used to declare the variables in SAP ABAP

Syntax :
DATA < Variable Name> Type <Data Type>
                           (Or)
DATA <Variable Name> Like <Data Type>
Ex: DATA V1 Type I.
       DATA V2 Like I.

Type is abap keyword for reference
Fields :
         Elementary
        DATA vendor_code(10) TYPE C.
         Reference to Non Elementary
        TYPES vend_code(10)  TYPE C,
        DATA  vendor_code TYPE vend_code.
         Reference to existing fields
        DATA : vend_code(10) TYPE C,
                                   vendor_code LIKE Vend_code.



0 First ABAP program


First ABAP program:

    ABAP Editor(se38) : used for Writing Report programs..etc
  Log on to sap
  Go to SE38 transaction code

Enter the program  name 
Note : Program Name starts with Z (or) Y

click on create
Then one popup window will trigger 
Enter the Title and select the type as executable program
Click on save then it will ask the package name
Enter the package name as $TMP
Click on save
Then it will open the ABAP Editor  like this
Where we can develop our code
*&---------------------------------------------------------------------*
*& Report  YDEMO01
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT  YDEMO01 .
* Declare Variables
data var1 type i.
data var2 type c.
data var3 type string.
data var4 type dats.
data var5 type tims.
data var6 type p decimals 2.
data var7 type n.
data var8 type char10.

* Assigning values to those variables
var1 = 
100.
var2 = 
'A'.
var3 = 
'dfsmngbsmnghbmngb'.
var4 = 
'20110909'.
var5 = 
'095612'.
var6 = 
'100.25'.
var7 = 
1.
var8 = 
'CAREER IT'.

* Display Output
write var1.
write var2.
write var3.
write var4.
write var5.
write var6.
write var7.
write var8.


Note :  After completion  of code to save press Ctrl + S
            To check syntax errors Ctrl + F2
            To Activate program    Ctrl + F3
            To Execute your object F8
Output :












 

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