Skip to Content
0
Former Member
Apr 07, 2014 at 07:58 PM

Idoc successfully posted but Segment Field value not updated in WE02

1722 Views

Hello Experts,

Im a beginner in SAP ABAP.

I have a requirement to update KDMAT field of segment E1EDL24 on the basis of PO number and PO line item number in the segment which I have to take as input in EKPO table and extract MATNR from EKPO and place in KDMAT field.

I have written the source code and the data is successfully updated in debugging mode and the Idoc is successfully posted as well, but the data is not populated in segment.

I have written the code as-

function zpp_edi_desadv_12.

*"----------------------------------------------------------------------

*"*"Local Interface:

*" TABLES

*" IDOC_DATA STRUCTURE EDIDD

*" CHANGING

*" REFERENCE(IDOC_CONTROL) LIKE EDIDC STRUCTURE EDIDC

*" EXCEPTIONS

*" IDOC_ERROR

*" DO_NOT_PROCESS_IDOC

*"----------------------------------------------------------------------

* Local Type Declaration.

types : begin of lty_ekpo,

ebeln type ebeln, "Purchasing Document Number

ebelp type ebelp, "Item number of purchasing document

matnr type matnr, "Material Number

end of lty_ekpo,

begin of lty_mean,

matnr type matnr, "Material Number

ean11 type ean11, "International Article Number (EAN/UPC)

end of lty_mean.

* Local Range Declaration

data : lr_ean11 type range of ean11. "Range table for International Article Number (EAN/UPC)

* Local table declaration.

data : li_ekpo type standard table of lty_ekpo

initial size 0, "PO item Data

li_mean type standard table of lty_mean

initial size 0. "EAN for material data

* Local work area declaration.

data: lw_e1edl24 type e1edl24, "Segment E1EDL24

lw_e1edl37 type e1edl37, "Segment E1EDL37

lw_e1edl41 type e1edl41, "Segment E1EDL41

lw_ean11 like line of lr_ean11. "Work Area for EAN No.

* Local variable declaration

data : l_matnr type matnr, "Material no

l_ebeln type ebeln. "Local variable for PO number.

* Local Field-symbols declaration.

field-symbols : <lfs_edidd> type edidd, "Idoc Structure

<lfs_ekpo> type lty_ekpo, "PO item data

<lfs_mean> type lty_mean. "EAN for material data

* Local Constants declaration.

constants : lc_e1edl24 type e1edl24 value 'E1EDL24', "Segment E1EDL24

lc_e1edl37 type e1edl37 value 'E1EDL37', "Segment E1EDL37

lc_e1edl41 type e1edl41 value 'E1EDL41', "Segment E1EDL41

lc_qualf_on type char3 value '001', "Qualifier

lc_sign type char1 value 'I', "Sign I

lc_option type char2 value 'EQ'. "Option E

* Loop the internal table which contains data records of the IDOC.

loop at idoc_data assigning <lfs_edidd>.

case <lfs_edidd>-segnam.

when lc_e1edl41.

lw_e1edl41 = <lfs_edidd>-sdata.

if lw_e1edl41-quali eq lc_qualf_on.

l_ebeln = lw_e1edl41-bstnr.

endif.

when lc_e1edl37.

lw_e1edl37 = <lfs_edidd>-sdata.

lw_ean11-sign = lc_sign.

lw_ean11-option = lc_option.

shift lw_e1edl37-vhilm_ku left deleting leading '0'.

lw_ean11-low = lw_e1edl37-vhilm_ku.

append lw_ean11 to lr_ean11.

when others.

endcase. "CASE <lfs_edidd>-segnam.

endloop. "LOOP AT idoc_data ASSIGNING <lfs_edidd>.

* Get material no from EKPO table on the basis of PO number and PO line item number value in the segment E1EDL24

select ebeln "Purchasing Document Number

ebelp "Item number of purchasing document

matnr "Material Number

from ekpo

into table li_ekpo

where ebeln eq l_ebeln.

if sy-subrc is initial.

endif. "IF sy-subrc IS INITIAL of EKPO Select.

* Get material number from MEAN table on the basis of VHILM_KU field of E1EDL37 segment which contains EAN11 value as input.

select matnr "Material Number

ean11 "International Article Number (EAN/UPC)

from mean

into table li_mean

where ean11 in lr_ean11.

if sy-subrc is initial.

sort li_mean by ean11.

endif. "IF sy-subrc IS INITIAL of MEAN Select.

* Looping Idoc Data Records

loop at idoc_data assigning <lfs_edidd>.

case <lfs_edidd>-segnam.

when lc_e1edl24.

lw_e1edl24 = <lfs_edidd>-sdata.

* Read material number from EKPO on the basis of PO number and PO line item number.

* Table alrady sorted

read table li_ekpo assigning <lfs_ekpo>

with key ebeln = l_ebeln

ebelp = lw_e1edl24-posnr

binary search.

if sy-subrc is initial and <lfs_ekpo> is assigned.

l_matnr = lw_e1edl24-kdmat.

* To convert the format of material no.

call function 'CONVERSION_EXIT_MATN1_INPUT'

exporting

input = l_matnr

importing

output = l_matnr

exceptions

length_error = 1

others = 2.

if sy-subrc <> 0.

"Do nothing.

endif.

* Check whether material no in EKPO table is same as that of KDMAT value in segment

if l_matnr ne <lfs_ekpo>-matnr.

l_matnr = <lfs_ekpo>-matnr.

call function 'CONVERSION_EXIT_MATN1_OUTPUT'

exporting

input = l_matnr

importing

output = l_matnr.

lw_e1edl24-kdmat = l_matnr. "Replace KDMAT segment value with MATNR value in EKPO table

<lfs_edidd>-sdata = lw_e1edl24.

endif. "IF l_matnr NE <lfs_ekpo>-matnr.

endif. "IF sy-subrc IS INITIAL of read table li_ekpo.

when lc_e1edl37.

lw_e1edl37 = <lfs_edidd>-sdata.

* Read material number from MEAN on the basis of EAN no given in VHILM_KU field of segment.

read table li_mean assigning <lfs_mean>

with key ean11 = lw_e1edl37-vhilm_ku

binary search.

if sy-subrc is initial.

l_matnr = <lfs_mean>-matnr.

call function 'CONVERSION_EXIT_MATN1_OUTPUT'

exporting

input = l_matnr

importing

output = l_matnr.

lw_e1edl37-vhilm_ku = l_matnr. "Replace the existing value of VHILM_KU with new found out MATNR

<lfs_edidd>-sdata = lw_e1edl37.

endif. "IF sy-subrc IS INITIAL of Read table li_mean.

when others.

* Do nothing

endcase. " CASE <lfs_edidd>-segnam.

endloop. "LOOP AT idoc_data ASSIGNING <lfs_edidd>.

endfunction.




Please reply ASAP.

Thanks in Advance.