0% found this document useful (0 votes)
16 views13 pages

SAPGROOVY

The document contains code snippets and examples demonstrating the use of Groovy programming language. It shows how to define classes and methods, perform operations on lists and strings, and includes examples of customer account management and login validation code.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views13 pages

SAPGROOVY

The document contains code snippets and examples demonstrating the use of Groovy programming language. It shows how to define classes and methods, perform operations on lists and strings, and includes examples of customer account management and login validation code.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 13

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

*& Report Z46341316PMMG3


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

REPORT Z46341316PMMG3.
TYPES: BEGIN OF TYAIRLINES,
SCCARRID TYPE SCARR-CARRID,
CARRNAME TYPE SCARR-CARRNAME,
SPCARRID TYPE SPFLI-CARRID,
CONNID TYPE SPFLI-CONNID,
COUNTRYFROM TYPE SPFLI-COUNTRYFR,
COUNTRYTO TYPE SPFLI-COUNTRYTO,
END OF TYAIRLINES.

DATA ITAIRLINES TYPE STANDARD TABLE OF TYAIRLINES.


DATA WAAIRLINES LIKE LINE OF ITAIRLINES.

SELECT SC~CARRID SC~CARRNAME


SP~CARRID SP~CONNID SP~COUNTRYFR SP~COUNTRYTO
INTO TABLE ITAIRLINES
FROM SCARR AS SC
INNER JOIN
SPFLI AS SP
ON SC~CARRID = SP~CARRID.

LOOP AT ITAIRLINES INTO WAAIRLINES.


PERFORM DISP.
ENDLOOP.
SKIP.

FORM DISP.
WRITE : / WAAIRLINES-SCCARRID ,
9 WAAIRLINES-CARRNAME,
28 WAAIRLINES-SPCARRID ,
38 WAAIRLINES-CONNID,
48 WAAIRLINES-COUNTRYFROM,
58 WAAIRLINES-COUNTRYTO.
ENDFORM.

Inner join
*&---------------------------------------------------------------------*
*& Report Z46341316PMMG2
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT Z46341316PMMG2.
TYPES: BEGIN OF TYDEPT,
DEPARTNO TYPE Z46341316DEPT3-DEPARTNO,
DEPTNAME TYPE Z46341316DEPT3-DEPTNAME,
EMPID TYPE Z46341316EMP1-EMPID,
EMPNAME TYPE Z46341316EMP1-EMPNAME,
EMPSALARY TYPE Z46341316EMP1-EMPSALARY,
EMPPHONE TYPE Z46341316EMP1-EMPPHONE,
EMPDEPARTNO TYPE Z46341316EMP1-DEPARTNO,
END OF TYDEPT.

DATA IT_TYDEPT TYPE STANDARD TABLE OF TYDEPT.


DATA WA_TYDEPT TYPE TYDEPT.

WRITE: 'DEPT-NO',18 'EMP ID',30 'EMP NAME',45 'EMP SALARY',59 'EMP PHONE
',70 'EMPLOYEE DEPARTNO'.

SELECT DE~DEPARTNO DE~DEPTNAME EM~EMPID EM~EMPNAME EM~EMPSALARY EM~EMPPHONE


EM~DEPARTNO
INTO TABLE IT_TYDEPT
FROM Z46341316DEPT3 AS DE
INNER JOIN Z46341316EMP1 AS EM
ON DE~DEPARTNO = EM~EMPID.

LOOP AT IT_TYDEPT INTO WA_TYDEPT.


PERFORM DISP.
ENDLOOP.
SKIP.

FORM DISP.
WRITE : / WA_TYDEPT-DEPARTNO,
18 WA_TYDEPT-EMPID,
30 WA_TYDEPT-EMPNAME,
45 WA_TYDEPT-EMPSALARY,
59 WA_TYDEPT-EMPPHONE,
70 WA_TYDEPT-EMPDEPARTNO.
ENDFORM.

Sir report assignment 3

*&---------------------------------------------------------------------*
*& Report Z46341316A1
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT Z46341316A1.
WRITE:/ 'User name:',SY-UNAME(12),'DATE:',SY-DATUM.
write:/'REPORT NAME:',SY-REPID(40),'PAGE-NO:',SY-CPAGE.
TABLES Z46341316DEPT.
data: it_dept TYPE STANDARD TABLE OF Z46341316DEPT INITIAL SIZE 0,
wa_dept TYPE Z46341316DEPT.
PARAMETERS s_dept TYPE Z46341316DEPT-DEPTNO.
START-OF-SELECTION .
select * from Z46341316DEPT INTO TABLE it_dept WHERE deptno = s_dept.
if sy-subrc <> 0.
WRITE:/ 'There is no data selected for input value'.
ENDIF.
end-of-SELECTION.
WRITE:/ 'DeptNo','DEPARTMENT','LOCATION'.
loop at it_dept INTO wa_dept .
WRITE:/ wa_dept-deptno,wa_dept-dname,wa_dept-loc.
ENDLOOP.

Assignment 2

REPORT Z46341316A2.
TABLES Z46341316DEPT.
data: it_dept TYPE STANDARD TABLE OF Z46341316DEPT INITIAL SIZE 0,
wa_dept TYPE Z46341316DEPT.
select-options: s_dept for Z46341316DEPT-DEPTNO.
START-OF-SELECTION .
select * from Z46341316DEPT INTO TABLE it_dept WHERE deptno = s_dept.
if sy-subrc <> 0.
WRITE:/ 'There is no data selected for input value'.
ENDIF.
end-of-SELECTION.
WRITE:/ 'DeptNo','DEPARTMENT NAME','LOCATION'.
loop at it_dept INTO wa_dept .
WRITE:/ wa_dept-deptno,wa_dept-dname,wa_dept-loc.
ENDLOOP.

Primary keys
REPORT Z46341316PMG6.
TABLES Z46341316EMP3.
PARAMETERS pempid TYPE Z46341316EMP3-EMPID.
PERFORM selectfromdb.
SKIP.

FORM selectfromdb.
SELECT *
FROM Z46341316EMP3 "into a fieldstring like
" SCARR, implied
WHERE EMPID = pempid.
ENDSELECT.
WRITE: / 'SY-SUBRC:' , sy-subrc.
IF sy-subrc = 0.
PERFORM disp.
ELSE.
WRITE: /'empid does not exist:', pempid.
ENDIF.
ENDFORM.

FORM disp.
WRITE: /'Empid is:', Z46341316EMP3-EMPID,
/ 'EMPLOYEE NAME:', Z46341316EMP3-EMPNAME,
/ 'EMPLOYEE SALARY:', Z46341316EMP3-EMPSALARY,
/ 'EMPLOYEE PHONE:', Z46341316EMP3-EMPPHONE,
/ 'EMPLOYEE LOCATION:', Z46341316EMP3-EMPLOC.
ENDFORM.
calc
REPORT Z46341316PMGCALC.
PARAMETERS: NUM1 TYPE I,
NUM2 TYPE I,
INPUT3 TYPE C.
DATA: RES TYPE I.
CALL FUNCTION 'Z46341316FM2'
EXPORTING
num1 = NUM1
num2 = NUM2
input3 = INPUT3
IMPORTING
RES = RES.

Assignment 2
SE14 FOR DATABASE CHANGES

GROOVY

/*
class Cust{
def final cbname ="kotak"
def cname
def caddr
def caccno
def cbal
def Cust(cname, caddr, caccno, cbal)
{
this.cname=cname
this.caddr=caddr
this.caccno=caccno
this.cbal=cbal
}
def deposit(damt)
{
cbal=cbal+damt
println "the balance after deposit $damt is: $cbal"
}
def withdraw(wamt)
{
if(wamt<cbal){
cbal = cbal-wamt
println "the withdraw ammount $wamt after withdrawal balance is: $cbal"}
else {
println "the withdraw amount $wamt is not possible you have insufficient
balance: $cbal"
}
}
def balenq()
{
println "the check bal is: $cbal"
}
def display()
{
println "Customer name: $cname"
println "Customer address: $caddr"
println "Customer account no: $caccno"
println "Customer balance: $cbal"
}
}
c1= new Cust('SIYA','MUMBAI',40019,2000)
c1.balenq()
c1.deposit(3000)
c1.withdraw(6000)
c1.withdraw(2000)
c1.display()
c1.balenq()

c2= new Cust('SAM','MUMBAI',40020,3000)


c2.balenq()
c2.deposit(4000)
c2.withdraw(6000)
c2.withdraw(1000)
c2.balenq()
c2 .display()
*/

/*

def find_avg_marks(name,marks)
{
println "HI $name"
sumofmarks=marks.sum()
totalsub=marks.size()
avgmarks=sumofmarks/totalsub
return avgmarks
}
def computegrde(avgmarks)
{
if (avgmarks>=80)
{
grade = 'A'
}
else if (avgmarks<=75)
{
grade = 'B'
}
else if (avgmarks<=60)
{
grade = 'C'
}
else
{
grade = 'FAILED!!'
}
return grade
}
println "#"*30
marks=[40,78,90,80,34,56]
avgmarks=find_avg_marks('SAM',marks)
println"your average marks is: $avgmarks"
grade=computegrde(avgmarks)
println"your grade is $grade"
println "#"*30
marks=[45,98,78,90,56,78]
avgmarks=find_avg_marks('John',marks)
println"your average marks is: $avgmarks"
grade=computegrde(avgmarks)
println"your grade is $grade"

//function to find avg marks


def find_avg_marks(name,marks){
println "Hi $name"
sum_of_marks=marks.sum() //list1=[10,20,30]
total_sub=marks.size()
avg_marks=sum_of_marks/total_sub
//println "your avg marks $avg_marks"
return avg_marks}
//calculate the grade
def compute_grade(avg_marks){
if (avg_marks>=80){
grade='A' }
else if (avg_marks>=60) {
grade='B'
}
else if (avg_marks>=50){
grade='C'}
else {
grade='F' }
return grade }
marks=[45,67,89,98,90,71]
avg_marks=find_avg_marks('Bob',marks)
println "your avg marks $avg_marks"
grade=compute_grade(avg_marks)
println "Your grade is: $grade"
println "#"*40
marks=[87,89,89,98,90,81]
avg_marks=find_avg_marks('Siri',marks)
println "your avg marks $avg_marks"
grade=compute_grade(avg_marks)
println "Your grade is: $grade"

atmpin=7890
i=1
pin= System.console()readLine"enter the pin:"
pin = pin as int

while(i<4)
if (pin==atmpin)
{
println "Logged in sucessfully."
}
else
{
println "limit exceeded!!!"
}
i++
*/

/*
class Cust {
//customer application
def final cbname="SBI" //static variables
def cname
def caddr
def caccno
def cbal
def Cust(cname, caddr, caccno, cbal)
{
this.cname=cname
this.caddr=caddr //instance variables
this.caccno=caccno
this.cbal=cbal
}
def deposit(damt)
{
cbal=cbal+damt
println "the balance of the accoount after deposit is $cbal."
}
def withdraw(wamt)
{
if (wamt<cbal)
{
cbal=cbal-wamt
println "the withdraw amount is $wamt and after withdrawal the
balance is $cbal."
}
else
{
println "the withdrawal $wamt is not possible you have Insufficient
bal"
}
}
def balenq()
{
println "the balance of the account is :$cbal."
}
def display()
{
println "customer name :$cname"
println "customer address :$caddr"
println "customer accoount number :$caccno"
println "customer balance :$cbal"
}
}
c1=new Cust("John","Hyd",1001,1000)
c1.balenq()
c1.deposit(2000)
c1.balenq()
c1.withdraw(5000)
c1.withdraw(1000)
c1.balenq()
c1.display()

c2=new Cust("siri","pune",1002,2000)
c2.balenq()
c2.display()
*/

/*
atm_pin =3112
i=1
while(i<4)
{pin = System.console().readLine"enter the pin:"
pin = pin as int
if (atm_pin==pin)
{
println "logged in succesfully"
break
}
else if (i==3)
{
println"limit exceeded!!"
}
i++
}
*/

strng1 = [10,20,30,40,'helo']
//println "Your strng is: $strng1"
//strng2 = System.console().readLine"enter the string: "
println strng1.add("world")
println strng1
println strng1.size()
//println "after concat your string is: $strng1"

/*
k_list =[20,103,'hello','groovy',90,45]
println "#"*30 //repetetion operator
println k_list.size() //gives the length of array
println k_list.count(1) // counts the occurance of element in array
println k_list.remove(2) //removes the given index
println k_list
println k_list.pop() // deletes the firts value
println k_list.reverse() // reverses the list
println k_list.add("ulist") // append the value at the end of array
println k_list
println k_list.contains(55) // provides boolean output after checking if
the element is present or not present in the array
println k_list.push(78) // appends the provided value on the first index of
the array
println k_list.drop(2) //deletes the first given values, here first 2.
*/

mylist =[10,20,"A","SAM","ON",89,'&']
println "#"*30
println mylist
println mylist.getClass()
println "#"*30

for (i in mylist)
{
println i
}
println "#"*30
// accessing single vlaues
println mylist[0]
println mylist[-1]
println "#"*30
//accessing multiples vlaues
println mylist[0..3]
//length of the list
len = mylist.size()
println "total length of mylist is: $len"

rev = mylist.reverse()
println "total length of mylist is: $rev"
*/
/*
println "#"*30 //repetetion operator
println mylist.size() //gives the length of array
println mylist.count(10) // counts the occurance of element in array
println mylist.remove(2) //removes the given index
println mylist
println mylist.pop() // deletes the firts value
println mylist.reverse() // reverses the list
println mylist.add("ulist") // append the value at the end of array
println mylist
println mylist.contains(55) // provides boolean output after checking if
the element is present or not present in the array
println mylist.push(78) // appends the provided value on the first index of
the array
println mylist.drop(2) //deletes the first given values, here first 2.

println "###############file handling#####################"


file1=new File('test2.txt').getText()
println file1

file1=new File('test2.txt')
for (i in file1.readLines())
{
if (i =~ /groovy/)
{
println i
}
}

file1=new File('test1.txt')
for (i in file1.readLines())
{
//file1.write("groovy\npython\n")
if (i =~ /[6-7][0-9]{9}/)
{
println i
}
}

strng1="groovyscript"
strng2="Hello"
println strng1[0]
println strng1[-1]
len = strng1.length()
rev = strng1.reverse()
println "the length of $strng1 is $len"
println "the reverse of $strng1 is $rev"
print "the substring of $strng1 from range (0,5) is:"
println (strng1.substring(0,5))
print "the index of $strng1 of y is:"
println(strng1.indexOf('y'))
println(strng1.toLowerCase())
println(strng1.toUpperCase())
println(strng1.split('1'))
println(strng1.replace('o','m'))

strng1="groovyscript"
strng2="Hello"
println strng1[0]
println strng1[-1]
len = strng1.length
println strng1[0..5]
*/

num1=System.console().readLine"Enter your num1:"


num1 as int
num2=System.console().readLine"Enter your num2:"
num2 as int
println "the addition of $num1 and $num2 is: ${num1 + num2}"
println "the subtraction of $num1 and $num2 is: ${num1 - num2}"
println "the multiplication of $num1 and $num2 is: ${num1 * num2}"
println "the mode of $num1 and $num2 is: ${num1 % num2}"
println "the division of $num1 and $num2 is: ${num1 / num2}"
println "the power of $num1 and $num2 is: ${num1 ** num2}"
println "\n\n\n\n\t\t\t\t\tWHILE LOOP\n\t\t\t\t\t***************\n"
i=1
while(i<=10)
{
println i
i++
}
println "Bye"

println "\n\n\n\n\t\t\t\t\tWHILE LOOP\n\t\t\t\t\t***************\n"


i=10
while(i>=1)
{
println i
i--
}
println "Bye"

i = 1
while (i<=10)
{
if (i==5)
{
i++
continue
}
println i
i++
}

You might also like