怎么使用ABAP提高工作效率
本篇内容主要讲解“怎么使用ABAP提高工作效率”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“怎么使用ABAP提高工作效率”吧!
让客户满意是我们工作的目标,不断超越客户的期望值来自于我们对这个行业的热爱。我们立志把好的技术通过有效、简单的方式提供给客户,将通过不懈努力成为客户在信息化领域值得信任、有价值的长期合作伙伴,公司提供的服务项目有:主机域名、虚拟主机、营销软件、网站建设、万源网站维护、网站推广。
(1) 直接批量生成数据到ABAP内表里:
* 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) 采用内联方式遍历ABAP内表:
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) 两个内表间数据的复制,两个内表的列结构可以不同,开发人员需要额外传入一个映射表,告诉corresponding关键字,源内表的哪一列应该赋到目标内表的哪一列。
* 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:
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
cl_demo_output=>display(
|Offset off is { off }.\n| &&
|Length len is { len }.\n| &&
|
ENDMETHOD.
ENDCLASS.
START-OF-SELECTION.
demo=>main( ).
(6) 全动态方式调用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) 内联函数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提高工作效率”有了更深的了解,不妨来实际操作一番吧!这里是创新互联网站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!
分享标题:怎么使用ABAP提高工作效率
转载注明:http://myzitong.com/article/gohghe.html