AT END OF matnr.
Hello-
In loop - endloop I have AT END OF matnr. But it is not working. For all material it is going inside AT ENDAT. It shoulg go inside only for unique matrial. But it is not working like that.
LOOP AT temp_hu_detl.
v_sum = v_sum + temp_hu_detl-qty.
AT END OF matnr.
temp_hu_detl_2 = temp_hu_detl.
temp_hu_detl_2-qty = v_sum.
append temp_hu_detl_2.
CLEAR : v_sum, temp_hu_detl_2.
ENDAT.
ENDLOOP.
Should I have material as first field in the table.
Thanks.
First sort the records based on the Matnr first. Also in the internal table temp_hu_detl, make the matnr as first field.
One more thing is when u r using the AT END all the fields after matnr will become *******....so first pass the header values to some work area before using the AT END statement.
LOOP AT temp_hu_detl.
temp_hu_detl_2 = temp_hu_detl.
v_sum = v_sum + temp_hu_detl-qty.
AT END OF matnr.
temp_hu_detl_2-qty = v_sum.
append temp_hu_detl_2.
CLEAR : v_sum, temp_hu_detl_2.
ENDAT.
ENDLOOP.
Similar Messages
-
How to use AT END OF logic in ALV reports?
Hi Experts!!
I have a requirement which is given below and the same should be the output of an alv report. I have all the data in one itab which has ields as matnr, sl.no, name and place. And I have the itab values as
MATNR SL.NO NAME PLACE
134 1 ABCD INDIA
134 2 XYZ US
134 3 QWERT GERMANY
256 4 FDGHS CNTRY1
256 5 GVHB CNTRY2
256 6 GHI CNTRY3
256 7 YGJN CNTRY4
256 8 ESEGVU CNTRY5
Now I need the alv output as the below:
Sl.No. Name Place
MATNR: 134
1 ABCD INDIA
2 XYZ US
3 QWERT GERMANY
MATNR: 256
5 FDGHS CNTRY1
6 GVHB CNTRY2
7 GHI CNTRY3
8 YGJN CNTRY4
9 ESEGVU CNTRY5
In normal classic report, I can achieve this by using AT END OF MATNR, and then printing. But how can i achieve the same in ALV report?
Kindly suggest me the normal ALV method, istead of OOPS concepts. I don't ant to consider OOPS, if this is possible by normal ALVs.
Thanks a lot in advance.
Regards,
SeenuHi,
Try this:
data: h_alv_sorttab type slis_t_sortinfo_alv.
h_alv_sorttab-fieldname = 'matnr'.
h_alv_sorttab-tabname = 'it_data'.
h_alv_sorttab-up = 'x'.
h_alv_sorttab-subtot = 'x'.
append h_alv_sorttab.
call function 'reuse_alv_grid_display'
exporting
i_background_id = 'alv_background'
i_callback_program = g_repid
is_layout = gs_layout
it_fieldcat = gt_fieldcat[]
it_sort = h_alv_sorttab
i_save = g_save
is_variant = g_variant
it_events = gt_events[]
i_default = 'x'
tables
t_outtab = it_data.
Hope this information is help to you.
Regards,
José -
Problem with AT NEW and AT END Statements
Hi all,
I am facing a problem in a report with i have to change ,
currently report is for single plant input but now multiple option is to be given , so now the material quantity and value should come along with material and plant.
But in report lot's of AT NEW matnr and AT END of matnr has been use but now i have to add plant in it , but these statements take only one parameter.
I tried using ON CHANGE Statement but in that SUM Can't be use.
So please help me in sorting out this problem.
Thanks and Regards,
VivekHi,
Already you are using material in AT NEW statements and you want to include Plant. by changing the structure you can continue with the same statement i.e., AT NEW matnr.
Structure:
Data: begin of itab occurs 0,
werks type werks,
matnr type matnr,
qyt type matqty,
end of itab.
SORT itab BY werks, matnr.
If you use AT NEW matnr. this will be triggered when plant value changes and also when matnr changes.
Hope it is clear. -
At new and at end of statement
how to use AT NEW and AT END OF
efficiently,kindly give some solid examples.
thanks!!Now say, u have internal table with mateirals....there are 100 records with 10 mterials...
loop at it_matnr.
at new matnr.
<b>write code</b>
endat.
<b>write code.</b>
at end of matnr.
<b>write code</b>
endat.
endloop.
Check this which is explained...
Control Level Processing
When you perform a sort using the SORTstatement, control levels are defined in the extract dataset. For general information about control levels, refer to Processing Internal Tables in Loops The control level hierarchy of an extract dataset corresponds to the sequence of the fields in the header field group. After sorting, you can use the ATstatement within a LOOP loop to program statement blocks that the system processes only when the control level changes.
AT NEW f | AT END OF f.
ENDAT.
A control break occurs when the value of the field f or a superior field in the current record has a different value from the previous record (AT NEW) or the subsequent record (AT END). Field f must be part of the header field group.
If the extract dataset is not sorted, the AT - ENDAT block is never executed. Furthermore, all extract records with the value HEX null in the field f are ignored when the control breaks are determined.
The AT... ENDAT blocks in a loop are processed in the order in which they occur. This sequence should be the same as the sort sequence. This sequence must not necessarily be the sequence of the fields in the header field group, but can also be the one determined in the SORT statement.
If you have sorted an extract dataset by the fields f1, f2, , the processing of the control levels should be written between the other control statements in the LOOP loop as follows:
LOOP.
AT FIRST.... ENDAT.
AT NEW f1....... ENDAT.
AT NEW f2....... ENDAT.
AT fgi..... ENDAT.
Single record processing without control statement
AT END OF f2.... ENDAT.
AT END OF f1.... ENDAT.
AT LAST..... ENDAT.
ENDLOOP.
You do not have to use all of the statement blocks listed here, but only the ones you require.
REPORT demo_extract_at_new.
DATA: t1(4) TYPE c, t2 TYPE i.
FIELD-GROUPS: header.
INSERT t2 t1 INTO header.
t1 ='AABB'. t2 = 1. EXTRACT header.
t1 ='BBCC'. t2 = 2. EXTRACT header.
t1 ='AAAA'. t2 = 2. EXTRACT header.
t1 ='AABB'. t2 = 1. EXTRACT header.
t1 ='BBBB'. t2 = 2. EXTRACT header.
t1 ='BBCC'. t2 = 2. EXTRACT header.
t1 ='AAAA'. t2 = 1. EXTRACT header.
t1 ='BBBB'. t2 = 1. EXTRACT header.
t1 ='AAAA'. t2 = 3. EXTRACT header.
t1 ='AABB'. t2 = 1. EXTRACT header.
SORT BY t1 t2.
LOOP.
AT FIRST.
WRITE 'Start of LOOP'.
ULINE.
ENDAT.
AT NEW t1.
WRITE / ' New T1:'.
ENDAT.
AT NEW t2.
WRITE / ' New T2:'.
ENDAT.
WRITE: /14 t1, t2.
AT END OF t2.
WRITE / 'End of T2'.
ENDAT.
AT END OF t1.
WRITE / 'End of T1'.
ENDAT.
AT LAST.
ULINE.
ENDAT.
ENDLOOP.
This program creates a sample extract, containing the fields of the header field group only. After the sorting process, the extract dataset has several control breaks for the control levels T1 and T2, which are indicated in the following figure:
In the LOOP loop, the system displays the contents of the dataset and the control breaks it recognized as follows:
http://help.sap.com/saphelp_erp2005vp/helpdata/en/9f/db9f1f35c111d1829f0000e829fbfe/frameset.htm -
Hello experts!
I have the following issue at the code bellow: when is executed the concatenate command, the program ignores the quantity summarized by COLLECT and gets the last quantity of the record.
loop at it_lips.
it_reg03-cant = it_lips-lgmng.
collect it_reg03.
write it_reg03-cant to vl_cant_lips.
at end of matnr.
write it_reg03-cant to vl_cant_lips.
concatenate it_reg03-tipo_reg it_reg03-rent_cod_pr
it_reg03-rent_cod_um vl_cant_lips
it_reg03-pr_cod_prod it_reg03-pr_des_prod
it_reg03-pr_des_um it_reg03-cant_adj
'/n'
into it_linha-linha separated by '|'.
append it_linha.
endat.
endloop.
How can I get the summarized value to add in it_linha it?
Thanks a lot!
Michel Khouri>>However, when I append in another internal table, the value is from the last record.
that is b'coz of whats in the header.. you will have to either READ it_reg03 or LOOP at it.. to append the right value..
~Suresh -
Can i give b AT END OF /b with condition
Hi experts
can i give AT END OF with condition
like that
AT END OF MATNR WITH KEY WERKS = 'CCRC'.
OR LIKE DAT
AT END OF MATNR WHERE WERKS = 'CCRC'..
can we give like that or not
if not then how
Thanks & Regards
Prashant guptaHi,
check this sample code....
if you comment if condition it will give you many results and if you dont comment the if condition inside the loop it only gives the resuts of carrid which has A in it.....
DATA : t_spfli TYPE TABLE OF spfli.
DATA : spfli TYPE spfli.
SELECT * FROM spfli INTO TABLE t_spfli.
LOOP AT t_spfli INTO spfli.
IF spfli-carrid CS 'A'.
AT END OF carrid.
WRITE spfli-carrid.
ENDAT.
ENDIF.
ENDLOOP.
Regards,
Siddarth -
Sum the currency field by MATNR -urgent
Hi All,
LOOP AT itab1.
LOOP AT itab2 where matnr = itab1-matnr.
itab3-Diff = itab1-zzstwrt - itab2-zzstwrt.
if itab3-diff ne 0.
WRITE: /01 itab1-YYRVCTR, 09 itab1-VRSIO,17 itab1-VKORG,
23 itab1-zzstwrt,47 itab1-STWAE,53 itab2-matnr,
62 itab2-zzstwrt,87 itab2-STWAE,100 itab3-Diff.
endif.
ENDLOOP.
ENDLOOP.
How to SUM along this code ..this si u
example
MATNR(materil)
EU_11504
EU_11504
EU_11504
EU_11504
EU_11504
EU_11504
EU_11504
zzstwrt (ST Currency S780-field)
759.01
759.01
759.01
759.01
759.01
759.01
759.01
0.00
Differece (ST curr Difference )
6,831.09
6,831.09
6,831.09
6,831.09
6,831.09
6,831.09
6,831.09
I have to SUMARAISE by materail..
same matnr have different amount ..how to sum by currency towards MATNR
I mean currency amount should add by matetail wieseHI,
USE SUM EVENT..
check this.... MATNR shub be the first field in itab for reference.
REPORT zkb_test.
DATA: BEGIN OF i_tab1 OCCURS 0,
matnr(18) TYPE c,
desc(20) TYPE c,
valu TYPE i,
quan TYPE i,
sno(2) TYPE c,
END OF i_tab1.
DATA: i_tab2 LIKE TABLE OF i_tab1 WITH HEADER LINE.
START-OF-SELECTION.
i_tab1-sno = 1.
i_tab1-matnr = 'abc'.
i_tab1-desc = 'abc'.
i_tab1-valu = 10.
i_tab1-quan = 20.
APPEND i_tab1.
i_tab1-sno = 2.
i_tab1-matnr = 'xyz'.
i_tab1-desc = 'xyz'.
i_tab1-valu = 10.
i_tab1-quan = 20.
APPEND i_tab1.
i_tab1-sno = 3.
i_tab1-matnr = 'abc'.
i_tab1-desc = 'abc'.
i_tab1-valu = 10.
i_tab1-quan = 20.
APPEND i_tab1.
SORT i_tab1 BY matnr.
LOOP AT i_tab1.
i_tab2 = i_tab1.
AT END OF matnr.
SUM.
i_tab2-valu = i_tab1-valu.
i_tab2-quan = i_tab1-quan.
APPEND i_tab2.
ENDAT.
ENDLOOP.
LOOP AT i_tab2.
WRITE:/ i_tab2-sno, i_tab2-matnr, i_tab2-valu, i_tab2-quan.
ENDLOOP.
Regards
SAB -
Moderator message: please use a more informative subject in future
Dear Experts;
I am fetch values And stored in IT_EKPO. this itab available record in below format.
ebeln matnr count
10 lo45 0
10 l045 0
10 o77 0
13 li12. 0
my case is count matnr comparing ebeln.that is my output is stored it_ekpo1.for this way.
ebeln matnr count
10 lo45 2
10 lo77 1
13 li12 1
I am trying this code.is not working .
it_ekpo1[] = it_ekpo[].
sort it_ekpo1 by matnr comparing ebeln.
sort it_ekpo by matnr comparing ebeln.
loop at it_ekpo.
clear count1.
loop at it_ekpo1 where matnr = it_ekpo-matnr.
read table it_ekpo1 with key ebeln = it_ekko-ebeln.
loop at it_ekpo1 where matnr = it_ekpo-matnr.
count1 = count1 + 1.
endloop.
it_count-matnr = it_ekpo-matnr.
it_count-count1 = count1.
append it_count.
clear it_count.
endloop.
<<text removed>>
regards,
raj
Edited by: Matt on Dec 11, 2008 2:40 PM - Please use tags around your ABAP. Do not say "ASAP".Hi Soosai,
The following code will work for you.
int_tab - Source table:
ebeln matnr count
10 lo45 0
10 lo45 0
10 o77 0
13 li12 0
int_tab1 - Target table:
ebeln matnr count
10 lo45 2
10 o77 1
13 li12 1
SORT int_tab BY ebeln matnr.
LOOP AT int_tab INTO wa_tab.
w_count = w_count + 1.
wa_tab1 = wa_tab.
AT END OF matnr.
wa_tab1-count = w_count.
CLEAR w_count.
APPEND wa_tab1 TO int_tab1.
ENDAT.
ENDLOOP.
Hope this will help you.
Regards,
Manoj Kumar P -
Closing stock of a particular date
how to get plant wise material closing stock on any particular date. say previous months end date. I am calculating that from MSEG table with the help of MSEGINSMK and MSEGSHKZG field. (with date filtaration by joining MBLNR of MKPF table) But stock is showing different with the closing stock showing in MB5B report for that date. I don't know which BWART of MSEG table to be excluded. My email id is [email protected]
Hi,
This is a stock aging report, you can use this for reference.
Logic: Based on current stock and value from MBEW table. The latest receipt dates were taken till the qty tallies off.Rejections and reversals are considered.
The movement types considered are ('101','102','105','106','122','123','131','132','301','302','309','310','501','502','531','532','561','562','701','702').
*& Report ZMM03_TRY *
REPORT ZMM03 LINE-SIZE 226
LINE-COUNT 35(2)
NO STANDARD PAGE HEADING..
TABLES : S032, "Current Stock And Grouping Terms
MBEW, "Material Valuation
T023T, "Material Group Desc.
MAKT, "Material Description
EKPO. "Purchasing Document Item.
DATA : BEGIN OF T_HEADER OCCURS 0,
MTART LIKE MARA-MTART,
MATNR LIKE MBEW-MATNR,
BWKEY LIKE MBEW-BWKEY,
MATKL LIKE MARA-MATKL,
MAKTX LIKE MAKT-MAKTX,
MEINS LIKE MARA-MEINS,
LBKUM LIKE MBEW-LBKUM,
SALK3 LIKE MBEW-SALK3,
VERPR LIKE MBEW-VERPR,
CLSTK LIKE MBEW-LBKUM,
CLVAL LIKE CKMLCR-SALK3,
UNIT LIKE CKMLCR-PVPRS,
END OF T_HEADER.
DATA : BEGIN OF T_MSEG OCCURS 0,
MATNR LIKE MSEG-MATNR,
WERKS LIKE MSEG-WERKS,
BUDAT LIKE MKPF-BUDAT,
MBLNR LIKE MKPF-MBLNR,
MJAHR LIKE MKPF-MJAHR,
ZEILE LIKE MSEG-ZEILE,
LFBNR LIKE MSEG-LFBNR,
LFBJA LIKE MSEG-LFBJA,
LFPOS LIKE MSEG-LFPOS,
BWART LIKE MSEG-BWART,
MENGE LIKE MSEG-MENGE,
EBELN LIKE MSEG-EBELN,
EBELP LIKE MSEG-EBELP,
XAUTO LIKE MSEG-XAUTO,
UMMAT LIKE MSEG-UMMAT,
UMWRK LIKE MSEG-UMWRK,
MARK(1),
END OF T_MSEG.
TYPE-POOLS : SLIS.
DATA : L_STOCK TYPE MSEG-MENGE.
DATA : WA_MSEG LIKE T_MSEG.
DATA : WA_MSEG1 LIKE T_MSEG.
DATA : T_ITEMS LIKE T_MSEG OCCURS 0 WITH HEADER LINE.
DATA : T_CUR_STOCK LIKE T_MSEG OCCURS 0 WITH HEADER LINE.
DATA : L_LBKUM TYPE MBEW-LBKUM.
DATA : BEGIN OF T_OUTPUT OCCURS 0,
WERKS LIKE MSEG-WERKS,
MATNR LIKE MSEG-MATNR,
BUDAT LIKE MKPF-BUDAT,
MENGE LIKE MSEG-MENGE,
PDAYS TYPE I,
PVAL TYPE MSEG-MENGE,
MAKTX LIKE MAKT-MAKTX,
CQTY LIKE MSEG-MENGE,
CPRC LIKE MBEW-SALK3,
END OF T_OUTPUT.
DATA: GRID_TAB TYPE SLIS_T_FIELDCAT_ALV WITH HEADER LINE.
DATA : T_SORT TYPE SLIS_T_SORTINFO_ALV,
WA_SORT TYPE SLIS_SORTINFO_ALV.
*AT SELECTION-SCREEN.
SELECTION-SCREEN BEGIN OF BLOCK 1 WITH FRAME TITLE TEXT-014.
SELECTION-SCREEN SKIP 1.
PARAMETERS : P_DATE LIKE S032-LETZTABG OBLIGATORY DEFAULT SY-DATUM.
SELECTION-SCREEN SKIP 1.
SELECTION-SCREEN END OF BLOCK 1.
SELECTION-SCREEN BEGIN OF BLOCK 2 WITH FRAME TITLE TEXT-015.
PARAMETERS : P_WERKS TYPE S032-WERKS OBLIGATORY.
SELECT-OPTIONS : S_LGORT FOR S032-LGORT,
S_MATNR FOR S032-MATNR.
SELECTION-SCREEN END OF BLOCK 2.
SELECTION-SCREEN BEGIN OF BLOCK 3 WITH FRAME TITLE TEXT-016.
SELECT-OPTIONS : S_MTART FOR S032-MTART,
S_MATKL FOR S032-MATKL.
SELECTION-SCREEN END OF BLOCK 3.
IF P_DATE IS INITIAL AND
P_WERKS IS INITIAL AND
S_LGORT IS INITIAL AND
S_MATNR IS INITIAL AND
S_MTART IS INITIAL AND
S_MATKL IS INITIAL.
MESSAGE I398(00) WITH 'Enter Selection Critirea'(019).
SY-SUBRC = '1'.
ELSE.
SELECT AMATNR ABWKEY BMATKL BMTART CMAKTX BMEINS A~LBKUM
A~SALK3
INTO CORRESPONDING FIELDS OF TABLE T_HEADER
FROM MBEW AS A INNER JOIN MARA AS B ON AMATNR = BMATNR
INNER JOIN MAKT AS C ON AMATNR = CMATNR
WHERE A~MATNR IN S_MATNR
AND A~BWKEY EQ P_WERKS
AND MATKL IN S_MATKL
AND MTART IN S_MTART
AND BWTAR EQ ' '
AND C~SPRAS = SY-LANGU.
IF SY-SUBRC EQ 0.
SELECT ABUDAT AMBLNR AMJAHR BZEILE BMATNR BWERKS B~BWART
BMENGE BLFBNR BLFBJA BLFPOS BEBELN BEBELP B~XAUTO
BUMMAT BUMWRK
INTO CORRESPONDING FIELDS OF TABLE T_MSEG
FROM MKPF AS A INNER JOIN MSEG AS B ON AMBLNR = BMBLNR
AND AMJAHR = BMJAHR
FOR ALL ENTRIES IN T_HEADER
WHERE A~BUDAT <= P_DATE
AND B~MATNR = T_HEADER-MATNR
AND B~WERKS = T_HEADER-BWKEY
AND B~BWART IN ('101',
'102',
'105',
'106',
'122',
'123',
'301',
'302',
'701',
'702',
'131',
'132',
'309',
'310',
'501',
'502',
'531',
'532',
'561',
'562').
PERFORM GET_DEAD_STOCK.
PERFORM DISPLAY_OUTPUT.
ELSE.
MESSAGE S398(00) WITH 'No Data found for'(013)
'Given Selection Critirea'(017).
LEAVE LIST-PROCESSING.
ENDIF.
ENDIF.
*& Form get_dead_stock
text
FORM GET_DEAD_STOCK .
LOOP AT T_HEADER.
SORT T_MSEG BY MATNR WERKS BUDAT DESCENDING MBLNR DESCENDING.
LOOP AT T_MSEG WHERE MATNR = T_HEADER-MATNR
AND WERKS = T_HEADER-BWKEY
AND ( BWART = '101' OR
BWART = '105' OR
BWART = '501' OR
BWART = '531' OR
BWART = '561' OR
BWART = '701' OR
BWART = '309' OR
BWART = '301' OR
BWART = '131' ).
IF T_MSEG-BWART = 101.
READ TABLE T_MSEG WITH KEY LFBNR = T_MSEG-MBLNR
LFBJA = T_MSEG-MJAHR
LFPOS = T_MSEG-ZEILE
BWART = 102.
IF SY-SUBRC = 0.
T_MSEG-MARK = 'X'.
MODIFY T_MSEG.
CONTINUE.
ENDIF.
READ TABLE T_MSEG INTO WA_MSEG WITH KEY LFBNR = T_MSEG-MBLNR
LFBJA = T_MSEG-MJAHR
LFPOS = T_MSEG-ZEILE
BWART = 122.
IF SY-SUBRC = 0.
READ TABLE T_MSEG INTO WA_MSEG1 WITH KEY LFBNR = WA_MSEG-MBLNR
LFBJA = WA_MSEG-MJAHR
LFPOS = WA_MSEG-ZEILE
BWART = 123.
IF SY-SUBRC EQ 0.
WA_MSEG-MARK = 'X'.
MODIFY T_MSEG FROM WA_MSEG.
CONTINUE.
ELSE.
IF T_MSEG-MENGE EQ WA_MSEG-MENGE.
T_MSEG-MARK = 'X'.
MODIFY T_MSEG.
CONTINUE.
ELSE.
T_MSEG-MENGE = T_MSEG-MENGE - WA_MSEG-MENGE.
MODIFY T_MSEG.
ENDIF.
ENDIF.
ENDIF.
ELSEIF T_MSEG-BWART = 105.
READ TABLE T_MSEG INTO WA_MSEG WITH KEY LFBNR = T_MSEG-MBLNR
LFBJA = T_MSEG-MJAHR
LFPOS = T_MSEG-ZEILE
BWART = 106.
IF SY-SUBRC = 0.
T_MSEG-MARK = 'X'.
MODIFY T_MSEG.
CONTINUE.
ENDIF.
ELSEIF T_MSEG-BWART = 131.
READ TABLE T_MSEG INTO WA_MSEG WITH KEY LFBNR = T_MSEG-MBLNR
LFBJA = T_MSEG-MJAHR
LFPOS = T_MSEG-ZEILE
BWART = 132.
IF SY-SUBRC = 0.
T_MSEG-MARK = 'X'.
MODIFY T_MSEG.
CONTINUE.
ENDIF.
ELSEIF T_MSEG-BWART = 501.
READ TABLE T_MSEG WITH KEY LFBNR = T_MSEG-MBLNR
LFBJA = T_MSEG-MJAHR
LFPOS = T_MSEG-ZEILE
BWART = 502.
IF SY-SUBRC = 0.
T_MSEG-MARK = 'X'.
MODIFY T_MSEG.
CONTINUE.
ENDIF.
ELSEIF T_MSEG-BWART = 301.
READ TABLE T_MSEG WITH KEY LFBNR = T_MSEG-MBLNR
LFBJA = T_MSEG-MJAHR
LFPOS = T_MSEG-ZEILE
BWART = 302.
IF SY-SUBRC = 0.
T_MSEG-MARK = 'X'.
MODIFY T_MSEG.
CONTINUE.
ENDIF.
ELSEIF T_MSEG-BWART = 531.
READ TABLE T_MSEG WITH KEY LFBNR = T_MSEG-MBLNR
LFBJA = T_MSEG-MJAHR
LFPOS = T_MSEG-ZEILE
BWART = 532.
IF SY-SUBRC = 0.
T_MSEG-MARK = 'X'.
MODIFY T_MSEG.
CONTINUE.
ENDIF.
ELSEIF T_MSEG-BWART = 561.
READ TABLE T_MSEG WITH KEY LFBNR = T_MSEG-MBLNR
LFBJA = T_MSEG-MJAHR
LFPOS = T_MSEG-ZEILE
BWART = 562.
IF SY-SUBRC = 0.
T_MSEG-MARK = 'X'.
MODIFY T_MSEG.
CONTINUE.
ENDIF.
ELSEIF T_MSEG-BWART = 701.
READ TABLE T_MSEG WITH KEY LFBNR = T_MSEG-MBLNR
LFBJA = T_MSEG-MJAHR
LFPOS = T_MSEG-ZEILE
BWART = 702.
IF SY-SUBRC = 0.
T_MSEG-MARK = 'X'.
MODIFY T_MSEG.
CONTINUE.
ENDIF.
ELSEIF T_MSEG-BWART = 309.
READ TABLE T_MSEG WITH KEY LFBNR = T_MSEG-MBLNR
LFBJA = T_MSEG-MJAHR
LFPOS = T_MSEG-ZEILE
BWART = 310.
IF SY-SUBRC = 0.
T_MSEG-MARK = 'X'.
MODIFY T_MSEG.
CONTINUE.
ELSEIF T_MSEG-XAUTO = ' '.
T_MSEG-MARK = 'X'.
MODIFY T_MSEG.
CONTINUE.
ELSEIF T_MSEG-MATNR EQ T_MSEG-UMMAT.
T_MSEG-MARK = 'X'.
MODIFY T_MSEG.
CONTINUE.
ENDIF.
ENDIF.
SELECT SINGLE EBELN INTO EKPO-EBELN FROM EKPO
WHERE EBELN = T_MSEG-EBELN
AND EBELP = T_MSEG-EBELP
AND KNTTP = 'K'.
IF SY-SUBRC = 0.
T_MSEG-MARK = 'X'.
MODIFY T_MSEG.
CONTINUE.
ENDIF.
TMENGE = TMENGE - t_mseg-MENGE.
ENDLOOP.
ENDLOOP.
DELETE T_MSEG WHERE MARK = 'X'.
DELETE T_MSEG WHERE ( BWART = '102' OR
BWART = '106' OR
BWART = '502' OR
BWART = '532' OR
BWART = '562' OR
BWART = '702' OR
BWART = '310' OR
BWART = '302' OR
BWART = '123' OR
BWART = '122' OR
BWART = '132' ).
SORT T_HEADER BY MATNR BWKEY.
DELETE ADJACENT DUPLICATES FROM T_HEADER COMPARING MATNR BWKEY.
T_CUR_STOCK[] = T_MSEG[].
SORT T_CUR_STOCK BY MATNR WERKS.
LOOP AT T_CUR_STOCK.
WA_MSEG = T_CUR_STOCK.
AT END OF WERKS.
ENDAT.
ENDLOOP.
LOOP AT T_HEADER.
CLEAR L_LBKUM.
L_LBKUM = T_HEADER-LBKUM.
REFRESH T_ITEMS.
CLEAR T_ITEMS.
LOOP AT T_MSEG WHERE MATNR EQ T_HEADER-MATNR
AND WERKS EQ T_HEADER-BWKEY.
T_ITEMS = T_MSEG.
APPEND T_ITEMS.
CLEAR T_ITEMS.
ENDLOOP.
SORT T_ITEMS BY BUDAT DESCENDING
MBLNR DESCENDING.
CLEAR L_LBKUM.
LOOP AT T_ITEMS.
L_LBKUM = T_ITEMS-MENGE - T_HEADER-LBKUM.
IF L_LBKUM GE 0.
T_OUTPUT-MATNR = T_HEADER-MATNR.
T_OUTPUT-WERKS = T_HEADER-BWKEY.
T_OUTPUT-BUDAT = T_ITEMS-BUDAT.
T_OUTPUT-MENGE = T_HEADER-LBKUM.
APPEND T_OUTPUT.
CLEAR T_OUTPUT.
EXIT.
ELSE.
T_HEADER-LBKUM = T_HEADER-LBKUM - T_ITEMS-MENGE.
T_OUTPUT-MATNR = T_HEADER-MATNR.
T_OUTPUT-WERKS = T_HEADER-BWKEY.
T_OUTPUT-BUDAT = T_ITEMS-BUDAT.
T_OUTPUT-MENGE = T_ITEMS-MENGE.
APPEND T_OUTPUT.
CLEAR T_OUTPUT.
CONTINUE.
ENDIF.
ENDLOOP.
ENDLOOP.
ENDFORM. " get_dead_stock
*& Form DISPLAY_OUTPUT
text
FORM DISPLAY_OUTPUT .
DATA: L_DAYS TYPE I.
DATA : WA_OUTPUT LIKE T_OUTPUT.
DATA : T_FINAL LIKE T_OUTPUT OCCURS 0 WITH HEADER LINE.
DATA : WA_FINAL LIKE T_OUTPUT.
DATA : L_CQTY TYPE MSEG-MENGE,
L_CPRC TYPE MBEW-SALK3.
DATA : L_TITLE TYPE LVC_TITLE.
DATA : L_NAME1 TYPE T001W-NAME1.
*C-- Not to output when the quantity is zero.
DELETE T_OUTPUT WHERE MENGE EQ 0.
SORT T_OUTPUT BY WERKS MATNR BUDAT.
LOOP AT T_OUTPUT.
T_FINAL = T_OUTPUT.
AT NEW MATNR.
CLEAR T_HEADER.
READ TABLE T_HEADER WITH KEY MATNR = T_OUTPUT-MATNR
BWKEY = T_OUTPUT-WERKS.
ENDAT.
T_FINAL-MAKTX = T_HEADER-MAKTX.
IF T_HEADER-LBKUM GT 0.
T_FINAL-PVAL = ( T_OUTPUT-MENGE * T_HEADER-SALK3 / T_HEADER-LBKUM ).
ELSE.
CLEAR T_FINAL-PVAL.
ENDIF.
L_CQTY = L_CQTY + T_OUTPUT-MENGE.
IF T_HEADER-LBKUM GT 0.
L_CPRC = L_CPRC + ( T_OUTPUT-MENGE * T_HEADER-SALK3 / T_HEADER-LBKUM ).
ENDIF.
CALL FUNCTION 'HR_SGPBS_YRS_MTHS_DAYS'
EXPORTING
BEG_DA = T_OUTPUT-BUDAT
END_DA = P_DATE
IMPORTING
NO_CAL_DAY = L_DAYS
EXCEPTIONS
DATEINT_ERROR = 1
OTHERS = 2.
IF SY-SUBRC <> 0.
WRITE : 70 'Error While Calculating days'(018) .
ELSE.
T_FINAL-PDAYS = L_DAYS.
ENDIF.
T_FINAL-CQTY = L_CQTY.
T_FINAL-CPRC = L_CPRC.
APPEND T_FINAL.
AT END OF MATNR.
CLEAR : L_CPRC, L_CQTY.
ENDAT.
ENDLOOP.
PERFORM BUILD_FIELD_CATALOG.
WA_SORT-FIELDNAME = 'MATNR'.
WA_SORT-SPOS = '1'.
APPEND WA_SORT TO T_SORT.
SELECT SINGLE NAME1 FROM T001W INTO L_NAME1
WHERE WERKS = P_WERKS.
CONCATENATE 'Plant: ' P_WERKS ',' L_NAME1 INTO L_TITLE.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM = SY-CPROG
I_GRID_TITLE = L_TITLE
IT_FIELDCAT = GRID_TAB[]
IT_SORT = T_SORT
I_SAVE = 'A'
TABLES
T_OUTTAB = T_FINAL[].
SORT T_FINAL BY WERKS MATNR BUDAT.
LOOP AT T_FINAL.
WRITE : /10 T_FINAL-MATNR.
WRITE : 30 T_FINAL-WERKS.
WRITE : 40 T_FINAL-BUDAT.
WRITE : 50 T_FINAL-MENGE.
**C-- FM to find the number of days between
**C-- todays date and the posting date
CALL FUNCTION 'HR_SGPBS_YRS_MTHS_DAYS'
EXPORTING
BEG_DA = T_FINAL-BUDAT
END_DA = P_DATE
IMPORTING
NO_CAL_DAY = L_DAYS
EXCEPTIONS
DATEINT_ERROR = 1
OTHERS = 2.
IF SY-SUBRC <> 0.
WRITE : 70 'Error While Calculating days'(018) .
ELSE.
WRITE : 70 L_DAYS.
ENDIF.
AT END OF MATNR.
ULINE.
READ TABLE T_HEADER WITH KEY MATNR = T_FINAL-MATNR
BWKEY = T_FINAL-WERKS.
IF SY-SUBRC EQ 0.
WRITE : /1 'Total Valuated Stock', T_HEADER-LBKUM.
WRITE : /1 'Value of total valuated Stock', T_HEADER-SALK3.
ULINE.
ENDIF.
ENDAT.
ENDLOOP.
ENDFORM. " DISPLAY_OUTPUT
*& Form BUILD_FIELD_CATALOG
text
--> p1 text
<-- p2 text
FORM BUILD_FIELD_CATALOG .
DATA : CNT1 TYPE I.
CNT1 = CNT1 + 1.
GRID_TAB-COL_POS = CNT1.
GRID_TAB-SELTEXT_L = 'Material'.
GRID_TAB-FIELDNAME = 'MATNR'.
GRID_TAB-KEY = 'X'.
GRID_TAB-NO_ZERO = 'X'.
GRID_TAB-TABNAME = 'T_FINAL'.
APPEND GRID_TAB.
CLEAR GRID_TAB.
CNT1 = CNT1 + 1.
GRID_TAB-COL_POS = CNT1.
GRID_TAB-SELTEXT_L = 'Material Description'.
GRID_TAB-FIELDNAME = 'MAKTX'.
GRID_TAB-OUTPUTLEN = '30'.
GRID_TAB-KEY = 'X'.
GRID_TAB-NO_ZERO = 'X'.
GRID_TAB-TABNAME = 'T_FINAL'.
APPEND GRID_TAB.
CLEAR GRID_TAB.
CNT1 = CNT1 + 1.
GRID_TAB-COL_POS = CNT1.
GRID_TAB-SELTEXT_L = 'Date of Reciept'.
GRID_TAB-FIELDNAME = 'BUDAT'.
GRID_TAB-KEY = 'X'.
GRID_TAB-NO_ZERO = 'X'.
GRID_TAB-TABNAME = 'T_FINAL'.
APPEND GRID_TAB.
CLEAR GRID_TAB.
CNT1 = CNT1 + 1.
GRID_TAB-COL_POS = CNT1.
GRID_TAB-SELTEXT_L = 'Quantity'.
GRID_TAB-FIELDNAME = 'MENGE'.
GRID_TAB-KEY = 'X'.
GRID_TAB-NO_ZERO = 'X'.
GRID_TAB-TABNAME = 'T_FINAL'.
APPEND GRID_TAB.
CLEAR GRID_TAB.
CNT1 = CNT1 + 1.
GRID_TAB-COL_POS = CNT1.
GRID_TAB-SELTEXT_L = 'Pending Days'.
GRID_TAB-FIELDNAME = 'PDAYS'.
GRID_TAB-KEY = 'X'.
GRID_TAB-NO_ZERO = 'X'.
GRID_TAB-TABNAME = 'T_FINAL'.
APPEND GRID_TAB.
CLEAR GRID_TAB.
CNT1 = CNT1 + 1.
GRID_TAB-COL_POS = CNT1.
GRID_TAB-SELTEXT_L = 'Value'.
GRID_TAB-FIELDNAME = 'PVAL'.
GRID_TAB-KEY = 'X'.
GRID_TAB-NO_ZERO = 'X'.
GRID_TAB-TABNAME = 'T_FINAL'.
APPEND GRID_TAB.
CLEAR GRID_TAB.
CNT1 = CNT1 + 1.
GRID_TAB-COL_POS = CNT1.
GRID_TAB-SELTEXT_L = 'Cumulative Quantity'.
GRID_TAB-FIELDNAME = 'CQTY'.
GRID_TAB-KEY = 'X'.
GRID_TAB-NO_ZERO = 'X'.
GRID_TAB-TABNAME = 'T_FINAL'.
APPEND GRID_TAB.
CLEAR GRID_TAB.
CNT1 = CNT1 + 1.
GRID_TAB-COL_POS = CNT1.
GRID_TAB-SELTEXT_L = 'Value of Cumulative Quantity'.
GRID_TAB-OUTPUTLEN = '30'.
GRID_TAB-FIELDNAME = 'CPRC'.
GRID_TAB-KEY = 'X'.
GRID_TAB-NO_ZERO = 'X'.
GRID_TAB-TABNAME = 'T_FINAL'.
APPEND GRID_TAB.
ENDFORM. " BUILD_FIELD_CATALOG -
Upload Purchase order text using BDC while updating Material Master MM02
Hi All,
Please help me out with sample code upload PO Txt ( long text...which is more than 72 chars)using MM02. Its very urgent
I am not able to pass data into following fields seen in recording,
RSTXT-TXLINE(02),
RSTXT-TXLINE(03),
RSTXT-TXLINE(04),
RSTXT-TXLINE(05), as we can see only RSTXT-TXLINE field in the RSTXT structure......
how to split the long text into 72 chrs each and pass into data into the RSTXT-TXLINE(02), RSTXT-TXLINE(03), RSTXT-TXLINE(04)....correspondingly........
Thanks in advance.....
Reagards,
Prasad KR.Hi
see the sample program
REPORT zmm_longtext
NO STANDARD PAGE HEADING
LINE-SIZE 255.
Internal Table for Upload of Long Texts Data
DATA: BEGIN OF itab1 OCCURS 0,
matnr LIKE mara-matnr, " Material
text1 LIKE tline-tdline, " Long Text
text2 LIKE tline-tdline, " Long Text
text3 LIKE tline-tdline, " Long Text
text4 LIKE tline-tdline, " Long Text
text5 LIKE tline-tdline, " Long Text
text6 LIKE tline-tdline, " Long Text
text7 LIKE tline-tdline, " Long Text
text8 LIKE tline-tdline, " Long Text
text9 LIKE tline-tdline, " Long Text
text10 LIKE tline-tdline, " Long Text
text11 LIKE tline-tdline, " Long Text
text12 LIKE tline-tdline, " Long Text
text13 LIKE tline-tdline, " Long Text
text14 LIKE tline-tdline, " Long Text
text15 LIKE tline-tdline, " Long Text
text16 LIKE tline-tdline, " Long Text
text17 LIKE tline-tdline, " Long Text
text18 LIKE tline-tdline, " Long Text
text19 LIKE tline-tdline, " Long Text
text20 LIKE tline-tdline, " Long Text
text21 LIKE tline-tdline, " Long Text
text22 LIKE tline-tdline, " Long Text
text23 LIKE tline-tdline, " Long Text
text24 LIKE tline-tdline, " Long Text
text25 LIKE tline-tdline, " Long Text
END OF itab1.
Internal Table for Upload of Long Texts Data
DATA: BEGIN OF itab OCCURS 0,
matnr LIKE mara-matnr, " Material
text LIKE tline-tdline, " Long Text
END OF itab.
To create Long Text lines for CREATE_TEXT function module
DATA:BEGIN OF dt_lines OCCURS 0.
INCLUDE STRUCTURE tline. " Long Text
DATA:END OF dt_lines.
Variable declarations for CREATE_TEXT function module
DATA : dl_name TYPE thead-tdname, " Object Name
dl_lan TYPE thead-tdspras, " Language
gv_matnr TYPE matnr.
Constants
CONSTANTS:
Object ID for Long Text of Material Basic Data 1
c_best TYPE thead-tdid VALUE 'GRUN',
c_material TYPE thead-tdobject VALUE 'MATERIAL'. " Object
Parameters
PARAMETERS p_file LIKE rlgrap-filename.
At selection-screen on Value Request for file Name
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
Get the F4 Values for the File
CALL FUNCTION 'F4_FILENAME'
EXPORTING
program_name = syst-cprog
dynpro_number = syst-dynnr
IMPORTING
file_name = p_file.
Start Of Selection
START-OF-SELECTION.
*To Upload Flat file
CALL FUNCTION 'UPLOAD'
EXPORTING
filename = p_file
filetype = 'DAT'
TABLES
data_tab = itab1
EXCEPTIONS
conversion_error = 1
invalid_table_width = 2
invalid_type = 3
no_batch = 4
unknown_error = 5
gui_refuse_filetransfer = 6
OTHERS = 7.
SORT itab1 BY matnr.
LOOP AT itab1.
CLEAR gv_matnr.
SELECT SINGLE matnr INTO gv_matnr
FROM mara WHERE bismt = itab1-matnr.
IF itab1-text25 NE ' '.
itab-matnr = gv_matnr.
itab-text = itab1-text25.
APPEND itab.
ENDIF.
IF itab1-text24 NE ' '.
itab-matnr = gv_matnr.
itab-text = itab1-text24.
APPEND itab.
ENDIF.
IF itab1-text23 NE ' '.
itab-matnr = gv_matnr.
itab-text = itab1-text23.
APPEND itab.
ENDIF.
IF itab1-text22 NE ' '.
itab-matnr = gv_matnr.
itab-text = itab1-text22.
APPEND itab.
ENDIF.
IF itab1-text21 NE ' '.
itab-matnr = gv_matnr.
itab-text = itab1-text21.
APPEND itab.
ENDIF.
IF itab1-text20 NE ' '.
itab-matnr = gv_matnr.
itab-text = itab1-text20.
APPEND itab.
ENDIF.
IF itab1-text19 NE ' '.
itab-matnr = gv_matnr.
itab-text = itab1-text19.
APPEND itab.
ENDIF.
IF itab1-text18 NE ' '.
itab-matnr = gv_matnr.
itab-text = itab1-text18.
APPEND itab.
ENDIF.
IF itab1-text17 NE ' '.
itab-matnr = gv_matnr.
itab-text = itab1-text17.
APPEND itab.
ENDIF.
IF itab1-text16 NE ' '.
itab-matnr = gv_matnr.
itab-text = itab1-text16.
APPEND itab.
ENDIF.
IF itab1-text15 NE ' '.
itab-matnr = gv_matnr.
itab-text = itab1-text15.
APPEND itab.
ENDIF.
IF itab1-text14 NE ' '.
itab-matnr = gv_matnr.
itab-text = itab1-text14.
APPEND itab.
ENDIF.
IF itab1-text13 NE ' '.
itab-matnr = gv_matnr.
itab-text = itab1-text13.
APPEND itab.
ENDIF.
IF itab1-text12 NE ' '.
itab-matnr = gv_matnr.
itab-text = itab1-text12.
APPEND itab.
ENDIF.
IF itab1-text11 NE ' '.
itab-matnr = gv_matnr.
itab-text = itab1-text11.
APPEND itab.
ENDIF.
IF itab1-text10 NE ' '.
itab-matnr = gv_matnr.
itab-text = itab1-text10.
APPEND itab.
ENDIF.
IF itab1-text9 NE ' '.
itab-matnr = gv_matnr.
itab-text = itab1-text9.
APPEND itab.
ENDIF.
IF itab1-text8 NE ' '.
itab-matnr = gv_matnr.
itab-text = itab1-text8.
APPEND itab.
ENDIF.
IF itab1-text7 NE ' '.
itab-matnr = gv_matnr.
itab-text = itab1-text7.
APPEND itab.
ENDIF.
IF itab1-text6 NE ' '.
itab-matnr = gv_matnr.
itab-text = itab1-text6.
APPEND itab.
ENDIF.
IF itab1-text5 NE ' '.
itab-matnr = gv_matnr.
itab-text = itab1-text5.
APPEND itab.
ENDIF.
IF itab1-text4 NE ' '.
itab-matnr = gv_matnr.
itab-text = itab1-text4.
APPEND itab.
ENDIF.
IF itab1-text3 NE ' '.
itab-matnr = gv_matnr.
itab-text = itab1-text3.
APPEND itab.
ENDIF.
IF itab1-text2 NE ' '.
itab-matnr = gv_matnr.
itab-text = itab1-text2.
APPEND itab.
ENDIF.
IF itab1-text1 NE ' '.
itab-matnr = gv_matnr.
itab-text = itab1-text1.
APPEND itab.
ENDIF.
CLEAR itab.
ENDLOOP.
DELETE itab WHERE matnr EQ ' '.
Upload the Texts
SORT itab BY matnr.
LOOP AT itab.
dt_lines-tdformat = 'ST'.
dt_lines-tdline = itab-text.
APPEND dt_lines.
dl_lan = sy-langu.
dl_name = itab-matnr.
Call the Function Module to Create Text
CALL FUNCTION 'CREATE_TEXT'
EXPORTING
fid = c_best
flanguage = dl_lan
fname = dl_name
fobject = c_material
save_direct = 'X'
fformat = '*'
TABLES
flines = dt_lines
EXCEPTIONS
no_init = 1
no_save = 2
OTHERS = 3.
IF sy-subrc <> 0.
WRITE:/ 'Long Text Creation failed for Material'(001),
itab-matnr.
ELSE.
WRITE:/ 'Long Text Created Successfully for Material'(002),
itab-matnr.
ENDIF.
AT END OF matnr.
REFRESH dt_lines.
ENDAT.
ENDLOOP.
Reward points for useful Answers
Regards
Anji -
Report needs to be corrected it is urgent
Ageing Analysis of Inventory Material. This is a report for Inventory Ageing. The report is not giving correct result for the field Value of total valuated stock(MBEWH-SALK3). After displaying the report when we add up the field SALK3 it not the correct result which I got in transaction code MB5L. Can anyone kindly help me in correcting out this report. I am keeping the source code also.
*& Application : Materials Management (MM)
*& Description : Ageing Analysis of Inventory Material
*& Transaction Code :
*& Area Menu Code : ZMM
Report ZMM0001.
MAPPING OF MONTH AND PERIOD AS FINACIAL YEAR STARTS FROM APR - MAR. *
just for reference.
MONTH PERIOD
01.2003 - 10.2003
02.2003 - 11.2003
03.2003 - 12.2003
04.2003 - 01.2003
05.2003 - 02.2003
06.2003 - 03.2003
07.2003 - 04.2003
08.2003 - 05.2003
09.2003 - 06.2003
10.2003 - 07.2003
11.2003 - 08.2003
12.2003 - 09.2003
01.2004 - 10.2004
02.2004 - 11.2004
03.2004 - 12.2004
04.2004 - 01.2004
REPORT ZMMR0001 MESSAGE-ID GW NO STANDARD PAGE HEADING
LINE-COUNT 1000
LINE-SIZE 170.
*FLOWLOGIC
*This Program displays the Ageing Analysis details of Material inventory
*pick up the opening balance consider the previous month of the period
*entered in selection screen.
*Get the qty and value for all material types from mbew table but
*excludeentries where no valuation type is defined
*calculate the receipt qty pick all entries from z_mkpf_mseg where
*date( is less that or equal to the last day of the month and movement
*type equals '101', '561', '501', '951', '953', '955', '957', '301' *
*into i_mseg table.
*To calculate the reversal for receipt qty.
*To get the issue qty upto the date of receipt, delete the issue qty
*fromstock to get the exact stock value on the date the receipt of
*materials happen.
*Calculate the difference in days and mark values based on the below
*condition.
*Display the output as per the user given format.
*FLOWLOGIC
Tables
TABLES : S031, " Statistics: Movements for current stocks
S032, " Statistics: Current Stock and Grouping Terms
MBEW, " Material Valuation
MBEWH, " Material Valuation: History
MARC, " Plant Data for Material
MARA, "material master
T001W, " Plant Details
MKPF,
V_T179.
TYPE-POOLS
TYPE-POOLS: SLIS.
DATA: IT_HEADING TYPE SLIS_T_LISTHEADER WITH HEADER LINE.
DATA: IT_FCAT TYPE SLIS_T_FIELDCAT_ALV WITH HEADER LINE.
DATA: LAY TYPE SLIS_LAYOUT_ALV.
DATA: IT_SORT_SUBTOTAL TYPE SLIS_T_SORTINFO_ALV WITH HEADER LINE.
DATA: IT_EVENT TYPE SLIS_T_EVENT WITH HEADER LINE.
DATA: V_REPID LIKE SY-REPID.
DATA: PRDHA1(5),
PRDHA2(10),
LVL1(40),
LVL2(40),
LVL3(40).
RANGES: S_BWTAR FOR BWTAR.
INTERNAL Tables
*******For Mat. Desc.************
DATA : BEGIN OF I_MAKT OCCURS 0,
MATNR TYPE MAKT-MATNR, " Material Code
MAKTX TYPE MAKT-MAKTX, " Material Description
END OF I_MAKT.
DATA : BEGIN OF TEMP OCCURS 0,
VTEXT(40),
END OF TEMP.
*******For Mat. No. & Type & Grp*
DATA : BEGIN OF I_MARA OCCURS 0,
MATNR TYPE MARA-MATNR, " Material Code
MATKL TYPE MARA-MATKL,
MTART TYPE MARA-MTART,
MFRNR TYPE MARA-MFRNR,
END OF I_MARA.
******For Stock******************
DATA : BEGIN OF I_MBEWH OCCURS 0,
MATNR TYPE MBEWH-MATNR,
BWTAR TYPE MBEWH-BWTAR,
LBKUM TYPE MBEWH-LBKUM,
SALK3 TYPE MBEWH-SALK3,
BWKEY TYPE MBEWH-BWKEY,
VBELN TYPE EBEW-VBELN,
POSNR TYPE EBEW-POSNR,
SOBKZ TYPE QBEW-SOBKZ,
PSPNR TYPE QBEW-PSPNR,
LFGJA TYPE MBEW-LFGJA,
LFMON TYPE MBEW-LFMON,
END OF I_MBEWH.
DATA: I_MBEWH1 LIKE I_MBEWH OCCURS 0 WITH HEADER LINE.
*******For Moving Price***********
DATA : BEGIN OF I_MBEW OCCURS 0,
MATNR TYPE MBEWH-MATNR,
BWTAR TYPE MBEWH-BWTAR,
LBKUM TYPE MBEWH-LBKUM,
VERPR TYPE MBEWH-VERPR,
VPRSV TYPE MBEWH-VPRSV,
STPRS TYPE MBEWH-STPRS,
END OF I_MBEW.
DATA : BEGIN OF I_RECIPT1 OCCURS 0,
MATNR TYPE Z_MKPF_MSEG-MATNR,
NAME1 TYPE LFA1-NAME1,
MAKTX TYPE MAKT-MAKTX,
BWTAR TYPE Z_MKPF_MSEG-BWTAR,
VERPR TYPE MBEWH-VERPR,
PRDHA LIKE MARA-PRDHA,
VTEXT(40) ,
LBKUM TYPE MBEWH-LBKUM,
SALK3 TYPE MBEWH-SALK3,
QTY1 TYPE MBEWH-LBKUM,
VAL1 TYPE P DECIMALS 2,
QTY2 TYPE MBEWH-LBKUM,
VAL2 TYPE P DECIMALS 2,
QTY3 TYPE MBEWH-LBKUM,
VAL3 TYPE P DECIMALS 2,
QTY4 TYPE MBEWH-LBKUM,
VAL4 TYPE P DECIMALS 2,
QTY5 TYPE MBEWH-LBKUM,
VAL5 TYPE P DECIMALS 2,
QTY6 TYPE MBEWH-LBKUM,
VAL6 TYPE P DECIMALS 2,
QTY7 TYPE MBEWH-LBKUM,
VAL7 TYPE P DECIMALS 2,
END OF I_RECIPT1.
DATA : BEGIN OF I_MKPF_MSEG OCCURS 0,
MATNR LIKE MARA-MATNR,
MBLNR LIKE MSEG-MBLNR,
ZEILE LIKE MSEG-ZEILE,
MENGE LIKE MSEG-MENGE,
BWART LIKE MSEG-BWART,
BUDAT LIKE MKPF-BUDAT,
NET_VAL LIKE MSEG-MENGE,
EBELN LIKE MSEG-EBELN,
EBELP LIKE MSEG-EBELP,
LFBNR LIKE MSEG-LFBNR,
LFPOS LIKE MSEG-LFPOS,
SHKZG LIKE MSEG-SHKZG,
MEINS LIKE MARA-MEINS,
SMBLN LIKE MSEG-SMBLN,
SMBLP LIKE MSEG-SMBLP,
END OF I_MKPF_MSEG,
WA_MSEG LIKE I_MKPF_MSEG.
********For Material Movement***
DATA: BEGIN OF I_MSEG OCCURS 0,
MBLNR TYPE Z_MKPF_MSEG-MBLNR,
MATNR TYPE Z_MKPF_MSEG-MATNR,
WERKS TYPE Z_MKPF_MSEG-WERKS,
BWART TYPE Z_MKPF_MSEG-BWART,
BUDAT TYPE Z_MKPF_MSEG-BUDAT,
MENGE TYPE Z_MKPF_MSEG-MENGE,
MEINS TYPE Z_MKPF_MSEG-MEINS,
BWTAR TYPE Z_MKPF_MSEG-BWTAR,
NET_VAL LIKE MSEG-MENGE,
ZEILE TYPE MSEG-ZEILE,
END OF I_MSEG.
********For Material Monvment(Reverse)***
DATA: BEGIN OF I_MSEG1 OCCURS 0,
MBLNR TYPE Z_MKPF_MSEG-MBLNR,
MATNR TYPE Z_MKPF_MSEG-MATNR,
WERKS TYPE Z_MKPF_MSEG-WERKS,
BWART TYPE Z_MKPF_MSEG-BWART,
BUDAT TYPE Z_MKPF_MSEG-BUDAT,
MENGE TYPE Z_MKPF_MSEG-MENGE,
MEINS TYPE Z_MKPF_MSEG-MEINS,
BWTAR TYPE Z_MKPF_MSEG-BWTAR,
SMBLN TYPE Z_MKPF_MSEG-SMBLN,
SMBLP TYPE Z_MKPF_MSEG-SMBLP,
END OF I_MSEG1.
DATA: I_MSEG2 LIKE I_MSEG1 OCCURS 0 WITH HEADER LINE.
********For Recipt Details*******
DATA: BEGIN OF I_RECIPT OCCURS 0,
MATNR TYPE Z_MKPF_MSEG-MATNR,
BWTAR TYPE Z_MKPF_MSEG-BWTAR,
BUDAT TYPE Z_MKPF_MSEG-BUDAT,
DAYS TYPE P,
QTY TYPE Z_MKPF_MSEG-MENGE,
MONTH(3),
YEAR(4),
VERPR TYPE MBEWH-VERPR,
COST TYPE P DECIMALS 2,
MARK(1),
END OF I_RECIPT.
DATA: BEGIN OF I_PLANT OCCURS 0,
WERKS LIKE T024W-WERKS,
EKORG LIKE T024W-EKORG,
BUKRS LIKE T024E-BUKRS,
CHK(1) TYPE C,
END OF I_PLANT.
DATA: BEGIN OF I_USERGRP OCCURS 0.
INCLUDE STRUCTURE USGRP_USER.
DATA: VKORG LIKE VBAK-VKORG,
END OF I_USERGRP.
DATA: MUGRP LIKE USGRP_USER-USERGROUP.
DATA: MUNAME LIKE SY-UNAME,
MMSGTX1(50) TYPE C.
*********For Temp.Values*****
*data: begin of i_temp occurs 0,
matnr type z_mkpf_mseg-matnr,
bwtar type z_mkpf_mseg-bwtar,
budat type z_mkpf_mseg-budat,
menge type z_mkpf_mseg-menge,
end of i_temp.
DATA: DAYS(2).
DATA: NET_VAL LIKE MSEG-MENGE.
DATA: DATE1 TYPE D.
DATA: DATE2 TYPE D.
DATA: MBLNR TYPE MSEG-MBLNR.
DATA: MATNR TYPE MSEG-MATNR.
DATA: BWTAR TYPE MSEG-BWTAR.
DATA : V_DATE TYPE SY-DATUM.
DATA : X(2) TYPE C VALUE '01'.
DATA : P TYPE T009B-POPER. " MONTH
DATA : Q TYPE T009B-BDATJ. " YEAR
DATA : A TYPE T009B-POPER. " FOR MONTH WHERE MONTH STARTS AT APRIL
DATA : B(4) TYPE C. " FOR YEAR
DATA : DATE TYPE SY-DATUM.
DATA: NUMBER_OF_DAYS TYPE P.
DATA: DAT TYPE D.
DATA : X1(2) .
DATA: VPRSV TYPE MBEWH-VPRSV,
STPRS TYPE MBEWH-STPRS.
DATA: C TYPE C VALUE 0,
S(10).
Parameter / Selection - screens
SELECTION-SCREEN BEGIN OF BLOCK IND1 WITH FRAME TITLE TEXT_001.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 1(28) TEXT_002 FOR FIELD P_WERKS.
PARAMETERS : P_WERKS LIKE S031-WERKS OBLIGATORY.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 1(28) TEXT_003 FOR FIELD P_SPMON.
PARAMETERS : P_SPMON LIKE S031-SPMON MODIF ID ABC .
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 1(25) TEXT_004 FOR FIELD S_MATNR.
SELECT-OPTIONS : S_MATNR FOR S031-MATNR.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN END OF BLOCK IND1.
SELECTION-SCREEN BEGIN OF BLOCK B2 WITH FRAME TITLE TEXT_005.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 1(25) TEXT_006 FOR FIELD SO_MATTP.
SELECT-OPTIONS : SO_MATTP FOR MARA-MTART.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 1(25) TEXT_007 FOR FIELD SO_MATGP.
SELECT-OPTIONS : SO_MATGP FOR MARA-MATKL.
SELECTION-SCREEN END OF LINE.
begin of changes by cvns01
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 1(25) TEXT_008 FOR FIELD SO_MFRNR.
SELECT-OPTIONS : SO_MFRNR FOR MARA-MFRNR.
SELECTION-SCREEN END OF LINE.
end of changes by cvns01
*changes
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 1(25) TEXT_009 FOR FIELD SO_MFRNR.
SELECT-OPTIONS : SO_PRDHA FOR MARA-PRDHA NO INTERVALS."NO-EXTENSION.
SELECTION-SCREEN END OF LINE.
*end
SELECTION-SCREEN END OF BLOCK B2.
Initialization
INITIALIZATION.
TEXT_001 = 'Required Data'.
TEXT_002 = 'Plant'.
TEXT_003 = 'Period to analyze - month'.
TEXT_004 = 'Material Number'.
TEXT_005 = 'Optional Data'.
TEXT_006 = 'Material Type'.
TEXT_007 = 'Material Group'.
start of changes by cvns01
TEXT_008 = 'Manufacturer No.'.
TEXT_009 = 'Product Hierarchy'.
end of changes by cvns01
CLEAR:P,Q.
CLEAR A.
P = SY-DATUM+4(2).
SHIFT P LEFT DELETING LEADING C.
Q = SY-DATUM(4).
IF P <= 9.
CONCATENATE Q '0' P INTO S. "p_spmon.
ELSE.
CONCATENATE Q P INTO S. "p_spmon.
ENDIF.
*concatenate q p into s. "p_spmon.
CONDENSE S.
P_SPMON = S.
AT SELECTION-SCREEN ON WERKS
AT SELECTION-SCREEN ON P_WERKS.
CHECK SY-UCOMM = 'ONLI'.
SELECT SINGLE * FROM T001W WHERE WERKS EQ P_WERKS.
IF SY-SUBRC NE 0.
MESSAGE E999 WITH 'Invalid Plant'.
ENDIF.
SELECT T024W~WERKS T024E~EKORG T024E~BUKRS
INTO CORRESPONDING FIELDS OF TABLE I_PLANT
FROM T024W
JOIN T024E ON T024E~EKORG = T024W~EKORG
WHERE T024W~WERKS EQ P_WERKS.
SORT I_PLANT BY WERKS.
DELETE ADJACENT DUPLICATES FROM I_PLANT COMPARING WERKS.
SELECT * INTO CORRESPONDING FIELDS OF TABLE I_USERGRP
FROM USGRP_USER
WHERE BNAME = SY-UNAME.
IF I_USERGRP[] IS INITIAL.
MESSAGE E208(00) WITH 'You are not authorised to view this report'.
ENDIF.
LOOP AT I_USERGRP.
CONCATENATE I_USERGRP-USERGROUP(2) '00' INTO I_USERGRP-VKORG.
MODIFY I_USERGRP.
ENDLOOP.
LOOP AT I_USERGRP.
LOOP AT I_PLANT WHERE BUKRS = I_USERGRP-VKORG.
I_PLANT-CHK = 'X'.
MODIFY I_PLANT.
ENDLOOP.
ENDLOOP.
*delete i_plant where chk = ''.
IF NOT I_PLANT[] IS INITIAL.
LOOP AT I_PLANT.
IF I_PLANT-CHK = ''.
CLEAR P_WERKS.
CONCATENATE 'You are not authorised for plant ' I_PLANT-WERKS INTO MMSGTX1 SEPARATED BY SPACE.
MESSAGE E208(00) WITH MMSGTX1.
ENDIF.
ENDLOOP.
ENDIF.
IF P_WERKS = ''.
MESSAGE E208(00) WITH 'Select/Enter Plant'.
ENDIF.
AT SELECTION-SCREEN OUTPUT.
LOOP AT SCREEN.
IF SCREEN-GROUP1 = 'ABC'.
SCREEN-INPUT = '0'.
MODIFY SCREEN.
ENDIF.
ENDLOOP.
AT SELECTION-SCREEN
*AT SELECTION-SCREEN .
SELECT SINGLE * FROM s031 WHERE werks EQ p_werks
AND spmon EQ p_spmon
AND matnr IN s_matnr.
IF sy-subrc NE 0.
MESSAGE e999 WITH 'NO VALUES EXIST FOR SELECTION CRITERIA'.
ENDIF.
START-OF-SELECTION
START-OF-SELECTION.
PERFORM PRDHA_INITIALIZATION.
PERFORM FETCH_DATA.
PERFORM DISPLAY_DATA.
END-OF-SELECTION.
*& Form FETCH_DATA
text
--> p1 text
<-- p2 text
FORM FETCH_DATA .
CLEAR:P,Q.
CLEAR A.
P = P_SPMON+4(2).
Q = P_SPMON+0(4).
******Materials**********************************
changes made by akshatha
SELECT MARA~MATNR
FROM MARA
JOIN MARC
ON MARCMATNR = MARAMATNR
INTO CORRESPONDING FIELDS OF TABLE I_MARA
WHERE MARA~MATNR IN S_MATNR
AND MARC~WERKS = P_WERKS
AND MARA~MTART IN SO_MATTP
AND MARA~MATKL IN SO_MATGP
AND MARA~MFRNR IN SO_MFRNR
AND MARA~PRDHA IN SO_PRDHA.
end of changes
To get material description for the material
IF NOT I_MARA[] IS INITIAL.
SELECT MATNR
MAKTX
FROM MAKT
INTO CORRESPONDING FIELDS OF TABLE I_MAKT
FOR ALL ENTRIES IN I_MARA
WHERE MATNR = I_MARA-MATNR
AND SPRAS = SY-LANGU.
TO GET OPEN BALANCE QTY WE NEED TO CONSIDER PREVIOUS MONTH OF THE
CORRESPONDING PERIOD
WE WILL GET PROBLEM ONLY PROBLEM WHEN PERIOD IS '01'. THEN WE MUST
CONSIDER FOR 12 TH MONTH OF PREVIOUS YEAR.
****Closing Stock as on Selection-Screen Month....
*By Default last date of month is taken
changed by akshatha
CONCATENATE P_SPMON X INTO V_DATE.
CALL FUNCTION 'DATE_TO_PERIOD_CONVERT'
EXPORTING
I_DATE = V_DATE
I_MONMIT = 00
I_PERIV = 'V3'
IMPORTING
E_BUPER = A
E_GJAHR = Q
EXCEPTIONS
INPUT_FALSE = 1
T009_NOTFOUND = 2
T009B_NOTFOUND = 3
OTHERS = 4 .
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
to get stock quantity
SELECT MATNR LBKUM SALK3 BWKEY LFGJA LFMON
FROM MBEWH
INTO CORRESPONDING FIELDS OF TABLE I_MBEWH
FOR ALL ENTRIES IN I_MARA
WHERE MATNR = I_MARA-MATNR
AND BWKEY = P_WERKS AND BWTAR IN S_BWTAR
AND LFGJA = Q
AND LFMON = A
AND LBKUM > '0.0'.
SELECT MATNR LBKUM SALK3 BWKEY VBELN POSNR LFGJA LFMON
FROM EBEWH
APPENDING CORRESPONDING FIELDS OF TABLE I_MBEWH
WHERE MATNR = I_MARA-MATNR
AND BWKEY = P_WERKS
AND BWTAR IN S_BWTAR
AND LFGJA = Q
AND LFMON = A
AND LBKUM > '0.0'.
and VPRSV = 'S'.
SELECT MATNR LBKUM SALK3 BWKEY SOBKZ PSPNR LFGJA LFMON
FROM QBEWH
APPENDING CORRESPONDING FIELDS OF TABLE I_MBEWH
WHERE MATNR = I_MARA-MATNR
AND BWKEY = P_WERKS
AND BWTAR IN S_BWTAR
AND LFGJA = Q
AND LFMON = A
AND LBKUM > '0.0'.
SELECT MATNR LBKUM SALK3 BWKEY BWTAR
FROM MBEW
INTO CORRESPONDING FIELDS OF TABLE I_MBEWH1
FOR ALL ENTRIES IN I_MARA
WHERE MATNR = I_MARA-MATNR
AND BWKEY = P_WERKS
AND LBKUM > '0.0'.
SELECT MATNR LBKUM SALK3 BWKEY VBELN POSNR SOBKZ BWTAR
FROM EBEW
APPENDING CORRESPONDING FIELDS OF TABLE I_MBEWH1
FOR ALL ENTRIES IN I_MARA
WHERE MATNR = I_MARA-MATNR
AND BWKEY = P_WERKS
AND LBKUM > '0.0'.
SELECT MATNR LBKUM SALK3 BWKEY BWTAR SOBKZ PSPNR
FROM QBEW
APPENDING CORRESPONDING FIELDS OF TABLE I_MBEWH1
FOR ALL ENTRIES IN I_MARA
WHERE MATNR = I_MARA-MATNR
AND BWKEY = P_WERKS
AND LBKUM > '0.0'.
SORT I_MBEWH BY MATNR BWKEY.
SORT I_MBEWH1 BY MATNR BWKEY.
LOOP AT I_MBEWH.
LOOP AT I_MBEWH1 WHERE MATNR = I_MBEWH-MATNR
AND BWKEY = I_MBEWH-BWKEY.
DELETE I_MBEWH1.
ENDLOOP.
ENDLOOP.
APPEND LINES OF I_MBEWH1 TO I_MBEWH.
CLEAR : I_MBEWH1.
REFRESH I_MBEWH1.
SORT I_MBEWH BY MATNR.
LOOP AT I_MBEWH .
I_MBEWH1 = I_MBEWH.
AT END OF MATNR.
SUM.
I_MBEWH1-LBKUM = I_MBEWH-LBKUM.
I_MBEWH1-SALK3 = I_MBEWH-SALK3.
APPEND I_MBEWH1.
ENDAT.
ENDLOOP.
DELETE I_MBEWH1 WHERE LBKUM <= 0.
I_MBEWH[] = I_MBEWH1[].
end of changes
loop at i_mara.
concatenate p_spmon x into v_date.
call function 'DATE_TO_PERIOD_CONVERT'
exporting
i_date = v_date
I_MONMIT = 00
i_periv = 'V3'
importing
e_buper = a
e_gjahr = q
exceptions
input_false = 1
t009_notfound = 2
t009b_notfound = 3
others = 4 .
if sy-subrc <> 0.
message id sy-msgid type sy-msgty number sy-msgno
with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
endif.
To get STOCK QUANTITY and STOCK VALUE for All Valuation Type
select matnr
bwtar
lbkum
salk3
from mbewh
into corresponding fields of i_mbewh
where matnr = i_mara-matnr
and bwkey = p_werks
and lfmon = a " 'A' IS PERIOD FOR FISCAL YR
and lfgja = q.
collect i_mbewh.
clear i_mbewh.
endselect.
if sy-subrc ne 0.
select matnr
bwtar
lbkum
salk3
from mbew
into corresponding fields of i_mbewh
where matnr = i_mara-matnr
and bwkey = p_werks.
collect i_mbewh.
clear i_mbewh.
endselect.
endif.
endloop.
end of changes
Logic: If the Val. Type is defined then for that material dont take
the line item where Val. Type is blank......
sort i_mbewh by matnr bwtar.
i_mbewh1[] = i_mbewh[].
delete i_mbewh where bwtar = ' '.
loop at i_mbewh1.
read table i_mbewh with key matnr = i_mbewh1-matnr.
if sy-subrc <> 0.
move-corresponding i_mbewh1 to i_mbewh.
append i_mbewh.
endif.
endloop.
sort i_mbewh by matnr bwtar.
i_mbewh1[] = i_mbewh[].
end of changes
*****************Last Date of the month is Calculated to find Qty
DAT = V_DATE.
CALL FUNCTION 'HR_E_NUM_OF_DAYS_OF_MONTH'
EXPORTING
P_FECHA = DAT
IMPORTING
NUMBER_OF_DAYS = NUMBER_OF_DAYS.
X1 = NUMBER_OF_DAYS.
CONCATENATE P_SPMON X1 INTO DATE.
********RECIPT QTY FETCHING*************************
select mblnr
matnr
bwart
budat
menge
meins
bwtar
zeile
from z_mkpf_mseg
into (i_mseg-mblnr,
i_mseg-matnr,
i_mseg-bwart,
i_mseg-budat,
i_mseg-menge,
i_mseg-meins,
i_mseg-bwtar,
i_mseg-zeile)
for all entries in i_mbewh
where matnr = i_mbewh-matnr and werks = p_werks
and ( budat le date or budat eq date )
and bwart in ('101','561','501','951','953','955',
**'957','301','105')
and bwtar = i_mbewh-bwtar.
append i_mseg.
clear i_mseg.
endselect.
select mblnr
matnr
bwart
budat
menge
meins
bwtar
zeile
from mseg "z_mkpf_mseg
into corresponding fields of table i_mseg
(i_mseg-mblnr,
i_mseg-matnr,
i_mseg-bwart,
i_mseg-budat,
i_mseg-menge,
i_mseg-meins,
i_mseg-bwtar,
i_mseg-zeile)
for all entries in i_mbewh
where matnr = i_mbewh-matnr and werks = p_werks
and ( budat le date or budat eq date )
and bwart in ('101','561','501','951','953','955',
***'957','301','105')
and bwart in ('101','561','501','951','953','955',
*'957','301','309','105')
and bwtar = i_mbewh-bwtar.
loop at i_mseg.
select single * from mkpf
where mblnr = i_mseg-mblnr.
if ( mkpf-budat ge date ).
delete i_mseg where mblnr = i_mseg-mblnr.
else.
i_mseg-budat = mkpf-budat.
modify i_mseg.
endif.
endloop.
sort i_mseg descending by matnr bwtar budat.
**********For Reversal FOR RECIPT(CHECK FOR REFERENCE)
**********(102,562,502,952,954,956,958)
select mblnr
matnr
bwart
menge
meins
bwtar
smbln
smblp
from mseg
into corresponding fields of table i_mseg1
for all entries in i_mbewh
where matnr = i_mbewh-matnr and werks = p_werks
and bwart in ('102','562','502','952','954','956','958','302')
and bwtar = i_mbewh-bwtar.
loop at i_mseg1.
select single * from mkpf
where mblnr = i_mseg1-mblnr.
if ( mkpf-budat ge date ).
delete i_mseg1 where mblnr = i_mseg1-mblnr.
else.
i_mseg1-budat = mkpf-budat.
modify i_mseg1.
endif.
endloop.
loop at i_mseg1.
read table i_mseg with key mblnr = i_mseg1-smbln
zeile = i_mseg1-smblp.
if sy-subrc = 0.
i_mseg-menge = i_mseg-menge - i_mseg1-menge.
delete i_mseg where mblnr = i_mseg1-smbln and
zeile = i_mseg1-smblp.
move-corresponding i_mseg to i_mseg2.
append i_mseg2.
endif.
endloop.
loop at i_mseg2.
move-corresponding i_mseg2 to i_mseg.
append i_mseg.
endloop.
end of changes.
SELECT MSEGMATNR MSEGMBLNR MSEGZEILE MSEGMENGE MSEGBWART MSEGEBELN
MSEGEBELP MSEGSMBLN MSEG~SMBLP
MKPFBUDAT MSEGSHKZG
FROM MKPF
JOIN MSEG ON MSEGMBLNR = MKPFMBLNR
AND MSEGMJAHR = MKPFMJAHR
INTO CORRESPONDING FIELDS OF TABLE I_MKPF_MSEG
FOR ALL ENTRIES IN I_MARA
WHERE MSEG~MATNR = I_MARA-MATNR
AND MSEG~WERKS = P_WERKS
AND MKPF~BUDAT LE DATE
AND MSEG~BWART IN ('101','105','561','501','301','309','951','953','955','957','712','657','658',
'521','522','303','304','102','562','502','952','954','956','958','302').
DELETE I_MKPF_MSEG WHERE ( BWART = '309' AND SHKZG = 'H' )
OR ( BWART = '303' AND SHKZG = 'H' )
OR ( BWART = '304' AND SHKZG = 'S' )
OR ( BWART = '657' AND SHKZG = 'H' )
OR ( BWART = '658' AND SHKZG = 'S' ).
SORT I_MKPF_MSEG BY MATNR MBLNR.
LOOP AT I_MKPF_MSEG.
if i_mkpf_mseg-bwart = '101' or i_mkpf_mseg-bwart = '102'.
select single * from ekpo where ebeln = i_mkpf_mseg-ebeln
and ebelp = i_mkpf_mseg-ebelp.
if ekpo-pstyp = 7.
delete i_mkpf_mseg where ebeln = i_mkpf_mseg-ebeln
and ebelp = i_mkpf_mseg-ebelp.
CLEAR I_MKPF_MSEG-MENGE.
endif.
endif.
IF ( I_MKPF_MSEG-BWART = '101' OR I_MKPF_MSEG-BWART = '105' OR I_MKPF_MSEG-BWART = '561' OR
I_MKPF_MSEG-BWART = '501' OR I_MKPF_MSEG-BWART = '301' OR I_MKPF_MSEG-BWART = '309' OR
I_MKPF_MSEG-BWART = '951' OR I_MKPF_MSEG-BWART = '953' OR I_MKPF_MSEG-BWART = '955' OR
I_MKPF_MSEG-BWART = '957' OR I_MKPF_MSEG-BWART = '303' OR I_MKPF_MSEG-BWART = '521' OR
I_MKPF_MSEG-BWART = '712' OR I_MKPF_MSEG-BWART = '657' ).
NET_VAL = NET_VAL + I_MKPF_MSEG-MENGE.
ENDIF.
LOOP AT I_MKPF_MSEG WHERE MATNR = I_MKPF_MSEG-MATNR.
IF ( I_MKPF_MSEG-BWART = '102' OR I_MKPF_MSEG-BWART = '562' OR
I_MKPF_MSEG-BWART = '502' OR I_MKPF_MSEG-BWART = '952' OR
I_MKPF_MSEG-BWART = '954' OR I_MKPF_MSEG-BWART = '956' OR
I_MKPF_MSEG-BWART = '958' OR I_MKPF_MSEG-BWART = '302' OR
I_MKPF_MSEG-BWART = '304' OR I_MKPF_MSEG-BWART = '522' OR
I_MKPF_MSEG-BWART = '658' ) AND
( I_MKPF_MSEG-MBLNR = I_MKPF_MSEG-SMBLN AND
I_MKPF_MSEG-ZEILE = I_MKPF_MSEG-SMBLP ).
NET_VAL = NET_VAL - I_MKPF_MSEG-MENGE.
DELETE I_MSEG WHERE MBLNR = I_MSEG1-SMBLN AND
ZEILE = I_MSEG1-SMBLP.
ENDIF.
ENDLOOP.
WA_MSEG = I_MKPF_MSEG.
AT END OF MATNR.
I_MSEG-MATNR = WA_MSEG-MATNR.
I_MSEG-MENGE = NET_VAL.
I_MSEG-BUDAT = WA_MSEG-BUDAT.
APPEND I_MSEG.
CLEAR NET_VAL.
ENDAT.
ENDLOOP.
end of changes
DELETE I_MSEG WHERE MENGE = '0.000'.
SORT I_MSEG DESCENDING BY MATNR BWTAR BUDAT.
***#******RECIPT COMPLETE FINAL TABLE( I_MSEG)**********
********IF THE VAL. TYPE IS NOT THERE THEN PUT 'X'
loop at i_mbewh.
if i_mbewh-bwtar = ' '.
i_mbewh-bwtar = 'X'.
modify i_mbewh.
endif.
endloop.
delete i_mbewh where lbkum = '0.00'.
end of changes
loop at i_mseg.
if i_mseg-bwtar = ' '.
i_mseg-bwtar = 'X'.
modify i_mseg.
endif.
endloop.
end of changes
DATA: MENGE TYPE MSEG-MENGE.
start of changes by akshatha
SORT I_MSEG BY MATNR BWTAR.
SORT I_MBEWH BY MATNR BWTAR.
LOOP AT I_MSEG.
if condition, read and it_mseg-loop commented by akshatha.
if i_mbewh-lbkum > '0.00'.
read table i_mbewh with key matnr = i_mseg-matnr
bwtar = i_mseg-bwtar.
loop at i_mseg .
if ( i_mseg-mblnr <> mblnr ) and ( i_mseg-matnr ne i_temp-matnr
or i_mseg-bwtar ne i_temp-bwtar ) .
i_temp-matnr = i_mseg-matnr.
i_temp-bwtar = i_mseg-bwtar.
i_temp-budat = i_mseg-budat.
i_temp-menge = i_mseg-menge.
mblnr = i_mseg-mblnr.
matnr = i_mseg-matnr.
bwtar = i_mseg-bwtar.
append i_temp.
end of changes
delete i_mseg .
loop at i_mbewh where matnr = matnr
and bwtar = bwtar.
end of changes
LOOP AT I_MBEWH WHERE MATNR = I_MSEG-MATNR
AND BWTAR = I_MSEG-BWTAR.
FOR GETTING THE VALUES OF ISSUES ON & UPTO THE DATE OF RECIPT.
DELETE THE ISSUE QTY FROM STOCK SO THAT WE CAN GET THE EXACT STOCK
VALUE ON THE DATE WHEN RECIPT OF MATERIAL HAS HAPPEN
ISSUES R NOTHING BUT TYPE OF CONSUPTION.
commented and changed by akshatha
if ( i_mbewh-lbkum >= i_temp-menge ).
IF ( I_MBEWH-LBKUM >= I_MSEG-MENGE ).
I_RECIPT-MATNR = I_MBEWH-MATNR.
I_RECIPT-BWTAR = I_MBEWH-BWTAR.
i_recipt-budat = i_temp-budat.
I_RECIPT-BUDAT = I_MSEG-BUDAT.
end of changes
*Type Conversion From Sy-datum to type d.
DATE1 = DATE.
DATE2 = I_RECIPT-BUDAT.
*Type Conversion From Sy-datum to type d.
CALL FUNCTION 'SD_DATETIME_DIFFERENCE'
EXPORTING
DATE1 = DATE1
TIME1 = SY-UZEIT
DATE2 = DATE2
TIME2 = SY-UZEIT
IMPORTING
DATEDIFF = I_RECIPT-DAYS.
IF SY-SUBRC <> 0.
ENDIF.
i_recipt-qty = i_temp-menge.
I_RECIPT-QTY = I_MSEG-MENGE.
i_mbewh-lbkum = i_mbewh-lbkum - i_temp-menge.
I_MBEWH-LBKUM = I_MBEWH-LBKUM - I_MSEG-MENGE.
elseif ( i_mbewh-lbkum < i_temp-menge ).
ELSEIF ( I_MBEWH-LBKUM < I_MSEG-MENGE ).
I_RECIPT-MATNR = I_MBEWH-MATNR.
I_RECIPT-BWTAR = I_MBEWH-BWTAR.
i_recipt-budat = i_temp-budat.
I_RECIPT-BUDAT = I_MSEG-BUDAT.
*Type Conversion From Sy-datum to type d.
DATE1 = DATE.
DATE2 = I_RECIPT-BUDAT.
*Calculation of Difference of dates
CALL FUNCTION 'SD_DATETIME_DIFFERENCE'
EXPORTING
DATE1 = DATE1
TIME1 = SY-UZEIT
DATE2 = DATE2
TIME2 = SY-UZEIT
IMPORTING
DATEDIFF = I_RECIPT-DAYS.
IF SY-SUBRC <> 0.
ENDIF.
I_RECIPT-QTY = I_MBEWH-LBKUM.
I_MBEWH-LBKUM = '0.00'.
ENDIF.
MODIFY I_MBEWH.
APPEND I_RECIPT.
exit.
end of changes
ENDLOOP.
endif.
IF I_MBEWH-LBKUM <> '0.00'.
clear i_temp.
CLEAR I_MSEG.
ENDIF.
endloop.
endif.
end of changes
ENDLOOP.
**********FINAL RECIPT TABLE WITH AGE
SORT I_RECIPT BY MATNR BWTAR DAYS.
LOOP AT I_RECIPT.
*Calculation of Fiscal yr for moving price.
PERFORM PERIOD_CALCULATION USING I_RECIPT-BUDAT+4(2)
I_RECIPT-BUDAT+0(4) I_RECIPT-MONTH
I_RECIPT-YEAR.
IF I_RECIPT-BWTAR = 'X'.
I_RECIPT-BWTAR = ' '.
ENDIF.
**************Moving Price for All material for all months......
SELECT SINGLE VERPR
VPRSV
STPRS
FROM MBEWH
INTO (I_RECIPT-VERPR,
VPRSV,
STPRS )
WHERE MATNR = I_RECIPT-MATNR
AND BWTAR = I_RECIPT-BWTAR
AND BWKEY = P_WERKS
AND LFMON = I_RECIPT-MONTH
AND LFGJA = I_RECIPT-YEAR
and lbkum = i_recipt-qty.
IF SY-SUBRC <> 0.
SELECT SINGLE VERPR
VPRSV
STPRS
FROM MBEW
INTO (I_RECIPT-VERPR,
VPRSV,
STPRS )
WHERE MATNR = I_RECIPT-MATNR
AND BWKEY = P_WERKS
and lbkum = i_recipt-qty.
ENDIF.
IF I_RECIPT-VERPR IS INITIAL.
SELECT SINGLE VERPR
VPRSV
STPRS
FROM EBEWH
INTO (I_RECIPT-VERPR,
VPRSV,
STPRS )
WHERE MATNR = I_RECIPT-MATNR
AND BWTAR = I_RECIPT-BWTAR
AND BWKEY = P_WERKS
AND LFMON = I_RECIPT-MONTH
AND LFGJA = I_RECIPTNever mind. I updated my aperture in app store and it fixed the problem. Thank you.
-
Hi ALL i have a BDC code it is not working properly
this BDC code is not working properly , when ever the file is transfering BDC is aborting in the case of invalid material/batch comes into teh picture... so please could you ''Check for invalid material/batch combinations so they are not processed by the BDC in the program and correctly output in an exception report''
*****************************CODE HERE*****************************
S E L E C T I O N S C R E E N
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME.
PARAMETERS: p_file LIKE rlgrap-filename,
p_arch LIKE rlgrap-filename. "RM080107
SELECTION-SCREEN SKIP.
PARAMETERS: p_mode LIKE ctu_params-dismode DEFAULT 'N'.
SELECTION-SCREEN END OF BLOCK b1.
I N C L U D E S
INCLUDE zwm_np_stock_recon_top.
INCLUDE zwm_np_stock_recon_f01.
I N I T I A L I Z A T I O N
INITIALIZATION.
PERFORM get_interface_filename USING c_interface_file p_file.
PERFORM get_interface_filename USING c_archive_file p_arch."RM080107
S T A R T O F S E L E C T I O N
START-OF-SELECTION.
PERFORM read_file USING p_file.
PERFORM pre_processing.
E N D O F S E L E C T I O N
END-OF-SELECTION.
PERFORM process_checks.
IF w_no_change = 'X'.
WRITE: / text-b03.
WRITE: / sy-uline(34).
ELSE.
PERFORM bdc_mi09.
PERFORM file_check_report.
PERFORM bdc_report.
ENDIF.
PERFORM post_process_checks.
*-- Move the processed file to archive directory
PERFORM move_file.
...*************.........first include...................************
INCLUDE ZWM_NP_STOCK_RECON_TOP *
Data declaration ----------------------------------------------
TYPES: st_rawdata(2000) TYPE c.
TYPES: BEGIN OF st_stck_cnt,
werks TYPE iseg-werks, "plant
lgort TYPE iseg-lgort, "storage location
matnr TYPE iseg-matnr, "material number
charg TYPE iseg-charg, "batch
vfdat TYPE mch1-vfdat, "Sell by date
lwedt TYPE mch1-lwedt, "Manufacture date
quarn(8) TYPE n, "qaunrantine quantity
menge(8) TYPE n, "quantity on hand
message(1), "Message Type (E/W/I)
msg_txt TYPE t100-text, "Message Text
zerostck(1), "Zero stock identifier "RM220307
END OF st_stck_cnt.
TYPES: BEGIN OF st_batch_errors,
matnr TYPE iseg-matnr, "material number
charg TYPE iseg-charg, "batch
clabs TYPE mchb-clabs, "Stock Balance
END OF st_batch_errors.
DATA:
t_rawdata TYPE TABLE OF st_rawdata,
w_rawdata TYPE st_rawdata,
t_stck_cnt TYPE TABLE OF st_stck_cnt,
d_stck_cnt TYPE TABLE OF st_stck_cnt, "RM191006
w_stck_cnt TYPE st_stck_cnt,
t_batch_errors TYPE TABLE OF st_batch_errors,
w_batch_errors TYPE st_batch_errors,
t_messtab LIKE bdcmsgcoll OCCURS 0,
w_messtab LIKE LINE OF t_messtab,
w_no_change.
CONSTANTS: c_interface_file(26) TYPE c VALUE 'ZNP_STOCK_RECON',
c_archive_file(26) TYPE c
VALUE 'ZNP_STOCK_RECON_ARCHIVE'. "RM080107
.*************................second include..........************
***INCLUDE ZWM_NEXTPHARMA_STOKRECON_F01 .
*& Form read_file
reads NextPharma file sent through via webmethods
-->P_FILENAME
FORM read_file USING p_filename.
CLEAR: t_rawdata,
w_rawdata.
REFRESH: t_rawdata.
OPEN DATASET p_filename FOR INPUT IN TEXT MODE.
IF sy-subrc <> 0.
MESSAGE e720(01).
ENDIF.
DO.
READ DATASET p_filename INTO w_rawdata.
IF sy-subrc <> 0.
EXIT.
ELSE.
APPEND w_rawdata TO t_rawdata.
ENDIF.
ENDDO.
CLOSE DATASET p_filename.
ENDFORM. " read_file
*& Form pre_processing
Read file values into internal table
FORM pre_processing.
DATA: lw_matnr TYPE iseg-matnr.
LOOP AT t_rawdata INTO w_rawdata.
lw_matnr = w_rawdata+21(20). "RM031006
lw_matnr = w_rawdata+22(18). "RM031006
CALL FUNCTION 'CONVERSION_EXIT_MATN1_INPUT'
EXPORTING
input = lw_matnr
IMPORTING
output = lw_matnr
EXCEPTIONS
length_error = 1
OTHERS = 2.
MOVE: lw_matnr TO w_stck_cnt-matnr.
w_stck_cnt-werks = w_rawdata+14(4).
w_stck_cnt-lgort = w_rawdata+18(4).
w_stck_cnt-charg = w_rawdata+84(25).
w_stck_cnt-vfdat = w_rawdata+109(8).
w_stck_cnt-lwedt = w_rawdata+117(8).
w_stck_cnt-quarn = w_rawdata+141(8).
w_stck_cnt-menge = w_rawdata+125(8).
APPEND w_stck_cnt TO t_stck_cnt.
CLEAR w_stck_cnt.
ENDLOOP.
SORT t_stck_cnt BY werks
lgort
matnr
charg.
DELETE ADJACENT DUPLICATES FROM t_stck_cnt.
ENDFORM. " pre_processing
*& Form bdc_mi09
Run file data via BDC TCODE: MI09
FORM bdc_mi09.
DATA: t_bdcdata TYPE TABLE OF bdcdata,
w_bdcdata TYPE bdcdata,
lw_datum(10) TYPE c,
lw_count(2) TYPE n.
WRITE sy-datum TO lw_datum DD/MM/YYYY.
Front Screen
CLEAR w_bdcdata.
w_bdcdata-program = 'SAPMM07I'.
w_bdcdata-dynpro = '0700'.
w_bdcdata-dynbegin = 'X'.
APPEND w_bdcdata TO t_bdcdata.
Enter
CLEAR w_bdcdata.
w_bdcdata-fnam = 'BDC_OKCODE'.
w_bdcdata-fval = '/00'.
APPEND w_bdcdata TO t_bdcdata.
Count Date
CLEAR w_bdcdata.
w_bdcdata-fnam = 'RM07I-ZLDAT'.
w_bdcdata-fval = lw_datum.
APPEND w_bdcdata TO t_bdcdata.
Document Date
CLEAR w_bdcdata.
w_bdcdata-fnam = 'RM07I-BLDAT'.
w_bdcdata-fval = lw_datum.
APPEND w_bdcdata TO t_bdcdata.
Plant
CLEAR w_bdcdata.
w_bdcdata-fnam = 'IKPF-WERKS'.
w_bdcdata-fval = w_stck_cnt-werks.
APPEND w_bdcdata TO t_bdcdata.
Storage Location
CLEAR w_bdcdata.
w_bdcdata-fnam = 'IKPF-LGORT'.
w_bdcdata-fval = w_stck_cnt-lgort.
APPEND w_bdcdata TO t_bdcdata.
LOOP AT t_stck_cnt INTO w_stck_cnt.
Do not submit items with Errors against them
CHECK w_stck_cnt-message NE 'E' AND
w_stck_cnt-zerostck NE 'X'.
"RM220307
lw_count = lw_count + 1.
Input Screen
CLEAR w_bdcdata.
w_bdcdata-program = 'SAPMM07I'.
w_bdcdata-dynpro = '0731'.
w_bdcdata-dynbegin = 'X'.
APPEND w_bdcdata TO t_bdcdata.
Page Down
CLEAR w_bdcdata.
w_bdcdata-fnam = 'BDC_OKCODE'.
w_bdcdata-fval = '=P+'.
APPEND w_bdcdata TO t_bdcdata.
Material
CLEAR w_bdcdata.
w_bdcdata-fnam = 'ISEG-MATNR(01)'.
w_bdcdata-fval = w_stck_cnt-matnr.
APPEND w_bdcdata TO t_bdcdata.
Batch
CLEAR w_bdcdata.
w_bdcdata-fnam = 'ISEG-CHARG(01)'.
w_bdcdata-fval = w_stck_cnt-charg.
APPEND w_bdcdata TO t_bdcdata.
IF w_stck_cnt-menge NE 0.
Quantity
CLEAR w_bdcdata.
w_bdcdata-fnam = 'ISEG-ERFMG(01)'.
w_bdcdata-fval = w_stck_cnt-menge.
APPEND w_bdcdata TO t_bdcdata.
*-- Begin RM220307 - We need to create an item when the quantity is zero
*-- in file and is non-zero in SAP
ELSE.
Zero Stock indicator
CLEAR w_bdcdata.
w_bdcdata-fnam = 'ISEG-XNULL(01)'.
w_bdcdata-fval = 'X'.
APPEND w_bdcdata TO t_bdcdata.
*-- End RM220307
ENDIF.
ENDLOOP.
CHECK lw_count NE 0.
After all line items have been input
Final Screen
CLEAR w_bdcdata.
w_bdcdata-program = 'SAPMM07I'.
w_bdcdata-dynpro = '0731'.
w_bdcdata-dynbegin = 'X'.
APPEND w_bdcdata TO t_bdcdata.
Save Document
CLEAR w_bdcdata.
w_bdcdata-fnam = 'BDC_OKCODE'.
w_bdcdata-fval = '=BU'.
APPEND w_bdcdata TO t_bdcdata.
CALL TRANSACTION 'MI09' USING t_bdcdata
MODE p_mode
MESSAGES INTO t_messtab.
ENDFORM. " bdc_mi09
*& Form bdc_report
Write BDC Messages.
FORM bdc_report.
DATA: lw_text TYPE t100-text.
SKIP.
WRITE: / text-b01.
WRITE: / sy-uline(21).
SKIP.
Write BDC Messages
LOOP AT t_messtab INTO w_messtab WHERE msgspra = sy-langu.
MESSAGE ID w_messtab-msgid TYPE w_messtab-msgtyp
NUMBER w_messtab-msgnr
WITH w_messtab-msgv1
w_messtab-msgv2
w_messtab-msgv3
w_messtab-msgv4
INTO lw_text.
WRITE: / lw_text.
ENDLOOP.
ENDFORM. " bdc_report
*& Form process_checks
Perform process check before creating BDC Session
FORM process_checks.
DATA: lw_clabs LIKE mchb-clabs,
lw_menge LIKE mchb-clabs,
lw_matnr LIKE mara-matnr,
lw_charg LIKE mch1-charg,
lw_fail,
lw_vfdat TYPE mch1-vfdat,
lv_sell TYPE c, "RM191006
lv_qty(8) TYPE c. "RM191006
CLEAR: d_stck_cnt[], d_stck_cnt. "RM191006
Check if any of the stock figures differ from current stock figures
LOOP AT t_stck_cnt INTO w_stck_cnt.
lw_menge = w_stck_cnt-menge.
SELECT SINGLE clabs INTO lw_clabs
FROM mchb
WHERE matnr = w_stck_cnt-matnr
AND werks = w_stck_cnt-werks
AND lgort = w_stck_cnt-lgort
AND charg = w_stck_cnt-charg.
IF sy-subrc = 0.
IF lw_clabs NE lw_menge.
lw_fail = 'X'.
*-- Begin RM220307 - Do not create PI item if the stock is zero in the
*-- file and is zero in SAP
EXIT.
ELSEIF lw_clabs = 0 AND lw_menge = 0.
w_stck_cnt-zerostck = 'X'.
MODIFY t_stck_cnt FROM w_stck_cnt.
ENDIF.
*-- End RM220307
ELSE.
lw_fail = 'X'.
ERROR
ENDIF.
ENDLOOP.
If no differences are found set NO CHANGE Flag
IF lw_fail NE 'X'.
w_no_change = 'X'.
EXIT.
ENDIF.
Check for Errors in file data
LOOP AT t_stck_cnt INTO w_stck_cnt.
CLEAR lv_sell. "RM191006
SELECT SINGLE matnr INTO lw_matnr
FROM mara
WHERE matnr = w_stck_cnt-matnr.
IF sy-subrc NE 0.
Invalid Material (E)
w_stck_cnt-message = 'E'.
w_stck_cnt-msg_txt = 'Invalid Material'.
MODIFY t_stck_cnt FROM w_stck_cnt.
CONTINUE.
ENDIF.
SELECT SINGLE charg vfdat
INTO (lw_charg, lw_vfdat)
FROM mch1 "KOB01 - changed from MCHA
WHERE matnr = w_stck_cnt-matnr
AND charg = w_stck_cnt-charg.
AND werks = w_stck_cnt-werks.
IF sy-subrc NE 0.
Invalid Material Batch (E)
w_stck_cnt-message = 'E'.
CONCATENATE 'Invalid Material Batch for plant' w_stck_cnt-werks
INTO w_stck_cnt-msg_txt SEPARATED BY space.
MODIFY t_stck_cnt FROM w_stck_cnt.
CONTINUE.
ELSE.
IF w_stck_cnt-vfdat <> lw_vfdat.
Sell by dates do not match (W)
w_stck_cnt-message = 'W'.
w_stck_cnt-msg_txt =
'Sell by Date does not match Shelf life Expiry Date'.
MODIFY t_stck_cnt FROM w_stck_cnt.
lv_sell = 'X'. "RM191006
CONTINUE. "RM191006
ENDIF.
ENDIF.
IF w_stck_cnt-quarn > 0.
Quarantine balance not Zero (W)
w_stck_cnt-message = 'W'.
*-- Begin RM191006
*-- We do want all warning messages on the report
lv_qty = w_stck_cnt-quarn.
CONDENSE lv_qty NO-GAPS.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT'
EXPORTING
input = lv_qty
IMPORTING
output = lv_qty.
w_stck_cnt-msg_txt = 'Quarantine balance is not zero'.
CONCATENATE 'Quarantine balance is ' lv_qty '- not zero'
INTO w_stck_cnt-msg_txt SEPARATED BY space.
MODIFY t_stck_cnt FROM w_stck_cnt.
CONTINUE.
IF lv_sell = 'X'.
APPEND w_stck_cnt TO d_stck_cnt.
CLEAR lv_sell.
ELSE.
MODIFY t_stck_cnt FROM w_stck_cnt.
ENDIF.
*-- End RM191006
ENDIF.
ENDLOOP.
*-- Begin RM191006
*-- Finally get all the records into dummy table to report
APPEND LINES OF t_stck_cnt TO d_stck_cnt.
SORT d_stck_cnt.
DELETE ADJACENT DUPLICATES FROM d_stck_cnt.
*-- End RM191006
ENDFORM. " process_checks
*& Form file_check_report
Write warning and Error messages from File checks
FORM file_check_report.
WRITE: /2 'Material',
22 'Batch',
32 'Sell By',
45 'Message Text'.
WRITE: /2 sy-uline(115).
SKIP.
LOOP AT t_stck_cnt INTO w_stck_cnt. "RM191006
LOOP AT d_stck_cnt INTO w_stck_cnt. "RM191006
CHECK w_stck_cnt-message NE ' '.
WRITE: /2 w_stck_cnt-matnr,
22 w_stck_cnt-charg,
32 w_stck_cnt-vfdat,
43 w_stck_cnt-message,
45 w_stck_cnt-msg_txt.
ENDLOOP.
ENDFORM. " file_check_report
*& Form post_process_checks
Check Material Batches in SAP against NP File
FORM post_process_checks.
RANGES: r_matnr FOR mchb-matnr,
r_lgort FOR mchb-lgort,
r_werks FOR mchb-werks.
SORT t_stck_cnt.
LOOP AT t_stck_cnt INTO w_stck_cnt.
AT END OF matnr.
r_lgort-sign = 'I'.
r_lgort-option = 'EQ'.
r_lgort-low = w_stck_cnt-lgort.
APPEND r_lgort.
r_werks-sign = 'I'.
r_werks-option = 'EQ'.
r_werks-low = w_stck_cnt-werks.
APPEND r_werks.
r_matnr-sign = 'I'.
r_matnr-option = 'EQ'.
r_matnr-low = w_stck_cnt-matnr.
APPEND r_matnr.
ENDAT.
ENDLOOP.
Select all material batches for NP Materials
SELECT matnr charg clabs
INTO TABLE t_batch_errors
FROM mchb
WHERE werks IN r_werks
AND lgort IN r_lgort.
IF sy-subrc EQ 0.
Check if the Material Batches are in the NP file
LOOP AT t_batch_errors INTO w_batch_errors.
Disregard Batches without positive unrestricted stock
IF w_batch_errors-clabs LE 0.
DELETE t_batch_errors.
CONTINUE.
ENDIF.
READ TABLE t_stck_cnt INTO w_stck_cnt
WITH KEY matnr = w_batch_errors-matnr
charg = w_batch_errors-charg.
IF sy-subrc = 0.
DELETE t_batch_errors.
ENDIF.
ENDLOOP.
ENDIF.
CHECK NOT t_batch_errors[] IS INITIAL.
Write Batch chak results to report
SKIP.
WRITE: / text-b02.
WRITE: / sy-uline(74).
WRITE: /2 'Material',
22 'Batch'.
WRITE: /2 sy-uline(32).
SKIP.
LOOP AT t_batch_errors INTO w_batch_errors.
WRITE: /2 w_batch_errors-matnr,
22 w_batch_errors-charg.
ENDLOOP.
ENDFORM. " post_process_checks
G E T _ I N T E R F A C E _ F I L E N A M E
FORM get_interface_filename USING filename lw_path.
DATA: i_file TYPE filename-fileintern,
out_filename LIKE v_path-pathextern.
CLEAR: out_filename.
i_file = filename.
get the interface filename to be used when creating file
CALL FUNCTION 'FILE_GET_NAME'
EXPORTING
logical_filename = i_file
IMPORTING
file_name = out_filename
EXCEPTIONS
file_not_found = 1
OTHERS = 2.
IF sy-subrc = 0.
MOVE out_filename TO lw_path.
IF filename NE c_archive_file. "RM080107
CONCATENATE lw_path 'NP_StockBalance.dat'
INTO lw_path.
*-- Begin RM080107 - Add timestamp to the archived file
ELSE.
CONCATENATE lw_path 'NP_StockBalance' sy-datum sy-uzeit '.dat'
INTO lw_path.
ENDIF.
*-- End RM080107
ELSE.
ENDIF.
ENDFORM. "get_interface_filename
*& Form move_file RM080107
Move the processed file to archive directory
FORM move_file.
*-- At last move the file to archive directory
OPEN DATASET p_arch FOR OUTPUT IN TEXT MODE.
IF sy-subrc = 0.
LOOP AT t_rawdata INTO w_rawdata.
TRANSFER w_rawdata TO p_arch.
ENDLOOP.
ENDIF.
CLOSE DATASET p_arch.
DELETE DATASET p_file.
ENDFORM. " move_fileHi,
S E L E C T I O N S C R E E N
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME.
PARAMETERS: p_file LIKE rlgrap-filename,
p_arch LIKE rlgrap-filename. "RM080107
SELECTION-SCREEN SKIP.
PARAMETERS: p_mode LIKE ctu_params-dismode DEFAULT 'N'.
SELECTION-SCREEN END OF BLOCK b1.
I N C L U D E S
INCLUDE zwm_np_stock_recon_top.
INCLUDE zwm_np_stock_recon_f01.
I N I T I A L I Z A T I O N
INITIALIZATION.
PERFORM get_interface_filename USING c_interface_file p_file.
PERFORM get_interface_filename USING c_archive_file p_arch."RM080107
S T A R T O F S E L E C T I O N
START-OF-SELECTION.
PERFORM read_file USING p_file.
PERFORM pre_processing.
E N D O F S E L E C T I O N
END-OF-SELECTION.
PERFORM process_checks.
IF w_no_change = 'X'.
WRITE: / text-b03.
WRITE: / sy-uline(34).
ELSE.
PERFORM bdc_mi09.
PERFORM file_check_report.
PERFORM bdc_report.
ENDIF.
PERFORM post_process_checks.
*-- Move the processed file to archive directory
PERFORM move_file.
...*************.........first include...................************
INCLUDE ZWM_NP_STOCK_RECON_TOP *
Data declaration ----------------------------------------------
TYPES: st_rawdata(2000) TYPE c.
TYPES: BEGIN OF st_stck_cnt,
werks TYPE iseg-werks, "plant
lgort TYPE iseg-lgort, "storage location
matnr TYPE iseg-matnr, "material number
charg TYPE iseg-charg, "batch
vfdat TYPE mch1-vfdat, "Sell by date
lwedt TYPE mch1-lwedt, "Manufacture date
quarn(8) TYPE n, "qaunrantine quantity
menge(8) TYPE n, "quantity on hand
message(1), "Message Type (E/W/I)
msg_txt TYPE t100-text, "Message Text
zerostck(1), "Zero stock identifier "RM220307
END OF st_stck_cnt.
TYPES: BEGIN OF st_batch_errors,
matnr TYPE iseg-matnr, "material number
charg TYPE iseg-charg, "batch
clabs TYPE mchb-clabs, "Stock Balance
END OF st_batch_errors.
DATA:
t_rawdata TYPE TABLE OF st_rawdata,
w_rawdata TYPE st_rawdata,
t_stck_cnt TYPE TABLE OF st_stck_cnt,
d_stck_cnt TYPE TABLE OF st_stck_cnt, "RM191006
w_stck_cnt TYPE st_stck_cnt,
t_batch_errors TYPE TABLE OF st_batch_errors,
w_batch_errors TYPE st_batch_errors,
t_messtab LIKE bdcmsgcoll OCCURS 0,
w_messtab LIKE LINE OF t_messtab,
w_no_change.
CONSTANTS: c_interface_file(26) TYPE c VALUE 'ZNP_STOCK_RECON',
c_archive_file(26) TYPE c
VALUE 'ZNP_STOCK_RECON_ARCHIVE'. "RM080107
.*************................second include..........************
***INCLUDE ZWM_NEXTPHARMA_STOKRECON_F01 .
*& Form read_file
reads NextPharma file sent through via webmethods
-->P_FILENAME
FORM read_file USING p_filename.
CLEAR: t_rawdata,
w_rawdata.
REFRESH: t_rawdata.
OPEN DATASET p_filename FOR INPUT IN TEXT MODE.
IF sy-subrc <> 0.
MESSAGE e720(01).
ENDIF.
DO.
READ DATASET p_filename INTO w_rawdata.
IF sy-subrc <> 0.
EXIT.
ELSE.
APPEND w_rawdata TO t_rawdata.
ENDIF.
ENDDO.
CLOSE DATASET p_filename.
ENDFORM. " read_file
*& Form pre_processing
Read file values into internal table
FORM pre_processing.
DATA: lw_matnr TYPE iseg-matnr.
LOOP AT t_rawdata INTO w_rawdata.
lw_matnr = w_rawdata+21(20). "RM031006
lw_matnr = w_rawdata+22(18). "RM031006
CALL FUNCTION 'CONVERSION_EXIT_MATN1_INPUT'
EXPORTING
input = lw_matnr
IMPORTING
output = lw_matnr
EXCEPTIONS
length_error = 1
OTHERS = 2.
MOVE: lw_matnr TO w_stck_cnt-matnr.
w_stck_cnt-werks = w_rawdata+14(4).
w_stck_cnt-lgort = w_rawdata+18(4).
w_stck_cnt-charg = w_rawdata+84(25).
w_stck_cnt-vfdat = w_rawdata+109(8).
w_stck_cnt-lwedt = w_rawdata+117(8).
w_stck_cnt-quarn = w_rawdata+141(8).
w_stck_cnt-menge = w_rawdata+125(8).
APPEND w_stck_cnt TO t_stck_cnt.
CLEAR w_stck_cnt.
ENDLOOP.
SORT t_stck_cnt BY werks
lgort
matnr
charg.
DELETE ADJACENT DUPLICATES FROM t_stck_cnt.
ENDFORM. " pre_processing
*& Form bdc_mi09
Run file data via BDC TCODE: MI09
FORM bdc_mi09.
DATA: t_bdcdata TYPE TABLE OF bdcdata,
w_bdcdata TYPE bdcdata,
lw_datum(10) TYPE c,
lw_count(2) TYPE n.
WRITE sy-datum TO lw_datum DD/MM/YYYY.
<b>select single MATNR
WERKS
CHARG
from MCHA
into (l_matnr, l_werks, l_charg)
where matnr = w_stck_cnt-matnr
and werks = w_stck_cnt-werks.
and charg = w_stck_cnt-charg.
if sy-subrc ne 0.
continue.
endif.</b>
Front Screen
CLEAR w_bdcdata.
w_bdcdata-program = 'SAPMM07I'.
w_bdcdata-dynpro = '0700'.
w_bdcdata-dynbegin = 'X'.
APPEND w_bdcdata TO t_bdcdata.
Enter
CLEAR w_bdcdata.
w_bdcdata-fnam = 'BDC_OKCODE'.
w_bdcdata-fval = '/00'.
APPEND w_bdcdata TO t_bdcdata.
Count Date
CLEAR w_bdcdata.
w_bdcdata-fnam = 'RM07I-ZLDAT'.
w_bdcdata-fval = lw_datum.
APPEND w_bdcdata TO t_bdcdata.
Document Date
CLEAR w_bdcdata.
w_bdcdata-fnam = 'RM07I-BLDAT'.
w_bdcdata-fval = lw_datum.
APPEND w_bdcdata TO t_bdcdata.
Plant
CLEAR w_bdcdata.
w_bdcdata-fnam = 'IKPF-WERKS'.
w_bdcdata-fval = w_stck_cnt-werks.
APPEND w_bdcdata TO t_bdcdata.
Storage Location
CLEAR w_bdcdata.
w_bdcdata-fnam = 'IKPF-LGORT'.
w_bdcdata-fval = w_stck_cnt-lgort.
APPEND w_bdcdata TO t_bdcdata.
LOOP AT t_stck_cnt INTO w_stck_cnt.
Do not submit items with Errors against them
CHECK w_stck_cnt-message NE 'E' AND
w_stck_cnt-zerostck NE 'X'.
"RM220307
lw_count = lw_count + 1.
Input Screen
CLEAR w_bdcdata.
w_bdcdata-program = 'SAPMM07I'.
w_bdcdata-dynpro = '0731'.
w_bdcdata-dynbegin = 'X'.
APPEND w_bdcdata TO t_bdcdata.
Page Down
CLEAR w_bdcdata.
w_bdcdata-fnam = 'BDC_OKCODE'.
w_bdcdata-fval = '=P+'.
APPEND w_bdcdata TO t_bdcdata.
Material
CLEAR w_bdcdata.
w_bdcdata-fnam = 'ISEG-MATNR(01)'.
w_bdcdata-fval = w_stck_cnt-matnr.
APPEND w_bdcdata TO t_bdcdata.
Batch
CLEAR w_bdcdata.
w_bdcdata-fnam = 'ISEG-CHARG(01)'.
w_bdcdata-fval = w_stck_cnt-charg.
APPEND w_bdcdata TO t_bdcdata.
IF w_stck_cnt-menge NE 0.
Quantity
CLEAR w_bdcdata.
w_bdcdata-fnam = 'ISEG-ERFMG(01)'.
w_bdcdata-fval = w_stck_cnt-menge.
APPEND w_bdcdata TO t_bdcdata.
*-- Begin RM220307 - We need to create an item when the quantity is zero
*-- in file and is non-zero in SAP
ELSE.
Zero Stock indicator
CLEAR w_bdcdata.
w_bdcdata-fnam = 'ISEG-XNULL(01)'.
w_bdcdata-fval = 'X'.
APPEND w_bdcdata TO t_bdcdata.
*-- End RM220307
ENDIF.
ENDLOOP.
CHECK lw_count NE 0.
After all line items have been input
Final Screen
CLEAR w_bdcdata.
w_bdcdata-program = 'SAPMM07I'.
w_bdcdata-dynpro = '0731'.
w_bdcdata-dynbegin = 'X'.
APPEND w_bdcdata TO t_bdcdata.
Save Document
CLEAR w_bdcdata.
w_bdcdata-fnam = 'BDC_OKCODE'.
w_bdcdata-fval = '=BU'.
APPEND w_bdcdata TO t_bdcdata.
CALL TRANSACTION 'MI09' USING t_bdcdata
MODE p_mode
MESSAGES INTO t_messtab.
ENDFORM. " bdc_mi09
*& Form bdc_report
Write BDC Messages.
FORM bdc_report.
DATA: lw_text TYPE t100-text.
SKIP.
WRITE: / text-b01.
WRITE: / sy-uline(21).
SKIP.
Write BDC Messages
LOOP AT t_messtab INTO w_messtab WHERE msgspra = sy-langu.
MESSAGE ID w_messtab-msgid TYPE w_messtab-msgtyp
NUMBER w_messtab-msgnr
WITH w_messtab-msgv1
w_messtab-msgv2
w_messtab-msgv3
w_messtab-msgv4
INTO lw_text.
WRITE: / lw_text.
ENDLOOP.
ENDFORM. " bdc_report
*& Form process_checks
Perform process check before creating BDC Session
FORM process_checks.
DATA: lw_clabs LIKE mchb-clabs,
lw_menge LIKE mchb-clabs,
lw_matnr LIKE mara-matnr,
lw_charg LIKE mch1-charg,
lw_fail,
lw_vfdat TYPE mch1-vfdat,
lv_sell TYPE c, "RM191006
lv_qty(8) TYPE c. "RM191006
CLEAR: d_stck_cnt[], d_stck_cnt. "RM191006
Check if any of the stock figures differ from current stock figures
LOOP AT t_stck_cnt INTO w_stck_cnt.
lw_menge = w_stck_cnt-menge.
SELECT SINGLE clabs INTO lw_clabs
FROM mchb
WHERE matnr = w_stck_cnt-matnr
AND werks = w_stck_cnt-werks
AND lgort = w_stck_cnt-lgort
AND charg = w_stck_cnt-charg.
IF sy-subrc = 0.
IF lw_clabs NE lw_menge.
lw_fail = 'X'.
*-- Begin RM220307 - Do not create PI item if the stock is zero in the
*-- file and is zero in SAP
EXIT.
ELSEIF lw_clabs = 0 AND lw_menge = 0.
w_stck_cnt-zerostck = 'X'.
MODIFY t_stck_cnt FROM w_stck_cnt.
ENDIF.
*-- End RM220307
ELSE.
lw_fail = 'X'.
ERROR
ENDIF.
ENDLOOP.
If no differences are found set NO CHANGE Flag
IF lw_fail NE 'X'.
w_no_change = 'X'.
EXIT.
ENDIF.
Check for Errors in file data
LOOP AT t_stck_cnt INTO w_stck_cnt.
CLEAR lv_sell. "RM191006
SELECT SINGLE matnr INTO lw_matnr
FROM mara
WHERE matnr = w_stck_cnt-matnr.
IF sy-subrc NE 0.
Invalid Material (E)
w_stck_cnt-message = 'E'.
w_stck_cnt-msg_txt = 'Invalid Material'.
MODIFY t_stck_cnt FROM w_stck_cnt.
CONTINUE.
ENDIF.
SELECT SINGLE charg vfdat
INTO (lw_charg, lw_vfdat)
FROM mch1 "KOB01 - changed from MCHA
WHERE matnr = w_stck_cnt-matnr
AND charg = w_stck_cnt-charg.
AND werks = w_stck_cnt-werks.
IF sy-subrc NE 0.
Invalid Material Batch (E)
w_stck_cnt-message = 'E'.
CONCATENATE 'Invalid Material Batch for plant' w_stck_cnt-werks
INTO w_stck_cnt-msg_txt SEPARATED BY space.
MODIFY t_stck_cnt FROM w_stck_cnt.
CONTINUE.
ELSE.
IF w_stck_cnt-vfdat <> lw_vfdat.
Sell by dates do not match (W)
w_stck_cnt-message = 'W'.
w_stck_cnt-msg_txt =
'Sell by Date does not match Shelf life Expiry Date'.
MODIFY t_stck_cnt FROM w_stck_cnt.
lv_sell = 'X'. "RM191006
CONTINUE. "RM191006
ENDIF.
ENDIF.
IF w_stck_cnt-quarn > 0.
Quarantine balance not Zero (W)
w_stck_cnt-message = 'W'.
*-- Begin RM191006
*-- We do want all warning messages on the report
lv_qty = w_stck_cnt-quarn.
CONDENSE lv_qty NO-GAPS.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT'
EXPORTING
input = lv_qty
IMPORTING
output = lv_qty.
w_stck_cnt-msg_txt = 'Quarantine balance is not zero'.
CONCATENATE 'Quarantine balance is ' lv_qty '- not zero'
INTO w_stck_cnt-msg_txt SEPARATED BY space.
MODIFY t_stck_cnt FROM w_stck_cnt.
CONTINUE.
IF lv_sell = 'X'.
APPEND w_stck_cnt TO d_stck_cnt.
CLEAR lv_sell.
ELSE.
MODIFY t_stck_cnt FROM w_stck_cnt.
ENDIF.
*-- End RM191006
ENDIF.
ENDLOOP.
*-- Begin RM191006
*-- Finally get all the records into dummy table to report
APPEND LINES OF t_stck_cnt TO d_stck_cnt.
SORT d_stck_cnt.
DELETE ADJACENT DUPLICATES FROM d_stck_cnt.
*-- End RM191006
ENDFORM. " process_checks
*& Form file_check_report
Write warning and Error messages from File checks
FORM file_check_report.
WRITE: /2 'Material',
22 'Batch',
32 'Sell By',
45 'Message Text'.
WRITE: /2 sy-uline(115).
SKIP.
LOOP AT t_stck_cnt INTO w_stck_cnt. "RM191006
LOOP AT d_stck_cnt INTO w_stck_cnt. "RM191006
CHECK w_stck_cnt-message NE ' '.
WRITE: /2 w_stck_cnt-matnr,
22 w_stck_cnt-charg,
32 w_stck_cnt-vfdat,
43 w_stck_cnt-message,
45 w_stck_cnt-msg_txt.
ENDLOOP.
ENDFORM. " file_check_report
*& Form post_process_checks
Check Material Batches in SAP against NP File
FORM post_process_checks.
RANGES: r_matnr FOR mchb-matnr,
r_lgort FOR mchb-lgort,
r_werks FOR mchb-werks.
SORT t_stck_cnt.
LOOP AT t_stck_cnt INTO w_stck_cnt.
AT END OF matnr.
r_lgort-sign = 'I'.
r_lgort-option = 'EQ'.
r_lgort-low = w_stck_cnt-lgort.
APPEND r_lgort.
r_werks-sign = 'I'.
r_werks-option = 'EQ'.
r_werks-low = w_stck_cnt-werks.
APPEND r_werks.
r_matnr-sign = 'I'.
r_matnr-option = 'EQ'.
r_matnr-low = w_stck_cnt-matnr.
APPEND r_matnr.
ENDAT.
ENDLOOP.
Select all material batches for NP Materials
SELECT matnr charg clabs
INTO TABLE t_batch_errors
FROM mchb
WHERE werks IN r_werks
AND lgort IN r_lgort.
IF sy-subrc EQ 0.
Check if the Material Batches are in the NP file
LOOP AT t_batch_errors INTO w_batch_errors.
Disregard Batches without positive unrestricted stock
IF w_batch_errors-clabs LE 0.
DELETE t_batch_errors.
CONTINUE.
ENDIF.
READ TABLE t_stck_cnt INTO w_stck_cnt
WITH KEY matnr = w_batch_errors-matnr
charg = w_batch_errors-charg.
IF sy-subrc = 0.
DELETE t_batch_errors.
ENDIF.
ENDLOOP.
ENDIF.
CHECK NOT t_batch_errors[] IS INITIAL.
Write Batch chak results to report
SKIP.
WRITE: / text-b02.
WRITE: / sy-uline(74).
WRITE: /2 'Material',
22 'Batch'.
WRITE: /2 sy-uline(32).
SKIP.
LOOP AT t_batch_errors INTO w_batch_errors.
WRITE: /2 w_batch_errors-matnr,
22 w_batch_errors-charg.
ENDLOOP.
ENDFORM. " post_process_checks
G E T _ I N T E R F A C E _ F I L E N A M E
FORM get_interface_filename USING filename lw_path.
DATA: i_file TYPE filename-fileintern,
out_filename LIKE v_path-pathextern.
CLEAR: out_filename.
i_file = filename.
get the interface filename to be used when creating file
CALL FUNCTION 'FILE_GET_NAME'
EXPORTING
logical_filename = i_file
IMPORTING
file_name = out_filename
EXCEPTIONS
file_not_found = 1
OTHERS = 2.
IF sy-subrc = 0.
MOVE out_filename TO lw_path.
IF filename NE c_archive_file. "RM080107
CONCATENATE lw_path 'NP_StockBalance.dat'
INTO lw_path.
*-- Begin RM080107 - Add timestamp to the archived file
ELSE.
CONCATENATE lw_path 'NP_StockBalance' sy-datum sy-uzeit '.dat'
INTO lw_path.
ENDIF.
*-- End RM080107
ELSE.
ENDIF.
ENDFORM. "get_interface_filename
*& Form move_file RM080107
Move the processed file to archive directory
FORM move_file.
*-- At last move the file to archive directory
OPEN DATASET p_arch FOR OUTPUT IN TEXT MODE.
IF sy-subrc = 0.
LOOP AT t_rawdata INTO w_rawdata.
TRANSFER w_rawdata TO p_arch.
ENDLOOP.
ENDIF.
CLOSE DATASET p_arch.
DELETE DATASET p_file.
ENDFORM. " move_file
Best regards,
Prashant -
Hello. I'm trying to develop a PO Price History Report for our compnay based on ME1P. This is the format I want my report to look something like this:
h5Material Code Mat.Description Vendor Code Vendor Descrip. Qty Price/ea PO Number Date
1111111111 abcaba 11111 abc abc abc 1 KWD 195 1010001002 21/05/2010
11111 abc abc abc 2 KWD 196 1010001003 21/04/2010
21111 bcd bcd bcd 1 KWD 195 1010001006 21/05/2010
Total Qty:
2222222222 xyz xyz 11111 abc abc abc 1 KWD 195 1010001002 21/05/2010
11111 abc abc abc 2 KWD 196 1010001003 21/04/2010
21111 bcd bcd bcd 1 KWD 195 1010001006 21/05/2010
Total Qty:
This is the coding I've done so far:
REPORT Z_MM_POHISTORY.
TABLES: EKPO, EKKO, LFA1, MAKT.
TYPES : BEGIN OF tw_ekpo.
INCLUDE STRUCTURE EKPO.
TYPES : END OF tw_ekpo.
types : BEGIN OF tw_ekko.
INCLUDE STRUCTURE EKKO.
types : END OF tw_ekko.
TYPES : BEGIN OF tw_LFA1.
INCLUDE STRUCTURE LFA1.
TYPES : END OF tw_LFA1.
types : BEGIN OF tw_MAKT.
INCLUDE STRUCTURE MAKT.
types : END OF tw_MAKT.
types : tt_ekpo type STANDARD TABLE OF tw_ekpo, tt_LFA1 type STANDARD TABLE OF tw_LFA1, tt_MAKT type STANDARD TABLE OF tw_MAKT,
tt_ekko type STANDARD TABLE OF tw_ekko.
data : lt_ekpo type tt_ekpo, t_LFA1 type tt_LFA1, t_MAKT type tt_MAKT,
lt_ekko type tt_ekko.
data : begin of lt_mix OCCURS 0,
bedat type ekko-bedat,
matnr type ekpo-matnr,
werks type ekpo-werks,
lgort type ekpo-lgort,
EBELN type ekpo-EBELN,
menge type ekpo-menge,
BUKRS type ekKO-BUKRS,
EKORG type ekKo-EKORG,
NETPR type ekPO-NETPR,
STATUS type ekpo-STATUS,
LIFNR type ekKo-LIFNR,
Name1 type LFA1-Name1,
MAKTX TYPE MAKT-MAKTX,
SPRAS TYPE MAKT-SPRAS,
end of lt_mix.
data : begin of lt_final OCCURS 0,
bedat type ekko-bedat,
matnr type ekpo-matnr,
werks type ekpo-werks,
lgort type ekpo-lgort,
EBELN type ekpo-EBELN,
menge type ekpo-menge,
BUKRS type ekKO-BUKRS,
EKORG type ekKo-EKORG,
NETPR type ekPO-NETPR,
STATUS type ekpo-STATUS,
LIFNR type ekKo-LIFNR,
Name1 type LFA1-Name1,
MAKTX TYPE MAKT-MAKTX,
SPRAS TYPE MAKT-SPRAS,
end of lt_final.
selection-SCREEN : BEGIN OF BLOCK blk01 WITH FRAME TITLE text-001.
select-options : P_ORG FOR EKKO-EKORG, C_CODE FOR EKKO-BUKRS OBLIGATORY, PLANT for ekpo-werks, MATNR for ekpo-matnr,
PDOC_NO FOR EKKO-EBELN, PDOCDATE FOR EKKO-BEDAT OBLIGATORY, STATUS FOR EKPO-STATUS, LANG FOR MAKT-SPRAS,
VENDOR for ekKO-LIFNR.
selection-SCREEN : end OF BLOCK blk01.
START-OF-SELECTION.
select a~bedat A~EKORG B~STATUS b~matnr b~werks b~lgort b~EBELN b~menge a~bukrs d~spras d~maktx a~lifnr c~name1 b~netpr
into CORRESPONDING FIELDS OF TABLE lt_mix
from EKPO as b INNER JOIN ekko as a on b~EBELN = a~EBELN
JOIN LFA1 AS c ON c~LIFNR = A~LIFNR
JOIN MAKT AS d ON d~MATNR = b~MATNR
WHERE
A~BUKRS IN C_CODE AND A~BEDAT IN PDOCDATE AND a~ebeln IN PDOC_NO AND D~SPRAS IN LANG AND b~matnr IN MATNR
SORT lt_mix by matnr LIFNR BEDAT ebeln.
loop at lt_mix.
lt_final = lt_mix.
AT END OF menge.
SUM.
append lt_final.
ENDAT.
ENDLOOP.
LOOP AT lt_final.
write: / lt_final-MATNR, lt_final-MAKTx, lt_final-LIFNR, lt_final-NAME1, lt_final-MENGE, lt_final-NETPR, lt_final-EBELN, lt_final-bedat.
at END OF matnr.
sum.
skip.
ULINE.
write: / 'Total qty', lt_final-menge, 'Total Price: ' , lt_final-netpr.
ULINE.
SKIP 2.
ENDAT.
ENDLOOP.
IF sy-subrc ne 0.
WRITE: 'No records found!'.
endif.
When I run the report, Materials with same PO date are grouped together but the same material with another date doesn't get added to that group.
I would really appreciate if anyone could help out.REPORT Z_MM_POHISTORY.
TABLES: EKPO, EKKO, LFA1, MAKT.
TYPES : BEGIN OF tw_ekpo.
INCLUDE STRUCTURE EKPO.
TYPES : END OF tw_ekpo.
types : BEGIN OF tw_ekko.
INCLUDE STRUCTURE EKKO.
types : END OF tw_ekko.
TYPES : BEGIN OF tw_LFA1.
INCLUDE STRUCTURE LFA1.
TYPES : END OF tw_LFA1.
types : BEGIN OF tw_MAKT.
INCLUDE STRUCTURE MAKT.
types : END OF tw_MAKT.
types : tt_ekpo type STANDARD TABLE OF tw_ekpo, tt_LFA1 type STANDARD TABLE OF tw_LFA1, tt_MAKT type STANDARD TABLE OF tw_MAKT,
tt_ekko type STANDARD TABLE OF tw_ekko.
data : lt_ekpo type tt_ekpo, t_LFA1 type tt_LFA1, t_MAKT type tt_MAKT,
lt_ekko type tt_ekko.
data : begin of lt_mix OCCURS 0,
matnr type ekpo-matnr,
bedat type ekko-bedat,
LIFNR type ekKo-LIFNR,
werks type ekpo-werks,
lgort type ekpo-lgort,
EBELN type ekpo-EBELN,
menge type ekpo-menge,
BUKRS type ekKO-BUKRS,
EKORG type ekKo-EKORG,
STATU type ekKo-STATU,
WAERS TYPE EKKO-WAERS,
BPRME TYPE EKPO-BPRME,
NETPR type ekPO-NETPR,
Name1 type LFA1-Name1,
MAKTX TYPE MAKT-MAKTX,
SPRAS TYPE MAKT-SPRAS,
end of lt_mix.
data : begin of lt_final OCCURS 0,
matnr type ekpo-matnr,
bedat type ekko-bedat,
LIFNR type ekKo-LIFNR,
werks type ekpo-werks,
lgort type ekpo-lgort,
EBELN type ekpo-EBELN,
menge type ekpo-menge,
BUKRS type ekKO-BUKRS,
EKORG type ekKo-EKORG,
STATU type ekKo-STATU,
WAERS TYPE EKKO-WAERS,
BPRME TYPE EKPO-BPRME,
NETPR type ekPO-NETPR,
Name1 type LFA1-Name1,
MAKTX TYPE MAKT-MAKTX,
SPRAS TYPE MAKT-SPRAS,
end of lt_final.
selection-SCREEN : BEGIN OF BLOCK blk01 WITH FRAME TITLE text-001.
select-options : P_ORG FOR EKKO-EKORG, C_CODE FOR EKKO-BUKRS OBLIGATORY, PLANT for ekpo-werks, MATNR for ekpo-matnr,
PDOC_NO FOR EKKO-EBELN, PDOCDATE FOR EKKO-BEDAT OBLIGATORY, LANG FOR MAKT-SPRAS, STATU FOR EKKO-STATU,
VENDOR for ekKO-LIFNR.
selection-SCREEN : end OF BLOCK blk01.
START-OF-SELECTION.
select a~bedat A~EKORG B~STATUS b~matnr b~werks b~lgort b~EBELN b~menge a~bukrs d~spras d~maktx a~lifnr c~name1 b~netpr a~waers B~BPRME
into CORRESPONDING FIELDS OF TABLE lt_mix
from EKPO as b INNER JOIN ekko as a on b~EBELN = a~EBELN
JOIN LFA1 AS c ON c~LIFNR = A~LIFNR
JOIN MAKT AS d ON d~MATNR = b~MATNR
WHERE
A~BUKRS IN C_CODE AND A~BEDAT IN PDOCDATE AND a~ebeln IN PDOC_NO AND D~SPRAS IN LANG AND b~matnr IN MATNR AND a~lifnr in vendoR
AND b~werks IN Plant AND a~ekorg IN P_Org AND A~STATU IN STATU
SORT lt_mix by matnr bedat ebeln lifnr.
loop at lt_mix.
lt_final = lt_mix.
AT END OF menge.
SUM.
append lt_final.
ENDAT.
ENDLOOP.
LOOP AT lt_final.
ON CHANGE OF LT_FINAL-MATNR.
WRITE: lt_final-matnr, LT_FINAL-MAKTX.
ENDON.
write: /60 lt_final-LIFNR, lt_final-NAME1, LT_FINAL-BPRME, lt_final-MENGE, LT_FINAL-WAERS, lt_final-NETPR, lt_final-EBELN, lt_final-bedat.
at END OF matnr.
sum.
ULINE.
write: /'Total qty', lt_final-menge, 'Total Price: ' , lt_final-netpr.
ULINE.
SKIP 2.
ENDAT.
ENDLOOP.
IF sy-subrc ne 0.
WRITE: 'No records found!'.
endif. -
Alv report on material document
hi to all thankds in advancee
can u pls give coding for the report following
created alv report to display materila document list per given receiving plant , receving storage location , and supplying plant , receving supplying storage location movemnt type and document date .
thanksHi,
Use another internal table to display output.
make changes in new table from previous table.
loop at itab.
at new <matnr>.
jtab = itab. " Copy all the fields from itab to jtab and append
append jtab.
continue.
endat.
ord_quan = ord_quan + count1.
ship_quan = ship_quan + count2.
at end of <matnr>.
itab-ord-quan = ord-quan.
itab-ship_quan = ship_quan.
itab-balance = itab-ord_quan - itab-ship_quan.
jtab = itab.
append jtab.
endat.
clear itab.
endloop.
Use this JTAB to print the output.
Regards,
Bhanu -
How to insert sales text (MM02) into a single record of a Ztable.
Hi,
I'm extracting data from different data base tables and populating a Ztable which has Matnr as primary key and sales text as a field.
I have already used READ_TEXT to display the text and it is displayed in multiple records which in turn leads to duplication of Material numbers.
Now I want to avoid duplication of records (Matnr) as this being a primary record, and display the sales text of a particular material number into one single record.
Can anyone tell me how to insert sales text (MM02) transaction into one single record.
Thanks,
Govindsorry i am not enough clear about your requirement...
as i can understand i am explaining to you.
suppose your itab contains repaeating matnr.
matnr
1
1
2
2
2
3
3
like this.
data : text(200),
matnr like mara-matnr.
loop at itab.
call READ_TEXT fnmodule.
loop at tline.
concatenate text tline-tdline into text.
endloop.
matnr = itab-matnr.
at end of matnr.
itab1-matnr = matnr.
itab1-text = text.
append itab1.
clear text.
endat.
endloop.
NB change the code as per your requirement
regards
shiba dutta
Maybe you are looking for
-
How do I find the serial number for a lost ipad?
My ipad's been stolen, and I need to find the sertial nunber to give to the Police. Unfortunately, I did not keep the original packaging, so cannot refer to that for the serial number. I have an itunes account....am I able to locate my serial number
-
Can I pass a parameter to a mapping without using a process flow?
I have to load data from multiple countries at different times. Rather than creating an individual mapping for each country, I want to create 1 mapping and pass the country code as a parameter to the mapping. I tried to use an input parameter in the
-
Bootcamp 64 bit for MacBook Pro 13" 2010?
When inserting my Snow Leo disk, it says 64 bit isn't supported for this device. There is however a 64 bit update for the same device in the downloads section of Apple.com, but I can't install that.
-
With the new download previous purchases on ITunes, you can download all of your music, TV Shows, etc. Why cant you download movies that you have downloaded? I had a external hard drive that crashed and it had approx 20 movies that I paid for and dow
-
Doubt on crystal report,webi
Hi All, First of all thank you verymuch for solving my earlier doubts. Can you pls answer the following as i am facing these questions while attending interviews. I would appreciate you all. 1) How can i use dynamic prompt in crystal reports likewise