Search This Blog

Search This Blog

AT LINE-SELECTION ( GET CURSOR )

REPORT  ZCLASS_G11 NO STANDARD PAGE HEADING LINE-COUNT 28(3).

TABLES MARA.

SELECT-OPTIONS S_MATNR FOR MARA-MATNR.

PARAMETERS P_MATNR LIKE MARA-MATNR DEFAULT '100-100'.

DATA: BEGIN OF IT_MARA OCCURS 0,
        MATNR  TYPE  MARA-MATNR,
        ERSDA  TYPE  MARA-ERSDA,
        ERNAM  TYPE  MARA-ERNAM,
        MATKL  TYPE  MARA-MATKL,
      END OF IT_MARA.

DATA: BEGIN OF IT_MARD OCCURS 0,
        MATNR  TYPE  MARD-MATNR,
        WERKS  TYPE  MARD-WERKS,
        LGORT  TYPE  MARD-LGORT,
        LABST  TYPE  MARD-LABST,
      END OF IT_MARD.


DATA IT_T023T LIKE T023T OCCURS 0 WITH HEADER LINE.
**************************************************************************
*                            INITIALIZATION                              *
**************************************************************************
INITIALIZATION.

  S_MATNR-SIGN = 'I'.
  S_MATNR-OPTION = 'BT'.
  S_MATNR-LOW = '100-100'.
  S_MATNR-HIGH = '100-200'.

  APPEND S_MATNR.

  S_MATNR-SIGN = 'I'.
  S_MATNR-OPTION = 'BT'.
  S_MATNR-LOW = '100-300'.
  S_MATNR-HIGH = '300-400'.

  APPEND S_MATNR.

**************************************************************************
*                         AT SELECTION-SCREEN                            *
**************************************************************************
AT SELECTION-SCREEN.

  DATA G_MATNR LIKE MARA-MATNR.

  SELECT SINGLE MATNR FROM MARA INTO G_MATNR WHERE MATNR = P_MATNR.
  IF G_MATNR IS INITIAL.
    SET CURSOR FIELD 'P_MATNR'.
    MESSAGE E000(ZG01) WITH P_MATNR.
  ENDIF.

**************************************************************************
*                          START-OF-SELECTION                            *
**************************************************************************
START-OF-SELECTION.

  SELECT MATNR
         ERSDA
         ERNAM
         MATKL INTO TABLE IT_MARA
               FROM MARA
               WHERE MATNR IN S_MATNR.

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

  SET TITLEBAR 'ZMARA'.

  LOOP AT IT_MARA.
    WRITE:/ IT_MARA-MATNR HOTSPOT ON,
            IT_MARA-ERSDA,
            IT_MARA-ERNAM,
            IT_MARA-MATKL HOTSPOT ON.
    HIDE IT_MARA-MATNR.
  ENDLOOP.

**************************************************************************
*                               TOP-OF-PAGE                              *
**************************************************************************
TOP-OF-PAGE.

  ULINE.
  WRITE:/  TEXT-A01.
  ULINE.

**************************************************************************
*                               END-OF-PAGE                              *
**************************************************************************
END-OF-PAGE.

  ULINE.
  WRITE:/10 '*** End of Page ***', SY-PAGNO.
  ULINE.

**************************************************************************
*                              AT LINE-SELECTION                         *
**************************************************************************
AT LINE-SELECTION.

  DATA: G_FIELD(20) TYPE C,
        G_VALUE(18) TYPE C.

  GET CURSOR FIELD G_FIELD VALUE G_VALUE.

  IF G_FIELD EQ 'IT_MARA-MATNR'.

    SELECT MATNR
           WERKS
           LGORT
           LABST INTO TABLE IT_MARD
                 FROM MARD
                 WHERE MATNR = G_VALUE.

    LOOP AT IT_MARD.
      WRITE:/ IT_MARD-MATNR, IT_MARD-WERKS, IT_MARD-LGORT, IT_MARD-LABST.
    ENDLOOP.

  ELSEIF G_FIELD EQ 'IT_MARA-MATKL'.

    SELECT * FROM T023T INTO TABLE IT_T023T WHERE SPRAS = SY-LANGU
                                              AND MATKL = G_VALUE.
    LOOP AT IT_T023T.
      WRITE:/ IT_T023T-MATKL, IT_T023T-WGBEZ.
    ENDLOOP.
  ENDIF.
**************************************************************************
*                    TOP-OF-PAGE DURING LINE-SELECTION                   *
**************************************************************************
TOP-OF-PAGE DURING LINE-SELECTION.

  ULINE.

  IF G_FIELD EQ 'IT_MARA-MATNR'.

    SET TITLEBAR 'ZMARD'.
    WRITE:/10 'Material Price Details..'.

  ELSEIF G_FIELD EQ 'IT_MARA-MATKL'.

    SET TITLEBAR 'ZT023T'.
    WRITE:/10 'Material Group Description..'.

  ENDIF.

  ULINE.











 


















 



Complete Reference For ABAP

The following ebook is for the ABAP beginners giving an overview of basic topics in ABAP.

  • ENTERPRISE RESOURCE PLANNING (ERP)
  • SAP ADVANTAGES
  • Role of ABAPer
  • R/3 ARCHITECTURE COMPONENTS
  • WHAT IS CLIENT IN SAP
  • Development Objects -  REPOSITORY OBJECTS and  DATA DICTIONARY OBJECTS
  • ABAP GUI
  • DATA DICTIONARY
  • INTERNAL TABLES
  • SUBROUTINES
  • Reports
  • MODULE POOL PROGRAMMING
  • Menu Painter
  • BATCH DATA COMMUNICATION
  • LSMW ( Legacy System Migration Workbench)
  • SAPSCRIPTS
  • SMARTFORMS 

Radio Buttons ( AT SELECTION-SCREEN OUTPUT )

REPORT  ZCLASS_G12.

PARAMETERS: P_RAD1 RADIOBUTTON GROUP GP1 USER-COMMAND 123,
            P_RAD2 RADIOBUTTON GROUP GP1.

TABLES: EKKO, VBAK.

SELECT-OPTIONS: S_VBELN FOR VBAK-VBELN MODIF ID DDD,
                S_KUNNR FOR VBAK-KUNNR MODIF ID DDD,
                S_EBELN FOR EKKO-EBELN MODIF ID XXX.

INITIALIZATION.

  P_RAD1 = 'X'.


AT SELECTION-SCREEN OUTPUT.

  IF P_RAD1 EQ 'X'.
    LOOP AT SCREEN.
      IF SCREEN-GROUP1 EQ 'XXX'.
        SCREEN-INPUT = 0.
        SCREEN-INVISIBLE = 1.

        MODIFY SCREEN.
      ENDIF.
    ENDLOOP.
  ENDIF.


  IF P_RAD2 EQ 'X'.
    LOOP AT SCREEN.
      IF SCREEN-GROUP1 EQ 'DDD'.
        SCREEN-INPUT = 0.
        SCREEN-INVISIBLE = 1.

        MODIFY SCREEN.
      ENDIF.
    ENDLOOP.
  ENDIF.




AT USER-COMMAND

REPORT  ZCLASS_G13.

TABLES VBAK.

SELECT-OPTIONS S_VBELN FOR VBAK-VBELN.

RANGES R_VBELN FOR VBAK-VBELN.

DATA: BEGIN OF IT_VBAK OCCURS 0,
        VBELN LIKE VBAK-VBELN,
        ERDAT LIKE VBAK-ERDAT,
        KUNNR LIKE VBAK-KUNNR,
      END OF IT_VBAK.

DATA: BEGIN OF IT_VBAP OCCURS 0,
        VBELN LIKE VBAP-VBELN,
        POSNR LIKE VBAP-POSNR,
        MATNR LIKE VBAP-MATNR,
        NETWR LIKE VBAP-NETWR,
      END OF IT_VBAP.


DATA G_CHK(1) TYPE C.

START-OF-SELECTION.

  SELECT VBELN
         ERDAT
         KUNNR INTO TABLE IT_VBAK
               FROM VBAK
               WHERE VBELN IN S_VBELN.

END-OF-SELECTION.

  SET PF-STATUS 'ZG13'.

  LOOP AT IT_VBAK.

    WRITE:/ G_CHK AS CHECKBOX,
            IT_VBAK-VBELN,
            IT_VBAK-ERDAT,
            IT_VBAK-KUNNR.

  ENDLOOP.


******************************************************************************
AT USER-COMMAND.

  DATA G_VBELN(10) TYPE N.

  REFRESH R_VBELN[].

  IF SY-UCOMM EQ 'VBAP'.

    DO.

      READ LINE SY-INDEX FIELD VALUE G_CHK IT_VBAK-VBELN INTO G_VBELN.

      IF SY-SUBRC NE 0.

        EXIT.

      ELSEIF G_CHK EQ 'X'.
        R_VBELN-SIGN = 'I'.
        R_VBELN-OPTION = 'EQ'.
        R_VBELN-LOW = G_VBELN.

        APPEND R_VBELN.

      ENDIF.

    ENDDO.


    IF NOT R_VBELN[] IS INITIAL.
      SELECT VBELN
             POSNR
             MATNR
             NETWR INTO TABLE IT_VBAP
                   FROM VBAP
                   WHERE VBELN IN R_VBELN.


      LOOP AT IT_VBAP.
        WRITE:/ IT_VBAP-VBELN, IT_VBAP-POSNR, IT_VBAP-MATNR, IT_VBAP-NETWR.
      ENDLOOP.

    ENDIF.
  ENDIF.




ALV Heirarchy Report

REPORT  ZCLASS_G16 LINE-SIZE 150.

  TABLES VBAK.

  SELECT-OPTIONS S_VBELN FOR VBAK-VBELN.

  DATA: BEGIN OF IT_VBAK OCCURS 0,
          VBELN LIKE VBAK-VBELN,
          ERDAT LIKE VBAK-ERDAT,
          ERNAM LIKE VBAK-ERNAM,
          KUNNR LIKE VBAK-KUNNR,
          EXP(1),
        END OF IT_VBAK.

  DATA: BEGIN OF IT_VBAP OCCURS 0,
          VBELN  TYPE  VBAP-VBELN,
          POSNR  TYPE  VBAP-POSNR,
          MATNR  TYPE  VBAP-MATNR,
          NETWR  TYPE  VBAP-NETWR,
          EXP(1),
        END OF IT_VBAP.

  TYPE-POOLS SLIS.

  DATA IT_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV.

  DATA WA_FIELDCAT TYPE SLIS_FIELDCAT_ALV.
  DATA WA_KEY TYPE SLIS_KEYINFO_ALV.
  DATA WA_LAYOUT TYPE SLIS_LAYOUT_ALV.
  DATA IT_SORT TYPE SLIS_T_SORTINFO_ALV.
  DATA WA_SORT TYPE SLIS_SORTINFO_ALV.

  START-OF-SELECTION.

    SELECT VBELN
           ERDAT
           ERNAM
           KUNNR INTO TABLE IT_VBAK
                 FROM VBAK
                 WHERE VBELN IN S_VBELN.

    IF NOT IT_VBAK[] IS INITIAL.
      SORT IT_VBAK BY VBELN.

      SELECT VBELN
             POSNR
             MATNR
             NETWR INTO TABLE IT_VBAP
                   FROM VBAP
                   FOR ALL ENTRIES IN IT_VBAK
                   WHERE VBELN = IT_VBAK-VBELN.

    ENDIF.

  END-OF-SELECTION.

*-- VBAK
    WA_FIELDCAT-FIELDNAME = 'VBELN'.
    WA_FIELDCAT-TABNAME = 'IT_VBAK'.
    WA_FIELDCAT-SELTEXT_L = 'Sales Doc'.
    WA_FIELDCAT-KEY = 'X'.

    APPEND WA_FIELDCAT TO IT_FIELDCAT.
    CLEAR WA_FIELDCAT.

    WA_FIELDCAT-FIELDNAME = 'ERDAT'.
    WA_FIELDCAT-TABNAME = 'IT_VBAK'.
    WA_FIELDCAT-SELTEXT_L = 'Date'.
    WA_FIELDCAT-OUTPUTLEN = 10.
    WA_FIELDCAT-EDIT_MASK = '__-__-____'.

    APPEND WA_FIELDCAT TO IT_FIELDCAT.
    CLEAR WA_FIELDCAT.


    WA_FIELDCAT-FIELDNAME = 'ERNAM'.
    WA_FIELDCAT-TABNAME = 'IT_VBAK'.
    WA_FIELDCAT-SELTEXT_L = 'USER'.
    WA_FIELDCAT-EDIT = 'X'.

    APPEND WA_FIELDCAT TO IT_FIELDCAT.
    CLEAR WA_FIELDCAT.


    WA_FIELDCAT-FIELDNAME = 'KUNNR'.
    WA_FIELDCAT-TABNAME = 'IT_VBAK'.
    WA_FIELDCAT-SELTEXT_L = 'Cutomer'.
    WA_FIELDCAT-EMPHASIZE = 'C710'.

    APPEND WA_FIELDCAT TO IT_FIELDCAT.
    CLEAR WA_FIELDCAT.

*-- VBAP
    WA_FIELDCAT-FIELDNAME = 'VBELN'.
    WA_FIELDCAT-TABNAME = 'IT_VBAP'.
    WA_FIELDCAT-SELTEXT_L = 'Sales Doc'.
    WA_FIELDCAT-KEY = 'X'.

    APPEND WA_FIELDCAT TO IT_FIELDCAT.
    CLEAR WA_FIELDCAT.

    WA_FIELDCAT-FIELDNAME = 'POSNR'.
    WA_FIELDCAT-TABNAME = 'IT_VBAP'.
    WA_FIELDCAT-SELTEXT_L = 'Item NO'.

    APPEND WA_FIELDCAT TO IT_FIELDCAT.
    CLEAR WA_FIELDCAT.

    WA_FIELDCAT-FIELDNAME = 'MATNR'.
    WA_FIELDCAT-TABNAME = 'IT_VBAP'.
    WA_FIELDCAT-SELTEXT_L = 'Mat No'.

    APPEND WA_FIELDCAT TO IT_FIELDCAT.
    CLEAR WA_FIELDCAT.

    WA_FIELDCAT-FIELDNAME = 'NETWR'.
    WA_FIELDCAT-TABNAME = 'IT_VBAP'.
    WA_FIELDCAT-SELTEXT_L = 'Amount'.
    WA_FIELDCAT-DO_SUM = 'X'.

    APPEND WA_FIELDCAT TO IT_FIELDCAT.
    CLEAR WA_FIELDCAT.

*--KEY
    WA_KEY-HEADER01 = 'VBELN'(001).
    WA_KEY-ITEM01 = 'VBELN'(001).


*--Layout- Expand
    WA_LAYOUT-EXPAND_FIELDNAME = 'EXP'.

    CALL FUNCTION 'REUSE_ALV_HIERSEQ_LIST_DISPLAY'
      EXPORTING
*   I_INTERFACE_CHECK              = ' '
*   I_CALLBACK_PROGRAM             =
*   I_CALLBACK_PF_STATUS_SET       = ' '
*   I_CALLBACK_USER_COMMAND        = ' '
     IS_LAYOUT                      = WA_LAYOUT
       IT_FIELDCAT                    = IT_FIELDCAT
*   IT_EXCLUDING                   =
*   IT_SPECIAL_GROUPS              =
*   IT_SORT                        =  IT_SORT
*  IT_FILTER                      =
*   IS_SEL_HIDE                    =
*   I_SCREEN_START_COLUMN          = 0
*   I_SCREEN_START_LINE            = 0
*   I_SCREEN_END_COLUMN            = 0
*   I_SCREEN_END_LINE              = 0
*   I_DEFAULT                      = 'X'
*   I_SAVE                         = ' '
*   IS_VARIANT                     =
*   IT_EVENTS                      =
*   IT_EVENT_EXIT                  =
        I_TABNAME_HEADER               = 'IT_VBAK'
        I_TABNAME_ITEM                 = 'IT_VBAP'
*   I_STRUCTURE_NAME_HEADER        =
*   I_STRUCTURE_NAME_ITEM          =
        IS_KEYINFO                     = WA_KEY
*   IS_PRINT                       =
*   IS_REPREP_ID                   =
*   I_BYPASSING_BUFFER             =
*   I_BUFFER_ACTIVE                =
*   IR_SALV_HIERSEQ_ADAPTER        =
*   IT_EXCEPT_QINFO                =
*   I_SUPPRESS_EMPTY_DATA          = ABAP_FALSE
* IMPORTING
*   E_EXIT_CAUSED_BY_CALLER        =
*   ES_EXIT_CAUSED_BY_USER         =
      TABLES
        T_OUTTAB_HEADER                = IT_VBAK
        T_OUTTAB_ITEM                  = IT_VBAP
* EXCEPTIONS
*   PROGRAM_ERROR                  = 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.















ALV Report

* FIELD CATALOG MANUALLY BUILT *

REPORT  ZCLASS_G14.

TABLES VBAK.

SELECT-OPTIONS S_VBELN FOR VBAK-VBELN.

DATA: BEGIN OF IT_VBAK OCCURS 0,
        VBELN LIKE VBAK-VBELN,
        ERDAT LIKE VBAK-ERDAT,
        ERNAM LIKE VBAK-ERNAM,
        KUNNR LIKE VBAK-KUNNR,
        NETWR LIKE VBAK-NETWR,
      END OF IT_VBAK.

TYPE-POOLS SLIS.

DATA IT_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV.
DATA IT_SORT TYPE SLIS_T_SORTINFO_ALV.

DATA WA_FIELDCAT TYPE SLIS_FIELDCAT_ALV.
DATA WA_LAYOUT TYPE SLIS_LAYOUT_ALV.
DATA WA_SORT TYPE SLIS_SORTINFO_ALV.

START-OF-SELECTION.

  SELECT VBELN
         ERDAT
         ERNAM
         KUNNR
         NETWR INTO TABLE IT_VBAK
               FROM VBAK
               WHERE VBELN IN S_VBELN.

END-OF-SELECTION.

  WA_FIELDCAT-FIELDNAME = 'VBELN'.
  WA_FIELDCAT-SELTEXT_L = 'Sales Doc'.
  WA_FIELDCAT-KEY = 'X'.
  WA_FIELDCAT-OUTPUTLEN = 20.

  APPEND WA_FIELDCAT TO IT_FIELDCAT.
  CLEAR WA_FIELDCAT.

  WA_FIELDCAT-FIELDNAME = 'ERDAT'.
  WA_FIELDCAT-SELTEXT_L = 'Date'.
  WA_FIELDCAT-OUTPUTLEN = 10.
  WA_FIELDCAT-EDIT_MASK = '__-__-____'.
*
  APPEND WA_FIELDCAT TO IT_FIELDCAT.
  CLEAR WA_FIELDCAT.


  WA_FIELDCAT-FIELDNAME = 'ERNAM'.
  WA_FIELDCAT-SELTEXT_L = 'USER'.
*  WA_FIELDCAT-EDIT = 'X'.

  APPEND WA_FIELDCAT TO IT_FIELDCAT.
  CLEAR WA_FIELDCAT.


  WA_FIELDCAT-FIELDNAME = 'KUNNR'.
  WA_FIELDCAT-SELTEXT_L = 'Cutomer'.
  WA_FIELDCAT-EMPHASIZE = 'C710'.

  APPEND WA_FIELDCAT TO IT_FIELDCAT.
  CLEAR WA_FIELDCAT.

  WA_FIELDCAT-FIELDNAME = 'NETWR'.
  WA_FIELDCAT-SELTEXT_L = 'Amount'.
  WA_FIELDCAT-DO_SUM = 'X'.

  APPEND WA_FIELDCAT TO IT_FIELDCAT.
  CLEAR WA_FIELDCAT.

*---
  WA_LAYOUT-ZEBRA = 'X'.
  WA_LAYOUT-COLWIDTH_OPTIMIZE = 'X'.

*--
  WA_SORT-FIELDNAME = 'KUNNR'.
  WA_SORT-UP = 'X'.
  WA_SORT-SUBTOT = 'X'.

  APPEND WA_SORT TO IT_SORT.

  CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
   EXPORTING
*   I_INTERFACE_CHECK              = ' '
*   I_BYPASSING_BUFFER             =
*   I_BUFFER_ACTIVE                = ' '
*   I_CALLBACK_PROGRAM             = ' '
*   I_CALLBACK_PF_STATUS_SET       = ' '
*   I_CALLBACK_USER_COMMAND        = ' '
*   I_STRUCTURE_NAME               =
   IS_LAYOUT                      = WA_LAYOUT
   IT_FIELDCAT                    = IT_FIELDCAT
*   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
*   IR_SALV_LIST_ADAPTER           =
*   IT_EXCEPT_QINFO                =
*   I_SUPPRESS_EMPTY_DATA          = ABAP_FALSE
* IMPORTING
*   E_EXIT_CAUSED_BY_CALLER        =
*   ES_EXIT_CAUSED_BY_USER         =
    TABLES
      T_OUTTAB                       = IT_VBAK
* EXCEPTIONS
*   PROGRAM_ERROR                  = 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.