2

I am writing a program and I have three columns that copies the content of their next three columns and vice versa when one of them doesn't have data. Why columns are copying neighbor columns?

photo.jpg

Here columns circled in red are copying the content from the columns circled in blue,which is not wright. The columns in red should have 0 values.

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.
Sandra Rossi
  • 11,934
  • 5
  • 22
  • 48
dragospirnut
  • 13
  • 1
  • 8
  • There is no image attached, and this is far from a minimal example. Please create a copy of your program and delete everything that is not absolutely essential to demonstrating the problem. – vwegert Oct 12 '17 at 07:13
  • Hi vwegert, i deleted all comentaries and added the photo as well. Any clue? – dragospirnut Oct 12 '17 at 07:22
  • `when one of them does not have data` why do you think that sum line is being calculated wrong? Your **Cant. buc. predate** and **Cant. predata** both have the same values, so their sums will be identical. Everything is correct. – Suncatcher Oct 12 '17 at 07:49
  • @dragospirnut "deleting comments" is not the point - remove all the irrelevant application code. This will usually help you spot the problem yourself. – vwegert Oct 12 '17 at 08:41
  • @Suncatcher ,the columns Bucati pe comanda,Unitate ,Cant.buc.predate should have no sums, no values at all. – dragospirnut Oct 12 '17 at 09:31

2 Answers2

1

Use INTO CORRESPONDING FIELDS OF TABLE clause in your SELECT, not just INTO TABLE lt_join. Probably, table values are transferred into wrong fields of the itab.
Excerpt from the SELECT documentation:

If all columns are read with * and CORRESPONDING FIELDS is not specified, SELECT behaves as follows:

  • When specifying a work area that does not contain any reference variables for LOB handles, the row is assigned to the result set left-aligned and unconverted according to the structure of the result set. Unaffected parts of the wa contain their previous content. To be able to access the components of the result set according to their type, the work area wa must be structured like the result set.

Also, your condition

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

might not be met, if MEINH field is filled after the condition.

Suncatcher
  • 10,355
  • 10
  • 52
  • 90
  • Thank your reply , I commented : IF wa_join-MEINH = 'KG'. wa_join-MGVRG = '0'. wa_join-MEINH = '0'. wa_join-MENGE = '0'. endif. and used INTO CORRESPONDING FIELDS OF and i get the error "You cannot use an internal table as a work area" and points me to the :SELECT line. – dragospirnut Oct 12 '17 at 11:37
  • in your case you should use INTO CORRESPONDING FIELDS OF **TABLE**, I thought you'd be able to guess the right form:) – Suncatcher Oct 12 '17 at 11:52
  • i commented : IF wa_join-MEINH = 'KG'. wa_join-MGVRG = '0'. wa_join-MEINH = '0'. wa_join-MENGE = '0' and used INTO CORRESPONDING FIELDS OF TABLE ,unfortunately same result :((.Thank you so much for your time. – dragospirnut Oct 12 '17 at 12:05
  • same result means what? you tried both `INTO CORRESPONDING FIELDS OF TABLE lt_join` and `INTO CORRESPONDING FIELDS OF lt_join` and got `You cannot use an internal table as a work area`? I cannot believe that. – Suncatcher Oct 12 '17 at 12:16
  • Commenting this IF condition will give you nothing, and cannot cause any errors, so don't alter this part. – Suncatcher Oct 12 '17 at 12:35
  • Thank you for your reply.same result means that columns circled in red copy the same content from columns circled in blue. I commented the IF condition because that was a condition which is not very proper. Normally my selection should work without the IF condition. I tried the code with the IF condition and the result is pretty much ok. The only problem is that in some cases i dont have values in the red circled columns which i normally should have different than the columns circled in blue. – dragospirnut Oct 12 '17 at 12:55
  • fields in lt_join don`t match with fieldcatalog because i need a certain order in fieldcatalog. Fieldnames in fieldcatalog need to match the fieldnames in lt_join? – dragospirnut Oct 12 '17 at 13:00
  • The technical names (not descriptions) in field catalog MUST match those from the table structure. – Jagger Oct 12 '17 at 13:02
0

I experienced duplicated column values if the fieldcatalog definition is somehow wrong for a column.

Check your fieldcat fieldnames and if they properly match your internal table fieldnames in lt_join and try to use as little fieldcatalog options as possible to avoid wrong configurations.

futu
  • 868
  • 6
  • 12
  • thank you for your reply, fields in lt_join don`t match with fieldcatalog because i need a certain order in fieldcatalog. Fieldnames in fieldcatalog need to match the fieldnames in lt_join? – dragospirnut Oct 12 '17 at 11:42