Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

ALV Tree Report

Former Member
0 Likes
1,062

Hi,

I Have created a ALV tree report using oop's.

The first level is the company code.

Second level is the plants allocated to each company code,

Third level is the materials in each plant.

Now i want to display the screen MM03 when i click on the material.

*&---------------------------------------------------------------------*
*&      Module  USER_COMMAND_0100  INPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE USER_COMMAND_0100 INPUT.
DATA :  R_UCOMM LIKE SY-UCOMM,
        R_SELFIELD TYPE SLIS_SELFIELD.

CASE : R_UCOMM.

WHEN '&IC1'.

        read table itab3 index R_SELFIELD-tabindex.
        check sy-subrc eq 0.
        set parameter id 'MAT' field itab3-matnr.
        call transaction 'MM03' and skip first screen.

 WHEN OTHERS.
 LEAVE SCREEN.

 ENDCASE.


ENDMODULE.                 " USER_COMMAND_0100  INPUT

This is the code i have written. I am calling this module in the PAI event.

Help please

Regards

Dinesh

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
989

HI.

check it.

FORM user_command USING r_ucomm LIKE sy-ucomm

rs_selfield TYPE slis_selfield.

CASE r_ucomm.

WHEN 'PICK'. " Double click line

  • Check field clicked on within ALVgrid report

IF rs_selfield-fieldname = 'VBELN'.

  • Read data table, using index of row user clicked on

READ TABLE t_disp_tab INTO wa_item_tab INDEX

rs_selfield-tabindex.

  • Set parameter ID for transaction screen field

SET PARAMETER ID 'VL' FIELD wa_item_tab-vbeln.

CALL TRANSACTION 'VL03N' AND SKIP FIRST SCREEN.

endif.

endform.

Reward points if useful

Regards

Jay

Hi,

I Have created a ALV tree report using oop's.

The first level is the company code.

Second level is the plants allocated to each company code,

Third level is the materials in each plant.

Now i want to display the screen MM03 when i click on the material.

*&---------------------------------------------------------------------*
*&      Module  USER_COMMAND_0100  INPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE USER_COMMAND_0100 INPUT.
DATA :  R_UCOMM LIKE SY-UCOMM,
        R_SELFIELD TYPE SLIS_SELFIELD.

CASE : R_UCOMM.

WHEN '&IC1'.

        read table itab3 index R_SELFIELD-tabindex.
        check sy-subrc eq 0.
        set parameter id 'MAT' field itab3-matnr.
        call transaction 'MM03' and skip first screen.

 WHEN OTHERS.
 LEAVE SCREEN.

 ENDCASE.


ENDMODULE.                 " USER_COMMAND_0100  INPUT

This is the code i have written. I am calling this module in the PAI event.

Help please

Regards

Dinesh

4 REPLIES 4
Read only

Former Member
0 Likes
989

Hi,

Plz check the following code.

FORM alv_init_report_events TABLES ot_events TYPE slis_t_event.

CLEAR ot_events.

REFRESH ot_events.

ot_events-name = slis_ev_user_command.

ot_events-form = 'USER_COMMAND'.

APPEND ot_events.

FORM user_command USING value(iv_ucomm) LIKE sy-ucomm

is_selfield TYPE slis_selfield.

CASE iv_ucomm.

WHEN '&IC1'. "ALV record selection

PERFORM display_record USING is_selfield.

  • when ...

  • ...

ENDCASE.

ENDFORM. " USER_COMMAND

regards,

Ruchika

Reward if useful.........

Read only

0 Likes
989

Hi,

This is my program. Please check.

*&---------------------------------------------------------------------*
*&SIMPLE_TREE_CONTROL                                                  *
*&                                                                     *
*&---------------------------------------------------------------------*

REPORT SAPSIMPLE_TREE_CONTROL_DEMO MESSAGE-ID TREE_CONTROL_MSG.

TYPE-POOLS: SLIS.

* Tables
TABLES:T001,
       T001K,
       T001W.

CLASS LCL_APPLICATION DEFINITION DEFERRED.
CLASS CL_GUI_CFW DEFINITION LOAD.

TYPES: NODE_TABLE_TYPE LIKE STANDARD TABLE OF MTREESNODE
         WITH DEFAULT KEY.

DATA: G_APPLICATION TYPE REF TO LCL_APPLICATION,
      G_CUSTOM_CONTAINER TYPE REF TO CL_GUI_CUSTOM_CONTAINER,
      G_TREE TYPE REF TO CL_GUI_SIMPLE_TREE,
      G_OK_CODE TYPE SY-UCOMM.

* Fields on Dynpro 100
DATA: G_EVENT(30),
      G_NODE_KEY TYPE TV_NODEKEY.

TYPES: BEGIN OF TYP_ONE,
       BUKRS TYPE T001K-BUKRS,
       WERKS TYPE T001W-WERKS,
       BWKEY TYPE T001K-BWKEY,
       END OF TYP_ONE.

DATA : BEGIN OF ITAB2 OCCURS 0,
        BUKRS TYPE T001K-BUKRS,
        END OF ITAB2.

DATA : BEGIN OF ITAB3 OCCURS 0,
       MATNR TYPE MARC-MATNR,
       WERKS TYPE MARC-WERKS,
       END OF ITAB3.

DATA: ITAB1 TYPE STANDARD TABLE OF TYP_ONE WITH HEADER LINE,
      WA_ITAB1 TYPE TYP_ONE.

DATA: LVL1 LIKE MTREESNODE-NODE_KEY,
      LVL2 LIKE MTREESNODE-NODE_KEY,
      LVL3 LIKE MTREESNODE-NODE_KEY.

*----------------------------------------------------------------------*
*   INCLUDE SIMPLE_TREE_CONTROL_DEMOCL1                                *
*----------------------------------------------------------------------*

CLASS LCL_APPLICATION DEFINITION.

  PUBLIC SECTION.
    METHODS:
      HANDLE_NODE_DOUBLE_CLICK
        FOR EVENT NODE_DOUBLE_CLICK
        OF CL_GUI_SIMPLE_TREE
        IMPORTING NODE_KEY,
      HANDLE_EXPAND_NO_CHILDREN
        FOR EVENT EXPAND_NO_CHILDREN
        OF CL_GUI_SIMPLE_TREE
        IMPORTING NODE_KEY.
ENDCLASS.                    "LCL_APPLICATION DEFINITION

*---------------------------------------------------------------------*
*       CLASS LCL_APPLICATION IMPLEMENTATION
*---------------------------------------------------------------------*
*
*---------------------------------------------------------------------*
CLASS LCL_APPLICATION IMPLEMENTATION.

  METHOD  HANDLE_NODE_DOUBLE_CLICK.
    " this method handles the node double click event of the tree
    " control instance
    " show the key of the double clicked node in a dynpro field
    G_EVENT = 'NODE_DOUBLE_CLICK'.
    G_NODE_KEY = NODE_KEY.
  ENDMETHOD.                    "HANDLE_NODE_DOUBLE_CLICK

  METHOD HANDLE_EXPAND_NO_CHILDREN.
    " this method handles the expand no children event of the tree
    " control instance
    DATA: NODE_TABLE TYPE NODE_TABLE_TYPE,
          NODE TYPE MTREESNODE,
          LD_NODE TYPE STRING.

    " show the key of the double clicked node in a dynpro field
    G_EVENT = 'EXPAND_NO_CHILDREN'.
    G_NODE_KEY = NODE_KEY.

    IF NODE_KEY = 'Child1'.                                 "#EC NOTEXT
    ENDIF.
  ENDMETHOD.                    "HANDLE_EXPAND_NO_CHILDREN

ENDCLASS.                    "LCL_APPLICATION IMPLEMENTATION


*-------------------------------------------------------------------
***INCLUDE simple_tree_control_demoO01 .
*-------------------------------------------------------------------
*&---------------------------------------------------------------------*
*&      Module  PBO_0400  OUTPUT
*&---------------------------------------------------------------------*

MODULE PBO_0100 OUTPUT.
  SET PF-STATUS 'STAUS_1'.
  IF G_TREE IS INITIAL.
    " The Tree Control has not been created yet.
    " Create a Tree Control and insert nodes into it.
    PERFORM CREATE_AND_INIT_TREE.
  ENDIF.
ENDMODULE.                 " PBO_0100  OUTPUT

*-------------------------------------------------------------------
***INCLUDE simple_tree_control_demoI01 .
*-------------------------------------------------------------------
*&---------------------------------------------------------------------*
*&      Module  PAI_0400  INPUT
*&---------------------------------------------------------------------*

MODULE PAI_0100 INPUT.
  DATA: RETURN_CODE TYPE I.

  CALL METHOD CL_GUI_CFW=>DISPATCH
    IMPORTING
      RETURN_CODE = RETURN_CODE.
  IF RETURN_CODE <> CL_GUI_CFW=>RC_NOEVENT.
    " a control event occured => exit PAI
    CLEAR G_OK_CODE.
    EXIT.
  ENDIF.

  CASE G_OK_CODE.
    WHEN 'TEST'.
      CALL METHOD G_TREE->EXPAND_NODE
        EXPORTING
          NODE_KEY = 'New1'.
    WHEN 'BACK'. " Finish program
      IF NOT G_CUSTOM_CONTAINER IS INITIAL.
        " destroy tree container (detroys contained tree control, too)
        CALL METHOD G_CUSTOM_CONTAINER->FREE
          EXCEPTIONS
            CNTL_SYSTEM_ERROR = 1
            CNTL_ERROR        = 2.
        IF SY-SUBRC <> 0.
          MESSAGE A000.
        ENDIF.
        CLEAR G_CUSTOM_CONTAINER.
        CLEAR G_TREE.
      ENDIF.
      LEAVE PROGRAM.
  ENDCASE.
* CAUTION: clear ok code!
  CLEAR G_OK_CODE.
ENDMODULE.                 " PAI_0100  INPUT

*-------------------------------------------------------------------
***INCLUDE simple_tree_control_demoF01 .
*-------------------------------------------------------------------

*&---------------------------------------------------------------------*
*&      Form  CREATE_AND_INIT_TREE
*&---------------------------------------------------------------------*

FORM CREATE_AND_INIT_TREE.
  DATA: NODE_TABLE TYPE NODE_TABLE_TYPE,
        EVENTS TYPE CNTL_SIMPLE_EVENTS,
        EVENT TYPE CNTL_SIMPLE_EVENT.

* create a container for the tree control
  CREATE OBJECT G_CUSTOM_CONTAINER
    EXPORTING
      " the container is linked to the custom control with the
      " name 'TREE_CONTAINER' on the dynpro
      CONTAINER_NAME = 'TREE_CONTAINER'
    EXCEPTIONS
      CNTL_ERROR = 1
      CNTL_SYSTEM_ERROR = 2
      CREATE_ERROR = 3
      LIFETIME_ERROR = 4
      LIFETIME_DYNPRO_DYNPRO_LINK = 5.
  IF SY-SUBRC <> 0.
    MESSAGE A000.
  ENDIF.


* create a tree control
  CREATE OBJECT G_TREE
    EXPORTING
      PARENT              = G_CUSTOM_CONTAINER
      " single node selection is used
      NODE_SELECTION_MODE = CL_GUI_SIMPLE_TREE=>NODE_SEL_MODE_SINGLE
    EXCEPTIONS
      LIFETIME_ERROR              = 1
      CNTL_SYSTEM_ERROR           = 2
      CREATE_ERROR                = 3
      FAILED                      = 4
      ILLEGAL_NODE_SELECTION_MODE = 5.
  IF SY-SUBRC <> 0.
    MESSAGE A000.
  ENDIF.

* define the events which will be passed to the backend
  " node double click
  EVENT-EVENTID = CL_GUI_SIMPLE_TREE=>EVENTID_NODE_DOUBLE_CLICK.
  EVENT-APPL_EVENT = 'X'. " process PAI if event occurs
  APPEND EVENT TO EVENTS.

  " expand no children
  EVENT-EVENTID = CL_GUI_SIMPLE_TREE=>EVENTID_EXPAND_NO_CHILDREN.
  EVENT-APPL_EVENT = 'X'.
  APPEND EVENT TO EVENTS.

  CALL METHOD G_TREE->SET_REGISTERED_EVENTS
    EXPORTING
      EVENTS                    = EVENTS
    EXCEPTIONS
      CNTL_ERROR                = 1
      CNTL_SYSTEM_ERROR         = 2
      ILLEGAL_EVENT_COMBINATION = 3.
  IF SY-SUBRC <> 0.
    MESSAGE A000.
  ENDIF.

* assign event handlers in the application class to each desired event
  SET HANDLER G_APPLICATION->HANDLE_NODE_DOUBLE_CLICK FOR G_TREE.
  SET HANDLER G_APPLICATION->HANDLE_EXPAND_NO_CHILDREN FOR G_TREE.

  PERFORM BUILD_NODE_TABLE USING NODE_TABLE.

ENDFORM.                    " CREATE_AND_INIT_TREE
*&---------------------------------------------------------------------*
*&      Form  build_node_table
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*

FORM BUILD_NODE_TABLE
  USING
    NODE_TABLE TYPE NODE_TABLE_TYPE.

  DATA: NODE LIKE MTREESNODE,
        LD_NODE TYPE STRING.

  DELETE ITAB3 WHERE MATNR = ' '.
  LOOP AT ITAB2 .
    LVL1 = SY-TABIX.
    CONDENSE LVL1.
    CONCATENATE 'LV1' LVL1 INTO LVL1.
* Build the node table.

* Caution: The nodes are inserted into the tree according to the order
* in which they occur in the table. In consequence, a node must not
* occur in the node table before its parent node.

* Node with key 'Root'
    NODE-NODE_KEY = LVL1. "ITAB2-BUKRS.  " 'Root'.   #EC NOTEXT
    " Key of the node
    CLEAR NODE-RELATKEY.      " Special case: A root node has no parent
    CLEAR NODE-RELATSHIP.     " node.

    NODE-HIDDEN = ' '.        " The node is visible,
    NODE-DISABLED = ' '.      " selectable,
    NODE-ISFOLDER = 'X'.      " a folder.
    CLEAR NODE-N_IMAGE.       " Folder-/ Leaf-Symbol in state "closed":
    " use default.
    CLEAR NODE-EXP_IMAGE.     " Folder-/ Leaf-Symbol in state "open":
    " use default
    CLEAR NODE-EXPANDER.      " see below.
    NODE-TEXT = ITAB2-BUKRS.
    APPEND NODE TO NODE_TABLE.

* Node with key 'Child1'
*     Node with key wa_itab1-bwkey    "'Child1'
    " Key of the node
    LOOP AT ITAB1 INTO WA_ITAB1 WHERE BUKRS EQ ITAB2-BUKRS.

      LVL2 = SY-TABIX.
      CONDENSE LVL2.
      CONCATENATE 'LV2' LVL2 INTO LVL2.

      LD_NODE = SY-TABIX.
      CONCATENATE WA_ITAB1-WERKS LD_NODE INTO LD_NODE.
      NODE-NODE_KEY = LVL2.
      "wa_ITAB1-WERKS. "ld_node.  "'Child1'. #EC NOTEXT

      " Node is inserted as child of the node with key wa_ITAB1-BUKRS.
      NODE-RELATKEY = LVL1. "wa_ITAB1-BUKRS..
      NODE-RELATSHIP = CL_GUI_SIMPLE_TREE=>RELAT_LAST_CHILD.

      NODE-HIDDEN = ' '.
      NODE-DISABLED = ' '.
      NODE-ISFOLDER = 'X'.
      CLEAR NODE-N_IMAGE.
      CLEAR NODE-EXP_IMAGE.
      NODE-EXPANDER = 'X'. " The node is marked with a '+', although
      " it has no children. When the user clicks on the
      " + to open the node, the event
      " expand_no_children is fired. The programmer can
      " add the children of the
      " node within the event handler of the
      " expand_no_children event
      " (see method handle_expand_no_children
      " of class lcl_application)

      NODE-TEXT = WA_ITAB1-WERKS.
      APPEND NODE TO NODE_TABLE.

      LOOP AT ITAB3 WHERE WERKS EQ WA_ITAB1-WERKS.
        LVL3 = SY-TABIX.
        CONDENSE LVL3.
        CONCATENATE 'LV3' LVL3 INTO LVL3.

        LD_NODE = SY-TABIX.
        IF ITAB3-MATNR NE ' '.
          CONCATENATE 'MAT' LD_NODE INTO LD_NODE.
          NODE-NODE_KEY = LVL3. "ld_node.  "'Child1'. #EC NOTEXT
*          CLEAR NODE.
*          NODE-NODE_KEY = itab3-matnr.                      "#EC NOTEXT
          NODE-RELATKEY = LVL2. "wa_itab1-werks.
          NODE-RELATSHIP = '6'. "CL_GUI_SIMPLE_TREE=>RELAT_LAST_CHILD.
          NODE-N_IMAGE = ' '.                               "@10@
          NODE-EXPANDER = SPACE.
          NODE-ISFOLDER = SPACE.
          NODE-TEXT = ITAB3-MATNR.
          APPEND NODE TO NODE_TABLE.
        ENDIF.
      ENDLOOP.
    ENDLOOP.
  ENDLOOP.

  DELETE NODE_TABLE WHERE NODE_KEY = '000000000000'.

  CALL METHOD G_TREE->ADD_NODES
    EXPORTING
      TABLE_STRUCTURE_NAME           = 'MTREESNODE'
      NODE_TABLE                     = NODE_TABLE
    EXCEPTIONS
      FAILED                         = 1
      ERROR_IN_NODE_TABLE            = 2
      DP_ERROR                       = 3
      TABLE_STRUCTURE_NAME_NOT_FOUND = 4
      OTHERS                         = 5.
  IF SY-SUBRC <> 0.
    MESSAGE A000.
  ENDIF.
ENDFORM.                    " build_node_table

START-OF-SELECTION.
* create the application object
* this object is needed to handle the ABAP Objects Events of
* Controls
  CREATE OBJECT G_APPLICATION.

  SET SCREEN 0100.

  SELECT T001K~BUKRS
         T001W~WERKS
         T001K~BWKEY
         INTO TABLE ITAB1
         FROM T001K INNER JOIN T001W ON T001K~BWKEY = T001W~WERKS
                                    AND T001K~BWKEY = T001W~BWKEY.

  SORT ITAB1 BY BUKRS .
  DELETE ADJACENT DUPLICATES FROM ITAB1.

  LOOP AT ITAB1 INTO WA_ITAB1.
    ITAB2-BUKRS = WA_ITAB1-BUKRS.
    APPEND ITAB2.
  ENDLOOP.

  SORT ITAB2 BY BUKRS.

  DELETE ADJACENT DUPLICATES FROM ITAB2.

  SELECT MATNR
         WERKS
         FROM MARC
         INTO TABLE ITAB3.
**       from marc inner join t001w on marc~werks = t001w~werks.
  LOOP AT ITAB1.
    WA_ITAB1-WERKS = ITAB3-WERKS.
    APPEND ITAB3.
  ENDLOOP.

  SORT ITAB3 BY WERKS.

  DELETE ADJACENT DUPLICATES FROM ITAB3.
*&---------------------------------------------------------------------*
*&      Module  USER_COMMAND_0100  INPUT
*&---------------------------------------------------------------------*

<b>MODULE USER_COMMAND_0100 INPUT.
DATA : R_UCOMM LIKE SY-UCOMM,
       R_SELFIELD TYPE SLIS_SELFIELD.


  CASE : R_UCOMM.

    WHEN '&IC1'.

      READ TABLE ITAB3 INDEX R_SELFIELD-TABINDEX.
      CHECK SY-SUBRC EQ 0.
      SET PARAMETER ID 'MAT' FIELD ITAB3-MATNR.
      CALL TRANSACTION 'MM03' AND SKIP FIRST SCREEN.

    WHEN OTHERS.
      LEAVE SCREEN.

  ENDCASE.
ENDMODULE.                 " USER_COMMAND_0100  INPUT

</b>

I am getting the problem as R_UCOMM is not assigned the value of &IC1.

when i change that value in the debugging mode it is coming properly.

PLEASE HELP

Dinesh.

Read only

Former Member
0 Likes
990

HI.

check it.

FORM user_command USING r_ucomm LIKE sy-ucomm

rs_selfield TYPE slis_selfield.

CASE r_ucomm.

WHEN 'PICK'. " Double click line

  • Check field clicked on within ALVgrid report

IF rs_selfield-fieldname = 'VBELN'.

  • Read data table, using index of row user clicked on

READ TABLE t_disp_tab INTO wa_item_tab INDEX

rs_selfield-tabindex.

  • Set parameter ID for transaction screen field

SET PARAMETER ID 'VL' FIELD wa_item_tab-vbeln.

CALL TRANSACTION 'VL03N' AND SKIP FIRST SCREEN.

endif.

endform.

Reward points if useful

Regards

Jay

Read only

Former Member
0 Likes
989

THANKS