Tuesday, November 08, 2016

Provide Process code for the Idoc LOIPGR for transferring Product Group data

Background

SAP provides the Idoc LOIPGR for transferring Product Group data but does not provide the process code and background objects to load or process the Idoc.

IMG Process

SPRO>Logistics General>Supply Chain Planning Interfaces (SCPI)>Auto ID Backend Integration>Communication>Maintain Inbound Processes
Tables TBD51, TBD52
Message no. B1500
The application function module cannot be determined for message type LOIPGR in IDoc inbound processing.
1. Please check that the process code in the inbound partner profile is correct.
2. If it is, check that the IDoc inbound processing setting for message type LOIPGR is correct and complete.
3. If the process code is not correct, check that the function module used for inbound processing is available.
4. If necessary, regenerate the interface.



Maintain Inbound Process

Use

In this IMG activity, you have the option of doing the following:
  • Maintaining the attributes of your own function module used for dispatching IDocs from the auto-ID infrastructure systems to the backend system (inbound processing).
  • Assigning a function module to different IDoc types and message types
  • Defining a process code that will utilize the function module for inbound processing
You subsequently assign the process code to the inbound parameters of each message type in the auto-ID infrastructure partner profiles (IMG activity Maintain Partner Profiles).

Standard settings

Settings are provided in the standard system.

Activities

If you want to use your own function module, assign a function module to your own message types or define your own process code, copy the standard entries and then edit them accordingly.

Name of function module for inbound IDoc

Function module for IDoc input.
Incoming IDocs can be transferred to an application using a direct function module call. The function module receives the IDoc, posts it and outputs a success message.
The function module must have the following interface:
*"       IMPORTING
*"               INPUT_METHOD          LIKE  BDWFAP_PAR-INPUTMETHD
*"               MASS_PROCESSING       LIKE  BDWFAP_PAR-MASS_PROC
*"       EXPORTING
*"               WORKFLOW_RESULT       LIKE  BDWFAP_PAR-RESULT
*"               APPLICATION_VARIABLE  LIKE  BDWFAP_PAR-APPL_VAR
*"                IN_UPDATE_TASK        LIKE  BDWFAP_PAR-UPDATETASK
*"              CALL_TRANSACTION_DONE LIKE  BDWFAP_PAR-CALLTRANS
*"       TABLES
*"               IDOC_CONTRL           STRUCTURE  EDIDC
*"               IDOC_DATA             STRUCTURE  EDIDD
*"               IDOC_STATUS           STRUCTURE  BDIDOCSTAT
*"                RETURN_VARIABLES      STRUCTURE  BDWFRETVAR
*"                SERIALIZATION_INFO    STRUCTURE  BDI_SER
*"       EXCEPTIONS
*"              WRONG_FUNCTION_CALLED




Function Module Z_PROCESS_INBOUND_IDOC_PRODGRP

Function module interface is SAP standard as instructed above use IDOC_INPUT_PROFITCENTER_CHANGE as a reference.

Here follows a completed example
FUNCTION Z_PROCESS_INBOUND_IDOC_PRODGRP.
*"----------------------------------------------------------------------
*"*"Local Interface:
*"  IMPORTING
*"     VALUE(INPUT_METHOD) LIKE  BDWFAP_PAR-INPUTMETHD
*"     VALUE(MASS_PROCESSING) LIKE  BDWFAP_PAR-MASS_PROC
*"  EXPORTING
*"     VALUE(WORKFLOW_RESULT) LIKE  BDWF_PARAM-RESULT
*"     VALUE(APPLICATION_VARIABLE) LIKE  BDWF_PARAM-APPL_VAR
*"     VALUE(IN_UPDATE_TASK) LIKE  BDWFAP_PAR-UPDATETASK
*"     VALUE(CALL_TRANSACTION_DONE) LIKE  BDWFAP_PAR-CALLTRANS
*"  TABLES
*"      IDOC_CONTRL STRUCTURE  EDIDC
*"      IDOC_DATA STRUCTURE  EDIDD
*"      IDOC_STATUS STRUCTURE  BDIDOCSTAT
*"      RETURN_VARIABLES STRUCTURE  BDWFRETVAR
*"      SERIALIZATION_INFO STRUCTURE  BDI_SER
*"  EXCEPTIONS
*"      WRONG_FUNCTION_CALLED
*"----------------------------------------------------------------------
    data: t_idoc_data        like edidd        occurs 10 with header line,
        t_idoc_status      like bdidocstat   occurs 10 with header line,
        t_return_variables like bdwfretvar   occurs 10 with header line,
        f_idoc_contrl      like edidc.

  data: v_workflow_result like bdwf_param-result,
        t_idoc_data_lines like sy-tabix.

* Read IDOC control record (this module can post only one idoc)
  loop at idoc_contrl.
    f_idoc_contrl = idoc_contrl.
    exit.
  endloop.
* Check Type
  if sy-subrc <> 0.
    exit.
  elseif f_idoc_contrl-idoctp <> 'LOIPGR01'.
    raise wrong_function_called.
  endif.
* Read IDOC data records
  refresh t_idoc_data.
  clear t_idoc_data.

  loop at idoc_data where docnum = f_idoc_contrl-docnum.
    t_idoc_data = idoc_data.
    append t_idoc_data.
  endloop.

  describe table t_idoc_data lines t_idoc_data_lines.
  if t_idoc_data_lines <> 0.
    perform idoc_post tables t_idoc_data
                             t_idoc_status
                             t_return_variables
                      using  f_idoc_contrl
                             v_workflow_result
                             input_method.

  endif.

* set return values
  loop at t_idoc_status.
    idoc_status = t_idoc_status.
    append idoc_status.
  endloop.

  loop at t_return_variables.
    return_variables = t_return_variables.
    append return_variables.
  endloop.

  workflow_result = v_workflow_result.

endfunction.




*----------------------------------------------------------------------*
***INCLUDE LZFG_INBOUND_IDOCF01.
*----------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*&      Form  IDOC_POST
*&---------------------------------------------------------------------*
*       Post Product Group Change
*----------------------------------------------------------------------*
*      -->T_IDOC_DATA  text
*      -->T_IDOC_STATUS  text
*      -->T_RETURN_VARIABLES  text
*      -->F_IDOC_CONTRL  text
*      -->V_WORKFLOW_RESULT  text
*      -->INPUT_METHOD  text
*
*----------------------------------------------------------------------*
form idoc_post tables t_idoc_data           structure edidd
                      t_idoc_status         structure bdidocstat
                      return_variables    structure bdwfretvar
               using  f_idoc_control        structure edidc
                      v_workflow_result     like bdwf_param-result
                      input_method          like bdwfap_par-inputmethd.

  data: t_idoc_data_wa    like edidd        occurs 10 with header line,
        t_idoc_status_ce  like bdidocstat   occurs 10 with header line,
        t_return_var_ce   like bdwfretvar   occurs 10 with header line.

  data: e1pgpil like e1pgpil,
        e1pghdl like e1pghdl,
        e1pgmbl like e1pgmbl,
        e1maktm like e1maktm.

  data: error_flag,
        bapi_idoc_status like bdidocstat-status,
        bapi_retn_info  like bapiret2 occurs 0 with header line.
  data:
       return like
        bapiret2,
       product_group type matnr.
  data:
     begin of cha_pgmi occurs 10.
          include structure pgmi.
  data: end of cha_pgmi,

  begin of dum_pgmi occurs 1.
          include structure pgmi.
  data: end of dum_pgmi,

  begin of dum_pgzu occurs 1.
          include structure pgzu.
  data: end of dum_pgzu.
  data: fm_operation type c length 1.
*
  constants: c_update value 'U',
             c_insert value 'I',
             c_delete value 'D'.
*   through all segments of this IDoc                                  *
  clear error_flag.
  refresh bapi_retn_info.
  catch system-exceptions conversion_errors = 1.
    clear cha_pgmi.
    refresh cha_pgmi.
    clear dum_pgmi.
    refresh dum_pgmi.
    clear dum_pgzu.
    refresh dum_pgzu.
    clear fm_operation.
    loop at t_idoc_data into t_idoc_data_wa.
      cha_pgmi-mandt = sy-mandt.

      case t_idoc_data_wa-segnam.

        when 'E1PGPIL'.
          e1pgpil = t_idoc_data_wa-sdata.
          move e1pgpil-matnr to cha_pgmi-prgrp.
          "move e1pgpil-meins to
        when 'E1PGHDL'.
          e1pghdl = t_idoc_data_wa-sdata.
          move e1pghdl-werks to cha_pgmi-werks.
          move e1pghdl-werks to cha_pgmi-wemit.
        when 'E1PGMBL'.
          e1pgmbl = t_idoc_data_wa-sdata.
          cha_pgmi-nrmit = e1pgmbl-nrmit.
          cha_pgmi-datum = '29991231'."e1pgmbl-

          case e1pgmbl-msgfn.
            when '009'.
              fm_operation = c_insert.
            when '004'.
              fm_operation = c_update.
            when '003'.
              fm_operation = c_delete.
          endcase.
        when 'E1MAKTM'.
          e1maktm = t_idoc_data_wa-sdata.

      endcase.

    endloop.
    append cha_pgmi.
  endcatch.
  if sy-subrc = 1.
*     write IDoc status-record as error and exit                 *
    clear bapi_retn_info.
    bapi_retn_info-type   = 'E'.
    bapi_retn_info-id     = 'B1'.
    bapi_retn_info-number = '527'.
    bapi_retn_info-message_v1 = t_idoc_data-segnam.
    bapi_idoc_status      = '51'.
    perform idoc_status_product_group
        tables t_idoc_data
               t_idoc_status
               return_variables
         using f_idoc_control
               bapi_retn_info
               bapi_idoc_status
               v_workflow_result.
    exit.
  endif.
*
  case fm_operation.
    when c_insert.
      call function 'PRODUCTGROUP_CHANGE'
        tables
          pgmi_d                   = dum_pgmi
          pgmi_i                   = cha_pgmi
          pgmi_u                   = dum_pgmi
          pgzu_d                   = dum_pgzu
          pgzu_i                   = dum_pgzu
          pgzu_u                   = dum_pgzu
        exceptions
          pg_or_material_not_found = 1
          error_with_int_number    = 2
          others                   = 3.
    when c_update.
      call function 'PRODUCTGROUP_CHANGE'
        tables
          pgmi_d                   = dum_pgmi
          pgmi_i                   = dum_pgmi
          pgmi_u                   = cha_pgmi
          pgzu_d                   = dum_pgzu
          pgzu_i                   = dum_pgzu
          pgzu_u                   = dum_pgzu
        exceptions
          pg_or_material_not_found = 1
          error_with_int_number    = 2
          others                   = 3.
    when c_delete.
      call function 'PRODUCTGROUP_CHANGE'
        tables
          pgmi_d                   = cha_pgmi
          pgmi_i                   = dum_pgmi
          pgmi_u                   = dum_pgmi
          pgzu_d                   = dum_pgzu
          pgzu_i                   = dum_pgzu
          pgzu_u                   = dum_pgzu
        exceptions
          pg_or_material_not_found = 1
          error_with_int_number    = 2
          others                   = 3.
  endcase.
  if sy-subrc <> 0.
* Implement suitable error handling here
*     write IDoc status-record as error                                *
    error_flag = 'X'.
    clear bapi_retn_info.
    bapi_retn_info-type       = 'E'.
    bapi_retn_info-id         = sy-msgid.
    bapi_retn_info-number     = sy-msgno.
    bapi_retn_info-message_v1 = sy-msgv1.
    bapi_retn_info-message_v2 = sy-msgv2.
    bapi_retn_info-message_v3 = sy-msgv3.
    bapi_retn_info-message_v4 = sy-msgv4.
    bapi_idoc_status          = '51'.
    perform idoc_status_product_group
            tables t_idoc_data
                   t_idoc_status
                   return_variables
             using f_idoc_control
                   bapi_retn_info
                   bapi_idoc_status
                   v_workflow_result.
  else.
*     write idoc status-record as successful        *
    clear bapi_retn_info.
    bapi_retn_info-type       = 'S'.
    bapi_retn_info-id         = 'B1'.
    bapi_retn_info-number     = '999'.
    bapi_retn_info-message_v1 = 'Product Group Member'.
    bapi_retn_info-message_v2 = cha_pgmi-nrmit.
    bapi_retn_info-message_v3 = 'Maintained for'.
    bapi_retn_info-message_v4 = cha_pgmi-prgrp.
    bapi_idoc_status          = '53'.
    perform idoc_status_product_group
    tables t_idoc_data
           t_idoc_status
           return_variables
     using f_idoc_control
           bapi_retn_info
           bapi_idoc_status
           v_workflow_result.
    clear return_variables.
    return_variables-wf_param = 'Appl_Objects'.
  endif.
endform.                    " IDOC_POST
*&---------------------------------------------------------------------*
*&      Form  IDOC_STATUS_PRODUCT_GROUP
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->T_EDIDD  text
*      -->IDOC_STATUS  text
*      -->RETURN_VARIABLES  text
*      -->IDOC_CONTRL  text
*      -->BAPI_RETN_INFO  text
*      -->BAPI_IDOC_STATUS  text
*      -->WORKFLOW_RESULT  text
*----------------------------------------------------------------------*
form idoc_status_product_group
                       tables idoc_data    structure  edidd
                              idoc_status  structure  bdidocstat
                              r_variables  structure  bdwfretvar
                       using idoc_contrl  like  edidc
                             value(retn_info) like   bapiret2
                             status       like  bdidocstat-status
                             wf_result    like  bdwf_param-result.
*
  clear idoc_status.
  idoc_status-docnum   = idoc_contrl-docnum.
  idoc_status-msgty    = retn_info-type.
  idoc_status-msgid    = retn_info-id.
  idoc_status-msgno    = retn_info-number.
  idoc_status-appl_log = retn_info-log_no.
  idoc_status-msgv1    = retn_info-message_v1.
  idoc_status-msgv2    = retn_info-message_v2.
  idoc_status-msgv3    = retn_info-message_v3.
  idoc_status-msgv4    = retn_info-message_v4.
  idoc_status-repid    = sy-repid.
  idoc_status-status   = status.

  insert idoc_status index 1.

  if idoc_status-status = '51'.
    wf_result = '99999'.
    r_variables-wf_param   = 'Error_IDOCs'.
    r_variables-doc_number = idoc_contrl-docnum.
    read table r_variables from r_variables.
    if sy-subrc <> 0.
      append r_variables.
    endif.
  elseif idoc_status-status = '53'.
    clear wf_result.
    r_variables-wf_param = 'Processed_IDOCs'.
    r_variables-doc_number = idoc_contrl-docnum.
    read table r_variables from r_variables.
    if sy-subrc <> 0.
      append r_variables.
    endif.
    r_variables-wf_param = 'Appl_Object_Type'.
    r_variables-doc_number = 'Product Group'.
    read table r_variables from r_variables.
    if sy-subrc <> 0.
      append r_variables.
    endif.
  endif.


endform.                    " IDOC_STATUS_PRODUCT_GROUP

IMG Steps


Maintain Attributes of Inbound Function module


Assign Function Module to Message and IDoc Types

Define Inbound Process Code

LSMW for upload of Product Group

Object Attributes

Message Type is LOIPGR and Basic Type LOIPGR01

Source Structure


Field Mapping Options

Product Group

Plant

Product Group Member

Using the Conversion routines defined below.

LSMW Conversion routines

Conversion ur_MAT_INTERNAL

form ur_MAT_INTERNAL
     using p_in
  changing p_out.
data: mat_test type matnr.
* if SAP material number is passed into the load

    call function 'CONVERSION_EXIT_MATN1_INPUT'
      exporting
        input        = p_in
      importing
        output       = p_out
      exceptions
        length_error = 1
        others       = 2.

    select single matnr into mat_test from mara
      where matnr = p_out.
    if sy-subrc ne 0.
      write: / 'Error: SAP material number', p_in, 'does not exists'.
      g_skip_transaction = yes.
    endif.

endform.

Conversion ur_MEMBER_FUNCTION

form ur_member_function
     using p_in
  changing p_out.

  case p_in.
    when 'I'.
      p_out = '009'.
    when 'U'.
      p_out = '004'.
    when 'D'.
      p_out = '003'.
    when others.
      write: / 'Error: specify (I)insert,(D)delete,(U)update'.
      g_skip_transaction = yes.
  endcase.
endform.                    "ur_MEMBER_FUNCTION


End of Document

No comments: