Saturday, 7 April 2012

GETTING STARTED WITH ABAP.....

Open the ABAP Editor by using the Transaction Code  SE38 . Give a   Program name starting with Z/Y (customer namespace) and click on Create . Give a small title , choose type 1 program ( report program )
and save it in local object or any package.  Then write the  program code , save it (Ctrl + S) , Check it ( Ctrl + F2)  for syntax check , activate it  (Ctrl + F3)  and  then execute it  (F8) . To come back to editor press (F3).

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

########### INITIAL KEY WORD ###########

data : flag type c value 's'.
if flag is initial.
  write :/ 'flag is initial'.
else.
  write :/ 'flag is not initial'.
endif.
uline.
clear flag.
if flag is initial.
  write :/ 'flag is initial'.
else.
  write :/ 'flag is not initial'.
endif.

############## MATH FUNCTIONS ##############

data : x type p decimals 2.
data : y type p decimals 2 value '-4.67'.

x = abs( y ). write :/ 'abs=', x.
x = ceil( y ). write :/ 'ceil=', x.
x = floor( y ). write :/ 'floor=', x.
x = sign( y ). write :/ 'sign=', x.
x = frac( y ). write :/ 'frac=', x.
x = trunc( y ). write :/ 'trunc=', x.

########### SELECT-OPTIONS ################

data : wa_sflight type sflight.
select-options : s_carrid for wa_sflight-carrid.
if 'BA' in s_carrid.
  write :/ 'BA selected'.
  else.
    write :/ 'BA not selected'.
    endif.

############## SELECT-OPTION ################

DATA WA_CARRID TYPE SPFLI-CARRID.

SELECT-OPTIONS AIRLINE FOR WA_CARRID.

WRITE: 'Inside', 'Outside'.

SELECT CARRID FROM SPFLI INTO WA_CARRID.
  IF WA_CARRID IN AIRLINE.
    WRITE: / WA_CARRID UNDER 'Inside'.
  ELSE.
WRITE: / WA_CARRID UNDER 'Outside'.
ENDIF.
ENDSELECT.

*********** RANGE INPUT BY ELECT-OPTIONS ******************

tables : spfli.
select-options : S_carrid for spfli-carrid.
TYPES : BEGIN OF TAB1,
        CARRID TYPE SPFLI-CARRID,
        CONNID TYPE SPFLI-CONNID,
        COUNTRYFR TYPE SPFLI-COUNTRYFR,
        CITYFROM TYPE SPFLI-CITYFROM,
        AIRPFROM TYPE SPFLI-AIRPFROM,
        COUNTRYTO TYPE SPFLI-COUNTRYTO,
        CITYTO TYPE SPFLI-CITYTO,
        AIRPTO TYPE SPFLI-AIRPTO,
        DISTANCE TYPE SPFLI-DISTANCE,
      END OF TAB1.

DATA : IT_FLIGHT1 TYPE TABLE OF TAB1,
       WA_FLIGHT1 TYPE TAB1.

INITIALIZATION.
S_CARRID-LOW = 'AA'.
S_CARRID-HIGH = 'ZZ'.
S_CARRID-SIGN = 'I'.
S_CARRID-OPTION = 'BT'.
APPEND S_CARRID.

START-OF-SELECTION.
SELECT CARRID
       CONNID
       COUNTRYFR
       CITYFROM
       AIRPFROM
       COUNTRYTO
       CITYTO
       AIRPTO
       DISTANCE FROM SPFLI INTO TABLE IT_FLIGHT1 UP TO 20 ROWS WHERE CARRID IN S_CARRID .

*SELECT * FROM SPFLI INTO CORRESPONDING FIELDS OF TABLE IT_FLIGHT1 UP TO 20 ROWS.

  LOOP AT IT_FLIGHT1 INTO WA_FLIGHT1.
    WRITE :/ WA_FLIGHT1-CARRID,
             WA_FLIGHT1-CONNID,
             WA_FLIGHT1-COUNTRYFR,
             WA_FLIGHT1-CITYFROM ,
             WA_FLIGHT1-AIRPFROM,
             WA_FLIGHT1-COUNTRYTO,
             WA_FLIGHT1-CITYTO,
             WA_FLIGHT1-AIRPTO,
             WA_FLIGHT1-DISTANCE.
    ENDLOOP.

########## SELECT WITH FORMATTING OPTION ##################

TABLES spfli.
SKIP.
ULINE AT /(62).
SELECT * FROM spfli .

  WRITE: / sy-vline, spfli-connid, sy-vline,
               (15) spfli-cityfrom, 26 sy-vline,
               31 spfli-cityto, 51 sy-vline, 62 sy-vline,
              / sy-vline, 8 sy-vline,
              spfli-deptime UNDER spfli-cityfrom, 26 sy-vline,
              spfli-arrtime UNDER spfli-cityto, 51 sy-vline,
              spfli-fltime, 62 sy-vline.
  ULINE AT /(62).
ENDSELECT.

WRITE: /10 'SAP *** SAP *** SAP *** SAP *** SAP *** SAP',
       /19(43) 'Flight Information System',
       /19(43) 'International Connections'.

##########  SCROLLING LIST #####################

REPORT ZTASK1 line-size 40 no standard page heading.

TOP-OF-PAGE.
  WRITE: 'Top of Page', sy-pagno, 'SY-SROWS:', sy-srows.
  ULINE.

START-OF-SELECTION.
  DO 100 TIMES.
    WRITE / sy-index.
  ENDDO.
  DO 1 TIMES.
    SCROLL LIST FORWARD.
  ENDDO.

##########SCROLL LIST TO COLUMN#############

REPORT ZTASK1 NO STANDARD PAGE HEADING LINE-SIZE 200.

TOP-OF-PAGE.
  WRITE: AT 161 'Top of Page', sy-pagno,
  'SY-SCOLS:', sy-scols.
  ULINE.

START-OF-SELECTION.
  DO 200 TIMES.
    WRITE sy-index.
  ENDDO.
  SCROLL LIST TO COLUMN 178.

###########SCROLL BOUNDARY LEFT RIGHT ##################

REPORT YPGM NO STANDARD PAGE HEADING LINE-COUNT 3 LINE-SIZE 140.

START-OF-SELECTION.
  DO 3 TIMES.
    WRITE: /10 'SY-INDEX:'.
    DO 10 TIMES.
      WRITE sy-index.
    ENDDO.
  ENDDO.
  SET RIGHT SCROLL-BOUNDARY COLUMN 20.
  DO 3 TIMES.
    WRITE: / 'SY-INDEX:'.
    DO 10 TIMES.
      WRITE sy-index.
    ENDDO.
  ENDDO.
  SET RIGHT SCROLL-BOUNDARY COLUMN 10.

#############SCROLL TO PAGE#############


REPORT YPGM NO STANDARD PAGE HEADING LINE-SIZE 40 LINE-COUNT 8(2).

DATA: pag TYPE i VALUE 15,
lin TYPE i VALUE 4.

TOP-OF-PAGE.
  WRITE: 'Top of Page', sy-pagno.
  ULINE.

END-OF-PAGE.
  ULINE.
  WRITE: 'End of Page', sy-pagno.

START-OF-SELECTION.
  DO 100 TIMES.
    DO 4 TIMES.
      WRITE / sy-index.
    ENDDO.
  ENDDO.
  SCROLL LIST TO PAGE pag LINE lin.

############SCROLL FORWARD###############


REPORT YPGM NO STANDARD PAGE HEADING LINE-SIZE 40.

TOP-OF-PAGE.
WRITE: 'Top of Page', sy-pagno, 'SY-SROWS:', sy-srows.
ULINE.
START-OF-SELECTION.
DO 100 TIMES.
WRITE / sy-index.
ENDDO.
DO 3 TIMES.
SCROLL LIST FORWARD.
ENDDO.

###########SCROLL RIGHT###############

REPORT ZTASK1 NO STANDARD PAGE HEADING LINE-SIZE 200.


TOP-OF-PAGE.
  WRITE: AT 161 'Top of Page', sy-pagno,
  'SY-SCOLS:', sy-scols.
  ULINE.

START-OF-SELECTION.
  DO 200 TIMES.
    WRITE sy-index.
  ENDDO.
  SCROLL LIST RIGHT.

#########NO SCROLLING##########

REPORT YPGM NO STANDARD PAGE HEADING LINE-COUNT 3 LINE-SIZE 140.

START-OF-SELECTION.
  DO 3 TIMES.
    WRITE: / 'SY-INDEX:'.
    DO 10 TIMES.
      WRITE sy-index.
    ENDDO.
  ENDDO.
  NEW-LINE NO-SCROLLING.
  ULINE AT 20(20).
  NEW-LINE NO-SCROLLING.
  WRITE AT 20 '| **** Fixed! **** |'.
  NEW-LINE NO-SCROLLING.
  ULINE AT 20(20).
  DO 3 TIMES.
    WRITE: / 'SY-INDEX:'.
    DO 10 TIMES.
      WRITE sy-index.
    ENDDO.
  ENDDO.

###########CHECK BOX IN LIST################


DATA: flag1(1) TYPE c VALUE ' ',
           flag2(1) TYPE c VALUE 'X',
           flag3(5) TYPE c VALUE 'Xenon'.

WRITE: / 'Flag 1 ', flag1 AS CHECKBOX,
             / 'Flag 2 ', flag2 AS CHECKBOX,
             / 'Flag 3 ', flag3 AS CHECKBOX.

############COLOR CODES################

DATA i TYPE i VALUE 0.
DATA col(15) TYPE c.
WHILE i < 8.

CASE  i.
WHEN 0. col = 'COL_BACKGROUND '.
WHEN 1. col = 'COL_HEADING '.
WHEN 2. col = 'COL_NORMAL '.
WHEN 3. col = 'COL_TOTAL '.
WHEN 4. col = 'COL_KEY '.
WHEN 5. col = 'COL_POSITIVE '.
WHEN 6. col = 'COL_NEGATIVE '.
WHEN 7. col = 'COL_GROUP '.
ENDCASE.

FORMAT INTENSIFIED COLOR = i.
WRITE: /(4) i, AT 7 sy-vline,
         col, sy-vline,
         col INTENSIFIED OFF, sy-vline,
         col INVERSE.
i = i + 1.
ENDWHILE.

############INPTU ON AT LIST################

WRITE 'Please fill in your name before printing:'.
WRITE / ' Enter name here ' INPUT ON.
ULINE.
WRITE 'You can overwrite the following line:'.
FORMAT INPUT ON INTENSIFIED OFF.
ULINE.
FORMAT INPUT OFF INTENSIFIED ON.

############OUTPUT WITH SYMBOL AND ICON############

REPORT YPGM.
INCLUDE <symbol>. " FOR TYPE-POOLS : SYM
INCLUDE <icon>.
WRITE :/  'Phone Symbol:', SYM_PHONE AS SYMBOL.
SKIP.
WRITE: / 'Alarm Icon: ', icon_alarm AS ICON.

###########FORAMTTING HOT SPOT############

INCLUDE <list>.
START-OF-SELECTION.
WRITE 'Now comes a'.
FORMAT HOTSPOT ON COLOR 5 INVERSE ON.
WRITE 'HOTSPOT'.
FORMAT HOTSPOT OFF COLOR OFF.
AT LINE-SELECTION.
WRITE / 'New list AT-LINE-SELECTION'.
SKIP.
WRITE 'This is also a hotspot:'.
WRITE icon_list AS ICON HOTSPOT.

#########RESERVE LINE#############


REPORT ZTASK1 line-count 8(2) no standard page heading.

end-of-page.
  uline.

start-of-selection.
  do 4 times.
    write :/ sy-index.
  enddo.
  reserve 3 lines.
  do 2 times.
    write :/ sy-index.
  enddo.

  reserve 3 lines.

  do 3 times.
    write :/ 'index ', sy-index.
  enddo.

#################TRIANGLE STAR DISPLAY #############

PARAMETERS : NO_LINE TYPE I DEFAULT 5.
DATA : POS TYPE I value 30.
DATA : POS1 TYPE I value 27 .
DATA : N TYPE I VALUE 1.
data : indx like sy-index.
data : line type i.
line = no_line - 1.
DO NO_LINE TIMES.
  indx = sy-index.
  do n times.
  WRITE AT pos(1) '*' RIGHT-JUSTIFIED.
  pos = pos + 1.
  enddo.
  NEW-LINE.
  n = n + 2.
  pos = pos - ( indx * 2 ).
ENDDO.
pos1 = pos + 2.
new-line.
n = n - 4.
DO LINE TIMES.
  do n times.
  WRITE AT pos1(1) '*' RIGHT-JUSTIFIED.
  pos1 = pos1 + 1.
   indx = sy-index.
  enddo.
  NEW-LINE.
  n = n - 2.
  pos1 = ( pos1 + 1 ) - indx.
ENDDO.

###########SELECT-SCREEN WITH NO INTERVAL#############

SELECTION-SCREEN BEGIN OF BLOCK RAD1 WITH FRAME TITLE TEXT-002 no intervals.
PARAMETERS R1 RADIOBUTTON GROUP GR1.
PARAMETERS R2 RADIOBUTTON GROUP GR1.
PARAMETERS R3 RADIOBUTTON GROUP GR1.
SELECTION-SCREEN END OF BLOCK RAD1.

##########SELECTION-SCREEN POSITON#################

DATA WA_SPFLI TYPE SPFLI.
SELECT-OPTIONS AIRLINE FOR WA_SPFLI-CARRID.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN POSITION POS_low.
PARAMETERS FIELD(5).
SELECTION-SCREEN END OF LINE.

#########MACROS#############

data : num1 type i value 20.
data : num2 type i value 230.
data : res type i .

define addition.
 &3 = &1 + &2.
write : 'sum of two numbers =', &3.
  end-of-definition.
  addition num1 num2 res.
  uline.
  addition '30' '40' res.
  uline.
  addition '100' '200' res.

##########NEW PAGE################

TOP-OF-PAGE.
  WRITE: 'TOP-OF-PAGE', sy-pagno.
  ULINE AT /(17).

START-OF-SELECTION.
  DO 2 TIMES.
    WRITE / 'Loop:'.
    DO 3 TIMES.
      WRITE / sy-index.
    ENDDO.
    NEW-PAGE.
  ENDDO.

###########NEW PAGES########

WRITE: 'Page', sy-pagno.
NEW-PAGE NO-TITLE.
WRITE: 'Page', sy-pagno.
NEW-PAGE NO-HEADING.
WRITE: 'Page', sy-pagno.
NEW-PAGE WITH-TITLE.
WRITE: 'Page', sy-pagno.
NEW-PAGE WITH-HEADING.
WRITE: 'Page', sy-pagno.

#######GET RUN TIME FIELD##########

data : r_t type i.
do 10 times.
  get run time field r_t.
  write :/ sy-index , 'relative run time = ' , r_t , 'microseconds'.
  enddo.

*  ********* output every time varies depending on system load ****************

         1  relative run time =           0  microseconds
         2  relative run time =          70  microseconds
         3  relative run time =          81  microseconds
         4  relative run time =          90  microseconds
         5  relative run time =          99  microseconds
         6  relative run time =         107  microseconds
         7  relative run time =         116  microseconds
         8  relative run time =         124  microseconds
         9  relative run time =         133  microseconds
        10  relative run time =         141  microseconds

###########PUSH BUTTON AT SELECTION SCREEN#################

TABLES SSCRFIELDS.
DATA FLAG.
SELECTION-SCREEN: BEGIN OF SCREEN 500 AS WINDOW TITLE TIT,
                 BEGIN OF LINE,
                 PUSHBUTTON 2(10) BUT1 USER-COMMAND CLI1,
                 PUSHBUTTON 12(10) TEXT-020 USER-COMMAND CLI2,
                 END OF LINE,
                 BEGIN OF LINE,
                 PUSHBUTTON 2(10) BUT3 USER-COMMAND CLI3,
                 PUSHBUTTON 12(10) TEXT-040 USER-COMMAND CLI4,
                 END OF LINE,
END OF SCREEN 500.

AT SELECTION-SCREEN.
  CASE SSCRFIELDS.
    WHEN 'CLI1'.
      FLAG = '1'.
    WHEN 'CLI2'.
      FLAG = '2'.
    WHEN 'CLI3'.
      FLAG = '3'.
    WHEN 'CLI4'.
      FLAG = '4'.
  ENDCASE.

START-OF-SELECTION.
  TIT = 'Four Buttons'.
  BUT1 = 'Button 1'.
  BUT3 = 'Button 3'.
  CALL SELECTION-SCREEN 500 STARTING AT 10 10.
  CASE FLAG.
    WHEN '1'.
      WRITE / 'Button 1 was clicked'.
    WHEN '2'.
      WRITE / 'Button 2 was clicked'.
    WHEN '3'.
      WRITE / 'Button 3 was clicked'.
    WHEN '4'.
      WRITE / 'Button 4 was clicked'.
    WHEN OTHERS.
      WRITE / 'No Button was clicked'.
  ENDCASE.

##########SELECTION SCREEN AS SUBSCREEN##################

SELECTION-SCREEN BEGIN OF SCREEN 1100 AS SUBSCREEN.
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-010.
PARAMETERS: p1(10) TYPE c,
            p2(10) TYPE c,
            p3(10) TYPE c.
SELECTION-SCREEN END OF BLOCK b1.
SELECTION-SCREEN END OF SCREEN 1100.

SELECTION-SCREEN BEGIN OF SCREEN 1200 AS SUBSCREEN.
SELECTION-SCREEN BEGIN OF BLOCK b2 WITH FRAME TITLE text-020.
PARAMETERS: q1(10) TYPE c OBLIGATORY,
            q2(10) TYPE c OBLIGATORY,
            q3(10) TYPE c OBLIGATORY.
SELECTION-SCREEN END OF BLOCK b2.
SELECTION-SCREEN END OF SCREEN 1200.


DATA: ok_code TYPE sy-ucomm,
      save_ok TYPE sy-ucomm.

DATA: number(4) TYPE n VALUE '1100'.

START-OF-SELECTION.
  CALL SCREEN 100.


MODULE status_0100 OUTPUT.
  SET PF-STATUS 'SCREEN_100'.
ENDMODULE.


MODULE cancel INPUT.
  LEAVE PROGRAM.
ENDMODULE.


MODULE user_command_0100 INPUT.
  save_ok = ok_code.
  CLEAR ok_code.
  CASE save_ok.
    WHEN 'BUTTON1'.
      number = 1100.
    WHEN 'BUTTON2'.
      number = 1200.
  ENDCASE.
ENDMODULE.

AT SELECTION-SCREEN.
  MESSAGE s888(sabapdocu) WITH text-030 sy-dynnr.

*  *************************************************
  PROCESS BEFORE OUTPUT.
 MODULE STATUS_0100.
   CALL SUBSCREEN area INCLUDING sy-repid number.

PROCESS AFTER INPUT.
module cancel at exit-command .
  CALL SUBSCREEN area.
 MODULE USER_COMMAND_0100.

##########SELECTION SCREEN AS TABBED BLOCK##############

DATA flag(1) TYPE c.
SELECTION-SCREEN BEGIN OF SCREEN 100 AS SUBSCREEN.
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME.
PARAMETERS: p1(10) TYPE c,
            p2(10) TYPE c,
            p3(10) TYPE c.
SELECTION-SCREEN END OF BLOCK b1.
SELECTION-SCREEN END OF SCREEN 100.

* SUBSCREEN 2
SELECTION-SCREEN BEGIN OF SCREEN 200 AS SUBSCREEN.
SELECTION-SCREEN BEGIN OF BLOCK b2 WITH FRAME.
PARAMETERS: q1(10) TYPE c OBLIGATORY,
            q2(10) TYPE c OBLIGATORY,
            q3(10) TYPE c OBLIGATORY.
SELECTION-SCREEN END OF BLOCK b2.
SELECTION-SCREEN END OF SCREEN 200.
* STANDARD SELECTION SCREEN

SELECTION-SCREEN: BEGIN OF TABBED BLOCK mytab FOR 10 LINES,
TAB (20) button1 USER-COMMAND push1,
TAB (20) button2 USER-COMMAND push2,
TAB (20) button3 USER-COMMAND push3
                 DEFAULT SCREEN 300,
END OF BLOCK mytab.

INITIALIZATION.
  button1 = text-010.
  button2 = text-020.
  button3 = text-030.
  mytab-prog = sy-repid.
  mytab-dynnr = 100.
  mytab-activetab = 'BUTTON1'.

AT SELECTION-SCREEN.
  CASE sy-dynnr.
    WHEN 1000.
      CASE sy-ucomm.
        WHEN 'PUSH1'.
          mytab-dynnr = 100.
          mytab-activetab = 'BUTTON1'.
        WHEN 'PUSH2'.
          mytab-dynnr = 200.
          mytab-activetab = 'BUTTON2'.

      ENDCASE.
    WHEN 100.
      MESSAGE s888(sabapdocu) WITH text-040 sy-dynnr.
    WHEN 200.
      MESSAGE s888(sabapdocu) WITH text-040 sy-dynnr.
  ENDCASE.

MODULE init_0100 OUTPUT.
  LOOP AT SCREEN.
    IF screen-group1 = 'MOD'.
      CASE flag.
        WHEN 'X'.
          screen-input = '1'.
        WHEN ' '.
          screen-input = '0'.
      ENDCASE.
      MODIFY SCREEN.
    ENDIF.
  ENDLOOP.
ENDMODULE.

MODULE user_command_0100 INPUT.
  MESSAGE s888(sabapdocu) WITH text-050 sy-dynnr.
  CASE sy-ucomm.
    WHEN 'TOGGLE'.
      IF flag = ' '.
        flag = 'X'.
      ELSEIF flag = 'X'.
        flag = ' '.
      ENDIF.
  ENDCASE.
ENDMODULE.

START-OF-SELECTION.
  WRITE: / 'P1:', p1,'Q1:', q1,
         / 'P2:', p2,'Q2:', q2,
         / 'P3:', p3,'Q3:', q3.

############SELECTION SCREEN TABBED BLOCK WITH APPLICATION TOOLBAR#########

TABLES sscrfields.
* SUBSCREEN 1
SELECTION-SCREEN BEGIN OF SCREEN 100 AS SUBSCREEN.
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-010.
PARAMETERS: p1(10) TYPE c,
            p2(10) TYPE c,
            p3(10) TYPE c.
SELECTION-SCREEN END OF BLOCK b1.
SELECTION-SCREEN END OF SCREEN 100.

* SUBSCREEN 2
SELECTION-SCREEN BEGIN OF SCREEN 200 AS SUBSCREEN.
SELECTION-SCREEN BEGIN OF BLOCK b2 WITH FRAME TITLE text-020.
PARAMETERS: q1(10) TYPE c,
            q2(10) TYPE c,
            q3(10) TYPE c.
SELECTION-SCREEN END OF BLOCK b2.
SELECTION-SCREEN END OF SCREEN 200.

* SUBSCREEN 3
SELECTION-SCREEN BEGIN OF SCREEN 300 AS SUBSCREEN.
SELECTION-SCREEN BEGIN OF BLOCK b3 WITH FRAME TITLE text-030.
PARAMETERS: r1(10) TYPE c,
            r2(10) TYPE c,
            r3(10) TYPE c.
SELECTION-SCREEN END OF BLOCK b3.
SELECTION-SCREEN END OF SCREEN 300.

* STANDARD SELECTION SCREEN
SELECTION-SCREEN: FUNCTION KEY 1,
                  FUNCTION KEY 2.
SELECTION-SCREEN: BEGIN OF TABBED BLOCK sub FOR 10 LINES,
                  END OF BLOCK sub.


INITIALIZATION.
  sscrfields-functxt_01 = '@0D@'.
  sscrfields-functxt_02 = '@0E@'.
  sub-prog = sy-repid.
  sub-dynnr = 100.


AT SELECTION-SCREEN.
  CASE sy-dynnr.
    WHEN 100.
      IF sscrfields-ucomm = 'FC01'.
        sub-dynnr = 300.
      ELSEIF sscrfields-ucomm = 'FC02'.
        sub-dynnr = 200.
      ENDIF.
    WHEN 200.
      IF sscrfields-ucomm = 'FC01'.
        sub-dynnr = 100.
      ELSEIF sscrfields-ucomm = 'FC02'.
        sub-dynnr = 300.
      ENDIF.
    WHEN 300.
      IF sscrfields-ucomm = 'FC01'.
        sub-dynnr = 200.
      ELSEIF sscrfields-ucomm = 'FC02'.
        sub-dynnr = 100.
      ENDIF.
  ENDCASE.

START-OF-SELECTION.
  WRITE: / 'P1:', p1,'Q1:', q1, 'R1:', r1,
         / 'P2:', p2,'Q2:', q2, 'R2:', r2,
         / 'P3:', p3,'Q3:', q3, 'R3:', r3.

###########SELECTION SCREEN TABSTRIP##########

SELECTION-SCREEN BEGIN OF SCREEN 1100 AS SUBSCREEN NO INTERVALS.
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-010.
PARAMETERS: p1(10) TYPE c,
            p2(10) TYPE c,
             p3(10) TYPE c.
SELECTION-SCREEN END OF BLOCK b1.
SELECTION-SCREEN END OF SCREEN 1100.

SELECTION-SCREEN BEGIN OF SCREEN 1200 AS SUBSCREEN NO INTERVALS.
SELECTION-SCREEN BEGIN OF BLOCK b2 WITH FRAME TITLE text-020.
PARAMETERS: q1(10) TYPE c OBLIGATORY,
            q2(10) TYPE c OBLIGATORY,
            q3(10) TYPE c OBLIGATORY.
SELECTION-SCREEN END OF BLOCK b2.
SELECTION-SCREEN END OF SCREEN 1200.


CONTROLS mytabstrip TYPE TABSTRIP.
DATA: ok_code TYPE sy-ucomm,
       save_ok TYPE sy-ucomm.

DATA: number(4) TYPE n VALUE '1100'.

START-OF-SELECTION.
  mytabstrip-activetab = 'BUTTON1'.

  CALL SCREEN 100.

MODULE status_0100 OUTPUT.
  SET PF-STATUS 'SCREEN_100'.
ENDMODULE.
MODULE cancel INPUT.
  LEAVE PROGRAM.
ENDMODULE.
MODULE user_command_0100 INPUT.
  save_ok = ok_code.
  CLEAR ok_code.
  CASE save_ok.
    WHEN 'BUTTON1'.
      mytabstrip-activetab = save_ok.
      number = 1100.
    WHEN 'BUTTON2'.
      mytabstrip-activetab = save_ok.
      number = 1200.
  ENDCASE.
ENDMODULE.

AT SELECTION-SCREEN.
  MESSAGE s888(sabapdocu) WITH text-030 sy-dynnr.

*  *********************
  PROCESS BEFORE OUTPUT.
MODULE status_0100.
CALL SUBSCREEN area INCLUDING sy-repid number.
PROCESS AFTER INPUT.
MODULE cancel AT EXIT-COMMAND.
CALL SUBSCREEN area.
MODULE user_command_0100.

#######NESTED SELECTION SCREEN#############

SELECTION-SCREEN BEGIN OF BLOCK SEL1 WITH FRAME TITLE TIT1.
          PARAMETERS: CITYFR LIKE SPFLI-CITYFROM,
                      CITYTO LIKE SPFLI-CITYTO.
SELECTION-SCREEN END OF BLOCK SEL1.

SELECTION-SCREEN BEGIN OF SCREEN 500 AS WINDOW.
          SELECTION-SCREEN INCLUDE BLOCKS SEL1.
          SELECTION-SCREEN BEGIN OF BLOCK SEL2 WITH FRAME TITLE TIT2.
                    PARAMETERS: AIRPFR LIKE SPFLI-AIRPFROM,
                                AIRPTO LIKE SPFLI-AIRPTO.
          SELECTION-SCREEN END OF BLOCK SEL2.
SELECTION-SCREEN END OF SCREEN 500.


INITIALIZATION.
  TIT1 = 'Cities'.

AT SELECTION-SCREEN.
  CASE SY-DYNNR.
    WHEN '0500'.
      MESSAGE W159(AT) WITH 'Screen 500'.
    WHEN '1000'.
      MESSAGE W159(AT) WITH 'Screen 1000'.
  ENDCASE.


START-OF-SELECTION.
  TIT1 = 'Cities for Airports'.
  TIT2 = 'Airports'.
  CALL SELECTION-SCREEN 500 STARTING AT 10 10.
  TIT1 = 'Cities again'.
  CALL SELECTION-SCREEN 1000 STARTING AT 10 10.

##########BUTTON IN APPLICATION TOOLBAR########

TABLES : SSCRFIELDS.

PARAMETERS: p_NAME TYPE C LENGTH 10.


SELECTION-SCREEN: FUNCTION KEY 1,
                  FUNCTION KEY 2,
                  FUNCTION KEY 3,
                  FUNCTION KEY 4,
                  FUNCTION KEY 5.
INITIALIZATION.
  sscrfields-functxt_01 = 'INDIA'.
  sscrfields-functxt_02 = 'PAK'.
  sscrfields-functxt_03 = 'SRILANKA'.
  sscrfields-functxt_04 = 'AUSTRALIA'.
  sscrfields-functxt_05 = 'SOUTHAFRICA'.

AT SELECTION-SCREEN.
  CASE sscrfields-ucomm.
      WHEN'FC01'.
      P_NAME = 'SACHIN'.
    WHEN 'FC02'.
      P_NAME = 'ANWAR'.
    WHEN 'FC03'.
      P_NAME = 'MURALI'.
    WHEN 'FC04'.
      P_NAME = 'POINTING'.
    WHEN 'FC05'.
      P_NAME = 'SMITHHH'.
  ENDCASE.
START-OF-SELECTION.
  WRITE : / 'CRICKTER NAME = ', P_NAME.

#########LIST BOX AT SELECTION SCREEN #############

TYPE-POOLS : VRM.

DATA: NAME  TYPE VRM_ID,
      LIST  TYPE VRM_VALUES,
      VALUE LIKE LINE OF LIST.

PARAMETERS : P_NAME(10) TYPE C  OBLIGATORY AS LISTBOX VISIBLE LENGTH 10.

AT SELECTION-SCREEN OUTPUT.
  NAME = 'P_NAME'.

  VALUE-KEY = 'SIVA'.
  VALUE-TEXT = 'SIVA'.

  APPEND VALUE TO LIST.

  VALUE-KEY = 'PRASAD'.
  VALUE-TEXT = 'PRASAD'.
  APPEND VALUE TO LIST.

  VALUE-KEY = 'SUDIPTA'.
  VALUE-TEXT = 'SUDIPTA'.
  APPEND VALUE TO LIST.


  CALL FUNCTION 'VRM_SET_VALUES'
    EXPORTING
      ID              = NAME
      VALUES          = LIST
    EXCEPTIONS
      ID_ILLEGAL_NAME = 1
      OTHERS          = 2.
  IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.

start-of-selection.

  WRITE : / 'SELECTED VALUE =', P_NAME.

###########NESTED INTERNAL TABLE###########

DATA: BEGIN OF LINE1,
      COL1(3) TYPE C,
      COL2(2) TYPE N,
      COL3 TYPE I,
     END OF LINE1.
DATA : ITAB1 LIKE TABLE OF LINE1.
DATA: BEGIN OF LINE2,
      COL1 TYPE C,
      COL2 LIKE ITAB1,
     END OF LINE2.
DATA ITAB2 LIKE  TABLE OF LINE2 .

LINE1-COL1 = 'ABC'.
LINE1-COL2 = '12'.
LINE1-COL3 = '3'.
APPEND LINE1 TO ITAB1.

LINE1-COL1 = 'DEF'.
LINE1-COL2 = '34'.
LINE1-COL3 = '35'.
APPEND LINE1 TO ITAB1.

LINE2-COL1 = 'X'.
LINE2-COL2 = ITAB1.
APPEND LINE2 TO ITAB2.

REFRESH ITAB1.

LINE1-COL1 = 'GHI'.
LINE1-COL2 = '56'.
LINE1-COL3 = '7'.
APPEND LINE1 TO ITAB1.

LINE1-COL1 = 'JKL'.
LINE1-COL2 = '78'.
LINE1-COL3 = '9'.
APPEND LINE1 TO ITAB1.

LINE2-COL1 = 'Y'.
LINE2-COL2 = ITAB1.
APPEND LINE2 TO ITAB2.

LOOP AT ITAB2 INTO LINE2.
  WRITE :/ LINE2-COL1.
  LOOP AT LINE2-COL2 INTO LINE1.
    WRITE :/ LINE1-COL1, LINE1-COL2, LINE1-COL3.
    ENDLOOP.
  ENDLOOP.

########SELECTION SCREEN WITH RADIOBUTTON GROUP##############

SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME.
PARAMETERS: R1 RADIOBUTTON GROUP RAD1 DEFAULT 'X',
            R2 RADIOBUTTON GROUP RAD1,
            R3 RADIOBUTTON GROUP RAD1.
SELECTION-SCREEN END OF BLOCK B1.

SELECTION-SCREEN BEGIN OF BLOCK B2 WITH FRAME.
PARAMETERS: R4 RADIOBUTTON GROUP RAD2 DEFAULT 'X',
            R5 RADIOBUTTON GROUP RAD2,
            R6 RADIOBUTTON GROUP RAD2.
SELECTION-SCREEN END OF BLOCK B2.

AT SELECTION-SCREEN ON RADIOBUTTON GROUP RAD1.
  IF R1 = 'X'.
    MESSAGE 'GROUP1 SELECTED' TYPE 'I'.
  ENDIF.

AT SELECTION-SCREEN ON RADIOBUTTON GROUP RAD2.
  IF R4 = 'X'.
    MESSAGE 'GROUP2 SELECTED' TYPE 'I'.
  ENDIF.

#######SELECTION SCREEN WITH BLOCK###########

SELECTION-SCREEN BEGIN OF BLOCK PART1 WITH FRAME.
PARAMETERS: NUMBER1 TYPE I,
            NUMBER2 TYPE I,
            NUMBER3 TYPE I.
SELECTION-SCREEN END OF BLOCK PART1.

SELECTION-SCREEN BEGIN OF BLOCK PART2 WITH FRAME.
PARAMETERS: NUMBER4 TYPE I,
            NUMBER5 TYPE I,
            NUMBER6 TYPE I.
SELECTION-SCREEN END OF BLOCK PART2.

AT SELECTION-SCREEN ON BLOCK PART1.
  IF NUMBER3 LT NUMBER2 OR NUMBER3 LT NUMBER1 OR NUMBER2 LT NUMBER1.
    MESSAGE 'INVAID INPUT IN BLOCK 1' TYPE 'E'.
  ENDIF.

AT SELECTION-SCREEN ON BLOCK PART2.
  IF NUMBER6 LT NUMBER5 OR NUMBER6 LT NUMBER4 OR NUMBER5 LT NUMBER4.
    MESSAGE 'INVAID INPUT IN BLOCK 2' TYPE 'E'.
  ENDIF.

##########SELECTION SCREEN WITH DYNAMIC CHANGE########

PARAMETERS: TEST1(10) MODIF ID SC1,
            TEST2(10) MODIF ID SC2,
            TEST3(10) MODIF ID SC1,
            TEST4(10) MODIF ID SC2.

AT SELECTION-SCREEN OUTPUT.
  LOOP AT SCREEN.
    IF SCREEN-GROUP1 = 'SC1'.
      SCREEN-INTENSIFIED = '1'.
      MODIFY SCREEN.
      CONTINUE.
    ENDIF.
    IF SCREEN-GROUP1 = 'SC2'.
      SCREEN-INTENSIFIED = '0'.
      MODIFY SCREEN.
    ENDIF.
  ENDLOOP.

#######USE OF CONTINUE, CHECK, EXIT  AND SKIP STATEMENT ###########

do 5 times.
  if sy-index eq 2.
    continue.
  endif.
  write :/ sy-index.
enddo.
uline.
do 5 times.
  check sy-index between 2 and 4.
  write :/ sy-index.
enddo.
uline.

do 5 times.
  if sy-index eq 3.
    exit.
  endif.
  write :/ sy-index.
enddo.
uline.
do 3 times.
  write sy-index.
  skip.
  do 4 times.
    write   sy-index.
  enddo.
  skip.
enddo.

######## CATCH & ENDCATCH SYSTEM EXCEPTION #############

data : num type i value 10.
data res type p decimals 3.
  catch system-exceptions arithmetic_errors = 5.
do .
  num = num - 1.
  res = 1 / num.
 write :/ 'res=', res.
  enddo.

  endcatch.
  if sy-subrc = 5.
    write :/ 'division byh zero'.
    endif.

*    *****output *********

 res=            0,111
res=            0,125
res=            0,143
res=            0,167
res=            0,200
res=            0,250
res=            0,333
res=            0,500
res=            1,000
division byh zero

########DISABLING STANDARD TOOLBAR BUTTONS#################

*PASS THE INTERNAL TABLE TO THE FM THAT CONTAINS  FUNCTION CODES OF THE BUTTONS U WANT TO HIDE *

DATA itab TYPE TABLE OF sy-ucomm.
PARAMETERS test(10) TYPE c.

AT SELECTION-SCREEN OUTPUT.
  APPEND: 'PRIN' TO itab,
                    'SPOS' TO itab.
  CALL FUNCTION 'RS_SET_SELSCREEN_STATUS'
    EXPORTING
      p_status  = sy-pfkey
    TABLES
      p_exclude = itab.

###FUNCTION MODULE TO SPLIT ADDRESS INTO ADDRESS AND FILE NAME  #####

DATA: file_name LIKE  rlgrap-filename,
             file_path LIKE  rlgrap-filename.


CALL FUNCTION 'SO_SPLIT_FILE_AND_PATH'
EXPORTING
full_name = 'C:\Documents and Settings\Administ\SERVER\Desktop\HW.jpg'
IMPORTING
stripped_name = file_name
file_path     = file_path.

WRITE:/ file_name,file_path.

####FUNCTION MODULE TO SPLIT ADDRESS INTO FILE NAME AND EXTENSION ####

DATA: name LIKE  SDBAH-ACTID,
           extn LIKE  SDBAD-FUNCT.
CALL FUNCTION 'SPLIT_FILENAME'
  EXPORTING
    LONG_FILENAME  = 'C:\Documents and Settin\SERVER\Desktop\HW.jpg'
 IMPORTING
   PURE_FILENAME        = name
   PURE_EXTENSION       = extn .

    write : / name , extn.

######## FUNCTION MODULE FOR RANDOM NUMBER GENERATION ########

DATA : RAN_SEED1 TYPE QF00-RAN_SEED .
DATA : RAN_NUMBER TYPE QF00-RAN_NUMBER,
             RAN_SEED2 TYPE QF00-RAN_SEED .

CALL FUNCTION 'QF05_RANDOM'
 EXPORTING
   RAN_SEED         = RAN_SEED1
 IMPORTING
   RAN_NUMBER       = RAN_NUMBER
   RAN_SEED         = RAN_SEED2 .

  WRITE : / 'RANDOM NUMBER=', RAN_NUMBER.

****************************************************
DATA : RAN_INT TYPE QF00-RAN_INT.

  CALL FUNCTION 'QF05_RANDOM_INTEGER'
   EXPORTING
     RAN_INT_MAX         = 2000000000
     RAN_INT_MIN         = 0000000000
   IMPORTING
     RAN_INT             = RAN_INT
   EXCEPTIONS
     INVALID_INPUT       = 1
    OTHERS              = 2            .
  WRITE :/ 'RANDOM INTEGER NUMBER=', RAN_INT.

**  *****************************************************
  DATA : RANDOM_NUMBER TYPE INT4 .

  CALL FUNCTION 'SXMS_CREATE_RANDOM_NUMBER'
   IMPORTING
     RANDOM_NUMBER       = RANDOM_NUMBER .

  WRITE : / 'RANDOM NUMBER=', RANDOM_NUMBER.

*  ***************************************************
DATA : RANDOM_AMOUNT TYPE BBSEG-WRBTR .

CALL FUNCTION 'RANDOM_AMOUNT'
 EXPORTING
   RND_MIN          = '00000000'
   RND_MAX          = '10000000'
   VALCURR          = 'DEM'
 IMPORTING
   RND_AMOUNT       = RANDOM_AMOUNT.

 WRITE : /  RANDOM_AMOUNT.

* *********************************************************
DATA RND_VALUE TYPE DATATYPE-CHAR0128.

CALL FUNCTION 'RANDOM_C'
  EXPORTING
    LEN_MIN   = 0
    LEN_MAX   = 128
    CHAR_MIN  = 1
    CHAR_MAX  = 50
  IMPORTING
    RND_VALUE = rnd_value.

WRITE : / 'RANDOM CHARACTER =' , RND_VALUE .

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

 DATA : RND_VALUE TYPE DATATYPE-INTEGER4.

CALL FUNCTION 'RANDOM_I4'
 EXPORTING
   RND_MIN         = 0
   RND_MAX         = 1000000000
 IMPORTING
   RND_VALUE       = RND_VALUE
          .
WRITE : / 'RANDOM =' , RND_VALUE .

*****************************************************
DATA : RND_VALUE TYPE DATATYPE-INTEGER2 .

CALL FUNCTION 'RANDOM_I2'
 EXPORTING
   RND_MIN         = 0
   RND_MAX         = 10000
 IMPORTING
   RND_VALUE       = RND_VALUE .

WRITE : / 'RANDOM =' , RND_VALUE .

***********************************************************
DATA : GUID_NO_16 TYPE GUID_16.
DATA : GUID_NO_22 TYPE GUID_22.
DATA : GUID_NO_32 TYPE GUID_32.
CALL FUNCTION 'GUID_CREATE'
 IMPORTING
   EV_GUID_16       = GUID_NO_16
   EV_GUID_22       = GUID_NO_22
   EV_GUID_32       = GUID_NO_32 .

WRITE : / 'GLOBAL UNIQUE IDENTIFICATION NUMBER 16= ' , GUID_NO_16.
WRITE : / 'GLOBAL UNIQUE IDENTIFICATION NUMBER 22= ' , GUID_NO_22.
WRITE : / 'GLOBAL UNIQUE IDENTIFICATION NUMBER 32= ' , GUID_NO_32.

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

DATA prng TYPE REF TO CL_ABAP_RANDOM.
DATA num  TYPE I.

START-OF-SELECTION.
  prng = CL_ABAP_RANDOM=>create( ).
  DO 10000 TIMES.
    num = prng->Int( ).
    WRITE / num.
  ENDDO.

Other classes used to generate pseudo-random numbers:
CL_ABAP_RANDOM_FLOAT
CL_ABAP_RANDOM_INT
CL_ABAP_RANDOM_PACKED
CL_ABAP_RANDOM_PACKED_DEC1
CL_ABAP_RANDOM_PACKED_DEC2
CL_ABAP_RANDOM_PACKED_DEC3
CL_ABAP_RANDOM_PACKED_DEC4
CL_ABAP_RANDOM_PACKED_DEC5
CL_ABAP_RANDOM_PACKED_DEC6
CL_ABAP_RANDOM_PACKED_DEC7
CL_ABAP_RANDOM_PACKED_DEC8
CL_ABAP_RANDOM_PACKED_DEC9
CL_ABAP_RANDOM_PACKED_DEC10
CL_ABAP_RANDOM_PACKED_DEC11
CL_ABAP_RANDOM_PACKED_DEC12
CL_ABAP_RANDOM_PACKED_DEC13
CL_ABAP_RANDOM_PACKED_DEC14

Comments system

Disqus Shortname