Subscribe

RSS Feed (xml)

Powered By

Skin Design:
Free Blogger Skins

Powered by Blogger

Saturday, March 1, 2008

ALV Example: Contract Renewal Details

*----------------------------------------------------------------------*
* Contract Renewal Details *
*----------------------------------------------------------------------*

************************************************************************
* Description: The contract details of the customers in a particular *
* sales area are displayed. This report is run to view the *
* * contract details existing *
* Author : M.Praveen kumar *
* Date : 18 March 2005 *
* *
*----------------------------------------------------------------------*
* Change No | Date | Details | Req No *
*----------------------------------------------------------------------*
* CR-102 | 18/03/05 | Original Version | PRDK90011*
* | | | *
************************************************************************

REPORT zadi_sd_contractalv NO STANDARD PAGE HEADING
LINE-COUNT 45(2) LINE-SIZE 130
MESSAGE-ID ymessage.

**********************Type Pool Declaration for ALV********************

TYPE-POOLS: slis.

********************Table Declaration**********************************

TABLES: vbak,vbfa,veda.

*********************Declaring Data Objects****************************

DATA: BEGIN OF lt_sd_c1 OCCURS 0,
vbeln LIKE vbak-vbeln, "Sales Document Number
vbelv LIKE vbfa-vbelv, "Preceding Sales and Distribution Doc
kunnr LIKE vbak-kunnr, "Customer Number
END OF lt_sd_c1.

*data: Lt_Sd_C2 like veda occurs 0 with header line.

DATA: gt_fieldcat TYPE slis_t_fieldcat_alv, "ALV Catalog Table
gs_fieldcat TYPE slis_fieldcat_alv. "ALV Catalog Structure


DATA: BEGIN OF lt_sd_c2 OCCURS 0,
vbeln LIKE veda-vbeln, "Sales Document Number
vlaufz LIKE veda-vlaufz, "Validity Period of Contract
vuntdat LIKE veda-vuntdat, "Date on which Contract was Signed
vbegdat LIKE veda-vbegdat, "Contract Start Date
venddat LIKE veda-venddat, "Contract End Date
END OF lt_sd_c2.

*****************************Selection Screen***************************


SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-101.
SELECT-OPTIONS: s_vkorg FOR vbak-vkorg OBLIGATORY,"Sales organization.
s_vtweg FOR vbak-vtweg, "Distribution channel.
s_spart FOR vbak-spart, "Division.
s_kunnr FOR vbak-kunnr, "Customer number
p_dat FOR sy-datum."Date=current date
SELECTION-SCREEN END OF BLOCK b1.

SELECTION-SCREEN BEGIN OF BLOCK c1 WITH FRAME TITLE text-100.
PARAMETERS list RADIOBUTTON GROUP radi.
PARAMETERS alv RADIOBUTTON GROUP radi.
SELECTION-SCREEN END OF BLOCK c1.


*****************Validation of Selection Screen Fields******************

AT SELECTION-SCREEN.

SELECT SINGLE vkorg FROM tvko INTO vbak-vkorg WHERE vkorg IN s_vkorg.
IF sy-subrc <> 0.
MESSAGE e002.
ENDIF.


SELECT SINGLE vtweg FROM tvkov INTO vbak-vtweg WHERE vtweg IN s_vtweg.
IF sy-subrc <> 0.
MESSAGE e004.
ENDIF.

SELECT SINGLE spart FROM tspa INTO vbak-spart WHERE spart IN s_spart.
IF sy-subrc <> 0.
MESSAGE e006.
ENDIF.


SELECT SINGLE kunnr FROM kna1 INTO vbak-kunnr WHERE kunnr IN s_kunnr.
IF sy-subrc <> 0.
MESSAGE e007.
ENDIF.

*********************************Data Fetching**************************

START-OF-SELECTION.

SELECT a~vbeln a~kunnr b~vbelv
FROM vbak AS a INNER JOIN vbfa AS b
ON a~vbeln = b~vbeln
INTO CORRESPONDING FIELDS OF TABLE lt_sd_c1
WHERE vkorg IN s_vkorg
AND vtweg IN s_vtweg
AND spart IN s_spart
AND kunnr IN s_kunnr.

IF NOT lt_sd_c1[] IS INITIAL.

SELECT vbeln vlaufz vuntdat vbegdat venddat
FROM veda INTO CORRESPONDING FIELDS OF TABLE lt_sd_c2
FOR ALL ENTRIES IN lt_sd_c1
WHERE vbeln = lt_sd_c1-vbelv
AND venddat = p_dat.

ELSE.

MESSAGE i005.
EXIT.

ENDIF.


END-OF-SELECTION.

*******************************Display of Data**************************

IF list = 'X'.

LOOP AT lt_sd_c2.

WRITE:/0 sy-vline,
lt_sd_c2-vbeln UNDER 'SALES DOCUMENT', 16 sy-vline,
lt_sd_c2-vuntdat UNDER 'CONTRACT SINGED DATE', 42 sy-vline,
lt_sd_c2-vbegdat UNDER 'CONTRACT START DATE', 65 sy-vline,
lt_sd_c2-venddat UNDER 'CONTRACT END DATE' COLOR 6, 100 sy-vline,
lt_sd_c2-vlaufz UNDER 'VALIDITY PERIOD OF CONTRACT', 130 sy-vline.

ENDLOOP.

ULINE.

ELSE.

**************Calling a subroutine for Field display in ALV*************

PERFORM built_field_catalog.

*************Calling fucntion module for ALV****************************

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_background_id = 'ALV_BACKGROUND'
i_grid_title = 'Contract Details'
* i_structure_name = 'veda'
it_fieldcat = gt_fieldcat[]
TABLES
t_outtab = lt_sd_c2.

ENDIF.


**************************Header for the page***************************

TOP-OF-PAGE.

WRITE:/ 'CREATED BY : ', sy-uname,
102 'CREATED ON :', sy-datum,
/1(130) sy-uline .

WRITE:/ sy-vline, 50 ' CONTRACT DETAILS ' COLOR 5,
111 'Page No:',
sy-pagno,
130 sy-vline.

ULINE.

WRITE:/0 sy-vline,
2 'SALES DOCUMENT' COLOR 3,16 sy-vline,
20 'CONTRACT SIGNED DATE' COLOR 3, 42 sy-vline,
45 'CONTRACT START DATE' COLOR 3, 65 sy-vline,
75 'CONTRACT END DATE' COLOR 3, 100 sy-vline,
102 'VALIDITY PERIOD OF CONTRACT' COLOR 3, 130 sy-vline.

ULINE.



*&---------------------------------------------------------------------*
*& Form built_field_catalog
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*

FORM built_field_catalog.

gs_fieldcat-col_pos = '1'.
gs_fieldcat-fieldname = 'VBELN'.
gs_fieldcat-outputlen = 30.
gs_fieldcat-seltext_l = 'SALES DOCUMENT NUMBER'.
APPEND gs_fieldcat TO gt_fieldcat.

gs_fieldcat-col_pos = '2'.
gs_fieldcat-fieldname = 'VLAUFZ'.
gs_fieldcat-outputlen = 9.
gs_fieldcat-seltext_l = 'VALIDITY'.
APPEND gs_fieldcat TO gt_fieldcat.

gs_fieldcat-col_pos = '3'.
gs_fieldcat-fieldname = 'VUNTDAT'.
gs_fieldcat-outputlen = 12.
gs_fieldcat-seltext_l = 'SIGNED DATE'.
APPEND gs_fieldcat TO gt_fieldcat.

gs_fieldcat-col_pos = '4'.
gs_fieldcat-fieldname = 'VBEGDAT'.
gs_fieldcat-outputlen = 12.
gs_fieldcat-seltext_l = 'START DATE'.
APPEND gs_fieldcat TO gt_fieldcat.

gs_fieldcat-col_pos = '5'.
gs_fieldcat-fieldname = 'VENDDAT'.
gs_fieldcat-outputlen = 12.
gs_fieldcat-seltext_l = 'END DATE'.
APPEND gs_fieldcat TO gt_fieldcat.

ENDFORM.

An ALV Related Simple Example Code

[TABLE NAME] = USE EXISTING TABLE.

**************start of code*********
REPORT ZNEW .
*

* Data to be displayed

DATA: GT_SFLIGHT TYPE TABLE OF [TABLE NAME].

*---------------------------------------------------------------------*

* Selection

SELECT * FROM [TABLE NAME] INTO TABLE GT_SFLIGHT.

* Call ABAP List Viewer (ALV)

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

I_STRUCTURE_NAME = [TABLE NAME]

TABLES

T_OUTTAB = GT_SFLIGHT.

*****************end of code*************

ALV Sample Code

Question : Subject: ALV Sample Code

Hi friends,

I would like to set up list through ALV grid control.

Can any body send me simple sample program.

Thanks in advance.

Reply : Subject: ALV Sample Code

Hello,

here I am sending you sample program for alv

========================================

Report ZHELLO.

Tables:
MAKT,
MARA.

data: begin of itab_alv1 occurs 10,
MAKTX like MAKT-MAKTX ,
MATFI like MARA-MATFI ,
MATNR like MARA-MATNR ,
MFRPN like MARA-MFRPN ,
END OF ITAB_ALV1.

type-pools: slis.

data: afield type slis_fieldcat_alv.

DATA: fieldcat type slis_t_fieldcat_alv.

clear afield.

afield-col_pos = 1 .
afield-fieldname = 'MAKTX'.
afield-seltext = ''.
append afield to fieldcat.
afield-col_pos = 2 .
afield-fieldname = 'MATFI'.
afield-seltext = ''.
append afield to fieldcat.

select * from mara.
select * from makt where
matnr = mara-matnr.
itab_alv1-matnr = mara-matnr.
itab_alv1-maktx = makt-maktx.
append itab_alv1.
endselect.
endselect.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
IT_FIELDCAT = fieldcat
Tables
t_outtab = itab_alv1.

Reply : Subject: ALV Sample Code

ALV Sample ABAP Code - Group

Question : Subject : ALV Sample ABAP Code - Group

Dear Abapers,

Can anybody send me code for ALV report where group has been used.

Thanks in Advance.

Warm Regards,

Reply : Subject : ALV Sample Code - Group

I will be sending some code about ALV.

It may help you out.

Regards

======================================

REPORT ALV.

* REPORT Z_LIST_MATERIALS.

TYPE-POOLS: SLIS.
TABLES:MARC, MARD, VBAP, LIPS, EKPO, VBFA, EKBE, MARM, VBBE, MARA, MBEW.

SELECTION-SCREEN BEGIN OF BLOCK SEL WITH FRAME TITLE TEXT-001.
SELECT-OPTIONS: S_WERKS FOR MARC-WERKS, " Plant
S_MATNR FOR MARC-MATNR, " Material
S_MTART FOR MARA-MTART. " Material Type
SELECTION-SCREEN END OF BLOCK SEL.

PARAMETERS: P_VARI LIKE DISvariant-VARIANT. " ALV Variant

CONSTANTS: FORMNAME_TOP_OF_PAGE TYPE SLIS_FORMNAME VALUE 'TOP_OF_PAGE'.

DATA: BEGIN OF INV OCCURS 100,
WERKS LIKE MARD-WERKS, " Plant
MATNR LIKE MARD-MATNR, " Material
MTART LIKE MARA-MTART, " Material Type
STPRS LIKE MBEW-STPRS, " Standard Price
AVAIL LIKE MARD-LABST, " Available
LABST LIKE MARD-LABST, " Unrestricted use
INSME LIKE MARD-INSME, " Quality Inspection
RETME LIKE MARD-RETME, " Returns
TRANS LIKE MARC-UMLMC, " Stock in transit (calculated)
UMLMC LIKE MARC-UMLMC, " Stock Transfer (plant)
UMLME LIKE MARD-UMLME, " Transfer (SLoc)
WESBS LIKE EKBE-WESBS, " GR Blocked Stock
TRAME LIKE MARC-TRAME, " Stock in transit
SPEME LIKE MARD-SPEME, " Blocked
KWMENG LIKE VBAP-KWMENG, " Sales orders
LFIMG LIKE LIPS-LFIMG, " Scheduled for Delivery
MENGE LIKE EKPO-MENGE, " Open Purch. Orders
VALUE LIKE MBEW-SALK3, " Stock Value (Calculated)
MEINS LIKE MARA-MEINS, " Unit of measure
END OF INV.

DATA: FIELDTAB TYPE SLIS_T_FIELDCAT_ALV,
HEADING TYPE SLIS_T_LISTHEADER,
LAYOUT TYPE SLIS_LAYOUT_ALV,
EVENTS TYPE SLIS_T_EVENT,
REPNAME LIKE SY-REPID,
F2CODE LIKE SY-UCOMM VALUE '&ETA',
G_SAVE(1) TYPE C,
G_EXIT(1) TYPE C,
G_VARIANT LIKE DISVARIANT,
GX_VARIANT LIKE DISVARIANT.

break-point.
INITIALIZATION.
REPNAME = SY-REPID.
PERFORM INITIALIZE_FIELDCAT USING FIELDTAB[].
PERFORM BUILD_EVENTTAB USING EVENTS[].
PERFORM BUILD_COMMENT USING HEADING[].
PERFORM INITIALIZE_VARIANT.

break-point.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_VARI.
PERFORM F4_FOR_VARIANT.
break-point.
AT SELECTION-SCREEN.
PERFORM PAI_OF_SELECTION_SCREEN.
break-point.
START-OF-SELECTION.
PERFORM GET_MARD.
PERFORM GET_UNIT_OF_MEASURE.
PERFORM GET_MARC.
PERFORM GET_EKPO.
PERFORM GET_LIPS.
PERFORM GET_VBAP.
PERFORM GET_OPEN.
PERFORM GET_PRICE.

END-OF-SELECTION.
break-point.
PERFORM BUILD_LAYOUT USING LAYOUT.
PERFORM WRITE_OUTPUT.

*&---------------------------------------------------------------------*
*& Form INITIALIZE_FIELDCAT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_FIELDTAB[] text *
*----------------------------------------------------------------------*
FORM INITIALIZE_FIELDCAT USING P_FIELDTAB TYPE SLIS_T_FIELDCAT_ALV.
DATA: L_FIELDCAT TYPE SLIS_FIELDCAT_ALV.
* fixed columns (obligatory)
CLEAR L_FIELDCAT.

L_FIELDCAT-TABNAME = 'INV'.
L_FIELDCAT-FIX_COLUMN = 'X'.
L_FIELDCAT-NO_OUT = 'O'.

L_FIELDCAT-FIELDNAME = 'WERKS'.
APPEND L_FIELDCAT TO P_FIELDTAB.
L_FIELDCAT-FIELDNAME = 'MATNR'.
APPEND L_FIELDCAT TO P_FIELDTAB.

* totalized columns
CLEAR L_FIELDCAT.
L_FIELDCAT-TABNAME = 'INV'.
L_FIELDCAT-SP_GROUP = 'A'.
L_FIELDCAT-DO_SUM = 'X'.
L_FIELDCAT-FIELDNAME = 'LABST'.
APPEND L_FIELDCAT TO P_FIELDTAB.
L_FIELDCAT-FIELDNAME = 'INSME'.
APPEND L_FIELDCAT TO P_FIELDTAB.
L_FIELDCAT-FIELDNAME = 'RETME'.
APPEND L_FIELDCAT TO P_FIELDTAB.
L_FIELDCAT-FIELDNAME = 'UMLME'.
APPEND L_FIELDCAT TO P_FIELDTAB.
L_FIELDCAT-FIELDNAME = 'WESBS'.
APPEND L_FIELDCAT TO P_FIELDTAB.
L_FIELDCAT-FIELDNAME = 'SPEME'.
APPEND L_FIELDCAT TO P_FIELDTAB.

* columns with different description
L_FIELDCAT-FIELDNAME = 'KWMENG'.
L_FIELDCAT-SELTEXT_M = 'Sales Orders'.
L_FIELDCAT-SELTEXT_S = 'Sales Or'.
L_FIELDCAT-SELTEXT_L = 'Sales Orders Qty'.
APPEND L_FIELDCAT TO P_FIELDTAB.
L_FIELDCAT-FIELDNAME = 'LFIMG'.
L_FIELDCAT-SELTEXT_M = 'Sched. Delivery'.
L_FIELDCAT-SELTEXT_S = 'Schd. Del'.
L_FIELDCAT-SELTEXT_L = 'Scheduled for Delivery'.
APPEND L_FIELDCAT TO P_FIELDTAB.
L_FIELDCAT-FIELDNAME = 'TRANS'.
L_FIELDCAT-SELTEXT_M = 'Stk. in transit'.
L_FIELDCAT-SELTEXT_S = 'Stk. trns'.
L_FIELDCAT-SELTEXT_L = 'Stock in transit (sum)'.
APPEND L_FIELDCAT TO P_FIELDTAB.
L_FIELDCAT-FIELDNAME = 'AVAIL'.
L_FIELDCAT-SELTEXT_M = 'Available'.
L_FIELDCAT-SELTEXT_S = 'Avail.'.
L_FIELDCAT-SELTEXT_L = 'Stock Available'.
APPEND L_FIELDCAT TO P_FIELDTAB.
L_FIELDCAT-FIELDNAME = 'MENGE'.
L_FIELDCAT-SELTEXT_M = 'Open Orders'.
L_FIELDCAT-SELTEXT_S = 'Open Ord'.
L_FIELDCAT-SELTEXT_L = 'Open Purchase Orders'.
APPEND L_FIELDCAT TO P_FIELDTAB.

* columns not displayed
CLEAR L_FIELDCAT.
L_FIELDCAT-TABNAME = 'INV'.
L_FIELDCAT-SP_GROUP = 'A'.
L_FIELDCAT-NO_OUT = 'X'.
L_FIELDCAT-FIELDNAME = 'MEINS'.
APPEND L_FIELDCAT TO P_FIELDTAB.
L_FIELDCAT-FIELDNAME = 'UMLMC'.
APPEND L_FIELDCAT TO P_FIELDTAB.
L_FIELDCAT-FIELDNAME = 'TRAME'.
APPEND L_FIELDCAT TO P_FIELDTAB.
L_FIELDCAT-FIELDNAME = 'STPRS'.
APPEND L_FIELDCAT TO P_FIELDTAB.
L_FIELDCAT-FIELDNAME = 'VALUE'.
APPEND L_FIELDCAT TO P_FIELDTAB.
ENDFORM. " INITIALIZE_FIELDCAT

*&---------------------------------------------------------------------*
*& Form BUILD_EVENTTAB
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_EVENTS[] text *
*----------------------------------------------------------------------*
FORM BUILD_EVENTTAB USING P_EVENTS TYPE SLIS_T_EVENT.
DATA: LS_EVENT TYPE SLIS_ALV_EVENT.
CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
EXPORTING
I_LIST_TYPE = 0
IMPORTING
ET_EVENTS = P_EVENTS.
READ TABLE P_EVENTS WITH KEY NAME = SLIS_EV_TOP_OF_PAGE
INTO LS_EVENT.
IF SY-SUBRC = 0.
MOVE FORMNAME_TOP_OF_PAGE TO LS_EVENT-FORM.
APPEND LS_EVENT TO P_EVENTS.
ENDIF.
ENDFORM. " BUILD_EVENTTAB

*&---------------------------------------------------------------------*
*& Form BUILD_COMMENT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_HEADING[] text *
*----------------------------------------------------------------------*
FORM BUILD_COMMENT USING P_HEADING TYPE SLIS_T_LISTHEADER.
DATA: HLINE TYPE SLIS_LISTHEADER,
TEXT(60) TYPE C,
SEP(20) TYPE C.
CLEAR: HLINE, TEXT.
HLINE-TYP = 'H'.
WRITE: TEXT-101 TO TEXT+23.
HLINE-INFO = TEXT.
APPEND HLINE TO P_HEADING.
CLEAR TEXT.
WRITE: 'User: ' TO TEXT,
SY-UNAME TO TEXT+6,
'Date: ' TO TEXT+25,
SY-DATUM TO TEXT+31,
'Page: ' TO TEXT+50,
SY-PAGNO TO TEXT+56.
HLINE-INFO = TEXT.
APPEND HLINE TO P_HEADING.

ENDFORM. " BUILD_COMMENT

*---------------------------------------------------------------------*
* FORM TOP_OF_PAGE *
*---------------------------------------------------------------------*
* ........ *
*---------------------------------------------------------------------*
FORM TOP_OF_PAGE.
CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
EXPORTING
IT_LIST_COMMENTARY = HEADING.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form INITIALIZE_VARIANT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM INITIALIZE_VARIANT.
G_SAVE = 'A'.
CLEAR G_VARIANT.
G_VARIANT-REPORT = REPNAME.
GX_VARIANT = G_VARIANT.
CALL FUNCTION 'REUSE_ALV_VARIANT_DEFAULT_GET'
EXPORTING
I_SAVE = G_SAVE
CHANGING
CS_VARIANT = GX_VARIANT
EXCEPTIONS
NOT_FOUND = 2.
IF SY-SUBRC = 0.
P_VARI = GX_VARIANT-VARIANT.
ENDIF.
ENDFORM. " INITIALIZE_VARIANT

*&---------------------------------------------------------------------*
*& Form F4_FOR_VARIANT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM F4_FOR_VARIANT.
CALL FUNCTION 'REUSE_ALV_VARIANT_F4'
EXPORTING
IS_VARIANT = G_VARIANT
I_SAVE = G_SAVE
IMPORTING
E_EXIT = G_EXIT
ES_VARIANT = GX_VARIANT
EXCEPTIONS
NOT_FOUND = 2.
IF SY-SUBRC = 2.
MESSAGE ID SY-MSGID TYPE 'S' NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ELSE.
IF G_EXIT = SPACE.
P_VARI = GX_VARIANT-VARIANT.
ENDIF.
ENDIF.
ENDFORM. " F4_FOR_VARIANT

*&---------------------------------------------------------------------*
*& Form PAI_OF_SELECTION_SCREEN
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM PAI_OF_SELECTION_SCREEN.
*
IF NOT P_VARI IS INITIAL.
MOVE G_VARIANT TO GX_VARIANT.
MOVE P_VARI TO GX_VARIANT-VARIANT.
CALL FUNCTION 'REUSE_ALV_VARIANT_EXISTENCE'
EXPORTING
I_SAVE = G_SAVE
CHANGING
CS_VARIANT = GX_VARIANT.
G_VARIANT = GX_VARIANT.
ELSE.
PERFORM INITIALIZE_VARIANT.
ENDIF.
ENDFORM. " PAI_OF_SELECTION_SCREEN

*&---------------------------------------------------------------------*
*& Form GET_MARD
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM GET_MARD.
SELECT MATNR WERKS LABST INSME RETME UMLME SPEME
FROM MARD
INTO CORRESPONDING FIELDS OF INV
WHERE MATNR IN S_MATNR
AND WERKS IN S_WERKS.
COLLECT INV.
ENDSELECT.
PERFORM FILTER_BY_MATERIAL_TYPE.
ENDFORM. " GET_MARD

*&---------------------------------------------------------------------*
*& Form FILTER_BY_MATERIAL_TYPE
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM FILTER_BY_MATERIAL_TYPE.
LOOP AT INV.
CLEAR INV-MTART.
SELECT SINGLE MTART
INTO INV-MTART
FROM MARA
WHERE MATNR EQ INV-MATNR
AND MTART IN S_MTART.
IF SY-SUBRC EQ 0.
MODIFY INV.
ELSE.
DELETE INV.
ENDIF.
ENDLOOP.
ENDFORM. " FILTER_BY_MATERIAL_TYPE

*&---------------------------------------------------------------------*
*& Form GET_MARC
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM GET_MARC.
LOOP AT INV.
SELECT SINGLE UMLMC TRAME
FROM MARC
INTO CORRESPONDING FIELDS OF INV
WHERE MATNR EQ INV-MATNR
AND WERKS EQ INV-WERKS.
IF SY-SUBRC EQ 0.
INV-TRANS = INV-UMLMC + INV-TRAME.
MODIFY INV.
ENDIF.
ENDLOOP.
ENDFORM. " GET_MARC
*&---------------------------------------------------------------------*
*& Form GET_EKPO
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM GET_EKPO.
DATA: WESBS LIKE INV-WESBS,
SHKZG LIKE EKBE-SHKZG,
MEINS LIKE EKPO-MEINS,
LMEIN LIKE EKPO-LMEIN.
LOOP AT INV.
CLEAR: WESBS, SHKZG, MEINS, LMEIN.
SELECT Y~WESBS Y~SHKZG X~MEINS X~LMEIN
INTO (WESBS, SHKZG, MEINS, LMEIN)
FROM EKPO AS X JOIN EKBE AS Y
ON X~EBELN = Y~EBELN
AND X~EBELP = Y~EBELP
WHERE X~MATNR EQ INV-MATNR
AND X~WERKS EQ INV-WERKS
AND X~LOEKZ NE 'L'.
IF SHKZG EQ 'H'.
MULTIPLY WESBS BY -1.
ENDIF.
IF MEINS NE LMEIN.
PERFORM CONVERT_UNIT_OF_MEASURE CHANGING INV-MATNR MEINS WESBS.
ENDIF.
ADD WESBS TO INV-WESBS.
ENDSELECT.
MODIFY INV.
ENDLOOP.
ENDFORM. " GET_EKPO
*&---------------------------------------------------------------------*
*& Form GET_LIPS
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM GET_LIPS.
DATA: LFIMG LIKE INV-LFIMG.
LOOP AT INV.
CLEAR: LFIMG, INV-LFIMG.
SELECT OMENG
INTO LFIMG
FROM VBBE
WHERE MATNR EQ INV-MATNR
AND WERKS EQ INV-WERKS
AND VBTYP EQ 'J'.
ADD LFIMG TO INV-LFIMG.
ENDSELECT.
MODIFY INV.
ENDLOOP.
ENDFORM. " GET_LIPS
*&---------------------------------------------------------------------*
*& Form GET_VBAP
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM GET_VBAP.
DATA: KWMENG LIKE INV-KWMENG.
LOOP AT INV.
CLEAR: KWMENG, INV-KWMENG.
SELECT OMENG
INTO KWMENG
FROM VBBE
WHERE MATNR EQ INV-MATNR
AND WERKS EQ INV-WERKS
AND VBTYP EQ 'C'.
ADD KWMENG TO INV-KWMENG.
ENDSELECT.
INV-AVAIL = INV-LABST - INV-INSME - INV-KWMENG - INV-LFIMG.
MODIFY INV.
ENDLOOP.
ENDFORM. " GET_VBAP

*&---------------------------------------------------------------------*
*& Form GET_UNIT_OF_MEASURE
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM GET_UNIT_OF_MEASURE.
LOOP AT INV.
SELECT SINGLE MEINS
FROM MARA
INTO INV-MEINS
WHERE MATNR EQ INV-MATNR.
MODIFY INV.
ENDLOOP.
ENDFORM. " GET_UNIT_OF_MEASURE

*&---------------------------------------------------------------------*
*& Form GET_OPEN
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM GET_OPEN.
DATA: BEGIN OF XTAB OCCURS 10, " Open orders table
WERKS LIKE EKPO-WERKS,
LGORT LIKE EKPO-LGORT,
MATNR LIKE EKPO-MATNR,
MENGE LIKE EKPO-MENGE,
MENGK LIKE EKPO-MENGE,
END OF XTAB.
RANGES: L_WERKS FOR MARD-WERKS.

LOOP AT INV.
REFRESH XTAB.
CLEAR: XTAB, L_WERKS.
MOVE INV-WERKS TO L_WERKS-LOW.
CALL FUNCTION 'MB_ADD_PURCHASE_ORDER_QUANTITY'
EXPORTING
X_MATNR = INV-MATNR
X_MEINS = INV-MEINS
X_ELIKZ = SPACE
X_LOEKZ = SPACE
TABLES
XTAB = XTAB
XWERKS = L_WERKS.
MOVE XTAB-MENGE TO INV-MENGE.
MODIFY INV.
ENDLOOP.
ENDFORM. " GET_OPEN

*&---------------------------------------------------------------------*
*& Form GET_PRICE
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM GET_PRICE.
LOOP AT INV.
SELECT SINGLE STPRS
FROM MBEW
INTO INV-STPRS
WHERE MATNR EQ INV-MATNR
AND BWKEY EQ INV-WERKS
AND BWTAR EQ SPACE.
IF SY-SUBRC EQ 0.
INV-VALUE = INV-STPRS *
( INV-LABST + INV-INSME + INV-TRANS + INV-SPEME ).
MODIFY INV.
ENDIF.
ENDLOOP.
ENDFORM. " GET_PRICE

*---------------------------------------------------------------------*
* FORM CONVERT_UNIT_OF_MEASURE *
*---------------------------------------------------------------------*
* text *
*---------------------------------------------------------------------*
* --> P_MATNR *
* --> P_VRKME *
* --> P_QUANT *
*---------------------------------------------------------------------*
FORM CONVERT_UNIT_OF_MEASURE USING P_MATNR P_VRKME P_QUANT.
DATA: UMREZ LIKE MARM-UMREZ,
UMREN LIKE MARM-UMREN.
SELECT SINGLE UMREZ UMREN
INTO (UMREZ, UMREN)
FROM MARM
WHERE MATNR EQ P_MATNR
AND MEINH EQ P_VRKME.
IF SY-SUBRC EQ 0.
COMPUTE P_QUANT = ( P_QUANT * UMREZ ) / UMREN.
ENDIF.
ENDFORM.

*&---------------------------------------------------------------------*
*& Form BUILD_LAYOUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_LAYOUT text *
*----------------------------------------------------------------------*
FORM BUILD_LAYOUT USING P_LAYOUT TYPE SLIS_LAYOUT_ALV.
P_LAYOUT-F2CODE = F2CODE.
P_LAYOUT-ZEBRA = 'X'.
P_LAYOUT-DETAIL_POPUP = 'X'.
ENDFORM. " BUILD_LAYOUT

*&---------------------------------------------------------------------*
*& Form WRITE_OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM WRITE_OUTPUT.
SORT INV BY WERKS MATNR.
CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
EXPORTING
I_PROGRAM_NAME = REPNAME
I_INTERNAL_TABNAME = 'INV'
I_INCLNAME = REPNAME
CHANGING
CT_FIELDCAT = FIELDTAB.
IF SY-SUBRC <> 0.
WRITE: 'SY-SUBRC: ', SY-SUBRC, 'REUSE_ALV_FIELDCATALOG_MERGE'.
ENDIF.

CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM = REPNAME
I_STRUCTURE_NAME = 'INV'
IS_LAYOUT = LAYOUT
IT_FIELDCAT = FIELDTAB
I_DEFAULT = 'A'
I_SAVE = G_SAVE
IS_VARIANT = G_VARIANT
IT_EVENTS = EVENTS[]
TABLES
T_OUTTAB = INV.
break-point.
IF SY-SUBRC <> 0.
WRITE: 'SY-SUBRC: ', SY-SUBRC, 'REUSE_ALV_LIST_DISPLAY'.
ENDIF.
ENDFORM. " WRITE_OUTPUT

A Simple ABAP ALV LIST VIEWER Example

This ALV program have all the basic report requirements such as page heading, page no, sub-total and a grand total.

* This is a basic ALV with the followings:-
* - Page Heading
* - Page No
* - Sub-Total
* - Grand Total

REPORT ZALV.

TYPE-POOLS: SLIS.

DATA: G_REPID LIKE SY-REPID,
GS_PRINT TYPE SLIS_PRINT_ALV,
GT_LIST_TOP_OF_PAGE TYPE SLIS_T_LISTHEADER,
GT_EVENTS TYPE SLIS_T_EVENT,
GT_SORT TYPE SLIS_T_SORTINFO_ALV,
GS_LAYOUT TYPE SLIS_LAYOUT_ALV,
GT_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV,
FIELDCAT_LN LIKE LINE OF GT_FIELDCAT,
COL_POS TYPE I.

DATA: BEGIN OF ITAB,
FIELD1(5) TYPE C,
FIELD2(5) TYPE C,
FIELD3(5) TYPE P DECIMALS 2,
END OF ITAB.

DATA: BEGIN OF ITAB1 OCCURS 0.
INCLUDE STRUCTURE ITAB.
DATA: END OF ITAB1.

DATA: BEGIN OF ITAB_FIELDCAT OCCURS 0.
INCLUDE STRUCTURE ITAB.
DATA: END OF ITAB_FIELDCAT.

* Print Parameters
PARAMETERS:
P_PRINT AS CHECKBOX DEFAULT ' ', "PRINT IMMEDIATE
P_NOSINF AS CHECKBOX DEFAULT 'X', "NO SELECTION INFO
P_NOCOVE AS CHECKBOX DEFAULT ' ', "NO COVER PAGE
P_NONEWP AS CHECKBOX DEFAULT ' ', "NO NEW PAGE
P_NOLINF AS CHECKBOX DEFAULT 'X', "NO PRINT LIST INFO
P_RESERV TYPE I. "NO OF FOOTER LINE

INITIALIZATION.
G_REPID = SY-REPID.
PERFORM PRINT_BUILD USING GS_PRINT. "Print PARAMETERS

START-OF-SELECTION.
* TEST DATA
MOVE 'TEST1' TO ITAB1-FIELD1.
MOVE 'TEST1' TO ITAB1-FIELD2.
MOVE '10.00' TO ITAB1-FIELD3.
APPEND ITAB1.

MOVE 'TEST2' TO ITAB1-FIELD1.
MOVE 'TEST2' TO ITAB1-FIELD2.
MOVE '20.00' TO ITAB1-FIELD3.
APPEND ITAB1.

DO 50 TIMES.
APPEND ITAB1.
ENDDO.

END-OF-SELECTION.

PERFORM BUILD.
PERFORM EVENTTAB_BUILD CHANGING GT_EVENTS.
PERFORM COMMENT_BUILD CHANGING GT_LIST_TOP_OF_PAGE.
PERFORM CALL_ALV.

FORM BUILD.
* DATA FIELD CATALOG
* Explain Field Description to ALV
DATA: FIELDCAT_IN TYPE SLIS_FIELDCAT_ALV.

CLEAR FIELDCAT_IN.
FIELDCAT_LN-FIELDNAME = 'FIELD1'.
FIELDCAT_LN-TABNAME = 'ITAB1'.
*FIELDCAT_LN-NO_OUT = 'X'. "FIELD NOT DISPLAY, CHOOSE FROM LAYOUT
FIELDCAT_LN-KEY = ' '. "SUBTOTAL KEY
FIELDCAT_LN-NO_OUT = ' '.
FIELDCAT_LN-SELTEXT_L = 'HEAD1'.
APPEND FIELDCAT_LN TO GT_FIELDCAT.

CLEAR FIELDCAT_IN.
FIELDCAT_LN-FIELDNAME = 'FIELD2'.
FIELDCAT_LN-TABNAME = 'ITAB1'.
FIELDCAT_LN-NO_OUT = 'X'.
FIELDCAT_LN-SELTEXT_L = 'HEAD2'.
APPEND FIELDCAT_LN TO GT_FIELDCAT.

CLEAR FIELDCAT_IN.
FIELDCAT_LN-FIELDNAME = 'FIELD3'.
FIELDCAT_LN-TABNAME = 'ITAB1'.
FIELDCAT_LN-REF_FIELDNAME = 'MENGE'. "<- REF FIELD IN THE DICTIONNARY
FIELDCAT_LN-REF_TABNAME = 'MSEG'. "<- REF TABLE IN THE DICTIONNARY
FIELDCAT_LN-NO_OUT = ' '.
FIELDCAT_LN-DO_SUM = 'X'. "SUM UPON DISPLAY
APPEND FIELDCAT_LN TO GT_FIELDCAT.

* DATA SORTING AND SUBTOTAL
DATA: GS_SORT TYPE SLIS_SORTINFO_ALV.

CLEAR GS_SORT.
GS_SORT-FIELDNAME = 'FIELD1'.
GS_SORT-SPOS = 1.
GS_SORT-UP = 'X'.
GS_SORT-SUBTOT = 'X'.
APPEND GS_SORT TO GT_SORT.

CLEAR GS_SORT.
GS_SORT-FIELDNAME = 'FIELD2'.
GS_SORT-SPOS = 2.
GS_SORT-UP = 'X'.
*GS_SORT-SUBTOT = 'X'.
APPEND GS_SORT TO GT_SORT.

ENDFORM.

FORM CALL_ALV.
* ABAP List Viewer
CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
EXPORTING
* I_INTERFACE_CHECK = ' '
* I_BYPASSING_BUFFER =
* I_BUFFER_ACTIVE = ' '
I_CALLBACK_PROGRAM = G_REPID
* I_CALLBACK_PF_STATUS_SET = ' '
* I_CALLBACK_USER_COMMAND = ' '
I_STRUCTURE_NAME = 'ITAB1'
IS_LAYOUT = GS_LAYOUT
IT_FIELDCAT = GT_FIELDCAT[]
* IT_EXCLUDING =
* IT_SPECIAL_GROUPS =
IT_SORT = GT_SORT[]
* IT_FILTER =
* IS_SEL_HIDE =
* I_DEFAULT = 'X'
* I_SAVE = ' '
* IS_VARIANT =
IT_EVENTS = GT_EVENTS[]
* IT_EVENT_EXIT =
IS_PRINT = GS_PRINT
* IS_REPREP_ID =
* 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 =
TABLES
T_OUTTAB = ITAB1
EXCEPTIONS
PROGRAM_ERROR = 1
OTHERS = 2.
ENDFORM.

* HEADER FORM
FORM EVENTTAB_BUILD CHANGING LT_EVENTS TYPE SLIS_T_EVENT.
CONSTANTS:
GC_FORMNAME_TOP_OF_PAGE TYPE SLIS_FORMNAME VALUE 'TOP_OF_PAGE'.
*GC_FORMNAME_END_OF_PAGE TYPE SLIS_FORMNAME VALUE 'END_OF_PAGE'.

DATA: LS_EVENT TYPE SLIS_ALV_EVENT.

CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
EXPORTING
I_LIST_TYPE = 0
IMPORTING
ET_EVENTS = LT_EVENTS.

READ TABLE LT_EVENTS WITH KEY NAME = SLIS_EV_TOP_OF_PAGE
INTO LS_EVENT.
IF SY-SUBRC = 0.
MOVE GC_FORMNAME_TOP_OF_PAGE TO LS_EVENT-FORM.
APPEND LS_EVENT TO LT_EVENTS.
ENDIF.

* define END_OF_PAGE event
* READ TABLE LT_EVENTS WITH KEY NAME = SLIS_EV_END_OF_PAGE
* INTO LS_EVENT.
* IF SY-SUBRC = 0.
* MOVE GC_FORMNAME_END_OF_PAGE TO LS_EVENT-FORM.
* APPEND LS_EVENT TO LT_EVENTS.
* ENDIF.
ENDFORM.

FORM COMMENT_BUILD CHANGING GT_TOP_OF_PAGE TYPE SLIS_T_LISTHEADER.
DATA: GS_LINE TYPE SLIS_LISTHEADER.

CLEAR GS_LINE.
GS_LINE-TYP = 'H'.
GS_LINE-INFO = 'HEADER 1'.
APPEND GS_LINE TO GT_TOP_OF_PAGE.

CLEAR GS_LINE.
GS_LINE-TYP = 'S'.
GS_LINE-KEY = 'STATUS 1'.
GS_LINE-INFO = 'INFO 1'.
APPEND GS_LINE TO GT_TOP_OF_PAGE.
GS_LINE-KEY = 'STATUS 2'.
GS_LINE-INFO = 'INFO 2'.
APPEND GS_LINE TO GT_TOP_OF_PAGE.

* CLEAR GS_LINE.
* GS_LINE-TYP = 'A'.
*
* GS_LINE-INFO = 'ACTION'.
* APPEND GS_LINE TO GT_TOP_OF_PAGE.

ENDFORM.

FORM TOP_OF_PAGE.
CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
EXPORTING
IT_LIST_COMMENTARY = GT_LIST_TOP_OF_PAGE.
WRITE: SY-DATUM, 'Page No', SY-PAGNO LEFT-JUSTIFIED.
ENDFORM.

FORM END_OF_PAGE.
WRITE at (sy-linsz) sy-pagno CENTERED.
ENDFORM.

* PRINT SETTINGS
FORM PRINT_BUILD USING LS_PRINT TYPE SLIS_PRINT_ALV.
LS_PRINT-PRINT = P_PRINT. "PRINT IMMEDIATE
LS_PRINT-NO_PRINT_SELINFOS = P_NOSINF. "NO SELECTION INFO
LS_PRINT-NO_COVERPAGE = P_NOCOVE. "NO COVER PAGE
LS_PRINT-NO_NEW_PAGE = P_NONEWP.
LS_PRINT-NO_PRINT_LISTINFOS = P_NOLINF. "NO PRINT LIST INFO
LS_PRINT-RESERVE_LINES = P_RESERV.
ENDFORM.

*END OF ZALV PROGRAM

Definition and a Program on ALV

Give definition and a Program on ALV.

I would say that ALV is a tool that you can use in ABAP to display data in a grid - you just call a function doing it, pass the data to it and the function itself produces a nice report with many functions (like sort by, filtler etc.)

I attach a demo program, which is perfectly prepared that you change the columns to contain what you want.

There is also another way of doing the same, using the objects.

REPORT z_pj_test_reuse .


* A demo program for the function REUSE_ALV_LIST_DISPLAY


* Types that we need
TYPE-POOLS slis.


TYPES:
BEGIN OF ts_my_item,

* This structure represents a line of our table
* You can change this structure in any way you want,
* but do not forget : you must then modify the form show_alv_grid
* to show also the new components of this structure

m_element1 TYPE char30,
m_element2 TYPE num5,
* If there is an element in this structure for which you do not
* insert the statement "ls_fieldcat-fieldname = ..."
* then the element will not be displayed, for example this one:
m_element_not_displayed TYPE char32,
END OF ts_my_item.


TYPES : t_tab_my_item TYPE TABLE OF ts_my_item.


* After you run the program, this will be executed:
PERFORM main.


*---------------------------------------------------------------------*
* FORM main *
*---------------------------------------------------------------------*
* Main program
*---------------------------------------------------------------------*
FORM main.
DATA lt_items TYPE t_tab_my_item.
PERFORM fill_test_data USING lt_items.
PERFORM show_alv_grid USING lt_items.
ENDFORM.



*---------------------------------------------------------------------*
* FORM fill_test_data *
*---------------------------------------------------------------------*
* ........ *
*---------------------------------------------------------------------*
* --> LT_ITEMS *
*---------------------------------------------------------------------*
FORM fill_test_data CHANGING lt_items TYPE t_tab_my_item.

* Here the structure will be filled with demo data
* In reality, the structure will have different components
* (those which you need)
* And will be filled with real data

DATA ls_line TYPE LINE OF t_tab_my_item.
CLEAR lt_items.
* First line of ALV grid
ls_line-m_element1 = 'Some data'.
ls_line-m_element2 = '4444'.
ls_line-m_element_not_displayed = 'This will not be displayed'.
APPEND ls_line TO lt_items.

* second line
ls_line-m_element1 = 'Some other data'.
ls_line-m_element2 = '4445'.
APPEND ls_line TO lt_items.


* third line
ls_line-m_element1 = 'More data'.
APPEND ls_line TO lt_items.

ENDFORM.


**************************************************************
* FORM show_alv_grid
*
FORM show_alv_grid CHANGING tab_output TYPE t_tab_my_item.

DATA: it_fieldcat TYPE slis_t_fieldcat_alv,
gt_events TYPE slis_t_event,
repid LIKE sy-repid,
ls_fieldcat TYPE slis_fieldcat_alv,
it_layout TYPE slis_layout_alv.

""""""""""""""""""""""""""""""""
" ls_fieldcat

ls_fieldcat-tabname = 'IT_DENIK'. " Interní tabulka
ls_fieldcat-ref_tabname = 'EKKO'. " Pùvodní tabulka.

* The following three lines must be here for each element
* that we want to display
* The fieldname must be in capital letters

ls_fieldcat-fieldname = 'M_ELEMENT1'.
ls_fieldcat-reptext_ddic = 'Title of 1st column'.
APPEND ls_fieldcat TO it_fieldcat.

ls_fieldcat-fieldname = 'M_ELEMENT2'.
ls_fieldcat-reptext_ddic = 'Title of 2nd column'.
APPEND ls_fieldcat TO it_fieldcat.

* I purpochasely ommited the element m_element_not_displayed
* Therefore it will not be displayed

""""""""""""""""""""""""""""""""
" it_layout

* There is a lot of code which I do not understand
* You can write some strings there and watch where on the screen
* they will appear.

CLEAR it_layout.
it_layout-detail_popup = ' '.
it_layout-detail_titlebar = ' '."Detail of the window (?)
it_layout-info_fieldname = ' '.
it_layout-header_text = 'Our title'.
it_layout-no_colhead = ' '.
"'X' cancels headlines of columns
it_layout-no_hotspot = ' '.
"'X' = cannot select a column
it_layout-window_titlebar = it_layout-header_text.
it_layout-list_append = ' '.
it_layout-item_text = ' '.

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" call REUSE_ALV_LIST_DISPLAY


repid = sy-repid.
CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
EXPORTING
i_callback_program = repid
it_fieldcat = it_fieldcat
it_events = gt_events[]
is_layout = it_layout
TABLES
t_outtab = tab_output.
ENDFORM.

Friday, February 29, 2008

SAP Transaction Code For Graphical Structure Maintenance

PGOM PDGRAPHX Graphical Structure Maintenance

SAP Transaction Code For Maintain Workflow Template

PFWS RHSFLOW0 Maintain Workflow Template

SAP Transaction Code For Maintain Workflow Task (Customer)

PFWF SAPLRHWP Maintain Workflow Task (Customer)

Recent Topics