Autor Tema: Reporte para Mostrar el Detalle de los Materiales Configurables  (Leído 5015 veces)

0 Usuarios y 1 Visitante están viendo este tema.

Desconectado Enrique.Borroni

  • Moderador_
  • Usuario Completo
  • *****
  • Mensajes: 86
    • Ver Perfil
Reporte para Mostrar el Detalle de los Materiales Configurables
« en: 08 de Agosto de 2009, 09:41:52 am »
Este reporte es un ejemplo de como obtener los detalles de configuracion de los Materiales
del Tipo Configurables...

Elementos de Textos para el Programa :

* Elementos de Texto
* ----------------------------
* I002     Material configurable
* I004     Página
* I006     Ce.:
* I102     Centro
* I103     Denominación
* I111     Característica
* I112     Valor

* Textos de Seleccion
* -----------------------------------
* SPM_CONFG        Visualizar valoración
* SPM_DATUM        Fecha
* SPM_STDPD        Material configurable
* SPM_WERKS        Centro




REPORT Y_REPO_MAT_CONFIGURABLE.
MESSAGE-ID cu
        NO STANDARD PAGE HEADING
        LINE-SIZE 80.
TABLES :
         conf_out,
         makt,
         mara,
         marc,
         mava1,
         mtcom,
         pgmi,
         sscrfields.

PARAMETERS :
         pm_stdpd LIKE mara-matnr   MEMORY ID mat MATCHCODE OBJECT mat1,
         pm_werks LIKE marc-werks,
         pm_datum LIKE cabn-datuv    DEFAULT sy-datum,
         pm_confg LIKE rmclre-rmerka DEFAULT space,
         pm_slmod TYPE c             NO-DISPLAY.


DATA:
  printing(1) TYPE c,
  configuration LIKE conf_out OCCURS 0 WITH HEADER LINE.


DATA :  BEGIN OF cincl.
        INCLUDE STRUCTURE incl_bild.
DATA :  END OF cincl,
         BEGIN OF cwind.
        INCLUDE STRUCTURE linerow.
DATA :   END OF cwind,
         object_found TYPE c,
         object_done TYPE c,
         BEGIN OF xmakt OCCURS 0,
           matnr LIKE makt-matnr,
           maktx LIKE makt-maktx,
         END OF xmakt,
         BEGIN OF xpgmi OCCURS 0,
           nrmit LIKE pgmi-nrmit,
           werks LIKE pgmi-werks,
           wemit LIKE pgmi-wemit,
         END OF xpgmi,
         BEGIN OF xxx OCCURS 0,
           x,
         END OF xxx,

         frame_size LIKE sy-linsz,
         len_matnr LIKE sy-fdpos,
         len_maktx LIKE sy-fdpos,
         len_werks LIKE sy-fdpos,
         len_atbez LIKE sy-fdpos,
         len_atwtb LIKE sy-fdpos,
         xposition LIKE sy-fdpos,
         xtext     LIKE sy-lisel,
         ytext     LIKE sy-lisel.

FIELD-SYMBOLS:
         <xtext>, <ytext>.

CONSTANTS :
         mtcom_kenng_makt LIKE mtcom-kenng VALUE 'MAKT',
         mtcom_kenng_mava1 LIKE mtcom-kenng VALUE 'MAVA1',
         param_cux LIKE tpara-paramid VALUE 'CUX',
         param_wrk LIKE tpara-paramid VALUE 'WRK',
         pgtyp_s LIKE pgmi-pgtyp VALUE 'S',
         x TYPE c VALUE 'X'.

INITIALIZATION.
  DESCRIBE FIELD marc-matnr     LENGTH  len_matnr IN CHARACTER MODE.
  DESCRIBE FIELD marc-werks     LENGTH len_werks IN CHARACTER MODE.
  DESCRIBE FIELD makt-maktx     LENGTH len_maktx IN CHARACTER MODE.
  DESCRIBE FIELD conf_out-atbez LENGTH len_atbez IN CHARACTER MODE.
  DESCRIBE FIELD conf_out-atwtb LENGTH len_atwtb IN CHARACTER MODE.
  IF pm_confg IS INITIAL.
    frame_size = len_matnr + len_werks + len_maktx + 4.
  ELSE.
    frame_size = len_atbez + len_atwtb + 3.
  ENDIF.

  GET PARAMETER ID param_wrk FIELD pm_werks.

AT SELECTION-SCREEN.
  IF pm_confg IS INITIAL.
    frame_size = len_matnr + len_werks + len_maktx + 4.
  ELSE.
    frame_size = len_atbez + len_atwtb + 3.
  ENDIF.
  PERFORM header_prepare.
  CLEAR printing.
  IF sscrfields-ucomm = 'PRIN'.
    NEW-PAGE LINE-COUNT 65.
    printing = 'X'.
  ENDIF.

START-OF-SELECTION.
  SET PF-STATUS 'ZSTATUS'.
  PERFORM types_select.
  PERFORM types_prepare.

END-OF-SELECTION.
  PERFORM show_result.

TOP-OF-PAGE.
  PERFORM print_header.

TOP-OF-PAGE DURING LINE-SELECTION.
  PERFORM print_header.

AT LINE-SELECTION.
  IF pm_slmod IS INITIAL.
    PERFORM display_configuration_marc.
  ELSE.
    PERFORM select_configuration.
  ENDIF.

AT USER-COMMAND.
  CASE sy-ucomm.
    WHEN 'PRIN'.
      NEW-PAGE PRINT ON NEW-SECTION LINE-COUNT 65.
      printing = 'X'.
      PERFORM show_result.
      CLEAR printing.
    WHEN OTHERS.
      LEAVE.
  ENDCASE.

*---------------------------------------------------------------------*
*       FORM TYPES_LIST_WITH_CONFIG                                   *
*---------------------------------------------------------------------*
FORM types_list_with_config.

  DATA:
    xlen LIKE sy-fdpos.

  FORMAT COLOR COL_NORMAL INTENSIFIED OFF.

  NEW-PAGE.
  SORT xpgmi BY nrmit werks wemit.
  LOOP AT xpgmi.
    CLEAR object_done.
    RESERVE 8 LINES.
    object_found = x.
    READ TABLE xmakt WITH KEY xpgmi-nrmit.

    FORMAT COLOR COL_BACKGROUND INTENSIFIED OFF.

    xlen = STRLEN( text-005 ) + 3.
    WRITE: /2 text-005    COLOR COL_BACKGROUND INTENSIFIED ON.
    POSITION xlen.
    WRITE:    xpgmi-nrmit COLOR COL_BACKGROUND INTENSIFIED OFF,
              xmakt-maktx COLOR COL_BACKGROUND INTENSIFIED OFF.
    WRITE: /2 text-006    COLOR COL_BACKGROUND INTENSIFIED ON.
    POSITION xlen.
    WRITE:    xpgmi-wemit COLOR COL_BACKGROUND INTENSIFIED OFF.
    SKIP 1.

    PERFORM print_box.
    object_done = 'X'.

    FORMAT COLOR COL_NORMAL INTENSIFIED OFF.

    PERFORM get_all_configuration_data TABLES configuration.
    LOOP AT configuration.
      PERFORM check_bottom_of_page.
      PERFORM set_margins.
      POSITION 2.
      WRITE: configuration-atbez.
      xposition = len_atbez + 3.
      POSITION xposition.
      WRITE: configuration-atwtb.
    ENDLOOP.
    IF sy-subrc IS INITIAL.
      PERFORM set_uline_p.
    ENDIF.
  ENDLOOP.

  IF sy-subrc IS INITIAL.
    PERFORM set_uline_p.
  ELSE.
    IF pm_slmod IS INITIAL.
    ELSE.
      FORMAT COLOR COL_NEGATIVE.
      WRITE : /1 sy-vline.
      ytext = text-003.
      xposition = frame_size - 2.
      ASSIGN ytext(xposition) TO <ytext>.
      POSITION 2.
      WRITE <ytext>.
      POSITION frame_size.
      WRITE sy-vline.
      PERFORM set_uline_p.
    ENDIF.
  ENDIF.
ENDFORM.                    "types_list_with_config

*---------------------------------------------------------------------*
*       FORM TYPES_LIST                                               *
*---------------------------------------------------------------------*
FORM types_list.

  FORMAT COLOR COL_NORMAL INTENSIFIED OFF.

  NEW-PAGE.

  SORT xpgmi BY nrmit werks wemit.
  LOOP AT xpgmi.
    PERFORM check_bottom_of_page.
    object_found = x.
    READ TABLE xmakt WITH KEY xpgmi-nrmit.
    PERFORM set_margins.
    POSITION 2.
    IF pm_slmod IS INITIAL.
      WRITE xpgmi-nrmit COLOR COL_KEY HOTSPOT ON.
    ELSE.
      WRITE xpgmi-nrmit COLOR COL_KEY.
    ENDIF.
    xposition = len_matnr + 3.
    POSITION xposition.
    IF pm_slmod IS INITIAL.
      WRITE xpgmi-wemit COLOR COL_KEY HOTSPOT ON.
    ELSE.
      WRITE xpgmi-wemit COLOR COL_KEY.
    ENDIF.
    xposition = xposition + len_werks + 1.
    POSITION xposition.
    WRITE xmakt-maktx COLOR COL_NORMAL.
    HIDE : xpgmi.
  ENDLOOP.

  IF sy-subrc IS INITIAL.
    PERFORM set_uline_p.
  ELSE.
    IF pm_slmod IS INITIAL.
    ELSE.
      FORMAT COLOR COL_NEGATIVE.
      WRITE : /1 sy-vline.
      ytext = text-003.
      xposition = frame_size - 2.
      ASSIGN ytext(xposition) TO <ytext>.
      POSITION 2.
      WRITE <ytext>.
      POSITION frame_size.
      WRITE sy-vline.
      PERFORM set_uline_p.
    ENDIF.
  ENDIF.
ENDFORM.                    "types_list

*---------------------------------------------------------------------*
*       FORM HEADER_PREPARE                                           *
*---------------------------------------------------------------------*
FORM header_prepare.
  PERFORM cf_material_read_mava.
ENDFORM.                    "header_prepare

*---------------------------------------------------------------------*
*       FORM TYPES_PREPARE                                            *
*---------------------------------------------------------------------*
FORM types_prepare.
  CLEAR xmakt.
  SORT xpgmi BY nrmit werks wemit.
  LOOP AT xpgmi.
    READ TABLE xmakt WITH KEY xpgmi-nrmit BINARY SEARCH.
    CASE sy-subrc.
      WHEN 4.
        xmakt-matnr = xpgmi-nrmit.
        INSERT xmakt INDEX sy-tabix.
      WHEN 8.
        xmakt-matnr = xpgmi-nrmit.
        APPEND xmakt.
    ENDCASE.
  ENDLOOP.
  LOOP AT xmakt.
    PERFORM cf_material_read_ma00.
    xmakt-maktx = makt-maktx.
    MODIFY xmakt.
  ENDLOOP.
ENDFORM.                    "types_prepare

*---------------------------------------------------------------------*
*       FORM TYPES_SELECT                                             *
*---------------------------------------------------------------------*
FORM types_select.
  CLEAR object_found.
  IF pm_werks IS INITIAL.
    SELECT * FROM pgmi WHERE pgtyp = pgtyp_s
                         AND prgrp = pm_stdpd.
      xpgmi-nrmit = pgmi-nrmit.
      xpgmi-wemit = pgmi-wemit.
      xpgmi-werks = pgmi-werks.
      APPEND xpgmi.
    ENDSELECT.
  ELSE.
    SELECT * FROM pgmi WHERE pgtyp = pgtyp_s
                         AND prgrp = pm_stdpd
                         AND werks = pm_werks.
      xpgmi-nrmit = pgmi-nrmit.
      xpgmi-wemit = pgmi-wemit.
      xpgmi-werks = pgmi-werks.
      APPEND xpgmi.
    ENDSELECT.
    SELECT * FROM pgmi WHERE pgtyp = pgtyp_s
                         AND prgrp = pm_stdpd
                         AND werks = space.
      xpgmi-nrmit = pgmi-nrmit.
      xpgmi-wemit = pgmi-wemit.
      xpgmi-werks = pgmi-werks.
      APPEND xpgmi.
    ENDSELECT.
  ENDIF.
ENDFORM.                    "types_select

*---------------------------------------------------------------------*
*       FORM CF_MATERIAL_READ_MA00                                    *
*---------------------------------------------------------------------*
FORM cf_material_read_ma00.
  CLEAR mtcom.
  mtcom-kenng = mtcom_kenng_makt.
  mtcom-matnr = xmakt-matnr.
  mtcom-spras = sy-langu.

  CALL FUNCTION 'MATERIAL_READ_MA00'
    EXPORTING
      schluessel         = mtcom
    IMPORTING
      matdaten           = makt
    TABLES
      seqmat01           = xxx
    EXCEPTIONS
      material_not_found = 4.

  IF sy-subrc <> 0.
    MESSAGE e703 WITH xmakt-matnr.
*   Todavía no se ha creado el artículo &
  ENDIF.
ENDFORM.                    "cf_material_read_ma00

*---------------------------------------------------------------------*
*       FORM CF_MATERIAL_READ_MAVA                                    *
*---------------------------------------------------------------------*
FORM cf_material_read_mava.
  CLEAR mtcom.
  mtcom-kenng = mtcom_kenng_mava1.
  mtcom-matnr = pm_stdpd.
  mtcom-spras = sy-langu.

  CALL FUNCTION 'MATERIAL_READ_MAVA'
    EXPORTING
      schluessel         = mtcom
    IMPORTING
      matdaten           = mava1
    TABLES
      seqmat01           = xxx
    EXCEPTIONS
      material_not_found = 4.

  IF sy-subrc <> 0.
    MESSAGE e703 WITH pm_stdpd.
*   Todavía no se ha creado el artículo &.
  ENDIF.
  IF mava1-kzkfg IS INITIAL.
    MESSAGE e704 WITH pm_stdpd.
*   No está previsto el artículo & para la configuración de variantes.
  ENDIF.
ENDFORM.                    "cf_material_read_mava

*---------------------------------------------------------------------*
*       FORM DISPLAY_CONFIGURATION_MARC.                              *
*---------------------------------------------------------------------*
*       Anzeige der Konfiguration zum Material                        *
*---------------------------------------------------------------------*
FORM display_configuration_marc.

  IF xpgmi-wemit IS INITIAL.
    SELECT SINGLE * FROM mara WHERE matnr = xpgmi-nrmit.
    marc-cuobj = mara-cuobf.
  ELSE.
    SELECT SINGLE * FROM marc WHERE matnr = xpgmi-nrmit
                                AND werks = xpgmi-wemit.
  ENDIF.

  CHECK sy-subrc = 0.

  CALL FUNCTION 'CUD0_CONFIGURATION_INITIALIZER'.

  CLEAR cincl.

  DATA: i_configuration LIKE  conf_out OCCURS 0 WITH HEADER LINE.
  DATA: i_configuration_idoc LIKE  api_value OCCURS 0 WITH HEADER LINE.
  DATA: i_mill_se_conf_no_idoc LIKE  conf_out OCCURS 0 WITH HEADER LINE.



  CALL FUNCTION 'VC_I_GET_CONFIGURATION'
    EXPORTING
      instance             = marc-cuobj
    TABLES
      configuration        = i_configuration
      configuration_idoc   = i_configuration_idoc
      mill_se_conf_no_idoc = i_mill_se_conf_no_idoc.
  IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.



ENDFORM.                    "display_configuration_marc

*---------------------------------------------------------------------*
*       FORM SELECT_CONFIGURATION                                     *
*---------------------------------------------------------------------*
FORM select_configuration.
  IF xpgmi-wemit IS INITIAL.
    SELECT SINGLE * FROM mara WHERE matnr = xpgmi-nrmit.
    CHECK sy-subrc = 0.
    SET PARAMETER ID param_cux FIELD mara-cuobf.
  ELSE.
    SELECT SINGLE * FROM marc WHERE matnr = xpgmi-nrmit
                                AND werks = xpgmi-wemit.
    CHECK sy-subrc = 0.
    SET PARAMETER ID param_cux FIELD marc-cuobj.
  ENDIF.
  LEAVE.
ENDFORM.                    "select_configuration

*---------------------------------------------------------------------*
*       FORM SET_ULINE_H                                              *
*---------------------------------------------------------------------*
FORM set_uline_h.
  ASSIGN sy-uline(frame_size) TO <xtext>.
  WRITE <xtext>.
ENDFORM.                    "set_uline_h

*---------------------------------------------------------------------*
*       FORM SET_ULINE_P                                              *
*---------------------------------------------------------------------*
FORM set_uline_p.
  ASSIGN sy-uline(frame_size) TO <ytext>.
  WRITE <ytext>.
ENDFORM.                    "set_uline_p

*---------------------------------------------------------------------*
*       FORM SET_MARGINS                                              *
*---------------------------------------------------------------------*
FORM set_margins.

  IF pm_confg IS INITIAL.
    WRITE : /1 sy-vline.
    xposition = len_matnr + 2.
    POSITION xposition.
    WRITE sy-vline.
    xposition = xposition + len_werks + 1.
    POSITION xposition.
    WRITE sy-vline.
    POSITION frame_size.
    WRITE sy-vline.
  ELSE.
    WRITE : /1 sy-vline.
    xposition = len_atbez + 2.
    POSITION xposition.
    WRITE sy-vline.
    POSITION frame_size.
    WRITE sy-vline.
  ENDIF.

ENDFORM.                    "set_margins

*----------------------------------------------------------------------*
* print the header of each page                                        *
*----------------------------------------------------------------------*
FORM print_header.

  DATA:
    xlen LIKE sy-fdpos,
    pagno(10) TYPE c.

  FORMAT COLOR COL_BACKGROUND INTENSIFIED ON.

  pagno = sy-pagno.
  SHIFT pagno LEFT DELETING LEADING ' '.

  WRITE: /2 text-001.
  IF NOT ( printing IS INITIAL ).
    WRITE: 59 text-004, pagno, 70 sy-datum.
  ENDIF.

  SKIP 1.

  WRITE: /2 text-002    COLOR COL_BACKGROUND INTENSIFIED ON,
            pm_stdpd    COLOR COL_BACKGROUND INTENSIFIED OFF,
            mava1-maktx COLOR COL_BACKGROUND INTENSIFIED OFF.
  SKIP 1.

  IF NOT ( pm_confg IS INITIAL ).
    CHECK NOT ( object_done IS INITIAL ).
    xlen = STRLEN( text-005 ) + 3.
    WRITE: /2 text-005    COLOR COL_BACKGROUND INTENSIFIED ON.
    POSITION xlen.
    WRITE:    xpgmi-nrmit COLOR COL_BACKGROUND INTENSIFIED OFF,
              xmakt-maktx COLOR COL_BACKGROUND INTENSIFIED OFF.
    WRITE: /2 text-006    COLOR COL_BACKGROUND INTENSIFIED ON.
    POSITION xlen.
    WRITE:    xpgmi-wemit COLOR COL_BACKGROUND INTENSIFIED OFF.
    SKIP 1.
  ENDIF.

  PERFORM print_box.

ENDFORM.                    "print_header

*----------------------------------------------------------------------*
* print box                                                            *
*----------------------------------------------------------------------*
FORM print_box.

  FORMAT COLOR COL_HEADING INTENSIFIED ON.

  PERFORM set_uline_h.
  CHECK NOT ( object_found IS INITIAL ).
  PERFORM set_margins.

  IF pm_confg IS INITIAL.
    xtext = text-101.
    ASSIGN xtext(len_matnr) TO <xtext>.
    POSITION 2.
    WRITE <xtext> COLOR COL_HEADING INVERSE OFF.

    xtext = text-102.
    ASSIGN xtext(len_werks) TO <xtext>.
    xposition = len_matnr + 3.
    POSITION xposition.
    WRITE <xtext> COLOR COL_HEADING INVERSE OFF.

    xtext = text-103.
    ASSIGN xtext(len_maktx) TO <xtext>.
    xposition = xposition + len_werks + 1.
    POSITION xposition.
    WRITE <xtext> COLOR COL_HEADING INVERSE OFF.
  ELSE.
    xtext = text-111.
    ASSIGN xtext(30) TO <xtext>.
    POSITION 2.
    WRITE <xtext> COLOR COL_HEADING INVERSE OFF.

    xtext = text-112.
    ASSIGN xtext(30) TO <xtext>.
    xposition = len_atbez + 3.
    POSITION xposition.
    WRITE <xtext> COLOR COL_HEADING INVERSE OFF.
  ENDIF.

  PERFORM set_uline_h.

  FORMAT COLOR COL_NORMAL INTENSIFIED OFF.

ENDFORM.                    "print_box

*----------------------------------------------------------------------*
* check for bottom of page                                             *
*----------------------------------------------------------------------*
FORM check_bottom_of_page.

  DATA:
    row TYPE i.

  row = sy-linno + 1.
  IF row EQ sy-linct.
    PERFORM set_uline_p.
  ENDIF.

ENDFORM.                    "check_bottom_of_page

*----------------------------------------------------------------------*
* get all configuration data                                           *
*----------------------------------------------------------------------*
FORM get_all_configuration_data
     TABLES configuration STRUCTURE conf_out.

  DATA:
    instance LIKE inob-cuobj.

  CLEAR configuration. REFRESH configuration.

  IF xpgmi-wemit IS INITIAL.
    SELECT SINGLE * FROM mara WHERE matnr = xpgmi-nrmit.
    CHECK sy-subrc = 0.
    instance = mara-cuobf.
  ELSE.
    SELECT SINGLE * FROM marc WHERE matnr = xpgmi-nrmit
                                AND werks = xpgmi-wemit.
    CHECK sy-subrc = 0.
    instance = marc-cuobj.
  ENDIF.

  CALL FUNCTION 'VC_I_GET_CONFIGURATION'
    EXPORTING
      instance           = instance
    TABLES
      configuration      = configuration
    EXCEPTIONS
      instance_not_found = 0.

ENDFORM.                    "get_all_configuration_data

*----------------------------------------------------------------------*
* show result                                                          *
*----------------------------------------------------------------------*
FORM show_result.

  IF pm_confg IS INITIAL.
    PERFORM types_list.
  ELSE.
    PERFORM types_list_with_config.
  ENDIF.

ENDFORM.                    "show_result

Saludos.

Atte.,
Enrique Borroni

maito : enrique.borroni@abap.es