Dynamic Radio button program in SAP ABAP


Requirement : We have total 6 radio button in the below program. we want to show radio button based upon the RB1 and RB2.

Total radio buttons are  - RB1, RB2, RB3, RB4, RB5, RB6.

When we click RB1 then RB3 and RB4 radio button will show, RB5 and RB6 will be hidden.
When we click RB2 then RB5 and RB6 radio button will show, RB3 and RB4 will be hidden.


Code :
REPORT ZVP_RADIO_BUTTON_DYNAMIC.

SELECTION-SCREENBEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-100.
PARAMETERSRB1 RADIOBUTTON GROUP RBG DEFAULT 'X' USER-COMMAND COMM,
            RB2 RADIOBUTTON GROUP RBG.

SELECTION-SCREENBEGIN OF BLOCK B2 WITH FRAME TITLE TEXT-001.
PARAMETERSRB3 RADIOBUTTON GROUP RBG1 MODIF ID MD1,
            RB4 RADIOBUTTON GROUP RBG1 MODIF ID MD1.
SELECTION-SCREENEND OF BLOCK B2.

SELECTION-SCREENBEGIN OF BLOCK B3 WITH FRAME TITLE TEXT-102.
PARAMETERSRB5 RADIOBUTTON GROUP RBG2 MODIF ID MD2,
            RB6 RADIOBUTTON GROUP RBG2 MODIF ID MD2.
SELECTION-SCREENEND OF BLOCK B3.

SELECTION-SCREENEND OF BLOCK B1.


AT SELECTION-SCREEN OUTPUT.
  IF RB1 'X'.
    LOOP AT SCREEN.
      IF SCREEN-GROUP1 'MD1'.
        SCREEN-ACTIVE 1.
        MODIFY SCREEN.
      ELSEIF SCREEN-GROUP1 'MD2'.
        SCREEN-ACTIVE 0.
        MODIFY SCREEN.
      ENDIF.
    ENDLOOP.
  ELSE.
    LOOP AT SCREEN.
      IF SCREEN-GROUP1 'MD1'.
        SCREEN-ACTIVE 0.
        MODIFY SCREEN.
      ELSEIF SCREEN-GROUP1 'MD2'.
        SCREEN-ACTIVE 1.
        MODIFY SCREEN.
      ENDIF.
    ENDLOOP.
  ENDIF.

IDE Used To Test This Code : ABAP Editor.

Try this code in your computer for better understanding. Enjoy the code. If you have any Question you can contact us or mail us.We will reply you as soon as possible.

SELECT-OPTIONS in SAP ABAP


OBLIGATORY
Code :
REPORT ZVP_SELECT_OPTION.

DATALV_MATNR  TYPE MARA-MATNR.

SELECT-OPTIONSS_MATNR FOR LV_MATNR OBLIGATORY.

Output :

NO-DISPLAY
Code :
REPORT ZVP_SELECT_OPTION.

DATA: LV1_MATNR TYPE MARA-MATNR.

SELECT-OPTIONS: S1_MATNR FOR LV1_MATNR NO-DISPLAY.


NO-EXTENSION
Code :
REPORT ZVP_SELECT_OPTION.

DATA: LV2_MATNR TYPE MARA-MATNR.

SELECT-OPTIONS: S2_MATNR FOR LV2_MATNR NO-EXTENSION.

Output :


NO INTERVALS
Code :
REPORT ZVP_SELECT_OPTION.

DATA: LV3_MATNR TYPE MARA-MATNR.

SELECT-OPTIONS: S3_MATNR FOR LV3_MATNR NO INTERVALS.

Output :

IDE Used To Test This Code : SAP Login 730.

Try this code in your computer for better understanding. Enjoy the code. If you have any Question you can contact us or mail us.We will reply you as soon as possible.

String search in Internal Table in SAP ABAP


Code :
REPORT ZVP_INTERNAL_TBL_STRING_SEARCH.

TYPESBEGIN OF STR,
         ID   TYPE CHAR10,
         NAME TYPE CHAR10,
       END OF STR.

DATAIT_STR TYPE STANDARD TABLE OF STR,
      WA_STR TYPE STR.

WA_STR-ID '1'.
WA_STR-NAME 'SUJOY'.
APPEND WA_STR TO IT_STR.
CLEAR WA_STR.

WA_STR-ID '2'.
WA_STR-NAME 'KAMAL'.
APPEND WA_STR TO IT_STR.
CLEAR WA_STR.

WA_STR-ID '3'.
WA_STR-NAME 'BIJOY'.
APPEND WA_STR TO IT_STR.
CLEAR WA_STR.

WA_STR-ID '4'.
WA_STR-NAME 'NANDAN'.
APPEND WA_STR TO IT_STR.
CLEAR WA_STR.

LOOP AT IT_STR INTO WA_STR.
  SEARCH WA_STR-NAME FOR '*OY'.
  IF SY-SUBRC EQ 0.
    WRITE:/ WA_STR-ID,
    WA_STR-NAME.
  ENDIF.
ENDLOOP.


Output :

IDE Used To Test This Code : SAP Login 730.

Try this code in your computer for better understanding. Enjoy the code. If you have any Question you can contact us or mail us.We will reply you as soon as possible.

How to Initialize a value in Parameter in SAP ABAP


Code :
REPORT ZVP_INIT.

PARAMETERSP_NAME TYPE CHAR10.

INITIALIZATION.
P_NAME 'WORLD'.


Output :

IDE Used To Test This Code : SAP Login 730.

Try this code in your computer for better understanding. Enjoy the code. If you have any Question you can contact us or mail us.We will reply you as soon as possible.

Custom F4 Help program in SAP ABAP


Code :
REPORT ZVP_F4_HELP.

PARAMETERSP_NAME TYPE CHAR10.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_NAME.
  PERFORM GET_HELP.

AT SELECTION-SCREEN.
  IF P_NAME 'HELLO'.
    MESSAGE 'SUCCESS' TYPE 'S'.
  ENDIF.

FORM GET_HELP.

  TYPESBEGIN OF TY_HELP,
           NAME TYPE CHAR15,
         END OF TY_HELP.

  DATAIT_HELP   TYPE STANDARD TABLE OF TY_HELP,
        WA_HELP   TYPE TY_HELP,

        IT_RETURN TYPE TABLE OF DDSHRETVAL,
        WA_RETURN TYPE DDSHRETVAL.

  WA_HELP-NAME 'HELLO'.
  APPEND WA_HELP TO IT_HELP.
  CLEAR WA_HELP.

  WA_HELP-NAME 'WORLD'.
  APPEND WA_HELP TO IT_HELP.
  CLEAR WA_HELP.

  CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
    EXPORTING
      RETFIELD   'NAME'
      VALUE_ORG  'S'
    TABLES
      VALUE_TAB  IT_HELP
      RETURN_TAB IT_RETURN.

*read and transfer the selected value to field / parameter.
  READ TABLE IT_RETURN INTO WA_RETURN INDEX 1.
  P_NAME WA_RETURN-FIELDVAL.

ENDFORM.


Output :

IDE Used To Test This Code : SAP Login 730.

Try this code in your computer for better understanding. Enjoy the code. If you have any Question you can contact us or mail us.We will reply you as soon as possible.

Sum of a series program in CPP


Code :
#include<iostream>
#include<conio.h>
using namespace std;
int main() {
int i, number, sum=0;
cout<<"Enter the limit : ";
cin>>number;
for(i=1; i<=number; i++) {
    sum = sum + i;
}
cout<<"Sum of given series : "<<sum;
return 0;
}


Output :



IDE Used To Test This Code : DEV C++.

Try this code in your computer for better understanding. Enjoy the code. If you have any Question you can contact us or mail us.We will reply you as soon as possible.

Parallel Cursor program in SAP ABAP


Code :
REPORT ZVP_PARALLEL_CURSOR.

TYPESBEGIN OF EMP,
         ID   TYPE I,
         NAME TYPE CHAR10,
       END OF EMP.

TYPES:  BEGIN OF SAL,
          ID     TYPE I,
          MONTH  TYPE CHAR10,
          SALARY TYPE I,
        END OF SAL.

DATAIT_EMP   TYPE STANDARD TABLE OF EMP,
      WA_EMP   TYPE EMP,
      IT_SAL   TYPE STANDARD TABLE OF SAL,
      WA_SAL   TYPE SAL,
      LV_INDEX TYPE I.

WA_EMP-ID '1'.
WA_EMP-NAME 'AAA'.
APPEND WA_EMP TO IT_EMP.

WA_EMP-ID '2'.
WA_EMP-NAME 'BBB'.
APPEND WA_EMP TO IT_EMP.

WA_EMP-ID '3'.
WA_EMP-NAME 'CCC'.
APPEND WA_EMP TO IT_EMP.

WA_SAL-ID '3'.
WA_SAL-MONTH 'MAY'.
WA_SAL-SALARY '3000'.
APPEND WA_SAL TO IT_SAL.

WA_SAL-ID '1'.
WA_SAL-MONTH 'JUNE'.
WA_SAL-SALARY '1000'.
APPEND WA_SAL TO IT_SAL.

WA_SAL-ID '2'.
WA_SAL-MONTH 'JULY'.
WA_SAL-SALARY '2000'.
APPEND WA_SAL TO IT_SAL.

SORTIT_EMPIT_SAL.

LOOP AT IT_EMP INTO WA_EMP.

  READ TABLE IT_SAL INTO WA_SAL WITH KEY ID WA_EMP-ID.
  IF SY-SUBRC 0.
    LV_INDEX SY-TABIX.

    LOOP AT IT_SAL INTO WA_SAL FROM LV_INDEX .
      IF WA_EMP-ID <> WA_SAL-ID.
        EXIT.
      ENDIF.

      WRITE:/ WA_EMP-ID,'|',
              WA_EMP-NAME,'|',
              WA_SAL-MONTH,'|',
              WA_SAL-SALARY,'|'.
    ENDLOOP.
  ENDIF.
ENDLOOP.


Output :

IDE Used To Test This Code : SAP Login 730.

Try this code in your computer for better understanding. Enjoy the code. If you have any Question you can contact us or mail us.We will reply you as soon as possible.

ALV program using Subroutine in SAP ABAP


Code :
REPORT ZVP_ALV_EKPO_DETAILS.

TYPE-POOLSSLIS.

TYPESBEGIN OF ST_EKPO,
         EBELN TYPE EBELN,
         MATNR TYPE MATNR,
         EMATN TYPE EMATN,
         BUKRS TYPE BUKRS,
       END OF ST_EKPO.


DATAIT_EKPO   TYPE STANDARD TABLE OF ST_EKPO,
      WA_EKPO   TYPE ST_EKPO,

      IT_FCAT   TYPE SLIS_T_FIELDCAT_ALV,
      WA_FCAT   TYPE SLIS_FIELDCAT_ALV,
      WA_LAYOUT TYPE SLIS_LAYOUT_ALV,

      LV_EBELN  TYPE EKPO-EBELN.

SELECT-OPTIONSS_EBELN FOR LV_EBELN.

SELECT EBELN
       MATNR
       BUKRS
  FROM EKPO INTO TABLE IT_EKPO UP TO 50 ROWS
  WHERE EBELN IN S_EBELN.

PERFORM GETDETAILS.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
  EXPORTING
    IS_LAYOUT   WA_LAYOUT
    IT_FIELDCAT IT_FCAT
  TABLES
    T_OUTTAB    IT_EKPO.


FORM GETDETAILS.
  WA_FCAT-COL_POS '1'.
  WA_FCAT-FIELDNAME 'EBELN'.
  WA_FCAT-SELTEXT_M 'Purchasing Document Number'.
  APPEND WA_FCAT TO IT_FCAT.

  WA_FCAT-COL_POS '2'.
  WA_FCAT-FIELDNAME 'MATNR'.
  WA_FCAT-SELTEXT_M 'Material Number'.
  APPEND WA_FCAT TO IT_FCAT.

  WA_FCAT-COL_POS '3'.
  WA_FCAT-FIELDNAME 'BURKS'.
  WA_FCAT-SELTEXT_M 'Company Code'.
  APPEND WA_FCAT TO IT_FCAT.

  WA_LAYOUT-COLWIDTH_OPTIMIZE 'X'.
ENDFORM.


Output :


IDE Used To Test This Code : SAP Login 730.

Try this code in your computer for better understanding. Enjoy the code. If you have any Question you can contact us or mail us.We will reply you as soon as possible.

How to Concatenate two Strings in SAP ABAP


Code :
REPORT ZVP_PRACTICE.

DATAVAR1(50)    TYPE C,
      VAR2(50)    TYPE C,
      OUTPUT(200TYPE C.

VAR1 'HELLO'.
VAR2 'WORLD!'.

CONCATENATE VAR1 VAR2 INTO OUTPUT SEPARATED BY ','.

WRITE:OUTPUT.


Output :
HELLO,WORLD!

IDE Used To Test This Code : SAP Login 730.

Try this code in your computer for better understanding. Enjoy the code. If you have any Question you can contact us or mail us.We will reply you as soon as possible.

Compare two string in SAP ABAP


Code :
REPORT ZVP_PRACTICE.

DATAVAR1(50TYPE C,
      VAR2(50TYPE C.

VAR1 'HELLO WORLD!'.
VAR2 'HELLO WORLD!'.

IF VAR1 VAR2.
  WRITE:/'EQUAL'.
ELSE.
  WRITE:/'NOT EQUAL'.
ENDIF.

Output :
EQUAL

IDE Used To Test This Code : SAP Login 730.

Try this code in your computer for better understanding. Enjoy the code. If you have any Question you can contact us or mail us.We will reply you as soon as possible.

Length of a string program in SAP ABAP


Code :
REPORT ZVP_PRACTICE.

DATAVAR1(50TYPE C,
      OUTPUT TYPE I.

VAR1 'HELLO WORLD!'.

OUTPUT STRLENVAR1 ).

WRITE:'LENGTH OF THE STRING IS :',OUTPUT.


Output :
LENGTH OF THE STRING IS : 12

IDE Used To Test This Code : SAP Login 730

Try this code in your computer for better understanding. Enjoy the code. If you have any Question you can contact us or mail us.We will reply you as soon as possible.

How to count no of record in Internal Table in SAP ABAP


Code :
REPORT ZVP_PRACTICE.

TYPESBEGIN OF ST_EKKO,
         EBELN TYPE EKKO-EBELN,
         BUKRS TYPE EKKO-BUKRS,
         BSART TYPE EKKO-BSART,
       END OF ST_EKKO.

DATAIT_EKKO TYPE STANDARD TABLE OF ST_EKKO,
      WA_EKKO TYPE ST_EKKO,
      LV_VAR  TYPE I.

SELECT EBELN
       BUKRS
       BSART
  FROM EKKO INTO TABLE IT_EKKO UP TO 10 ROWS WHERE BUKRS '3000'.

IF SY-SUBRC 0.
  LOOP AT IT_EKKO INTO WA_EKKO.
    WRITE:/ WA_EKKO-EBELN'|',
            WA_EKKO-BUKRS'|',
            WA_EKKO-BSART'|'.
    ULINE.
  ENDLOOP.
ENDIF.

DESCRIBE TABLE IT_EKKO LINES LV_VAR.
WRITE'TOTAL ROWS ARE :',LV_VAR.


Output :

IDE Used To Test This Code : SAP Login 370.

Try this code in your computer for better understanding. Enjoy the code. If you have any Question you can contact us or mail us.We will reply you as soon as possible.

SAP ABAP Internal Table value check sample program


Code :
REPORT ZVP_PRACTICE.

TYPESBEGIN OF STPRODUCT,
         PRODUCT_NAME     TYPE CHAR10,
         PRODUCT_QUANTITY TYPE CHAR10,
       END OF STPRODUCT.

DATAIT_STPRODUCT TYPE STANDARD TABLE OF STPRODUCT,
      WA_STPRODUCT TYPE STPRODUCT,
      LV_VAR       TYPE I.

WA_STPRODUCT-PRODUCT_NAME 'SOAP'.
WA_STPRODUCT-PRODUCT_QUANTITY 10.
APPEND WA_STPRODUCT TO IT_STPRODUCT.
CLEAR WA_STPRODUCT.

WA_STPRODUCT-PRODUCT_NAME 'SHAMPOO'.
WA_STPRODUCT-PRODUCT_QUANTITY 5.
APPEND WA_STPRODUCT TO IT_STPRODUCT.
CLEAR WA_STPRODUCT.

WA_STPRODUCT-PRODUCT_NAME 'BRUSH'.
WA_STPRODUCT-PRODUCT_QUANTITY 3.
APPEND WA_STPRODUCT TO IT_STPRODUCT.
CLEAR WA_STPRODUCT.

WA_STPRODUCT-PRODUCT_NAME 'OIL PACKET'.
WA_STPRODUCT-PRODUCT_QUANTITY 9.
APPEND WA_STPRODUCT TO IT_STPRODUCT.
CLEAR WA_STPRODUCT.

WA_STPRODUCT-PRODUCT_NAME 'PERFUME'.
WA_STPRODUCT-PRODUCT_QUANTITY 5.
APPEND WA_STPRODUCT TO IT_STPRODUCT.
CLEAR WA_STPRODUCT.



LOOP AT IT_STPRODUCT INTO WA_STPRODUCT.
  WRITE:/ WA_STPRODUCT-PRODUCT_NAME'|',
          WA_STPRODUCT-PRODUCT_QUANTITY'|'.


  IF WA_STPRODUCT-PRODUCT_QUANTITY 3.
    LV_VAR WA_STPRODUCT-PRODUCT_QUANTITY.
  ENDIF.


  ULINE.
ENDLOOP.

IF LV_VAR 3.
  WRITE:'LOW STOCK FOUND'.
ELSE.
  WRITE:'NOT FOUND'.
ENDIF.

 
Output :

IDE Used To Test This Code : SAP GUI 730

Try this code in your computer for better understanding. Enjoy the code. If you have any Question you can contact us or mail us.We will reply you as soon as possible.