Вы находитесь на странице: 1из 5

*&---------------------------------------------------------------------*

*& Report ZVR_ITAB_OPERATIONS


*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT zvr_itab_operations LINE-SIZE 300.

*****************************************************************
***2nd internal table operation using APPEND KEYWORD
***sample application
***declaration of TYPES structure
TYPES : BEGIN OF ty_vbak,
vbeln TYPE vbak-vbeln,
ernam TYPE vbak-ernam,
erdat TYPE vbak-erdat,
vbtyp TYPE vbak-vbtyp,
auart TYPE vbak-auart,
kunnr TYPE vbak-kunnr,
vkorg TYPE vbak-vkorg,
vtweg TYPE vbak-vtweg,
spart TYPE vbak-spart,
netwr TYPE vbak-netwr,
END OF ty_vbak.

***declaration of work area & internal table


DATA : ls_vbak TYPE ty_vbak,
lt_vbak1 TYPE TABLE OF ty_vbak,
ls_vbak2 TYPE ty_vbak,
lt_vbak2 TYPE TABLE OF ty_vbak,
lv_rec TYPE i,
lv_nor TYPE i.

***selection screen design


SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
SELECTION-SCREEN SKIP.
SELECT-OPTIONS : s_vbeln FOR ls_vbak-vbeln,
s_erdat FOR ls_vbak-erdat NO-EXTENSION,
s_vbtyp FOR ls_vbak-vbtyp NO INTERVALS NO-EXTENSION.
SELECTION-SCREEN SKIP.
SELECTION-SCREEN END OF BLOCK b1.

***extract data from DB table to 1st internal table


SELECT vbeln
ernam
erdat
vbtyp
auart
kunnr
vkorg
vtweg
spart
netwr FROM vbak
INTO TABLE lt_vbak1
WHERE vbeln IN s_vbeln
AND erdat IN s_erdat
AND vbtyp IN s_vbtyp.

***Manually fill 1st internal table from work area


ls_vbak-vbeln = '4990'.
ls_vbak-ernam = sy-uname.
ls_vbak-erdat = sy-datum.
ls_vbak-vbtyp = 'C'.
ls_vbak-auart = 'OR'.
ls_vbak-kunnr = '1000'.
ls_vbak-vkorg = 'IN01'.
ls_vbak-vtweg = '10'.
ls_vbak-spart = '00'.
ls_vbak-netwr = '10000'.
APPEND ls_vbak TO lt_vbak1.
CLEAR ls_vbak.

***extract data to 2nd internal table


SELECT vbeln
ernam
erdat
vbtyp
auart
kunnr
vkorg
vtweg
spart
netwr FROM vbak UP TO 25 ROWS
INTO TABLE lt_vbak2
WHERE ernam = 'BOLLINGER'.
***check no. of records in 2nd internal table
LOOP AT lt_vbak2 INTO ls_vbak2.
IF sy-tabix = 1.
lv_nor = sy-tfill.
ELSE.
EXIT.
ENDIF.
ENDLOOP.
***transfer 1st internal table data to second internal table
***Certain record of 1st internal table from certain position
APPEND LINES OF lt_vbak1 FROM 8 TO lt_vbak2.

****single record of 1st internal table


*APPEND LINES OF lt_vbak1 FROM 5 TO 5 TO lt_vbak2.

****certain records of 1st internal table


*APPEND LINES OF lt_vbak1 FROM 5 TO 10 TO lt_vbak2.

***all records of 1st internal table


*APPEND LINES OF lt_vbak1 TO lt_vbak2.

****display 1st internal table data


*WRITE :/ 'First internal table data by extracting from DB table' COLOR 6.
*SKIP 2.
*ULINE.
*LOOP AT lt_vbak1 INTO ls_vbak.
* WRITE :/ ls_vbak-vbeln,
* ls_vbak-ernam,
* ls_vbak-erdat,
* ls_vbak-vbtyp,
* ls_vbak-auart,
* ls_vbak-kunnr,
* ls_vbak-vkorg,
* ls_vbak-vtweg,
* ls_vbak-spart,
* ls_vbak-netwr.
* CLEAR ls_vbak.
*ENDLOOP.
*
*
*SKIP 3.
*ULINE.
*SKIP 2.
***display 2nd internal table data
WRITE :/ 'Second internal table data by extracting from DB table' COLOR 6.
SKIP 2.
ULINE.
LOOP AT lt_vbak2 INTO ls_vbak2.
IF sy-tabix = 1.
lv_rec = sy-tfill.
ENDIF.
IF sy-tabix LE lv_nor.
WRITE :/ ls_vbak2-vbeln,
ls_vbak2-ernam,
ls_vbak2-erdat,
ls_vbak2-vbtyp,
ls_vbak2-auart,
ls_vbak2-kunnr,
ls_vbak2-vkorg,
ls_vbak2-vtweg,
ls_vbak2-spart,
ls_vbak2-netwr.
CLEAR ls_vbak2.
ELSE.
FORMAT COLOR 5.
WRITE :/ ls_vbak2-vbeln,
ls_vbak2-ernam,
ls_vbak2-erdat,
ls_vbak2-vbtyp,
ls_vbak2-auart,
ls_vbak2-kunnr,
ls_vbak2-vkorg,
ls_vbak2-vtweg,
ls_vbak2-spart,
ls_vbak2-netwr.
CLEAR ls_vbak2.
ENDIF.

ENDLOOP.

ULINE.
SKIP 2.
WRITE :/ 'Total no. of records in 2nd internal table:', lv_rec.

*******************************************************************
*****1st internal table operation MANUAL TRANSFER
*****sample application
*****declaration of TYPES structure
**TYPES : BEGIN OF ty_vbak,
** vbeln TYPE vbak-vbeln,
** ernam TYPE vbak-ernam,
** erdat TYPE vbak-erdat,
** vbtyp TYPE vbak-vbtyp,
** auart TYPE vbak-auart,
** kunnr TYPE vbak-kunnr,
** vkorg TYPE vbak-vkorg,
** vtweg TYPE vbak-vtweg,
** spart TYPE vbak-spart,
** netwr TYPE vbak-netwr,
** END OF ty_vbak.
**
*****declaration of work area & internal table
**DATA : ls_vbak TYPE ty_vbak,
** lt_vbak1 TYPE TABLE OF ty_vbak,
** ls_vbak2 TYPE ty_vbak,
** lt_vbak2 TYPE TABLE OF ty_vbak.
**
*****selection screen design
**SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
**SELECTION-SCREEN SKIP.
**SELECT-OPTIONS : s_vbeln FOR ls_vbak-vbeln,
** s_erdat FOR ls_vbak-erdat NO-EXTENSION,
** s_vbtyp FOR ls_vbak-vbtyp NO INTERVALS NO-EXTENSION.
**SELECTION-SCREEN SKIP.
**SELECTION-SCREEN END OF BLOCK b1.
**
*****extract data from DB table to 1st internal table
**SELECT vbeln
** ernam
** erdat
** vbtyp
** auart
** kunnr
** vkorg
** vtweg
** spart
** netwr FROM vbak
** INTO TABLE lt_vbak1
** WHERE vbeln IN s_vbeln
** AND erdat IN s_erdat
** AND vbtyp IN s_vbtyp.
**
*****Manually fill 1st internal table from work area
**ls_vbak-vbeln = '4990'.
**ls_vbak-ernam = sy-uname.
**ls_vbak-erdat = sy-datum.
**ls_vbak-vbtyp = 'C'.
**ls_vbak-auart = 'OR'.
**ls_vbak-kunnr = '1000'.
**ls_vbak-vkorg = 'IN01'.
**ls_vbak-vtweg = '10'.
**ls_vbak-spart = '00'.
**ls_vbak-netwr = '10000'.
**APPEND ls_vbak TO lt_vbak1.
**CLEAR ls_vbak.
**
*****transfer complete 1st internal table data to 2nd internal table
**lt_vbak2[] = lt_vbak1[].
**
******display 1st internal table data
***WRITE :/ 'First internal table data by extracting from DB table' COLOR 6.
***SKIP 2.
***ULINE.
***LOOP AT lt_vbak1 INTO ls_vbak.
*** WRITE :/ ls_vbak-vbeln,
*** ls_vbak-ernam,
*** ls_vbak-erdat,
*** ls_vbak-vbtyp,
*** ls_vbak-auart,
*** ls_vbak-kunnr,
*** ls_vbak-vkorg,
*** ls_vbak-vtweg,
*** ls_vbak-spart,
*** ls_vbak-netwr.
*** CLEAR ls_vbak.
***ENDLOOP.
**
**
***SKIP 3.
***ULINE.
***SKIP 2.
*****display 2nd internal table data
**WRITE :/ 'Second internal table data by extracting from DB table' COLOR 6.
**SKIP 2.
**ULINE.
**LOOP AT lt_vbak2 INTO ls_vbak2.
** WRITE :/ ls_vbak2-vbeln,
** ls_vbak2-ernam,
** ls_vbak2-erdat,
** ls_vbak2-vbtyp,
** ls_vbak2-auart,
** ls_vbak2-kunnr,
** ls_vbak2-vkorg,
** ls_vbak2-vtweg,
** ls_vbak2-spart,
** ls_vbak2-netwr.
** CLEAR ls_vbak2.
**ENDLOOP.