Vous êtes sur la page 1sur 7

TABLES : mara.

*--------------------------------------------------------------------* Types Declaration..


*--------------------------------------------------------------------TYPES :
BEGIN OF t_mara,
matnr TYPE matnr,
mtart TYPE mtart,
maktx TYPE maktx,
END OF t_mara,
BEGIN OF t_marc,
matnr TYPE matnr,
werks TYPE werks_d,
mtart TYPE mtart,
maktx TYPE maktx,
END OF t_marc.
*--------------------------------------------------------------------* Internal Tables Declaration..
*--------------------------------------------------------------------DATA :
i_mara TYPE TABLE OF t_mara,
i_marc TYPE TABLE OF t_marc,
i_fcat1 TYPE lvc_t_fcat,
i_fcat2 TYPE lvc_t_fcat.
*--------------------------------------------------------------------* Constants Declaration..
*--------------------------------------------------------------------CONSTANTS :
c_cont1 TYPE scrfname VALUE 'HEAD_DPLY',
c_cont2 TYPE scrfname VALUE 'DETAIL_DPLY'.
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME.
SELECT-OPTIONS:
s_matnr FOR mara-matnr NO INTERVALS.
SELECTION-SCREEN SKIP 1.
PARAMETERS :
p_hotspt RADIOBUTTON GROUP r1 DEFAULT 'X',
p_bttn RADIOBUTTON GROUP r1.
SELECTION-SCREEN END OF BLOCK b1.
* Class forward referncing.
CLASS lcl_rcvr_class DEFINITION DEFERRED.
*---------------------------------------------------------------------* Pointers Declaration..
*---------------------------------------------------------------------DATA :
lp_rcvr TYPE REF TO lcl_rcvr_class,
lp_cont1 TYPE REF TO cl_gui_custom_container,
lp_cont2 TYPE REF TO cl_gui_custom_container,
lp_grid1 TYPE REF TO cl_gui_alv_grid,
lp_grid2 TYPE REF TO cl_gui_alv_grid.
*---------------------------------------------------------------------* Local Class Definiton.
*---------------------------------------------------------------------CLASS lcl_rcvr_class DEFINITION.
PUBLIC SECTION.
METHODS :
hotspot_click FOR EVENT hotspot_click OF cl_gui_alv_grid
IMPORTING e_row_id e_column_id es_row_no,

handle_double_click FOR EVENT double_click OF cl_gui_alv_grid


IMPORTING e_row e_column.
ENDCLASS.
"lcl_rcvr_class DEFINITION
*---------------------------------------------------------------------* Local Class Implementation.
*---------------------------------------------------------------------CLASS lcl_rcvr_class IMPLEMENTATION.
METHOD hotspot_click.
DATA :
wa_mara TYPE t_mara,
wa_marc TYPE t_marc.
DATA :
l_index TYPE sy-tabix.
READ TABLE i_mara INTO wa_mara INDEX e_row_id-index.
IF sy-subrc EQ 0.
REFRESH i_marc.
SELECT matnr
werks
INTO TABLE i_marc
FROM marc
WHERE matnr EQ wa_mara-matnr.
IF sy-subrc EQ 0.
LOOP AT i_marc INTO wa_marc.
l_index = sy-tabix.
wa_marc-mtart = wa_mara-mtart.
wa_marc-maktx = wa_mara-maktx.
MODIFY i_marc FROM wa_marc INDEX l_index
TRANSPORTING mtart maktx.
ENDLOOP.
CALL SCREEN 200.
ELSE.
"MESSAGE e121 WITH text-005 wa_mara-matnr.
ENDIF.
ENDIF.
ENDMETHOD.

"hotspot_click

METHOD handle_double_click.
DATA :
wa_mara TYPE t_mara,
wa_marc TYPE t_marc.
DATA :
l_index TYPE sy-tabix.
READ TABLE i_mara INTO wa_mara INDEX e_row-index.
IF sy-subrc EQ 0.
REFRESH i_marc.
SELECT matnr
werks
INTO TABLE i_marc
FROM marc
WHERE matnr EQ wa_mara-matnr.
IF sy-subrc EQ 0.
LOOP AT i_marc INTO wa_marc.
l_index = sy-tabix.

wa_marc-mtart = wa_mara-mtart.
wa_marc-maktx = wa_mara-maktx.
MODIFY i_marc FROM wa_marc INDEX l_index
TRANSPORTING mtart maktx.
ENDLOOP.
CALL SCREEN 200.
ELSE.
"MESSAGE e121 WITH text-005 wa_mara-matnr.
ENDIF.
ENDIF.
ENDMETHOD.
"handle_double_click
ENDCLASS.
"lcl_rcvr_class IMPLEMENTATION
*---------------------------------------------------------------------* Start of Selection
*---------------------------------------------------------------------START-OF-SELECTION.
* Extract the Material Master data for the Input Material.
SELECT a~matnr
a~mtart
b~maktx
INTO TABLE i_mara
FROM mara AS a
INNER JOIN makt AS b
ON a~matnr EQ b~matnr
WHERE a~matnr IN s_matnr
AND b~spras EQ sy-langu.
END-OF-SELECTION.
IF NOT i_mara[] IS INITIAL.
* Call Screen to display the Material Master data.
CALL SCREEN 100.
ELSE.
"MESSAGE s121 WITH text-006.
ENDIF.
*&---------------------------------------------------------------------*
*& Module DISP_GRID OUTPUT (SE DEBE COLOCAR EN EL PBO DE LA PANTALLA 100)
*&---------------------------------------------------------------------*
MODULE disp_grid OUTPUT.
* Build the Field catelog for Material Master data.
PERFORM build_fcat.
* Display the Material Master data using ALV.
PERFORM disp_alv.
ENDMODULE. " DISP_GRID OUTPUT
*&---------------------------------------------------------------------*
*& Module USER_COMMAND_0100 INPUT
*&---------------------------------------------------------------------*
MODULE user_command_0100 INPUT.
*when exit or cancel is clicked program has to come out
CASE sy-ucomm.
WHEN 'EXIT' OR 'CANC'.
LEAVE PROGRAM.
WHEN 'BACK'.
LEAVE TO SCREEN 0.
ENDCASE.
ENDMODULE. " USER_COMMAND_0100 INPUT
*&---------------------------------------------------------------------*

*& Form build_fcat


*&---------------------------------------------------------------------*
FORM build_fcat.
DATA : ws_fcat TYPE lvc_s_fcat.
ws_fcat-fieldname = 'MATNR'.
ws_fcat-scrtext_m = text-001.
ws_fcat-tabname = 'I_MARA'.
IF p_hotspt EQ 'X'.
ws_fcat-hotspot = 'X'.
ENDIF.
APPEND ws_fcat TO i_fcat1.
CLEAR ws_fcat.
ws_fcat-fieldname
ws_fcat-scrtext_m
ws_fcat-tabname =
APPEND ws_fcat TO
CLEAR ws_fcat.

= 'MTART'.
= text-002.
'I_MARA'.
i_fcat1.

ws_fcat-fieldname
ws_fcat-scrtext_m
ws_fcat-tabname =
APPEND ws_fcat TO
CLEAR ws_fcat.

= 'MAKTX'.
= text-003.
'I_MARA'.
i_fcat1.

ENDFORM. " build_fcat


*&---------------------------------------------------------------------*
*& Form disp_alv
*&---------------------------------------------------------------------*
FORM disp_alv.
IF lp_cont1 IS INITIAL.
* Create the Container Object of Material Master.
CREATE OBJECT lp_cont1
EXPORTING
container_name
= c_cont1
EXCEPTIONS
cntl_error
= 1
cntl_system_error
= 2
create_error
= 3
lifetime_error
= 4
lifetime_dynpro_dynpro_link = 5
OTHERS
= 6.
IF sy-subrc NE 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ELSE.
* Create the Object for Grid of Material Master.
CREATE OBJECT lp_grid1
EXPORTING
i_parent
= lp_cont1
EXCEPTIONS
error_cntl_create = 1
error_cntl_init = 2
error_cntl_link = 3
error_dp_create = 4
OTHERS
= 5.
IF sy-subrc NE 0.

MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno


WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ELSE.
* Dipslay Material Master data by calling method.
CALL METHOD lp_grid1->set_table_for_first_display
CHANGING
it_outtab
= i_mara
it_fieldcatalog
= i_fcat1
EXCEPTIONS
invalid_parameter_combination = 1
program_error
= 2
too_many_lines
= 3
OTHERS
= 4.
IF sy-subrc NE 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ELSE.
* Set Handler for the Hot Spot Event.
CREATE OBJECT lp_rcvr.
IF p_hotspt EQ 'X'.
SET HANDLER lp_rcvr->hotspot_click FOR lp_grid1.
ELSE.
SET HANDLER lp_rcvr->handle_double_click FOR lp_grid1.
ENDIF.
ENDIF.
ENDIF.
ENDIF.
ENDIF.
ENDFORM. " disp_alv
*&---------------------------------------------------------------------*
*& Module STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
MODULE status_0100 OUTPUT.
"SET PF-STATUS 'MAIN_STAT'.
"SET TITLEBAR 'T_100'.
ENDMODULE. " STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
*& Module STATUS_0200 OUTPUT
*&---------------------------------------------------------------------*
MODULE status_0200 OUTPUT.
"SET PF-STATUS 'PLANT_STAT'.
"SET TITLEBAR 'T_200'.
ENDMODULE. " STATUS_0200 OUTPUT
*&---------------------------------------------------------------------*
*& Module DISP_GRID_plant OUTPUT (SE DEBE COLOCAR EN EL PBO DE LA PANTALLA 200)
*&---------------------------------------------------------------------*
MODULE disp_grid_plant OUTPUT.
* Build the Field catelog for Material Plant data.
PERFORM build_fcat_plant.
* Display the Material Master Plant data using ALV.
PERFORM disp_alv_plant.
ENDMODULE. " DISP_GRID_plant OUTPUT
*&---------------------------------------------------------------------*
*& Module USER_COMMAND_0200 INPUT
*&---------------------------------------------------------------------*
MODULE user_command_0200 INPUT.
*when exit or cancel is clicked program has to come out
CASE sy-ucomm.

WHEN 'EXIT' OR 'CANC'.


LEAVE PROGRAM.
WHEN 'BACK'.
LEAVE TO SCREEN 0.
ENDCASE.
ENDMODULE. " USER_COMMAND_0200 INPUT
*&---------------------------------------------------------------------*
*& Form build_fcat_plant
*&---------------------------------------------------------------------*
FORM build_fcat_plant.
DATA : ws_fcat TYPE lvc_s_fcat.
ws_fcat-fieldname
ws_fcat-scrtext_m
ws_fcat-tabname =
APPEND ws_fcat TO
CLEAR ws_fcat.

= 'MATNR'.
= text-001.
'I_MARC'.
i_fcat2.

ws_fcat-fieldname
ws_fcat-scrtext_m
ws_fcat-tabname =
APPEND ws_fcat TO
CLEAR ws_fcat.

= 'WERKS'.
= text-004.
'I_MARC'.
i_fcat2.

ws_fcat-fieldname
ws_fcat-scrtext_m
ws_fcat-tabname =
APPEND ws_fcat TO
CLEAR ws_fcat.

= 'MTART'.
= text-002.
'I_MARC'.
i_fcat2.

ws_fcat-fieldname
ws_fcat-scrtext_m
ws_fcat-tabname =
APPEND ws_fcat TO
CLEAR ws_fcat.

= 'MAKTX'.
= text-003.
'I_MARC'.
i_fcat2.

ENDFORM. " build_fcat_plant


*&---------------------------------------------------------------------*
*& Form disp_alv_plant
*&---------------------------------------------------------------------*
FORM disp_alv_plant.
IF lp_cont2 IS INITIAL.
* Create the Container Object of Material Plant data.
CREATE OBJECT lp_cont2
EXPORTING
container_name
= c_cont2
EXCEPTIONS
cntl_error
= 1
cntl_system_error
= 2
create_error
= 3
lifetime_error
= 4
lifetime_dynpro_dynpro_link = 5
OTHERS
= 6.
IF sy-subrc NE 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ELSE.
* Create the Object for Grid of Material Plant data.
CREATE OBJECT lp_grid2

EXPORTING
i_parent
= lp_cont2
EXCEPTIONS
error_cntl_create = 1
error_cntl_init = 2
error_cntl_link = 3
error_dp_create = 4
OTHERS
= 5.
IF sy-subrc NE 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ELSE.
* Display Material Plant data by calling method.
CALL METHOD lp_grid2->set_table_for_first_display
CHANGING
it_outtab
= i_marc
it_fieldcatalog
= i_fcat2
EXCEPTIONS
invalid_parameter_combination = 1
program_error
= 2
too_many_lines
= 3
OTHERS
= 4.
IF sy-subrc NE 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
ENDIF.
ENDIF.
ELSE.
* Call method 'REFRESH_TABLE_DISPLAY' to refresh the grid data.
CALL METHOD lp_grid2->refresh_table_display.
ENDIF.
ENDFORM. " disp_alv_plant

Vous aimerez peut-être aussi