Call dialog screen from report - Example 2

Select a line in the report and display a dialog screen with some of the values from the screen. The values Sort1, Sort2 and Sort3 can be cahnged in the dialog screen. When the user clicks the OK button, the database table ZPLUKSORT is updated and the report re-displayed.

 


      1  report ZDKFRAHEN_TEST001.
      2  *----------------------------------------------------------------------*
      3  *
      4  * This program demonstrates:
      5  * - How to select a line in a report,
      6  * - Show a custom dialog screen populated with values from the selected
      7  *   line in the report
      8  * - Change the vakue in the dialog screen and re-display the report
      9  *   with the changed values
     10  *
     11  * Programmer: Henrik Frank
     12  * Date      : 07-08-2007
     13  *----------------------------------------------------------------------*
     14 
     15 
     16  ***********************************************************************
     17  * DECLARATIONS
     18  ***********************************************************************
     19  TABLES: mara,
     20          makt,
     21          zpluksortlist.
     22 
     23 
     24  DATA: BEGIN OF tab OCCURS 1,
     25          matnr LIKE mara-matnr,
     26          mtart LIKE mara-mtart,
     27          matkl LIKE mara-matkl,
     28          maktx LIKE makt-maktx,
     29          plant      TYPE werks_d,
     30          sortlistno LIKE zpluksort-sortlistno,
     31          atwrt      LIKE zpluksort-atwrt,
     32          sort1      LIKE zpluksort-sort1,
     33          sort2      LIKE zpluksort-sort2,
     34          sort3      LIKE zpluksort-sort3,
     35        END OF tab.
     36 
     37  DATA:
     38    g_screen2000 LIKE zpluksort, "Data for screen 2000
     39    g_okcode2000(6) TYPE c,      "OK code screen 2000
     40    g_tabix LIKE sy-tabix,
     41    g_sortkey(30) TYPE c,
     42    g_text TYPE string,
     43    g_sortlistno LIKE zpluksort-sortlistno.
     44 
     45  ***********************************************************************
     46  * SELECTION SCREEN
     47  ***********************************************************************
     48 
     49  SELECTION-SCREEN BEGIN OF BLOCK grp1 WITH FRAME TITLE text-100.
     50  SELECT-OPTIONS: matnr FOR mara-matnr.
     51  SELECT-OPTIONS: mtart FOR mara-mtart DEFAULT 'FERT'.
     52  SELECT-OPTIONS: matkl FOR mara-matkl.
     53  SELECT-OPTIONS: p_plant FOR zpluksortlist-plant DEFAULT '0000'.
     54 
     55  PARAMETERS: show1 AS CHECKBOX.
     56  PARAMETERS: sort1 RADIOBUTTON GROUP type.
     57  PARAMETERS: sort2 RADIOBUTTON GROUP type.
     58  SELECTION-SCREEN END OF BLOCK grp1.
     59 
     60 
     61 
     62  ***********************************************************************
     63  * LIST EVENTS
     64  ***********************************************************************
     65  START-OF-SELECTION.
     66  * Read data and display list
     67    PERFORM display_list.                                     "BC2058
     68 
     69 
     70  *----------------------------------------------------------------------*
     71  *   TOP-OF-PAGE                                                        *
     72  *----------------------------------------------------------------------*
     73  *   Write title                                                        *
     74  *----------------------------------------------------------------------*
     75  TOP-OF-PAGE.
     76    PERFORM write_title.                                      "BC2058
     77 
     78  *----------------------------------------------------------------------*
     79  *   TOP-OF-PAGE  DURING LINE-SELECTION                                 *
     80  *----------------------------------------------------------------------*
     81  *   Write title when program returns sfrom screen 2000
     82  *
     83  *----------------------------------------------------------------------*
     84  TOP-OF-PAGE DURING LINE-SELECTION.
     85    PERFORM write_title.
     86 
     87 
     88  *----------------------------------------------------------------------*
     89  *   AT LINE-SELECTION.
     90  *----------------------------------------------------------------------*
     91  *   User has choosen a line in the report
     92  *   Move key fields from report to screen 2000 and display the screen
     93  *----------------------------------------------------------------------*
     94 
     95  AT LINE-SELECTION.
     96 
     97    CLEAR:
     98      g_screen2000,
     99      g_okcode2000.
    100 
    101 
    102  * Move fields from report line to screen 2000
    103    MOVE:
    104      tab-sortlistno TO g_screen2000-sortlistno,
    105      tab-atwrt TO g_screen2000-atwrt,
    106      tab-sort1 TO g_screen2000-sort1,
    107      tab-sort2 TO g_screen2000-sort2,
    108      tab-sort3 TO g_screen2000-sort3.
    109 
    110  *   Call screen 2000 to edit values
    111      CALL SCREEN 2000 STARTING AT 40 10 ENDING AT 100 20.
    112 
    113 
    114  *----------------------------------------------------------------------*
    115  *   AT USER-COMMAND.
    116  *----------------------------------------------------------------------*
    117  *   Dummy user command - Necessary to re-display list with changes
    118  *   after return from  screen 2000
    119  *----------------------------------------------------------------------*
    120  AT USER-COMMAND.
    121    IF sy-ucomm = 'DUMMY'.
    122      sy-lsind = sy-lsind - 1.
    123      PERFORM display_list.
    124    ENDIF.
    125 
    126  ***********************************************************************
    127  * SCREEN LOGIC FOR SCREEN 2000
    128  ***********************************************************************
    129 
    130 
    131  *&---------------------------------------------------------------------*
    132  *&      Module  STATUS_2000  OUTPUT
    133  *&---------------------------------------------------------------------*
    134  *       PF status for screen 2000
    135  *----------------------------------------------------------------------*
    136  MODULE status_2000 OUTPUT.
    137    SET PF-STATUS 'STATUS_2000'.
    138  ENDMODULE.                 " STATUS_2000  OUTPUT
    139 
    140  *&---------------------------------------------------------------------*
    141  *&      Module  USER_COMMAND_2000  INPUT
    142  *&---------------------------------------------------------------------*
    143  *       User command screen 2000
    144  *----------------------------------------------------------------------*
    145  MODULE user_command_2000 INPUT.
    146    CASE g_okcode2000.
    147      WHEN 'BUTOK'.
    148  *     OK button - update
    149        PERFORM update_zpluksort.
    150 
    151  *     If update OK, then g_okcode2000 still = BUTOK
    152        IF g_okcode2000 = 'BUTOK'.
    153  *       Execute dummy command to re-display the list
    154          SET USER-COMMAND 'DUMMY'.
    155          sy-ucomm = 'DUMMY'.
    156        ENDIF.
    157        SET SCREEN 0.
    158 
    159      WHEN 'BUTCAN'.
    160  *     Cancel button - no update
    161        SET SCREEN 0.
    162    ENDCASE.
    163 
    164 
    165  ENDMODULE.                 " USER_COMMAND_2000  INPUT
    166 
    167 
    168  *&---------------------------------------------------------------------*
    169  *&      Form  write_title
    170  *&---------------------------------------------------------------------*
    171  *       Write list header
    172  *----------------------------------------------------------------------*
    173  FORM write_title.
    174    FORMAT COLOR 4.
    175    WRITE: /1 'Carlsberg'.
    176    WRITE: 40 'Sort of picking for selected materials'.
    177    WRITE: 111(5) 'Page:'.
    178    WRITE: 117(4) sy-pagno.
    179 
    180    WRITE: /91  'Printet:'.
    181    WRITE: 100  sy-datum DD/MM/YYYY.
    182    WRITE: 111 'Time:'.
    183    WRITE: 119 sy-uzeit USING EDIT MASK '__:__'.
    184    FORMAT COLOR OFF.
    185    ULINE.
    186 
    187    WRITE AT 1  text-001. "Matnr
    188    WRITE AT 10 text-002. "Description
    189    WRITE AT 51 text-003. "Mtyp
    190    WRITE AT 56 text-004. "Mat group
    191    WRITE AT 66 text-005. "Sort1
    192    WRITE AT 72 text-006. "Sort2
    193    WRITE AT 78 text-007. "Sort3
    194    WRITE AT 84 text-008. "Sort rule
    195    WRITE AT 95 text-009. "Charac
    196    WRITE AT 110 text-010. "Plant
    197 
    198 
    199    NEW-LINE.
    200 
    201    WRITE '-------' UNDER text-001.
    202    WRITE '---------------------------------------' UNDER text-002.
    203    WRITE '----' UNDER text-003.
    204    WRITE '---------' UNDER text-004.
    205    WRITE '----' UNDER text-005.
    206    WRITE '----' UNDER text-006.
    207    WRITE '----' UNDER text-007.
    208    WRITE '---------' UNDER text-008.
    209    WRITE '------' UNDER text-009.
    210    WRITE '----' UNDER text-010.
    211 
    212 
    213 
    214 
    215  ENDFORM.                    " write_title
    216 
    217  *&---------------------------------------------------------------------*
    218  *&      Form  display_list
    219  *&---------------------------------------------------------------------*
    220  *       Display list
    221  *----------------------------------------------------------------------*
    222  FORM display_list.
    223 
    224 
    225    CLEAR tab. REFRESH tab.
    226    SELECT matnr mtart matkl INTO CORRESPONDING FIELDS OF TABLE tab
    227      FROM mara
    228      WHERE matnr IN matnr
    229        AND mtart IN mtart
    230        AND matkl IN matkl.
    231 
    232 
    233 
    234 
    235    LOOP AT tab.
    236 
    237      CLEAR:
    238        g_sortkey,
    239        tab-sort1,
    240        tab-sort2,
    241        tab-sort3.
    242 
    243 
    244      CALL FUNCTION 'Z_GET_SORT_FIELD'
    245         EXPORTING
    246              i_matnr      = tab-matnr
    247              i_plant      = tab-plant                        "BC2058
    248         IMPORTING
    249             e_sortlistno       = tab-sortlistno
    250             e_atwrt            = tab-atwrt
    251             e_sort1            = tab-sort1
    252             e_sort2            = tab-sort2
    253             e_sort3            = tab-sort3
    254         EXCEPTIONS
    255              no_sortfield = 1
    256              no_material  = 2
    257              OTHERS       = 3.    .
    258      IF sy-subrc <> 0.
    259  * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    260  *         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    261      ENDIF.
    262 
    263      CLEAR makt.
    264      SELECT SINGLE * FROM makt
    265        WHERE matnr = tab-matnr
    266          AND spras = 'E'.
    267      IF sy-subrc NE 0.
    268        SELECT SINGLE * FROM makt
    269         WHERE matnr = tab-matnr
    270           AND spras = 'K'.
    271      ENDIF.
    272      IF sy-subrc = 0.
    273        tab-maktx = makt-maktx.
    274      ELSE.
    275        tab-maktx = ' '.
    276      ENDIF.
    277 
    278      MODIFY tab.
    279    ENDLOOP.
    280 
    281    IF show1 = 'X'.
    282      LOOP AT tab.
    283        IF tab-sort1 = ' ' AND
    284           tab-sort2 = ' ' AND
    285           tab-sort3 = ' '.
    286          DELETE tab.
    287        ENDIF.
    288      ENDLOOP.
    289    ENDIF.
    290 
    291    IF sort1 = 'X'.
    292      SORT tab BY matnr plant.
    293    ENDIF.
    294 
    295    IF sort2 = 'X'.
    296      SORT tab BY sort1 sort2 sort3 matnr.
    297    ENDIF.
    298 
    299 
    300    LOOP AT tab.
    301 
    302      NEW-LINE.
    303      WRITE tab-matnr UNDER text-001.
    304      WRITE tab-maktx UNDER text-002.
    305      WRITE tab-mtart UNDER text-003.
    306      WRITE tab-matkl UNDER text-004.
    307      WRITE tab-sort1 UNDER text-005.
    308      WRITE tab-sort2 UNDER text-006.
    309      WRITE tab-sort3 UNDER text-007.
    310      WRITE tab-sortlistno UNDER text-008.
    311      WRITE tab-atwrt UNDER text-009.
    312      WRITE tab-plant UNDER text-010.
    313 
    314      HIDE:
    315        tab-sortlistno,
    316        tab-atwrt,
    317        tab-sort1,
    318        tab-sort2,
    319        tab-sort3.
    320 
    321 
    322    ENDLOOP.
    323 
    324  ENDFORM.                    " display_list
    325  *&---------------------------------------------------------------------*
    326  *&      Form  update_zpluksort
    327  *&---------------------------------------------------------------------*
    328  *       Update table ZPLUKSORT with changes to sort rule
    329  *----------------------------------------------------------------------*
    330  FORM update_zpluksort.
    331    DATA: l_answer TYPE string.
    332 
    333  * Confirm update
    334    CALL FUNCTION 'POPUP_TO_CONFIRM_STEP'
    335         EXPORTING
    336              textline1      = 'Do you want to update sort rule ?'
    337              titel          = 'Update sort rule'
    338              cancel_display = ''
    339         IMPORTING
    340              answer         = l_answer.
    341    IF l_answer <> 'J'.
    342      g_okcode2000 = 'BUTCAN'.
    343      EXIT.
    344    ENDIF.
    345 
    346  * Update
    347    UPDATE zpluksort FROM g_screen2000.
    348 
    349    IF sy-subrc = 0.
    350  *   Update OK - Show message
    351      CALL FUNCTION 'POPUP_TO_DISPLAY_TEXT'
    352           EXPORTING
    353                titel     = 'Update'
    354                textline1 = 'Sort rule updated'.
    355      g_okcode2000 = 'BUTOK'.
    356 
    357    ELSE.
    358  *   Update failed - Show message
    359      CALL FUNCTION 'POPUP_TO_DISPLAY_TEXT'
    360           EXPORTING
    361                titel     = 'Error '
    362                textline1 = 'Error in update of sort rule'.
    363      g_okcode2000 = 'BUTCAN'.
    364    ENDIF.
    365 
    366 
    367 
    368  ENDFORM.                    " update_zpluksort
  
Converted from CHM to HTML with chm2web Standard 2.7 (unicode)