Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

how to connect MSEG with MARC

former_member691402
Participant
0 Kudos

can I connect the two mseg and marc tables with the matnr and werks fields?

4 REPLIES 4

mateuszadamus
Active Contributor

Hello nick99999

Yes, you can find MARC record for each of the MSEG records by joining MARC with MSEG on mentioned fields.

MARC~MATNR = MSEG~MATNR and MARC~WERKS = MSEG~WERKS
Kind regards,
Mateusz

0 Kudos

thanks for the answer, another question, joining and also doing a where with the MARC fields with the input parameters and in addition a condition between marc and mseg, does the system understand which material it is referring to?

0 Kudos

Hello nick99999

If you prefix the field with the table name, like shown in my example, then yes, system knows. Otherwise, if it's unknown but required, you will receive an error message, that the field name is ambiguous.

Kind regards,
Mateusz

former_member1716
Active Contributor

Hello nick99999,

Yes you can join the fields from both tables, the ambiguity between the fields are removed using the alias names given to the tables. When the alias names are given system can understand the table to which it is referred to.

Please find the code below for your reference.

SELECT a~matnr,
       a~werks,
       b~mblnr
  FROM marc AS a               ---> A is the alias for MARC
  INNER JOIN mseg AS b         ---> B is the alias for MSEG
  ON a~matnr = b~matnr AND
     a~werks = b~werks         ---> Alias Names used as reference in Join Condition
  INTO TABLE @DATA(it_tab)
  WHERE a~matnr IN @s_matnr.   ---> Alias Names used as reference in where Condition
IF sy-subrc EQ 0.
  SORT it_tab BY matnr.
ENDIF.

Regards!