Doppelklick im Table Control

Today one of the member of our telegram group aked how to open a document in it’s related transaction by doubleclicking the documentnumber in a tablecontrol. So I created a small demo report to open a material by doubleclicking on materialnumber.

Create a report in SE38 or SE80 and copy the following code into it.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
REPORT zstkeos_table_control.
 
TYPES:
  BEGIN OF gty_mara,
    matnr           TYPE mara-matnr,
    ersda           TYPE mara-ersda,
    ernam           TYPE mara-ernam,
    laeda           TYPE mara-laeda,
    aenam           TYPE mara-aenam,
    vpsta           TYPE mara-vpsta,
    pstat           TYPE mara-pstat,
    lvorm           TYPE mara-lvorm,
  END OF gty_mara.
TABLES:
  mara.
DATA:
  gv_ucomm          TYPE syucomm,
  gv_initialization TYPE char1,
  gv_field          TYPE char128,
  gv_line           TYPE systepl.
DATA:
  gs_mara           TYPE gty_mara,
  gt_mara           TYPE TABLE OF gty_mara.
 
CONTROLS:
  tc_mara           TYPE TABLEVIEW USING SCREEN 0100.
 
CALL SCREEN 100.
 
*&---------------------------------------------------------------------*
*&      Module  TEST_INIT  OUTPUT
*&---------------------------------------------------------------------*
MODULE tc_init OUTPUT.
  IF gv_initialization IS INITIAL.
    SELECT matnr ersda ernam laeda aenam vpsta pstat lvorm
      FROM mara INTO TABLE gt_mara
      UP TO 100 ROWS.
    gv_initialization = 'X'.
    REFRESH CONTROL 'tc_mara' FROM SCREEN '0100'.
  ENDIF.
  IF gv_line IS NOT INITIAL.
    SET CURSOR FIELD gv_field LINE gv_line.
  ENDIF.
ENDMODULE.
 
*&---------------------------------------------------------------------*
*&      Module  TEST_MOVE  OUTPUT
*&---------------------------------------------------------------------*
MODULE test_move OUTPUT.
  MOVE-CORRESPONDING gs_mara TO mara.
ENDMODULE.
 
*&---------------------------------------------------------------------*
*&      Module  STATUS_0100  OUTPUT
*&---------------------------------------------------------------------*
MODULE status_0100 OUTPUT.
  SET PF-STATUS '0100'.
  SET TITLEBAR '0100'.
ENDMODULE.
 
*&---------------------------------------------------------------------*
*&      Module  USER_COMMAND_0100  INPUT
*&---------------------------------------------------------------------*
MODULE user_command_0100 INPUT.
 
  DATA:
    lv_itab_line  TYPE i,
    lv_matnr      TYPE matnr.
 
  gv_ucomm = sy-ucomm.
  CLEAR: sy-ucomm.
  CASE gv_ucomm.
    WHEN 'BACK' OR 'EXIT' OR 'CANC'.
      LEAVE PROGRAM.
    WHEN 'MARA'.
      GET CURSOR FIELD gv_field LINE gv_line.
      CASE gv_field.
        WHEN 'MARA-MATNR'.
          lv_itab_line = tc_mara-top_line + gv_line - 1.
 
          READ TABLE gt_mara INTO gs_mara INDEX lv_itab_line.
          IF sy-subrc EQ 0.
            lv_matnr = gs_mara-matnr.
            SET PARAMETER ID 'MAT' FIELD lv_matnr.
            CALL TRANSACTION 'MM03' AND SKIP FIRST SCREEN.
          ENDIF.
      ENDCASE.
  ENDCASE.
ENDMODULE.

Create a screen 100 and copy the following code into flow logic of the screen.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
PROCESS BEFORE OUTPUT.
  MODULE tc_init.
 
  LOOP AT gt_mara INTO gs_mara WITH CONTROL tc_mara
       CURSOR tc_mara-current_line.
    MODULE test_move.
  ENDLOOP.
 
  MODULE status_0100.
 
PROCESS AFTER INPUT.
  LOOP AT gt_mara.
  ENDLOOP.
 
  MODULE user_command_0100.

Create PF-Status 0100 as shown below.

Important for the doubleclick is funktioncode 4.
Create title 0100 as shown below.
Now place the tablecontrol on screen 100 as described below.
1. Use normal tablecontrol and not tablecontrol wizard. 2. Fill the screen with the tablecontrol object
1. Open the Dictionary/Program Fields Window 2. Enter the tablename “MARA” 3. click Get From Dictionary 4. Choose the fields 5. Confirm with OK
Place the selected fields in the grey area at top of the tablecontrol.
1. Doubleclick on every field directly under the header 2. Uncheck Input Field for all fields
1. Check Responds to double-click for the first column in tablecontrol.

Now activate all created objects and execute the report.

Doubleclick one Material in Column Material.
See that the material will be open