Skip to end of metadata
Go to start of metadata

When you have to simulate input data in a selection screen, and have to enter selection criteria that may change at each run, the following subroutines may help you to fill the BDC data easily, they only need a simple range internal table as input.

The code is provided in 2 parts. Note that second part should be included before the first part, the order here is only for the ease of reading.

A last thing before you play with it, it is probably not performant at all, if you have hundreds of lines to enter in the selection criteria, so it is recommended in that case to use another workaround like creating dynamically a variant, and so on.

First part : quick demo (needs the utility subroutines supplied in the second part)

Error rendering macro 'code': Invalid value specified for parameter 'com.atlassian.confluence.ext.code.render.InvalidValueException'
TABLES : scustom, scarr.
SELECT-OPTIONS s_custom FOR scustom-id.
SELECT-OPTIONS s_carrid FOR scarr-carrid.
START-OF-SELECTION.

* SF_EXAMPLE_03 selection screen
  PERFORM bdc_dynpro USING 'SAPLWBABAP' '0100'.
  PERFORM bdc_field USING 'BDC_CURSOR' 'RS38M-PROGRAMM'.
  PERFORM bdc_field USING 'BDC_OKCODE' '=STRT'.
  PERFORM bdc_field USING 'RS38M-PROGRAMM' 'SF_EXAMPLE_03'.
  PERFORM bdc_field USING 'RS38M-FUNC_EDIT' 'X'.

* Fill AIRLINE selection criteria
  PERFORM bdc_dynpro USING 'SF_EXAMPLE_03' '1000'.
  PERFORM bdc_field USING 'BDC_OKCODE' '=%' & "<=== on 2 lines just because of SDN wiki issue 8-/
                                          '001'.
  PERFORM fill_select_options_bdc USING s_carrid[]. "<=== Here the "magic" code ;-)

* Fill CUSTOMER selection criteria
  PERFORM bdc_dynpro USING 'SF_EXAMPLE_03' '1000'.
  PERFORM bdc_field USING 'BDC_OKCODE' '=%' & "<=== on 2 lines just because of SDN wiki issue 8-/
                                          '000'.
  PERFORM fill_select_options_bdc USING s_custom[]. "<=== Here the "magic" code ;-)

  CALL TRANSACTION 'SE38' USING bdcdata MODE 'A'.

Second part : utility subroutines (note that bdc_dynpro and bdc_field forms are the ones generated automatically from SHDB, so you probably already have them in your program):

Error rendering macro 'code': Invalid value specified for parameter 'com.atlassian.confluence.ext.code.render.InvalidValueException'
DATA bdcdata TYPE STANDARD TABLE OF bdcdata WITH HEADER LINE.

*----------------------------------------------------------------------*
*        Start new screen                                              *
*----------------------------------------------------------------------*
FORM bdc_dynpro USING program dynpro.
  CLEAR bdcdata.
  bdcdata-program  = program.
  bdcdata-dynpro   = dynpro.
  bdcdata-dynbegin = 'X'.
  APPEND bdcdata.
ENDFORM.                    "BDC_DYNPRO

*----------------------------------------------------------------------*
*        Insert field                                                  *
*----------------------------------------------------------------------*
FORM bdc_field USING fnam fval.
  CLEAR bdcdata.
  bdcdata-fnam = fnam.
  bdcdata-fval = fval.
  APPEND bdcdata.
ENDFORM.                    "BDC_FIELD

*----------------------------------------------------------------------*
FORM fill_select_options_bdc
      USING it_range TYPE STANDARD TABLE.

* initialize the select option first
  PERFORM bdc_dynpro USING 'SAPLALDB' '3000'.
  PERFORM bdc_field USING 'BDC_OKCODE' '/EDELA'.

* Now fill values from the range
  PERFORM bdc_dynpro USING 'SAPLALDB' '3000'.
  PERFORM fill_select_options_bdc2 USING it_range 'SIVA' 'I' 'S'.
  PERFORM fill_select_options_bdc2 USING it_range 'INTL' 'I' 'I'.
  PERFORM fill_select_options_bdc2 USING it_range 'NOSV' 'E' 'S'.
  PERFORM fill_select_options_bdc2 USING it_range 'NOINT' 'E' 'I'.
* action on the previously filled screen
  PERFORM bdc_field USING 'BDC_OKCODE' '=ACPT'.
ENDFORM.                    "fill_select_options_bdc

*----------------------------------------------------------------------*
FORM fill_select_options_bdc2
      USING
        it_range  TYPE STANDARD TABLE
        i_ucomm   TYPE syucomm
        i_sign    TYPE rsdsselopt-sign
        i_sng_int TYPE char1.
  FIELD-SYMBOLS <ls_range> TYPE ANY.
  FIELD-SYMBOLS <l_sign> TYPE rsdsselopt-sign.
  FIELD-SYMBOLS <l_option> TYPE rsdsselopt-option.
  FIELD-SYMBOLS <l_low> TYPE clike.
  FIELD-SYMBOLS <l_high> TYPE clike.
  DATA l_row_number TYPE n LENGTH 2.
  DATA l_first_time TYPE flag.
  DATA l_is_interval TYPE flag.
  DATA l_fnam TYPE bdcdata-fnam.
  l_first_time = 'X'.
  LOOP AT it_range ASSIGNING <ls_range>.
    ASSIGN COMPONENT 'SIGN' OF STRUCTURE <ls_range> TO <l_sign>.
    ASSERT sy-subrc = 0.
    ASSIGN COMPONENT 'OPTION' OF STRUCTURE <ls_range> TO <l_option>.
    ASSERT sy-subrc = 0.
    IF <l_option> = 'BT' OR <l_option> = 'NB'.
      l_is_interval = 'X'.
    ELSE.
      CLEAR l_is_interval.
    ENDIF.
    IF ( i_ucomm = 'SIVA' AND <l_sign> = 'I' AND l_is_interval IS INITIAL )
          OR ( i_ucomm = 'INTL' AND <l_sign> = 'I' AND l_is_interval = 'X' )
          OR ( i_ucomm = 'NOSV' AND <l_sign> = 'E' AND l_is_interval IS INITIAL )
          OR ( i_ucomm = 'NOINT' AND <l_sign> = 'E' AND l_is_interval = 'X' ).
      IF l_first_time = 'X'.
        IF i_ucomm <> 'SIVA'.
* change to tabstrip tab (action recorded on the previously filled screen)
          PERFORM bdc_field USING 'BDC_OKCODE' i_ucomm.
* now, prepare start of next screen
          PERFORM bdc_dynpro USING 'SAPLALDB' '3000'.
        ENDIF.
        l_row_number = 1.
        CLEAR l_first_time.
      ELSEIF l_row_number = 9.
* Simulate page down by Enter key (action recorded on the previously filled screen)
        PERFORM bdc_field USING 'BDC_CURSOR' l_fnam.
        PERFORM bdc_field USING 'BDC_OKCODE' 'P+'.
* now, prepare start of next screen
        PERFORM bdc_dynpro USING 'SAPLALDB' '3000'.
* page down will scroll 7 lines only (last line of last page becomes the first line)
* so fill from second line
        l_row_number = 2.
      ENDIF.
      ASSIGN COMPONENT 'LOW' OF STRUCTURE <ls_range> TO <l_low>.
      ASSERT sy-subrc = 0.
      CONCATENATE 'RSCSEL-' i_sng_int 'LOW_' i_sign '(' l_row_number ')' INTO l_fnam.
      PERFORM bdc_field USING l_fnam <l_low>.
      IF i_sng_int = 'I'.
        ASSIGN COMPONENT 'HIGH' OF STRUCTURE <ls_range> TO <l_high>.
        ASSERT sy-subrc = 0.
        CONCATENATE 'RSCSEL-' i_sng_int 'HIGH_' i_sign '(' l_row_number ')' INTO l_fnam.
        PERFORM bdc_field USING l_fnam <l_high>.
      ENDIF.
      ADD 1 TO l_row_number.
    ENDIF.
  ENDLOOP.
ENDFORM.                    "fill_select_options_bdc2
  • No labels

4 Comments

  1. This is great, many thanks.

    I've been searching a while for a standard function module which did this, with no success. Reason being that SUBMIT doesn't allow to capture messages, so I wanted to try CALL TRANSACTION...MESSAGES INTO using this approach with the report being submitted...

    A possible glitch I found in your code however, is that the select options are not entirely overwritten with BDCDATA. In the same example of your coding, program  SF_EXAMPLE_03 initializes both select options with range values, which are kept besides of the sent values. Maybe you purposely left it as this, but I think it would be better to overwrite them completely (as in SUBMIT WITH selopt IN range).

    Nevertheless, thanks for sharing.

    EDIT: I got the code needed to initialize the select option, it should be put inside FORM fill_select_options_bdc. My additions are marked in bold red (I don't find the option to edit the wiki code directly so you may add it afterwards):

      FORM fill_select_options_bdc
          USING it_range TYPE STANDARD TABLE.

    * initialize the select option first
      PERFORM bdc_dynpro USING 'SAPLALDB' '3000'.
      PERFORM bdc_field USING 'BDC_OKCODE' '/EDELA'.

    * Now fill values from the range
      PERFORM bdc_dynpro USING 'SAPLALDB' '3000'.
      PERFORM fill_select_options_bdc2 USING it_range 'SIVA' 'I' 'S'.
      PERFORM fill_select_options_bdc2 USING it_range 'INTL' 'I' 'I'.
      PERFORM fill_select_options_bdc2 USING it_range 'NOSV' 'E' 'S'.
      PERFORM fill_select_options_bdc2 USING it_range 'NOINT' 'E' 'I'.
    * action on the previously filled screen
      PERFORM bdc_field USING 'BDC_OKCODE' '=ACPT'.
    ENDFORM.                    "fill_select_options_bdc 

    Regards

  2. Done. Thanks Alejandro (smile)

  3. I got a couple more comments, I don't have the code at hand now but this shouldn't be difficult:

    1) Another fix: this code dumps if the range you use is not character based (e.g. packed numbers - TYPE p). What I did was to replace <low> and <high> field symbols type with SIMPLE. Then I created dynamically (CREATE DATA) a FVAL typed C variable, with the same lenght as the output lenght of the low / high field (DESCRIBE FIELD ... OUTPUT-LENGTH). Finally <low> and <high> are written (WRITE, so that they get converted to output format) to this FVAL, and in turn the FVAL is appended to BDCDATA.

    2) An improvement: instead of using the select option IDs (001, 002, etc) generated on the selection screen, which could change with positioning, function module RS_COMPLEX_SELECTIONS_FCODE can be used to determine them using the select option name as source.

    3) A warning: this code doesn't support values in the OPTION field other than EQ / CP / BT. For supporting others, additional BDC code is required, with seems a bit complex to implement (the option in the extension dynpro is chosen based on a list output).

    Regards

  4. Thx for these feedbacks. That would be nice if you can ask the rights to be a wiki editor, to the SCN admins. I don't remember what is the procedure, you can check the blogs.