Simple CLASS Program in SAP ABAP


Code :
REPORT ZVP_CLASS_SAMPLE.

CLASS DEMO DEFINITION.
  PUBLIC SECTION.
  DATAV1 TYPE VALUE 20.

  PROTECTED SECTION.

  PRIVATE SECTION.
ENDCLASS.

START-OF-SELECTION.
DATA OBJ TYPE REF TO DEMO.
CREATE OBJECT OBJ.
WRITE:/ OBJ->V1.


Output :

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.

SAP ABAP ALV Block List program


Code :
REPORT ZVP_ALV_BLOCKED.

TYPE-POOLSSLIS.

TYPESBEGIN OF TY_MARA,
        MATNR TYPE MARA-MATNR,
        MTART TYPE MARA-MTART,
        MBRSH TYPE MARA-MBRSH,
        MATKL TYPE MARA-MATKL,
        MEINS TYPE MARA-MEINS,
      END OF TY_MARA.

TYPESBEGIN OF TY_MAKT,
        MATNR TYPE MAKT-MATNR,
        SPRAS TYPE MAKT-SPRAS,
        MAKTX TYPE MAKT-MAKTX,
      END OF TY_MAKT.

DATAIT_MARA TYPE TABLE OF TY_MARA,
      WA_MARA TYPE TY_MARA,

      IT_MAKT TYPE TABLE OF TY_MAKT,
      WA_MAKT TYPE TY_MAKT.

DATAIT_FCAT_MARA TYPE SLIS_T_FIELDCAT_ALV"FOR MARA TABLE
      WA_FCAT_MARA TYPE SLIS_FIELDCAT_ALV,

      IT_FCAT_MAKT TYPE SLIS_T_FIELDCAT_ALV"FOR MAKT TABLE
      WA_FCAT_MAKT TYPE SLIS_FIELDCAT_ALV,

      IT_EVENTS TYPE SLIS_T_EVENT,
      WA_LAYOUT TYPE SLIS_LAYOUT_ALV.

PARAMETERSP_MTART TYPE MARA-MTART.

SELECT MATNR
       MTART
       MBRSH
       MATKL
       MEINS
  FROM MARA INTO TABLE IT_MARA UP TO ROWS WHERE MTART P_MTART.

  IF IT_MARA IS NOT INITIAL.
    SELECT MATNR
           SPRAS
           MAKTX
      FROM MAKT INTO TABLE IT_MAKT UP TO ROWS
      FOR ALL ENTRIES IN IT_MARa WHERE MATNR IT_MARA-MATNR.
  ENDIF.

"FOR MARA TABLE
WA_FCAT_MARA-COL_POS '1'.
WA_FCAT_MARA-FIELDNAME 'MATNR'.
WA_FCAT_MARA-TABNAME 'IT_MARA'.
WA_FCAT_MARA-REF_TABNAME 'MARA'.
WA_FCAT_MARA-REF_FIELDNAME 'MATNR'.
APPEND WA_FCAT_MARA TO IT_FCAT_MARA.
CLEAR WA_FCAT_MARA.

WA_FCAT_MARA-COL_POS '2'.
WA_FCAT_MARA-FIELDNAME 'MTART'.
WA_FCAT_MARA-TABNAME 'IT_MARA'.
WA_FCAT_MARA-REF_TABNAME 'MARA'.
WA_FCAT_MARA-REF_FIELDNAME 'MTART'.
APPEND WA_FCAT_MARA TO IT_FCAT_MARA.
CLEAR WA_FCAT_MARA.

WA_FCAT_MARA-COL_POS '3'.
WA_FCAT_MARA-FIELDNAME 'MBRSH'.
WA_FCAT_MARA-TABNAME 'IT_MARA'.
WA_FCAT_MARA-REF_TABNAME 'MARA'.
WA_FCAT_MARA-REF_FIELDNAME 'MBRSH'.
APPEND WA_FCAT_MARA TO IT_FCAT_MARA.
CLEAR WA_FCAT_MARA.

WA_FCAT_MARA-COL_POS '4'.
WA_FCAT_MARA-FIELDNAME 'MATKL'.
WA_FCAT_MARA-TABNAME 'IT_MARA'.
WA_FCAT_MARA-REF_TABNAME 'MARA'.
WA_FCAT_MARA-REF_FIELDNAME 'MATKL'.
APPEND WA_FCAT_MARA TO IT_FCAT_MARA.
CLEAR WA_FCAT_MARA.

WA_FCAT_MARA-COL_POS '5'.
WA_FCAT_MARA-FIELDNAME 'MEINS'.
WA_FCAT_MARA-TABNAME 'IT_MARA'.
WA_FCAT_MARA-REF_TABNAME 'MARA'.
WA_FCAT_MARA-REF_FIELDNAME 'MEINS'.
APPEND WA_FCAT_MARA TO IT_FCAT_MARA.
CLEAR WA_FCAT_MARA.

"FOR MAKT TABLE
WA_FCAT_MAKT-COL_POS '1'.
WA_FCAT_MAKT-FIELDNAME 'MATNR'.
WA_FCAT_MAKT-TABNAME 'IT_MAKT'.
WA_FCAT_MAKT-REF_TABNAME 'MAKT'.
WA_FCAT_MAKT-REF_FIELDNAME 'MATNR'.
APPEND WA_FCAT_MAKT TO IT_FCAT_MAKT.
CLEAR WA_FCAT_MAKT.

WA_FCAT_MAKT-COL_POS '2'.
WA_FCAT_MAKT-FIELDNAME 'SPRAS'.
WA_FCAT_MAKT-TABNAME 'IT_MAKT'.
WA_FCAT_MAKT-REF_TABNAME 'MAKT'.
WA_FCAT_MAKT-REF_FIELDNAME 'SPRAS'.
APPEND WA_FCAT_MAKT TO IT_FCAT_MAKT.
CLEAR WA_FCAT_MAKT.

WA_FCAT_MAKT-COL_POS '3'.
WA_FCAT_MAKT-FIELDNAME 'MAKTX'.
WA_FCAT_MAKT-TABNAME 'IT_MAKT'.
WA_FCAT_MAKT-REF_TABNAME 'MAKT'.
WA_FCAT_MAKT-REF_FIELDNAME 'MAKTX'.
APPEND WA_FCAT_MAKT TO IT_FCAT_MAKT.
CLEAR WA_FCAT_MAKT.

CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_INIT'
  EXPORTING
    I_CALLBACK_PROGRAM             SY-REPID.
*   I_CALLBACK_PF_STATUS_SET       = ' '
*   I_CALLBACK_USER_COMMAND        = ' '
*   IT_EXCLUDING                   =

CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_APPEND'
  EXPORTING
    IS_LAYOUT                        WA_LAYOUT
    IT_FIELDCAT                      IT_FCAT_MARA
    I_TABNAME                        'IT_MARA'
    IT_EVENTS                        IT_EVENTS
*   IT_SORT                          =
*   I_TEXT                           = ' '
  TABLES
    T_OUTTAB                         IT_MARA
* EXCEPTIONS
*   PROGRAM_ERROR                    = 1
*   MAXIMUM_OF_APPENDS_REACHED       = 2
*   OTHERS                           = 3
          .
IF SY-SUBRC <> 0.
* Implement suitable error handling here
ENDIF.

CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_APPEND'
  EXPORTING
    IS_LAYOUT                        WA_LAYOUT
    IT_FIELDCAT                      IT_FCAT_MAKT
    I_TABNAME                        'IT_MAKT'
    IT_EVENTS                        IT_EVENTS
*   IT_SORT                          =
*   I_TEXT                           = ' '
  TABLES
    T_OUTTAB                         IT_MAKT
* EXCEPTIONS
*   PROGRAM_ERROR                    = 1
*   MAXIMUM_OF_APPENDS_REACHED       = 2
*   OTHERS                           = 3
          .
IF SY-SUBRC <> 0.
* Implement suitable error handling here
ENDIF.

CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_DISPLAY'
* EXPORTING
*   I_INTERFACE_CHECK             = ' '
*   IS_PRINT                      =
*   I_SCREEN_START_COLUMN         = 0
*   I_SCREEN_START_LINE           = 0
*   I_SCREEN_END_COLUMN           = 0
*   I_SCREEN_END_LINE             = 0
* IMPORTING
*   E_EXIT_CAUSED_BY_CALLER       =
*   ES_EXIT_CAUSED_BY_USER        =
* EXCEPTIONS
*   PROGRAM_ERROR                 = 1
*   OTHERS                        = 2
          .
IF SY-SUBRC <> 0.
* Implement suitable error handling here
ENDIF.


Output : 


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.

SAP ABAP Program for Lowercase to Uppercase character


Code :
REPORT ZVP_STRING_UPPERCASE.

PARAMETERSP_STRING TYPE CHAR10.

TRANSLATE P_STRING TO UPPER CASE.
WRITEP_STRING.


Output :


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.

SAP ABAP Program using COLLECT Statement


Code :
REPORT ZVP_COLLECT_PROGRAM.

TYPESBEGIN OF PERSON,
  ID TYPE N,
  NAME TYPE CHAR10,
  SALARY TYPE I,
  END OF PERSON.

DATAIT TYPE TABLE OF PERSON,
      WA TYPE PERSON.

WA-ID '1'.
WA-NAME 'SANJAY'.
WA-SALARY '5000'.
COLLECT WA INTO IT.
CLEAR WA.

WA-ID '1'.
WA-NAME 'SANJAY'.
WA-SALARY '500'.
COLLECT WA INTO IT.
CLEAR WA.

WA-ID '3'.
WA-NAME 'NIKESH'.
WA-SALARY '3000'.
COLLECT WA INTO IT.
CLEAR WA.

WA-ID '4'.
WA-NAME 'HIMANGSHU'.
WA-SALARY '5200'.
COLLECT WA INTO IT.
CLEAR WA.

LOOP AT IT INTO WA.
WRITE/ WA-ID'|',
          WA-NAME'|',
          WA-SALARY.
ULINE.
ENDLOOP.


Output :

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.

ABAP Report with SUM Aggregate functions.


Code :
REPORT ZVP_SELECT_SUM_GROUP_BY.

TYPESBEGIN OF TY_VBAP,
         VBELN TYPE VBAP-VBELN,
         CMPRE TYPE VBAP-CMPRE,
       END OF TY_VBAP.

DATAIT       TYPE TABLE OF TY_VBAP,
      WA       TYPE TY_VBAP,

      LV_VBELN TYPE VBAP-VBELN.

SELECT-OPTIONSS_VBELN FOR LV_VBELN.

SELECT VBELN
       SUMCMPRE )
  FROM VBAP INTO TABLE IT UP TO 20 ROWS WHERE VBELN IN S_VBELN GROUP BY VBELN.

IF SY-SUBRC EQ 0.
  WRITE:'VBELN''             CMPRE'.
  LOOP AT IT INTO WA.
    WRITE:/ WA-VBELN,
    WA-CMPRE.

  ENDLOOP.
ENDIF.


Output :

sum of the CMPRE values with corresponding to same VBELN values.



 

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.

Message class creation in SAP ABAP


1. To create Message class in SAP go to Transaction Code SE91.

2. Put the Message class name with Z (like ZVP_MSG_CLASS) and click Create button.

3. Put the Message Short Text with respect to Message Number (like 000,001,002).


4. Save the Message text and Activate the Message class.

5. After that go to SE38 and give a program name starting with Z, in my case i am giving ZVP_MSG_CLASS_CALL.

6. Source code is below.

REPORT ZVP_MSG_CLASS_CALL.
message i002(zvp_msg_class).

7. Here 'i' information, you can use e, s which is error error and success. Activate the program and run it.

Output :

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.

Control Break Statement Program in SAP ABAP


Code :
REPORT ZVP_CONTROL_BREAK.

TYPESBEGIN OF TY_MARC,
         MATNR TYPE MARC-MATNR,
         WERKS TYPE MARC-WERKS,
       END OF TY_MARC.

DATAIT_MARC TYPE TABLE OF TY_MARC,
      WA_MARC TYPE TY_MARC,
      WA_TEMP TYPE TY_MARC.


SELECT MATNR
       WERKS
  FROM MARC INTO TABLE IT_MARC UP TO 20 ROWS.
DELETE IT_MARC WHERE MATNR SPACE.

WRITE:'FULL TABLE'.
LOOP AT IT_MARC INTO WA_MARC.
  WRITE:/ SY-TABIX,
          WA_MARC-MATNR,
          WA_MARC-WERKS.
ENDLOOP.

WRITE:'AT FIRST'.
LOOP AT IT_MARC INTO WA_MARC.
  WA_TEMP WA_MARC.
  AT FIRST.
    WRITE:/ SY-TABIX,
              WA_TEMP-MATNR,
              WA_TEMP-WERKS.
  ENDAT.
ENDLOOP.

WRITE:'AT LAST'.
LOOP AT IT_MARC INTO WA_MARC.
  WA_TEMP WA_MARC.
  AT LAST.
    WRITE:/ SY-TABIX,
              WA_TEMP-MATNR,
              WA_TEMP-WERKS.
  ENDAT.
ENDLOOP.

WRITE:'AT NEW'.
LOOP AT IT_MARC INTO WA_MARC.
  WA_TEMP WA_MARC.
  AT NEW MATNR.
    WRITE:/ SY-TABIX,
              WA_TEMP-MATNR,
              WA_TEMP-WERKS.
  ENDAT.
ENDLOOP.

WRITE:'AT END OF'.
LOOP AT IT_MARC INTO WA_MARC.
  WA_TEMP WA_MARC.
  AT END OF MATNR.
    WRITE:/ SY-TABIX,
              WA_TEMP-MATNR,
              WA_TEMP-WERKS.
  ENDAT.
ENDLOOP.

Output :


IDE Used To Test This Code : SAP 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.

ALV Subtotal Program in SAP ABAP


Code :
REPORT ZVP_ALV_SUBTOTAL.

TYPE-POOLSSLIS.

TYPESBEGIN OF TY_VBAP,
        VBELN TYPE VBAP-VBELN,
        MATNR TYPE VBAP-MATNR,
        POSAR TYPE VBAP-POSAR,
        NETPR TYPE VBAP-NETPR,
      END OF TY_VBAP.

DATAIT_VBAP TYPE TABLE OF TY_VBAP,
      WA_VBAP TYPE TY_VBAP,

      IT_FCAT TYPE SLIS_T_FIELDCAT_ALV,
      WA_FCAT TYPE SLIS_FIELDCAT_ALV,
      IT_SORT   TYPE SLIS_T_SORTINFO_ALV,
      WA_SORT   TYPE SLIS_SORTINFO_ALV,
      WA_LAYOUT TYPE SLIS_LAYOUT_ALV.


SELECT  VBELN
        MATNR
        POSAR
        NETPR
  FROM VBAP INTO TABLE IT_VBAP UP TO 12 ROWS.


WA_FCAT-COL_POS '1'.
WA_FCAT-FIELDNAME 'VBELN'.
WA_FCAT-SELTEXT_M 'VBELN'.
APPEND WA_FCAT TO IT_FCAT.

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

WA_FCAT-COL_POS '3'.
WA_FCAT-FIELDNAME 'POSAR'.
WA_FCAT-SELTEXT_M 'POSAR'.
APPEND WA_FCAT TO IT_FCAT.

WA_FCAT-COL_POS '4'.
WA_FCAT-FIELDNAME 'NETPR'.
WA_FCAT-SELTEXT_M 'NETPR'.
WA_FCAT-DO_SUM 'X'.
APPEND WA_FCAT TO IT_FCAT.

WA_SORT-SPOS '2'.
WA_SORT-FIELDNAME 'MATNR'.
WA_SORT-UP 'X'.
WA_SORT-SUBTOT 'X'.
APPEND WA_SORT TO IT_SORT.


WA_LAYOUT-COLWIDTH_OPTIMIZE 'X'.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
 EXPORTING
*   I_INTERFACE_CHECK                 = ' '
*   I_BYPASSING_BUFFER                = ' '
*   I_BUFFER_ACTIVE                   = ' '
*   I_CALLBACK_PROGRAM                = ' '
*   I_CALLBACK_PF_STATUS_SET          = ' '
*   I_CALLBACK_USER_COMMAND           = ' '
*   I_CALLBACK_TOP_OF_PAGE            = ' '
*   I_CALLBACK_HTML_TOP_OF_PAGE       = ' '
*   I_CALLBACK_HTML_END_OF_LIST       = ' '
*   I_STRUCTURE_NAME                  =
*   I_BACKGROUND_ID                   = ' '
*   I_GRID_TITLE                      =
*   I_GRID_SETTINGS                   =
   IS_LAYOUT                         WA_LAYOUT
   IT_FIELDCAT                       IT_FCAT
*   IT_EXCLUDING                      =
*   IT_SPECIAL_GROUPS                 =
   IT_SORT                           IT_SORT
*   IT_FILTER                         =
*   IS_SEL_HIDE                       =
*   I_DEFAULT                         = 'X'
*   I_SAVE                            = ' '
*   IS_VARIANT                        =
*   IT_EVENTS                         =
*   IT_EVENT_EXIT                     =
*   IS_PRINT                          =
*   IS_REPREP_ID                      =
*   I_SCREEN_START_COLUMN             = 0
*   I_SCREEN_START_LINE               = 0
*   I_SCREEN_END_COLUMN               = 0
*   I_SCREEN_END_LINE                 = 0
*   I_HTML_HEIGHT_TOP                 = 0
*   I_HTML_HEIGHT_END                 = 0
*   IT_ALV_GRAPHICS                   =
*   IT_HYPERLINK                      =
*   IT_ADD_FIELDCAT                   =
*   IT_EXCEPT_QINFO                   =
*   IR_SALV_FULLSCREEN_ADAPTER        =
* IMPORTING
*   E_EXIT_CAUSED_BY_CALLER           =
*   ES_EXIT_CAUSED_BY_USER            =
  TABLES
    T_OUTTAB                          IT_VBAP
* EXCEPTIONS
*   PROGRAM_ERROR                     = 1
*   OTHERS                            = 2
          .
IF SY-SUBRC <> 0.
* Implement suitable error handling here
ENDIF.


Output :

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.

Traffic light program in SAP ABAP


Code :
REPORT ZVP_TRAFFIC_LIGHT_PROGRAM.

TYPE-POOLSSLIS.

TYPESBEGIN OF TY_MARA,
         MATNR  TYPE MARA-MATNR,
         MTART  TYPE MARA-MTART,
         MATKL  TYPE MARA-MATKL,
         GROES  TYPE MARA-GROES,
         NTGEW  TYPE MARA-NTGEW,
         LIGHTS TYPE C,
       END OF TY_MARA.


DATAIT_MARA   TYPE STANDARD TABLE OF TY_MARA,
      WA_MARA   TYPE TY_MARA,

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

      LV_MATNR  TYPE MARA-MATNR.

SELECT-OPTIONSS_MATNR FOR LV_MATNR.


SELECT MATNR
       MTART
       MATKL
       GROES
       NTGEW
  FROM MARA INTO TABLE IT_MARA WHERE MATNR IN S_MATNR.

PERFORM CALL_ALV.


CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
  EXPORTING
*   I_INTERFACE_CHECK  = ' '
*   I_BYPASSING_BUFFER = ' '
*   I_BUFFER_ACTIVE    = ' '
    I_CALLBACK_PROGRAM SY-REPID
*   I_CALLBACK_PF_STATUS_SET          = ' '
*   I_CALLBACK_USER_COMMAND           = ' '
*   I_CALLBACK_TOP_OF_PAGE            = ' '
*   I_CALLBACK_HTML_TOP_OF_PAGE       = ' '
*   I_CALLBACK_HTML_END_OF_LIST       = ' '
*   I_STRUCTURE_NAME   =
*   I_BACKGROUND_ID    = ' '
*   I_GRID_TITLE       =
*   I_GRID_SETTINGS    =
    IS_LAYOUT          WA_LAYOUT
    IT_FIELDCAT        IT_FCAT
*   IT_EXCLUDING       =
*   IT_SPECIAL_GROUPS  =
*   IT_SORT            =
*   IT_FILTER          =
*   IS_SEL_HIDE        =
*   I_DEFAULT          = 'X'
*   I_SAVE             = ' '
*   IS_VARIANT         =
*   IT_EVENTS          =
*   IT_EVENT_EXIT      =
*   IS_PRINT           =
*   IS_REPREP_ID       =
*   I_SCREEN_START_COLUMN             = 0
*   I_SCREEN_START_LINE               = 0
*   I_SCREEN_END_COLUMN               = 0
*   I_SCREEN_END_LINE  = 0
*   I_HTML_HEIGHT_TOP  = 0
*   I_HTML_HEIGHT_END  = 0
*   IT_ALV_GRAPHICS    =
*   IT_HYPERLINK       =
*   IT_ADD_FIELDCAT    =
*   IT_EXCEPT_QINFO    =
*   IR_SALV_FULLSCREEN_ADAPTER        =
* IMPORTING
*   E_EXIT_CAUSED_BY_CALLER           =
*   ES_EXIT_CAUSED_BY_USER            =
  TABLES
    T_OUTTAB           IT_MARA
* EXCEPTIONS
*   PROGRAM_ERROR      = 1
*   OTHERS             = 2
  .
IF SY-SUBRC <> 0.
* Implement suitable error handling here
ENDIF.

FORM CALL_ALV.

  LOOP AT IT_MARA INTO WA_MARA.
    IF
      WA_MARA-MATKL 'XLCL'.
      WA_MARA-LIGHTS 1.
    ELSEIF
      WA_MARA-MATKL 'XLVL'.
      WA_MARA-LIGHTS 2.
    ELSE.
      WA_MARA-LIGHTS 3.
    ENDIF.
    MODIFY IT_MARA FROM WA_MARA TRANSPORTING LIGHTS.
    CLEAR WA_MARA.
  ENDLOOP.


  WA_FCAT-COL_POS '1'.
  WA_FCAT-FIELDNAME 'MATNR'.
  WA_FCAT-SELTEXT_M 'MATERIAL NUMBER'.
  APPEND WA_FCAT TO IT_FCAT.
  CLEAR WA_FCAT.

  WA_FCAT-COL_POS '2'.
  WA_FCAT-FIELDNAME 'MTART'.
  WA_FCAT-SELTEXT_M 'MTART'.
  APPEND WA_FCAT TO IT_FCAT.
  CLEAR WA_FCAT.

  WA_FCAT-COL_POS '3'.
  WA_FCAT-FIELDNAME 'MATKL'.
  WA_FCAT-SELTEXT_M 'MATKL'.
  APPEND WA_FCAT TO IT_FCAT.
  CLEAR WA_FCAT.

  WA_FCAT-COL_POS '4'.
  WA_FCAT-FIELDNAME 'GROES'.
  WA_FCAT-SELTEXT_M 'GROES'.
  APPEND WA_FCAT TO IT_FCAT.
  CLEAR WA_FCAT.

  WA_FCAT-COL_POS '5'.
  WA_FCAT-FIELDNAME 'NTGEW'.
  WA_FCAT-SELTEXT_M 'NTGEW'.
  APPEND WA_FCAT TO IT_FCAT.
  CLEAR WA_FCAT.

  WA_LAYOUT-LIGHTS_FIELDNAME 'LIGHTS'.
ENDFORM.

Output :

 

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.

How to show Excel data to Internal Table in SAP ABAP


EXCEL DATA

Code :
REPORT ZVP_EXCEL_TO_INTERNAL_TABLE.

TYPE-POOLSTRUXS.

TYPESBEGIN OF STRC,
         ID   TYPE CHAR10,
         NAME TYPE CHAR10,
         AGE  TYPE CHAR10,
       END OF STRC.

DATAIT_STRC TYPE TABLE OF STRC,
      WA_STRC TYPE STRC.

DATAIT_RAW TYPE TRUXS_T_TEXT_DATA.

PARAMETERSP_FILE TYPE RLGRAP-FILENAME.

**************************************************************
AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FILE.
  CALL FUNCTION 'F4_FILENAME'
    EXPORTING
*     PROGRAM_NAME        = SYST-CPROG
*     DYNPRO_NUMBER       = SYST-DYNNR
      FIELD_NAME 'P_FILE'
    IMPORTING
      FILE_NAME  P_FILE.
**************************************************************

**************************************************************
START-OF-SELECTION.
  CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'
    EXPORTING
*     I_FIELD_SEPERATOR    =
      I_LINE_HEADER        'X'
      I_TAB_RAW_DATA       IT_RAW
      I_FILENAME           P_FILE
    TABLES
      I_TAB_CONVERTED_DATA IT_STRC
    EXCEPTIONS
      CONVERSION_FAILED    1
      OTHERS               2.

  IF IT_STRC IS INITIAL.
    MESSAGE'EMPTY' TYPE 'I'.
  ENDIF.

END-OF-SELECTION.
*************************************************************

  LOOP AT IT_STRC INTO WA_STRC.
      WRITE:/ WA_STRC-ID,
              WA_STRC-NAME,
              WA_STRC-AGE.
  ENDLOOP.
  .


Output :


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.

How to change Radio button text alignment in SAP ABAP


Code :
REPORT ZVP_RADIO_BUTTON_POSITION.

SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 2(10TEXT-001.
PARAMETERSRB1 RADIOBUTTON GROUP RBG.
SELECTION-SCREEN END OF LINE.

SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 2(10TEXT-002.
PARAMETERSRB2 RADIOBUTTON GROUP RBG.
SELECTION-SCREEN END OF LINE.


Note: Goto - Text Elements - Text Symbols - Put the name of button.

Output :

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.

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.