Skip to Content
-3
Jan 19, 2021 at 11:46 AM

SQL SY-SUBRC = 4 failed to get datas

42 Views

TYPES:
  BEGIN OF GTS_VAL,
    BUKRS TYPE ZMM0011T-BUKRS,
    MATNR TYPE MARA-MATNR,
    MATNR_TMP TYPE MARC-MATNR,
    BWKEY TYPE T001W-BWKEY,
    WERKS TYPE T001W-WERKS,
  END OF GTS_VAL. 
GTT_VAL TYPE STANDARD TABLE OF GTS_VAL. 
Data:
   GDT_R_DATE type range of sy-datlo.
  GDT_STARTDAY TYPE MSEG-BUDAT_MKPT
  GDT_STARTDAY1 TYPE MSEG-BUDAT_MKPF.

  GDT_LASTDAY TYPE MSEG-BUDAT_MKPF. 
  LDT_VAL TYPE GTT_VAL. 
*First day of period
  CONCATENATE S_ZYEAR-LOW '01' INTO GDF_STARTDAY1.
  CONCATENATE S_ZYEAR-HIGH '01' INTO GDF_STARTDAY. 
*Last day of period
  Call function 'LAST_DAY_OF_MONTHS'. 
  EXPORTING
    DAY_IN = GDF_STARTDAY
  IMPORTING
    LAST_DAY_OF_MONTH = GDF_LASTDAY
  EXCEPTION
   ~

GDF_R_DATE = VALUE #( BASE GDF_R_DATE ( SIGN = 'I' OPTION = 'BT' LOW = GDF_STARTDAY1 HIGH = GDF_LASTDAY ) ).

SELECT ZMM0011T~EBELN,
       ZMM0011T~EBELP,
       ZMM0011T~MENGE_GR,
       ZMM0011T~DMBST_GR
  FROM ZMM0011T
 WHERE BUKRS = @P_BUKRS
INTO TABLE  = @GDT_ZMM0011T

SELECT MSEG~BWART,
       MSEG~DMBTR,
       MSEG~BNBTR,
       MSEG~SHKZG,
       MSEG~MENGE,
       MSEG~EBELN,
       MSEG~EBELP,
       EKPO~PSTYP,
       EKPO~MENGE,
       EKPO~KNTTP,
       T156~SHKZG,
       T156~XSTBW
  FROM MSEG
INNER JOIN EKPO
        ON EKPO~EBELN = MSEG~EBELN
       AND EKPO~EBELP = MSEG~EBELP
       AND EKPO~KNTTP = ' '
INNER JOIN T156
        ON T156~BWART = MSEG~BWART
  FOR ALL ENTRIES IN
           @LDT_VAL
     WHERE MSEG~MATNR = @LDT_VAL-MATNR  
       AND MSEG~WERKS = @LDT_VAL-WERKS
       AND MSEG~BUKRS = @P_BUKRS
INTO TABLE @GDT_MSEG.