Skip to Content

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

Goods Receipt HU for Inbound delivery

Hello Experts,

i need to execute a goods receipt for a hu of an inbound delivery.

This can be done via transaction /scwm/prdi:

I need to do this via abap-code and a HU-Ident and the delivery number are provided.

Does anyone know how to implement this and what classes / function modules need to be used? I already have read SAP-Note 1414179 about delivery service providers, but i do not find a way for a hu-goods-receipt.

Thanks in advance,

Matthias

Tags:
Former Member
Former Member replied

I found out on my own how to do this. If someone is interested, this the solution:

DATA lo_sp_prd_in TYPE REF TO /scdl/cl_sp_prd_inb.

  DATA lo_message_box TYPE REF TO /scdl/cl_sp_message_box.

  DATA lt_sp_a_head TYPE /scdl/t_sp_a_head.

  DATA ls_sp_a_head TYPE /scdl/s_sp_a_head.

  DATA ls_sp_k_head TYPE /scdl/s_sp_k_head.

  DATA lt_sp_k_head TYPE /scdl/t_sp_k_head.

  DATA ls_sp_a_hu TYPE /scdl/s_sp_a_hu.

  DATA lt_sp_a_hu TYPE /scdl/t_sp_a_hu.

  DATA lv_rejected TYPE boolean.

  DATA lt_return_codes TYPE /scdl/t_sp_return_code.

  DATA ls_sp_a_hu_scwm TYPE /scwm/s_sp_a_hu.

  DATA lt_sp_a_hu_scwm TYPE /scwm/t_sp_a_hu.

  DATA ls_sp_a_myhu_scwm TYPE /scwm/s_sp_a_hu.

  DATA ls_sp_k_hu_scwm TYPE /scwm/s_sp_k_hu.

  DATA lt_sp_k_hu_scwm TYPE /scwm/t_sp_k_hu.

  "Create service provider for inbound delivery

  CREATE OBJECT lo_sp_prd_in

    EXPORTING

      io_message_box = lo_message_box.     " Service Provider Nachrichtenverwaltung

  ls_sp_k_head-docid = is_proch-docid.

  APPEND ls_sp_k_head TO lt_sp_k_head.

  "select delivery head data

  CALL METHOD lo_sp_prd_in->/scdl/if_sp1_aspect~select

    EXPORTING

      inkeys       = lt_sp_k_head

      aspect       = /scdl/if_sp_c=>sc_asp_head

    IMPORTING

      outrecords   = lt_sp_a_head

      rejected     = lv_rejected

      return_codes = lt_return_codes.

  "Lock delivery

  CALL METHOD lo_sp_prd_in->/scdl/if_sp1_locking~lock

    EXPORTING

      inkeys       = lt_sp_k_head

      aspect       = /scdl/if_sp_c=>sc_asp_head

      lockmode     = 'E'

    IMPORTING

      rejected     = lv_rejected

      return_codes = lt_return_codes.

  "If lock has been successful

  IF lv_rejected = abap_false.

    "select hu data from delivery

    CALL METHOD lo_sp_prd_in->/scdl/if_sp1_aspect~select_by_relation

      EXPORTING

        "        relation     = /scdl/if_sp_c=>sc_rel_head_to_hu

        relation     = /scwm/if_sp_c=>sc_rel_head_to_hu

        inrecords    = lt_sp_k_head

        aspect       = /scdl/if_sp_c=>sc_asp_head

*       options      =

      IMPORTING

        outrecords   = lt_sp_a_hu_scwm

        rejected     = lv_rejected

        return_codes = lt_return_codes.

    LOOP AT lt_sp_a_hu_scwm INTO ls_sp_a_hu_scwm.

      "determine hu data which has to be moved.

      IF ls_sp_a_hu_scwm-huno = /scwm/huhdr-huident.

        ls_sp_a_myhu_scwm = ls_sp_a_hu_scwm.

        MOVE-CORRESPONDING ls_sp_a_hu_scwm TO ls_sp_k_hu_scwm.

        APPEND ls_sp_k_hu_scwm TO lt_sp_k_hu_scwm.

        EXIT.

      ENDIF.

    ENDLOOP.

    CLEAR lt_sp_a_hu_scwm.

    CLEAR lt_sp_a_head.

    "execute action hu goods movement

    CALL METHOD lo_sp_prd_in->/scdl/if_sp1_action~execute

      EXPORTING

        aspect             = /scwm/if_sp_c=>sc_asp_hu    " Aspect Name

        inkeys             = lt_sp_k_hu_scwm    " Objects to Act On

*       inparam            =     " Parameters

        action             = /scwm/if_sp_c=>sc_act_hu_post_gm   " Name of Action

        relation_inkey     = ls_sp_k_head     " Key for Target Aspect

        relation           = /scwm/if_sp_c=>sc_rel_head_to_hu     " Name of Relation

      IMPORTING

        outrecords         = lt_sp_a_hu_scwm     " Changed Aspect Objects

        rejected           = lv_rejected    " Error on Back End

        return_codes       = lt_return_codes     " Table of Return Codes

        relation_outrecord = lt_sp_a_head.    " Changed Target Aspect Line

    "Save changes

    CALL METHOD lo_sp_prd_in->/scdl/if_sp1_transaction~save

      EXPORTING

        synchronously = abap_false

      IMPORTING

        rejected      = lv_rejected.

    "remove lock

    CALL METHOD lo_sp_prd_in->/scdl/if_sp1_transaction~cleanup

      EXPORTING

        reason = 'END'.

  ENDIF.

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