Monday, 8 August 2016

Open Sql Statements

Open Sql

Steps

  • Go to Transaction Code SE11.
  • Create a Table.
   


  • Enter some records.

  • Go to Transaction SE38.
  • Enter the program name which start's with Y or Z < program name > and click on Create.
  • Enter the Title.
  • Select the Attribute Type as Executable Program.
  • Click on SAVE.



Source Code


DATA : WA TYPE ZSD_VBAK.
SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001.
  PARAMETERS : VBELN TYPE ZSD_VBAK-SALESORDERNUM.
  SELECTION-SCREEN SKIP 2.
  SELECTION-SCREEN BEGIN OF LINE.
    SELECTION-SCREEN PUSHBUTTON 15(10) W_TEXT1 USER-COMMAND INS.
    SELECTION-SCREEN PUSHBUTTON 25(10) W_TEXT2 USER-COMMAND DEL.
    SELECTION-SCREEN PUSHBUTTON 35(10) W_TEXT3 USER-COMMAND CLR.
    SELECTION-SCREEN PUSHBUTTON 45(10) W_TEXT4 USER-COMMAND DIS.
    SELECTION-SCREEN PUSHBUTTON 65(10) W_TEXT5 USER-COMMAND UPD.
    SELECTION-SCREEN PUSHBUTTON 79(10) W_TEXT6 USER-COMMAND MOD.
  SELECTION-SCREEN END OF LINE.
  SELECTION-SCREEN SKIP 2.
  PARAMETERS : CDATE TYPE ZSD_VBAK-CREATIONDATE ,
               ETIME TYPE ZSD_VBAK-ENTRYTIME ,
               CREATED TYPE ZSD_VBAK-CREATEDBY,
               NETCURR TYPE ZSD_VBAK-SALESCURR.

SELECTION-SCREEN END OF BLOCK B1.

INITIALIZATION.
W_TEXT1 = 'INSERT'.
W_TEXT2 = 'DELETE'.
W_TEXT3 = 'CLEAR'.
W_TEXT4 = 'DISPLAY'.
W_TEXT5 = 'UPDATE'.
W_TEXT6 = 'MODIFY'.
AT SELECTION-SCREEN.
  CASE SY-UCOMM.
    WHEN 'INS'.
      WA-SALESORDERNUM = VBELN.
      WA-CREATIONDATE = CDATE.
      WA-ENTRYTIME = ETIME.
      WA-CREATEDBY = CREATED.
      WA-SALESCURR = NETCURR.

      INSERT ZSD_VBAK FROM WA.
      IF SY-SUBRC = 4.
        MESSAGE 'RECORD ALREADY EXISTS. PLEASE TRY WITH ANOTHER VBELN' TYPE 'I'.
      ELSEIF SY-SUBRC = 0.
        MESSAGE 'RECORD IS INSERTED' TYPE 'S'.
      ELSE.
        MESSAGE 'RECORD IS NOT INSERTED' TYPE 'I'.

      ENDIF.
   WHEN 'DEL'.
      DELETE FROM ZSD_VBAK WHERE SALESORDERNUM = VBELN.
      IF SY-SUBRC = 4.
        MESSAGE 'RECORD DOESNT EXIST. PLEASE TRY WITH ANOTHER VBELN' TYPE 'I'.
      ELSEIF SY-SUBRC = 0.
        MESSAGE 'RECORD IS DELETED' TYPE 'S'.
      ELSE.
        MESSAGE 'RECORD IS NOT DELETED.' TYPE 'I'.
      ENDIF.
  WHEN 'CLR'.
      CLEAR : VBELN , CDATE , ETIME , CREATED , NETCURR.
  WHEN 'DIS'.
    CLEAR WA.
    SELECT SINGLE * FROM ZSD_VBAK INTO WA WHERE SALESORDERNUM = VBELN.
    IF SY-SUBRC <> 0.
      MESSAGE 'RECORD DOESNT EXIST. PLEASE TRY WITH ANOTHER VBELN' TYPE 'I'.
    ELSE.
      VBELN = WA-SALESORDERNUM.
      CDATE = WA-CREATIONDATE.
      ETIME = WA-ENTRYTIME.
      CREATED = WA-CREATEDBY.
      NETCURR = WA-SALESCURR.
    ENDIF.
  WHEN 'UPD'.
    UPDATE ZSD_VBAK SET: CREATIONDATE = CDATE ENTRYTIME = ETIME CREATEDBY = CREATED SALESCURR = NETCURR
      WHERE SALESORDERNUM = VBELN.
    IF SY-SUBRC = 4.
      MESSAGE 'RECORD DOESNT EXIST. PLEASE TRY WITH ANOTHER VBELN' TYPE 'I'.
    ELSEIF SY-SUBRC = 0.
      MESSAGE 'RECORD UPDATED SUCCESSFULLY.' TYPE 'S'.
    ELSE.
      MESSAGE 'RECORD IS NOT UPDATED.' TYPE 'I'.
    ENDIF.
  WHEN 'MOD'.
      WA-SALESORDERNUM = VBELN.
      WA-CREATIONDATE = CDATE.
      WA-ENTRYTIME = ETIME.
      WA-CREATEDBY = CREATED.
      WA-SALESCURR = NETCURR.
    MODIFY ZSD_VBAK FROM WA.
    IF SY-SUBRC = 0.
        MESSAGE 'RECORD IS MODIFIED' TYPE 'S'.
    ENDIF.
  ENDCASE.




  • Save -> Check -> Activate.
  • Execute ( F8 ).

Input -1

  • Enter the VBELN value  which is  there in table records  and click on Display.

Output

Input -2

  • Click on Clear Button.

Output


Input-3

  • Enter VBELN value which is not there in table records and click  Display Button.

Output

Input-4

  • Enter the input values and click on Insert Button.

Output



Input-5

  • Enter the VBELN value which is there in table records and click on DELETE button.


Output

Input-6

  • Enter the VBELN value which is not  there in table records and click on DELETE button.

Output



No comments:

Post a Comment