Registration

Dear SAP Community Member,
In order to fully benefit from what the SAP Community has to offer, please register at:
http://scn.sap.com
Thank you,
The SAP Community team.
Skip to end of metadata
Go to start of metadata

**********************************************************************
* PROGRAM ID           : ZPROCORDCTRL                                *
* PROGRAM TITLE        : Process Order Status Management Report      *
* DESCRIPTION          : THE PURPOSE OF THIS PROGRAM IS TO DISPLAY   *
*                        ORDERS AND ASSOCIATED CONTROL RECIPES,      *
*                        PI SHEETS AND MESSAGES IN HIERARCHYCAL ORDER*
*                        AND PERFORMING OPERATIONS LIKE DISPLAY/CHANGE
*                        ORDER, COMPLETE/DISCARD CR/PI SHEET ETC.    *
*====================================================================*
* COPIED FROM          : (CLONED PROGRAM                             *
* TITLE                : (PROGRAM TITLE)                             *
* OTHER RELATED OBJ    : (OBJECT NAMES)                              *
*====================================================================*
* CHANGE HISTORY LOG                                                 *
*--------------------------------------------------------------------*
* MOD. NO.|  DATE   | NAME   | CORRECTION NUMBER | CHANGE REFERENCE #*
*--------------------------------------------------------------------*
* MOD-001 |         |        | XXXXXXXXXX       | XXXXXXXXX          *
*                                                                    *
* DESCRIPTION:                                                       *
*--------------------------------------------------------------------*
* MOD-002 |DD/MM/YYYY| XXXXXX | XXXXXXXXXX                           *
*                                                                    *
* DESCRIPTION:                                                       *
**********************************************************************
 REPORT  ZPROCORDCTRL NO STANDARD PAGE HEADING
                      LINE-SIZE  190
                      LINE-COUNT 255
*                     MESSAGE-ID zprgtpt_trans.
                      MESSAGE-ID ZZ.

*Tables---------------------------------------------------------------*
 TABLES: afko,
         resb,
         aufk,
         mara,
         crhd,
         coch,
         tj48t,
         tj02t,
         t001w,
         t003o,
         t024f,
         t134,
         tcb04t,
         rco53if,
         rco54if,
         rcrde,
         makt,
         tc52,
         tc50.

*Type Declaration-----------------------------------------------------*

*Type declaration for final report output display
 TYPES: BEGIN OF struct_temp,
       box TYPE text10,
       err(4) TYPE c,
       summ(4) TYPE c,
       exe(4) TYPE c,
       count(4) TYPE c,
       status(20) TYPE c,"aufastnr,
       type(10) TYPE c,"aufart,
       destination TYPE adr,
       material TYPE matnr,
       description TYPE maktx,
       creationdate(10) TYPE c,"auferfdat,
       creationtime(8) TYPE c,"auferfdat,
 END OF struct_temp.

*Type Declaration for Selection profile status and order status fields
 TYPES: BEGIN OF typ_s_aufnr,
          aufnr TYPE aufnr,
        END OF typ_s_aufnr,

*Type Declaration for Selection profile status and order status fields
        typ_ts_aufnr TYPE SORTED TABLE OF typ_s_aufnr
                WITH NON-UNIQUE KEY aufnr,
        BEGIN OF typ_s_objnr,
           aufnr TYPE aufnr,
           aufpl TYPE co_aufpl,
           aplfl TYPE plnfolge,
           plnfl TYPE plnfolge,
           objnr TYPE j_objnr,
       END OF typ_s_objnr,
       typ_ts_aufnr_objnr TYPE SORTED TABLE OF typ_s_objnr
                      WITH NON-UNIQUE KEY aufnr objnr,
       typ_ts_objnr TYPE SORTED TABLE OF typ_s_objnr.

*Type declaration for order informations
 TYPES: BEGIN OF ty_afko,
          aufnr TYPE aufnr,      " Process Order
          auart TYPE aufart,     " Order type
          aufpl TYPE co_aufpl,   " Routing number
          aplzt TYPE co_aplzl,   " Counter number
          werks TYPE werks_d,    " Plant
          rsnum TYPE rsnum,      " Number of Reservation
          objnr TYPE j_objnr,    " Object number
          erdat TYPE auferfdat,   "Created on
          aedat TYPE aufaedat,    "chaged on
          erfzeit TYPE co_ins_time, "Created at
          plnbez TYPE matnr,     " Material
          maktx TYPE maktx,      " Material description
          flag(1) TYPE c,        " Flag indicator
          objnrdec TYPE j_stext, " Decoded value of objnr
        END OF ty_afko,

*Type declaration for Operation within an order information
      BEGIN OF ty_afvc,
        aufpl TYPE co_aufpl,    " Routing number
        arbid TYPE cr_objid,    " Object Id
        phseq TYPE phseq,       " Control Receipe Dest.
        arbpl TYPE arbpl,       " Resource
      END OF ty_afvc,

*Type declaration for lookup informations
      BEGIN OF ty_lookup,
        itemno(4) TYPE c,       " Item No
        doctype(4) TYPE c,      " Document Type
        docno(20) TYPE c,       " Document
        order TYPE aufnr,       " Order
        plant TYPE werks,       " Plant
        frdate TYPE auferfdat,  "creation date
        todate TYPE aufaedat,   "changed on
        pitype TYPE c,          "PI Type
        sender TYPE adr,        "Sender
      END OF ty_lookup.

*Type Declaration for error messages
 TYPES: BEGIN OF ty_errorlog,
          docno(20) TYPE c,     " Document
          message(50) TYPE c,   " Error Log
        END OF ty_errorlog,

*Type Declaration for Plant
       BEGIN OF ty_werks,
         werks  TYPE t001w-werks, "Plant
       END OF ty_werks,

*Type Declaration for status
       BEGIN OF ty_status,
         status TYPE j_txt04,  "LIKE tj02t-txt04,  "Status
       END OF ty_status.

 TYPES: BEGIN OF ty_status_tmp,
         stat TYPE j_status,    "LIKE jest-stat,
         excl TYPE flg_sel,     "LIKE rc27x-flg_sel,
       END OF ty_status_tmp.

* INTERNAL TABLES------------------------------------------------------*

*Internal table for holding order data
 DATA: i_afko TYPE STANDARD TABLE OF ty_afko
       INITIAL SIZE 0 WITH HEADER LINE.

 DATA: i_afvc TYPE STANDARD TABLE OF ty_afvc
       INITIAL SIZE 0 WITH HEADER LINE.

*Internal table to hold lookup information
 DATA: i_lookup TYPE STANDARD TABLE OF ty_lookup
       INITIAL SIZE 0 WITH HEADER LINE.

*Internal table to hold all valid Plants
 DATA: i_werks TYPE STANDARD TABLE OF ty_werks
       INITIAL SIZE 0 WITH HEADER LINE.

*Internal table to hold order master data
 DATA : i_aufk TYPE STANDARD TABLE OF aufk
        INITIAL SIZE 0 WITH HEADER LINE.

*Internal table to hold order status
 DATA: i_status_table TYPE  STANDARD TABLE OF ty_status
        INITIAL SIZE 0 WITH HEADER LINE.

*Internal table to hold Process Management: Control Recipe Header data
 DATA : i_sheet_header TYPE  STANDARD TABLE OF coch
        INITIAL SIZE 0 WITH HEADER LINE.

*Internal table to hold Return Code and Message for PI Sheet data
 DATA : i_return_message TYPE STANDARD TABLE OF rcopisrtc
        INITIAL SIZE 0 WITH HEADER LINE.

*Internal table to hold Process Management: Control Recipe Header data
 DATA : i_crheader TYPE STANDARD TABLE OF coch
        INITIAL SIZE 0 WITH HEADER LINE.

*Internal table to hold PP-PI: Header Data for Process Messages data
 DATA : i_comh TYPE STANDARD TABLE OF comh
        INITIAL SIZE 0 WITH HEADER LINE.

*Internal table to hold final report layout data
 DATA: i_report TYPE struct_temp.

*Internal table to hold Status header data
 DATA : i_status_hdr_tab TYPE STANDARD TABLE OF ty_status_tmp
        INITIAL SIZE 0 WITH HEADER LINE.

*Internal table to hold ALV tree control: List of selected checkboxes
 DATA : mt_checked_items TYPE lvc_t_chit.

*Internal table to hold bapi informations
 DATA : i_procmessheader TYPE STANDARD TABLE OF bapi_rcomhapi
        INITIAL SIZE 0 WITH HEADER LINE,

        i_procmesscharac TYPE STANDARD TABLE OF bapi_rcomeapi
        INITIAL SIZE 0 WITH HEADER LINE,

        i_procmessheaderreturn TYPE STANDARD TABLE OF bapi_rcomhrtc
        INITIAL SIZE 0 WITH HEADER LINE,

        i_procmesscharacreturn TYPE STANDARD TABLE OF bapi_rcomertc
        INITIAL SIZE 0 WITH HEADER LINE,

        i_processmessagenew TYPE STANDARD TABLE OF bapi_rcomh
        INITIAL SIZE 0 WITH HEADER LINE,

        i_procmesstextlines TYPE STANDARD TABLE OF bapi_rcomstxt
        INITIAL SIZE 0 WITH HEADER LINE,

        i_return TYPE STANDARD TABLE OF bapiret2
        INITIAL SIZE 0 WITH HEADER LINE,

        i_discard_pi TYPE STANDARD TABLE OF bapi_cntlrecid
        INITIAL SIZE 0 WITH HEADER LINE.

*Internal table to hold data for final report output display
 DATA :  i_header TYPE STANDARD TABLE OF struct_temp
         INITIAL SIZE 0." WITH HEADER LINE.

* Table for storing the error messages
 DATA: i_errorlog TYPE STANDARD TABLE OF ty_errorlog
       INITIAL SIZE 0 WITH HEADER LINE.

*Internal table to hold alv display data
 DATA: l_layout_node TYPE lvc_s_layn.
 DATA: i_lvc_nkey TYPE lvc_t_nkey.
 DATA: i_children TYPE lvc_t_nkey.
 DATA: i_nodekey_change TYPE lvc_t_nkey.
 DATA: i_nodekey_change1 TYPE lvc_t_nkey.

*&---------------------------------------------------------------------&
*                      RANGES                                          *
*&---------------------------------------------------------------------&
 RANGES: aufnr_range       FOR aufk-aufnr.

*variables-------------------------------------------------------------*
* DEFINE STANDARD TABLES                                               *
 DATA: v_alv_tree         TYPE REF TO cl_gui_alv_tree,
       v_column_tree      TYPE REF TO cl_gui_column_tree,
       v_custom_container TYPE REF TO cl_gui_custom_container.

 CLASS cl_gui_column_tree DEFINITION LOAD.
 CLASS cl_gui_cfw DEFINITION LOAD.

 DATA tree1  TYPE REF TO cl_gui_alv_tree.
 DATA mr_toolbar TYPE REF TO cl_gui_toolbar.

 DATA : i_fieldcatalog TYPE lvc_t_fcat,
        v_max TYPE i VALUE 255,
        v_check TYPE c,
        v_ordstatus TYPE bsvx-sttxt,
        v_discard_pi TYPE c,
        v_cr_status(5) TYPE c,
        v_fav_key TYPE lvc_nkey.

 DATA : v_state TYPE  co_crstat,
        v_exe(4) TYPE c,
        v_proc_mess_id_tmp TYPE co_msid2,
        v_ordclick TYPE c,
        v_checkbox_check TYPE c.

 DATA: v_node_key TYPE lvc_t_nkey."lvc_nkey,
 DATA v_item_name TYPE lvc_nkey."tv_itmname.
 DATA v_node_key1 TYPE lvc_fname.
 DATA : i_node_key TYPE lvc_nkey,
        i_item_layout TYPE lvc_t_layi,
        i_item_layout_s TYPE lvc_s_layn,
        i_outtab_line TYPE abc_ftreet.

 DATA : v_node_text TYPE lvc_value.
 DATA : v_key(4) TYPE c.
 DATA : v_mt_checked_items TYPE lvc_s_chit.
 DATA : v_return_code TYPE i.
 DATA : v_crd(8) TYPE c VALUE 'Y_ST_'.

*Constants-------------------------------------------------------------*
 CONSTANTS :
 c_dash(1) TYPE c VALUE '-',       " value of -
 c_x(1) TYPE c VALUE 'X',          " value of X
 c_3p(4) TYPE c VALUE ' (3P)',      " value of  (3P)
 c_bz(4) TYPE c VALUE ' (BZ)',      " value of  (BZ)
 c_5b(4) TYPE c VALUE ' (5B)',      " value of  (5B)
 c_kb(4) TYPE c VALUE ' (KB)',      " value of  (KB)
 c_j4(4) TYPE c VALUE ' (J4)',      " value of  (J4)
 c_39(4) TYPE c VALUE ' (39)',      " value of  (39)
 c_ord(3) TYPE c VALUE 'ORD',      " value of ORD
 c_cr(2) TYPE c VALUE 'CR',        " value of CR
 c_mesg(4) TYPE c VALUE 'MESG',    " value of MSEG
 c_pi(2) TYPE c VALUE 'PI',        " value of PI
 c_box(3) TYPE c VALUE 'BOX',      " value of BOX
 c_dot(1) TYPE c VALUE '.',        " value of .
 c_one(5) TYPE c VALUE '00001',    " value of '00001
 c_two(5) TYPE c VALUE '00002',    " value of '00002
 c_three(5) TYPE c VALUE '00003',  " value of '00003
 c_four(5) TYPE c VALUE '00004',   " value of '00004
 c_five(5) TYPE c VALUE '00005',   " value of '00005
 c_six(5) TYPE c VALUE '00006',    " value of '00006
 c_seven(5) TYPE c VALUE '00007',  " value of '00007
 c_eight(5) TYPE c VALUE '00008',  " value of '00008
 c_nine(5) TYPE c VALUE '00009',   " value of '00009
 c_5d(4) TYPE c VALUE ' (5D)',      " value of  (5D)
 c_5c(4) TYPE c VALUE ' (5C)',      " value of  (5C)
 c_5f(4) TYPE c VALUE ' (5F)',      " value of  (5F)
 c_0a(4) TYPE c VALUE ' (0A)',      " value of  (0A)
 c_09(4) TYPE c VALUE ' (09)',      " value of  (09)
 c_03(4) TYPE c VALUE ' (03)',      " value of  (03)
 c_08(4) TYPE c VALUE ' (08)',      " value of  (08)
 c_t(1) TYPE c VALUE 'T',          " value of T
 c_d(1) TYPE c VALUE 'D',          " value of D
 c_n(1) TYPE c VALUE 'N',          " value of N
 c_e(1) TYPE c VALUE 'E',          " value of E
 c_i(1) TYPE c VALUE 'I',          " value of I
 c_w(1) TYPE c VALUE 'W',          " value of W
 c_o(1) TYPE c VALUE 'O',          " value of O
 c_c(1) TYPE c VALUE 'C',          " value of C
 c_p(1) TYPE c VALUE 'P',          " value of P
 c_m(1) TYPE c VALUE 'M',          " value of M
 c_eq(2) TYPE c VALUE 'EQ',        " value of EQ
 c_a(1) TYPE c VALUE 'A',          " value of Abort
 c_br1(3) TYPE c VALUE 'BR1',      " value of BR1
 c_err TYPE lvc_fname VALUE 'ERR', " value of ERR
 c_container(9) TYPE c VALUE 'CONTAINER'," value of CONTAINER
 c_anr(3) TYPE c VALUE 'ANR',      " value of ANR
 c_wrk(3) TYPE c VALUE 'WRK',      " value of WRK
 c_cor3(4) TYPE c VALUE 'COR3',    " value of COR3
 c_cor2(4) TYPE c VALUE 'COR2',    " value of COR2
 c_co53(4) TYPE c VALUE 'CO53',    " value of CO53
 c_co54(4) TYPE c VALUE 'CO54',    " value of CO54
 c_co60(4) TYPE c VALUE 'CO60',    " value of CO60
 c_star(1) TYPE c VALUE '*',       " value of *
 c_transaction(17) TYPE c VALUE 'ZPROCORDCTRL',
                                   " value of ZPROCORDCTRL
 c_terminated(10) TYPE c VALUE 'Terminated',
                                   " value of TERMINATED
 c_discarded(9) TYPE c VALUE 'Discarded',  " value of Discarded
 c_processed(9) TYPE c VALUE 'Processed',  " value of Processed
 c_completed(9) TYPE c VALUE 'Completed',  " value of Completed
 c_inprocess(10) TYPE c VALUE 'In Process'," value of In Process
 c_new1(3) TYPE c VALUE 'New',             " value of New
 c_tobecompleted(15) TYPE c VALUE 'To Be Completed',
                                           " value of To be Completed
 c_cancelled(9) TYPE c VALUE 'Cancelled',  " value of CAncelled
 c_sent(4) TYPE c VALUE 'Sent',            " value of Sent
 c_tobesent(10) TYPE c VALUE 'To Be Sent', " value of To be sent
 c_sentwithwarning(17) TYPE c VALUE 'Sent with Warning',
                                           " value of Sent with Warning
 c_pi_crst(7) TYPE c VALUE 'PI_CRST',      " value of PI_CRST
 c_pppi_process_order(18) TYPE c VALUE 'PPPI_PROCESS_ORDER',
                                           " value of PPPI_PROCESS_ORDER
 c_char(4) TYPE c VALUE 'CHAR',            " value of CHAR
 c_pppi_control_recipe(19) TYPE c VALUE 'PPPI_CONTROL_RECIPE',
                                " value of PPPI_CONTROL_RECEIPE
 c_pppi_control_recipe_status(26) TYPE c VALUE
                              'PPPI_CONTROL_RECIPE_STATUS',
                                " value of PPPI_RECEIPE_STATUS
 c_complete(8) TYPE c VALUE 'COMPLETE',    " value of COMPLETE
 c_00005(5) TYPE c VALUE '00005',          " value of 00005
 c_00007(5) TYPE c VALUE '00007',          " value of 00007
 c_pppi_event_date(15) TYPE c VALUE 'PPPI_EVENT_DATE',
                                           " value of PPPI_EVENT_DATE
 c_date(4) TYPE c VALUE 'DATE',            " value of DATE
 c_pppi_event_time(15) TYPE c VALUE 'PPPI_EVENT_TIME',
                                           " value of PPPI_EVENT_TIME
 c_time(4) TYPE c VALUE 'TIME',            " value of TIME
 c_2(1) TYPE c VALUE '2',                  " value of 2
 c_ms(2) TYPE c VALUE 'MS'.                " value of MS

*----------------------------------------------------------------------*
*                        Selection screen                              *
*----------------------------------------------------------------------*

** REGULAR SELECTION SCREEN                                            *
 SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
 SELECT-OPTIONS:
                 s_werks FOR aufk-werks MEMORY ID wrk OBLIGATORY, "plant
                 s_auart FOR aufk-auart MEMORY ID aat,    "Order Type
                 s_aufnr FOR aufk-aufnr MATCHCODE OBJECT ordb
                              MEMORY ID anr,           " process order
                 s_fevor FOR afko-fevor,           "Production scheduler
                 s_plnbez FOR afko-plnbez MATCHCODE OBJECT ordb,
                                                         "Material
                 s_mtart FOR t134-mtart MEMORY ID mta , "material Type
                 s_ress FOR crhd-arbpl                   " Ressource
                              MATCHCODE OBJECT cram
                              MEMORY ID agr,
                 s_phseq FOR coch-phseq  . " MEMORY ID phseq.

 SELECTION-SCREEN: END OF BLOCK b1 .

 SELECTION-SCREEN : BEGIN OF BLOCK b2 WITH FRAME TITLE text-002  .
 SELECT-OPTIONS: s_gstrp FOR afko-gstrp ," MEMORY ID sed,
                 s_gltrp FOR afko-gltrp .

 SELECTION-SCREEN : END OF BLOCK b2 .
 SELECTION-SCREEN : BEGIN OF BLOCK b3 WITH FRAME TITLE text-003 .
 SELECT-OPTIONS   s_status FOR tj02t-txt04.              "Order Status

 SELECTION-SCREEN SKIP 1.

 SELECTION-SCREEN : BEGIN OF BLOCK b3_box1 WITH FRAME TITLE text-020."B1

 SELECTION-SCREEN : BEGIN OF LINE .
 SELECTION-SCREEN POSITION 5.
 SELECTION-SCREEN COMMENT 5(18) text-008 FOR FIELD c_new.
 PARAMETER : c_new AS   CHECKBOX DEFAULT 'X'.
 SELECTION-SCREEN COMMENT 40(18) text-011  FOR FIELD c_inwork .
 PARAMETER : c_inwork TYPE co_pis_inwork AS CHECKBOX DEFAULT 'X'.
 SELECTION-SCREEN  COMMENT  75(18) text-013 FOR FIELD c_close .
 PARAMETER c_close TYPE co_pis_close
                 AS CHECKBOX DEFAULT 'X'.
 SELECTION-SCREEN : END OF LINE .

 SELECTION-SCREEN : BEGIN OF LINE .
 SELECTION-SCREEN COMMENT 5(18) text-016 FOR FIELD c_canc .
 PARAMETER : c_canc TYPE co_pis_canc
                 AS CHECKBOX DEFAULT 'X'.
 SELECTION-SCREEN COMMENT  40(18) text-017 FOR FIELD c_disc.
 PARAMETER : c_disc TYPE co_pis_disc
                 AS CHECKBOX DEFAULT 'X'.

 SELECTION-SCREEN : END OF LINE .

 SELECTION-SCREEN : BEGIN OF LINE .
 SELECTION-SCREEN COMMENT 5(18) text-018 FOR FIELD c_comp .
 PARAMETER : c_comp TYPE co_pis_compl
                 AS CHECKBOX DEFAULT 'X'.
 SELECTION-SCREEN COMMENT 40(18) text-019 FOR FIELD c_arch .
 PARAMETER : c_arch TYPE co_pis_arch
                 AS CHECKBOX DEFAULT 'X'.
 SELECTION-SCREEN : END OF LINE .

 SELECTION-SCREEN : END OF BLOCK b3_box1.  "B1

 SELECTION-SCREEN : BEGIN OF BLOCK b3_box2 WITH FRAME TITLE text-021."B2

 SELECTION-SCREEN : BEGIN OF LINE .
 SELECTION-SCREEN POSITION 5.
 SELECTION-SCREEN COMMENT 5(18) text-009 FOR FIELD c_create.
 PARAMETER : c_create AS CHECKBOX DEFAULT 'X'.
 SELECTION-SCREEN COMMENT 40(18) text-012 FOR FIELD c_sentcr .
 PARAMETER : c_sentcr AS CHECKBOX DEFAULT 'X'.
 SELECTION-SCREEN COMMENT 75(18) text-014 FOR FIELD c_proces .
 PARAMETER : c_proces AS CHECKBOX DEFAULT 'X'.

 SELECTION-SCREEN : END OF LINE .

 SELECTION-SCREEN : BEGIN OF LINE .

 SELECTION-SCREEN COMMENT 5(18) text-015 FOR FIELD c_termin .
 PARAMETER c_termin AS CHECKBOX DEFAULT 'X'.
 SELECTION-SCREEN COMMENT 40(18) text-017 FOR FIELD c_disccr .
 PARAMETER : c_disccr AS CHECKBOX DEFAULT 'X'.

 SELECTION-SCREEN : END OF LINE .

 SELECTION-SCREEN : END OF BLOCK b3_box2.

 SELECTION-SCREEN : BEGIN OF BLOCK b3_box3 WITH FRAME TITLE text-022.

 SELECTION-SCREEN : BEGIN OF LINE .
 SELECTION-SCREEN POSITION 5.

 SELECTION-SCREEN COMMENT 5(18) text-010 FOR FIELD c_tosend.
 PARAMETER : c_tosend AS CHECKBOX DEFAULT 'X'.
 SELECTION-SCREEN COMMENT 40(18) text-012 FOR FIELD c_sentpm.
 PARAMETER : c_sentpm AS CHECKBOX DEFAULT 'X'.
 SELECTION-SCREEN COMMENT 75(18) text-015 FOR FIELD c_end .
 PARAMETER : c_end AS CHECKBOX DEFAULT 'X'.

 SELECTION-SCREEN : END OF LINE .

 SELECTION-SCREEN : END OF BLOCK b3_box3."B3

 SELECTION-SCREEN : END OF BLOCK b3 .

*---------------------------------------------------------------------*
*       AT SELECTION-SCREEN ON VALUE-REQUEST                          *
*---------------------------------------------------------------------*
 AT SELECTION-SCREEN ON VALUE-REQUEST FOR s_status-low.
   DATA: stsma     TYPE j_stsma.       "LIKE atj49-stsma.
   DATA: f4_cstate TYPE co_cstatus.    "LIKE atj49-cstate.

   PERFORM value_state(saplcoss) USING stsma CHANGING f4_cstate
                                       s_status-low.

 AT SELECTION-SCREEN ON VALUE-REQUEST FOR s_status-high.
   DATA: stsma     TYPE j_stsma.       "LIKE atj49-stsma.
   DATA: f4_cstate TYPE co_cstatus.    "LIKE atj49-cstate.

   PERFORM value_state(saplcoss) USING stsma CHANGING f4_cstate
                                       s_status-high.

** INITIALIZATION------------------------------------------------------*
*INITIALIZATION.                                                       *
*                                                                      *
** AT SELECTION SCREEN-------------------------------------------------*

*Validation of Plant
 AT SELECTION-SCREEN ON s_werks.
   PERFORM validate_plant.

* Check the authorisation
   PERFORM check_authorisations.

*Validation of Order type
 AT SELECTION-SCREEN ON s_auart.
   PERFORM validate_order_type.

*Validation of Process Order
 AT SELECTION-SCREEN ON s_aufnr.
   PERFORM validate_order.

*Validation of Production scheduler
 AT SELECTION-SCREEN ON s_fevor.
   PERFORM validate_prod_scheduler.

*Validation of Material
 AT SELECTION-SCREEN ON s_plnbez.
   PERFORM validate_material.

*Validation of Material type
 AT SELECTION-SCREEN ON s_mtart.
   PERFORM validate_material_type.

*Validation of Resource
 AT SELECTION-SCREEN ON s_ress.
   PERFORM validate_resource.

*Validation of Control Recipe Dest.
 AT SELECTION-SCREEN ON s_phseq.
   PERFORM validate_cntrl_recp_dest.

*Validation of order status
 AT SELECTION-SCREEN ON s_status.

   LOOP AT s_status.
     IF NOT s_status-high IS INITIAL.
       PERFORM system_state_check CHANGING s_status-low.
       MODIFY s_status.
       PERFORM system_state_check CHANGING s_status-high.
       MODIFY s_status.
     ELSE.
       PERFORM system_state_check CHANGING s_status-low.
       MODIFY s_status.
     ENDIF.
   ENDLOOP.

*Check at list one of the checkbox is checked or not
 AT SELECTION-SCREEN.
   PERFORM checkbox_check.

****************INCLUDES*******************************
   INCLUDE <icon>.

****************INCLUDES*******************************

*###############################################################
* LOCAL CLASSES
*###############################################################
*§1. Define a (local) class for event handling

 CLASS lcl_tree_event_receiver DEFINITION.

   PUBLIC SECTION.
*§2. Define an event handler method for each event you want to react to.
     METHODS handle_node_double_click
       FOR EVENT node_double_click OF cl_gui_alv_tree
       IMPORTING node_key sender.

     METHODS handle_checkbox_change
       FOR EVENT checkbox_change OF cl_gui_alv_tree
       IMPORTING node_key sender.

* 'sender' is an implicit event parameter that is provided by
* ABAP Objects runtime system. It contains a reference to the
* object that fired the event. You may directly use it to
* call methods of this instance.
     METHODS handle_item_double_click
       FOR EVENT item_double_click OF cl_gui_alv_tree
       IMPORTING node_key sender.

 ENDCLASS.                    "lcl_tree_event_receiver DEFINITION
******************************************************************
 CLASS lcl_tree_event_receiver IMPLEMENTATION.

*Node double click handling
   METHOD handle_node_double_click.
     DATA: lt_children TYPE lvc_t_nkey.
*first check if the node is a leaf, i.e. can not be expanded

     CALL METHOD sender->get_children
       EXPORTING
         i_node_key  = node_key
       IMPORTING
         et_children = lt_children.

     IF NOT lt_children IS INITIAL.

       IF v_ordclick EQ c_o.
         PERFORM call_transaction_cor2.
       ELSE.
         CALL METHOD sender->expand_node
           EXPORTING
             i_node_key    = node_key
             i_level_count = 2.
       ENDIF.

     ELSEIF v_ordclick EQ c_c.
       PERFORM call_transaction_co53.
     ELSEIF v_ordclick EQ c_m.
       PERFORM call_transaction_co54.
     ELSEIF v_ordclick EQ c_p.
       PERFORM call_transaction_co60.

     ENDIF.

   ENDMETHOD.                    "handle_node_double_click

*Checkbox change handling
   METHOD handle_checkbox_change.

   ENDMETHOD.                    "handle_checkbox_change

*Item Double click handling
   METHOD handle_item_double_click.
     DATA: lt_children TYPE lvc_t_nkey.
     DATA: lt_selected_node TYPE lvc_nkey,
           lt_fieldname TYPE lvc_fname.

     CALL METHOD sender->get_selected_item
       IMPORTING
         e_selected_node = lt_selected_node
         e_fieldname     = lt_fieldname.

     IF NOT lt_selected_node IS INITIAL.
*Code for the Item selec event
       IF v_ordclick EQ c_c.
         PERFORM call_transaction_co53.
       ELSEIF v_ordclick EQ c_m.
         PERFORM call_transaction_co54.
       ELSEIF v_ordclick EQ c_p.
         PERFORM call_transaction_co60.
       ENDIF.
     ENDIF.

     CALL METHOD sender->get_children
       EXPORTING
         i_node_key  = node_key
       IMPORTING
         et_children = lt_children.

     IF NOT lt_children IS INITIAL.

       IF v_ordclick EQ c_o.
         PERFORM call_transaction_cor2.
       ELSE.
         CALL METHOD sender->expand_node
           EXPORTING
             i_node_key    = node_key
             i_level_count = 2.
       ENDIF.
     ENDIF.

   ENDMETHOD.                    "handle_item_double_click

 ENDCLASS.                    "lcl_tree_event_receiver IMPLEMENTATION
*##################################################################

** TOP OF PAGE---------------------------------------------------------*
*TOP-OF-PAGE.                                                          *
*                                                                      *
** START OF SELECTION--------------------------------------------------*
 START-OF-SELECTION.

* Populate the table i_afvc with phase information
   PERFORM populate_afvc.

*Get Order status into an internal table.
   PERFORM order_status_table.

* fill status tables
   PERFORM fill_status_tables.

* fill select ranges for order
   PERFORM fill_ranges.

* status check header
   PERFORM check_s_selid.

* fill aufnr_range
   PERFORM update_s_aufnr .

*Retrive required data from AFKO table based on the selection screen
   PERFORM get_order_data.

** AT LINE SELECTION---------------------------------------------------*
*AT LINE-SELECTION.                                                    *
*                                                                      *
** AT USER COMMAND-----------------------------------------------------*
*AT USER-COMMAND.                                                      *
*                                                                      *
** END OF SELECTION----------------------------------------------------*

 END-OF-SELECTION.

*Call custom screen where report is to be displayed
   CALL SCREEN 100.
*&---------------------------------------------------------------------

*&      Module  PBO OUTPUT
*&---------------------------------------------------------------------
* Module Process before output
*----------------------------------------------------------------------

 MODULE pbo OUTPUT.
*Set PF-Status and titlebar for the report
   SET PF-STATUS 'MAIN100'.
   SET TITLEBAR 'MAINTITLE'.

*Prepare hierarchy report
   IF v_alv_tree IS INITIAL.
     PERFORM init_tree.

     IF NOT i_lookup[] IS INITIAL.
*Expand all order nodes
       PERFORM all_header_node_expand.

       CALL METHOD cl_gui_cfw=>flush
         EXCEPTIONS
           cntl_system_error = 1
           cntl_error        = 2.
       IF sy-subrc NE 0.
         CALL FUNCTION 'POPUP_TO_INFORM'
           EXPORTING
             titel = text-054 "'Errors in Automation Queue'
             txt1  = text-055 "'Internal Error'
             txt2  = text-056 "'A Method in Automation Queue'
             txt3  = text-057."'has an Error Released'.
       ENDIF.
     ENDIF.
   ENDIF.

 ENDMODULE.                 " PBO OUTPUT
*&---------------------------------------------------------------------*
*&      Module  PAI INPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
 MODULE pai INPUT.

*Get the item or node selected
   PERFORM get_item_and_node_select.

   CASE sy-ucomm.
     WHEN 'EXIT' OR 'BACK' OR 'CANC'.
       PERFORM exit_program.

*When Display Order
     WHEN 'DISPORD'.
       PERFORM call_transaction_cor3.

*When Change Ordre
     WHEN 'CHANGORD'.
       PERFORM call_transaction_cor2.

*Control Recipe
     WHEN 'CNTRLRECP'.
       PERFORM call_transaction_co53.

*Proces Messages
     WHEN 'MESSAGE'.
       PERFORM call_transaction_co54.

*Display Error log
     WHEN 'DISPLOG'.
       PERFORM display_log.

*Complete Control recipe/PI Sheet
     WHEN 'COMPLETE'.
       PERFORM complete_proecess.

*Discard Control recipe
     WHEN 'DISCARD'.
       PERFORM discard_proecess.

*Refresh Report Display
     WHEN 'REFRESH'.
       PERFORM refresh_display_list.

*When Item/Node double click or checkbox change
     WHEN OTHERS.
       READ TABLE i_lookup WITH KEY itemno = v_key.
       IF sy-subrc = 0.
         IF i_lookup-doctype = c_ord.
           v_ordclick = c_o.
         ELSEIF i_lookup-doctype = c_cr AND
                  NOT i_lookup-docno IS INITIAL.
           v_ordclick = c_c.
         ELSEIF i_lookup-doctype = c_pi AND
                  NOT i_lookup-docno IS INITIAL.
           v_ordclick = c_p.
         ELSEIF i_lookup-doctype = c_mesg AND
                  NOT i_lookup-docno IS INITIAL.
           v_ordclick = c_m.
         ENDIF.
*Checkbox change,node and item click ivent triger
         CALL METHOD cl_gui_cfw=>dispatch
           IMPORTING
             return_code = v_return_code.
         CLEAR v_ordclick.
       ENDIF.

   ENDCASE.

   CALL METHOD cl_gui_cfw=>flush
     EXCEPTIONS
       cntl_system_error = 1
       cntl_error        = 2.

 ENDMODULE.                 " PAI INPUT
**&---------------------------------------------------------------------
**&      Form  exit_program
**&---------------------------------------------------------------------
**       free object and leave program
**----------------------------------------------------------------------

 FORM exit_program.

   CALL METHOD v_custom_container->free.

   LEAVE TO TRANSACTION c_transaction.

 ENDFORM.                               " exit_program
**&---------------------------------------------------------------------
**&      Form  init_tree
**&---------------------------------------------------------------------
** Create Field catalog,container and hierarchy order report
**----------------------------------------------------------------------
 FORM init_tree .

* create container for alv-tree
   DATA: l_tree_container_name(30) TYPE c.

   l_tree_container_name = 'CONTAINER'.

   CREATE OBJECT v_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 text-058.  "'ERROR'.
   ENDIF.

* create tree control
   CREATE OBJECT v_alv_tree
     EXPORTING
         parent              = v_custom_container
        node_selection_mode = cl_gui_column_tree=>node_sel_mode_multiple
         item_selection      = c_x
         no_html_header      = c_x
         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 text-058.  "'ERROR'.       "#EC NOTEXT
   ENDIF.

* create Hierarchy-header
   DATA l_hierarchy_header TYPE treev_hhdr.
   PERFORM build_hierarchy_header CHANGING l_hierarchy_header.

* repid for saving variants
   DATA: l_variant TYPE disvariant.
   l_variant-report = sy-repid.

* Hide columns and mark complete column for icon display
   PERFORM build_fieldcatalog.

*Set the display table
   CALL METHOD v_alv_tree->set_table_for_first_display
     EXPORTING
       is_hierarchy_header = l_hierarchy_header
*       it_list_commentary  = l_list_commentary
*       i_logo              = l_logo
*       i_background_id     = 'ALV_BACKGROUND'
*       i_save              = 'A'
       is_variant          = l_variant
     CHANGING
       it_fieldcatalog     = i_fieldcatalog
       it_outtab           = i_header. "table must be empty !

   PERFORM create_hierarchy.

* add own functioncodes to the toolbar
*  PERFORM CHANGE_TOOLBAR.

   IF i_lookup[] IS INITIAL.
     CALL METHOD v_custom_container->free.
     MESSAGE i000 WITH text-035.
     LEAVE TO TRANSACTION c_transaction.
   ELSE.
     PERFORM register_events.

* Send data to frontend.
     CALL METHOD v_alv_tree->frontend_update.
   ENDIF.

 ENDFORM.                    " init_tree
**&---------------------------------------------------------------------
**&      Form  build_fieldcatalog
**&---------------------------------------------------------------------
** Build field catalog table
** Field properties are specified with fix value. Constant not declared
** for them
**----------------------------------------------------------------------
 FORM build_fieldcatalog.

   DATA: l_fieldcatalog TYPE lvc_s_fcat.

   l_fieldcatalog-row_pos = 0.
   l_fieldcatalog-col_pos = 1.
   l_fieldcatalog-fieldname = 'BOX'.
   l_fieldcatalog-tabname = 1.
   l_fieldcatalog-datatype = 'CHAR'.
   l_fieldcatalog-fix_column = 'X'.
   l_fieldcatalog-outputlen = 7.
   l_fieldcatalog-inttype = 'C'.
   l_fieldcatalog-intlen = 000006.
   l_fieldcatalog-reptext = '     '.
   l_fieldcatalog-domname = 'TEXT10'.
   l_fieldcatalog-ref_table = 'ZPISTATUS'.
   l_fieldcatalog-dd_outlen = 000006.
   l_fieldcatalog-scrtext_l =  '     '.
   l_fieldcatalog-scrtext_m =  '     '.
   l_fieldcatalog-scrtext_s =  '     '.
   APPEND l_fieldcatalog TO i_fieldcatalog.

   l_fieldcatalog-row_pos = 0.
   l_fieldcatalog-col_pos = 2.
   l_fieldcatalog-fieldname = 'ERR'.
   l_fieldcatalog-tabname = 1.
   l_fieldcatalog-datatype = 'CHAR'.
   l_fieldcatalog-fix_column = 'X'.
   l_fieldcatalog-outputlen = 6.
   l_fieldcatalog-inttype = 'C'.
   l_fieldcatalog-intlen = 000004.
   l_fieldcatalog-reptext = '      '.
   l_fieldcatalog-domname = 'ZEXE'.
   l_fieldcatalog-ref_table = 'ZPISTATUS'.
   l_fieldcatalog-dd_outlen = 000004.
   l_fieldcatalog-scrtext_l =  ' Err  '.
   l_fieldcatalog-scrtext_m =  ' Err  '.
   l_fieldcatalog-scrtext_s =  ' Err  '.
   APPEND l_fieldcatalog TO i_fieldcatalog.

   l_fieldcatalog-row_pos = 0.
   l_fieldcatalog-col_pos = 3.
   l_fieldcatalog-fieldname = 'SUMM'.
   l_fieldcatalog-tabname = 1.
   l_fieldcatalog-datatype = 'CHAR'.
   l_fieldcatalog-fix_column = 'X'.
   l_fieldcatalog-outputlen = 6.
   l_fieldcatalog-inttype = 'C'.
   l_fieldcatalog-intlen = 000004.
   l_fieldcatalog-reptext = '      '.
   l_fieldcatalog-domname = 'ZEXE'.
   l_fieldcatalog-ref_table = 'ZPISTATUS'.
   l_fieldcatalog-dd_outlen = 000004.
   l_fieldcatalog-scrtext_l =  'Action'.
   l_fieldcatalog-scrtext_m =  'Action'.
   l_fieldcatalog-scrtext_s =  '  Ac  '.
   APPEND l_fieldcatalog TO i_fieldcatalog.

   l_fieldcatalog-row_pos = 0.
   l_fieldcatalog-col_pos = 4.
   l_fieldcatalog-fieldname = 'COUNT'.
   l_fieldcatalog-tabname = 1.
   l_fieldcatalog-datatype = 'CHAR'.
   l_fieldcatalog-fix_column = 'X'.
   l_fieldcatalog-outputlen = 6.
   l_fieldcatalog-inttype = 'C'.
   l_fieldcatalog-intlen = 000004.
   l_fieldcatalog-reptext = 'No'.
   l_fieldcatalog-domname = 'ZEXE'.
   l_fieldcatalog-ref_table = 'ZPISTATUS'.
   l_fieldcatalog-dd_outlen = 000004.
   l_fieldcatalog-scrtext_l =  'No Count'.
   l_fieldcatalog-scrtext_m =  'No Count'.
   l_fieldcatalog-scrtext_s =  '  No  '.
   APPEND l_fieldcatalog TO i_fieldcatalog.

   l_fieldcatalog-row_pos = 0.
   l_fieldcatalog-col_pos = 5.
   l_fieldcatalog-fieldname = 'EXE'.
   l_fieldcatalog-tabname = 1.
   l_fieldcatalog-datatype = 'CHAR'.
   l_fieldcatalog-fix_column = 'X'.
   l_fieldcatalog-outputlen = 8.
   l_fieldcatalog-inttype = 'C'.
   l_fieldcatalog-intlen = 000006.
   l_fieldcatalog-reptext = 'Exc'.
   l_fieldcatalog-domname = 'ZEXE'.
   l_fieldcatalog-ref_table = 'ZPISTATUS'.
   l_fieldcatalog-dd_outlen = 000006.
   l_fieldcatalog-scrtext_l =  'Exc'.
   l_fieldcatalog-scrtext_m =  'Exc'.
   l_fieldcatalog-scrtext_s =  'Exc'.
   APPEND l_fieldcatalog TO i_fieldcatalog.

   l_fieldcatalog-row_pos = 0.
   l_fieldcatalog-col_pos = 6.
   l_fieldcatalog-fieldname = 'STATUS'.
   l_fieldcatalog-tabname = 1.
   l_fieldcatalog-datatype = 'NUMC'.
   l_fieldcatalog-fix_column = 'X'.
   l_fieldcatalog-outputlen = 20.
   l_fieldcatalog-inttype = 'N'.
   l_fieldcatalog-intlen = 000002.
   l_fieldcatalog-reptext = 'Stat'.
   l_fieldcatalog-domname = 'AUFSTNR'.
   l_fieldcatalog-ref_table = 'ZPISTATUS'.
   l_fieldcatalog-dd_outlen = 000002.
   l_fieldcatalog-scrtext_l =  'Document status'.
   l_fieldcatalog-scrtext_m =  'Status'.
   l_fieldcatalog-scrtext_s =  'Status'.
   APPEND l_fieldcatalog TO i_fieldcatalog.

   l_fieldcatalog-row_pos = 0.
   l_fieldcatalog-col_pos = 7.
   l_fieldcatalog-fieldname = 'TYPE'.
   l_fieldcatalog-tabname = 1.
   l_fieldcatalog-datatype = 'CHAR'.
   l_fieldcatalog-fix_column = 'X'.
   l_fieldcatalog-outputlen = 14.
   l_fieldcatalog-inttype = 'C'.
   l_fieldcatalog-intlen = 000009.
   l_fieldcatalog-reptext = 'Type'.
   l_fieldcatalog-domname = 'AUFART'.
   l_fieldcatalog-ref_table = 'ZPISTATUS'.
   l_fieldcatalog-dd_outlen = 000008.
   l_fieldcatalog-scrtext_l =  'Document type'.
   l_fieldcatalog-scrtext_m =  'Type'.
   l_fieldcatalog-scrtext_s =  'Type'.
   APPEND l_fieldcatalog TO i_fieldcatalog.

   l_fieldcatalog-row_pos = 0.
   l_fieldcatalog-col_pos = 8.
   l_fieldcatalog-fieldname = 'DESTINATION'.
   l_fieldcatalog-tabname = 1.
   l_fieldcatalog-datatype = 'CHAR'.
   l_fieldcatalog-fix_column = 'X'.
   l_fieldcatalog-outputlen = 32.
   l_fieldcatalog-inttype = 'C'.
   l_fieldcatalog-intlen = 000032.
   l_fieldcatalog-reptext = 'Destination address'.
   l_fieldcatalog-domname = 'CHAR32'.
   l_fieldcatalog-ref_table = 'ZPISTATUS'.
   l_fieldcatalog-dd_outlen = 000032.
   l_fieldcatalog-scrtext_l =  'Destination/Sender address'.
   l_fieldcatalog-scrtext_m =  'Destn/Sendr'.
   l_fieldcatalog-scrtext_s =  'Destn/Send'.
   APPEND l_fieldcatalog TO i_fieldcatalog.

   l_fieldcatalog-row_pos = 0.
   l_fieldcatalog-col_pos = 9.
   l_fieldcatalog-fieldname = 'MATERIAL'.
   l_fieldcatalog-tabname = 1.
   l_fieldcatalog-convexit = 'MATN1'.
   l_fieldcatalog-datatype = 'CHAR'.
   l_fieldcatalog-fix_column = 'X'.
   l_fieldcatalog-outputlen = 18.
   l_fieldcatalog-inttype = 'C'.
   l_fieldcatalog-intlen = 000018.
   l_fieldcatalog-reptext = 'Material'.
   l_fieldcatalog-domname = 'MATNR'.
   l_fieldcatalog-ref_table = 'ZPISTATUS'.
   l_fieldcatalog-dd_outlen = 000018.
   l_fieldcatalog-scrtext_l =  'Material'.
   l_fieldcatalog-scrtext_m =  'Material'.
   l_fieldcatalog-scrtext_s =  'Material'.
   APPEND l_fieldcatalog TO i_fieldcatalog.

   l_fieldcatalog-row_pos = 0.
   l_fieldcatalog-col_pos = 10.
   l_fieldcatalog-fieldname = 'DESCRIPTION'.
   l_fieldcatalog-tabname = 1.
   l_fieldcatalog-datatype = 'CHAR'.
   l_fieldcatalog-fix_column = 'X'.
   l_fieldcatalog-outputlen = 40.
   l_fieldcatalog-inttype = 'C'.
   l_fieldcatalog-intlen = 000040.
   l_fieldcatalog-reptext = 'Material description'.
   l_fieldcatalog-domname = 'TEXT40'.
   l_fieldcatalog-ref_table = 'ZPISTATUS'.
   l_fieldcatalog-dd_outlen = 000040.
   l_fieldcatalog-scrtext_l =  'Material description'.
   l_fieldcatalog-scrtext_m =  'Description'.
   l_fieldcatalog-scrtext_s =  'Mat Descr'.
   APPEND l_fieldcatalog TO i_fieldcatalog.

   l_fieldcatalog-row_pos = 0.
   l_fieldcatalog-col_pos = 11.
   l_fieldcatalog-fieldname = 'CREATIONDATE'.
   l_fieldcatalog-tabname = 1.
   l_fieldcatalog-datatype = 'DATS'.
   l_fieldcatalog-fix_column = 'X'.
   l_fieldcatalog-outputlen = 14.
   l_fieldcatalog-inttype = 'D'.
   l_fieldcatalog-intlen = 000012.
   l_fieldcatalog-reptext = 'Created on'.
   l_fieldcatalog-domname = 'DATUM'.
   l_fieldcatalog-ref_table = 'ZPISTATUS'.
   l_fieldcatalog-dd_outlen = 000012.
   l_fieldcatalog-scrtext_l =  'Created on'.
   l_fieldcatalog-scrtext_m =  'Created on'.
   l_fieldcatalog-scrtext_s =  ' Crtd on   '.
   APPEND l_fieldcatalog TO i_fieldcatalog.

   l_fieldcatalog-row_pos = 0.
   l_fieldcatalog-col_pos = 12.
   l_fieldcatalog-fieldname = 'CREATIONTIME'.
   l_fieldcatalog-tabname = 1.
   l_fieldcatalog-datatype = 'TIMS'.
   l_fieldcatalog-fix_column = 'X'.
   l_fieldcatalog-outputlen = 12.
   l_fieldcatalog-inttype = 'D'.
   l_fieldcatalog-intlen = 000010.
   l_fieldcatalog-reptext = 'Created at'.
   l_fieldcatalog-domname = 'UZEIT'.
   l_fieldcatalog-ref_table = 'ZPISTATUS'.
   l_fieldcatalog-dd_outlen = 000010.
   l_fieldcatalog-scrtext_l =  'Created at'.
   l_fieldcatalog-scrtext_m =  'Created at'.
   l_fieldcatalog-scrtext_s =  ' Crtd at   '.
   APPEND l_fieldcatalog TO i_fieldcatalog.

** Change the fieldcatalog to hide fields and to determine
** some initial calculations for chosen fields.
   LOOP AT i_fieldcatalog INTO l_fieldcatalog.
     CASE l_fieldcatalog-fieldname.

       WHEN 'MATERIAL' OR 'DESCRIPTION'.
         l_fieldcatalog-no_out = 'X'.

       WHEN 'EXE'.
         l_fieldcatalog-icon = 'X'.

       WHEN 'ERR'.
         l_fieldcatalog-icon = 'X'.

       WHEN 'SUMM'.
         l_fieldcatalog-icon = 'X'.

       WHEN 'COUNT'.
         l_fieldcatalog-just = 'C'.

       WHEN 'BOX'.
         l_fieldcatalog-just = 'C'.

       WHEN 'STATUS'.
         l_fieldcatalog-just = 'L'.

     ENDCASE.

     MODIFY i_fieldcatalog FROM l_fieldcatalog.
   ENDLOOP.
** The fieldcatalog is provided in form 'init_tree' using method
** set_table_for_first_display.
 ENDFORM.                               " build_fieldcatalog
**&---------------------------------------------------------------------
*
**&      Form  create_hierarchy
**&---------------------------------------------------------------------
** Create hierarchycal display report with auder, CR PI and message
** status details for each order
**----------------------------------------------------------------------
 FORM create_hierarchy.

   DATA: i_report_t TYPE struct_temp OCCURS 0,
         l_top_key TYPE lvc_nkey.

* add data to tree
   DATA: l_carrid_key TYPE lvc_nkey,
         l_connid_key TYPE lvc_nkey,
         l_last_key TYPE lvc_nkey.

   DATA: l_month_key TYPE lvc_nkey,
         l_node_image TYPE tv_image.
* node-layout
   DATA: l_node_text TYPE lvc_value,
         l_month_text(15) TYPE c,
         l_carrier_image TYPE tv_image.
   DATA: l_count(4) TYPE c,
         l_itemno(4) TYPE c.

* Replace string for planetype by icon
*  perform insert_icons tables i_report_t.

   CLEAR i_afko.
   CLEAR i_lookup.
   l_count = 0.
   l_itemno = 0.
   IF NOT i_afko[] IS INITIAL.

     SORT i_afko BY aufnr.
*Loop at Order data and get CR,PI and messages for the process order and
*display the detail status report.
     LOOP AT i_afko.

       CLEAR i_report.
       CLEAR l_count.
*Check for the mat type, Resource & Control Recipe Dest
       PERFORM check_mattype_resourc_crdest.
*If either of these are not valid ignore that record.
       IF v_check IS INITIAL.

         PERFORM populate_order_data USING i_afko.
*Remove leading zeros form order no
         CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT'
           EXPORTING
             input  = i_afko-aufnr
           IMPORTING
             output = l_node_text.
         CONCATENATE l_node_text c_dash i_report-material c_dash
                     i_report-description INTO l_node_text
                     SEPARATED BY space.
*Checkbox check is done for checkbox display at the item & node
         CLEAR l_layout_node.
         l_layout_node-exp_image = c_3p.
         l_layout_node-n_image = c_3p.
         CLEAR l_month_key.
*Add first node with order status information
         PERFORM add_a_node USING i_report l_month_key l_node_text
                                  space l_carrier_image
                            CHANGING l_connid_key.
         l_month_key = l_connid_key.
         CLEAR v_checkbox_check.
         CLEAR l_layout_node.
*Prepare lookup table
         l_itemno = l_itemno + 1.
         PERFORM prepare_lookup_table USING l_itemno c_ord i_afko-aufnr.

*Get Cpntrol Recipe data for the order and display the required data in
*the status report
         PERFORM get_cr_data.

         IF i_crheader[] IS INITIAL.
*Make child folder for Control Recipes if no CR found for the order
           PERFORM display_folder USING i_report
                                        l_month_key
                                        text-036
                                         space
                                CHANGING l_connid_key.
*Prepare lookup table
           l_itemno = l_itemno + 1.
           PERFORM prepare_lookup_table USING l_itemno c_cr space.
         ELSE.

           CLEAR i_report.
           i_report-summ = v_exe.
           CLEAR v_exe.
           DESCRIBE TABLE i_crheader LINES l_count.
           i_report-count = l_count.
           l_node_text = text-036.
*Make child node for displaying Control Recipes for the order
           PERFORM add_a_node USING i_report l_month_key l_node_text
                                    space l_carrier_image
                              CHANGING l_connid_key.

*Prepare lookup table
           l_itemno = l_itemno + 1.
           PERFORM prepare_lookup_table USING l_itemno c_cr space.
*Loop at the Control recipe found for the order and display in the
*status report
           LOOP AT i_crheader.

             PERFORM populate_cr_data.

             l_node_text = i_crheader-crid.

             v_checkbox_check = c_x.
             l_layout_node-n_image = c_39. "Icon Generate
*Display Control Recipe items for the order
            PERFORM add_a_node USING  i_report l_connid_key l_node_text
                                      space l_carrier_image
                                 CHANGING l_last_key.

             CLEAR v_checkbox_check.
*Prepare lookup table
             l_itemno = l_itemno + 1.
             i_lookup-pitype = i_crheader-cotyp.
             PERFORM prepare_lookup_table USING l_itemno c_cr
                                                i_crheader-crid.
           ENDLOOP.
           CLEAR l_layout_node.
         ENDIF.

*Get PI Sheet data for the order and display the required data in the
*status report.
         PERFORM get_pi_sheet_data.

         IF i_sheet_header[] IS INITIAL.
*Make child folder for PI Sheets if no data found for the order
           PERFORM display_folder USING i_report
                                          l_month_key
                                          text-037
                                           space
                                  CHANGING l_connid_key.
*Prepare lookup table
           l_itemno = l_itemno + 1.
           PERFORM prepare_lookup_table USING l_itemno c_pi space.

         ELSE.
           CLEAR i_report.
           i_report-summ = v_exe.  "c_bz.
           DESCRIBE TABLE i_sheet_header LINES l_count.
           i_report-count = l_count.
           l_node_text = text-037.
*Make child node for displaying PI Sheets for the order
           PERFORM add_a_node USING i_report l_month_key l_node_text
                                    space l_carrier_image
                              CHANGING l_connid_key.

*Prepare lookup table
           l_itemno = l_itemno + 1.
           PERFORM prepare_lookup_table USING l_itemno c_pi space.

*Loop at the PI Sheet found for the order and prepare status report
           LOOP AT i_sheet_header.
*Get status of the PI Sheet
             PERFORM get_pi_status.
*Populate i_Report with PI Sheet data
             PERFORM populate_pi_data.

             l_node_text = i_sheet_header-crid.
*Display PI Sheet items for the order
             l_node_image = c_x.
             l_layout_node-n_image = c_j4. "Icon HTM
            PERFORM add_a_node USING  i_report l_connid_key l_node_text
                                      l_node_image l_carrier_image
                                 CHANGING l_last_key.

*Prepare lookup table
             l_itemno = l_itemno + 1.
             PERFORM prepare_lookup_table USING l_itemno c_pi
                                                i_sheet_header-crid.

           ENDLOOP.
           CLEAR l_layout_node.
         ENDIF.

*Get Messages for the order and display the required mesage info in the
*status report.
         PERFORM get_message_data.

         IF i_comh[] IS INITIAL.
*Make child folder for PI Sheets if no data found for the order
           PERFORM display_folder USING i_report
                                        l_month_key
                                        text-038
                                         space
                                CHANGING l_connid_key.

*Prepare lookup table
           l_itemno = l_itemno + 1.
           PERFORM prepare_lookup_table USING l_itemno c_mesg space.

         ELSE.

           CLEAR i_report.
           i_report-summ = v_exe.
           CLEAR v_exe.
           DESCRIBE TABLE i_comh LINES l_count.
           i_report-count = l_count.
           l_node_text = text-038.
*Make child folder for Message if no data found
           PERFORM add_a_node USING i_report l_month_key l_node_text
                                    space l_carrier_image
                              CHANGING l_connid_key.

*Prepare lookup table
           l_itemno = l_itemno + 1.
           PERFORM prepare_lookup_table USING l_itemno c_mesg space.

*Loop at message table for the order and prepare status report
           LOOP AT i_comh.

             PERFORM populate_mesg_data.

             l_node_text = i_comh-msid.
*Display Message item details for the order
             l_node_image = c_x.
             l_layout_node-n_image = c_kb. "Icon Transfer
            PERFORM add_a_node USING  i_report l_connid_key l_node_text
                                      l_node_image l_carrier_image
                                 CHANGING l_last_key.

*Prepare lookup table
             l_itemno = l_itemno + 1.
             PERFORM prepare_lookup_table USING l_itemno c_mesg
                                                i_comh-msid.

           ENDLOOP.
         ENDIF.
       ENDIF.
     ENDLOOP.
     CLEAR l_layout_node.
   ENDIF.

 ENDFORM.                               " create_hierarchy

**&---------------------------------------------------------------------
*
**&      Form  build_hierarchy_header
**&---------------------------------------------------------------------
**       build hierarchy-header-information
**----------------------------------------------------------------------
**      -->P_L_HIERARCHY_HEADER  strucxture for hierarchy-header
**----------------------------------------------------------------------

 FORM build_hierarchy_header CHANGING
                                p_hierarchy_header TYPE treev_hhdr.

   p_hierarchy_header-heading = text-039.
   p_hierarchy_header-tooltip = text-040.
   p_hierarchy_header-width = 42.
   p_hierarchy_header-width_pix = c_x.

 ENDFORM.                               " build_hierarchy_header
**&---------------------------------------------------------------------
*
**&      Form  register_events.
**&---------------------------------------------------------------------
** Registers events
**----------------------------------------------------------------------
 FORM register_events.
* Event registration: tell ALV Tree which events shall be passed
* from frontend to backend.
   DATA: lt_events TYPE cntl_simple_events,
         l_event TYPE cntl_simple_event.
   DATA: l_event_receiver TYPE REF TO lcl_tree_event_receiver.

* The following four tree events registers ALV Tree in the constructor
* method itself.
*    - cl_gui_column_tree=>eventid_expand_no_children
* (needed to load data to frontend when a user expands a node)
*    - cl_gui_column_tree=>eventid_header_context_men_req
* (needed for header context menu)
*    - cl_gui_column_tree=>eventid_header_click
* (allows selection of columns (only when item selection activated))
*   - cl_gui_column_tree=>eventid_item_keypress
* (needed for F1-Help (only when item selection activated))
*
* Nevertheless you have to provide their IDs again if you register
* additional events with SET_REGISTERED_EVENTS (see below).
* To do so, call first method  GET_REGISTERED_EVENTS (this way,
* all already registered events remain registered, even your own):
   CALL METHOD v_alv_tree->get_registered_events
     IMPORTING
       events = lt_events.

* (If you do not these events will be deregistered!!!).
* You do not have to register events of the toolbar again.

* define the events which will be passed to the backend
* node double click
   l_event-eventid = cl_gui_column_tree=>eventid_node_double_click.
   l_event-appl_event = c_x. " process PAI if event occurs
   APPEND l_event TO lt_events.

*item double click
   l_event-eventid = cl_gui_column_tree=>eventid_item_double_click.
   l_event-appl_event = c_x.
   APPEND l_event TO lt_events.

**expand no children
*  l_event-eventid = CL_GUI_COLUMN_TREE=>EVENTID_EXPAND_NO_CHILDREN.
*  l_event-appl_event = 'X'.
*  append l_event to lt_events.
*
**link click
*  l_event-eventid = CL_GUI_COLUMN_TREE=>EVENTID_LINK_CLICK.
*  l_event-appl_event = 'X'.
*  append l_event to lt_events.
*
** button click
*  l_event-eventid = CL_GUI_COLUMN_TREE=>EVENTID_button_click.
*  l_event-appl_event = 'X'.
*  append l_event to lt_events.

*checkbox change
   l_event-appl_event = c_x.
   l_event-eventid = cl_gui_column_tree=>eventid_checkbox_change.
   APPEND l_event TO lt_events.

* register events on frontend
   CALL METHOD v_alv_tree->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 text-058.  "'ERROR'.          "#EC NOTEXT
   ENDIF.

* set Handler
   CREATE OBJECT l_event_receiver.
   SET HANDLER l_event_receiver->handle_node_double_click
                                                      FOR v_alv_tree.
   SET HANDLER l_event_receiver->handle_item_double_click
                                                    FOR v_alv_tree.
   SET HANDLER l_event_receiver->handle_checkbox_change
                                                      FOR v_alv_tree.

 ENDFORM.                               " register_events
*&---------------------------------------------------------------------*
*&      Form  GET_ORDER_DATA
*&---------------------------------------------------------------------*
* Select order related data from table AUFK and AFKO based on the
* selection parameter/
*----------------------------------------------------------------------*
 FORM get_order_data .
   REFRESH i_afko.
*Retreieve Data from AFKO and AUFK
   SELECT a~aufnr
          b~auart
          a~aufpl
          a~aplzt
          b~werks
          a~rsnum
          b~objnr
          b~erdat
          b~aedat
          b~erfzeit
          a~plnbez
   INTO CORRESPONDING FIELDS OF TABLE i_afko
   FROM afko AS a INNER JOIN aufk AS b
     ON a~aufnr = b~aufnr
   WHERE b~werks IN s_werks
    AND b~auart IN s_auart
    AND a~aufnr IN s_aufnr "process order
    AND a~fevor IN s_fevor
    AND a~plnbez IN s_plnbez
    AND a~gstrp IN s_gstrp
    AND a~gltrp IN s_gltrp.

   IF sy-subrc <> 0.
*  Issue error message and stop processing
     MESSAGE i000 WITH text-061.    "'No data selected'.
     LEAVE LIST-PROCESSING.
   ELSE.
*   Sort the table I_afko
     SORT i_afko BY plnbez.
   ENDIF.

 ENDFORM.                    " GET_ORDER_DATA

*&---------------------------------------------------------------------*
*&      Form  validate_plant
*&---------------------------------------------------------------------*
*Validate Plant
*----------------------------------------------------------------------*
 FORM validate_plant .

   IF NOT s_werks[] IS INITIAL.
     SELECT werks            " Plant
     INTO TABLE i_werks
     FROM t001w
     WHERE werks IN s_werks.
     IF sy-subrc <> 0.
*Issue error message and stop processing
       MESSAGE e000 WITH text-041.
     ENDIF.
   ENDIF.

 ENDFORM.                    " validate_plant
*&---------------------------------------------------------------------*
*&      Form  validate_order_type
*&---------------------------------------------------------------------*
* Validation of Ordre Type
*----------------------------------------------------------------------*
 FORM validate_order_type .

   IF NOT s_auart[] IS INITIAL.
     SELECT auart            " Order Type
     INTO t003o-auart
     UP TO 1 ROWS
     FROM t003o
     WHERE auart IN s_auart.
     ENDSELECT.
     IF sy-subrc <> 0.
*Issue error message and stop processing
       MESSAGE e000 WITH text-042.
     ENDIF.
   ENDIF.

 ENDFORM.                    " validate_order_type
*&---------------------------------------------------------------------*
*&      Form  validate_order
*&---------------------------------------------------------------------*
* Validation of Process Order
*----------------------------------------------------------------------*
 FORM validate_order .

   IF NOT s_aufnr IS INITIAL.
     SELECT SINGLE * FROM aufk
     WHERE aufnr IN s_aufnr.

     IF sy-subrc <> 0.
       MESSAGE e000 WITH text-043.
     ENDIF.
   ENDIF.

 ENDFORM.                    " validate_order
*&---------------------------------------------------------------------*
*&      Form  validate_Prod_scheduler
*&---------------------------------------------------------------------*
* Validation of Production Scheduller
*----------------------------------------------------------------------*
 FORM validate_prod_scheduler .

   IF NOT s_fevor[] IS INITIAL.
     SELECT fevor            " Production Scheduler
     INTO t024f-fevor
     UP TO 1 ROWS
     FROM t024f
     WHERE fevor IN s_fevor.
     ENDSELECT.
     IF sy-subrc <> 0.
*Issue error message and stop processing
       MESSAGE e000 WITH text-044.
     ENDIF.
   ENDIF.

 ENDFORM.                    " validate_Prod_scheduler
*&---------------------------------------------------------------------*
*&      Form  validate_material
*&---------------------------------------------------------------------*
* Validation of Material entered
*----------------------------------------------------------------------*
 FORM validate_material .

   IF NOT s_plnbez IS INITIAL.
     SELECT SINGLE * FROM mara
     WHERE matnr IN s_plnbez.

     IF sy-subrc <> 0.
       MESSAGE e000 WITH text-045.
     ENDIF.
   ENDIF.

 ENDFORM.                    " validate_material
*&---------------------------------------------------------------------*
*&      Form  validate_material_type
*&---------------------------------------------------------------------*
*Validation of material type entered in the selection screen
*----------------------------------------------------------------------*
 FORM validate_material_type .

   IF NOT s_mtart[] IS INITIAL.
     SELECT mtart            " Material Type
     INTO t134-mtart
     UP TO 1 ROWS
     FROM t134
     WHERE mtart IN s_mtart.
     ENDSELECT.
     IF sy-subrc <> 0.
*Issue error message and stop processing
       MESSAGE e000 WITH text-046.
     ENDIF.
   ENDIF.

 ENDFORM.                    " validate_material_type
*&---------------------------------------------------------------------*
*&      Form  validate_Resource
*&---------------------------------------------------------------------*
*  Validation of Resource
*----------------------------------------------------------------------*
 FORM validate_resource .

   IF NOT s_ress IS INITIAL.
     SELECT SINGLE * FROM crhd
     INTO crhd
     WHERE arbpl IN s_ress.

     IF sy-subrc <> 0.
       MESSAGE e000 WITH text-047.
     ENDIF.
   ENDIF.

 ENDFORM.                    " validate_Resource
*&---------------------------------------------------------------------*
*&      Form  validate_Cntrl_Recp_Dest
*&---------------------------------------------------------------------*
* Validation of control recipe destination
*----------------------------------------------------------------------*
 FORM validate_cntrl_recp_dest .

   IF NOT s_phseq[] IS INITIAL.
     SELECT phseq            " Control Receipe Dest.
     INTO tc52-phseq
     UP TO 1 ROWS
     FROM tc52
     WHERE phseq IN s_phseq.
     ENDSELECT.
     IF sy-subrc <> 0.
*Issue error message and stop processing
       MESSAGE e000 WITH text-048.
     ENDIF.
   ENDIF.

 ENDFORM.                    " validate_Cntrl_Recp_Dest
*&---------------------------------------------------------------------*
*&      Form  add_a_node
*&---------------------------------------------------------------------*
* Add node
*----------------------------------------------------------------------*
*      -->P_i_report  text
*      -->P_L_MONTH_KEY  text
*      -->P_L_NODE_TEXT  text
*      -->P_SPACE  text
*      -->P_L_CARRIER_IMAGE  text
*      <--P_L_CONNID_KEY  text
*----------------------------------------------------------------------*
 FORM add_a_node USING  p_report TYPE struct_temp
                        p_relat_key TYPE lvc_nkey
                        p_node_text TYPE lvc_value
                        p_node_image TYPE tv_image
                        p_item_image TYPE tv_image
               CHANGING p_new_key.

   DATA: l_node_text TYPE lvc_value.

* set item-layout
   DATA: l_item_layout TYPE lvc_t_layi,
         l_item_layout_s TYPE lvc_s_layi.

   l_item_layout_s-fieldname = v_alv_tree->c_hierarchy_column_name.

   IF v_checkbox_check = c_x.
     l_item_layout_s-fieldname = c_box.
     l_item_layout_s-class   = cl_gui_column_tree=>item_class_checkbox.
     l_item_layout_s-editable = c_x.
     l_item_layout_s-togg_right = c_x.
   ELSE.
     l_item_layout_s-fieldname = c_box.
     l_item_layout_s-hidden = c_x.
   ENDIF.
   l_item_layout_s-t_image = p_node_image.
   APPEND l_item_layout_s TO l_item_layout.

   CALL METHOD v_alv_tree->add_node
     EXPORTING
       i_relat_node_key = p_relat_key
       i_relationship   = cl_gui_column_tree=>relat_last_child
       i_node_text      = p_node_text
       is_outtab_line   = p_report
       is_node_layout   = l_layout_node
       it_item_layout   = l_item_layout
     IMPORTING
       e_new_node_key   = p_new_key.

 ENDFORM.                    " add_a_node
*&---------------------------------------------------------------------*
*&      Form  GET_ITEM_AND_NODE_SELECT
*&---------------------------------------------------------------------*
* Get the Item/node selected in the hierarchy status report
*----------------------------------------------------------------------*
 FORM get_item_and_node_select .

   CALL METHOD v_alv_tree->get_selected_item
     IMPORTING
       e_selected_node = v_item_name
       e_fieldname     = v_node_key1.

   IF NOT v_item_name IS INITIAL.
     i_node_key = v_item_name.
   ELSE.
     CALL METHOD v_alv_tree->get_selected_nodes
       CHANGING
         ct_selected_nodes = v_node_key.
     LOOP AT v_node_key INTO i_node_key.

     ENDLOOP.
   ENDIF.

   IF NOT i_node_key IS INITIAL.
     v_key = i_node_key+7(4).
     IF v_key+0(1) = space.
       v_key = i_node_key+8(4).
     ENDIF.
   ENDIF.

 ENDFORM.                    " GET_ITEM_AND_NODE_SELECT
*&---------------------------------------------------------------------*
*&      Form  POPULATE_ORDER_DATA
*&---------------------------------------------------------------------*
*Populate Ordre data to the I_report table for display
*----------------------------------------------------------------------*
*      -->P_I_AFKO  text
*----------------------------------------------------------------------*
 FORM populate_order_data  USING    p_i_afko.

   CLEAR makt-maktx.
   SELECT SINGLE maktx FROM makt
   INTO makt-maktx
   WHERE
   matnr = i_afko-plnbez AND
   spras = sy-langu.

   i_report-material = i_afko-plnbez.
   i_report-description = makt-maktx.
   CONCATENATE i_afko-erdat+6(2) c_dot
               i_afko-erdat+4(2) c_dot
               i_afko-erdat+0(4) INTO i_report-creationdate.
   CONCATENATE i_afko-erfzeit+0(2) c_dot
               i_afko-erfzeit+2(2) c_dot
               i_afko-erfzeit+4(2) INTO i_report-creationtime.

   CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT'
     EXPORTING
       input  = i_report-material
     IMPORTING
       output = i_report-material.

 ENDFORM.                    " POPULATE_ORDER_DATA
*&---------------------------------------------------------------------*
*&      Form  POPULATE_CR_DATA
*&---------------------------------------------------------------------*
* Populate Control Recipe data to the I_report table for display
*----------------------------------------------------------------------*
 FORM populate_cr_data .

   CLEAR tcb04t-crstktx.
   SELECT SINGLE crstktx FROM tcb04t
             INTO tcb04t-crstktx
             WHERE
             crstat = i_crheader-crstat AND
             spras = sy-langu.

   CLEAR i_report.
   i_report-type = i_crheader-phseq.
   IF tcb04t-crstktx = c_terminated OR tcb04t-crstktx = c_discarded.
     i_report-exe = c_0a.
   ELSEIF tcb04t-crstktx = c_processed.
     i_report-exe = c_08.
   ELSE.
     i_report-exe = c_09.
   ENDIF.
   i_report-err = c_5f.
   i_report-status = tcb04t-crstktx.
   i_report-destination = i_crheader-adres.
   CONCATENATE i_crheader-andat+6(2) c_dot i_crheader-andat+4(2) c_dot
               i_crheader-andat+0(4) INTO i_report-creationdate.
   CONCATENATE i_crheader-anuzt+0(2) c_dot i_crheader-anuzt+2(2) c_dot
               i_crheader-anuzt+4(2) INTO i_report-creationtime.

 ENDFORM.                    " POPULATE_CR_DATA
*&---------------------------------------------------------------------*
*&      Form  POPULATE_PI_DATA
*&---------------------------------------------------------------------*
*Populate PI Sheet data to the I_report table for display
*----------------------------------------------------------------------*
 FORM populate_pi_data .

   CLEAR i_report.
   i_report-type = i_sheet_header-phseq.
   IF v_state = c_five.
     i_report-exe = c_08.
     i_report-status = c_completed.
   ELSEIF v_state = c_two.
     i_report-exe = c_09.
     i_report-status = c_inprocess.
   ELSEIF v_state = c_three.
     i_report-exe = c_09.
     i_report-status = c_new1.
   ELSEIF v_state = c_eight.
     i_report-exe = c_09.
     i_report-status = c_tobecompleted.
   ELSEIF v_state = c_four OR v_state = c_seven.
     i_report-exe = c_0a.
     i_report-status = c_cancelled.
   ELSEIF v_state = c_six.
     i_report-exe = c_0a.
     i_report-status = c_discarded.
   ENDIF.
   CLEAR v_state.
   i_report-err = c_5f.
   i_report-destination = i_sheet_header-adres.
  CONCATENATE i_sheet_header-andat+6(2) c_dot i_sheet_header-andat+4(2)
            c_dot i_sheet_header-andat+0(4) INTO i_report-creationdate.
   CONCATENATE i_crheader-anuzt+0(2) c_dot i_crheader-anuzt+2(2) c_dot
               i_crheader-anuzt+4(2) INTO i_report-creationtime.

 ENDFORM.                    " POPULATE_PI_DATA
*&---------------------------------------------------------------------*
*&      Form  POPULATE_MESG_DATA
*&---------------------------------------------------------------------*
* Populate Process Message data to the I_report table for display
*----------------------------------------------------------------------*
 FORM populate_mesg_data .

   CLEAR i_report.
   i_report-type = i_comh-mscla.
   IF i_comh-errkz = c_n.
     i_report-exe = c_08.
     i_report-status = c_sent.
   ELSEIF i_comh-errkz = c_t OR i_comh-errkz = space.
     i_report-exe = c_09.
     i_report-status = c_tobesent.
   ELSEIF i_comh-errkz = c_w.
     i_report-exe = c_08.
     i_report-status = c_sentwithwarning.
   ELSE."IF i_comh-errkz = c_E.
     i_report-exe = c_0a.
     i_report-status = c_terminated.
   ENDIF.
   i_report-destination = i_comh-source.
   CONCATENATE i_comh-sedat+6(2) c_dot i_comh-sedat+4(2)
             c_dot i_comh-sedat+0(4) INTO i_report-creationdate.
   CONCATENATE i_comh-seuzt+0(2) c_dot i_comh-seuzt+2(2)
               c_dot i_comh-seuzt+4(2) INTO i_report-creationtime.

 ENDFORM.                    " POPULATE_MESG_DATA
*&---------------------------------------------------------------------*
*&      Form  GET_CR_DATA
*&---------------------------------------------------------------------*
* Get all Control Recipe data for the Process Order
*----------------------------------------------------------------------*
 FORM get_cr_data .

   CALL FUNCTION 'COCB_CONTROL_RECIPE_GET_LIST'
  EXPORTING
*      PLANT                         =
*      CONTROL_RECIPE                =
    process_order                 = i_afko-aufnr
*      ADDRESS                       = ' '
*      DESTINATION                   =
*      DEST_TYPE                     =
*      TEST_CNTL_REC                 = 'X'
*      PROD_CNTL_REC                 = 'X'
*      STATUS                        =
*      DATE_FROM                     =
*      DATE_TO                       = SY-DATLO
*      TIME_FROM                     =
*      MATERIAL                      =
*      BATCH                         =
*      INSPECTION_LOT                =
*      SCHED_DATE_FROM               =
*      SCHED_DATE_TO                 =
*      MAX_NO_OF_ENTRIES             =
*      NO_AUTHORITY_CHECK_REQ        = ' '
*    IMPORTING
*      NO_OF_SELECTED_ENTRIES        =
  TABLES
      cr_header                     = i_crheader
    EXCEPTIONS
      no_control_recipe_found       = 1
      no_authority                  = 2
      internal_failure              = 3
      OTHERS                        = 4
             .
   IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
*Message e000 with text-062 i_afko-aufnr.
   ENDIF.

   IF NOT s_phseq[] IS INITIAL.
     DELETE i_crheader WHERE NOT phseq IN s_phseq.
   ENDIF.
   CLEAR i_crheader.

   IF NOT c_create IS INITIAL OR NOT c_sentcr IS INITIAL OR
      NOT c_proces IS INITIAL OR NOT c_termin IS INITIAL OR
      NOT c_disccr IS INITIAL.

     IF c_create IS INITIAL.
       DELETE i_crheader WHERE crstat = c_one.
     ENDIF.

     IF c_sentcr IS INITIAL.
       DELETE i_crheader WHERE crstat = c_three.
     ENDIF.
     IF c_proces IS INITIAL.
       DELETE i_crheader WHERE crstat = c_five.
     ENDIF.
     IF c_termin IS INITIAL.
       DELETE i_crheader WHERE crstat = c_four.
     ENDIF.
     IF c_disccr IS INITIAL.
       DELETE i_crheader WHERE crstat = c_seven.
     ENDIF.
   ENDIF.

   LOOP AT i_crheader.
     IF i_crheader-crstat EQ c_five OR i_crheader-crstat EQ c_seven
        OR i_crheader-crstat EQ c_four.
       v_exe = c_5b.
     ELSE.
       v_exe = c_5d.
       EXIT.
     ENDIF.
   ENDLOOP.

 ENDFORM.                    " GET_CR_DATA
*&---------------------------------------------------------------------*
*&      Form  GET_PI_SHEET_DATA
*&---------------------------------------------------------------------*
*Get all PI Sheet data for the Process Order
*----------------------------------------------------------------------*
 FORM get_pi_sheet_data .

   CALL FUNCTION 'PI_SHEET_GET_LIST'
     EXPORTING
       process_order     = i_afko-aufnr
     TABLES
       pi_sheet_header   = i_sheet_header
       return_message    = i_return_message
     EXCEPTIONS
       no_pi_sheet_found = 1
       no_authority      = 2
       internal_failure  = 3.

   IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
*   message e000 with text-063 i_afko-aufnr.
   ENDIF.
   CLEAR i_sheet_header.

   IF NOT c_new IS INITIAL OR NOT c_inwork IS INITIAL OR
      NOT c_close IS INITIAL OR NOT c_canc IS INITIAL OR
      NOT c_disc IS INITIAL OR NOT c_comp IS INITIAL OR
      NOT c_arch IS INITIAL.

     IF c_new IS INITIAL.
       DELETE i_sheet_header WHERE crstat = c_three.
     ENDIF.
     IF c_inwork IS INITIAL.
       DELETE i_sheet_header WHERE crstat = c_two.
     ENDIF.
     IF c_close IS INITIAL.
       DELETE i_sheet_header WHERE crstat = c_eight.
     ENDIF.
     IF c_canc IS INITIAL.
       DELETE i_sheet_header WHERE crstat = c_four.
     ENDIF.
     IF c_disc IS INITIAL.
       DELETE i_sheet_header WHERE crstat = c_six.
     ENDIF.
     IF c_comp IS INITIAL.
       DELETE i_sheet_header WHERE crstat = c_five.
     ENDIF.
*     IF c_arch IS INITIAL.
*       DELETE i_sheet_header WHERE crstat = '00007'.
*     ENDIF.

   ENDIF.

   LOOP AT i_sheet_header.
     IF i_sheet_header-crstat EQ c_five OR
        i_sheet_header-crstat EQ c_seven OR
        i_sheet_header-crstat EQ c_four.
       v_exe = c_5b.
     ELSE.
       v_exe = c_5d.
       EXIT.
     ENDIF.
   ENDLOOP.

 ENDFORM.                    " GET_PI_SHEET_DATA
*&---------------------------------------------------------------------*
*&      Form  GET_MESSAGE_DATA
*&---------------------------------------------------------------------*
* Get all Process Messages for the Process Order
*----------------------------------------------------------------------*
 FORM get_message_data .

   SELECT * FROM comh INTO TABLE i_comh
   WHERE
   werk IN s_werks AND
   aufnr = i_afko-aufnr.

   IF NOT c_tosend IS INITIAL OR NOT c_sentpm IS INITIAL OR
      NOT c_end IS INITIAL.

     IF c_tosend IS INITIAL.
       DELETE i_comh WHERE errkz = space OR errkz = c_t.
     ENDIF.
     IF c_sentpm IS INITIAL.
       DELETE i_comh WHERE errkz = c_n.
     ENDIF.
     IF c_end IS INITIAL.
       DELETE i_comh WHERE errkz = c_d.
     ENDIF.
   ENDIF.

   READ TABLE i_comh WITH KEY errkz = c_d.
   IF sy-subrc = 0.
     v_exe = c_5c.                                          "' (0A)'.
   ELSE.
     READ TABLE i_comh WITH KEY errkz = space.
     IF sy-subrc = 0.
       v_exe = c_5d.                                        "' (09)'.
     ELSE.
       READ TABLE i_comh WITH KEY errkz = c_t.
       IF sy-subrc = 0.
         v_exe = c_5d.                                      "' (09)'.
       ELSE.
         READ TABLE i_comh WITH KEY errkz = c_e.
         IF sy-subrc = 0.
           v_exe = c_5c.                                    "' (0A)'.
         ELSE.
           READ TABLE i_comh WITH KEY errkz = c_w.
           IF sy-subrc = 0.
             v_exe = c_5d.                                  "' (0A)'.
           ELSE.
             v_exe = c_5b.                                  "' (08)'.
           ENDIF.
         ENDIF.
       ENDIF.
     ENDIF.
   ENDIF.

 ENDFORM.                    " GET_MESSAGE_DATA
*&---------------------------------------------------------------------*
*&      Form  display_folder
*&---------------------------------------------------------------------*
* Display a folder if there is no data to be inserted under the node
*----------------------------------------------------------------------*
*      -->P_i_report  text
*      -->P_L_MONTH_KEY  text
*      -->P_1606   text
*      -->P_1607   text
*      -->P_ELSE  text
*----------------------------------------------------------------------*
 FORM display_folder  USING    p_report TYPE struct_temp
                               p_relat_key TYPE lvc_nkey
                               p_node_text TYPE lvc_value
                               p_value TYPE c
                      CHANGING p_new_key.

   DATA: l_node_text TYPE lvc_value.
   DATA: l_layout_node TYPE lvc_s_layn.
* set item-layout
   DATA: l_item_layout TYPE lvc_t_layi,
         l_item_layout_s TYPE lvc_s_layi.

   CLEAR i_report.
   i_report-summ = c_bz.
   i_report-status = p_value.

   l_item_layout_s-fieldname = c_box.
   l_item_layout_s-hidden = c_x.
   APPEND l_item_layout_s TO l_item_layout.
   CLEAR l_item_layout_s.
   l_layout_node-isfolder = c_x.   "=>add a folder, NOT a leaf

   CALL METHOD v_alv_tree->add_node
     EXPORTING
       i_relat_node_key = p_relat_key
       i_relationship   = cl_gui_column_tree=>relat_last_child
       i_node_text      = p_node_text
       is_outtab_line   = p_report
       is_node_layout   = l_layout_node
       it_item_layout   = l_item_layout
     IMPORTING
       e_new_node_key   = p_new_key.

 ENDFORM.                    " display_folder
*&---------------------------------------------------------------------*
*&      Form  system_state_check
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      <--P_S_STATUS  text
*----------------------------------------------------------------------*
 FORM system_state_check
          CHANGING p_status TYPE j_txt04. "tj02t-txt04.

   DATA: l_status TYPE j_txt04,      "LIKE p_status,
         l_status_nr TYPE j_status.  "LIKE jest-stat.

   CHECK NOT p_status IS INITIAL.

   CALL FUNCTION 'STATUS_TEXT_CONVERSION'
     EXPORTING
       language           = sy-langu
       txt04              = p_status
     IMPORTING
       status_number      = l_status_nr
     EXCEPTIONS
       insufficient_input = 1
       not_found          = 2
       object_not_found   = 3
       wrong_mode         = 4
       OTHERS             = 5.
   IF sy-subrc <> 0.
*   ok, now we try with upper case
     l_status = p_status.
     TRANSLATE l_status TO UPPER CASE.                   "#EC TRANSLANG

     CALL FUNCTION 'STATUS_TEXT_CONVERSION'
       EXPORTING
         language           = sy-langu
         txt04              = l_status
       IMPORTING
         status_number      = l_status_nr
       EXCEPTIONS
         insufficient_input = 1
         not_found          = 2
         object_not_found   = 3
         wrong_mode         = 4
         OTHERS             = 5.

     IF sy-subrc = 0.
*     if uppercase is correct, then we use it from now on
       p_status    = l_status.
     ELSE.
       MESSAGE e000 WITH text-059. "'we expect a correct value here!'.
*      MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
*              WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
     ENDIF.
   ENDIF.

 ENDFORM.                    " system_state_check
*&---------------------------------------------------------------------*
*&      Form  fill_status_tables
*&---------------------------------------------------------------------*
* This subroutine fills the status tables
*----------------------------------------------------------------------*
 FORM fill_status_tables .

   LOOP AT i_status_table.
     PERFORM fill_status_table
               TABLES i_status_hdr_tab
               USING  i_status_table-status.
   ENDLOOP.

 ENDFORM.                    " fill_status_tables
*&---------------------------------------------------------------------*
*&      Form  fill_ranges
*&---------------------------------------------------------------------*
* This subroutines copies the Process order range table
*----------------------------------------------------------------------*
 FORM fill_ranges .

   aufnr_range[] = s_aufnr[].

 ENDFORM.                    " fill_ranges
*&---------------------------------------------------------------------*
*&      Form  check_s_selid
*&---------------------------------------------------------------------*
*  This subroutine validates the selection id
*----------------------------------------------------------------------*
 FORM check_s_selid .

   DATA:
     lts_objnr TYPE typ_ts_aufnr_objnr.

   FIELD-SYMBOLS:
     <ls_objnr> TYPE typ_s_objnr
     .
*  CHECK NOT p_selid          IS INITIAL
*  OR    NOT status_hdr_tab[] IS INITIAL.
   CHECK NOT i_status_hdr_tab[] IS INITIAL.
*  SELECT aufnr objnr FROM aufk
*         INTO CORRESPONDING FIELDS OF TABLE lts_objnr[]
*         FOR ALL ENTRIES IN aufnr_range[]
*         WHERE aufnr = aufnr_range-low.

   SELECT aufnr objnr FROM aufk
          INTO CORRESPONDING FIELDS OF TABLE lts_objnr[]
          WHERE aufnr IN aufnr_range[]
          AND autyp = 40. "Only Process orders required for this report

   PERFORM reduce_aufnr_objnr_by_status
           TABLES i_status_hdr_tab
*          USING  p_selid
           CHANGING lts_objnr[].

*Check whether order entered matches with status entered in the
*selection screen
   IF lts_objnr[] IS INITIAL.
     MESSAGE i000 WITH text-049.
     LEAVE LIST-PROCESSING.
   ENDIF.

* Auftragsnummern-Range löschen und neu füllen
   REFRESH aufnr_range[].
   aufnr_range-sign   = c_i.
   aufnr_range-option = c_eq.
   CLEAR aufnr_range-low.
   CLEAR aufnr_range-high.
   LOOP AT lts_objnr[] ASSIGNING <ls_objnr>.
     aufnr_range-low =  <ls_objnr>-aufnr.
     APPEND aufnr_range.
   ENDLOOP.
* no order found
   IF sy-subrc <> 0.
     APPEND aufnr_range.
   ENDIF.
* Speicherbereiche freigeben
   FREE: lts_objnr[].

 ENDFORM.                    " check_s_selid
*&---------------------------------------------------------------------*
*&      Form  update_s_aufnr
*&---------------------------------------------------------------------*
*  This subroutine updates the Process order range table
*----------------------------------------------------------------------*
 FORM update_s_aufnr .

   CLEAR s_aufnr.
   REFRESH s_aufnr.

   s_aufnr[]  = aufnr_range[].

 ENDFORM.                    " update_s_aufnr
*&---------------------------------------------------------------------*
*&      Form  fill_status_table
*&---------------------------------------------------------------------*
*  This subroutine populates the status table
*----------------------------------------------------------------------*
 FORM fill_status_table TABLES p_status_tab STRUCTURE i_status_hdr_tab
                        USING s_status  TYPE j_txt04. "LIKE tj02t-txt04.

   DATA l_status_tmp TYPE ty_status_tmp.   "LIKE status_hdr_tab.
* append status to imported status table
   CLEAR l_status_tmp.
* Status vom Selektionsbild
   IF NOT s_status IS INITIAL.
     CALL FUNCTION 'STATUS_TEXT_CONVERSION'
       EXPORTING
         language           = sy-langu
         txt04              = s_status
       IMPORTING
         status_number      = l_status_tmp-stat
       EXCEPTIONS
         insufficient_input = 1
         not_found          = 2
         object_not_found   = 3
         wrong_mode         = 4
         OTHERS             = 5.
     IF sy-subrc EQ 0.
       l_status_tmp-excl = c_x.
       COLLECT l_status_tmp INTO p_status_tab.
     ENDIF.
   ENDIF.

 ENDFORM.                    " fill_status_table
*&---------------------------------------------------------------------*
*&      Form  ORDER_STATUS_TABLE
*&---------------------------------------------------------------------*
*  This subroutine populates the order status table
*----------------------------------------------------------------------*
 FORM order_status_table .

   IF NOT s_status[] IS INITIAL.
     IF s_status-high IS INITIAL.
       LOOP AT s_status.
         i_status_table-status = s_status-low.
         APPEND i_status_table.
         CLEAR i_status_table.
       ENDLOOP.
     ELSE.
       SELECT txt04 FROM tj02t
       INTO TABLE i_status_table
       WHERE
       spras = sy-langu AND
       txt04 IN s_status.
     ENDIF.
   ENDIF.

 ENDFORM.                    " ORDER_STATUS_TABLE
*&---------------------------------------------------------------------*
*&      Form  reduce_aufnr_objnr_by_status
*&---------------------------------------------------------------------*
*  This subroutine updates the status
*----------------------------------------------------------------------*
 FORM reduce_aufnr_objnr_by_status
      TABLES   p_status_tab STRUCTURE i_status_hdr_tab
*     USING    selid      LIKE p_selid
      CHANGING l_cts_objnr  TYPE typ_ts_objnr.

* Statusobjekte
   DATA:
     l_objnr_tab TYPE STANDARD TABLE OF jsto_pre
     INITIAL SIZE 0 WITH HEADER LINE.
   "LIKE jsto_pre OCCURS 0 WITH HEADER LINE.

   FIELD-SYMBOLS:
     <ls_objnr> TYPE typ_s_objnr.

*  CHECK NOT selid        IS INITIAL
*  OR    NOT status_tab[] IS INITIAL.
   CHECK NOT p_status_tab[] IS INITIAL.
* preread
   LOOP AT l_cts_objnr[] ASSIGNING <ls_objnr>.
     l_objnr_tab-objnr = <ls_objnr>-objnr.
     APPEND l_objnr_tab.
   ENDLOOP.
   CALL FUNCTION 'STATUS_PRE_READ'
     TABLES
       jsto_pre_tab = l_objnr_tab.

   DATA objects_deleted.
   PERFORM reduce_objnr_by_status
           TABLES   l_objnr_tab
                    p_status_tab
*          USING    selid
           CHANGING objects_deleted.

   IF objects_deleted = c_x.
* Alle Aufträge entfernen, deren OBJNR nicht mehr in der Tabelle
* OBJNR_TAB enthalten ist.
     IF l_objnr_tab[] IS INITIAL.
       REFRESH l_cts_objnr[].
     ELSE.
       SORT l_objnr_tab BY objnr.
       LOOP AT l_cts_objnr[] ASSIGNING <ls_objnr>.
         READ TABLE l_objnr_tab
              WITH KEY objnr = <ls_objnr>-objnr
              BINARY SEARCH.
         IF sy-subrc <> 0.
           DELETE l_cts_objnr[].
         ENDIF.
       ENDLOOP.
     ENDIF.
   ENDIF.

 ENDFORM.                    " reduce_aufnr_objnr_by_status
*&---------------------------------------------------------------------*
*&      Form  reduce_objnr_by_status
*&---------------------------------------------------------------------*
*  This subroutine updates the status
*----------------------------------------------------------------------*
 FORM reduce_objnr_by_status
      TABLES   p_objnr_tab  STRUCTURE objnr_tab
               p_status_tab STRUCTURE i_status_hdr_tab
*     USING    selid      LIKE p_selid
      CHANGING p_objects_deleted.
   DATA l_objnr_cnt TYPE sydbcnt.      "LIKE sy-dbcnt.
   DATA l_dbcnt TYPE sydbcnt.

   CLEAR p_objects_deleted.
   CHECK NOT p_objnr_tab[]  IS INITIAL.
   DESCRIBE TABLE p_objnr_tab LINES l_objnr_cnt.
* Statusprüfung gegen Status in Statustabelle
   LOOP AT p_status_tab.
     IF p_objnr_tab[] IS INITIAL.
       EXIT.
     ELSE.
* Alle Objektnummern, bei denen der geforderte Status (nicht) sitzt,
* werden aus der Tabelle OBJNR_TAB gelöscht.
       CALL FUNCTION 'STATUS_CHECK_MULTI'
         EXPORTING
           status      = p_status_tab-stat
           flg_exclude = p_status_tab-excl
         TABLES
           OBJECTS     = p_objnr_tab.
     ENDIF.
   ENDLOOP.
* Statusprüfung gegen das Selektionsschema
*  IF NOT selid IS INITIAL.
*   LOOP AT objnr_tab.
*     DATA flg_status_ok TYPE c.       "Statusprüfung OK
*     CALL FUNCTION 'STATUS_CHECK_BY_SELSCHEM'
*       EXPORTING
*         objnr          = objnr_tab-objnr
*         selid          = ' '"selid
*       IMPORTING
*         fullfill       = flg_status_ok
*       EXCEPTIONS
*         no_stat_scheme = 01
*         no_stat_tab    = 02.
*     IF  sy-subrc      IS INITIAL
*     AND flg_status_ok IS INITIAL.
*       DELETE objnr_tab.
*     ENDIF.
*   ENDLOOP.
*  ENDIF.

   DESCRIBE TABLE p_objnr_tab LINES l_dbcnt. "sy-dbcnt.
   IF l_dbcnt <> l_objnr_cnt.
     p_objects_deleted = c_x.
   ENDIF.

 ENDFORM.                    " reduce_objnr_by_status
*&---------------------------------------------------------------------*
*&      Form  check_mattype_resourc_CRdest
*&---------------------------------------------------------------------*
* Check the material type and Resource destination for the selected
* order records.
*----------------------------------------------------------------------*
 FORM check_mattype_resourc_crdest.

   CLEAR v_check.

*Check for material type with the value entered in the selection screen
   SELECT SINGLE mtart
   FROM mara INTO mara-mtart
   WHERE
   matnr = i_afko-plnbez.
   IF NOT mara-mtart IN s_mtart.
     v_check = c_x.
   ENDIF.

*Check for control recipe destination with the selection screen value
   IF v_check IS INITIAL.
     CLEAR i_afvc.
     READ TABLE i_afvc WITH KEY aufpl = i_afko-aufpl BINARY SEARCH.
     IF sy-subrc <> 0. " Reading is not successful
       v_check = c_x.
     ENDIF.

   ENDIF.

 ENDFORM.                    " check_mattype_resourc_CRdest
*&---------------------------------------------------------------------*
*&      Form  populate_afvc
*&---------------------------------------------------------------------*
*Get Operation within an order data from table AFVC
*----------------------------------------------------------------------*
 FORM populate_afvc .

   SELECT a~aufpl
          a~arbid
          a~phseq
          b~arbpl
   INTO TABLE i_afvc
   FROM afvc AS a INNER JOIN crhd AS b
   ON a~arbid = b~objid
   WHERE  a~phseq IN s_phseq
      AND b~arbpl IN s_ress
      AND a~phflg = c_x.
   IF sy-subrc = 0.
*     Sort the table I_afvc
     SORT i_afvc BY aufpl.
   ENDIF.

 ENDFORM.                    " populate_afvc
*&---------------------------------------------------------------------*
*&      Form  populate_selected_data_table
*&---------------------------------------------------------------------*
*  Populate all tables required for COntrol Recipe Discard/Complete
*----------------------------------------------------------------------*
 FORM populate_selected_data_table .

   v_proc_mess_id_tmp = v_proc_mess_id_tmp + 1.

   i_procmessheader-proc_mess_id_tmp = v_proc_mess_id_tmp.
   i_procmessheader-plant = i_lookup-plant.
   i_procmessheader-proc_mess_category = c_pi_crst.
   i_procmessheader-test_flag = space.
   i_procmessheader-sender_name = i_lookup-sender.
   APPEND i_procmessheader.
   CLEAR i_procmessheader.

   i_procmesscharac-proc_mess_id_tmp = v_proc_mess_id_tmp.
   i_procmesscharac-name_char = c_pppi_process_order.
   i_procmesscharac-char_value = i_lookup-order.
   i_procmesscharac-data_type = c_char.
   APPEND i_procmesscharac.
   CLEAR i_procmesscharac.

   i_procmesscharac-proc_mess_id_tmp = v_proc_mess_id_tmp.
   i_procmesscharac-name_char = c_pppi_control_recipe.
   i_procmesscharac-char_value = i_lookup-docno.
   i_procmesscharac-data_type = c_char.
   APPEND i_procmesscharac.
   CLEAR i_procmesscharac.

   i_procmesscharac-proc_mess_id_tmp = v_proc_mess_id_tmp.
   i_procmesscharac-name_char = c_pppi_control_recipe_status.
   IF sy-ucomm = c_complete.
     i_procmesscharac-char_value = c_00005.
   ELSE.
     i_procmesscharac-char_value = c_00007.
   ENDIF.
   i_procmesscharac-data_type = c_char.
   APPEND i_procmesscharac.
   CLEAR i_procmesscharac.

   i_procmesscharac-proc_mess_id_tmp = v_proc_mess_id_tmp.
   i_procmesscharac-name_char = c_pppi_event_date.
   i_procmesscharac-char_value = sy-datum.
   i_procmesscharac-data_type = c_date.
   APPEND i_procmesscharac.
   CLEAR i_procmesscharac.

   i_procmesscharac-proc_mess_id_tmp = v_proc_mess_id_tmp.
   i_procmesscharac-name_char = c_pppi_event_time.
   i_procmesscharac-char_value = sy-uzeit.
   i_procmesscharac-data_type = c_time.
   APPEND i_procmesscharac.
   CLEAR i_procmesscharac.

*Processing for the external CRD type

   SELECT SINGLE *
       FROM coch                      "control recipe table
       WHERE crid = i_lookup-docno.

   IF sy-subrc = 0.

* Lookup process message categories for CRD using convention Y_ST_<CRD>

     IF coch-cotyp = c_2.               "external CRD type

       v_crd+5(2) = coch-phseq.

       SELECT SINGLE *                  "existence check
           FROM tc50                    "proc mess categories table
           WHERE werks = coch-werk
           AND cstyp = c_ms
           AND costr = v_crd.

       IF sy-subrc = 0.

*   Create process message for external CRD if process message category
*         exists

         v_proc_mess_id_tmp = v_proc_mess_id_tmp + 1.

         i_procmessheader-proc_mess_id_tmp = v_proc_mess_id_tmp.
         i_procmessheader-plant = i_lookup-plant.
         i_procmessheader-proc_mess_category = v_crd.
         i_procmessheader-test_flag = space.
         i_procmessheader-sender_name = i_lookup-sender.
         APPEND i_procmessheader.
         CLEAR i_procmessheader.

         i_procmesscharac-proc_mess_id_tmp = v_proc_mess_id_tmp.
         i_procmesscharac-name_char = c_pppi_process_order.
         i_procmesscharac-char_value = i_lookup-order.
         i_procmesscharac-data_type = c_char.
         APPEND i_procmesscharac.
         CLEAR i_procmesscharac.

         i_procmesscharac-proc_mess_id_tmp = v_proc_mess_id_tmp.
         i_procmesscharac-name_char = c_pppi_control_recipe.
         i_procmesscharac-char_value = i_lookup-docno.
         i_procmesscharac-data_type = c_char.
         APPEND i_procmesscharac.
         CLEAR i_procmesscharac.

         i_procmesscharac-proc_mess_id_tmp = v_proc_mess_id_tmp.
         i_procmesscharac-name_char = c_pppi_control_recipe_status.
         IF sy-ucomm = c_complete.
           i_procmesscharac-char_value = c_00005.
         ELSE.
           i_procmesscharac-char_value = c_00007.
         ENDIF.
         i_procmesscharac-data_type = c_char.
         APPEND i_procmesscharac.
         CLEAR i_procmesscharac.

         i_procmesscharac-proc_mess_id_tmp = v_proc_mess_id_tmp.
         i_procmesscharac-name_char = c_pppi_event_date.
         i_procmesscharac-char_value = sy-datum.
         i_procmesscharac-data_type = c_date.
         APPEND i_procmesscharac.
         CLEAR i_procmesscharac.

         i_procmesscharac-proc_mess_id_tmp = v_proc_mess_id_tmp.
         i_procmesscharac-name_char = c_pppi_event_time.
         i_procmesscharac-char_value = sy-uzeit.
         i_procmesscharac-data_type = c_time.
         APPEND i_procmesscharac.
         CLEAR i_procmesscharac.
       ENDIF.
     ENDIF.
   ENDIF.

 ENDFORM.                    " populate_selected_data_table
*&---------------------------------------------------------------------*
*&      Form  discard_control_recipe
*&---------------------------------------------------------------------*
* Discard Control recipe and prepare errorlog table
*----------------------------------------------------------------------*
 FORM discard_control_recipe .

   DATA: i_count TYPE lvc_nkey.

   CALL FUNCTION 'BAPI_PROCESS_MESSAGE_CREATEMLT'
     TABLES
       procmessheader       = i_procmessheader
       procmesscharac       = i_procmesscharac
       procmesstextlines    = i_procmesstextlines
       processmessagenew    = i_processmessagenew
       procmessheaderreturn = i_procmessheaderreturn
       procmesscharacreturn = i_procmesscharacreturn
       return               = i_return.

*Building eror log table
   LOOP AT i_procmessheaderreturn WHERE return_code <> 00.
     IF i_procmessheaderreturn-return_code = 99.
       LOOP AT i_procmesscharacreturn WHERE
           proc_mess_id_tmp = i_procmessheaderreturn-proc_mess_id_tmp
           AND return_code <> 00.
         READ TABLE i_procmesscharac WITH KEY
             proc_mess_id_tmp = i_procmesscharacreturn-proc_mess_id_tmp
             name_char = c_pppi_control_recipe.
         IF sy-subrc = 0.
*Build table for where Err flag needs to be set
           READ TABLE i_lookup WITH KEY
                      docno = i_procmesscharac-char_value
                      doctype = c_cr.
           IF sy-subrc = 0.
             i_count = i_count + i_lookup-itemno.
             APPEND i_count TO i_nodekey_change.
             CLEAR i_count.
           ENDIF.
*Build errorlog table
           i_errorlog-docno = i_procmesscharac-char_value.
           i_errorlog-message = i_procmesscharacreturn-message.
           APPEND i_errorlog.
           CLEAR i_errorlog.
         ENDIF.
       ENDLOOP.
     ELSE.

     ENDIF.
   ENDLOOP.

   LOOP AT i_return WHERE type = c_e OR type = c_a.
     READ TABLE i_procmesscharac WITH KEY
         name_char = c_pppi_control_recipe.
     i_errorlog-docno = i_procmesscharac-char_value.
     i_errorlog-message = i_return-message.
     APPEND i_errorlog.
     CLEAR i_errorlog.
*Build table for where Err flag needs to be set
     READ TABLE i_lookup WITH KEY
                docno = i_procmesscharac-char_value
                doctype = c_cr.
     IF sy-subrc = 0.
       i_count = i_count + i_lookup-itemno.
       APPEND i_count TO i_nodekey_change.
       CLEAR i_count.
     ENDIF.
   ENDLOOP.

   REFRESH i_procmessheader.
   REFRESH i_procmesscharac.
   REFRESH i_procmesstextlines.
*   REFRESH i_processmessagenew.
   REFRESH i_procmessheaderreturn.
   REFRESH i_procmesscharacreturn.
   REFRESH i_return.

 ENDFORM.                    " discard_control_recipe
*&---------------------------------------------------------------------*
*&      Form  discard_pi_sheet
*&---------------------------------------------------------------------*
*  Discard PI sheet and prepare errorlog table
*----------------------------------------------------------------------*
 FORM discard_pi_sheet .

   DATA : l_not_discarded_count TYPE i,
          i_count TYPE lvc_nkey,
          l_discarded_count TYPE i.
*Discard PI sheet
   CALL FUNCTION 'PI_SHEET_DISCARD'
     EXPORTING
       dialog_flag         = c_x
     IMPORTING
       discarded_count     = l_discarded_count
       not_discarded_count = l_not_discarded_count
     TABLES
       cntrl_recipe_id_tab = i_discard_pi.

*Build errorlog table
   IF NOT l_not_discarded_count IS INITIAL.
     LOOP AT i_discard_pi.
       i_errorlog-docno = i_discard_pi-cntl_rec_id.
       i_errorlog-message = text-065.
       "'Unable to discard or cancel PI Sheet'.
       APPEND i_errorlog.
       CLEAR i_errorlog.
*Set Error flag to the Control Recipe
       READ TABLE i_lookup WITH KEY
                  docno = i_discard_pi-cntl_rec_id
                  doctype = c_cr.
       IF sy-subrc = 0.
         i_count = i_count + i_lookup-itemno.
         APPEND i_count TO i_nodekey_change.
         CLEAR i_count.
       ENDIF.
*Set Error flag to PI Sheet for the corresponding Control Recipe
       READ TABLE i_lookup WITH KEY
                  docno = i_discard_pi-cntl_rec_id
                  doctype = c_pi.
       IF sy-subrc = 0.
         i_count = i_count + i_lookup-itemno.
         APPEND i_count TO i_nodekey_change.
         CLEAR i_count.
       ENDIF.
     ENDLOOP.
   ENDIF.

   CLEAR: l_discarded_count.
   CLEAR:l_not_discarded_count.
   REFRESH i_discard_pi.

 ENDFORM.                    " discard_pi_sheet
*&---------------------------------------------------------------------*
*&      Form  BAPI_TRANSACTION_COMMIT
*&---------------------------------------------------------------------*
* BAPI Commit
*----------------------------------------------------------------------*
 FORM bapi_transaction_commit .

   CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
*     EXPORTING
*       WAIT          =
     IMPORTING
       return        = i_return.

 ENDFORM.                    " BAPI_TRANSACTION_COMMIT
*&---------------------------------------------------------------------*
*&      Form  ALL_HEADER_NODE_EXPAND
*&---------------------------------------------------------------------*
* Expand all selected nodes
*----------------------------------------------------------------------*
 FORM all_header_node_expand .

   DATA: l_lvc_nkey TYPE lvc_nkey.
   DATA: l_first_node TYPE lvc_nkey.

   LOOP AT i_lookup WHERE doctype = c_ord.
     l_lvc_nkey = l_lvc_nkey + i_lookup-itemno.
     APPEND l_lvc_nkey TO i_lvc_nkey.
     CLEAR l_lvc_nkey.
   ENDLOOP.

   CALL METHOD v_alv_tree->expand_nodes
     EXPORTING
       it_node_key = i_lvc_nkey.
   REFRESH i_lvc_nkey.

   l_first_node = l_first_node + 1.
   CALL METHOD v_alv_tree->set_top_node
     EXPORTING
       i_node_key = l_first_node.
   CLEAR l_first_node.

 ENDFORM.                    " ALL_HEADER_NODE_EXPAND
*&---------------------------------------------------------------------*
*&      Form  DISPLAY_LOG
*&---------------------------------------------------------------------*
*  Prepare and display log table
*----------------------------------------------------------------------*
 FORM display_log .

   DATA: lv_tfill       TYPE i,
         ls_field       TYPE help_value,   "LIKE help_value,
         lt_fields      TYPE STANDARD TABLE OF help_value
                        INITIAL SIZE 0 WITH HEADER LINE,
         lv_index       TYPE sytabix.      "LIKE sy-tabix.

   IF i_errorlog[] IS INITIAL.
     EXIT.
   ENDIF.

   ls_field-tabname    =  'COCH'.
   ls_field-fieldname  =  'CRID'.
   ls_field-selectflag =  'X'.
   APPEND ls_field TO lt_fields.

   ls_field-tabname    =  'PMCHECK'.
   ls_field-fieldname  =  'ERROR_TEXT'.
   ls_field-selectflag =  'X'.
   APPEND ls_field TO lt_fields.

*Display ErrorLog table
   SORT i_errorlog BY docno.
   CALL FUNCTION 'MD_POPUP_SHOW_INTERNAL_TABLE'
     EXPORTING
       title   = text-060
     IMPORTING
       index =
          lv_index "'The following control recipes could not be updated'
     TABLES
       values    = i_errorlog
       columns   = lt_fields
     EXCEPTIONS
       leave     = 1
       OTHERS    = 2.

   IF sy-subrc <> 0.
*     FREE i_errorlog.
*     EXIT.
   ENDIF.

 ENDFORM.                    " DISPLAY_LOG
*&---------------------------------------------------------------------*
*&      Form  CALL_TRANSACTION_COR3
*&---------------------------------------------------------------------*
* Set parameter ID and call transaction COR3
*----------------------------------------------------------------------*
 FORM call_transaction_cor3 .

   READ TABLE i_lookup WITH KEY itemno = v_key.
   IF sy-subrc = 0 AND i_lookup-doctype = c_ord.
     SET PARAMETER ID: c_br1 FIELD i_lookup-docno.
     CALL TRANSACTION c_cor3 AND SKIP FIRST SCREEN .
     CLEAR v_node_text.
     CLEAR i_node_key.
     CLEAR v_key.
   ELSE.
     MESSAGE i000 WITH text-034.
   ENDIF.

 ENDFORM.                    " CALL_TRANSACTION_COR3
*&---------------------------------------------------------------------*
*&      Form  CALL_TRANSACTION_COR2
*&---------------------------------------------------------------------*
*   Set parameter ID and call transaction COR2
*----------------------------------------------------------------------*
 FORM call_transaction_cor2 .

   READ TABLE i_lookup WITH KEY itemno = v_key.
   IF sy-subrc = 0 AND i_lookup-doctype = c_ord.
     SET PARAMETER ID: c_br1 FIELD i_lookup-docno.
     CALL TRANSACTION c_cor2 AND SKIP FIRST SCREEN .
     CLEAR v_node_text.
     CLEAR i_node_key.
     CLEAR v_key.

   ELSE.
     MESSAGE i000 WITH text-034.
   ENDIF.

 ENDFORM.                    " CALL_TRANSACTION_COR2
*&---------------------------------------------------------------------*
*&      Form  CALL_TRANSACTION_CO53
*&---------------------------------------------------------------------*
* Set parameter ID and call transaction CO53
*----------------------------------------------------------------------*
 FORM call_transaction_co53 .

   DATA : l_flg-no_init TYPE c.

   READ TABLE i_lookup WITH KEY itemno = v_key.
   IF sy-subrc = 0." AND i_lookup-doctype = c_CR.
     l_flg-no_init = c_x.
     rco53if-abdat = i_lookup-frdate.
     SET PARAMETER ID: 'WRK' FIELD i_lookup-plant.
     SET PARAMETER ID: 'ANR' FIELD i_lookup-order.
     SET PARAMETER ID: 'ABDAT' FIELD rco53if-abdat.
     SET PARAMETER ID 'NO_INIT' FIELD l_flg-no_init.
     CALL TRANSACTION c_co53 AND SKIP FIRST SCREEN .
     CLEAR rco54if-abdat.
     CLEAR l_flg-no_init.
   ELSE.
     MESSAGE i000 WITH text-033.
   ENDIF.

 ENDFORM.                    " CALL_TRANSACTION_CO53
*&---------------------------------------------------------------------*
*&      Form  CALL_TRANSACTION_CO54
*&---------------------------------------------------------------------*
* Set parameter ID and call transaction CO54
*----------------------------------------------------------------------*
 FORM call_transaction_co54 .

   DATA : l_flg-no_init TYPE c.

   READ TABLE i_lookup WITH KEY itemno = v_key.
   IF sy-subrc = 0." AND i_lookup-doctype = c_MESG.
     l_flg-no_init = c_x.
     rco54if-abdat = i_lookup-frdate.
     SET PARAMETER ID: 'WRK' FIELD i_lookup-plant.
     SET PARAMETER ID: 'BID' FIELD i_lookup-order.
     SET PARAMETER ID: 'ABDAT' FIELD rco54if-abdat.
     SET PARAMETER ID 'NO_INIT_SAPLCO51' FIELD l_flg-no_init.
     CALL TRANSACTION c_co54 AND SKIP FIRST SCREEN .
     CLEAR rco54if-abdat.
     CLEAR l_flg-no_init.
   ELSE.
     MESSAGE i000 WITH text-032.
   ENDIF.

 ENDFORM.                    " CALL_TRANSACTION_CO54
*&---------------------------------------------------------------------*
*&      Form  COMPLETE_PROECESS
*&---------------------------------------------------------------------*
* Perform CR complete process for the selected CR
*----------------------------------------------------------------------*
 FORM complete_proecess .

   DATA: l_count TYPE lvc_nkey.
*Free error log
   FREE i_errorlog.

   IF NOT i_nodekey_change1[] IS INITIAL.
     PERFORM clear_log_err_icon.
   ENDIF.

   CALL METHOD cl_gui_cfw=>dispatch.

   CALL METHOD v_alv_tree->get_checked_items
     IMPORTING
       et_checked_items = mt_checked_items.

   IF NOT mt_checked_items IS INITIAL.
     LOOP AT mt_checked_items INTO v_mt_checked_items.
       CLEAR v_discard_pi.
       v_key = v_mt_checked_items-nodekey+7(4).
       IF v_key+0(1) = space.
         v_key = v_mt_checked_items-nodekey+8(4).
       ENDIF.
       READ TABLE i_lookup WITH KEY itemno = v_key.
       IF sy-subrc = 0 AND i_lookup-doctype = c_cr.
         IF i_lookup-pitype = 4.
           v_discard_pi = v_discard_pi + 1.
*Prepare errorlog table
           i_errorlog-docno = i_lookup-docno.
           i_errorlog-message = text-031.
           APPEND i_errorlog.
           CLEAR i_errorlog.
*prepare error icon display table.
           l_count = l_count + i_lookup-itemno.
           APPEND l_count TO i_nodekey_change.
           CLEAR l_count.
         ELSE.
*Check for the status of the Control Recipe
           PERFORM status_lookup.
           IF NOT v_cr_status EQ c_x.
             PERFORM populate_selected_data_table.
           ENDIF.
         ENDIF.
       ENDIF.
     ENDLOOP.
     CLEAR v_proc_mess_id_tmp.
*     IF v_discard_pi IS INITIAL AND NOT i_procmessheader[] IS INITIAL.
     IF NOT i_procmessheader[] IS INITIAL.
       PERFORM discard_control_recipe.
       PERFORM bapi_transaction_commit.
     ENDIF.

     IF NOT i_nodekey_change[] IS INITIAL.
       PERFORM modify_nodes.
     ENDIF.

   ENDIF.
   IF NOT v_discard_pi IS INITIAL OR v_cr_status EQ c_x.
     MESSAGE i000 WITH text-023 text-024.
   ELSE.
     MESSAGE i000 WITH text-051.
   ENDIF.
   CLEAR v_discard_pi.

 ENDFORM.                    " COMPLETE_PROECESS
*&---------------------------------------------------------------------*
*&      Form  DISCARD_PROECESS
*&---------------------------------------------------------------------*
* PErform discard process for the order and associated CR which are
* selected
*----------------------------------------------------------------------*
 FORM discard_proecess .

   DATA: l_count TYPE lvc_nkey.
*Free error log
   FREE i_errorlog.

   IF NOT i_nodekey_change1[] IS INITIAL.
     PERFORM clear_log_err_icon.
   ENDIF.

   CALL METHOD cl_gui_cfw=>dispatch.

   CALL METHOD v_alv_tree->get_checked_items
     IMPORTING
       et_checked_items = mt_checked_items.

   IF NOT mt_checked_items IS INITIAL.

     LOOP AT mt_checked_items INTO v_mt_checked_items.
       CLEAR v_discard_pi.
       v_key = v_mt_checked_items-nodekey+7(4).
       IF v_key+0(1) = space.
         v_key = v_mt_checked_items-nodekey+8(4).
       ENDIF.
       READ TABLE i_lookup WITH KEY itemno = v_key.
       IF sy-subrc = 0 AND i_lookup-doctype = c_cr.
         IF i_lookup-pitype NE 4.                   "PI Type
**Prepare errorlog table
*           i_errorlog-docno = i_lookup-docno.
*           i_errorlog-message = text-031.
*           APPEND i_errorlog.
*           CLEAR i_errorlog.
**prepare error icon display table.
*           l_count = l_count + i_lookup-itemno.
*           APPEND l_count TO i_nodekey_change.
*           CLEAR l_count.
*Check for the status of the Control Recipe
           PERFORM status_lookup.
           IF NOT v_cr_status EQ c_x.
             PERFORM populate_selected_data_table.
           ENDIF.
           IF NOT i_procmessheader[] IS INITIAL.
             PERFORM discard_control_recipe.
*Check for the function call success
             PERFORM bapi_transaction_commit.
           ENDIF.

         ELSE.
*         IF i_lookup-pitype = 4.
*Check for the status of the Control Recipe
           PERFORM status_lookup.
           IF NOT v_cr_status EQ c_x.
             i_discard_pi-cntl_rec_id = i_lookup-docno.
             APPEND i_discard_pi.
             CLEAR i_discard_pi.
           ENDIF.
*         ENDIF.
           IF NOT v_cr_status EQ c_x.
             PERFORM populate_selected_data_table.
           ENDIF.
         ENDIF.                                     "PI Type
       ENDIF.
     ENDLOOP.
     CLEAR v_proc_mess_id_tmp.
     IF NOT i_procmessheader[] IS INITIAL.
       PERFORM discard_control_recipe.
       IF NOT i_discard_pi[] IS INITIAL
          AND NOT i_processmessagenew[] IS INITIAL.
         PERFORM discard_pi_sheet.
       ELSE.
         PERFORM bapi_transaction_commit.
       ENDIF.

     ENDIF.

     IF NOT i_nodekey_change[] IS INITIAL.
       PERFORM modify_nodes.
     ENDIF.

   ENDIF.
*   IF NOT v_cr_status IS INITIAL.
   IF NOT i_errorlog[] IS INITIAL.
     MESSAGE i000 WITH text-050 text-024.
   ELSE.
     MESSAGE i000 WITH text-052.
   ENDIF.
   CLEAR v_cr_status.

 ENDFORM.                    " DISCARD_PROECESS
*&---------------------------------------------------------------------*
*&      Form  call_transaction_co60
*&---------------------------------------------------------------------*
* Set parameter ID and call transaction CO60
*----------------------------------------------------------------------*
 FORM call_transaction_co60 .

   READ TABLE i_lookup WITH KEY itemno = v_key.
   IF sy-subrc = 0 AND i_lookup-doctype = c_pi.
     SET PARAMETER ID: 'WRK' FIELD i_lookup-plant.
     SET PARAMETER ID: 'ANR' FIELD i_lookup-order.
     CALL TRANSACTION c_co60 AND SKIP FIRST SCREEN .
   ELSE.
     MESSAGE i000 WITH text-030.
   ENDIF.

 ENDFORM.                    " call_transaction_co60
*&---------------------------------------------------------------------*
*&      Form  modify_nodes
*&---------------------------------------------------------------------*
* Change CR and PI items after complete or discard
*----------------------------------------------------------------------*
 FORM modify_nodes .

   DATA : l_nodekey_change TYPE lvc_nkey.

   LOOP AT i_nodekey_change INTO l_nodekey_change.
     IF NOT i_errorlog[] IS INITIAL.
       CALL METHOD v_alv_tree->change_item
         EXPORTING
           i_node_key  = l_nodekey_change
           i_fieldname = c_err
           i_data      = c_03
           i_u_data    = c_x.

       CALL METHOD v_alv_tree->frontend_update.
       APPEND l_nodekey_change TO i_nodekey_change1.
     ENDIF.
   ENDLOOP.

   REFRESH i_nodekey_change.

 ENDFORM.                    " modify_nodes
*&---------------------------------------------------------------------*
*&      Form  REFRESH_DISPLAY_LIST
*&---------------------------------------------------------------------*
*  Refresh Status report
*----------------------------------------------------------------------*
 FORM refresh_display_list .

   REFRESH i_errorlog.
   REFRESH i_lvc_nkey.
   REFRESH i_lookup.
   REFRESH i_fieldcatalog.
   REFRESH i_header.
   REFRESH i_afko.
   CALL METHOD v_custom_container->free.
   PERFORM get_order_data.
   PERFORM init_tree.
   PERFORM all_header_node_expand.

 ENDFORM.                    " REFRESH_DISPLAY_LIST
*&---------------------------------------------------------------------*
*&      Form  GET_PI_STATUS
*&---------------------------------------------------------------------*
*  Get PI status
*----------------------------------------------------------------------*
 FORM get_pi_status .

   CALL FUNCTION 'PI_SHEET_GET_STATE'
     EXPORTING
       cntrl_recipe_id              = i_sheet_header-crid
*             CRD_TYPE                     =
     IMPORTING
       cr_state                     = v_state
     EXCEPTIONS
       not_found                    = 1
       crd_type_not_supported       = 2
       internal_error               = 3
       OTHERS                       = 4 .
   IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
*Message e000 with text-064 i_sheet_header-crid.
   ENDIF.

 ENDFORM.                    " GET_PI_STATUS
*&---------------------------------------------------------------------*
*&      Form  PREPARE_LOOKUP_TABLE
*&---------------------------------------------------------------------*
* Prepare Lookup file
*----------------------------------------------------------------------*
*      -->P_L_ITEMNO  text
*      -->p_doctype   text
*      -->p_docno  text
*----------------------------------------------------------------------*
 FORM prepare_lookup_table  USING    p_l_itemno TYPE any
                                     p_doctype TYPE any
                                     p_docno TYPE any.

   i_lookup-itemno = p_l_itemno.
   i_lookup-doctype = p_doctype.
   i_lookup-docno = p_docno.
   i_lookup-order = i_afko-aufnr.
   i_lookup-plant = i_afko-werks.
   i_lookup-frdate = i_afko-erdat.
   i_lookup-todate = i_afko-aedat.
   APPEND i_lookup.
   CLEAR i_lookup.

 ENDFORM.                    " PREPARE_LOOKUP_TABLE
*&---------------------------------------------------------------------*
*&      Form  checkbox_check
*&---------------------------------------------------------------------*
* Check at least one checkbox is checked or not.
*----------------------------------------------------------------------*
 FORM checkbox_check .

   IF c_new IS INITIAL AND c_inwork IS INITIAL AND c_close IS INITIAL
      AND c_canc IS INITIAL AND c_disc IS INITIAL AND c_comp IS INITIAL
      AND c_arch IS INITIAL.
     MESSAGE e000 WITH text-029.
   ENDIF.

   IF c_create IS INITIAL AND c_sentcr IS INITIAL
   AND c_proces IS INITIAL AND c_termin IS INITIAL
   AND c_disccr IS INITIAL.
     MESSAGE e000 WITH text-028.
   ENDIF.

   IF c_tosend IS INITIAL AND c_sentpm IS INITIAL
   AND c_end IS INITIAL.
     MESSAGE e000 WITH text-027.
   ENDIF.

 ENDFORM.                    " checkbox_check
*&---------------------------------------------------------------------*
*&      Form  status_lookup
*&---------------------------------------------------------------------*
* Check he status of the control recipe selected for discard/complete
*----------------------------------------------------------------------*
 FORM status_lookup .

   DATA: l_count TYPE lvc_nkey.

   CLEAR v_cr_status.
   SELECT SINGLE *
   FROM coch
   WHERE
   crid = i_lookup-docno.
   IF sy-subrc = 0.
     IF coch-crstat EQ c_four OR coch-crstat EQ c_five
               OR coch-crstat EQ c_seven.
       v_cr_status = c_x.
*prepare error log table
       i_errorlog-docno = i_lookup-docno.
       CONCATENATE text-025 coch-crstat text-026
                   INTO i_errorlog-message SEPARATED BY space.
       APPEND i_errorlog.
       CLEAR i_errorlog.
*prepare error icon display table.
       l_count = l_count + i_lookup-itemno.
       APPEND l_count TO i_nodekey_change.
       CLEAR l_count.
     ENDIF.
   ENDIF.
   CLEAR coch.

 ENDFORM.                    " status_lookup
*&---------------------------------------------------------------------*
*&      Form  CLEAR_LOG_ERR_ICON
*&---------------------------------------------------------------------*
* clear error log and error icons
*----------------------------------------------------------------------*
 FORM clear_log_err_icon .

   REFRESH i_errorlog.

   DATA : l_nodekey_change TYPE lvc_nkey.

   LOOP AT i_nodekey_change1 INTO l_nodekey_change.
     CALL METHOD v_alv_tree->change_item
       EXPORTING
         i_node_key  = l_nodekey_change
         i_fieldname = c_err
         i_data      = c_5f
         i_u_data    = c_x.

     CALL METHOD v_alv_tree->frontend_update.

   ENDLOOP.

   REFRESH i_nodekey_change1.

 ENDFORM.                    " CLEAR_LOG_ERR_ICON
*&---------------------------------------------------------------------*
*&      Form  check_authorisations
*&---------------------------------------------------------------------*
* Authorization Check for Plant
*----------------------------------------------------------------------*
 FORM check_authorisations .

   LOOP AT i_werks.

     AUTHORITY-CHECK OBJECT 'C_MESS_WRK'
              ID 'ACTVT' FIELD c_star
              ID 'WERKS' FIELD i_werks-werks.

     IF NOT sy-subrc IS INITIAL.
       MESSAGE s000 WITH text-053 i_werks-werks.
       LEAVE LIST-PROCESSING.
     ENDIF.

   ENDLOOP.

 ENDFORM.                    " check_authorisations

  • No labels