‎2009 Jan 19 9:10 AM
hi,
how to get itemwise customer data??..
i had joined vbak and vbap tables and selected data for the entered item range..
later i used for all entries of (vbak and vbap joining) itab to fetch the data from kna1.
is it a correct way??.
thanks
Sri
‎2009 Jan 19 9:14 AM
‎2009 Jan 19 9:14 AM
Hi,
This looks good only. r u not getting the desired values what you are expecting ?
then let us know the problem.
Regards,
Venkatesh
‎2009 Jan 19 9:16 AM
Not a problem if you get dat afor all your customers based on your ITAB using
FOR ALL ENTRIES IN itab
WHERE kunnr = itab-kunnr...
Later on to fill your output tab you could READ this kna1_itab and fill details based on customer number..
‎2009 Jan 19 9:23 AM
hi,
this is the code i wrote actually,but i couldnt get output even if there are records in kna1 itab.
REPORT ZITEM_REPORT line-size 150.
&----
*& STRUCTURE DECLARATION
&----
types: begin of ty_sale, " Sales document header
vbeln type vbeln_va, " Sales document
posnr type posnr_va, " Sales document Item
netwr type netwr_ak, " Net value
kunnr type kunnr, " Customer Number
end of ty_sale,
begin of ty_kna1,
kunnr type kunnr, " Customer Number
land1 type land1_gp, " Country
name1 type name1_gp, " Customer Name
ort01 type ort01_gp, " City
pstlz type pstlz, " Postal Code
end of ty_kna1,
begin of ty_output, " Output Structure
posnr type posnr,va, " Sales document Item
netwr type netwr_ak, " Net value
kunnr type kunnr, " Customer Number
land1 type land1_gp, " Country
name1 type name1_gp, " Customer Name
ort01 type ort01_gp, " City
pstlz type pstlz, " Postal Code
end of ty_output.
&----
*& INTERNAL TABLE DECLARATION
&----
data: t_sale type standard table of ty_sale initial size 0,
t_kna1 type standard table of ty_kna1 initial size 0,
t_output type standard table of ty_output initial size 0,
&----
*& WORK AREA DECLARATION
&----
w_sale type ty_sale,
w_kna1 type ty_kna1,
w_output type ty_output,
&----
*& GLOBAL VARIABLE DECLARATION
&----
g_posnr type vbap-posnr.
&----
*& SELECTION-SCREEN DECLARATION
&----
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE t001.
SELECT-OPTIONS: s_posnr for g_posnr.
SELECTION-SCREEN END OF BLOCK B1.
&----
*& INITIALIZATION EVENT
&----
initialization.
clear: w_sale,
w_kna1,
w_output.
refresh: t_sale,
t_kna1,
t_output.
&----
*& AT SELECTION-SCREEN
&----
AT SELECTION-SCREEN.
perform sub_validate_posnr.
&----
*& START-OF-SELECTION EVENT
&----
start-of-selection.
Get sales document data
perform sub_get_saledata.
Get the Sold-to-party data
perform sub_get_kna1.
Get output data
perform sub_disp_output.
&----
*& Form SUB_VALIDATE_POSNR
&----
SUBROUTINE TO VALIDATE ITEM NUMBER
----
FORM SUB_VALIDATE_POSNR.
data: l_posnr type posnr_va.
SELECT SINGLE POSNR
FROM VBUP
INTO l_posnr
where posnr in s_posnr.
if sy-subrc <> 0.
message e001(zks) with 'Data not found for the given range' s_posnr.
endif.
ENDFORM. " SUB_VALIDATE_POSNR
&----
*& Form SUB_GET_SALEDATA
&----
Subroutine to get sales document data
----
FORM SUB_GET_SALEDATA .
SELECT A~VBELN
A~POSNR
B~NETWR
B~KUNNR
INTO TABLE T_SALE
FROM VBAP AS A INNER JOIN VBAK AS B
ON AVBELN = BVBELN
WHERE A~POSNR IN S_POSNR.
IF sy-subrc <> 0.
message e001(zks) with 'Data not selected in Sales tables' s_posnr.
endif.
ENDFORM. " SUB_GET_SALEDATA
&----
*& Form SUB_GET_KNA1
&----
SUBROUTINE TO FETCH SOLD-TO-PARTY DATA
----
FORM SUB_GET_KNA1 .
IF T_SALE IS NOT INITIAL.
select kunnr
land1
name1
ort01
pstlz
from kna1
into table t_kna1
for all entries in t_SALE
where kunnr = t_SALE-kunnr.
if sy-subrc <> 0.
message e001(zks) with 'Customer data not selected' s_posnr.
endif.
ENDIF.
ENDFORM. " SUB_GET_KNA1
&----
*& Form SUB_DISP_OUTPUT
&----
SUBROUTINE TO DISPLAY OUTPUT
----
FORM SUB_DISP_OUTPUT .
LOOP AT T_kna1 INTO W_kna1.
W_OUTPUT-KUNNR = W_kna1-KUNNR.
W_OUTPUT-LAND1 = W_KNA1-LAND1.
W_OUTPUT-NAME1 = W_KNA1-NAME1.
W_OUTPUT-ORT01 = W_KNA1-ORT01.
W_OUTPUT-PSTLZ = W_KNA1-PSTLZ.
CLEAR w_sale.
READ TABLE T_sale INTO W_sale WITH KEY = W_kna1-KUNNR.
IF SY-SUBRC = 0.
W_OUTPUT-POSNR = W_SALE-POSNR.
W_OUTPUT-NETWR = W_SALE-NETWR.
ENDIF.
COLLECT w_OUTPUT into t_output.
ENDLOOP.
SORT T_OUTPUT BY POSNR KUNNR.
clear w_output.
LOOP AT T_OUTPUT INTO W_OUTPUT.
write:/ w_output-posnr,20 w_output-netwr, 50 w_output-kunnr , 80 w_output-name1,
120 w_output-land1,130 w_output-pstlz.
ENDLOOP.
ENDFORM.
Edited by: Sri on Jan 19, 2009 10:51 AM
‎2009 Jan 19 9:29 AM
hi,
yes it is correct..since kunnr is the key of the kna1 it will fetch the details correctly...
‎2009 Jan 19 9:41 AM
ur program is syntatically correct...
but m not clear as wat is ur requirement???
u have put a loop for kna1 and in dat u reading the join table with key kunnr (But here in join table there will be multiple records with same kunnr as it contain line item also.Since u r reading,only ull get the first record,and hence only the netwr of one posnr)
So if u collect also u wont get the summed up value,ull get only one line value.....
‎2009 Jan 19 9:47 AM
I have to fetch the itemwise customer data..
how to make output table?..
I m facing problem in output table.. i couldnt get the item number and net value..
they r coming as zeros..
Edited by: Sri on Jan 19, 2009 10:48 AM
‎2009 Jan 19 10:08 AM
Hi...change like dis...
LOOP AT T_sale INTO W_sale .
W_OUTPUT-POSNR = W_SALE-POSNR.
W_OUTPUT-NETWR = W_SALE-NETWR.
READ TABLE T_kna1 INTO W_kna1 WITH KEY = W_sale-KUNNR.
IF SY-SUBRC = 0.
W_OUTPUT-KUNNR = W_kna1-KUNNR.
W_OUTPUT-LAND1 = W_KNA1-LAND1.
W_OUTPUT-NAME1 = W_KNA1-NAME1.
W_OUTPUT-ORT01 = W_KNA1-ORT01.
W_OUTPUT-PSTLZ = W_KNA1-PSTLZ.
ENDIF.
COLLECT w_OUTPUT into t_output. " i dunno y u have used collect
APPEND w_OUTPUT TO t_output.
ENDLOOP.
SORT T_OUTPUT BY POSNR KUNNR.
clear w_output.
LOOP AT T_OUTPUT INTO W_OUTPUT.
write:/ w_output-posnr,20 w_output-netwr, 50 w_output-kunnr , 80 w_output-name1,
120 w_output-land1,130 w_output-pstlz.
ENDLOOP.
‎2009 Jan 19 10:11 AM
i tried with ur code,but unable to display the customer data,its only displaying the item number and net value.
‎2009 Jan 19 10:23 AM
Hi...change the statement like dis...
READ TABLE T_kna1 INTO W_kna1 WITH KEY kunnr = W_sale-KUNNR.