10-07-2008 12:14 PM
here is the code
&----
*& Report ZSD_RDD0022_DELIVERY_REPORT *
*& *
*& AUTHOR: SUSHANTH.
TITLE: Delivery Report
DESCRIPTION: This report is used to display the list of deliveries
and the corresponding delivery address.!!!
Transport :DONK900306
*& Vesrion :V1
&----
REPORT ZSD_RDD0022_DELIVERY_REPORT.
&----
*& Structure Declarations
&----
Structure declaration for delivery header data
TYPES:BEGIN OF ty_likp,
vbeln TYPE vbeln_vl, "Delivery Number
vkorg TYPE vkorg, "Sales Org
lfart TYPE lfart, "Delivery type
lddat TYPE lddat, "Loading date
kunnr TYPE kunwe, "Ship to party
END OF ty_likp,
Structure Declaration for Delivery ITem data
BEGIN OF ty_lips,
vbeln TYPE vbeln_vl, "Delivery Num
posnr TYPE posnr, "Delivery Item
matnr TYPE matnr, "Materail Number
matkl TYPE matkl, "Materail Grp
lgort TYPE lgort_d, "Storage Location
ntgew TYPE ntgew_15, "Net value
vgbel TYPE vgbel, "Sales Ord Num
vgpos TYPE vgpos, "Sales Item
END OF ty_lips,
Structure declaration for ship to party address details
BEGIN OF ty_kna1,
kunnr TYPE kunnr, "Ship to party
name1 TYPE name1, "Customer Name
ort01 TYPE ort01, "City
pstlz TYPE pstlz, "Postal COde
regio TYPE regio, "Region
END OF ty_kna1,
Structure Declaration for SAles ORder Header
BEGIN OF ty_vbak,
vbeln TYPE vbeln_va, "Sales Order Num
vkorg TYPE vkorg, "SalesOrg
vkgrp TYPE vkgrp, "Sales Grp
kunnr TYPE kunnr, "Sold to Party
END OF ty_vbak,
Structure Declaration for SAles ORder Item data
BEGIN OF ty_vbap,
vbeln TYPE vbeln_va, "Sales ORder
posnr TYPE posnr, "Sales Item
matnr TYPE matnr, "Materail
matkl TYPE matkl, "Materail GRp
netwr TYPE netwr, "Net Value
END OF ty_vbap,
Structure Declaration for final output
BEGIN OF ty_output,
Delivery Header and Address Details
vbeln TYPE vbeln_vl, "Delivery Number
vkorg TYPE vkorg, "Sales Org
lfart TYPE lfart, "Delivery type
lddat TYPE lddat, "Loading date
kunnr TYPE kunwe, "Ship to party
name1 TYPE name1, "Customer Name
ort01 TYPE ort01, "City
pstlz TYPE pstlz, "Postal COde
regio TYPE regio, "Region
Sales Order Header and Address Details
vbeln_1 TYPE vbeln_va, "Sales Ord
vkorg_1 TYPE vkorg, "SAles ORg
vkgrp TYPE vkgrp, "Sales Grp
kunnr_1 TYPE kunnr, "Sold To Party
name1_1 TYPE name1, "Customer Name
ort01_1 TYPE ort01, "City
pstlz_1 TYPE pstlz, "Postal COde
regio_1 TYPE regio, "Region
Delivery ITem deatails
posnr TYPE posnr, "Delivery Item
matnr TYPE matnr, "Materail Number
matkl TYPE matkl, "Materail Grp
lgort TYPE lgort_d, "Storage Location
ntgew TYPE ntgew_15, "Net value
Sales Order ITem Details
posnr_1 TYPE posnr, "Delivery Item
matnr_1 TYPE matnr, "Materail Number
matkl_1 TYPE matkl, "Materail Grp
netwr TYPE netwr, "Net value
END OF ty_output.
&----
*& Internal table Declarations
&----
Internal table declaration for delivery header data
DATA:t_likp TYPE STANDARD TABLE OF ty_likp INITIAL SIZE 0,
Internal table declaration for delivery item data
t_lips TYPE STANDARD TABLE OF ty_lips INITIAL SIZE 0,
Internal table declataion for ship to pary and sold to party address
t_kna1 TYPE STANDARD TABLE OF ty_kna1 INITIAL SIZE 0,
Internal table declartion for final output
t_output TYPE STANDARD TABLE OF ty_output INITIAL SIZE 0,
Internal table declaration for sales order header
t_vbak TYPE STANDARD TABLE OF ty_vbak INITIAL SIZE 0,
Internal table declaration for sales order item data
t_vbap TYPE STANDARD TABLE OF ty_vbap INITIAL SIZE 0,
&----
*& Work area Declarations
&----
Work area declaration for delivery header data
w_likp TYPE ty_likp,
Work area declaration for delivery item data
w_lips TYPE ty_lips,
Work area declaration for address detail
w_kna1 TYPE ty_kna1,
work area declaration for final output
w_output TYPE ty_output,
work area declaration for sales header
w_vbak TYPE ty_vbak,
Work area declaration for Sales ITem
w_vbap TYPE ty_vbap,
&----
*& GLobal Varaible Declarations
&----
g_vbeln TYPE likp-vbeln.
&----
*& Selection Screen Declarations
&----
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME.
SELECT-OPTIONS:s_vbeln FOR g_vbeln.
SELECTION-SCREEN END OF BLOCK b1.
&----
*& Initialization event
&----
INITIALIZATION.
Clear work areas
CLEAR:w_likp,
w_lips,
w_kna1,
w_output,
w_vbak,
w_vbap.
Refresh the internal tables
REFRESH:t_likp,
t_lips,
t_kna1,
t_output,
t_vbak,
t_vbap.
&----
*& At Selection screen Declarations
&----
AT SELECTION-SCREEN.
Validate the delivery number
PERFORM sub_validate_vbeln.
&----
*& Start of Selection Declarations
&----
START-OF-SELECTION.
Get the Delivery Header
PERFORM sub_get_likp.
Get the Delivery Item data
PERFORM sub_get_lips.
Get the Customer data
PERFORM sub_get_kna1.
Get the Sales Order ITem data
PERFORM sub_get_vbap.
Get the Sales ORder Header data
PERFORM sub_get_vbak.
Get the Sold to party Address Details
PERFORM sub_get_kna1_1.
Displaying the output
PERFORM sub_disp_output.
&----
*& Form sub_validate_vbeln
&----
This subroutine is used to validate the delivery number
----
FORM sub_validate_vbeln .
DATA:l_vbeln TYPE vbeln_vl. "#EC
SELECT SINGLE vbeln "ASK RANKI WHY VBUK
FROM vbuk
INTO l_vbeln
WHERE vbeln IN s_vbeln. "#EC
IF sy-subrc <> 0.
MESSAGE e002(zbatch17) WITH 'Invalid Delivery numbers' ."#EC
ENDIF.
ENDFORM. " sub_validate_vbeln
&----
*& Form sub_get_likp
&----
text
----
FORM sub_get_likp .
SELECT vbeln "Delivery
vkorg "Sales Org
lfart "Delivery type
lddat "Loading Date
kunnr "Ship to party
FROM likp
INTO TABLE t_likp
WHERE vbeln IN s_vbeln.
IF sy-subrc <> 0.
MESSAGE i002(zbatch17) WITH 'Data Not found'.
LEAVE LIST-PROCESSING.
ENDIF.
ENDFORM. " sub_validate_vbeln
&----
*& Form sub_get_lips
&----
text
----
FORM sub_get_lips .
*if t_likp is not initial.
SELECT vbeln " Delivery Num
posnr " Delivery Item
matnr " Materal
matkl "Materail Grp
lgort "Sloc
ntgew "Net Value
vgbel "Sales ORd
vgpos "Sales ITem
FROM lips
INTO TABLE t_lips
FOR ALL ENTRIES IN t_likp
WHERE vbeln = t_likp-vbeln.
*endif.
ENDFORM. " sub_get_lips
&----
*& Form sub_get_kna1
&----
text
----
FORM sub_get_kna1 .
*if t_likp is not initial.
SELECT kunnr "Ship to party
name1 " Customer name
ort01 "City
pstlz "Postal Code
regio "Region
FROM kna1
INTO TABLE t_kna1
FOR ALL ENTRIES IN t_likp
WHERE kunnr = t_likp-kunnr.
*endif.
ENDFORM. " sub_get_kna1
&----
*& Form sub_get_vbap
&----
text
----
FORM sub_get_vbap .
IF t_lips IS NOT INITIAL.
SELECT vbeln "Sales Ord
posnr "Sales Item
matnr "Materail
matkl "Matetial Grp
netwr "Net Value
FROM vbap
INTO TABLE t_vbap
FOR ALL ENTRIES IN t_lips
WHERE vbeln = t_lips-vgbel
AND posnr = t_lips-vgpos.
ENDIF.
ENDFORM. " sub_get_vbap
&----
*& Form sub_get_vbak
&----
text
----
FORM sub_get_vbak .
IF t_vbap IS NOT INITIAL.
SELECT vbeln "Sales Ord
vkorg "Sales ORg
vkgrp "Sales Grp
kunnr "Sold to party
FROM vbak
INTO TABLE t_vbak
FOR ALL ENTRIES IN t_vbap
WHERE vbeln = t_vbap-vbeln.
ENDIF.
ENDFORM. " sub_get_vbak
&----
*& Form sub_get_kna1_1
&----
text
----
FORM sub_get_kna1_1 .
IF t_vbak IS NOT INITIAL.
SELECT kunnr "Ship to party
name1 " Customer name
ort01 "City
pstlz "Postal Code
regio "Region
FROM kna1
APPENDING TABLE t_kna1
FOR ALL ENTRIES IN t_vbak
WHERE kunnr = t_vbak-kunnr.
ENDIF.
ENDFORM. " s
&----
*& Form sub_disp_output
&----
text
----
FORM sub_disp_output .
LOOP AT t_lips INTO w_lips.
Move all the item data to final output
w_output-vbeln = w_lips-vbeln.
w_output-posnr = w_lips-posnr.
w_output-matnr = w_lips-matnr.
w_output-matkl = w_lips-matkl.
w_output-lgort = w_lips-lgort.
w_output-ntgew = w_lips-ntgew.
Move all the header data to final output
CLEAR w_likp.
READ TABLE t_likp INTO w_likp WITH KEY vbeln = w_lips-vbeln.
IF sy-subrc = 0.
w_output-vkorg = w_likp-vkorg.
w_output-lfart = w_likp-lfart.
w_output-lddat = w_likp-lddat.
w_output-kunnr = w_likp-kunnr.
ENDIF.
Move all the ship to party address details
CLEAR w_kna1.
READ TABLE t_kna1 INTO w_kna1 WITH KEY kunnr = w_likp-kunnr.
IF sy-subrc = 0.
w_output-name1 = w_kna1-name1.
w_output-ort01 = w_kna1-ort01.
w_output-pstlz = w_kna1-pstlz.
w_output-regio = w_kna1-regio.
ENDIF.
Move all the sales order item data
CLEAR w_vbap.
READ TABLE t_vbap INTO w_vbap WITH KEY vbeln = w_lips-vgbel
posnr = w_lips-vgpos.
IF sy-subrc = 0.
w_output-vbeln_1 = w_vbap-vbeln.
w_output-posnr_1 = w_vbap-posnr.
w_output-matkl_1 = w_vbap-matkl.
w_output-netwr = w_vbap-netwr.
ENDIF.
Move all the sales Order Header data
CLEAR w_vbak.
READ TABLE t_vbak INTO w_vbak WITH KEY vbeln = w_vbap-vbeln.
IF sy-subrc = 0.
w_output-vkorg_1 = w_vbak-vkorg.
w_output-vkgrp = w_vbak-vkgrp.
w_output-kunnr_1 = w_vbak-kunnr.
ENDIF.
Move Sold to Pary Adress Deatils
CLEAR w_kna1.
READ TABLE t_kna1 INTO w_kna1 WITH KEY kunnr = w_vbak-kunnr.
IF sy-subrc = 0.
w_output-name1_1 = w_kna1-name1.
w_output-ort01_1 = w_kna1-ort01.
w_output-pstlz_1 = w_kna1-pstlz.
w_output-regio_1 = w_kna1-regio.
ENDIF.
APPEND w_output TO t_output.
CLEAR w_output.
ENDLOOP.
to display on the screen-
code here **
Question -
as you see the internal tables were combined based on some values like here -
FORM sub_get_vbap .
IF t_lips IS NOT INITIAL.
SELECT vbeln "Sales Ord
posnr "Sales Item
matnr "Materail
matkl "Matetial Grp
netwr "Net Value
FROM vbap
INTO TABLE t_vbap
FOR ALL ENTRIES IN t_lips
WHERE vbeln = t_lips-vgbel
AND posnr = t_lips-vgpos.
ENDIF.
how can we decide that based on a few particular common fields we can join tables ???? is there a particular way to identify such fields ?? which are common in both tables and which can be used as a link??
thanks
sushanth
10-09-2008 4:38 AM
Hi,
I think it comes from:
1. Experience
You get the information from someone more experienced than you. Or from "on the job" experience.
2. Testing
Create some test data and check how they are stored in SAP tables.
3. or Training.
On the training you are told about the relations of those tables.
Regards,
Teddy Kurniawan
10-09-2008 8:20 AM
Hi,
Better to check the key fields in both the tables and use the common fields to join the tables.
Thanks,
Sudheer Kumar
10-09-2008 10:25 AM
Hi ,
If you want to know the relationship between fields, you can type the field name in se13 and press the where- to -used list.
It will show you all the tables, in which this field is used.
And the relationship between the tables based on fields can be only found by real time experience with the usage of those tables.
Rewar points, if usefull.
10-10-2008 6:47 AM
in which version can we go to se13 and type the table name?
i am using 4.7 .. can you tell me in which version is this possible?
regards
sushanth