Wednesday, June 13, 2012

0 Extended program check


Extended program check:
This is used to avoid the unnecessary declarations of the program
Transaction code for the extended program check is SLIN
After completion of program
Go to menu bar
Program -> check -> extend program check
Execute
Double click on error and warnings
Identify the unnecessary declarations 

Monday, June 11, 2012

0 Finding Programs for Transaction


Finding program for the transaction

How to find the program for a transaction if you have the Transaction code?
Scenario:-
When you have the the TCODE and you want to see the underlying coding or the program related to it.

Solution 1:-

Go to transaction SE93 .Type in the transaction code and press display.





Solution 2:-

Go to the TCODE.
In the menu got to system > status



In the Pop-up SAP Data box holds the program details.



Solution 3:-
Goto table TSTC.Enter TCODE and execute.





This is very useful when you have multiple TCODES for which you need to find the programs.

0 FIELD SYMBOLS IN ABAP


Field symbols:
Field symbols are placeholders or symbolic names for other fields. They do not physically reserve space for a field, but point to its contents. A field symbol can point to any data object. The data object to which a field symbol points is assigned to it after it has been declared in the program.
To declare a Field Symbol, use the statement,
FIELD-SYMBOLS <FS> [<type>|STRUCTURE <s> DEFAULT <wa>].
Typing  Field Symbols:
The <type> addition allows you to specify the type of a field symbol.
Syntax:
FIELD-SYMBOLS <FS> <type>
Ex :
*//variable declaration
      DATA: WA(10VALUE '0123456789'.
DATABEGIN OF LINE1,
COL1(
3),
COL2(
2),
COL3(
5),
END OF LINE1.

DATABEGIN OF LINE2,
COL1(
2),
COL2 
LIKE SY-DATUM,
END OF LINE2.
*//Field symbol declaration
FIELD-SYMBOLS: <F1> STRUCTURE LINE1 DEFAULT WA,
<F2> 
STRUCTURE LINE2 DEFAULT WA.
*//Display output      
WRITE: / <F1>-COL1, <F1>-COL2, <F1>-COL3,
/ <F2>-COL1, <F2>-COL2.
Output:
Static Assign:
The name of the data object you want to assign to a field symbol before run time.
Syntax:
           ASSIGN <f>  TO <FS>.
Ex:
*//Field symbol declaration
FIELD-SYMBOLS:  <F1> , <F2> TYPE I.

*//variable declaration
DATA : NUM  TYPE I VALUE 5,
      
TEXT(10TYPE C  VALUE 'HELLO'.
*//Static assign
      
ASSIGN TEXT TO <F1>.
      
ASSIGN NUM TO <F2>.
*//Display output      
      
WRITE: / <F1> , <F2>. Output:

Dynamic  Assign:
The name of the data object you want to assign to a field symbol only at  run time.
Syntax:  ASSIGN (<f>)  TO <FS>.

0 Control Structures In ABAP


control structures :
This are used to control the flow of execution of the program
Controlling the Flow of ABAP/4 Programming:
The flow of an ABAP/4 program can be controlled internally  and externally.
 Internal control is steered  by using some standard  control keywords( IF,CASE, DO,WHILE).
Control structures are 2 types
1.Branching  Control structures(IF,CASE)
2.Looping Control structures(DO,WHILE)
External control is steered by events . Events are generated either from other ABAP/4 programs (system programs or user programs) or from interactive user input (like, for example, using the mouse to click on the screen).
Programming Logical Expressions
 Use logical expressions in conditions statements with key words
 IF, CHECK and WHILE to compare data fields.
         comparisons with all field types
         comparisons  with character strings and numeric strings
Comparisons with all field types:
Use following operators in logical expressions for comparisons
with all field types
         EQ(=)
         NE(<> or ><)
         LT(<)
         LE(<=>)
         GT(>)
         GE(>=)
Example:
              DATA: F type f value '100.00',
              P 
type P value '50.00' Decimals 2,
              
I type I value   '30.00'.
Write 'The following Logical expressions are true'.
     
If F >= P.
    
Write :/ F, '> =', P.
     
Else.
      
write :/ F, '<' P.
    
Endif.
If I EQ P.
Write : / I'EQ',P.
else.
Write: / I'NE',P.
endif.

Programming Branches and Loops
Branching
         Conditional branching using IF
         Conditional branching using CASE
Loops
         Unconditional looping using DO
         Conditional loops using WHILE
          Terminating Loops
Conditional Branching using IF
The IF statement allows you to divert the program flow to a particular statement block, depending on a condition. This statement block consists of all the commands which occur between an IF statement and the next ELSEIF, ELSE, or ENDIF statement.
Syntax
             IF <condition1>.
  <statement block>
ELSEIF <condition2>.
   <statement block>
ELSEIF <condition3>.
   <statement block>
.....
ELSE.
   <statement block>
ENDIF.
Conditional Branching with CASE:
     To execute different statement blocks depending on the contents of particular data fields.
Note: Conditional branching using CASE is shorter form of similar processing with IF.
Syntax
CASE <field>.
   WHEN <value1>.
        <statement block>
   WHEN <value2>.
        <statement block>
   WHEN <value3>.
        <statement block>
   WHEN ...
   ......
   WHEN OTHERS.
        <statement block>
ENDCASE.
EX:
*//variable declaration
Data: text1 value 'x',
           text2 
value 'y',
           text3 
value 'z',
           string 
value 'a'.
CASE string.
When text1.
  
Write: / 'string is',text1.
When text2.
  
Write: / 'string is',text2.
When text3.
  
Write: /'string is',text3.
When others.
  
Write: /'string is not', text1,text2,text3.
Endcase.
OUTPUT: String is not X,Y,X
Unconditional Looping using DO
If you want to process a statement block more than once, you can program a loop with the DO statement as follows:
Syntax
DO [<n> TIMES].
    <statement block>
ENDDO.
Note: Avoid endless loops when working with do statement.If you don’t use the times option, include at least EXIT,STOP or REJECT.
Ex:
        DO.
  
Write:  sy-index.
  
If sy-index = 3.
       
Exit.
  
Endif.
ENDDO.
Output:  u will get the output as 1 2 3

Conditional Loops using WHILE
If you want to process a statement block more than once as long as a condition is true, you can program a loop with the WHILE statement as follows:
Syntax
WHILE <condition> .
       <statement block>
ENDWHILE.
To terminate the processing of a loop, use one of the following keywords.
Keyword                                                   Purpose
CONTINUE                                     Terminating a Loop Pass Unconditionally
CHECK                                           Terminating a Loop Pass Conditionally
EXIT                                                Terminating a Loop Entirely
STOP                                              Terminates the Loop(used only in main program)
Example for Terminating a Loop Pass Unconditionally
To terminate a loop pass immediately without any condition, use the CONTINUE statement as follows:
DO 4 TIMES.
   
IF SY-INDEX = 2.
       
CONTINUE.
   
ENDIF.
   
WRITE SY-INDEX.
ENDDO.
Output: we will get the output as 1 3 4
Note: Here, the system terminates the second loop pass without processing the WRITE statement
Example For Terminating a Loop Pass Conditionally:
To terminate a loop pass conditionally, use the CHECK statement as follows:
Syntax
CHECK <condition>.
DO 4 TIMES.
   
CHECK SY-INDEX BETWEEN 2 and 3.
   
WRITE SY-INDEX.
ENDDO.
Output: 2 3
Here, the system terminates the first and the fourth loop pass without processing the WRITE statement because SY-INDEX does not fall between 2 and 3.
Example For Terminating a Loop Entirely:
To terminate a loop entirely without any condition, use the EXIT statement as follows:
Syntax : EXIT.
Ex: DO 10 TIMES.
    
if sy-index = 4 .
      
exit.
      
ENDIF.
   
WRITE SY-INDEX.
ENDDO.
Output: 1 2 3
Here, the system terminates the entire loop processing in the third loop pass without processing the WRITE statement or the fourth loop pass.
         Comparison statements are IF and CASE.
         Comparison operators like EQ,NE,LT,LE,GT,GE are used
      for comparing all field types.
         Special operators like CO,CN.CA,NA,CS,NS,CP and NP are used
      for comparing strings
         Conditional branching using CASE is shorter form of similar
        processing with IF
         The loop statements are do and while.
         sy-index always contains the counter for the current loop pass. After the loop is finished, its value is reset to the value it had when the loop began. Although you can change sy-index, its value is reset with the next pass of the loop.
         Use the exit, continue, and check statements to modify loop processing.
         exit terminates loop processing and continues execution at the first statement following the loop.
          continue jumps to the end of the loop    immediately
         check exp jumps to the end of the loop if exp is false. When exp is true, check does nothing.
         DON'T use check or continue within a select loop to filter out records. Instead, use the where clause to filter them out.
Object:
Write a  small report using DO loop with EXIT,CHECK and CONTINUE
statement. use SY-INDEX for writing output.
The output should be as follows.
1         3     4   for CONTINUE  statement
2        3            for CHECK statement
1        2           for EXIT      statement    

0 Move ,Compute & Move-Corresponding in ABAP


Move & Compute:
MOVE source TO target.
COMPUTE target = source.
DATA : d1(4),
             d2 TYPE I VALUE 75,
             d3 TYPE I.
    MOVE ‘SAP’ TO d1.
   COMPUTE d3 = d2 + 125.                                                                         
If source & target fields have different type then source is converted in the format of target.
Basic Assignment Operations
Assigning values with Offset specifications
Copying values between components of Field Strings
Basic Assignment Operations
Syntax:    MOVE <f1> TO  <f2>
The MOVE statement transports the contents of the source field <f1>, which can be any data object, to the target field <f2>
The MOVE statement and the assignment operator have the same function. The above statement when written with assignment                                                                                 operator (=) has the form:
f2 = f1.
Example:
DATA: T(10),
           NUMBER TYPE P DECIMALS 1,
            COUNT TYPE P DECIMALS 1.
T  =  1111.
MOVE  ‘ 5.3 ‘  TO  NUMBER.
COUNT  =  NUMBER.
The result of this assignment is that fields T, NUMBER, and COUNT contain the values ‘ 1111 ’, ‘ 5.3 ‘, and ‘ 5.3 ‘.
Assigning values with Offset specifications
You can Specify offsets and lengths for elementary data objects in every ABAP/4 statement.
Syntax:                                                                                                             
MOVE <f1> [+<p1>][(<l1>)] TO <f2> [+<p2>][(<l2>)].
The contents of the section of field <f1>, which begins at the position <p1>+1 and has a length of <l1>, are assigned to field <f2> where they overwrite the section which begins at the position <p2>+1 and has a length of <l2>.
In the MOVE statement, all offset and length specifications can be variables.
Example:
DATA:F1(8) VALUE  ‘ABCDEFGH’,
          F2(8).
DATA:O TYPE I VALUE 2,
L TYPE I VALUE 4.
MOVE  F1  TO  F2.             
Write / F2.
MOVE  F1+O(L)  TO  F2.     
Write / F2.
MOVE  F1  TO  F2 +O(L).   
 Write / F2.
CLEAR F2.
MOVE  F1  TO  F2 +O(L).
 Write / F2.
MOVE  F1+O(L)  TO  F2+O(L).
 Write / F2.
The above example produces the following output:
ABCDEFGH
CDEF
CDABCD
CDEF
Copying values between components of Field Strings
Syntax:
MOVE-CORRESPONDING <STRING1>  TO <STRING2>.
This statement assigns the contents of the components of field string <string1> to those components of field string <string2> which have the same names.
The system executes a MOVE statement for each name pair as follows:
MOVE STRING1- <component> TO STRING2- <component>
 

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