fetch material group,material account 3010 and Plant(WERKS)

SAP R/3 Materialwirtschaft: Einkauf, Bestandsführung, Rechnungsprüfung, Inventur, Bewertung, Leistungsabwicklung, Materialstamm...
1 Beitrag • Seite 1 von 1
1 Beitrag Seite 1 von 1

fetch material group,material account 3010 and Plant(WERKS)

Beitrag von dragospirnut1 (ForumUser / 7 / 0 / 0 ) »
Dear programmers,I want to make a report for material environment classification . Until now i can fetch the material,material description,material class name,material class type,material characteristic name and material characteristic value,material status number and material status name. I used so far TABLES:klah,mara,cabn,makt,marc.I think i can fetch ,material account 3010 from T134t with field MTART depedning on material group from T023T or MARA from the field MATKL and Plant(WERKS) from T001W? in the report below because i need to know each material from which plant belongs and depending on account 3010 and material group for each material .I tried to select werks from table marc based on the matnr from i_makt1-matnr and werks IN s_werks.the result in the column werks is matnr instead of werks. Please if anyone can give me some help much appreciated. The report is below and the output is attached to this post:

capture.png

TABLES:klah,
mara,
cabn,
makt,
marc.

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
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
"werks TYPE marc-werks,
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, "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 marc-werks,
END OF type_final.

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

*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.

*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_marc_te TYPE STANDARD TABLE OF type_marc.

*Variabile
DATA:wf_initial_char TYPE rmclm-basisd. "rmclm-structura , basisd-Date de bază sistem de clasificare

*selection screen
SELECT-OPTIONS: s_klart FOR klah-klart,"Class type
s_class FOR klah-class OBLIGATORY MATCHCODE OBJECT clas DEFAULT 'Z_MEDIU'."Class name
"SELECT-OPTIONS: s_maktx FOR makt-maktx NO INTERVALS NO-EXTENSION. "Material Decsription
SELECT-OPTIONS: s_matnr FOR mara-matnr default ''. "Material No
SELECT-OPTIONS: s_prdha FOR mara-prdha. "Product heirarchy
SELECT-OPTIONS: s_atinn FOR cabn-atinn. "characteristics
SELECT-OPTIONS: s_werks FOR t001w-werks DEFAULT '3000'. "Unitate logistica
SELECTION-SCREEN SKIP 1.
"PARAMETER p_disch AS CHECKBOX. "Skip characteristics with initial value

START-OF-SELECTION.

* IF s_matnr[] IS NOT INITIAL OR s_maktx IS NOT INITIAL. " OR s_werks[] IS not initial.
* IF s_maktx IS NOT INITIAL.
* LOOP AT s_maktx.
* CALL FUNCTION 'TERM_TRANSLATE_TO_UPPER_CASE'
* EXPORTING
* langu = sy-langu
* text = s_werks-low
* IMPORTING
* text_uc = s_werks-low
* EXCEPTIONS
* no_locale_available = 1
* OTHERS = 2.
* IF sy-subrc = 0.
* MODIFY s_maktx INDEX sy-tabix TRANSPORTING low.
* ENDIF.
* ENDLOOP.
* ENDIF.

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


" ENDIF.

SELECT werks matnr " imerk(are element de data atinn) -caracteristica interna , clint-numar intern clasa , klart-tip clasa
INTO TABLE i_marc
FROM MARC FOR ALL ENTRIES IN i_makt1
WHERE matnr = i_makt1-matnr
AND werks IN s_werks.
"AND matnr IN s_matnr.




IF i_makt1[] IS INITIAL.
MESSAGE 'Nu s-au gasit inregistrari!' 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 inregistrari!' 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 'No records found' 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 'No records found' 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 p_disch IS INITIAL.
* wf_initial_char = abap_true..
* 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.
"wa_class1-werks.
ENDLOOP.
ENDIF.

IF i_final[] IS NOT INITIAL.
PERFORM build_field_catalouge.
PERFORM display_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.

DATA:i_objclass TYPE TABLE OF sclass.
DATA:i_objectdata TYPE TABLE OF clobjdat.
DATA:i_objects 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.

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.

IF ra_werks[] IS INITIAL.
IF wa_objects-objekt NOT IN ra_werks[].
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".
wa_objects2.
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".
wa_objects2.
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_object2 TYPE clobjekte.
"p_p_werks TYPE marc-werks.

wa_final-matnr = 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_object2-objekt.
wa_final-werks = s_werks.

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_object2-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.
" 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 = 'MATNR'.
wa_fieldcat-seltext_m = 'Cod 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 = 'KLART'.
wa_fieldcat-seltext_m = 'Tip clasa'.
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 = 'ATBEZ'.
* wa_fieldcat-seltext_m = 'Characteristic Text'.
* 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.

wa_fieldcat-fieldname = 'WERKS'.
wa_fieldcat-seltext_m = 'Unitate logistica'.
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[]
TABLES
t_outtab = i_final[]
EXCEPTIONS
program_error = 1
OTHERS = 2.
ENDFORM. " DISPLAY_DATA

I need to fetch also material account( MTART with condition 3010) and material group (MATKL) and in Unitate logistica i need to have the plant 3000 without IEQ. Please give some help if someone know. I tried some things but is not working

capture.png (47.8 kB)


Thank you ,Julian

gesponsert
Stellenangebote auf ABAPforum.com schalten
kostenfrei für Ausbildungsberufe und Werksstudenten


Seite 1 von 1

Vergleichbare Themen

1
Antw.
2209
Views
fetch material group,material account 3010 and Plant(WERKS)
von dragospirnut1 » 05.07.2017 12:27 • Verfasst in ABAP Objects®
1
Antw.
2276
Views
Gemeinkostenzuschlag Material
von Makaay » 24.05.2005 15:27 • Verfasst in Financials
8
Antw.
5633
Views
Dokumente zu Material
von Gottschall » 29.10.2013 20:08 • Verfasst in ABAP® für Anfänger
3
Antw.
6752
Views
Konfigurierbares Material
von juergen.waibel » 17.06.2013 11:21 • Verfasst in Material Management & Produktionsplanung
5
Antw.
4624
Views
Subcontracting Material
von Apabtalker » 21.07.2010 14:39 • Verfasst in Material Management & Produktionsplanung

Über diesen Beitrag

dragospirnut1
Unterstütze die Community und teile den Beitrag für mehr Leser und Austausch

Newsletter Anmeldung

Keine Beiträge verpassen! Wöchentlich versenden wir lesenwerte Beiträge aus unserer Community.
Die letzte Ausgabe findest du hier.
Details zum Versandverfahren und zu Ihren Widerrufsmöglichkeiten findest du in unserer Datenschutzerklärung.

Unbeantwortete Forenbeiträge

aRFC im OO-Kontext
vor 4 Wochen von ralf.wenzel 1 / 1567
Hilfe bei SWEC/SWE2
letzen Monat von retsch 1 / 8175