Skip to Content
-2

see all the materials even if i don`t put a value in s_matnr or in s_grpmat

Jun 29, 2017 at 12:56 PM

260

avatar image
Former Member

capture.pngDear colleagues ,

Thank you for your answers until now. I have managed to make changes to my report but i still have some issues. When i put a value in s_grpmat it brings me all the columns in the grid except maktx. Also another thing that i would like to do is to be able to see all the materials even if i don`t put a value in s_matnr or in s_grpmat .Now is showing me only one material when i don`t put nothing in s_matnr and nothing in s_grpmat.

Thank you for your help!

TABLES:klah,
mara,
cabn,
makt,
marc,
t001w,
t023t,
t134t.

TYPE-POOLS:abap,
slis.

*Types declarations



TYPES:BEGIN OF type_class1,
class TYPE klah-class, "Nume clasa
klart TYPE klah-klart," Tip clasa
END OF type_class1.

TYPES:BEGIN OF type_makt,
matnr TYPE makt-matnr,"cod material
maktx TYPE makt-maktx, "descriere material
"werks type t001w-werks,
END OF type_makt.

TYPES:BEGIN OF type_ksml, "caracteristici clasa
imerk TYPE ksml-imerk,"caracteristica interna
clint TYPE ksml-clint,"numar intern clasa
klart TYPE ksml-klart, "tip clasa
END OF type_ksml.

TYPES:BEGIN OF type_charclass,
atnam TYPE atnam, "Nume caracteristica
objek1_internal TYPE objnum, "chei obiectului de clasificat
objek1 TYPE objnum,"chei obiectului de clasificat
objek1_text TYPE clobjtxt, "Descriere obiect
klart TYPE klah-klart, "tip clasa
END OF type_charclass.

TYPES:BEGIN OF type_status,
klart TYPE tclut-klart,"tip clasa
status TYPE tclut-status, "stare clasa
stext TYPE tclut-stext, "text pentru intrare de tabel
END OF type_status.

TYPES:BEGIN OF type_obtab,
klart TYPE tcla-klart,"tip clasa
obtab TYPE tabelle, "Nume tabel baz? de date pt.obiect
END OF type_obtab.

TYPES:BEGIN OF type_final,
matnr TYPE clobjekte-objekt,"marc-matnr," Structur? transfer: obiecte clasificate
class TYPE klah-class," nume clasa
klart TYPE klah-klart, "tip clasa
status TYPE sclass-statu, "sclass-Structur? de referin??: Date clas?,statu-Stare clasificare
maktx TYPE makt-maktx, "Descriere material
atnam TYPE clobjdat-atnam, " clobjdat-Structur? referin??: Date clasificare obiect- atnam-nume caracteristica
atwrt TYPE clobjdat-ausp1, "ausp1- Valoare caracteristic?
atbez TYPE clobjdat-smbez, "smbez -Descriere caracteristic?
stext TYPE tclut-stext, "stext - Text pt.o intrare de tabel
werks TYPE t001w-werks, " unitate logistica
matkl TYPE mara-matkl, " grup material
mtart TYPE mara-mtart, " cont material
END OF type_final.

TYPES:BEGIN OF type_t001w,
werks TYPE t001w-werks,
"matnr TYPE MARC-matnr,
END OF type_t001w.

TYPES:BEGIN OF type_marc,
werks TYPE marc-werks,
matnr TYPE MARC-matnr,
END OF type_marc.

TYPES:BEGIN OF type_mara,
matnr TYPE mara-matnr, "cod material
matkl TYPE mara-matkl, " grup material
mtart TYPE mara-mtart, " cont material
END OF type_mara.


*Ranges
DATA:ra_matnr TYPE RANGE OF makt-matnr.
DATA:ra_werks TYPE RANGE OF marc-werks.

*zone de lucru
DATA:wa_final TYPE type_final.
DATA:wa_class1 TYPE type_class1.
DATA:wa_makt1 TYPE type_makt.
DATA:wa_ksml TYPE type_ksml.
DATA:wa_charclass TYPE type_charclass.
DATA:wa_tcla1 TYPE type_obtab.
DATA:wa_status TYPE type_status.
DATA:wa_fieldcat TYPE slis_fieldcat_alv.
DATA:wa_layout TYPE slis_layout_alv.
DATA:wa_matnr LIKE LINE OF ra_matnr.
DATA:wa_marc TYPE type_marc.
DATA:wa_werks LIKE LINE OF ra_werks.
DATA:wa_t001w TYPE type_t001W.
DATA:wa_mara TYPE type_mara.

*Tabele interne
DATA:i_final TYPE TABLE OF type_final.
DATA:i_class1 TYPE STANDARD TABLE OF type_class1.
DATA:i_makt1 TYPE STANDARD TABLE OF type_makt.
DATA:i_ksml TYPE STANDARD TABLE OF type_ksml.
DATA:i_ksml_te TYPE STANDARD TABLE OF type_ksml.
DATA:i_tcla1 TYPE STANDARD TABLE OF type_obtab.
DATA:i_charclass TYPE STANDARD TABLE OF type_charclass.
DATA:i_status TYPE STANDARD TABLE OF type_status.
DATA:i_fieldcat TYPE TABLE OF slis_fieldcat_alv.
DATA:i_marc TYPE STANDARD TABLE OF type_marc.
DATA:i_t001w TYPE STANDARD TABLE OF type_t001W.
DATA:i_mara TYPE STANDARD TABLE OF type_mara.

*Variabile
DATA:wf_initial_char TYPE rmclm-basisd. "rmclm-structura , basisd-Date de baz? sistem de clasificare
DATA: g_werks type marc-werks.
DATA: it_filter TYPE slis_t_filter_alv.
Data: ls_filter TYPE slis_filter_alv.


*selection screen
SELECT-OPTIONS: s_klart FOR klah-klart NO INTERVALS NO-EXTENSION DEFAULT '001',"Tip clasa
s_class FOR klah-class NO INTERVALS NO-EXTENSION OBLIGATORY MATCHCODE OBJECT clas DEFAULT 'Z_MEDIU'."Nume clasa

SELECT-OPTIONS: s_grpmat FOR t023t-matkl NO INTERVALS NO-EXTENSION. "Grup Material
"SELECT-OPTIONS: s_cntmat FOR t134t-mtart NO INTERVALS NO-EXTENSION DEFAULT '3010'. "Grup Material
SELECT-OPTIONS: s_matnr FOR mara-matnr NO INTERVALS NO-EXTENSION. "Numar Material
SELECT-OPTIONS: s_atinn FOR cabn-atinn NO INTERVALS NO-EXTENSION. "Caracteristici
"SELECT-OPTIONS: s_werks FOR t001w-werks NO INTERVALS NO-EXTENSION DEFAULT '3000'. "Unitate logistica
SELECTION-SCREEN SKIP 1.


START-OF-SELECTION.

*IF s_matnr[] IS INITIAL AND s_werks[] IS INITIAL AND s_grpmat[] IS INITIAL AND s_cntmat[] IS INITIAL.

SELECT matnr maktx FROM makt INTO TABLE i_makt1
WHERE matnr IN s_matnr AND
spras = sy-langu. "and
"maktg IN s_maktx .


SELECT werks matnr FROM marc into table i_marc "
where matnr IN s_matnr. "AND


*IF i_makt1 IS INITIAL.
* SELECT werks matnr
* INTO TABLE i_marc
* FROM marc FOR ALL ENTRIES IN i_makt1
* WHERE matnr EQ i_makt1-matnr.
* "AND werks IN s_werks.
*ENDIF.


"IF s_matnr[] IS INITIAL AND s_grpmat[] IS INITIAL.
SELECT matnr matkl mtart FROM mara INTO TABLE i_mara "
WHERE matnr IN s_matnr AND
matkl IN s_grpmat AND
mtart = '3010'."s_cntmat.


"ENDIF.

"IF s_klart[] IS INITIAL.

* SELECT matnr matkl mtart FROM mara INTO TABLE i_mara "
* WHERE "matnr IN s_matnr AND
* "matkl IN s_grpmat AND
* mtart = '3010'."s_cntmat.

"ENDIF.


*IF s_cntmat[] IS INITIAL.
*
*MESSAGE 'Nu sunt date pentru selectia efectuata' TYPE 'E'.
* EXIT.
* ENDIF.
* Loop AT i_mara INTO WA_mara.
* ENDLOOP.

" ENDIF.


* IF i_makt1[] IS INITIAL.
* MESSAGE 'Nu s-au gasit inregistrari2!' TYPE 'E'.
* EXIT.
* ELSE.
* LOOP AT i_makt1 INTO wa_makt1.
* wa_matnr-sign = 'I'.
* wa_matnr-option = 'EQ'.
* wa_matnr-low = wa_makt1-matnr.
* APPEND wa_matnr TO ra_matnr.
* ENDLOOP.
* ENDIF.

* IF i_marc[] IS INITIAL.
* MESSAGE 'Nu s-au gasit inregistrari1!' TYPE 'E'.
* EXIT.
* ELSE.
* LOOP AT i_marc INTO wa_marc.
* wa_werks-sign = 'I'.
* wa_werks-option = 'EQ'.
* wa_werks-low = wa_marc-werks.
* APPEND wa_werks TO ra_werks.
* ENDLOOP.
* ENDIF.



SELECT class klart FROM klah INTO TABLE i_class1
WHERE class IN s_class
AND klart IN s_klart.

IF i_class1[] IS INITIAL.
MESSAGE 'Nu sunt date pentru selectia efectuata' TYPE 'E'.
EXIT.
ENDIF.

IF s_atinn[] IS NOT INITIAL. "s_atinn -caracteristica din select-options
IF i_class1[] IS NOT INITIAL.
SELECT imerk clint klart " imerk(are element de data atinn) -caracteristica interna , clint-numar intern clasa , klart-tip clasa
INTO TABLE i_ksml
FROM ksml FOR ALL ENTRIES IN i_class1
WHERE klart = i_class1-klart
AND imerk IN s_atinn "s_atinn = cabn-atinn
AND lkenz = space.
ENDIF.



IF i_ksml[] IS NOT INITIAL.
SORT i_ksml BY imerk ASCENDING.
i_ksml_te[] = i_ksml[].
LOOP AT i_ksml_te INTO wa_ksml.
AT NEW imerk.
PERFORM get_classes USING wa_ksml-imerk
wa_ksml-klart
wa_ksml-clint.
"wa_marc-werks.
ENDAT.
ENDLOOP.
IF i_charclass[] IS INITIAL.
MESSAGE 'Nu sunt date pentru selectia efectuata' TYPE 'E'.
EXIT.
ENDIF.
ENDIF.
ENDIF.

IF i_class1[] IS NOT INITIAL.
SELECT klart
status
stext
INTO TABLE i_status
FROM tclut
FOR ALL ENTRIES IN i_class1
WHERE klart = i_class1-klart
AND spras = sy-langu.
SELECT klart obtab
INTO TABLE i_tcla1
FROM tcla
FOR ALL ENTRIES IN i_class1
WHERE klart = i_class1-klart.
ENDIF.



IF s_atinn[] IS NOT INITIAL.
*Process the classes retrieved for the characteristics entered
LOOP AT i_charclass INTO wa_charclass.
PERFORM get_objects USING wa_charclass-objek1
wa_charclass-klart.
"wa_charclass-werks.
ENDLOOP.
ELSE.
*Process for all the classes entered
LOOP AT i_class1 INTO wa_class1.
PERFORM get_objects USING wa_class1-class
wa_class1-klart.

ENDLOOP.

* LOOP AT i_marc into wa_marc.
*
* Perform get_objects using wa_marc-werks.
*
* ENDLOOP.

ENDIF.

IF i_final[] IS NOT INITIAL.
PERFORM build_field_catalouge.

Refresh it_filter.
ls_filter-fieldname = 'MATKL'.
ls_filter-tabname = 'i_final[]'.
ls_filter-sign0 = 'I'.
ls_filter-optio = 'NE'.
ls_filter-valuf_int = ' '.
APPEND ls_filter TO It_filter.

PERFORM display_data.
** perform validate_screen.
**perform get_mat_stock_data.
* ELSE.
* MESSAGE 'No records found' TYPE 'E'.
* EXIT.
*
ENDIF.


*&---------------------------------------------------------------------*
*& Form GET_CLASSES
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_<FS_KSML>_IMERK text
*----------------------------------------------------------------------*
FORM get_classes USING p_imerk TYPE ksml-imerk
p_klart TYPE ksml-klart
p_clint TYPE ksml-clint.
"p_werks TYPE marc-werks.

DATA:i_classes TYPE tt_ctwul_output.
DATA:wa_classes TYPE ctwul_output.
DATA:wa_ksmltemp TYPE type_ksml.

DATA:wf_atnam TYPE atnam.
DATA:wf_werks TYPE werks.

CLEAR i_classes[].
WRITE p_imerk TO wf_atnam USING EDIT MASK '==ATINN'.
"WRITE p_werks TO wf_werks USING EDIT MASK '==WERKS'.

PERFORM get_characteristics TABLES i_classes
USING wf_atnam
p_klart.
"p_werks.
CHECK sy-subrc = 0.
LOOP AT i_classes INTO wa_classes WHERE objek1 IN s_class. "and objek1 in s_werks.
READ TABLE i_ksml WITH KEY clint = wa_classes-objek1_internal
klart = wa_classes-klart
TRANSPORTING NO FIELDS.

IF sy-subrc = 0.
MOVE : wa_classes-objek1 TO wa_charclass-objek1,
wa_classes-objek1_internal TO wa_charclass-objek1_internal,
wa_classes-klart TO wa_charclass-klart,
wa_classes-objek1_text TO wa_charclass-objek1_text.
wa_charclass-atnam = wf_atnam.
APPEND wa_charclass TO i_charclass.
CLEAR wa_charclass.
ENDIF.
ENDLOOP.




ENDFORM. " GET_CLASSES
*&---------------------------------------------------------------------*
*& Form GET_CHARACTERISTICS
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_I_CLASSES text
* -->P_WF_ATNAM text
* -->P_P_KLART text
*----------------------------------------------------------------------*
FORM get_characteristics TABLES p_classes TYPE tt_ctwul_output
USING p_atnam TYPE atnam
p_klart TYPE klah-klart.
"p_werks TYPE marc-werks.

CALL FUNCTION 'CTWUL_CHARACT_USAGE'
EXPORTING
charact_name = p_atnam
class_type = p_klart
classes = 'X'
IMPORTING
et_classes = p_classes[]
EXCEPTIONS
charact_not_found = 1
value_conversion = 2
no_authority = 3
OTHERS = 4.

ENDFORM. " GET_CHARACTERISTICS
*&---------------------------------------------------------------------*
*& Form GET_OBJECTS
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_WA_CLASS1_CLASS text
* -->P_WA_CLASS1_KLART text
*----------------------------------------------------------------------*
FORM get_objects USING p_wf_class TYPE any
p_klart TYPE klah-klart.
"p_werks type marc-werks.
"p_wf_werks TYPE any.

DATA:i_objclass TYPE TABLE OF sclass.
DATA:i_objectdata TYPE TABLE OF clobjdat.
DATA:i_objects TYPE TABLE OF clobjekte.
DATA:i_objects2 TYPE TABLE OF clobjekte.

DATA:wa_objclass TYPE sclass.
DATA:wa_objects TYPE clobjekte.
DATA:wa_object_data TYPE clobjdat.
DATA:wa_objects2 TYPE clobjekte.

DATA:wf_class TYPE klah-class.
DATA:wf_node_l TYPE i.
DATA:wf_node_h TYPE i.
DATA:wf_obtab TYPE tcla-obtab.
DATA:wf_werks TYPE marc-werks.
"DATA:wf_node_2 TYPE i.
"DATA:wf_node_h TYPE i.



"wf_werks = p_wf_werks.
wf_class = p_wf_class.

READ TABLE i_tcla1 INTO wa_tcla1 WITH KEY klart = wa_class1-klart.
IF sy-subrc = 0.
wf_obtab = wa_tcla1-obtab.
ENDIF.

CALL FUNCTION 'CLAF_OBJECTS_OF_CLASS'
EXPORTING
class = wf_class
classes = abap_true
classtext = abap_true
classtype = p_klart
language = sy-langu
key_date = sy-datum
objecttable = wf_obtab
initial_charact = wf_initial_char
TABLES
t_class = i_objclass
t_objectdata = i_objectdata
t_objects = i_objects
EXCEPTIONS
no_classification = 1
invalid_class_type = 2
OTHERS = 3.
IF sy-subrc = 0.

LOOP AT i_objects INTO wa_objects.
IF sy-tabix EQ 1.
wf_node_l = sy-tabix.
wf_node_h = wa_objects-anzaus.
ELSE.
wf_node_l = wf_node_h + 1.
wf_node_h = wf_node_h + wa_objects-anzaus.
ENDIF.

* IF ra_matnr[] IS NOT INITIAL.
* IF wa_objects-objekt NOT IN ra_matnr[].
* CONTINUE.
* ENDIF.
* ENDIF.

READ TABLE i_objclass INTO wa_objclass
WITH KEY class = wf_class.
IF sy-subrc NE 0.
CLEAR wa_objclass.
ENDIF.

IF s_atinn[] IS NOT INITIAL.
LOOP AT i_objectdata INTO wa_object_data FROM wf_node_l TO wf_node_h
WHERE atnam EQ wa_charclass-atnam.
PERFORM build_data USING wa_object_data
wa_objects
wa_objclass
p_klart
wf_class.
ENDLOOP.
ELSE.
LOOP AT i_objectdata INTO wa_object_data FROM wf_node_l TO wf_node_h.
PERFORM build_data USING wa_object_data
wa_objects
wa_objclass
p_klart
wf_class.

ENDLOOP.
ENDIF.
ENDLOOP.
ENDIF.
ENDFORM.





" GET_OBJECTS
*&---------------------------------------------------------------------*
*& Form BUILD_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_WA_OBJECTDATA text
* -->P_WA_OBJECTS text
* -->P_P_KLART text
* -->P_WF_CLASS text
*----------------------------------------------------------------------*
FORM build_data USING p_wa_objectdata TYPE clobjdat
p_wa_objects TYPE clobjekte
p_wa_class TYPE sclass
p_p_klart TYPE klah-klart
p_wf_class TYPE klah-class.
"p_wa_objects TYPE marc-matnr.

wa_final-matnr = p_wa_objects-objekt. "p_wa_objects-objekt.
wa_final-klart = p_p_klart.
wa_final-class = p_wf_class.
wa_final-status = p_wa_class-statu.
"wa_final-werks = p_wa_objects2-objekt. "p_wa_objects-objekt."
"wa_final-werks = wa_marc-werks."p_p_werks.
"wa_final-mtart = wa_mara-mtart.

IF wa_makt1-matnr <> p_wa_objects-objekt.
READ TABLE i_makt1 INTO wa_makt1
WITH KEY matnr = p_wa_objects-objekt BINARY SEARCH
TRANSPORTING maktx.
IF sy-subrc <> 0.
CLEAR wa_makt1.
ENDIF.
ENDIF.

IF wa_marc-werks <> p_wa_objects-objekt. "p_wa_objects-objekt.

READ TABLE i_marc INTO wa_marc
WITH KEY matnr = p_wa_objects-objekt BINARY SEARCH "p_wa_object2-objekt BINARY SEARCH
TRANSPORTING WERKS.

IF sy-subrc <> 0.
CLEAR wa_marc.
ENDIF.
ENDIF.

IF wa_mara-matkl <> p_wa_objects-objekt. "p_wa_object2-objekt.

READ TABLE i_mara INTO wa_mara
WITH KEY matnr = p_wa_objects-objekt BINARY SEARCH "p_wa_object2-objekt BINARY SEARCH
TRANSPORTING matnr matkl mtart.

IF sy-subrc <> 0.
CLEAR wa_mara.
ENDIF.
ENDIF.



wa_final-mtart = wa_mara-mtart.
wa_final-matkl = wa_mara-matkl.
wa_final-werks = wa_marc-werks.
wa_final-maktx = wa_makt1-maktx.
wa_final-atnam = p_wa_objectdata-atnam.
wa_final-atwrt = p_wa_objectdata-ausp1.
wa_final-atbez = p_wa_objectdata-smbez.
IF p_wa_class-statu <> wa_status-status.
READ TABLE i_status INTO wa_status
WITH KEY status = p_wa_class-statu.
IF sy-subrc <> 0.
CLEAR wa_status.
ENDIF.
ENDIF.
wa_final-stext = wa_status-stext.
APPEND wa_final TO i_final.
ENDFORM. " BUILD_DATA
*&---------------------------------------------------------------------*
*& Form BUILD_FIELD_CATALOUGE
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM build_field_catalouge .

wa_layout-colwidth_optimize = abap_true.
wa_layout-zebra = abap_true.

wa_fieldcat-fieldname = 'WERKS'.
wa_fieldcat-seltext_m = 'Unitate logistica'.
APPEND wa_fieldcat TO i_fieldcat.
CLEAR wa_fieldcat.

wa_fieldcat-fieldname = 'KLART'.
wa_fieldcat-seltext_m = 'Tip clasa'.
APPEND wa_fieldcat TO i_fieldcat.
CLEAR wa_fieldcat.

wa_fieldcat-fieldname = 'MTART'.
wa_fieldcat-seltext_m = 'Cont Material'.
APPEND wa_fieldcat TO i_fieldcat.
CLEAR wa_fieldcat.

wa_fieldcat-fieldname = 'MAKTX'.
wa_fieldcat-seltext_m = 'Descriere'.
APPEND wa_fieldcat TO i_fieldcat.
CLEAR wa_fieldcat.

* wa_fieldcat-fieldname = 'CLASS'.
* wa_fieldcat-seltext_m = 'Nume clasa'.
* APPEND wa_fieldcat TO i_fieldcat.
* CLEAR wa_fieldcat.

wa_fieldcat-fieldname = 'MATNR'.
wa_fieldcat-seltext_m = 'Cod Material'.
APPEND wa_fieldcat TO i_fieldcat.
CLEAR wa_fieldcat.

wa_fieldcat-fieldname = 'MATKL'.
wa_fieldcat-seltext_m = 'Grupa Material'.
APPEND wa_fieldcat TO i_fieldcat.
CLEAR wa_fieldcat.

wa_fieldcat-fieldname = 'ATNAM'.
wa_fieldcat-seltext_m = 'Nume caracteristica'.
APPEND wa_fieldcat TO i_fieldcat.
CLEAR wa_fieldcat.

wa_fieldcat-fieldname = 'ATWRT'.
wa_fieldcat-seltext_m = 'Valoare caracteristica'.
APPEND wa_fieldcat TO i_fieldcat.
CLEAR wa_fieldcat.



* wa_fieldcat-fieldname = 'STATUS'.
* wa_fieldcat-seltext_m = 'Status'.
* APPEND wa_fieldcat TO i_fieldcat.
* CLEAR wa_fieldcat.
*
* wa_fieldcat-fieldname = 'STEXT'.
* wa_fieldcat-seltext_m = 'Stare'.
* APPEND wa_fieldcat TO i_fieldcat.
* CLEAR wa_fieldcat.



ENDFORM. " BUILD_FIELD_CATALOUGE
*&---------------------------------------------------------------------*
*& Form DISPLAY_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM display_data .

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = sy-repid
i_grid_title = 'Clasificarea materialelor si caracteristicile lor'
is_layout = wa_layout
it_fieldcat = i_fieldcat[]
it_filter = it_filter
TABLES
t_outtab = i_final[]
EXCEPTIONS
program_error = 1
OTHERS = 2.
ENDFORM. " DISPLAY_DATA

Thank you for your answers until now. I have managed to make changes to my report but i still have some issues. When i put a value in s_grpmat it brings me all the columns in the grid except maktx. Also another thing that i would like to do is to be able to see all the materials even if i don`t put a value in s_matnr or in s_grpmat .Now is showing me only one material when i don`t put nothing in s_matnr and nothing in s_grpmat.

Thank you for your help!

capture.png (26.2 kB)
10 |10000 characters needed characters left characters exceeded

A few points.

1. Why use FOR ALL ENTRIES when you can use the usually more efficient and simpler INNER JOIN? E.g. this bit of code

SELECT matnr maktx FROM makt INTO TABLE i_makt1
     WHERE matnr IN s_matnr AND
           spras = sy-langu. 
" Note - here you should check if i_makt1 is empty
IF i_makt1 IS NOT INITIAL.<br>  SELECT werks matnr 
      INTO TABLE i_marc
      FROM MARC FOR ALL ENTRIES IN i_makt1
      WHERE matnr EQ i_makt1-matnr
        AND werks IN s_werks.
ENDIF.

Can be simplified, with a suitably defined internal table materials to

SELECT makt~matnr makt~maktx marc~werks FROM makt
    INTO TABLE materials
    INNER JOIN marc
       ON marc~matnr EQ makt~matnr
    WHERE makt~matn IN s_matnr
      AND marc~werks IN s_werks
      AND makt~spras EQ sy-langu.

You may well find a performance improvement.


2. Why use function module REUSE_ALV_GRID_DISPLAY, which is really old technology, when you can use something that is easier to use and provides richer functionality in CL_SALV_TABLE. And it that isn't suitable, using the classes directly for CL_GUI_ALV_GRID isn't too difficult.

3. You'll notice that above I used the "code" button in the editor, to make the ABAP easy to read. As a moderator, may I ask you in future to ensure that your code is properly formatted.

1

Why do you use TABLES?

0
Former Member
Horst Keller

Dear Horst ,

I use tables because and old programmer taught me like this.Is there any better way? Thank you

0

Yep, read the recent documentation and/or new books.

TABLES is obsolete since decades if not used for classical dynpros.

https://help.sap.com/http.svc/rc/abapdocu_751_index_htm/7.51/en-US/index.htm?file=abentable_work_area_guidl.htm

0
Former Member
Horst Keller

Thank you !

0
Former Member

Dear Matthew,

Thank you for your answer. I am delighted that you answered to my post. I read many answers that you gave to other programmers. I tried what you advised me below:

SELECT matnr maktx FROM makt INTO TABLE i_makt1
     WHERE matnr IN s_matnr AND
           spras = sy-langu. 
" Note - here you should check if i_makt1 is empty
IF i_makt1 IS NOT INITIAL.<br>  SELECT werks matnr 
      INTO TABLE i_marc
      FROM MARC FOR ALL ENTRIES IN i_makt1
      WHERE matnr EQ i_makt1-matnr
        AND werks IN s_werks.


The only problem is that my program still dosen`t fetch values in werks column. I cannot see any values. If it makes a difference i need also to fetch the material group and material account 3010 to this report. If i add :wa_final-werks = s_werks it shows me somehow the plant number with IEQ3000 .(3000 is the plant number in the selection screen which i should see only.) i don`t know what IEQ means. My code is properly formatted in abap editor. When i copied into my post the code aligned to left.Thank you so much again for spending your time helping a young abaper.

0
* Please Login or Register to Answer, Follow or Comment.

2 Answers

Michelle Crapo Jun 29, 2017 at 06:50 PM
1

OK without being on your system or looking at all your code:

MCHA will give you material/plant based on batch number. There probably will be several records. You can limit them based upon material.

FM 'BAPI_OBJCL_GETDETAIL' to retrieve the classification data. (See https://archive.sap.com/discussions/thread/705378)

Import params:

  • 1. Object key : Material number remember if it is all numeric - pad the front with 0s or use the FM for conversion
  • 2. Object table : MARA
  • 3. Class Num: Name of class
  • 4. Class type whatever class type you are using 21 for batch, 01 for material

You will get the classification data in the following tables:

  • ALLOCVALUESRNUM
  • ALLOCVALUESCHAR
  • ALLOCVALUESCUR

LQUA - you have material and batch you can use those, but what are you looking for? Just make sure you use the correct fields to check (Like blocking) It depends on how your system is set up.

There might be OOP that could help as well. I'm on an older system.

Show 4 Share
10 |10000 characters needed characters left characters exceeded
Former Member

Dear Michelle,

Thank you for your answer. I will try what you advised me and let you know. Thank you again.! I also need to fetch the stock for each material. Is the table mardh ok?

0

MARD is a great place to get that! The only thing you might want to think about is you can have stock in different states. What I mean is you can have blocked stock, quality inspection, and more buckets. So if you want to get all the stock, you would total the different fields in the table.

0
Former Member
Michelle Crapo

Dear Michelle,

Please tell me what do you mean by "MCHA will give you material/plant based on batch number. There probably will be several records. You can limit them based upon material." what is the batch number?

Thank you !

0
Former Member
Former Member

Thank you Michelle for your answer,

I am still struggling to fetch werks value from table marc based on select-option: s_werks. The result obtained in the column werks is matnr value instead of werks value.Do i need to put this sequence of code in the program in a specific place?.I still get the matnr value instead of value of werks if i add in my program wa_final-werks = s_werks..Please if you can give some help.

0
Raghu Govindarajan Jun 30, 2017 at 02:34 PM
-1

In your selection...

SELECT werks matnr 
INTO TABLE i_marc
FROM MARC FOR ALL ENTRIES IN i_makt1
WHERE matnr = i_makt1-matnr
AND werks IN s_werks.

... try using INTO CORRESPONDING FIELDS OF TABLE. That could have an impact on your getting the material in the WERKS field.

Show 4 Share
10 |10000 characters needed characters left characters exceeded
Former Member

Dear Raghu,

Thank you for your answer.I already tried that code in my program and it still doesn`t fetch the value of werks.Do i need to put this sequence of code in the program in a specific place?.I still get the matnr value instead of value of werks if i add in my program wa_final-werks = p_wa_objects-objekt.

0

Since werks and matnr are the defined in the type by which i_marc is defined - no, using INTO CORRESPONDING won't help at all.

0

Manole, I don't have access to an SAP system right now to test your code. However can you confirm that this selection is the first place you are seeing a problem? What about the previous selection from MAKT. Trying to narrow down where in the code you are first seeing the material in WERKS field. Have you run through the debugger at all, or are you just going from the final results?

0
Former Member

Dear Raghu,

Yes ,the problem is only in this selection. selections from makt work fine. i can see the material in werks field if i add : wa_final-werks = p_wa_objects-objekt to my program. I did run the debugger and see in the final results too.if i add :

wa_final-werks = s_werks it showd me the plant number with IEQ3000 .(3000 is the plant number in the selection screen) i don`t know what IEQ means.

Thank you!

0