cancel
Showing results for 
Search instead for 
Did you mean: 

BAPI/FM for material assignment to an inspection plan QP02

Arun_Prabhu_K
Active Contributor
3,217

Requirement: To assign single material to an existing inspection plan.

I had referred several threads and posting it here since I did not get any concrete solution. Some threads suggest direct update of MAPL table. Hope a better method exists.

BAPI

BAPI_INSPECTIONPLAN_CHANGE is unavailable in our system.

BDC

I tried BDC but the problem is that there is no facility for new row addition to insert a material assignment. I have to do multiple page downs to get a blank row for insertion. This will increase response time when the records are more. I could write a logic for the number of page downs required based on MAPL total count divided by count of visible rows in material assignment screen of QP02 tcode.

FM

I checked ROUTING_MAINTAIN but it did not contain any input for passing task list type.

If you had done this requirement using any FM/BAPI, kindly provide the FM detail or idea in BDC to quickly get to the table control empty row in order to assign a material to an inspection plan?

View Entire Topic
ferces
Discoverer
0 Kudos

I think could be better the solution already answered before, but i did it by BDC.
You can make a "page end" action on the list and move to the end.

My solution:

FUNCTION zsqm_qp02_asign_mat_insp_plan.
*"----------------------------------------------------------------------
*"*"Interfase local
*"  IMPORTING
*"     VALUE(CTU) LIKE  APQI-PUTACTIVE DEFAULT 'X'
*"     VALUE(MODE) LIKE  APQI-PUTACTIVE DEFAULT 'N'
*"     VALUE(UPDATE) LIKE  APQI-PUTACTIVE DEFAULT 'S'
*"     VALUE(GROUP) LIKE  APQI-GROUPID OPTIONAL
*"     VALUE(USER) LIKE  APQI-USERID OPTIONAL
*"     VALUE(KEEP) LIKE  APQI-QERASE OPTIONAL
*"     VALUE(HOLDDATE) LIKE  APQI-STARTDATE OPTIONAL
*"     VALUE(NODATA) LIKE  APQI-PUTACTIVE DEFAULT '/'
*"     VALUE(MATNR) TYPE  MAPL-MATNR
*"     VALUE(WERKS) TYPE  MAPL-WERKS DEFAULT '1000'
*"     VALUE(PLNNR) TYPE  MAPL-PLNNR DEFAULT '1'
*"     VALUE(PLNAL) TYPE  MAPL-PLNAL DEFAULT '1'
*"     VALUE(STTAG) TYPE  STTAG OPTIONAL
*"  EXPORTING
*"     VALUE(SUBRC) LIKE  SYST-SUBRC
*"  TABLES
*"      MESSTAB STRUCTURE  BDCMSGCOLL OPTIONAL
*"----------------------------------------------------------------------

**********************************************************************
* ASIGNAR MATERIAL A PLAN DE INSPECCIÓN (QP02)
*--------------------------------------------------------------------*
* Dado un centro y un grupo de hojas de ruta, se asignará un material
* al plan de inspección.
**********************************************************************

  CONSTANTS: lc_entry_act TYPE bdcdata-fval VALUE '1'. " Parametro obtenido de la grabación de QP02 desde SHDB

  DATA: lv_bdc_matnr TYPE bdcdata-fval,
        lv_bdc_werks TYPE bdcdata-fval,
        lv_bdc_plnnr TYPE bdcdata-fval,
        lv_bdc_plnal TYPE bdcdata-fval
*        lv_bdc_sttag TYPE bdcdata-fval " Campo sttag viene relleno por defecto con fecha actual en QP02
        .

  CALL FUNCTION 'CONVERSION_EXIT_MATN1_OUTPUT'
    EXPORTING
      input  = matnr
    IMPORTING
      output = lv_bdc_matnr.

  lv_bdc_werks = CONV #( werks ).
  lv_bdc_plnnr = CONV #( plnnr ).
  lv_bdc_plnal = CONV #( plnal ).

*  IF sttag IS INITIAL.
*    lv_bdc_sttag = CONV #( sy-datum ).
*  ELSE.
*    lv_bdc_sttag = CONV #( sttag ).
*  ENDIF.

  subrc = 0.

  PERFORM bdc_nodata      USING nodata.
  PERFORM open_group      USING group user keep holddate ctu.

*- Dynpro 8010 ------------------------------------------------------*
  PERFORM bdc_dynpro      USING 'SAPLCPDI' '8010'.              " Dynpro QP02 - 1 (pantalla seleccion)
  PERFORM bdc_field       USING 'BDC_OKCODE' '/00'.             " Intro
  PERFORM bdc_field       USING 'RC27M-WERKS' lv_bdc_werks.     " Centro
  PERFORM bdc_field       USING 'RC271-PLNNR' lv_bdc_plnnr.     " Grupo hojas de ruta
*  PERFORM bdc_field       USING 'RC271-STTAG' sttag.            " Día fijado

*- Dynpro 1400 ------------------------------------------------------*
  PERFORM bdc_dynpro      USING 'SAPLCPDI' '1400'.              " Dynpro QP02 - 2 (listado hojas de ruta)
  PERFORM bdc_field       USING 'BDC_OKCODE' '=MTUE'.           " 'Plan de inspección'->'Asignación material'
  PERFORM bdc_field       USING 'RC27X-ENTRY_ACT' lc_entry_act. " Parámetro dynpro???

*- Dynpro 4010 ------------------------------------------------------*
  PERFORM bdc_dynpro      USING 'SAPLCZDI' '4010'.              " Sub-Dynpro QP02 - 3 (materiales asignados a la hoja de ruta)
  PERFORM bdc_field       USING 'BDC_CURSOR' 'MAPL-MATNR(01)'.
  PERFORM bdc_field       USING 'BDC_OKCODE' '=P++'.            " Ultima página

  PERFORM bdc_dynpro      USING 'SAPLCZDI' '4010'.
  PERFORM bdc_field       USING 'BDC_CURSOR' 'MAPL-MATNR(01)'.
  PERFORM bdc_field       USING 'BDC_OKCODE' '=P+'.             " Pagina siguiente

  PERFORM bdc_dynpro      USING 'SAPLCZDI' '4010'.
  PERFORM bdc_field       USING 'BDC_CURSOR' 'MAPL-MATNR(02)'.
  PERFORM bdc_field       USING 'BDC_OKCODE' '=BACK'.           " Ok
  PERFORM bdc_field       USING 'MAPL-PLNAL(02)' lv_bdc_plnal.  " Grupo hojas de ruta
  PERFORM bdc_field       USING 'MAPL-MATNR(02)' lv_bdc_matnr.  " Material
  PERFORM bdc_field       USING 'MAPL-WERKS(02)' lv_bdc_werks.  " Centro

*- Dynpro 1400 -----------------------------------------------------*
  PERFORM bdc_dynpro      USING 'SAPLCPDI' '1400'.              " Dynpro QP02 - 2 (listado hojas de ruta)
  PERFORM bdc_field       USING 'BDC_OKCODE' '=BU'.             " Guardar
  PERFORM bdc_field       USING 'RC27X-ENTRY_ACT' lc_entry_act. " Parámetro dynpro???

*- Lanzar BDC ------------------------------------------------------*
  PERFORM bdc_transaction TABLES messtab
                           USING 'QP02'
                                 ctu
                                 mode
                                 update.
  IF sy-subrc <> 0.
    subrc = sy-subrc.
    EXIT.
  ENDIF.

  PERFORM close_group USING ctu.

ENDFUNCTION.

INCLUDE bdcrecxy .