You are on page 1of 10

REPORT ZANK_SELECTION_SCREEN.

SELECTION-SCREEN BEGIN OF SCREEN 1001 AS WINDOW.


SELECTION-SCREEN begin of BLOCK B1 WITH FRAME
title v_b1tit.
PARAMETERS : p_kunnr type kunnr, "Customer
p_vkorg type vkorg. "Sales Org
SELECTION-SCREEN END of BLOCK B1.

SELECTION-SCREEN SKIP 2.

SELECTION-SCREEN begin of BLOCK B2 WITH FRAME


title text-001.
PARAMETERS : p_lifnr type lifnr, "Vendor
p_ekorg type ekorg. "Purchasing Org
SELECTION-SCREEN END of BLOCK B2.

SELECTION-SCREEN begin of BLOCK B3 WITH FRAME


title text-002.

SELECTION-SCREEN begin of line.


SELECTION-SCREEN COMMENT 3(5) text-003.
PARAMETERS : r1 RADIOBUTTON GROUP G1.
SELECTION-SCREEN COMMENT 20(5) text-004.
PARAMETERS r2 RADIOBUTTON GROUP G1.
SELECTION-SCREEN end of line.
SELECTION-SCREEN SKIP 2.
PARAMETERS : r3 RADIOBUTTON GROUP G2,
R4 RADIOBUTTON GROUP G2 DEFAULT 'X'.
SELECTION-SCREEN END of BLOCK B3.

SELECTION-SCREEN begin of BLOCK B4 WITH FRAME


title text-005.
PARAMETERS : cb_raw as CHECKBOX,
cb_fin AS CHECKBOX DEFAULT 'X',
cb_sfin AS CHECKBOX.
SELECTION-SCREEN END of BLOCK B4.

SELECTION-SCREEN END OF SCREEN 1001.

CALL SELECTION-SCREEN 1001 STARTING AT 15 5.

INITIALIZATION. "Event- Triggered before Displaying


"Sel.Screen
v_b1tit = 'Customer'.

START-OF-SELECTION.
IF R1 = 'X'.
WRITE / 'R1 is Selected'.
elseif R2 = 'X'.
WRITE / 'R2 is Selected'.
ENDIF

TYPES :begin of TY_POS,


ebeln TYPE zebeln,
lifnr TYPE zlifnr,
aedat TYPE erdat,
ebelp TYPE ebelp,
matnr TYPE matnr,
menge TYPE menge_d,
netpr TYPE bprei,
end of TY_POS.
DATA : IT_POS TYPE TABLE OF TY_POS,
wa_POS TYPE TY_POS.

SELECT zekko~ebeln
zekko~lifnr
zekko~aedat
zekpo~ebelp
zekpo~matnr
zekpo~menge
zekpo~netpr
INTO TABLE IT_POS
FROM zekko INNER JOIN zekpo
on zekko~ebeln = zekpo~ebeln.

SORT IT_POS BY EBELN ASCENDING .

LOOP AT it_POS into wa_POS.


at FIRST.
write / 'List of Purchases Orders' COLOR 1.
ULINE.
ENDAT.
AT NEW EBELN.
write : / wa_POS-ebeln COLOR 1.
ENDAT.

WRITE : / wa_POS-lifnr,
wa_POS-aedat ,
wa_POS-ebelp,
wa_POS-matnr,
wa_POS-menge,
wa_POS-netpr.

AT END OF EBELN.
SUM.
WRITE : /30 'Total PO Value' COLOR 1, wa_pos-netpr COLOR 3.
endat.

at LAST .
SUM.
WRITE : /50 'Total of All POs ' COLOR 1, wa_pos-netpr COLOR 3.
ENDAT.
ENDLOOP.

TYPES :begin of TY_POS,


lifnr TYPE zlifnr,
ebeln TYPE zebeln,
aedat TYPE erdat,
ebelp TYPE ebelp,
matnr TYPE matnr,
menge TYPE menge_d,
netpr TYPE bprei,
end of TY_POS.
DATA : IT_POS TYPE TABLE OF TY_POS,
wa_POS TYPE TY_POS.

SELECT
zekko~lifnr
zekko~ebeln
zekko~aedat
zekpo~ebelp
zekpo~matnr
zekpo~menge
zekpo~netpr
INTO TABLE IT_POS
FROM zekko INNER JOIN zekpo
on zekko~ebeln = zekpo~ebeln.

SORT IT_POS BY lifnr EBELN ASCENDING .

LOOP AT it_POS into wa_POS.


at FIRST.
write / 'List of Purchases Orders' COLOR 1.
ULINE.
ENDAT.
AT NEW lifnr.
write : /5 'Vendor' COLOR 3, wa_POS-lifnr COLOR 1.
ENDAT.
AT NEW EBELN.
write : / 'PO' COLOR 3, wa_POS-ebeln COLOR 7.
ENDAT.

WRITE : /
wa_POS-aedat ,
wa_POS-ebelp,
wa_POS-matnr,
wa_POS-menge,
wa_POS-netpr.

AT END OF EBELN.
SUM.
WRITE : /30 'Total PO Value' COLOR 1, wa_pos-netpr COLOR 3.
endat.
AT END OF lifnr.
SUM.
WRITE : /50 'Total @ Vendor' COLOR 7, wa_pos-lifnr COLOR 3.
endat.
at LAST .
SUM.
WRITE : /50 'Total of All POs ' COLOR 1, wa_pos-netpr COLOR 3.
ENDAT.
ENDLOOP.
lifnr ebeln ebelp netpr
v1 p1 10 1000

v1 p1 20 2000

v1 p1 30 3000

loop at itab into wa.


at end of ebeln.
sum.
(within this block, all the field values right to ebeln turns into
0(numeric), ***(non numeric)
endat.
endloop.
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
----
operation on itab data

Display - is always rec. by record


loop at itab into wa
[<n1> to <n2>
where <condition>]
display data from ,wa>.
endloop.
***********************************************************************************
***********************************************************************************
**
Adding recs
--
APPEND <WA> TO <ITAB>
INSERT <WA> INTO TABLE <ITAB>
INSERT <WA> INTO TABLE <ITAB> [INDEX n].
***********************************************************************************
***********************************************************************************
**
Moving Data from ITAB1 TO ITAB2
loop at itab1 into wa
append wa to itab2.
endloop.
OR

Append lines of itab1 [from n1 to n2] to itab2.


Insert Lines of itab1 [from n1 to n2] into itab2 index <n>.
***********************************************************************************
*******************************
DELETING:

DELETE <itab> [ from <n1> to <n2> Where <condition>].

delete <itab> index <n>.


delete <itab> where <condition>.
***********************************************************************************
***********************************************************************************
Deleting Duplicates:
1 1
3 1
5 _sort______ 3
5 3
7 4
1 4
3
4

DELETE ADJACENT DUPLICATES FROM <ITAB> COMPARING <F1> <F2>.../ALL FIELDS


MAKE SURE THAT ITAB IS SORTED TO ARRANGE THE DUPLICATE RECORDS INTO ADJACENT.
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
Modify/overwrite:

modify <itab> from <wa>


[ transporting <f1> <f2> ... ] [index n]
[ where <condition>].

NOTE: SY-TABIX maintains the currently processed record counter within loop-
endloop.
But not loop counter

when itab has 10 recs


loop at itab1 from wa.
write / sy-tabix.
endloop.

o/p: 1 2 3 ..10

when itab has 10 recs


loop at itab1 from wa from 5 to 10.
write / sy-tabix.
endloop.

o/p: 5 6 7...10
***********************************************************************************
**********
Reading a particular record from itab:

READ can read only read one record.


READ TABLE <itab> into <wa> index <n>.
READ TABLE <itab> into <wa> with key <condition>[binary search>

itab must be sorted for binary search].


********************----------------------------------------------/////////////////
///***************************************
DESCRIBE: To find out no. of recs in itab.

DESCRIBE TABLE <itab> LINES <V_LINES>.


The no of lines in the itab are filled into <v_lines> and also into system variable
sy-tfill.
or

<v_lines> = LINES( itab ).

***********************************************************************************
******************************************************************

REPORT ZANK_ITAB_OPERATIONS.
TYPES: BEGIN OF ty_zekpo,
ebeln TYPE zekpo-ebeln,
ebelp TYPE zekpo-ebelp,
matnr TYPE zekpo-matnr,
menge TYPE zekpo-menge,
netpr TYPE zekpo-netpr,
tnetpr type zekpo-netpr,
END OF ty_zekpo.
DATA : WA_ZEKPO TYPE TY_ZEKPO,
IT_ZEKPO TYPE TABLE OF TY_ZEKPO.

*SELECT ebeln ebelp matnr menge netpr


*INTO WA_ZEKPO FROM ZEKPO.
*
* APPEND WA_ZEKPO TO IT_ZEKPO.
*ENDSELECT.

SELECT ebeln ebelp matnr menge netpr


INTO TABLE IT_ZEKPO FROM ZEKPO.
DATA V_LINES TYPE I.

IF IT_ZEKPO IS NOT INITIAL.


V_LINES = LINES( IT_ZEKPO ).
WRITE : / 'No of Records from it_zekpo are', v_lines COlor 7.
ULINE.
LOOP AT it_zekpo into wa_zekpo.
wa_zekpo-tnetpr = wa_zekpo-menge * wa_zekpo-netpr.

modify it_zekpo from wa_zekpo


index sy-tabix TRANSPORTING tnetpr
.
write : / sy-tabix COLOR 1,
wa_zekpo-ebeln,
wa_zekpo-ebelp,
wa_zekpo-matnr,
wa_zekpo-menge,
wa_zekpo-netpr,
wa_zekpo-tnetpr.
ENDLOOP.
else.
write / 'No Data' COLOR 1.
ENDIF.
skip 2.
*ADD Duplicates
append LINES OF it_zekpo to it_zekpo.
sort it_zekpo by ebeln ebelp.
write : / 'it_zekpo after adding duplicates' COLOR 7.
ULINE.
LOOP AT it_zekpo into wa_zekpo.
.
write : / sy-tabix COLOR 1,
wa_zekpo-ebeln,
wa_zekpo-ebelp,
wa_zekpo-matnr,
wa_zekpo-menge,
wa_zekpo-netpr,
wa_zekpo-tnetpr.
ENDLOOP.

ULINE.

delete ADJACENT DUPLICATES FROM it_zekpo


COMPARING ALL FIELDS.

write : / 'it_zekpo after Deleting duplicates' COLOR 7.


ULINE.
LOOP AT it_zekpo into wa_zekpo.
.
write : / sy-tabix COLOR 1,
wa_zekpo-ebeln,
wa_zekpo-ebelp,
wa_zekpo-matnr,
wa_zekpo-menge,
wa_zekpo-netpr,
wa_zekpo-tnetpr.
ENDLOOP.

ULINE.

*read
clear wa_zekpo.
read TABLE it_zekpo into wa_zekpo
with key ebelp = '00105'.

WRITE / 'Result of READ is' COLOR 7.


ULINE.
if sy-subrc = 0. "successful
write / sy-tabix COLOR 7.
write : / wa_zekpo-ebeln,
wa_zekpo-ebelp,
wa_zekpo-matnr,
wa_zekpo-menge,
wa_zekpo-netpr.
else.
write / 'no record to READ'.
endif.
***********************************************************************************
***********************************************************************************

COLLECT:

COLLECT
COLLECTS ALL THE RECORDS WITH THE SAME NON NUMERIC FIELDS AS A SINGLE RECORD BY
ADDING THE NUMERIC FIELD VALUES.

EX:

TYPES : BEGIN OF ty_sales,


kunnr type kunnr,
sales type i,
end of ty_sales.
data : wa type ty_sales,
itab type TABLE OF ty_sales.
clear wa.
wa-kunnr = '1000'.
wa-sales = 1000.
COLLECT wa into itab.

clear wa.
wa-kunnr = '2000'.
wa-sales = 2000.
COLLECT wa into itab.

clear wa.
wa-kunnr = '1000'.
wa-sales = 3000.
COLLECT wa into itab.

LOOP AT itab into wa.


write : / wa-kunnr COLOR 1,
wa-sales COLOR 2.
ENDLOOP.
**********************************************************************************

REPORT ZANK_ITAB_MSLNS.

TYPES : BEGIN OF ty_sales,


kunnr type kunnr,
sales type i,
end of ty_sales.
data :
itab type TABLE OF ty_sales WITH HEADER LINE.

itab-kunnr = '1000'.
itab-sales = 1000.
append itab to itab.

itab-kunnr = '2000'.
itab-sales = 2000.
append itab to itab.

clear itab.

LOOP AT itab .
write: / itab-kunnr, itab-sales.
ENDLOOP.
***********************************************************************************
****************************************************************
INDEXED

*Standard (Default) - always non-unique

*Sorted - either unique/non-unique need to be defined


Records are always arranged in sorted order as per the key.

*Non-Indexed
.Hashed
- always unique
processing records are always via key

Conclusion:

Indexed operations are not allowed on Hashed Itabs

Sorted itab cannot be sorted explicitly

only standard itabs can be used without restriction.

***********************************************************************************
*********************************

REPORT ZANK_ITAB_TYPES.

data : it_kna1 type STANDARD TABLE OF kna1


,

it_s_kna1 type SORTED TABLE OF kna1


WITH NON-UNIQUE KEY LAND1,
it_h_kna1 type hashed TABLE OF kna1
with unique key kunnr.

delete it_kna1 index 5.


*delete it_h_kna1 index 5. "not allowed
"as it is Hashed

*SORT IT_S_KNA1 BY KUNNR."NOT ALLOWED


"Sorted itab cannot be
"sorted explictly