Wednesday, December 16, 2015

ABAP SAMPLE ALV REPORT

*&---------------------------------------------------------------------*
*& Report  ZSAMPLE_ALV
*&
*&---------------------------------------------------------------------*
*& TITLE:        ALV INTERACTIVE REPORT FOR SALES AND BILLING REPORTS
*& CREATED BY :  ABCDEFGH
*& CREATED DATE: 20 SEPT 2010.
*&
*&---------------------------------------------------------------------*

REPORT  ZSAMPLE_ALV MESSAGE-ID ZSAMPLE_MSG.
TABLES: VBAK, VBAP, VBRK, VBRP, VBFA.
TYPE-POOLS : SLIS.

************************************************************************
*                     BASIC INTERNAL TABLE FOR VBAK
************************************************************************

TYPES :BEGIN OF I_VBAK,
       VBELN TYPE VBAK-VBELN,                              " SALES DOCUMENT
       ERDAT TYPE VBAK-ERDAT,                              " DATE ON WHICH RECORD IS CREATED
       ERNAM TYPE VBAK-ERNAM,                              " NAME OF THE PERSON WHO CREATED THE OBJECT
       AUDAT TYPE VBAK-AUDAT,                              " DOCUMENT DATE
       NETWR TYPE VBAK-NETWR,                              " NET VALUE OF SALES ORDER
       KUNNR TYPE VBAK-KUNNR,                              " SOLD TO PARTY
       VTWEG TYPE VBAK-VTWEG,                              " DISTRIBUTION CHANNEL
       VKORG TYPE VBAK-VKORG,                              " SALES ORGANIZATION
       SPART TYPE VBAK-SPART,                              " DIVISION
       END OF I_VBAK.

DATA : IT_VBAK TYPE STANDARD TABLE OF I_VBAK INITIAL SIZE 0,
       WA_VBAK TYPE I_VBAK.

************************************************************************
*                     SECONDARY INTERNAL TABLE FOR VBAP
************************************************************************

TYPES :BEGIN OF I_VBAP ,
       VBELN TYPE VBAP-VBELN,                              " SALES DOCUMENT
       POSNR TYPE VBAP-POSNR,                              " SALES DOCUMENT ITEM
       MATNR TYPE VBAP-MATNR,                              " MATERIAL NUMBER
       MATKL TYPE VBAP-MATKL,                              " MATERIAL GROUP
       MEINS TYPE VBAP-MEINS,                              " BASE UNIT OF MEASURE
       ZWERT TYPE VBAP-ZWERT,                              " TARGET VALUE FOR OUTLINE AGREEMENT
       END OF I_VBAP.

DATA: IT_VBAP TYPE STANDARD TABLE OF I_VBAP INITIAL SIZE 0,
      WA_VBAP TYPE I_VBAP .

*************************************************************************
*                 BASIC INTERNAL TABLE FOR VBRK                         *
*************************************************************************
TYPES: BEGIN OF I_VBRK,
        VBELN TYPE VBRK-VBELN,                             " BILLING DOCUMENT
        FKART TYPE VBRK-FKART,                             " BILLING TYPE
        FKDAT TYPE VBRK-FKDAT,                             " BILLING DATE
        GJAHR TYPE VBRK-GJAHR,                             " FISCAL YEAR
        POPER TYPE VBRK-POPER,                             " POSTING PERIOD
        LAND1 TYPE VBRK-LAND1,                             " COUNTRY OF DESTINATION
        REGIO TYPE VBRK-REGIO,                             " REGION
        BUKRS TYPE VBRK-BUKRS,                             " COMPANY CODE
        VKORG TYPE VBRK-VKORG,                             " SALES ORGANIZATION
        SPART TYPE VBRK-SPART,                             " DIVISION
        VTWEG TYPE VBRK-VTWEG,                             " DISTRIBUTION CHANNEL
        ERDAT TYPE VBRK-ERDAT,                             " DATE ON WHICH RECORD IS CREATED
*        VBELV TYPE VBRK-VBELV,                             " PRECEDING SALES AND DISTRIBUTION DOC
      END OF I_VBRK.

DATA: IT_VBRK TYPE STANDARD TABLE OF I_VBRK INITIAL SIZE 0,
      WA_VBRK TYPE I_VBRK.

*****************************************************************************
*                SECONDARY LIST INTERNAL TABLE FOR VBRP                     *
*****************************************************************************

TYPES: BEGIN OF I_VBRP,
        VBELN TYPE VBRP-VBELN,                             " BILLING DOC
        POSNR TYPE VBRP-POSNR,                             " BILLING ITEM
        VRKME TYPE VBRP-VRKME,                             " SALES UNIT
        MEINS TYPE VBRP-MEINS,                             " BASE UNIT OF MEASURE
        NETWR TYPE VBRP-NETWR,                             " NET VALUE
        AUBEL TYPE VBRP-AUBEL,                             " SALES DOCUMENT
        AUPOS TYPE VBRP-AUPOS,                             " SALES DOCUMENT ITEM
        MATNR TYPE VBRP-MATNR,                             " MATERIAL NUMBER
        VKORG TYPE VBRP-VKORG_AUFT,                        " SALES ORGANIZATION
        SPART TYPE VBRP-SPART,                             " DIVISION
        VTWEG TYPE VBRP-VTWEG_AUFT,                        " DISTRIBUTION CHANNEL
        ERDAT TYPE VBRP-ERDAT,                             " DATE ON WHICH RECORD IS CREATED
      END OF I_VBRP.

DATA: IT_VBRP TYPE STANDARD TABLE OF I_VBRP INITIAL SIZE 0,
      WA_VBRP TYPE I_VBRP.

*****************************************************************************
*             INTERNAL TABLE FOR VBFA
*****************************************************************************
TYPES: BEGIN OF I_VBFA,
        VBELV TYPE VBFA-VBELN,
        VBELN TYPE VBFA-VBELN,
       END OF I_VBFA.
DATA: IT_VBFA TYPE STANDARD TABLE OF I_VBFA INITIAL SIZE 0,
      WA_VBFA TYPE I_VBFA.

**********************************************************************
*                      PROGRAM NAME
**********************************************************************
DATA: V_REPID LIKE SY-REPID .

**********************************************************************
****         FIELD CATELOG TYPE DELARATIONS
**********************************************************************
DATA: I_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV,
      WA_FIELDCAT TYPE SLIS_FIELDCAT_ALV.

***********************************************************************
****        LISTHEADER TYPE DECLARATIONS
***********************************************************************
DATA: IT_LISTHEADER TYPE SLIS_T_LISTHEADER.

***********************************************************************
*****       EVENTS TYPE DECLARATIONS
***********************************************************************
DATA: V_EVENTS TYPE SLIS_T_EVENT,
      WA_EVENT TYPE SLIS_ALV_EVENT.


*************************************************************************
****                  REPORT TITLE
*************************************************************************
DATA: TITLE_VBAK TYPE LVC_TITLE VALUE 'CONTRACT BASIC LIST'.
DATA: TITLE_VBAP TYPE LVC_TITLE VALUE 'CONTRACT SECONDRY LIST'.
DATA: TITLE_VBRK TYPE LVC_TITLE VALUE 'BILLING BASIC LIST'.
DATA: TITLE_VBRP TYPE LVC_TITLE VALUE 'BILLING SECONDARY LIST'.

*************************************************************************
*                   SELECTION BLOCK ONE
*************************************************************************

SELECTION-SCREEN : BEGIN OF BLOCK BLK1 WITH FRAME TITLE T1.

PARAMETERS : S_VKORG TYPE VBAK-VKORG,
             S_SPART TYPE VBAK-SPART,
             S_VTWEG TYPE VBAK-VTWEG.

SELECTION-SCREEN : END OF BLOCK BLK1.


*************************************************************************
*                   SELECTION BLOCK TWO
*************************************************************************

SELECTION-SCREEN : BEGIN OF BLOCK BLK2 WITH FRAME TITLE T2.
  SELECT-OPTIONS   : S_VBELN FOR WA_VBAK-VBELN OBLIGATORY.
  SELECT-OPTIONS   : S_AUDAT FOR WA_VBAK-ERDAT OBLIGATORY.
SELECTION-SCREEN : END OF BLOCK BLK2.

*************************************************************************
*                   SELECTION SCREEN THREE
*************************************************************************

SELECTION-SCREEN : BEGIN OF BLOCK BLK3 WITH FRAME TITLE T3.
 PARAMETERS :   R1 RADIOBUTTON GROUP RAD1 DEFAULT 'X',
                R2 RADIOBUTTON GROUP RAD1,
                R3 RADIOBUTTON GROUP RAD1.
SELECTION-SCREEN : END OF BLOCK BLK3.

**************************************************************************
*                   INITIALAZATION
**************************************************************************
INITIALIZATION.
T1 = 'SALES HEADER DATA'.
T2 = 'SALES ITEM DATA'.
T3 = 'SELECT SALES INFORMATION'.
S_VKORG = '1000'.
S_SPART = '00'.
S_VTWEG = '12'.
V_REPID = SY-REPID.

**************************************************************************
*                    AT SELECTION SCREEN
**************************************************************************
AT SELECTION-SCREEN ON S_VKORG .
  IF NOT S_VKORG IS INITIAL.
   SELECT SINGLE * FROM VBAK WHERE VKORG EQ S_VKORG.
     IF  SY-SUBRC NE 0.
       MESSAGE E000.
     ENDIF.
  ENDIF.

AT SELECTION-SCREEN ON S_SPART.
  IF NOT S_SPART IS INITIAL.
    SELECT SINGLE * FROM VBAK WHERE SPART EQ S_SPART.
      IF SY-SUBRC NE 0.
        MESSAGE E001.
      ENDIF.
  ENDIF.

*AT SELECTION-SCREEN ON S_VTWEG.
* IF NOT S_VTWEG IS INITIAL.
*    SELECT SINGLE * FROM VBAK WHERE VTWEG EQ S_VTWEG.
*      IF SY-SUBRC NE 0.
*       MESSAGE E002.
*      ENDIF.
*  ENDIF.

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

IF R1 = 'X'.

PERFORM GET_DATA.
PERFORM BUILD_FIELDCATLOG.
PERFORM EVENT_CALL.
PERFORM POPULATE_EVENT.
*
*PERFORM GET_DATA.
PERFORM BUILD_LISTHEADER USING IT_LISTHEADER.
PERFORM DISPLAY_ALV_REPORT.


ELSEIF R2 = 'X'.

PERFORM GET_DATA2.
PERFORM BUILD_FCAT2.
PERFORM EVENT_CALL.
PERFORM POPULATE_EVENT2.
PERFORM BUILD_LISTHEADER USING IT_LISTHEADER.
PERFORM DISPLAY_GRID2.

ELSEIF R3 = 'X'.
      PERFORM BUILD_FCAT3.
      PERFORM EVENT_CALL3.
      PERFORM POPULATE_EVENT_VBRP.
      PERFORM GET_DATA3.
      PERFORM BUILD_LISTHEADER_3 USING IT_LISTHEADER.
      PERFORM DISPLAY_GRID_VBRP.

ENDIF.


*&---------------------------------------------------------------------*
*&      Form  BUILD_FIELDCATLOG
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM BUILD_FIELDCATLOG .

WA_FIELDCAT-TABNAME = 'IT_VBAK'.
WA_FIELDCAT-FIELDNAME = 'VBELN'.
WA_FIELDCAT-SELTEXT_M = 'Sales Document'.
APPEND WA_FIELDCAT TO I_FIELDCAT.
CLEAR WA_FIELDCAT.

WA_FIELDCAT-TABNAME = 'IT_VBAK'.
WA_FIELDCAT-FIELDNAME = 'ERDAT'.
WA_FIELDCAT-SELTEXT_M = 'Date on Which Record Was Created'.
APPEND WA_FIELDCAT TO I_FIELDCAT.
CLEAR WA_FIELDCAT.

WA_FIELDCAT-TABNAME = 'IT_VBAK'.
WA_FIELDCAT-FIELDNAME = 'ERNAM'.
WA_FIELDCAT-SELTEXT_M = 'Name of Person who Created the Object'.
APPEND WA_FIELDCAT TO I_FIELDCAT.
CLEAR WA_FIELDCAT.

WA_FIELDCAT-TABNAME = 'IT_VBAK'.
WA_FIELDCAT-FIELDNAME = 'AUDAT'.
WA_FIELDCAT-SELTEXT_M = 'Document Date (Date Received/Sent)'.
APPEND WA_FIELDCAT TO I_FIELDCAT.
CLEAR WA_FIELDCAT.

WA_FIELDCAT-TABNAME = 'IT_VBAK'.
WA_FIELDCAT-FIELDNAME = 'NETWR'.
WA_FIELDCAT-SELTEXT_M = 'Net Value of the Sales Order in Document Currency'.
APPEND WA_FIELDCAT TO I_FIELDCAT.
CLEAR WA_FIELDCAT.

WA_FIELDCAT-TABNAME = 'IT_VBAK'.
WA_FIELDCAT-FIELDNAME = 'KUNNR'.
WA_FIELDCAT-SELTEXT_M = 'Sold-to party'.
APPEND WA_FIELDCAT TO I_FIELDCAT.
CLEAR WA_FIELDCAT.

WA_FIELDCAT-TABNAME = 'IT_VBAK'.
WA_FIELDCAT-FIELDNAME = 'VTWEG'.
WA_FIELDCAT-SELTEXT_M = 'Distribution ChanneL'.
APPEND WA_FIELDCAT TO I_FIELDCAT.
CLEAR WA_FIELDCAT.

ENDFORM.                    " BUILD_FIELDCATLOG
*&---------------------------------------------------------------------*
*&      Form  EVENT_CALL
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM EVENT_CALL .

CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
EXPORTING
I_LIST_TYPE = 0
IMPORTING
ET_EVENTS = V_EVENTS
 EXCEPTIONS
 LIST_TYPE_WRONG = 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.

ENDFORM.                    " EVENT_CALL
*&---------------------------------------------------------------------*
*&      Form  POPULATE_EVENT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM POPULATE_EVENT .

READ TABLE V_EVENTS INTO WA_EVENT WITH KEY NAME = 'TOP_OF_PAGE'.
IF SY-SUBRC EQ 0.
WA_EVENT-FORM = 'TOP_OF_PAGE'.
MODIFY V_EVENTS FROM WA_EVENT TRANSPORTING FORM WHERE NAME =
WA_EVENT-FORM.
ENDIF.

READ TABLE V_EVENTS INTO WA_EVENT WITH KEY NAME = 'USER_COMMAND'.
IF SY-SUBRC EQ 0.
WA_EVENT-FORM = 'USER_COMMAND'.
MODIFY V_EVENTS FROM WA_EVENT TRANSPORTING FORM WHERE NAME =
WA_EVENT-NAME.
ENDIF.

ENDFORM.                    " POPULATE_EVENT

*&---------------------------------------------------------------------*
*&      Form  POPULATE_EVENT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM POPULATE_EVENT2 .

READ TABLE V_EVENTS INTO WA_EVENT WITH KEY NAME = 'TOP_OF_PAGE'.
IF SY-SUBRC EQ 0.
WA_EVENT-FORM = 'TOP_OF_PAGE'.
MODIFY V_EVENTS FROM WA_EVENT TRANSPORTING FORM WHERE NAME =
WA_EVENT-FORM.
ENDIF.

READ TABLE V_EVENTS INTO WA_EVENT WITH KEY NAME = 'USER_COMMAND2'.
IF SY-SUBRC EQ 0.
WA_EVENT-FORM = 'USER_COMMAND2'.
MODIFY V_EVENTS FROM WA_EVENT TRANSPORTING FORM WHERE NAME =
WA_EVENT-NAME.
ENDIF.

ENDFORM.                    " POPULATE_EVENT2
*&---------------------------------------------------------------------*
*&      Form  GET_DATA
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM GET_DATA .

SELECT VBELN
       ERDAT
       ERNAM
       AUDAT
       NETWR
       KUNNR
       VTWEG
       VKORG
       SPART FROM VBAK INTO TABLE IT_VBAK WHERE VBELN IN S_VBELN  AND
                                                VKORG = S_VKORG AND
                                                SPART = S_SPART AND
                                                VTWEG = S_VTWEG AND AUDAT IN S_AUDAT.

ENDFORM.                    " GET_DATA
*&---------------------------------------------------------------------*
*&      Form  BUILD_LISTHEADER
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_IT_LISTHEADER  text
*----------------------------------------------------------------------*
FORM BUILD_LISTHEADER  USING    P_IT_LISTHEADER.

DATA HLINE TYPE SLIS_LISTHEADER.
*HLINE-INFO = 'INTERACTIVE ALV REPORT'.
*HLINE-TYP = 'H'.


ENDFORM.                    " BUILD_LISTHEADER
*&---------------------------------------------------------------------*
*&      Form  DISPLAY_ALV_REPORT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*---------------------------------------------------------------------*
FORM DISPLAY_ALV_REPORT .


CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
 EXPORTING
   I_CALLBACK_PROGRAM                = V_REPID
   I_CALLBACK_USER_COMMAND           = 'USER_COMMAND'
   I_CALLBACK_TOP_OF_PAGE            = 'TOP_OF_PAGE'
   I_GRID_TITLE                      = TITLE_VBAK
   IT_FIELDCAT                       = I_FIELDCAT[]
   I_SAVE                            = 'A'
   IT_EVENTS                         = V_EVENTS
  TABLES
    T_OUTTAB                          = IT_VBAK
 EXCEPTIONS
   PROGRAM_ERROR                     = 1
   OTHERS                            = 2
          .
IF SY-SUBRC <> 0.

 MESSAGE ID 'ZSAMPLE_MSG' TYPE 'E' NUMBER '000'.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.

ENDFORM.                    " DISPLAY_ALV_REPORT



*&--------------------------------------------------------------------*
*& Form TOP_OF_PAGE
*&--------------------------------------------------------------------*
* text
*---------------------------------------------------------------------*
FORM TOP_OF_PAGE.
CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
EXPORTING
IT_LIST_COMMENTARY = IT_LISTHEADER
.

ENDFORM. "TOP_OF_PAGE

*&--------------------------------------------------------------------*
*& Form USER_COMMAND
*&--------------------------------------------------------------------*
* text
*---------------------------------------------------------------------*
* -->R_UCOMM text
* -->, text
* -->RS_SLEFIELDtext
*---------------------------------------------------------------------*
FORM USER_COMMAND USING R_UCOMM LIKE SY-UCOMM
RS_SELFIELD TYPE SLIS_SELFIELD.
CASE R_UCOMM.
WHEN '&IC1'.
*READ TABLE IT_VBAK INDEX RS_SELFIELD-TABINDEX INTO WA_VBAK.
READ TABLE IT_VBAK INTO WA_VBAK INDEX RS_SELFIELD-TABINDEX.
*PERFORM DATA_RETRIEVAL_VBAP.


PERFORM BUILD_FIELDCATLOG_VBAP.
PERFORM EVENT_CALL_VBAP.
PERFORM POPULATE_EVENT_3.
PERFORM GET_DATA_VBAP.
PERFORM BUILD_LISTHEADER_VBAP USING IT_LISTHEADER.
PERFORM DISPLAY_ALV_VBAP.
ENDCASE.
ENDFORM. "user_command
*&--------------------------------------------------------------------*
*& Form BUILD_FIELDCATLOG_VBAP
*&--------------------------------------------------------------------*
* text
*---------------------------------------------------------------------*
FORM BUILD_FIELDCATLOG_VBAP.
CLEAR I_FIELDCAT.
CLEAR WA_FIELDCAT.

WA_FIELDCAT-TABNAME = 'I_VBAP'.
WA_FIELDCAT-FIELDNAME = 'VBELN'.
WA_FIELDCAT-SELTEXT_M = 'Sales Document'.
APPEND WA_FIELDCAT TO I_FIELDCAT.
CLEAR WA_FIELDCAT.

WA_FIELDCAT-TABNAME = 'IT_VBAP'.
WA_FIELDCAT-FIELDNAME = 'POSNR'.
WA_FIELDCAT-SELTEXT_M = 'Sales Document Item'.
APPEND WA_FIELDCAT TO I_FIELDCAT.
CLEAR WA_FIELDCAT.
WA_FIELDCAT-TABNAME = 'IT_VBAP'.
WA_FIELDCAT-FIELDNAME = 'MATNR'.
WA_FIELDCAT-SELTEXT_M = 'Material Number'.
APPEND WA_FIELDCAT TO I_FIELDCAT.
CLEAR WA_FIELDCAT.
WA_FIELDCAT-TABNAME = 'I_VBAP'.
WA_FIELDCAT-FIELDNAME = 'MATKL'.
WA_FIELDCAT-SELTEXT_M = 'Material Group'.
APPEND WA_FIELDCAT TO I_FIELDCAT.
CLEAR WA_FIELDCAT.
WA_FIELDCAT-TABNAME = 'I_VBAP'.
WA_FIELDCAT-FIELDNAME = 'MEINS'.
WA_FIELDCAT-SELTEXT_M = 'Base Unit of Measure'.
APPEND WA_FIELDCAT TO I_FIELDCAT.
CLEAR WA_FIELDCAT.

WA_FIELDCAT-TABNAME = 'I_VBAP'.
WA_FIELDCAT-FIELDNAME = 'ZWERT'.
WA_FIELDCAT-SELTEXT_M = ' Document Currency'.
APPEND WA_FIELDCAT TO I_FIELDCAT.
CLEAR WA_FIELDCAT.

ENDFORM. "BUILD_FIELDCATLOG_VBAP

*&--------------------------------------------------------------------*
*& Form event_call_VBAP
*&--------------------------------------------------------------------*
* we get all events - TOP OF PAGE or USER COMMAND in table v_events
*---------------------------------------------------------------------*
FORM EVENT_CALL_VBAP.
CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
EXPORTING
I_LIST_TYPE = 0
IMPORTING
ET_EVENTS = V_EVENTS
 EXCEPTIONS
 LIST_TYPE_WRONG = 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.
ENDFORM. "event_call_VBAP


*&--------------------------------------------------------------------*
*& Form POPULATE_EVENT
*&--------------------------------------------------------------------*
* Events populated for TOP OF PAGE & USER COMAND
*--------------------------------------------------------------------*
FORM POPULATE_EVENT_VBAP.
READ TABLE V_EVENTS INTO WA_EVENT WITH KEY NAME = 'TOP_OF_PAGE'.
IF SY-SUBRC EQ 0.
WA_EVENT-FORM = 'TOP_OF_PAGE'.
MODIFY V_EVENTS FROM WA_EVENT TRANSPORTING FORM WHERE NAME =
WA_EVENT-FORM.
ENDIF.

ENDFORM. "POPULATE_EVENT

*&--------------------------------------------------------------------*
*& Form TOP_OF_PAGE
*&--------------------------------------------------------------------*
* text
*---------------------------------------------------------------------*
FORM F_TOP_OF_PAGE.
CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
EXPORTING
IT_LIST_COMMENTARY = IT_LISTHEADER
* i_logo =
* I_END_OF_LIST_GRID =
.

ENDFORM. "TOP_OF_PAGE

*&--------------------------------------------------------------------*
*& Form USER_COMMAND
*&--------------------------------------------------------------------*
* text
*---------------------------------------------------------------------*
* -->R_UCOMM text
* -->, text
* -->RS_SLEFIELDtext
*---------------------------------------------------------------------*

*retreiving values from the database table VBAK
FORM GET_DATA_VBAP.
SELECT  VBELN
        POSNR
        MATNR
        MATKL
        MEINS
        ZWERT FROM VBAP INTO TABLE IT_VBAP WHERE VBELN = WA_VBAK-VBELN.
ENDFORM.
FORM BUILD_LISTHEADER_VBAP USING I_LISTHEADER TYPE SLIS_T_LISTHEADER.
DATA: HLINE1 TYPE SLIS_LISTHEADER.
*HLINE1-TYP = 'H'.
HLINE1-INFO = 'CHECKING PGM'.
ENDFORM.


FORM DISPLAY_ALV_VBAP.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM = V_REPID
I_CALLBACK_TOP_OF_PAGE = 'TOP_OF_PAGE'

I_GRID_TITLE = 'CONTRACT SECONDARY LIST DISPLAY'
IT_FIELDCAT = I_FIELDCAT[]
I_SAVE = 'A'
IT_EVENTS = V_EVENTS
TABLES
T_OUTTAB = 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.
ENDFORM.



*&---------------------------------------------------------------------*
*&      Form  BUILD_FCAT2
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM BUILD_FCAT2 .

WA_FIELDCAT-TABNAME = 'IT_VBRK'.
WA_FIELDCAT-FIELDNAME = 'VBELN'.
WA_FIELDCAT-SELTEXT_M = 'Billing Document'.
APPEND WA_FIELDCAT TO I_FIELDCAT.
CLEAR WA_FIELDCAT.

WA_FIELDCAT-TABNAME = 'IT_VBRK'.
WA_FIELDCAT-FIELDNAME = 'FKART'.
WA_FIELDCAT-SELTEXT_M = 'Billing Type'.
APPEND WA_FIELDCAT TO I_FIELDCAT.
CLEAR WA_FIELDCAT.

WA_FIELDCAT-TABNAME = 'IT_VBRK'.
WA_FIELDCAT-FIELDNAME = 'FKDAT'.
WA_FIELDCAT-SELTEXT_M = 'Billing Date'.
APPEND WA_FIELDCAT TO I_FIELDCAT.
CLEAR WA_FIELDCAT.

WA_FIELDCAT-TABNAME = 'IT_VBRK'.
WA_FIELDCAT-FIELDNAME = 'GJAHR'.
WA_FIELDCAT-SELTEXT_M = 'Fiscal Year'.
APPEND WA_FIELDCAT TO I_FIELDCAT.
CLEAR WA_FIELDCAT.

WA_FIELDCAT-TABNAME = 'IT_VBRK'.
WA_FIELDCAT-FIELDNAME = 'POPER'.
WA_FIELDCAT-SELTEXT_M = 'Posting Period'.
APPEND WA_FIELDCAT TO I_FIELDCAT.
CLEAR WA_FIELDCAT.

WA_FIELDCAT-TABNAME = 'IT_VBRK'.
WA_FIELDCAT-FIELDNAME = 'LAND1'.
WA_FIELDCAT-SELTEXT_M = 'Country Of Destination'.
APPEND WA_FIELDCAT TO I_FIELDCAT.
CLEAR WA_FIELDCAT.

WA_FIELDCAT-TABNAME = 'IT_VBRK'.
WA_FIELDCAT-FIELDNAME = 'REGIO'.
WA_FIELDCAT-SELTEXT_M = 'Region'.
APPEND WA_FIELDCAT TO I_FIELDCAT.
CLEAR WA_FIELDCAT.

WA_FIELDCAT-TABNAME = 'IT_VBRK'.
WA_FIELDCAT-FIELDNAME = 'BUKRS'.
WA_FIELDCAT-SELTEXT_M = 'Company Code'.
APPEND WA_FIELDCAT TO I_FIELDCAT.
CLEAR WA_FIELDCAT.

ENDFORM.                    " BUILD_FCAT2

*&---------------------------------------------------------------------*
*&      Form  GET_DATA2
*&--------------ઞ------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*---------------------------------------------------------------------*
FORM   GET_DATA2 .

SELECT VBELV VBELN FROM VBFA INTO CORRESPONDING FIELDS OF TABLE IT_VBFA WHERE VBELV IN S_VBELN.
*BREAK-POINT.
SELECT VBELN
        FKART
        FKDAT
        GJAHR
        POPER
        LAND1
        REGIO
        BUKRS
        VKORG
        SPART
        VTWEG
        ERDAT FROM VBRK INTO CORRESPONDING FIELDS OF TABLE IT_VBRK
                    FOR ALL ENTRIES IN IT_VBFA
                    WHERE VBELN = IT_VBFA-VBELN AND
                          VKORG = S_VKORG AND
                          SPART = S_SPART AND
                          VTWEG = S_VTWEG." AND FKDAT = S_AUDAT.
*BREAK-POINT.
*SELECT * FROM VBRK INTO CORRESPONDING FIELDS OF TABLE IT_VBRK WHERE VBELN IN S_VBELN.
ENDFORM.                    " GET_DATA2

*&---------------------------------------------------------------------*
*&      Form  DISPLAY_GRID2
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM DISPLAY_GRID2 .

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
 EXPORTING
   I_CALLBACK_PROGRAM                = V_REPID
   I_CALLBACK_USER_COMMAND           = 'USER_COMMAND2'
   I_CALLBACK_TOP_OF_PAGE            = 'TOP_OF_PAGE'
   I_GRID_TITLE                     = TITLE_VBRK
   IT_FIELDCAT                       = I_FIELDCAT[]

   I_SAVE                            = 'A'
   IT_EVENTS                         = V_EVENTS
  TABLES
    T_OUTTAB                          = IT_VBRK
  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.


ENDFORM.                    " DISPLAY_GRID2

*&--------------------------------------------------------------------*
*& Form USER_COMMAND2
*&--------------------------------------------------------------------*
* text
*---------------------------------------------------------------------*
* -->R_UCOMM text
* -->, text
* -->RS_SLEFIELDtext
*---------------------------------------------------------------------*
FORM USER_COMMAND2 USING R_UCOMM LIKE SY-UCOMM
RS_SELFIELD TYPE SLIS_SELFIELD.
CASE R_UCOMM.
WHEN '&IC1'.
*WRITE:/ RS_SELFIELD-TABINDEX.
*IF RS_SELFIELD = 'VBELN'.
READ TABLE IT_VBRK INTO WA_VBRK INDEX RS_SELFIELD-TABINDEX.
*ENDIF.
PERFORM BUILD_FIELDCATLOG_VBRP.
PERFORM EVENT_CALL_VBRP.
PERFORM POPULATE_EVENT_VBRP.
PERFORM DATA_RETRIEVAL_VBRP.
PERFORM BUILD_LISTHEADER_VBRP USING IT_LISTHEADER.
PERFORM DISPLAY_ALV_VBRP.
ENDCASE.
ENDFORM. "user_command2

*&--------------------------------------------------------------------*
*& Form BUILD_FIELDCATLOG_VBRP
*&--------------------------------------------------------------------*
* text
*---------------------------------------------------------------------*
FORM BUILD_FIELDCATLOG_VBRP.
CLEAR I_FIELDCAT.
CLEAR WA_FIELDCAT.
WA_FIELDCAT-TABNAME = 'I_VBRP'.
WA_FIELDCAT-FIELDNAME = 'VBELN'.
WA_FIELDCAT-SELTEXT_M = 'Billing Document'.
APPEND WA_FIELDCAT TO I_FIELDCAT.
CLEAR WA_FIELDCAT.

WA_FIELDCAT-TABNAME = 'IT_VBRP'.
WA_FIELDCAT-FIELDNAME = 'POSNR'.
WA_FIELDCAT-SELTEXT_M = 'Billing Item'.
APPEND WA_FIELDCAT TO I_FIELDCAT.
CLEAR WA_FIELDCAT.
WA_FIELDCAT-TABNAME = 'IT_VBRP'.
WA_FIELDCAT-FIELDNAME = 'VRKME'.
WA_FIELDCAT-SELTEXT_M = 'Sales Unit'.
APPEND WA_FIELDCAT TO I_FIELDCAT.
CLEAR WA_FIELDCAT.
WA_FIELDCAT-TABNAME = 'I_VBRP'.
WA_FIELDCAT-FIELDNAME = 'MEINS'.
WA_FIELDCAT-SELTEXT_M = 'Base Unit of Measure'.
APPEND WA_FIELDCAT TO I_FIELDCAT.
CLEAR WA_FIELDCAT.
WA_FIELDCAT-TABNAME = 'I_VBRP'.
WA_FIELDCAT-FIELDNAME = 'NETWR'.
WA_FIELDCAT-SELTEXT_M = 'Net Value'.
APPEND WA_FIELDCAT TO I_FIELDCAT.
CLEAR WA_FIELDCAT.

WA_FIELDCAT-TABNAME = 'I_VBRP'.
WA_FIELDCAT-FIELDNAME = 'AUBEL'.
WA_FIELDCAT-SELTEXT_M = ' Sales Document'.
APPEND WA_FIELDCAT TO I_FIELDCAT.
CLEAR WA_FIELDCAT.
WA_FIELDCAT-TABNAME = 'I_VBRP'.
WA_FIELDCAT-FIELDNAME = 'AUPOS'.
WA_FIELDCAT-SELTEXT_M = ' Sales Document Item'.
APPEND WA_FIELDCAT TO I_FIELDCAT.
CLEAR WA_FIELDCAT.
WA_FIELDCAT-TABNAME = 'I_VBRP'.
WA_FIELDCAT-FIELDNAME = 'MATNR'.
WA_FIELDCAT-SELTEXT_M = ' Material Number'.
APPEND WA_FIELDCAT TO I_FIELDCAT.
CLEAR WA_FIELDCAT.

ENDFORM. "BUILD_FIELDCATLOG_VBRP

*&--------ઞ-----------------------------------------------------------*
*& Form event_call_VBAP
*&--------------------------------------------------------------------*
* we get all events - TOP OF PAGE or USER COMMAND in table v_events
*---------------------------------------------------------------------*
FORM EVENT_CALL_VBRP.
CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
EXPORTING
I_LIST_TYPE = 0
IMPORTING
ET_EVENTS = V_EVENTS
 EXCEPTIONS
 LIST_TYPE_WRONG = 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.
ENDFORM. "event_call_VBRP

*&--------------------------------------------------------------------*
*& Form POPULATE_EVENT
*&--------------------------------------------------------------------*
* Events populated for TOP OF PAGE & USER COMAND
*---------------------------------------------------------------------*
FORM POPULATE_EVENT_VBRP.
READ TABLE V_EVENTS INTO WA_EVENT WITH KEY NAME = 'TOP_OF_PAGE'.
IF SY-SUBRC EQ 0.
WA_EVENT-FORM = 'TOP_OF_PAGE'.
MODIFY V_EVENTS FROM WA_EVENT TRANSPORTING FORM WHERE NAME =
WA_EVENT-FORM.
ENDIF.

ENDFORM. "POPULATE_EVENT

*&--------------------------------------------------------------------*
*& Form USER_COMMAND
*&--------------------------------------------------------------------*
* text
*----------------------------------------------------------ઞ----------*
* -->R_UCOMM text
* -->, text
* -->RS_SLEFIELDtext
*---------------------------------------------------------------------*

*retreiving values from the database table VBRK
FORM DATA_RETRIEVAL_VBRP.
SELECT  VBELN
            POSNR
            VRKME
            MEINS
            NETWR
            AUBEL
           AUPOS
           MATNR FROM VBRP INTO CORRESPONDING FIELDS OF TABLE IT_VBRP WHERE VBELN = WA_VBRK-VBELN.
ENDFORM.
FORM BUILD_LISTHEADER_VBRP USING I_LISTHEADER TYPE SLIS_T_LISTHEADER.
DATA: HLINE1 TYPE SLIS_LISTHEADER.
HLINE1-TYP = 'H'.
HLINE1-INFO = 'CHECKING PGM'.
ENDFORM.


FORM DISPLAY_ALV_VBRP.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING

I_CALLBACK_PROGRAM = V_REPID
I_CALLBACK_TOP_OF_PAGE = 'TOP_OF_PAGE'

I_GRID_TITLE = 'BILLING SECONDARY LIST'
IT_FIELDCAT = I_FIELDCAT[]
I_SAVE = 'A'
IT_EVENTS = V_EVENTS
TABLES
T_OUTTAB = IT_VBRP
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.
ENDFORM.

*&---------------------------------------------------------------------*
*&      Form  BUILD_FIELDCATLOG_VBRP
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM BUILD_FCAT3.

  CLEAR I_FIELDCAT.
  CLEAR WA_FIELDCAT.

  WA_FIELDCAT-TABNAME = 'IT_VBRP'.
  WA_FIELDCAT-FIELDNAME = 'VBELN'.
  WA_FIELDCAT-SELTEXT_M = 'BILLING DOCUMENT'.
  APPEND WA_FIELDCAT TO I_FIELDCAT.
  CLEAR WA_FIELDCAT.

  WA_FIELDCAT-TABNAME = 'IT_VBRP'.
  WA_FIELDCAT-FIELDNAME = 'POSNR'.
  WA_FIELDCAT-SELTEXT_M = 'BILLING ITEM'.
  APPEND WA_FIELDCAT TO I_FIELDCAT.
  CLEAR WA_FIELDCAT.

  WA_FIELDCAT-TABNAME = 'IT_VBRP'.
  WA_FIELDCAT-FIELDNAME = 'VRKME'.
  WA_FIELDCAT-SELTEXT_M = 'SALES UNIT'.
  APPEND WA_FIELDCAT TO I_FIELDCAT.
  CLEAR WA_FIELDCAT.

  WA_FIELDCAT-TABNAME = 'IT_VBRP'.
  WA_FIELDCAT-FIELDNAME = 'MEINS'.
  WA_FIELDCAT-SELTEXT_M = 'UNIT OF MEASURE'.
  APPEND WA_FIELDCAT TO I_FIELDCAT.
  CLEAR WA_FIELDCAT.

  WA_FIELDCAT-TABNAME = 'IT_VBRP'.
  WA_FIELDCAT-FIELDNAME = 'NETWR'.
  WA_FIELDCAT-SELTEXT_M = 'Net Value of the Sales Order in Document Currency'.
  APPEND WA_FIELDCAT TO I_FIELDCAT.
  CLEAR WA_FIELDCAT.

  WA_FIELDCAT-TABNAME = 'IT_VBRP'.
  WA_FIELDCAT-FIELDNAME = 'AUBEL'.
  WA_FIELDCAT-SELTEXT_M = 'SALES DOCUMENT'.
  APPEND WA_FIELDCAT TO I_FIELDCAT.
  CLEAR WA_FIELDCAT.

  WA_FIELDCAT-TABNAME = 'IT_VBRP'.
  WA_FIELDCAT-FIELDNAME = 'AUPOS'.
  WA_FIELDCAT-SELTEXT_M = 'SALES DOCUMENT ITEM'.
  APPEND WA_FIELDCAT TO I_FIELDCAT.
  CLEAR WA_FIELDCAT.

  WA_FIELDCAT-TABNAME = 'IT_VBRP'.
  WA_FIELDCAT-FIELDNAME = 'MATNR'.
  WA_FIELDCAT-SELTEXT_M = 'MATERIAL NUMBER'.
  APPEND WA_FIELDCAT TO I_FIELDCAT.
  CLEAR WA_FIELDCAT.



ENDFORM.                    " BUILD_FIELDCATLOG_VBRP
*&---------------------------------------------------------------------*
*&      Form  EVENT_CALL_VBRP
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM EVENT_CALL3.
CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
  EXPORTING
  I_LIST_TYPE = 0
  IMPORTING
  ET_EVENTS = V_EVENTS
 EXCEPTIONS
 LIST_TYPE_WRONG = 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.
ENDFORM. "event_call3



*&---------------------------------------------------------------------*
*&      Form  POPULATE_EVENT_VBRP
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM POPULATE_EVENT_3.
 READ TABLE V_EVENTS INTO WA_EVENT WITH KEY NAME = 'TOP_OF_PAGE'.
  IF SY-SUBRC EQ 0.
    WA_EVENT-FORM = 'TOP_OF_PAGE'.
    MODIFY V_EVENTS FROM WA_EVENT TRANSPORTING FORM WHERE NAME =
    WA_EVENT-FORM.
  ENDIF.

ENDFORM. "POPULATE_EVENT_VBRP

*&--------------------------------------------------------------------*
*& Form TOP_OF_PAGE
*&--------------------------------------------------------------------*
* text
*---------------------------------------------------------------------*
FORM TOP_OF_PAGE_VBRP.
  CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
  EXPORTING
  IT_LIST_COMMENTARY = IT_LISTHEADER
* i_logo =
* I_END_OF_LIST_GRID =
  .

ENDFORM. "TOP_OF_PAGE

*&---------------------------------------------------------------------*
*&      Form  DATA_RETRIEVAL_VBRP
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM GET_DATA3.

SELECT VBELV VBELN FROM VBFA INTO CORRESPONDING FIELDS OF TABLE IT_VBFA WHERE VBELV IN S_VBELN.

SELECT VBELN
       POSNR
       VRKME
       MEINS
       NETWR
       AUBEL
       AUPOS
       MATNR
       VKORG_AUFT
       SPART
       VTWEG_AUFT
       ERDAT FROM VBRP INTO TABLE IT_VBRP
       FOR ALL ENTRIES IN IT_VBFA WHERE VBELN = IT_VBFA-VBELN AND
                                        VKORG_AUFT = S_VKORG AND
                                        SPART = S_SPART AND
                                        VTWEG_AUFT = S_VTWEG." AND ERDAT IN S_AUDAT.
ENDFORM.                    " GET_DATA3
*&---------------------------------------------------------------------*
*&      Form  BUILD_LISTHEADER_VBRP
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_IT_LISTHEADER  text
*----------------------------------------------------------------------*
FORM BUILD_LISTHEADER_3  USING    P_IT_LISTHEADER.
 DATA: HLINE1 TYPE SLIS_LISTHEADER.
  HLINE1-TYP = 'H'.
  HLINE1-INFO = 'CHECKING PGM'.

ENDFORM.                    " BUILD_LISTHEADER_3


*&---------------------------------------------------------------------*
*&      Form  DISPLAY_ALV_VBRP
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM DISPLAY_GRID_VBRP .

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
  EXPORTING
  I_CALLBACK_PROGRAM = V_REPID
  I_CALLBACK_TOP_OF_PAGE = 'TOP_OF_PAGE'

  I_GRID_TITLE = 'CONTRACT AND BILLING SECONDARY LIST'
  IT_FIELDCAT = I_FIELDCAT[]
  I_SAVE = 'A'
  IT_EVENTS = V_EVENTS
  TABLES
  T_OUTTAB = IT_VBRP
  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.

ENDFORM.                    " DISPLAY_GRID_VBRP

Tuesday, December 15, 2015

Changing of TR Description and Status after released

To Change the TR Description and Status after released



Lets see how we can make the below Released TR into Modifiable

Step 1: Go to SE38 - Execute Program RDDIT076.





Step 2: Give your released requests number and execute again.





Step 3: After executing, you will get the list of all tasks from the Transport request.  





Step 4: Double click on every Task and change the Status from R to D.   And save it for all the task and request.

You Can change the Description as below


You Can change the Status to Modifiable (D) from Released (R)















Friday, July 26, 2013

ABAP Program to Find UserExits for a Tcode


REPORT z_find_userexit NO STANDARD PAGE HEADING.
*&---------------------------------------------------------------------*
*&  Enter the transaction code that you want to search through in order
*&  to find which Standard SAP User Exits exists.
*&---------------------------------------------------------------------*
* Selection Text: P_TCODE: Transaction Code to Search
* Text Symbols: 001 - Enter the Transaction Code that you want to search through for a 
*  User Exit

*&---------------------------------------------------------------------*
*& Tables
*&---------------------------------------------------------------------*

TABLES : TSTC,     "SAP Transaction Codes
         TADIR,    "Directory of Repository Objects
         MODSAPT,  "SAP Enhancements - Short Texts
         MODACT,   "Modifications
         TRDIR,    "System table TRDIR
         TFDIR,    "Function Module
         ENLFDIR,  "Additional Attributes for Function Modules
         TSTCT.    "Transaction Code Texts
*&---------------------------------------------------------------------*
*& Variables
*&---------------------------------------------------------------------*

DATA : JTAB LIKE TADIR OCCURS WITH HEADER LINE.
DATA : FIELD1(30).
DATA : V_DEVCLASS LIKE TADIR-DEVCLASS.

*&---------------------------------------------------------------------*
*& Selection Screen Parameters
*&---------------------------------------------------------------------*
SELECTION-SCREEN BEGIN OF BLOCK A01 WITH FRAME TITLE TEXT-001.
SELECTION-SCREEN SKIP.
PARAMETERS : P_TCODE LIKE TSTC-TCODE OBLIGATORY.
SELECTION-SCREEN SKIP.
SELECTION-SCREEN END OF BLOCK A01.

*&---------------------------------------------------------------------*
*& Start of main program
*&---------------------------------------------------------------------*

START-OF-SELECTION.

* Validate Transaction Code
  SELECT SINGLE FROM TSTC
    WHERE TCODE EQ P_TCODE.

* Find Repository Objects for transaction code
  IF SY-SUBRC EQ 0.
    SELECT SINGLE FROM TADIR
       WHERE PGMID    = 'R3TR'
         AND OBJECT   = 'PROG'
         AND OBJ_NAME = TSTC-PGMNA.

    MOVE : TADIR-DEVCLASS TO V_DEVCLASS.

    IF SY-SUBRC NE 0.
      SELECT SINGLE FROM TRDIR
         WHERE NAME = TSTC-PGMNA.

      IF TRDIR-SUBC EQ 'F'.
        SELECT SINGLE FROM TFDIR
          WHERE PNAME = TSTC-PGMNA.

        SELECT SINGLE FROM ENLFDIR
          WHERE FUNCNAME = TFDIR-FUNCNAME.

        SELECT SINGLE FROM TADIR
          WHERE PGMID    = 'R3TR'
            AND OBJECT   = 'FUGR'
            AND OBJ_NAME = ENLFDIR-AREA.

        MOVE : TADIR-DEVCLASS TO V_DEVCLASS.
      ENDIF.
    ENDIF.

* Find SAP Modifactions
    SELECT FROM TADIR
      INTO TABLE JTAB
      WHERE PGMID    = 'R3TR'
        AND OBJECT   = 'SMOD'
        AND DEVCLASS = V_DEVCLASS.

    SELECT SINGLE FROM TSTCT
      WHERE SPRSL EQ SY-LANGU
        AND TCODE EQ P_TCODE.

    FORMAT COLOR COL_POSITIVE INTENSIFIED OFF.
    WRITE:/(19) 'Transaction Code - ',
    20(20) P_TCODE,
    45(50) TSTCT-TTEXT.
    SKIP.
    IF NOT JTAB[] IS INITIAL.
      WRITE:/(95) SY-ULINE.
      FORMAT COLOR COL_HEADING INTENSIFIED ON.
      WRITE:/1 SY-VLINE,
      'Exit Name',
      21 SY-VLINE ,
      22 'Description',
      95 SY-VLINE.
      WRITE:/(95) SY-ULINE.

      LOOP AT JTAB.
        SELECT SINGLE FROM MODSAPT
        WHERE SPRSL = SY-LANGU AND
        NAME = JTAB-OBJ_NAME.
        FORMAT COLOR COL_NORMAL INTENSIFIED OFF.
        WRITE:/1 SY-VLINE,
        JTAB-OBJ_NAME HOTSPOT ON,
        21 SY-VLINE ,
        22 MODSAPT-MODTEXT,
        95 SY-VLINE.
      ENDLOOP.

      WRITE:/(95) SY-ULINE.
      DESCRIBE TABLE JTAB.
      SKIP.
      FORMAT COLOR COL_TOTAL INTENSIFIED ON.
      WRITE:/ 'No of Exits:' , SY-TFILL.
    ELSE.
      FORMAT COLOR COL_NEGATIVE INTENSIFIED ON.
      WRITE:/(95) 'No User Exit exists'.
    ENDIF.
  ELSE.
    FORMAT COLOR COL_NEGATIVE INTENSIFIED ON.
    WRITE:/(95) 'Transaction Code Does Not Exist'.
  ENDIF.

* Take the user to SMOD for the Exit that was selected.
AT LINE-SELECTION.
  GET CURSOR FIELD FIELD1.
  CHECK FIELD1(4) EQ 'JTAB'.
  SET PARAMETER ID 'MON' FIELD SY-LISEL+1(10).
  CALL TRANSACTION 'SMOD' AND SKIP FIRST SCREEN.

SAP ABAP PDF Creation Program

report zabap_2_pdf.
 
*-- Enhancements: only allow to be run with variant.  Then called
*-- program will be transparent to users
*-- TABLES
tables:
  tsp01.
*-- STRUCTURES
data:
  mstr_print_parms like pri_params,
  mc_valid(1)      type c,
  mi_bytecount     type i,
  mi_length        type i,
  mi_rqident       like tsp01-rqident.
*-- INTERNAL TABLES
data:
  mtab_pdf    like tline occurs 0 with header line,
  mc_filename like rlgrap-filename.
*-- SELECTION SCREEN
parameters:
  p_repid like sy-repid, " Report to execute
  p_linsz like sy-linsz default 132, " Line size
  p_paart like sy-paart default 'X_65_132'.  " Paper Format
start-of-selection.
concatenate 'c:\'
            p_repid
            '.pdf'
  into mc_filename.
*-- Setup the Print Parmaters
  call function 'GET_PRINT_PARAMETERS'
   exporting
     authority= space
     copies   = '1'
     cover_page                   = space
     data_set = space
     department                   = space
     destination                  = space
     expiration                   = '1'
     immediately                  = space
     in_archive_parameters        = space
     in_parameters                = space
     layout   = space
     mode     = space
     new_list_id                  = 'X'
     no_dialog= 'X'
     user     = sy-uname
   importing
     out_parameters               = mstr_print_parms
     valid    = mc_valid
   exceptions
     archive_info_not_found       = 1
     invalid_print_params         = 2
     invalid_archive_params       = 3
     others   = 4.
*-- Make sure that a printer destination has been set up
*-- If this is not done the PDF function module ABENDS
  if mstr_print_parms-pdest = space.
    mstr_print_parms-pdest = 'LOCL'.
  endif.
*-- Explicitly set line width, and output format so that
*-- the PDF conversion comes out OK
  mstr_print_parms-linsz = p_linsz.
  mstr_print_parms-paart = p_paart.
  submit (p_repid) to sap-spool without spool dynpro
                   spool parameters mstr_print_parms
                   via selection-screen
                   and return.
*-- Find out what the spool number is that was just created
  perform get_spool_number using sy-repid
             sy-uname
    changing mi_rqident.
*-- Convert Spool to PDF
  call function 'CONVERT_ABAPSPOOLJOB_2_PDF'
    exporting
      src_spoolid= mi_rqident
      no_dialog  = space
      dst_device = mstr_print_parms-pdest
    importing
      pdf_bytecount                  = mi_bytecount
    tables
      pdf        = mtab_pdf
    exceptions
      err_no_abap_spooljob           = 1
      err_no_spooljob                = 2
      err_no_permission              = 3
      err_conv_not_possible          = 4
      err_bad_destdevice             = 5
      user_cancelled                 = 6
      err_spoolerror                 = 7
      err_temseerror                 = 8
      err_btcjob_open_failed         = 9
      err_btcjob_submit_failed       = 10
      err_btcjob_close_failed        = 11
      others     = 12.
call function 'DOWNLOAD'
     exporting
          bin_filesize            = mi_bytecount
          filename                = mc_filename
          filetype                = 'BIN'
     importing
          act_filename            = mc_filename
     tables
          data_tab                = mtab_pdf.
*---------------------------------------------------------------------*
*       FORM get_spool_number *
*---------------------------------------------------------------------*
*       Get the most recent spool created by user/report              *
*---------------------------------------------------------------------*
*  -->  F_REPID               *
*  -->  F_UNAME               *
*  -->  F_RQIDENT             *
*---------------------------------------------------------------------*
form get_spool_number using f_repid
     f_uname
                changing f_rqident.
  data:
    lc_rq2name like tsp01-rq2name.
  concatenate f_repid+0(8)
              f_uname+0(3)
    into lc_rq2name separated by '_'.
  select * from tsp01 where  rq2name = lc_rq2name
  order by rqcretime descending.
    f_rqident = tsp01-rqident.
    exit.
  endselect.
  if sy-subrc ne 0.
    clear f_rqident.
  endif.
endform." get_spool_number