Erzeugen einer HU anhand von PV

Das folgende Programm kann Handling Units anhand einer gewählten Packvorschrift anlegen. Die meisten Attribute sind starr hinterlegt, zeigen aber grundsätzlich, wie die Programmierung durchgeführt werden kann.

Anmerkung

Packprofile und Customizing müssen natürlich überprüft und gegebenenfalls angepasst werden.

Der Packvorschlag kann per F4-Hilfe zum Material ermittelt und übernommen werden.

Coding

TYPE-POOLS pdt.

DATA gs_pdpara            TYPE pdt_pdpara.
DATA gv_packnr            TYPE pdt_packnr.
DATA gs_header_proposal   TYPE huhdr_proposal.
DATA gt_headers_proposal  TYPE huhdr_prop.
DATA gt_items_proposal    TYPE huitm_prop.
DATA gs_hu_header         TYPE vekpvb.
DATA gt_hu_items          TYPE hum_hu_item_t.
DATA gt_hu_messages       TYPE huitem_messages_t.
DATA gt_packitems         TYPE pdt_packitems.
DATA gs_object            TYPE pdt_object.
DATA gs_header_add        TYPE huhdr_additional_data.
DATA gt_headers_add       TYPE huhdr_add.
DATA gs_header_cap        TYPE huhdr_capacity.
DATA gt_headers_cap       TYPE huhdr_cap.
DATA gs_komgp             TYPE komgp.
DATA gs_kondp             TYPE kondp.

FIELD-SYMBOLS <packitem>  TYPE packitem.

PARAMETERS: p_pobjid TYPE pl_pobjid DEFAULT ‘PV_123’.


AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_pobjid.
*** F4 ***
  gs_komgp-matnr = ‘MAT123’.
  gs_komgp-lgort = ‘0100’.
  gs_komgp-werks = ‘0100’.
  gs_komgp-lgnum = ‘100’.
  gs_komgp-rmatp = ‘RMAT_ABC’.
  CLEAR gs_kondp.

  CALL FUNCTION ‘VHUPOSEL_PACK_INST_DETERMINE’
    EXPORTING
      i_dialog            = ‘X’
      i_scheme            = ‘000000’
      i_komgp             = gs_komgp
    CHANGING
      ch_packnr           = gv_packnr
      ch_kondp            = gs_kondp
    EXCEPTIONS
      packinstr_not_found = 1
      packinstr_deleted   = 2
      OTHERS              = 3.
  IF sy-subrc = 0.
    CALL FUNCTION ‘VHUPODB_PACKOBJ_CONV_GUID2ID’
      EXPORTING
        packnr_imp = gv_packnr
      IMPORTING
        pobjid_exp = p_pobjid
      EXCEPTIONS
        OTHERS     = 3.
  ENDIF.


START-OF-SELECTION.

*** Packobjekt umwandeln
  CALL FUNCTION ‘VHUPODB_PACKOBJ_CONV_ID2GUID’
    EXPORTING
      pobjid_imp       = p_pobjid
      packtyp_imp      = ‘P’
    IMPORTING
      packnr_exp       = gv_packnr
    EXCEPTIONS
      prog_error       = 1
      pobjid_not_found = 2
      OTHERS           = 3.

*** Parameter
  gs_pdpara-profile          = ‘0007’.
  gs_pdpara-packmode         = ‘1’.
  gs_pdpara-selection_dialog = ‘X’.
  gs_pdpara-requ_status      = ‘2’.
  gs_pdpara-requ_stat_save   = ‘2’.
  gs_pdpara-respect_qty      = ‘X’.

  gs_object-objtype    = ’12’. “Freie HU

  APPEND INITIAL LINE TO gt_packitems ASSIGNING <packitem>.
  <packitem>-pgid      = 1.
  <packitem>-matnr     = ‘MAT123’.
  <packitem>-maktx     = ‘Testmaterial 123’.
  <packitem>-charg     = ‘BATCH_0815’.
  <packitem>-xchar     = ‘X’.
  <packitem>-xchpf     = ‘X’.
  <packitem>-magrv     = ‘Z001’.
  <packitem>-rmatp     = ‘RMAT_ABC’.
  <packitem>-werks     = ‘0100’.
  <packitem>-lgort     = ‘0100’.
  <packitem>-acqua     = ‘100.000’. “100 Meter
  <packitem>-qunit_a   = ‘M’.
  <packitem>-packnr    = gv_packnr.
  <packitem>-pos_group = 1.

*** Init
  CALL FUNCTION ‘HU_INITIALIZE_PACKING’.

*** HU aus Packvorschlag erzeugen
  CALL FUNCTION ‘VHUPILE_CREATE_HU_PROPOSALS’
    EXPORTING
      application         = ‘1’
      object              = gs_object
      pdpara              = gs_pdpara
      packitems           = gt_packitems
    IMPORTING
      t_hd_prp            = gt_headers_proposal
      t_hd_cap            = gt_headers_cap
      t_hd_add            = gt_headers_add
      t_items             = gt_items_proposal
    EXCEPTIONS
      failure             = 1
      profile_not_found   = 2
      profile_wrong       = 3
      creation_failed     = 4
      no_packgood_found   = 5
      packinstr_deleted   = 6
      packinstr_not_found = 7
      OTHERS              = 8.
  IF sy-subrc <> 0.
    WRITE: / ‘Fehler’, (2) sy-subrc, ‘Bei VHUPILE_CREATE_HU_PROPOSALS’.
  ENDIF.

  LOOP AT gt_headers_proposal INTO gs_header_proposal.
    CLEAR gs_header_add.
    CLEAR gs_header_cap.

    READ TABLE gt_headers_cap INTO gs_header_cap
          WITH KEY exidv = gs_header_proposal-exidv.
    READ TABLE gt_headers_add INTO gs_header_add
          WITH KEY exidv = gs_header_proposal-exidv.

*** HU aus Packvorschlag anlegen
    CALL FUNCTION ‘HU_CREATE_ONE_HU’
      EXPORTING
        if_create_hu       = space
        is_header_proposal = gs_header_proposal
        is_header_capacity = gs_header_cap
        is_header_add      = gs_header_add
        it_items           = gt_items_proposal
      IMPORTING
        es_header          = gs_hu_header
        et_items           = gt_hu_items
        et_messages        = gt_hu_messages
      EXCEPTIONS
        input_missing      = 1
        not_possible       = 2
        header_error       = 3
        item_error         = 4
        serial_nr_error    = 5
        fatal_error        = 6
        OTHERS             = 7.
    IF sy-subrc <> 0.
      BREAK-POINT.
      WRITE: / ‘Fehler’, (2) sy-subrc, ‘bei HU_CREATE_ONE_HU’.
    ELSE.
      WRITE: / ‘HU erzeugt. EXIDV =’, gs_hu_header-exidv.
    ENDIF.

  ENDLOOP.

*** Verbuchen der Handling Units
  CALL FUNCTION ‘HU_POST’
    EXPORTING
      if_synchron = space
      if_commit   = ‘X’.

Enno Wulff
Letzte Artikel von Enno Wulff (Alle anzeigen)

Leave a Comment