0% found this document useful (0 votes)
195 views

Abap Code Practice

The document provides examples of different ABAP programming concepts including data types, control structures, string operations, internal tables, selection screens, and database access. Specifically, it shows 21 programs demonstrating: 1) data declarations and arithmetic operations, 2) IF/ELSE control structures, 3) CASE/WHEN, 4) DO/ENDDO loops, 5) string concatenation and splitting, 6) internal tables with append, read, modify, delete, and loop statements, 7) selection screens, parameters, and blocks, and 8) database table access.

Uploaded by

Akhila
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
195 views

Abap Code Practice

The document provides examples of different ABAP programming concepts including data types, control structures, string operations, internal tables, selection screens, and database access. Specifically, it shows 21 programs demonstrating: 1) data declarations and arithmetic operations, 2) IF/ELSE control structures, 3) CASE/WHEN, 4) DO/ENDDO loops, 5) string concatenation and splitting, 6) internal tables with append, read, modify, delete, and loop statements, 7) selection screens, parameters, and blocks, and 8) database table access.

Uploaded by

Akhila
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 35

----user define data types

****first way -- itemno type vbeln,


****2nd way --- item no(8) type n,
*****3rd way ----itemno type zordh_1-ono.

<field> type (<data element>)


<in built type>
<global_structure/table>-filed)

*****______ work area --workarea is nothing but it holdes the single record at
runtime during the session of the program

program --------(1)

data : lv_input1(2) type n value 10,


lv_input2(2) type n value 20,
lv_output type n .
lv_output = lv_input1 + lv_input2.
write : / ' the output is ', lv_output.

write : / 'first input is ' , lv_input1.


write : / 'second input is ' , lv_input2.

-----------

PROGRAM ------(2) if statment

data : lv_input1(3) type n value 2.


if lv_input = 2.
write : 'the output is' , lv_input.
else.
write : 'wrong input'.
endif.

program---(3) if ,elseif , else

data : lv_input(3) type n valuE 4.

if lv_input = 1.

write : 'the output' , lv_input.


elseif lv_input = 2.
write : 'the output is ' , lv_input.
elseif lv_input = 3.
write : 'output is ' , lv_input.
else .
write : 'wrong input'.
endif.
program---(4) CASE STATMENT

data : lv_input(3) type n value 3.

case lv_input .
when 1 .
write : 'the output is ', lv_input.
when 2.
write : 'the output is ', lv_input.
when 3 .
write : 'the output is ', lv_input.

when others .
write : 'wrong input '.
endcase.

program(5) ..do

data : lv_input(3) type n value 10.

do 10 times.
write : / 'the output is ' , lv_input.
lv_input = lv_input + 1.
enddo.
-----------------------------------

program(6) ..exit

data : lv_input(3) type n value 10.


do .
if lv_input = 15.
exit.
endif.
write : / 'the output is ' , lv_input.
lv_input = lv_input + 1.
enddo.
-------------------------------------
program(7)....continue
data : lv_input(2) type n value 10.
do 10 times.
if lv_input = 15.
continue.
endif.
write : ' the output is ' , lv_input.'
lv_input = lv_input + 1.
enddo.

------------

program(8) ....while

data : lv_input(2) type n value 10.


while lv_input lt 15.
write : / 'the output is ', lv_input.
lv_input = lv_input + 1.
endwhile.
-----------

program(9)..... check

data : lv_input(2) type n value 10.


do 10 times.
lv_input = lv_input + 1.
check lv_input = 15.
write : ' the output is ', lv_input.
enddo.

-----------------
program(10) ....system variables

write : 'the user name of the system is ' , sy-uname. "user name

do 10 times. "system index and tabix

write : / sy-index , sy-tabix.


enddo.

write : / 'the current date is ' , sy-datum. "system date


write : / 'the current time is ' , sy-uzeit. "sytem time

--------------------------
program(11) ......string operations concatenate

data : lv_input1(20) type c value ' advanced',


lv_input2(20) type c value 'business' ,
lv_input3(20) type c value 'application',
lv_input4(20) type c value 'programming language'
lv_output type c.

concatenate lv_input1 lv_input2 lv_input3 lv_input4 into lv_output separated by


'/'. " concatenate
write : / 'after conacatenation ' , lv_output.

data : lv_res1(20) type c ,


lv_res2(20) type c,
lv_res3(20) type c,
lv_res4(20) type c.

split lv_output at '/' into lv_res1 lv_res2 lv_res3 lv_res4.


" split
write : / 'split after result is ' , / lv_res1 , / lv_res2 , / lv_res3 , /
lv_res4.

program(12) .....string condense

data : lv_input type string value ' welcome to sap abap '.
data : lv_length(2) type n.

lv_length = strlen( lv_input ) .


write : / ' the length before condense ' , lv_length.
write : / 'before condense ' , lv_input.

condense lv_input.
"CONDENSE

lv_length = strlen( lv_input ).


write : / ' length after condense ' , lv_length.
write : / ' afte condese ' , lv_input.

condense lv_input no-gaps.


"NO-GAPS
lv_length = strlen( lv_input ).
write : / ' length before condense no-gaps ' , lv_length.
write : / ' after condense no-gaps ' , lv_input.

---------
program(13) .......string operations FIND

data : lv_input(50) type c value 'abap editor screen'.

find 'Abap' in lv_input ignoring case.


if sy-subrc = 0.
write : ' this is sucessful ' , lv_input.
else.
write : / ' this is un-sucessful ' .
endif.

---------------------
program(14).........string operations TRANSLATE

data : lv_res1(50) type c value 'sap is an erp softwear',


lv_res2(50) type c value 'SAP IS AN ERP SOFTWEAR'.

translate lv_res1 to upper case.


write : / 'the result after translate is ' , lv_res1.

translate lv-res2 to lower case.


write : / ' the result after translate is ' , lv_res2.

.......another way

data : lv_rule(50) type c value 'AaSsPpEeRrNnOo'.


translate lv_res1 using lv_rule.
write : / 'the result after translate is ', lv_res1.

----------------progaram(15) ....string operations SHIFT

data : lv_a1(10) type c value '0123456789',


lv_a2(10) type c value '0123456789',
lv_a3(10) type c value '0123456789'.

shift lv_a1 by 5 places left.


write : / 'left side ' , lv_a1.

shift lv_a2 by 5 places right.


write : / ' right side ' , lv_a2.
shift lv_a3 by 4 places circular.
write : / ' circular ' , lv_a3.

---------------------
progran(16) ...SHIFT (TRAILING ,LEADING )

data : lv-x1(10) type c value '7000000000',


lv_x2(10) type c value '0000000007',
shift lv-x1 right deleting trailing '0'.

condense lv_x1.
write : / ' result after deletion ' , lv_x1.

shift lv_x2 left deleting leading '0'.


write : / ' reslut after deletion ', lv_x2.

------------------

program(17) ....substring processing

data : lv_input(20) type c value '91-410-9911223344',


lv_cntry(2) type c,
lv_city(3) type c,
lv_number(10) type c .

lv_cntry = lv_input+0(2).
write : / ' country code is ' , lv_cntry.

lv_city = lv_input+3(3).
write : / 'city code is ' , lv-city.

lv_number = lv_input+7(10).
write : / 'number is ' , lv_number.

-------------------------

program(18) ......INTERNAL TABLE AND WORKAREA

types : begin of lty_data,


ono type zdeono_28,
pm type zdepm_28,
end of lty_data.

data : lt_data type table of lty_data.


data : lwa_data type lty_data.

lwa_data-ono = 1.
lwa_data-pm = 'C'.
append lwa_data to lt_data.
clear lwa_data.

lwa_data-ono = 1.
lwa_data-pm = 'D'.
append lwa_data to lt_data.
clear lwa_data.

lwa_data-ono = 2.
lwa_data-pm = 'C'.
append lwa_data to lt_data.
clear lwa_data.

lwa_data-ono = 2.
lwa_data-pm = 'D'.
append lwa_data to lt_data.
clear lwa_data.

lwa_data-ono = 3.
lwa_data-pm = 'C'.
append lwa_data to lt_data.
clear lwa_data.

* loop ---------

loop at lt_data into lwa_data.


write : / lwa_data-ono , / lwa_data-pm.
endloop.

* DELETE ------2 ways

delete lt_data where pm = 'D'. " (way 1)


(OR)
delete lt_data where ONO = 3. " (way2)

delete lt_data index 1. " through index


*after this we have to write loop

* MODIFY
loop at lt_data into lwa_data.
if lwa_data-ono = 1.
lwa_data-pm = 'N'.
modify lt_data from lwa_data transporting pm .
write : / lwa_data-ono , lwa_data-pm.
endif.
endloop.

* READ TABLE (2 WAYS)

read table lt_data into lwa_data with key pm = 'C'.


if sy-subrc = 0.
write : / lwa_data-ono , lwa_data_pm .
endif.

(or)

read table lt_data into lwa_data with key ono = 3.


if sy-subrc = 0.
write : / lwa_data-ono , lwa_data-pm .
else.
write : / 'unsucesfull'.
endif.

* clear or refresh and describe table

clear : lt_data.
refresh : lt_data.
*create data : lv_lines type I.

describe table lt_data lines lv_lines.


write : / lv_lines.
clear : lt_data.
describe table lt_data lines lv_lines.
write : / lv_lines.

* SORT

sort lt_data by ono descending pm descending.


*after sort write loop statement

loop at lt_data into lwa_data.


write : / lwa_data-ono , lwa_data-pm.
endloop.

-----------------
program(19)......with headerline

types : begin of lty_data,


ono type zdeono_28,

pm type zdepm_28,
end of lty_data.
data : lt_data type table of lty_data with header line.

lt_data-ono = 1.
lt_data-pm = 'C'.
append lt_data.
clear : lt_data.

lt_data-ono = 2.
lt_data-pm = 'C'.
append lt_data.
clear : lt_data

loop at lt_data.
write : / lt-data-ono , lt_data-pm.
endloop.

_____________________________________

program(20) ........*PARAMETERS

parameter : p_ono type zdeono_28 default 1. " we can use *obligatory means
mandatory

* radiobuttons
parameters : p_r1 type c radiobutton group g1,
p_r2 type c radiobutton group g1,
p_r3 type c radiobutton group g1,
p_r4 type c radiobutton group g1 default 'X'.

* CHECKBOXES
parameters : p_chk1 as checkbox,
P_chk2 as checkbox,
p_chk3 as checkbox.

* SELECTION-SCREEN AND BLOCK -------

data : lv_ono type zdeono_28.

selection-screen : begin of block b1 with frame title text-000.

select-options : s_ono for lv_ono.


parameters : p_r1 type c radiobutton group g1,
p_r2 type c radiobutton group g1,
p_r3 type c radiobutton group g1,
p_r4 type c radiobutton group g1 default 'X'.
parameters : p_chk1 as checkbox,
P_chk2 as checkbox,
p_chk3 as checkbox.
selection-screen : end of block b1.

__________________________________
program(21)...
*parameters sum

data : lv_output type numc2.


parameters : p_input1 type numc2,
p_input2 type numc2.

lv_output = p_input1 + p_input2.


write : / 'output is ' , lv_input.

------------------
* database table

types : begin of lty_data,


ono type zdeono_28,
odate type zdeodate_28,
ta type zdetc_28,
curr type zdecur_28,
end of lty_data.

data : lt_data type table of lty_data.


data : lwa_data type lty_data.
data : lv_ono type zdeono_28,
lv_odate type zdeodate_28,
lv_ta type zdetc_28,
lv_curr type zdecur_28.
parameters : p_ono type zdeono_28.

select ono odate ta curr


from zordeh_28
into table lt_data
where ono = p_ono.

loop at lt_data into lwa_data.


write : / lwa_data-ono , lwa_data-odate , lwa_data-ta , lwa_data-curr.
endloop.

* using read table (at the time of using read table comment the loop statment)

read table lt-data into lwa_data index 1.


if sy-subrc = 0.
write : / lwa_data-ono , lwa_data-odate , lwa_data-ta , lwa_data-curr.
endif.

* another way using SINGLE (comment first select quiery)


select single ono odate ta curr
from zordeh_28
into ( lv_ono , lv_odate , lv_ta , lv_curr )
where ono = p_ono.

if sy-subrc = 0.
write : / lv_ono , lv_odate , lv_ta , lv_curr.
endif.

_________________________________
* range or select-options

types : begin of lty_data,


ono type zdeono_28,
odate type zdeodate_28,
ta type zdetc_28,
curr type zdecur_28,
end of lty_data.

data : lt_data type table of lty_data.


data : lwa_data type lty_data.

data : lv_ono type zdeono_28.

select-options : s_ono for lv_ono .

select ono odate ta curr


from zordeh_28
into table lt_data
where ono in s_ono.

loop at lt-data into lwa_data.


write : / lwa_data-ono , lwa_data-odate , lwa_data-ta , lwa_data-curr.
endloop.

--------------------------
* MULTIPLE DATABASE table
types : begin of lty_data,
ono type zdeono_28,
odate type zdeodate_28,
pm type zdepm_28,
curr type zdecur_28,
end of lty_data.
data : lt_data type table of lty_data.
data : lwa_data type lty_data.
data : lv_ono type zdeono-28.

types : begin of lty_data1,


oin type zdeitemno_28,
icost type zdeoicost_28,
end of lty_data1.
data : lt_data1 type table of lty_data1.
data : lwa_data1 type lty_data1.

types : begin of lty_final,


ono type zdeono_28,
odate type zdeodate_28,
pm type zdepm_28,
curr type zdecur_28,
oin type zdeitemno_28,
icost type zdeoicost_28,
end of lty_final.

data : lt_final type table of lty_final.


data : lwa_final type lty_final.
data : lv_flag type boolean.

select-options : s_ono for lv_ono.

if select lt_data IS NOT INTITIAL


from zordi_28
into table lt_data1
for all entries in lt_data
where ono = lt_data-ono.
endif.

loop at lt_data into lwa_data.


loop at lt_data1 into lwa_data1 where ono = lwa_data1-ono.
lwa_final-ono = lwa_data-ono.
lwa_final-odate = lwa_data-odate.
lwa_final-pm = lwa_data-pm.
lwa_final-curr = lwa_data-curr.
lwa_final-oin= lwa_data1-oin.
lwa_final-icost = lwa_data1-icost.
append lw_final to lt_final.
clear : lwa_final.
lv_flag = 'X'.
endloop.
if lv_flag = ' '.
lwa_final-ono = lwa_data-ono.
lwa_final-odate = lwa_data-odate.
lwa_final-pm = lwa_data-pm.
lwa_final-curr = lwa_data-curr.
append lwa_final to lt_final.
clear : lwa_final.
endif.
clear : lv_flag.
endloop.

sort lt_final by ono.


loop at lt_final into lwa_final.
write : / lwa_final-ono , lwa_final-oin , lwa_final-odate = lwa_data-icost ,
lwa_final-pm , lwa_final-curr.
endloop.

---------------
program...classical_report_join

types : begin of lty_final,'


ono type zdeono_28
odate type zdeodate_28,
pm type zdepm_28,
curr type zdecur_28,
oin type zdeitemno_28,
icost type zdeoicost_28,
end of lty_final.
data : lv_final type table of lty_final.
data : lwa_final type lty_final.
data : lv_ono type zdeono_28.
select-options : s_ono for lv_ono.

*select a~ono a~odate a~pm a~curr b~oin b~icost


*from zordeh_28 as a join zordi_28 as b
*on a~ono = b~ono
*into table lt_final
*where a~ono in s_ono.

select a~ono a~odate a~pm a~curr b~oin b~icost


from zordeh_28 as a left outer join zordi_28 as b
on a~ono = b~ono
into table lt_final
where a~ono in s_ono.

if* uline and vline


write : sy-uline(77).
write : / sy-vline, text-000,
15 sy-vline,text-001,
27 sy-vline,text-002,
41 sy-vline,text-003,
51 sy-vline,text-004,
66 sy-vline,text-005,
77 sy-vline,text-006,
write : / sy-uline(77).

loop at lt_final lwa_final.


write : / sy-vline ,lwa_final-ono under text-000,
15 sy-vline , lwa_final-oin under text-001,
27 sy-vline ,lwa_final-odate under text-002,
41 sy-vline,lwa_data-icost under text-003 ,
51 sy-vline ,lwa_final-pm under text-004,
66 sy-vline ,lwa_final-curr under text-005.
77 sy-vline.
endloop.
-----------------------------
program....MESSAGE

types : begin of lty_data,


ono type zdeono_28,
odate type zdeodate_28,
ta type zdetc_28,
curr type zdecur_28,
end of lty_data.

data : lt_data type table of lty_data.


data : lwa_data type lty_data.
data : lv_flag type c.

parameters : p_ono type zdeono_28.


parameters : p_pm type zdepm_28.
select ono odate ta curr
from zordeh_28
into table lt_data
where ono = p_ono.

* error message(E)
if sy-subec <> 0.
message E000(zmessage).
endif.

*INFORAMTION(I)
if sy-subec <> 0.
message i001(zmessage).
lv_flag = 'X'.

endif.

* information (2nd message)


if sy-subec <> 0.
message i002(zmessage) with p_ono p_pm.
lv_flag = 'X'.
endif.

if lv_flag = ' '.


loop at lt_data into lwa_data.
write : / lwa_data-ono , lwa_data-odate , lwa_data-ta , lwa_data-curr.
endloop.

___________________________________________________________________________________
_________________________________

* CLASICAL REPORT EVENTS


data : lv_odate type zdeodate_28,
lv_pm type zdepm_28,
lv_curr type zdecur_28.

select-options : s_odate for lv_odate no-extension,


s_pm for lv_pm no intervals,
s_curr for lv_curr no intervals modif id cur.

*****( 1st event---INITIALIZATION )---------------------------------------

INITIALIIZATION.
s_odate-sign = 'I'.
s_odate-option = 'BT'.
s_odate-low = sy-datum - 100.
s-odate-high = sy-dattum.
append s_odate.

******( 2nd event ----- AT SELECTION-SCREEN)--------------------------------

AT SELECTION-SCREEN.
if s_pm-low is not initial.
if s_pm-low <> 'C' AND s_pm-low <> 'D' AND s_pm-low <> 'N'.
message e004(message) " tcode-se91
endif.
endif.

*****( 3rd event ----START-OF-SELECTION)-------------------------------------

* first define structure

types : begin of lty_data,


ono type zdeono_28,
odate type zdeodate_28,
pm type zdepm_28,
curr type zdecur_28,
end of lty_data.

data : lt_data type table of lty_data,


lwa_data type lty_data.

START-OF-SELECTION.

select ono odate pm curr


from zordeh_28
into table lt_data
where odate in s_odate
and pm in s_pm and curr in s_curr.

loop at lt_data into lwa_data.


write : / lwa_data-ono , lwa_data-odate , lwa_data-pm , lwa_data-curr.
endloop.

****( 4th event - - ------ END-OF-SELECTION)--------------------------

END-OF-SELECTION.
write : / text-000.

****( 5th event --------- TOP-OF-PAGE )------------------------

* write UNDER & TEXT statement in loop.

TOP-of-PAGE.
write : / text-001 , sy-pagno.

write : / text-002 , 15 text-003 , 27 text-004 , 41 text-005.

s
*****( 6th evevnt ------- END-OF-PAGE)-----------------------------

END-OF-PAGE.
* ***write LINE-COUNT 10(2) in abap editor name
write : / text-006 , sy-pagno.

*****( 7th event --------AT SELECTION-SCREEN


OUTPUT )--------------------------------------
* define parameter checkbox
parameter : p_chk type c as checkbox USER-COMMAND select.

* WRITE MODIF ID CUR IN SELECTION-OPTIONS.


select-options : s_curr for lv_curr modif id cur.

AT SELCTION-SCREEN OUTPUT.
if p_chk = ' '.
loop at screen.
if screen-group1 = 'CUR'.
screen-active = 0.
modify screen.
endif.
endloop.

endif.

if p_chk = 'X'.
loop at screen.
IF screen-group1 = 'CUR'.
screen-active = 1.
modify screen.
endif.
endloop.
endif.

*******( 8th event -------AT SELCTION-SCREEN ON VALUE


REQUEST)---------------------------------------

AT SELECTION-SCREEN ON VALUE REQUEST FOR s_pm-low.


types : begin of lty_pm,
pm type zdepm_28,
desc type desc40,
end of lty_pm.

data : lt_pm type table of lty_pm.


data : lwa_pm type lty_pm.

lwa_pm-pm = 'C'.
lwa_pm-desc = text-008. "credit card payment
append lwa_pm to lt_pm.
clear : lwa_pm.

lwa_pm-pm = 'D'.
lwa_pm-desc = text-009. " debit card payment
append lwa_pm to lt_pm.
clear : lwa_pm.

lwa_pm-pm = 'N'.
lwa_pm-desc = text-010. " Net banking payment
append lwa_pm to lt_pm.
clear : lwa_pm.

* go to t-code se37 ....copy function module F4IF_INT_TABLE_VALUE_REQUEST


* CLICK PATTERN paste the module function in CALL FUNCTION.

CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'


EXPORTING
retfield = 'PM'
dynpprog = sy-repid
dynpnr = sy-dynnr
dynprofield = 'S_PM-LOW'
value_org = 'S'

TABLES
value_tab = lt_pm
EXCEPTIONS
parameter_error = 1
no_value_found = 2
others = 3.

if sy-subrc <> 0.
endif.

* for currency

AT SELCTION-SCREEN ON VALUE REQUEST FOR s_curr-low.

types : begin of lty_cur,


curr type zdecur_28,
desc type desc40,
end of lty_cur.
data : lt_cur type table of lty_cur.
data : lwa_cur type lty_cur.

lwa_cur-cur = 'INR'.
lwa_cur-desc = text-011 "Indian Rupees
append lwa_cur to lt_cur.
clear : lwa_cur.

lwa_cur-cur = 'USD'.
lwa_cur-desc = text-012 " United States Dollers'.
append lwa_cur to lt_cur.
clear : lwa_cur.

CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'


EXPORTING
retfield = 'CUR'
dynpprog = sy-repid
dynpnr = sy-dynnr
dynprofield = 'S_CURR-LOW'
value_org = 'S'
TABLES
value_tab = lt_CUR

EXCEPTIONS
parameter_error = 1
no_value_found = 2
others = 3.

if sy-subrc <> 0.
endif.

******( 9th event AT SELECTION-SCREEN ON HELP REQUEST FOR <FIELD>) " TECHNICAL
INFO --------------------------------------------

* TCODE - SE61
* select --text ....TX
* give name --- zdoccur

* create on editor and write like following.

Check box for currency


selected(True)-Currency field will be visible
deselected(False)- currency field will not be visible

* and save

data : lt_links type table of tline.


data : lt_fields type table of helpval.
data : lwa_fields type helpval.

AT SELECTION-SCREEN ON HELP-REQUEST FOR p_chk.


CALL FUNCTION 'HELP_OBJECT_SHOW'.
EXPORTING
dokclass = 'TX'
dokname = 'zdoccur'

TABLES
links = lt_links
EXCEPTIONS
object_not_found = 1
sapscript_erroe = 2
others = 3

if sy-subrc <> 0.
endif.

*****(10th event -----AT SELECTION-SCREEN ON <field> )


----------------------------------------

AT SELCTION-SCREEN ON s_pm.
if s_pm-low is not initial.
if s_pm-low <> 'C' AND s_pm-low <> 'D' and s_pm-low <> 'N'.
message e005(zmessage). "se91
endif.
endif.

AT SELCTION-SCREEN ON s_curr
-low.
if s_cur-low is not initial.
if s_cur-low <> 'INR' AND s_cur-low <> 'USD'.
message e005(zmessage). "se91
endif.
endif.

___________________________________________________________________________________
_____________________________________________________________________________

**************** INTERACTIVE CLASSICAL REPORTS*******************

types : begin of lty_data,


ono type zdeono_28,
odate type zdeodate_28,
pm type zdepm_28,
curr type zdecur_28,
end of lty_data.

types : begin of lty_data1,


ono type zdeono_28,
oin type zdeoitmno_28,
icost type zdeoicost_28,
end of lty_data1.
data : lt_data type table of lty_data.
data : lwa_data type lty_data.

data : lt_data1 type table of lty_data1,


lwa_data1 type lty_data1.

data : lv_ono type zdeono_28.


selct-options : s_ono for lv_ono.

start-of-selection.
select ono odate pm curr
from zordeh_28
into table lt_data
where ono in s_ono.

loop at lt_data into lwa_data.


write : / lwa_data-ono , lwa_data-odate , lwa_data-pm , lwa_data-curr.
endloop.

at line-selection.
select ono oin icost
from zordi_28
into table lt_data1
where ono = sy-lisel+0(10).

loop at lt_data1 into lwa_data1.


write : / lwa_data1-ono , lwa_data1-oin , lwa_data1-icost.
endloop.

****( AT USER-COMMAND )********

types : begin of lty_data,


ono type zdeono_28,
odate type zdeodate_28,
pm type zdepm_28,
curr type zdecur_28,
end of lty_data.

data : lt_data type table of lty_data.


data : lwa_data type lty_data.

data : lv_ono type zdeono_28.


selct-options : s_ono for lv_ono.

start-of-selection.
select ono odate pm curr
from zordeh_28
into table lt_data
where ono in s_ono.
loop at lt_data into lwa_data.
write : / lwa_data-ono , lwa_data-odate , lwa_data-pm , lwa_data-curr.
endloop.

set pf-status 'FUNCTION'.

AT USER-COMMAND.
if sy-ucomm = 'ASCENDING'.
sort lt_data by ono.
loop at lt_data into lwa_data.
write : / lwa_data-ono , lwa_data-odate , lwa_data-pm , lwa_data-curr.
endloop.

if sy-ucomm = 'DESCENDING'.
sort lt_data by ono DESCENDING.
loop at lt_data into lwa_data.
write : / lwa_data-ono , lwa_data-odate , lwa_data-pm , lwa_data-curr.
endloop.

**********( TOP-OF-PAGE DURING LINE-SELECTION )

types : begin of lty_data,


ono type zdeono_28,
odate type zdeodate_28,
pm type zdepm_28,
curr type zdecur_28,
end of lty_data.

types : begin of lty_data1,


ono type zdeono_28,
oin type zdeoitmno_28,
icost type zdeoicost_28,
end of lty_data1.

data : lt_data type table of lty_data.


data : lwa_data type lty_data.

data : lt_data1 type table of lty_data1,


lwa_data1 type lty_data1.

data : lv_ono type zdeono_28.


selct-options : s_ono for lv_ono.

start-of-selection.
select ono odate pm curr
from zordeh_28
into table lt_data
where ono in s_ono.

loop at lt_data into lwa_data.


write : / lwa_data-ono , lwa_data-odate , lwa_data-pm , lwa_data-curr.
endloop.

at line-selection.
select ono oin icost
from zordi_28
into table lt_data1
where ono = sy-lisel+0(10).

loop at lt_data1 into lwa_data1.


write : / lwa_data1-ono , lwa_data1-oin , lwa_data1-icost.
endloop.

TOP-OF-PAGE.
data : lv_pm type zdepm_28.

select-options : s_pm for lv_pm NO INTERVALS.

select pm ta
from zordeh_28
into table lt_data
where pm in s_pm.

sort lt_data by pm.

loop at lt_data into lwa_data.

AT FIRST .
write : / text-000. " the sum based upon paymentmode is as follows
ENDAT.

AT NEW pm.
write : / lwa_data-pm.
ENDAT.

AT END OF pm.
SUM.
write : lwa_data-ta.

AT LAST.
write : / text-001. " end of collection
ENDAT.

endloop.

-----------------------------------------------------------------------------------
------------------------------

Types : begin of lty_data,


ono type zdeono_28,
pm type zdepm_28,
ta type zdetc-28,
end of lty_data.

Types : begin of lty_data1,


pm type zdepm_28,
ono type zdeo_28,
ta type zdetc-28,
end of lty_data1.

data : lt_data type table of lty_data.


data : lwa_data type lty_data.
data : lt_data1 type table of lty_data1.
data : lwa_data1 type lty_data1.

data : lv_pm type zdepm_28.

select-options : s_pm for lv_pm NO INTERVALS.

select pm ta
from zordeh_28
into table lt_data
where pm in s_pm.

loop at lt_data into lwa_data.


lwa_data1-pm = lwa_data-pm.
lwa_data1-ono = lwa_data-ono.
lwa_data1-ta = lwa_data-ta.
append lwa_data1 to lt_data1.
clear : lwa_data1.

sort lt_data1 by pm.

loop at lt_data1 into lwa_data1.

AT FIRST .

write : / text-000.

" the sum based upon paymentmode is as follows


ENDAT.

AT NEW pm.
write : / lwa_data1-pm.
ENDAT.

AT END OF pm.
SUM.
write : lwa_data1-ta.

AT LAST.
write : / text-001. " end of collection
ENDAT.

endloop.

___________________________________________________________________________________
_________________________

*********DATABASE OPERATIONS************
**insert

types : begin of lty_ono,


ono type zdeono_28,
end of lty_ono.

data : lt_ono type table of lty_ono.


data : lwa_ono type table lty_ono.

Data : lwa_data type zordeh_28.

parameters : p_ono type zdeono_28,


p_odate type zdeodate_28,
p_pm type zdepm_28,
p_ta type zdetc_28,
p_curr type zdecur_28.

parameters : p_r1 type c radiobutton group r1,


p_r2 type c radiobutton group r1,
p_r3 type c radiobutton group r1,
p_r4 type c radiobutton group r1 default 'X'.

start-of-selection.

if p_r1 = 'X'.
lwa_data-ono = p_ono.
lwa_data-odate = p_odate.
lwa_data-pm = p_pm.
lwa_data-ta = p_ta.
lwa_data-curr = p_curr.

insert zordeh_28 from lwa_data.

if sy-subrc = 0.
write : text-000. "recored inserted sucessfully
else.
write : text-001. "record failed to insert
endif.

* for at selection-screen write structure of ono internal table nd work area.

at selection-screen.

if p_r1 = 'X'.
select ono
from zordeh_28
into table lt_ono
where ono = p_ono.

(or)

select single ono


from zordeh_28
into lwa_ono
where ono = p_ono.

if sy-subrc = 0.
message e003(zmessage) with p_ono . "order number & already exists
endif.
endif.

*****DELETE***

Data : lwa_data type zordeh_28.

parameters : p_ono type zdeono_28 obligatory,


p_odate type zdeodate_28 modif id A1,
p_pm type zdepm_28 modif id A2,
p_ta type zdetc_28 modif id A3,
p_curr type zdecur_28 modif id A4.

parameters : p_r1 type c radiobutton group r1 user-command ABC,


p_r2 type c radiobutton group r1,
p_r3 type c radiobutton group r1,
p_r4 type c radiobutton group r1 default 'X'.

start-of-selection.

if p_r2 = 'X'.
lwa_data- ono = p_ono.

DELETE zordeh_28 from lwa_data.


if sy-subrc = 0.
write : text-002. " record deleted sucesfully
endif.
endif.

at selection-screen.

if p_r2 = 'X'.
select single ono
from zordeh_28
into lwa_ono
where ono = p_ono.

if sy-subrc <> 0.
message e007(zmessage) with p_ono.
endif.
endif.

at selection-screen output.

if p_r2 = 'X'.
loop at screen.

if screen-group1 = 'A1' and screen-group1 = 'A2' and screen-group1 = 'A3' and


screen-group1 = 'A4'.
screen-active = 0.
modify screen.
endif.
endloop.
endif.

********update***********

types : begin of lty_display,


odate type zdeodate_28,
pm type zdepm_28,
curr type zdecur_28.
data : lwa_display type lty_display.

start-of-selection.

if p_r3 = 'X'.
lwa_data-ono = p_ono.
lwa_data-odate = p_odate.
lwa_data-pm = p_pm.
lwa_data-ta = p_ta.
lwa_data-curr = p_curr.

update zordeh_28 from lw_data.

if sy-subrc = 0.
write : text-003.
endif.endif.

at selection-screen.

if p_r3 = 'X'.
select single ono
from zordeh_28
into lwa_ono
where ono = p_ono.

if sy-subrc <> 0.
message e007(zmessage) with p_ono.
else.
select single odate pm ta curr
from zordeh_28
into lwa_display
where ono = p_ono.
endif.
endif.

at selection-screen output.

if p_r3 = 'X'.
p_odate = lwa_display-odate.
p_pm = lwa_display-pm.
p_curr = lwa_display-curr.
endif.

*******MODIFY *********

start-of-selection.
if p_r4 = 'X'.
lwa_data-ono = p_ono.
lwa_data-odate = p_odate.
lwa_data-pm = p_pm.
lwa_data-ta = p_ta.
lwa_data-curr = p_curr.

modify zordeh_28 from lw_data.

if sy-subrc = 0.
write : text-004, ':', p_ono. " record modified sucesfully
endif.endif.

at selection-screen.

if p_r4 = 'X'.
SELECT single odate pm ta curr
from zordeh_28
into lwa_display
where ono = p_ono.

if sy-subrc <> 0.
clear : lwa_display.
endif.
endif.

at selection-screen output.

if p_r4 = 'X'.
p_odate = lwa_display-odate.
p_pm = lwa_display-pm.
p_ta = lwa_display-ta.
p_curr = lwa_display-curr.
endif.

You might also like