07-21-2007 2:20 PM
How to trasnfer the contents from two internal tables into one internal table in the same program and from different?
07-21-2007 2:36 PM
i don't think you can get data into 1internal table from different programs. but while executing one program you can use joins.
sample code
TYPES:
BEGIN OF TY_OUTPUT,
KUNNR TYPE VBAK-KUNNR,
VBELN TYPE VBAK-VBELN,
AUDAT TYPE VBAK-AUDAT,
VBTYP TYPE VBAK-VBTYP,
MATNR TYPE VBAP-MATNR,
ZMENG TYPE VBAP-ZMENG,
NETPR TYPE VBAP-NETPR,
NETWR TYPE VBAP-NETWR,
MAKTX TYPE MAKT-MAKTX,
END OF TY_OUTPUT.
DATA:
ST_OUTPUT TYPE TY_OUTPUT,
IT_OUTPUT TYPE TY_OUTPUT.
SELECT-OPTIONS: SKUNNR FOR ST_OUTPUT-KUNNR.
SELECT-OPTIONS: SAUDAT FOR ST_OUTPUT-AUDAT.
SELECT-OPTIONS: SVBTYP FOR ST_OUTPUT-VBTYP.
SELECT VBAKKUNNR VBAKVBELN VBAKAUDAT VBAKVBTYP VBAPMATNR VBAPZMENG VBAPNETPR VBAPNETWR MAKT~MAKTX INTO TABLE IT_OUTPUT
FROM VBAK
INNER JOIN VBAP ON VBAKVBELN = VBAPVBELN
WHERE VBAK~KUNNR = SKUNNR
VBAK~AUDAT = SAUDAT
VBAK~VBTYP = SVBTYP.
Check this sample
Select single VbrkBukrs VbrkKunrg Vbrk~Vbeln
VbrkFkdat VbrkBstnk_Vf Vbrk~Zterm
Tvzbt~Vtext
VbakVbeln VbakBstdk
LikpVbeln Likplfdat Likp~Lfuhr
into w_vbrk
from vbrk
inner join Tvzbt on TvzbtZterm = VbrkZterm and
Tvzbt~Spras = sy-langu
Inner join Vbfa as SalesLnk
on SalesLnk~vbeln = pu_vbeln and
SalesLnk~vbtyp_v = c_order
inner join Vbak on VbakVbeln = SalesLnkVbelv
Inner join Vbfa as DeliveryLnk
on DeliveryLnk~vbeln = pu_vbeln and
DeliveryLnk~vbtyp_v = c_Delivery
inner join Likp on LikpVbeln = DeliveryLnkVbelv
where vbrk~vbeln = pu_Vbeln.
regards,
srinivas
<b>*reward for useful answers*</b>
07-21-2007 2:44 PM
Check this sample code...
DATA: BEGIN OF fs_spfli,
carrid TYPE spfli-carrid,
connid TYPE spfli-connid,
countryfr TYPE spfli-countryfr,
END OF fs_spfli.
DATA: BEGIN OF fs_sflight,
carrid TYPE sflight-carrid,
connid TYPE sflight-connid,
fldate TYPE sflight-fldate,
price TYPE sflight-price,
END OF fs_sflight.
DATA: BEGIN OF fs_outtab,
carrid TYPE spfli-carrid,
connid TYPE spfli-connid,
countryfr TYPE spfli-countryfr,
fldate TYPE sflight-fldate,
price TYPE sflight-price,
END OF fs_outtab.
DATA: t_spfli LIKE STANDARD TABLE OF fs_spfli,
t_sflight LIKE STANDARD TABLE OF fs_sflight,
t_outtab LIKE STANDARD TABLE OF fs_outtab.
SELECT * FROM spfli INTO CORRESPONDING FIELDS OF TABLE t_spfli.
SELECT * FROM sflight INTO CORRESPONDING FIELDS OF TABLE t_sflight.
LOOP AT t_sflight INTO fs_sflight.
READ TABLE t_spfli INTO fs_spfli with key carrid = fs_sflight-carrid
.
IF sy-subrc EQ 0.
MOVE fs_spfli-carrid TO fs_outtab-carrid.
MOVE fs_spfli-connid TO fs_outtab-connid.
MOVE fs_spfli-countryfr TO fs_outtab-countryfr.
MOVE fs_sflight-fldate TO fs_outtab-fldate.
MOVE fs_sflight-price TO fs_outtab-price.
APPEND fs_outtab TO t_outtab.
ENDIF.
CLEAR fs_spfli.
CLEAR fs_sflight.
ENDLOOP.
Regards,
Pavan
07-21-2007 5:32 PM
Hi Tariq,
If is is in the same program or from different program, the internal table structure should be same for the two internal tables which you want to make as one internal table.
If you want to make two internal tables into one internal table in the same program then code as follows.
APPEND LINES OF ITAB1 INTO IT_FINAL.
APPEND LINES OF ITAB2 INTO IT_FINAL.
If ITAB1 and ITAB2 are your internal tables and IT_FINAL is you contents of two internal tables.
If you want to make two internal tables into one internal table from different programs use EXPORT TO ... MEMORY statement to get the other internal table data from other program and add the contents of two internal tables into one internal table.
Thanks,
Vinay
07-21-2007 10:30 PM
Hello,
I think transferring in one program has already been answered above
for different programs, what you need to do is to export the internal table to memory in the first program, import it from memory in the second and follow the same steps as if its a table from the same program
this is the syntax for exporting / importing
Exporting...
DATA: wa_indx TYPE indx.
EXPORT tab = itab TO DATABASE indx(xy) FROM wa_indx CLIENT
SY-MANDT
ID 'DETAILLIST'.
Importing...
* imports from database the list sent by the calling program
IMPORT tab = itab FROM DATABASE indx(xy) TO wa_indx CLIENT sy-mandt
ID 'DETAILLIST'.
* deletes the data to save wastage of memory
DELETE FROM DATABASE indx(xy)
CLIENT sy-mandt
ID 'DETAILLIST'.