‎2008 Oct 12 5:10 AM
sap gurus,
im making a code for getting sales order shipping data, i have several requirements..
my 1st requirement is to retrieve details of the selection-screen..
this is what i did..
retrieve details of the selection screen for sales order
SELECT a~vbeln
a~kunnr
a~ernam
a~auart
b~posnr
b~vstel
b~route
c~maktx
INTO CORRESPONDING FIELDS OF TABLE it_sales
FROM ( ( vbak AS a
INNER JOIN vbap AS b ON avbeln = bvbeln )
INNER JOIN makt AS c ON bmatnr = cmatnr )
WHERE a~vbeln = p_vbeln
AND
aauart = 'CPF1' OR aauart = 'CPF2'.
IF sy-subrc NE 0.
WRITE: 'wala'.
ENDIF.
2nd requirement, get the shipping details from several tables..
select shipping details from vbkd
SELECT inco1
inco2
INTO CORRESPONDING FIELDS OF TABLE it_sales
FROM vbkd
FOR ALL ENTRIES IN it_sales
WHERE vbeln EQ it_sales-vbeln
AND posnr EQ it_sales-posnr.
get description of shipping point
SELECT vtext
INTO CORRESPONDING FIELDS OF TABLE it_sales
FROM tvstt
FOR ALL ENTRIES IN it_sales
WHERE spras = 'en'
AND vstel = it_sales-vstel.
get description of incoterms
SELECT bezei
INTO CORRESPONDING FIELDS OF TABLE it_sales
FROM tinct
FOR ALL ENTRIES IN it_sales
WHERE inco1 = it_sales-inco1.
AND
inco1 = it_sales-inco2.
SELECT bezei
INTO CORRESPONDING FIELDS OF TABLE it_sales
FROM tinct.
WHERE inco1 = it_sales-inco2
get description route
SELECT bezei
INTO CORRESPONDING FIELDS OF TABLE it_sales
FROM tvrot
FOR ALL ENTRIES IN it_sales
WHERE route = it_sales-route.
3rd requirement, i have to get the customer details and update it_sales based on the customer to include the address.
is this correct?
Get customer details
SELECT kunnr
name1
name2
ort01
pstlz
regio
pfach
INTO CORRESPONDING FIELDS OF TABLE it_sales
FROM kna1
FOR ALL ENTRIES IN it_sales
WHERE kunnr EQ it_sales-kunnr.
4th requirement is after i have extracted all the data from the tables i have to store it in it_detail..
how will i do that..
im just a beginner and i need help if the code i wrote is correct..
‎2008 Oct 12 5:52 AM
Hi there,
Just to bring to your notice...
(1)when we do a select with respect to for all entries on a table we need to check if that table is empty or not
eg:
if it_sales[] is not initial.
SELECT inco1 inco2
INTO CORRESPONDING FIELDS OF TABLE it_sales
FROM vbkd
FOR ALL ENTRIES IN it_sales
WHERE vbeln EQ it_sales-vbeln
AND posnr EQ it_sales-posnr.
select XX from XX into XX FOR ALL ENTRIES IN it_sales
where XX and XX.
endif.
if it is not checked,what happens is that , if the table it_sales[] is empty, it will fetch all the records..so this checking should be done for all the 'select' statements with respect to the table on which 'for all entries' fetch is done
(2) For all your select statements the destination is it_sales.........
check in the debugger what is happening in the it_sales table after each select statement
(to activate debugger use '/h' or write 'Break-point' in your code at required location) ,i believe the records are overwritten after each select...there are numerous approach to obtain the desired output like..
(a)we can fetch all data into differernt internal tables and get them together in a loop based on key fields/relations or(b) we can keep modifying existing table with the required data based on key fields etc...
Hope it helps,
Pls check
Regards
Byju
‎2008 Oct 12 5:52 AM
Hi there,
Just to bring to your notice...
(1)when we do a select with respect to for all entries on a table we need to check if that table is empty or not
eg:
if it_sales[] is not initial.
SELECT inco1 inco2
INTO CORRESPONDING FIELDS OF TABLE it_sales
FROM vbkd
FOR ALL ENTRIES IN it_sales
WHERE vbeln EQ it_sales-vbeln
AND posnr EQ it_sales-posnr.
select XX from XX into XX FOR ALL ENTRIES IN it_sales
where XX and XX.
endif.
if it is not checked,what happens is that , if the table it_sales[] is empty, it will fetch all the records..so this checking should be done for all the 'select' statements with respect to the table on which 'for all entries' fetch is done
(2) For all your select statements the destination is it_sales.........
check in the debugger what is happening in the it_sales table after each select statement
(to activate debugger use '/h' or write 'Break-point' in your code at required location) ,i believe the records are overwritten after each select...there are numerous approach to obtain the desired output like..
(a)we can fetch all data into differernt internal tables and get them together in a loop based on key fields/relations or(b) we can keep modifying existing table with the required data based on key fields etc...
Hope it helps,
Pls check
Regards
Byju