Skip to Content
0

CNTB_ERROR_FCODE while processing alv tree

Mar 13, 2017 at 09:22 AM

121

avatar image
Former Member
REPORT yyidoc_automation.
*REPORT  Z_ALV_TREE                    .
****TYPES

INCLUDE yyyyidoc_automation_dd.

*INCLUDE yyz_alv_tree_dd.



SELECTION-SCREEN BEGIN OF BLOCK b1.

SELECT-OPTIONS: s_mestyp FOR edidc-mestyp,

                s_credat FOR edidc-credat OBLIGATORY.

SELECTION-SCREEN SKIP 1.

PARAMETERS: p_check AS CHECKBOX.

SELECTION-SCREEN END OF BLOCK b1.





START-OF-SELECTION.

  IF p_check EQ gc_x.

    PERFORM ztable_update.

*  ELSE.

*    PERFORM get_ztable.

  ENDIF.

CALL SCREEN 100.

END-OF-SELECTION.



****

*&---------------------------------------------------------------------*

*&      Module  STATUS_0100  OUTPUT

*&---------------------------------------------------------------------*

MODULE status_0100 OUTPUT.

  REFRESH : gt_fieldcatalog, it_exit1.

  SET PF-STATUS 'ALVTREE'.

  SET TITLEBAR 'IDOC STATUS'.

*  IF tree1 IS INITIAL.

  PERFORM get_ztable.

*  PERFORM free_objects.

* CATALOG

  PERFORM fo_fieldcat.

* CREATE TREE

  PERFORM create_tree.

* create Hierarchy-header

  PERFORM build_hierarchy_header CHANGING l_hierarchy_header.

* create info-table for html-header

  PERFORM build_comment USING

                 lt_list_commentary.

* repid for saving variants

  ls_variant-report = sy-repid.



* Creation of ALV

  CALL METHOD tree1->set_table_for_first_display

    EXPORTING

      is_hierarchy_header = l_hierarchy_header

      it_list_commentary  = lt_list_commentary

      i_save              = 'A'

      is_variant          = ls_variant

    CHANGING

      it_outtab           = it_exit1

      it_fieldcatalog     = gt_fieldcatalog.

* create hierarchy

  PERFORM create_hierarchy.

* register events

  PERFORM register_events.

*  ENDIF.

  CALL METHOD cl_gui_cfw=>flush.

ENDMODULE.                 " STATUS_0100  OUTPUT

*&---------------------------------------------------------------------*

*&      Module  USER_COMMAND_0100  INPUT

*&---------------------------------------------------------------------*

MODULE user_command_0100 INPUT.

  CLEAR ok_code.

  ok_code = sy-ucomm.

  CASE ok_code.

    WHEN 'EXIT' OR 'BACK' .

      PERFORM exit_program.

    WHEN 'BACK1'.

      CALL METHOD tree1->free.

      LEAVE TO SCREEN 0.

    WHEN 'REPROCESS'.

      PERFORM get_selected_item.



    WHEN 'REFRESH'.

      PERFORM refresh.

      REFRESH gt_docnum2.

      CALL SCREEN 100.

    WHEN OTHERS.

      CALL METHOD cl_gui_cfw=>dispatch.

  ENDCASE.

  CLEAR ok_code.

  CALL METHOD cl_gui_cfw=>flush.

ENDMODULE.                 " USER_COMMAND_0100  INPUT

*&---------------------------------------------------------------------*

*&      Form  exit_program

*&---------------------------------------------------------------------*

FORM exit_program.

  CALL METHOD tree1->free.

  LEAVE TO SCREEN 0.

ENDFORM.                    " exit_program

*&---------------------------------------------------------------------*

*&      Form  fo_fieldcat

*&---------------------------------------------------------------------*

FORM fo_fieldcat.

  DATA: ls_fieldcatalog TYPE lvc_s_fcat.

****MAIN NODE

  ls_fieldcatalog-col_pos = '1'.

  ls_fieldcatalog-fieldname = 'NODE_MAIN'.

  ls_fieldcatalog-tabname = 'IT_EXIT'.

  ls_fieldcatalog-coltext  = 'Main Node'.

  ls_fieldcatalog-key = 'X'.

  ls_fieldcatalog-just = 'L'.

  ls_fieldcatalog-no_out = 'X'.

  ls_fieldcatalog-outputlen = '50'.

  APPEND  ls_fieldcatalog TO gt_fieldcatalog.

  CLEAR ls_fieldcatalog.



**** idoc number

  ls_fieldcatalog-col_pos = '2'.

  ls_fieldcatalog-fieldname = 'IDOC_NUM'.

  ls_fieldcatalog-tabname = 'IT_EXIT'.

  ls_fieldcatalog-coltext  = 'Idoc Number'.

*  ls_fieldcatalog-key = 'X'.

  ls_fieldcatalog-just = 'L'.

*  ls_fieldcatalog-no_out = 'X'.

*  ls_fieldcatalog-hotspot = 'X'.

  ls_fieldcatalog-outputlen = '30'.

  APPEND  ls_fieldcatalog TO gt_fieldcatalog.

  CLEAR ls_fieldcatalog.



* Material Number

  ls_fieldcatalog-col_pos = '3'.

  ls_fieldcatalog-fieldname = 'NODE_N01'.

  ls_fieldcatalog-tabname = 'IT_EXIT'.

  ls_fieldcatalog-coltext  = 'Material Number'.

*  ls_fieldcatalog-key = 'X'.

  ls_fieldcatalog-just = 'L'.

*  ls_fieldcatalog-no_out = 'X'.

*  ls_fieldcatalog-hotspot = 'X'.

  ls_fieldcatalog-outputlen = '30'.

  APPEND  ls_fieldcatalog TO gt_fieldcatalog.

  CLEAR ls_fieldcatalog.

* Customer number

  ls_fieldcatalog-col_pos = '4'.

  ls_fieldcatalog-fieldname = 'NODE_N02'.

  ls_fieldcatalog-tabname = 'IT_EXIT'.

  ls_fieldcatalog-coltext  = 'Customer number'.

*  ls_fieldcatalog-key = 'X'.

  ls_fieldcatalog-just = 'L'.

*  ls_fieldcatalog-no_out = 'X'.

  ls_fieldcatalog-outputlen = '30'.

  APPEND  ls_fieldcatalog TO gt_fieldcatalog.

*  CLEAR LS_FIELDCATALOG.

* Vendor Number4

  ls_fieldcatalog-col_pos = '4'.

  ls_fieldcatalog-fieldname = 'NODE_N03'.

  ls_fieldcatalog-tabname = 'IT_EXIT'.

  ls_fieldcatalog-coltext  = 'Vendor Number'.

*  ls_fieldcatalog-key = 'X'.

  ls_fieldcatalog-just = 'L'.

*  ls_fieldcatalog-no_out = 'X'.

  ls_fieldcatalog-outputlen = '30'.

  APPEND  ls_fieldcatalog TO gt_fieldcatalog.

  CLEAR ls_fieldcatalog.

ENDFORM.                    " fo_fieldcat

*&---------------------------------------------------------------------*

*&      Form  create_tree

*&---------------------------------------------------------------------*

FORM create_tree.

* create container for alv-tree

  DATA: l_tree_container_name(30) TYPE c.

*        l_custom_container        TYPE REF TO cl_gui_custom_container.

  l_tree_container_name = 'TREE1'.

  IF l_custom_container IS INITIAL.

    CREATE OBJECT l_custom_container

      EXPORTING

        container_name              = l_tree_container_name

      EXCEPTIONS

        cntl_error                  = 1

        cntl_system_error           = 2

        create_error                = 3

        lifetime_error              = 4

        lifetime_dynpro_dynpro_link = 5.

    IF sy-subrc <> 0.

      MESSAGE x208(00) WITH 'ERROR'.

    ENDIF.

  ENDIF.

* create tree control

  IF tree1 IS INITIAL.

    CREATE OBJECT tree1

      EXPORTING

        parent                      = l_custom_container

        node_selection_mode         = cl_gui_column_tree=>node_sel_mode_multiple

        item_selection              = 'X'

        no_html_header              = ''

        no_toolbar                  = ''

      EXCEPTIONS

        cntl_error                  = 1

        cntl_system_error           = 2

        create_error                = 3

        lifetime_error              = 4

        illegal_node_selection_mode = 5

        failed                      = 6

        illegal_column_name         = 7.

    IF sy-subrc <> 0.

      MESSAGE x208(00) WITH 'ERROR'.                        "#EC NOTEXT

    ENDIF.

  ENDIF.



****

ENDFORM.                    " create_tree

*&---------------------------------------------------------------------*

*&      Form  build_hierarchy_header

*&---------------------------------------------------------------------*

FORM build_hierarchy_header CHANGING

                               p_hierarchy_header TYPE treev_hhdr.

  CLEAR p_hierarchy_header.

  p_hierarchy_header-heading = 'Message Types'.

  p_hierarchy_header-width = 70.

  p_hierarchy_header-width_pix = ''.

ENDFORM.                    " build_hierarchy_header

*&---------------------------------------------------------------------*

*&      Form  build_comment

*&---------------------------------------------------------------------*

*       text

*----------------------------------------------------------------------*

*      -->P_LT_LIST_COMMENTARY  text

*----------------------------------------------------------------------*

FORM build_comment USING

      pt_list_commentary TYPE slis_t_listheader.

  DATA: ls_line  TYPE slis_listheader, text(60) TYPE c.

  DATA  url(132).

  DATA picture TYPE REF TO cl_gui_picture.

  REFRESH:pt_list_commentary.

  CLEAR ls_line.

  ls_line-typ  = 'H'.

  ls_line-info = 'Number Of Counts'."sy-title.

  APPEND ls_line TO pt_list_commentary.



  IF NOT gv_matcnt IS INITIAL .

    CLEAR ls_line.

    ls_line-key = 'Matmas:'.

    ls_line-info = gv_matcnt."sy-uname.

    ls_line-typ  = 'S'.

    APPEND ls_line TO pt_list_commentary.

  ENDIF.

  IF NOT gv_crecnt IS INITIAL.

    CLEAR ls_line.

    ls_line-key = 'Cremas:'.

    ls_line-info = gv_crecnt."sy-uname.

    ls_line-typ  = 'S'.

    APPEND ls_line TO pt_list_commentary.

  ENDIF.



  IF NOT gv_debcnt IS INITIAL.

    CLEAR ls_line.

    ls_line-key = 'Debmas:'.

    ls_line-info = gv_debcnt."sy-uname.

    ls_line-typ  = 'S'.

    APPEND ls_line TO pt_list_commentary.

  ENDIF.



  IF NOT gv_adrcnt IS INITIAL.

    CLEAR ls_line.

    ls_line-key = 'Adrmas:'.

    ls_line-info = gv_adrcnt."sy-uname.

    ls_line-typ  = 'S'.

    APPEND ls_line TO pt_list_commentary.

  ENDIF.



  IF NOT gv_maqcnt IS INITIAL.

    CLEAR ls_line.

    ls_line-key = 'Matqm:'.

    ls_line-info = gv_maqcnt."sy-uname.

    ls_line-typ  = 'S'.

    APPEND ls_line TO pt_list_commentary.

  ENDIF.



  IF NOT gv_procnt IS INITIAL.

    CLEAR ls_line.

    ls_line-key = 'Project:'.

    ls_line-info = gv_procnt."sy-uname.

    ls_line-typ  = 'S'.

    APPEND ls_line TO pt_list_commentary.

  ENDIF.



  IF NOT gv_clfcnt IS INITIAL.

    CLEAR ls_line.

    ls_line-key = 'Clfmas:'.

    ls_line-info = gv_clfcnt."sy-uname.

    ls_line-typ  = 'S'.

    APPEND ls_line TO pt_list_commentary.

  ENDIF.





ENDFORM.                    " build_comment

*&---------------------------------------------------------------------*

*&      Form  create_hierarchy

*&---------------------------------------------------------------------*

FORM create_hierarchy.

* add data to tree

  DATA: l_key_main      TYPE lvc_nkey,

        l_key_node1     TYPE lvc_nkey,

        l_key_node2     TYPE lvc_nkey,

        l_key_node3     TYPE lvc_nkey,

        l_node          TYPE lvc_value,

        p_node_key      TYPE lvc_nkey,

        p_node_key2     TYPE lvc_nkey,

        p_aux           TYPE it,

        p_node_cremas   TYPE lvc_nkey,

        p_node_cremas2  TYPE lvc_nkey,

        p_node_cremas3  TYPE lvc_nkey,

        p_node_debmas   TYPE lvc_nkey,

        p_node_debmas2  TYPE lvc_nkey,

        p_node_clfmas   TYPE lvc_nkey,

        p_node_clfmas2  TYPE lvc_nkey,

        p_node_adrmas   TYPE lvc_nkey,

        p_node_adrmas2  TYPE lvc_nkey,

        p_node_matqm    TYPE lvc_nkey,

        p_node_matqm2   TYPE lvc_nkey,

        p_node_project  TYPE lvc_nkey,

        p_node_project2 TYPE lvc_nkey.



  DATA: l_node_text TYPE lvc_value,

        lv_var      TYPE char10,

        lv_text     TYPE lvc_value,

        lv_count    TYPE i,

        lv_count2   TYPE lvc_value,

        lv_msgid    TYPE t100-arbgb,

        lv_msgno    TYPE t100-msgnr.

  DATA: l_event_receiver TYPE REF TO lcl_tree_event_receiver.

  CREATE OBJECT l_event_receiver.

* set item-layout

  DATA: lt_item_layout TYPE lvc_t_layi,

        ls_item_layout TYPE lvc_s_layi.

  ls_item_layout-fieldname = tree1->c_hierarchy_column_name.

  ls_item_layout-class   = cl_gui_column_tree=>item_class_text.

*  ls_item_layout-editable = 'X'.

  APPEND ls_item_layout TO lt_item_layout.

*  p_aux-node_n01 = '92111'.



  " MATMAS

  IF NOT gt_matmas_n2 IS INITIAL.

    IF NOT gv_matcnt IS INITIAL.

      CALL METHOD tree1->add_node

        EXPORTING

          i_relat_node_key = ''

          i_relationship   = cl_gui_column_tree=>relat_last_child

*         IS_OUTTAB_LINE   = P_AUX

          i_node_text      = 'MATMAS' "L_NODE_TEXT

          it_item_layout   = lt_item_layout

        IMPORTING

          e_new_node_key   = p_node_key.



* Matmas Loop



      LOOP AT gt_matmas_n2 INTO gs_matmas_n2.

        lv_msgid = gs_matmas_n2-msgid.

        lv_msgno = gs_matmas_n2-msgno.

        CALL FUNCTION 'MESSAGE_PREPARE'

          EXPORTING

            language               = sy-langu

            msg_id                 = lv_msgid

            msg_no                 = lv_msgno

*           msg_var1               = "<ts_matmas>-msgv1

*           msg_var2               = "<ts_matmas>-msgv2

*           msg_var3               = "<ts_matmas>-msgv3

*           msg_var4               = "<ts_matmas>-msgv4

          IMPORTING

            msg_text               = lv_text

          EXCEPTIONS

            function_not_completed = 1

            message_not_found      = 2

            OTHERS                 = 3.

        IF sy-subrc <> 0.

* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

        ENDIF.



        CALL METHOD tree1->add_node

          EXPORTING

            i_relat_node_key = p_node_key

            i_relationship   = cl_gui_column_tree=>relat_last_child

*           IS_OUTTAB_LINE   = P_AUX

            i_node_text      = lv_text

            it_item_layout   = lt_item_layout

          IMPORTING

            e_new_node_key   = p_node_key2.



        LOOP AT gt_matmas_n INTO  gs_matmas_n WHERE msgno = gs_matmas_n2-msgno.

          lv_count = lv_count + 1.

          lv_count2 = lv_count.

          READ TABLE gt_matnr INTO gs_matnr WITH KEY docnum = gs_matmas_n-docnum.

          IF sy-subrc EQ 0.

            p_aux-idoc_num = gs_matnr-docnum.

            p_aux-node_n01 = gs_matnr-matnr.

            CALL METHOD tree1->add_node

              EXPORTING

                i_relat_node_key = p_node_key2

                i_relationship   = cl_gui_column_tree=>relat_last_child

                is_outtab_line   = p_aux

                i_node_text      = lv_count2

                it_item_layout   = lt_item_layout.

            CLEAR: lv_count2,p_aux.

          ENDIF.



        ENDLOOP.

        CLEAR : lv_count2,lv_count.

      ENDLOOP.

    ENDIF.

  ENDIF.



  SORT gt_edid4 BY docnum.

*  SORT gt_edidc BY docnum.

  gt_edids_n2[] = gt_edids_n[].

  SORT gt_edids_n2 BY stamid stamno stapa1 stapa2 stapa3 stapa4.

  DELETE ADJACENT DUPLICATES FROM gt_edids_n2 COMPARING stamid stamno stapa1 stapa2 stapa3 stapa4.



* cremas

  IF NOT gv_crecnt IS INITIAL.

*    IF gv_creflag2 NE gc_x.

    CALL METHOD tree1->add_node

      EXPORTING

        i_relat_node_key = ''

        i_relationship   = cl_gui_column_tree=>relat_last_child

*       IS_OUTTAB_LINE   = P_AUX

        i_node_text      = 'CREMAS' "L_NODE_TEXT

        it_item_layout   = lt_item_layout

      IMPORTING

        e_new_node_key   = p_node_cremas.



    CLEAR lv_count2.



* Cremas loop

    LOOP AT gt_edids_n2 INTO gs_edids_n2.

      READ TABLE gt_edid4 INTO gs_edid4 WITH KEY  docnum = gs_edids_n2-docnum BINARY SEARCH.

      IF sy-subrc EQ 0.

        IF gs_edid4-segnam = 'E1LFA1M'.

          CLEAR gv_text.

          PERFORM read_text.

          CALL METHOD tree1->add_node

            EXPORTING

              i_relat_node_key = p_node_cremas

              i_relationship   = cl_gui_column_tree=>relat_last_child

*             IS_OUTTAB_LINE   = P_AUX

              i_node_text      = gv_text

              it_item_layout   = lt_item_layout

            IMPORTING

              e_new_node_key   = p_node_cremas2.



          LOOP AT gt_edids_n INTO gs_edids_n WHERE  stamid = gs_edids_n2-stamid AND

                                                stamno = gs_edids_n2-stamno AND

                                                stapa1 = gs_edids_n2-stapa1 AND

                                                stapa2 = gs_edids_n2-stapa2 AND

                                                stapa3 = gs_edids_n2-stapa3 AND

                                                stapa4 = gs_edids_n2-stapa4.



            READ TABLE gt_edid4 INTO gs_edid4 WITH KEY  docnum = gs_edids_n-docnum BINARY SEARCH.

            IF sy-subrc EQ 0.

              IF gs_edid4-segnam = 'E1LFA1M'.

                lv_count = lv_count + 1.

                lv_count2 = lv_count.

                p_aux-idoc_num = gs_edid4-docnum.

                p_aux-node_n03 = gs_edid4-sdata+3(10).

                CALL METHOD tree1->add_node

                  EXPORTING

                    i_relat_node_key = p_node_cremas2

                    i_relationship   = cl_gui_column_tree=>relat_last_child

                    is_outtab_line   = p_aux

                    i_node_text      = lv_count2

                    it_item_layout   = lt_item_layout.

              ENDIF.

            ENDIF.

            CLEAR: gs_edid4,p_aux.

          ENDLOOP.

          CLEAR : lv_count2,lv_count.

        ENDIF.

      ENDIF.

    ENDLOOP.

*    ENDIF.

  ENDIF.

*  ENDIF.



* debmas loop

  IF NOT gv_debcnt IS INITIAL.

*    IF gv_debflag2 NE gc_x.

    CALL METHOD tree1->add_node

      EXPORTING

        i_relat_node_key = ''

        i_relationship   = cl_gui_column_tree=>relat_last_child

*       IS_OUTTAB_LINE   = P_AUX

        i_node_text      = 'DEBMAS' "L_NODE_TEXT

        it_item_layout   = lt_item_layout

      IMPORTING

        e_new_node_key   = p_node_debmas.



    CLEAR lv_count2.

    LOOP AT gt_edids_n2 INTO gs_edids_n2.

      READ TABLE gt_edid4 INTO gs_edid4 WITH KEY  docnum = gs_edids_n2-docnum BINARY SEARCH.

      IF sy-subrc EQ 0.

        IF gs_edid4-segnam = 'E1KNA1M'.

          PERFORM read_text.

          CALL METHOD tree1->add_node

            EXPORTING

              i_relat_node_key = p_node_debmas

              i_relationship   = cl_gui_column_tree=>relat_last_child

*             IS_OUTTAB_LINE   = P_AUX

              i_node_text      = gv_text

              it_item_layout   = lt_item_layout

            IMPORTING

              e_new_node_key   = p_node_debmas2.



          LOOP AT gt_edids_n INTO gs_edids_n WHERE  stamid = gs_edids_n2-stamid AND

                                                stamno = gs_edids_n2-stamno AND

                                                stapa1 = gs_edids_n2-stapa1 AND

                                                stapa2 = gs_edids_n2-stapa2 AND

                                                stapa3 = gs_edids_n2-stapa3 AND

                                                stapa4 = gs_edids_n2-stapa4.

            READ TABLE gt_edid4 INTO gs_edid4 WITH KEY  docnum = gs_edids_n-docnum BINARY SEARCH.

            IF sy-subrc EQ 0.

              IF gs_edid4-segnam = 'E1KNA1M'.

                lv_count = lv_count + 1.

                lv_count2 = lv_count.

                p_aux-idoc_num = gs_edid4-docnum.

                p_aux-node_n02 = gs_edid4-sdata+3(10).

                CALL METHOD tree1->add_node

                  EXPORTING

                    i_relat_node_key = p_node_debmas2

                    i_relationship   = cl_gui_column_tree=>relat_last_child

                    is_outtab_line   = p_aux

                    i_node_text      = lv_count2

                    it_item_layout   = lt_item_layout.

              ENDIF.

            ENDIF.

            CLEAR: gs_edid4,p_aux.

          ENDLOOP.

          CLEAR : lv_count2,lv_count.

        ENDIF.

      ENDIF.

    ENDLOOP.

*    ENDIF.

  ENDIF.



* Clfmas Loop

  IF NOT gv_clfcnt IS INITIAL.

*    IF gv_clfflag2 NE gc_x.

    CALL METHOD tree1->add_node

      EXPORTING

        i_relat_node_key = ''

        i_relationship   = cl_gui_column_tree=>relat_last_child

*       IS_OUTTAB_LINE   = P_AUX

        i_node_text      = 'CLFMAS' "L_NODE_TEXT

        it_item_layout   = lt_item_layout

      IMPORTING

        e_new_node_key   = p_node_clfmas.



    CLEAR lv_count2.



    LOOP AT gt_edids_n2 INTO gs_edids_n2.

      READ TABLE gt_edid4 INTO gs_edid4 WITH KEY  docnum = gs_edids_n2-docnum BINARY SEARCH.

      IF sy-subrc EQ 0.

        IF gs_edid4-segnam = 'E1OCLFM'.

          PERFORM read_text.

          CALL METHOD tree1->add_node

            EXPORTING

              i_relat_node_key = p_node_clfmas

              i_relationship   = cl_gui_column_tree=>relat_last_child

*             IS_OUTTAB_LINE   = P_AUX

              i_node_text      = gv_text

              it_item_layout   = lt_item_layout

            IMPORTING

              e_new_node_key   = p_node_clfmas2.



          LOOP AT gt_edids_n INTO gs_edids_n WHERE  stamid = gs_edids_n2-stamid AND

                                                stamno = gs_edids_n2-stamno AND

                                                stapa1 = gs_edids_n2-stapa1 AND

                                                stapa2 = gs_edids_n2-stapa2 AND

                                                stapa3 = gs_edids_n2-stapa3 AND

                                                stapa4 = gs_edids_n2-stapa4.

            READ TABLE gt_edid4 INTO gs_edid4 WITH KEY  docnum = gs_edids_n-docnum BINARY SEARCH.

            IF sy-subrc EQ 0.

              IF gs_edid4-segnam = 'E1OCLFM'.

                lv_count = lv_count + 1.

                lv_count2 = lv_count.

                p_aux-idoc_num = gs_edid4-docnum.

                CALL METHOD tree1->add_node

                  EXPORTING

                    i_relat_node_key = p_node_clfmas2

                    i_relationship   = cl_gui_column_tree=>relat_last_child

                    is_outtab_line   = p_aux

                    i_node_text      = lv_count2

                    it_item_layout   = lt_item_layout.

              ENDIF.

            ENDIF.

            CLEAR: gs_edid4,p_aux.

          ENDLOOP.

          CLEAR : lv_count2,lv_count.

        ENDIF.

      ENDIF.

    ENDLOOP.

*    ENDIF.

  ENDIF.



* adrmas loop

  IF NOT gv_adrcnt IS INITIAL.

*    IF gv_adrflag2 NE gc_x.

    CALL METHOD tree1->add_node

      EXPORTING

        i_relat_node_key = ''

        i_relationship   = cl_gui_column_tree=>relat_last_child

*       IS_OUTTAB_LINE   = P_AUX

        i_node_text      = 'ADRMAS' "L_NODE_TEXT

        it_item_layout   = lt_item_layout

      IMPORTING

        e_new_node_key   = p_node_adrmas.



    CLEAR lv_count2.



    LOOP AT gt_edids_n2 INTO gs_edids_n2.

      READ TABLE gt_edid4 INTO gs_edid4 WITH KEY  docnum = gs_edids_n2-docnum BINARY SEARCH.

      IF sy-subrc EQ 0.

        IF gs_edid4-segnam = 'E1ADRMAS'.

          PERFORM read_text.

          CALL METHOD tree1->add_node

            EXPORTING

              i_relat_node_key = p_node_adrmas

              i_relationship   = cl_gui_column_tree=>relat_last_child

*             IS_OUTTAB_LINE   = P_AUX

              i_node_text      = gv_text

              it_item_layout   = lt_item_layout

            IMPORTING

              e_new_node_key   = p_node_adrmas2.



          LOOP AT gt_edids_n INTO gs_edids_n WHERE  stamid = gs_edids_n2-stamid AND

                                                stamno = gs_edids_n2-stamno AND

                                                stapa1 = gs_edids_n2-stapa1 AND

                                                stapa2 = gs_edids_n2-stapa2 AND

                                                stapa3 = gs_edids_n2-stapa3 AND

                                                stapa4 = gs_edids_n2-stapa4.

            READ TABLE gt_edid4 INTO gs_edid4 WITH KEY  docnum = gs_edids_n-docnum BINARY SEARCH.

            IF sy-subrc EQ 0.

              IF gs_edid4-segnam = 'E1ADRMAS'.

                lv_count = lv_count + 1.

                lv_count2 = lv_count.

                p_aux-idoc_num = gs_edid4-docnum.

                CALL METHOD tree1->add_node

                  EXPORTING

                    i_relat_node_key = p_node_adrmas2

                    i_relationship   = cl_gui_column_tree=>relat_last_child

                    is_outtab_line   = p_aux

                    i_node_text      = lv_count2

                    it_item_layout   = lt_item_layout.

              ENDIF.

            ENDIF.

            CLEAR: gs_edid4,p_aux.

          ENDLOOP.

          CLEAR : lv_count2,lv_count.

        ENDIF.

      ENDIF.

    ENDLOOP.

*    ENDIF.

  ENDIF.



* Matqm loop

  IF NOT gv_maqcnt IS INITIAL.

*    IF gv_maqflag2 NE gc_x.

    CALL METHOD tree1->add_node

      EXPORTING

        i_relat_node_key = ''

        i_relationship   = cl_gui_column_tree=>relat_last_child

*       IS_OUTTAB_LINE   = P_AUX

        i_node_text      = 'MATQM' "L_NODE_TEXT

        it_item_layout   = lt_item_layout

      IMPORTING

        e_new_node_key   = p_node_matqm.



    CLEAR lv_count2.



    LOOP AT gt_edids_n2 INTO gs_edids_n2.

      READ TABLE gt_edid4 INTO gs_edid4 WITH KEY  docnum = gs_edids_n2-docnum BINARY SEARCH.

      IF sy-subrc EQ 0.

        IF gs_edid4-segnam = 'E1BP1001004_QMAT'.

          PERFORM read_text.

          CALL METHOD tree1->add_node

            EXPORTING

              i_relat_node_key = p_node_matqm

              i_relationship   = cl_gui_column_tree=>relat_last_child

*             IS_OUTTAB_LINE   = P_AUX

              i_node_text      = gv_text

              it_item_layout   = lt_item_layout

            IMPORTING

              e_new_node_key   = p_node_matqm2.



          LOOP AT gt_edids_n INTO gs_edids_n WHERE  stamid = gs_edids_n2-stamid AND

                                                stamno = gs_edids_n2-stamno AND

                                                stapa1 = gs_edids_n2-stapa1 AND

                                                stapa2 = gs_edids_n2-stapa2 AND

                                                stapa3 = gs_edids_n2-stapa3 AND

                                                stapa4 = gs_edids_n2-stapa4.

            READ TABLE gt_edid4 INTO gs_edid4 WITH KEY  docnum = gs_edids_n-docnum BINARY SEARCH.

            IF sy-subrc EQ 0.

              IF gs_edid4-segnam = 'E1BP1001004_QMAT'.

                lv_count = lv_count + 1.

                lv_count2 = lv_count.

                p_aux-idoc_num = gs_edid4-docnum.

                CALL METHOD tree1->add_node

                  EXPORTING

                    i_relat_node_key = p_node_matqm2

                    i_relationship   = cl_gui_column_tree=>relat_last_child

                    is_outtab_line   = p_aux

                    i_node_text      = lv_count2

                    it_item_layout   = lt_item_layout.

              ENDIF.

            ENDIF.

            CLEAR: gs_edid4,p_aux.

          ENDLOOP.

          CLEAR : lv_count2,lv_count.

        ENDIF.

      ENDIF.

    ENDLOOP.

*    ENDIF.

  ENDIF.



* Project loop

  IF NOT gv_procnt IS INITIAL.

*    IF gv_proflag2 NE gc_x .

    CALL METHOD tree1->add_node

      EXPORTING

        i_relat_node_key = ''

        i_relationship   = cl_gui_column_tree=>relat_last_child

*       IS_OUTTAB_LINE   = P_AUX

        i_node_text      = 'PROJECT' "L_NODE_TEXT

        it_item_layout   = lt_item_layout

      IMPORTING

        e_new_node_key   = p_node_project.



    CLEAR lv_count2.



    LOOP AT gt_edids_n2 INTO gs_edids_n2.

      READ TABLE gt_edid4 INTO gs_edid4 WITH KEY  docnum = gs_edids_n2-docnum BINARY SEARCH.

      IF sy-subrc EQ 0.

        IF gs_edid4-segnam = 'E1BP2054_PROJDEFINITION'.

          PERFORM read_text.

          CALL METHOD tree1->add_node

            EXPORTING

              i_relat_node_key = p_node_project

              i_relationship   = cl_gui_column_tree=>relat_last_child

*             IS_OUTTAB_LINE   = P_AUX

              i_node_text      = gv_text

              it_item_layout   = lt_item_layout

            IMPORTING

              e_new_node_key   = p_node_project.



          LOOP AT gt_edids_n INTO gs_edids_n WHERE  stamid = gs_edids_n2-stamid AND

                                                stamno = gs_edids_n2-stamno AND

                                                stapa1 = gs_edids_n2-stapa1 AND

                                                stapa2 = gs_edids_n2-stapa2 AND

                                                stapa3 = gs_edids_n2-stapa3 AND

                                                stapa4 = gs_edids_n2-stapa4.

            READ TABLE gt_edid4 INTO gs_edid4 WITH KEY  docnum = gs_edids_n-docnum BINARY SEARCH.

            IF sy-subrc EQ 0.

              IF gs_edid4-segnam = 'E1BP2054_PROJDEFINITION'.

                lv_count = lv_count + 1.

                lv_count2 = lv_count.

                p_aux-idoc_num = gs_edid4-docnum.

                CALL METHOD tree1->add_node

                  EXPORTING

                    i_relat_node_key = p_node_project2

                    i_relationship   = cl_gui_column_tree=>relat_last_child

                    is_outtab_line   = p_aux

                    i_node_text      = lv_count2

                    it_item_layout   = lt_item_layout.

              ENDIF.

            ENDIF.

            CLEAR: gs_edid4,p_aux.

          ENDLOOP.

          CLEAR : lv_count2,lv_count.

        ENDIF.

      ENDIF.

    ENDLOOP.

*    ENDIF.

  ENDIF.



* this method must be called to send the data to the frontend

  CALL METHOD tree1->frontend_update.

*****

ENDFORM.                    " create_hierarchy

*&---------------------------------------------------------------------*

*&      Form  register_events

*&---------------------------------------------------------------------*

FORM register_events.

* define the events which will be passed to the backend

  DATA: lt_events TYPE cntl_simple_events,

        l_event   TYPE cntl_simple_event.

*  DATA: g_application TYPE REF TO lcl_application.

* define the events which will be passed to the backend

  l_event-eventid = cl_gui_column_tree=>eventid_expand_no_children.

  APPEND l_event TO lt_events.

  l_event-eventid = cl_gui_column_tree=>eventid_checkbox_change.

  APPEND l_event TO lt_events.

  l_event-eventid = cl_gui_column_tree=>eventid_header_context_men_req.

  APPEND l_event TO lt_events.

  l_event-eventid = cl_gui_column_tree=>eventid_node_context_menu_req.

  APPEND l_event TO lt_events.

  l_event-eventid = cl_gui_column_tree=>eventid_item_context_menu_req.

  APPEND l_event TO lt_events.

  l_event-eventid = cl_gui_column_tree=>eventid_header_click.

  APPEND l_event TO lt_events.

  l_event-eventid = cl_gui_column_tree=>eventid_item_keypress.

  APPEND l_event TO lt_events.

  l_event-eventid = cl_gui_column_tree=>eventid_node_double_click.

  APPEND l_event TO lt_events.

  l_event-eventid = cl_gui_column_tree=>eventid_node_double_click.

  APPEND l_event TO lt_events.

  l_event-eventid = cl_gui_column_tree=>eventid_node_double_click.

  APPEND l_event TO lt_events.

  l_event-eventid = cl_gui_column_tree=>eventid_item_double_click.

  APPEND l_event TO lt_events.



*  l_event-eventid = cl_gui_column_tree=>eventid_node_double_click.

*  APPEND l_event TO lt_events.

*  l_event-eventid = cl_gui_column_tree=>eventid_item_double_click.

*  APPEND l_event TO lt_events.



  CALL METHOD tree1->set_registered_events

    EXPORTING

      events                    = lt_events

    EXCEPTIONS

      cntl_error                = 1

      cntl_system_error         = 2

      illegal_event_combination = 3.

  IF sy-subrc <> 0.

    MESSAGE x208(00) WITH 'ERROR'.                          "#EC NOTEXT

  ENDIF.

* set Handler

  DATA: l_event_receiver TYPE REF TO lcl_tree_event_receiver.

  CREATE OBJECT l_event_receiver.

*  CREATE OBJECT gv_rcvr.

  SET HANDLER l_event_receiver->handle_node_ctmenu_request

                                                        FOR tree1.

  SET HANDLER l_event_receiver->handle_node_ctmenu_selected

                                                        FOR tree1.

  SET HANDLER l_event_receiver->handle_item_ctmenu_request

                                                        FOR tree1.

  SET HANDLER l_event_receiver->handle_item_ctmenu_selected

                                                        FOR tree1.

  SET HANDLER:

    lcl_eventhandler=>handle_item_double_click FOR tree1.



*  SET HANDLER:

**    lcl_eventhandler=>handle_node_double_click FOR tree1,

*    lcl_eventhandler=>handle_item_double_click FOR tree1.

*  SET HANDLER l_event_receiver->handle_node_double_click FOR tree1.

*  SET HANDLER l_event_receiver->RIGHT_CLICK FOR tree1.

*  SET HANDLER gv_rcvr->hotspot_click FOR tree1.

ENDFORM.                    " register_events

*&---------------------------------------------------------------------*

*&      Form  add_node_main

*&---------------------------------------------------------------------*

FORM add_node      USING       p_aux TYPE it

                               p_relat_key TYPE lvc_nkey

                               p_node TYPE lvc_value

                     CHANGING  p_node_key TYPE lvc_nkey.

  DATA: l_node_text TYPE lvc_value,

        ls_sflight  TYPE sflight.

* set item-layout

  DATA: lt_item_layout TYPE lvc_t_layi,

        ls_item_layout TYPE lvc_s_layi.

*  ls_item_layout-t_image = '<at:var at:name="3P" />'.

  ls_item_layout-fieldname = tree1->c_hierarchy_column_name.

  ls_item_layout-style   =

                        cl_gui_column_tree=>style_intensifd_critical.

  APPEND ls_item_layout TO lt_item_layout.

* add node

  l_node_text =  p_node.

  CALL METHOD tree1->add_node

    EXPORTING

      i_relat_node_key = p_relat_key

      i_relationship   = cl_gui_column_tree=>relat_last_child

      i_node_text      = l_node_text

      is_outtab_line   = p_aux

      it_item_layout   = lt_item_layout

    IMPORTING

      e_new_node_key   = p_node_key.

*****

ENDFORM.                    " add_node

*&---------------------------------------------------------------------*

*&      Form  add_complete_line

*&---------------------------------------------------------------------*

FORM add_complete_line USING   p_aux TYPE it

                               p_relat_key TYPE lvc_nkey

                               p_node TYPE lvc_value

                     CHANGING  p_node_key TYPE lvc_nkey.

  DATA: l_node_text TYPE lvc_value.

* set item-layout

  DATA: lt_item_layout TYPE lvc_t_layi,

        ls_item_layout TYPE lvc_s_layi.

  ls_item_layout-fieldname = tree1->c_hierarchy_column_name.

  ls_item_layout-class   = cl_gui_column_tree=>item_class_text.

*  ls_item_layout-editable = 'X'.

  APPEND ls_item_layout TO lt_item_layout.

  l_node_text =  p_node.

  CALL METHOD tree1->add_node

    EXPORTING

      i_relat_node_key = p_relat_key

      i_relationship   = cl_gui_column_tree=>relat_last_child

      is_outtab_line   = p_aux

      i_node_text      = l_node_text

      it_item_layout   = lt_item_layout

    IMPORTING

      e_new_node_key   = p_node_key.

ENDFORM.                    " add_complete_line

*&---------------------------------------------------------------------*

*&      Form  add_node_main

*&---------------------------------------------------------------------*

FORM add_node_main USING       p_aux TYPE it

                               p_relat_key TYPE lvc_nkey

                               p_node TYPE lvc_value

                     CHANGING  p_node_key TYPE lvc_nkey.

  DATA: l_node_text TYPE lvc_value,

        ls_sflight  TYPE sflight.

* set item-layout

  DATA: lt_item_layout TYPE lvc_t_layi,

        ls_item_layout TYPE lvc_s_layi.

*  ls_item_layout-t_image = '<at:var at:name="3P" />'.

  ls_item_layout-fieldname = tree1->c_hierarchy_column_name.

  ls_item_layout-style   =

                        cl_gui_column_tree=>style_intensifd_critical.

  APPEND ls_item_layout TO lt_item_layout.

* add node

  l_node_text =  p_node.

  CALL METHOD tree1->add_node

    EXPORTING

      i_relat_node_key = p_relat_key

      i_relationship   = cl_gui_column_tree=>relat_last_child

      i_node_text      = l_node_text

      is_outtab_line   = p_aux

      it_item_layout   = lt_item_layout

    IMPORTING

      e_new_node_key   = p_node_key.

*****

ENDFORM.                    " add_node_main

*&---------------------------------------------------------------------*

*&      Form  GET_DATA

*&---------------------------------------------------------------------*

*       text

*----------------------------------------------------------------------*

*  -->  p1        text

*  <--  p2        text

*----------------------------------------------------------------------*

FORM get_data.

  DATA: lv_msgno    LIKE t100-msgnr,

        lv_date(10),

        lv_time(8),

        lv_cnt      TYPE i.



  CLEAR:    t_report.

  REFRESH:  t_report.



  SELECT docnum credat mestyp

        FROM edidc

        INTO TABLE gt_edidc

        WHERE status = '51' AND

              mestyp IN s_mestyp AND

              test = '' AND

              credat IN s_credat.



  IF sy-subrc EQ 0.



  ENDIF.



  IF NOT gt_edidc IS INITIAL.

*    SELECT docnum segnam dtint2 sdata

*           FROM edid4 CLIENT SPECIFIED

*           INTO TABLE gt_edid4

*           FOR ALL ENTRIES IN gt_edidc

*           WHERE docnum = gt_edidc-docnum AND

*                 segnam IN gr_segnam.

*    IF sy-subrc EQ 0.

*    ENDIF.



    REFRESH: gt_edids, gt_edids3.



* Fetch latest 51 status from DB

    LOOP AT gt_edidc ASSIGNING <ts_edidc>.

      SELECT mandt docnum logdat logtim countr credat cretim status uname

             repid routid stacod statxt

             segnum segfld stapa1 stapa2 stapa3 stapa4 statyp stamqu

             stamid stamno tid  appl_log _dataaging

      FROM edids

      INTO TABLE gt_edids3 UP TO 1 ROWS

      WHERE docnum = <ts_edidc>-docnum AND

            status = '51'

      ORDER BY credat DESCENDING  cretim DESCENDING countr DESCENDING.

      IF sy-subrc EQ 0.

        APPEND LINES OF gt_edids3 TO gt_edids.

      ENDIF.

      REFRESH gt_edids3.

    ENDLOOP.



  ENDIF.



*  IF  NOT gt_edid4 IS INITIAL.

*    LOOP AT gt_edid4 INTO gs_edid4.

*      gs_matnr-docnum = gs_edid4-docnum.

*      gs_matnr-matnr = gs_edid4-sdata+3(18).

*      APPEND gs_matnr TO gt_matnr.

*      CLEAR gs_matnr.

*    ENDLOOP.

*  ENDIF.



** 'MATMAS' Logic

*  IF NOT gt_edids IS INITIAL.

*    IF gv_matflag = 'X'.

*      SELECT lognumber

*            object

*            subobject

*            extnumber

*            aldate

*            altime

*            aluser

*     FROM balhdr

*     INTO TABLE t_balhdr

*     FOR ALL ENTRIES IN gt_edids

*     WHERE lognumber = gt_edids-appl_log AND

*           object EQ 'MATU' AND

*           aldate IN s_credat.

** Delete previous logs and consider just the last one for each IDOC

*      IF sy-subrc = 0.

*        SORT t_balhdr BY extnumber ASCENDING lognumber DESCENDING.

*        DELETE ADJACENT DUPLICATES FROM t_balhdr COMPARING extnumber.

*      ENDIF.

*    ENDIF.

*  ENDIF.

*

*  IF NOT t_balhdr[] IS INITIAL.

*    LOOP AT t_balhdr ASSIGNING <ts_balhdr>.

**   Get log

*      CALL FUNCTION 'APPL_LOG_READ_DB'

*        EXPORTING

*          object           = '*'

*          subobject        = '*'

*          external_number  = <ts_balhdr>-extnumber

*          program_name     = '*'

*          transaction_code = '*'

*        TABLES

*          messages         = t_message.

*      IF sy-subrc = 0.

**     Delete previous attempts

*        DELETE t_message WHERE lognumber NE <ts_balhdr>-lognumber.

**     Delete messages that aren't error

*        DELETE t_message WHERE msgty     NE 'E'.

*      ENDIF.

**      ASSIGN ts_message2 TO <ts_message2>.

**      LOOP AT t_message ASSIGNING <ts_message>.

**        MOVE-CORRESPONDING <ts_message> TO <ts_message2>.

**        APPEND <ts_message2> TO t_message2.

**      ENDLOOP.

*      APPEND LINES OF t_message TO t_message2.

*      REFRESH: t_message.

*    ENDLOOP.

*

*    t_matmas[] = t_message2[].

*    SORT t_matmas[] BY msgno.

*    DELETE ADJACENT DUPLICATES FROM t_matmas[] COMPARING msgno.

*  ENDIF.





ENDFORM.

*&---------------------------------------------------------------------*

*&      Form  READ_TEXT

*&---------------------------------------------------------------------*

*       text

*----------------------------------------------------------------------*

*  -->  p1        text

*  <--  p2        text

*----------------------------------------------------------------------*

FORM read_text .



  CALL FUNCTION 'FORMAT_MESSAGE'

    EXPORTING

      id        = gs_edids_n2-stamid

      lang      = '-D'

      no        = gs_edids_n2-stamno

      v1        = gs_edids_n2-stapa1

      v2        = gs_edids_n2-stapa2

      v3        = gs_edids_n2-stapa3

      v4        = gs_edids_n2-stapa4

    IMPORTING

      msg       = gv_text "gs_cremas-msg

    EXCEPTIONS

      not_found = 1

      OTHERS    = 2.

  IF sy-subrc <> 0.

* Implement suitable error handling here

  ENDIF.

ENDFORM.

*&---------------------------------------------------------------------*

*&      Form  FIND_OCCUR

*&---------------------------------------------------------------------*

*       text

*----------------------------------------------------------------------*

*  -->  p1        text

*  <--  p2        text

*----------------------------------------------------------------------*

FORM find_occur.

  DATA: lv_cnt TYPE i.

  CLEAR : gv_matflag,gv_creflag,gv_debflag,gv_clfflag,gv_maqflag,gv_proflag.

  FIND ALL OCCURRENCES OF 'MATMAS' IN TABLE s_mestyp

          RESULTS tbl_tab1_result IN CHARACTER MODE.

  IF sy-subrc EQ 0.

    gv_matflag = gc_x.

  ENDIF.



  FIND ALL OCCURRENCES OF 'CREMAS' IN TABLE s_mestyp

          RESULTS tbl_tab1_result IN CHARACTER MODE.

  IF sy-subrc EQ 0.

    gv_creflag = gc_x.

  ENDIF.



  FIND ALL OCCURRENCES OF 'DEBMAS' IN TABLE s_mestyp

          RESULTS tbl_tab1_result IN CHARACTER MODE.

  IF sy-subrc EQ 0.

    gv_debflag = gc_x.

  ENDIF.



  FIND ALL OCCURRENCES OF 'CLFMAS' IN TABLE s_mestyp

        RESULTS tbl_tab1_result IN CHARACTER MODE.

  IF sy-subrc EQ 0.

    gv_clfflag = gc_x.

  ENDIF.



  FIND ALL OCCURRENCES OF 'MATQM' IN TABLE s_mestyp

          RESULTS tbl_tab1_result IN CHARACTER MODE.

  IF sy-subrc EQ 0.

    gv_maqflag = gc_x.

  ENDIF.



  FIND ALL OCCURRENCES OF 'PROJECT' IN TABLE s_mestyp

        RESULTS tbl_tab1_result IN CHARACTER MODE.

  IF sy-subrc EQ 0.

    gv_proflag = gc_x.

  ENDIF.



  FIND ALL OCCURRENCES OF 'ADRMAS' IN TABLE s_mestyp

        RESULTS tbl_tab1_result IN CHARACTER MODE.

  IF sy-subrc EQ 0.

    gv_adrflag = gc_x.

  ENDIF.



ENDFORM.

*&---------------------------------------------------------------------*

*&      Form  GET_SELECTED_ITEM

*&---------------------------------------------------------------------*

*       text

*----------------------------------------------------------------------*

*  -->  p1        text

*  <--  p2        text

*----------------------------------------------------------------------*

FORM get_selected_item.



  DATA:   e_outtab_line TYPE char255,

          lt_nkey       TYPE lvc_t_nkey,

          lwa_nkey      TYPE lvc_nkey,

          lvc_fname     TYPE lvc_fname,

          lvc_value     TYPE lvc_value,

          lv_var(16),

          gw_status     TYPE bdidocstat,

          gt_status     TYPE TABLE OF bdidocstat,

          lv_doc        TYPE  edi_docnum,

          lvc_nkey      TYPE lvc_nkey,



          lv_idoc       TYPE edi_docnum.







  RANGES    lt_rspar      FOR bdidocs-docnum. "TYPE TABLE OF rsparams,

*          ls_rspar      LIKE LINE OF lt_rspar.



  CALL METHOD tree1->get_selected_item

    IMPORTING

      e_selected_node = lvc_nkey

      e_fieldname     = lvc_fname.



*  LOOP AT lt_nkey INTO lwa_nkey.

*    CALL METHOD tree1->get_outtab_line

*      EXPORTING

*        i_node_key    = lwa_nkey

*      IMPORTING

**       E_OUTTAB_     =

*        e_node_text   = lvc_value

*        e_outtab_line = e_outtab_line.

*    gs_docnum-docnum = e_outtab_line+15(16).

*    APPEND gs_docnum TO gt_docnum.

*    APPEND gs_docnum TO gt_docnum2.

*    CLEAR gs_docnum.

*  ENDLOOP.



  CALL METHOD tree1->get_outtab_line

    EXPORTING

      i_node_key    = lvc_nkey

    IMPORTING

*     E_OUTTAB_     =

      e_node_text   = lvc_value

      e_outtab_line = e_outtab_line.



  lv_idoc =  e_outtab_line+15(16).

  gs_docnum2-docnum = lv_idoc.

  APPEND gs_docnum2 TO gt_docnum2.

  CLEAR gs_docnum2.

  PERFORM bdc_begin USING 'RBDMON00' '1100'.

  PERFORM bdc_valu  USING: 'BDC_CURSOR' 'SX_UPDDA-HIGH',

                           'BDC_OKCODE' '=CRET',

                           'SX_DOCNU-LOW' lv_idoc,

                           'SX_CRETI-LOW' '00:00:00',

                           'SX_CRETI-HIGH' '00:00:00',

                           'SX_UPDDA-LOW' '',

                           'SX_UPDDA-HIGH' ''.



  CALL TRANSACTION 'BD87' USING t_bdcdata MODE 'E'.

  CALL METHOD cl_gui_cfw=>dispatch.

  REFRESH gt_docnum.



ENDFORM.

*&---------------------------------------------------------------------*

*&      Form  BDC_BEGIN

*&---------------------------------------------------------------------*

*       text

*----------------------------------------------------------------------*

*      -->P_3146   text

*      -->P_3147   text

*----------------------------------------------------------------------*

FORM bdc_begin  USING rv_program rv_screen.

  DATA: s_bdcdata TYPE bdcdata.



  s_bdcdata-program = rv_program.

  s_bdcdata-dynpro  = rv_screen.

  s_bdcdata-dynbegin = gc_x.

  APPEND s_bdcdata TO t_bdcdata.





ENDFORM.

*&---------------------------------------------------------------------*

*&      Form  BDC_VALU

*&---------------------------------------------------------------------*

*       text

*----------------------------------------------------------------------*

*      -->P_3151   text

*      -->P_3152   text

*----------------------------------------------------------------------*

FORM bdc_valu  USING rv_fnam rv_fval.

  DATA: s_bdcdata TYPE bdcdata.



  s_bdcdata-fnam = rv_fnam.

  s_bdcdata-fval = rv_fval.

  APPEND s_bdcdata TO t_bdcdata.



ENDFORM.

*&---------------------------------------------------------------------*

*&      Form  REFRESH

*&---------------------------------------------------------------------*

*       text

*----------------------------------------------------------------------*

*  -->  p1        text

*  <--  p2        text

*----------------------------------------------------------------------*

FORM refresh.



  IF NOT gt_docnum2 IS INITIAL.

    LOOP AT gt_docnum2 INTO gs_docnum2.

      SELECT mandt docnum logdat logtim countr credat cretim status uname

                 repid routid stacod statxt

                 segnum segfld stapa1 stapa2 stapa3 stapa4 statyp stamqu

                 stamid stamno tid  appl_log _dataaging

          FROM edids

          INTO TABLE gt_edids3 UP TO 1 ROWS

          WHERE docnum = gs_docnum2-docnum AND

                status = '51'

          ORDER BY credat DESCENDING cretim DESCENDING countr DESCENDING.

      IF sy-subrc EQ 0.

        READ TABLE gt_edids3 INTO gs_edids3 WITH KEY docnum = gs_docnum2-docnum.

        IF sy-subrc EQ 0.

          IF gs_edids3-status NE '51'.

*          DELETE FROM yyidoc_monitor WHERE docnum = gs_docnum2-docnum.

            DELETE FROM yyidoc_monitor WHERE  credat = gs_edids3-credat AND

                                              docnum =  gs_edids3-docnum.

            COMMIT WORK AND WAIT.

          ENDIF.

        ENDIF.

      ENDIF.

    ENDLOOP.

*    PERFORM get_ztable.

  ELSE.

    MESSAGE 'Reprocess IDOCS' TYPE 'I' DISPLAY LIKE 'E'.



  ENDIF.



ENDFORM.

*&---------------------------------------------------------------------*

*&      Form  MATMAS

*&---------------------------------------------------------------------*

*       text

*----------------------------------------------------------------------*

*  -->  p1        text

*  <--  p2        text

*----------------------------------------------------------------------*

FORM matmas.



* 'MATMAS' Logic

  IF NOT gt_edids IS INITIAL.

    SELECT lognumber

          object

          subobject

          extnumber

          aldate

          altime

          aluser

   FROM balhdr

   INTO TABLE t_balhdr

   FOR ALL ENTRIES IN gt_edids

   WHERE lognumber = gt_edids-appl_log AND

         object EQ 'MATU' AND

         aldate IN s_credat.

* Delete previous logs and consider just the last one for each IDOC

    IF sy-subrc = 0.

      SORT t_balhdr BY extnumber ASCENDING lognumber DESCENDING.

      DELETE ADJACENT DUPLICATES FROM t_balhdr COMPARING extnumber.

    ENDIF.

  ENDIF.



  IF NOT t_balhdr[] IS INITIAL.

    LOOP AT t_balhdr ASSIGNING <ts_balhdr>.

*   Get log

      CALL FUNCTION 'APPL_LOG_READ_DB'

        EXPORTING

          object           = '*'

          subobject        = '*'

          external_number  = <ts_balhdr>-extnumber

          program_name     = '*'

          transaction_code = '*'

        TABLES

          messages         = t_message.

      IF sy-subrc = 0.

*     Delete previous attempts

        DELETE t_message WHERE lognumber NE <ts_balhdr>-lognumber.

*     Delete messages that aren't error

        DELETE t_message WHERE msgty     NE 'E'.

      ENDIF.

      APPEND LINES OF t_message TO t_message2.

      REFRESH: t_message.

    ENDLOOP.



  ENDIF.





ENDFORM.

*&---------------------------------------------------------------------*

*&      Form  ZTABLE_UPDATE

*&---------------------------------------------------------------------*

*       text

*----------------------------------------------------------------------*

*  -->  p1        text

*  <--  p2        text

*----------------------------------------------------------------------*

FORM ztable_update.

  PERFORM get_data.



  PERFORM matmas.



  PERFORM update.

ENDFORM.

*&---------------------------------------------------------------------*

*&      Form  GET_ZTABLE

*&---------------------------------------------------------------------*

*       text

*----------------------------------------------------------------------*

*  -->  p1        text

*  <--  p2        text

*----------------------------------------------------------------------*

FORM get_ztable.

  DATA : lv_cnt      TYPE i.

  REFRESH:  gt_edid4,

            gt_ztable2,

            gt_matmas_n,

            gt_edids_n,

            gt_edids_n2.



  CLEAR: gv_matcnt,gv_crecnt,gv_debcnt,gv_adrcnt,gv_maqcnt,gv_procnt,gv_clfcnt.

  SELECT *   FROM  yyidoc_monitor

             INTO TABLE gt_ztable2

             WHERE credat IN s_credat AND

                   mestyp IN s_mestyp.

  IF sy-subrc EQ 0.

* matmas count

    FIND ALL OCCURRENCES OF 'MATMAS' IN TABLE gt_ztable2 MATCH COUNT lv_cnt RESPECTING CASE.

    IF sy-subrc EQ 0.

      gv_matcnt = lv_cnt.

      CLEAR lv_cnt.

    ENDIF.

* cremas count

    FIND ALL OCCURRENCES OF 'CREMAS' IN TABLE gt_ztable2 MATCH COUNT lv_cnt RESPECTING CASE.

    IF sy-subrc EQ 0.

      gv_crecnt = lv_cnt.

      CLEAR lv_cnt.

    ENDIF.

* debmas count

    FIND ALL OCCURRENCES OF 'DEBMAS' IN TABLE gt_ztable2 MATCH COUNT lv_cnt RESPECTING CASE.

    IF sy-subrc EQ 0.

      gv_debcnt = lv_cnt.

      CLEAR lv_cnt.

    ENDIF.

* adrmas count

    FIND ALL OCCURRENCES OF 'ADRMAS' IN TABLE gt_ztable2 MATCH COUNT lv_cnt RESPECTING CASE.

    IF sy-subrc EQ 0.

      gv_adrcnt = lv_cnt.

      CLEAR lv_cnt.

    ENDIF.

* matqm count

    FIND ALL OCCURRENCES OF 'MATQM' IN TABLE gt_ztable2 MATCH COUNT lv_cnt RESPECTING CASE.

    IF sy-subrc EQ 0.

      gv_maqcnt = lv_cnt.

      CLEAR lv_cnt.

    ENDIF.

* project count

    FIND ALL OCCURRENCES OF 'PROJECT' IN TABLE gt_ztable2 MATCH COUNT lv_cnt RESPECTING CASE.

    IF sy-subrc EQ 0.

      gv_procnt = lv_cnt.

      CLEAR lv_cnt.

    ENDIF.

*clfmas count

    FIND ALL OCCURRENCES OF 'CLFMAS' IN TABLE gt_ztable2 MATCH COUNT lv_cnt RESPECTING CASE.

    IF sy-subrc EQ 0.

      gv_clfcnt = lv_cnt.

      CLEAR lv_cnt.

    ENDIF.

  ELSEIF sy-subrc NE 0.

    MESSAGE 'Update The ZTable For Given Period' TYPE 'I' DISPLAY LIKE 'E'.

    LEAVE LIST-PROCESSING.

  ENDIF.



  IF NOT gt_ztable2 IS INITIAL.

    SELECT docnum segnam dtint2 sdata

             FROM edid4

             INTO TABLE gt_edid4

             FOR ALL ENTRIES IN gt_ztable2

             WHERE docnum = gt_ztable2-docnum AND

                   segnam IN gr_segnam.

    IF sy-subrc EQ 0.



      IF  NOT gt_edid4 IS INITIAL.

        LOOP AT gt_edid4 INTO gs_edid4.

          gs_matnr-docnum = gs_edid4-docnum.

          gs_matnr-matnr = gs_edid4-sdata+3(18).

          APPEND gs_matnr TO gt_matnr.

          CLEAR gs_matnr.

        ENDLOOP.

      ENDIF.

    ENDIF.

  ENDIF.



  LOOP AT gt_ztable2 INTO gs_ztable2.

* matmas

    IF gs_ztable2-mestyp EQ 'MATMAS'.

      gs_matmas_n-docnum = gs_ztable2-docnum.

      gs_matmas_n-msgid = gs_ztable2-msgid.

      gs_matmas_n-msgno = gs_ztable2-msgno.

    ELSE.

* Other

      gs_edids_n-docnum = gs_ztable2-docnum.

      gs_edids_n-stamid = gs_ztable2-stamid.

      gs_edids_n-stamno = gs_ztable2-stamno.

      gs_edids_n-stapa1 = gs_ztable2-stapa1.

      gs_edids_n-stapa2 = gs_ztable2-stapa2.

      gs_edids_n-stapa3 = gs_ztable2-stapa3.

      gs_edids_n-stapa4 = gs_ztable2-stapa4.

    ENDIF.

    IF NOT gs_matmas_n IS INITIAL.

      APPEND gs_matmas_n TO gt_matmas_n.

    ENDIF.

    IF NOT gs_edids_n IS INITIAL.

      APPEND gs_edids_n TO gt_edids_n.

    ENDIF.

    CLEAR: gs_ztable2,gs_matmas_n.

  ENDLOOP.



  IF NOT gt_matmas_n[] IS INITIAL.

    gt_matmas_n2[] = gt_matmas_n[].

    SORT gt_matmas_n2[] BY msgno.

    DELETE ADJACENT DUPLICATES FROM gt_matmas_n2[] COMPARING msgno.

  ENDIF.





ENDFORM.

*&---------------------------------------------------------------------*

*&      Form  UPDATE

*&---------------------------------------------------------------------*

*       text

*----------------------------------------------------------------------*

*  -->  p1        text

*  <--  p2        text

*----------------------------------------------------------------------*

FORM update.

  SORT: gt_edids BY docnum,

        gt_edidc BY docnum,

        t_balhdr BY extnumber,

        t_message2 BY lognumber.

  LOOP AT gt_edids INTO gs_edids.

    READ TABLE gt_edidc INTO gs_edidc WITH KEY docnum = gs_edids-docnum BINARY SEARCH.

    IF sy-subrc EQ 0.

      gs_ztable-credat = gs_edidc-credat.

      gs_ztable-mestyp = gs_edidc-mestyp.

      gs_ztable-docnum = gs_edidc-docnum.

      IF gs_edidc-mestyp NE 'MATMAS'.

        gs_ztable-stamid = gs_edids-stamid.

        gs_ztable-stamno = gs_edids-stamno.

        gs_ztable-stapa1 = gs_edids-stapa1.

        gs_ztable-stapa2 = gs_edids-stapa2.

        gs_ztable-stapa3 = gs_edids-stapa3.

        gs_ztable-stapa4 = gs_edids-stapa4.

      ENDIF.

    ENDIF.

    IF gs_edidc-mestyp EQ 'MATMAS'.

      READ TABLE t_balhdr INTO ts_balhdr WITH KEY extnumber = gs_edids-docnum BINARY SEARCH.

      IF sy-subrc EQ 0.

        READ TABLE t_message2 INTO ts_message2 WITH KEY lognumber = ts_balhdr-lognumber BINARY SEARCH.

        IF sy-subrc EQ 0.

          gs_ztable-lognumber = ts_message2-lognumber.

          gs_ztable-msgid = ts_message2-msgid.

          gs_ztable-msgno = ts_message2-msgno.

        ENDIF.

      ENDIF.

    ENDIF.

    APPEND gs_ztable TO gt_ztable.

    CLEAR: gs_ztable,ts_balhdr, ts_message2, gs_edidc,gs_edids.

  ENDLOOP.



  IF NOT gt_ztable IS INITIAL.

    MODIFY yyidoc_monitor FROM TABLE gt_ztable.

    IF sy-subrc EQ 0.

      COMMIT WORK AND WAIT.

      MESSAGE 'Table Updated Sucessfully' TYPE 'S'.

    ENDIF.

  ENDIF.





ENDFORM.

*&---------------------------------------------------------------------*

*&      Form  FREE_OBJECTS

*&---------------------------------------------------------------------*

*       text

*----------------------------------------------------------------------*

*  -->  p1        text

*  <--  p2        text

*----------------------------------------------------------------------*

FORM free_objects.



  IF NOT l_custom_container IS INITIAL.

    CALL METHOD l_custom_container->free.

*      EXCEPTIONS

*        cntl_error        = 1

*        cntl_system_error = 2

*        OTHERS            = 3.



    CLEAR l_custom_container.

  ENDIF.



  IF NOT tree1 IS INITIAL.

    CALL METHOD tree1->free.

    CLEAR: tree1.

*    CALL METHOD cl_gui_cfw=>flush.



  ENDIF.









ENDFORM.

I am getting error

Exception condition "CNTB_ERROR_FCODE" triggered

while going back to the previous screen.

I have given the initial check for the create objects still I am facing this issue.

code is provided in code window.

Please help.

Thanks,

Darshan

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

0 Answers