Total Pageviews

Monday, December 13, 2010

ABAP Report ALV Block List in SAP Programming




 Description:

This sap programming report with sample code using abap programming language explains you how to use alv block list to append the report.


REPORT ZALVBLOCK .


TYPE-POOLS : SLIS.


TABLES : AFKO,AFPO.


TYPES : BEGIN OF SAFPO ,

AUFNR LIKE AFPO-AUFNR,

POSNR LIKE AFPO-POSNR,

PLNUM LIKE AFPO-PLNUM,

STRMP LIKE AFPO-STRMP,

MATNR LIKE AFPO-MATNR,

PSMNG LIKE AFPO-PSMNG,

MEINS LIKE AFPO-MEINS,

END OF SAFPO.

TYPES : BEGIN OF SAFKO,

AUFNR LIKE AFKO-AUFNR,

END OF SAFKO.

DATA : IAFKO TYPE TABLE OF SAFKO WITH HEADER LINE,

IAFPO TYPE TABLE OF SAFPO WITH HEADER LINE.


DATA : IFIELDCAT1 TYPE SLIS_T_FIELDCAT_ALV,

WFIELDCAT1 TYPE SLIS_FIELDCAT_ALV,

ILAYOUT1 TYPE SLIS_LAYOUT_ALV,

IEVENT1 TYPE SLIS_T_EVENT,

WEVENT1 TYPE SLIS_ALV_EVENT,

IKEYINFO1 TYPE SLIS_KEYINFO_ALV.


DATA : IFIELDCAT2 TYPE SLIS_T_FIELDCAT_ALV,

WFIELDCAT2 TYPE SLIS_FIELDCAT_ALV,

ILAYOUT2 TYPE SLIS_LAYOUT_ALV,

IEVENT2 TYPE SLIS_T_EVENT,

WEVENT2 TYPE SLIS_ALV_EVENT.


SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001.


SELECT-OPTIONS : S_AUFNR FOR AFKO-AUFNR,

S_GLTRP FOR AFKO-GLTRP.


SELECTION-SCREEN END OF BLOCK B1.

START-OF-SELECTION.

CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_INIT'

EXPORTING

I_CALLBACK_PROGRAM = SY-REPID.


I_CALLBACK_PF_STATUS_SET = ' '

I_CALLBACK_USER_COMMAND = ' '

IT_EXCLUDING =

.


PERFORM GET_DATA.

PERFORM BUILD_FIELDCAT.

PERFORM BUILD_LAYOUT.

PERFORM BUILD_EVENT.

PERFORM BUILD_KEYINFO.


PERFORM BUILD_FIELDCAT2.

PERFORM BUILD_LAYOUT2.

PERFORM BUILD_EVENT2.


PERFORM DISPLAY_BLOCK1.


PERFORM DISPLAY_BLOCK2.


CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_DISPLAY'

EXPORTING

I_INTERFACE_CHECK = ' '

IS_PRINT =

I_SCREEN_START_COLUMN = 0

I_SCREEN_START_LINE = 0

I_SCREEN_END_COLUMN = 0

I_SCREEN_END_LINE = 0

IMPORTING

E_EXIT_CAUSED_BY_CALLER =

ES_EXIT_CAUSED_BY_USER =

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.

&---------------------------------------------------------------------

*& Form GET_DATA

&---------------------------------------------------------------------

text

----------------------------------------------------------------------

--> p1 text

<-- p2 text

----------------------------------------------------------------------

FORM GET_DATA .

SELECT AUFNR FROM AFKO INTO CORRESPONDING FIELDS OF TABLE IAFKO

WHERE AUFNR IN S_AUFNR AND GLTRP IN S_GLTRP.


SELECT AUFNR POSNR PLNUM STRMP MATNR PSMNG MEINS FROM AFPO INTO CORRESPONDING FIELDS OF TABLE

IAFPO WHERE AUFNR IN S_AUFNR.

ENDFORM. " GET_DATA

&---------------------------------------------------------------------

*& Form BUILD_FIELDCAT

&---------------------------------------------------------------------

text

----------------------------------------------------------------------

--> p1 text

<-- p2 text

----------------------------------------------------------------------

FORM BUILD_FIELDCAT .

REFRESH : IFIELDCAT1.


*WFIELDCAT1-FIELDNAME = 'AUFNR'.

*WFIELDCAT1-COL_POS = '1'.

*WFIELDCAT1-SELTEXT_L = 'Order No'.

*APPEND WFIELDCAT1 TO IFIELDCAT1.

*CLEAR WFIELDCAT1.

WFIELDCAT1-FIELDNAME = 'GLTRP'.

WFIELDCAT1-COL_POS = '1'.

WFIELDCAT1-SELTEXT_L = 'Basic Finish Time'.

APPEND WFIELDCAT1 TO IFIELDCAT1.

CLEAR WFIELDCAT1.


WFIELDCAT1-FIELDNAME = 'GSTRP'.

WFIELDCAT1-COL_POS = '2'.

WFIELDCAT1-SELTEXT_L = 'Basic Start Time'.

APPEND WFIELDCAT1 TO IFIELDCAT1.

CLEAR WFIELDCAT1.


WFIELDCAT1-FIELDNAME = 'GAMNG'.

WFIELDCAT1-COL_POS = '3'.

WFIELDCAT1-SELTEXT_L = 'Total Order Qty'.

APPEND WFIELDCAT1 TO IFIELDCAT1.

CLEAR WFIELDCAT1.


WFIELDCAT1-FIELDNAME = 'GMEIN'.

WFIELDCAT1-COL_POS = '4'.

WFIELDCAT1-SELTEXT_L = 'UOM'.

APPEND WFIELDCAT1 TO IFIELDCAT1.

CLEAR WFIELDCAT1.


ENDFORM. " BUILD_FIELDCAT

&---------------------------------------------------------------------

*& Form BUILD_LAYOUT

&---------------------------------------------------------------------

text

----------------------------------------------------------------------

--> p1 text

<-- p2 text

----------------------------------------------------------------------

FORM BUILD_LAYOUT .

ILAYOUT1-COLWIDTH_OPTIMIZE = 'X'.

ILAYOUT1-ZEBRA = 'X'.


ENDFORM. " BUILD_LAYOUT

&---------------------------------------------------------------------

*& Form BUILD_EVENT

&---------------------------------------------------------------------

text

----------------------------------------------------------------------

--> p1 text

<-- p2 text

----------------------------------------------------------------------

FORM BUILD_EVENT .


WEVENT1-FORM = 'TOPOFLIST1'.

WEVENT1-NAME = SLIS_EV_TOP_OF_LIST.

APPEND WEVENT1 TO IEVENT1.


ENDFORM. " BUILD_EVENT

&---------------------------------------------------------------------

*& Form DISPLAY_BLOCK1

&---------------------------------------------------------------------

text

----------------------------------------------------------------------

--> p1 text

<-- p2 text

----------------------------------------------------------------------

FORM DISPLAY_BLOCK1 .

*CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_HS_APPEND'

EXPORTING

IS_LAYOUT = ILAYOUT1

IT_FIELDCAT = IFIELDCAT2

IS_KEYINFO = IKEYINFO1

I_HEADER_TABNAME = 'IAFKO'

I_ITEM_TABNAME = 'IAFPO'

IT_EVENTS = IEVENT1

IT_SORT =

I_TEXT = ' '

TABLES

T_OUTTAB_HEADER = IAFKO

T_OUTTAB_ITEM = IAFPO

EXCEPTIONS

PROGRAM_ERROR = 1

MAXIMUM_OF_APPENDS_REACHED = 2

OTHERS = 3

.

*IF SY-SUBRC 0.

MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

*ENDIF.

*

CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_APPEND'

EXPORTING

IS_LAYOUT = ILAYOUT1

IT_FIELDCAT = IFIELDCAT1

I_TABNAME = 'IAFKO'

IT_EVENTS = IEVENT1

IT_SORT =

I_TEXT = ' '

TABLES

T_OUTTAB = IAFKO

EXCEPTIONS

PROGRAM_ERROR = 1

MAXIMUM_OF_APPENDS_REACHED = 2

OTHERS = 3

.

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_BLOCK1


FORM TOPOFLIST1.


WRITE :/10 'TABLE AFKO CONTENTS'.

WRITE :/(30) SY-ULINE.


ENDFORM.

&---------------------------------------------------------------------

*& Form BUILD_FIELDCAT2

&---------------------------------------------------------------------

text

----------------------------------------------------------------------

--> p1 text

<-- p2 text

----------------------------------------------------------------------

FORM BUILD_FIELDCAT2 .

REFRESH : IFIELDCAT2.

WFIELDCAT2-FIELDNAME = 'AUFNR'.

WFIELDCAT2-COL_POS = '1'.

WFIELDCAT2-SELTEXT_L = 'Order No'.

APPEND WFIELDCAT2 TO IFIELDCAT2.

CLEAR WFIELDCAT2.


WFIELDCAT2-FIELDNAME = 'POSNR'.

WFIELDCAT2-COL_POS = '2'.

WFIELDCAT2-SELTEXT_L = 'Order Item No'.

APPEND WFIELDCAT2 TO IFIELDCAT2.

CLEAR WFIELDCAT2.


WFIELDCAT2-FIELDNAME = 'PLNUM'.

WFIELDCAT2-COL_POS = '3'.

WFIELDCAT2-SELTEXT_L = 'Planned Order No'.

APPEND WFIELDCAT2 TO IFIELDCAT2.

CLEAR WFIELDCAT2.


WFIELDCAT2-FIELDNAME = 'STRMP'.

WFIELDCAT2-COL_POS = '4'.

WFIELDCAT2-SELTEXT_L = 'Strt Dt Plnd ordr No'.

APPEND WFIELDCAT2 TO IFIELDCAT2.

CLEAR WFIELDCAT2.


WFIELDCAT2-FIELDNAME = 'MATNR'.

WFIELDCAT2-COL_POS = '5'.

WFIELDCAT2-SELTEXT_L = 'Material No'.

APPEND WFIELDCAT2 TO IFIELDCAT2.

CLEAR WFIELDCAT2.


WFIELDCAT2-FIELDNAME = 'PSMNG'.

WFIELDCAT2-COL_POS = '6'.

WFIELDCAT2-SELTEXT_L = 'Pland Ordr Qty'.

APPEND WFIELDCAT2 TO IFIELDCAT2.

CLEAR WFIELDCAT2.


WFIELDCAT2-FIELDNAME = 'MEINS'.

WFIELDCAT2-COL_POS = '7'.

WFIELDCAT2-SELTEXT_L = 'UOM'.

APPEND WFIELDCAT2 TO IFIELDCAT2.

CLEAR WFIELDCAT2.

ENDFORM. " BUILD_FIELDCAT2

&---------------------------------------------------------------------

*& Form BUILD_LAYOUT2

&---------------------------------------------------------------------

text

----------------------------------------------------------------------

--> p1 text

<-- p2 text

----------------------------------------------------------------------

FORM BUILD_LAYOUT2 .

ILAYOUT2-COLWIDTH_OPTIMIZE = 'X'.

ILAYOUT2-ZEBRA = 'X'.

ENDFORM. " BUILD_LAYOUT2

&---------------------------------------------------------------------

*& Form BUILD_EVENT2

&---------------------------------------------------------------------

text

----------------------------------------------------------------------

--> p1 text

<-- p2 text

----------------------------------------------------------------------

FORM BUILD_EVENT2 .


WEVENT2-FORM = 'TOPOFLIST2'.

WEVENT2-NAME = SLIS_EV_TOP_OF_LIST.

APPEND WEVENT2 TO IEVENT2.

CLEAR WEVENT2.


ENDFORM. " BUILD_EVENT2

&---------------------------------------------------------------------

*& Form DISPLAY_BLOCK2

&---------------------------------------------------------------------

text

----------------------------------------------------------------------

--> p1 text

<-- p2 text

----------------------------------------------------------------------

FORM DISPLAY_BLOCK2 .

CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_APPEND'

EXPORTING

IS_LAYOUT = ILAYOUT2

IT_FIELDCAT = IFIELDCAT2

I_TABNAME = 'IAFPO'

IT_EVENTS = IEVENT2

IT_SORT =

I_TEXT = ' '

TABLES

T_OUTTAB = IAFPO

EXCEPTIONS

PROGRAM_ERROR = 1

MAXIMUM_OF_APPENDS_REACHED = 2

OTHERS = 3

.

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_BLOCK2


FORM TOPOFLIST2.

WRITE : /10 'TABLE AFPO CONTENTS'.

WRITE :/(35) SY-ULINE.

ENDFORM.

&---------------------------------------------------------------------

*& Form BUILD_KEYINFO

&---------------------------------------------------------------------

text

----------------------------------------------------------------------

--> p1 text

<-- p2 text

----------------------------------------------------------------------

FORM BUILD_KEYINFO .

IKEYINFO1-HEADER01 = 'AUFNR'.

IKEYINFO1-ITEM01 = 'AUFNR'.

ENDFORM. " BUILD_KEYINFO



Read more: http://www.abapprogramming.net/2010/09/abap-report-alv-block-list-in-sap.html#ixzz180iOedjv

Friday, December 10, 2010

ABAP Programming Report Stock Requirement List


This ABAP report gives you a sneak peak about about the SAP Report which can give you different options to extract data from the source server about stock requiremnt of a comapany.This report provides a real-time display of the inventory on hand and the requirements for a specific material. All recommendations and exception messages from MPS/MRP are as current as the most recent planning-run.

Starting with the current date, this report displays the inventory on hand, followed by one line for each element of supply and demand, any related MPS/MRP exception messages, and the projected balance. The report offers drilldown capabilities for additional detail to enable a quick assessment of the inventory position.

You must enter the Material number and Plant before running this report. If you want to review a product group instead of a specific material, you will need to enter the Product group on the first screen.

From the output of this report, you can:

  1. Immediately convert MPS/MRP planned orders into production orders
  2. Immediately convert purchase requisitions into purchase orders or scheduling agreements
  3. Start a pegging report for any element to determine the source of demand
  4. View lower-level dependent requirements and call up an order report
  5. Select various menu options to review detailed planning parameters
  6. Display available-to-promise calculations
  7. Invoke capacity planning functions from the menu
  8. Compare the last MRP report to assess changes in the planning situation
This program can be used to convert orders and invoke capacity planning. Thus, the system administrator may want to limit user authorization to this program.

From this report, you can select the following functions:

Print the displayed stock/requirements results (List → Print).
Invoke the rescheduling function (List → Rescheduling).
Calculate ATP (List → Calculate ATP).
Display additional detail:
Stock statistics such as receipts, issues, quantities in restricted stock, at vendors, in transit, QI, and returns (Goto → Stock statistics)
Sales statistics such as quantity of a material on sales orders, quotes, and contracts (Goto → Sales statistics)
Planning data drawn from the material master, such as the MRP controller, MRP group, MRP type, reorder point and lot sizing data, availability check, special procurement type, and a recap of all receipts and issue by source/type (Goto → Material overview)

Display additional data such as a second exception message, order dates, quantity, strategy (Edit → Additional data; an icon is also available or you can simply double-click). From the popup window, it is possible to convert the item or invoke pegging reports; this can also be done directly from various Environment menu options.

To access the first screen for this report, choose

Logistics → Production → MRP → Evaluations → Stock/reqmts list.
1. Enter the material (for example, 100-100) or product group in Material.
2. Enter the plant associated with the material (for example, 3000) or product group in Plant.
3. If you entered a product group in step 1 above, select Product group.
4. Choose Enter.

The system displays the following:

A Date of receipt/requirement and associated type of supply or demand
B Material number, order number, etc.
C MRP exception message D Receipt or requirement quantity
E Available quantity

The width of columns may be adjusted by dragging the column divider.


Pricing Routines using VOFM transaction to change the Net Price in Billing to Basic Price


FORM FRM_KONDI_WERT_901.
*{ INSERT SMDK900281 1
**--- Routine for ZGPR
*---------------------------------------------------------------------*
* CONSTANTS DECLARATION
*---------------------------------------------------------------------*

CONSTANTS: C_ZGRP(4) VALUE 'ZGRP',
C_PR00(4) VALUE 'PR00',
C_JEXP(4) VALUE 'JEXP',
C_JEAP(4) VALUE 'JEAP',
C_JECE(4) VALUE 'JECE',
C_JESC(4) VALUE 'JESC',
C_ZS01(4) VALUE 'ZS01'.
*---------------------------------------------------------------------*
* DATA DECLARATION
*---------------------------------------------------------------------*
DATA: lv_ZGRP_KWERT like konv-kwert, "Condition Value of NET RATE
lv_JEXP_KWERT like konv-kwert, "Condition Value of A/R BED%
lv_JEAP_KWERT like konv-kwert, "Condition Value of A/R AED%
lv_JECE_KWERT like konv-kwert, "Condition Value of ECSS
lv_JESC_KWERT like konv-kwert, "Condition Value of SECSS
lv_PR00_KWERT like KONV-kwert, "Condition Value of Gross Price
lv_PR00_KBETR like komv-kbetr, "Amount for the condition PR00
lv_ZS01_KWERT like konv-kwert, "Condition Value of Cash Discount
LV_SUM_KWERT(16) type p decimals 2,
LV_XKWERT(16) TYPE P DECIMALS 2,
LV_RED_KWERT like konv-kwert,
LV_KPEIN(13) type C,
LV_CVAL_KWERT like komv-kwert,
lv_afd_KWERT like komv-kwert.

DATA: LTXKOMV LIKE XKOMV OCCURS 0 WITH HEADER LINE.

IF NOT XKOMV[] IS INITIAL.
LTXKOMV[] = XKOMV[].
clear : XKWERT , YKBETR, LV_CVAL_KWERT,lv_PR00_KBETR.
loop at ltxkomv.
CASE LTXKOMV-KSCHL.

WHEN C_ZGRP.
read table LTXKOMV with key kschl = C_ZGRP.
if sy-subrc = 0.
lv_ZGRP_KWERT = LTXKOMV-kwert.
endif.

WHEN C_ZS01.
read table LTXKOMV with key kschl = C_ZS01.
if sy-subrc = 0.
lv_ZS01_KWERT = LTXKOMV-kwert.
endif.

WHEN C_JEXP.
read table LTXKOMV with key kschl = C_JEXP.
if sy-subrc = 0.
lv_JEXP_KWERT = LTXKOMV-kwert.
endif.

WHEN C_JEAP.
read table LTXKOMV with key kschl = C_JEAP.
if sy-subrc = 0.
lv_JEAP_KWERT = LTXKOMV-kwert.
endif.

WHEN C_JECE.
read table LTXKOMV with key kschl = C_JECE.
if sy-subrc = 0.
lv_JECE_KWERT = LTXKOMV-kwert.
endif.

WHEN C_JESC.
read table LTXKOMV with key kschl = C_JESC.
if sy-subrc = 0.
lv_JESC_KWERT = LTXKOMV-kwert.
endif.

ENDCASE.

*--remove the discount amt from zgpr value
lv_afd_KWERT = lv_ZGRP_KWERT.
*--- Summ all the Excise Amounts
LV_SUM_KWERT = lv_JEXP_KWERT + lv_JEAP_KWERT + lv_JECE_KWERT + lv_JESC_KWERT.
*--- Subtract from the netamount without Discount
LV_RED_KWERT = lv_afd_KWERT - LV_SUM_KWERT.
LV_CVAL_KWERT = LV_RED_KWERT.

*--- For getting the Quantity
LV_KPEIN = xmenge.
*--- Call function Module to reamove the Decimal Zeros
CALL FUNCTION 'FTR_CORR_SWIFT_DELETE_ENDZERO'
CHANGING
C_VALUE = LV_KPEIN.
*--- Check for the availability of Quantity
if lv_kpein <> 0.
lv_PR00_KBETR = LV_CVAL_KWERT / LV_KPEIN.
endif.

endloop.
endif.

if not lv_SUM_KWERT is initial.

XKWERT = LV_CVAL_KWERT.

*---- Read table Conditions for the Condition Type Gross Price
read table ltxkomv with key kschl = C_PR00.
if sy-subrc = 0.
YKBETR = lv_PR00_KBETR.
ltxkomv-kbetr = YKBETR.
else.
YKBETR = lv_PR00_KBETR.
ltxkomv-kbetr = YKBETR.
endif.
*--- Populate the YKBETR value to get the Amount for the Condition PR00
xkomv-kbetr = YKBETR.
else.
XKWERT = LV_CVAL_KWERT.
endif.

*} INSERT
ENDFORM.