ABAP Interactive reporting + BDC (RM Creation)

REPORT ZMM01_RM .

TABLES: mara,
        marc,
        makt.

DATA: BEGIN OF bdcdata OCCURS 0.
        INCLUDE STRUCTURE bdcdata.
DATA: END OF bdcdata.

DATA: BEGIN OF waRm OCCURS 0,
        mtart LIKE mara-mtart,
        werks LIKE marc-werks,
        lgort LIKE mard-lgort,
        maktx LIKE makt-maktx,
        meins LIKE mara-meins,
        matkl LIKE mara-matkl,
        extwg LIKE mara-extwg,
        ekwsl LIKE mara-ekwsl,
        plifz LIKE marc-plifz,
        peinh LIKE mbew-peinh,
        stprs LIKE mbew-stprs,
        losgr LIKE marc-losgr,
        j_4kcsgr LIKE mara-j_4kcsgr,
      END OF waRm.

DATA itab_waRm LIKE STANDARD TABLE OF waRm.

DATA: matType LIKE mara-mtart,
      plndate(3)  TYPE C, "marc-plifz.
      stdprice(12) TYPE C, "mbew-stprs
      priceunt(5) TYPE C, "mbew-peinh
      ok_code LIKE sy-ucomm.

SELECTION-SCREEN BEGIN OF BLOCK b2 WITH FRAME TITLE text-002.
  PARAMETER werks LIKE marc-werks DEFAULT '1000' OBLIGATORY.
  PARAMETER lgort LIKE mard-lgort OBLIGATORY.
  PARAMETER maktx LIKE makt-maktx OBLIGATORY.
  PARAMETER meins LIKE mara-meins OBLIGATORY.
  PARAMETER matkl LIKE mara-matkl OBLIGATORY.
  PARAMETER extwg LIKE mara-extwg OBLIGATORY.
  PARAMETER ekwsl LIKE mara-ekwsl OBLIGATORY.
  PARAMETER j_3apgnr LIKE mara-j_3apgnr OBLIGATORY.
  PARAMETER peinh LIKE mbew-peinh DEFAULT '1' OBLIGATORY.
  PARAMETER stprs LIKE mbew-stprs OBLIGATORY.
  PARAMETER losgr LIKE marc-losgr DEFAULT '1000' OBLIGATORY.
SELECTION-SCREEN END OF BLOCK b2.

SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
  PARAMETERS yfab  RADIOBUTTON GROUP GR1 USER-COMMAND ACT DEFAULT 'X'.
  PARAMETERS yacc  RADIOBUTTON GROUP GR1.
  PARAMETERS ypak  RADIOBUTTON GROUP GR1.
SELECTION-SCREEN END OF BLOCK b1.

*SELECTION-SCREEN BEGIN OF BLOCK b2 WITH FRAME TITLE text-002.
**
*SELECTION-SCREEN END OF BLOCK b2 .

SELECTION-SCREEN BEGIN OF BLOCK b3 WITH FRAME TITLE text-003.
  PARAMETER zeinr LIKE mara-zeinr.
  PARAMETER j_3afcc LIKE mara-j_3afcc MODIF ID A.
  PARAMETER j_3acol LIKE mara-j_3acol MODIF ID A.
  PARAMETER plifz LIKE marc-plifz .
  PARAMETER j_4kcsgr LIKE mara-j_4kcsgr .
  PARAMETER land1 LIKE t005-land1.
SELECTION-SCREEN END OF BLOCK b3 .

AT SELECTION-SCREEN.
  ok_code = sy-ucomm.

AT SELECTION-SCREEN OUTPUT.
  LOOP AT screen.
    IF yfab = 'X'.
      IF screen-group1 = 'B'.
        screen-active = 0.
      ENDIF.
    ELSEIF yacc = 'X' OR ypak = 'X'.
      IF screen-group1 = 'A'.
        screen-active = 0.
      ENDIF.
    ENDIF.
    MODIFY screen.
  ENDLOOP.


START-OF-SELECTION.

  CLEAR: matType, plndate, stdprice, priceunt.

  IF yfab = 'X'.
    matType = 'ZFAB'.
  ELSEIF yacc = 'X'.
    matType = 'ZACC'.
  ELSEIF ypak = 'X'.
    matType = 'ZPAK'.
  ENDIF.

  plndate  = plifz.
  stdprice = stprs.
  priceunt = peinh.

  perform bdc_dynpro      using 'SAPLMGMM' '0060'.
  perform bdc_field       using 'BDC_OKCODE'  '=ENTR'.
  perform bdc_field       using 'RMMG1-MBRSH'  'F'.
  perform bdc_field       using 'RMMG1-MTART'  matType.

  IF matType = 'ZFAB'.
    perform bdc_dynpro      using 'SAPLMGMM' '0070'.
    perform bdc_field       using 'BDC_OKCODE'  '/00'.
    perform bdc_field       using 'MSICHTAUSW-KZSEL(01)'  'X'.
    perform bdc_field       using 'MSICHTAUSW-KZSEL(02)'  'X'.
    perform bdc_field       using 'MSICHTAUSW-KZSEL(03)'  'X'.
    perform bdc_field       using 'MSICHTAUSW-KZSEL(05)'  'X'.
    perform bdc_field       using 'MSICHTAUSW-KZSEL(08)'  'X'.
    perform bdc_field       using 'MSICHTAUSW-KZSEL(09)'  'X'.
    perform bdc_field       using 'MSICHTAUSW-KZSEL(10)'  'X'.
    perform bdc_field       using 'MSICHTAUSW-KZSEL(11)'  'X'.
    perform bdc_field       using 'MSICHTAUSW-KZSEL(12)'  'X'.

    PERFORM bdc_field       USING 'BDC_OKCODE' '=P+'.
    perform bdc_dynpro      using 'SAPLMGMM' '0070'.
    perform bdc_field       using 'MSICHTAUSW-KZSEL(01)'  'X'.
    perform bdc_field       using 'MSICHTAUSW-KZSEL(02)'  'X'.
    perform bdc_field       using 'MSICHTAUSW-KZSEL(03)'  'X'.
    perform bdc_field       using 'MSICHTAUSW-KZSEL(04)'  'X'.
    perform bdc_field       using 'MSICHTAUSW-KZSEL(05)'  'X'.
    perform bdc_field       using 'BDC_OKCODE'  '=ENTR'.
  ELSEIF matType = 'ZACC' OR matType = 'ZPAK'.
    perform bdc_dynpro      using 'SAPLMGMM' '0070'.
    perform bdc_field       using 'BDC_OKCODE'  '/00'.
    perform bdc_field       using 'MSICHTAUSW-KZSEL(01)'  'X'.
    perform bdc_field       using 'MSICHTAUSW-KZSEL(02)'  'X'.
    perform bdc_field       using 'MSICHTAUSW-KZSEL(03)'  'X'.
    perform bdc_field       using 'MSICHTAUSW-KZSEL(05)'  'X'.
    perform bdc_field       using 'MSICHTAUSW-KZSEL(08)'  'X'.
    perform bdc_field       using 'MSICHTAUSW-KZSEL(09)'  'X'.
    perform bdc_field       using 'MSICHTAUSW-KZSEL(10)'  'X'.
    perform bdc_field       using 'MSICHTAUSW-KZSEL(11)'  'X'.
    perform bdc_field       using 'MSICHTAUSW-KZSEL(12)'  'X'.
    perform bdc_field       using 'MSICHTAUSW-KZSEL(15)'  'X'.
    perform bdc_field       using 'MSICHTAUSW-KZSEL(16)'  'X'.
    perform bdc_field       using 'MSICHTAUSW-KZSEL(17)'  'X'.
    perform bdc_field       using 'MSICHTAUSW-KZSEL(18)'  'X'.

    PERFORM bdc_field       USING 'BDC_OKCODE' '=P+'.
    perform bdc_dynpro      using 'SAPLMGMM' '0070'.
    perform bdc_field       using 'MSICHTAUSW-KZSEL(01)'  'X'.
    perform bdc_field       using 'BDC_OKCODE'  '=ENTR'.
  ENDIF.
* Organizational Level
  perform bdc_dynpro      using 'SAPLMGMM' '0080'.
  perform bdc_field       using 'BDC_OKCODE'  '=ENTR'.
  perform bdc_field       using 'RMMG1-WERKS'  werks.
  perform bdc_field       using 'RMMG1-LGORT'  lgort.
* Basic Data 1
  perform bdc_dynpro      using 'SAPLMGMM' '4004'.
  perform bdc_field       using 'BDC_OKCODE'  '/00'.
  perform bdc_field       using 'MAKT-MAKTX'  maktx.
  perform bdc_field       using 'MARA-MEINS'  meins.
  perform bdc_field       using 'MARA-MATKL'  matkl.
  perform bdc_field       using 'MARA-EXTWG'  extwg.
* Basic Data 2
  perform bdc_dynpro      using 'SAPLMGMM' '4004'.
  perform bdc_field       using 'BDC_OKCODE'  '/00'.
  perform bdc_field       using 'MAKT-MAKTX'  maktx.
  perform bdc_field       using 'MARA-ZEINR'  zeinr.
  perform bdc_field       using 'MARA-J_3AFCC'  j_3afcc.
* AFS Basic Data
  perform bdc_dynpro      using 'SAPLMGMM' '4030'.
  perform bdc_field       using 'BDC_OKCODE'  '=AFSSTAT'.
  perform bdc_field       using 'MAKT-MAKTX'  maktx.
  perform bdc_field       using 'MARA-J_3APGNR'  j_3apgnr.
  perform bdc_field       using 'MARA-J_3ACOL'  j_3acol.
  IF j_3apgnr <> 'NO GRID'.
    perform bdc_field       using 'MARA-J_3ANOGRID'  ''.
  ELSE.
    perform bdc_field       using 'MARA-J_3ANOGRID'  'X'.
  ENDIF.
  perform bdc_field       using 'MARA-J_4KCSGR'  j_4kcsgr.
  perform bdc_field       using 'MARA-J_4KCOVSA'  j_4kcsgr.
  perform bdc_field       using 'MARA-MEINS'  meins.

  perform bdc_dynpro      using 'SAPLSPO1' '0300'.
  perform bdc_field       using 'BDC_OKCODE'  '=YES'.

  perform bdc_dynpro      using 'SAPLMGMM' '4030'.
  perform bdc_field       using 'BDC_OKCODE'  '/00'.
  perform bdc_field       using 'MAKT-MAKTX'  maktx.
  IF j_3apgnr <> 'NO GRID'.
    perform bdc_field       using 'MARA-J_3ANOGRID'  ''.
  ELSE.
    perform bdc_field       using 'MARA-J_3ANOGRID'  'X'.
  ENDIF.
  perform bdc_field       using 'MARA-MEINS'  meins.

  perform bdc_dynpro      using 'SAPLMGMM' '4030'.
  perform bdc_field       using 'BDC_OKCODE'  '/00'.
  perform bdc_field       using 'MAKT-MAKTX'  maktx.
* Purchasing
  perform bdc_dynpro      using 'SAPLMGMM' '4000'.
  perform bdc_field       using 'BDC_OKCODE'  '/00'.
  perform bdc_field       using 'MAKT-MAKTX'  maktx.
  perform bdc_field       using 'MARA-MEINS'  meins.
  perform bdc_field       using 'MARA-MATKL'  matkl.
  perform bdc_field       using 'MARA-EKWSL'  '2'.
* MRP 1
  perform bdc_dynpro      using 'SAPLMGMM' '4000'.
  perform bdc_field       using 'BDC_OKCODE'  '/00'.
  perform bdc_field       using 'MAKT-MAKTX'  maktx.
  perform bdc_field       using 'MARA-MEINS'  meins.
  perform bdc_field       using 'MARC-DISMM'  'PD'.
  perform bdc_field       using 'MARC-DISPO'  '100'.
  perform bdc_field       using 'MARC-DISLS'  'EX'.
* MRP 2
  perform bdc_dynpro      using 'SAPLMGMM' '4000'.
  perform bdc_field       using 'BDC_OKCODE'  '/00'.
  perform bdc_field       using 'MAKT-MAKTX'  maktx.
  perform bdc_field       using 'MARC-SOBSL'  '80'.
  perform bdc_field       using 'MARC-PLIFZ'  plndate.
  perform bdc_field       using 'MARC-FHORI'  '000'.
* MRP 3
  perform bdc_dynpro      using 'SAPLMGMM' '4000'.
  perform bdc_field       using 'BDC_OKCODE'  '/00'.
  perform bdc_field       using 'MAKT-MAKTX'  maktx.
  perform bdc_field       using 'MARC-PERKZ'  'M'.
  perform bdc_field       using 'MARC-MTVFP'  '02'.
* MRP 4
  perform bdc_dynpro      using 'SAPLMGMM' '4000'.
  perform bdc_field       using 'BDC_OKCODE'  '/00'.
  perform bdc_field       using 'MAKT-MAKTX'  maktx.
* AFS MRP
  perform bdc_dynpro      using 'SAPLMGMM' '4030'.
  perform bdc_field       using 'BDC_OKCODE'  '=AFSSTATC'.
  perform bdc_field       using 'MAKT-MAKTX'  maktx.
  perform bdc_field       using 'MARC-J_3ADISPKZ'  'N'.
  perform bdc_field       using 'MARC-J_3ACHINT'  'X'.
  perform bdc_field       using 'MARC-XCHPF'  'X'.

  perform bdc_dynpro      using 'SAPLSPO1' '0300'.
  perform bdc_field       using 'BDC_OKCODE'  '=YES'.

  perform bdc_dynpro      using 'SAPLMGMM' '4030'.
  perform bdc_field       using 'BDC_OKCODE'  '/00'.
  perform bdc_field       using 'MAKT-MAKTX'  maktx.
  perform bdc_field       using 'MARC-J_3ADISPKZ'  'N'.
  perform bdc_field       using 'MARC-XCHPF'  'X'.

  perform bdc_dynpro      using 'SAPLMGMM' '4030'.
  perform bdc_field       using 'BDC_OKCODE'  '/00'.
  perform bdc_field       using 'MAKT-MAKTX'  maktx.

  perform bdc_dynpro      using 'SAPLMGMM' '4030'.
  perform bdc_field       using 'BDC_OKCODE'  '/00'.
  perform bdc_field       using 'MAKT-MAKTX'  maktx.

  perform bdc_dynpro      using 'SAPLMGMM' '4030'.
  perform bdc_field       using 'BDC_OKCODE'  '/00'.
  perform bdc_field       using 'MAKT-MAKTX'  maktx.
* Accounting 1
  perform bdc_dynpro      using 'SAPLMGMM' '4000'.
  perform bdc_field       using 'BDC_OKCODE'  '/00'.
  perform bdc_field       using 'MAKT-MAKTX'  maktx.
  perform bdc_field       using 'MARA-MEINS'  meins.
  perform bdc_field       using 'MBEW-PEINH'  priceunt.
  perform bdc_field       using 'MBEW-STPRS'  stdprice.
* Accounting 2
  perform bdc_dynpro      using 'SAPLMGMM' '4000'.
  perform bdc_field       using 'BDC_OKCODE'  '/00'.
  perform bdc_field       using 'MAKT-MAKTX'  maktx.
* AFS Valuation
  perform bdc_dynpro      using 'SAPLMGMM' '4030'.
  perform bdc_field       using 'BDC_OKCODE'  '/00'.
  perform bdc_field       using 'MAKT-MAKTX'  maktx.
  perform bdc_field       using 'MARC-J_4KDEFSC'  land1.
* Costing 1
  perform bdc_dynpro      using 'SAPLMGMM' '4000'.
  perform bdc_field       using 'BDC_OKCODE'  '/00'.
  perform bdc_field       using 'MAKT-MAKTX'  maktx.
  perform bdc_field       using 'MARA-MEINS'  meins.
  perform bdc_field       using 'MARC-NCOST'  'X'.
  perform bdc_field       using 'MBEW-HKMAT'  'X'.
  perform bdc_field       using 'MARC-PRCTR'  matkl.
  perform bdc_field       using 'MARC-LOSGR'  '1000'.
* Costing 2
  perform bdc_dynpro      using 'SAPLMGMM' '4000'.
  perform bdc_field       using 'BDC_OKCODE'  '/00'.
  perform bdc_field       using 'MAKT-MAKTX'  maktx.
  perform bdc_field       using 'MBEW-PEINH'  priceunt.
  perform bdc_field       using 'MBEW-STPRS'  stdprice.

  perform bdc_dynpro      using 'SAPLSPO1' '0300'.
  perform bdc_field       using 'BDC_OKCODE'  '=YES'.

  CALL TRANSACTION 'MM01' USING bdcdata MODE 'E' UPDATE 'S'.
  REFRESH bdcdata.
  CLEAR: lgort, maktx, meins, matkl, extwg, ekwsl, j_3apgnr,
         plifz, stprs, j_4kcsgr, land1.

*---------------------------------------------------------------------*
*       FORM BDC_DYNPRO                                               *
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
*  -->  PROGRAM                                                       *
*  -->  DYNPRO                                                        *
*---------------------------------------------------------------------*
FORM bdc_dynpro USING program dynpro.
  CLEAR bdcdata.
  bdcdata-program  = program.
  bdcdata-dynpro   = dynpro.
  bdcdata-dynbegin = 'X'.
  APPEND bdcdata.
ENDFORM.                    " BDC_DYNPRO

*---------------------------------------------------------------------*
*       FORM BDC_FIELD                                                *
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
*  -->  FNAM                                                          *
*  -->  FVAL                                                          *
*---------------------------------------------------------------------*
FORM bdc_field USING fnam fval.
  CLEAR bdcdata.
  bdcdata-fnam = fnam.
  bdcdata-fval = fval.
  APPEND bdcdata.
ENDFORM.
*-- Kosala Wijesuriya

Get help for your ABAP problems
Do you have a ABAP Question?

ABAP Books
ABAP Certification, BAPI, Java, Web Programming, Smart Forms, Sapscripts Reference Books

BDC Tips and Tricks 
BDC Programming Tips

ABAP Programming Tips
ABAP Forum for Discussion and Samples Program Codes for Abapers

Best regards,
SAP Basis, ABAP Programming and Other IMG Stuff
http://www.erpgreat.com

All the site contents are Copyright © www.erpgreat.com and the content authors. All rights reserved.
All product names are trademarks of their respective companies.  The site www.erpgreat.com is in no way affiliated with SAP AG.
Every effort is made to ensure the content integrity.  Information used on this site is at your own risk.
 The content on this site may not be reproduced or redistributed without the express written permission of
www.erpgreat.com or the content authors.