Module Pool Programming Explained in Detail Starting From Basic

25
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 : STATUS ICON Status icon is used in screens to indicate visually about the status of the program.Before the status icon can be used ,it should be placed on the screen,it is a type of screen element. To use the status icon we have to write some abap code and also to change icons whenever required in the program. First step is to create a variable of type ICONS-TEXT. e.g. DATA: status TYPE ICONS-TEXT. The name of the variable in the abap program should be same as that of in the screen. Declaring it merely wont show anything , we have to use the function module ICON_CREATE to fill it with the required icon, generally PBO of the screen is used for this purpose. There are 3 parameters to be passed. CALL FUNCTION 'ICON_CREATE' EXPORTING NAME = 'icon name' TEXT = 'text to be displayed'

Transcript of Module Pool Programming Explained in Detail Starting From Basic

Page 1: Module Pool Programming Explained in Detail Starting From Basic

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 :

STATUS ICON

 

  Status icon is used in screens to indicate visually about the status of the

program.Before the status icon can be used ,it should be placed on the

screen,it is a type of screen element.

 To use the status icon we have to write some abap code and also to

change icons whenever required in the program. First step is to create

a variable of type ICONS-TEXT.

 

e.g. DATA: status TYPE ICONS-TEXT.

      The name of the variable in the abap program should be same as that

of in the screen.

      Declaring it merely wont show anything , we have to use the function module ICON_CREATE to fill it with the required icon, generally PBO of the screen is used for this purpose. There are 3 parameters to be passed.

 

 CALL FUNCTION 'ICON_CREATE'

   EXPORTING

    NAME = 'icon name'

    TEXT   = 'text to be displayed'

    INFO   = 'tooltip text'

 

  Here name can be anything like ICON_RED_LIGHT,ICON_GREEN_LIGHT etc.  Infact any icon can be shown that exists but we should adhere to SAP

Page 2: Module Pool Programming Explained in Detail Starting From Basic

recommended style guidelines

 

CONTEXT MENU

 

  Context menu can 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)

or dynamically by using the methods of the global class CL_CTMENU.

 All context menus are objects of this global class.

 There are number of methods which can be used to create and modify context menu dynamically . These are:

 

LOAD_GUI_STATUS

 This method is used to load a static context menu already defined using

menu painter.The exporting parameters are PROGRAM ,STATUS and MENU. Where MENU indicates the menu to which the context menu will be attached .

 

ADD_FUNCTION

 This method adds a function code to the menu ,The exporting parameters are FCODE and TEXT. These are used to specify the function code and the corresponding text in the men.

ADD_MENU

 This method adds a context menu to another one.

ADD_SEPARATOR

 This method adds a separator line.

ADD_SUBMENU

 This method adds a menu to another one as a sub menu the exporting parameters are MENU and the TEXT that will be displayed.

HIDE_FUNCTIONS

SHOW_FUNCTIONS

Page 3: Module Pool Programming Explained in Detail Starting From Basic

DISABLE_FUNCTIONS

ENABLE_FUNCTIONS

 

These functions are used to modify the context menu by hiding,enabling etc them.

 

SET_DEFAULT_FUNCTION

 This method will mark a particular menu item as the default one ,the corresponding function code is passed as an exporting parameter.

 

The context menu should be linked to the screen element in the screen painte(SE51) by specifying an ID which is known as CONTEXT in the context menu field.

We can specify the same context for different screen elements or different context for different elements.

    For each context specified in the screen painter a special call back

subroutine is used in the abap program. the syntax of this special routine

is:

 

FORM ON_CTLMENU_context USING menu TYPE REF TO CL_CTMENU

...

ENDFORM

 This subroutine can be used to modify or load or create a context menu at runtime when the user right clicks the screen element.

 In the above subroutine the context is the context assigned to the screen element and menu is the menu object that was passed to this call back routine which is initially blank, we have to use methods of the class as stated above to create a working menu or load an existing static context menu previously build in the menu painter.

 

e.g. To load an existing context menu

FORM on_ctmenu_text USING menu TYPE REF TO cl_ctmenu.  CALL METHOD menu->load_gui_status                      EXPORTING program = prog                                status  = 'CON_MENU'                                menu    = menu .  CALL METHOD  menu->set_default_function                      EXPORTING fcode = 'list'.ENDFORM.

Page 4: Module Pool Programming Explained in Detail Starting From Basic

e.g. CREATING A NEW CONTEXT MENU DYNAMICALLY.

FORM on_ctmenu_text USING menu TYPE REF TO cl_ctmenu.  DATA new_menu TYPE REF TO cl_ctmenu.  CREATE OBJECT new_menu.  CALL METHOD new_menu->add_function                      EXPORTING fcode = 'list'                                text  = text-001.

  CALL METHOD  new_menu->add_function                       EXPORTING fcode = 'add'                                 text  = text-002.  CALL METHOD   new_menu->add_function                       EXPORTING fcode = 'delete'                                text  = text-003.

  CALL METHOD   new_menu->add_submenu                       EXPORTING menu = new_menu                                 text = text-005.ENDFORM.

The ABAP program should check for the OK_CODE field to find out whichmenu item was selected by the user. Selecting a function code will trigger a PAI while right clicking will not trigger the PAI.

SCREEN KEYWORDS

 Screen language is used to create Screen Flow Logic, It is similar to ABAP but with limited functionality .Only certain keywords can be used

and these are:

 

PROCESS

MODULE

FIELD

ON

LOOP

ENDLOOP

CHAIN

ENDCHAIN

CALL

 

SCREEN EVENTS

Screen Flow Logic serves as the cotainer for screen processing blocks.There are four events processing block supported out of which

Page 5: Module Pool Programming Explained in Detail Starting From Basic

 FIRST two are automatically inserted when we create a new screen. The 4 events are:

 

PROCESS BEFORE OUTPUT

This event is fired just before the screen is displayed .

e.g. MODULE LOAD_STATUS_1000 .

PROCESSS AFTER INPUT

This event is fired when user selects  a function code or presses enter key

e.g.   MODULE USER_COMMAND_1000 .

PROCESS ON HELP-REQUEST

This event is fired when the user presses F1 key.

PROCESS ON VALUE-REQUEST

This event is fired when the user presses F4 key.

 

These events are triggered by the runtime environment.The ABAP

program serves as the container for the processing blocks associated with

these events.Each processing block in ABAP starts with the keyword MODULE .

PBO modules have OUTPUT keyword attached to them while for remaining 3 events there associated modules have INPUT keyword attached to them in the ABAP program.

e.g. MODULE LOAD_STATUS_1000 OUTPUT.

       MODULE USER_COMMAND_1000 INPUT.

 

MODULE name AT EXIT-COMMAND 

The specified module is called when the user selects a function code of type E like BACK,EXIT and CANCEL in PAI all other dialog modules are bypassed. 

 

GUI STATUS & TITLE

SET PF-STATUS status OF PROGRAM prog EXCLUDING f statement is used

to set the status of a ABAP program.The status provides user interface.It consists

of standard toolbar,application toolbar and menu.When ever the user selects a function the function code is placed in the OK_CODE field and structure SYST-UCOMM. The status is set in PBO event.

Page 6: Module Pool Programming Explained in Detail Starting From Basic

  The title is set using

SET TITLEBAR title OF PROGRAM program WITH p1 p2

where the values for p1 p2 can be specified at run time. Menu Painter (SE41) is used to create GUI status and titlebar.

SCREEN FIelds & OK_CODE

  Screen fields are fields in the working memory of the screen ,these are attached

to the screen elements.There contents are passed to similarly named fields in abap program during PAI and viceversa in PBO.

  OK_CODEeld is a 20 char field which is found in every screen , it stores the function code selected by the user.It's contents are same as that of SY_UCOMM.It is a screen element.

 

SubScreen explained in detail .

Basic Concepts Input Help Step Loop Table Control ListBox SubScreen TabStrip

Subscreens are screens which can be embeded into another screen. These can be used and created with both selection screen as well as screen painter.

  They differ from normal screens in the way that that they don't have OK_CODE field of ther own and there PBO and PAI transfer data to the ABAP program in which these screens were created and the cannot have module calls which change status or leave screen and module call AT EXIT-COMMAND AND E type function codes.

In screen painter(SE51) choose the subscreen tool button and draw a subscreen area on the screen,this subscreen area will be used to hold the subscreen at run time.To make a subscreen select the attribute screen type as subscreen and specify the size of the subscreen according to the size of the subscreen area in which it will be placed.

We use ABAP statement to embed and start the flow logic of the subscreen area in the PBO of a screen. A subscreen can contain another subscreen.

CALL SUBSCREEN subscreen_area INCLUDING program screen_number.

A similar call should also exist in PAI of screen.It will also call the PAI modules of the subscreen and will transfer data from subscreen to ABAP program.

CALL SUBSCREEN subscreen_area.

Subscreen can be created in selection screen using ABAP ststement and can be used with tabstrip defined on the selection screen or with the screen defined in the screen painter.

SELECTION-SCREEN BEGIN OF SCREEN screen_number AS SUBSCREEN NO-INTERVALS.

Page 7: Module Pool Programming Explained in Detail Starting From Basic

....

...

SELECTION-SCREEN END OF SCREEN screen_number .

 

to use such a subscreen with tabstrip defined on the selection screen we should

use the DYNNR compnent of the structure which is created when the tabstrip is created and specifying the number of the screen .We can also define the subscreen statically for such a tabstrip by using

DEFAULT PROGRAM program SCREEN subscreen_number when declaring a tabstrip in selection screen.

 

SELECTION-SCREEN BEGIN OF TABBED BLOCK tab_area FOR height LINES.

SELECTION-SCREN TAB (width)tab_name USER_COMMAND funct_code DEFAULT program SCREEN subscreen_no .

...

END OF BLOCK  tab_area .

 

 For each tabbed apge TAB addition is used with SELECTION-SCREEN statement. At the initialization event we can fill the tabstrip structure to dsiplay the default screen or specify it with DEFAULT addition.

tab_area-PROGRAM = SY-REPID.

tab_area-DYNNR  =  subscreen_nummber.

tab_area-ACTIVETAB = tabname.

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

Input help can be programmed in selection screen using event

AT SELECTION-SCREEN ON VALUE-REQUEST FOR  FIELD and for module pools in event

PROCESS ON VALUE_REQUEST   using module call starting with FIELD

i.e FIELD field MODULE module

Page 8: Module Pool Programming Explained in Detail Starting From Basic

 

 There ar number of function modules that can be used for the purpose, but these

can fullfill the task easily or combination of them.

 

DYNP_VALUE_READF4IF_FIELD_VALUE_REQUESTF4IF_INT_TABLE_VALUE_REQUEST

POPUP_WITH_TABLE_DISPLAY

 

DYNP_VALUE_READ

 This function module is used to read values in the screen fields. Use of this

FM causes forced transfer of data from screen fields to ABAP fields.

   There are 3 exporting parameters

    DYNAME = program name   = SY-CPROG

    DYNUMB = Screen number  = SY-DYNNR

    TRANSLATE_TO_UPPER    = 'X'

 and one importing TABLE parameter  

   DYNPFIELDS = Table of TYPE DYNPREAD

 The DYNPFIELDS parameter is used to pass internal table of type DYNPREAD

to this FM and the values read from the screen will be stored in this table.This

table consists of two fields:

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

Page 9: Module Pool Programming Explained in Detail Starting From Basic

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. 

Page 10: Module Pool Programming Explained in Detail Starting From Basic

       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.

Page 11: Module Pool Programming Explained in Detail Starting From Basic

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.

Page 12: Module Pool Programming Explained in Detail Starting From Basic

 

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

Page 13: Module Pool Programming Explained in Detail Starting From Basic

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

Page 14: Module Pool Programming Explained in Detail Starting From Basic

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.

Page 15: Module Pool Programming Explained in Detail Starting From Basic

   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

Page 16: Module Pool Programming Explained in Detail Starting From Basic

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

Page 17: Module Pool Programming Explained in Detail Starting From Basic

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'

Page 18: Module Pool Programming Explained in Detail Starting From Basic

  EXPORTING

      ID                =  name of screen element ,it is of TYPE VRM_ID

      VALUES      =  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 .

Page 19: Module Pool Programming Explained in Detail Starting From Basic

 

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.

Page 20: Module Pool Programming Explained in Detail Starting From Basic

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 NOINTERVALS.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.

Page 21: Module Pool Programming Explained in Detail Starting From Basic

SELECTION-SCREEN BEGIN OF SCREEN 002 AS SUBSCREEN NO INTERVALS.SELECTION-SCREEN BEGIN OF BLOCK block2 WITH FRAME TITLE text-003 NOINTERVALS.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.

Page 22: Module Pool Programming Explained in Detail Starting From Basic