List Processing in ABAP

5,665
-1

Published on

Second part of series shared on http://sapdocs.info/sap/abap/documents-for-sap-abap-beginners/

Published in: Business
1 Comment
2 Likes
Statistics
Notes
No Downloads
Views
Total Views
5,665
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
747
Comments
1
Likes
2
Embeds 0
No embeds

No notes for slide

List Processing in ABAP

  1. 1. ABAP Chapter 2 <ul><li>Report Statement </li></ul><ul><li>Write & Format Statement </li></ul><ul><li>Flow Control in ABAP </li></ul><ul><li>Manipulating Character Data </li></ul><ul><li>Report Driven : Page Report (List Header) </li></ul>
  2. 2. List Processing Report Header Report Listing (Body)
  3. 3. Report Statement * Syntax REPORT < report name > [NO STANDARD PAGE HEADING] [LINE-SIZE no of columns ] [LINE-COUNT no of lines [( no of footer )]]. REPORT ztest1 NO STANDARD PAGE HEADING. REPORT ztest LINE-SIZE 132 LINE-COUNT 65(2). sy-linsz
  4. 4. Text Element : Title&Headers <ul><li>Text Element </li></ul><ul><ul><li>Title and Headers </li></ul></ul><ul><ul><li>List Header </li></ul></ul><ul><ul><li>Column Header </li></ul></ul>This is test program by Prapoj Column Column #1 #2 Report ztest. Write ‘Hello World’.
  5. 5. Creating Lists <ul><li>ABAP statement that create list </li></ul><ul><ul><li>WRITE </li></ul></ul><ul><ul><li>SKIP </li></ul></ul><ul><ul><li>ULINE </li></ul></ul><ul><li>The complete report list will appears automatically at the end of the processing block </li></ul>
  6. 6. List Buffer <ul><ul><ul><ul><li>Dialog WP </li></ul></ul></ul></ul>TaskHandler Dynpro Processor ABAP Processor Local Memory Memory Space DB Interface List Buffer WRITE,SKIP,ULINE
  7. 7. WRITE Statement <ul><ul><li>* Write data </li></ul></ul><ul><ul><li>WRITE ‘Hello World’. </li></ul></ul><ul><ul><li>WRITE: ‘OK’, ‘Test data’. </li></ul></ul><ul><ul><li>WRITE: /15(10) ‘ABCDEFGHIJKLMNOPQ’. </li></ul></ul><ul><ul><li>WRITE / 20 ‘Test data’. </li></ul></ul>
  8. 8. Breaking to a New Line * Write data WRITE: / ‘First Line’, ‘Data 1’, / ‘Second Line’, ‘Data 2’, /(20) ‘Third Line’, ‘Data 3’, /35 ‘Fourth Line’, ‘Data 4’. sy-colno
  9. 9. Text Symbol <ul><li>Text Element </li></ul><ul><ul><li>Text Symbols </li></ul></ul><ul><ul><li>Text Symbol Text </li></ul></ul>Text 2 Text 1 Report ztest. Write: Text-001, Text-002. 001 002
  10. 10. Text Symbol write: / Text-001. write: / Text-001. write: / Text-001. write: / Text-001. write: / Text-001.
  11. 11. Column Position DATA colno type I value 10. write: /5 ‘Hello’, at colno ‘World’. write: at /colno ‘OK’.
  12. 12. Options of the WRITE Statement * Write Syntax WRITE var [NO-ZERO] [NO-SIGN] [NO-GROUPING] [NO-GAP] [DECIMALS no of decimals ]
  13. 13. Suppressing Blanks(NO-ZERO) <ul><ul><li>* No Zero </li></ul></ul><ul><ul><li>DATA: number(10) TYPE N VALUE 23. </li></ul></ul><ul><ul><li>WRITE: number, number NO-ZERO. </li></ul></ul>
  14. 14. Suppressing Number(+ / -) Sign <ul><ul><li>* No Sign </li></ul></ul><ul><ul><li>DATA: v_integer TYPE I VALUE -1. </li></ul></ul><ul><ul><li>WRITE: v_integer, v_integer NO-SIGN. </li></ul></ul>
  15. 15. NO-GROUPING <ul><ul><li>* No grouping </li></ul></ul><ul><ul><li>DATA: v_integer TYPE I VALUE 120000. </li></ul></ul><ul><ul><li>WRITE: v_integer, v_integer NO-GROUPING. </li></ul></ul>
  16. 16. NO-GAP <ul><ul><li>* No gap </li></ul></ul><ul><ul><li>WRITE: ‘Hello’ NO-GAP, ‘World’. </li></ul></ul>
  17. 17. DECIMALS <ul><ul><li>* Decimals </li></ul></ul><ul><ul><li>DATA: v_pack TYPE P DECIMALS 4 </li></ul></ul><ul><ul><li>VALUE ‘1234.5678’. </li></ul></ul><ul><ul><li>WRITE: v_pack, v_pack DECIMALS 2. </li></ul></ul>
  18. 18. Formatting Options * Format options of WRITE statement * LEFT-JUSTIFIED for Integer data * RIGHT-JUSTIFIED for Character data * CENTERED Data tmp1(20) value ‘test’. WRITE: tmp1 CENTERED. test
  19. 19. Inserting Blank Lines(SKIP) <ul><ul><li>* Skip Statement </li></ul></ul><ul><ul><li>SKIP. </li></ul></ul><ul><ul><li>WRITE: ‘Hello World’ , sy-linno . </li></ul></ul><ul><ul><li>SKIP. </li></ul></ul><ul><ul><li>WRITE: ‘Test 1’. </li></ul></ul><ul><ul><li>SKIP 5. </li></ul></ul><ul><ul><li>WRITE: ‘Test 2’. </li></ul></ul><ul><ul><li>SKIP TO LINE 20. </li></ul></ul><ul><ul><li>WRITE ‘This is line 20’. </li></ul></ul>
  20. 20. Inserting Horizontal Lines(ULINE) <ul><ul><li>* Uline </li></ul></ul><ul><ul><li>WRITE: ‘Hello World’. </li></ul></ul><ul><ul><li>WRITE: / 5(35) sy-uline, sy-vline. </li></ul></ul><ul><ul><li>ULINE /5(35). </li></ul></ul><ul><ul><li>ULINE. </li></ul></ul><ul><ul><li>WRITE: / ‘This is an u nderline’. </li></ul></ul><ul><ul><li>ULINE /(18). </li></ul></ul>
  21. 21. Frame <ul><ul><li>uline: /(45). </li></ul></ul><ul><ul><li>write: /1 sy-vline, 'Column #1', </li></ul></ul><ul><ul><li>15 sy-vline, 'Column #2', </li></ul></ul><ul><ul><li>30 sy-vline, 'Column #3', </li></ul></ul><ul><ul><li>45 sy-vline. </li></ul></ul><ul><ul><li>uline: /(45). </li></ul></ul>
  22. 22. Exercise I sy-datum sy-uzeit
  23. 23. FORMAT Statement FORMAT [INTENSIFIED] [INTENSIFIED OFF] [COLOR < color >] [COLOR OFF] [HOTSPOT ON] [HOTSPOT OFF] [RESET]
  24. 24. FORMAT Statement <ul><ul><li>FORMAT COLOR 1. </li></ul></ul><ul><ul><li>WRITE: / ‘Hello World’, ‘Test’ COLOR 7. </li></ul></ul><ul><ul><li>FORMAT COLOR OFF. </li></ul></ul>
  25. 25. FORMAT COLOR FORMAT COLOR col_heading. “color 1 FORMAT COLOR col_normal. “color 2 FORMAT COLOR col_total. “color 3 FORMAT COLOR col_key. “color 4 FORMAT COLOR col_positive. “color 5 FORMAT COLOR col_negative. “color 6 FORMAT COLOR col_group. “color 7 FORMAT COLOR col_background. “color off
  26. 26. Exercise I
  27. 27. Include Program <ul><li>You can create a program with program type include program in the program attribute </li></ul><ul><li>Include program do not have to have an introductory statement </li></ul><ul><li>During the syntax check and during program generation by the ABAP compiler, the INCLUDE statement is replaced by the source text of the defined include program </li></ul>Data tmp(10). Data tmp1 type i. Data tmp2 type p. Data tmp3. Include Program : ZINCLUDE1 <ul><ul><li>REPORT ztest1. </li></ul></ul><ul><ul><li>INCLUDE zinclude1. </li></ul></ul><ul><ul><li>… </li></ul></ul><ul><ul><li>REPORT ztest2. </li></ul></ul><ul><ul><li>INCLUDE zinclude1. </li></ul></ul><ul><ul><li>… </li></ul></ul>
  28. 28. Symbols and Icons <ul><ul><li>* Display Icon or Symbol in List </li></ul></ul><ul><ul><li>INCLUDE < LIST >. </li></ul></ul><ul><ul><li>WRITE: / ‘Phone : ’ , SYM_PHONE AS SYMBOL. </li></ul></ul><ul><ul><li>WRITE: / ‘Alarm :’, ICON_ALARM AS ICON. </li></ul></ul><ul><ul><li>WRITE: / ‘Green Light :’, </li></ul></ul><ul><ul><li>ICON_GREEN_LIGHT AS ICON HOTSPOT . </li></ul></ul><ul><ul><li>FORMAT HOTSPOT ON. </li></ul></ul><ul><ul><li>WRITE: / ‘Hello ABAP’, ’Hi!’. </li></ul></ul><ul><ul><li>FORMAT HOTSPOT OFF. </li></ul></ul>
  29. 29. Flow Control in ABAP
  30. 30. Flow Control in ABAP <ul><li>Branching ==> IF, CASE. </li></ul><ul><li>Looping ==> DO, WHILE. </li></ul>
  31. 31. IF Statement <ul><ul><li>IF < Condition >. </li></ul></ul><ul><ul><li><Statement Block> </li></ul></ul><ul><ul><li>ELSEIF < Condition >. </li></ul></ul><ul><ul><li><Statement Block> </li></ul></ul><ul><ul><li>ELSEIF < Condition >. </li></ul></ul><ul><ul><li><Statement Block> </li></ul></ul><ul><ul><li>ELSE. </li></ul></ul><ul><ul><li><Statement Block> </li></ul></ul><ul><ul><li>ENDIF. </li></ul></ul>
  32. 32. IF Statement <ul><ul><li>IF sy-mandt = ‘1 00 ’. </li></ul></ul><ul><ul><li>WRITE: / ‘This is Production Client’. </li></ul></ul><ul><ul><li>ELSEIF sy-mandt = ‘ 800 ’. </li></ul></ul><ul><ul><li>WRITE: / ‘This is Development Client’. </li></ul></ul><ul><ul><li>ELSE. </li></ul></ul><ul><ul><li>WRITE: / ‘This is Test Client’. </li></ul></ul><ul><ul><li>ENDIF. </li></ul></ul>
  33. 33. CASE Statement <ul><ul><li>CASE < field >. </li></ul></ul><ul><ul><li>WHEN < value1 >. </li></ul></ul><ul><ul><li><Statement Block> </li></ul></ul><ul><ul><li>WHEN < value2 >. </li></ul></ul><ul><ul><li><Statement Block> </li></ul></ul><ul><ul><li>... </li></ul></ul><ul><ul><li>WHEN OTHERS. </li></ul></ul><ul><ul><li><Statement Block> </li></ul></ul><ul><ul><li>ENDCASE. </li></ul></ul>
  34. 34. CASE Statement CASE sy- mandt . WHEN ‘100’ . WRITE: / ‘ Production Client ’. WHEN ‘800’ . WRITE: / ‘Development Client’ . WHEN OTHERS. WRITE: / ‘ Test Client ’. ENDCASE.
  35. 35. DO Statement <ul><ul><li>DO. </li></ul></ul><ul><ul><li>WRITE sy-index. </li></ul></ul><ul><ul><li>IF sy-index = 3. </li></ul></ul><ul><ul><li>EXIT. </li></ul></ul><ul><ul><li>ENDIF. </li></ul></ul><ul><ul><li>WRITE: sy-index. </li></ul></ul><ul><ul><li>ENDDO. </li></ul></ul>
  36. 36. CONTINUE Statement <ul><ul><li>DO 5 TIMES. </li></ul></ul><ul><ul><li>IF sy-index = 3. </li></ul></ul><ul><ul><li>CONTINUE. </li></ul></ul><ul><ul><li>ENDIF. </li></ul></ul><ul><ul><li>WRITE: sy-index. </li></ul></ul><ul><ul><li>ENDDO. </li></ul></ul>
  37. 37. CHECK Statement <ul><ul><li>DO 4 TIMES. </li></ul></ul><ul><ul><li>CHECK sy-index BETWEEN 2 AND 3. </li></ul></ul><ul><ul><li>WRITE: sy-index. </li></ul></ul><ul><ul><li>ENDDO. </li></ul></ul>
  38. 38. WHILE Statement <ul><ul><li>DATA: count TYPE I value 1. </li></ul></ul><ul><ul><li>WHILE count <> 4. </li></ul></ul><ul><ul><li>WRITE: sy-index. </li></ul></ul><ul><ul><li>count = count + 1. </li></ul></ul><ul><ul><li>ENDWHILE. </li></ul></ul>
  39. 39. Logical Expressions <ul><ul><li>>,GT </li></ul></ul><ul><ul><li><,LT </li></ul></ul><ul><ul><li>>=, =>, GE </li></ul></ul><ul><ul><li><=, =<, LE </li></ul></ul><ul><ul><li>=, EQ </li></ul></ul><ul><ul><li><>, ><, NE </li></ul></ul><ul><ul><li>BETWEEN value1 AND value2 </li></ul></ul><ul><ul><li>IS INITIAL </li></ul></ul>
  40. 40. Arithmetic Operators <ul><ul><li>+ , - , * , / , ** </li></ul></ul><ul><ul><li>DIV </li></ul></ul><ul><ul><li>MOD </li></ul></ul><ul><ul><ul><ul><li>Example : </li></ul></ul></ul></ul><ul><ul><ul><ul><li>9 / 2 = 4.5 </li></ul></ul></ul></ul><ul><ul><ul><ul><li>9 DIV 2 = 4.0 </li></ul></ul></ul></ul><ul><ul><ul><ul><li>9 MOD 2 = 1 </li></ul></ul></ul></ul><ul><ul><ul><ul><li>SQRT( 2 ) = 1.41 </li></ul></ul></ul></ul><ul><ul><ul><ul><li>2 ** 4 = 16 </li></ul></ul></ul></ul>
  41. 41. Character String Operator <ul><ul><li>if ‘AABB’ co ‘AB’. </li></ul></ul><ul><ul><li>if ‘ABCD’ co ‘ABC’. </li></ul></ul><ul><ul><li>if ‘AXCZ’ ca ‘AB’. </li></ul></ul><ul><ul><li>if ‘ABCD’ ca ‘XYZ’. </li></ul></ul><ul><ul><li>if ‘ABCD’ cp ‘+B*’. </li></ul></ul>T F T F T
  42. 42. Manipulating Character Data
  43. 43. Manipulating Character Data * Substrings with offsets DATA tmp(10) VALUE ‘ABCDEFGHIJ’. DATA tmp1(2). WRITE: tmp+3 (7) , tmp+1(4), tmp+0(8), tmp+7(3). MOVE tmp+4(2) TO tmp1. DEFGHIJ BCDE ABCDEFGH HIJ
  44. 44. SHIFT Statement * SHIFT Statement DATA tmp(5) VALUE ‘12345’. SHIFT tmp. SHIFT tmp BY 2 PLACE S . SHIFT tmp BY 2 PLACE S CIRCULAR. SHIFT tmp UP TO ‘3’. SHIFT tmp UP TO ‘3’ RIGHT. SHIFT tmp UP TO ‘3’ RIGHT CIRCULAR. SHIFT tmp RIGHT DELETING TRA I LING SPACE. SHIFT tmp LEFT DELETING LEADING SPACE. 2345_ 345__ 34512 __123 345__ 45123
  45. 45. SHIFT <ul><ul><li>* Shift </li></ul></ul><ul><ul><li>DATA name(30) VALUE ‘Alexander Bill Charles’. </li></ul></ul><ul><ul><li>SHIFT name UP TO ‘Bill’. </li></ul></ul><ul><ul><li>WRITE: / name. </li></ul></ul>Bill Charles
  46. 46. SEARCH ( Non Case-sensitive ) <ul><ul><li>* Search </li></ul></ul><ul><ul><li>DATA tmp(5) VALUE ‘ABCDE’. </li></ul></ul><ul><ul><li>SEARCH tmp FOR ‘C’. </li></ul></ul><ul><ul><li>DATA tmp1(10) VALUE ‘Till Bill’. </li></ul></ul><ul><ul><li>SEARCH tmp1 FOR ‘Bill’. </li></ul></ul><ul><ul><li>IF SY-SUBRC = 0. </li></ul></ul><ul><ul><li>WRITE: / SY-FDPOS. </li></ul></ul><ul><ul><li>ENDIF. </li></ul></ul>
  47. 47. TRANSLATE * Translate DATA tmp(5) VALUE ‘abc ‘. TRANSLATE tmp TO UPPER CASE. TRANSLATE tmp TO LOWER CASE. TRANSLATE tmp USING ‘ 0’. TRANSLATE tmp USING ‘ 0aA’.
  48. 48. REPLACE * Replace DATA tmp(20) VALUE ‘I was a boy’. REPLACE ‘was’ WITH ‘am’ INTO tmp. IF sy-subrc = 0. write ‘Replace OK’. ELSE. write ‘Cannot find data to be replaced’. ENDIF.
  49. 49. Removing Spaces(CONDENSE) * Condense DATA: tmp(20) VALUE ‘I am a boy’. CONDENSE tmp. CONDENSE tmp NO-GAPS. I am a boy Iamaboy
  50. 50. Concatenation String(CONCATENATE) * Concatenate DATA: tmp1(2) VALUE ‘AB’, tmp2(3) VALUE ‘CDE’, tmp3(10). CONCATENATE tmp1 tmp2 INTO tmp3. CONCATENATE tmp1 tmp2 INTO tmp3 SEPARATED BY ‘ ‘. ABCDE AB CDE
  51. 51. Split * Split DATA: name(30) value ‘David, John, Peter’, one(10), two(10), three(30). split name at ‘,’ into one two three.
  52. 52. Working with Date Variables * Date DATA today TYPE D. today = sy-datum. WRITE: today, ‘ Year :’ , today+0(4), ‘ Month :’, today+4(2), ‘ Day :’ , today+6(2). sy-datum+0(4)
  53. 53. WRITE … TO … DATA: today TYPE D, tmp(10). today = sy-datum. tmp = today. WRITE tmp. WRITE today TO tmp. WRITE tmp. CLEAR today. WRITE today NO-ZERO TO tmp. WRITE tmp.
  54. 54. Invalid Date <ul><ul><li>DATA: today TYPE D. </li></ul></ul><ul><ul><li>today = ‘2006 13 21’. </li></ul></ul><ul><ul><li>today = today + 0. </li></ul></ul><ul><ul><li>if today is initial. </li></ul></ul><ul><ul><li>write: / ‘invalid date’. </li></ul></ul><ul><ul><li>else. </li></ul></ul><ul><ul><li>write: / today. </li></ul></ul><ul><ul><li>endif. </li></ul></ul>
  55. 55. Built-in Functions <ul><li>ABAP provides a lot of built-in functions </li></ul><ul><li>A Built-in function calculates a return value from an argument </li></ul><ul><ul><li>abs = Absolute value of argument </li></ul></ul><ul><ul><li>sign = +/- sign of argument </li></ul></ul><ul><ul><li>sqrt = Square root </li></ul></ul><ul><ul><li>strlen = Number of characters in arg </li></ul></ul><ul><ul><li>xstrlen = Number of bytes in arg </li></ul></ul>
  56. 56. STRLEN Built-in Function <ul><ul><li>DATA: tmp(20) VALUE ‘Test String’, </li></ul></ul><ul><ul><li>count TYPE I. </li></ul></ul><ul><ul><li>count = strlen( tmp ). </li></ul></ul><ul><ul><li>WRITE count. </li></ul></ul>
  57. 57. STRLEN Built-in Function Example <ul><ul><li>DATA: tmp(20) VALUE ‘ xx a x ’, </li></ul></ul><ul><ul><li>cn tlen TYPE I. </li></ul></ul><ul><ul><li>cntlen = strlen( tmp ). </li></ul></ul><ul><ul><li>cntlen = cntlen – 2. </li></ul></ul><ul><ul><li>if tmp+cntlen(1) = ‘a’. “cntlen >= 0 </li></ul></ul><ul><ul><li>write: / ‘OK’. </li></ul></ul><ul><ul><li>endif. </li></ul></ul>
  58. 58. WRITE ‘ <ul><ul><li>*If we need the word like this I’m a boy </li></ul></ul><ul><ul><li>WRITE: ‘ I’’m a boy’ . </li></ul></ul>
  59. 59. Exercise <ul><li>Create program to display current month in text for example October </li></ul>
  60. 60. Report Driven : Page Report
  61. 61. Application Driven Programming <ul><ul><li>REPORT ztest. </li></ul></ul><ul><ul><li>DATA: today TYPE D. </li></ul></ul><ul><ul><li>today = ‘20061321’. </li></ul></ul><ul><ul><li>today = today + 0. </li></ul></ul><ul><ul><li>IF today IS INITIAL. </li></ul></ul><ul><ul><li>WRITE: / ‘invalid date’. </li></ul></ul><ul><ul><li>ELSE. </li></ul></ul><ul><ul><li>WRITE: / today. </li></ul></ul><ul><ul><li>ENDIF. </li></ul></ul>
  62. 62. Event Driven Programming <ul><ul><li>REPORT ztest. </li></ul></ul><ul><ul><li>DATA today TYPE D. </li></ul></ul><ul><ul><li>TOP-OF-PAGE. </li></ul></ul><ul><ul><li>< ABAP statement > </li></ul></ul><ul><ul><li>END-OF-PAGE. </li></ul></ul><ul><ul><li>< ABAP statement > </li></ul></ul><ul><ul><li>START-OF-SELECTION. </li></ul></ul><ul><ul><li>< ABAP statement > </li></ul></ul>
  63. 63. Report Driven List Header REPORT ztest NO STANDARD PAGE HEADING. TOP-OF-PAGE. FORMAT COLOR 1. WRITE: /5 ‘User Name’, 25 ‘Program Name’. ULINE. START-OF-SELECTION. WRITE: /5 sy-uname, 25 sy-repid.
  64. 64. Report Driven Page Footer REPORT ztest no standard page heading LINE-COUNT 10(2). TOP-OF-PAGE. FORMAT COLOR 1. WRITE: / ‘ Page : ’, sy-pagno . ULINE. END-OF-PAGE. ULINE. WRITE: / ‘To be continue on n ext p age…’ . START-OF-SELECTION. DO 20 TIMES. WRITE: / sy-index. ENDDO.
  65. 65. TOP-OF-PAGE REPORT ztest no standard page heading. TOP-OF-PAGE. FORMAT COLOR 1. WRITE: / 'Report Header'. ULINE. START-OF-SELECTION. DO 100 TIMES. WRITE: / sy-index. ENDDO.
  66. 66. ABAP Program Structure <ul><li>Report ztest. </li></ul><ul><li>*Data declaration </li></ul><ul><li>data ... </li></ul><ul><li>data begin of ... </li></ul><ul><li>*Top-of-Page event </li></ul><ul><li>top-of-page. </li></ul><ul><li>*End-of-Page event </li></ul><ul><li>end-of-page. </li></ul><ul><li>*Start-of-selection </li></ul><ul><li>Start-of-selection. </li></ul>
  67. 67. ABAP Practice
  68. 68. Exercise II sy-datum sy-uzeit sy-repid sy-uname
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×