Skip to Content

The purpose of this program is to:       

                                                                        

1. Changing status of  Order BOM from 1 to 9                             

2. Changing the status Order BOM from 9 to 1                             

3. Deleting the order BOM                



The following are the logics for displaying the report and corresponding buttons and their actions:-

  1. Call the form f_select_order_bom to select the required data for display the ALV. This form do a join on the tables MAKT,KDST,STKO and MARC to select the required data.To select the data for last change done by the user and the date use the FM: CHANGEDOCUMENT_READ_HEADERS.
  1. Call screen 100 to display the ALV.
  1. Generate the PF-status ZVAR_1629 to create the 3 buttons with the following function code: ‘&ST1’,’&ST9’ and ‘&DBO’.
  1. Create the following PBO Modules & PAI Modules:
  • MODULE status_0100.
  • MODULE user_command_0100.
  • MODULE exit AT EXIT-COMMAND.
  1. The Module status_PBO contains the following logic:

SET PF-STATUS ‘ZVAR_1629’.
SET TITLEBAR ‘ZVAR_1629’.

IF g_custom_container IS INITIAL.
CREATE OBJECT g_custom_container
EXPORTING
container_name              = g_container
EXCEPTIONS
cntl_error                  = 1
cntl_system_error           = 2
create_error                = 3
lifetime_error              = 4
lifetime_dynpro_dynpro_link = 5.
IF sy-subrc <> 0.

CALL FUNCTION ‘POPUP_TO_INFORM’
EXPORTING
titel = g_repid
txt2  = sy-subrc
txt1  = ‘The control could not be created!'(002).
ENDIF.

CREATE OBJECT g_grid_9000
EXPORTING
i_parent = g_custom_container.

*    gs_layout-cwidth_opt = ‘X’.
gs_layout-sel_mode   = ‘A’.

*creating Field Catalogue

CALL FUNCTION ‘LVC_FIELDCATALOG_MERGE’
EXPORTING
i_structure_name = ‘ZRVAR_OUTPUT_1629’
CHANGING
ct_fieldcat      = gt_fieldcat[].

* Modifying the Field catalogue
PERFORM f_modify_field_catalogue CHANGING gt_fieldcat.

*Displaying the ALV
CALL METHOD g_grid_9000->set_table_for_first_display
EXPORTING
*       i_structure_name   = c_structure
*       is_print           = gs_print
is_layout          = gs_layout
i_save             = ‘A’
i_buffer_active    = ‘ ‘
i_default          = ‘ ‘
i_bypassing_buffer = ‘ ‘
*       is_variant         = ls_vari
CHANGING
*       it_sort            = gs_sort
it_fieldcatalog    = gt_fieldcat[]
it_outtab          = gt_output.

  1. The  MODULE user_command_0100 contains the following logic:

CONSTANTS: lc_1 TYPE char1 VALUE ‘1’,
lc_9 TYPE char1 VALUE ‘9’.

DATA: lt_output1 TYPE STANDARD TABLE OF zrvar_output_1629.

CASE ok_code.

WHEN ‘&ALL’.
LOOP AT gt_output ASSIGNING <gfs_output>.
<gfs_output>-checkbox = ‘X’.
ENDLOOP.
CALL METHOD g_grid_9000->refresh_table_display.
WHEN ‘&SAL’.
LOOP AT gt_output ASSIGNING <gfs_output>.
CLEAR <gfs_output>-checkbox.
ENDLOOP.
CALL METHOD g_grid_9000->refresh_table_display.
WHEN ‘&ST9’.
CALL METHOD g_grid_9000->check_changed_data.
PERFORM f_change_status USING gt_output lc_9.
CALL METHOD g_grid_9000->refresh_table_display.
WHEN ‘&ST1’.
CALL METHOD g_grid_9000->check_changed_data.
PERFORM f_change_status USING gt_output lc_1.
CALL METHOD g_grid_9000->refresh_table_display.
WHEN ‘&DBO’.
CALL METHOD g_grid_9000->check_changed_data.
PERFORM f_delete_order_bom USING gt_output.
CALL METHOD g_grid_9000->refresh_table_display.
ENDCASE.
CLEAR ok_code.

  1. The Module Exit contains the following logic:

                  CASE ok_code.
when ‘BACK’ or ‘%EX’ or ‘RW’.
LEAVE TO SCREEN 0.
ENDCASE.

                               

REPORT  zvarr_1629_par_rel_order_bom MESSAGE-ID zvar_1629 NO STANDARD PAGE HEADING.

*Selection Screen

INCLUDE zvari_169_sel.

* Global Data

INCLUDE zvari_169_global.

*Global Form routines

INCLUDE zvari_1629_f01.

AT SELECTION-SCREEN.

*Selecting the data

   PERFORM f_select_order_bom CHANGING gt_output.

START-OF-SELECTION.

*Calling the ALV

   CALL SCREEN 100.

*Include for PBO Modules

   INCLUDE zvari_1629_o01.

*Include for PAI Modules

   INCLUDE zvari_1629_i01.

*&————————————————————————–*

*&  Include           ZVARR_169_SEL

*&————————————————————————–*

SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.

PARAMETERS : p_order TYPE vbap-vbeln, “Sales Order

              p_item  TYPE vbap-posnr. “Item

SELECTION-SCREEN END OF BLOCK b1.

*&————————————————————————–*

*&  Include           ZVARR_169_GLOBAL

*&————————————————————————–*

*Global Workarea

TABLES: afpo,ekkn,ekpo.

*Global Data

DATA: ok_code            TYPE sy-ucomm,

       g_repid            TYPE sy-repid,

       gs_layout          TYPE lvc_s_layo,

       gt_fieldcat        TYPE lvc_t_fcat,

       g_answer           TYPE c VALUE ‘3’,

       g_container        TYPE scrfname VALUE ‘ALV_CONTAINER’,

       g_custom_container TYPE REF TO cl_gui_custom_container,

       g_grid_9000        TYPE REF TO cl_gui_alv_grid,

       lt_rows            TYPE lvc_t_row.                    “#EC NEEDED

data:  g_splitter           TYPE REF TO cl_gui_splitter_container,

        g_custom_container_1 TYPE REF TO cl_gui_container,

        g_custom_container_2 TYPE REF TO cl_gui_container,

        gr_docking           TYPE REF TO cl_gui_docking_container.

*Global Output Tables

DATA gt_output          TYPE STANDARD TABLE OF zrvar_output_1629.

*Global Types

TYPES: tty_output        TYPE STANDARD TABLE OF zrvar_output_1629,

        tty_exp_bom_data  TYPE STANDARD TABLE OF capp_bom,

        tty_exp_itm_data  TYPE STANDARD TABLE OF capp_itm.

*Global Field symbol

FIELD-SYMBOLS     <gfs_output> TYPE zrvar_output_1629.

*****************************************************************

** LOCAL CLASSES: Definition

*****************************************************************

CLASS zlcl_event_receiver DEFINITION.

   PUBLIC SECTION.

     METHODS: handle_top_of_page

              FOR EVENT top_of_page OF cl_gui_alv_grid

              IMPORTING

                 e_dyndoc_id

                 table_index.

ENDCLASS.                    “zlcl_event_receiver DEFINITION

*———————————————————————-*

*       CLASS zlcl_event_receiver IMPLEMENTATION

*———————————————————————-*

*

*———————————————————————-*

CLASS zlcl_event_receiver IMPLEMENTATION.

   METHOD handle_top_of_page  .

     PERFORM event_top_of_page USING e_dyndoc_id

                                    table_index .

   ENDMETHOD.                    “HANDLE_TOP_OF_PAGE

ENDCLASS.                    “ZLCL_EVENT_RECEIVER IMPLEMENTATION

DATA: g_dd_document    TYPE REF TO cl_dd_document,

       g_event_reciever TYPE REF TO zlcl_event_receiver,

       g_HTML_CNTRL     type ref to cl_gui_html_viewer.

*—————————————————————————*

***INCLUDE ZVARI_1629_F01 .

*&————————————————————————–*

FORM f_select_order_bom  CHANGING p_output LIKE gt_output.

*Local data and constants

   CONSTANTS: lc_k             TYPE char1 VALUE ‘K’,

              lc_en            TYPE char2 VALUE ‘EN’.

   FIELD-SYMBOLS <lfs_output>  TYPE zrvar_output_1629.

   DATA:     l_objectid   TYPE cdhdr-objectid,

             lt_cdhdr     TYPE STANDARD TABLE OF cdhdr,

             ls_cdhdr     TYPE cdhdr,

             l_flag       TYPE c,

             l_name       TYPE cdhdr-username,

             lt_makt      TYPE STANDARD TABLE OF makt,

             lt_makt1     TYPE STANDARD TABLE OF makt,

             ls_makt      TYPE makt.

   DATA: lt_exp_bom_data TYPE STANDARD TABLE OF capp_bom,

         lt_exp_itm_data TYPE STANDARD TABLE OF capp_itm.

   CONSTANTS: lc_x         TYPE c VALUE ‘X’,

              lc_stue      TYPE cdhdr-objectclas VALUE ‘STUE’.

**Selecting the ALV Data from Join of the tables KDST,STKO,MAKT,MARC.

*  SELECT a~matnr “Material

*         a~maktx “material Text

*         c~stlst “BOM status

*         d~sobsl “Special procurement type

*         d~sbdkz “Dependent requirements ind. for individual and coll. reqmts

*         d~beskz “Procurement Type

*         b~annam “User who created record

*         b~andat “Date record created on

*         c~aenam “Name of Person Who Changed Object

*         b~werks “Plant

*         b~stlan “BOM Usage

*         c~datuv “Valid-From Date

*         c~stlal “Alternative BOM

*         c~bmeng “Confirmed Quantity

*         c~stlnr “Bill of material

*         c~aedat INTO CORRESPONDING FIELDS OF TABLE p_output

*                      FROM ( ( ( makt AS a INNER JOIN

*                      kdst AS b ON a~matnr = b~matnr  )  INNER JOIN

*                      stko AS c ON b~stlnr = c~stlnr  )  INNER JOIN

*                      marc AS d ON a~matnr  = d~matnr

*                              AND  b~werks  = d~werks )

*     WHERE b~vbeln = p_order

*      AND  b~vbpos = p_item

*      AND  c~stlty = lc_k.                                  “#EC WARNOK

   SELECT  a~matnr “Material

           b~stlst “BOM status

           c~sobsl “Special procurement type

           c~sbdkz “Dependent requirements ind. for individual and coll. reqmts

           c~beskz “Procurement Type

           a~annam “User who created record

           a~andat “Date record created on

           b~aenam “Name of Person Who Changed Object

           c~werks “Plant

           a~stlan “BOM Usage

           b~datuv “Valid-From Date

           b~stlal “Alternative BOM

           b~bmeng “Confirmed Quantity

           b~stlnr “Bill of material

           b~aedat INTO CORRESPONDING FIELDS OF TABLE p_output

     FROM ( (           kdst AS a INNER JOIN

                        stko AS b ON a~stlnr = b~stlnr )  INNER JOIN

                        marc AS c ON a~matnr  = c~matnr

                                AND  a~werks  = c~werks )

       WHERE a~vbeln = p_order

        AND  a~vbpos = p_item

        AND  b~stlty = lc_k.                                 “#EC WARNOK

   IF sy-subrc = 0.

     DELETE ADJACENT DUPLICATES FROM gt_output COMPARING matnr.

     IF gt_output IS NOT INITIAL.

       SELECT

        matnr

        spras

        maktx

       FROM makt

       INTO CORRESPONDING FIELDS OF TABLE lt_makt

       FOR ALL ENTRIES IN gt_output

       WHERE spras = sy-langu

         AND matnr = gt_output-matnr.

     ENDIF.

     IF gt_output IS NOT INITIAL.

       SELECT

        matnr

        spras

        maktx

       FROM makt

       INTO CORRESPONDING FIELDS OF TABLE lt_makt1

       FOR ALL ENTRIES IN gt_output

       WHERE spras = lc_en

         AND matnr = gt_output-matnr.

     ENDIF.

     LOOP AT gt_output ASSIGNING <lfs_output>.

       <lfs_output>-checkbox = lc_x.

       CLEAR <lfs_output>-maktx.

       READ TABLE lt_makt WITH KEY matnr = <lfs_output>-matnr INTO ls_makt.

       IF sy-subrc = 0.

         <lfs_output>-maktx = ls_makt-maktx.

       ELSE.

         CLEAR ls_makt.

         READ TABLE lt_makt1 WITH KEY matnr = <lfs_output>-matnr INTO ls_makt.

         IF sy-subrc = 0.

           <lfs_output>-maktx = ls_makt-maktx.

         ENDIF.

       ENDIF.

*Checking whether data has been changed

       CALL FUNCTION ‘CABM_READ_BOM’

         EXPORTING

           i_matnr         = <lfs_output>-matnr

           i_werks         = <lfs_output>-werks

           i_vbeln         = p_order

           i_vbpos         = p_item

           i_stlal         = <lfs_output>-stlal

           i_stlan         = <lfs_output>-stlan

         TABLES

           exp_bom_data    = lt_exp_bom_data

           exp_itm_data    = lt_exp_itm_data

         EXCEPTIONS

           no_record_found = 1

           OTHERS          = 2.

       IF sy-subrc <> 0.

* Implement suitable error handling here

       ENDIF.

* Checking for changes

       PERFORM f_check_bom_data_changed

       USING lt_exp_bom_data lt_exp_itm_data CHANGING l_flag.

*Creating the Object ID

       CONCATENATE sy-mandt lc_k <lfs_output>-stlnr INTO l_objectid.

       CLEAR l_name.

       IF l_flag IS INITIAL.

*checking the change docs for the changes done via transaction

         CALL FUNCTION ‘CHANGEDOCUMENT_READ_HEADERS’

           EXPORTING

             objectclass                = lc_stue

             objectid                   = l_objectid

             username                   = l_name

           TABLES

             i_cdhdr                    = lt_cdhdr

           EXCEPTIONS

             no_position_found          = 1

             wrong_access_to_archive    = 2

             time_zone_conversion_error = 3

             OTHERS                     = 4.

         IF sy-subrc <> 0.

* Implement suitable error handling here

         ENDIF.

         IF sy-subrc = 0.

           READ TABLE lt_cdhdr INTO ls_cdhdr INDEX 1.

           IF sy-subrc = 0.

             <lfs_output>-aenam = ls_cdhdr-username.

             <lfs_output>-aedat = ls_cdhdr-udate.

           ENDIF.

         ENDIF.

       ENDIF.

     ENDLOOP.

   ELSE.

     MESSAGE e000.

   ENDIF.

ENDFORM.                    ” F_SELECT_ORDER_BOM

*&———————————————————————*

*&      Form  F_MODIFY_FIELD_CATALOGUE

*&———————————————————————*

*       text

*———————————————————————-*

*      <–P_GT_FIELDCAT  text

*———————————————————————-*

FORM f_modify_field_catalogue  CHANGING p_fieldcat TYPE  lvc_t_fcat.

   CONSTANTS: lc_x TYPE c VALUE ‘X’,

              lc_l TYPE c VALUE ‘L’.

   FIELD-SYMBOLS <lfs_fieldcat>  TYPE lvc_s_fcat.

*changing the output lenght for fields in the ALV

   LOOP AT p_fieldcat ASSIGNING <lfs_fieldcat>.

     IF <lfs_fieldcat>-fieldname = ‘CHECKBOX’.

       <lfs_fieldcat>-scrtext_l = text-003.

       <lfs_fieldcat>-scrtext_m = text-003.

       <lfs_fieldcat>-scrtext_s = text-003.

       <lfs_fieldcat>-checkbox  = lc_x.

       <lfs_fieldcat>-edit      = lc_x.

       <lfs_fieldcat>-outputlen = 9.

     ENDIF.

     CASE <lfs_fieldcat>-fieldname.

       WHEN ‘STLST’.

         <lfs_fieldcat>-f4availabl = abap_true.

         <lfs_fieldcat>-just       = lc_l.

         <lfs_fieldcat>-outputlen = 10.

       WHEN ‘SOBSL’.

         <lfs_fieldcat>-outputlen = 16.

         <lfs_fieldcat>-f4availabl = abap_true.

         <lfs_fieldcat>-just       = lc_l.

         <lfs_fieldcat>-col_pos = 6.

       WHEN ‘SBDKZ’.

         <lfs_fieldcat>-outputlen = 16.

         <lfs_fieldcat>-col_pos = 7.

       WHEN ‘BESKZ’.

         <lfs_fieldcat>-outputlen = 16.

         <lfs_fieldcat>-col_pos = 5.

       WHEN ‘WERKS’.

         <lfs_fieldcat>-no_out = ‘X’.

       WHEN ‘STLAN’.

         <lfs_fieldcat>-no_out = ‘X’.

       WHEN ‘BMENG’.

         <lfs_fieldcat>-no_out = ‘X’.

       WHEN ‘DATUV’.

         <lfs_fieldcat>-no_out = ‘X’.

       WHEN ‘STLAL’.

         <lfs_fieldcat>-no_out = ‘X’.

       WHEN ‘STLNR’.

         <lfs_fieldcat>-no_out = ‘X’.

       WHEN ‘ANNAM’.

         <lfs_fieldcat>-col_pos = 8.

       WHEN ‘ANDAT’.

         <lfs_fieldcat>-col_pos = 9.

       WHEN ‘AENAM’.

         <lfs_fieldcat>-col_pos = 10.

       WHEN ‘AEDAT’.

         <lfs_fieldcat>-col_pos = 11.

     ENDCASE.

   ENDLOOP.

ENDFORM.                    ” F_MODIFY_FIELD_CATALOGUE

*&———————————————————————*

*&      Form  PROCESS_USER_COMMAND

*&———————————————————————*

*       text

*———————————————————————-*

*      –>P_E_UCOMM  text

*      –>P_S_SELFIELD  text

*———————————————————————-*

FORM process_user_command  USING    p_ucomm TYPE sy-ucomm.

   CONSTANTS: lc_back TYPE char4 VALUE ‘BACK’,

              lc_rw   TYPE char2 VALUE  ‘RW’,

              lc_ex   TYPE char3 VALUE  ‘%EX’.

   CASE p_ucomm.

     WHEN lc_back  OR lc_rw OR lc_ex.

       LEAVE TO SCREEN 0.

   ENDCASE.

ENDFORM.                    ” PROCESS_USER_COMMAND

*&———————————————————————*

*&      Form  F_EXIT_PROGRAM

*&———————————————————————*

*       text

*———————————————————————-*

*  –>  p1        text

*  <–  p2        text

*———————————————————————-*

FORM f_exit_program .

   CALL METHOD g_custom_container->free.

   CALL METHOD cl_gui_cfw=>flush.

   IF sy-subrc <> 0.

     CALL FUNCTION ‘POPUP_TO_INFORM’

       EXPORTING

         titel = g_repid

         txt2  = sy-subrc

         txt1  = ‘Error in Flush’(006).

   ENDIF.

   SET SCREEN 0.

   LEAVE PROGRAM.

ENDFORM.                    ” F_EXIT_PROGRAM

*&———————————————————————*

*&      Form  F_CHANGE_STATUS

*&———————————————————————*

*       text

*———————————————————————-*

*      –>P_LT_OUTPUT1  text

*      –>P_LC_1  text

*———————————————————————-*

FORM f_change_status  USING    p_output TYPE tty_output

                                p_status TYPE char1.

   DATA: ls_stko_api01 TYPE stko_api01,

         l_datauv      TYPE csap_kbom-datuv,

         l_val         TYPE char13,

         l_ref         TYPE REF TO cx_root.                  “#EC NEEDED

   FIELD-SYMBOLS <lfs_output> TYPE zrvar_output_1629.

   CONSTANTS: lc_st9 TYPE char4 VALUE ‘&ST9’,

              lc_1   TYPE c VALUE ‘1’,

              lc_3   TYPE c VALUE ‘3’,

              lc_x   TYPE c VALUE ‘X’.

   LOOP AT p_output ASSIGNING <lfs_output> WHERE checkbox = lc_x.

     IF ok_code = lc_st9.

       PERFORM f_check_production_order_exist USING <lfs_output>-matnr.

     ENDIF.

     IF g_answer = lc_1 OR g_answer = lc_3.

       CLEAR ls_stko_api01.

*      l_val = <lfs_output>-bmeng.

       WRITE <lfs_output>-bmeng TO l_val DECIMALS 0.

       ls_stko_api01-base_quan = l_val.

*      REPLACE ‘,’ WITH ‘.’ INTO ls_stko_api01-base_quan.

       ls_stko_api01-bom_status = p_status.

       CONCATENATE sy-datum+6(2) sy-datum+4(2) sy-datum+0(4)  INTO l_datauv.

       TRY.

           CALL FUNCTION ‘CSAP_ORD_BOM_MAINTAIN’

             EXPORTING

               order      = p_order

               position   = p_item

               material   = <lfs_output>-matnr

               plant      = <lfs_output>-werks

               bom_usage  = <lfs_output>-stlan

               valid_from = l_datauv

               i_stko     = ls_stko_api01

             EXCEPTIONS

               error      = 1

               OTHERS     = 2.

         CATCH cx_sy_conversion_overflow INTO l_ref.

           ##no_handler

ENDTRY.

           IF sy-subrc = 0.

             <lfs_output>-stlst = p_status.

* Implement suitable error handling here

           ELSE.

             MESSAGE e001 DISPLAY LIKE ‘I’.

           ENDIF.

           CONTINUE.

         ENDIF.

       ENDLOOP.

       UNASSIGN <lfs_output>.

     ENDFORM.                    ” F_CHANGE_STATUS

*&———————————————————————*

*&      Form  F_DELETE_ORDER_BOM

*&———————————————————————*

*       text

*———————————————————————-*

*      –>P_LT_OUTPUT1  text

*———————————————————————-*

FORM f_delete_order_bom  USING    p_output TYPE tty_output.

   DATA ls_kdst TYPE kdst.

   FIELD-SYMBOLS <lfs_output> TYPE zrvar_output_1629.

   DATA l_tabix TYPE sy-tabix.

   CONSTANTS: lc_dbo TYPE char3 VALUE ‘&DBO’,

              lc_1   TYPE c VALUE ‘1’,

              lc_3   TYPE c VALUE ‘3’,

              lc_x   TYPE c VALUE ‘X’.

   LOOP AT p_output ASSIGNING <lfs_output> WHERE checkbox = lc_x.

       CLEAR l_tabix.

     l_tabix = sy-tabix.

     IF ok_code = lc_dbo.

       PERFORM f_check_production_order_exist USING <lfs_output>-matnr.

     ENDIF.

     IF g_answer = lc_1 OR g_answer = lc_3.

       CALL FUNCTION ‘CSAP_ORD_BOM_DELETE’

         EXPORTING

           order     = p_order

           position  = p_item

           material  = <lfs_output>-matnr

           bom_usage = <lfs_output>-stlan

         EXCEPTIONS

           error     = 1

           OTHERS    = 2.

       IF sy-subrc = 0.

         DELETE p_output INDEX l_tabix.

       ELSE.

         SELECT SINGLE * FROM kdst INTO ls_kdst

           WHERE     vbeln = p_order

                 AND vbpos = p_item

                 AND matnr = <lfs_output>-matnr

                 AND stlan = <lfs_output>-stlan.

         IF sy-subrc <> 0.

           MESSAGE E003 DISPLAY LIKE ‘I’.

         ELSE.

           MESSAGE E002 DISPLAY LIKE ‘I’

           .

         ENDIF.

* Implement suitable error handling here

       ENDIF.

     ENDIF.

   ENDLOOP.

ENDFORM.                    ” F_DELETE_ORDER_BOM

*&———————————————————————*

*&      Form  F_CHECK_PRODUCTION_ORDER_EXIST

*&———————————————————————*

*       text

*———————————————————————-*

*  –>  p1        text

*  <–  p2        text

*———————————————————————-*

FORM f_check_production_order_exist USING p_matnr TYPE matnr.

   CLEAR afpo.

   SELECT SINGLE aufnr posnr

    FROM afpo INTO (afpo-aufnr, afpo-posnr)

     WHERE kdauf = p_order

      AND  kdpos = p_item

      AND  matnr = p_matnr.                                  “#EC WARNOK

   IF sy-subrc = 0 AND afpo-aufnr IS NOT INITIAL.

     CALL FUNCTION ‘POPUP_TO_CONFIRM’

       EXPORTING

         text_question  = text-004

         text_button_1  = ‘Yes’(007)

         text_button_2  = ‘No’(008)

       IMPORTING

         answer         = g_answer

       EXCEPTIONS

         text_not_found = 1

         OTHERS         = 2.

     IF sy-subrc <> 0.

* Implement suitable error handling here

     ENDIF.

   ELSE.

     PERFORM f_check_purchase_order_exist USING p_matnr.

   ENDIF.

ENDFORM.                    ” F_CHECK_PRODUCTION_ORDER_EXIST

*&———————————————————————*

*&      Form  F_CHECK_PURCHASE_ORDER_EXIST

*&———————————————————————*

*       text

*———————————————————————-*

*  –>  p1        text

*  <–  p2        text

*———————————————————————-*

FORM f_check_purchase_order_exist USING p_matnr TYPE matnr.

   CLEAR: ekkn,ekpo.

   DATA:   lt_ekkn TYPE STANDARD TABLE OF ekkn,

           lt_ekpo TYPE STANDARD TABLE OF ekpo.

   SELECT ebeln ebelp FROM ekkn

   INTO CORRESPONDING FIELDS OF TABLE lt_ekkn

     WHERE vbeln = p_order

     AND   vbelp = p_item.                                   “#EC WARNOK

   IF sy-subrc = 0.

     SELECT  ebeln

             ebelp

             matnr FROM ekpo INTO CORRESPONDING FIELDS OF TABLE lt_ekpo

     FOR ALL ENTRIES IN lt_ekkn

     WHERE ebeln = lt_ekkn-ebeln

       AND ebelp = lt_ekkn-ebelp

       AND matnr = p_matnr

       AND loekz = space.

     IF sy-subrc = 0.

       CALL FUNCTION ‘POPUP_TO_CONFIRM’

         EXPORTING

           text_question  = text-005

           text_button_1  = ‘Yes’(007)

           text_button_2  = ‘No’(008)

         IMPORTING

           answer         = g_answer

         EXCEPTIONS

           text_not_found = 1

           OTHERS         = 2.

       IF sy-subrc <> 0.

* Implement suitable error handling here

       ENDIF.

     ENDIF.

   ENDIF.

ENDFORM.                    ” F_CHECK_PURCHASE_ORDER_EXIST

*&———————————————————————*

*&      Form  F_CHECK_BOM_DATA_CHANGED

*&———————————————————————*

*       text

*———————————————————————-*

*      –>P_LT_EXP_BOM_DATA  text

*      –>P_LT_EXP_ITM_DATA  text

*      <–P_L_FLAG  text

*———————————————————————-*

FORM f_check_bom_data_changed  USING    p_lt_exp_bom_data TYPE tty_exp_bom_data

                                         p_lt_exp_itm_data TYPE tty_exp_itm_data

                                CHANGING p_flag TYPE c.

   DATA:      ls_exp_bom_data TYPE capp_bom,

              ls_exp_itm_data TYPE capp_itm.

   CONSTANTS: lc_x TYPE c VALUE ‘X’.

   CLEAR p_flag.

   READ TABLE p_lt_exp_bom_data INTO ls_exp_bom_data INDEX 1.

   IF sy-subrc = 0.

     IF ls_exp_bom_data-aenam IS INITIAL AND ls_exp_bom_data-aedat IS INITIAL.

       p_flag = lc_x.

     ENDIF.

   ENDIF.

   LOOP AT p_lt_exp_itm_data INTO ls_exp_itm_data.

     IF ls_exp_itm_data-aenam IS INITIAL AND ls_exp_itm_data-aedat IS INITIAL.

       p_flag = lc_x.

     ELSE.

       CLEAR p_flag.

     ENDIF.

   ENDLOOP.

ENDFORM.                    ” F_CHECK_BOM_DATA_CHANGED

*&———————————————————————*

*&      Form  F_EXCLUDE_FCODE

*&———————————————————————*

*       text

*———————————————————————-*

*      <–P_LT_EXCLUDING  text

*———————————————————————-*

FORM f_exclude_fcode  CHANGING p_excluding TYPE ui_functions.

   DATA ls_exclude TYPE ui_func.

*excluding Fcode

   ls_exclude = cl_gui_alv_grid=>mc_fc_detail.

   APPEND ls_exclude TO p_excluding.

   ls_exclude =  cl_gui_alv_grid=>mc_fc_check.

   APPEND ls_exclude TO p_excluding.

   ls_exclude   = cl_gui_alv_grid=>mc_fc_average.

   APPEND ls_exclude TO p_excluding.

   ls_exclude = cl_gui_alv_grid=>mc_fc_loc_paste_new_row.

   APPEND ls_exclude TO p_excluding.

   ls_exclude  = cl_gui_alv_grid=>mc_fc_loc_paste.

   APPEND ls_exclude TO p_excluding.

   ls_exclude = cl_gui_alv_grid=>mc_fc_loc_copy_row.

   APPEND ls_exclude TO p_excluding.

   ls_exclude  = cl_gui_alv_grid=>mc_fc_loc_copy.

   APPEND ls_exclude TO p_excluding.

   ls_exclude = cl_gui_alv_grid=>mc_fc_loc_cut.

   APPEND ls_exclude TO p_excluding.

   ls_exclude = cl_gui_alv_grid=>mc_fc_loc_insert_row.

   APPEND ls_exclude TO p_excluding.

   ls_exclude  = cl_gui_alv_grid=>mc_fc_loc_delete_row.

   APPEND ls_exclude TO p_excluding.

   ls_exclude = cl_gui_alv_grid=>mc_fc_loc_append_row.

   APPEND ls_exclude TO p_excluding.

   ls_exclude = cl_gui_alv_grid=>mc_fc_graph.

   APPEND ls_exclude TO p_excluding.

   ls_exclude = cl_gui_alv_grid=>mc_fc_loc_undo.

   APPEND ls_exclude TO p_excluding.

   ls_exclude =  cl_gui_alv_grid=>mc_fc_filter.

   APPEND ls_exclude TO p_excluding.

   ls_exclude =  cl_gui_alv_grid=>mc_fc_sum.

   APPEND ls_exclude TO p_excluding.

   ls_exclude =  cl_gui_alv_grid=>mc_fc_subtot.

   APPEND ls_exclude TO p_excluding.

   ls_exclude =  cl_gui_alv_grid=>mc_fc_info.

   APPEND ls_exclude TO p_excluding.

   ls_exclude =  cl_gui_alv_grid=>mc_fc_auf.

   APPEND ls_exclude TO p_excluding.

   ls_exclude =  cl_gui_alv_grid=>mc_fc_check.

   APPEND ls_exclude TO p_excluding.

   ls_exclude =  cl_gui_alv_grid=>mc_fc_to_office.

   APPEND ls_exclude TO p_excluding.

   ls_exclude =  cl_gui_alv_grid=>mc_fc_average.

   APPEND ls_exclude TO p_excluding.

   ls_exclude =  cl_gui_alv_grid=>mc_fc_count.

   APPEND ls_exclude TO p_excluding.

   ls_exclude =  cl_gui_alv_grid=>mc_fc_maximum.

   APPEND ls_exclude TO p_excluding.

   ls_exclude =  cl_gui_alv_grid=>mc_fc_minimum.

   APPEND ls_exclude TO p_excluding.

ENDFORM.                    ” F_EXCLUDE_FCODE

*&———————————————————————*

*&      Form  EVENT_TOP_OF_PAGE

*&———————————————————————*

*       text

*———————————————————————-*

*      –>P_E_DYNDOC_ID  text

*      –>P_TABLE_INDEX  text

*———————————————————————-*

FORM event_top_of_page  USING    p_e_dyndoc_id TYPE REF TO cl_dd_document

                                  p_table_index TYPE sy-index.

   DATA : ls_vbep TYPE vbep,

          lt_vbep TYPE STANDARD TABLE OF vbep,

          l_text  TYPE sdydo_text_element,

          l_gap   TYPE i,

          l_matnr TYPE matnr.

   SELECT vbeln

          posnr

          etenr

          ettyp

          bmeng  FROM vbep INTO CORRESPONDING FIELDS OF TABLE lt_vbep

     WHERE vbeln = p_order

      AND  posnr = p_item.

   IF sy-subrc = 0.

     IF sy-dbcnt > 1.

       LOOP AT lt_vbep INTO ls_vbep WHERE bmeng > 0.

         READ TABLE lt_vbep INTO ls_vbep INDEX sy-tabix.

       ENDLOOP.

     ELSE.

       READ TABLE lt_vbep INTO ls_vbep INDEX 1.

     ENDIF.

* Sales order

     l_gap = ‘1’.

     PERFORM add_gap USING l_gap

                               p_e_dyndoc_id.

     l_text = text-009.

     PERFORM add_text USING l_text p_e_dyndoc_id.

     l_gap = ‘1’.

     PERFORM add_gap USING l_gap

                               p_e_dyndoc_id.

     l_text = ls_vbep-vbeln.

     PERFORM add_text_val USING l_text

                          p_e_dyndoc_id.

     CALL METHOD p_e_dyndoc_id->new_line.

     CLEAR :l_text, l_gap.

*Sales order Item

     l_gap = ’12’.

     PERFORM add_gap USING l_gap

                               p_e_dyndoc_id.

     l_text = text-010.

     PERFORM add_text USING l_text p_e_dyndoc_id.

     l_gap = ‘1’.

     PERFORM add_gap USING l_gap

                               p_e_dyndoc_id.

     l_text = ls_vbep-posnr.

     PERFORM add_text_val USING l_text

                          p_e_dyndoc_id.

     CALL METHOD p_e_dyndoc_id->new_line.

     CLEAR :l_text, l_gap.

* Material

     l_gap = ‘7’.

     PERFORM add_gap USING l_gap

                               p_e_dyndoc_id.

     l_text = text-011.

     PERFORM add_text USING l_text p_e_dyndoc_id.

     l_gap = ‘1’.

     PERFORM add_gap USING l_gap

                               p_e_dyndoc_id.

* Finding the material for Sales order item

     SELECT SINGLE matnr FROM vbap INTO l_matnr

       WHERE vbeln = p_order

         AND posnr = p_item.

     IF sy-subrc = 0.

       SHIFT l_matnr LEFT DELETING LEADING ‘0’.

       l_text = l_matnr.

     ENDIF.

     PERFORM add_text_val USING l_text

                          p_e_dyndoc_id.

     CALL METHOD p_e_dyndoc_id->new_line.

     CLEAR :l_text, l_gap.

*Schedule line category

     l_text = text-012.

     PERFORM add_text USING l_text p_e_dyndoc_id.

     l_gap = ‘1’.

     PERFORM add_gap USING l_gap

                               p_e_dyndoc_id.

     l_text = ls_vbep-ettyp.

     PERFORM add_text_val USING l_text

                          p_e_dyndoc_id.

     CALL METHOD p_e_dyndoc_id->new_line.

     CLEAR :l_text, l_gap.

   ENDIF.

   IF g_html_cntrl IS INITIAL .

     CREATE OBJECT g_html_cntrl

       EXPORTING

         parent = g_custom_container_1.

   ENDIF .

   CALL METHOD p_e_dyndoc_id->merge_document.

   p_e_dyndoc_id->html_control = g_html_cntrl.

   CALL METHOD p_e_dyndoc_id->display_document

     EXPORTING

       reuse_control      = ‘X’

       parent             = g_custom_container_1

     EXCEPTIONS

       html_display_error = 1.

ENDFORM.                    ” EVENT_TOP_OF_PAGE

*&———————————————————————*

*&      Form  add_gap

*&———————————————————————*

*       text

*———————————————————————-*

*      –>P_GAP      text

*      –>P_DOCUMENT text

*———————————————————————-*

FORM add_gap  USING p_gap TYPE i

                     p_document TYPE REF TO cl_dd_document.

   CALL METHOD p_document->add_gap

     EXPORTING

       width = p_gap.

ENDFORM.                    ” ADD_GAP

*&———————————————————————*

*&      Form  add_text

*&———————————————————————*

*       text

*———————————————————————-*

*      –>P_TEXT     text

*      –>P_DOCUMENT text

*———————————————————————-*

FORM add_text  USING p_text TYPE sdydo_text_element

                      p_document TYPE REF TO cl_dd_document.

   CALL METHOD p_document->add_text

     EXPORTING

       text          = p_text

       sap_fontsize  = cl_dd_area=>medium

       sap_fontstyle = cl_dd_area=>sans_serif

       sap_emphasis  = cl_dd_area=>strong.

ENDFORM.                    ” ADD_TEXT

*&———————————————————————*

*&      Form  add_text_val

*&———————————————————————*

*       text

*———————————————————————-*

*      –>P_TEXT     text

*      –>P_DOCUMENT text

*———————————————————————-*

FORM add_text_val  USING p_text TYPE sdydo_text_element

                          p_document TYPE REF TO cl_dd_document.

   CALL METHOD p_document->add_text

     EXPORTING

       text          = p_text

       sap_fontsize  = cl_dd_area=>medium

       sap_fontstyle = cl_dd_area=>sans_serif.

ENDFORM.                    ” ADD_TEXT_VAL


———————————————————————-*

***INCLUDE ZVARI_1629_O01 .

*———————————————————————-*

MODULE status_0100 OUTPUT.

   DATA:      l_variant                TYPE disvariant,

              lt_excluding             TYPE ui_functions.

   CONSTANTS: lc_zrvar_output_1629     TYPE dd02l-tabname VALUE ‘ZRVAR_OUTPUT_1629’,

              lc_a                     TYPE c VALUE ‘A’,

              lc_s                     TYPE c VALUE ‘S’.

* Calling GUI status

   SET PF-STATUS ‘ZVAR_1629’.

   SET TITLEBAR ‘ZVAR_1629’.

* User variant for the ALV layout

CLEAR: l_variant.

        l_variant-report = sy-repid.

        l_variant-handle = ‘MAIN’.

   IF gr_docking IS NOT BOUND.

     CREATE OBJECT gr_docking

       EXPORTING

         repid     = sy-repid

         dynnr     = sy-dynnr

*       RATIO     = ’95’.

         extension = 1600.

   ENDIF.

   IF g_splitter IS NOT BOUND.

     CREATE OBJECT g_splitter

       EXPORTING

         parent  = gr_docking

         rows    = 2

         columns = 1.

     CALL METHOD g_splitter->get_container

       EXPORTING

         row       = 1

         column    = 1

       RECEIVING

         container = g_custom_container_1.

** Lower Container

     CALL METHOD g_splitter->get_container

       EXPORTING

         row       = 2

         column    = 1

       RECEIVING

         container = g_custom_container_2.

     CALL METHOD g_splitter->set_row_height

       EXPORTING

         id     = 1

         height = 16.

   ENDIF.

* Create object for GRID

   IF g_grid_9000 IS NOT BOUND.

     CREATE OBJECT g_grid_9000

       EXPORTING

         i_parent = g_custom_container_2.

* Create object for CL_DD_DOCUMENT Class => contents of Header

     IF g_dd_document IS INITIAL.

       CREATE OBJECT g_dd_document.

     ENDIF.

* Create object for Local event Handler class

     IF g_event_reciever IS INITIAL.

       CREATE OBJECT g_event_reciever.

     ENDIF.

* Set handler method for event Top of Page

     SET HANDLER :

       g_event_reciever->handle_top_of_page FOR g_grid_9000.

     CALL METHOD g_grid_9000->list_processing_events

       EXPORTING

         i_event_name  = ‘TOP_OF_PAGE’

         i_dyndoc_id   = g_dd_document

         i_table_index = 1.

*Setting Layout

     gs_layout-sel_mode     = lc_a.

     gs_layout-cwidth_opt   = abap_true.

*creating Field Catalogue

     CALL FUNCTION ‘LVC_FIELDCATALOG_MERGE’

       EXPORTING

         i_structure_name = lc_zrvar_output_1629

       CHANGING

         ct_fieldcat      = gt_fieldcat[].

* Modifying the Field catalogue

     PERFORM f_modify_field_catalogue CHANGING gt_fieldcat.

*exclude Function codes

     PERFORM f_exclude_fcode CHANGING lt_excluding.

*Displaying the ALV

     CALL METHOD g_grid_9000->set_table_for_first_display

       EXPORTING

         i_structure_name     = lc_zrvar_output_1629

         is_layout            = gs_layout

         i_save               = ‘U’

         is_variant           = l_variant

*        i_buffer_active      = ‘ ‘

*        i_default            = ‘ ‘

*        i_bypassing_buffer   = ‘ ‘

         it_toolbar_excluding = lt_excluding

       CHANGING

         it_fieldcatalog      = gt_fieldcat[]

         it_outtab            = gt_output.

   ELSE.

     CALL METHOD g_grid_9000->refresh_table_display.

   ENDIF.

ENDMODULE.                 ” STATUS_0100  OUTPUT


*—————————————————————————*

***INCLUDE ZVARI_1629_I01 .

*—————————————————————————*

MODULE user_command_0100 INPUT.

*Declaring constants

   CONSTANTS: lc_1   TYPE char1 VALUE ‘1’,

              lc_9   TYPE char1 VALUE ‘9’,

              lc_all TYPE char4 VALUE ‘&ALL’,

              lc_sal TYPE char4 VALUE ‘&SAL’,

              lc_st9 TYPE char4 VALUE ‘&ST9’,

              lc_st1 TYPE char4 VALUE ‘&ST1’,

              lc_dbo TYPE char4 VALUE ‘&DBO’,

              lc_x   TYPE c     VALUE ‘X’.

   CASE ok_code.

*Select All

     WHEN lc_all.

       LOOP AT gt_output ASSIGNING <gfs_output>.

         <gfs_output>-checkbox = lc_x.

       ENDLOOP.

       CALL METHOD g_grid_9000->refresh_table_display.

*Deselect All

     WHEN lc_sal.

       LOOP AT gt_output ASSIGNING <gfs_output>.

         CLEAR <gfs_output>-checkbox.

       ENDLOOP.

       CALL METHOD g_grid_9000->refresh_table_display.

* changing the status to 9

     WHEN lc_st9.

       CALL METHOD g_grid_9000->check_changed_data.

       PERFORM f_change_status USING gt_output lc_9.

       CALL METHOD g_grid_9000->refresh_table_display.

*changing the status to 1

     WHEN lc_st1.

       CALL METHOD g_grid_9000->check_changed_data.

       PERFORM f_change_status USING gt_output lc_1.

       CALL METHOD g_grid_9000->refresh_table_display.

*Deleting Order BOM

     WHEN lc_dbo.

       CALL METHOD g_grid_9000->check_changed_data.

       PERFORM f_delete_order_bom USING gt_output.

       CALL METHOD g_grid_9000->refresh_table_display.

   ENDCASE.

   CLEAR ok_code.

ENDMODULE.                 ” USER_COMMAND_0100  INPUT

*&———————————————————————*

*&      Module  EXIT  INPUT

*&———————————————————————*

*       text

*———————————————————————-*

MODULE exit INPUT.

   CONSTANTS: lc_back TYPE char4 VALUE ‘BACK’,

             lc_ex   TYPE char3 VALUE ‘%EX’,

             lc_rw   TYPE char2 VALUE ‘RW’.

*When exit button is pressed

   CASE ok_code.

     WHEN lc_back OR lc_ex OR lc_rw.

       LEAVE TO SCREEN 0.

   ENDCASE.

ENDMODULE.                 ” EXIT  INPUT

To report this post you need to login first.

Be the first to leave a comment

You must be Logged on to comment or reply to a post.

Leave a Reply