Thursday, January 10, 2008

Hierarchical ALV list

REPORT Z_FI_RP_PROFIT_CENTER_DOCS NO STANDARD PAGE HEADING
MESSAGE-ID ZMSGCLASS.
************************************************************************
* Program Name : Z_FI_RP_PROFIT_CENTER_DOCS *
* Development class : ZDEVELOPMENT *
* Description : This program displays the Accounting documents *
* and their corresponding line items based on the *
* posting keys. *
* 1. Accouting Document *
* 2. Company code *
* 3. Fiscal Year *
* 4. Document date *
* 5. Posting date *
* 6. User name *
************************************************************************
*----------------------------------------------------------------------*
* Request No. Created Date Developer name
*----------------------------------------------------------------------*
*----------------------------------------------------------------------*

*----------------------------------------------------------------------*
* TYPE-POOLS *
*----------------------------------------------------------------------*
TYPE-POOLS: SLIS. " ALV Global types

*----------------------------------------------------------------------*
* TABLES *
*----------------------------------------------------------------------*
TABLES: BKPF,
FAGLFLEXA.

*---------------------------------------------------------------------*
* DATA DECLARATIONS *
*---------------------------------------------------------------------*
DATA:LS_LAYOUT TYPE SLIS_LAYOUT_ALV,
LS_KEYINFO TYPE SLIS_KEYINFO_ALV,
LS_SORT TYPE SLIS_SORTINFO_ALV,
LT_SORT TYPE SLIS_T_SORTINFO_ALV,
LS_FIELDCAT TYPE SLIS_FIELDCAT_ALV,
LT_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV,
GT_SORT TYPE SLIS_T_SORTINFO_ALV,
T_FIELDCATALOG TYPE SLIS_T_FIELDCAT_ALV,
S_FIELDCATALOG TYPE SLIS_FIELDCAT_ALV,
FCAT TYPE SLIS_T_FIELDCAT_ALV,
LAYOUT TYPE SLIS_LAYOUT_ALV,
EVENT TYPE SLIS_T_EVENT WITH HEADER LINE,
HEAD TYPE SLIS_T_LISTHEADER WITH HEADER LINE,
ITEM TYPE SLIS_T_LISTHEADER WITH HEADER LINE,
SORT TYPE SLIS_T_SORTINFO_ALV WITH HEADER LINE.
*---------------------------------------------------------------------*
* CONSTANTS *
*---------------------------------------------------------------------*
CONSTANTS :C_X TYPE C VALUE 'X',
C_IT_HEAD TYPE SLIS_TABNAME VALUE 'IT_HEAD',
C_IT_ITEM TYPE SLIS_TABNAME VALUE 'IT_ITEM',
C_K TYPE C VALUE 'K',
C_D TYPE C VALUE 'D',
C_BLN(03) TYPE C VALUE 'BLN',
C_BUK(03) TYPE C VALUE 'BUK',
C_GJR(03) TYPE C VALUE 'GJR',
C_FB03(04) TYPE C VALUE 'FB03'.
*--- Constant for FORM TOP_OF_PAGE
CONSTANTS:GC_FORMNAME_TOP_OF_PAGE TYPE SLIS_FORMNAME VALUE 'TOP_OF_PAGE'.

*---------------------------------------------------------------------*
* INTERNAL TABLE DECLARATIONS *
*---------------------------------------------------------------------*
*--- Internal table declaration to hold the Accounting Document Header data
DATA: BEGIN OF IT_BKPF OCCURS 0,
BUKRS LIKE BKPF-BUKRS, " Company Code
BELNR LIKE BKPF-BELNR, " Accounting Document Number
GJAHR LIKE BKPF-GJAHR, " Fiscal Year
BLDAT LIKE BKPF-BLDAT, " Document Date in Document
BUDAT LIKE BKPF-BUDAT, " Posting Date in the Document
CPUDT LIKE BKPF-CPUDT, " Day On Which Accounting Document Was Entered
USNAM LIKE BKPF-USNAM, " User Name
END OF IT_BKPF.
*--- Internal table declaration to hold the General Ledger: Actual Line Items
DATA: BEGIN OF IT_FAGLFLEXA OCCURS 0,
DOCNR LIKE FAGLFLEXA-DOCNR, " Accounting Document Number
BUDAT LIKE FAGLFLEXA-BUDAT, " Posting Date in the Document
RYEAR LIKE FAGLFLEXA-RYEAR, " Fiscal Year
RBUKRS LIKE FAGLFLEXA-RBUKRS, " Company Code
PRCTR LIKE FAGLFLEXA-PRCTR, " Profit Center
BUZEI LIKE FAGLFLEXA-BUZEI, " Line Item No.
TSL LIKE FAGLFLEXA-TSL, " Value in Transaction Currency
HSL LIKE FAGLFLEXA-HSL, " Value in Local Currency
DRCRK LIKE FAGLFLEXA-DRCRK, " Debit/Credit Indicator
BSCHL LIKE FAGLFLEXA-BSCHL, " Posting Key
RMVCT LIKE FAGLFLEXA-RMVCT, " Transaction Type
RTCUR LIKE FAGLFLEXA-RTCUR, " Currency Key
RCNTR LIKE FAGLFLEXA-RCNTR, " Cost Center
KOKRS LIKE FAGLFLEXA-KOKRS, " Controlling Ara
SEGMENT LIKE FAGLFLEXA-SEGMENT, " Segment
RASSC LIKE FAGLFLEXA-RASSC, " Company ID of trading partner
POPER LIKE FAGLFLEXA-POPER, " Posting Period
BSTAT LIKE FAGLFLEXA-BSTAT, " Document Status
USNAM LIKE FAGLFLEXA-USNAM, " Username
END OF IT_FAGLFLEXA.
*--- Internal table declaration to hold the Posting Keys
DATA: BEGIN OF IT_TBSL OCCURS 0,
BSCHL LIKE TBSL-BSCHL, " Posting Key
KOART LIKE TBSL-KOART, " Account Type
END OF IT_TBSL.
*--- Internal table declaration to hold Accounting: Secondary Index for Vendors
DATA: BEGIN OF IT_BSIK OCCURS 0,
BUKRS LIKE BSIK-BUKRS, " Company Code
LIFNR LIKE BSIK-LIFNR, " Vendor
UMSKZ LIKE BSIK-UMSKZ, " Special G/L Indicator
GJAHR LIKE BSIK-GJAHR, " Fiscal Year
BELNR LIKE BSIK-BELNR, " Accounting Document
BUZEI LIKE BSIK-BUZEI, " Line Item
END OF IT_BSIK.
*--- Internal table declaration to hold Accounting: Secondary Index for Vendors (Cleared Items)
DATA: BEGIN OF IT_BSAK OCCURS 0,
BUKRS LIKE BSAK-BUKRS, " Company Code
LIFNR LIKE BSAK-LIFNR, " Vendor
UMSKZ LIKE BSAK-UMSKZ, " Special G/L Indicator
GJAHR LIKE BSAK-GJAHR, " Fiscal Year
BELNR LIKE BSAK-BELNR, " Accounting Document
BUZEI LIKE BSAK-BUZEI, " Line Item
END OF IT_BSAK.
*--- Internal table declaration to hold Accounting: Secondary Index for Customers
DATA: BEGIN OF IT_BSID OCCURS 0,
BUKRS LIKE BSID-BUKRS, " Company Code
KUNNR LIKE BSID-KUNNR, " Customer Number
UMSKZ LIKE BSID-UMSKZ, " Special G/L Indicator
GJAHR LIKE BSID-GJAHR, " Fiscal Year
BELNR LIKE BSID-BELNR, " Accounting Document
BUZEI LIKE BSID-BUZEI, " Line Item
END OF IT_BSID.
*--- Internal table declaration to hold Accounting: Secondary Index for Customers (Cleared Items)
DATA: BEGIN OF IT_BSAD OCCURS 0,
BUKRS LIKE BSAD-BUKRS, " Company Code
KUNNR LIKE BSAD-KUNNR, " Customer Number
UMSKZ LIKE BSAD-UMSKZ, " Special G/L Indicator
GJAHR LIKE BSAD-GJAHR, " Fiscal Year
BELNR LIKE BSAD-BELNR, " Accounting Document
BUZEI LIKE BSAD-BUZEI, " Line Item
END OF IT_BSAD.
*--- Internal table declaration to hold Accounting: Secondary Index for G/L Accounts
DATA: BEGIN OF IT_BSIS OCCURS 0,
BUKRS LIKE BSIS-BUKRS, " Company Code
HKONT LIKE BSIS-HKONT, " GL Account
GJAHR LIKE BSIS-GJAHR, " Fiscal Year
BELNR LIKE BSIS-BELNR, " Accounting Document
BUZEI LIKE BSIS-BUZEI, " Line Item
END OF IT_BSIS.
*--- Internal table declaration to hold Accounting: Secondary Index for G/L Accounts (Cleared Items)
DATA: BEGIN OF IT_BSAS OCCURS 0,
BUKRS LIKE BSAS-BUKRS, " Company Code
HKONT LIKE BSAS-HKONT, " GL Account
GJAHR LIKE BSAS-GJAHR, " Fiscal Year
BELNR LIKE BSAS-BELNR, " Accounting Document
BUZEI LIKE BSAS-BUZEI, " Line Item
END OF IT_BSAS.
*--- Internal table to hold the Header data
DATA: BEGIN OF IT_HEAD OCCURS 0,
BUKRS LIKE BKPF-BUKRS, " Company Code
BELNR LIKE BKPF-BELNR, " Accounting Document
GJAHR LIKE BKPF-GJAHR, " Fiscal Year
BLDAT LIKE BKPF-BLDAT, " Document Date
BUDAT LIKE BKPF-BUDAT, " Posting date
CPUDT LIKE BKPF-CPUDT, " Entry Date
USNAM LIKE BKPF-USNAM, " User name
END OF IT_HEAD.
*--- Internal table to hold the Item data
DATA: BEGIN OF IT_ITEM OCCURS 0.
INCLUDE STRUCTURE IT_FAGLFLEXA.
DATA: LIFNR LIKE BSIK-LIFNR, " Vendor
UMSKZ LIKE BSIK-UMSKZ, " Special GL Indicator
KUNNR LIKE BSID-KUNNR, " Customer
HKONT LIKE BSIS-HKONT, " GL Account
ACCNT_NAME LIKE SKAT-TXT50, " GL Account Name
END OF IT_ITEM.
*--- Internal table to hold Vendor descriptions
DATA: BEGIN OF IT_LFA1 OCCURS 0,
LIFNR LIKE LFA1-LIFNR, " Vendor NUmber
NAME1 LIKE LFA1-NAME1, " Vendor Name
END OF IT_LFA1.
*--- Internal table to hold Customer descriptions
DATA: BEGIN OF IT_KNA1 OCCURS 0,
KUNNR LIKE KNA1-KUNNR, " Customer Number
NAME1 LIKE KNA1-NAME1, " Customer Name
END OF IT_KNA1.
*--- Internal table to hold GL descriptions
DATA: BEGIN OF IT_SKAT OCCURS 0,
SAKNR LIKE SKAT-SAKNR, " GL Account Number
TXT50 LIKE SKAT-TXT50, " GL Account Name
END OF IT_SKAT.

*---------------------------------------------------------------------*
* SELECTION-SCREEN *
*---------------------------------------------------------------------*
SELECTION-SCREEN BEGIN OF BLOCK SCLSCR1 WITH FRAME TITLE TEXT-001.
SELECT-OPTIONS: S_BUKRS FOR BKPF-BUKRS OBLIGATORY NO-EXTENSION, " Company Code
S_BELNR FOR BKPF-BELNR, " Accounting Document Number
S_GJAHR FOR BKPF-GJAHR OBLIGATORY NO-EXTENSION, " Fiscal Year
S_BLART FOR BKPF-BLART, " Document Type
S_BLDAT FOR BKPF-BLDAT, " Document Date in Document
S_BUDAT FOR BKPF-BUDAT, " Posting Date in the Document
S_CPUDT FOR BKPF-CPUDT, " Accounting Document Entry Date
S_USNAM FOR BKPF-USNAM NO-EXTENSION, " User Name
S_PRCTR FOR FAGLFLEXA-PRCTR OBLIGATORY. " Profit Center
SELECTION-SCREEN END OF BLOCK SCLSCR1.

*---------------------------------------------------------------------*
* AT SELECTION-SCREEN *
*---------------------------------------------------------------------*
AT SELECTION-SCREEN ON S_BUKRS.
*--- Perform to validate Company code
PERFORM VALIDATE_BUKRS.

AT SELECTION-SCREEN ON S_BELNR.
*--- Perform to validate Accounting Document Number
PERFORM VALIDATE_BELNR.

AT SELECTION-SCREEN ON S_GJAHR.
*--- Perform to validate Fiscal Year
PERFORM VALIDATE_GJAHR.

AT SELECTION-SCREEN ON S_BLART.
*--- Perform to validate Document Type
PERFORM VALIDATE_BLART.

AT SELECTION-SCREEN ON S_USNAM.
*--- Perform to validate User Name
PERFORM VALIDATE_USNAM.

AT SELECTION-SCREEN ON S_PRCTR.
*--- Perform to validate User Name
PERFORM VALIDATE_PRCTR.

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

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

*--- Perform to get the Accounting Document Header data
PERFORM GET_BKPF_DATA.
*--- Perform to get the General Ledger: Actual Line Items
PERFORM GET_FAGLFLEXA_DATA.
*--- Perform to get the Posting Keys
PERFORM GET_TBSL_DATA.
*--- Perform to get the Account Information based on Posting key
PERFORM GET_ACCOUNT_INFO.
*--- Perform to get the Vendor Descriptions
PERFORM GET_LFA1_DATA.
*--- Perform to get the Customer Descriptions
PERFORM GET_KNA1_DATA.
*--- Perform to get the GL Descriptions
PERFORM GET_SKAT_DATA.

*---------------------------------------------------------------------*
* END-OF-SELECTION *
*---------------------------------------------------------------------*
END-OF-SELECTION.
*--- Perform to get the Output data
PERFORM GET_OUTPUT.
*--- Perform to Build the fieldcat to display the output in ALV format
PERFORM BUILD_FIELDCAT_ALV.
*--- Perform to display the Hierarchial ALV List
PERFORM DISPLAY_ALV_OUTPUT.

*&---------------------------------------------------------------------*
*& Form GET_BKPF_DATA
*&---------------------------------------------------------------------*
* To get the Accounting Document Header data
*----------------------------------------------------------------------*
FORM GET_BKPF_DATA.

*--- Select construct to get the Accounting Document Header data
SELECT BUKRS BELNR GJAHR BLDAT BUDAT CPUDT USNAM
FROM BKPF
INTO TABLE IT_BKPF
WHERE BUKRS IN S_BUKRS
AND BELNR IN S_BELNR
AND GJAHR IN S_GJAHR
AND BLART IN S_BLART
AND BLDAT IN S_BLDAT
AND BUDAT IN S_BUDAT
AND CPUDT IN S_CPUDT
AND USNAM IN S_USNAM.
IF SY-SUBRC = 0.
*--- Sort table IT_BKPF by Accounting document
SORT IT_BKPF BY BELNR.
ELSE.
*--- Display message if an invalid Profit Center is entered
MESSAGE S002(ZMSGCLASS)
WITH 'No data exists for the selection criteria'.
ENDIF.


ENDFORM. " GET_BKPF_DATA
*&---------------------------------------------------------------------*
*& Form GET_FAGLFLEXA_DATA
*&---------------------------------------------------------------------*
* To get the General Ledger: Actual Line Items
*----------------------------------------------------------------------*
FORM GET_FAGLFLEXA_DATA .

IF NOT IT_BKPF[] IS INITIAL.
*--- Select construct to get the General Ledger: Actual Line Items
SELECT DOCNR " Document NUmber
BUDAT " Posting Date
RYEAR " Fiscal Year
RBUKRS " Company code
PRCTR " Profit center
BUZEI " Line Item
TSL " Value in Transaction Currency
HSL " Value in Local Currency
DRCRK " Debit/Credit Indicator
BSCHL " Posting Key
RMVCT " Transaction Type
RTCUR " Currency Key
RCNTR " Cost Center
KOKRS " Controlling Area
SEGMENT " Segment for Segmental Reporting
RASSC " Company ID of trading partner
POPER " Posting period
BSTAT " Document status
USNAM " User name
FROM FAGLFLEXA
INTO TABLE IT_FAGLFLEXA
FOR ALL ENTRIES IN IT_BKPF
WHERE RYEAR = IT_BKPF-GJAHR
AND DOCNR = IT_BKPF-BELNR
AND RBUKRS = IT_BKPF-BUKRS
AND PRCTR IN S_PRCTR.
IF SY-SUBRC = 0.
*--- Sort table IT_FAGLFLEXA by Document number
SORT IT_FAGLFLEXA BY DOCNR.
ENDIF.

ENDIF.

ENDFORM. " GET_FAGLFLEXA_DATA

*&---------------------------------------------------------------------*
*& Form GET_TBSL_DATA
*&---------------------------------------------------------------------*
* To get the Posting Keys
*----------------------------------------------------------------------*
FORM GET_TBSL_DATA.

IF NOT IT_FAGLFLEXA[] IS INITIAL.
*--- Select construct to get the Posting keys
SELECT BSCHL KOART
FROM TBSL
INTO TABLE IT_TBSL
FOR ALL ENTRIES IN IT_FAGLFLEXA
WHERE BSCHL = IT_FAGLFLEXA-BSCHL.
IF SY-SUBRC = 0.
ENDIF.

ENDIF.

ENDFORM. " GET_TBSL_DATA
*&---------------------------------------------------------------------*
*& Form GET_ACCOUNT_INFO
*&---------------------------------------------------------------------*
* To get the Vendor/Customer/GL Account Information
*----------------------------------------------------------------------*
FORM GET_ACCOUNT_INFO .

*--- Loop to get the Vendor, Customer, G/L related data based on posting key
LOOP AT IT_TBSL.
*--- If posting key relates to Vendor
IF IT_TBSL-KOART = C_K.
PERFORM GET_BSIK_DATA.
*--- If posting key relates to Customer
ELSEIF IT_TBSL-KOART = C_D.
PERFORM GET_BSID_DATA.
*--- If posting key relates to G/L
ELSE.
PERFORM GET_BSIS_DATA.
ENDIF.
ENDLOOP.

ENDFORM. " GET_ACCOUNT_INFO

*&---------------------------------------------------------------------*
*& Form GET_BSIK_DATA
*&---------------------------------------------------------------------*
* To get the Vendor data
*----------------------------------------------------------------------*
FORM GET_BSIK_DATA .

IF NOT IT_FAGLFLEXA[] IS INITIAL.
*--- Select construct to get the Vendor and document number from BSIK
SELECT BUKRS LIFNR UMSKZ GJAHR BELNR BUZEI
FROM BSIK
INTO TABLE IT_BSIK
FOR ALL ENTRIES IN IT_FAGLFLEXA
WHERE BUKRS = IT_FAGLFLEXA-RBUKRS
AND GJAHR = IT_FAGLFLEXA-RYEAR
AND BELNR = IT_FAGLFLEXA-DOCNR
AND BUZEI = IT_FAGLFLEXA-BUZEI.

IF SY-SUBRC <> 0.
*--- If document does not exist in BSIK get from BSAK
*--- Select construct to get the Vendor and document number from BSIK
SELECT BUKRS LIFNR UMSKZ GJAHR BELNR BUZEI
FROM BSAK
INTO TABLE IT_BSAK
FOR ALL ENTRIES IN IT_FAGLFLEXA
WHERE BUKRS = IT_FAGLFLEXA-RBUKRS
AND GJAHR = IT_FAGLFLEXA-RYEAR
AND BELNR = IT_FAGLFLEXA-DOCNR
AND BUZEI = IT_FAGLFLEXA-BUZEI.

ENDIF.
ENDIF.
ENDFORM. " GET_BSIK_DATA
*&---------------------------------------------------------------------*
*& Form GET_BSID_DATA
*&---------------------------------------------------------------------*
* To get the Customer data
*----------------------------------------------------------------------*
FORM GET_BSID_DATA .

IF NOT IT_FAGLFLEXA[] IS INITIAL.
*--- Select construct to get the Vendor and document number from BSID
SELECT BUKRS KUNNR UMSKZ GJAHR BELNR BUZEI
FROM BSID
INTO TABLE IT_BSID
FOR ALL ENTRIES IN IT_FAGLFLEXA
WHERE BUKRS = IT_FAGLFLEXA-RBUKRS
AND GJAHR = IT_FAGLFLEXA-RYEAR
AND BELNR = IT_FAGLFLEXA-DOCNR
AND BUZEI = IT_FAGLFLEXA-BUZEI.

IF SY-SUBRC <> 0.
*--- If document does not exist in BSID get from BSAD
*--- Select construct to get the Vendor and document number from BSAD
SELECT BUKRS KUNNR UMSKZ GJAHR BELNR BUZEI
FROM BSAD
INTO TABLE IT_BSAD
FOR ALL ENTRIES IN IT_FAGLFLEXA
WHERE BUKRS = IT_FAGLFLEXA-RBUKRS
AND GJAHR = IT_FAGLFLEXA-RYEAR
AND BELNR = IT_FAGLFLEXA-DOCNR
AND BUZEI = IT_FAGLFLEXA-BUZEI.

ENDIF.
ENDIF.

ENDFORM. " GET_BSID_DATA
*&---------------------------------------------------------------------*
*& Form GET_BSIS_DATA
*&---------------------------------------------------------------------*
* To get the G/L data
*----------------------------------------------------------------------*
FORM GET_BSIS_DATA .

IF NOT IT_FAGLFLEXA[] IS INITIAL.
*--- Select construct to get the Vendor and document number from BSID
SELECT BUKRS HKONT GJAHR BELNR BUZEI
FROM BSIS
INTO TABLE IT_BSIS
FOR ALL ENTRIES IN IT_FAGLFLEXA
WHERE BUKRS = IT_FAGLFLEXA-RBUKRS
AND GJAHR = IT_FAGLFLEXA-RYEAR
AND BELNR = IT_FAGLFLEXA-DOCNR
AND BUZEI = IT_FAGLFLEXA-BUZEI.

IF SY-SUBRC <> 0.
*--- If document does not exist in BSID get from BSAD
*--- Select construct to get the Vendor and document number from BSAD
SELECT BUKRS HKONT GJAHR BELNR BUZEI
FROM BSAS
INTO TABLE IT_BSAS
FOR ALL ENTRIES IN IT_FAGLFLEXA
WHERE BUKRS = IT_FAGLFLEXA-RBUKRS
AND GJAHR = IT_FAGLFLEXA-RYEAR
AND BELNR = IT_FAGLFLEXA-DOCNR
AND BUZEI = IT_FAGLFLEXA-BUZEI.

ENDIF.

ENDIF.

ENDFORM. " GET_BSIS_DATA

*&---------------------------------------------------------------------*
*& Form GET_LFA1_DATA
*&---------------------------------------------------------------------*
* To get the Vendor Descriptions
*----------------------------------------------------------------------*
FORM GET_LFA1_DATA.

IF NOT IT_BSIK[] IS INITIAL.
*--- Select construct to get the Vendor Names
SELECT LIFNR NAME1
FROM LFA1
INTO TABLE IT_LFA1
FOR ALL ENTRIES IN IT_BSIK
WHERE LIFNR = IT_BSIK-LIFNR.
IF SY-SUBRC <> 0.
ENDIF.
ENDIF.

ENDFORM. " GET_LFA1_DATA
*&---------------------------------------------------------------------*
*& Form GET_KNA1_DATA
*&---------------------------------------------------------------------*
* To get the Customer descriptions
*----------------------------------------------------------------------*
FORM GET_KNA1_DATA .

IF NOT IT_BSID[] IS INITIAL.
*--- Select construct to get the Vendor Names
SELECT KUNNR NAME1
FROM KNA1
INTO TABLE IT_KNA1
FOR ALL ENTRIES IN IT_BSID
WHERE KUNNR = IT_BSID-KUNNR.
IF SY-SUBRC <> 0.
ENDIF.
ENDIF.

ENDFORM. " GET_KNA1_DATA
*&---------------------------------------------------------------------*
*& Form GET_SKAT_DATA
*&---------------------------------------------------------------------*
* To get the GL Descriptions
*----------------------------------------------------------------------*
FORM GET_SKAT_DATA .

IF NOT IT_BSIS[] IS INITIAL.
*--- Select construct to get the GL Account descriptions
SELECT SAKNR TXT50
FROM SKAT
INTO TABLE IT_SKAT
FOR ALL ENTRIES IN IT_BSIS
WHERE SAKNR = IT_BSIS-HKONT
AND SPRAS = 'EN'.

IF SY-SUBRC <> 0.
ENDIF.
ENDIF.

ENDFORM. " GET_SKAT_DATA
*&---------------------------------------------------------------------*
*& Form GET_OUTPUT
*&---------------------------------------------------------------------*
* To get the Output data
*----------------------------------------------------------------------*
FORM GET_OUTPUT.

DATA: L_LIFNR LIKE BSIK-LIFNR,
L_KUNNR LIKE BSID-KUNNR,
L_SAKNR LIKE SKAT-SAKNR.
DATA: FG_DOC TYPE C.

LOOP AT IT_BKPF.
FG_DOC = SPACE.
LOOP AT IT_FAGLFLEXA WHERE DOCNR = IT_BKPF-BELNR.
*--- Get the documents pertaining to profit center
IF FG_DOC = SPACE.
IT_HEAD-BUKRS = IT_BKPF-BUKRS.
IT_HEAD-BELNR = IT_BKPF-BELNR.
IT_HEAD-GJAHR = IT_BKPF-GJAHR.
IT_HEAD-BLDAT = IT_BKPF-BLDAT.
IT_HEAD-BUDAT = IT_BKPF-BUDAT.
IT_HEAD-CPUDT = IT_BKPF-CPUDT.
IT_HEAD-USNAM = IT_BKPF-USNAM.
APPEND IT_HEAD.
CLEAR IT_HEAD.
FG_DOC = 'X'.
ENDIF.

IT_ITEM = IT_FAGLFLEXA.

*--- Read tables BSIK to get the Vendor data
READ TABLE IT_BSIK WITH KEY BELNR = IT_FAGLFLEXA-DOCNR
BUZEI = IT_FAGLFLEXA-BUZEI.
IF SY-SUBRC = 0.
IT_ITEM-LIFNR = IT_BSIK-LIFNR.
IT_ITEM-UMSKZ = IT_BSIK-UMSKZ.
L_LIFNR = IT_BSIK-LIFNR.
ELSE.
*--- Read tables BSAK to get the Vendor data
READ TABLE IT_BSAK WITH KEY BELNR = IT_FAGLFLEXA-DOCNR
BUZEI = IT_FAGLFLEXA-BUZEI.
IF SY-SUBRC = 0.
IT_ITEM-LIFNR = IT_BSAK-LIFNR.
IT_ITEM-UMSKZ = IT_BSAK-UMSKZ.
L_LIFNR = IT_BSAK-LIFNR.
ENDIF.
ENDIF.
*---- Get the Vendor description into output table
READ TABLE IT_LFA1 WITH KEY LIFNR = L_LIFNR.
IF SY-SUBRC = 0.
IT_ITEM-ACCNT_NAME = IT_LFA1-NAME1.
ENDIF.

*--- Read tables BSID to get the Customer data
READ TABLE IT_BSID WITH KEY BELNR = IT_FAGLFLEXA-DOCNR
BUZEI = IT_FAGLFLEXA-BUZEI.
IF SY-SUBRC = 0.
IT_ITEM-KUNNR = IT_BSID-KUNNR.
IT_ITEM-UMSKZ = IT_BSID-UMSKZ.
L_KUNNR = IT_BSID-KUNNR.
ELSE.
*--- Read tables BSAD to get the Customer data
READ TABLE IT_BSAD WITH KEY BELNR = IT_FAGLFLEXA-DOCNR
BUZEI = IT_FAGLFLEXA-BUZEI.
IF SY-SUBRC = 0.
IT_ITEM-KUNNR = IT_BSAD-KUNNR.
IT_ITEM-UMSKZ = IT_BSAD-UMSKZ.
L_KUNNR = IT_BSAD-KUNNR.
ENDIF.
ENDIF.
*---- Get the Customer description into output table
READ TABLE IT_KNA1 WITH KEY KUNNR = L_KUNNR.
IF SY-SUBRC = 0.
IT_ITEM-ACCNT_NAME = IT_KNA1-NAME1.
ENDIF.

*--- Read tables BSIS to get the G/L data
READ TABLE IT_BSIS WITH KEY BELNR = IT_FAGLFLEXA-DOCNR
BUZEI = IT_FAGLFLEXA-BUZEI.
IF SY-SUBRC = 0.
L_SAKNR = IT_BSIS-HKONT.
ELSE.
*--- Read tables BSAS to get the G/L data
READ TABLE IT_BSAS WITH KEY BELNR = IT_FAGLFLEXA-DOCNR
BUZEI = IT_FAGLFLEXA-BUZEI.
IF SY-SUBRC = 0.
L_SAKNR = IT_BSAS-HKONT.
ENDIF.
ENDIF.
*--- Get the GL Account descrition into Output table
READ TABLE IT_SKAT WITH KEY SAKNR = L_SAKNR.
IF SY-SUBRC = 0.
IT_ITEM-HKONT = L_SAKNR.
IT_ITEM-ACCNT_NAME = IT_SKAT-TXT50.
ENDIF.

APPEND: IT_ITEM.
CLEAR: IT_ITEM,
L_LIFNR,
L_KUNNR,
L_SAKNR.
ENDLOOP.
ENDLOOP.

ENDFORM. " GET_OUTPUT
*&---------------------------------------------------------------------*
*& Form BUILD_FIELDCAT_ALV
*&---------------------------------------------------------------------*
* Format and display the output
*----------------------------------------------------------------------*
FORM BUILD_FIELDCAT_ALV .

DATA: LS_SORT TYPE SLIS_SORTINFO_ALV.
DATA: S_LAYOUT TYPE SLIS_LAYOUT_ALV.

*--- Set Layout properties
LS_LAYOUT-GROUP_CHANGE_EDIT = C_X.
LS_LAYOUT-COLWIDTH_OPTIMIZE = SPACE.
LS_LAYOUT-ZEBRA = C_X.
LS_LAYOUT-DETAIL_POPUP = C_X.
LS_LAYOUT-GET_SELINFOS = C_X.

**--- Build field catalog and sort table
S_FIELDCATALOG-COL_POS = '1'.
S_FIELDCATALOG-FIELDNAME = 'BELNR'.
S_FIELDCATALOG-TABNAME = 'IT_HEAD'.
S_FIELDCATALOG-ROLLNAME = 'BELNR_D'.
S_FIELDCATALOG-OUTPUTLEN = '10'.
S_FIELDCATALOG-SP_GROUP = 'A'.
S_FIELDCATALOG-EMPHASIZE = 'C71'.
APPEND S_FIELDCATALOG TO T_FIELDCATALOG.
CLEAR: S_FIELDCATALOG.

*--- Fieldcatalog for Company Code (Header data)
S_FIELDCATALOG-COL_POS = '2'.
S_FIELDCATALOG-FIELDNAME = 'BUKRS'.
S_FIELDCATALOG-TABNAME = 'IT_HEAD'.
S_FIELDCATALOG-ROLLNAME = 'BUKRS'.
S_FIELDCATALOG-OUTPUTLEN = '10'.
APPEND S_FIELDCATALOG TO T_FIELDCATALOG.
CLEAR: S_FIELDCATALOG.

*--- Fieldcatalog for Fiscal year (Header data)
S_FIELDCATALOG-COL_POS = '3'.
S_FIELDCATALOG-FIELDNAME = 'GJAHR'.
S_FIELDCATALOG-TABNAME = 'IT_HEAD'.
S_FIELDCATALOG-ROLLNAME = 'GJAHR'.
S_FIELDCATALOG-OUTPUTLEN = '12'.
APPEND S_FIELDCATALOG TO T_FIELDCATALOG.
CLEAR: S_FIELDCATALOG.

*--- Fieldcatalog for Document Date (Header data)
S_FIELDCATALOG-COL_POS = '4'.
S_FIELDCATALOG-FIELDNAME = 'BLDAT'.
S_FIELDCATALOG-TABNAME = 'IT_HEAD'.
S_FIELDCATALOG-ROLLNAME = 'BLDAT'.
S_FIELDCATALOG-OUTPUTLEN = '10'.
APPEND S_FIELDCATALOG TO T_FIELDCATALOG.
CLEAR: S_FIELDCATALOG.

*--- Fieldcatalog for Posting Date (Header data)
S_FIELDCATALOG-COL_POS = '5'.
S_FIELDCATALOG-FIELDNAME = 'BUDAT'.
S_FIELDCATALOG-TABNAME = 'IT_HEAD'.
S_FIELDCATALOG-ROLLNAME = 'BUDAT'.
S_FIELDCATALOG-OUTPUTLEN = '10'.
APPEND S_FIELDCATALOG TO T_FIELDCATALOG.
CLEAR: S_FIELDCATALOG.

*--- Fieldcatalog for Document Entry Date (Header data)
S_FIELDCATALOG-COL_POS = '6'.
S_FIELDCATALOG-FIELDNAME = 'CPUDT'.
S_FIELDCATALOG-TABNAME = 'IT_HEAD'.
S_FIELDCATALOG-ROLLNAME = 'CPUDT'.
S_FIELDCATALOG-OUTPUTLEN = '10'.
APPEND S_FIELDCATALOG TO T_FIELDCATALOG.
CLEAR: S_FIELDCATALOG.

*--- Fieldcatalog for UserName (Header data)
S_FIELDCATALOG-COL_POS = '7'.
S_FIELDCATALOG-FIELDNAME = 'USNAM'.
S_FIELDCATALOG-TABNAME = 'IT_HEAD'.
S_FIELDCATALOG-ROLLNAME = 'USNAM'.
S_FIELDCATALOG-OUTPUTLEN = '12'.
APPEND S_FIELDCATALOG TO T_FIELDCATALOG.
CLEAR: S_FIELDCATALOG.

*--- Fieldcatalog for Document No. (Item data)
S_FIELDCATALOG-COL_POS = '1'.
S_FIELDCATALOG-FIELDNAME = 'DOCNR'.
S_FIELDCATALOG-TABNAME = 'IT_ITEM'.
S_FIELDCATALOG-ROLLNAME = 'BELNR_D'.
S_FIELDCATALOG-OUTPUTLEN = '10'.
S_FIELDCATALOG-EMPHASIZE = 'C11'.
APPEND S_FIELDCATALOG TO T_FIELDCATALOG.
CLEAR: S_FIELDCATALOG.

*--- Fieldcatalog for Posting Date. (Item data)
S_FIELDCATALOG-COL_POS = '2'.
S_FIELDCATALOG-FIELDNAME = 'BUDAT'.
S_FIELDCATALOG-TABNAME = 'IT_ITEM'.
S_FIELDCATALOG-ROLLNAME = 'BUDAT'.
S_FIELDCATALOG-OUTPUTLEN = '10'.
APPEND S_FIELDCATALOG TO T_FIELDCATALOG.
CLEAR: S_FIELDCATALOG.

*--- Fieldcatalog for Fiscal Year (Item data)
S_FIELDCATALOG-COL_POS = '3'.
S_FIELDCATALOG-FIELDNAME = 'RYEAR'.
S_FIELDCATALOG-TABNAME = 'IT_ITEM'.
S_FIELDCATALOG-ROLLNAME = 'RYEAR'.
S_FIELDCATALOG-OUTPUTLEN = '10'.
APPEND S_FIELDCATALOG TO T_FIELDCATALOG.
CLEAR: S_FIELDCATALOG.

*--- Fieldcatalog for Company Code. (Item data)
S_FIELDCATALOG-COL_POS = '4'.
S_FIELDCATALOG-FIELDNAME = 'RBUKRS'.
S_FIELDCATALOG-TABNAME = 'IT_ITEM'.
S_FIELDCATALOG-ROLLNAME = 'BUKRS'.
S_FIELDCATALOG-OUTPUTLEN = '10'.
APPEND S_FIELDCATALOG TO T_FIELDCATALOG.
CLEAR: S_FIELDCATALOG.

*--- Fieldcatalog for Profit Center (Item data)
S_FIELDCATALOG-COL_POS = '5'.
S_FIELDCATALOG-FIELDNAME = 'PRCTR'.
S_FIELDCATALOG-TABNAME = 'IT_ITEM'.
S_FIELDCATALOG-ROLLNAME = 'PRCTR'.
S_FIELDCATALOG-OUTPUTLEN = '10'.
APPEND S_FIELDCATALOG TO T_FIELDCATALOG.
CLEAR: S_FIELDCATALOG.

*--- Fieldcatalog for Item No. (Item data)
S_FIELDCATALOG-COL_POS = '6'.
S_FIELDCATALOG-FIELDNAME = 'BUZEI'.
S_FIELDCATALOG-TABNAME = 'IT_ITEM'.
S_FIELDCATALOG-ROLLNAME = 'BUZEI'.
S_FIELDCATALOG-OUTPUTLEN = '3'.
APPEND S_FIELDCATALOG TO T_FIELDCATALOG.
CLEAR: S_FIELDCATALOG.

*--- Fieldcatalog for Value in Transaction Currency (Item data)
S_FIELDCATALOG-COL_POS = '7'.
S_FIELDCATALOG-FIELDNAME = 'TSL'.
S_FIELDCATALOG-TABNAME = 'IT_ITEM'.
S_FIELDCATALOG-ROLLNAME = 'VTCUR12'.
S_FIELDCATALOG-OUTPUTLEN = '15'.
APPEND S_FIELDCATALOG TO T_FIELDCATALOG.
CLEAR: S_FIELDCATALOG.

*--- Fieldcatalog for Value in Local Currency (Item data)
S_FIELDCATALOG-COL_POS = '8'.
S_FIELDCATALOG-FIELDNAME = 'HSL'.
S_FIELDCATALOG-TABNAME = 'IT_ITEM'.
S_FIELDCATALOG-ROLLNAME = 'VLCUR12'.
S_FIELDCATALOG-OUTPUTLEN = '15'.
APPEND S_FIELDCATALOG TO T_FIELDCATALOG.
CLEAR: S_FIELDCATALOG.

*--- Fieldcatalog for Debit/Credit Indicator (Item data)
S_FIELDCATALOG-COL_POS = '9'.
S_FIELDCATALOG-FIELDNAME = 'DRCRK'.
S_FIELDCATALOG-TABNAME = 'IT_ITEM'.
S_FIELDCATALOG-ROLLNAME = 'DRCRK'.
S_FIELDCATALOG-OUTPUTLEN = '2'.
APPEND S_FIELDCATALOG TO T_FIELDCATALOG.
CLEAR: S_FIELDCATALOG.

*--- Fieldcatalog for Posting Key (Item data)
S_FIELDCATALOG-COL_POS = '10'.
S_FIELDCATALOG-FIELDNAME = 'BSCHL'.
S_FIELDCATALOG-TABNAME = 'IT_ITEM'.
S_FIELDCATALOG-ROLLNAME = 'BSCHL'.
S_FIELDCATALOG-OUTPUTLEN = '4'.
APPEND S_FIELDCATALOG TO T_FIELDCATALOG.
CLEAR: S_FIELDCATALOG.

*--- Fieldcatalog for Vendor Number (Item data)
S_FIELDCATALOG-COL_POS = '11'.
S_FIELDCATALOG-FIELDNAME = 'LIFNR'.
S_FIELDCATALOG-TABNAME = 'IT_ITEM'.
S_FIELDCATALOG-ROLLNAME = 'LIFNR'.
S_FIELDCATALOG-OUTPUTLEN = '10'.
APPEND S_FIELDCATALOG TO T_FIELDCATALOG.
CLEAR: S_FIELDCATALOG.

*--- Fieldcatalog for (Item data)
S_FIELDCATALOG-COL_POS = '12'.
S_FIELDCATALOG-FIELDNAME = 'UMSKZ'.
S_FIELDCATALOG-TABNAME = 'IT_ITEM'.
S_FIELDCATALOG-ROLLNAME = 'UMSKZ'.
S_FIELDCATALOG-OUTPUTLEN = '3'.
APPEND S_FIELDCATALOG TO T_FIELDCATALOG.
CLEAR: S_FIELDCATALOG.

*--- Fieldcatalog for Customer Number (Item data)
S_FIELDCATALOG-COL_POS = '13'.
S_FIELDCATALOG-FIELDNAME = 'KUNNR'.
S_FIELDCATALOG-TABNAME = 'IT_ITEM'.
S_FIELDCATALOG-ROLLNAME = 'KUNNR'.
S_FIELDCATALOG-OUTPUTLEN = '10'.
APPEND S_FIELDCATALOG TO T_FIELDCATALOG.
CLEAR: S_FIELDCATALOG.

*--- Fieldcatalog for GL Account (Item data)
S_FIELDCATALOG-COL_POS = '14'.
S_FIELDCATALOG-FIELDNAME = 'HKONT'.
S_FIELDCATALOG-TABNAME = 'IT_ITEM'.
S_FIELDCATALOG-ROLLNAME = 'HKONT'.
S_FIELDCATALOG-OUTPUTLEN = '10'.
APPEND S_FIELDCATALOG TO T_FIELDCATALOG.
CLEAR: S_FIELDCATALOG.

*--- Fieldcatalog for Account Name (Item data)
S_FIELDCATALOG-COL_POS = '15'.
S_FIELDCATALOG-FIELDNAME = 'ACCNT_NAME'.
S_FIELDCATALOG-TABNAME = 'IT_ITEM'.
S_FIELDCATALOG-ROLLNAME = 'NAME1_GP'.
S_FIELDCATALOG-OUTPUTLEN = '50'.
APPEND S_FIELDCATALOG TO T_FIELDCATALOG.
CLEAR: S_FIELDCATALOG.

*--- Fieldcatalog for Transaction Type (Item data)
S_FIELDCATALOG-COL_POS = '16'.
S_FIELDCATALOG-FIELDNAME = 'RMVCT'.
S_FIELDCATALOG-TABNAME = 'IT_ITEM'.
S_FIELDCATALOG-ROLLNAME = 'RMVCT'.
S_FIELDCATALOG-OUTPUTLEN = '4'.
APPEND S_FIELDCATALOG TO T_FIELDCATALOG.
CLEAR: S_FIELDCATALOG.

*--- Fieldcatalog for Currency Key (Item data)
S_FIELDCATALOG-COL_POS = '17'.
S_FIELDCATALOG-FIELDNAME = 'RTCUR'.
S_FIELDCATALOG-TABNAME = 'IT_ITEM'.
S_FIELDCATALOG-ROLLNAME = 'RTCUR'.
S_FIELDCATALOG-OUTPUTLEN = '5'.
APPEND S_FIELDCATALOG TO T_FIELDCATALOG.
CLEAR: S_FIELDCATALOG.

*--- Fieldcatalog for Cost Center (Item data)
S_FIELDCATALOG-COL_POS = '18'.
S_FIELDCATALOG-FIELDNAME = 'RCNTR'.
S_FIELDCATALOG-TABNAME = 'IT_ITEM'.
S_FIELDCATALOG-ROLLNAME = 'RCNTR'.
S_FIELDCATALOG-OUTPUTLEN = '10'.
APPEND S_FIELDCATALOG TO T_FIELDCATALOG.
CLEAR: S_FIELDCATALOG.

*--- Fieldcatalog for Controlling Area (Item data)
S_FIELDCATALOG-COL_POS = '19'.
S_FIELDCATALOG-FIELDNAME = 'KOKRS'.
S_FIELDCATALOG-TABNAME = 'IT_ITEM'.
S_FIELDCATALOG-ROLLNAME = 'KOKRS'.
S_FIELDCATALOG-OUTPUTLEN = '10'.
APPEND S_FIELDCATALOG TO T_FIELDCATALOG.
CLEAR: S_FIELDCATALOG.

*--- Fieldcatalog for Segment (Item data)
S_FIELDCATALOG-COL_POS = '20'.
S_FIELDCATALOG-FIELDNAME = 'SEGMENT'.
S_FIELDCATALOG-TABNAME = 'IT_ITEM'.
S_FIELDCATALOG-ROLLNAME = 'SEGMENT'.
S_FIELDCATALOG-OUTPUTLEN = '10'.
APPEND S_FIELDCATALOG TO T_FIELDCATALOG.
CLEAR: S_FIELDCATALOG.

*--- Fieldcatalog for Company ID of trading partner (Item data)
S_FIELDCATALOG-COL_POS = '21'.
S_FIELDCATALOG-FIELDNAME = 'RASSC'.
S_FIELDCATALOG-TABNAME = 'IT_ITEM'.
S_FIELDCATALOG-ROLLNAME = 'RASSC'.
S_FIELDCATALOG-OUTPUTLEN = '10'.
APPEND S_FIELDCATALOG TO T_FIELDCATALOG.
CLEAR: S_FIELDCATALOG.

*--- Fieldcatalog for Posting period (Item data)
S_FIELDCATALOG-COL_POS = '22'.
S_FIELDCATALOG-FIELDNAME = 'POPER'.
S_FIELDCATALOG-TABNAME = 'IT_ITEM'.
S_FIELDCATALOG-ROLLNAME = 'POPER'.
S_FIELDCATALOG-OUTPUTLEN = '10'.
APPEND S_FIELDCATALOG TO T_FIELDCATALOG.
CLEAR: S_FIELDCATALOG.

*--- Fieldcatalog for Document Status (Item data)
S_FIELDCATALOG-COL_POS = '23'.
S_FIELDCATALOG-FIELDNAME = 'BSTAT'.
S_FIELDCATALOG-TABNAME = 'IT_ITEM'.
S_FIELDCATALOG-ROLLNAME = 'BSTAT'.
S_FIELDCATALOG-OUTPUTLEN = '4'.
APPEND S_FIELDCATALOG TO T_FIELDCATALOG.
CLEAR: S_FIELDCATALOG.

*--- Fieldcatalog for User Name (Item data)
S_FIELDCATALOG-COL_POS = '24'.
S_FIELDCATALOG-FIELDNAME = 'USNAM'.
S_FIELDCATALOG-TABNAME = 'IT_ITEM'.
S_FIELDCATALOG-ROLLNAME = 'USNAM'.
S_FIELDCATALOG-OUTPUTLEN = '10'.
APPEND S_FIELDCATALOG TO T_FIELDCATALOG.
CLEAR: S_FIELDCATALOG.

S_LAYOUT-SUBTOTALS_TEXT = 'SUBTOTAL TEXT'.
S_LAYOUT-KEY_HOTSPOT = 'X'.
S_LAYOUT-EXPAND_FIELDNAME = 'EXPAND'.

*--- Add events for the Hierarchial List
EVENT-NAME = 'TOP_OF_PAGE'.
EVENT-FORM = 'TOP_OF_PAGE'.
APPEND EVENT.

*--- Specifying the Key field information
LS_KEYINFO-HEADER01 = 'BELNR'.
LS_KEYINFO-ITEM01 = 'DOCNR'.
LS_KEYINFO-ITEM02 = 'RYEAR'.

ENDFORM. " BUILD_FIELDCAT_ALV
*&---------------------------------------------------------------------*
*& Form DISPLAY_ALV_OUTPUT
*&---------------------------------------------------------------------*
* To display the ALV list output
*----------------------------------------------------------------------*
FORM DISPLAY_ALV_OUTPUT .

*--- Call function to display Hierarchical list
CALL FUNCTION 'REUSE_ALV_HIERSEQ_LIST_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM = SY-CPROG
I_CALLBACK_USER_COMMAND = 'USER_COMMAND'
IT_EVENTS = EVENT[]
IS_LAYOUT = LS_LAYOUT
IT_FIELDCAT = T_FIELDCATALOG
I_TABNAME_HEADER = C_IT_HEAD
I_TABNAME_ITEM = C_IT_ITEM
IS_KEYINFO = LS_KEYINFO
TABLES
T_OUTTAB_HEADER = IT_HEAD
T_OUTTAB_ITEM = IT_ITEM
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_ALV_OUTPUT

*&---------------------------------------------------------------------*
*& Form USER_COMMAND
*&---------------------------------------------------------------------*
* To navigate to the Document display - transaction FB03
*----------------------------------------------------------------------*
FORM USER_COMMAND USING I_UCOMM TYPE SY-UCOMM
IS_SELFIELD TYPE SLIS_SELFIELD. "#EC CALLED

DATA: LS_HEAD LIKE IT_HEAD,
LS_ITEM LIKE IT_ITEM.

*--- Check the User command
CASE I_UCOMM.
WHEN '&IC1'. " Pick
CASE IS_SELFIELD-TABNAME.
*--- Check whether selection is from HEADER data
WHEN C_IT_HEAD.
*--- Get the Values from the Header table matching the selected values
READ TABLE IT_HEAD INDEX IS_SELFIELD-TABINDEX INTO LS_HEAD.
IF SY-SUBRC EQ 0.
*--- Set the parameter IDs for BELNR and BUKRS and fill values
SET PARAMETER ID C_BLN FIELD LS_HEAD-BELNR.
SET PARAMETER ID C_BUK FIELD LS_HEAD-BUKRS.
SET PARAMETER ID C_GJR FIELD LS_HEAD-GJAHR.
*--- Call transaction for the corresponding value selected
CALL TRANSACTION C_FB03 AND SKIP FIRST SCREEN.
ENDIF.

*--- Check whether selection is from ITEM data
WHEN C_IT_ITEM.
*--- Get the Values from the Header table matching the selected values
READ TABLE IT_ITEM INDEX IS_SELFIELD-TABINDEX INTO LS_ITEM.
IF SY-SUBRC EQ 0.
*--- Set the parameter IDs for BELNR and BUKRS and fill values
SET PARAMETER ID C_BLN FIELD LS_ITEM-DOCNR.
SET PARAMETER ID C_BUK FIELD LS_ITEM-RBUKRS.
SET PARAMETER ID C_GJR FIELD LS_ITEM-RYEAR.
*--- Call transaction for the corresponding value selected
CALL TRANSACTION C_FB03 AND SKIP FIRST SCREEN.
ENDIF.
ENDCASE.
ENDCASE.

ENDFORM. " USER_COMMAND

*&---------------------------------------------------------------------*
*& Form VALIDATE_BUKRS
*&---------------------------------------------------------------------*
* To validate Company code against the check table T001
*----------------------------------------------------------------------*
FORM VALIDATE_BUKRS.

DATA: L_BUKRS LIKE BKPF-BUKRS.

IF NOT S_BUKRS[] IS INITIAL.
*--- Select Construct to check S_BUKRS against BUKRS from T001
SELECT SINGLE BUKRS
INTO L_BUKRS
FROM T001
WHERE BUKRS IN S_BUKRS.
IF SY-SUBRC <> 0.
*--- Display message if an invalid Company Code is entered
MESSAGE E002(ZMSGCLASS) WITH 'Enter a valid Company code'.
ENDIF.
ENDIF.

ENDFORM. " VALIDATE_BUKRS
*&---------------------------------------------------------------------*
*& Form VALIDATE_BELNR
*&---------------------------------------------------------------------*
* Validating the Document No. against the check table BKPF
*----------------------------------------------------------------------*
FORM VALIDATE_BELNR .

DATA: L_BELNR LIKE BKPF-BELNR.

IF NOT S_BELNR[] IS INITIAL.
*--- Select Construct to check S_BELNR against BELNR from BKPF
SELECT SINGLE BELNR
INTO L_BELNR
FROM BKPF
WHERE BELNR IN S_BELNR.
IF SY-SUBRC <> 0.
*--- Display message if an invalid Document Number is entered
MESSAGE E002(ZMSGCLASS) WITH 'Enter a valid Document Number'.
ENDIF.
ENDIF.

ENDFORM. " VALIDATE_BELNR
*&---------------------------------------------------------------------*
*& Form VALIDATE_GJAHR
*&---------------------------------------------------------------------*
* Validating the Fiscal Year against the check table BKPF
*----------------------------------------------------------------------*
FORM VALIDATE_GJAHR.

DATA: L_GJAHR LIKE BKPF-GJAHR.

IF NOT S_GJAHR[] IS INITIAL.
*--- Select Construct to check S_GJAHR against GJAHR from BKPF
SELECT SINGLE GJAHR
INTO L_GJAHR
FROM BKPF
WHERE GJAHR IN S_GJAHR.
IF SY-SUBRC <> 0.
*--- Display message if an invalid Fiscal Year is entered
MESSAGE E002(ZMSGCLASS) WITH 'Enter a valid Fiscal Year'.
ENDIF.
ENDIF.

ENDFORM. " VALIDATE_GJAHR
*&---------------------------------------------------------------------*
*& Form VALIDATE_BLART
*&---------------------------------------------------------------------*
* Validating the Document Type against T003
*----------------------------------------------------------------------*
FORM VALIDATE_BLART .

DATA: L_BLART LIKE T003-BLART.

IF NOT S_BLART[] IS INITIAL.
*--- Select Construct to check S_BELNR against BELNR from BKPF
SELECT SINGLE BLART
INTO L_BLART
FROM T003
WHERE BLART IN S_BLART.
IF SY-SUBRC <> 0.
*--- Display message if an invalid Document Type is entered
MESSAGE E002(ZMSGCLASS) WITH 'Enter a valid Document Type'.
ENDIF.
ENDIF.

ENDFORM. " VALIDATE_BLART
*&---------------------------------------------------------------------*
*& Form VALIDATE_USNAM
*&---------------------------------------------------------------------*
* Validating the Username against the check table BKPF
*----------------------------------------------------------------------*
FORM VALIDATE_USNAM .

DATA: L_USNAM LIKE BKPF-USNAM.

IF NOT S_USNAM[] IS INITIAL.
*--- Select Construct to check S_USNAM against USNAM from BKPF
SELECT SINGLE USNAM
INTO L_USNAM
FROM BKPF
WHERE USNAM IN S_USNAM.
IF SY-SUBRC <> 0.
*--- Display message if an invalid User Name is entered
MESSAGE E002(ZMSGCLASS) WITH 'Enter a valid User Name'.
ENDIF.
ENDIF.

ENDFORM. " VALIDATE_USNAM
*&---------------------------------------------------------------------*
*& Form VALIDATE_PRCTR
*&---------------------------------------------------------------------*
* Validating the Profit against the check table CEPC
*----------------------------------------------------------------------*
FORM VALIDATE_PRCTR .

DATA: L_PRCTR LIKE CEPC-PRCTR.

IF NOT S_PRCTR[] IS INITIAL.
*--- Select Construct to check S_PRCTR against PRCTR from CEPC
SELECT SINGLE PRCTR
INTO L_PRCTR
FROM CEPC
WHERE PRCTR IN S_PRCTR.
IF SY-SUBRC <> 0.
*--- Display message if an invalid Profit Center is entered
MESSAGE E002(ZMSGCLASS) WITH 'Enter a valid Profit Center'.
ENDIF.
ENDIF.

ENDFORM. " VALIDATE_PRCTR

*---------------------------------------------------------------------*
* FORM TOP_OF_PAGE *
*---------------------------------------------------------------------*
* TOP OF PAGE *
*---------------------------------------------------------------------*
FORM TOP_OF_PAGE.

DATA: V_COUNT(05) TYPE N.
DATA: L_COUNT(05) TYPE C.
DATA: V_HEADER(100) TYPE C.

*--- Get the number of Documents to be displayed
DESCRIBE TABLE IT_HEAD LINES V_COUNT.
V_COUNT = V_COUNT.
L_COUNT = V_COUNT.
CONCATENATE ' Profit center wise documents'
'Number of Documents'
V_COUNT
INTO V_HEADER SEPARATED BY ':'.

REFRESH HEAD.
HEAD-TYP = 'H'.
HEAD-INFO = V_HEADER.
APPEND HEAD.

CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
EXPORTING
IT_LIST_COMMENTARY = HEAD[]
* I_LOGO =
* I_END_OF_LIST_GRID =
.
ENDFORM. "TOP_OF_PAGE

No comments: