Extract ADR6 Cust E-Mail Addresses (Business Address Services) Data in CSV File Using ABAP Program

Extract ADR6 Customer E-Mail Addresses (Business Address Services) Data in CSV File Using ABAP Program.

ABAP Program Name ) Z_SZA1_D0100_CUSTOMER         

  •  Program Type – ABAP 
  • ABAP Program Name – Z_SZA1_D0100_CUSTOMER 
  • Tcode – Z_SZA1_CUST  
  • Entity Description – Customer E-Mail Addresses (Business Address Services) Data 
  • Output File Location – “C:tmp” 
  • Output File Name- SZA1_D0100.CSV  
  • Output File Type – CSV (Column with Semicolon separator (;) 
  • SAP Table Name – ADR6, ADRC, KNA1, KNB1 
  • List of fields to be extracted –  
  • KUNNR 
  • SMTP_ADDR 

———ABAP PROGRAM START FROM HERE———————

REPORT Z_SZA1_D0100_HERO_CUS.

TYPE-POOLS: VRM.

DATA: NAME TYPE VRM_ID,
LIST TYPE VRM_VALUES,
VALUE LIKE LINE OF LIST.

PARAMETERS: ENTITY(10) AS LISTBOX VISIBLE LENGTH 10.
PARAMETERS : OPATH TYPE STRING DEFAULT ‘\SERVERNAMEtmpSZA1_D0100.csv’.

AT SELECTION-SCREEN OUTPUT.

NAME = ‘ENTITY’.

VALUE-KEY = ‘UK01’.
VALUE-TEXT = ‘UK01’.
APPEND VALUE TO LIST.

VALUE-KEY = ‘UK75’.
VALUE-TEXT = ‘UK75’.
APPEND VALUE TO LIST.

VALUE-KEY = ‘UK21’.
VALUE-TEXT = ‘UK21’.
APPEND VALUE TO LIST.

VALUE-KEY = ‘UK31’.
VALUE-TEXT = ‘UK31’.
APPEND VALUE TO LIST.

VALUE-KEY = ‘UK41’.
VALUE-TEXT = ‘UK41’.
APPEND VALUE TO LIST.

VALUE-KEY = ‘UK02’.
VALUE-TEXT = ‘UK02’.
APPEND VALUE TO LIST.

VALUE-KEY = ‘UK73’.
VALUE-TEXT = ‘UK73’.
APPEND VALUE TO LIST.

VALUE-KEY = ‘UK04’.
VALUE-TEXT = ‘UK04’.
APPEND VALUE TO LIST.

VALUE-KEY = ‘UK61’.
VALUE-TEXT = ‘UK61’.
APPEND VALUE TO LIST.

CALL FUNCTION ‘VRM_SET_VALUES’ EXPORTING ID = NAME VALUES = LIST.

START-OF-SELECTION.

type-pools:TRUXS.
data: begin of itab occurs 0,
KUNNR like KNA1-KUNNR,
SMTP_ADDR like ADR6-SMTP_ADDR,
BUKRS like KNB1-BUKRS,
end of itab.

data: itab1 type TRUXS_T_TEXT_DATA.
SELECT DISTINCT KNA1~KUNNR
ADR6~SMTP_ADDR
KNB1~BUKRS
from KNA1 INNER JOIN ADRC ON KNA1~ADRNR = ADRC~ADDRNUMBER
INNER JOIN ADR6 ON ADRC~ADDRNUMBER = ADR6~ADDRNUMBER
INNER JOIN KNB1 ON KNA1~KUNNR = KNB1~KUNNR
into table itab
WHERE KNB1~BUKRS IN (ENTITY) AND ADR6~FLGDEFAULT IN (‘X’).

CALL FUNCTION ‘SAP_CONVERT_TO_CSV_FORMAT’
EXPORTING
I_FIELD_SEPERATOR = ‘,’
TABLES
I_TAB_SAP_DATA = itab
CHANGING
I_TAB_CONVERTED_DATA = itab1
EXCEPTIONS
CONVERSION_FAILED = 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.

CALL FUNCTION ‘GUI_DOWNLOAD’
EXPORTING
filename = OPATH
TABLES
data_tab = itab1
EXCEPTIONS
OTHERS = 1.

Scroll to Top