60 Flares Twitter 0 Facebook 60 Google+ 0 LinkedIn 0 Email -- Pin It Share 0 60 Flares ×

OBJECT: Retrieve the  VBELN, ERDAT, ERZET, ERNAM,ANGDT fields data from VBAK  based on the selection screen sales order number(VBELN) and VBELN, POSNR, MATNR, MATWA fields data from VBAP based on the VBAK VBELN and populate the data into final internal table while displaying  the data place check box for each and every record and create download and delete function keys, If user clicks on the download button then I want to download the selected fields into C drive (or) D drive if use click the delete button then I want delete the selected fields from database.

Source Code:

*&———————————————————————*
*& Report  ZCheckbox_NORMAL_REPORT
*&
*&———————————————————————*
*&
*&
*&———————————————————————*

REPORT  ZCheckbox_normal_report NO STANDARD PAGE HEADING .

INITIALIZATION.
*//Tables Declaration
TABLES:vbak.

*//Types Dclaration For Vbak
TYPES:BEGIN OF ty_vbak,
vbeln  TYPE vbeln_va,
erdat  TYPE erdat,
erzet  TYPE erzet,
ernam  TYPE ernam,
angdt  TYPE angdt_v,
END OF ty_vbak.

*//Types Declaration For VBAP
TYPES:BEGIN OF ty_vbap,
vbeln  TYPE vbeln_va,
posnr  TYPE posnr_va,
matnr  TYPE matnr,
matwa  TYPE matwa,
END OF ty_vbap.
*//Final Types
TYPES:BEGIN OF ty_final,
vbeln  TYPE vbeln_va,
erdat  TYPE erdat,
erzet  TYPE erzet,
ernam  TYPE ernam,
angdt  TYPE angdt_v,
posnr  TYPE posnr_va,
matnr  TYPE matnr,
matwa  TYPE matwa,
end of ty_final.

*//Internal Table Declaration
DATA:lt_vbak      TYPE TABLE OF ty_vbak,
lt_vbap      TYPE TABLE OF ty_vbap,
lt_final      TYPE TABLE OF ty_final,
lt_final1     TYPE TABLE OF ty_final.

*//Work Area Dclaration
DATA:wa_vbak      TYPE ty_vbak,
wa_vbap      TYPE ty_vbap,
wa_final      TYPE ty_final,
wa_final1      TYPE ty_final.

DATA:a,v2,v3.

*//Selection screen Design
SELECTION-SCREEN BEGIN OF BLOCK blk1 WITH FRAME.
SELECT-OPTIONS:s_vbeln FOR vbak-vbeln .
SELECTION-SCREEN END OF BLOCK blk1.

START-OF-SELECTION.
*//Validate The Selection Screen
IF s_vbeln IS NOT INITIAL.
*//Retrieve Data Form VBAK
*    set pf-STATUS ‘ZMENU’.
SELECT vbeln erdat erzet ernam angdt
FROM vbak
INTO TABLE lt_vbak
WHERE vbeln IN s_vbeln.
*//Retrieve data from VBAP
if lt_vbak IS NOT INITIAL.
SELECT vbeln posnr matnr matwa
FROM vbap
INTO TABLE lt_vbap
WHERE vbeln EQ wa_vbak-vbeln.
endif.
ELSE.
MESSAGE ID ‘YMYMSG’ TYPE ‘E’ NUMBER ‘007’.
ENDIF.

*//populate data into final internal table
LOOP at lt_vbap into wa_vbap.
READ TABLE lt_vbak INTO wa_vbak with KEY vbeln = wa_vbap-vbeln.
if sy-subrc eq 0.
wa_final-vbeln = wa_vbak-vbeln.
wa_final-erdat = wa_vbak-erdat.
wa_final-erzet = wa_vbak-erzet.
wa_final-ernam = wa_vbak-ernam.
wa_final-angdt = wa_vbak-angdt.
wa_final-posnr = wa_vbap-posnr.
wa_final-matnr = wa_vbap-matnr.
wa_final-matwa = wa_vbap-matwa.
ENDIF.
append wa_final to lt_final.
clear wa_final.
ENDLOOP.

*//Displaying Data
LOOP AT lt_vbak INTO wa_vbak.
WRITE:/ a AS CHECKBOX ,wa_vbak-vbeln,wa_vbak-erdat,wa_vbak-erzet,wa_vbak-ernam,wa_vbak-angdt,wa_vbap-posnr,wa_vbap-matnr,wa_vbap-matwa.
*  hide : wa_vbak-vbeln,wa_vbak-erdat.

ENDLOOP.
DATA w3 TYPE sy-linno.
SET PF-STATUS ‘ZMENU’.
w3 = sy-linno.

AT USER-COMMAND.
IF sy-ucomm EQ ‘DOWN’.
DO w3 TIMES.
READ LINE sy-index FIELD VALUE a INTO v2
wa_vbak-vbeln INTO wa_final1-vbeln
wa_vbak-erdat INTO wa_final1-erdat
wa_vbak-erzet INTO wa_final1-erzet
wa_vbak-ernam INTO wa_final1-ernam
wa_vbak-angdt INTO wa_final1-angdt
wa_vbap-posnr INTO wa_final1-posnr.
IF v2 = ‘X’.
APPEND wa_final1 TO lt_final1.
ENDIF.

ENDDO.
*//Downloading selected fields data
CALL FUNCTION ‘GUI_DOWNLOAD’
EXPORTING
filename              = ‘C:\Documents and Settings\Pavan\Desktop\vishnu.txt’
filetype              = ‘ASC’
write_field_separator = ‘|’
TABLES
data_tab              = lt_final1.

 

ELSEIF sy-ucomm EQ ‘DELETE’.
DO w3 TIMES.
READ LINE sy-index FIELD VALUE a INTO v2
wa_vbak-vbeln INTO v3.

IF v2 = ‘X’.
DELETE FROM vbak WHERE vbeln = v3.
ENDIF.
ENDDO.
ENDIF.

IF sy-subrc EQ 0.
MESSAGE ‘SUCCESS’ TYPE ‘S’.
else.
MESSAGE ‘NODAT FOUNF’ TYPE ‘I’.
ENDIF.

Note: In Above source code double click on  ZMENU (SET PF-STATUS ‘ZMENU’) and create Menu with Download and Delete buttons.

Output:

Click on save, check and execute the program then you will get output as shown below.

SAP ABAP report with checkbox to Download selected records at runtimeSelect some field and click on download button.

SAP ABAP report with checkbox to Download selected records at runtime 1Clicks on download button then the selected fields are downloaded into presentation server (Your system).

That’s it.

Enjoy 🙂

Also Read:

Hierarchical ALV Report in SAP ABAP.

Naming Standards in SAP ABAP.

Types of Internal Tables in SAP ABAP.

ALV Tree Display in SAP ABAP. 

60 Flares Twitter 0 Facebook 60 Google+ 0 LinkedIn 0 Email -- Pin It Share 0 60 Flares ×