Friday, May 12, 2023

SAP ABAP System Variables

SYSTEM VARIBLES IMAGE

 

In SAP ABAP, system variables are predefined variables that hold system-related information. Here are some commonly used system variables in ABAP: 

 1. SY-DATUM: This variable holds the current system date in the format YYYYMMDD.  

2. SY-UZEIT: This variable holds the current system time in the format HHMMSS.  

3. SY-UNAME: This variable holds the name of the current user.  

4. SY-SYSID: This variable holds the name of the current system. 

5. SY-MANDT: This variable holds the current client number.  

6. SY-INDEX: This variable holds the current loop index value within a loop.  

7. SY-SUBRC: This variable holds the return code of the last executed ABAP statement.  

8. SY-DBCNT: This variable holds the number of rows affected by the last executed database operation.  

9. SY-LANGU: This variable holds the current user's language.  

10. SY-MSGTY: This variable holds the message type of the last executed ABAP statement. 

 You can use these system variables in your ABAP programs to perform various tasks, such as date and time calculations, user and system validation, and message handling. You can also define your own custom system variables using the SYST structure. 

For example, you can define a custom system variable like SY-<variable_name> and assign a value to it using the SYST-<variable_name> statement.


CODE FOR THE SAME GIVEN BELOW:

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

PARAMETERS P_X TYPE DEFAULT 20 OBLIGATORY,
             P_Y TYPE DEFAULT 10 OBLIGATORY,
             P_STR  TYPE STRING LOWER CASE DEFAULT 'HELLO WORLD'.


DATA V_Z TYPE I" VARIABLE DECLARED NORMALLY USING V_ AND THIS VARIBLE IS USED TO STORE USER INPUT

V_Z P_X + P_Y.


WRITE :'SUM OF TWO NUMBERS IS :'V_Z COLOR LEFT-JUSTIFIED.

*WRITE :/ 'ENTERED STRING IS :', P_STR COLOR 2 LEFT-JUSTIFIED.      "(OR )

FORMAT COLOR 6.

WRITE :'ENTERED STRING IS :'P_STR.

FORMAT COLOR off.

WRITE :'CURRENT DATE IS 'SY-datum.
WRITE :'CURRENT TIME IS 'SY-uzeit.
WRITE :'CURRENT TIME IS 'SY-UNAME.
WRITE :'CURRENT TIME IS 'SY-REPID.
WRITE :'CURRENT TIME IS 'SY-PAGNO.


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


OUTPUT FOR THE ABOVE CODE :


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

 Follow me for more on LinkedIn : 👍 (432) LinkedIn

 

Thursday, May 11, 2023

SELECTION SCREEN IN SAP ABAP






 Selection Screen is a user interface element in SAP ABAP that is used to get input from the user at the start of a program execution. It allows users to input the required values or parameters for the program to execute correctly.

A selection screen can be defined using ABAP statements and provides a set of input fields that can be used to receive the user's input. These input fields include selection options, parameters, checkboxes, and radio buttons.

Here are some common selection screen elements in SAP ABAP:

  1. Selection Options: Allows users to select multiple values from a list of available options.

  2. Parameters: Allows users to input a single value such as date, text, or number.

  3. Checkboxes: Allows users to select one or more options.

  4. Radio Buttons: Allows users to select a single option from a set of available options.

In addition to these elements, selection screens can also include pushbuttons such as execute, cancel, or help. The selection screen is displayed at the start of the program and allows the user to input values before executing the program.

Once the user enters the required values, the program can use these values to perform further operations. Therefore, selection screens play a vital role in user interaction with SAP ABAP programs.

CODE FOR THE ABOVE IMAGE GIVEN BELOW:

DATA V_Z TYPE I.

SELECTION-SCREEN BEGIN OF BLOCK BK1 WITH FRAME title t1.   " Selctiom screen block layout.

SELECTION-SCREEN BEGIN OF LINE.
  SELECTION-SCREEN COMMENT 8(20LB1.
                             """"8 MEANS STARTING FROM 8 FROM LEFT POSITION AND RESERVE 20 CHAR OR SPACES NOW FOR ENTIRE TEXT GIVING SOME VARIABLE NAME LB1
  PARAMETERS P_X TYPE DEFAULT 20 OBLIGATORY.


SELECTION-SCREEN END OF LINE.

SELECTION-SCREEN BEGIN OF LINE.
  SELECTION-SCREEN COMMENT 8(20LB2.
                             """"8 MEANS STARTING FROM 8 FROM LEFT POSITION AND RESERVE 20 CHAR OR SPACES NOW FOR ENTIRE TEXT GIVING SOME VARIABLE NAME LB1
  PARAMETERS P_Y TYPE DEFAULT 15 OBLIGATORY.


SELECTION-SCREEN END OF LINE.

SELECTION-SCREEN END OF BLOCK BK1.

SELECTION-SCREEN BEGIN OF BLOCK BK2 WITH FRAME TITLE T2.



PARAMETERS P_R1 RADIOBUTTON GROUP GRP1,
             P_R2 RADIOBUTTON GROUP GRP1,
             P_R3 RADIOBUTTON GROUP GRP1,
             P_R4 RADIOBUTTON GROUP GRP1,
             P_R5 RADIOBUTTON GROUP GRP1 DEFAULT 'X'.

SELECTION-SCREEN END OF BLOCK BK2.

INITIALIZATION.

LB1 'ENTER FIRST NUMBER'.
LB2 'ENTER SECOND NUMBER'.
T1 'ENTER INPUT VALUES'.
T2 'ARITHMETIC OPERATIONS'.

START-OF-SELECTION.

IF P_R1 'X'.
  V_Z P_X + P_Y.
  WRITE :'SUM IS :'V_Z.

ELSEIF P_R2 'X'.
  V_Z P_X P_Y.

  if V_Z >= 0.
    WRITE :'DIFFERENCE IS :'V_Z.
  ELSE.
    WRITE :'DIFFERENCE IS : -' NO-GAP,V_Z NO-SIGN LEFT-JUSTIFIED.
  ENDIF.


ELSEIF P_R3 'X'.
  V_Z P_X * P_Y.
  WRITE :'PRODUCT IS :'V_Z.
ELSEIF P_R4 'X'.
  V_Z P_X / P_Y.
  WRITE :' IS :'V_Z.

ELSE.
  write :'NONE OF THE BUTTON IS SELECTED'.
   MESSAGE 'NONE RADIOBUTTON SELECTED' TYPE 'I'.
ENDIF.




Follow me for more on LinkedIn : 👍 (432) LinkedIn

SAP ABAP System Variables

  In SAP ABAP, system variables are predefined variables that hold system-related information. Here are some commonly used system variables ...