Translate

Monday, 30 July 2012

Change Inspection type Details in Material Master Change MM02

BDC Program for Change Inspection type Details in Material Master Data.

REPORT  ZBDC_MM02_QCVIEW_03022010.

TABLES : MARA , QMAT  .

DATA: BEGIN OF RECORD OCCURS 0,
        MATNR LIKE MARA-MATNR,    " Material No
        MTART LIKE MARA-MTART,
        ART   LIKE QMAT-ART,
        VIEWCNT(2TYPE C,
        REC(10TYPE C, " LIKE SY-DBCNT,
       END OF RECORD.

DATA: BEGIN OF ITAB OCCURS 0,
        MATNR LIKE MARA-MATNR,    " Material No
        MTART LIKE MARA-MTART,
        ART   LIKE QMAT-ART,
        VIEWCNT(2TYPE C,
        REC(10TYPE C, " LIKE SY-DBCNT,
       END OF ITAB.

DATA : BDCDATA LIKE BDCDATA OCCURS WITH HEADER LINE.
DATA : D_FILE TYPE RLGRAP-FILENAME.
DATA : MSG     LIKE BDCMSGCOLL OCCURS WITH HEADER LINE,
       TEXT(40).
DATA : OPN TYPE VORNR.
DATA : LT_BTCI TYPE STANDARD TABLE OF BDCDATA WITH HEADER LINE.
TYPES:FS_STRUCT(4096TYPE OCCURS 0 .
DATA: W_STRUCT TYPE FS_STRUCT.

SELECTION-SCREEN : SKIP 3.
SELECTION-SCREEN : BEGIN OF BLOCK BLK WITH FRAME TITLE T1.
SELECTION-SCREEN : SKIP 1.
SELECTION-SCREEN : SKIP.
PARAMETERS       : P_FILE TYPE RLGRAP-FILENAME.
*SELECT-OPTIONS : MATNR1 FOR MARA-MATNR NO INTERVALS.
SELECTION-SCREEN : SKIP.
PARAMETERS       : ART1 LIKE QMAT-ART.
*SELECT-OPTIONS : MTART1 FOR MARA-MTART NO-EXTENSION NO INTERVALS.
SELECTION-SCREEN : SKIP.
SELECTION-SCREEN : END OF BLOCK BLK.

SELECTION-SCREEN : BEGIN OF BLOCK BLK1 WITH FRAME NO INTERVALS.
*SELECTION-SCREEN : COMMENT /1(70) COM1 MODIF ID MG1.
SELECTION-SCREEN : SKIP 1.
PARAMETERS : MODE TYPE CTU_PARAMS-DISMODE DEFAULT 'A' ."MODIF ID MG1.
SELECTION-SCREEN : SKIP.
SELECTION-SCREEN : END OF BLOCK BLK1.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FILE.
  CALL FUNCTION 'F4_FILENAME'
   EXPORTING
     PROGRAM_NAME        SYST-CPROG
     DYNPRO_NUMBER       SYST-DYNNR
*   FIELD_NAME          = ' '
   IMPORTING
     FILE_NAME           P_FILE.

INITIALIZATION.
*  COM1 = 'Text file --->   * Material No  '.
  T1   'BDC to change QCVIEW by MM02 '.
  LOOP AT SCREEN.
    IF SCREEN-GROUP1 'MG1'.
      SCREEN-INTENSIFIED '1'.
      SCREEN-DISPLAY_3D  '1'.
      MODIFY SCREEN.
    ENDIF.
  ENDLOOP.

START-OF-SELECTION.



  IF NOT P_FILE IS INITIAL.
    D_FILE P_FILE.
  ENDIF.

  CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'
    EXPORTING
     I_FIELD_SEPERATOR          'X'
*     I_LINE_HEADER              =
      I_TAB_RAW_DATA             W_STRUCT
      I_FILENAME                 D_FILE
    TABLES
      I_TAB_CONVERTED_DATA       RECORD
*   EXCEPTIONS
*     CONVERSION_FAILED          = 1
*     OTHERS                     = 2
            .
  IF SY-SUBRC <> 0.
* Implement suitable error handling here
  ENDIF.
  SORT RECORD BY MATNR.

DATA : LV_DYTXT(30TYPE C,
       LV_KZSEL(30TYPE C,
       LV_CNT(2TYPE C.

  SELECT MATNR ART FROM QMAT INTO CORRESPONDING FIELDS OF TABLE ITAB
       WHERE WERKS 'HIP' .
       IF SY-SUBRC 0.
       ENDIF.
    SORT ITAB.

  LOOP AT RECORD.
    SELECT SINGLE MTART FROM MARA INTO RECORD-MTART
       WHERE MATNR RECORD-MATNR.
       MODIFY RECORD.
   ENDLOOP.

**********************************************************
DATA : R1 LIKE SY-DBCNT.
R1 0.
  LOOP AT RECORD.
     LOOP AT ITAB WHERE MATNR RECORD-MATNR.
      AT NEW MATNR.
       R1 0.
      ENDAT.
      R1 R1 + 1.
      MOVE R1 TO RECORD-REC.
      CONDENSE RECORD-REC.
      MODIFY RECORD.
      MOVE R1 TO ITAB-REC.
      CONDENSE ITAB-REC.
      MOVE RECORD-MTART TO ITAB-MTART.
      MODIFY ITAB.
   ENDLOOP.
 ENDLOOP.

DELETE ITAB WHERE ART <> ART1 OR REC IS INITIAL ).

**********************************************************
LOOP AT ITAB.
CALL FUNCTION 'MATERIAL_BTCI_SELECTION_NEW'
EXPORTING
MATERIAL    ITAB-MATNR
MATERIALART ITAB-MTART
SELECTION 'Q'
TCODE 'MM02'
TABLES
BTCI_D0070 LT_BTCI.

READ TABLE LT_BTCI WITH KEY FVAL 'X'.
IF SY-SUBRC 0.
LV_CNT LT_BTCI-FNAM+17(2).
ENDIF.
MOVE LV_CNT TO ITAB-VIEWCNT.
MODIFY ITAB.
ENDLOOP.
**********************************************************

DATA : VTEXT3 TYPE STRING.
DATA : VTEXT4 TYPE STRING.

SORT ITAB BY MATNR REC VIEWCNT.

LOOP AT ITAB.

CONCATENATE 'MSICHTAUSW-DYTXT(' ITAB-VIEWCNT ')' INTO VTEXT3.
CONCATENATE 'MSICHTAUSW-KZSEL(' ITAB-VIEWCNT ')' INTO VTEXT4.

PERFORM BDC_DYNPRO      USING 'SAPLMGMM' '0060'.
PERFORM BDC_FIELD       USING 'BDC_CURSOR'
                              'RMMG1-MATNR'.
PERFORM BDC_FIELD       USING 'BDC_OKCODE'
                              '=AUSW'.
PERFORM BDC_FIELD       USING 'RMMG1-MATNR'
                               ITAB-MATNR. " 'A06400250080F000'.
PERFORM BDC_DYNPRO      USING 'SAPLMGMM' '0070'.
PERFORM BDC_FIELD       USING 'BDC_CURSOR'
                               VTEXT3 .     " 'MSICHTAUSW-DYTXT(08)'.
PERFORM BDC_FIELD       USING 'BDC_OKCODE'
                              '=ENTR'.
PERFORM BDC_FIELD       USING  VTEXT4      " 'MSICHTAUSW-KZSEL(08)'
                              'X'.
PERFORM BDC_DYNPRO      USING 'SAPLMGMM' '0080'.
PERFORM BDC_FIELD       USING 'BDC_CURSOR'
                              'RMMG1-WERKS'.
PERFORM BDC_FIELD       USING 'BDC_OKCODE'
                              '=ENTR'.
PERFORM BDC_FIELD       USING 'RMMG1-WERKS'
                              'hip'.
PERFORM BDC_DYNPRO      USING 'SAPLMGMM' '4000'.
PERFORM BDC_FIELD       USING 'BDC_OKCODE'
                              '=PB01'.

IF ITAB-ART '01'.
PERFORM BDC_FIELD       USING 'BDC_CURSOR'
                              'MARC-QMATV'.
*perform bdc_field       using 'MARA-MEINS'
*                              'EA'.
PERFORM BDC_FIELD       USING 'MARC-WEBAZ'
                              '5'.
PERFORM BDC_FIELD       USING 'MARA-QMPUR'
                              'X'.
PERFORM BDC_FIELD       USING 'MARC-SSQSS'
                              '0001'.
ENDIF.

IF ITAB-REC '1'.
PERFORM BDC_DYNPRO      USING 'SAPLQPLS' '0100'.
PERFORM BDC_FIELD       USING 'BDC_CURSOR'
                              'QMICON-PADETAIL(01)'.

PERFORM BDC_FIELD       USING 'BDC_OKCODE'
                              '=SELE'.
PERFORM BDC_FIELD       USING 'RMQAM-INSMK'
                              'X'.
PERFORM BDC_FIELD       USING 'RMQAM-EIN'
                              'X'.
PERFORM BDC_FIELD       USING 'RMQAM-AFR'
                              ''.
PERFORM BDC_FIELD       USING 'RMQAM-HPZ'
                              'X'.
PERFORM BDC_FIELD       USING 'RMQAM-QKZVERF'
                              '06'.
PERFORM BDC_FIELD       USING 'RMQAM-DYN'
                              'X'.
PERFORM BDC_FIELD       USING 'RMQAM-AVE'
                              'X'.

PERFORM BDC_FIELD       USING 'RMQAM-APA(01)'
                              ''.

PERFORM BDC_DYNPRO      USING 'SAPLQPLS' '0100'.
PERFORM BDC_FIELD       USING 'BDC_CURSOR'
                               'RMQAM-ART(01)'.

PERFORM BDC_FIELD       USING 'BDC_OKCODE'
                              '=SELE'.
PERFORM BDC_FIELD       USING 'RMQAM-INSMK'
                              'X'.
PERFORM BDC_FIELD       USING 'RMQAM-EIN'
                              'X'.
PERFORM BDC_FIELD       USING 'RMQAM-HPZ'
                              'X'.
PERFORM BDC_FIELD       USING 'RMQAM-QKZVERF'
                              '06'.
PERFORM BDC_FIELD       USING 'RMQAM-DYN'
                              'X'.
PERFORM BDC_FIELD       USING 'RMQAM-AVE'
                              'X'.

PERFORM BDC_FIELD       USING 'RMQAM-AKTIV(01)'
                              'X'.
PERFORM BDC_DYNPRO      USING 'SAPLQPLS' '0100'.
PERFORM BDC_FIELD       USING 'BDC_CURSOR'
                              'RMQAM-DYN'.
PERFORM BDC_FIELD       USING 'BDC_OKCODE'
                              '=SELE'.
PERFORM BDC_FIELD       USING 'RMQAM-INSMK'
                              'X'.
PERFORM BDC_FIELD       USING 'RMQAM-AFR'
                              ' '.
PERFORM BDC_FIELD       USING 'RMQAM-SPEZUEBER'
                              ' '.
PERFORM BDC_FIELD       USING 'RMQAM-PPL'
                              ' '.
PERFORM BDC_FIELD       USING 'RMQAM-CONF'
                              ' '.
PERFORM BDC_FIELD       USING 'RMQAM-APP'
                              ' '.
PERFORM BDC_FIELD       USING 'RMQAM-MER'
                              ' '.
PERFORM BDC_FIELD       USING 'RMQAM-EIN'
                              'X'.
PERFORM BDC_FIELD       USING 'RMQAM-HPZ'
                              'X'.
PERFORM BDC_FIELD       USING 'RMQAM-MST'
                              ' '.
PERFORM BDC_FIELD       USING 'RMQAM-MPB'
                              ' '.
PERFORM BDC_FIELD       USING 'RMQAM-QKZVERF'
                              '06'.
PERFORM BDC_FIELD       USING 'RMQAM-DYN'
                              'X'.
PERFORM BDC_FIELD       USING 'RMQAM-AVE'
                              'X'.
PERFORM BDC_DYNPRO      USING 'SAPLQPLS' '0100'.
PERFORM BDC_FIELD       USING 'BDC_CURSOR'
                              'RMQAM-AVE'.
PERFORM BDC_FIELD       USING 'BDC_OKCODE'
                              '=SELE'.
PERFORM BDC_FIELD       USING 'RMQAM-INSMK'
                              'X'.
PERFORM BDC_FIELD       USING 'RMQAM-EIN'
                              'X'.
PERFORM BDC_FIELD       USING 'RMQAM-HPZ'
                              'X'.
PERFORM BDC_FIELD       USING 'RMQAM-QKZVERF'
                              '06'.
PERFORM BDC_FIELD       USING 'RMQAM-DYN'
                              'X'.
PERFORM BDC_FIELD       USING 'RMQAM-AVE'
                              'X'.
ENDIF.
**************************************************************************************** 2
IF ITAB-REC '2'.

PERFORM BDC_DYNPRO      USING 'SAPLQPLS' '0100'.
PERFORM BDC_FIELD       USING 'BDC_CURSOR'
                              'QMICON-PADETAIL(02)'.

PERFORM BDC_FIELD       USING 'BDC_OKCODE'
                              '=SELE'.
PERFORM BDC_FIELD       USING 'RMQAM-INSMK'
                              'X'.
PERFORM BDC_FIELD       USING 'RMQAM-EIN'
                              'X'.
PERFORM BDC_FIELD       USING 'RMQAM-AFR'
                              ''.
PERFORM BDC_FIELD       USING 'RMQAM-HPZ'
                              'X'.
PERFORM BDC_FIELD       USING 'RMQAM-QKZVERF'
                              '06'.
PERFORM BDC_FIELD       USING 'RMQAM-DYN'
                              'X'.
PERFORM BDC_FIELD       USING 'RMQAM-AVE'
                              'X'.

PERFORM BDC_FIELD       USING 'RMQAM-APA(02)'
                              ''.

PERFORM BDC_DYNPRO      USING 'SAPLQPLS' '0100'.
PERFORM BDC_FIELD       USING 'BDC_CURSOR'
                               'RMQAM-ART(02)'.

PERFORM BDC_FIELD       USING 'BDC_OKCODE'
                              '=SELE'.
PERFORM BDC_FIELD       USING 'RMQAM-INSMK'
                              'X'.
PERFORM BDC_FIELD       USING 'RMQAM-EIN'
                              'X'.
PERFORM BDC_FIELD       USING 'RMQAM-HPZ'
                              'X'.
PERFORM BDC_FIELD       USING 'RMQAM-QKZVERF'
                              '06'.
PERFORM BDC_FIELD       USING 'RMQAM-DYN'
                              'X'.
PERFORM BDC_FIELD       USING 'RMQAM-AVE'
                              'X'.
PERFORM BDC_FIELD       USING 'RMQAM-AKTIV(02)'
                              'X'.

PERFORM BDC_DYNPRO      USING 'SAPLQPLS' '0100'.
PERFORM BDC_FIELD       USING 'BDC_CURSOR'
                              'RMQAM-DYN'.
PERFORM BDC_FIELD       USING 'BDC_OKCODE'
                              '=SELE'.
PERFORM BDC_FIELD       USING 'RMQAM-INSMK'
                              'X'.
PERFORM BDC_FIELD       USING 'RMQAM-AFR'
                              ' '.
PERFORM BDC_FIELD       USING 'RMQAM-SPEZUEBER'
                              ' '.
PERFORM BDC_FIELD       USING 'RMQAM-PPL'
                              ' '.
PERFORM BDC_FIELD       USING 'RMQAM-CONF'
                              ' '.
PERFORM BDC_FIELD       USING 'RMQAM-APP'
                              ' '.
PERFORM BDC_FIELD       USING 'RMQAM-MER'
                              ' '.
PERFORM BDC_FIELD       USING 'RMQAM-EIN'
                              'X'.
PERFORM BDC_FIELD       USING 'RMQAM-HPZ'
                              'X'.
PERFORM BDC_FIELD       USING 'RMQAM-MST'
                              ' '.
PERFORM BDC_FIELD       USING 'RMQAM-MPB'
                              ' '.
PERFORM BDC_FIELD       USING 'RMQAM-QKZVERF'
                              '06'.
PERFORM BDC_FIELD       USING 'RMQAM-DYN'
                              'X'.
PERFORM BDC_FIELD       USING 'RMQAM-AVE'
                              'X'.

PERFORM BDC_DYNPRO      USING 'SAPLQPLS' '0100'.
PERFORM BDC_FIELD       USING 'BDC_CURSOR'
                              'RMQAM-AVE'.
PERFORM BDC_FIELD       USING 'BDC_OKCODE'
                              '=SELE'.
PERFORM BDC_FIELD       USING 'RMQAM-INSMK'
                              'X'.
PERFORM BDC_FIELD       USING 'RMQAM-EIN'
                              'X'.
PERFORM BDC_FIELD       USING 'RMQAM-HPZ'
                              'X'.
PERFORM BDC_FIELD       USING 'RMQAM-QKZVERF'
                              '06'.
PERFORM BDC_FIELD       USING 'RMQAM-DYN'
                              'X'.
PERFORM BDC_FIELD       USING 'RMQAM-AVE'
                              'X'.

ENDIF.
**************************************************************************************** 2
IF ITAB-ART '01'.
PERFORM BDC_DYNPRO      USING 'SAPLMGMM' '4000'.
PERFORM BDC_FIELD       USING 'BDC_OKCODE'
                              '=BU'.
PERFORM BDC_FIELD       USING 'BDC_CURSOR'
                              'MAKT-MAKTX'.
*perform bdc_field       using 'MAKT-MAKTX'
*                              '64.5  DIA X 16     (SOFT BLANK)'.
*perform bdc_field       using 'MARA-MEINS'
*                              'EA'.
PERFORM BDC_FIELD       USING 'MARC-WEBAZ'
                              '5'.
PERFORM BDC_FIELD       USING 'MARA-QMPUR'
                              'X'.
PERFORM BDC_FIELD       USING 'MARC-SSQSS'
                              '0001'.
ENDIF.

 CALL TRANSACTION 'MM02' USING BDCDATA MODE 'A' UPDATE 'A'
                                     MESSAGES INTO MSG.

    IF MODE <> 'A' AND MODE <> 'E'.
      RETURN.
    ENDIF.

    LOOP AT MSG.
      CALL FUNCTION 'FORMAT_MESSAGE'
        EXPORTING
          ID        MSG-MSGID
          LANG      SY-LANGU
          NO        MSG-MSGNR
          V1        MSG-MSGV1
          V2        MSG-MSGV2
          V3        MSG-MSGV3
          V4        MSG-MSGV4
        IMPORTING
          MSG       TEXT
        EXCEPTIONS
          NOT_FOUND 1
          OTHERS    2.
      IF SY-SUBRC <> 0.
        MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
                WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.

      WRITE : TEXT, ITAB-MATNR .
      CLEAR MSG.
    ENDLOOP.
    REFRESH MSG.
    REFRESH BDCDATA.
  ENDLOOP.

*----------------------------------------------------------------------
*
*        Start new screen
*
*----------------------------------------------------------------------
*
FORM BDC_DYNPRO USING PROGRAM DYNPRO.
  BDCDATA-PROGRAM  PROGRAM.
  BDCDATA-DYNPRO   DYNPRO.
  BDCDATA-DYNBEGIN 'X'.
  APPEND BDCDATA.
  CLEAR BDCDATA.
ENDFORM.                    "bdc_dynpro

*----------------------------------------------------------------------
*
*        Insert field
*
*----------------------------------------------------------------------
*
FORM BDC_FIELD USING FNAM FVAL.
  BDCDATA-FNAM FNAM.
  BDCDATA-FVAL FVAL.
  APPEND BDCDATA.
  CLEAR BDCDATA.
ENDFORM.        

No comments: