Студопедия
Случайная страница | ТОМ-1 | ТОМ-2 | ТОМ-3
АрхитектураБиологияГеографияДругоеИностранные языки
ИнформатикаИсторияКультураЛитератураМатематика
МедицинаМеханикаОбразованиеОхрана трудаПедагогика
ПолитикаПравоПрограммированиеПсихологияРелигия
СоциологияСпортСтроительствоФизикаФилософия
ФинансыХимияЭкологияЭкономикаЭлектроника

Wa-percentage, ’%’.

Pa_int1 TYPE i, pa_op(1) TYPE c, pa_int2 TYPE i. | DATA result TYPE p DECIMALS 2. | ENDLOOP. ENDIF. | Wa_flight-seatsocc / wa_flight-seatsmax. | INSERT wa_flight INTO TABLE it_flight. | ID ’ACTVT’ FIELD ’02’. | SELECT-OPTIONSname FORdata_object. | MESSAGE e045(bc400) WITH pa_car. ENDIF. | CALL SCREEN 100. | CLEAR wa_sbook. |



ENDFORM. " WRITE_LIST


 

LessonSummary

You should now be able to:

• Define subroutines

• Call subroutines

• Analyze the execution of subroutines in debugging mode


 

UnitSummary

You should now be able to:

• Define subroutines

• Call subroutines

• Analyze the execution of subroutines in debugging mode

 

Related Information

 

... Refer to the online documentation for the relevant ABAP statement.


 

Unit 8

 

201 IntroductiontoABAPEvents

 

 

See the introductory instructors’ note in the lesson

 

Unit Overview

 

Refer to the lesson summaries for an overview of this unit.

 

 

UnitObjectives

After completing this unit, you will be able to:

 

• Describe the event-controlled processing of an executable ABAP program

• List the most important basic events and explain their purpose

• Use the most important basic events expediently

 

 

Unit Contents

 

Lesson: ABAP Events..........................................................222


 


Lesson:

202


ABAP Events

 

Lesson Duration: 20 Minutes

 

 

Lesson Overview

 

In this lesson, you will find out how an executable ABAP program is processed in an event-controlled manner. You will learn about the most important basic events as well as their purposes and you will be able to use them in your programs.


 

 

 
Lesson Objectives

 

After completing this lesson, you will be able to:

 

• Describe the event-controlled processing of an executable ABAP program

• List the most important basic events and explain their purpose

• Use the most important basic events expediently

 

 

 
Event control is an SAP-specific concept. The purpose of this lesson is to explain the way the ABAP runtime system works with regards to an executable (type

1) program.

 

The participants are to learn about the most important basic events, understand their purpose, and be able to use them in their programs.


 

We will also illustrate how a more complex, executable program is structured and why earlier programs could be executed.

 

Hint: The LOAD-OF-PROGRAM event, which has existed in parallel to INITIALIZATION since Release 4.6 and was previously taught unnecessarily in this course in connection with executable programs, has now been replaced with INITIALIZATION for the following reasons:

 

• LOAD-OF-PROGRAM has been mainly designed for use in function groups and module pools that did not have a “start action” prior to 4.6. INITIALIZATION is still used for executable programs in order to implement the dynamic default settings for the selection screen. (See also the documentation for the corresponding events)

• Using LOAD-OF-PROGRAM in an executable program can have undesirable side effects, which the following mini program illustrates:

 

PARAMETERS myvar TYPE i DEFAULT 10. LOAD-OF-PROGRAM.

(IF...) " optional, not important here myvar = myvar + 1.

(ENDIF.)

 

 

Why does a 1 appear instead of 11 as the default value on the selection screen?

 

The reason for that is:

 

– in contrast to INITIALIZATION, the LOAD-OF-PROGRAM event is triggered before(!) executing the DEFAULT additions of PARAMETERS or SELECT-OPTIONS statements and

– DEFAULT additions are evaluated only if the value of the corresponding data object is still initial.

 

If INITIALIZATION was used in the mini program, 11 would appear as the default value on the selection screen as INITIALIZATION is only triggered after the DEFAULT additions have been evaluated.

 

Business Example

 

You are to prepopulate your selection screen with default values dynamically

(i.e. with reference to the situation).


 

Purpose and Usage of ABAP events

 

 

 

 

 

Figure 125: Structures and Procedures of an Executable ABAP Program

 

When you start an ABAP program, all global data objects of the programs are first created in the working memory (memory allocation). After that, the runtime system triggers various events in succession. If a processing block exists for a triggered event in the program, then the statements of this block are executed

in sequence.

 

The graphic above shows which basic events are triggered in which sequence and how the corresponding processing blocks are implemented in the program. An executable ABAP program is a collection of processing blocks that are processed for the respective events.

 

Outputs created by means of WRITE statements are first stored in list buffers and only displayed as a list once the START-OF-SELECTION block has been processed.


 

 

 

 
Figure 126: Purpose of ABAP Events

 

If values are assigned to the PARAMETERS variables in the INITIALIZATION

block, then these are displayed as (changeable) default values in the input

fields when the selection screen is displayed subsequently. You do have the option of specifying a default value for the respective input field in the PARAMETERS definition by means of the DEFAULT addition. However, you can use the described value assignment in the INITIALIZATION block to assign another default value (dynamic prepopulation of the selection screen) in a runtime-dynamic manner (meaning with reference to the situation). The example program on the next graphic illustrates this.

 

If the user confirms with the F8 pushbutton on the selection screen, then his inputs are transported into the corresponding program-internal PARAMETERS variables and the AT SELECTION-SCREEN event is triggered. Hence the corresponding processing block is suitable for an input or authorization check. The sending

of a type 'E' message in this event block (for example, in case of a missing user authorization) would cause the selection screen to be displayed again with the error message (so that a new entry can be made). The “selection screen” lesson explains this in more detail.

 

If no error message is sent in the AT SELECTION-SCREEN block, then START-OF-SELECTION is triggered as the subsequent event. The main processing of the program should then happen in the corresponding processing block.


 

 
The general input or authorization checks are implemented in the AT SELECTION-SCREEN block and, if necessary, an error message is sent in order to process the selection screen for a new entry. For the time being the latter should be mentioned without an example as more details are provided in the “selection screen” lesson. It should be emphasized that the option of displaying the selection screen again is no longer given in the START-OF-SELECTION block to further emphasize the difference between these two events.

 

 

 

 

 
Figure 127: Example Program

 

The example given here contains a selection screen with an input field for a date. Under normal circumstances, the current date is to appear as the default value (DEFAULT sy-datum). However, under certain conditions (IF) the date of the same weekday of the following week (pa_date = pa_date + 7.) is to be displayed as the default value.

 

The graphic above also shows how the runtime system reacts when the processing block is missing. There are simply no statements executed for the corresponding event and the next event is triggered.


 

 
To demonstrate this, the above example program should be shown without the AT SELECTION-SCREEN block (maybe using the debugger). It is not available as a standard demonstration in the system, as it is up to the instructor to decide which dynamic check condition is used. For example, the following options are available:

 

IF sy-datum = ’20051231’. IF sy-langu = ’D’.

IF sy-uname = <name of instructor>.

 

 

 

 

Figure 128: Event Block Characteristics

 

Processing blocks cannot be nested as nesting would contradict the concept of

ABAP events.

 

As mentioned, if the processing block is missing no statements are executed and the next event is triggered.

 

The ABAP runtime system controls the triggering of the events and thus the execution of the processing blocks. Therefore, the sequence in which the event blocks are placed in the program is not important.

 

If no blocks are implemented in the program, then all statements are implicitly assigned to the standard processing block START-OF-SELECTION. That is also the reason why earlier programs of this course could be executed.

 

Apart from the already explained basic events for executable programs, there are further events for various other tasks. For example, there is the AT LINE-SELECTION event that is triggered by the user double-clicking on the list. This event can be used, for example, to display the detailed information for the row in the list that was clicked on. The “list” lesson provides more information on this. You can find further documents in the ABAP documentation for the term “event”.

 

The following graphic shows the general overall structure of an executable ABAP

program.


 

 

 

 
Figure 129: Program Structure (Overview)

 

In addition to the already explained event blocks other processing blocks can be implemented in the program. For example, a subroutine (FORM... ENDFORM.) is a block executed for the “event” triggered by PERFORM.

 

If you want to send the user a screen, then you must have defined this for the program in advance. Apart from the layout, the so-called flow logic of the screen also has to be implemented. This specifies, which program-internal processing units (modules) are to be executed in preparation for the screen display (for example, reading the data to be displayed) or as a reaction to the user actions on the screen. This is called the Process Before Output (PBO) or Process After Input (PAI) of the screen. Together, they form the flow logic of the screen.

The flow logic does not contain any direct ABAP statements but references to modules that are implemented in the program in the form of processing blocks (MODULE... ENDMODULE.). The appropriate lesson provides more information on screen programming.


 

 
Facilitated Discussion

 

You now have the opportunity to discuss any questions.

 

 

Discussion Questions

Use the following questions to engage the participants in the discussion. Feel free to use your own additional questions.

 

See list of lesson objectives.


 

LessonSummary

You should now be able to:

• Describe the event-controlled processing of an executable ABAP program

• List the most important basic events and explain their purpose

• Use the most important basic events expediently


 

UnitSummary

You should now be able to:

• Describe the event-controlled processing of an executable ABAP program

• List the most important basic events and explain their purpose

• Use the most important basic events expediently

 

Related Information

 

... Refer to the article “Event Blocks” in the online documentation and to the keyword documentation for the relevant ABAP statement.


 


 

Unit 9

 

209 Userdialogs

 

 

See the introductory instructors’ notes in the lessons

 

Unit Overview

 

Refer to the lesson objectives for an overview of this unit.

 

 

 
Unit Objectives

 

After completing this unit, you will be able to:

 

• Describe the attributes and benefits of ABAP lists

• Implement list and column headers

• Implement multi-level lists

• Implement interactive lists

• List the properties and benefits of selection screens

• Implement the options for restricting selections on the selection screen

• Implement the input and authorization check with an error dialog using the selection screen

• List attributes and benefits of screens

• Implement a simple screen with input and output fields as well as pushbuttons and call it from your program

• Explain and implement the program-internal processing for screen calls

• Implement a GUI title

• Implement a GUI status (menu bar, symbol toolbar and application toolbar)

for the list and screen

• Maintain the function key assignment of the screen

 

 

Unit Contents

 

Lesson: List......................................................................235


 

Exercise 12: List............................................................247

Lesson: Selection Screen......................................................255

Exercise 13: Selection Screen............................................267

Lesson: Screen.................................................................273

Exercise 14: Creating and Calling a Screen............................301

Exercise 15: Screens: Data Transport..................................307

Exercise 16: Screens: Specifying the Next Screen Dynamically....313

Lesson: User Interface.........................................................320

Exercise 17: Creating an Interface.......................................331


 


Lesson:

211


List

 

Lesson Duration: 110 Minutes

 

 

Lesson Overview

 

In this lesson, you will learn about the benefits and different functions of the ABAP list. You will also be able to react to the user double-clicking the basic list by showing a details list that contains detailed information on the basic list rows that have been clicked (interactive list).


 

 
Lesson Objectives

 

After completing this lesson, you will be able to:

 

• Describe the attributes and benefits of ABAP lists

• Implement list and column headers

• Implement multi-level lists

• Implement interactive lists

 

 

 
Details lists are a very good example of how event-controlled programming saves the application developer a lot of work. You should emphasize this.

 

 

Business Example

 

You need to writea program that displays row-specific information in a details list when the user chooses a row in a basic list.


 

The List

 

 

 

 

Figure 130: Features of Lists

 

The main purpose of a list is to display data with a minimum of programming efforts. Lists also take the special requirements of business data into account:

 

• Lists can be designed in multiple languages: Texts and headers appear in the logon language whenever a corresponding translation is available.

• Lists can display monetary values in the appropriate currency. The following options are available when programming a list:

• Screen: You can add colors and icons

• Printers

• Internet/Intranet: The system is able to automatically convert to HTML.

• Save: You can save lists within the SAP system as well as outside (for further processing, for example, using spreadsheet programs).

 

 

 
In the following section, show the standard list functions, primarily the menu System → List. Furthermore, you should demonstrate list headers, text symbols and the multilingual capability.


 

 

 
Figure 131: Standard List Functions

 

The standard list GUI offers the user several functions:

 

You can use the Menu Painter to adapt the default list interface to your own needs. The “User Interface” lesson provides more information on this.

 

 

 

 

 

Figure 132: List and Column Headers


 

Each list can have a single line list header and up to four lines of column headers. If no list header is defined, the program title (short description) is used as the header.

 

For the initial maintenance of the headlines, you must first activate your program. Afterwards, create the list by running the program. You can then maintain the headers directly above your list using the menu System → List → List Header. The next time you start the program, they will appear in the list automatically.

 

If you want to change the maintained header (follow-up maintenance), then you do not have to start the program again and generate the list. Instead, starting from the editor into which the program is loaded you can get to the maintenance environment for changing the headers by choosing Goto → Text Elements →

List Headers.

 

 

 

Figure 133: Multilingual Capabilities of Lists

 

The text elements of a program - this also includes the header - can be translated into different languages. When a user executes a program, relevant text elements are always automatically displayed in the logon language of the user (automatic language).

 

To translate the text elements of your program choose the Menu Goto →

Translation from the ABAP-Editor.


 

In order to design texts in the list body in multiple languages and use the automatic language, text symbols are used. A text symbol consists of a three-digit alphanumeric ID xxx as well as a translatable text and, like the headers, belongs to the text elements of a program. There are two options for defining

text symbols for your program:

 

• From the ABAP Editor, choose the menu Goto → Text Elements → Text

Symbols or

• you address the text symbol in your source code using the syntax described below and double-click its ID (Forward navigation).

 

From your program, you address a text symbol with TEXT-xxx. At runtime the text is inserted in the logon language of the user if the appropriate translation exists (see “translating the text elements” above).

 

In order to make specifying a text symbol more intuitive you can also use the following syntax instead of TEXT-xxx: ’...’(xxx). Here, ’...’ should be the text of the text symbol in the original language of the program.

 

Hint: Please note that text elements also have to be activated.

 

 

 

 

Figure 134: Generating a Basic List

 

The above graphic shows the generation of the basic list as an introduction to the details list. In addition to the WRITE statement, you can also use SKIP and ULINE to structure the list. Refer to the ABAP keyword documentation for these two statements.


 

 

 

 
Figure 135: Generating a Details List

 

When the user selects a basic list by means of double-click or function key F2, the ABAP event AT LINE-SELECTION is triggered. If you want to have the system display a list with the required detailed information (interactive list) as the response to this user action, then you must implement this in your program in the form of a corresponding processing block. There, you can read the data requested by the user and output them with the WRITE statement. The details list with the output data, which “overwrites” the basic list, is generated automatically. By pressing the pushbutton with the “green arrow” or the F3 function key, the user can return to the basic list and choose another row.

 

Hint: If an AT LINE-SELECTION block is implemented in the program, then a pushbutton with the magnifying glass symbol also appears above the list. Marking the list row and then choosing this button has the same effect as double-clicking the list row.


 

 

 
Figure 136: Generating Several Details Lists

 

The row selection on the detail list also triggers the AT LINE-SELECTION event. This means that the corresponding processing block in the program is executed in this case as well. Hence you must be able to determine within this block on which list the current row selection was made so that you can react adequately. You can use the sy-lsind system field for this. This field shows the current list level: “0” for the basic list, “1” for the first details list, and so on. The above graphic shows the value of sy-lsind and how it is set in each case: Each row selection automatically increases sy-lsind by 1; each return to the previous list level reduces sy-lsind by 1. Up to 20 list levels are possible.

 

The value of sy-lsind should be used to control processing in the AT LINE-SELECTION block (for example, by means of a CASE statement).

 

A WRITE statement is always executed on the current list level.

 

If no details list is generated for a row selection in the AT LINE-SELECTION block, then sy-lsind is automatically reduced by one. Afterwards, the system displays the same level where the row selection took place.


 

 

 

 
Figure 137: Simple Syntax Example

 

The above example program has the following function:

 

• On the basic list, the text “Basic list” is output followed by the current

sy-lsind value of 0.

• When a basic list row is selected, the text “1st details list” is displayed on the details list followed by the current sy-lsind value of 1.

• When the user selects a row from the details list, he or she gets a second details list on which the text “2nd details list” appears followed by the current sy-lsind value of 2.

• If a line of the seconds details list is selected, sy-lsind is increased to 3 but no further details list is generated. Hence sy-lsind is automatically reduced by 1 and the second details list is displayed again.


 

 

 

 
Figure138:ApplicationExampleofaDetailsList

 

 
Program SAPBC400UDD_DETAIL_LIST of pack- age BC400 is suitable for the demonstration.

If necessary, you can also demonstrate the selection of an invalid

line. Such an action should not have any effects. This can be implemented using the CLEAR commands and the CHECK NOT wa_spfli-carrid IS INITIAL. statement. All three statements are still commented out in the program so that you can give a meaningful demonstration. If necessary, the comments should be removed in a copy of the program. The exercise follows this section.

 

 

The above graphic shows an application example for a program with a basic list and a details list:

 

• The flight connections with detailed data should be displayed on the basic list. These are read from database table SPFLI.

• On the details list, the flight schedules for the selected flight connection should appear with the respective detailed data. These are read from database table SFLIGHT.

 

In order to be able to select relevant information for the details list when a basic list row is selected, the selected row or at least the key values of the row must be available for the AT LINE-SELECTION event. The following graphics show you how this can be implemented.


 

 

 

 
Figure 139: Buffering Row-Specific Data in the Hide Area

 

In order to be able to access the key values of the selected row when a basic list row is selected, you have to implement the following concept:

 

• For each basic list row, the relevant key values are stored in the HIDE area

within the program.

• When a row is selected the data that has been hidden for that particular row will be made available again.

 

The row-specific holding of key values in the HIDE area happens by means of the HIDE statement (here: HIDE: wa_spfli-carrid, wa_spfli-connid.), which must be executed directly after generating each basic list row. When the row is selected, the relevant key values are transported back to the source fields (here: wa_spfli-carrid and wa_spfli-connid) and the AT LINE-SELECTION event is triggered. The following graphic illustrates this.

 

Hint: You do not have to output the HIDE fields with the WRITE statement first. That means: For each basic list row, you can also store information that does not appear on the basic list in the HIDE area by means of the HIDE statement. The HIDE field can also be a “flat” structure.


 

 

 

 
Figure 140: Data Flow for the Row Selection

 

Hint: Details lists do not have fixed standard headers like basic lists as they can be varied dynamically. Hence, you might have to implement your own headers using WRITE statements.

 

The following graphic shows the entire AT LINE-SELECTION block of the example program. In this block, basically data (here: flight schedules) is read and output by means of the HIDE values that have been transported back to the source fields.


 

 

 
Figure 141: Source Code Excerpt (Application Example)

 

Hint: The sample program presented is SAPBC400UDD_DE- TAIL_LIST, part of package BC400.


 

 

223 Exercise 12: List

 

Exercise Duration: 50 Minutes

 

 

Exercise Objectives

 

After completing this exercise, you will be able to:

• Implement details lists in the program

 

 

Business Example

 

When a basic list row is selected by the user, your program should display the corresponding information on a details list.

 

 

 
When you discuss the exercise you should explain to the participants that the two CLEAR statements in the sample solution are useful. They serve to catch an invalid row selection (e.g. double-click list header). Without CLEAR statements “old wa_flight data” would be used to generate a details list for an invalid row selection. With CLEAR statements, a blank details list would be generated. If you do not wish to generate a details list at all, then a wa_flight check is also required in the AT LINE-SELECTION block (see program SAPBC400UDS_DETAIL_LIST2).

 

 

System Data

 

System: Will be assigned Client: Will be assigned User ID: Will be assigned Password: Will be assigned

Set up instructions: No special instructions when using a standard training system

 

Task 1:

 

Prepare the generation of the details list

 

1. Copy your program ZBC400_##_SELECT_SFLIGHT or the corresponding template SAPBC400DDS_AUTHORITY_CHECK to the new program ZBC400_##_DETAIL_LIST.

 

2. Ensure that the relevant key values for the creation of the details list are available to your program when a basic list row (specific flight date) is selected.

 

3. In your program, implement a function block for generating the basic list and one for the details list.

 

Continued on next page


 

Task 2:

 

Create the details list

 

1. In the first line of the details list, display key information from the selected flight schedule. Underneath, display a horizontal line and a blank line.

 

2. Retrieve all bookings for the selected flight schedule from database table SBOOK and output them on the details list. Read only the following fields for output for each booking:

 

BOOKID, CUSTOMID, CUSTTYPE, CLASS, ORDER_DATE, SMOKER, CANCELLED.

 

3. Optional: Display the fields LOCCURAM and LOCCURKEY on the details list: Use the CURRENCY addition of the WRITE statement to make sure that the currency amount LOCCURAM is formatted according to the currency LOCCURKEY.

 

Hint:

 

WRITE: wa_sbook-loccuram

CURRENCY wa_sbook-loccurkey, wa_sbook-loccurkey.

 

4. Optional: Display the BOOKID field in the color COL_KEY.


 

Solution 12: List

 

Task 1:

 

Prepare the generation of the details list

 

1. Copy your program ZBC400_##_SELECT_SFLIGHT or the corresponding template SAPBC400DDS_AUTHORITY_CHECK to the new program ZBC400_##_DETAIL_LIST.

 

a) Carry out this step as usual.

 

2. Ensure that the relevant key values for the creation of the details list are available to your program when a basic list row (specific flight date) is selected.

 

a) See source code excerpt in the model solution.

 

3. In your program, implement a function block for generating the basic list and one for the details list.

 

a) See source code excerpt in the model solution.

 

Task 2:

 

Create the details list

 

1. In the first line of the details list, display key information from the selected flight schedule. Underneath, display a horizontal line and a blank line.

 

a) See source code excerpt in the model solution.

 

2. Retrieve all bookings for the selected flight schedule from database table SBOOK and output them on the details list. Read only the following fields for output for each booking:

 

BOOKID, CUSTOMID, CUSTTYPE, CLASS, ORDER_DATE, SMOKER, CANCELLED.

 

a) See source code excerpt in the model solution.

 

Continued on next page


 

3. Optional: Display the fields LOCCURAM and LOCCURKEY on the details list: Use the CURRENCY addition of the WRITE statement to make sure that the currency amount LOCCURAM is formatted according to the currency LOCCURKEY.

 

Hint:

 

WRITE: wa_sbook-loccuram

CURRENCY wa_sbook-loccurkey, wa_sbook-loccurkey.

 

a) See source code excerpt in the model solution.

 

4. Optional: Display the BOOKID field in the color COL_KEY. a) See source code excerpt in the model solution.

 

 

Result

 

Source code excerpt (without optional parts): SAPBC400UDS_DETAIL_LIST

 

REPORT sapbc400uds_detail_list.

CONSTANTS actvt_display TYPE activ_auth VALUE ’03’. DATA: wa_flight TYPE sbc400focc,

wa_sbook TYPE sbook. PARAMETERS pa_car TYPE s_carr_id.

 

START-OF-SELECTION.

 

 

AUTHORITY-CHECK OBJECT ’S_CARRID’ ID ’CARRID’ FIELD pa_car

ID ’ACTVT’ FIELD actvt_display.

 

 

CASE sy-subrc.

WHEN 0.

SELECT carrid connid fldate seatsmax seatsocc FROM sflight

INTO CORRESPONDING FIELDS OF wa_flight

WHERE carrid = pa_car. wa_flight-percentage =

100 * wa_flight-seatsocc / wa_flight-seatsmax.

 

Continued on next page


 

 

WRITE: / wa_flight-carrid, wa_flight-connid, wa_flight-fldate, wa_flight-seatsocc, wa_flight-seatsmax, wa_flight-percentage,’%’.

* Hide key values of the current line


Дата добавления: 2015-11-16; просмотров: 77 | Нарушение авторских прав


<== предыдущая страница | следующая страница ==>
WRITE: / ’Authority-Check Error’(001). ENDCASE.| Wa_sbook-loccurkey.

mybiblioteka.su - 2015-2024 год. (0.134 сек.)