BC ABAP Programming PHẦN 9 ppt

153 308 0
BC ABAP Programming PHẦN 9 ppt

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

SAP AG BC - ABAP Programming Using Logical Databases December 1999 1227 Using Logical Databases There are two ways of using a logical database: Either by linking it with an executable program, or by using the function module LDB_PROCESS in any ABAP program. BC - ABAP Programming SAP AG Using Logical Databases 1228 December 1999 Struktur Selektionen Struktur Selektionen Event block GET TABLE Event block GET TABLE Executable program Declarations NODES TABLES Declarations NODES TABLES Selection Selection screen screen Program Function group CALL FUNCTION LDB_PROCESS CALL FUNCTION LDB_PROCESS FORM CALLBACK ENDFORM FORM CALLBACK ENDFORM FUNCTION LDB_PROCESS ENDFUNCTION. FUNCTION LDB_PROCESS ENDFUNCTION. Logical database Logical database Database Structure Structure Selections Selections Database program Database program SAP AG BC - ABAP Programming Using Logical Databases December 1999 1229 When you link a logical database to an executable program, the user can enter values on the selection screen, and the data read by the logical database is passed back to the program using the interface work areas. If you call the logical database using a function module, the selection screen is not displayed. The calling program does not have to provide interface work areas. Instead, it uses special subroutines called callback routines, which are called by the function module and filled with the required data. Linking a Logical Database to an Executable Program [Page 1230] Calling a Logical Database Using a Function Module [Page 1234] BC - ABAP Programming SAP AG Linking a Logical DB to an Executable Program 1230 December 1999 Linking a Logical DB to an Executable Program When you link an executable program to a logical database by entering the name of the logical database in the program attributes, the subroutines of the logical database program and the event blocks of the executable program form a modularized program for reading and processing data. The individual processing blocks are called in a predefined sequence by the runtime environment (see the diagram in the section Logical Databases and Contexts [Page 60]). The runtime sequence is controlled by the structure, selections, and PUT statements in the logical database, and by the GET statements in the executable program. Selection Screen If you specify a logical database in the attributes of an executable program, this affects the standard selection screen of the program. It contains both the selection fields from the logical database and those from the program itself. You can specify which of the logical database selections are relevant for your program, and should therefore appear on the screen, by declaring interface work areas for the relevant nodes. Runtime Behavior The following list shows the sequence in which the ABAP runtime environment calls the subroutines of the logical database and the event blocks in the executable program [Page 992]. The runtime environment executes a series of processors (selection screen processor, reporting processor). The ABAP code listed below shows the processing blocks that belong to the individual steps. 1. Initialization before the selection screen is processed. Subroutine: FORM INIT This subroutine is called once only before the selection screen is first displayed. Event block: INITIALIZATION. This event occurs once only before the selection screen is first displayed. 2. PBO of the Selection screen Initialization before each occasion on which the selection screen is displayed (for example, to supply default values for key fields). Subroutine: FORM PBO. This subroutine is called each time the selection screen is sent (before it is displayed). Event block: AT SELECTION-SCREEN OUTPUT. This event is called each time the selection screen is sent (before it is displayed). 3. The selection screen is displayed at the presentation server, and the user can enter data in the input fields. 4. Input help (F4) or field help (F1) requests. SAP AG BC - ABAP Programming Linking a Logical DB to an Executable Program December 1999 1231 Subroutines: FORM <par>_VAL. FORM <selop>_VAL. FORM <selop>-LOW_VAL. FORM <selop>-HIGH_VAL. If the user requests a list of possible entries for database-specific parameters <par> or selection criteria <selop>, these subroutines are called as required. If the user requests field help for these parameters, the subroutines are called with the ending _HLP instead of _VAL. Event blocks: AT SELECTION-SCREEN ON VALUE-REQUEST FOR <par>. AT SELECTION-SCREEN ON VALUE-REQUEST FOR <selop>-LOW. AT SELECTION-SCREEN ON VALUE-REQUEST FOR <selop>-HIGH. If the user requests a list of possible entries for database-specific parameters <par> or selection criteria <selop>, these events are triggered as required. If the user requests field help for these parameters, the events with the addition ON HELP-REQUEST occurs instead of ON VALUE-REQUEST. 5. PAI of the selection screen. Checks to see whether the user has entered correct, complete, and plausible data. Also contains authorization checks. If an error occurs, you can program a user dialog and make the relevant fields ready for input again. Subroutines: FORM PAI USING FNAME MARK. The interface parameters FNAME and MARK are passed by the runtime environment. FNAME contains the name of a selection criterion or parameter on the selection screen. If MARK = SPACE, the user has entered a simple single value or range selection. If MARK = '*', the user has also entered selections on the Multiple Selection screen. Using the combination FNAME = '*' and MARK = 'ANY', you can check all entries at once when the user chooses a function or presses ENTER. Event blocks: AT SELECTION-SCREEN ON <fname>. Event for processing a particular input field. AT SELECTION-SCREEN ON END OF <fname>. Event for processing multiple selections. AT SELECTION-SCREEN. Event for processing all user input. 6. Processing before reading data. Subroutine: BC - ABAP Programming SAP AG Linking a Logical DB to an Executable Program 1232 December 1999 BEFORE EVENT 'START-OF-SELECTION'. The logical database can use this subroutine for necessary actions before reading data, for example, initializing internal tables. Event block: START-OF-SELECTION. First event in an executable program after the selection screen has been processed. You can use this event block to prepare the program for processing data. 7. Reading data in the logical database and processing in the executable program. Subroutine: FORM PUT_<node> The logical database reads the selected data of the node <node>. Event block: GET <table> [LATE]. This event is triggered by the PUT statement in the above subroutine. This event block allows you to process the data read for <node> in the corresponding interface work area. 8. Processing after reading data. Subroutine: AFTER EVENT 'END-OF-SELECTION'. The logical database can use this subroutine for necessary actions after reading data, for example, releasing memory space. Event block: END-OF-SELECTION. Last reporting event. You can use this event block to process the temporary dataset that you have created (for example, sort it). 9. If a list was generated during the above steps, the list processor in the runtime environment takes control of the program and displays the list. Suppose TABLE1 is the root node and TABLE2 is its only subordinate node in a logical database. The processing steps for reading and processing data would then have the following hierarchical order: START-OF-SELECTION. FORM PUT_TABLE1. GET TABLE1. FORM PUT_TABLE2. GET TABLE2. GET TABLE1 LATE. SAP AG BC - ABAP Programming Linking a Logical DB to an Executable Program December 1999 1233 END-OF-SELECTION. Authorization Checks in Logical Databases It makes sense to use authorization checks using the AUTHORITY-CHECK [Page 506] statement in the following subroutines in the database program or event blocks of the executable program: • Subroutines in the database program: − PAI − AUTHORITY_CHECK_<table> • Event blocks in the executable program: − AT SELECTION-SCREEN − AT SELECTION-SCREEN ON <fname> − AT SELECTION-SCREEN ON END OF <fname> − GET <table> Whether you place the authorization checks in the database program or in the executable program depends on the following: • The structure of the logical database. For example, you should only check authorizations for company code if you actually read lines containing the company code at runtime. • Performance Avoid repetitive checks (for example, within a SELECT loop). The separation of database access and application logic allows you to program all of your authorization checks centrally in the logical database program. This makes it easier to maintain large programming systems. BC - ABAP Programming SAP AG Calling a Logical Database Using a Function Module 1234 December 1999 Calling a Logical Database Using a Function Module From Release 4.5A it is possible to call logical databases independently from any ABAP program. Previously it was only possible to link a logical database to an executable program, in which the processing blocks of the logical database and the program were controlled by the ABAP runtime environment. To call a logical database from another program, use the function module LDB_PROCESS. This allows you to use the logical database as a routine for reading data. You can call more than one logical database from the same program. You may also call the same logical database more than once from the same program. In the past, it was only possible to use a logical database more than once or use more than one logical database by calling a further executable program using SUBMIT [Page 1059]. These programs had to be linked to the corresponding logical database, and the data had to be passed to the calling program using ABAP memory [Page 1073] or a similar technique. When you call a logical database using the function module LDB_PROCESS, its selection screen is not displayed. Instead, you fill the selections using the interface parameters of the function module. The logical database does not trigger any GET events in the calling program, but passes the data back to the caller in callback routines. Calling a logical database using LDB_PROCESS thus decouples the actual data retrieval from the preceding selection screen processing and the subsequent data processing. There is no need to adapt a logical database for use with LDB_PROCESS, except in the following cases: If you do not adapt a logical database, it is not possible to use the function module to call the same logical database more than once. The PAI subroutine is not called when you use LDB_PROCESS. This means that none of the checks for selections programmed in it are performed. You can work around these restrictions by including the subroutines LDB_PROCESS_INIT and LDB_PROCESS_CHECK_SELECTIONS [Page 1269] in the database program. Runtime Behavior The subroutines in the logical database are called in the following sequence when you call the function module LDB_PROCESS: 1. LDB_PROCESS_INIT 2. INIT 3. LDB_PROCESS_CHECK_SELECTIONS 4. PUT <node>. None of the subroutines used to process the selection screen when you link the logical database to an executable program [Page 1230] are called, neither does the runtime environment trigger any reporting events in the calling program. Instead, the PUT statements in the logical database trigger actions in the function module that call callback routines in the calling program. In other words, the function module catches the events that are otherwise processed by the runtime environment. Parameters of LDB_PROCESS The function module has the following import parameters: • LDBNAME SAP AG BC - ABAP Programming Calling a Logical Database Using a Function Module December 1999 1235 Name of the logical database you want to call. • VARIANT Name of a variant to fill the selection screen of the logical database. The variant must already be assigned to the database program of the logical database. The data is passed in the same way as when you use the WITH SELECTION-TABLE addition in a SUBMIT [Page 1060] statement. • EXPRESSIONS In this parameter, you can pass extra selections for the nodes of the logical database for which dynamic selections are allowed. The data type of the parameter RSDS_TEXPR is defined in the type group RSDS. The data is passed in the same way as when you use the WITH FREE SELECTION addition in a SUBMIT [Page 1060] statement. • FIELD_SELECTION You can use this parameter to pass a list of the required fields for the nodes of the logical database for which dynamic selections are allowed. The data type of the parameter is the deep internal table RSFS_FIELDS, defined in the type group RSFS. The component TABLENAME contains the name of the node and the deep component FIELDS contains the names of the fields that you want to read. The function module has the following tables parameters: • CALLBACK You use this parameter to assign callback routines to the names of nodes and events. The parameter determines the nodes of the logical database for which data is read, and when the data is passed back to the program and in which callback routine. • SELECTIONS You can use this parameter to pass input values for the fields of the selection screen of the logical database. The data type of the parameter corresponds to the structure RSPARAMS in the ABAP Dictionary. The data is passed in the same way as when you use the WITH SELECTION-TABLE addition in a SUBMIT [Page 1060] statement. If you pass selections using more than one of the interface parameters, values passed in SELECTIONS and EXPRESSIONS overwrite values for the same field in VARIANT. Read Depth and Callback Routines When you link a logical database with an executable program, the GET statements determine the depth to which the logical database is read. When you call the function module LDB_PROCESS, you determine the depth by specifying a node name in the CALLBACK parameter. For each node for which you request data, a callback routine can be executed at two points. These correspond to the GET and GET LATE events in executable programs. In the table parameter CALLBACK, you specify the name of the callback routine and the required execution point for each node. A callback routine is a subroutine in the calling program or another program that is to be executed at the required point. For the GET event, the callback routine is executed directly after the data has been read for the node, and before the subordinate nodes are processed. For the GET_LATE event, the callback routine is processed after the subordinate nodes have been processed. The line type of the table parameter CALLBACK is the flat structure LDBCB from the ABAP Dictionary. It has the following components: BC - ABAP Programming SAP AG Calling a Logical Database Using a Function Module 1236 December 1999 • LDBNODE Name of the node of the logical database to be read. • GET A flag (contents X or SPACE), to call the corresponding callback routine at the GET event. • GET_LATE A flag (contents X or SPACE), to call the corresponding callback routine at the GET LATE event. • CB_PROG Name of the ABAP program in which the callback routine is defined. • CB_FORM Name of the callback routine. If you pass an internal table to the CALLBACK parameter, you must fill at least one of the GET or GET_LATE columns with X for each node (you may also fill both with X). A callback routine is a subroutine that must be defined with the following parameter interface: FORM <subr> USING <node> LIKE LDBCB-LDBNODE <wa> [TYPE <t>] <evt> <check>. The parameters are filled by the function module LDB_PROCESS. They have the following meaning: • <node> contains the name of the node. • <wa> is the work area of the data read for the node. The program that calls the function module LDB_PROCESS and the program containing the callback routine do not have to declare interface work areas using NODES or TABLES. If the callback routine is only used for one node, you can use a TYPE reference to refer to the data type of the node in the ABAP Dictionary. Only then can you address the individual components of structured nodes directly in the subroutine. If you use the callback routine for more than one node, you cannot use a TYPE reference. In this case, you would have to address the components of structured nodes by assigning them one by one [Page 214] to a field symbol. • <evt> contains G or L, for GET or GET LATE respectively. This means that the subroutine can direct the program flow using the contents of <evt>. • <check> allows the callback routine to influence how the program is processed further (but only if <evt> contains the value G). The value X is assigned to the parameter when the subroutine is called. If it has the value SPACE when the subroutine ends, this flags that the subordinate nodes of the logical database should not be processed in the function module LDB_PROCESS. This is the same as leaving a GET event block using CHECK [Page 1015] in an executable program. If this prevents unnecessary data from being read, it will improve the performance of your program. [...]... like this: December 199 9 12 39 BC - ABAP Programming SAP AG Calling a Logical Database Using a Function Module 1240 December 199 9 SAP AG BC - ABAP Programming Editing Logical Databases Editing Logical Databases You edit logical databases using the Logical Database Builder in the ABAP Workbench To start the Logical Database Builder, use Transaction SE36 or SLDB, or choose Tools → ABAP Workbench, followed... declared and linked to the node BKPF Dynamic selections are defined for the tables LFA1 and LFB1 Field selections are defined for tables LFB1 and LFC1 December 199 9 12 49 BC - ABAP Programming SAP AG Editing Selections 1250 December 199 9 SAP AG BC - ABAP Programming Editing the Database Program Editing the Database Program To display or change the database program of a logical database, choose Database program... program is displayed in the ABAP Editor You can change it as described in Editing the Database Program [Page 1251] 8 If you repeatedly choose Previous screen (left arrow in the application toolbar), you can display and change the general attributes of the logical database 9 Finally, you can maintain optional selection texts and documentation December 199 9 1243 BC - ABAP Programming SAP AG Processing... type from the ABAP Dictionary to which it refers, and its short text • To select/deselect a sub-tree, choose Edit → Sub-tree → Select/deselect To move a selected sub-tree in a structure to a position indicated by the cursor, choose Edit → Subtree → Reassign • To delete a sub-tree, place the cursor on the node or select it and choose Edit → Subtree → Delete 1244 December 199 9 SAP AG BC - ABAP Programming. .. cursor on the node or select it and choose Edit → Subtree → Delete 1244 December 199 9 SAP AG BC - ABAP Programming Processing the Structure December 199 9 1245 BC - ABAP Programming SAP AG Editing a Search Help Editing a Search Help A search help is a ABAP Dictionary object used to define possible values (F4) help There are two kinds of search help - elementary and collective An elementary search help... December 199 9 SAP AG BC - ABAP Programming Creating a Logical Database When you have confirmed the dialog box, a list appears, on which you can select all of the nodes that you want to use for field selections or dynamic selections The fields that you select are included in the source code generated by the system for the selection include 5 The generated selection include is displayed in the ABAP Editor... the Database Program [Page 1258] Field Selections in the Database Program [Page 1262] Search Helps in the Database Program [Page 1265] Independent Calls and the Database Program [Page 12 69] December 199 9 1257 BC - ABAP Programming SAP AG Dynamic Selections in the Database Program Dynamic Selections in the Database Program The statement SELECTION-SCREEN DYNAMIC SELECTIONS FOR NODE|TABLE declares... TABLE DYN_SEL-CLAUSES WITH KEY DYNAMIC_SELECTIONS-TABLENAME INTO DYNAMIC_SELECTIONS FLAG_READ = 'X' ENDIF SELECT * FROM SCARR WHERE CARRID IN S_CARRID AND (DYNAMIC_SELECTIONS-WHERE_TAB) December 199 9 12 59 BC - ABAP Programming SAP AG Dynamic Selections in the Database Program PUT SCARR ENDSELECT ENDFORM The line of the internal table DYN_SEL-CLAUSES that contains the value SCARR in column DYN_SEL-CLAUSES-TABLENAME... is the name of the root node This subroutine can use the value list in _SP to read the actual data and trigger the GET event using the PUT_ statement 1246 December 199 9 SAP AG BC - ABAP Programming Editing Selections Editing Selections To display or change the structure of a logical database, choose Selections from the initial screen of the Logical Database Builder, or navigate... field list in the GET statement to specify which fields of the node of the logical database should be read In the function module LDB_PROCESS, the parameter FIELD_SELECTION must be December 199 9 1247 BC - ABAP Programming SAP AG Editing Selections passed accordingly Dynamic selections require special handling in the database program • The statements SELECTION-SCREEN BEGIN OF VERSION SELECTION-SCREEN . SAP AG BC - ABAP Programming Processing the Structure December 199 9 1245 BC - ABAP Programming SAP AG Editing a Search Help 1246 December 199 9 Editing a Search Help A search help is a ABAP Dictionary. look like this: BC - ABAP Programming SAP AG Calling a Logical Database Using a Function Module 1240 December 199 9 SAP AG BC - ABAP Programming Editing Logical Databases December 199 9 1241 Editing. flat structure LDBCB from the ABAP Dictionary. It has the following components: BC - ABAP Programming SAP AG Calling a Logical Database Using a Function Module 1236 December 199 9 • LDBNODE Name

Ngày đăng: 09/08/2014, 14:20

Từ khóa liên quan

Tài liệu cùng người dùng

  • Đang cập nhật ...

Tài liệu liên quan