Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

Report on bdc field valuation based on matnr

dear experts,

                  we have requirement we need to valudate material by assigning grid based on tables mara  j_3apgen based on flat file. in flat file each material have one grid based on material colour and length we have to assign valution type(grid) on mm02 transction.

iam attching the screen shot of my mm02 transction.

fst enter some material number nxt all scrren tabes are come click afs valution tab.

          

this my code

REPORT zmm02_val

        NO STANDARD PAGE HEADING LINE-SIZE 255.

TYPE-POOLS: slis.

*INCLUDE bdcrecx1.

*******************DATA declaration

TYPES: BEGIN OF ty_file,

        matnr(18),    " Material number

        werks(4),    " Plant

        j_3akord1(8), " Default grid value

        j_3akord2(8), " Value of the First Dimension

        j_3akord3(8), " Value of the second Dimension

*      j_4kscat(16), " Stock category

        j_3akalgr(10)," Valuation Type (AFS)

        j_3akalsw(1), " Preference SKU

        END OF ty_file.

TYPES: BEGIN OF ty_mara,

        matnr    TYPE mara-matnr,

        j_3apgnr TYPE mara-j_3apgnr,

      END OF ty_mara.

*****Internal table decleration

DATA: it_mara TYPE TABLE OF ty_mara,

      wa_mara TYPE ty_mara.

TYPES:BEGIN OF ty_j_3apgen.

        INCLUDE STRUCTURE j_3apgen.

TYPES:matnr TYPE mara-matnr,

      END OF ty_j_3apgen.

DATA:it_j_3apgen TYPE TABLE OF ty_j_3apgen,

      wa_j_3apgen TYPE ty_j_3apgen.

DATA :wa_bdcdata TYPE bdcdata,

      it_bdcdata TYPE TABLE OF bdcdata.

DATA:wa_params  TYPE ctu_params,

      it_messtab  TYPE STANDARD TABLE OF bdcmsgcoll,

      wa_messtab TYPE bdcmsgcoll.

DATA:it_file TYPE STANDARD TABLE OF ty_file,

      wa_file TYPE ty_file.

DATA:it_file1 TYPE STANDARD TABLE OF ty_file,

      wa_file1 TYPE ty_file.

DATA:it_file2 TYPE STANDARD TABLE OF ty_file,

      wa_file2 TYPE ty_file.

DATA:it_file_tmp TYPE STANDARD TABLE OF ty_file,

      wa_file_tmp TYPE ty_file.

DATA: var(4)  TYPE c,                                " record count.

      mess(200) TYPE c,

      cnt(2) TYPE n,

      cnt1(2) TYPE n..

DATA: lv_j_3akord1(30),

      lv_j_3akord2(30),

      lv_j_4kscat(30),

      lv_j_3akalsw(30),

      lv_j_3akalgr(30).

*********** selection-screen

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

PARAMETERS:  p_file TYPE rlgrap-filename OBLIGATORY.

PARAMETERS : mod TYPE ctu_params-dismode DEFAULT 'A'.

PARAMETERS : upd TYPE ctu_params-updmode DEFAULT 'S'.

SELECTION-SCREEN END OF BLOCK b1.

************** at selection-screen on value-request

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.

  PERFORM validate_file USING p_file.

*&---------------------------------------------------------------------*

*&      Form  VALIDATE_FILE

*&---------------------------------------------------------------------*

*      text

*----------------------------------------------------------------------*

*      -->P_P_FILE  text

*----------------------------------------------------------------------*

FORM validate_file  USING    p_p_file.

  CALL FUNCTION 'F4_FILENAME'

    EXPORTING

      program_name  = syst-cprog

      dynpro_number = syst-dynnr

      field_name    = 'P_FILE'

    IMPORTING

      file_name    = p_file.

ENDFORM.                    " VALIDATE_FILE

******************* start-of-selection

START-OF-SELECTION.

  wa_params-dismode = mod. " 'A'. "All screen mode

  wa_params-updmode = upd. " 'S'. "Asynchronous or synchronous update

  wa_params-defsize = 'X'. "standard size

  wa_params-nobinpt = 'X'.

  wa_params-nobiend = 'X'.

  PERFORM get_data.

  PERFORM featch_table_data.

  PERFORM bdc_upload.

*************** end-of-selection

END-OF-SELECTION.

  PERFORM display_bdc_error_log.

*&---------------------------------------------------------------------*

*&      Form  GET_DATA

*&---------------------------------------------------------------------*

*      text

*----------------------------------------------------------------------*

*  -->  p1        text

*  <--  p2        text

*----------------------------------------------------------------------*

FORM get_data .

  DATA: v_file TYPE string.

  v_file = p_file.                    "  data type conversion

  CALL FUNCTION 'GUI_UPLOAD'

    EXPORTING

      filename                      = v_file

      filetype                      = 'ASC'

      has_field_separator            = 'X'

*  HEADER_LENGTH                = 0

*  READ_BY_LINE                  = 'X'

*  DAT_MODE                      = ' '

*  CODEPAGE                      = ' '

*  IGNORE_CERR                  = ABAP_TRUE

*  REPLACEMENT                  = '#'

*  CHECK_BOM                    = ' '

*  VIRUS_SCAN_PROFILE            =

*  NO_AUTH_CHECK                = ' '

*  ISDOWNLOAD                    = ' '

* IMPORTING

*  FILELENGTH                    =

*  HEADER                        =

    TABLES

      data_tab                      = it_file

* CHANGING

*  ISSCANPERFORMED              = ' '

    EXCEPTIONS

      file_open_error              = 1

      file_read_error              = 2

      no_batch                      = 3

      gui_refuse_filetransfer      = 4

      invalid_type                  = 5

      no_authority                  = 6

      unknown_error                = 7

      bad_data_format              = 8

      header_not_allowed            = 9

      separator_not_allowed        = 10

      header_too_long              = 11

      unknown_dp_error              = 12

      access_denied                = 13

      dp_out_of_memory              = 14

      disk_full                    = 15

      dp_timeout                    = 16

      OTHERS                        = 17

            .

  IF sy-subrc <> 0.

* Implement suitable error handling here

  ENDIF.

ENDFORM.                    " GET_DATA

*&---------------------------------------------------------------------*

*&      Form  FEATCH_TABLE_DATA

*&---------------------------------------------------------------------*

*      text

*----------------------------------------------------------------------*

*  -->  p1        text

*  <--  p2        text

*----------------------------------------------------------------------*

FORM featch_table_data .

  TYPES:BEGIN OF ty_matnr,

        matnr TYPE mara-matnr,

        END OF ty_matnr.

  DATA: lt_matnr TYPE TABLE OF ty_matnr,

        ls_matnr TYPE ty_matnr.

  FIELD-SYMBOLS:<fs_j_3apgen> TYPE ty_j_3apgen.

  LOOP AT it_file INTO wa_file.

    ls_matnr-matnr = wa_file-matnr.

    CALL FUNCTION 'CONVERSION_EXIT_MATN1_INPUT'

      EXPORTING

        input        = ls_matnr-matnr

      IMPORTING

        output      = ls_matnr-matnr

      EXCEPTIONS

        length_error = 1

        OTHERS      = 2.

    IF sy-subrc <> 0.

* Implement suitable error handling here

    ENDIF.

    APPEND ls_matnr TO lt_matnr.

  ENDLOOP.

  SORT lt_matnr.

  DELETE ADJACENT DUPLICATES FROM lt_matnr.

  IF lt_matnr[] IS NOT INITIAL.

    SELECT matnr j_3apgnr FROM mara INTO TABLE it_mara

      FOR ALL ENTRIES IN lt_matnr

        WHERE matnr = lt_matnr-matnr.

  ENDIF.

  IF it_mara[] IS NOT INITIAL.

    SELECT *

        FROM j_3apgen INTO TABLE it_j_3apgen

        FOR ALL ENTRIES IN it_mara

        WHERE j_3apgnr = it_mara-j_3apgnr.

  ENDIF.

  LOOP AT it_j_3apgen  ASSIGNING <fs_j_3apgen>.

    READ TABLE it_mara INTO wa_mara WITH KEY j_3apgnr = <fs_j_3apgen>-j_3apgnr.

    IF sy-subrc IS INITIAL.

      CALL FUNCTION 'CONVERSION_EXIT_MATN1_OUTPUT'

        EXPORTING

          input  = wa_mara-matnr

        IMPORTING

          output = wa_mara-matnr.

      <fs_j_3apgen>-matnr = wa_mara-matnr.

    ENDIF.

  ENDLOOP.

ENDFORM.                    " FEATCH_TABLE_DATA

*&---------------------------------------------------------------------*

*&      Form  BDC_UPLOAD

*&---------------------------------------------------------------------*

*      text

*----------------------------------------------------------------------*

*  -->  p1        text

*  <--  p2        text

*----------------------------------------------------------------------*

FORM bdc_upload .

  FIELD-SYMBOLS:<fs_file> TYPE ty_file.

  SORT it_file BY matnr werks j_3akord1 j_3akord2 j_3akord3 j_3akalgr .

  it_file_tmp[] = it_file[].

  it_file1[]    = it_file[].

  it_file2[]    = it_file[].

  DELETE ADJACENT DUPLICATES FROM it_file1 COMPARING matnr.

  DELETE ADJACENT DUPLICATES FROM it_file2 COMPARING matnr werks j_3akalgr.

  LOOP AT it_file2 INTO wa_file2.

    READ TABLE it_file_tmp ASSIGNING <fs_file> WITH KEY matnr = wa_file2-matnr

                                                        werks = wa_file2-werks

                                                        j_3akalgr = wa_file2-j_3akalgr.

    IF sy-subrc IS INITIAL.

      <fs_file>-j_3akalsw = abap_true.

    ENDIF.

  ENDLOOP.

  LOOP AT it_file1 INTO wa_file.

    PERFORM bdc_dynpro      USING 'SAPLMGMM' '0060'.

    PERFORM bdc_field      USING 'BDC_CURSOR'

                                  'RMMG1-MATNR'.

    PERFORM bdc_field      USING 'BDC_OKCODE'

                                  '=ENTR'.

    PERFORM bdc_field      USING 'RMMG1-MATNR'

                                  wa_file-matnr(18)."'1000002827'.

    PERFORM bdc_dynpro      USING 'SAPLMGMM' '0070'.

    PERFORM bdc_field      USING 'BDC_CURSOR'

                                  'MSICHTAUSW-DYTXT(01)'.

    PERFORM bdc_field      USING 'BDC_OKCODE'

                                  '=P+'.

    PERFORM bdc_dynpro      USING 'SAPLMGMM' '0070'.

    PERFORM bdc_field      USING 'BDC_CURSOR'

                                  'MSICHTAUSW-DYTXT(06)'.

    PERFORM bdc_field      USING 'BDC_OKCODE'

                                  '=ENTR'.

    PERFORM bdc_field      USING 'MSICHTAUSW-KZSEL(06)'

                                  'X'.

    PERFORM bdc_dynpro      USING 'SAPLMGMM' '0080'.

    PERFORM bdc_field      USING 'BDC_CURSOR'

                                  'RMMG1-WERKS'.

    PERFORM bdc_field      USING 'BDC_OKCODE'

                                  '=ENTR'.

    PERFORM bdc_field      USING 'RMMG1-WERKS'

                                  wa_file-werks(4)."'1010'.

    PERFORM bdc_dynpro      USING 'SAPLMGMM' '4030'.

    PERFORM bdc_field      USING 'BDC_OKCODE'

                                  '=P+'.

*    PERFORM bdc_field      USING 'MAKT-MAKTX'

*                                  'Lining _ white'.

    PERFORM bdc_field      USING 'BDC_CURSOR'

                                  'J_3AMADKA-J_3AKALGR(05)'.

    PERFORM bdc_field      USING 'J_3ADEFSID'

                                  'CLE1.3 2'.

    CLEAR cnt.

*    LOOP AT it_file_tmp INTO wa_file_tmp  WHERE matnr = wa_file-matnr.

    LOOP AT it_j_3apgen INTO wa_j_3apgen WHERE matnr = wa_file-matnr.

      cnt = cnt + 1.

      IF cnt GT 5.

        PERFORM bdc_dynpro      USING 'SAPLMGMM' '4030'.

        PERFORM bdc_field      USING 'BDC_OKCODE'

                                      '=P+'.

        CLEAR:cnt.

      ENDIF.

      READ TABLE it_file_tmp INTO wa_file_tmp WITH KEY j_3akord1 = wa_j_3apgen-j_3akord1

                                                        j_3akord2 = wa_j_3apgen-j_3akord2

                                                        j_3akord3 = wa_j_3apgen-j_3akord3.

      IF sy-subrc IS INITIAL.

      ENDIF.

      CONCATENATE 'J_3AMADKA-J_3AKALGR(' cnt ')'  INTO lv_j_3akalgr.

      CONCATENATE 'J_3AMADKA-J_3AKALSW(' cnt ')'  INTO lv_j_3akalsw.

      PERFORM bdc_field      USING lv_j_3akalsw            "'J_3AMADKA-J_3AKALSW(01)'

                                      wa_file_tmp-j_3akalsw. "'X'.

      PERFORM bdc_field      USING lv_j_3akalgr            "'J_3AMADKA-J_3AKALGR(01)'

                                    wa_file_tmp-j_3akalgr.  "'SMALL'.

*      ENDIF.

      CLEAR:wa_file_tmp,wa_j_3apgen.

    ENDLOOP.

    PERFORM bdc_dynpro      USING 'SAPLMGMM' '4030'.

    PERFORM bdc_field      USING 'BDC_OKCODE'

                                  '=BU'.

    CALL TRANSACTION  'MM02'

                USING  it_bdcdata

        OPTIONS FROM  wa_params

        MESSAGES INTO  it_messtab.

    CLEAR : cnt1.

  ENDLOOP.

ENDFORM.                    "bdc_upload

*&---------------------------------------------------------------------*

*&      Form  DISPLAY_BDC_ERROR_LOG

*&---------------------------------------------------------------------*

*      text

*----------------------------------------------------------------------*

*  -->  p1        text

*  <--  p2        text

*----------------------------------------------------------------------*

FORM display_bdc_error_log .

  LOOP AT it_messtab INTO wa_messtab.

    var = var + 1.

    CALL FUNCTION 'FORMAT_MESSAGE'

      EXPORTING

        id  = wa_messtab-msgid

        no  = wa_messtab-msgnr

      IMPORTING

        msg = mess.

  ENDLOOP.

ENDFORM.                    " DISPLAY_BDC_ERROR_LOG

*----------------------------------------------------------------------*

*      -->P_0224  text

*      -->P_0225  text

*----------------------------------------------------------------------*

FORM bdc_dynpro  USING    program

                          dynpro.

  CLEAR wa_bdcdata.

  wa_bdcdata-program  = program.

  wa_bdcdata-dynpro  = dynpro.

  wa_bdcdata-dynbegin = 'X'.

  APPEND wa_bdcdata TO it_bdcdata.

ENDFORM.                    " BDC_DYNPRO

*&---------------------------------------------------------------------*

*&      Form  BDC_FIELD

*&---------------------------------------------------------------------*

*      text

*----------------------------------------------------------------------*

*      -->P_0229  text

*      -->P_0230  text

*----------------------------------------------------------------------*

FORM bdc_field  USING    fnam

                          fval.

  CLEAR wa_bdcdata.

  wa_bdcdata-fnam = fnam.

  wa_bdcdata-fval = fval.

  APPEND wa_bdcdata TO it_bdcdata.

ENDFORM.                    " BDC_FIELD

this my flat file data

20000005001010CLE1.32BONE1-5CM
20000005001010CLE2.63BONE1-5CM
20000005001010CLE2.94BONE1-5CM

thanks in advance

regards

sudha

Former Member
Not what you were looking for? View more on this topic or Ask a question