Extract Local Products Data Using ABAP Program into CSV File Based On Given Data Retention Rule

1st set of Local Prodct Extract :

  1. All local products that has a 7 digit reference AND
  2. All local products that has a reference starting with 4 OR 7 OR 8 AND
  3. All local products that are active ie: no # in description AND
  4. All local products that has stock >0 AND
  5. All local products which has a transaction within the last 12 months

ABAP Program – 

 

REPORT  Z_MARA_EX1_HERO_LP.
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 ‘\Server-009tmpMARA_1.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,
      MATNR like MARA-MATNR,
  MEINS like MARA-MEINS,
  MAKTX like MAKT-MAKTX,
  EAN11 like MARA-EAN11,
       BUKRS like MSEG-BUKRS,
      end of itab.
 
data:  itab1 type TRUXS_T_TEXT_DATA.
DATA:lv_date TYPE sy-datum.
lv_date = sy-datum – 365.
 
 SELECT DISTINCT
        MARA~MATNR
MARA~MEINS
MAKT~MAKTX
MARA~EAN11
   MSEG~BUKRS
         from MARA
         INNER JOIN MAKT
         ON MARA~MATNR EQ MAKT~MATNR
         INNER JOIN MARD
         ON MARA~MATNR EQ MARD~MATNR
         INNER JOIN MSEG
         ON MARA~MATNR EQ MSEG~MATNR
         INNER JOIN EKPO
         ON MARA~MATNR EQ EKPO~MATNR
         INNER JOIN EKKO
         ON EKPO~EBELN EQ EKKO~EBELN
 
         into table itab
         WHERE MSEG~BUKRS = ENTITY AND ( MARA~MATNR LIKE ‘000000000004%’ OR MARA~MATNR LIKE ‘000000000007%’ OR MARA~MATNR LIKE ‘000000000008%’ )
         AND MAKT~MAKTX NOT LIKE ‘#%’ AND EKKO~AEDAT >= lv_date AND MARD~LABST > 0.
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