Tuesday, May 31, 2011

User Exit

For all user exit you can find in the program SAPMV45A

go to se38: SAPMV45A (standard program)

You will have the all the user Exit here

Example :: INCLUDE MV45AFZZ.


Double click on it.

There you will find all the From here.
-----------------------------------------------------------------
example:
FORM USEREXIT_SAVE_DOCUMENT.

Double click on it.

perform userexit_save_document.

In Transaction VA01.

the user exit will be called.
-----------------------------------------------------------------

write the code here in the FORM.

click on Enhance(shift+f4)

Edit Enhancement operations

show implicit Enhancement operations

"""""""""""""""""""""""

Right click on it.

Enhancement Implementation

Create Implementation

code

Name it.

write the code in the Enhancement.
message display

Now Execute the transaction code VA01.

when you save the file it shows the message.

User Exit with Enhancement to a Standard Program.

If you want to delete the created Enhancement.

go to SE19.

Name of the created Enhancement.

Delete.

Enhancements in SAP table

The details about projects, enhancements and components are contained in two SAP tables:

MODSAP: containing enhancement name, type of exit and component

MODACT: containing project name and enhancements

REPORT ZDEMO_EXAMPLE.

TABLES: MODSAP, MODACT.

PARAMETERS: INPUT1 LIKE MODSAP-NAME DEFAULT ' ',
INPUT2 LIKE MODSAP-TYP DEFAULT ' ',
INPUT3 LIKE MODSAP-MEMBER DEFAULT ' '.

DATA: SEARCH1 LIKE MODSAP-NAME,
SEARCH2(3), " like modsap-typ,
SEARCH3 LIKE MODSAP-MEMBER.

CONCATENATE: '%' INPUT1 '%' INTO SEARCH1,
'%' INPUT2 INTO SEARCH2,
'%' INPUT3 '%' INTO SEARCH3.

SELECT * FROM MODSAP WHERE NAME LIKE SEARCH1
AND TYP LIKE SEARCH2
AND MEMBER LIKE SEARCH3.
SELECT SINGLE * FROM MODACT WHERE MEMBER = MODSAP-NAME.
WRITE: /10 MODSAP-NAME, 30 MODSAP-TYP, 45 MODSAP-MEMBER, 70 MODACT-NAME.
CLEAR : MODSAP, MODACT.
ENDSELECT.

IF SY-SUBRC NE 0.
WRITE : /'Not found'.
ENDIF.

END-OF-SELECTION.
CLEAR: SEARCH1, SEARCH2, SEARCH3.


NOTE: SAP’s naming convention for user exits-

· Program/Function exits : EXIT_AAAAAAAA_nnn where

AAAAAAAA stands for the program name which contains the exit and

nnn is a SAP assigned number starting from 001

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

· Menu exits : AAAAAAAA+XXX where

AAAAAAAA stands for the program name which contains the exit and

+XXX is the name of the function code contained in the menu item

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

· Screen Exits : AAAAAAAA_nnnn_BBBBBBBB_CCCCCCCC_mmmm where

AAAAAAAA : calling program name

nnnn : calling screen number

BBBBBBBB : area

CCCCCCCC : called program name

mmmm : called screen number

Enhancements (User Exits & Customer exits)

Enhancements:

The enhancement concept allows you to add your own functionality to SAP's standard business applications without having to modify the original applications.
To modify the standard SAP behavior as per customer requirements, we can use enhancement framework.


There are different ways to implement custom functionality in the SAP standard code.
ex: User exits,
customer exits,
BADI etc.


User exits can be found in the following ways:

Go to Object Navigator (SE80),

select Package and put VMOD (Application development R/3 SD customer modification) and

press enter.

You will find all the includes for user exits in SD.

User-exits are empty subroutines that SAP Developers have provided for you.

You can fill them with your own source code. Technically this is a modification.

All User exits start with the word USEREXIT_...

FORM USEREXIT_XXXX....
INCLUDE ZZUSEREXIT.......
ENDFORM.


customer exits:

SAP creates customer exits for specific programs, screens, and menus within standard applications.

These exits do not contain any functionality.

Instead, the customer exits act as hooks. You can hang your own add-on functionality onto these hooks.

Customer exits are nothing but a include in customer name space will be provided in the function module which starts with CALL CUSTOMER.

Advantage:
- They do not affect standard SAP source code.
- They do not affect software updates.

Disadvantage:
- Customer exits are not available for all programs and screens found in the SAP System.
- You can only use customer exits if they already exist in the SAP System.

Types of Customer Exits
1. Function Module exits
2. Screen exits
3. Menu exits

1. Function Module exits:

Function module exits are exits developed by SAP.

The exit is implemented as a call to a function module.

The code for the function module is written by the developer. You are not writing the code directly in the function module, but in the include that is implemented in the function module.

Format: CALL CUSTOMER-FUNCTION '910'
The naming standard of function modules for function module exits is:
EXIT__<3 digit suffix>

2. Screen exits:

Allow customer to add fields to a screen via a sub screen in an SAP program. The sub screen is called within the standard screen's flow logic.

Format: CALL CUSTOMER-SUBSCREEN CUSTSCR1

3. Menu exits:

Menu exits allow you to add your own functionality to menus.

Menu exits are implemented by SAP and are reserved menu entries in the GUI interface. The developer can add his/her own text and logic for the menu.

Function codes for menu exits all start with "+".
Format: +CUS (additional item in GUI status)


Author(s): Tutun Nandy


Reference from the link:



Monday, May 30, 2011

RFC in SAP

complete doc about how to connect with RFC (login for google Doc)


Wednesday, May 25, 2011

BDC using Session method.

Go sm35.

click on Recording.

click on New Recording.

recording: zbdcxk01.

transaction code:xk01.

give the details.

click on Save.

go to recording again.

select ur Recording name.

click on program.

give program name.

u will get the program thr..


report zbdcxk01
no standard page heading line-size 255.

*include bdcrecx1.

types: begin of ty_record,
* data element: LIF16
LIFNR TYPE LIFNR,
* data element: KTOKK
KTOKK TYPE KTOKK,
* data element: ANRED
ANRED TYPE ANRED,
* data element: NAME1_GP
NAME1 TYPE NAME1,
* data element: SORTL
SORTL TYPE SORTL,
* data element: LAND1_GP
LAND1 TYPE LAND1,
end of ty_record.


data: i_record type table of ty_record,
w_record type ty_record.

DATA : I_BDCDATA TYPE TABLE OF BDCDATA,
W_BDCDATA TYPE BDCDATA.


DATA: CLIENT TYPE APQI-MANDANT," SY-MANDT Client
DEST TYPE APQI-DESTSYS ,"FILLER8 Target system for ODC/no longer relevant
GROUP TYPE APQI-GROUPID," FILLER12 Session name
HOLDDATE TYPE APQI-STARTDATE," FILLER8 Session locked until specified date
KEEP TYPE APQI-QERASE," FILLER1 Indicator to keep processed sessions
USER TYPE APQI-USERID," FILLER12 Batch input user
RECORD TYPE APQI-PUTACTIVE," FILLER1 Indicator: BI recording ('X' or ' ')
PROG TYPE APQI-PROGID," SY-CPROG Creator Program
DCPFM TYPE USDEFAULTS-DCPFM," '%' Decimal Character Used
DATFM TYPE USDEFAULTS-DATFM." '%' Date Format Used

DATA : IT_FILE type table of ALSMEX_TABLINE, "if data is brought from Excel sheet
wa_file type ALSMEX_TABLINE. "if data is brought from Excel sheet

start-of-selection.

CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
EXPORTING
FILENAME = 'C:\Users\mouriuser54\Desktop\Ravi_XK01_INPUTDATA.XLSX'
I_BEGIN_COL = '1'
I_BEGIN_ROW = '1'
I_END_COL = '6'
I_END_ROW = '10'
TABLES
INTERN = IT_FILE
* EXCEPTIONS
* INCONSISTENT_PARAMETERS = 1
* UPLOAD_OLE = 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.

loop at it_file into wa_file.
case wa_file-col.
when 1.
w_record-LIFNR = wa_file-value.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
INPUT = w_record-LIFNR
IMPORTING
OUTPUT = w_record-LIFNR
.
when 2.
w_record-KTOKK = wa_file-value.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
INPUT = w_record-KTOKK
IMPORTING
OUTPUT = w_record-KTOKK.

when 3.
w_record-ANRED = wa_file-value.
when 4.
w_record-NAME1 = wa_file-value.
when 5.
w_record-SORTL = wa_file-value.
when 6.
w_record-LAND1 = wa_file-value.
endcase.

at end of row.
append w_record to i_record.
clear w_record.
endat.
endloop.

perform open_group.

LOOP AT I_RECORD INTO W_RECORD.
*do.
CLEAR : I_BDCDATA[].



perform bdc_dynpro using 'SAPMF02K' '0100'.
perform bdc_field using 'BDC_CURSOR'
'RF02K-KTOKK'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
perform bdc_field using 'RF02K-LIFNR'
w_record-lifnr.
perform bdc_field using 'RF02K-KTOKK'
w_record-ktokk.
perform bdc_dynpro using 'SAPMF02K' '0110'.
perform bdc_field using 'BDC_CURSOR'
'LFA1-LAND1'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
perform bdc_field using 'LFA1-ANRED'
w_record-ANRED.
perform bdc_field using 'LFA1-NAME1'
w_record-name1.
perform bdc_field using 'LFA1-SORTL'
w_record-sortl.
perform bdc_field using 'LFA1-LAND1'
w_record-land1.
perform bdc_dynpro using 'SAPMF02K' '0120'.
perform bdc_field using 'BDC_CURSOR'
'LFA1-KUNNR'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
perform bdc_dynpro using 'SAPMF02K' '0130'.
perform bdc_field using 'BDC_CURSOR'
'LFBK-BANKS(01)'.
perform bdc_field using 'BDC_OKCODE'
'=ENTR'.
perform bdc_dynpro using 'SAPMF02K' '0380'.
perform bdc_field using 'BDC_CURSOR'
'KNVK-NAMEV(01)'.
perform bdc_field using 'BDC_OKCODE'
'=ENTR'.
perform bdc_transaction using 'XK01'.

clear : w_record.


ENDLOOP.
perform close_group.


FORM OPEN_GROUP.

GROUP = 'RAVINDRA_SESS'.
USER = SY-UNAME.
KEEP = 'X'.
*HOLDDATE = ''.

* open batchinput group
CALL FUNCTION 'BDC_OPEN_GROUP'
EXPORTING CLIENT = SY-MANDT
GROUP = GROUP
USER = USER
KEEP = KEEP.
* HOLDDATE = HOLDDATE.
WRITE: /(30) 'BDC_OPEN_GROUP'(I02),
(12) 'returncode:'(I05),
SY-SUBRC.

ENDFORM.

FORM BDC_DYNPRO USING PROGRAM DYNPRO.
CLEAR W_BDCDATA.
W_BDCDATA-PROGRAM = PROGRAM.
W_BDCDATA-DYNPRO = DYNPRO.
W_BDCDATA-DYNBEGIN = 'X'.
APPEND W_BDCDATA TO I_BDCDATA.
ENDFORM.

FORM BDC_FIELD USING FNAM FVAL.
* IF FVAL <> NODATA.
CLEAR W_BDCDATA.
W_BDCDATA-FNAM = FNAM.
W_BDCDATA-FVAL = FVAL.
APPEND W_BDCDATA TO I_BDCDATA.
* ENDIF.
ENDFORM.

FORM BDC_TRANSACTION USING TCODE.

CALL FUNCTION 'BDC_INSERT'
EXPORTING TCODE = TCODE
TABLES DYNPROTAB = I_BDCDATA.

ENDFORM.
FORM CLOSE_GROUP.
* close batchinput group
CALL FUNCTION 'BDC_CLOSE_GROUP'.
WRITE: /(30) 'BDC_CLOSE_GROUP'(I04),
(12) 'returncode:'(I05),
SY-SUBRC.

ENDFORM.

Note: data will not be save in SAPDB.

go to sm35.

check the session name.

process the session.

BDC using Call Transaction method.

Go sm35.

click on Recording.

click on New Recording.

recording: zbdcxk01.

transaction code:xk01.

give the details.

click on Save.

go to recording again.

select ur Recording name.

click on program.

give program name.

u will get the program thr..

include bdcrecx1.---this include contains the 2 method call transaction and session method.


PROGRAM ::

report zbdcxk01 no standard page heading line-size 255.

types: begin of ty_record,
* data element: LIF16
LIFNR TYPE LIFNR,
* data element: KTOKK
KTOKK TYPE KTOKK,
* data element: ANRED
ANRED TYPE ANRED,
* data element: NAME1_GP
NAME1 TYPE NAME1,
* data element: SORTL
SORTL TYPE SORTL,
* data element: LAND1_GP
LAND1 TYPE LAND1,
end of ty_record.

data: i_record type table of ty_record,
w_record type ty_record.

DATA : I_BDCDATA TYPE TABLE OF BDCDATA,
W_BDCDATA TYPE BDCDATA.

DATA: I_MESSTAB TYPE TABLE OF BDCMSGCOLL,
W_MESSTAB TYPE BDCMSGCOLL.

DATA : IT_FILE type table of ALSMEX_TABLINE, "if data is brought from Excel sheet
wa_file type ALSMEX_TABLINE.
"if data is brought from Excel sheet

start-of-selection.

CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
EXPORTING
FILENAME = 'C:\Users\mouriuser54\Desktop\Ravi_XK01_INPUTDATA.XLSX'
I_BEGIN_COL = '1'
I_BEGIN_ROW = '1'
I_END_COL = '6'
I_END_ROW = '10'
TABLES
INTERN = IT_FILE
* EXCEPTIONS
* INCONSISTENT_PARAMETERS = 1
* UPLOAD_OLE = 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.

loop at it_file into wa_file.
case wa_file-col.
when 1.
w_record-LIFNR = wa_file-value.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
INPUT = w_record-LIFNR
IMPORTING
OUTPUT = w_record-LIFNR
.
when 2.
w_record-KTOKK = wa_file-value.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
INPUT = w_record-KTOKK
IMPORTING
OUTPUT = w_record-KTOKK.

when 3.
w_record-ANRED = wa_file-value.
when 4.
w_record-NAME1 = wa_file-value.
when 5.
w_record-SORTL = wa_file-value.
when 6.
w_record-LAND1 = wa_file-value.
endcase.

at end of row.
append w_record to i_record.
clear w_record.
endat.
endloop.

*use it for text file loading.
*CALL FUNCTION 'GUI_UPLOAD'
* EXPORTING
* FILENAME = 'C:\Users\mouriuser54\Desktop\Ravi_XK01.TXT'
* FILETYPE = 'ASC'
* HAS_FIELD_SEPARATOR = 'X'
** HEADER_LENGTH = 0
** READ_BY_LINE = 'X'
** DAT_MODE = ' '
** CODEPAGE = ' '
** IGNORE_CERR = ABAP_TRUE
** REPLACEMENT = '#'
** CHECK_BOM = ' '
** VIRUS_SCAN_PROFILE =
** NO_AUTH_CHECK = ' '
** IMPORTING
** FILELENGTH =
** HEADER =
* TABLES
* DATA_TAB = i_record[]
* EXCEPTIONS
* FILE_OPEN_ERROR = 1
* FILE_READ_ERROR = 2
* NO_BATCH = 3
* GUI_REFUSE_FILETRANSFER = 4
* INVALID_TYPE = 5
* NO_AUTHORITY = 6
* UNKNOWN_ERROR = 7
* BAD_DATA_FORMAT = 8
* HEADER_NOT_ALLOWED = 9
* SEPARATOR_NOT_ALLOWED = 10
* HEADER_TOO_LONG = 11
* UNKNOWN_DP_ERROR = 12
* ACCESS_DENIED = 13
* DP_OUT_OF_MEMORY = 14
* DISK_FULL = 15
* DP_TIMEOUT = 16
* OTHERS = 17
* .
*IF SY-SUBRC <> 0.
** MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
** WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
*ENDIF.


LOOP AT I_RECORD INTO W_RECORD.
*do.
CLEAR : I_BDCDATA[].
*read dataset dataset into record.
*if sy-subrc <> 0. exit. endif.

perform bdc_dynpro using 'SAPMF02K' '0100'.
perform bdc_field using 'BDC_CURSOR'
'RF02K-KTOKK'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
perform bdc_field using 'RF02K-LIFNR'
W_RECORD-LIFNR.
perform bdc_field using 'RF02K-KTOKK'
W_RECORD-KTOKK.
perform bdc_dynpro using 'SAPMF02K' '0110'.
perform bdc_field using 'BDC_CURSOR'
'LFA1-LAND1'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
perform bdc_field using 'LFA1-ANRED'
W_RECORD-ANRED.
perform bdc_field using 'LFA1-NAME1'
W_RECORD-NAME1.
perform bdc_field using 'LFA1-SORTL'
W_RECORD-SORTL.
perform bdc_field using 'LFA1-LAND1'
W_RECORD-LAND1.
perform bdc_dynpro using 'SAPMF02K' '0120'.
perform bdc_field using 'BDC_CURSOR'
'LFA1-KUNNR'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
perform bdc_dynpro using 'SAPMF02K' '0130'.
perform bdc_field using 'BDC_CURSOR'
'LFBK-BANKS(01)'.
perform bdc_field using 'BDC_OKCODE'
'=ENTR'.
perform bdc_dynpro using 'SAPMF02K' '0380'.
perform bdc_field using 'BDC_CURSOR'
'KNVK-NAMEV(01)'.
perform bdc_field using 'BDC_OKCODE'
'=ENTR'.
perform bdc_transaction using 'XK01'.
CLEAR : W_RECORD.

ENDLOOP.

FORM BDC_DYNPRO USING PROGRAM DYNPRO.
CLEAR W_BDCDATA.
W_BDCDATA-PROGRAM = PROGRAM.
W_BDCDATA-DYNPRO = DYNPRO.
W_BDCDATA-DYNBEGIN = 'X'.
APPEND W_BDCDATA TO I_BDCDATA.
CLEAR W_BDCDATA.
ENDFORM.

FORM BDC_FIELD USING FNAM FVAL.
* IF FVAL <> NODATA.
CLEAR W_BDCDATA.
W_BDCDATA-FNAM = FNAM.
W_BDCDATA-FVAL = FVAL.
APPEND W_BDCDATA TO I_BDCDATA.
CLEAR W_BDCDATA.
* ENDIF.
ENDFORM.

FORM BDC_TRANSACTION USING TCODE.
CALL TRANSACTION TCODE USING I_BDCDATA
MODE 'N'"CTUMODE'
UPDATE 'S'"CUPDATE
MESSAGES INTO I_MESSTAB.
ENDFORM.

Note: take always new data and once data is entered it will save in SAPDB.

Wednesday, May 18, 2011

ALV HIERARCHICAL List Display

*&---------------------------------------------------------------------*
*& Report ZDEMO_ALVHIER
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT ZDEMO_ALVHIER.


INCLUDE zdemo_alv_top.

START-OF-SELECTION.
PERFORM read_data.
PERFORM fill_key_info.

PERFORM fill_field_catalog using 'it_vbak' 'VBAK'.
PERFORM fill_field_catalog using 'it_vbap' 'VBAP'.

PERFORM display_heirseq_alv.

FORM read_data.
SELECT * INTO TABLE it_vbak from VBAK UP TO 10 ROWS.

if not it_vbak is INITIAL.
SELECT * INTO TABLE it_vbap FROM VBAP FOR ALL ENTRIES IN it_vbak WHERE vbeln = it_vbak-vbeln.
ENDIF.

ENDFORM.

FORM fill_field_catalog USING fp_tabnam TYPE c fp_structure TYPE c.
CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
EXPORTING
I_PROGRAM_NAME = sy-cprog
I_INTERNAL_TABNAME = fp_tabnam
I_STRUCTURE_NAME = fp_structure
* I_CLIENT_NEVER_DISPLAY = 'X'
* I_INCLNAME =
* I_BYPASSING_BUFFER =
* I_BUFFER_ACTIVE =
CHANGING
CT_FIELDCAT = it_fieldcat
* EXCEPTIONS
* INCONSISTENT_INTERFACE = 1
* PROGRAM_ERROR = 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.



FORM fill_key_info.
CLEAR gs_keyinfo.
gs_keyinfo-header01 = 'VBELN'.
gs_keyinfo-item01 = 'VBELN'.
gs_keyinfo-header02 = SPACE.
gs_keyinfo-item02 = 'POSNR'.
ENDFORM.

FORM display_heirseq_alv.
CALL FUNCTION 'REUSE_ALV_HIERSEQ_LIST_DISPLAY'
EXPORTING
* I_INTERFACE_CHECK = ' '
I_CALLBACK_PROGRAM = SY-CPROG
* I_CALLBACK_PF_STATUS_SET = ' '
* I_CALLBACK_USER_COMMAND = ' '
* IS_LAYOUT =
IT_FIELDCAT = it_fieldcat
* IT_EXCLUDING =
* IT_SPECIAL_GROUPS =
* IT_SORT =
* IT_FILTER =
* IS_SEL_HIDE =
* I_SCREEN_START_COLUMN = 0
* I_SCREEN_START_LINE = 0
* I_SCREEN_END_COLUMN = 0
* I_SCREEN_END_LINE = 0
* I_DEFAULT = 'X'
* I_SAVE = ' '
* IS_VARIANT =
* IT_EVENTS =
* IT_EVENT_EXIT =
I_TABNAME_HEADER = 'it_vbak'
I_TABNAME_ITEM = 'it_vbap'
* I_STRUCTURE_NAME_HEADER =
* I_STRUCTURE_NAME_ITEM =
IS_KEYINFO = gs_keyinfo
* IS_PRINT =
* IS_REPREP_ID =
* I_BYPASSING_BUFFER =
* I_BUFFER_ACTIVE =
* IR_SALV_HIERSEQ_ADAPTER =
* IT_EXCEPT_QINFO =
* I_SUPPRESS_EMPTY_DATA = ABAP_FALSE
* IMPORTING
* E_EXIT_CAUSED_BY_CALLER =
* ES_EXIT_CAUSED_BY_USER =
TABLES
T_OUTTAB_HEADER = it_vbak
T_OUTTAB_ITEM = it_vbap
* 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.

ALV Block List

*&---------------------------------------------------------------------*
*& Report ZDEMO_ALVBLOCK
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT ZDEMO_ALVBLOCK.

INCLUDE zdemo_alv_top.

sTART-OF-SELECTION.
list_layout-colwidth_optimize = 'X'.
PERFORM read_data.

end-of-SELECTION.
PERFORM initalize_alv_block.

PERFORM fill_field_catalog using 'IT_T001' 'T001'.
PERFORM append_data_to_alv_block USING 'IT_T001' IT_T001.

REFRESH it_fieldcat.

PERFORM fill_field_catalog using 'IT_KNB1' 'KNB1'.
PERFORM append_data_to_alv_block USING 'IT_KNB1' IT_KNB1.

PERFORM display_blocked_alv.

FORM initalize_alv_block.
CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_INIT'
EXPORTING
I_CALLBACK_PROGRAM = sy-cprog
* I_CALLBACK_PF_STATUS_SET = ' '
* I_CALLBACK_USER_COMMAND = ' '
* IT_EXCLUDING =
.
ENDFORM.

FORM fill_field_catalog USING fp_itab TYPE c fp_structure TYPE c.
CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
EXPORTING
I_PROGRAM_NAME = sy-cprog
I_INTERNAL_TABNAME = fp_itab
I_STRUCTURE_NAME = fp_structure
* I_CLIENT_NEVER_DISPLAY = 'X'
* I_INCLNAME =
* I_BYPASSING_BUFFER =
* I_BUFFER_ACTIVE =
CHANGING
CT_FIELDCAT = it_fieldcat
* EXCEPTIONS
* INCONSISTENT_INTERFACE = 1
* PROGRAM_ERROR = 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.

FORM read_data.
SELECT * INTO TABLE it_t001 from t001 UP TO 10 ROWS.

if not it_t001 is INITIAL.
SELECT * INTO TABLE it_knb1 FROM knb1 FOR ALL ENTRIES IN it_t001 WHERE bukrs = it_t001-bukrs.
ENDIF.

ENDFORM.

FORM append_data_to_alv_block USING fp_tnam TYPE c fp_data TYPE STANDARD TABLE.
CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_APPEND'
EXPORTING
IS_LAYOUT = list_layout
IT_FIELDCAT = it_fieldcat
I_TABNAME = fp_tnam
IT_EVENTS = it_events
* IT_SORT =
* I_TEXT = ' '
TABLES
T_OUTTAB = fp_data
* 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.


FORM display_blocked_alv.
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.
ENDFORM.

Simple ALV List Display Interactive

*&---------------------------------------------------------------------*
*& Report ZDEMO_ALVLIST1
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT ZDEMO_ALVLIST1.


INCLUDE zdemo_alv_top. "copy the alv top as include

PARAMETERS p_bstyp TYPE ebstyp DEFAULT 'F'.

START-OF-SELECTION.
PERFORM read_data_from_ekko.
PERFORM fill_events_tab.

end-of-SELECTION.
PERFORM display_data_using_alv.

*&---------------------------------------------------------------------*
*& Form display_data_using_alv
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
form display_data_using_alv.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
* I_INTERFACE_CHECK = ' '
* I_BYPASSING_BUFFER = ' '
* I_BUFFER_ACTIVE = ' '
I_CALLBACK_PROGRAM = sy-cprog
* I_CALLBACK_PF_STATUS_SET = ' '
* I_CALLBACK_USER_COMMAND = ' '
* I_CALLBACK_TOP_OF_PAGE = ' '
* I_CALLBACK_HTML_TOP_OF_PAGE = ' '
* I_CALLBACK_HTML_END_OF_LIST = ' '
I_STRUCTURE_NAME = 'EKKO'
* I_BACKGROUND_ID = ' '
* I_GRID_TITLE =
* I_GRID_SETTINGS =
* IS_LAYOUT =
* IT_FIELDCAT =
* IT_EXCLUDING =
* IT_SPECIAL_GROUPS =
* IT_SORT =
* IT_FILTER =
* IS_SEL_HIDE =
* I_DEFAULT = 'X'
* I_SAVE = ' '
* IS_VARIANT =
IT_EVENTS = it_events
* IT_EVENT_EXIT =
* IS_PRINT =
* IS_REPREP_ID =
* I_SCREEN_START_COLUMN = 0
* I_SCREEN_START_LINE = 0
* I_SCREEN_END_COLUMN = 0
* I_SCREEN_END_LINE = 0
* I_HTML_HEIGHT_TOP = 0
* I_HTML_HEIGHT_END = 0
* IT_ALV_GRAPHICS =
* IT_HYPERLINK =
* IT_ADD_FIELDCAT =
* IT_EXCEPT_QINFO =
* IR_SALV_FULLSCREEN_ADAPTER =
* IMPORTING
* E_EXIT_CAUSED_BY_CALLER =
* ES_EXIT_CAUSED_BY_USER =
TABLES
T_OUTTAB = it_ekko
* 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_data_using_alv

*&---------------------------------------------------------------------*
*& Form fill_events_tab
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM fill_events_tab.

CLEAR wa_events.
wa_events-name = 'TOP_OF_PAGE'.
wa_events-form = 'PRINT_HEADING'.
APPEND wa_events to it_events.

CLEAR wa_events.
wa_events-name = 'USER_COMMAND'.
wa_events-form = 'VALIDATE_COMMAND'.
APPEND wa_events to it_events.

CLEAR wa_events.
wa_events-name = 'PF_STATUS_SET'.
wa_events-form = 'ATTACH_STATUS'.
APPEND wa_events to it_events.

endform. "fill_events_tab

*&---------------------------------------------------------------------*
*& Form PRINT_HEADING
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM PRINT_HEADING.

data it_headings TYPE slis_t_listheader.
data wa_headings LIKE LINE OF it_headings.

CLEAR wa_headings.
wa_headings-typ = 'H'.
wa_headings-info = 'List of purchasing documents'.
APPEND wa_headings to it_headings.

CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
EXPORTING
IT_LIST_COMMENTARY = it_headings
I_LOGO = 'LOGO'
* I_END_OF_LIST_GRID =
* I_ALV_FORM =
.
ENDFORM. "PRINT_HEADING


*&---------------------------------------------------------------------*
*& Form read_data_from_ekko
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM read_data_from_ekko.
select * INTO TABLE it_ekko FROM ekko UP TO 13 ROWS.
ENDFORM. "read_data_from_ekko

*&---------------------------------------------------------------------*
*& Form VALIDATE_COMMAND
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->UCOMM text
* -->SEL_DET text
*----------------------------------------------------------------------*
FORM VALIDATE_COMMAND USING ucomm LIKE sy-ucomm sel_det TYPE slis_selfield.

case ucomm.
WHEN 'DETAIL'.
IF NOT it_ekko is INITIAL.

SELECT * INTO TABLE IT_EKPO FROM EKPO FOR ALL ENTRIES IN IT_EKKO WHERE EBELN = IT_EKKO-EBELN.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
* I_INTERFACE_CHECK = ' '
* I_BYPASSING_BUFFER = ' '
* I_BUFFER_ACTIVE = ' '
I_CALLBACK_PROGRAM = SY-CPROG
* I_CALLBACK_PF_STATUS_SET = ' '
* I_CALLBACK_USER_COMMAND = ' '
* I_CALLBACK_TOP_OF_PAGE = ' '
* I_CALLBACK_HTML_TOP_OF_PAGE = ' '
* I_CALLBACK_HTML_END_OF_LIST = ' '
I_STRUCTURE_NAME = 'EKPO'
* I_BACKGROUND_ID = ' '
* I_GRID_TITLE =
* I_GRID_SETTINGS =
* IS_LAYOUT =
* IT_FIELDCAT =
* IT_EXCLUDING =
* IT_SPECIAL_GROUPS =
* IT_SORT =
* IT_FILTER =
* IS_SEL_HIDE =
* I_DEFAULT = 'X'
* I_SAVE = ' '
* IS_VARIANT =
IT_EVENTS = IT_EVENTS
* IT_EVENT_EXIT =
* IS_PRINT =
* IS_REPREP_ID =
* I_SCREEN_START_COLUMN = 0
* I_SCREEN_START_LINE = 0
* I_SCREEN_END_COLUMN = 0
* I_SCREEN_END_LINE = 0
* I_HTML_HEIGHT_TOP = 0
* I_HTML_HEIGHT_END = 0
* IT_ALV_GRAPHICS =
* IT_HYPERLINK =
* IT_ADD_FIELDCAT =
* IT_EXCEPT_QINFO =
* IR_SALV_FULLSCREEN_ADAPTER =
* IMPORTING
* E_EXIT_CAUSED_BY_CALLER =
* ES_EXIT_CAUSED_BY_USER =
TABLES
T_OUTTAB = IT_EKPO
* 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.
ENDIF.
ENDCASE.
ENDFORM. "VALIDATE_COMMAND


*&---------------------------------------------------------------------*
*& Form ATTACH_STATUS
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->EX_TAB text
*----------------------------------------------------------------------*
FORM ATTACH_STATUS USING ex_tab TYPE slis_t_extab.
set PF-STATUS 'ZDEMO' EXCLUDING ex_tab.
ENDFORM. "ATTACH_STATUS

ALV TOP

TYPE-POOLS SLIS.
DATA: IT_EKKO LIKE TABLE OF EKKO WITH HEADER LINE,
WA_EKKO LIKE EKKO,

IT_EKPO LIKE TABLE OF EKPO WITH HEADER LINE,
it_csks LIKE TABLE OF csks,
IT_EVENTS TYPE SLIS_T_EVENT,
WA_EVENTS TYPE SLIS_ALV_EVENT,
IT_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV,
IT_T001 LIKE TABLE OF T001,
IT_KNB1 LIKE TABLE OF KNB1,
LIST_LAYOUT TYPE SLIS_LAYOUT_ALV,
GS_KEYINFO TYPE SLIS_KEYINFO_ALV.
DATA IT_FIELDCAT1 TYPE SLIS_T_FIELDCAT_ALV.

data : it_vbak type table of vbak,
it_vbap type table of vbap.