Google Search - Blog...........

ABAP - Sample Program To Display Funds Assigned To The Funds Center For The Year.

Check the report given below:
Report created for displaying the Funds assigned to the funds center for the year.
REPORT ZFI_ASSIGNED_FUND.
TABLES: FMIT,FMCIT.
TYPE-POOLS: SLIS.
*ALV data declarations
DATA: FIELDCATALOG TYPE SLIS_T_FIELDCAT_ALV WITH HEADER LINE, FIELDCATALOG1 TYPE SLIS_T_FIELDCAT_ALV WITH HEADER LINE, GD_TAB_GROUP TYPE SLIS_T_SP_GROUP_ALV,
GD_LAYOUT TYPE SLIS_LAYOUT_ALV,
GD_REPID LIKE SY-REPID.

SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001.
SELECT-OPTIONS: RFISTL FOR FMIT-RFISTL,
FIKRS FOR FMIT-FIKRS,
RYEAR FOR FMIT-RYEAR.SELECTION-SCREEN END OF BLOCK B1.
DATA: BEGIN OF IT_FMIT OCCURS 0,
RYEAR LIKE FMIT-RYEAR,
FIKRS LIKE FMIT-FIKRS,
RFISTL LIKE ZREV_BUDGET-KOSTL,
RFIPEX LIKE ZREV_BUDGET-KSTAR,
TSL01 LIKE FMIT-TSL01,
TSL02 LIKE FMIT-TSL02,
TSL03 LIKE FMIT-TSL03,
TSL04 LIKE FMIT-TSL04,
TSL05 LIKE FMIT-TSL05,
TSL06 LIKE FMIT-TSL06,
TSL07 LIKE FMIT-TSL07,
TSL08 LIKE FMIT-TSL08,
TSL09 LIKE FMIT-TSL09,
TSL10 LIKE FMIT-TSL10,
TSL11 LIKE FMIT-TSL11,
TSL12 LIKE FMIT-TSL12,
TSL13 LIKE FMIT-TSL13,
TSL14 LIKE FMIT-TSL14,
TSL15 LIKE FMIT-TSL15,
TSL16 LIKE FMIT-TSL16,
END OF IT_FMIT.

DATA: BEGIN OF IT_FMIT1 OCCURS 0,
RYEAR LIKE FMIT-RYEAR,
FIKRS LIKE FMIT-FIKRS,
RFISTL LIKE ZREV_BUDGET-KOSTL,
RFIPEX LIKE ZREV_BUDGET-KSTAR,
TOTAL LIKE FMIT-TSL01,
END OF IT_FMIT1.

DATA : BEGIN OF IT_BUDGET OCCURS 0,
GJAHR LIKE ZREV_BUDGET-GJAHR,
KOSTL LIKE ZREV_BUDGET-KOSTL, " COST CENTER
KSTAR LIKE ZREV_BUDGET-KSTAR,
APR_B LIKE ZREV_BUDGET-APR_B,
MAY_B LIKE ZREV_BUDGET-MAY_B,
JUN_B LIKE ZREV_BUDGET-JUN_B,
JUL_B LIKE ZREV_BUDGET-JUL_B,
AUG_B LIKE ZREV_BUDGET-AUG_B,
SEP_B LIKE ZREV_BUDGET-SEP_B,
OCT_B LIKE ZREV_BUDGET-OCT_B,
NOV_B LIKE ZREV_BUDGET-NOV_B,
DEC_B LIKE ZREV_BUDGET-DEC_B,
JAN_B LIKE ZREV_BUDGET-JAN_B,
FEB_B LIKE ZREV_BUDGET-FEB_B,
MAR_B LIKE ZREV_BUDGET-MAR_B,
END OF IT_BUDGET.

DATA : BEGIN OF IT_BUDGET1 OCCURS 0,
GJAHR LIKE ZREV_BUDGET-GJAHR,
KOSTL LIKE ZREV_BUDGET-KOSTL, " COST CENTER
KSTAR LIKE ZREV_BUDGET-KSTAR,
TOTAL1 LIKE FMIT-TSL01,
END OF IT_BUDGET1.

DATA: BEGIN OF IT_FINAL OCCURS 0,
FIKRS LIKE FMIT-FIKRS,
RFISTL LIKE FMIT-RFISTL,
RFIPEX LIKE FMIT-RFIPEX,
TEXT LIKE FMCIT-TEXT1,
ALLOC LIKE FMIT-TSL16,
USED LIKE FMIT-TSL16,
REMAIN LIKE FMIT-TSL16,
END OF IT_FINAL

START-OF-SELECTION.

PERFORM GET_DATA.
PERFORM PROCESS_DATA.
PERFORM BUILD_FIELDCATALOG.
PERFORM BUILD_LAYOUT.
PERFORM DISPLAY_ALV_REPORT.
*&---------------------------------------------------------------------
**& Form GET_DATA
*&---------------------------------------------------------------------
** text
*----------------------------------------------------------------------*
* --> p1 text* <-- p2 text *----------------------------------------------------------------------* FORM GET_DATA . SELECT RYEAR RFISTL RFIPEX TSL01 TSL02 TSL03 TSL04 TSL05 TSL06 TSL07 TSL08 TSL09 TSL10 TSL11 TSL12 TSL13 TSL14 TSL15 TSL16 INTO TABLE IT_FMIT FROM FMIT WHERE RYEAR IN RYEAR AND FIKRS IN FIKRS AND RFISTL IN RFISTL. LOOP AT IT_FMIT. MOVE-CORRESPONDING IT_FMIT TO IT_FMIT1. IT_FMIT1-TOTAL = IT_FMIT-TSL01 + IT_FMIT-TSL02 + IT_FMIT-TSL03 + IT_FMIT-TSL04 + IT_FMIT-TSL05 + IT_FMIT-TSL06 + IT_FMIT-TSL07 + IT_FMIT-TSL08 + IT_FMIT-TSL09 + IT_FMIT-TSL10 + IT_FMIT-TSL11 + IT_FMIT-TSL12 + IT_FMIT-TSL13. IT_FMIT1-TOTAL = IT_FMIT1-TOTAL * -1 . COLLECT IT_FMIT1. ENDLOOP. LOOP AT IT_FMIT1. CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT' EXPORTING INPUT = IT_FMIT1-RFISTL IMPORTING OUTPUT = IT_FMIT1-RFISTL. CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT' EXPORTING INPUT = IT_FMIT1-RFIPEX IMPORTING OUTPUT = IT_FMIT1-RFIPEX. MODIFY IT_FMIT1. ENDLOOP. SELECT GJAHR KOSTL KSTAR APR_B MAY_B JUN_B JUL_B AUG_B SEP_B OCT_B NOV_B DEC_B JAN_B FEB_B MAR_B INTO TABLE IT_BUDGET FROM ZREV_BUDGET FOR ALL ENTRIES IN IT_FMIT1 WHERE GJAHR IN RYEAR AND KOSTL EQ IT_FMIT1-RFISTL AND KSTAR EQ IT_FMIT1-RFIPEX. LOOP AT IT_BUDGET. MOVE-CORRESPONDING IT_BUDGET TO IT_BUDGET1. IT_BUDGET1-TOTAL1 = IT_BUDGET-APR_B + IT_BUDGET-MAY_B + IT_BUDGET-JUN_B + IT_BUDGET-JUL_B + IT_BUDGET-AUG_+ IT_BUDGET-SEP_B + IT_BUDGET-OCT_B + IT_BUDGET-NOV_B + IT_BUDGET-DEC_B + IT_BUDGET-JAN_B T_BUDGET-FEB_B + IT_BUDGET-MAR_B. IT_BUDGET1-TOTAL1 = IT_BUDGET1-TOTAL1 * 100000. COLLECT IT_BUDGET1. ENDLOOP. ENDFORM. " GET_DATA *&--------------------------------------------------------------------- * *& Form PROCESS_DATA *&--------------------------------------------------------------------- * * text*---------------------------------------------------------------------- ** --> p1 text* <-- p2 text *----------------------------------------------------------------------* FORM PROCESS_DATA . LOOP AT IT_FMIT1. IT_FINAL-FIKRS = IT_FMIT1-FIKRS. IT_FINAL-RFISTL = IT_FMIT1-RFISTL. IT_FINAL-RFIPEX = IT_FMIT1-RFIPEX. IT_FINAL-USED = IT_FMIT1-TOTAL. READ TABLE IT_BUDGET1 WITH KEY KOSTL = IT_FMIT1-RFISTL KSTAR = IT_FMIT1-RFIPEX. IF SY-SUBRC EQ 0. IT_FINAL-ALLOC = IT_BUDGET1-TOTAL1. ENDIF. CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING INPUT = IT_FMIT1-RFIPEX IMPORTING OUTPUT = IT_FMIT1-RFIPEX. SELECT SINGLE TEXT1 INTO IT_FINAL-TEXT FROM FMCIT WHERE SPRAS EQ 'EN' AND FIPEX EQ IT_FMIT1-RFIPEX. IT_FINAL-REMAIN = IT_FINAL-ALLOC - IT_FINAL-USED. APPEND IT_FINAL. CLEAR IT_FINAL. ENDLOOP. ENDFORM. " PROCESS_DATA *&--------------------------------------------------------------------- * *& Form BUILD_FIELDCATALOG *&---------------------------------------------------------------------* * text*---------------------------------------------------------------------- * * --> p1 text* <-- p2 text *----------------------------------------------------------------------* FORM BUILD_FIELDCATALOG . FIELDCATALOG-FIELDNAME = 'FIKRS'. FIELDCATALOG-SELTEXT_M = 'Functional Mng Area'. APPEND FIELDCATALOG TO FIELDCATALOG. CLEAR FIELDCATALOG. FIELDCATALOG-FIELDNAME = 'RFISTL'. FIELDCATALOG-SELTEXT_M = 'Fund Center'. APPEND FIELDCATALOG TO FIELDCATALOG. CLEAR FIELDCATALOG. FIELDCATALOG-FIELDNAME = 'RFIPEX'. FIELDCATALOG-SELTEXT_M = 'Commitment Item'. APPEND FIELDCATALOG TO FIELDCATALOG. CLEAR FIELDCATALOG. FIELDCATALOG-FIELDNAME = 'TEXT'. FIELDCATALOG-SELTEXT_M = 'Commitment Item Text'. APPEND FIELDCATALOG TO FIELDCATALOG. CLEAR FIELDCATALOG. FIELDCATALOG-FIELDNAME = 'ALLOC'. FIELDCATALOG-SELTEXT_M = 'Allocated Budget'. APPEND FIELDCATALOG TO FIELDCATALOG. CLEAR FIELDCATALOG. FIELDCATALOG-FIELDNAME = 'USED'. FIELDCATALOG-SELTEXT_M = 'Used Budget'. APPEND FIELDCATALOG TO FIELDCATALOG. CLEAR FIELDCATALOG. FIELDCATALOG-FIELDNAME = 'REMAIN'. FIELDCATALOG-SELTEXT_M = 'Remaining Budget'. APPEND FIELDCATALOG TO FIELDCATALOG. CLEAR FIELDCATALOG. ENDFORM. " BUILD_FIELDCATALOG *&---------------------------------------------------------------------* *& Form BUILD_LAYOUT *&---------------------------------------------------------------------* * text*---------------------------------------------------------------------- * * --> p1 text* <-- p2 text *----------------------------------------------------------------------* FORM BUILD_LAYOUT . GD_LAYOUT-NO_INPUT = 'X'. GD_LAYOUT-COLWIDTH_OPTIMIZE = 'X'. ENDFORM. " BUILD_LAYOUT *&---------------------------------------------------------------------* *& Form DISPLAY_ALV_REPORT *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * --> p1 text* <-- p2 text
*----------------------------------------------------------------------
FORM DISPLAY_ALV_REPORT .
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM = GD_REPID
IS_LAYOUT = GD_LAYOUT
IT_FIELDCAT = FIELDCATALOG[]
I_SAVE = 'X'
TABLES
T_OUTTAB = IT_FINAL
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_REPORT

No comments:

Post a Comment