Application Development Blog Posts
Learn and share on deeper, cross technology development topics such as integration and connectivity, automation, cloud extensibility, developing at scale, and security.
cancel
Showing results for 
Search instead for 
Did you mean: 
RobertVit
Active Contributor
0 Kudos
2,538

I got a (at least I thought) simple task to update a package instruction via BAPI.

So I started first with retrieving the data via BAPI_HU_PI_READ.

Then (first for testing purpose) I used this data to call the update BAPI_HU_PI_CHANGE.

And surprise it worked – not as I expected.

Normal packaging items (e.g. simple quantity change) worked fine. But we have as well some text items within our packaging instructions which I would not like to change.

Unfortunately calling the BAPI_HU_PI_CHANGE will delete the content of these text items – nevertheless how are you calling the BAPI.

Believe it or not SAP at least provided note 2250415.

Thus makes it impossible to change the package instruction via BAPI as you will get an error message that text items are not supported.

So there comes BAdI PL_PACK_INSTR_BADI where you can suppress the deletion of the text item.

Therefore i implemented method PACK_INSTR_BEFORE_SAVE:

DATA lt_packpo_del TYPE pi_t_packpo.
FIELD-SYMBOLS <ls_packpo> TYPE packpo.
FIELD-SYMBOLS <ls_cmvhupo> TYPE cmvhupo.

*     First check if it is called via BAPI
ASSIGN ('(SAPLVHUPO)CMVHUPO') TO <ls_cmvhupo>.
IF sy-subrc = 0.
IF <ls_cmvhupo>-nodia <> 'X'.
RETURN.
ENDIF.
ELSE.
RETURN.
ENDIF.
IF packpo_del IS INITIAL.
RETURN.
ENDIF.
*    !BAPI deletes content oft text items
*    to suppress deletion remove insert und deletion entries
*    before database update happens
LOOP AT packpo_ins ASSIGNING <ls_packpo> WHERE paitemtype = c_postyp_text.
DELETE packpo_ins WHERE packitemid = <ls_packpo>-packitemid.
ENDLOOP.

SELECT * FROM packpo INTO TABLE lt_packpo_del FOR ALL ENTRIES IN packpo_del
WHERE packitemid = packpo_del-packitemid
AND paitemtype = c_postyp_text.

LOOP AT lt_packpo_del ASSIGNING <ls_packpo>.
DELETE packpo_del WHERE packitemid = <ls_packpo>-packitemid.
ENDLOOP.

Labels in this area