Monday, November 5, 2007

Interactive Using REUSE_ALV_HIERSEQ_LIST_DISPLAY

REPORT Z_FI_RP_PROFIT_CENTER_DOCS NO STANDARD PAGE HEADING
MESSAGE-ID Z_MSGCLASS.
************************************************************************
* Program Name : Z_FI_RP_PROFIT_CENTER_DOCS *
* 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 *
* Functional : *
* Developer : *
* Development class : *
* *
************************************************************************


*----------------------------------------------------------------------*
* Request No. Created Date Developer name *
*----------------------------------------------------------------------*
* LD1K900601 15/07/2007
*----------------------------------------------------------------------*

*----------------------------------------------------------------------*
* 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," Sort table
LS_FIELDCAT TYPE SLIS_FIELDCAT_ALV,
LT_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV," Field catalog
GT_SORT TYPE SLIS_T_SORTINFO_ALV.

DATA: t_fieldcatalog TYPE slis_t_fieldcat_alv.
DATA: s_fieldcatalog TYPE slis_fieldcat_alv.

DATA:FCAT TYPE slis_t_fieldcat_alv.
DATA:LAYOUT TYPE slis_layout_alv.
DATA:EVENT TYPE slis_t_event WITH HEADER LINE.
DATA:HEAD TYPE slis_t_listheader WITH HEADER LINE.
DATA:ITEM TYPE slis_t_listheader WITH HEADER LINE.
DATA: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'.

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,
BELNR LIKE BKPF-BELNR,
GJAHR LIKE BKPF-GJAHR,
BLDAT LIKE BKPF-BLDAT,
BUDAT LIKE BKPF-BUDAT,
cpudt like bkpf-cpudt,
USNAM LIKE BKPF-USNAM,
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,
BUDAT LIKE FAGLFLEXA-BUDAT,
RYEAR LIKE FAGLFLEXA-RYEAR,
RBUKRS LIKE FAGLFLEXA-RBUKRS,
PRCTR LIKE FAGLFLEXA-PRCTR,
BUZEI LIKE FAGLFLEXA-BUZEI,
TSL LIKE FAGLFLEXA-TSL,
HSL LIKE FAGLFLEXA-HSL,
DRCRK LIKE FAGLFLEXA-DRCRK,
BSCHL LIKE FAGLFLEXA-BSCHL,
RMVCT LIKE FAGLFLEXA-RMVCT,
RTCUR LIKE FAGLFLEXA-RTCUR,
RCNTR LIKE FAGLFLEXA-RCNTR,
KOKRS LIKE FAGLFLEXA-KOKRS,
SEGMENT LIKE FAGLFLEXA-SEGMENT,
RASSC LIKE FAGLFLEXA-RASSC,
POPER LIKE FAGLFLEXA-POPER,
BSTAT LIKE FAGLFLEXA-BSTAT,
USNAM LIKE FAGLFLEXA-USNAM,
END OF IT_FAGLFLEXA.

*--- Internal table declaration to hold the Posting Keys
DATA: BEGIN OF IT_TBSL OCCURS 0,
BSCHL LIKE TBSL-BSCHL,
KOART LIKE TBSL-KOART,
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,
LIFNR LIKE BSIK-LIFNR,
UMSKZ LIKE BSIK-UMSKZ,
GJAHR LIKE BSIK-GJAHR,
BELNR LIKE BSIK-BELNR,
BUZEI LIKE BSIK-BUZEI,
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,
LIFNR LIKE BSAK-LIFNR,
UMSKZ LIKE BSAK-UMSKZ,
GJAHR LIKE BSAK-GJAHR,
BELNR LIKE BSAK-BELNR,
BUZEI LIKE BSAK-BUZEI,
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,
KUNNR LIKE BSID-KUNNR,
UMSKZ LIKE BSID-UMSKZ,
GJAHR LIKE BSID-GJAHR,
BELNR LIKE BSID-BELNR,
BUZEI LIKE BSID-BUZEI,
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,
KUNNR LIKE BSAD-KUNNR,
UMSKZ LIKE BSAD-UMSKZ,
GJAHR LIKE BSAD-GJAHR,
BELNR LIKE BSAD-BELNR,
BUZEI LIKE BSAD-BUZEI,
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,
HKONT LIKE BSIS-HKONT,
GJAHR LIKE BSIS-GJAHR,
BELNR LIKE BSIS-BELNR,
BUZEI LIKE BSIS-BUZEI,
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,
HKONT LIKE BSAS-HKONT,
GJAHR LIKE BSAS-GJAHR,
BELNR LIKE BSAS-BELNR,
BUZEI LIKE BSAS-BUZEI,
END OF IT_BSAS.

*--- Internal table to hold the Header data
DATA: BEGIN OF IT_HEAD OCCURS 0,
BUKRS LIKE BKPF-BUKRS,
BELNR LIKE BKPF-BELNR,
GJAHR LIKE BKPF-GJAHR,
BLDAT LIKE BKPF-BLDAT,
BUDAT LIKE BKPF-BUDAT,
cpudt like bkpf-cpudt,
USNAM LIKE BKPF-USNAM,
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,
UMSKZ LIKE BSIK-UMSKZ,
KUNNR LIKE BSID-KUNNR,
HKONT LIKE BSIS-HKONT,
*DATA: ACCNT_NUM(10) TYPE C,
ACCNT_NAME LIKE SKAT-TXT50,
END OF IT_ITEM.

*--- Internal table to hold Vendor descriptions
DATA: BEGIN OF IT_LFA1 OCCURS 0,
LIFNR LIKE LFA1-LIFNR,
NAME1 LIKE LFA1-NAME1,
END OF IT_LFA1.

*--- Internal table to hold Customer descriptions
DATA: BEGIN OF IT_KNA1 OCCURS 0,
KUNNR LIKE KNA1-KUNNR,
NAME1 LIKE KNA1-NAME1,
END OF IT_KNA1.

*--- Internal table to hold GL descriptions
DATA: BEGIN OF IT_SKAT OCCURS 0,
SAKNR LIKE SKAT-SAKNR,
TXT50 LIKE SKAT-TXT50,
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,
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 IT_BKPF BY BELNR.
ELSE.
*--- Display message if an invalid Profit Center is entered
MESSAGE S002(Z_MSGCLASS)
WITH 'No data exists with 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 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 or BSAK 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 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 or BSAD 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 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 or BSAS 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 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.

*--- 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.

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.

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.

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.

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.

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.

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.


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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.


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.

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.

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.

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.

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.

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.

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.

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.


DATA: s_layout TYPE slis_layout_alv.

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 Billing Document is entered
MESSAGE E002(Z_MSGCLASS)
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(Z_MSGCLASS)
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(Z_MSGCLASS)
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(Z_MSGCLASS)
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(Z_MSGCLASS)
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(Z_MSGCLASS)
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.

No comments: