Author: Jatra Riwayanto
Submitted: 01.05.2007
Description:
This tutorial will guide you how to convert old report program to new report program using OOP concept.
In old report we usually used subroutine, but in OOP we have to change it to be method in class. And in OOP there is several obsolate Abap syntax that we cann't use anymore. I hope this small piece of code can help anyone who need to create OOP report program.
First, let we se the complate source code of old report program.
There are three subroutine: get_data, process_data and write_data. And there are constants and global data.
Now let we create local class, name it: lcl_main. In Public section of this class, there are three method: get_data, process_data, write_data and one events: no_data. In Private section we put all constants and global data. In this part, we need make changes for internal table declaration.
Since in OO we cann't create internal table with header line, we have to use work area.
Here definition for lcl_main class.
Error rendering macro 'code': Invalid value specified for parameter 'com.atlassian.confluence.ext.code.render.InvalidValueException'*---------------------------------------------------------------------* * C.L.A.S.S lcl_main D.E.F.I.N.I.T.I.O.N *---------------------------------------------------------------------* CLASS lcl_main DEFINITION. PUBLIC SECTION. METHODS: get_data, process_data, write_data. EVENTS: no_data. PRIVATE SECTION. *---------------------------------- * C.O.N.S.T.A.N.T.S *---------------------------------- constants : tno(4) value 'No', tpernr(8) value 'Pers.No', tcname(23) value 'Name', ttrfst(5) value 'Level', tbtrtl(6) value 'Dept', tbegda(10) value 'Date', tbeguz(7) value 'Time', tawart(4) value 'Type', tatext(23) value 'Description'. *--------------------------------- * L.O.C.A.L D.A.T.A. *--------------------------------- DATA: nomer type i, begin of WA_RESULT, pernr type pa0001-pernr, cname type pa0002-cname, trfst type pa0008-trfst, btrtl type pa0001-btrtl, begda type pa2001-begda, beguz type pa2001-beguz, awart type pa2001-awart, atext type t554t-atext, BEGEN(10), end of WA_RESULT, begin of wa_pa0001, pernr type pa0001-pernr, werks type pa0001-werks, btrtl type pa0001-btrtl, trfst type pa0008-trfst, end of wa_pa0001, begin of wa_pa0002 , pernr type pa0002-pernr, cname type pa0002-cname, end of wa_pa0002, begin of wa_pa2001 , pernr type pa2001-pernr, begda type pa2001-begda, endda type pa2001-endda, awart type pa2001-awart, beguz type P2001-BEGUZ, enduz type P2001-ENDUZ, end of wa_pa2001, wa_t554t type t554t, IT_RESULT like standard table of WA_RESULT, IT_pa0001 like standard table of WA_pa0001, IT_pa0002 like standard table of WA_pa0002, IT_pa2001 like standard table of WA_pa2001, IT_t554t like standard table of WA_t554t. ENDCLASS.
Here the lcl_handler definition.
Error rendering macro 'code': Invalid value specified for parameter 'com.atlassian.confluence.ext.code.render.InvalidValueException'*---------------------------------------------------------------------* * C.L.A.S.S lcl_handler D.E.F.I.N.I.T.I.O.N *---------------------------------------------------------------------* CLASS lcl_handler DEFINITION. PUBLIC SECTION. METHODS handle_event FOR EVENT no_data OF lcl_main. ENDCLASS.
After we created class definition, we need to create class implementation.
lcl_main implementation:
*---------------------------------------------------------------------* * C.L.A.S.S lcl_main I.M.P.L.E.M.E.N.T.A.T.I.O.N *---------------------------------------------------------------------* CLASS lcl_main IMPLEMENTATION. *----------------------------------------------* * METHOD get_data * *----------------------------------------------* METHOD get_data. ENDMETHOD. *----------------------------------------------* * METHOD process_data * *----------------------------------------------* METHOD process_data. ENDMETHOD. *----------------------------------------------* * METHOD write_data * *----------------------------------------------* METHOD write_data. ENDMETHOD. ENDCLASS.
Lets copy source code from subroutine get_data into method get_data with some modification.
In subroutine get_data, when we found no data we just simply give message. But in method get_data, when we found no data we raise event no_data.
Old FORM get_data:
Error rendering macro 'code': Invalid value specified for parameter 'com.atlassian.confluence.ext.code.render.InvalidValueException'*&---------------------------------------------------------------------* *& Form get_data *&---------------------------------------------------------------------* FORM get_data . * get pernr select a~pernr a~werks a~btrtl b~trfst into corresponding fields of table it_pa0001 from pa0001 as a inner join pa0008 as b on a~pernr = b~pernr where a~werks = p_werks and a~btrtl in s_btrtl and a~endda = '99991231' and b~endda = '99991231'. if sy-subrc = 0. * get name select pernr cname into corresponding fields of table it_pa0002 from pa0002 for all entries in it_pa0001 where pernr = it_pa0001-pernr and endda = '99991231'. * get absence select PERNR BEGDA BEGUZ ENDUZ AWART into corresponding fields of table IT_PA2001 from PA2001 for all entries in it_pa0001 where pernr = it_pa0001-pernr and begda in s_ldate and endda in s_ldate AND awart = p_awart. * get absemce text if sy-subrc = 0. select AWART ATEXT into corresponding fields of table IT_T554T from T554T where SPRSL = SY-LANGU and AWART = P_AWART and MOABW in ( select moabw from t001p where werks = p_werks ). sort IT_T554T by AWART. else. message i398(00) with 'No entries exist for this selection !'. exit. endif. else. message i398(00) with 'No entries exist for this selection !'. exit. endif. ENDFORM. " get_data
New Method get_data:
Error rendering macro 'code': Invalid value specified for parameter 'com.atlassian.confluence.ext.code.render.InvalidValueException'METHOD get_data. * get pernr select a~pernr a~werks a~btrtl b~trfst into corresponding fields of table it_pa0001 from pa0001 as a inner join pa0008 as b on a~pernr = b~pernr where a~werks = p_werks and a~btrtl in s_btrtl and a~endda = '99991231' and b~endda = '99991231'. * if itab has no records, raise event IF it_pa0001[] IS INITIAL. RAISE EVENT no_data . ENDIF. * get name select pernr cname into corresponding fields of table it_pa0002 from pa0002 for all entries in it_pa0001 where pernr = it_pa0001-pernr and endda = '99991231'. * get absence select PERNR BEGDA BEGUZ ENDUZ AWART into corresponding fields of table IT_PA2001 from PA2001 for all entries in it_pa0001 where pernr = it_pa0001-pernr and begda in s_ldate and endda in s_ldate AND awart = p_awart. * if itab has no absence records, raise event IF it_pa2001[] IS INITIAL. RAISE EVENT no_data . ENDIF. * get absemce text select AWART ATEXT into corresponding fields of table IT_T554T from T554T where SPRSL = SY-LANGU and AWART = p_AWART and MOABW in ( select moabw from t001p where werks = p_werks ). ENDMETHOD.
After we complete Method get_data, we have to copy subroutine process_data and write_data with some modification too.
Method process_data and write_data:
*----------------------------------------------* * METHOD process_data * *----------------------------------------------* METHOD process_data. clear: IT_RESULT[]. sort IT_T554T by AWART. sort it_pa0001 by pernr. sort it_pa0002 by pernr. sort it_pa2001 by pernr begda. loop at it_pa2001 into wa_pa2001. clear: wa_T554T, wa_RESULT. move-corresponding wa_pa2001 to wa_RESULT. read table it_pa0002 into wa_pa0002 binary search with key pernr = wa_pa2001-pernr. if sy-subrc = 0. move-corresponding wa_pa0002 to wa_RESULT. endif. read table it_pa0001 into wa_pa0001 binary search with key pernr = wa_pa2001-pernr. if sy-subrc = 0. move-corresponding wa_pa0001 to wa_RESULT. endif. *** wa_RESULT-BEGDA = wa_PA2001-BEGDA. case wa_PA2001-AWART. when 'DL'. concatenate wa_PA2001-ENDUZ+0(2) ':' wa_PA2001-ENDUZ+2(2) into wa_RESULT-BEGEN. when 'PC'. concatenate wa_PA2001-BEGUZ+0(2) ':' wa_PA2001-BEGUZ+2(2) into wa_RESULT-BEGEN. when others. wa_RESULT-BEGEN = '-'. endcase. wa_RESULT-AWART = wa_PA2001-AWART. *** read table it_t554t into wa_t554t binary search with key awart = wa_pa2001-awart. if sy-subrc = 0. wa_RESULT-ATEXT = wa_T554T-ATEXT. endif. append wa_result to IT_RESULT. endloop. sort IT_RESULT by PERNR BEGDA descending. ENDMETHOD. *----------------------------------------------* * METHOD write_data * *----------------------------------------------* METHOD write_data. write / 'ABNORMAL ABSENCES'. if s_ldate is initial. write : / 'Date : All'. elseif s_ldate-high is initial. write : / 'Date : ', s_ldate-low. else. write : / 'Date : ', s_ldate-low, 'to', s_ldate-high. endif. skip 2. uline (98). write : / tno(4) color col_heading centered, tpernr color col_heading centered, tcname color col_heading centered, ttrfst color col_heading centered, tbtrtl color col_heading centered, tbegda color col_heading centered, tbeguz color col_heading centered, tawart color col_heading centered, tatext color col_heading centered. uline /(98). loop at it_result into wa_result. add 1 to nomer. write : /(4) nomer color col_normal, wa_result-pernr color col_normal, wa_result-cname(23) color col_normal, (5) wa_result-trfst color col_normal centered, (6) wa_result-btrtl color col_normal centered, wa_result-begda color col_normal, (7) wa_result-begen color col_normal centered, (4) wa_result-awart color col_normal, (23) wa_result-atext color col_normal. endloop. uline (98). ENDMETHOD.
Here some modification that we created in method process_data and write_data .
Subroutine |
Method |
---|---|
loop at it_pa2001. |
loop at it_pa2001 into wa_pa2001. |
clear: IT_T554T, IT_RESULT. |
clear: wa_T554T, wa_RESULT. |
read table it_pa0002 with key pernr = it_pa2001-pernr |
read table it_pa0002 into wa_pa0002 binary search |
move-corresponding it_pa2001 to IT_RESULT. |
move-corresponding wa_pa2001 to wa_RESULT. |
append IT_RESULT. |
append wa_result to IT_RESULT. |
loop at it_result. |
loop at it_result into wa_result. |
lcl_handler implementation:
Error rendering macro 'code': Invalid value specified for parameter 'com.atlassian.confluence.ext.code.render.InvalidValueException'*---------------------------------------------------------------------* * C.L.A.S.S lcl_handler I.M.P.L.E.M.E.N.T.A.T.I.O.N *---------------------------------------------------------------------* CLASS lcl_handler IMPLEMENTATION. METHOD handle_event. MESSAGE i398(00) with 'No entries exist for this selection !'. LEAVE LIST-PROCESSING.. ENDMETHOD. ENDCLASS.
After we create the class definition and implementation, we can create object of this class and use it in our report program.
Error rendering macro 'code': Invalid value specified for parameter 'com.atlassian.confluence.ext.code.render.InvalidValueException'*----------------------------------------------------------------------- * M.A.I.N. .P.R.O.G.R.A.M. *----------------------------------------------------------------------- START-OF-SELECTION. DATA: o_main TYPE REF TO lcl_main, o_handler TYPE REF TO lcl_handler. CREATE OBJECT: o_main, o_handler. SET HANDLER o_handler->handle_event FOR ALL INSTANCES. CALL METHOD o_main->get_data. CALL METHOD o_main->process_data. CALL METHOD o_main->write_data.
Notes:
Because i can't attach txt file, here the complete source code:
Old Report:
*&---------------------------------------------------------------------* *& Report ZJR_OOP4 *& *&---------------------------------------------------------------------* *& Program Description : * *& Name : Report Abnormal Absences * *& Programmer : XXXXXXXXXXXXXXX * *& Date : 22.08.2005 * *&---------------------------------------------------------------------* REPORT ZJR_OOP4. *----------------------------------------------------------------------- * D.A.T.A D.I.C.T.I.O.N.A.R.Y T.A.B.L.E/S. *----------------------------------------------------------------------- TABLES: PA0001, PA0008, PA2001. *----------------------------------------------------------------------- * C.O.N.S.T.A.N.T.S *----------------------------------------------------------------------- constants : tno(4) value 'No', tpernr(8) value 'Pers.No', tcname(23) value 'Name', ttrfst(5) value 'Level', tbtrtl(6) value 'Dept', tbegda(10) value 'Date', tbeguz(7) value 'Time', tawart(4) value 'Type', tatext(23) value 'Description'. *----------------------------------------------------------------------- * G.L.O.B.A.L D.A.T.A. *----------------------------------------------------------------------- DATA nomer type i. data : begin of IT_RESULT occurs 0, pernr like pa0001-pernr, cname like pa0002-cname, trfst like pa0008-trfst, btrtl like pa0001-btrtl, begda like pa2001-begda, beguz like pa2001-beguz, awart like pa2001-awart, atext like t554t-atext, BEGEN(10), end of it_result. data : begin of it_pa0001 occurs 0, pernr like pa0001-pernr, werks like pa0001-werks, btrtl like pa0001-btrtl, trfst like pa0008-trfst, end of it_pa0001. data : begin of it_pa0002 occurs 0, pernr like pa0002-pernr, cname like pa0002-cname, end of it_pa0002. data : begin of it_pa2001 occurs 0, pernr like pa2001-pernr, begda like pa2001-begda, endda like pa2001-endda, awart like pa2001-awart, beguz like P2001-BEGUZ, enduz like P2001-ENDUZ, end of it_pa2001. data : it_t554t like t554t occurs 0 with header line. *----------------------------------------------------------------------- * S.E.L.L.E.C.T.I.O.N. .S.C.R.E.E.N. *----------------------------------------------------------------------- selection-screen begin of block blok1 with frame title text-001. parameter: p_werks type pa0001-werks obligatory. select-options: s_btrtl for pa0001-btrtl obligatory, s_ldate for sy-datum obligatory. parameter: p_awart type pa2001-awart obligatory. selection-screen end of block blok1. *----------------------------------------------------------------------- * M.A.I.N. .P.R.O.G.R.A.M. *----------------------------------------------------------------------- START-OF-SELECTION. PERFORM get_data. perform process_data. perform write_data. *&---------------------------------------------------------------------* *& Form get_data *&---------------------------------------------------------------------* FORM get_data . * get pernr select a~pernr a~werks a~btrtl b~trfst into corresponding fields of table it_pa0001 from pa0001 as a inner join pa0008 as b on a~pernr = b~pernr where a~werks = p_werks and a~btrtl in s_btrtl and a~endda = '99991231' and b~endda = '99991231'. if sy-subrc = 0. * get name select pernr cname into corresponding fields of table it_pa0002 from pa0002 for all entries in it_pa0001 where pernr = it_pa0001-pernr and endda = '99991231'. * get absence select PERNR BEGDA BEGUZ ENDUZ AWART into corresponding fields of table IT_PA2001 from PA2001 for all entries in it_pa0001 where pernr = it_pa0001-pernr and begda in s_ldate and endda in s_ldate AND awart = p_awart. * get absemce text if sy-subrc = 0. select AWART ATEXT into corresponding fields of table IT_T554T from T554T where SPRSL = SY-LANGU and AWART = P_AWART and MOABW in ( select moabw from t001p where werks = p_werks ). sort IT_T554T by AWART. else. message i398(00) with 'No entries exist for this selection !'. exit. endif. else. message i398(00) with 'No entries exist for this selection !'. exit. endif. ENDFORM. " get_data *&---------------------------------------------------------------------* *& Form process_data *&---------------------------------------------------------------------* FORM process_data . clear: IT_RESULT[]. sort IT_T554T by AWART. sort it_pa0001 by pernr. sort it_pa0002 by pernr. sort it_pa2001 by pernr begda. loop at it_pa2001. clear: IT_T554T, IT_RESULT. move-corresponding it_pa2001 to IT_RESULT. read table it_pa0002 with key pernr = it_pa2001-pernr binary search. if sy-subrc = 0. move-corresponding it_pa0002 to IT_RESULT. endif. read table it_pa0001 with key pernr = it_pa2001-pernr binary search. if sy-subrc = 0. move-corresponding it_pa0001 to IT_RESULT. endif. *** IT_RESULT-BEGDA = IT_PA2001-BEGDA. case IT_PA2001-AWART. when 'DL'. concatenate IT_PA2001-ENDUZ+0(2) ':' IT_PA2001-ENDUZ+2(2) into IT_RESULT-BEGEN. when 'PC'. concatenate IT_PA2001-BEGUZ+0(2) ':' IT_PA2001-BEGUZ+2(2) into IT_RESULT-BEGEN. when others. IT_RESULT-BEGEN = '-'. endcase. IT_RESULT-AWART = IT_PA2001-AWART. *** read table it_t554t with key awart = it_pa2001-awart. if sy-subrc = 0. IT_RESULT-ATEXT = IT_T554T-ATEXT. endif. append IT_RESULT. endloop. sort IT_RESULT by PERNR BEGDA descending. ENDFORM. " process_data *&---------------------------------------------------------------------* *& Form write_data *&---------------------------------------------------------------------* FORM write_data . write / 'ABNORMAL ABSENCES'. if s_ldate is initial. write : / 'Date : All'. elseif s_ldate-high is initial. write : / 'Date : ', s_ldate-low. else. write : / 'Date : ', s_ldate-low, 'to', s_ldate-high. endif. skip 2. uline (98). write : / tno(4) color col_heading centered, tpernr color col_heading centered, tcname color col_heading centered, ttrfst color col_heading centered, tbtrtl color col_heading centered, tbegda color col_heading centered, tbeguz color col_heading centered, tawart color col_heading centered, tatext color col_heading centered. uline /(98). loop at it_result. add 1 to nomer. write : /(4) nomer color col_normal, it_result-pernr color col_normal, it_result-cname(23) color col_normal, (5) it_result-trfst color col_normal centered, (6) it_result-btrtl color col_normal centered, it_result-begda color col_normal, (7) it_result-begen color col_normal centered, (4) it_result-awart color col_normal, (23) it_result-atext color col_normal. endloop. uline (98). ENDFORM. " write_data
New Report:
Error rendering macro 'code': Invalid value specified for parameter 'com.atlassian.confluence.ext.code.render.InvalidValueException'*&---------------------------------------------------------------------* *& Report ZJR_OOP4 *& *&---------------------------------------------------------------------* *& Program Description : * *& Name : Report Abnormal Absences * *& Programmer : Jatra Riwayanto * *& Date : 01.05.2007 * *&---------------------------------------------------------------------* REPORT ZJR_OOP3. *----------------------------------------------------------------------- * D.A.T.A D.I.C.T.I.O.N.A.R.Y T.A.B.L.E/S. *----------------------------------------------------------------------- TABLES: PA0001, PA0008, PA2001. *----------------------------------------------------------------------- * S.E.L.L.E.C.T.I.O.N. .S.C.R.E.E.N. *----------------------------------------------------------------------- selection-screen begin of block blok1 with frame title text-001. parameter: p_werks type pa0001-werks obligatory. select-options: s_btrtl for pa0001-btrtl obligatory, s_ldate for sy-datum obligatory. parameter: p_awart type pa2001-awart obligatory. selection-screen end of block blok1. *---------------------------------------------------------------------* * C.L.A.S.S lcl_main D.E.F.I.N.I.T.I.O.N *---------------------------------------------------------------------* CLASS lcl_main DEFINITION. PUBLIC SECTION. METHODS: get_data, process_data, write_data. EVENTS: no_data. PRIVATE SECTION. *---------------------------------- * C.O.N.S.T.A.N.T.S *---------------------------------- constants : tno(4) value 'No', tpernr(8) value 'Pers.No', tcname(23) value 'Name', ttrfst(5) value 'Level', tbtrtl(6) value 'Dept', tbegda(10) value 'Date', tbeguz(7) value 'Time', tawart(4) value 'Type', tatext(23) value 'Description'. *--------------------------------- * L.O.C.A.L D.A.T.A. *--------------------------------- DATA: nomer type i, begin of WA_RESULT, pernr type pa0001-pernr, cname type pa0002-cname, trfst type pa0008-trfst, btrtl type pa0001-btrtl, begda type pa2001-begda, beguz type pa2001-beguz, awart type pa2001-awart, atext type t554t-atext, BEGEN(10), end of WA_RESULT, begin of wa_pa0001, pernr type pa0001-pernr, werks type pa0001-werks, btrtl type pa0001-btrtl, trfst type pa0008-trfst, end of wa_pa0001, begin of wa_pa0002 , pernr type pa0002-pernr, cname type pa0002-cname, end of wa_pa0002, begin of wa_pa2001 , pernr type pa2001-pernr, begda type pa2001-begda, endda type pa2001-endda, awart type pa2001-awart, beguz type P2001-BEGUZ, enduz type P2001-ENDUZ, end of wa_pa2001, wa_t554t type t554t, IT_RESULT like standard table of WA_RESULT, IT_pa0001 like standard table of WA_pa0001, IT_pa0002 like standard table of WA_pa0002, IT_pa2001 like standard table of WA_pa2001, IT_t554t like standard table of WA_t554t. ENDCLASS. *---------------------------------------------------------------------* * C.L.A.S.S lcl_handler D.E.F.I.N.I.T.I.O.N *---------------------------------------------------------------------* CLASS lcl_handler DEFINITION. PUBLIC SECTION. METHODS handle_event FOR EVENT no_data OF lcl_main. ENDCLASS. *---------------------------------------------------------------------* * C.L.A.S.S lcl_main I.M.P.L.E.M.E.N.T.A.T.I.O.N *---------------------------------------------------------------------* CLASS lcl_main IMPLEMENTATION. *----------------------------------------------* * METHOD get_data * *----------------------------------------------* METHOD get_data. * get pernr select a~pernr a~werks a~btrtl b~trfst into corresponding fields of table it_pa0001 from pa0001 as a inner join pa0008 as b on a~pernr = b~pernr where a~werks = p_werks and a~btrtl in s_btrtl and a~endda = '99991231' and b~endda = '99991231'. * if itab has no records, raise event IF it_pa0001[] IS INITIAL. RAISE EVENT no_data . ENDIF. * get name select pernr cname into corresponding fields of table it_pa0002 from pa0002 for all entries in it_pa0001 where pernr = it_pa0001-pernr and endda = '99991231'. * get absence select PERNR BEGDA BEGUZ ENDUZ AWART into corresponding fields of table IT_PA2001 from PA2001 for all entries in it_pa0001 where pernr = it_pa0001-pernr and begda in s_ldate and endda in s_ldate AND awart = p_awart. * if itab has no absence records, raise event IF it_pa2001[] IS INITIAL. RAISE EVENT no_data . ENDIF. * get absemce text select AWART ATEXT into corresponding fields of table IT_T554T from T554T where SPRSL = SY-LANGU and AWART = p_AWART and MOABW in ( select moabw from t001p where werks = p_werks ). ENDMETHOD. *----------------------------------------------* * METHOD process_data * *----------------------------------------------* METHOD process_data. clear: IT_RESULT[]. sort IT_T554T by AWART. sort it_pa0001 by pernr. sort it_pa0002 by pernr. sort it_pa2001 by pernr begda. loop at it_pa2001 into wa_pa2001. clear: wa_T554T, wa_RESULT. move-corresponding wa_pa2001 to wa_RESULT. read table it_pa0002 into wa_pa0002 binary search with key pernr = wa_pa2001-pernr. if sy-subrc = 0. move-corresponding wa_pa0002 to wa_RESULT. endif. read table it_pa0001 into wa_pa0001 binary search with key pernr = wa_pa2001-pernr. if sy-subrc = 0. move-corresponding wa_pa0001 to wa_RESULT. endif. *** wa_RESULT-BEGDA = wa_PA2001-BEGDA. case wa_PA2001-AWART. when 'DL'. concatenate wa_PA2001-ENDUZ+0(2) ':' wa_PA2001-ENDUZ+2(2) into wa_RESULT-BEGEN. when 'PC'. concatenate wa_PA2001-BEGUZ+0(2) ':' wa_PA2001-BEGUZ+2(2) into wa_RESULT-BEGEN. when others. wa_RESULT-BEGEN = '-'. endcase. wa_RESULT-AWART = wa_PA2001-AWART. *** read table it_t554t into wa_t554t binary search with key awart = wa_pa2001-awart. if sy-subrc = 0. wa_RESULT-ATEXT = wa_T554T-ATEXT. endif. append wa_result to IT_RESULT. endloop. sort IT_RESULT by PERNR BEGDA descending. ENDMETHOD. *----------------------------------------------* * METHOD write_data * *----------------------------------------------* METHOD write_data. write / 'ABNORMAL ABSENCES'. if s_ldate is initial. write : / 'Date : All'. elseif s_ldate-high is initial. write : / 'Date : ', s_ldate-low. else. write : / 'Date : ', s_ldate-low, 'to', s_ldate-high. endif. skip 2. uline (98). write : / tno(4) color col_heading centered, tpernr color col_heading centered, tcname color col_heading centered, ttrfst color col_heading centered, tbtrtl color col_heading centered, tbegda color col_heading centered, tbeguz color col_heading centered, tawart color col_heading centered, tatext color col_heading centered. uline /(98). loop at it_result into wa_result. add 1 to nomer. write : /(4) nomer color col_normal, wa_result-pernr color col_normal, wa_result-cname(23) color col_normal, (5) wa_result-trfst color col_normal centered, (6) wa_result-btrtl color col_normal centered, wa_result-begda color col_normal, (7) wa_result-begen color col_normal centered, (4) wa_result-awart color col_normal, (23) wa_result-atext color col_normal. endloop. uline (98). ENDMETHOD. ENDCLASS. *---------------------------------------------------------------------* * C.L.A.S.S lcl_handler I.M.P.L.E.M.E.N.T.A.T.I.O.N *---------------------------------------------------------------------* CLASS lcl_handler IMPLEMENTATION. METHOD handle_event. MESSAGE i398(00) with 'No entries exist for this selection !'. LEAVE LIST-PROCESSING.. ENDMETHOD. ENDCLASS. *----------------------------------------------------------------------- * M.A.I.N. .P.R.O.G.R.A.M. *----------------------------------------------------------------------- START-OF-SELECTION. DATA: o_main TYPE REF TO lcl_main, o_handler TYPE REF TO lcl_handler. CREATE OBJECT: o_main, o_handler. SET HANDLER o_handler->handle_event FOR ALL INSTANCES. CALL METHOD o_main->get_data. CALL METHOD o_main->process_data. CALL METHOD o_main->write_data.
3 Comments
Former Member
good example!! .. how about print this report using oop ALV?
Unknown User (xlsdknv)
I think this example has to be completly rewritten! First of all it is using DATA and BEGIN OF clausule, which shouldn't be used. Second, event handlers instead of exceptions are used for handling situation when we have no data found! Exceptions are better (definitelly) for that! Third, I suggest to use MVC concept and separate data selection, controlling and displaying into separate classes.
This example just shows how to port from forms into 1 class. Such usage of ABAP OO does not give any advantage beside better type control for methods (comparing to forms).
Unknown User (k6xjo1q)
Very good example. Thanks