Thursday 10 May 2012

Sap ABAP for Bi ...for practice


*&---------------------------------------------------------------------*
*& Report  ZABAP_002
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT  ZABAP_002 NO STANDARD PAGE HEADING.

*
*write : /8(28) 'GOD IS GREAT' COLOR 5 right-justified.
*skip 5.
*write : / 'India is my country' color 7.
*
*skip  3.
*position 28.
*write : 'Third statement' color 3.
*uline.
*
*data type   d. length  d. value
* I - Integer    1         0
* c - char       1         space
*n - numerical   1         0
*d - Date        8         00000000
*t - time        6         000000
*p - Packed decimal
*f - Floating decimal
* String - Allocates memory during run time
* default data type is c
*
* parameters - To receive values during run time
*String functions
*
**** Concatenate
**** split
**** Translate
**** offset
**** search
**** strlen
**** shift
**** condense
**** replace
**** overlay
**** if, nested if, case
*
*Today's topics
*** Do, DONE
*** While  DONE
*** usage of FM in programs - Done
*** system variables
*** Message - dONE
*** radio button - DONE
*** Check box - dONE
*** Selection OPtions - Done
*** Ranges - Done
*
*do 12 times.
*write : / 'Rama' .
*enddo.
*
*****************************************************
*********** first 10 multiples using DO statement
*****************************************************
*
*
*parameters : a type i.
*data : b type i, res type i.
*
*b = 1.
*do 10 times.
*res = a * b.
*write: / a, '*', b, '=', res.
*b = b + 1.
*enddo.
*
*
*b = 1.
*do 10 times.
*res = a * sy-index.
*write: / a, '*', sy-index, '=', res.
*
*enddo.
*
*****************************************************
*********** write a given statement 10 times in alternate colors
*****************************************************
*
*data : a type i, b type i.
*
*a = 1.
*do 10 times.
*
*b = ( a mod 2 ) + 6.
*write : / 'God is great' color = b.
*a = a + 1.
*
*enddo.
*
**data : a type i, b type i.
**
**a = 1.
**do 10 times.
**b = ( a mod 2 ).
**if b = 1.
**write : / 'God is great' color 7.
**else.
**write : / 'God is great' color 4.
**endif.
**a = a + 1.
**
**enddo.
*
*
*****************************************************
*********** While statement
*****************************************************
*
*data : n type i.
*n = 5.
*
*while n < 702.
*  write : / n.
*  n = n + 5.
*endwhile.
*
*
*
*data : n type i.
*
*n = 1.
*
*while n LE 10.
*
*  IF N = 5.
*  N = N + 1.
**    CONTINUE.
**EXIT.
*  ELSE.
*    WRITE: / N.
*  ENDIF.
*  N = N + 1.
*
*ENDWHILE.
*
***************************************************************
*DATA : STR TYPE STRING VALUE 'RAMESH',
*       STR1 TYPE STRING,
*       K TYPE I, n type i.
*
*K = STRLEN( STR ) .
*
*while n le k.
*  str1 = str+0(n).
*  write: / str1.
*  n = n + 1.
*endwhile.
*
* k = k - 1.
*
*WHILE  k GT 0.
*  STR1 = STR+0(K).
*  K = K - 1.
*  WRITE: / STR1.
*ENDWHILE.


*****************************************************
*********** Determine if a given number is prime
*****************************************************

*parameters : num type i.
*
*data : a type i, b type i, res type i.
*
*
*a =  num / 2.
*
*b = 3.
*while b le a.
*
*res = num mod b.
*
*if res = 0.
*write : 'Given number is Not prime'.
*exit.
*else.
*b = b + 1.
*endif.
*
*endwhile.
*
*if res <> 0.
*write : 'Given number is prime'.
*endif.

*parameters : num type i.
*data : a type i.
*
*a = ( num + 5 ) / 10.
*
*write : / a, 'using / as divison operator' .
*
*a = ( num + 5 ) div 10.
*
*write : / a, 'using DIV as divison operator' .
*
*a = ( num + 5 ) div 10 * 10.
*
*WRITE : / A.




*****************************************************
*********** using function modules - Random_I4
*****************************************************

*parameters : p_low type i,
*p_high type i.

*DATA : COL TYPE I, POS TYPE I, ln type i.
*
*DO 60 TIMES.
*CALL FUNCTION 'RANDOM_I4'
* EXPORTING
*   RND_MIN         = 1
*   RND_MAX         = 7
* IMPORTING
*   RND_VALUE       =  COL   .
*
*CALL FUNCTION 'RANDOM_I4'
* EXPORTING
*   RND_MIN         = 1
*   RND_MAX         = 28
* IMPORTING
*   RND_VALUE       =  ln   .
*
*
*CALL FUNCTION 'RANDOM_I4'
* EXPORTING
*   RND_MIN         = 1
*   RND_MAX         = 90
* IMPORTING
*   RND_VALUE       =  pos   .
*
**new-line.
*skip to line ln.
*   WRITE at /pos 'GOD is great' color = col .
*
*ENDDO.



*****************************************************
*********** FM - compute age in yrs, months
******months_between_two_dates
*****************************************************


*Parameters : DOB TYPE D.
*DATA : YEAR TYPE I, B TYPE I, MON TYPE I.
*
*
*CALL FUNCTION 'MONTHS_BETWEEN_TWO_DATES'
*  EXPORTING
*    I_DATUM_BIS         =  SY-DATUM
*    I_DATUM_VON         =  DOB
**   I_KZ_INCL_BIS       = ' '
* IMPORTING
*   E_MONATE            =   MON .
*
*YEAR = MON DIV 12 .
*MON = MON MOD 12.
*
*   WRITE : /2 'you are', year, 'yrs', MON, 'months young' .

*****************************************************
*********** using fuction keys to call FMs
*****************************************************

*START-OF-SELECTION.
*Write : / 'F4 - Calculator',
*        / 'F5 - Date',
*        / 'F6 - Open transaction SE11',
*        / 'F9 - Leave Program'.
*
*end-of-selection.
*at pf4.
*CALL FUNCTION 'FITRV_CALCULATOR' .
*
*AT PF5.
*CALL FUNCTION 'F4_DATE' .
*
*AT PF6.
*CALL TRANSACTION 'SE11'.
*
*AT PF9.
*LEAVE PROGRAM.


*****************************************************
*********** FM - DATE TO PERIOD CONVERT
*****************************************************

*DATA : fPd(3) type n,
*       fyr(4) type n,
*       fiscper(7) type n.
*
*CALL FUNCTION 'DATE_TO_PERIOD_CONVERT'
*  EXPORTING
*    I_DATE               = '20110804'
**   I_MONMIT             = 00
*    I_PERIV              = 'V3'
* IMPORTING
*   E_BUPER              = fpd
*   E_GJAHR              = fyr
*          .
*
*concatenate fyr fpd into fiscper.
*
*write: / fiscper.

*write: sy-uline .

******************************************************
************ Using parameters in select statement
******************************************************


Data : wa type kna1,
       itab type table of kna1.

Parameters : P_kunnr type kna1-kunnr.

start-of-selection.

select *
from KNA1
INTO TABLE ITAB
WHERE KUNNR = P_KUNNR.

IF SY-SUBRC = 0.

lOOP AT ITAB INTO WA.
WRITE: / WA-KUNNR, WA-NAME1, WA-ORT01.
ENDLOOP.

ENDIF.

END-OF-SELECTION.

at selection-screen.

select single *
from kna1
into wa WHERE KUNNR = P_KUNNR.

if sy-subrc NE 0.
Message 'Invalid customer. Please recheck' type 'E'.
endif.

******************************************************
************ Using select-options in select statement
******************************************************
*
*
*TABLES : kna1.
*
*data : wa type kna1,
*itab type table of kna1.
*
*SELECT-OPTIONS s_kunnr FOR kna1-kunnr.
*
*Select *
*from kna1
*into table itab
*where kunnr in s_kunnr.
*
*loop at itab into wa.
*write: / wa-kunnr, wa-name1, wa-ort01 .
*endloop.



*****************************************************
*********** Using Ranges
*****************************************************


*TABLES : kna1.
*
*data : wa type kna1,
*itab type table of kna1.
*
*ranges : RN FOR kna1-kunnr.
*
*RN-SIGN = 'I'.
*RN-OPTION = 'BT'.
*RN-LOW = '0000001001'.
*RN-HIGH = '0000005000'.
*
*APPEND RN.
*
*
*Select *
*from kna1
*into table itab
*where kunnr in RN.
*
*loop at itab into wa.
*write: / wa-kunnr, wa-name1, wa-ort01 .
*endloop.

*****************************************************
*********** Radio button
*****************************************************

*
*Parameters : a type i, b type i.
*
*selection-screen begin of block b1 with frame.
*PARAMETERS : rb1 type c radiobutton group RB ,
*             rb2 TYPE C RADIOBUTTON GROUP RB.
*selection-screen end of block b1 .
*
*data : c type i.
*
*IF rb1 = 'X'.
*  c = a + b .
*  Write: / ' sum of a & b is', c color 7.
*else.
*  c = a * b.
*  Write: / ' product of a & b is ', c color 5.
*endif.


*****************************************************
*********** Check box
*****************************************************

*Parameters : a type i, b type i.
*
*selection-screen begin of block b1 with frame.
*PARAMETERS : ch1 type c as checkbox,
*             ch2 type c as checkbox.
*selection-screen end of block b1 .
*
*data : c type i.
*
*IF ch1 = 'X'.
*  c = a + b .
*  Write: / ' sum of a & b is', c color 7.
*  endif.
*IF ch2 = 'X'.
*  c = a * b.
*  Write: / ' product of a & b is ', c color 5.
*endif.


*****************************************************
*********** Syste Variables
*****************************************************


write : sy-uzeit.

No comments:

Post a Comment