You are on page 1of 25

10/5/2018 ZMMR34.

txt

REPORT zmmr34 NO STANDARD PAGE HEADING.

TYPES : BEGIN OF ty_result_sto,


ref TYPE char50,
docdate TYPE char20,
bukrs TYPE char5,
doctyp TYPE char10,
porg TYPE char6,
pgrp TYPE char6,
splant TYPE char6,
moda TYPE char10,
ebeln LIKE ekko-ebeln,
messg(100),
END OF ty_result_sto.

TYPES : BEGIN OF ty_result_stock,


ref TYPE char50,
docdate TYPE char20,
bukrs TYPE char5,
doctyp TYPE char10,
porg TYPE char6,
pgrp TYPE char6,
plant TYPE char6,
lifnr TYPE lifnr,
ebeln LIKE ekko-ebeln,
messg(100),
END OF ty_result_stock.

TYPES : BEGIN OF ty_result_srv,


ref TYPE char50,
docdate TYPE char20,
bukrs TYPE char5,
doctyp TYPE char10,
porg TYPE char6,
pgrp TYPE char6,
vendor TYPE lifnr,
ebeln LIKE ekko-ebeln,
messg(100),
END OF ty_result_srv.

"--- PO STO -------------------


DATA : BEGIN OF gt_data OCCURS 0,
ref TYPE char50,
docdate TYPE char20,
bukrs TYPE char5,
splant TYPE char6,
moda TYPE char10,
po_itm TYPE char10,
matnr TYPE matnr,
qty TYPE menge_d,
meins TYPE char5,
deldate TYPE char20,
plant TYPE char10,
sloc TYPE char10,
shippoint TYPE char10,
curr TYPE char5,
condtype TYPE char5,
price TYPE netwr,
lifnr TYPE lifnr,
borrow TYPE char1,
doctyp TYPE char10,
porg TYPE char6,
pgrp TYPE char6,
itmcat TYPE char5,
desc TYPE text70,
END OF gt_data.

DATA : BEGIN OF gt_header OCCURS 0,


ref TYPE char50,
https://www.dropbox.com/s/0ikqnaeoc69u74q/ZMMR34.txt?dl=0 1/25
10/5/2018 ZMMR34.txt
docdate TYPE char20,
bukrs TYPE char5,
doctyp TYPE char10,
porg TYPE char6,
pgrp TYPE char6,
splant TYPE char6,
moda TYPE char10,
curr TYPE char5,
borrow TYPE char1,
END OF gt_header.

DATA : BEGIN OF gt_item OCCURS 0,


ref TYPE char50,
docdate TYPE char20,
bukrs TYPE char5,
doctyp TYPE char10,
porg TYPE char6,
pgrp TYPE char6,
splant TYPE char6,
moda TYPE char10,
po_itm TYPE char10,
itmcat TYPE char5,
matnr TYPE matnr,
desc TYPE text70,
qty TYPE menge_d,
meins TYPE char5,
deldate TYPE char20,
plant TYPE char10,
sloc TYPE char10,
shippoint TYPE char10,
END OF gt_item.

DATA : BEGIN OF gt_kschl OCCURS 0,


ref TYPE char50,
docdate TYPE char20,
bukrs TYPE char5,
doctyp TYPE char10,
porg TYPE char6,
pgrp TYPE char6,
splant TYPE char6,
moda TYPE char10,
po_itm TYPE char10,
curr TYPE char5,
condtype TYPE char5,
price TYPE netwr,
lifnr TYPE lifnr,
END OF gt_kschl.
"------ end of PO STO ----------

"_----- PO Service ----------


DATA : BEGIN OF gt_data_srv OCCURS 0,
ref TYPE char50,
docdate TYPE char20,
bukrs TYPE char5,
doctyp TYPE char10,
porg TYPE char6,
pgrp TYPE char6,
vendor TYPE lifnr,
po_itm TYPE char10,
itmcat TYPE char5,
acc_asgn TYPE char10,
descit TYPE text70,
qty TYPE menge_d,
meins TYPE char5,
deldate TYPE char20,
plant TYPE char10,
matkl TYPE char10,
tax TYPE char5,
serv_no TYPE char10,
descsrv TYPE char70,
https://www.dropbox.com/s/0ikqnaeoc69u74q/ZMMR34.txt?dl=0 2/25
10/5/2018 ZMMR34.txt
qtysrv TYPE menge_d,
meinsrv TYPE char5,
price TYPE netwr,
ccenter TYPE char10,
glakun TYPE char15,
END OF gt_data_srv.

DATA : BEGIN OF gt_header_srv OCCURS 0,


ref TYPE char50,
docdate TYPE char20,
bukrs TYPE char5,
doctyp TYPE char10,
porg TYPE char6,
pgrp TYPE char6,
vendor TYPE lifnr,
END OF gt_header_srv.

DATA : BEGIN OF gt_item_srv OCCURS 0,


ref TYPE char50,
docdate TYPE char20,
bukrs TYPE char5,
doctyp TYPE char10,
porg TYPE char6,
pgrp TYPE char6,
vendor TYPE lifnr,
po_itm TYPE char10,
acc_asgn TYPE char10,
itmcat TYPE char5,
descit TYPE text70,
qty TYPE menge_d,
meins TYPE char5,
deldate TYPE char20,
plant TYPE char10,
matkl TYPE char10,
tax TYPE char5,
END OF gt_item_srv.

DATA : BEGIN OF gt_item_srv_det OCCURS 0,


ref TYPE char50,
docdate TYPE char20,
bukrs TYPE char5,
doctyp TYPE char10,
porg TYPE char6,
pgrp TYPE char6,
vendor TYPE lifnr,
po_itm TYPE char10,
serv_no TYPE char10,
descsrv TYPE char70,
qtysrv TYPE menge_d,
meinsrv TYPE char5,
price TYPE netwr,
ccenter TYPE char10,
glakun TYPE saknr,
tax TYPE char5,
END OF gt_item_srv_det.

"------- end of PO Service -----

"------- PO Stock --------------


DATA : BEGIN OF gt_data_stock OCCURS 0,
ref TYPE char50,
docdate TYPE char20,
doctyp TYPE char10,
lifnr TYPE lifnr,
porg TYPE char6,
pgrp TYPE char6,
bukrs TYPE char5,
curr TYPE char5,
po_itm TYPE char10,
matnr TYPE matnr,
https://www.dropbox.com/s/0ikqnaeoc69u74q/ZMMR34.txt?dl=0 3/25
10/5/2018 ZMMR34.txt
plant TYPE char6,
qty TYPE menge_d,
meins TYPE char5,
price TYPE netwr,
deldate TYPE char20,
bwtar TYPE char10,
tax TYPE char5,
END OF gt_data_stock.

DATA : BEGIN OF gt_header_stock OCCURS 0,


ref TYPE char50,
docdate TYPE char20,
bukrs TYPE char5,
doctyp TYPE char10,
lifnr TYPE lifnr,
porg TYPE char6,
pgrp TYPE char6,
plant TYPE char6,
curr TYPE char5,
END OF gt_header_stock.

DATA : BEGIN OF gt_item_stock OCCURS 0,


ref TYPE char50,
docdate TYPE char20,
doctyp TYPE char10,
lifnr TYPE lifnr,
porg TYPE char6,
pgrp TYPE char6,
bukrs TYPE char5,
curr TYPE char5,
po_itm TYPE char10,
matnr TYPE matnr,
plant TYPE char6,
qty TYPE menge_d,
meins TYPE char5,
price TYPE netwr,
deldate TYPE char20,
bwtar TYPE char10,
desc TYPE text70,
tax TYPE char5,
END OF gt_item_stock.

"------- End of PO Stock -------

DATA: t_excel LIKE STANDARD TABLE OF alsmex_tabline WITH HEADER LINE.

DATA : gt_result_sto TYPE ty_result_sto OCCURS 0 WITH HEADER LINE,


gt_result_srv TYPE ty_result_srv OCCURS 0 WITH HEADER LINE,
gt_result_stock TYPE ty_result_stock OCCURS 0 WITH HEADER LINE.

DATA: t_alv_fieldcat TYPE slis_t_fieldcat_alv WITH HEADER LINE,


t_alv_event TYPE slis_t_event WITH HEADER LINE,
t_events TYPE slis_t_event,
t_alv_isort TYPE slis_t_sortinfo_alv WITH HEADER LINE,
d_alv_variant TYPE disvariant.

DATA: d_layout TYPE slis_layout_alv,


d_repid LIKE sy-repid,
d_print TYPE slis_print_alv.

SELECTION-SCREEN BEGIN OF BLOCK blk1 WITH FRAME TITLE text-f01.


PARAMETERS: p_file LIKE rlgrap-filename OBLIGATORY.
PARAMETERS : cb_test AS CHECKBOX DEFAULT 'X'.
SELECTION-SCREEN END OF BLOCK blk1.

SELECTION-SCREEN BEGIN OF BLOCK blk2 WITH FRAME TITLE text-f02.


PARAMETERS: rb_sto RADIOBUTTON GROUP b1 DEFAULT 'X',
rb_srv RADIOBUTTON GROUP b1,
https://www.dropbox.com/s/0ikqnaeoc69u74q/ZMMR34.txt?dl=0 4/25
10/5/2018 ZMMR34.txt
rb_stk RADIOBUTTON GROUP b1.
SELECTION-SCREEN END OF BLOCK blk2.

SELECTION-SCREEN BEGIN OF BLOCK b WITH FRAME TITLE txt_b.


SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 1(31) txt03 FOR FIELD p_col01.
PARAMETERS: p_col01(4) TYPE n DEFAULT 1 OBLIGATORY.
SELECTION-SCREEN COMMENT 41(10) txt04 FOR FIELD p_col02.
PARAMETERS: p_col02(4) TYPE n DEFAULT 30 OBLIGATORY.
SELECTION-SCREEN END OF LINE.

SELECTION-SCREEN BEGIN OF LINE.


SELECTION-SCREEN COMMENT 01(31) txt05 FOR FIELD p_row01.
PARAMETERS: p_row01(4) TYPE n DEFAULT 2 OBLIGATORY.
SELECTION-SCREEN COMMENT 41(10) txt06 FOR FIELD p_row02.
PARAMETERS: p_row02(4) TYPE n DEFAULT 9999 OBLIGATORY.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN END OF BLOCK b.

INITIALIZATION.
txt_b = 'Excel Data Source Ranges'.
txt03 = 'Start column'.
txt04 = 'End column'.
txt05 = 'Start Row'.
txt06 = 'End Row'.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.


PERFORM browse_file CHANGING p_file.

FORM browse_file CHANGING p_file LIKE rlgrap-filename.


DATA: filetab TYPE filetable,
rc TYPE i,
lv_offset TYPE i.

FREE filetab.
CALL METHOD cl_gui_frontend_services=>file_open_dialog
EXPORTING
window_title = 'Choose File'
default_extension = '*.*'
default_filename = 'c:\*.xls'
CHANGING
file_table = filetab
rc = rc
EXCEPTIONS
file_open_dialog_failed = 1
cntl_error = 2
error_no_gui = 3
OTHERS = 4.
IF sy-subrc = 0.
READ TABLE filetab INTO p_file INDEX 1.
ENDIF.
ENDFORM. " browse_file

START-OF-SELECTION.
PERFORM f_get_data_excel.

CASE 'X'.
WHEN rb_sto.
IF gt_data[] IS NOT INITIAL.
PERFORM f_call_bapi.
ENDIF.

WHEN rb_srv.
IF gt_data_srv[] IS NOT INITIAL.
PERFORM f_call_bapi_srv.
ENDIF.

WHEN rb_stk.
https://www.dropbox.com/s/0ikqnaeoc69u74q/ZMMR34.txt?dl=0 5/25
10/5/2018 ZMMR34.txt
IF gt_data_stock[] IS NOT INITIAL.
PERFORM f_call_bapi_stock.
ENDIF.
ENDCASE.

END-OF-SELECTION.
PERFORM f_write_report.

FORM f_get_data_excel .

DATA : ld_col01 TYPE i,


ld_col02 TYPE i,
ld_row01 TYPE i,
ld_row02 TYPE i.
DATA: ld_date(8) TYPE c.

REFRESH : gt_data, gt_header.


ld_col01 = p_col01.
ld_col02 = p_col02.
ld_row01 = p_row01.
ld_row02 = p_row02.

CASE 'X'.
WHEN rb_sto.
PERFORM fm_po_sto_excel USING ld_col01
ld_col02
ld_row01
ld_row02.

WHEN rb_srv.
PERFORM fm_po_serv_excel USING ld_col01
ld_col02
ld_row01
ld_row02.

WHEN rb_stk.
PERFORM fm_po_stock_excel USING ld_col01
ld_col02
ld_row01
ld_row02.
ENDCASE.

DEFINE assign_value.
&1 = &2.
&3 = 'X'.
END-OF-DEFINITION.

ENDFORM.

FORM f_call_bapi.

DATA: lv_tabix LIKE sy-tabix,


lv_exppurchaseorder LIKE bapimepoheader-po_number,
wa_poheader LIKE bapimepoheader,
wa_poheaderx LIKE bapimepoheaderx,
i_poitems TYPE bapimepoitem OCCURS 0 WITH HEADER LINE,
i_poitemsx TYPE bapimepoitemx OCCURS 0 WITH HEADER LINE,
i_poschedule TYPE bapimeposchedule OCCURS 0 WITH HEADER LINE,
i_poschedulex TYPE bapimeposchedulx OCCURS 0 WITH HEADER LINE,
i_poaccount TYPE bapimepoaccount OCCURS 0 WITH HEADER LINE,
i_poaccountx TYPE bapimepoaccountx OCCURS 0 WITH HEADER LINE,
i_pocond TYPE bapimepocond OCCURS 0 WITH HEADER LINE,
i_pocondx TYPE bapimepocondx OCCURS 0 WITH HEADER LINE,
i_return TYPE bapiret2 OCCURS 0 WITH HEADER LINE,
lv_poitem LIKE bapimepoitem-po_item,
i_shipping TYPE bapiitemship OCCURS 0 WITH HEADER LINE,
https://www.dropbox.com/s/0ikqnaeoc69u74q/ZMMR34.txt?dl=0 6/25
10/5/2018 ZMMR34.txt
i_shippingx TYPE bapiitemshipx OCCURS 0 WITH HEADER LINE,
lv_new_menge LIKE ekpo-menge,
lv_old_menge LIKE ekpo-menge,
lv_date(8).

DATA i_extensionin TYPE TABLE OF bapiparex WITH HEADER LINE.


DATA : i_extensioninx TYPE TABLE OF bapiparex WITH HEADER LINE,
ls_bapi_te_mepoheader TYPE zbapi_te_mepoheader,
ls_bapi_te_mepoheaderx TYPE bapi_te_mepoheaderx.

DATA : lv_coitm TYPE i.

SORT gt_header.
LOOP AT gt_header.
CLEAR: wa_poheader, wa_poheaderx, lv_exppurchaseorder.

REFRESH: i_poitems, i_poitemsx, i_poschedule, i_poschedulex,


i_poaccount, i_poaccountx, i_pocond, i_pocondx, i_return, i_extensionin, i_extensioninx,
i_shippingx, i_shipping.

assign_value: wa_poheader-doc_type gt_header-doctyp


wa_poheaderx-doc_type,
wa_poheader-comp_code gt_header-bukrs
wa_poheaderx-comp_code,
wa_poheader-purch_org gt_header-porg
wa_poheaderx-purch_org,
wa_poheader-pur_group gt_header-pgrp
wa_poheaderx-pur_group,
wa_poheader-suppl_plnt gt_header-splant
wa_poheaderx-suppl_plnt,
wa_poheader-doc_date gt_header-docdate
wa_poheaderx-doc_date,
wa_poheader-sales_pers gt_header-ref
wa_poheaderx-sales_pers,
wa_poheader-currency gt_header-curr
wa_poheaderx-currency.

CLEAR i_extensionin.
ls_bapi_te_mepoheader-traty = gt_header-moda.
ls_bapi_te_mepoheader-borrow = gt_header-borrow.
PERFORM transfer_to_extensionin USING ls_bapi_te_mepoheader CHANGING i_extensionin.
i_extensionin-structure = 'ZBAPI_TE_MEPOHEADER'.
APPEND i_extensionin.

CLEAR i_extensionin.
ls_bapi_te_mepoheaderx-traty = 'X'.
ls_bapi_te_mepoheaderx-borrow = 'X'.
PERFORM transfer_to_extensionin USING ls_bapi_te_mepoheaderx CHANGING i_extensionin.
i_extensionin-structure = 'BAPI_TE_MEPOHEADERX'.
APPEND i_extensionin.

LOOP AT gt_item WHERE ref = gt_header-ref


AND doctyp = gt_header-doctyp
AND bukrs = gt_header-bukrs
AND porg = gt_header-porg
AND pgrp = gt_header-pgrp
AND splant = gt_header-splant
AND docdate = gt_header-docdate
AND ref = gt_header-ref
AND moda = gt_header-moda.

CLEAR: i_poitems, i_poitemsx.


i_poitems-po_item = gt_item-po_itm.
i_poitemsx-po_item = gt_item-po_itm.
i_poitemsx-po_itemx = 'X'.
i_poitems-trackingno = gt_item-ref.
i_poitemsx-trackingno = 'X'.

https://www.dropbox.com/s/0ikqnaeoc69u74q/ZMMR34.txt?dl=0 7/25
10/5/2018 ZMMR34.txt
CALL FUNCTION 'CONVERSION_EXIT_CUNIT_INPUT'
EXPORTING
input = gt_item-meins
IMPORTING
output = gt_item-meins
EXCEPTIONS
unit_not_found = 1
OTHERS = 2.

assign_value: i_poitems-material gt_item-matnr i_poitemsx-material,


i_poitems-stge_loc gt_item-sloc i_poitemsx-stge_loc,
i_poitems-plant gt_item-plant i_poitemsx-plant,
i_poitems-quantity gt_item-qty i_poitemsx-quantity,
i_poitems-po_unit gt_item-meins i_poitemsx-po_unit,
i_poitems-gr_ind 'X' i_poitemsx-gr_ind.

IF gt_item-desc NE space.
assign_value: i_poitems-short_text gt_item-desc
i_poitemsx-short_text.
ENDIF.

IF gt_item-itmcat IS INITIAL.
assign_value i_poitems-item_cat '0' i_poitemsx-item_cat.
ELSE.
assign_value i_poitems-item_cat gt_item-itmcat i_poitemsx-item_cat.
ENDIF.
APPEND: i_poitems, i_poitemsx.

CLEAR: i_poschedule, i_poschedulex.


i_poschedule-po_item = gt_item-po_itm.
i_poschedule-sched_line = 1.
i_poschedulex-po_item = gt_item-po_itm.
i_poschedulex-sched_line = 1.
i_poschedulex-po_itemx = 'X'.
i_poschedulex-sched_linex = 'X'.

assign_value: i_poschedule-delivery_date gt_item-deldate


i_poschedulex-delivery_date,
i_poschedule-stat_date gt_item-deldate
i_poschedulex-stat_date,
i_poschedule-quantity gt_item-qty
i_poschedulex-quantity,
i_poschedule-po_date gt_item-docdate
i_poschedulex-po_date.
APPEND: i_poschedule, i_poschedulex.

assign_value: i_shipping-po_item gt_item-po_itm i_shippingx-po_item,


i_shipping-ship_point gt_item-shippoint i_shippingx-ship_point.
i_shippingx-po_item = gt_item-po_itm.
i_shippingx-po_itemx = 'X'.
APPEND : i_shipping, i_shippingx.

CLEAR lv_coitm.
IF gt_header-borrow = ''.
LOOP AT gt_kschl WHERE ref = gt_header-ref
AND doctyp = gt_header-doctyp
AND bukrs = gt_header-bukrs
AND porg = gt_header-porg
AND pgrp = gt_header-pgrp
AND splant = gt_header-splant
AND docdate = gt_header-docdate
AND ref = gt_header-ref
AND moda = gt_header-moda
AND po_itm = gt_item-po_itm.

assign_value: i_pocond-itm_number gt_item-po_itm i_pocondx-itm_number,


i_pocond-cond_type gt_kschl-condtype i_pocondx-cond_type,
i_pocond-cond_value gt_kschl-price i_pocondx-cond_value,
https://www.dropbox.com/s/0ikqnaeoc69u74q/ZMMR34.txt?dl=0 8/25
10/5/2018 ZMMR34.txt
i_pocond-currency gt_kschl-curr i_pocondx-currency.

i_pocondx-itm_number = gt_item-po_itm .
i_pocondx-itm_numberx = 'X' .
i_pocond-vendor_no = gt_kschl-lifnr.
i_pocond-change_id = 'I'.
CONDENSE i_pocond-vendor_no.

i_pocondx-vendor_no = 'X'.
i_pocondx-change_id = 'X'.
APPEND : i_pocond, i_pocondx.
ENDLOOP.
ENDIF.

ENDLOOP.

CALL FUNCTION 'BAPI_PO_CREATE1'


EXPORTING
poheader = wa_poheader
poheaderx = wa_poheaderx
no_price_from_po = 'X'
testrun = cb_test
IMPORTING
exppurchaseorder = lv_exppurchaseorder
TABLES
return = i_return
poitem = i_poitems
poitemx = i_poitemsx
pocond = i_pocond
pocondx = i_pocondx
poschedule = i_poschedule
poschedulex = i_poschedulex
poshipping = i_shipping
poshippingx = i_shippingx
extensionin = i_extensionin.

IF lv_exppurchaseorder EQ ''.
READ TABLE i_return WITH KEY type = 'E'.
IF sy-subrc EQ 0.
LOOP AT i_return WHERE type = 'E'.
MOVE-CORRESPONDING gt_header TO gt_result_sto.
CONCATENATE i_return-type i_return-message INTO gt_result_sto-messg SEPARATED BY space.

COLLECT gt_result_sto.
ENDLOOP.

ELSE.
MOVE-CORRESPONDING gt_header TO gt_result_sto.
gt_result_sto-messg = 'Error Not Found'.
COLLECT gt_result_sto.
ENDIF.

ELSE.
MOVE-CORRESPONDING gt_header TO gt_result_sto.
gt_result_sto-ebeln = lv_exppurchaseorder.
gt_result_sto-messg = 'Create PO Success'.
COLLECT gt_result_sto.
ENDIF.

IF cb_test EQ ''.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = 'X'.
ENDIF.

ENDLOOP.

ENDFORM.

https://www.dropbox.com/s/0ikqnaeoc69u74q/ZMMR34.txt?dl=0 9/25
10/5/2018 ZMMR34.txt
FORM transfer_to_extensionin
USING
is_bapi_extensionin TYPE any
CHANGING
cs_bapiparex TYPE bapiparex.
DATA l_distance_characters TYPE i.
FIELD-SYMBOLS <any> TYPE any.

DESCRIBE DISTANCE BETWEEN cs_bapiparex-structure


AND cs_bapiparex-valuepart1
INTO l_distance_characters
IN CHARACTER MODE.
ASSIGN cs_bapiparex+l_distance_characters(*) TO <any>
CASTING LIKE is_bapi_extensionin.
<any> = is_bapi_extensionin.
ENDFORM.

FORM f_gui_message USING fu_1.

CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'


EXPORTING
percentage = 0
text = fu_1.
ENDFORM. " F_GUI_MESSAGE
*&---------------------------------------------------------------------*
*& Form F_WRITE_REPORT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM f_write_report .

DATA : lv_no TYPE int4.

CASE 'X'.
WHEN rb_srv.

LOOP AT gt_header_srv.
FORMAT COLOR COL_HEADING.
WRITE : /,
AT 1(30) gt_header_srv-ref ,
AT 32(5) gt_header_srv-docdate ,
AT 39(5) gt_header_srv-bukrs ,
AT 47(5) gt_header_srv-doctyp ,
AT 54(5) gt_header_srv-porg ,
AT 61(5) gt_header_srv-pgrp ,
AT 68(5) gt_header_srv-vendor .

NEW-LINE.

FORMAT COLOR COL_BACKGROUND.


CLEAR lv_no.

LOOP AT gt_result_srv WHERE ref = gt_header_srv-ref


AND docdate = gt_header_srv-docdate
AND bukrs = gt_header_srv-bukrs
AND doctyp = gt_header_srv-doctyp
AND porg = gt_header_srv-porg
AND pgrp = gt_header_srv-pgrp
AND vendor = gt_header_srv-vendor.

ADD 1 TO lv_no.
WRITE : /,
AT 1(5) lv_no,
AT 7(12) gt_result_srv-ebeln,
AT 22(100) gt_result_srv-messg.

https://www.dropbox.com/s/0ikqnaeoc69u74q/ZMMR34.txt?dl=0 10/25
10/5/2018 ZMMR34.txt
ENDLOOP.

WRITE : /, sy-uline.
ENDLOOP.

WHEN rb_sto.

LOOP AT gt_header.
FORMAT COLOR COL_HEADING.
WRITE : /,
AT 1(30) gt_header-ref ,
AT 32(5) gt_header-docdate ,
AT 39(5) gt_header-bukrs ,
AT 47(5) gt_header-doctyp ,
AT 54(5) gt_header-porg ,
AT 61(5) gt_header-pgrp ,
AT 68(5) gt_header-splant ,
AT 75(5) gt_header-moda.

NEW-LINE.

FORMAT COLOR COL_BACKGROUND.


CLEAR lv_no.

LOOP AT gt_result_sto WHERE ref = gt_header-ref


AND docdate = gt_header-docdate
AND bukrs = gt_header-bukrs
AND doctyp = gt_header-doctyp
AND porg = gt_header-porg
AND pgrp = gt_header-pgrp
AND splant = gt_header-splant
AND moda = gt_header-moda..

ADD 1 TO lv_no.
WRITE : /,
AT 1(5) lv_no,
AT 7(12) gt_result_sto-ebeln,
AT 22(100) gt_result_sto-messg.

ENDLOOP.

WRITE : /, sy-uline.
ENDLOOP.

WHEN rb_stk.

LOOP AT gt_header_stock.
FORMAT COLOR COL_HEADING.
WRITE : /,
AT 1(30) gt_header_stock-ref ,
AT 32(5) gt_header_stock-docdate ,
AT 39(5) gt_header_stock-bukrs ,
AT 47(5) gt_header_stock-doctyp ,
AT 54(5) gt_header_stock-porg ,
AT 61(5) gt_header_stock-pgrp ,
AT 68(5) gt_header_stock-plant ,
AT 75(5) gt_header_stock-lifnr.

NEW-LINE.

FORMAT COLOR COL_BACKGROUND.


CLEAR lv_no.

LOOP AT gt_result_stock WHERE ref = gt_header_stock-ref


AND docdate = gt_header_stock-docdate
AND bukrs = gt_header_stock-bukrs
AND doctyp = gt_header_stock-doctyp
AND porg = gt_header_stock-porg
https://www.dropbox.com/s/0ikqnaeoc69u74q/ZMMR34.txt?dl=0 11/25
10/5/2018 ZMMR34.txt
AND pgrp = gt_header_stock-pgrp
AND plant = gt_header_stock-plant
AND lifnr = gt_header_stock-lifnr..

ADD 1 TO lv_no.
WRITE : /,
AT 1(5) lv_no,
AT 7(12) gt_result_stock-ebeln,
AT 22(100) gt_result_stock-messg.

ENDLOOP.

WRITE : /, sy-uline.
ENDLOOP.

ENDCASE.

ENDFORM.

*&---------------------------------------------------------------------*
*& Form FM_PO_STO_EXCEL
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM fm_po_sto_excel USING ld_col01
ld_col02
ld_row01
ld_row02.

PERFORM f_gui_message USING 'Open Excel Files and Call Object ...'.
CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
EXPORTING
filename = p_file
i_begin_col = ld_col01
i_begin_row = ld_row01
i_end_col = ld_col02
i_end_row = ld_row02
TABLES
intern = t_excel
EXCEPTIONS
inconsistent_parameters = 1
upload_ole = 2
OTHERS = 3.
IF sy-subrc <> 0.
ELSE.
PERFORM f_gui_message USING 'Finish Reading Excel Data ...'.
ENDIF.

LOOP AT t_excel.
CASE t_excel-col.
WHEN '0001'.
MOVE t_excel-value TO gt_data-ref.
WHEN '0002'.
MOVE t_excel-value TO gt_data-docdate.
WHEN '0003'.
MOVE t_excel-value TO gt_data-bukrs.
WHEN '0004'.
MOVE t_excel-value TO gt_data-splant.
WHEN '0005'.
MOVE t_excel-value TO gt_data-moda.
WHEN '0006'.
MOVE t_excel-value TO gt_data-po_itm.
WHEN '0007'.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = t_excel-value
https://www.dropbox.com/s/0ikqnaeoc69u74q/ZMMR34.txt?dl=0 12/25
10/5/2018 ZMMR34.txt
IMPORTING
output = gt_data-matnr.

WHEN '0008'.
MOVE t_excel-value TO gt_data-qty.
WHEN '0009'.
MOVE t_excel-value TO gt_data-meins.
WHEN '0010'.
MOVE t_excel-value TO gt_data-deldate.
WHEN '0011'.
MOVE t_excel-value TO gt_data-plant.
WHEN '0012'.
MOVE t_excel-value TO gt_data-sloc.
WHEN '0013'.
MOVE t_excel-value TO gt_data-shippoint.
WHEN '0014'.
MOVE t_excel-value TO gt_data-curr.
WHEN '0015'.
MOVE t_excel-value TO gt_data-condtype.
WHEN '0016'.
MOVE t_excel-value TO gt_data-price.
WHEN '0017'.
MOVE t_excel-value TO gt_data-lifnr.
WHEN '0018'.
MOVE t_excel-value TO gt_data-borrow.
ENDCASE.

AT END OF row.
APPEND gt_data.
CLEAR gt_data.
ENDAT.
ENDLOOP.

IF gt_data[] IS NOT INITIAL.


DATA : lv_itm TYPE char10.

LOOP AT gt_data.
CASE gt_data-bukrs.
WHEN 'B000'.
gt_data-doctyp = 'ZBUL'.
gt_data-porg = 'B000'.
gt_data-pgrp = 'B70'.
WHEN 'C000'.
gt_data-doctyp = 'ZCUL'.
gt_data-porg = 'C000'.
gt_data-pgrp = 'C70'.
WHEN 'D000'.
gt_data-doctyp = 'ZDUL'.
gt_data-porg = 'D000'.
gt_data-pgrp = 'D70'.
WHEN 'E000'.
gt_data-doctyp = 'ZEUL'.
gt_data-porg = 'E000'.
gt_data-pgrp = 'E70'.
WHEN 'F000'.
gt_data-doctyp = 'ZFUL'.
gt_data-porg = 'F000'.
gt_data-pgrp = 'F70'.
ENDCASE.
MODIFY gt_data TRANSPORTING doctyp porg pgrp.
ENDLOOP.

LOOP AT gt_data.
MOVE-CORRESPONDING gt_data TO gt_header.
APPEND gt_header.
ENDLOOP.

SORT gt_header BY ref docdate bukrs doctyp porg pgrp splant moda curr borrow.
DELETE ADJACENT DUPLICATES FROM gt_header.

https://www.dropbox.com/s/0ikqnaeoc69u74q/ZMMR34.txt?dl=0 13/25
10/5/2018 ZMMR34.txt
REFRESH gt_item.
LOOP AT gt_header.
CLEAR lv_itm.
LOOP AT gt_data WHERE ref = gt_header-ref
AND doctyp = gt_header-doctyp
AND bukrs = gt_header-bukrs
AND porg = gt_header-porg
AND pgrp = gt_header-pgrp
AND splant = gt_header-splant
AND docdate = gt_header-docdate
AND ref = gt_header-ref
AND moda = gt_header-moda.

MOVE-CORRESPONDING gt_data TO gt_item.

SELECT SINGLE maktx FROM makt INTO gt_item-desc


WHERE matnr = gt_item-matnr.

gt_item-itmcat = 'U'.
APPEND gt_item.

ENDLOOP.
ENDLOOP.

DELETE ADJACENT DUPLICATES FROM gt_item.

REFRESH gt_kschl.
LOOP AT gt_header.
LOOP AT gt_data WHERE ref = gt_header-ref
AND doctyp = gt_header-doctyp
AND bukrs = gt_header-bukrs
AND porg = gt_header-porg
AND pgrp = gt_header-pgrp
AND splant = gt_header-splant
AND docdate = gt_header-docdate
AND ref = gt_header-ref
AND moda = gt_header-moda.

CLEAR gt_kschl.
MOVE-CORRESPONDING gt_data TO gt_kschl.
APPEND gt_kschl.

ENDLOOP.
ENDLOOP.

DELETE ADJACENT DUPLICATES FROM gt_kschl.


ENDIF.

ENDFORM.

FORM fm_po_serv_excel USING ld_col01


ld_col02
ld_row01
ld_row02.

PERFORM f_gui_message USING 'Open Excel Files and Call Object ...'.
CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
EXPORTING
filename = p_file
i_begin_col = ld_col01
i_begin_row = ld_row01
i_end_col = ld_col02
i_end_row = ld_row02
TABLES
intern = t_excel
EXCEPTIONS
inconsistent_parameters = 1
upload_ole = 2
https://www.dropbox.com/s/0ikqnaeoc69u74q/ZMMR34.txt?dl=0 14/25
10/5/2018 ZMMR34.txt
OTHERS = 3.
IF sy-subrc <> 0.
ELSE.
PERFORM f_gui_message USING 'Finish Reading Excel Data ...'.
ENDIF.

REFRESH : gt_header_srv, gt_item_srv, gt_item_srv_det.


LOOP AT t_excel.
CASE t_excel-col.
WHEN '0001'.
MOVE t_excel-value TO gt_data_srv-ref.
WHEN '0002'.
MOVE t_excel-value TO gt_data_srv-docdate.
WHEN '0003'.
MOVE t_excel-value TO gt_data_srv-bukrs.
WHEN '0004'.
MOVE t_excel-value TO gt_data_srv-doctyp.
WHEN '0005'.
MOVE t_excel-value TO gt_data_srv-porg.
WHEN '0006'.
MOVE t_excel-value TO gt_data_srv-pgrp.
WHEN '0007'.
MOVE t_excel-value TO gt_data_srv-vendor.
WHEN '0008'.
MOVE t_excel-value TO gt_data_srv-po_itm.
WHEN '0009'.
MOVE t_excel-value TO gt_data_srv-itmcat.
WHEN '0010'.
MOVE t_excel-value TO gt_data_srv-acc_asgn.
WHEN '0011'.
MOVE t_excel-value TO gt_data_srv-descit.
WHEN '0012'.
MOVE t_excel-value TO gt_data_srv-qty.
WHEN '0013'.
MOVE t_excel-value TO gt_data_srv-meins.
WHEN '0014'.
MOVE t_excel-value TO gt_data_srv-deldate.
WHEN '0015'.
MOVE t_excel-value TO gt_data_srv-plant.
WHEN '0016'.
MOVE t_excel-value TO gt_data_srv-matkl.
WHEN '0017'.
MOVE t_excel-value TO gt_data_srv-tax.
WHEN '0018'.
MOVE t_excel-value TO gt_data_srv-serv_no.
WHEN '0019'.
MOVE t_excel-value TO gt_data_srv-descsrv.
WHEN '0020'.
MOVE t_excel-value TO gt_data_srv-qtysrv.
WHEN '0021'.
MOVE t_excel-value TO gt_data_srv-meinsrv.
WHEN '0022'.
MOVE t_excel-value TO gt_data_srv-price.
WHEN '0023'.
MOVE t_excel-value TO gt_data_srv-ccenter.
WHEN '0024'.
MOVE t_excel-value TO gt_data_srv-glakun.
ENDCASE.

AT END OF row.
APPEND gt_data_srv.
CLEAR gt_data_srv.
ENDAT.
ENDLOOP.

IF gt_data_srv[] IS NOT INITIAL.


DATA : lv_itm TYPE char10.

LOOP AT gt_data_srv.
MOVE-CORRESPONDING gt_data_srv TO gt_header_srv.
https://www.dropbox.com/s/0ikqnaeoc69u74q/ZMMR34.txt?dl=0 15/25
10/5/2018 ZMMR34.txt
APPEND gt_header_srv.
ENDLOOP.

SORT gt_header_srv BY ref docdate bukrs doctyp porg pgrp vendor.


DELETE ADJACENT DUPLICATES FROM gt_header_srv.

REFRESH gt_item_srv.
LOOP AT gt_header_srv.
CLEAR lv_itm.
LOOP AT gt_data_srv WHERE ref = gt_header_srv-ref
AND doctyp = gt_header_srv-doctyp
AND bukrs = gt_header_srv-bukrs
AND porg = gt_header_srv-porg
AND pgrp = gt_header_srv-pgrp
AND docdate = gt_header_srv-docdate
AND ref = gt_header_srv-ref
AND vendor = gt_header_srv-vendor.

CLEAR gt_item_srv.
MOVE-CORRESPONDING gt_data_srv TO gt_item_srv.
APPEND gt_item_srv.

ENDLOOP.
ENDLOOP.

DELETE ADJACENT DUPLICATES FROM gt_item_srv.

REFRESH gt_item_srv_det.
LOOP AT gt_header_srv.
LOOP AT gt_data_srv WHERE ref = gt_header_srv-ref
AND doctyp = gt_header_srv-doctyp
AND bukrs = gt_header_srv-bukrs
AND porg = gt_header_srv-porg
AND pgrp = gt_header_srv-pgrp
AND docdate = gt_header_srv-docdate
AND ref = gt_header_srv-ref
AND vendor = gt_header_srv-vendor.

CLEAR gt_item_srv_det..
MOVE-CORRESPONDING gt_data_srv TO gt_item_srv_det.
APPEND gt_item_srv_det.

ENDLOOP.
ENDLOOP.

DELETE ADJACENT DUPLICATES FROM gt_item_srv_det.


ENDIF.

ENDFORM.
*&---------------------------------------------------------------------*
*& Form F_CALL_BAPI_SRV
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM f_call_bapi_srv .

DATA: lv_tabix LIKE sy-tabix,


lv_exppurchaseorder LIKE bapimepoheader-po_number,
wa_poheader LIKE bapimepoheader,
wa_poheaderx LIKE bapimepoheaderx,
i_poitems TYPE bapimepoitem OCCURS 0 WITH HEADER LINE,
i_poitemsx TYPE bapimepoitemx OCCURS 0 WITH HEADER LINE,
i_poschedule TYPE bapimeposchedule OCCURS 0 WITH HEADER LINE,
i_poschedulex TYPE bapimeposchedulx OCCURS 0 WITH HEADER LINE,
i_poaccount TYPE bapimepoaccount OCCURS 0 WITH HEADER LINE,
https://www.dropbox.com/s/0ikqnaeoc69u74q/ZMMR34.txt?dl=0 16/25
10/5/2018 ZMMR34.txt
i_poaccountx TYPE bapimepoaccountx OCCURS 0 WITH HEADER LINE,
i_pocond TYPE bapimepocond OCCURS 0 WITH HEADER LINE,
i_pocondx TYPE bapimepocondx OCCURS 0 WITH HEADER LINE,
i_return TYPE bapiret2 OCCURS 0 WITH HEADER LINE,
lv_poitem LIKE bapimepoitem-po_item,
i_shipping TYPE bapiitemship OCCURS 0 WITH HEADER LINE,
i_shippingx TYPE bapiitemshipx OCCURS 0 WITH HEADER LINE,
i_service TYPE bapiesllc OCCURS 0 WITH HEADER LINE,
i_service_value TYPE bapiesklc OCCURS 0 WITH HEADER LINE,
lv_new_menge LIKE ekpo-menge,
lv_old_menge LIKE ekpo-menge,
lv_date(8).

DATA : lv_coitm TYPE i,


lv_pckg_no TYPE n LENGTH 10,
lv_subpckg_no TYPE n LENGTH 10,
lv_serno_acc TYPE dzekkn,
lv_serno TYPE dzekkn,
lv_line_no TYPE n LENGTH 10.

DATA : lv_extrow TYPE extrow,


lv_serial TYPE numc2.

DATA : lv_epstp LIKE t163y-epstp.

REFRESH : gt_result_srv.

SORT gt_header_srv.
LOOP AT gt_header_srv.
CLEAR: wa_poheader, wa_poheaderx, lv_exppurchaseorder, lv_pckg_no, lv_subpckg_no, lv_serno_acc, lv_serno,
lv_serial, lv_extrow,
lv_line_no.

REFRESH: i_poitems, i_poitemsx, i_poschedule, i_poschedulex,


i_poaccount, i_poaccountx, i_pocond, i_pocondx, i_return, i_shippingx, i_shipping,
i_service, i_service_value.

assign_value: wa_poheader-doc_type gt_header_srv-doctyp


wa_poheaderx-doc_type,
wa_poheader-comp_code gt_header_srv-bukrs
wa_poheaderx-comp_code,
wa_poheader-purch_org gt_header_srv-porg
wa_poheaderx-purch_org,
wa_poheader-pur_group gt_header_srv-pgrp
wa_poheaderx-pur_group,
wa_poheader-doc_date gt_header_srv-docdate
wa_poheaderx-doc_date,
wa_poheader-sales_pers gt_header_srv-ref
wa_poheaderx-sales_pers,
wa_poheader-vendor gt_header_srv-vendor
wa_poheaderx-vendor.

LOOP AT gt_item_srv WHERE ref = gt_header_srv-ref


AND doctyp = gt_header_srv-doctyp
AND bukrs = gt_header_srv-bukrs
AND porg = gt_header_srv-porg
AND pgrp = gt_header_srv-pgrp
AND vendor = gt_header_srv-vendor
AND docdate = gt_header_srv-docdate
AND ref = gt_header_srv-ref.

CLEAR: i_poitems, i_poitemsx.


CLEAR : i_service, i_service_value, lv_line_no, lv_extrow, lv_serial.

i_poitems-po_item = gt_item_srv-po_itm.
i_poitemsx-po_item = gt_item_srv-po_itm.
i_poitems-trackingno = gt_item_srv-ref.
https://www.dropbox.com/s/0ikqnaeoc69u74q/ZMMR34.txt?dl=0 17/25
10/5/2018 ZMMR34.txt
i_poitemsx-trackingno = 'X'.
i_poitemsx-po_itemx = 'X'.

CALL FUNCTION 'CONVERSION_EXIT_CUNIT_INPUT'


EXPORTING
input = gt_item_srv-meins
IMPORTING
output = gt_item_srv-meins
EXCEPTIONS
unit_not_found = 1
OTHERS = 2.

ADD 1 TO lv_pckg_no.

assign_value: i_poitems-plant gt_item_srv-plant i_poitemsx-plant,


i_poitems-quantity gt_item_srv-qty i_poitemsx-quantity,
i_poitems-po_unit gt_item_srv-meins i_poitemsx-po_unit,
i_poitems-acctasscat gt_item_srv-acc_asgn i_poitemsx-acctasscat,
i_poitems-matl_group gt_item_srv-matkl i_poitemsx-matl_group,
i_poitems-pckg_no lv_pckg_no i_poitemsx-pckg_no,
i_poitems-tax_code gt_item_srv-tax i_poitemsx-tax_code,
i_poitems-distrib '2' i_poitemsx-distrib,
i_poitems-part_inv '2' i_poitemsx-part_inv,
i_poitems-gr_ind 'X' i_poitemsx-gr_ind,
i_poitems-ir_ind 'X' i_poitemsx-ir_ind.

IF gt_item_srv-descit NE space.
assign_value: i_poitems-short_text gt_item_srv-descit
i_poitemsx-short_text.
ENDIF.

IF gt_item_srv-itmcat IS INITIAL.
assign_value i_poitems-item_cat '0' i_poitemsx-item_cat.
ELSE.

lv_epstp = gt_item_srv-itmcat.

CALL FUNCTION 'ME_ITEM_CATEGORY_INPUT'


EXPORTING
epstp = lv_epstp
IMPORTING
pstyp = lv_epstp.

assign_value i_poitems-item_cat lv_epstp i_poitemsx-item_cat.


ENDIF.
APPEND: i_poitems, i_poitemsx.

"_Services Header

ADD 1 TO lv_line_no.
ADD 2 TO lv_subpckg_no.

i_service-pckg_no = lv_pckg_no.
i_service-line_no = lv_line_no.
i_service-subpckg_no = lv_subpckg_no.
i_service-outl_ind = 'X'.
APPEND i_service.

lv_pckg_no = lv_subpckg_no.

CLEAR: i_poschedule, i_poschedulex.


i_poschedule-po_item = gt_item_srv-po_itm.
i_poschedule-sched_line = 1.
i_poschedulex-po_item = gt_item_srv-po_itm.
i_poschedulex-sched_line = 1.
i_poschedulex-po_itemx = 'X'.
i_poschedulex-sched_linex = 'X'.

assign_value: i_poschedule-delivery_date gt_item_srv-deldate


https://www.dropbox.com/s/0ikqnaeoc69u74q/ZMMR34.txt?dl=0 18/25
10/5/2018 ZMMR34.txt
i_poschedulex-delivery_date,
i_poschedule-stat_date gt_item_srv-deldate
i_poschedulex-stat_date,
i_poschedule-quantity gt_item_srv-qty
i_poschedulex-quantity,
i_poschedule-po_date gt_item_srv-docdate
i_poschedulex-po_date.
APPEND: i_poschedule, i_poschedulex.

CLEAR :lv_extrow.
LOOP AT gt_item_srv_det WHERE ref = gt_header_srv-ref
AND doctyp = gt_header_srv-doctyp
AND bukrs = gt_header_srv-bukrs
AND porg = gt_header_srv-porg
AND pgrp = gt_header_srv-pgrp
AND docdate = gt_header_srv-docdate
AND ref = gt_header_srv-ref
AND vendor = gt_header_srv-vendor
AND po_itm = gt_item_srv-po_itm.

CLEAR : i_service, i_service_value, i_poaccountx, i_poaccount.

ADD 1 TO lv_line_no.
ADD 10 TO lv_extrow.
ADD 1 TO lv_serial.

i_service-line_no = lv_line_no.
i_service-ext_line = lv_extrow.
i_service-pckg_no = lv_subpckg_no.

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'


EXPORTING
input = gt_item_srv_det-serv_no
IMPORTING
output = i_service-service.

i_service-quantity = gt_item_srv_det-qtysrv.

CALL FUNCTION 'CONVERSION_EXIT_CUNIT_INPUT'


EXPORTING
input = gt_item_srv_det-meinsrv
IMPORTING
output = gt_item_srv_det-meinsrv
EXCEPTIONS
unit_not_found = 1
OTHERS = 2.

i_service-short_text = gt_item_srv_det-descsrv.
i_service-base_uom = gt_item_srv_det-meinsrv.
i_service-gr_price = gt_item_srv_det-price / 100.
i_service-matl_group = gt_item_srv-matkl.
i_service-price_unit = 1.
i_service-tax_code = gt_item_srv_det-tax.
APPEND i_service.

"_Service Values.
i_service_value-pckg_no = lv_subpckg_no.
i_service_value-line_no = lv_line_no.
i_service_value-serno_line = '01'.
i_service_value-serial_no = lv_serial.
APPEND i_service_value.

"_Account.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = gt_item_srv_det-glakun
IMPORTING
output = gt_item_srv_det-glakun.
https://www.dropbox.com/s/0ikqnaeoc69u74q/ZMMR34.txt?dl=0 19/25
10/5/2018 ZMMR34.txt

assign_value: i_poaccount-po_item gt_item_srv-po_itm i_poaccountx-po_itemx,


i_poaccount-serial_no lv_serial i_poaccountx-serial_nox,
i_poaccount-gl_account gt_item_srv_det-glakun i_poaccountx-gl_account,
i_poaccount-costcenter gt_item_srv_det-ccenter i_poaccountx-costcenter.

i_poaccountx-po_item = gt_item_srv-po_itm.
i_poaccountx-serial_no = lv_serial.

i_poaccount-co_area = 'PIHC'.
i_poaccountx-co_area = 'X'.

APPEND : i_poaccountx, i_poaccount.

ENDLOOP.
ENDLOOP.

break aby_abap1.
CALL FUNCTION 'BAPI_PO_CREATE1'
EXPORTING
poheader = wa_poheader
poheaderx = wa_poheaderx
testrun = cb_test
no_price_from_po = 'X'
IMPORTING
exppurchaseorder = lv_exppurchaseorder
TABLES
return = i_return
poitem = i_poitems
poitemx = i_poitemsx
poschedule = i_poschedule
poschedulex = i_poschedulex
poservices = i_service
posrvaccessvalues = i_service_value
poaccount = i_poaccount
poaccountx = i_poaccountx.

IF lv_exppurchaseorder EQ ''.
READ TABLE i_return WITH KEY type = 'E'.
IF sy-subrc EQ 0.
LOOP AT i_return WHERE type = 'E'.
MOVE-CORRESPONDING gt_header_srv TO gt_result_srv.
CONCATENATE i_return-type i_return-message INTO gt_result_srv-messg SEPARATED BY space.

COLLECT gt_result_srv.
ENDLOOP.
ELSE.
MOVE-CORRESPONDING gt_header_srv TO gt_result_srv.
gt_result_srv-messg = 'Error Not Found'.
COLLECT gt_result_srv.
ENDIF.

ELSE.
MOVE-CORRESPONDING gt_header_srv TO gt_result_srv.
gt_result_srv-ebeln = lv_exppurchaseorder.
gt_result_srv-messg = 'Create PO Success'.
COLLECT gt_result_srv.
ENDIF.

IF cb_test EQ ''.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = 'X'.
ENDIF.

ENDLOOP.

ENDFORM.
*&---------------------------------------------------------------------*
https://www.dropbox.com/s/0ikqnaeoc69u74q/ZMMR34.txt?dl=0 20/25
10/5/2018 ZMMR34.txt
*& Form FM_PO_STOCK_EXCEL
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_LD_COL01 text
* -->P_LD_COL02 text
* -->P_LD_ROW01 text
* -->P_LD_ROW02 text
*----------------------------------------------------------------------*
FORM fm_po_stock_excel USING ld_col01
ld_col02
ld_row01
ld_row02.

PERFORM f_gui_message USING 'Open Excel Files and Call Object ...'.
CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
EXPORTING
filename = p_file
i_begin_col = ld_col01
i_begin_row = ld_row01
i_end_col = ld_col02
i_end_row = ld_row02
TABLES
intern = t_excel
EXCEPTIONS
inconsistent_parameters = 1
upload_ole = 2
OTHERS = 3.
IF sy-subrc <> 0.
ELSE.
PERFORM f_gui_message USING 'Finish Reading Excel Data ...'.
ENDIF.

LOOP AT t_excel.
CASE t_excel-col.
WHEN '0001'.
MOVE t_excel-value TO gt_data_stock-ref.
WHEN '0002'.
MOVE t_excel-value TO gt_data_stock-docdate.

WHEN '0003'.
MOVE t_excel-value TO gt_data_stock-doctyp.
WHEN '0004'.
MOVE t_excel-value TO gt_data_stock-lifnr.
WHEN '0005'.
MOVE t_excel-value TO gt_data_stock-porg.
WHEN '0006'.
MOVE t_excel-value TO gt_data_stock-pgrp.
WHEN '0007'.
MOVE t_excel-value TO gt_data_stock-bukrs.
WHEN '0008'.
MOVE t_excel-value TO gt_data_stock-curr.
WHEN '0009'.
MOVE t_excel-value TO gt_data_stock-po_itm.
WHEN '0010'.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = t_excel-value
IMPORTING
output = gt_data_stock-matnr.

WHEN '0011'.
MOVE t_excel-value TO gt_data_stock-plant.
WHEN '0012'.
MOVE t_excel-value TO gt_data_stock-qty.
WHEN '0013'.
MOVE t_excel-value TO gt_data_stock-meins.
WHEN '0014'.
MOVE t_excel-value TO gt_data_stock-price.
WHEN '0015'.
https://www.dropbox.com/s/0ikqnaeoc69u74q/ZMMR34.txt?dl=0 21/25
10/5/2018 ZMMR34.txt
MOVE t_excel-value TO gt_data_stock-deldate.

WHEN '0016'.
MOVE t_excel-value TO gt_data_stock-bwtar.
WHEN '0017'.
MOVE t_excel-value TO gt_data_stock-tax.
ENDCASE.

AT END OF row.
APPEND gt_data_stock.
CLEAR gt_data_stock.
ENDAT.
ENDLOOP.

IF gt_data_stock[] IS NOT INITIAL.


DATA : lv_itm TYPE char10.

LOOP AT gt_data_stock.
MOVE-CORRESPONDING gt_data_stock TO gt_header_stock.
APPEND gt_header_stock.
ENDLOOP.

SORT gt_header_stock BY ref docdate bukrs doctyp lifnr porg pgrp plant curr.
DELETE ADJACENT DUPLICATES FROM gt_header_stock.

REFRESH gt_item_stock.

LOOP AT gt_header_stock.
CLEAR lv_itm.
LOOP AT gt_data_stock WHERE ref = gt_header_stock-ref
AND docdate = gt_header_stock-docdate
AND bukrs = gt_header_stock-bukrs
AND doctyp = gt_header_stock-doctyp
AND lifnr = gt_header_stock-lifnr
AND porg = gt_header_stock-porg
AND plant = gt_header_stock-plant
AND pgrp = gt_header_stock-pgrp.

MOVE-CORRESPONDING gt_data_stock TO gt_item_stock.

SELECT SINGLE maktx FROM makt INTO gt_item_stock-desc


WHERE matnr = gt_item_stock-matnr.

APPEND gt_item_stock.

ENDLOOP.
ENDLOOP.

DELETE ADJACENT DUPLICATES FROM gt_item_stock.


ENDIF.

ENDFORM.
*&---------------------------------------------------------------------*
*& Form F_CALL_BAPI_STOCK
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM f_call_bapi_stock .

DATA: lv_tabix LIKE sy-tabix,


lv_exppurchaseorder LIKE bapimepoheader-po_number,
wa_poheader LIKE bapimepoheader,
wa_poheaderx LIKE bapimepoheaderx,
i_poitems TYPE bapimepoitem OCCURS 0 WITH HEADER LINE,
i_poitemsx TYPE bapimepoitemx OCCURS 0 WITH HEADER LINE,
i_poschedule TYPE bapimeposchedule OCCURS 0 WITH HEADER LINE,
https://www.dropbox.com/s/0ikqnaeoc69u74q/ZMMR34.txt?dl=0 22/25
10/5/2018 ZMMR34.txt
i_poschedulex TYPE bapimeposchedulx OCCURS 0 WITH HEADER LINE,
i_poaccount TYPE bapimepoaccount OCCURS 0 WITH HEADER LINE,
i_poaccountx TYPE bapimepoaccountx OCCURS 0 WITH HEADER LINE,
i_pocond TYPE bapimepocond OCCURS 0 WITH HEADER LINE,
i_pocondx TYPE bapimepocondx OCCURS 0 WITH HEADER LINE,
i_pocondheader TYPE bapimepocondheader OCCURS 0 WITH HEADER LINE,
i_pocondheaderx TYPE bapimepocondheaderx OCCURS 0 WITH HEADER LINE,
i_return TYPE bapiret2 OCCURS 0 WITH HEADER LINE,
lv_poitem LIKE bapimepoitem-po_item,
i_shipping TYPE bapiitemship OCCURS 0 WITH HEADER LINE,
i_shippingx TYPE bapiitemshipx OCCURS 0 WITH HEADER LINE,
lv_new_menge LIKE ekpo-menge,
lv_old_menge LIKE ekpo-menge,
lv_date(8).

DATA i_extensionin TYPE TABLE OF bapiparex WITH HEADER LINE.


DATA : i_extensioninx TYPE TABLE OF bapiparex WITH HEADER LINE,
ls_bapi_te_mepoheader TYPE zbapi_te_mepoheader,
ls_bapi_te_mepoheaderx TYPE bapi_te_mepoheaderx.

DATA : lv_coitm TYPE i,


lv_docdate TYPE budat,
lv_deldate TYPE budat.

DATA : lv_numc6(6) TYPE n ..

SORT gt_header_stock.

LOOP AT gt_header_stock.

CLEAR: wa_poheader, wa_poheaderx, lv_exppurchaseorder.

REFRESH: i_poitems, i_poitemsx, i_poschedule, i_poschedulex, i_pocondheader, i_pocondheaderx,


i_poaccount, i_poaccountx, i_pocond, i_pocondx, i_return, i_extensionin, i_extensioninx,
i_shippingx, i_shipping.

CONCATENATE gt_item_stock-docdate+4(4) gt_item_stock-docdate+2(2) gt_item_stock-docdate+0(2) INTO


lv_docdate.
assign_value: wa_poheader-doc_type gt_header_stock-doctyp
wa_poheaderx-doc_type,
wa_poheader-comp_code gt_header_stock-bukrs
wa_poheaderx-comp_code,
wa_poheader-purch_org gt_header_stock-porg
wa_poheaderx-purch_org,
wa_poheader-pur_group gt_header_stock-pgrp
wa_poheaderx-pur_group,
wa_poheader-doc_date lv_docdate
wa_poheaderx-doc_date,
wa_poheader-vendor gt_header_stock-lifnr
wa_poheaderx-vendor,
wa_poheader-sales_pers gt_header_stock-ref
wa_poheaderx-sales_pers,
wa_poheader-currency gt_header_stock-curr
wa_poheaderx-currency.

LOOP AT gt_item_stock WHERE ref = gt_header_stock-ref


AND doctyp = gt_header_stock-doctyp
AND bukrs = gt_header_stock-bukrs
AND porg = gt_header_stock-porg
AND pgrp = gt_header_stock-pgrp
AND plant = gt_header_stock-plant
AND docdate = gt_header_stock-docdate
AND ref = gt_header_stock-ref
AND lifnr = gt_header_stock-lifnr.

CLEAR: i_poitems, i_poitemsx, i_poschedulex, i_poschedule, i_pocond, i_pocondx, i_pocondheader,


i_pocondheaderx.
i_poitems-po_item = gt_item_stock-po_itm.
i_poitemsx-po_item = gt_item_stock-po_itm.
https://www.dropbox.com/s/0ikqnaeoc69u74q/ZMMR34.txt?dl=0 23/25
10/5/2018 ZMMR34.txt
i_poitemsx-po_itemx = 'X'.
i_poitems-trackingno = gt_item_stock-ref.
i_poitemsx-trackingno = 'X'.

CALL FUNCTION 'CONVERSION_EXIT_CUNIT_INPUT'


EXPORTING
input = gt_item_stock-meins
IMPORTING
output = gt_item_stock-meins
EXCEPTIONS
unit_not_found = 1
OTHERS = 2.

assign_value: i_poitems-material gt_item_stock-matnr i_poitemsx-material,


i_poitems-plant gt_item_stock-plant i_poitemsx-plant,
i_poitems-quantity gt_item_stock-qty i_poitemsx-quantity,
i_poitems-net_price gt_item_stock-price i_poitemsx-net_price,
i_poitems-po_unit gt_item_stock-meins i_poitemsx-po_unit,
i_poitems-ir_ind 'X' i_poitemsx-ir_ind,
i_poitems-gr_ind 'X' i_poitemsx-gr_ind,
i_poitems-tax_code gt_item_stock-tax i_poitemsx-tax_code,
i_poitems-val_type gt_item_stock-bwtar i_poitemsx-val_type.

IF gt_item_stock-desc NE space.
assign_value: i_poitems-short_text gt_item_stock-desc
i_poitemsx-short_text.
ENDIF.

APPEND: i_poitems, i_poitemsx.

CLEAR: i_poschedule, i_poschedulex.


i_poschedule-po_item = gt_item_stock-po_itm.
i_poschedule-sched_line = 1.
i_poschedulex-po_item = gt_item_stock-po_itm.
i_poschedulex-sched_line = 1.
i_poschedulex-po_itemx = 'X'.
i_poschedulex-sched_linex = 'X'.

CONCATENATE gt_item_stock-deldate+4(4) gt_item_stock-deldate+2(2) gt_item_stock-deldate+0(2) INTO


lv_deldate.
CONCATENATE gt_item_stock-docdate+4(4) gt_item_stock-docdate+2(2) gt_item_stock-docdate+0(2) INTO
lv_docdate.

assign_value: i_poschedule-delivery_date lv_deldate


i_poschedulex-delivery_date,
i_poschedule-stat_date lv_deldate
i_poschedulex-stat_date,
i_poschedule-quantity gt_item_stock-qty
i_poschedulex-quantity,
i_poschedule-po_date lv_docdate
i_poschedulex-po_date.
APPEND: i_poschedule, i_poschedulex.

ENDLOOP.

break aby_abap1.
CALL FUNCTION 'BAPI_PO_CREATE1'
EXPORTING
poheader = wa_poheader
poheaderx = wa_poheaderx
testrun = cb_test
no_price_from_po = 'X'
IMPORTING
exppurchaseorder = lv_exppurchaseorder
TABLES
return = i_return
poitem = i_poitems
poitemx = i_poitemsx
https://www.dropbox.com/s/0ikqnaeoc69u74q/ZMMR34.txt?dl=0 24/25
10/5/2018 ZMMR34.txt
poschedule = i_poschedule
poschedulex = i_poschedulex.

IF lv_exppurchaseorder EQ ''.
READ TABLE i_return WITH KEY type = 'E'.
IF sy-subrc EQ 0.
LOOP AT i_return WHERE type = 'E'.
MOVE-CORRESPONDING gt_header_stock TO gt_result_stock.
CONCATENATE i_return-type i_return-message INTO gt_result_stock-messg SEPARATED BY space.
COLLECT gt_result_stock.
ENDLOOP.

ELSE.
MOVE-CORRESPONDING gt_header_stock TO gt_result_stock.
gt_result_stock-messg = 'Error Not Found'.
COLLECT gt_result_stock.
ENDIF.

ELSE.
MOVE-CORRESPONDING gt_header_stock TO gt_result_stock.
gt_result_stock-ebeln = lv_exppurchaseorder.
gt_result_stock-messg = 'Create PO Success'.
COLLECT gt_result_stock.
ENDIF.

IF cb_test EQ ''.

CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.

UPDATE ekko SET borrow = 'X'


WHERE ebeln = lv_exppurchaseorder.

ENDIF.

ENDLOOP.

ENDFORM.

https://www.dropbox.com/s/0ikqnaeoc69u74q/ZMMR34.txt?dl=0 25/25