ALV with a lot function

Report ALV_WITH_SOME_FUNCTION.

* You also need to define a Dynpro including a customer container.

TYPE-POOLS:
ABAP.

*———————————————————————–
*— Declaration——————————————————–
*———————————————————————–

* Event Handler f¸r das Sichern und das Markieren
CLASS:
LCL_EVENT_RECIVER DEFINITION DEFERRED.

*— Datenreferenzen ————————————————–
DATA:
GO_EVENT TYPE REF TO LCL_EVENT_RECIVER,
GO_CUS_CNT TYPE REF TO CL_GUI_CUSTOM_CONTAINER,
GO_ALV_GRID TYPE REF TO CL_GUI_ALV_GRID.

*— Dictionary Tabellen ———————————————-
* Batch-Input-Strukturen

*— int. Strukturen die f¸r Typdefinitionen benˆtigt werden. ———

*— int. Typen ——————————————————-
TYPES:
BEGIN OF G_TYPE_CAUFV,
OBJNR TYPE JSTO-OBJNR.
INCLUDE STRUCTURE ZPP_S_VISUALIZE_EXTRACT AS DATA.
TYPES:
END OF G_TYPE_CAUFV.

*— int. Tables/ Structures ——————————————-
DATA:

* Tabelle und Struktur zur Ausgabe der selektierten Werte im ALV
GT_ALV_OUT TYPE TABLE OF ZPP_S_VISUALIZE_EXTRACT,
GS_ALV_OUT LIKE LINE OF GT_ALV_OUT,

* Tabelle und Struktur der selektierten Daten
GT_SEL_AUFV TYPE TABLE OF G_TYPE_CAUFV,
GS_SEL_AUFV LIKE LINE OF GT_SEL_AUFV,

* Tabelle und Struktur f¸r den Auftragsstatus
GT_STATUS TYPE TABLE OF JSTAT,
GS_STATUS LIKE LINE OF GT_STATUS,

* Tabelle und Struktur zum schreiben des Druckstatus
GT_PRN_STAT TYPE TABLE OF ZPP_PRN_STAT,
GS_PRN_STAT LIKE LINE OF GT_PRN_STAT,

GT_FIELDCAT TYPE LVC_T_FCAT,

* Struktur zur Auftragsview
GS_CAUFV LIKE CAUFV,

* Struktur f¸r die Variante im ALV
GS_VARIANT TYPE DISVARIANT,
GS_LAYOUT TYPE LVC_S_LAYO,

* Definition f¸r die Toolbar
GS_TOOLBAR TYPE STB_BUTTON.

*— Feldsymbole —————————————————–
FIELD-SYMBOLS:
<LS_ALV_OUT> TYPE ZPP_S_VISUALIZE_EXTRACT,
<GS_SEL_AUFV> TYPE G_TYPE_CAUFV.

*— Variables ——————————————————–
DATA:
GV_STAT_FREI TYPE J_ISTAT,
GV_STAT_RUECK TYPE J_ISTAT,
GV_CUST_LIST TYPE SCRFNAME VALUE ‘CUST_LIST’, “Dynpro 0100
GV_OKCODE TYPE SYUCOMM,
GV_PDEST TYPE SYPDEST.

*— Constants ——————————————————–
CONSTANTS:
GC_RUECK TYPE J_TXT04 VALUE ‘R‹CK’,
GC_FREI TYPE J_TXT04 VALUE ‘FREI’,
GC_STRUCTURE TYPE TABNAME VALUE ‘ZPP_S_VISUALIZE_EXTRACT’.

*— Ranges/Selektionshilfen ——————————————

*— Locale Klassen definition ————————————–
CLASS:
LCL_EVENT_RECIVER DEFINITION.

PUBLIC SECTION.
METHODS HANDLE_HOTSPOT_CLICK
FOR EVENT HOTSPOT_CLICK OF CL_GUI_ALV_GRID
IMPORTING ES_ROW_NO.
METHODS HANDLE_USER_COMMAND
FOR EVENT USER_COMMAND OF CL_GUI_ALV_GRID
IMPORTING E_UCOMM.
METHODS HANDLE_TOOLBAR
FOR EVENT TOOLBAR OF CL_GUI_ALV_GRID
IMPORTING E_OBJECT.

ENDCLASS. “LCL_EVENT_RECIVER DEFINITION
*— Locale Klassen Implementation ———————————-
CLASS:
LCL_EVENT_RECIVER IMPLEMENTATION.

METHOD HANDLE_HOTSPOT_CLICK.
PERFORM MARK_FIELD USING ES_ROW_NO-ROW_ID.
ENDMETHOD. “handle_hotspot_click

METHOD HANDLE_USER_COMMAND.
PERFORM USER_COMMAND USING E_UCOMM.
ENDMETHOD. “handle_user_command

METHOD HANDLE_TOOLBAR.
PERFORM TOOLBAR USING E_OBJECT.
ENDMETHOD. “handle_toolbar

ENDCLASS. “lcl_event_reciver IMPLEMENTATION
*———————————————————————–
*— Selection Screen ————————————————-
*———————————————————————–
SELECTION-SCREEN BEGIN OF BLOCK SELEKTION
WITH FRAME TITLE TEXT-F01. ” Selektion
SELECT-OPTIONS:
S_AUFNR FOR GS_ALV_OUT-AUFNR,
S_WERKS FOR GS_ALV_OUT-WERKS NO INTERVALS,
S_PRDHA FOR GS_ALV_OUT-PRDHA NO INTERVALS,
S_GSTRP FOR GS_ALV_OUT-GSTRP.

SELECTION-SCREEN SKIP 1.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 1(31) TEXT-P01 FOR FIELD P_LOKA.
PARAMETERS: P_LOKA TYPE ZPP_LOCATION
MATCHCODE OBJECT ZPP_LOCA
OBLIGATORY.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 1(31) TEXT-P02 FOR FIELD P_FOPNT.
PARAMETERS: P_FOPNT AS CHECKBOX.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN END OF BLOCK SELEKTION.

SELECTION-SCREEN SKIP 1.
SELECTION-SCREEN BEGIN OF BLOCK AUSGABE
WITH FRAME TITLE TEXT-F02. ” Ausgabe
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 1(31) TEXT-P05 FOR FIELD P_TRENN.
PARAMETERS P_TRENN(1) DEFAULT ‘;’.
SELECTION-SCREEN END OF LINE.
*SELECTION-SCREEN BEGIN OF LINE. ( HOST-File )
*SELECTION-SCREEN COMMENT 1(31) TEXT-P03 FOR FIELD P_LOCAL.( HOST-File )
*PARAMETERS P_LOCAL RADIOBUTTON GROUP OUT ( HOST-File )
* USER-COMMAND OUT ( HOST-File )
* DEFAULT ‘X’. ( HOST-File )
*SELECTION-SCREEN END OF LINE. ( HOST-File )

PARAMETERS P_DSN_L TYPE FILEEXTERN MODIF ID LOC
DEFAULT ‘\\10.33.15.110\’.

*SELECTION-SCREEN BEGIN OF LINE. ( HOST-File )
*SELECTION-SCREEN COMMENT 1(31) TEXT-P04 FOR FIELD P_HOST. ( HOST-File )
*PARAMETERS P_HOST RADIOBUTTON GROUP. ( HOST-File )
*SELECTION-SCREEN END OF LINE. ( HOST-File )
*
*PARAMETERS P_DSN_H TYPE FILEINTERN MODIF ID HST. ( HOST-File )
SELECTION-SCREEN END OF BLOCK AUSGABE.

*———————————————————————–
*— Processing ——————————————————–
*———————————————————————–
*———————————————————————–
* INITIALIZATION.
*———————————————————————–
INITIALIZATION.
* Vorbelegen der Produkthirarchie f¸r Transaktionsbatterien
S_PRDHA-LOW = ‘1101*’.
S_PRDHA-SIGN = ‘I’.
S_PRDHA-OPTION = ‘CP’.
APPEND S_PRDHA.
*———————————————————————–
* AT SELECTION-SCREEN.
*———————————————————————–

*———————————————————————–
* AT SELECTION-SCREEN OUTPUT.
*———————————————————————–
AT SELECTION-SCREEN OUTPUT.

* CASE ABAP_TRUE. ( HOST-File )
* WHEN P_LOCAL. ( HOST-File )
LOOP AT SCREEN.
CASE SCREEN-GROUP1.
WHEN ‘LOC’.
SCREEN-INPUT = 1.
SCREEN-ACTIVE = 1.
WHEN ‘HST’.
SCREEN-INPUT = 0.
SCREEN-ACTIVE = 0.
ENDCASE.
MODIFY SCREEN.
ENDLOOP.
* WHEN P_HOST. ( HOST-File )
* LOOP AT SCREEN. ( HOST-File )
* CASE SCREEN-GROUP1. ( HOST-File )
* WHEN ‘LOC’. ( HOST-File )
* SCREEN-INPUT = 0. ( HOST-File )
* SCREEN-ACTIVE = 0. ( HOST-File )
* WHEN ‘HST’. ( HOST-File )
* SCREEN-INPUT = 1. ( HOST-File )
* SCREEN-ACTIVE = 1. ( HOST-File )
* ENDCASE. ( HOST-File )
* MODIFY SCREEN. ( HOST-File )
* ENDLOOP. ( HOST-File )
* ENDCASE. ( HOST-File )
*———————————————————————–
* AT SELECTION-SCREEN ON BLOCK
*———————————————————————–

*———————————————————————–
* AT SELECTION-SCREEN ON VALUE-REQUEST FOR
*———————————————————————–
AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_DSN_L.

DATA:
LV_TITLE TYPE STRING,
LV_FILENAME TYPE STRING,
LV_PATH TYPE STRING,
LV_FULLPATH TYPE STRING.

LV_TITLE = ‘Speicherort'(001).
LV_FILENAME = P_DSN_L.
CALL METHOD CL_GUI_FRONTEND_SERVICES=>FILE_SAVE_DIALOG
EXPORTING
WINDOW_TITLE = LV_TITLE
DEFAULT_FILE_NAME = LV_FILENAME
CHANGING
FILENAME = LV_FILENAME
PATH = LV_PATH
FULLPATH = LV_FULLPATH.
P_DSN_L = LV_FULLPATH.

*———————————————————————–
* DEFINE MACROS
*———————————————————————–
DEFINE GET_STATUS.
SELECT
SINGLE ISTAT
FROM TJ02T:
INTO &1
WHERE SPRAS = ‘DE’
AND TXT04 = GC_FREI,
INTO &2
WHERE SPRAS = ‘DE’
AND TXT04 = GC_RUECK.
END-OF-DEFINITION.

*eject
*———————————————————————–
* START-OF-SELECTION.
*———————————————————————–
START-OF-SELECTION.

* CASE ABAP_TRUE. ( HOST-File )
* WHEN P_LOCAL. ( HOST-File )
IF P_DSN_L IS INITIAL.
* Bitte den lokalen Dateinamen angeben
MESSAGE E040.
ENDIF.
* WHEN P_HOST. ( HOST-File )
** Bitte den logischen Dateinamen angeben ( HOST-File )
* IF P_DSN_H IS INITIAL. ( HOST-File )
* MESSAGE E041. ( HOST-File )
* ENDIF. ( HOST-File )
* ENDCASE. ( HOST-File )

GET_STATUS GV_STAT_FREI GV_STAT_RUECK.

*———————————————————————–
* Verarbeitungsbeginn
*———————————————————————–
PERFORM SELEKTIEREN_DATEN.

PERFORM CHECK_DATEN.

*———————————————————————–
* END-OF-SELECTION.
*———————————————————————–
END-OF-SELECTION.

PERFORM ALV_AUSGABE.
*eject
*———————————————————————–
*— Subprograms ——————————————————-
*———————————————————————–
*&———————————————————————*
*& Form SELEKTIEREN_DATEN
*&———————————————————————*
* text
*———————————————————————-*
* –> p1 text
* <– p2 text
*———————————————————————-*
FORM SELEKTIEREN_DATEN .

SELECT *
FROM CAUFV
INTO GS_CAUFV
WHERE AUFNR IN S_AUFNR ” Auftragsnummer
AND WERKS IN S_WERKS ” Werk
AND GSTRP IN S_GSTRP. ” Eck-Starttermin
MOVE-CORRESPONDING GS_CAUFV TO GS_SEL_AUFV.

* Nun werden noch die Materialkurztexte benˆtigt
SELECT
SINGLE MAKTX
INTO GS_SEL_AUFV-MAKTX
FROM MAKT
WHERE MATNR = GS_CAUFV-PLNBEZ
AND SPRAS = SY-LANGU.

INSERT GS_SEL_AUFV INTO TABLE GT_SEL_AUFV.

ENDSELECT.

SELECT
SINGLE PDEST
FROM ZPP_VIS_LOC
INTO GV_PDEST
WHERE LOCATION = P_LOKA.

ENDFORM. ” SELEKTIEREN_DATEN
*&———————————————————————*
*& Form CHECK_DATEN
*&———————————————————————*
* text
*———————————————————————-*
* –> p1 text
* <– p2 text
*———————————————————————-*
FORM CHECK_DATEN .

DATA:
LFL_FREI TYPE FLAG,
LFL_RUECK TYPE FLAG,
LV_PRDHA TYPE PRODH_D,
LV_DRUCK TYPE ZPP_DRUCK.

CLEAR LV_PRDHA.

* Filtern nach Produkthirarchie
LOOP AT GT_SEL_AUFV ASSIGNING <GS_SEL_AUFV>.

* Lesen des Materialstamms
SELECT
SINGLE PRDHA
FROM MARA
INTO LV_PRDHA
WHERE MATNR = <GS_SEL_AUFV>-PLNBEZ
AND PRDHA IN S_PRDHA.
IF NOT SY-SUBRC IS INITIAL.
DELETE GT_SEL_AUFV.
ELSE.
<GS_SEL_AUFV>-PRDHA = LV_PRDHA.
ENDIF.

ENDLOOP.

* Nur wenn das Kennzeichen FORCE PRINT gesetz wurde
* soll auf jeden Fall gedruckt werden.
IF P_FOPNT = ABAP_FALSE.
LOOP AT GT_SEL_AUFV INTO GS_SEL_AUFV.
SELECT
SINGLE DRUCK
FROM ZPP_PRN_STAT
INTO LV_DRUCK
WHERE AUFNR = GS_SEL_AUFV-AUFNR.
IF SY-SUBRC IS INITIAL AND
LV_DRUCK = ABAP_TRUE.
DELETE GT_SEL_AUFV.
ENDIF.
ENDLOOP.
ENDIF.

* Filtern nach Auftragsstatus.
LOOP AT GT_SEL_AUFV INTO GS_SEL_AUFV.

* Lesen des Status zum Auftrag
CALL FUNCTION ‘STATUS_READ’
EXPORTING
CLIENT = SY-MANDT
OBJNR = GS_SEL_AUFV-OBJNR
ONLY_ACTIVE = ABAP_TRUE
TABLES
STATUS = GT_STATUS
EXCEPTIONS
OBJECT_NOT_FOUND = 1
OTHERS = 2.
IF SY-SUBRC <> 0.
WRITE: / ‘Kein Status zum Auftrag ermittelbar'(001),
GS_SEL_AUFV-AUFNR.
DELETE GT_SEL_AUFV.
CONTINUE.
ENDIF.

* Initialisieren der Statusschalter
LFL_FREI = LFL_RUECK = ABAP_FALSE.

* Pr¸fen von Status in der Statustabelle
LOOP AT GT_STATUS INTO GS_STATUS
WHERE STAT = GV_STAT_FREI
OR STAT = GV_STAT_RUECK.

IF GS_STATUS-STAT = GV_STAT_FREI.
LFL_FREI = ABAP_TRUE.
ENDIF.

IF GS_STATUS-STAT = GV_STAT_RUECK.
LFL_RUECK = ABAP_TRUE.
ENDIF.

ENDLOOP.

* Wenn der Status ‘FREI’ nicht gesetzt wurde bzw.
* der Status ‘R‹CK’ gesetzt wurde, dann mufl der Satz
* aus der Tabelle gelˆscht werden.
IF LFL_FREI = ABAP_FALSE OR
LFL_RUECK = ABAP_TRUE.
DELETE GT_SEL_AUFV.
ENDIF.

ENDLOOP.

ENDFORM. ” CHECK_DATEN
*&———————————————————————*
*& Form ALV_AUSGABE
*&———————————————————————*
* text
*———————————————————————-*
* –> p1 text
* <– p2 text
*———————————————————————-*
FORM ALV_AUSGABE.

* Bef¸llen der Ausgabestruktur.
LOOP AT GT_SEL_AUFV INTO GS_SEL_AUFV.
GS_ALV_OUT = GS_SEL_AUFV-DATA.
INSERT GS_ALV_OUT INTO TABLE GT_ALV_OUT.
ENDLOOP.

CALL SCREEN 0100.

ENDFORM. ” ALV_AUSGABE
*&———————————————————————*
*& Form MARK_FIELD
*&———————————————————————*
* text
*———————————————————————-*
* –>P_E_ROW_INDEX text
*———————————————————————-*
FORM MARK_FIELD USING PIV_ROW_ID.

DATA:
* ALV-Control: Refresh-Stabilit‰t
LS_STBL TYPE LVC_S_STBL.

READ TABLE GT_ALV_OUT ASSIGNING <LS_ALV_OUT>
INDEX PIV_ROW_ID.
IF <LS_ALV_OUT>-FLAG IS INITIAL.
<LS_ALV_OUT>-FLAG = ABAP_TRUE.
ELSE.
<LS_ALV_OUT>-FLAG = ABAP_FALSE.
ENDIF.

* Die Daten haben sich ge‰ndert also muss
* nun der ALV wieder aufgefrischt werden.
LS_STBL-ROW = ABAP_TRUE.
CALL METHOD GO_ALV_GRID->REFRESH_TABLE_DISPLAY
EXPORTING
IS_STABLE = LS_STBL.

ENDFORM. ” MARK_FIELD
*&———————————————————————*
*& Form USER_COMMAND
*&———————————————————————*
* text
*———————————————————————-*
* –> p1 text
* <– p2 text
*———————————————————————-*
FORM USER_COMMAND USING PIV_UCOMM TYPE SYUCOMM.

DATA:
LT_ROWS TYPE LVC_T_ROW,
LV_REPID TYPE SYREPID.

LV_REPID = SY-REPID.

CASE PIV_UCOMM.
WHEN ‘PRI’.
* Anstossen der Ausgabe und des Beschreibens
* der Tabelle ZPP_PRN_STAT
PERFORM OUTPUT_TO_FILE.
WHEN ‘SAL’.
PERFORM SELEKTIEREN USING ‘X’.
WHEN ‘DAL’.
PERFORM SELEKTIEREN USING ‘ ‘.
WHEN ‘INF’.
PERFORM INFO_DISPLAY.
ENDCASE.

ENDFORM. ” USER_COMMAND
*&———————————————————————*
*& Form TOOLBAR
*&———————————————————————*
* text
*———————————————————————-*
* –>P_E_OBJECT text
*———————————————————————-*
FORM TOOLBAR USING PIO_OBJECT TYPE REF TO CL_ALV_EVENT_TOOLBAR_SET.

* Einf¸gen eines Trennzeichens
CLEAR GS_TOOLBAR.
GS_TOOLBAR-BUTN_TYPE = 3.
APPEND GS_TOOLBAR TO PIO_OBJECT->MT_TOOLBAR.

* Button f¸r den Druck
CLEAR GS_TOOLBAR.
GS_TOOLBAR-BUTN_TYPE = 0.
GS_TOOLBAR-FUNCTION = ‘PRI’.
GS_TOOLBAR-ICON = ICON_PRINT.
GS_TOOLBAR-QUICKINFO = ‘Druck'(003).
GS_TOOLBAR-DISABLED = ABAP_FALSE.
APPEND GS_TOOLBAR TO PIO_OBJECT->MT_TOOLBAR.

* Button alle selektieren
CLEAR GS_TOOLBAR.
GS_TOOLBAR-BUTN_TYPE = 0.
GS_TOOLBAR-FUNCTION = ‘SAL’.
GS_TOOLBAR-ICON = ICON_SELECT_ALL.
GS_TOOLBAR-QUICKINFO = ‘Alles markieren'(004).
GS_TOOLBAR-DISABLED = ABAP_FALSE.
APPEND GS_TOOLBAR TO PIO_OBJECT->MT_TOOLBAR.

* Button alle selektionen lˆschen
CLEAR GS_TOOLBAR.
GS_TOOLBAR-BUTN_TYPE = 0.
GS_TOOLBAR-FUNCTION = ‘DAL’.
GS_TOOLBAR-ICON = ICON_DESELECT_ALL.
GS_TOOLBAR-QUICKINFO = ‘Alle Mark. lˆschen'(005).
GS_TOOLBAR-DISABLED = ABAP_FALSE.
APPEND GS_TOOLBAR TO PIO_OBJECT->MT_TOOLBAR.

* Button f¸r die Dokumentation
CLEAR GS_TOOLBAR.
GS_TOOLBAR-BUTN_TYPE = 0.
GS_TOOLBAR-FUNCTION = ‘INF’.
GS_TOOLBAR-ICON = ICON_INFORMATION.
GS_TOOLBAR-QUICKINFO = ‘Info'(006).
GS_TOOLBAR-DISABLED = ABAP_FALSE.
APPEND GS_TOOLBAR TO PIO_OBJECT->MT_TOOLBAR.

ENDFORM. ” TOOLBAR
*&———————————————————————*
*& Module PBO_0100 OUTPUT
*&———————————————————————*
* text
*———————————————————————-*
MODULE PBO_0100 OUTPUT.

DATA:
LT_TOOLBAR_EXCLUDING TYPE UI_FUNCTIONS,
LS_TOOLBAR_EXCLUDING TYPE UI_FUNC.

* Anpassen der Feldliste
PERFORM FELDLISTE_ALV TABLES GT_FIELDCAT.

SET PF-STATUS ‘ALV_0100′.

IF NOT GO_CUS_CNT IS BOUND.

* Men¸button die aus dem standard ausgeblendet werden sollen
LS_TOOLBAR_EXCLUDING = ‘&PRINT_BACK’.
INSERT LS_TOOLBAR_EXCLUDING INTO TABLE LT_TOOLBAR_EXCLUDING.
LS_TOOLBAR_EXCLUDING = ‘&DETAIL’.
INSERT LS_TOOLBAR_EXCLUDING INTO TABLE LT_TOOLBAR_EXCLUDING.
LS_TOOLBAR_EXCLUDING = ‘&MB_SUM’.
INSERT LS_TOOLBAR_EXCLUDING INTO TABLE LT_TOOLBAR_EXCLUDING.
LS_TOOLBAR_EXCLUDING = ‘&MB_SUBTOT’.
INSERT LS_TOOLBAR_EXCLUDING INTO TABLE LT_TOOLBAR_EXCLUDING.
LS_TOOLBAR_EXCLUDING = ‘&MB_VIEW’.
INSERT LS_TOOLBAR_EXCLUDING INTO TABLE LT_TOOLBAR_EXCLUDING.
LS_TOOLBAR_EXCLUDING = ‘&MB_EXPORT’.
INSERT LS_TOOLBAR_EXCLUDING INTO TABLE LT_TOOLBAR_EXCLUDING.
LS_TOOLBAR_EXCLUDING = ‘&GRAPH’.
INSERT LS_TOOLBAR_EXCLUDING INTO TABLE LT_TOOLBAR_EXCLUDING.
LS_TOOLBAR_EXCLUDING = ‘&INFO’.
INSERT LS_TOOLBAR_EXCLUDING INTO TABLE LT_TOOLBAR_EXCLUDING.

* Varianten zum speichern vorbereiten
GS_VARIANT-REPORT = SY-REPID.

CREATE OBJECT GO_CUS_CNT
EXPORTING
CONTAINER_NAME = GV_CUST_LIST.
CREATE OBJECT GO_ALV_GRID
EXPORTING
I_PARENT = GO_CUS_CNT.

CALL METHOD GO_ALV_GRID->SET_TABLE_FOR_FIRST_DISPLAY
EXPORTING
I_STRUCTURE_NAME = GC_STRUCTURE
IS_VARIANT = GS_VARIANT
I_SAVE = ‘X’
IS_LAYOUT = GS_LAYOUT
IT_TOOLBAR_EXCLUDING = LT_TOOLBAR_EXCLUDING
CHANGING
IT_OUTTAB = GT_ALV_OUT
IT_FIELDCATALOG = GT_FIELDCAT
EXCEPTIONS
INVALID_PARAMETER_COMBINATION = 1
PROGRAM_ERROR = 2
TOO_MANY_LINES = 3
OTHERS = 4.
IF SY-SUBRC <> 0.
* Fehler bei der Ausgabe des ALV. Returncode &.
MESSAGE E045 WITH SY-SUBRC.
ENDIF.

ENDIF.

* Nun noch die Objecte f¸r den Handler
CREATE OBJECT GO_EVENT.
SET HANDLER GO_EVENT->HANDLE_HOTSPOT_CLICK FOR GO_ALV_GRID.
SET HANDLER GO_EVENT->HANDLE_USER_COMMAND FOR GO_ALV_GRID.
SET HANDLER GO_EVENT->HANDLE_TOOLBAR FOR GO_ALV_GRID.

* Nun muss noch die Toolbar gesetzt werden.
CALL METHOD GO_ALV_GRID->SET_TOOLBAR_INTERACTIVE.

ENDMODULE. ” PBO_0100 OUTPUT
*&———————————————————————*
*& Module PAI_0100 INPUT
*&———————————————————————*
* text
*———————————————————————-*
MODULE PAI_0100 INPUT.

CASE GV_OKCODE.
WHEN ‘BACK’.
CALL METHOD GO_CUS_CNT->FREE.
CALL METHOD CL_GUI_CFW=>FLUSH.
LEAVE TO TRANSACTION SY-TCODE.
WHEN ‘ABBR’.
CALL METHOD GO_CUS_CNT->FREE.
CALL METHOD CL_GUI_CFW=>FLUSH.
LEAVE PROGRAM.
ENDCASE.

ENDMODULE. ” PAI_0100 INPUT
*&———————————————————————*
*& Form FELDLISTE_ALV
*&———————————————————————*
* text
*———————————————————————-*
* –>P_GT_FIELDCAT text
*———————————————————————-*
FORM FELDLISTE_ALV TABLES PT_FIELDCAT TYPE LVC_T_FCAT.

FIELD-SYMBOLS:
<LS_FIELDCAT> TYPE LVC_S_FCAT.

* Setzen diverser Layout eigenschaften
* kleine Titelzeile
GS_LAYOUT-SMALLTITLE = ‘X’.
* optimale Spaltenbreite
GS_LAYOUT-CWIDTH_OPT = ‘X’.
* ‹berschrift des ALV
GS_LAYOUT-GRID_TITLE = TEXT-002.
* Liste gestreift ausgeben
GS_LAYOUT-ZEBRA = ‘X’.

* Erstellen des Feldkatalogs
CALL FUNCTION ‘LVC_FIELDCATALOG_MERGE’
EXPORTING
I_STRUCTURE_NAME = GC_STRUCTURE
CHANGING
CT_FIELDCAT = GT_FIELDCAT.

LOOP AT GT_FIELDCAT ASSIGNING <LS_FIELDCAT>.
IF <LS_FIELDCAT>-FIELDNAME = ‘FLAG’.
<LS_FIELDCAT>-HOTSPOT = ‘X’.
<LS_FIELDCAT>-CHECKBOX = ‘X’.
ENDIF.
ENDLOOP.

ENDFORM. ” FELDLISTE_ALV
*&———————————————————————*
*& Form SELEKTIEREN
*&———————————————————————*
* text
*———————————————————————-*
* –>P_0845 text
*———————————————————————-*
FORM SELEKTIEREN USING PIV_ACTIV.

DATA:
* ALV-Control: Refresh-Stabilit‰t
LS_STBL TYPE LVC_S_STBL.

LOOP AT GT_ALV_OUT ASSIGNING <LS_ALV_OUT>.
<LS_ALV_OUT>-FLAG = PIV_ACTIV.
ENDLOOP.

* Nun wieder auffrischen des ALV
LS_STBL-ROW = ABAP_TRUE.
CALL METHOD GO_ALV_GRID->REFRESH_TABLE_DISPLAY
EXPORTING
IS_STABLE = LS_STBL.

ENDFORM. ” SELEKTIEREN
*&———————————————————————*
*& Form INFO_DISPLAY
*&———————————————————————*
* text
*———————————————————————-*
* –> p1 text
* <– p2 text
*———————————————————————-*
FORM INFO_DISPLAY .

* Anzeigen der Reportdokumentation
DATA:
LS_INFO TYPE HELP_INFO,
LT_DSELC TYPE TABLE OF DSELC WITH HEADER LINE,
LT_VALTB TYPE TABLE OF DVAL WITH HEADER LINE.

LS_INFO-CALL = ‘H’.
LS_INFO-OBJECT = ‘F’.
LS_INFO-PROGRAM = SY-CPROG.
LS_INFO-DYNPRO = SY-DYNNR.
LS_INFO-SPRAS = SY-LANGU.
LS_INFO-MENUFUNCT = ‘ERHI’.
LS_INFO-TCODE = SY-TCODE.
LS_INFO-PFKEY = ‘0100’.
LS_INFO-DOCUID = ‘FE’.
LS_INFO-DYNPPROG = SY-CPROG.

CALL FUNCTION ‘HELP_START’
EXPORTING
HELP_INFOS = LS_INFO
TABLES
DYNPSELECT = LT_DSELC
DYNPVALUETAB = LT_VALTB.

ENDFORM. ” INFO_DISPLAY
*&———————————————————————*
*& Form OUTPUT_TO_FILE
*&———————————————————————*
* text
*———————————————————————-*
* –> p1 text
* <– p2 text
*———————————————————————-*
FORM OUTPUT_TO_FILE .

DATA:
LV_FILENAME TYPE STRING,
LV_ZEINR TYPE DZEINR,
LT_OUT TYPE TABLE OF STRING,
LS_OUT LIKE LINE OF LT_OUT,
LV_ZAEHL TYPE I.

CLEAR LV_ZAEHL.
LOOP AT GT_ALV_OUT INTO GS_ALV_OUT
WHERE FLAG = ABAP_TRUE.
* initialisieren der ‹bergabetabelle und des Dateinamens
CLEAR: LT_OUT, LS_OUT, LV_FILENAME.
* Lesen der Zeichnungsnummer
SELECT
SINGLE ZZMM_ZEINR
FROM MARC
INTO LV_ZEINR
WHERE MATNR = GS_ALV_OUT-PLNBEZ
AND WERKS = GS_ALV_OUT-WERKS.
* Zusammensetzen des Dateinamens mit Pfad.
CONCATENATE P_DSN_L P_LOKA GS_ALV_OUT-AUFNR SY-DATUM SY-UZEIT ‘.DAT’
INTO LV_FILENAME.
* Entfernen aller Leerzeichen aus dem Dateinamen
CONDENSE LV_FILENAME NO-GAPS.
* Zusammensetzen des Dateiinhalts.
CONCATENATE GS_ALV_OUT-AUFNR P_TRENN
LV_ZEINR P_TRENN
GV_PDEST P_TRENN
INTO LS_OUT.
INSERT LS_OUT INTO TABLE LT_OUT.
* ‹bergeben der Datei an den Pr‰sentationsserver
CALL FUNCTION ‘GUI_DOWNLOAD’
EXPORTING
FILENAME = LV_FILENAME
FILETYPE = ‘ASC’
WRITE_FIELD_SEPARATOR = ‘X’
DAT_MODE = ‘X’
TABLES
DATA_TAB = LT_OUT.
ADD 1 TO LV_ZAEHL.
* Updaten der Tabelle ZPP_PRN_STAT.
CLEAR GS_PRN_STAT.
SELECT
SINGLE *
FROM ZPP_PRN_STAT
INTO GS_PRN_STAT
WHERE AUFNR = GS_ALV_OUT-AUFNR.
IF SY-SUBRC IS INITIAL.
GS_PRN_STAT-AENDT = SY-DATUM.
GS_PRN_STAT-AENNM = SY-UNAME.
GS_PRN_STAT-LOCATION = P_LOKA.
GS_PRN_STAT-DRUCK = ABAP_TRUE.
MODIFY ZPP_PRN_STAT FROM GS_PRN_STAT.
ELSE.
GS_PRN_STAT-AUFNR = GS_ALV_OUT-AUFNR.
GS_PRN_STAT-LOCATION = P_LOKA.
GS_PRN_STAT-DRUCK = ABAP_TRUE.
GS_PRN_STAT-DATUM = SY-DATUM.
GS_PRN_STAT-UNAME = SY-UNAME.
INSERT ZPP_PRN_STAT FROM GS_PRN_STAT.
ENDIF.
ENDLOOP.

CASE LV_ZAEHL.
WHEN 0.
* Es wurde keine Datei erstellt.
MESSAGE I043.
WHEN 1.
* Es wurde & Datei erstellt.
MESSAGE I044 WITH LV_ZAEHL.
WHEN OTHERS.
* Es wurden & Dateien erstellt.
MESSAGE I042 WITH LV_ZAEHL.
ENDCASE.
LEAVE TO TRANSACTION SY-TCODE.

ENDFORM. ” OUTPUT_TO_FILE

Kommentar abgeben: