14.01.2020 Views

ABAP_to_the_Future

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

String Processing 2.3

LD_RESULT = |Monster Number { ld_number } / { ld_status }|.

Listing 2.18 Building Up a String Using Pipes

This gives you much better control of spaces and punctuation and the like; it’s

slightly more difficult to use text symbols but not impossible. Moreover, you can

pass such constructs (the text between the starting | and the ending |) into

parameters of method calls that are ex pecting strings. Previously, you had to

build up the string in a helper variable and then pass that into the method call.

2.3.2 New String Features in Release 7.4

If you’re anything like me, you may spen

d half your life calling the functions

CONVERSION_EXIT_ALPHA_INPUT and CONVERSION_EXIT_ALPHA_OUTPUT to add and

remove leading zeroes from document numbers like delivery numbers; for example,

you might remove the zeroes when showing messages to the user, but then

then add them back before you read the database (Listing 2.19).

“Remove leading zeroes before output to user

CALL FUNCTION ‘CONVERSION_EXIT_ALPHA_OUTPUT’

EXPORTING in = ld_delivery_number

IMPORTING out = ld_delivery_number.

ld_message = |Problem with delivery number { ld_delivery_number }|.

MESSAGE ld_message TYPE ‘I’.

“Now add the leading zeroes back before database read

CALL FUNCTION ‘CONVERSION_EXIT_ALPHA_INPUT’

EXPORTING in = ld_delivery_number

IMPORTING out = ld_delivery_number.

SELECT *

FROM LIKP

INTO CORRESPONDING FIELDS OF ls_delivery_header

WHERE vbeln = ld_delivery_number.

Listing 2.19 Removing and Adding Leading Zeroes by a Function Call

In ABAP 7.4, this can be done in a more compact manner by using the ALPHA formatting

option, which does the exact sa me thing as the two function modules

used in Listing 2.19. To remove the leading zeroes in 7.4, you can write code such

as that in Listing 2.20.

ld_message = |{ ld_delivery ALPHA = OUT }|.

MESSAGE ld_message TYPE ‘I’.

SELECT *

FROM LIKP

97

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!