Você está na página 1de 16

Module Pool programming explained in detail starting from basic .Table Control, Step Loops and TabStrip Etc.

Basic Concepts Input Help Step Loop Table Control ListBox SubScreen TabStrip Basic Concepts Explained :

Value or Input help can be programmed for selection screen or for module pools.
Basic Concepts Input Help Step Loop Table Control ListBox SubScreen TabStrip
Status icon is used in screens to indicate visually about the status of the program.Before the status icon in selection screen using event on the Input help can be programmed can be used ,it should be placed screen,it is a type of screenON VALUE-REQUEST FOR FIELD and for module pools in event AT SELECTION-SCREEN element. To use the status icon we have to using module code and also FIELD PROCESS ON VALUE_REQUESTwrite some abapcall starting withto change icons whenever required in the program. First step is to create i.e FIELD field MODULE module a variable of type ICONS-TEXT. There ar number of function modules that can be used for the purpose, but these e.g. fullfill the task TYPE or combination of them. can DATA: status easily ICONS-TEXT. The name of the variable in the abap program should be same as that of in the screen. DYNP_VALUE_READ F4IF_FIELD_VALUE_REQUEST Declaring it merely wont show anything , we have to use the function module ICON_CREATE to fill it with F4IF_INT_TABLE_VALUE_REQUEST the required icon, generally PBO of the screen is used for this purpose. There are 3 parameters to be passed. POPUP_WITH_TABLE_DISPLAY CALL FUNCTION 'ICON_CREATE' DYNP_VALUE_READ EXPORTING This function module is used to read values in the screen fields. Use of this NAME = 'icon name' FM causes forced transfer of data from screen fields to ABAP fields. TEXT = 'text to be displayed' There are 3 exporting parameters INFO = 'tooltip text' DYNAME = program name = SY-CPROG DYNUMB = Screen number = SY-DYNNR Here name can be anything like ICON_RED_LIGHT,ICON_GREEN_LIGHT etc. Infact any icon can be shown that exists but we should= 'X' TRANSLATE_TO_UPPER adhere to SAP recommended styleTABLE parameter and one importing guidelines DYNPFIELDS = Table of TYPE DYNPREAD CONTEXT MENU parameter is used to pass internal table of type DYNPREAD The DYNPFIELDS to this FM and the values read from the screen will be stored in this table.This Context menu two fields: table consists ofcan be used in relation with the various screen elements like I/O fields, subscreen,group box,table control but not with push buttons,radio,check buttons. It can be used to show related options when the user right clicks on the screen elements. It is a type of status. SAP automatically creates a default context menu for dialog statuses consisting of all the function codes available. We can create a context menu statically using the menu painter(SE41) STATUS ICON

FIELDNAME : Used to pass the name of screen field for which the value is to be read. FIELDVALUE : Used to read the value of the field in the screen.

e.g. DATA: SCREEN_VALUES TYPE TABLE OF DYNPREAD , SCREEN_VALUE LIKE LINE OF SCREEN_VALUES.

SCREEN_VALUE-FIELDNAME = 'KUNNR' .

* Field to be read

APPEND SCREEN_VALUE TO SCREEN_VALUES. * Fill the table

CALL FUNCTION 'DYNP_VALUES_READ' EXPORTING DYNAME = SY-CPROG DYNUMB = SY-DYNNR TRANSLATE_TO_UPPER = 'X' TABLES DYNPFIELDS = SCREEN_VALUES. READ TABLE SCREEN_VALUES INDEX 1 INTO SCREEN_VALUE.Now the screen value for field KUNNR is in the SCREEN_VALUE-FIELDVALUE and can be used for further processing like using it to fill the internal table to be used as parameter in F4IF_INT_TABLE_VALUE_REQUEST ETC. F4IF_FIELD_VALUE_REQUEST This FM is used to display value help or input from ABAP dictionary.We have to pass the name of the structure or table(TABNAME) along with the field name(FIELDNAME) . The selection can be returned to the specified screen field if three parameters DYNPNR,DYNPPROG,DYNPROFIELD are also specified or to a table if RETRN_TAB is specified.

CALL FUNCTION 'F4IF_FIELD_VALUE_REQUEST' EXPORTING TABNAME = table/structure FIELDNAME = 'field name' DYNPPROG = SY-CPROG DYNPNR = SY-DYNR DYNPROFIELD = 'screen field'

IMPORTING RETURN_TAB . = table of type DYNPREAD

F4IF_INT_TABLE_VALUE_REQUEST This FM is used to dsiplay values stored in an internal table as input help.This FM is used to program our own custom help if no such input help exists in ABAP dictionary for a particular field. The parameter VALUE_TAB is used to pass the internal table containing input values.The parameter RETFIELD is used to specify the internal table field whose value will be returned to the screen field or RETURN_TAB. If DYNPNR,DYNPPROG and DYNPROFIELD are specified than the user selection is passed to the screen field specified in the DYNPROFIELD. If RETURN_TAB is specified the selectionis returned in a table.

CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST' EXPORTING RETFIELD = field from int table whose value will be returned DYNPPROG = SY-CPROG DYNPNR = SY-DYNNR DYNPROFIELD = 'screen field' VALUE_ORG = 'S' TABLES VALUE_TAB = internal table whose values will be shown. RETURN_TAB = internal table of type DDSHRETVAL

EXCEPTIONS parameter_error = 1 no_values_found = 2 others = 3.

POPUP_WITH_TABLE_DISPLAY This FM is used to display the contents of an internal table in a popup window.The user can select a row and the index of that is returned in the CHOISE parameter.The VALUETAB is used to pass the internal table. A suitable title can be set using TITLETEXT parameter. The starting and end position of the popup can be specified by the parameters STARTPOS_COL / ROW and ENDPOS_ROW / COL .

CALL FUNCTION 'POPUP_WITH_TABLE_DISPLAY' EXPORTING ENDPOS_COL = ENDPOS_ROW = STARTPOS_COL = STARTPOS_ROW = TITLETEXT = 'title text' IMPORTING CHOISE = TABLES VALUETAB = EXCEPTIONS BREAK_OFF = 1 OTHERS = 2. e.g.

DATA: w_choice TYPE SY-TABIX. DATA: BEGIN OF i_values OCCURS 0 WITH HEADER LINE, values TYPE I, END OF i_values. PARAMETRS : id TYPE I. AT SELECTION-SCREEN ON VALUE-REQUEST FOR id i_values-values = '0001'. APPEND i_values. i_values-values = '0002'. APPEND i_values. i_values-values = '0003'. APPEND i_values. i_values-values = '0004'. APPEND i_values.

CALL FUNCTION 'POPUP_WITH_TABLE_DISPLAY' EXPORTING ENDPOS_COL = 40 ENDPOS_ROW = 12 STARTPOS_COL = 20 STARTPOS_ROW = 5

TITLETEXT = 'Select an ID' IMPORTING CHOISE = w_choice TABLES VALUETAB = i_values EXCEPTIONS BREAK_OFF = 1 OTHERS = 2. CHECK w_choice > 0. READ TABLE i_values INDEX w_choice. ...now we can process the selection as it is contained ...in the structure i_values.

Other FM that may be used to provide input help is HELP_START .

Step Loop :creation on screen and ABAP programming.


Basic Concepts Input Help Step Loop Table Control ListBox SubScreen TabStrip

STEP LOOP The STEP LOOP are the predecessor of TABLE CONTROL they are used to display tabular data on the screen.They are repeated sequence of blocks of screen element.In a step loop number of screen elements are combined together to form a loop block.There are 2 types of step loops 1)fFxed Size 2)Variable Size.. In a fixed size loop the number of loop blocks shown in the screen is fixed,while in case of variable size step loop the number of blocks will change dynamically according to the size of the screen.There could be only one variable step loop per screen and unlimited fixed size step loops per screen. A step loop can extend more than one line on the screen(see Table Control).A vertical scroll bar is automatically created to show step loops on he screen. Step loops have no name. We use LOOP ...ENDLOOP to program step loops in a screen in both PBO and PAI. Since the number of loop blocks in variable step loops can change the number of loop blocks at any moment is placed by the system in system field SY-LOOPC

and the current step loop pass number is placed in system field SY-STEPL . Loop Type attribute is used to specify the type of step loop and Loop Count attribute is used to specify the number of step loop blocks that will be displayed on the screen at a time. Step Loop Screen Creation We create step loop in the screen painter(SE51). First we define the screen elements that will be part of the step loop on the screen ,they may extend to more than one line.Select all the elements as one group.Goto Edit menu and select Grouping-->Step Loop-->Define. To define a step loop as variable or fixed.goto Edit-->Grouping-->Step Loops-->Fix or Variable. To edit the Step Loop click on the border of the block and goto Edit-->Grouping-->Step Loop here we can use define/undefine(delete)variable fix options. Once created we have to program step loops through screen key word LOOP...ENDLOOP in PBO and PAI as these events are used to transfer back and forth the data from the ABAP program. STEP LOOP Coding We use two flavours of LOOP ... ENDLOOP in screen flow logic to program the step loops.We have to program both in PBO and PAI so that transfer of data can take place between screen and abap program. 1) LOOP MODULE fill_data ENDLOOP. here in PBO a module should be called that will transfer the data to the screen fields. In PAI the module call is not required only the empty LOOP..ENDLOOP will do or we can call a module to write the data to an internal table.In this method there is no automatic scrolling we have to program it in ABAP. 2) LOOP AT int_table [INTO wa ][CURSOR line_number][FROM n1 TO n2] ENDLOOP. Here in PBO a module call is not required to fill the step loop screen fields as the data is copied to the workare wa and from there to screen fields in step loop automatically. INTO wa is not required if we use the int_table declared with a header line. In PAI the addition AT int_table is also required for automatic scrolling. The parameter CURSOR line_number which is of TYPE I is used to specify the that will be the first to be displayed,it is filled in the ABAP program.

NOTE:

1) It is preferable to use TABLE CONTROL instead of STEP LOOPS. 2) It is preferable to use LOOP AT int_table instead of plain LOOP..ENDLOOP.

Table Control explained starting from concept.Runtime modification of Tabel Control using CXTAB_CONTROL structure .
Basic Concepts Input Help Step Loop Table Control ListBox SubScreen TabStrip

Attributes & Creation CXTAB_CONTROL Modification TABLE CONTROL

These are the screen elements used to display tabular data they can be called as screen tables( like STEP LOOP).To use table control we have to create it on the screen using SCREEN PAINTER(SE51) and declare a control variable of TYPE TABLEVIEW using CONTROLS statement in the ABAP program. We have to use LOOP .. ENDLOOP statement in both PBO and PAI with or without AT int_table parameter. IF AT int_table parameter is not used than we have to place a MODULE call between the LOOP...ENDLOOP statement to fill the screen table rows from the ABAP program in PBO and program our own scrolling functions using OK_CODE field. Having a parallel loop(at screen table rows & int table rows) by using parameter AT int_table makes the ABAP code simple. A special structure of type CXTAB_CONTROL is used to set/get various attributes of table control at runtime like CURRENT_LINE ,TOP_LINE.

ABAP declaration

CONTROLS: tab_con TYPE TABLEVIEW USING SCREEN nnnn Here tab_con is the same name we used in screen for the table control. This ABAP statement will declare a control variable that will be used to access the table control , and set it's various attributes like number of fixed columns(tab_con-FIXED_COLS) ,total number of records it will display(tab_con-LINES).It is of type CXTAB_CONTROL and is a deep structure(structure containing structures).

REFRESH CONTROL tab_con FROM SCREEN nnnn This ABAP statement will initialize the table control on the screen nnnn to its initial values.

PBO processing In PBO we have to use the screen LOOP ...ENDLOOP statement , with or without intenal table. LOOP WITH CONTROL tab_con. MODULE fill_tab_con. ENDLOOP. Here a module should be called between the loop endloop statement to transfer data from th ABAP program to the screen table through a structure.This module should use the CURRENT_LINE attribute of the table control variable to get the current screen table record index to read the data from the internal table into a work area. e.g. READ TABLE int_table INDEX tab_con-CURRENT_LINE The record read will be placed in the header line of the internal table and will be available to the similarly named screen fields or if these are different it can be written explicitly. e.g. screen_field_name = int_table-field_name ... . LOOP AT int_table INTO workarea WITH CONTROL tab_con CURSOR i FROM n1 TO n2. ENDLOOP.

Here the module call is not required to fill the screen table.The CURSOR parameter is a integer of type I indicating which absolute internal table line should be the first to display on the table control .FROM n1 TO n2 can be used to restrict the starting line and ending line number of the internal table , they are of type SY-TABIX.

In both cases before the LOOP statement a module should be called which is generally for setting of status ,in which we should fill the LINES attribute (tab_con-LINES ) of the control with the total number of internal table records,doing this ensures correct and automatic scrolling. The ABAP statement DESCRIBE TABLE int_table LINES lines can be used to get the total lines in an int table. PAI Processing We have to use LOOP ... ENDLOOP in PAI so that data can transfer fro table control to ABAP program. If we want to write changes to the data we should call a module between the LOOP ... ENDLOOP. The MODULE call to process user commands (SY-UCOM) should be called after the ENDLOOP statement. e.g. PROCESS AFTER INPUT MODULE mod AT EXIT-COMMAND. LOOP AT itab_table or LOOP "depending on whether we are using AT int_table MODULE modify_int_table. ENDLOOP. MODULE user_command.

In the MODULE call modify_int_table we can use MODIFY int_table FROM workarea INDEX tab_con-CURRENT_LINE or we can use int_table-field_name = screen_field_name.

Drop down List box in SAP ABAP explained .


Basic Concepts Input Help Step Loop Table Control ListBox SubScreen TabStrip

LIST BOX Drop down list box can be created in a dialog screen(SE51) as well as selection screen.

The sap list box allows to select a value from the list but we cannot enter our own value in the list box .The value list that will be displayed consists of two fields TEXT field of TYPE 80(C) and internal KEY field of TYPE 40(C).

In screen painter to create a input/output field into list box we use 'L" as a value for dropdown attribute for the i/o field. In screen painter to determine the type of method that will be used to fill the value list we use the attribute value list. If it is blank the value list will be filled by the first column of the input help assigned to the screen field.This input help can be defined in the ABAP Dictionary, on screen using SELECT,VALUES screen statements or in event POV (PROCESS ON VALUE-REQUEST ) and the input help that will be passed to the field should consists of 2 columns ,the key column is filled automatically by the system.SAP recommends value list field should be blank. or The value can be 'A' meaning that the value list will be filled in the event PBO(PROCESS BEFORE OUTPUT) or before the screen is displayed.In this method we use function module VRM_SET_VALUES to fill the values and pass it to the i/o field. If a function code is attached to the list box the selection of a value triggers a PAI otherwise PAI will not trigger. LIST BOX in SELECTION SCREEN List Box is created in selection screen using PARAMETERS staement with AS LISTBOX addition other attributes like VISIBLE LENGTH (width of listbox) can be specified with the declaration. PARAMETERS name(n) AS LISTBOX VISIBLE LENGTH n. Here n is an integer and name is the name of parameter. To populate the value list we use the FM VRM_SET_VALUES and the selection screen event AT SELECTION-SCREEN OUTPUT is used to write the code to fill it. VRM_SET_VALUES The function module VRM_SET_VALUES is used to fill the value list associated with a List Box .This FM uses types which are declared in type group VRM. So we should declare TYPE-POOLS VRM before using this FM.

Some important types declared in the VRM type group are VRM_ID It refers to the name of the input/output field associated with list box VRM_VALUES It refers to the internal table consisting of two fields TEXT(80C) and KEY(40)C that will be used to create the list values.

CALL FUNCTION 'VRM_SET_VALUES' EXPORTING ID VALUES = name of screen element ,it is of TYPE VRM_ID = internal table containing values,of TYPE VRM_VALUES

LIST BOX with value list from input help In this example the screen element attribute value list is set to blank as such the value list will be filled with the 1st column of the input help,We use PROCESS ON VALUE-REQUEST event to pass the value list to the listbox.In the MODULE call used to fill the value list we can use FM like F4IF_INT_TABLE_VALUE_REQUEST to create input help as explained in the input help.The value of first column will be shown in the field when selected.

PROCESS ON VALUE-REQUEST FIELD list MODULE fill_list_100

FIELD list MODULE fill_list_100 INPUT SELECT f1 f2 FROM table INTO int

CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST' EXPORTING retfield = 'input/output screen field' value_org = 'S' TABLES value_tab = itab "it contains 2 fields that will be shown in the list box EXCEPTIONS parameter_error = 1

no_values_found = 2 OTHERS = 3. IF sy-subrc <> 0. ... ENDIF. ENDMODULE.

VALUE LIST CREATED IN PBO

In this method we set the value list attribute to 'A'.The value list will be filled in the PBO by using FM VRM_SET_VALUES .

TYPE-POOLS : VRM DATA : field_id TYPE VRM_ID , values TYPE VRM_VALUES, value LIKE LINE OF values.

PROCESS BEFORE OUTPUT MODULE list_fill_100

MODULE list_fill_100 OUTPUT SELECT f1 f2 f3 FROM tab WHERE condition. value-KEY = f1. value-TEXT = f2 APPEND value TO VALUES

CALL FUNCTION 'VRM_SET_VALUES' EXPORTING id = 'i/o screen field' values = values.

ENDMODULE. LIST BOX with Selection Screen

For this the FM VRM_SET_VALUES is used to fill the value table and is passed to the parameter created with TYPE LISTBOX in the selection screen event AT SELECTION-SCREEN.

PROGRAM zlist TYPE-POOLS : VRM.

DATA: param TYPE vrm_id, values TYPE vrm_values, value LIKE LINE OF values. PARAMETERS: p_name(10) AS LISTBOX VISIBLE LENGTH 10. AT SELECTION-SCREEN OUTPUT. param = 'P_NAME'. value-key = '1'. value-text = 'JOHN'. APPEND value TO values. value-key = '2'. value-text = 'PETER'. APPEND value TO values. CALL FUNCTION 'VRM_SET_VALUES' EXPORTING id = param values = values.

Use of TabStrip in Selection screen with example code .


Basic Concepts Input Help Step Loop Table Control ListBox SubScreen TabStrip

This is a example code explaining the use of TabStrip in selection screen .

*& Use of TabStrip and SubScreen explained *& ---- The report shows the material on one tab *& and plant on one tab.Pressing the execute button will show *& the description of the material or plant as the case is. *& TEXT-002 = Material Number *& TEXT-003 = Plant Number.

REPORT znr1 NO STANDARD PAGE HEADING

LINE-SIZE 80 LINE-COUNT 60. TABLES : sscrfields. DATA activetab(6) TYPE c . DATA mat_des TYPE makt-maktx. DATA pl_des TYPE t001w-name1 .

SELECTION-SCREEN BEGIN OF SCREEN 001 AS SUBSCREEN NO INTERVALS. SELECTION-SCREEN BEGIN OF BLOCK block1 WITH FRAME TITLE text-002 NO INTERVALS. SELECTION-SCREEN BEGIN OF LINE. SELECTION-SCREEN COMMENT 14(18) text-002 FOR FIELD matnr. PARAMETERS matnr TYPE mara-matnr. SELECTION-SCREEN END OF LINE. SELECTION-SCREEN END OF BLOCK block1. SELECTION-SCREEN END OF SCREEN 001. SELECTION-SCREEN BEGIN OF SCREEN 002 AS SUBSCREEN NO INTERVALS. SELECTION-SCREEN BEGIN OF BLOCK block2 WITH FRAME TITLE text-003 NO INTERVALS. SELECTION-SCREEN BEGIN OF LINE. SELECTION-SCREEN COMMENT 14(18) text-003 FOR FIELD matnr. PARAMETERS werks TYPE t001w-werks. SELECTION-SCREEN END OF LINE. SELECTION-SCREEN END OF BLOCK block2. SELECTION-SCREEN END OF SCREEN 002.

SELECTION-SCREEN BEGIN OF TABBED BLOCK tabb1 FOR 5 LINES NO INTERVALS. SELECTION-SCREEN TAB (15) tabs1 USER-COMMAND ucomm1 DEFAULT SCREEN 001. SELECTION-SCREEN TAB (15) tabs2 USER-COMMAND ucomm2. * DEFAULT SCREEN 002 . SELECTION-SCREEN END OF BLOCK tabb1. INITIALIZATION. tabs1 = text-002. tabs2 = text-003. activetab = 'TABS1'. AT SELECTION-SCREEN . CASE sscrfields-ucomm. WHEN 'UCOMM1'. tabb1-prog = sy-repid. tabb1-dynnr = 001. tabb1-activetab = 'TABS1'. activetab = 'TABS1' . WHEN 'UCOMM2'. tabb1-prog = sy-repid. tabb1-dynnr = 002. tabb1-activetab = 'TABS2'. activetab = 'TABS2'.

ENDCASE. START-OF-SELECTION. CASE activetab. WHEN 'TABS1'. SELECT SINGLE maktx FROM makt INTO pl_des WHERE matnr = matnr. WRITE: 'Material ' , matnr , mat_des .

WHEN 'TABS2'. SELECT SINGLE name1 FROM t001w INTO pl_des WHERE werks = werks. WRITE: 'Plant ' , werks ,pl_des.

Você também pode gostar