DATA: ls_bapi_header TYPE bapi2093_res_head.
DATA: ls_bapi_items TYPE bapi2093_res_item,
ls_bapi_return TYPE bapiret2.
DATA: lt_bapi_items TYPE bapi2093_res_item OCCURS 0 WITH HEADER LINE,
lt_bapi_return TYPE bapiret2 OCCURS 0 WITH HEADER LINE,
lt_bapi_pasegment TYPE bapi_profitability_segment OCCURS 0.
DATA: ls_le169 LIKE zlet0169.
DATA: l_testrun TYPE bapi2093_test VALUE space.
ls_bapi_header-res_date = sy-datum. " 출고/이동 요청일
ls_bapi_header-move_type = '309'. " 이동유형
ls_bapi_header-move_plant = g_werks. " 입고될 플랜트
ls_bapi_header-move_stloc = g_rgort. " 입고될 저장위치
LOOP AT gt_le169 INTO ls_le169.
ls_bapi_items-material = ls_le169-matnr. " 출고될 품목코드(입/출고 동일)
ls_bapi_items-plant = g_werks. " 출고될 플랜트
ls_bapi_items-stge_loc = g_lgort. " 출고될 저장위치
ls_bapi_items-batch = ls_le169-charg. " 출고자(출고될 뱃치번호)
ls_bapi_items-gr_rcpt = ls_le169-rharg. " 입고자(입고될 뱃치번호) => 입고시 입고뱃치로 활용
ls_bapi_items-entry_qnt = ls_le169-erfmg. " 출고될 수량
ls_bapi_items-entry_uom = ls_le169-erfme. " 출고될 수량단위
ls_bapi_items-movement = 'X'.
APPEND ls_bapi_items TO lt_bapi_items.
ENDLOOP.
CLEAR g_res_number.
CALL FUNCTION 'BAPI_RESERVATION_CREATE1'
EXPORTING
reservationheader = ls_bapi_header
testrun = l_testrun
IMPORTING
reservation = g_res_number
TABLES
reservationitems = lt_bapi_items
profitabilitysegment = lt_bapi_pasegment
return = lt_bapi_return.
IF NOT g_res_number IS INITIAL.
LOOP AT gt_le169 INTO ls_le169.
ls_le169-rsnum = g_res_number.
ls_le169-erdat = sy-datum.
ls_le169-erset = sy-uzeit.
ls_le169-status = '1'.
MODIFY gt_le169 FROM ls_le169 TRANSPORTING rsnum erdat erset status.
ENDLOOP.
INSERT zlet0169 FROM TABLE gt_le169.
IF sy-subrc = 0.
COMMIT WORK.
MESSAGE s060(m7) WITH g_res_number.
LEAVE TO SCREEN 0.
ELSE.
ROLLBACK WORK.
MESSAGE s000 WITH '테이블 ZLET0169 업데이트중 오류가 발생했습니다.'.
ENDIF.
ELSE.
*" 에러를 화면에 보여주는 간단한 소스......
DATA : ls_layout TYPE slis_layout_alv.
DATA : l_repid TYPE sy-repid.
l_repid = sy-repid.
ls_layout-colwidth_optimize = 'X'.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
is_layout = ls_layout
i_structure_name = 'BAPIRET2'
TABLES
t_outtab = lt_bapi_return
EXCEPTIONS
program_error = 1.
ENDIF.
SET PARAMETER ID 'RES' FIELD g_res_number.