本篇內(nèi)容主要講解“怎么使用ABAP提高工作效率”,感興趣的朋友不妨來看看。本文介紹的方法操作簡單快捷,實用性強。下面就讓小編來帶大家學(xué)習(xí)“怎么使用ABAP提高工作效率”吧!
目前成都創(chuàng)新互聯(lián)公司已為近1000家的企業(yè)提供了網(wǎng)站建設(shè)、域名、網(wǎng)頁空間、網(wǎng)站改版維護、企業(yè)網(wǎng)站設(shè)計、儀隴網(wǎng)站維護等服務(wù),公司將堅持客戶導(dǎo)向、應(yīng)用為本的策略,正道將秉承"和諧、參與、激情"的文化,與客戶和合作伙伴齊心協(xié)力一起成長,共同發(fā)展。(1) 直接批量生成數(shù)據(jù)到ABAP內(nèi)表里:
* 2017-05-14 7:17PM in Xun's house, Wiesloch
INSERT demo_join1 FROM TABLE @( VALUE #(
( a = 'a1' b = 'b1' c = 'c1' d = 'uu' )
( a = 'a2' b = 'b2' c = 'c2' d = 'uu' )
( a = 'a3' b = 'b3' c = 'c3' d = 'vv' )
( a = 'a4' b = 'b4' c = 'c4' d = 'ww' ) ) ).
(2) 采用內(nèi)聯(lián)方式遍歷ABAP內(nèi)表:
DATA address_annos TYPE STANDARD TABLE OF field_anno-annoname
WITH EMPTY KEY.
address_annos = VALUE #(
( 'SEMANTICS.NAME.FULLNAME' )
( 'SEMANTICS.ADDRESS.STREET' )
( 'SEMANTICS.ADDRESS.CITY' )
( 'SEMANTICS.ADDRESS.ZIPCODE' )
( 'SEMANTICS.ADDRESS.COUNTRY' ) ).
DATA address_components TYPE STANDARD TABLE OF field_anno-fieldname
WITH EMPTY KEY.
address_components = VALUE #(
FOR address_anno IN address_annos
( VALUE #( fieldannos[ annoname = address_anno ]-fieldname
DEFAULT '---' ) ) ).
(3) 兩個內(nèi)表間數(shù)據(jù)的復(fù)制,兩個內(nèi)表的列結(jié)構(gòu)可以不同,開發(fā)人員需要額外傳入一個映射表,告訴corresponding關(guān)鍵字,源內(nèi)表的哪一列應(yīng)該賦到目標(biāo)內(nèi)表的哪一列。
* This is exactly what I want!!
REPORT demo_corresponding_vs_for.
CLASS demo DEFINITION.
PUBLIC SECTION.
CLASS-METHODS:
main,
class_constructor.
PRIVATE SECTION.
TYPES:
BEGIN OF struct,
carrier TYPE spfli-carrid,
connection TYPE spfli-connid,
departure TYPE spfli-cityfrom,
destination TYPE spfli-cityto,
END OF struct.
CLASS-DATA:
itab TYPE HASHED TABLE OF spfli
WITH UNIQUE KEY carrid connid,
result1 TYPE HASHED TABLE OF struct
WITH UNIQUE KEY carrier connection,
result2 TYPE HASHED TABLE OF struct
WITH UNIQUE KEY carrier connection,
result3 TYPE HASHED TABLE OF struct
WITH UNIQUE KEY carrier connection,
in TYPE REF TO if_demo_input,
out TYPE REF TO if_demo_output.
ENDCLASS.
CLASS demo IMPLEMENTATION.
METHOD main.
DATA(iterations) = 10.
in->request( CHANGING field = iterations ).
DO iterations TIMES.
DATA t1 TYPE i.
GET RUN TIME FIELD DATA(t11).
result1 = CORRESPONDING #(
itab MAPPING carrier = carrid
connection = connid
departure = cityfrom
destination = cityto ).
GET RUN TIME FIELD DATA(t12).
t1 = t1 + t12 - t11.
DATA t2 TYPE i.
GET RUN TIME FIELD DATA(t21).
result2 = VALUE #( FOR wa IN itab ( carrier = wa-carrid
connection = wa-connid
departure = wa-cityfrom
destination = wa-cityto ) ).
GET RUN TIME FIELD DATA(t22).
t2 = t2 + t22 - t21.
DATA t3 TYPE i.
GET RUN TIME FIELD DATA(t31).
result3 = VALUE #( FOR wa IN itab (
CORRESPONDING #(
wa MAPPING carrier = carrid
connection = connid
departure = cityfrom
destination = cityto ) ) ).
GET RUN TIME FIELD DATA(t32).
t3 = t3 + t32 - t31.
ENDDO.
IF result1 = result2 AND result1 = result3.
out->write(
|CORRESPONDING: {
CONV decfloat16( t1 / iterations )
WIDTH = 10 ALIGN = RIGHT } Microseconds\n| &&
|FOR: {
CONV decfloat16( t2 / iterations )
WIDTH = 10 ALIGN = RIGHT } Microseconds\n| &&
|FOR CORRESPONDING: {
CONV decfloat16( t3 / iterations )
WIDTH = 10 ALIGN = RIGHT } Microseconds\n|
)->line(
)->display( result1 ).
ELSE.
out->display( `What?` ).
ENDIF.
ENDMETHOD.
METHOD class_constructor.
in = cl_demo_input=>new( ).
out = cl_demo_output=>new( ).
SELECT *
FROM spfli
INTO TABLE @itab.
ENDMETHOD.
ENDCLASS.
START-OF-SELECTION.
demo=>main( ).
(4) DISCARDING DUPLICATES的用法
REPORT demo_corresponding_duplicates.
CLASS demo DEFINITION.
PUBLIC SECTION.
CLASS-METHODS main.
ENDCLASS.
CLASS demo IMPLEMENTATION.
METHOD main.
TYPES:
BEGIN OF line,
a1 TYPE i,
a2 TYPE i,
END OF line,
ntab1 TYPE STANDARD TABLE OF line WITH EMPTY KEY,
ntab2 TYPE SORTED TABLE OF line WITH UNIQUE KEY a1,
BEGIN OF line1,
x1 TYPE i,
x2 TYPE ntab1,
END OF line1,
BEGIN OF line2,
y1 TYPE i,
y2 TYPE ntab2,
END OF line2,
itab1 TYPE STANDARD TABLE OF line1 WITH EMPTY KEY,
itab2 TYPE SORTED TABLE OF line2 WITH UNIQUE KEY y1.
DATA(itab1) =
VALUE itab1( ( x1 = 1 x2 = VALUE #( ( a1 = 1 a2 = 2 )
( a1 = 3 a2 = 4 ) ) )
( x1 = 2 x2 = VALUE #( ( a1 = 1 a2 = 2 )
( a1 = 1 a2 = 4 ) ) )
( x1 = 1 x2 = VALUE #( ( a1 = 1 a2 = 2 )
( a1 = 3 a2 = 4 ) ) ) ).
DATA(itab2) =
CORRESPONDING itab2( itab1 DISCARDING DUPLICATES
MAPPING y1 = x1
y2 = x2 DISCARDING DUPLICATES ).
DATA(out) = cl_demo_output=>new( ).
LOOP AT itab2 INTO DATA(wa).
out->write( wa-y1
)->write( wa-y2
)->line( ).
ENDLOOP.
out->display( ).
ENDMETHOD.
ENDCLASS.
START-OF-SELECTION.
demo=>main( ).
(5) DESCRIBE DISTANCE BETWEEN
REPORT demo_describe_distance.
CLASS demo DEFINITION.
PUBLIC SECTION.
CLASS-METHODS main.
ENDCLASS.
CLASS demo IMPLEMENTATION.
METHOD main.
DATA: BEGIN OF struc,
comp1 TYPE i,
comp2 TYPE x LENGTH 1,
comp3 TYPE c LENGTH 4 VALUE 'Hey',
comp4 TYPE c LENGTH 4 VALUE 'you!',
comp5 TYPE x,
END OF struc.
FIELD-SYMBOLS: <hex> TYPE x,
<result> TYPE c.
DESCRIBE DISTANCE BETWEEN:
struc AND struc-comp3 INTO DATA(off) IN BYTE MODE,
struc-comp3 AND struc-comp5 INTO DATA(len) IN BYTE MODE.
ASSIGN: struc TO <hex> CASTING,
<hex>+off(len) TO <result> CASTING.
cl_demo_output=>display(
|Offset off is { off }.\n| &&
|Length len is { len }.\n| &&
|<result> points to "{ <result> }".| ).
ENDMETHOD.
ENDCLASS.
START-OF-SELECTION.
demo=>main( ).
(6) 全動態(tài)方式調(diào)用RFC
REPORT demo_rfc_dynamic_dest.
CLASS demo DEFINITION.
PUBLIC SECTION.
CLASS-METHODS:
main.
ENDCLASS.
CLASS demo IMPLEMENTATION.
METHOD main.
DATA:
val_in TYPE string VALUE `val_in`,
val_in_out TYPE string VALUE `val_in_out`,
val_out TYPE string,
msg TYPE c LENGTH 80.
IF sy-uname IS INITIAL.
cl_demo_output=>display(
|Example not possible for anonymous user| ).
RETURN.
ENDIF.
DATA(in) = cl_demo_input=>new( ).
DATA(client) = sy-mandt.
in->add_field( CHANGING field = client ).
DATA(uname) = sy-uname.
in->add_field( CHANGING field = uname ).
DATA(langu) = sy-langu.
in->add_field( CHANGING field = langu ).
DATA(sysid) = sy-sysid.
in->add_field( CHANGING field = sysid ).
DATA(host) = CONV rfchost( sy-host ).
in->add_field( CHANGING field = host ).
DATA(group) = CONV rfcload( 'PUBLIC' ).
in->add_field( CHANGING field = group ).
in->request( ).
DATA(dest) = cl_dynamic_destination=>create_rfc_destination(
logon_client = client
logon_user = uname
logon_language = langu
sid = sysid
server = host
group = group ).
CALL FUNCTION 'DEMO_RFM_PARAMETERS'
DESTINATION dest
EXPORTING
p_in = val_in
IMPORTING
p_out = val_out
CHANGING
p_in_out = val_in_out
EXCEPTIONS
system_failure = 2 MESSAGE msg
communication_failure = 4 MESSAGE msg.
IF sy-subrc <> 0.
cl_demo_output=>display( |Error when calling sRFC.\n{ msg }| ).
RETURN.
ENDIF.
cl_demo_output=>display( |{ val_out }\n{ val_in_out }| ).
ENDMETHOD.
ENDCLASS.
START-OF-SELECTION.
demo=>main( ).
(7) 內(nèi)聯(lián)函數(shù)line_index
REPORT.
CLASS demo DEFINITION.
PUBLIC SECTION.
CLASS-METHODS: class_constructor,
main.
PRIVATE SECTION.
CLASS-DATA
flight_tab
TYPE STANDARD TABLE OF spfli
WITH EMPTY KEY
WITH UNIQUE HASHED KEY id COMPONENTS carrid connid
WITH NON-UNIQUE SORTED KEY cities COMPONENTS cityfrom cityto.
ENDCLASS.
CLASS demo IMPLEMENTATION.
METHOD main.
DATA idx TYPE TABLE OF i.
idx = VALUE #(
( line_index( flight_tab[ carrid = 'UA'
connid = '0941'
##primkey[id] ] ) )
( line_index( flight_tab[ KEY id
carrid = 'UA'
connid = '0941' ] ) )
( line_index( flight_tab[ KEY id
carrid = 'xx'
connid = 'yyyy' ] ) )
( line_index( flight_tab[ cityfrom = 'FRANKFURT'
cityto = 'NEW YORK'
##primkey[cities] ] ) )
( line_index( flight_tab[ KEY cities
cityfrom = 'FRANKFURT'
cityto = 'NEW YORK' ] ) )
( line_index( flight_tab[ KEY cities
cityfrom = 'xxxxxxxx'
cityto = 'yyyyyyyy' ] ) ) ).
cl_demo_output=>display( idx ).
ENDMETHOD.
METHOD class_constructor.
SELECT *
FROM spfli
ORDER BY carrid, connid
INTO TABLE @flight_tab.
ENDMETHOD.
ENDCLASS.
START-OF-SELECTION.
demo=>main( ).
到此,相信大家對“怎么使用ABAP提高工作效率”有了更深的了解,不妨來實際操作一番吧!這里是創(chuàng)新互聯(lián)網(wǎng)站,更多相關(guān)內(nèi)容可以進入相關(guān)頻道進行查詢,關(guān)注我們,繼續(xù)學(xué)習(xí)!
網(wǎng)站標(biāo)題:怎么使用ABAP提高工作效率-創(chuàng)新互聯(lián)
轉(zhuǎn)載源于:http://jinyejixie.com/article48/csddep.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供定制開發(fā)、面包屑導(dǎo)航、小程序開發(fā)、做網(wǎng)站、全網(wǎng)營銷推廣、手機網(wǎng)站建設(shè)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容