Programming Tips:-
Field-Symbols:- field symbols are the place holder or symbolic name of the field , they don't physically reserve the space for the field , but point to it's contents. Field symbols can point to any data objects. and we use field symbols to make program more dynamic.
Example:-
Field-symbols f1 type c.
data text(4) type c value 'ABAP'.
assign text to f1 .
write f1 .
------------------------------------------------
Pass by reference:
A way of passing data from actual parameters to formal parameters. When you pass by reference, no local data object is specified for the actual parameter, but the procedure receives a reference to the actual parameter during call and works with the actual parameter itself. A change to the formal parameter in the subroutine also changes the value of the actual parameter.
Pass by value:
a local object with the same data type as the corresponding actual parameter is created in the subroutine and filled with its values. A change to the formal parameter in the subroutine does not change the value of the actual parameter. The actual parameter also retains its original value even after the subroutine has ended.
REPORT zkartest.
PARAMETER: test(2) TYPE c.
PERFORM change_test1 USING test.
WRITE:/ test.
PERFORM change_test2 USING test.
WRITE:/ test.
&---------------------------------------------------------------------
*& Form change_test1
&---------------------------------------------------------------------
* Value of test will change here. Pass by REFERENCE
----------------------------------------------------------------------
* -->P_TEST text
----------------------------------------------------------------------
FORM change_test1 USING p_test.
p_test = p_test + 2.
WRITE:/ p_test.
ENDFORM. "change_test1
&---------------------------------------------------------------------
*& Form change_test2
&---------------------------------------------------------------------
* Value of test will change here but only in the subroutine. Pass by VALUE
----------------------------------------------------------------------
* -->VALUE(P_TEST) text
----------------------------------------------------------------------
FORM change_test2 USING value(p_test).
p_test = p_test + 2.
WRITE:/ p_test.
ENDFORM. "change_test2
-------------------------======================---------------------------------------------------
Performance Tunning:
1.Use Primary Keys in Where Condition,
2. Instead of select * we have to give particular fields.
3.Inside Loop and Endloop remove loop at Itab.
4. If in select query where clause is very long create Secondary Index.
5. Use Binary search in read statement, (
Syntax:
SORT ITAB.
READ TABLE ITAB WITH KEY LIFNR = WA-LIFNR BINARY SEARCH.
Instead of Nested select or inner Join use FOR ALL ENTRIES.
6. Instead of MOVE-CORRESPONDING use INDIVIDUAL move statement.
dont' use- MOVE CORRESPONDING FROM IS_LFA1 TO IS_LFA1_1.
Use- MOVE IS_LFA1-LIFNR TO IS_LFA1_1-LIFNR
MOVE IS_LFA1-NAME1 TO IS_LFA1_1-NAME1
7. use Free, Refresh, Clear Statements,
8. Don't use inner Joins,
9. Remove nested loops,
10. Don't use corresponding fields of,
11. delete duplicate entries, ......
-----------------------------------------------------------------------------------------
Events:
TOP-OF-PAGE (TO PROVIDE LIST HEADING ( OUTPUT HEADINGS)
INITIALIZATION ( TO INITIALISE THE SELECTION SCREEN ELEMENTS )
AT SELECTION-SCREEN ( SELECTION SCREEN VALIDATIONS )
START-OF-SELECTION. ( NORMALLY WE WRITE THE REPORT LOGIC HERE )
GET .
GET LATE.
END-OF-SELECTION. (event is triggered in type 1 programs once the logical database has finished reading all data and before the list processor is started. )
END-OF-PAGE (TO PROVIDE FOOTER I.E., PAGE NUMBERS)
is the order
Initialization, At selection-screen, Start-of-selection, end-of-selection, top-of-page, end-of-page, At line-selection, At user-command, At PF, Get, At New, At LAST, AT END, AT FIRST. are the events..
-------------------------------------------------------------------------------------------------------------------
DATA: BEGIN OF LINE,
LAND(3) TYPE C,
NAME(10) TYPE C,
AGE TYPE I,
WEIGHT TYPE P DECIMALS 2,
END OF LINE.
DATA ITAB LIKE STANDARD TABLE OF LINE WITH NON-UNIQUE KEY LAND.
LINE-LAND = 'G'. LINE-NAME = 'Hans'.
LINE-AGE = 20. LINE-WEIGHT = '80.00'.
APPEND LINE TO ITAB.
LINE-LAND = 'USA'. LINE-NAME = 'Nancy'.
LINE-AGE = 35. LINE-WEIGHT = '45.00'.
APPEND LINE TO ITAB.
LINE-LAND = 'USA'. LINE-NAME = 'Howard'.
LINE-AGE = 40. LINE-WEIGHT = '95.00'.
APPEND LINE TO ITAB.
LINE-LAND = 'GB'. LINE-NAME = 'Jenny'.
LINE-AGE = 18. LINE-WEIGHT = '50.00'.
APPEND LINE TO ITAB.
LINE-LAND = 'F'. LINE-NAME = 'Michele'.
LINE-AGE = 30. LINE-WEIGHT = '60.00'.
APPEND LINE TO ITAB.
LINE-LAND = 'G'. LINE-NAME = 'Karl'.
LINE-AGE = 60. LINE-WEIGHT = '75.00'.
APPEND LINE TO ITAB.
PERFORM LOOP_AT_ITAB.
SORT ITAB.
PERFORM LOOP_AT_ITAB.
SORT ITAB.
PERFORM LOOP_AT_ITAB.
SORT ITAB STABLE.
PERFORM LOOP_AT_ITAB.
SORT ITAB DESCENDING BY LAND WEIGHT ASCENDING.
PERFORM LOOP_AT_ITAB.
FORM LOOP_AT_ITAB.
LOOP AT ITAB INTO LINE.
WRITE: / LINE-LAND, LINE-NAME, LINE-AGE, LINE-WEIGHT.
ENDLOOP.
SKIP.
ENDFORM.
The output is:G Hans 20 80.00
USA Nancy 35 45.00
USA Howard 40 95.00
GB Jenny 18 50.00
F Michele 30 60.00
G Karl 60 75.00
F Michele 30 60.00
G Hans 20 80.00
G Karl 60 75.00
GB Jenny 18 50.00
USA Howard 40 95.00
USA Nancy 35 45.00
F Michele 30 60.00
G Karl 60 75.00
G Hans 20 80.00
GB Jenny 18 50.00
USA Howard 40 95.00
USA Nancy 35 45.00
F Michele 30 60.00
G Karl 60 75.00
G Hans 20 80.00
GB Jenny 18 50.00
USA Howard 40 95.00
USA Nancy 35 45.00
USA Nancy 35 45.00
USA Howard 40 95.00
GB Jenny 18 50.00
G Karl 60 75.00
G Hans 20 80.00
F Michele 30 60.00The program sorts a standard table with one key field four times. First, the table is sorted twice by the key field (LAND) without the STABLE addition. The sort is unstable. The sequence of the second and third lines changes. The same sort is then performed using the STABLE addition. The sort is stable. The lines remain in the same sequence. Then, it is sorted by a sort key defined as LAND and WEIGHT. The general sort order is defined as descending, but for WEIGHT it is defined as ascending.
Field-Symbols:- field symbols are the place holder or symbolic name of the field , they don't physically reserve the space for the field , but point to it's contents. Field symbols can point to any data objects. and we use field symbols to make program more dynamic.
Example:-
Field-symbols f1
data text(4) type c value 'ABAP'.
assign text to
Pass by reference:
A way of passing data from actual parameters to formal parameters. When you pass by reference, no local data object is specified for the actual parameter, but the procedure receives a reference to the actual parameter during call and works with the actual parameter itself. A change to the formal parameter in the subroutine also changes the value of the actual parameter.
a local object with the same data type as the corresponding actual parameter is created in the subroutine and filled with its values. A change to the formal parameter in the subroutine does not change the value of the actual parameter. The actual parameter also retains its original value even after the subroutine has ended.
PARAMETER: test(2) TYPE c.
PERFORM change_test1 USING test.
WRITE:/ test.
PERFORM change_test2 USING test.
WRITE:/ test.
&---------------------------------------------------------------------
*& Form change_test1
&---------------------------------------------------------------------
* Value of test will change here. Pass by REFERENCE
----------------------------------------------------------------------
* -->P_TEST text
----------------------------------------------------------------------
FORM change_test1 USING p_test.
p_test = p_test + 2.
WRITE:/ p_test.
ENDFORM. "change_test1
&---------------------------------------------------------------------
*& Form change_test2
&---------------------------------------------------------------------
* Value of test will change here but only in the subroutine. Pass by VALUE
----------------------------------------------------------------------
* -->VALUE(P_TEST) text
----------------------------------------------------------------------
FORM change_test2 USING value(p_test).
p_test = p_test + 2.
WRITE:/ p_test.
ENDFORM. "change_test2
in a script, can we run a script form with out a main program?
No,it is not possible.
No,it is not possible.
2. Instead of select * we have to give particular fields.
3.Inside Loop and Endloop remove loop at Itab.
4. If in select query where clause is very long create Secondary Index.
Instead of Nested select or inner Join use FOR ALL ENTRIES.
-----------------------------------------------------------------------------------------
Events:
TOP-OF-PAGE (TO PROVIDE LIST HEADING ( OUTPUT HEADINGS)
INITIALIZATION ( TO INITIALISE THE SELECTION SCREEN ELEMENTS )
AT SELECTION-SCREEN ( SELECTION SCREEN VALIDATIONS )
START-OF-SELECTION. ( NORMALLY WE WRITE THE REPORT LOGIC HERE )
GET .
GET LATE.
END-OF-SELECTION. (event is triggered in type 1 programs once the logical database has finished reading all data and before the list processor is started. )
END-OF-PAGE (TO PROVIDE FOOTER I.E., PAGE NUMBERS)
is the order
Initialization, At selection-screen, Start-of-selection, end-of-selection, top-of-page, end-of-page, At line-selection, At user-command, At PF, Get, At New, At LAST, AT END, AT FIRST. are the events..
-------------------------------------------------------------------------------------------------------------------
DATA: BEGIN OF LINE,
LAND(3) TYPE C,
NAME(10) TYPE C,
AGE TYPE I,
WEIGHT TYPE P DECIMALS 2,
END OF LINE.
DATA ITAB LIKE STANDARD TABLE OF LINE WITH NON-UNIQUE KEY LAND.
LINE-LAND = 'G'. LINE-NAME = 'Hans'.
LINE-AGE = 20. LINE-WEIGHT = '80.00'.
APPEND LINE TO ITAB.
LINE-LAND = 'USA'. LINE-NAME = 'Nancy'.
LINE-AGE = 35. LINE-WEIGHT = '45.00'.
APPEND LINE TO ITAB.
LINE-LAND = 'USA'. LINE-NAME = 'Howard'.
LINE-AGE = 40. LINE-WEIGHT = '95.00'.
APPEND LINE TO ITAB.
LINE-LAND = 'GB'. LINE-NAME = 'Jenny'.
LINE-AGE = 18. LINE-WEIGHT = '50.00'.
APPEND LINE TO ITAB.
LINE-LAND = 'F'. LINE-NAME = 'Michele'.
LINE-AGE = 30. LINE-WEIGHT = '60.00'.
APPEND LINE TO ITAB.
LINE-LAND = 'G'. LINE-NAME = 'Karl'.
LINE-AGE = 60. LINE-WEIGHT = '75.00'.
APPEND LINE TO ITAB.
PERFORM LOOP_AT_ITAB.
SORT ITAB.
PERFORM LOOP_AT_ITAB.
SORT ITAB.
PERFORM LOOP_AT_ITAB.
SORT ITAB STABLE.
PERFORM LOOP_AT_ITAB.
SORT ITAB DESCENDING BY LAND WEIGHT ASCENDING.
PERFORM LOOP_AT_ITAB.
FORM LOOP_AT_ITAB.
LOOP AT ITAB INTO LINE.
WRITE: / LINE-LAND, LINE-NAME, LINE-AGE, LINE-WEIGHT.
ENDLOOP.
SKIP.
ENDFORM.
The output is:G Hans 20 80.00
USA Nancy 35 45.00
USA Howard 40 95.00
GB Jenny 18 50.00
F Michele 30 60.00
G Karl 60 75.00
F Michele 30 60.00
G Hans 20 80.00
G Karl 60 75.00
GB Jenny 18 50.00
USA Howard 40 95.00
USA Nancy 35 45.00
F Michele 30 60.00
G Karl 60 75.00
G Hans 20 80.00
GB Jenny 18 50.00
USA Howard 40 95.00
USA Nancy 35 45.00
F Michele 30 60.00
G Karl 60 75.00
G Hans 20 80.00
GB Jenny 18 50.00
USA Howard 40 95.00
USA Nancy 35 45.00
USA Nancy 35 45.00
USA Howard 40 95.00
GB Jenny 18 50.00
G Karl 60 75.00
G Hans 20 80.00
F Michele 30 60.00The program sorts a standard table with one key field four times. First, the table is sorted twice by the key field (LAND) without the STABLE addition. The sort is unstable. The sequence of the second and third lines changes. The same sort is then performed using the STABLE addition. The sort is stable. The lines remain in the same sequence. Then, it is sorted by a sort key defined as LAND and WEIGHT. The general sort order is defined as descending, but for WEIGHT it is defined as ascending.
No comments:
Post a Comment