Ysrilop c00016 f01 Fed

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 10

*&---------------------------------------------------------------------*

*& Include ZSRILIN_C00016_F01_FED


*&---------------------------------------------------------------------*

*&---------------------------------------------------------------------*
*& Form upl_xml
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM upload_xml .

DATA : lcl_xml TYPE REF TO cl_xml_document,


lv_filename TYPE string,
lt_xml TYPE swxmlcont,
lv_xml_string TYPE string,
lv_size TYPE i.

DATA : xml_xstring TYPE xstring,


lt_xml_data TYPE TABLE OF smum_xmltb INITIAL SIZE 0,
lt_xml_item TYPE TABLE OF smum_xmltb INITIAL SIZE 0,
lt_return TYPE STANDARD TABLE OF bapiret2.

DATA : lw_xml_data TYPE smum_xmltb,


lw_xml_item TYPE smum_xmltb,
lw_return LIKE LINE OF lt_return.

DATA : count(3) TYPE c,


count2(3) TYPE c.

DATA: gv_tabix TYPE sytabix.


DATA: tabix TYPE sytabix.
DATA: tabixx TYPE sytabix.

CREATE OBJECT lcl_xml.

"Passing File Path


lv_filename = p_fname.

"Upload File XML to SAP


CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = lv_filename
filetype = 'BIN'
has_field_separator = ' '
header_length = 0
IMPORTING
filelength = lv_size
TABLES
data_tab = lt_xml
EXCEPTIONS
OTHERS = 1.
IF sy-subrc EQ 0.
"Convert BIN to String
CALL FUNCTION 'SCMS_BINARY_TO_STRING'
EXPORTING
input_length = lv_size
IMPORTING
text_buffer = lv_xml_string
TABLES
binary_tab = lt_xml
EXCEPTIONS
failed = 1
OTHERS = 2.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ELSE.
"Convert String to Xstring
CALL FUNCTION 'SCMS_STRING_TO_XSTRING'
EXPORTING
text = lv_xml_string
IMPORTING
buffer = xml_xstring
EXCEPTIONS
failed = 1
OTHERS = 2.
IF sy-subrc EQ 0.
"Convert Xstring to Itab
CALL FUNCTION 'SMUM_XML_PARSE'
EXPORTING
xml_input = xml_xstring
TABLES
xml_table = lt_xml_data
return = lt_return
EXCEPTIONS
OTHERS = 0.
READ TABLE lt_return INTO lw_return WITH KEY type = 'E'.
IF sy-subrc EQ 0.
MESSAGE 'Error converting the input XML file' TYPE 'E'.
ELSE.
REFRESH lt_return.

"Clone Tab Header for Item


lt_xml_item[] = lt_xml_data[].

"Processing Header Data


LOOP AT lt_xml_data INTO lw_xml_data.
IF lw_xml_data-cname = 'row'. "row Means Header
count = count + 1. "Count Number PO

tabixx = sy-tabix + 1.
READ TABLE lt_xml_data INTO lw_xml_data INDEX tabixx.
gw_h_tab-supid = lw_xml_data-cvalue.

tabixx = sy-tabix + 1.
READ TABLE lt_xml_data INTO lw_xml_data INDEX tabixx.
gw_h_tab-dndate = lw_xml_data-cvalue.

tabixx = sy-tabix + 1.
READ TABLE lt_xml_data INTO lw_xml_data INDEX tabixx.
gw_h_tab-supplt = lw_xml_data-cvalue.

tabixx = sy-tabix + 1.
READ TABLE lt_xml_data INTO lw_xml_data INDEX tabixx.
gw_h_tab-dnno = lw_xml_data-cvalue.
tabixx = sy-tabix + 1.
READ TABLE lt_xml_data INTO lw_xml_data INDEX tabixx.
gw_h_tab-plant = lw_xml_data-cvalue.

tabixx = sy-tabix + 1.
READ TABLE lt_xml_data INTO lw_xml_data INDEX tabixx.
gw_h_tab-plantdesc = lw_xml_data-cvalue.

tabixx = sy-tabix + 1.
READ TABLE lt_xml_data INTO lw_xml_data INDEX tabixx.
gw_h_tab-po = lw_xml_data-cvalue.

tabixx = sy-tabix + 1.
READ TABLE lt_xml_data INTO lw_xml_data INDEX tabixx.
gw_h_tab-gate = lw_xml_data-cvalue.

tabixx = sy-tabix + 1.
READ TABLE lt_xml_data INTO lw_xml_data INDEX tabixx.
gw_h_tab-vin = lw_xml_data-cvalue.

tabixx = sy-tabix + 1.
READ TABLE lt_xml_data INTO lw_xml_data INDEX tabixx.
gw_h_tab-etd = lw_xml_data-cvalue.

tabixx = sy-tabix + 1.
READ TABLE lt_xml_data INTO lw_xml_data INDEX tabixx.
gw_h_tab-rcvawal = lw_xml_data-cvalue.

tabixx = sy-tabix + 1.
READ TABLE lt_xml_data INTO lw_xml_data INDEX tabixx.
gw_h_tab-rcvakhir = lw_xml_data-cvalue.

gw_h_tab-count = count.

APPEND gw_h_tab TO gt_h_tab.


ELSE.
CONTINUE.
ENDIF.
ENDLOOP.

"Processing Item Data


LOOP AT lt_xml_item INTO lw_xml_item.
IF lw_xml_item-cname = 'row'.
count2 = count2 + 1. "Count Number Item PO Based on PO
ENDIF.

IF lw_xml_item-cname = 'dtl'. "dtl Means Item


tabix = sy-tabix + 1.
READ TABLE lt_xml_item INTO lw_xml_item INDEX tabix.
gw_i_tab-po_item = lw_xml_item-cvalue.

tabix = sy-tabix + 1.
READ TABLE lt_xml_item INTO lw_xml_item INDEX tabix.
gw_i_tab-sup_num = lw_xml_item-cvalue.

tabix = sy-tabix + 1.
READ TABLE lt_xml_item INTO lw_xml_item INDEX tabix.
gw_i_tab-desc = lw_xml_item-cvalue.
tabix = sy-tabix + 1.
READ TABLE lt_xml_item INTO lw_xml_item INDEX tabix.
gw_i_tab-subc = lw_xml_item-cvalue.

tabix = sy-tabix + 1.
READ TABLE lt_xml_item INTO lw_xml_item INDEX tabix.
gw_i_tab-batchno = lw_xml_item-cvalue.

tabix = sy-tabix + 1.
READ TABLE lt_xml_item INTO lw_xml_item INDEX tabix.
gw_i_tab-qty = lw_xml_item-cvalue.

tabix = sy-tabix + 1.
READ TABLE lt_xml_item INTO lw_xml_item INDEX tabix.
gw_i_tab-packid = lw_xml_item-cvalue.

tabix = sy-tabix + 1.
READ TABLE lt_xml_item INTO lw_xml_item INDEX tabix.
gw_i_tab-packdesc = lw_xml_item-cvalue.

tabix = sy-tabix + 1.
READ TABLE lt_xml_item INTO lw_xml_item INDEX tabix.
gw_i_tab-packqty = lw_xml_item-cvalue.

tabix = sy-tabix + 1.
READ TABLE lt_xml_item INTO lw_xml_item INDEX tabix.
gw_i_tab-vpartnum = lw_xml_item-cvalue.

tabix = sy-tabix + 1.
READ TABLE lt_xml_item INTO lw_xml_item INDEX tabix.
gw_i_tab-critic = lw_xml_item-cvalue.

tabix = sy-tabix + 1.
READ TABLE lt_xml_item INTO lw_xml_item INDEX tabix.
gw_i_tab-p3cqty = lw_xml_item-cvalue.

gw_i_tab-count = count.

"Matching Number PO Based on Count Number


READ TABLE gt_h_tab INTO gw_h_tab WITH KEY count = gw_i_tab-count.
IF sy-subrc EQ 0.
gw_i_tab-po = gw_h_tab-po.
ENDIF.

APPEND gw_i_tab TO gt_i_tab.


ENDIF.
ENDLOOP.
ENDIF.
ENDIF.
ENDIF.
ENDIF.
ENDFORM.

*&---------------------------------------------------------------------*
*& Form upload_xls_fed
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM upload_xls_fed .

DATA : g_raw_data TYPE truxs_t_text_data.

DATA : e_msg(100) TYPE c,


lv_filename TYPE string,
lv_tabix TYPE sy-tabix.

lv_filename = p_fname.

CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'


EXPORTING
* I_FIELD_SEPERATOR =
i_line_header = 'X'
i_tab_raw_data = g_raw_data
i_filename = p_fname
* I_STEP = 1
TABLES
i_tab_converted_data = gt_upload.
IF sy-subrc <> 0.
CALL FUNCTION 'FORMAT_MESSAGE'
EXPORTING
id = sy-msgid
lang = '-D'
no = sy-msgno
v1 = sy-msgv1
v2 = sy-msgv2
v3 = sy-msgv3
v4 = sy-msgv4
IMPORTING
msg = e_msg
EXCEPTIONS
not_found = 1
OTHERS = 2.
IF sy-subrc EQ 0.
MESSAGE e_msg TYPE 'S' DISPLAY LIKE 'E'.
ENDIF.
ELSE.
READ TABLE gt_upload INTO DATA(lw_upload) INDEX 1.
IF sy-subrc EQ 0.
IF lw_upload-col1+10(2) NE '20'.
MESSAGE 'Please Upload ZDHG File' TYPE 'S' DISPLAY LIKE 'E'.
LEAVE LIST-PROCESSING.
ENDIF.
ENDIF.
ENDIF.
ENDFORM.

*&---------------------------------------------------------------------*
*& Form set_data_xml
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM set_data_xml.

DATA : lv_temp_open_qty TYPE kwmeng.

REFRESH : gt_rslt.

LOOP AT gt_h_tab INTO gw_h_tab.

CLEAR : gw_rslt.

gw_rslt-auart = 'ZDOE'.
gw_rslt-po = gw_h_tab-po.

"get Sales area


PERFORM get_sales_area USING gw_rslt-auart
CHANGING gw_rslt-vkorg gw_rslt-vtweg gw_rslt-spart.

"Change Date external to internal


PERFORM chg_date_to_internal USING gw_h_tab-dndate
CHANGING gw_rslt-dndate.

gw_rslt-dnno = gw_h_tab-dnno.

gw_rslt-plant = gw_h_tab-plant.
gw_rslt-plantdesc = gw_h_tab-plantdesc.
gw_rslt-vin = gw_h_tab-vin.

"get internal number SoldTo SAP


IF gw_h_tab-supid IS NOT INITIAL.
SELECT SINGLE kunnr
FROM knvv
INTO @DATA(lv_kunnr)
WHERE eikto EQ @gw_h_tab-supid
AND vkorg EQ @gw_rslt-vkorg
AND vtweg EQ @gw_rslt-vtweg
AND spart EQ @gw_rslt-spart.
IF sy-subrc EQ 0.
gw_rslt-kunnr2 = lv_kunnr.
ENDIF.
ENDIF.

"get internal number ShipTO SAP


IF gw_h_tab-plant IS NOT INITIAL.
SELECT SINGLE partner
FROM but000
INTO @DATA(lv_partner)
WHERE name_org3 EQ @gw_h_tab-plant
AND name_org4 EQ @gw_h_tab-plantdesc.
IF sy-subrc EQ 0.
gw_rslt-kunnr1 = lv_partner. "ShipTo
ENDIF.
ENDIF.

LOOP AT gt_i_tab INTO gw_i_tab.

* gw_rslt-po_item = gw_i_tab-po_item.

gw_rslt-vpartnum = gw_i_tab-sup_num.
PERFORM get_int_matnr USING gw_i_tab-sup_num
gw_rslt CHANGING gw_rslt-sup_num.

gw_rslt-qty = gw_i_tab-qty.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = gw_i_tab-po_item
IMPORTING
output = gw_rslt-po_item.

PERFORM conversion_exit_input CHANGING gw_rslt-sup_num.

"Check if Ref Already used or duplicate

"Check if PO Already has Sales Contract


PERFORM check_po CHANGING gw_rslt lv_temp_open_qty.
* PERFORM check_po USING gw_rslt-po gw_rslt-sup_num gw_rslt-dndate gw_rslt-
kunnr2 gw_rslt-po_item
* CHANGING gw_rslt-vbeln_co gw_rslt-posnr_co gw_rslt-
kwmeng_co gw_rslt-vrkme_co gw_rslt-open_qty gw_rslt-po_item gw_rslt-msg
lv_temp_open_qty.
READ TABLE gt_i_tab INTO DATA(wa_item) INDEX sy-tabix - 1.
IF sy-subrc <> 0. "Index 1
gw_rslt-open_qty = gw_rslt-kwmeng_co. "Default fill by contract qty
ELSE.
IF wa_item-po EQ gw_i_tab-po AND wa_item-po_item EQ gw_i_tab-po_item.
ELSE.
CLEAR lv_temp_open_qty.
ENDIF.
ENDIF.
IF gw_rslt-vbeln_co IS NOT INITIAL.
"After this PO has Contract, Check if this PO Already has SO based on
contract
PERFORM check_so USING gw_rslt-po gw_rslt-sup_num gw_rslt-po_item gw_rslt-
qty
CHANGING gw_rslt-open_qty lv_temp_open_qty gw_rslt-msg
gw_rslt-flag_lq.

"Check if Ref Already used or duplicate


PERFORM check_ref_doc USING gw_rslt-dnno CHANGING gw_rslt-msg gw_rslt-
flag_dup.
ENDIF.

APPEND gw_rslt TO gt_rslt.

CLEAR : gw_rslt-msg.
ENDLOOP.
ENDLOOP.

SORT gt_rslt BY dnno po po_item.

gt_header[] = gt_rslt[].
gt_item[] = gt_rslt[].

DELETE ADJACENT DUPLICATES FROM gt_header[] COMPARING po.


ENDFORM.

*&---------------------------------------------------------------------*
*& Form set_data_xls
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM set_data_xls .

DATA : lv_temp_open_qty TYPE kwmeng.

REFRESH : gt_rslt.

LOOP AT gt_upload INTO DATA(lw_upload).

CLEAR : gw_rslt.

gw_rslt-auart = lw_upload-col1+0(4).
gw_rslt-po = lw_upload-col16.

"get Sales area


PERFORM get_sales_area USING gw_rslt-auart
CHANGING gw_rslt-vkorg gw_rslt-vtweg gw_rslt-spart.

"Change Date external to internal


PERFORM chg_date_to_internal USING lw_upload-col4+0(11)
CHANGING gw_rslt-dndate.

gw_rslt-dnno = lw_upload-col2.
gw_rslt-plant = lw_upload-col7.
gw_rslt-plantdesc = lw_upload-col8.
gw_rslt-po_item = lw_upload-col19.
gw_rslt-sup_num = lw_upload-col20.
gw_rslt-vpartnum = lw_upload-col20.

PERFORM get_int_matnr USING lw_upload-col20


gw_rslt CHANGING gw_rslt-sup_num.

gw_rslt-qty = lw_upload-col26.
gw_rslt-flag_cd = lw_upload-col25.
gw_rslt-qq_code = lw_upload-col28.

"get internal number SoldTo SAP


IF lw_upload-col9 IS NOT INITIAL.
SELECT SINGLE kunnr
FROM knvv
INTO @DATA(lv_kunnr)
WHERE eikto EQ @lw_upload-col9.
IF sy-subrc EQ 0.
* gw_tab_rslt-bpext = lw_but000-partner.
gw_rslt-kunnr2 = lv_kunnr.
ENDIF.
ENDIF.

"get internal number ShipTO SAP


IF lw_upload-col7 IS NOT INITIAL.
SELECT SINGLE partner
FROM but000
INTO @DATA(lv_partner)
WHERE name_org3 EQ @lw_upload-col7.
IF sy-subrc EQ 0.
gw_rslt-kunnr1 = lv_partner. "ShipTo
ENDIF.
ENDIF.

"get internal number QQ SAP


IF gw_rslt-flag_cd EQ 'N'.
IF gw_rslt-qq_code IS NOT INITIAL. "additional add
SELECT SINGLE partner
FROM but000
INTO @DATA(lv_partn)
WHERE name_org3 EQ @gw_rslt-qq_code.
IF sy-subrc EQ 0.
gw_rslt-kunnr4 = lv_partn. "QQ
ENDIF.
ENDIF.
ENDIF.

PERFORM conversion_exit_input CHANGING gw_rslt-sup_num.

"Check if PO Already has Sales Contract


PERFORM check_po CHANGING gw_rslt lv_temp_open_qty.
* CHANGING gw_rslt-vbeln_co gw_rslt-posnr_co gw_rslt-kwmeng_co
gw_rslt-vrkme_co gw_rslt-open_qty gw_rslt-po_item gw_rslt-msg lv_temp_open_qty.

READ TABLE gt_i_tab INTO DATA(wa_item) INDEX sy-tabix - 1.


IF sy-subrc <> 0. "Index 1
gw_rslt-open_qty = gw_rslt-kwmeng_co. "Default fill by contract qty
ELSE.
IF wa_item-po EQ gw_i_tab-po AND wa_item-po_item EQ gw_i_tab-po_item.
ELSE.
CLEAR lv_temp_open_qty.
ENDIF.
ENDIF.

IF gw_rslt-vbeln_co IS NOT INITIAL.


"After this PO has Contract, Check if this PO Already has SO based on
contract
PERFORM check_so USING gw_rslt-po gw_rslt-sup_num gw_rslt-po_item gw_rslt-qty
CHANGING gw_rslt-open_qty lv_temp_open_qty gw_rslt-msg
gw_rslt-flag_lq.

"Check if Ref Already used or duplicate


PERFORM check_ref_doc USING gw_rslt-dnno CHANGING gw_rslt-msg gw_rslt-
flag_dup.
ENDIF.

APPEND gw_rslt TO gt_rslt.


ENDLOOP.

SORT gt_rslt BY dnno po po_item.

gt_header[] = gt_rslt[].
gt_item[] = gt_rslt[].

DELETE ADJACENT DUPLICATES FROM gt_header[] COMPARING po.


ENDFORM.

*&---------------------------------------------------------------------*
*& Form get_int_matnr
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> GW_I_TAB
*& <-- GW_RSLT_SUP_NUM
*&---------------------------------------------------------------------*
FORM get_int_matnr USING matnr
gw_rslt TYPE gs_rslt
CHANGING sup_num.

DATA : lw_knmt TYPE knmt.

SELECT SINGLE *
FROM knmt
INTO @lw_knmt
WHERE kdmat EQ @matnr
AND vkorg EQ @gw_rslt-vkorg
AND vtweg EQ @gw_rslt-vtweg.
IF sy-subrc EQ 0.
sup_num = lw_knmt-matnr.
ENDIF.
ENDFORM.

You might also like