Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use ABAP to improve work efficiency

2025-04-06 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly explains "how to use ABAP to improve work efficiency". Friends who are interested may wish to have a look. The method introduced in this paper is simple, fast and practical. Now let the editor take you to learn "how to use ABAP to improve work efficiency"!

(1) generate data in batches directly to the ABAP internal table:

* 2017-05-14 7:17PM in Xun's house, Wiesloch

INSERT demo_join1 FROM TABLE @ (VALUE # (

(a = 'a1b =' b1c = 'c1d =' uu')

(a = 'a2b =' b2c = 'c2d =' uu')

(a = 'a3' b =' b3' c = 'c3d =' vv')

(a = 'a4' b =' b4' c = 'c4d =' ww').

(2) use inline method to traverse the inner table of 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) for the replication of data between two inner tables, the column structure of the two inner tables can be different. The developer needs to pass in an additional mapping table to tell the corresponding keyword which column of the source inner table should be assigned to which column of the target inner table.

* This is exactly what I Wantasy!

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 + T2-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) the usage of 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 = 2x2 = VALUE # (A1 = 1a2 = 2)

(A1 = 1 a2 = 4)

(x1 = 1 x2 = VALUE # (A1 = 1 a2 = 2)

(A1 = 3a2 = 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 'YouTube'

Comp5 TYPE x

END OF struc.

FIELD-SYMBOLS: TYPE x

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 CASTING

+ off (len) TO CASTING.

Cl_demo_output= > display (

| | Offset off is {off}.\ n | & & |

| | Length len is {len}.\ n | & & |

| points to "{}". |).

ENDMETHOD.

ENDCLASS.

START-OF-SELECTION.

Demo= > main ().

(6) call RFC in full dynamic mode

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) inline function 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 [questions]))

(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 ().

At this point, I believe you have a deeper understanding of "how to use ABAP to improve work efficiency". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report