*&---------------------------------------------------------------------*
*& Report  ZSAM_QDL2_BDC_TEST
*&
*&---------------------------------------------------------------------*
*& Note 86590 - Changing quality level via 'CALL TRANSACTION USING' 참조
*&
*& Changing the quality level in the call mode is now supported.
*& You can now call the transaction 'Change quality level' via the
*& ABAP/4 statement 'CALL TRANSACTION 'QDL2' USING itab.Data transfer
*& is carried out by means of the internal table ITAB,
*& which contains screens in the batch-input format.
*& In call mode, the quality level determines the missing key fields
*& and the control fields via SET/GET parameter.These must be supplied
*& before calling the change function via 'CALL TRANSACTION tcod
*& USING itab'. Read subroutine 'Q_LAGE_DATEN_LESEN_C' of
*& main program 'SAPMQDQL' for the parameters
*& which are available in detail.
*&
*& For every dynamic modification level you can record an example
*& BDC session with the batch input recorder.
*& For this purpose, you must choose a suitable quality level anf
*& before the recording you must set user parameter QLD to:
*&
*& value '0', for dynamic modification at inspection type level
*& value '1', for dynamic modification at lot level
*& value '3', for dynamic modification at characteristic level
*&---------------------------------------------------------------------*

REPORT  ZSAM_QDL2_BDC_TEST.

DATA: BDCTAB LIKE TABLE OF BDCDATA WITH HEADER LINE,
      MSGTAB LIKE TABLE OF BDCMSGCOLL WITH HEADER LINE.
DATA: GT_QDQL LIKE TABLE OF QDQL WITH HEADER LINE.


SELECTION-SCREEN BEGIN OF BLOCK BLK1 WITH FRAME TITLE TEXT-001."#EC

PARAMETERS: P_WERKS LIKE MARC-WERKS,
            P_MATNR LIKE MARC-MATNR,
            P_LEVEL LIKE QDQL-PRSTUFENAE.

SELECTION-SCREEN SKIP.
PARAMETERS:P_MODE(1)  DEFAULT 'N'.
SELECTION-SCREEN END OF BLOCK BLK1.                         "#EC

*----------------------------------------------------------------------*
*START-OF-SELECTION                                                    *
*----------------------------------------------------------------------*
START-OF-SELECTION.
  DATA: LS_QDQL LIKE QDQL.

  CLEAR: BDCTAB, BDCTAB[], MSGTAB, MSGTAB[], GT_QDQL, GT_QDQL[].

  SELECT * INTO TABLE  GT_QDQL
           FROM QDQL
           WHERE WERKS EQ P_WERKS
             AND MATNR EQ P_MATNR.
  BREAK DABAPLSI.
  LOOP AT GT_QDQL.
    "(Batch Input으로 QDL2는 수행이 안되지만 Parameter를
    " 지정해주면 BDC수행이 가능해진다.
    SET PARAMETER ID 'QLD' FIELD '1'.
    PERFORM SET_PARAMETER USING GT_QDQL.

    PERFORM  : BDC_FORM   USING 'X'      'SAPMQDQL'      '0100',
               BDC_FORM   USING ' '      'BDC_OKCODE'    '=NEXT',
               BDC_FORM   USING ' '      'QDQL-WERKS'    P_WERKS,
               BDC_FORM   USING ' '      'QDQL-MATNR'    P_MATNR.

    PERFORM  : BDC_FORM   USING 'X'      'SAPMQDQL'         '0110',
               BDC_FORM   USING ' '      'BDC_OKCODE'       '=SAVE',
               BDC_FORM   USING ' '      'QDQL-PRSTUFENAE'  P_LEVEL,
               BDC_FORM   USING ' '      'QDQL-DELDATUM'    SY-DATUM.


    CALL TRANSACTION 'QDL2' USING BDCTAB
                            MODE P_MODE
                            UPDATE 'S'
                            MESSAGES INTO MSGTAB.
    "Parmeter Clear
    CLEAR: LS_QDQL.
    PERFORM SET_PARAMETER USING LS_QDQL.

    "Message 처리
    PERFORM WRITE_ERR_MESSAG.
  ENDLOOP.

*&---------------------------------------------------------------------*
*&      Form  BDC_FORM
*&---------------------------------------------------------------------*
FORM BDC_FORM USING    PARA1                                "  X
                       PARA2           " field  or program name
                       PARA3  .        " value  or screen
  CLEAR BDCTAB.
  IF PARA1 EQ 'X'.
    BDCTAB-DYNBEGIN = 'X'.
    BDCTAB-PROGRAM  = PARA2.
    BDCTAB-DYNPRO   = PARA3 .
  ELSE.
    BDCTAB-FNAM     = PARA2.
    BDCTAB-FVAL     = PARA3.
  ENDIF.
  APPEND BDCTAB.
ENDFORM.                               " BDC_FORM
*&---------------------------------------------------------------------*
*&      Form  WRITE_ERR_MESSAG
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM WRITE_ERR_MESSAG .
  DATA : L_LINE TYPE I,
        L_MSG(100),
        L_MSGV(20),
        SUCCESS_CNT TYPE I.

  DESCRIBE TABLE MSGTAB LINES L_LINE.
  READ TABLE MSGTAB INDEX L_LINE.

  SELECT SINGLE TEXT INTO L_MSG FROM T100
         WHERE SPRSL = SY-LANGU
           AND ARBGB = MSGTAB-MSGID
           AND MSGNR = MSGTAB-MSGNR.

  L_MSGV = MSGTAB-MSGV1. REPLACE '&' WITH L_MSGV INTO L_MSG.
  L_MSGV = MSGTAB-MSGV2. REPLACE '&' WITH L_MSGV INTO L_MSG.
  L_MSGV = MSGTAB-MSGV3. REPLACE '&' WITH L_MSGV INTO L_MSG.
  L_MSGV = MSGTAB-MSGV4. REPLACE '&' WITH L_MSGV INTO L_MSG.
  L_MSGV = MSGTAB-MSGV4. REPLACE '&' WITH L_MSGV INTO L_MSG.
  CONDENSE L_MSG.

 

  IF MSGTAB-MSGTYP = 'E'.              "ERROR
    FORMAT COLOR 6 INTENSIFIED OFF.
  ELSE.                                " 'S' 성공
    FORMAT COLOR 3 INTENSIFIED OFF.
  ENDIF.
  WRITE :/1 SY-VLINE,  2(1)    MSGTAB-MSGTYP,
          3 SY-VLINE,  4(18)   P_MATNR,
          22 SY-VLINE, 23(100) L_MSG,
          123 SY-VLINE.
  FORMAT RESET.


ENDFORM.                    " WRITE_ERR_MESSAG
*&---------------------------------------------------------------------*
*&      Form  SET_PARAMETER
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_GT_QDQL  text
*----------------------------------------------------------------------*
FORM SET_PARAMETER  USING    PS_QDQL STRUCTURE QDQL.

  SET PARAMETER ID 'WRK' FIELD PS_QDQL-WERKS.
  SET PARAMETER ID 'QLM' FIELD PS_QDQL-MATNR.
  SET PARAMETER ID 'QLT' FIELD PS_QDQL-PLNTY.
  SET PARAMETER ID 'QLN' FIELD PS_QDQL-PLNNR.
  SET PARAMETER ID 'QLZ' FIELD PS_QDQL-PLNAL.
  SET PARAMETER ID 'QLF' FIELD PS_QDQL-PLNFL.
  SET PARAMETER ID 'QLV' FIELD PS_QDQL-PLNKN.
  SET PARAMETER ID 'QLL' FIELD PS_QDQL-LIFNR.
  SET PARAMETER ID 'QLK' FIELD PS_QDQL-KUNNR.
  SET PARAMETER ID 'QLH' FIELD PS_QDQL-HERSTELLER.
  SET PARAMETER ID 'QLP' FIELD PS_QDQL-PRUEFART.

ENDFORM.                    " SET_PARAMETER