值在相邻列中重复

时间:2017-10-12 07:08:18

标签: sap abap alv

我正在编写一个程序,我有三列复制其下三列的内容,反之亦然,当其中一列没有数据时。为什么列要复制邻居列?

photo.jpg

此处以红色圈出的列正在复制蓝色圆圈中的内容,而不是怀特。红色的列应该有0个值。

REPORT  Z_KABAP_STATUS_COMENZI.

TABLES T003P.
TABLES AFKO.
TABLES AFPO.
TABLES AUFM.
TABLES AUFK.
TABLES MAKT.
TABLES AFVV.



TYPE-POOLS: slis.  " SLIS contains all the ALV data types

DATA: MyGridTitle TYPE LVC_TITLE.
DATA: report_id LIKE sy-repid.
DATA: MyLayout TYPE slis_layout_alv. "alv layout
DATA: afield TYPE slis_fieldcat_alv. "wa_fieldcat
*DATA: it_sort TYPE slis_t_sortinfo_alv.
DATA: it1_sort TYPE slis_t_sortinfo_alv.
*DATA: wa_sort   TYPE slis_sortinfo_alv.
DATA: it_filter TYPE slis_t_filter_alv.
Data: ls_filter TYPE slis_filter_alv.
DATA: FIELDCATALOG TYPE slis_t_fieldcat_alv, "WITH HEADER LINE,
      GD_LAYOUT    TYPE slis_layout_alv,
      G_SAVE TYPE C VALUE 'X',
      G_VARIANT TYPE DISVARIANT,
      GX_STOC TYPE DISVARIANT,
      G_EXIT TYPE C.
DATA: MyEvents TYPE slis_t_event.

DATA: it_sort      TYPE slis_t_sortinfo_alv,
      wa_sort      TYPE slis_sortinfo_alv..



TYPES: BEGIN OF tables_fields,


  AUFNR TYPE AUFK-AUFNR, "Nr comanda productie
  AUART TYPE AUFK-AUART, "Tip comanda /Sectie
  WERKS TYPE AUFK-WERKS, "Unitate logistica
  TXT   TYPE T003P-TXT,  "Nume sectie
  "MENGE TYPE AUFM-MENGE, "Cantitate buc predata
  GAMNG TYPE AFKO-GAMNG, "Cantitatea totala vrac in kg
  GMEIN TYPE AFKO-GMEIN, "Unitatea de masura cantitate totala
  "WEMNG TYPE AFPO-WEMNG, "Cantitatea totala livrata
  ERFMG TYPE AUFM-ERFMG, "Cantitatea kg totala livrata defalcata
  GSTRP Type AFKO-GSTRP, "Data lansarii comenzii
  GLTRP TYPE AFKO-GLTRP, "Data estimativa a finalizarii comenzii
  BLDAT TYPE AUFM-BLDAT, "Data finalizarii comenzii
  MGVRG TYPE AFVV-MGVRG, "Bucati pe comanda-cant de baza
  "MEINS TYPE AUFM-MEINS,"Unitate bucati pe comanda-rectificat
  MEINH TYPE AFVV-MEINH,  "Unitate bucati pe comanda
  MENGE TYPE AUFM-MENGE, "Cantitate buc predata

  MATNR TYPE AUFM-MATNR, "Cod material
  MAKTX TYPE MAKT-MAKTX, "Descriere material
   MBLNR TYPE AUFM-MBLNR,
  ZEILE TYPE AUFM-ZEILE,
  BMSCH TYPE AFVV-BMSCH,

  SPRAS TYPE T003P-SPRAS,"Restrictionare limba
  ZILEDEP TYPE I,"AFKO-GLTRP, "Filtru date intre care s-au realizat comenzi
  COMDEP(10) TYPE C,"Nr zile comanda depasita
  COMINTRE TYPE AFKO-GSTRP,"Data comenzi termen depasit

  line_color(4) TYPE c,

   END OF tables_fields.



DATA: lt_join TYPE STANDARD TABLE OF tables_fields,
      wa_join TYPE tables_fields.



FIELD-SYMBOLS :  <wa_join> TYPE tables_fields.

SELECTION-SCREEN BEGIN OF BLOCK BLOCK1 WITH FRAME TITLE text-001.
SELECT-OPTIONS NrCom FOR AUFK-AUFNR. "AUFK-AUFNR. "Comanda proces
SELECT-OPTIONS Material FOR AUFM-MATNR."AFKO-PLNBEZ. "Cod material
SELECT-OPTIONS UnitLog FOR AUFK-WERKS. " Unitate logistica
SELECT-OPTIONS TipCom FOR AUFK-AUART. "Tip comanda/Sectie
SELECT-OPTIONS COMINTRE FOR AFKO-GSTRP. "modif id m1. "Date intre care s-au lansat comenzi
SELECTION-SCREEN END OF BLOCK BLOCK1.

SELECTION-SCREEN BEGIN OF BLOCK BLOCK2 WITH FRAME TITLE text-001.
SELECTION-SCREEN COMMENT /1(79) label_4.
PARAMETERS: btn1    RADIOBUTTON GROUP RAD1 USER-COMMAND chk DEFAULT 'X',
            btn2    RADIOBUTTON GROUP RAD1,
            btn3    RADIOBUTTON GROUP RAD1.
SELECTION-SCREEN END OF BLOCK BLOCK2.


START-OF-SELECTION.



  PERFORM Selectare.
  PERFORM BUILD_FIELDCATALOG.
  PERFORM sort_catalog.


  LOOP AT lt_join INTO wa_join.

    IF wa_join-MEINH = 'ST'.
      wa_join-MEINH ='BUC'.
    ENDIF.


    IF wa_join-MEINH = 'KG'.
      wa_join-MGVRG = '0'.
      wa_join-MEINH = '0'.
      wa_join-MENGE = '0'.
    endif.

    IF wa_join-GMEIN = 'ST'.
      wa_join-GMEIN ='KG'.
    ENDIF.


    IF wa_join-erfmg = wa_join-menge.
      wa_join-GMEIN ='0'.
      wa_join-gamng = '0'.
      wa_join-ERFMG = '0'.
    ENDIF.



    IF wa_join-bldat > wa_join-gltrp."
      wa_join-comdep = 'Depasit'." Comenzi termen depasit.
    ELSE.
      wa_join-comdep = 'Nedepasit'.
    ENDIF.


    IF wa_join-bldat > wa_join-gltrp."" comanda nr zile depasite fata de data estimata .
      wa_join-ziledep = wa_join-bldat - wa_join-gltrp.
    ELSE.
      wa_join-ziledep = ''.
    ENDIF.

    MODIFY lt_join FROM wa_join TRANSPORTING MEINH MGVRG MENGE GMEIN GAMNG ERFMG COMDEP BLDAT  ZILEDEP."COMINTRE. "  WEMNG MEINS

  ENDLOOP.

  LOOP AT lt_join ASSIGNING <wa_join>.
    IF <wa_join>-aufnr EQ '2001'.
      MOVE 'C410' TO <wa_join>-line_color.
    ELSE.
      MOVE 'C510' TO <wa_join>-line_color.
    ENDIF.

  ENDLOOP.

  MyLayout-zebra = 'X'.
  MyLayout-colwidth_optimize = 'X'.
  MyLayout-info_fieldname =      'LINE_COLOR'.

  Refresh it_filter.
  if btn1 = 'X'.
    ls_filter-fieldname = 'COMDEP'.  "Filtru data comanda intre doua date calendaristice pentru Depasit radiobuton "
    ls_filter-tabname = 'LT_JOIN'.
    ls_filter-sign0 = 'I'.
    ls_filter-optio = 'EQ'.
    ls_filter-valuf_int = 'Depasit'.
    APPEND ls_filter TO It_filter.
  ELSEIF btn3 = 'X'.
    ls_filter-fieldname = 'COMDEP'.  "Filtru data comanda intre doua date calendaristice pentru Nedepasit radiobuton "
    ls_filter-tabname = 'LT_JOIN'.
    ls_filter-sign0 = 'I'.
    ls_filter-optio = 'EQ'.
    ls_filter-valuf_int = 'Nedepasit'.
    APPEND ls_filter TO It_filter.
  EndIf.


  PERFORM DISPLAY_ALV_REPORT TABLES lt_join.



FORM Selectare.


  ##too_many_itab_fields
  SELECT a~aufnr
         "e~aufnr
         a~auart
         a~werks
         b~txt
         c~gamng "cant kg pe comanda
         c~gmein " unit masura kg
         "d~wemng
         e~erfmg " cant kg pe comanda predata
         c~gstrp
         c~gltrp
         e~bldat
         g~mgvrg "cant buc pe comanda
         g~meinh " unit masura buc
         "e~meins
         e~menge " cant buc pe comanda predata
         e~matnr"c~plnbez
         f~maktx
         e~mblnr
         e~zeile
         g~bmsch



  FROM AUFK AS a
 inner JOIN T003P AS b
  ON a~auart = b~auart
inner  JOIN AFKO as c
  ON a~aufnr = c~aufnr
inner  JOIN AFPO as d
  ON a~aufnr = d~aufnr
 inner JOIN AUFM as e
  ON a~aufnr = e~aufnr
 inner JOIN MAKT as f
  ON d~matnr = f~matnr
inner JOIN AFVV as g
  ON c~aufpl = g~aufpl


INTO TABLE lt_join
"FOR ALL ENTRIES IN lt_join
    WHERE a~aufnr IN NrCom AND "
          a~werks IN UnitLog AND
          b~auart IN TipCom AND
          b~SPRAS = SY-LANGU AND
          f~spras = sy-langu and
          e~matnr IN Material AND "c~plnbez
          bwart = '101' AND
          c~gstrp IN COMINTRE.


  sort lt_join by MBLNR.

  DELETE ADJACENT DUPLICATES FROM lt_join comparing MBLNR."

ENDFORM.


FORM sort_catalog.

  wa_sort-spos      = 4.
  wa_sort-fieldname = 'AUFNR'.
  wa_sort-up        = 'X'.
  wa_sort-subtot    = 'X'.
  APPEND wa_sort TO it_sort.

ENDFORM.

FORM BUILD_FIELDCATALOG.
  REFRESH FIELDCATALOG.

  afield-FIELDNAME = 'WERKS'.
  afield-SELTEXT_M = 'Unitate logistica'.
  afield-COL_POS   = 1.
  afield-OUTPUTLEN = 10.
  APPEND afield TO FIELDCATALOG.
  CLEAR afield.

  afield-FIELDNAME = 'AUART'.
  afield-SELTEXT_M = 'Tip Comanda'.
  afield-COL_POS   = 2.
  afield-OUTPUTLEN = 10.
  APPEND afield TO FIELDCATALOG.
  CLEAR afield.

  afield-FIELDNAME = 'TXT'.
  afield-SELTEXT_M = 'Nume sectie'.
  afield-COL_POS   = 3.
  afield-OUTPUTLEN = 25.
  APPEND afield TO FIELDCATALOG.
  CLEAR afield.

  afield-FIELDNAME = 'AUFNR'.
  afield-SELTEXT_M = 'Numar comanda'.
  afield-COL_POS   = 4.
  afield-OUTPUTLEN = 10.
  afield-no_zero = 'X'.
  APPEND afield TO FIELDCATALOG.
  CLEAR afield.

  afield-FIELDNAME = 'MATNR'."'PLNBEZ'.
  afield-SELTEXT_M = 'Cod Material'.
  afield-COL_POS   = 5.
  afield-OUTPUTLEN = 15.
  APPEND afield TO FIELDCATALOG.
  CLEAR afield.

  afield-FIELDNAME = 'MAKTX'.
  afield-SELTEXT_M = 'Descriere material'.
  afield-COL_POS   = 6.
  afield-OUTPUTLEN = 25.
  APPEND afield TO FIELDCATALOG.
  CLEAR afield.

  afield-FIELDNAME = 'MGVRG'.
  afield-SELTEXT_M = 'Bucati pe comanda'.
  afield-COL_POS   = 7.
  afield-OUTPUTLEN = 13.
  afield-decimals_out = 0.
  APPEND afield TO FIELDCATALOG.
  CLEAR afield.

  afield-FIELDNAME = 'MEINH'."MEINS
  afield-SELTEXT_M = 'Unitate'.
  afield-COL_POS   = 8.
  afield-OUTPUTLEN = 7.
  APPEND afield TO FIELDCATALOG.
  CLEAR afield.

  afield-FIELDNAME = 'MENGE'.
  afield-SELTEXT_M = 'Cant. buc. predate'.
  afield-COL_POS   = 9.
  afield-OUTPUTLEN = 13.
  afield-decimals_out = 0.
  afield-do_sum = 'X'.
  APPEND afield TO FIELDCATALOG.
  CLEAR afield.

  afield-FIELDNAME = 'GAMNG'.
  afield-SELTEXT_M = 'Cant.pe comanda'.
  afield-COL_POS   = 10.
  afield-OUTPUTLEN = 13.
  "afield-decimals_out = 0.
  APPEND afield TO FIELDCATALOG.
  CLEAR afield.

  afield-FIELDNAME = 'GMEIN'.
  afield-SELTEXT_M = 'Unitate'.
  afield-COL_POS   = 11.
  afield-OUTPUTLEN = 5.
  APPEND afield TO FIELDCATALOG.
  CLEAR afield.

  afield-FIELDNAME = 'ERFMG'. "WEMNG
  afield-SELTEXT_M = 'Cant. predata'.
  afield-COL_POS   = 12.
  afield-OUTPUTLEN = 10.
  "afield-decimals_out = 0.
  afield-do_sum = 'X'.
  APPEND afield TO FIELDCATALOG.
  CLEAR afield.

  afield-FIELDNAME = 'GSTRP'.
  afield-SELTEXT_M = 'Lansare comanda'.
  afield-COL_POS   = 13.
  afield-OUTPUTLEN = 12.
  APPEND afield TO FIELDCATALOG.
  CLEAR afield.

  afield-FIELDNAME = 'GLTRP'.
  afield-SELTEXT_M = 'Data plan finalizare'.
  afield-COL_POS   = 14.
  afield-OUTPUTLEN = 15.
  APPEND afield TO FIELDCATALOG.
  CLEAR afield.

  afield-FIELDNAME = 'BLDAT'.
  afield-SELTEXT_M = 'Data predare comanda'.
  afield-COL_POS   = 15.
  afield-OUTPUTLEN = 13.
  APPEND afield TO FIELDCATALOG.
  CLEAR afield.

  afield-FIELDNAME = 'COMDEP'.
  afield-SELTEXT_M = 'Termen comanda'.
  afield-COL_POS   = 16.
  afield-OUTPUTLEN = 13.
  APPEND afield TO FIELDCATALOG.
  CLEAR afield.

  afield-FIELDNAME = 'ZILEDEP'.
  afield-SELTEXT_M = 'Nr zile'.
  afield-COL_POS   = 17.
  afield-OUTPUTLEN = 13.
  APPEND afield TO FIELDCATALOG.
  CLEAR afield.



ENDFORM.




FORM DISPLAY_ALV_REPORT TABLES lt_join.
* USING P_GRID_TITLE.
* rs_selfield TYPE slis_selfield.
  report_id = SY-REPID.
* RS_SELFIELD-ROW_STABLE = 'X'.
  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
      I_CALLBACK_PROGRAM       = report_id
      I_CALLBACK_TOP_OF_PAGE   = 'TOP-OF-PAGE'
*     I_CALLBACK_USER_COMMAND  = 'USER_COMMAND'
*     I_CALLBACK_PF_STATUS_SET = 'SET_PF_STATUS'
      IT_FIELDCAT              = FIELDCATALOG"[]
*     I_GRID_TITLE             = P_GRID_TITLE
      I_SAVE                   = 'X'
      IT_EVENTS                = MyEvents
      is_layout                = MyLayout
      it_sort                  = it_sort
      it_filter                = it_filter " List output filter criteria
*     IS_VARIANT               = G_VARIANT
    TABLES
      T_OUTTAB                 = lt_join
    EXCEPTIONS
      PROGRAM_ERROR            = 1
      OTHERS                   = 2.

  IF SY-SUBRC <> 0.
  ENDIF.

ENDFORM.


*---------------------------------------------------------*
* Grid  Header                                            *
*---------------------------------------------------------*
Form TOP-OF-PAGE.
*ALV Header declarations
  data: My_header type slis_t_listheader,
        wa_header type slis_listheader,
        My_line   like wa_header-info,
        ld_lines  type i,
        ld_linesc(10) type c.

* Title
  clear wa_header.
  wa_header-typ  = 'H'.
  wa_header-info =
    'Raport status comenzi de productie'.
  append wa_header to My_header.
*
*  clear wa_header.
*  wa_header-typ  = 'H'.
*  wa_header-info =`enter code here`
*  'Efectuati DUBLU Click pt Analiza Grafica - optiunile 01-08'.
*  append wa_header to My_header.
  CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
    EXPORTING
      it_list_commentary = My_header.
*            i_logo             = 'Z_LOGO'.
endform.

2 个答案:

答案 0 :(得分:1)

在SELECT中使用 INTO CORESPONDING FIELDS OF TABLE 子句,而不仅仅是INTO TABLE lt_join。表值可能会转移到itab的错误字段中。
摘自SELECT documentation

  

如果所有列都用*读取而且CORRESPONDING FIELDS不是   指定,SELECT的行为如下:

     
      
  • 指定不包含LOB句柄的任何引用变量的工作区时,将该行分配给结果集   根据结果​​的结构左对齐和未转换   设置即可。 wa的未受影响部分包含其先前的内容。成为   能够根据他们的访问权限访问结果集的组件   类型,工作区域必须像结果集一样构造。
  •   

另外,你的情况

IF wa_join-MEINH = 'KG'.
  wa_join-MGVRG = '0'.
  wa_join-MEINH = '0'.
  wa_join-MENGE = '0'.
endif.
如果在条件之后填写MEINH字段,则可能无法满足

答案 1 :(得分:0)

如果某个列的fieldcatalog定义有些错误,我会遇到重复的列值。

检查您的fieldcat字段名,以及它们是否与lt_join中的内部表字段名匹配正确,并尝试使用尽可能少的字段目录选项以避免错误配置。