Abap 010 ABAP Workbench More Basics

12
ABAP Workbench: More Basics Prepared by J Kreie New Mexico State University ABAP Workbench: More Basics This lesson assumes you have already created your first program in ABAP. In this lesson you will modify the first program you created and learn more about ABAP syntax, program structure, and commands. You will also make your program bilingual —showing text in English or Spanish. Modify a program Go to the Object Navigator and open your program in ABAP Editor. In the left navigation pane, you should see your package and below that, under the “Object Name” header, you should be able to expand “Programs” and see your first program. Double-click on that program and its code appears on the pane on the right. When you open the program it is not in edit mode. Click the Display <-> Change icon to switch to edit mode. Add the code shown here. This code has a parameters section and a data section and a processing section. The parameter section sets up a screen for user input. The naming convention is to put a “p” at the beginning of parameter names. The parameter name is limited to 8 characters. The parameters section starts with the word PARAMETERS and a colon. Each parameter definition is followed by a comma until the last one which has a period. The period marks the end of the parameter section. The parameter section shown here defines input for a first name (up to 12 characters and with a default of “Joe”) and a last name. The data section is where variables are declared. The naming convention is to start the variable name with “L” for this local variable that is a character data type (C) with a field size of 24. (See the reference section at the end of this lesson for a hyperlink to SAP Help’s list of predefined data types.) If more than one variable is declared, each definition would end with a comma until the last one which would have a period to end the DATA: section. The remainder of this short program is the processing section with executable statements. First, there is a statement to concatenate the parameter input values for first name and last name into one string variable called l_name. Second, there is a chained write statement with three parts. A chained statement Page 1 of 12

description

Abap 010

Transcript of Abap 010 ABAP Workbench More Basics

Page 1: Abap 010 ABAP Workbench More Basics

ABAP Workbench: More BasicsPrepared by J Kreie

New Mexico State University

ABAP Workbench: More Basics

This lesson assumes you have already created your first program in ABAP. In this lesson you will modify the first program you created and learn more about ABAP syntax, program structure, and commands. You will also make your program bilingual—showing text in English or Spanish.

Modify a program

Go to the Object Navigator and open your program in ABAP Editor. In the left navigation pane, you should see your package and below that, under the “Object Name” header, you should be able to expand “Programs” and see your first program. Double-click on that program and its code appears on the pane on the right. When

you open the program it is not in edit mode. Click the Display <-> Change icon to switch to edit mode.

Add the code shown here. This code has a parameters section and a data section and a processing section.

The parameter section sets up a screen for user input. The naming convention is to put a “p” at the beginning of parameter names. The parameter name is limited to 8 characters. The parameters section starts with the word PARAMETERS and a colon. Each parameter definition is followed by a comma until the last one which has a period. The period marks the end of the parameter section. The parameter section shown here defines input for a first name (up to 12 characters and with a default of “Joe”) and a last name.

The data section is where variables are declared. The naming convention is to start the variable name with “L” for this local variable that is a character data type (C) with a field size of 24. (See the reference section at the end of this lesson for a hyperlink to SAP Help’s list of predefined data types.) If more than one variable is declared, each definition would end with a comma until the last one which would have a period to end the DATA: section.

The remainder of this short program is the processing section with executable statements. First, there is a statement to concatenate the parameter input values for first name and last name into one string variable called l_name. Second, there is a chained write statement with three parts. A chained statement eliminates the need to keep repeating the same command, such as WRITE. WRITE, in this case, is followed by a colon and then multiple parts are listed with each part separated by a comma. The last part ends with the period to terminate the statement. We used the same chained structure for the PARAMETERS section of this program.

Save, check, activate and test your program. Below are examples of input and output screens.

Initial input screen. Default values are shown.

Page 1 of 8

Page 2: Abap 010 ABAP Workbench More Basics

ABAP Workbench: More BasicsPrepared by J Kreie

New Mexico State University

Default values are replaced with user input.

Program output screen.

Copying a program

In the left pane of the Object Navigator, use the context menu (right-click) for your existing program to select Copy. In the dialog box change the target program to ‘second_program’.

In the next dialog box, click Copy without changing any options.

Assign the program to your package and transport request. Your package name should appear automatically as the default choice if you haven’t logged off from SAP since you completed the first lesson.

If the package name doesn’t appear automatically, hit F4 or click the value search icon to locate your package. In the search screen you can use a wildcard character with some text. The example shown will search for any package name that starts with “z_jkra”. The asterisk is the

“wildcard” which accepts in text.

If the initial string of characters used in your search is specific enough, you should only see your package. Double-click it and you will return to the package assignment dialog box. Click the Save icon.

Page 2 of 8

Page 3: Abap 010 ABAP Workbench More Basics

ABAP Workbench: More BasicsPrepared by J Kreie

New Mexico State University

In the next screen, if you’re not sure the correct transport request number appears, click the search icon and find your transport request from the list shown.

Now, you have a copy of your first program.

Open your second program and switch to edit mode ( ).

Since this is a copy of your first program, it is important that you change the program comment header to match this program name.

By the way, notice the red triangle to the left of the edited line? The new ABAP Editor interface, which we set in lesson one, shows new/changed lines with this red mark.

Create Text Symbols

You’re going to make your program bilingual by using text symbols. A text symbol is one of the text elements ABAP uses to support text display in multiple languages.

To create the text symbols, use the SAP menu path: Goto ... Text Elements … Text Symbols.

Create text symbols, as shown. Be sure to set the maximum length (mLen). If you don’t, ABAP will set it to the length of text currently shown but the translation in another language may need more characters. The dLen field will automatically update after your input has been made.

Save and activate the text symbols. Don’t forget to activate!

Create translations

To create translations, use the SAP menu path: Goto … Translation.

When prompted enter ‘ES’ (Español) for the target language.

Page 3 of 8

Page 4: Abap 010 ABAP Workbench More Basics

ABAP Workbench: More BasicsPrepared by J Kreie

New Mexico State University

Enter Spanish versions of the text. Notice that the program is automatically included in the translation.

Save your translations. (Don’t worry about the “still 3 of 3 texts to be processed” message in the status line. Translations grow through an approval process which we’ll never complete in these lessons.)

Use the Back button to return to the Text Element screen then back to your program.

Modify your program so that it uses the text symbols you created. Notice the “text-001” and “text-002” changes in the WRITE statement. These are not in quotes in the program.

Save, check, activate and test your program. The output is still in English, isn’t it?

To see the effect of text symbols and translations log off of SAP. When you log back in, enter ES as the language.

You may not know Spanish but you’re familiar enough with SAP to navigate to the Object Navigator in ABAP Workbench. Open your program and test it. The input screen has a Spanish title with the variable names the same as before but the output screen displays the Spanish translation of your program.

Log off and log back in using English. You can enter EN or leave it blank if that’s the default language for your SAP installation.

Set the text display for parameters

Open your second program. The last thing you will modify in this program is the input screen display for the parameters. Right now, the user sees ‘p_fname’ and ‘p_lname’, not very helpful to the program user. To change the input display, we will work with another type of ABAP text element called selection text.

Page 4 of 8

Page 5: Abap 010 ABAP Workbench More Basics

ABAP Workbench: More BasicsPrepared by J Kreie

New Mexico State University

Use the SAP menu path Goto … Selection Texts. Enter text for each parameter as shown.

Save and activate your changes.

To test the selecton text, run the program. You’ll see the selection text instead of the parameter names.

This is all you would need to do for the English version of your program but you need to create a version in Spanish.

Create a translation using Goto … Translation. Enter ES as the target language. Enter the Spanish text and save.

Return to the Text Element screen. Save and activate your text elements. Run your program.

To test your program you’ll need to log in with Spanish (ES) as your language.

Though you’ll do some more translations in the upcoming lessons, in the future you probably won’t code the translation of your programs when you work on a development team. That can be done by a professional translator after you have completed your work on the project. However, you can see that it is important to understand text elements so the programs you create in SAP can be made multilingual.

Create a transaction code

The final step in this lesson is to create a transaction code for your second program. Open the Object Navigator. Open the context menu (right-click) for your second program. Select Create … Transaction.

Page 5 of 8

Page 6: Abap 010 ABAP Workbench More Basics

ABAP Workbench: More BasicsPrepared by J Kreie

New Mexico State University

Enter the transaction code based on this template:

Z_$$$$_p2

Enter the Short text and select the option “Program and selection screen (report transaction).”

You now see the Create Report Transaction screen in the Object Navigator. Type the name of your program in the box and select the GUI support shown.

Save and assign the transaction to your package and transport request.

Page 6 of 8

Page 7: Abap 010 ABAP Workbench More Basics

ABAP Workbench: More BasicsPrepared by J Kreie

New Mexico State University

To test your transaction code, exit the Object Navigator and return to the SAP Easy Access menu.

Exit Object Navigator. Enter your transaction code in the command field of the SAP Easy Access menu.

Now, add this transaction to your Favorites area. Use the context menu for Favorites to select Insert Transaction. Type the transaction code for you program.

Your SAP Easy Access menu should look something like this.

Practice

Practice what you learned in the first two lessons by completing the following tasks. It’s very important that you continue to use the naming convention for the prefix of anything you create.

Z_$_<the name you decide to use>

Create a new package and a new transport request. Use these. Do NOT put anything you create in this practice exercise in the package you are using for the lessons.

Create a program that uses an input screen to gets two integers from the user. Calculate the sum and product of these two numbers. Create an output screen that displays the results. Both the input and output screen should display standard English, not variable names. Both input and output should be viewable in Spanish, as well.

Page 7 of 8

Page 8: Abap 010 ABAP Workbench More Basics

ABAP Workbench: More BasicsPrepared by J Kreie

New Mexico State University

Terms to Know

chained statement.................................................................................................................................................. 1data section............................................................................................................................................................ 1parameter section................................................................................................................................................... 1selection text........................................................................................................................................................... 3text elements.......................................................................................................................................................... 2text symbol............................................................................................................................................................. 2

References

ABAP Basics, Gunther Farber and Julia Kirchner, SAP PRESS/Galileo Press, 2007.

ABAP Objects: An Introduction to Programming SAP Applications, Horst Keller and Sascha Kruger, SAP PRESS/Pearson Education Limited, 2002.

ABAP predefined dataypes (hyperlink to SAP Help)

Babelfish.yahoo.com (for language translations)

Page 8 of 8