Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

help with bapi BAPI_COPAPLANNING_POSTDATA

any example?

does not return any error but does not work.

*&---------------------------------------------------------------------*
*&      Form  CONTABILIZAR_ARIDO
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM contabilizar_arido USING value(p_test) TYPE testrun.
  DATA l_respuesta.
  DATA: BEGIN OF lt_ac_cta OCCURS 0, "Valores acumulados por Cta.
         kstar     TYPE kstar,"Nº de cuenta
         meinh     TYPE meinh,"Unidad de medida
         moneda    TYPE waers,"moneda
*          -----------------------------
         cantidad  TYPE zzcant_rest,     "Cantidad
         valor     TYPE zzvalor_restan,"valor
      END   OF lt_ac_cta.



  FIELD-SYMBOLS <lfarido> TYPE zcoe_escop_costes_y_compras.
*gte3_glpct Y gte3_costes
  DATA: l_perio(7) TYPE n,
        l_rid TYPE rke_record_id.
* ========================================================
  BREAK jmllacue.
  IF p_test = ''.
*  Pregunta de confirmación
    PERFORM preguntar CHANGING l_respuesta.
    IF l_respuesta NE '1'.
      MESSAGE s005."Cancelado por el usuario
    ENDIF.
    CHECK l_respuesta = '1'.
  ENDIF.

  break jmllacue.
  REFRESH: selectedfields,
           selection,
           data,
           return.

*  Acumular(valor y cantidad) por clase de coste para que no se repita(devolvería error bapi) en ningún registro_
*  ya que el resto de campos de la clave(los no numéricos) son fijos
  REFRESH lt_ac_cta.


  LOOP AT gt_arido_all ASSIGNING <lfarido>.
    CLEAR lt_ac_cta.
    lt_ac_cta-kstar    = <lfarido>-kstar."Clase de coste
    lt_ac_cta-meinh    = c_unidad.      "Unidad de medida
    lt_ac_cta-moneda   = c_moneda.      "Moneda
*   -----------------------------------------------------------
    lt_ac_cta-cantidad = <lfarido>-cant_res. "Cantidad
    lt_ac_cta-valor    = <lfarido>-valor_res."Valor
    COLLECT lt_ac_cta.
  ENDLOOP.
* /////////////////////////////////////////////////////



* LLENAR LA TABLA SELECTFIELDS PARA LA PABI --->:
  PERFORM selectedfields USING 'KOKRS'. "Sociedad CO
  PERFORM selectedfields USING 'BUKRS'. "Sociedad
  PERFORM selectedfields USING 'PERIO'. "Período
  PERFORM selectedfields USING 'VERSI'. "Versión
  PERFORM selectedfields USING 'KSTAR'. "Clase de coste
  PERFORM selectedfields USING 'WKGBTR'."Valor
  PERFORM selectedfields USING 'MEGBTR'."Cantidad
  PERFORM selectedfields USING 'MEINH'. "Unidad de medida



* LLENAR LA TABLA SELECTION PARA LA PABI --->:
  PERFORM selection USING 'KOKRS' 'I' 'EQ' p_kokrs ''."Sociedad CO

  PERFORM selection USING 'BUKRS' 'I' 'EQ' p_bukrs ''."Sociedad
  CONCATENATE p_ejer p_perio INTO l_perio.

  PERFORM selection USING 'PERIO' 'I' 'EQ' l_perio ''."Período

  PERFORM selection USING 'VERSI' 'I' 'EQ' c_version ''."Versión

  PERFORM selection USING 'MEINH' 'I' 'EQ' c_unidad ''."Unidad de medida



*  Llenar la tabla DATA para la BAPI -->:
  CLEAR l_rid.
  LOOP AT lt_ac_cta.
    ADD 1 TO l_rid.
    PERFORM data USING l_rid 'KOKRS'  p_kokrs             ''. "Sociedad CO
    PERFORM data USING l_rid 'BUKRS'  p_bukrs             ''. "Sociedad
    PERFORM data USING l_rid 'PERIO'  l_perio             ''. "Período
    PERFORM data USING l_rid 'VERSI'  c_version           ''. "Versión
*   -------------------------------------------------------------------------
    PERFORM data USING l_rid 'MEGBTR' lt_ac_cta-cantidad   ''. "Cantidad
    PERFORM data USING l_rid 'MEINH'  c_unidad             ''. "Unidad de medida
    PERFORM data USING l_rid 'WKGBTR' lt_ac_cta-valor  lt_ac_cta-moneda. "Valor y su moneda
    PERFORM data USING l_rid 'KSTAR'  lt_ac_cta-kstar      ''. "Nº de cuenta
  ENDLOOP.

  CALL FUNCTION 'BAPI_COPAPLANNING_POSTDATA'
    EXPORTING
      operatingconcern     = p_kokrs
      typeofprofitanalysis = '2'                            "<- tIPO 2
      testrun              = p_test
    TABLES
      selectedfields       = selectedfields
      selection            = selection
      data                 = data
      return               = return.

  READ TABLE return  WITH KEY type = 'E'.
  IF sy-subrc NE 0.
    READ TABLE return WITH KEY type = 'A'.
  ENDIF.
  IF sy-subrc = 0.
    g_error_arido = 'X'.
    PERFORM log_bapi.
  ELSE.
    CLEAR g_error_arido.
    IF p_test = ''.
*     Actualizar listado ---------
      PERFORM refrescar_listado_arido USING ''.
*     ----------------------------
    ENDIF.
    MESSAGE i000.
  ENDIF.


ENDFORM.                    " CONTABILIZAR_ARIDO

*&---------------------------------------------------------------------*
*&      Form  SELECTEDFIELDS
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_2259   text
*----------------------------------------------------------------------*
FORM selectedfields  USING value(p_fieldname) LIKE selectedfields-fieldname.

  selectedfields-fieldname = p_fieldname.
  APPEND selectedfields.

ENDFORM.                    " SELECTEDFIELDS
*&---------------------------------------------------------------------*
*&      Form  SELECTION
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM selection USING value(p_fieldname)
                     value(p_sign)
                     value(p_option)
                     value(p_low)
                     value(p_high) .

  selection-fieldname = p_fieldname.
  selection-sign =      p_sign.
  selection-option =    p_option.
  selection-low =       p_low.
  selection-high =      p_high.
  APPEND selection.
ENDFORM.                    " SELECTION
*&---------------------------------------------------------------------*
*&      Form  DATA
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_L_RID  text
*      -->P_2351   text
*      -->P_2352   text
*      -->P_2353   text
*----------------------------------------------------------------------*
FORM DATA  USING    value(p_rid)
                    value(p_fieldname)
                    value(p_value)
                    value(p_currency) .

  data-record_id = p_rid.
  data-fieldname = p_fieldname.
  data-value     = p_value.
  CONDENSE data-value.
  data-currency  = p_currency.
  APPEND data.

ENDFORM.                    " DATA

Not what you were looking for? View more on this topic or Ask a question