Skip to Content
avatar image
-1
Former Member

Batch number (CHARG) from AFPO when cannot find in MSEG

Hi experts,

Current code to get the Batch(MS."CHARG" CHARG) from MSEG table when goods movement happened, but i need to modify the code to get the batch number(AFPO-CHARG) before goods movement happened and at the time of production order creation that is table AFPO.

BEGIN

lt_marc_mseg =

SELECT

distinct

MS."MANDT"

, MC."WERKS" MARC_WERKS

, MS."CHARG" CHARG

, MC."MATNR"

, MC."WERKS" MSEG_WERKS

, MS."ZZDADATE" MSEG_ZZDADATE

, MS."ZZDATIME" MSEG_ZZDATIME

, MC."ZZDADATE" MARC_ZZDADATE

, MC."ZZDATIME" MARC_ZZDATIME

FROM"MSEG" MS

INNERJOIN"MARC" MC

ON MS."MATNR" = MC."MATNR"

AND MS."WERKS" = MC."WERKS"

AND MS."MATNR" = MC."MATNR"

WHERE 1=1

AND MC."XCHAR" ISNOTNULL

ANDltrim(MC."XCHAR", ' ') <> ''

AND MS."CHARG" <> ''

var_out =

SELECT

'SYS'as"0SAP"

, MS."MANDT"as"0MANDANT"

, MS."MSEG_WERKS" PLANT

, MS."CHARG" BATCHID

, MS."MATNR" PARTID

, MS."MARC_WERKS" PLANTOFPART

FROM :lt_marc_mseg ms

GROUPBY MS."MANDT"

, MS."MARC_WERKS"

, MS."CHARG"

, MS."MATNR"

, MS."MSEG_WERKS"

;

END/********* End Procedure Script ************/

Add comment
10|10000 characters needed characters exceeded

  • Former Member

    Hello Lars,

    Thanks for the reply, currently we are getting the Blade numbers from MSEG without issues, but how to modify the code in order to get Batch numbers from AFPO when the Batch number is missing in MSEG comparing MATNR and WERKS from MARC Table?

    Best

    Vadla

  • You haven’t told us what your question/problem is with this code.

    Looking at it I can tell you that a join on 1=1 is a bug in your code and that a GROUP BY without an aggregate function really is a DISTINCT projection.

    That in turn means your whole second statement is unnecessary.

    Besides these points: what do you think is the issue ?

  • Get RSS Feed

0 Answers