Hi Mounika
Thanks much for your time.,
Yes., Your understanding is right.. I use import and export memory ID .,
But Sy-subrc is "4"., at Import Export statement.and the control jumps from loop statement ( loop at <lft_submit> assigning <lfs_submit>.) to Sort . lt_submit itab is not getting filled with values..
*&---------------------------------------------------------------------*
*& Include ZMM_SUPPLIER_MAT_REP_FORM
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*& Form GET_BUILD_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* <--P_GT_FINAL text
*----------------------------------------------------------------------*
form get_build_data changing lt_final type tt_ty_final.
types: begin of ty_ekbe,
ebeln type ekbe-ebeln,
ebelp type ekbe-ebelp,
zekkn type ekbe-zekkn,
vgabe type ekbe-vgabe,
gjahr type ekbe-gjahr,
belnr type ekbe-belnr,
buzei type ekbe-buzei,
bewtp type ekbe-bewtp,
bwart type ekbe-bwart,
budat type ekbe-budat,
menge type ekbe-menge,
bpmng type ekbe-bpmng,
wrbtr type ekbe-wrbtr,
end of ty_ekbe,
tt_ty_ekbe type standard table of ty_ekbe,
begin of ty_eket,
ebeln type eket-ebeln,
ebelp type eket-ebelp,
etenr type eket-etenr,
eindt type eket-eindt,
end of ty_eket,
tt_ty_eket type standard table of ty_eket,
begin of ty_ekpo,
ebeln type ekpo-ebeln,
ebelp type ekpo-ebelp,
loekz type ekpo-loekz,
end of ty_ekpo,
tt_ty_ekpo type standard table of ty_ekpo.
* data : lifnr TYPE lfa1-lifnr.
data: fs_data type ref to data,
fs_test type table of merep_outtab_purchdoc,
lt_submit type table of merep_outtab_purchdoc,
lwa_submit type merep_outtab_purchdoc,
lt_ekbe type tt_ty_ekbe,
lwa_ekbe type ty_ekbe,
lt_eket type tt_ty_eket,
lwa_eket type ty_eket,
lt_ekpo type tt_ty_ekpo,
lwa_ekpo type ty_ekpo,
lwa_final type ty_final.
field-symbols: <lft_submit> type any table,
<lfs_submit> type merep_outtab_purchdoc.
constants : lc_alv type char3 value 'ALV',
lc_e type char1 value 'E',
lc_102 type char3 value '102',
lc_122 type char3 value '122',
lc_m1 type char2 value '-1'.
* fetch from Tcode ME2M
* submit rm06em00 with em_matnr in s_matnr " MATERIALS
* with em_werks in s_werks " Plant
* with listu eq lc_alv "'ALV' " Scope of List
* with s_pstyp in s_pstyp " Item category is populated in pgm as '' & 'L'
* with s_lifnr in s_lifnr " Vendor
* with s_bedat in s_aedat " PO date
* exporting list to memory and return.
DATA : SELTAB LIKE RSPARAMS OCCURS 0 WITH HEADER LINE.
SUBMIT rm06em00 USING SELECTION-SCREEN '1000'
WITH SELECTION-TABLE SELTAB AND RETURN.
SELTAB-SELNAME = 'EM_MATNR'.
SELTAB-KIND = 'S'.
SELTAB-SIGN = 'I'.
SELTAB-OPTION = 'BT'.
SELTAB-LOW = S_matnr-low.
SELTAB-HIGH = S_matnr-high.
APPEND SELTAB.
CLEAR SELTAB.
SELTAB-SELNAME = 'EM_WERKS'.
SELTAB-KIND = 'S'.
SELTAB-SIGN = 'I'.
SELTAB-OPTION = 'BT'.
SELTAB-LOW = S_werks-low.
SELTAB-HIGH = S_werks-high.
APPEND SELTAB.
CLEAR SELTAB.
*SELTAB-SELNAME = 'LC_ALV'.
*SELTAB-KIND = 'S'.
*SELTAB-SIGN = 'I'.
*SELTAB-OPTION = 'EQ'.
*SELTAB-LOW = s_lc_alv.
*SELTAB-HIGH =.
*APPEND SELTAB.
*CLEAR SELTAB.
SELTAB-SELNAME = 'S_PSTYP'.
SELTAB-KIND = 'S'.
SELTAB-SIGN = 'I'.
SELTAB-OPTION = 'BT'.
SELTAB-LOW = S_PSTYP-low.
SELTAB-HIGH = S_PSTYP-high.
APPEND SELTAB.
CLEAR SELTAB.
SELTAB-SELNAME = 'S_LIFNR'.
SELTAB-KIND = 'S'.
SELTAB-SIGN = 'I'.
SELTAB-OPTION = 'BT'.
SELTAB-LOW = S_LIFNR-low.
SELTAB-HIGH = S_LIFNR-high.
APPEND SELTAB.
CLEAR SELTAB.
SELTAB-SELNAME = 'S_AEDAT'.
SELTAB-KIND = 'S'.
SELTAB-SIGN = 'I'.
SELTAB-OPTION = 'BT'.
SELTAB-LOW = S_AEDAT-low.
SELTAB-HIGH = S_AEDAT-high.
APPEND SELTAB.
CLEAR SELTAB.
create data fs_data like fs_test.
assign fs_data->* to <lft_submit>.
IMPORT export = <lft_submit>[] from memory id 'ZME2M_MEMID'." OLD
free memory id 'ZME2M_MEMID'.
* Convert ME2M Field symbl data to simple IT
loop at <lft_submit> assigning <lfs_submit>.
lwa_submit = <lfs_submit>.
append lwa_submit to lt_submit.
endloop.
if lt_submit is not initial.
* SQL from EKBE - PO History table
select ebeln
ebelp
zekkn
vgabe
gjahr
belnr
buzei
bewtp
bwart
budat
menge
bpmng
wrbtr from ekbe into table lt_ekbe
for all entries in lt_submit
where ebeln = lt_submit-ebeln and
ebelp = lt_submit-ebelp and
bewtp = lc_e AND "'E'
budat IN s_budat.
* SQL from EKET- PO Scheduling Agreement Schedule Lines
select ebeln
ebelp
etenr
eindt from eket into table lt_eket
for all entries in lt_submit
where ebeln = lt_submit-ebeln and
ebelp = lt_submit-ebelp.
* SQL for PO line items deletion / locked
select ebeln
ebelp
loekz from ekpo into table lt_ekpo
for all entries in lt_submit
where ebeln = lt_submit-ebeln and
ebelp = lt_submit-ebelp.
endif.
sort lt_submit by ematn ebeln ebelp.
sort lt_ekbe by ebeln ebelp.
sort lt_eket by ebeln ebelp.
sort lt_ekpo by ebeln ebelp.
loop at lt_submit into lwa_submit.
lwa_final-superfield = lwa_submit-superfield. " Vendor # & name
lwa_final-ematn = lwa_submit-ematn.
lwa_final-txz01 = lwa_submit-txz01.
lwa_final-werks = lwa_submit-werks.
lwa_final-ebeln = lwa_submit-ebeln.
lwa_final-ebelp = lwa_submit-ebelp.
lwa_final-bedat = lwa_submit-bedat.
lwa_final-menge = lwa_submit-menge.
lwa_final-netpr = lwa_submit-netpr.
lwa_final-peinh = lwa_submit-peinh.
* For deletion / locked indicATOR
read table lt_ekpo into lwa_ekpo with key ebeln = lwa_submit-ebeln
ebelp = lwa_submit-ebelp
binary search.
if sy-subrc = 0.
lwa_final-loekz = lwa_ekpo-loekz.
clear: lwa_ekpo.
endif.
* PO doc Scheduled delivery dt
read table lt_eket into lwa_eket with key ebeln = lwa_submit-ebeln
ebelp = lwa_submit-ebelp
binary search.
if sy-subrc = 0.
lwa_final-eindt = lwa_eket-eindt.
clear: lwa_eket.
endif.
* For each ME2M`s O/p record, loop ing the history table EKBE for ALL GRs
loop at lt_ekbe into lwa_ekbe where ebeln = lwa_submit-ebeln and
ebelp = lwa_submit-ebelp.
lwa_final-bwart = lwa_ekbe-bwart.
lwa_final-budat = lwa_ekbe-budat.
if lwa_final-bwart = lc_102 or lwa_final-bwart = lc_122. " make Qty as -ve
lwa_final-menge_h = lwa_ekbe-menge * lc_m1.
else.
lwa_final-menge_h = lwa_ekbe-menge.
endif.
* Only if EKBE`s qty(history) is there, then calculating days b/w Doc Del dt(eindt) to GR`s posting date & Append looped lines
if lwa_final-menge_h is not initial.
call function 'FIMA_DAYS_AND_MONTHS_AND_YEARS'
exporting
i_date_from = lwa_final-eindt
* I_KEY_DAY_FROM =
i_date_to = lwa_final-budat
* I_KEY_DAY_TO =
i_flg_separate = ' '
importing
e_days = lwa_final-days
* E_MONTHS =
* E_YEARS =
.
endif.
append lwa_final to lt_final.
endloop.
* If no GR history, then only
* If no EKBE`s qty(history), then calculating days b/w Doc Del dt(eindt) to Current System date & append unlooped remaining lines
if lwa_ekbe is initial.
call function 'FIMA_DAYS_AND_MONTHS_AND_YEARS'
exporting
i_date_from = lwa_final-eindt
* I_KEY_DAY_FROM =
i_date_to = sy-datum "lwa_final-budat
* I_KEY_DAY_TO =
i_flg_separate = ' '
importing
e_days = lwa_final-days
* E_MONTHS =
* E_YEARS =
.
append lwa_final to lt_final.
endif.
clear: lwa_ekbe, lwa_final.
endloop.
DELETE lt_final WHERE budat not IN s_budat.
sort lt_final by superfield ematn ebeln ebelp.
endform. " GET_BUILD_DATA
*&---------------------------------------------------------------------*
*& Form DISPLAY
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_GT_FINAL text
*----------------------------------------------------------------------*
form display using lt_final type tt_ty_final.
constants: lc_1 type i value '1',
lc_true type sap_bool value 'X'.
try.
call method cl_salv_table=>factory
importing
r_salv_table = gr_alv
changing
t_table = lt_final.
catch cx_salv_msg into gv_oref.
gv_text = gv_oref->get_text( ).
endtry.
*Sorting for Material
call method gr_alv->get_sorts
receiving
value = gr_sorts.
call method gr_sorts->add_sort
exporting
columnname = 'SUPERFIELD'
position = 1 "lc_1 "1
sequence = if_salv_c_sort=>sort_up
subtotal = if_salv_c_bool_sap=>true
group = if_salv_c_sort=>group_none
obligatory = if_salv_c_bool_sap=>true
receiving
value = gr_sort.
* ref is created for get_display setting method for display of alv output.
call method gr_alv->get_display_settings
receiving
value = gr_display.
* enable all the functions
call method gr_alv->get_functions
receiving
value = gr_function.
call method gr_function->set_all
exporting
value = if_salv_c_bool_sap=>true.
*to get all column references.
gr_columns = gr_alv->get_columns( ).
*optimize width of columns
gr_columns->set_optimize( lc_true ).
perform get_col using:
text-000 text-001 text-001 text-001, " EMATN" material #
text-002 text-003 text-003 text-003, " TXZ01" material desc
text-004 text-005 text-005 text-005, " WERKS" plant
text-006 text-007 text-007 text-008, " EBELN" PO
text-008 text-009 text-009 text-009, " EBELP" PO Item
text-010 text-011 text-011 text-011, " BEDAT" PO dt
text-012 text-013 text-013 text-013, " MENGE" Qty ordered
text-014 text-015 text-015 text-015, " EINDT" Doc Delivery Dt
text-016 text-017 text-017 text-017, " NETPR" Net price
text-018 text-019 text-019 text-019, " PEINH" per
text-020 text-021 text-021 text-021, " BWART" Mvnmt type
text-022 text-023 text-023 text-023, " BUDAT" Actual Del Dt
text-024 text-025 text-025 text-025, " MENGE_H" Del Qty
text-026 text-027 text-027 text-027, " DAYS" Days late/Early
text-028 text-029 text-029 text-029, " SUPERFIELD " Vendor # & Name
text-030 text-031 text-031 text-031. " LOEKZ " Del / Lock
call method gr_alv->display( ) .
endform. " DISPLAY
*&---------------------------------------------------------------------*
*& Form GET_COL
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_TEXT_000 text
* -->P_TEXT_001 text
* -->P_TEXT_001 text
* -->P_TEXT_001 text
*----------------------------------------------------------------------*
form get_col using text1 type any " P_TEXT_001
text2 type any " P_TEXT_002
text3 type any " P_TEXT_002
text4 type any." P_TEXT_002.
data: l_v_oref type ref to cx_root,
l_v_text1 type string.
try.
call method gr_columns->get_column
exporting
columnname = text1
receiving
value = gr_column.
catch cx_salv_not_found into l_v_oref.
l_v_text1 = l_v_oref->get_text( ).
endtry.
try.
call method gr_column->set_short_text
exporting
value = text2+0(05).
call method gr_column->set_medium_text
exporting
value = text3+0(10).
call method gr_column->set_long_text
exporting
value = text4.
call method gr_column->set_alignment
exporting
value = if_salv_c_alignment=>centered.
*to maintain +ve / -ve sign even when downloaded to Spreadsheet
gr_column->set_sign( abap_true ).
catch cx_salv_not_found.
endtry.
endform. " GET_COL
Please do the needful..
Regards
Ssk bhat