cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Help me with this code to display the FG code against each material code.

tanya-singh222
Explorer
0 Likes
479

This is my abap code block

DATA
it_fg_code TYPE TABLE OF mast-matnr,   " Table to store FG Codes
      matnr1      TYPE mast-matnr.           " Variable for single FG Code

SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE text-001.

SELECT-OPTIONS material FOR mast-matnr.
SELECT-OPTIONS plant FOR mast-werks.

SELECTION-SCREEN END OF BLOCK B1.

START-OF-SELECTION.

" Step 1: Fetch FG Code from MAST table for material type 'FERT'
SELECT DISTINCT mast~matnr
  INTO TABLE IT_MTYPE1
  FROM mast
  INNER JOIN mara ON mast~matnr mara~matnr
  WHERE mast~matnr IN material
    AND mara~MTART 'FERT'.

" Step 2: Fetch details from MAST, STPO, and MAKt for materials and their exploded parts
SELECT mast~werks
       mast~stlnr
       mast~matnr
       makt~maktx
       idnrk
       stpo~menge
  INTO CORRESPONDING FIELDS OF TABLE itm_details
  FROM mast AS mast
  INNER JOIN stpo AS stpo ON mast~stlnr stpo~stlnr
  INNER JOIN makt AS makt ON mast~matnr makt~matnr
  WHERE mast~matnr IN material
    AND werks IN plant
    AND stpo~stlty 'M'
    AND mast~stlal mast~stlal.

IF NOT itm_details[] IS INITIAL.

  " Step 3: Fetch location data
  SELECT matnr
         werks
         lgpro
    INTO CORRESPONDING FIELDS OF TABLE it_loc
    FROM marc
    FOR ALL ENTRIES IN itm_details
    WHERE werks itm_details-werks
    AND matnr itm_details-matnr.

ENDIF.

IF NOT itm_details[] IS INITIAL.

  " Step 4: Fetch verification data for the materials
  SELECT mast~matnr
         mast~werks
         verid
         bdatu
         adatu
         mkal~stlal
         bstma
         idnrk
    INTO CORRESPONDING FIELDS OF TABLE it_ver
    FROM mast AS mast
    INNER JOIN mkal AS mkal ON mast~matnr mkal~matnr
    INNER JOIN stpo AS stpo ON mast~stlnr stpo~stlnr
    FOR ALL ENTRIES IN itm_details
    WHERE mast~werks itm_details-werks
    AND mast~matnr itm_details-matnr.

ENDIF.

* Step 5: Loop through itm_details and update FG Code for 'FERT' type materials
LOOP AT itm_details INTO DATA(ls_item).

  " Check if material type is 'FERT' by checking against IT_MTYPE1
  READ TABLE it_mtype1 INTO matnr1 WITH KEY matnr ls_item-matnr.
  IF sy-subrc 0.
    " Assign FG Code to the structure only for 'FERT' materials
    ls_item-fg_code matnr1.  " Assign FG Code to the structure
  ELSE.
    " For exploded parts, set FG code to blank or empty
    ls_item-fg_code ''.  " No FG code for exploded parts
  ENDIF.


The above mentioned code is displaying this output

tanyasingh222_0-1740388513270.png

I want on the FERT codes to be displayed against it. 

Accepted Solutions (0)

Answers (0)