没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
Tips for OO
1 常用的标准 CLASS 和 INTERFACE.......................................................................................2
2 LOCAL CLASS..................................................................................................................... 5
3 GLOBAL CLASS................................................................................................................... 6
3.1 GLOBAL CLASS – DIRECT TYPE DEFINITION.........................................................................7
3.3 CREATION OF A GLOBAL CLASS.........................................................................................8
4 ACCESS MODIFIERS.........................................................................................................14
4.1 5 RULES OF THUMB FOR ACCESS MODIFIERS...................................................................14
5 CREATION OF AN INTERFACE.........................................................................................15
1 OBJECTIVE......................................................................................................................... 15
2 DATABASE TABLES............................................................................................................. 16
3 INTERFACE......................................................................................................................... 17
6 CREATION OF AN EXCEPTION CLASS...........................................................................17
1 OBJECTIVE......................................................................................................................... 18
2 EXCEPTION CLASSES IN OBJECT ORIENTED PROGRAMMING.................................................18
7 CONSTRUCTOR & CLASS CONSTRUCTOR....................................................................24
1 Code Snippet................................................................................................................................25
2 Code Snippet – Constant access Scenario....................................................................................28
3 Code Snippet – Instanaon scenario.........................................................................................28
4 Code Snippet – Complex..............................................................................................................28
8 NARROW CASTING & WILD CASTING.............................................................................30
9 REFACTORING................................................................................................................... 30
1 MOVING COMPONENTS FROM SUPER CLASS TO SUBCLASS...................................................30
2 MOVING COMPONENTS FROM CLASS TO ASSOCIATED CLASS................................................31
9 ABAP OBJECTS QUESTIONS ANSWERS........................................................................33
8 事务的处理........................................................................................................................... 35
9 PERSISTENT CLASS & DATA ACCESS CLASS..............................................................37
1 CREATE A NEW RECORD/ READ A RECORD BY KEY................................................................41
2 QUERY FOR MULTIPLE RECORDS........................................................................................44
10 CREATION OF AN EDITABLE ALV.................................................................................45
11 MODEL CLASS & BUSINESS OBJECT CLASS..............................................................45
12 ENHANCEMENT TO A STANDARD CLASS...................................................................46
Tips for OO
1 常用的标准 class 和 interface
1) the data type of any class is ‘SEOCLSNAME’
2) OBJECT’ is the super class of all classes. Here why we are referring this, if you know the
name of the model class clearly declare the variable of the same type reference, where if you
don’t know, let us declare out reference variable of model class with reference to ‘Super
class’ of the classes.
1 事务相关:
IF_OS_TRANSACTION
IF_OS_TRANSACTION_MANAGER
2 Exception 相关:
CX_ROOT
3 ALV 相关
CL_SALV_TABLE 显示 ALV
4 和 string 相关
1) CL_ABAP_CHAR_UTILITIES => Utilities for Processing Characters
data:lv_texttypestring.
CONCATENATE'FirstTextString'
'SecondTextString'
intolv_textSEPARATEDBY
CL_ABAP_CHAR_UTILITIES=>NEWLINE.
5 cl_abap_typedescr
根据一个结构获得这个结构中的字段
DATA:LS_CUSTTYPEYCUST_SATISF_TT,
LT_CUSTTYPETABLEOFYCUST_SATISF_TT.
DATAlr_sdescrTYPEREFTOcl_abap_structdescr.
DATA:LT_FIELD_CATALOGTYPEABAP_COMPDESCR_TAB.
lr_sdescr?=cl_abap_typedescr=>describe_by_data(LS_CUST).
LT_FIELD_CATALOG=lr_sdescr->components[].
Tips for OO
6 ZIP compression technology
6.1 CL_ABAP_GZIP
DATA lv_syllabi TYPE xstring.
lv_syllabi = gr_course_pers->get_syllabi( ).
DATA lr_zip TYPE REF TO cl_abap_gzip.
IF lv_syllabi IS NOT INITIAL.
CREATE OBJECT lr_zip.
lr_zip->decompress_text(
EXPORTING gzip_in = lv_syllabi
IMPORTING text_out = gs_course-syllabi ).
ENDIF.
Listing 4.20 Decompress from the Persistent Object
DATA lv_syllabi TYPE xstring.
DATA lr_zip TYPE REF TO cl_abap_gzip.
IF gs_course-syllabi IS NOT INITIAL.
CREATE OBJECT lr_zip.
lr_zip->compress_text(
EXPORTING text_in = gs_course-syllabi
IMPORTING gzip_out = lv_syllabi ).
ENDIF.
gr_course_pers->set_syllabi( lv_syllabi ).
Listing 4.21 Compress Before Updating
6.2 CL_ABAP_ZIP – more advanced ZIP class
The logic for this ZIP library is quite similar to the &rst
library. The main di'erence is the use of the SPLICE static
method to provide an internal table of inner components of
the compressed string. Each inner component must be
pulled out of the compressed package using the GET
method.
CLEAR GS_COURSE_ASS-attachments.
DATA lr_zip TYPE REF TO cl_abap_zip.
DATA lv_attchements TYPE xstring.
DATA lt_splice TYPE cl_abap_zip=>t_splice_entries.
FIELD-SYMBOLS: <ls_splice> LIKE LINE OF lt_splice,
<ls_att> TYPE zcs2_course_9le.
lv_attchements = gr_persistent_object->get_attachments( ).
IF lv_attchements IS NOT INITIAL.
CREATE OBJECT lr_zip.
lt_splice = cl_abap_zip=>splice( lv_attchements ).
lr_zip->load( lv_attchements ).
ENDIF.
Tips for OO
LOOP AT lt_splice ASSIGNING <ls_splice>.
APPEND INITIAL LINE TO GS_COURSE_ASS-attachments
ASSIGNING <ls_att>.
<ls_att>-9lename = <ls_splice>-name.
<ls_att>-9lelen = <ls_splice>-length.
lr_zip->get(
EXPORTING name = <ls_att>-9lename
IMPORTING content = <ls_att>-content ).
ENDLOOP.
Listing 4.22 Splicing and Decompression of Attachments from the Persistent Object
DATA lr_zip TYPE REF TO cl_abap_zip.
DATA lv_attchments TYPE xstring.
FIELD-SYMBOLS <ls_att> TYPE zcs2_course_9le.
CREATE OBJECT lr_zip.
LOOP AT GS_COURSE_ASS-attachments ASSIGNING <ls_att>.
lr_zip->add( name = <ls_att>-9lename
content = <ls_att>-content ).
ENDLOOP.
lv_attchments = lr_zip->save( ).
gr_persistent_object->set_attachments( lv_attchments ).
Listing 4.23 Compression of Attachments Before Returning to the Persistent Object
6 cl_gui_frontend_services
cl_gui_frontend_services=>file_open_dialog(
EXPORTING
multiselection = abap_false
file_filter = ‘*.xls’
default_extension = ‘xls’
CHANGING
file_table = lt_retfiletable
rc = lv_retrc
user_action = lv_retuseraction ).
READ TABLE lt_retfiletable INTO p_file INDEX 1.
7 cl_abap_random
DATA: lr_random TYPE REF TO cl_abap_random.
DATA: lv_gpa TYPE i.
lr_random =
cl_abap_random=>create( cl_abap_random=>seed( ) ).
<ls_student>-credit_hrs =
lr_random->intinrange( low = 0 high = 150 ).
lv_gpa = lr_random->intinrange( low = 1000 high = 4000 ).
<ls_student>-gpa = lv_gpa / 1000.
CLEAR lr_random.
8 cl_abap_container_utilities
cl_abap_container_utilities=>fill_container_c
Tips for OO
2 Local class
Local Classes are commonly used to create Event handlers to handle ALV Events in a ALV
report/program. SAP allows the developer to handle the events in whichever way required event
though it is possible to handle events dynamically using EVENT HANDLER methods,
created for the EVENT, inside a global class.
CLASSlcl_basic_class_1DEFINITION.
PUBLICSECTION.
DATA:vbelnTYPEvbak-vbeln,
t_vbapTYPETABLEOFvbap.
METHODSget_items
IMPORTINGim_vbelnTYPEvbak-vbeln
EXPORTINGeit_vbapTYPESTANDARDTABLE.
ENDCLASS."lcl_basic_class_1DEFINITION
CLASSlcl_basic_class_1IMPLEMENTATION.
METHODget_items.
SELECT*FROMvbapINTOTABLEeit_vbap
WHEREvbeln=im_vbeln.
ENDMETHOD."get_items
ENDCLASS."lcl_basic_class_1IMPLEMENTATION
DATA:lo_objectTYPEREFTOlcl_basic_class_1,
lit_vbapTYPETABLEOFvbap,
wa_vbaptypevbap.
PARAMETERS:p_vbelnTYPEvbak-vbeln.
START-OF-SELECTION.
CREATEOBJECTlo_object.
callmethodlo_object->get_items
EXPORTING
im_vbeln=p_vbeln
IMPORTING
eit_vbap=lit_vbap.
loopatlit_vbapintowa_vbap.
write:/wa_vbap-VBELN,wa_vbap-POSNR,wa_vbap-MATNR.
ENDLOOP.
剩余51页未读,继续阅读
资源评论
雁舞九天
- 粉丝: 80
- 资源: 35
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功