Skip to Content
author's profile photo Former Member
Former Member

validation in alv report

Hi friends i am new to abap.i am doing some validation in my report .my program is executing properly but i need some modification.... its alv report on bapi for GOODS MOVEMENT TYPE For tht i am uploading a flat file using gui_upload.but i need some modification on validation..this program is abt goods transfer from one plant to another plant,s location .so in my flat file i am having material,from plant ,from location,to plant,to location and quantity .here is the code:

&----


*& Form VALIDATE_DATA

&----


  • 1.Check Material in Table MARC >> Material Plant Validation

  • If not found, Fill Remarks with 'Material Not Found in Plant'

  • 2.Check Plant is Assigned to POrg in Table T024W >> Plant POrg Validation

  • If not found, Fill Remarks with 'Invalid POrg for Plant'

  • 3.Check Location for Plant and Location in Table T001L >> Plant SLoc Validation

  • If not found, Fill Remarks with 'Invalid Storage Location for Plant'

----


FORM validate_data .

DATA: lv_ekorg TYPE t024e-ekorg.

  • Get POrg for CompanyCode

SELECT SINGLE ekorg INTO lv_ekorg FROM t024e

WHERE bukrs EQ p_bukrs.

LOOP AT it_final.

  • Check-1

SELECT SINGLE * FROM marc

WHERE matnr = it_final-matnr

AND werks = it_final-f_werks.

IF sy-subrc = 4.

it_final-remark = 'Material Not Found in Plant'.

MODIFY it_final.

ELSE.

  • Check-2

SELECT SINGLE * FROM t024w

WHERE werks = it_final-t_werks

AND ekorg = lv_ekorg.

IF sy-subrc = 4.

it_final-remark = 'Invalid POrg for Plant'.

MODIFY it_final.

ELSE.

  • Check-3

SELECT SINGLE * FROM t001l

WHERE werks = it_final-t_werks

AND lgort = it_final-t_lgort.

IF sy-subrc = 4.

it_final-remark = 'Invalid Storage Location for Plant'.

MODIFY it_final.

ENDIF.

ENDIF.

ENDIF.

ENDLOOP.

ENDFORM. " VALIDATE_DATA

for this code i am getting output as if plant value is wrong then there will be a remark in the output as material is 'Material Not Found in Plant'....and as same for location n purchase organization....

But in my output i want ,if there is plant n location is wrong the then 2 remarks should display in 2 rows but like wise now i am getting only one remark for 2 errors also..........getting remark based on first condition....

can any one help me hw to solve ...

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

1 Answer

  • author's profile photo Former Member
    Former Member
    Posted on Mar 29, 2008 at 03:46 PM

    Hi,

    try this

    FORM validate_data .
    
    DATA: lv_ekorg TYPE t024e-ekorg.
    
    data idx type sy-tabix.
    
        * Get POrg for CompanyCode
    
    SELECT SINGLE ekorg INTO lv_ekorg FROM t024e
    WHERE bukrs EQ p_bukrs.
    
    LOOP AT it_final.
    
     if it_final-matnr na sy-abcde.
    unpack it_final-matnr to it_final-matnr.
    endif.
    
    SELECT SINGLE * FROM marc
    WHERE matnr = it_final-matnr
    AND werks = it_final-f_werks.
    IF sy-subrc ne 0.
    it_final-remark = 'Material Not Found in Plant'.
    MODIFY it_final index idx.
    
    ELSE.
    
        * Check-2
    
    SELECT SINGLE * FROM t024w
    WHERE werks = it_final-t_werks
    AND ekorg = lv_ekorg.
    IF sy-subrc ne 0.
    it_final-remark = 'Invalid POrg for Plant'.
    MODIFY it_final index idx.
    ELSE.
    
        * Check-3
    
    SELECT SINGLE * FROM t001l
    WHERE werks = it_final-t_werks
    AND lgort = it_final-t_lgort.
    
    IF sy-subrc = 4.
    it_final-remark = 'Invalid Storage Location for Plant'.
    MODIFY it_final index idx..
    ENDIF.
    ENDIF.
    ENDIF.
    ENDLOOP.
    
    ENDFORM. " VALIDATE_DATA

    Reward if usefull

    can i have ur full code

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member

      &----


      *& Report YSG_IM_F2_002 *

      *& *

      &----


      *& This object is for goods transfer from one plant to another *

      *& plant using FM-BAPI_GOODSMVT_CREATE *

      &----


      REPORT YSG_IM_F2_002 .

      TABLES: marc, t024w, t001l.

      TYPE-POOLS:slis.

      TYPES: BEGIN OF i_list,

      matnr LIKE mard-matnr,

      f_werks LIKE mard-werks,

      f_lgort LIKE mard-lgort,

      t_werks LIKE mard-werks,

      t_lgort LIKE mard-lgort,

      labst LIKE mard-labst,

      remark TYPE c,

      END OF i_list.

      TYPES: BEGIN OF i_mara,

      matnr LIKE mara-matnr,

      END OF i_mara.

      TYPES:BEGIN OF i_marc,

      matnr LIKE marc-matnr,

      werks LIKE marc-werks,

      END OF i_marc.

      TYPES: BEGIN OF i_mard,

      matnr LIKE mard-matnr,

      f_werks LIKE mard-werks,

      f_lgort LIKE mard-lgort,

      t_werks LIKE mard-werks,

      t_lgort LIKE mard-lgort ,

      labst LIKE mard-labst,

      END OF i_mard.

      TYPES: BEGIN OF i_t001l,

      bukrs TYPE t001l-werks,

      lgort TYPE t001l-lgort,

      END OF i_t001l.

      TYPES: BEGIN OF i_t024e,

      ekorg TYPE t024e-ekorg,

      bukrs TYPE t024e-bukrs,

      END OF i_t024e.

      TYPES: BEGIN OF i_mkpf,

      xblnr type mkpf-xblnr,

      END OF i_mkpf.

      TYPES: BEGIN OF i_final,

      matnr LIKE mard-matnr,

      f_werks LIKE mard-werks,

      f_lgort LIKE mard-lgort,

      t_werks LIKE mard-werks,

      t_lgort LIKE mard-lgort,

      labst type c ,

      remark(50) type c,

      END OF i_final.

      DATA : filename TYPE string,

      title type c.

      DATA: it_list TYPE STANDARD TABLE OF i_list WITH HEADER LINE,

      it_mara TYPE STANDARD TABLE OF i_mara WITH HEADER LINE,

      it_marc TYPE STANDARD TABLE OF i_marc WITH HEADER LINE,

      it_mard TYPE STANDARD TABLE OF i_mard WITH HEADER LINE,

      it_t001l TYPE STANDARD TABLE OF i_t001l WITH HEADER LINE,

      it_t024e TYPE STANDARD TABLE OF i_t024e WITH HEADER LINE,

      it_mkpf TYPE STANDARD TABLE OF i_mkpf WITH HEADER LINE,

      it_final TYPE STANDARD TABLE OF i_final WITH HEADER LINE.

      DATA: fs_fldcat TYPE slis_fieldcat_alv , "Structure for Field catalog

      it_fldcat LIKE TABLE OF fs_fldcat,

      layout TYPE slis_layout_alv,

      V_REPID LIKE sy-repid.

      DATA: GT_LIST_TOP_OF_PAGE TYPE SLIS_T_LISTHEADER,

      EVENTS TYPE SLIS_T_EVENT,

      GW_EVENT TYPE SLIS_ALV_EVENT,

      GI_LISTHEADER TYPE SLIS_T_LISTHEADER.

      DATA: lv_matnr TYPE mara-matnr,

      lv_ekorg TYPE t024e-ekorg.

      DATA: BEGIN OF gmhead.

      INCLUDE STRUCTURE bapi2017_gm_head_01.

      DATA: END OF gmhead.

      DATA: BEGIN OF gmcode.

      INCLUDE STRUCTURE bapi2017_gm_code.

      DATA: END OF gmcode.

      DATA: BEGIN OF mthead.

      INCLUDE STRUCTURE bapi2017_gm_head_ret.

      DATA: END OF mthead.

      DATA: BEGIN OF itab OCCURS 100.

      INCLUDE STRUCTURE bapi2017_gm_item_create.

      DATA: END OF itab.

      DATA: BEGIN OF errmsg OCCURS 10.

      INCLUDE STRUCTURE bapiret2.

      DATA: END OF errmsg.

      *data: wmenge like iseg-menge,

      • errflag.

      • **********************************************************************************

      *Selection Screen Declaration

      ****************************************************************************

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

      PARAMETERS: p_bukrs LIKE t024e-bukrs OBLIGATORY,

      ekorg LIKE t024e-ekorg,

      f_file LIKE ibipparms-path OBLIGATORY,

      xblnr like mkpf-xblnr,

      Doc_Post type checkbox.

      SELECTION-SCREEN END OF BLOCK blk .

      AT SELECTION-SCREEN ON VALUE-REQUEST FOR f_file .

      CLEAR f_file.

      CALL FUNCTION 'F4_FILENAME'

      • EXPORTING

      • PROGRAM_NAME = .

      • DYNPRO_NUMBER = SYST-DYNNR

      IMPORTING

      file_name = f_file.

      START-OF-SELECTION.

      filename = f_file.

      CALL FUNCTION 'GUI_UPLOAD'

      EXPORTING

      filename = filename

      filetype = 'ASC'

      has_field_separator = 'x'

      TABLES

      data_tab = it_final

      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.

      • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

      • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

      ENDIF.

      PERFORM validate_data.

      PERFORM bapi_goods_mvt.

      PERFORM alv_grid_display.

      • endif.

      • PERFORM BAPI_GOODS_MVT.

      &----


      *& Form VALIDATE_DATA

      &----


      • 1.Check Material in Table MARC >> Material Plant Validation

      • If not found, Fill Remarks with 'Material Not Found in Plant'

      • 2.Check Plant is Assigned to POrg in Table T024W >> Plant POrg Validation

      • If not found, Fill Remarks with 'Invalid POrg for Plant'

      • 3.Check Location for Plant and Location in Table T001L >> Plant SLoc Validation

      • If not found, Fill Remarks with 'Invalid Storage Location for Plant'

      ----


      FORM validate_data .

      • Get POrg for CompanyCode

      SELECT SINGLE ekorg INTO lv_ekorg FROM t024e

      WHERE bukrs EQ p_bukrs.

      LOOP AT it_final.

      • Check-1

      CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'

      EXPORTING

      input = it_final-matnr

      IMPORTING

      output = lv_matnr.

      SELECT SINGLE * FROM marc

      WHERE matnr = lv_matnr

      AND werks = it_final-f_werks.

      IF sy-subrc <> 0.

      it_final-remark = 'Material Not Found in Plant'.

      append it_final .

      endif .

      SELECT SINGLE * FROM marc

      WHERE matnr = lv_matnr

      AND werks = it_final-t_werks.

      IF sy-subrc <> 0.

      it_final-remark = 'Material Not Found in Plant'.

      append it_final .

      endif.

      • Check-2

      SELECT SINGLE * FROM t024w

      WHERE werks = it_final-t_werks

      AND ekorg = lv_ekorg.

      IF sy-subrc <> 0.

      it_final-remark = 'Invalid POrg for Plant'.

      append it_final .

      Endif.

      SELECT SINGLE * FROM t024w

      WHERE werks = it_final-f_werks

      AND ekorg = lv_ekorg.

      IF sy-subrc <> 0.

      it_final-remark = 'Invalid POrg for Plant'.

      append it_final .

      Endif.

      • Check-3

      SELECT SINGLE * FROM t001l

      WHERE werks = it_final-t_werks

      AND lgort = it_final-t_lgort.

      IF sy-subrc <> 0.

      it_final-remark = 'Invalid Storage Location for Plant'.

      append it_final .

      ENDIF.

      SELECT SINGLE * FROM t001l

      WHERE werks = it_final-f_werks

      AND lgort = it_final-f_lgort.

      IF sy-subrc <> 0.

      it_final-remark = 'Invalid Storage Location for Plant'.

      append it_final .

      ENDIF.

      • ENDIF.

      • ENDIF.

      ENDLOOP.

      ENDFORM. " VALIDATE_DATA

      &----


      *& Form ALV_GRID_DISPLAY

      &----


      • text

      ----


      FORM alv_grid_display.

      DATA:l_edit TYPE lvc_s_glay.

      PERFORM build_fieldcat.

      PERFORM layout_build USING layout.

      PERFORM fill_list_header USING gi_listheader.

      v_repid = sy-repid.

      gw_event-name = slis_ev_top_of_page.

      gw_event-form = 'TOP_OF_PAGE'.

      APPEND gw_event TO events.

      l_edit-edt_cll_cb = 'X'.

      CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

      EXPORTING

      i_callback_program = V_REPID

      • i_callback_pf_status_set = 'SET_PF_STATUS'

      • I_CALLBACK_USER_COMMAND = ' '

      • I_CALLBACK_TOP_OF_PAGE = ' '

      • i_grid_title = title

      • I_GRID_SETTINGS =

      is_layout = layout

      it_fieldcat = it_fldcat

      i_save = 'x'

      • IS_VARIANT =

      IT_EVENTS = events

      TABLES

      t_outtab = it_final

      EXCEPTIONS

      program_error = 1

      OTHERS = 2

      .

      IF sy-subrc <> 0.

      • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

      • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

      ENDIF.

      ENDFORM. "ALV_GRID_DISPLAY

      &----


      *& Form build_fieldcat

      &----


      • text

      ----


      FORM build_fieldcat.

      PERFORM fieldcat USING: 'IT_FINAL' "Internal table name

      'MATNR' "CREDIT CONTROL AREA

      '10' "length

      'MATERIAL' "Description

      'L' "Dictionary long text

      ' ' "Database table name

      ' ' "Database tab' field name

      ' ' "Justification R/M/L

      ' ' "To do total

      ' ' "emphasize

      ' ' "emphasize

      ' ' "emphasize

      ' ' "Data type

      ' ' "edit.

      ' '. "round

      PERFORM fieldcat USING: 'IT_FINAL' "Internal table name

      'F_WERKS' "CREDIT CONTROL AREA

      '10' "length

      'FROM PLANT' "Description

      'L' "Dictionary long text

      ' ' "Database table name

      ' ' "Database tab' field name

      ' ' "Justification R/M/L

      ' ' "To do total

      ' ' "emphasize

      ' ' "emphasize

      ' ' "emphasize

      ' ' "Data type

      ' ' "edit.

      ' '. "round

      PERFORM fieldcat USING: 'IT_FINAL' "Internal table name

      'F_LGORT' "CREDIT CONTROL AREA

      '10' "length

      'LOCATION' "Description

      'L' "Dictionary long text

      ' ' "Database table name

      ' ' "Database tab' field name

      ' ' "Justification R/M/L

      ' ' "To do total

      ' ' "emphasize

      ' ' "emphasize

      ' ' "emphasize

      ' ' "Data type

      ' ' "edit.

      ' '. "round

      PERFORM fieldcat USING: 'IT_FINAL' "Internal table name

      'T_WERKS' "CREDIT CONTROL AREA

      '10' "length

      'TO PLANT' "Description

      'L' "Dictionary long text

      ' ' "Database table name

      ' ' "Database tab' field name

      ' ' "Justification R/M/L

      ' ' "To do total

      ' ' "emphasize

      ' ' "emphasize

      ' ' "emphasize

      ' ' "Data type

      ' ' "edit.

      ' '. "round

      PERFORM fieldcat USING: 'IT_FINAL' "Internal table name

      'T_LGORT' "CREDIT CONTROL AREA

      '10' "length

      'LOCATION' "Description

      'L' "Dictionary long text

      ' ' "Database table name

      ' ' "Database tab' field name

      ' ' "Justification R/M/L

      ' ' "To do total

      ' ' "emphasize

      ' ' "emphasize

      ' ' "emphasize

      ' ' "Data type

      ' ' "edit.

      ' '. "round

      PERFORM fieldcat USING: 'I_FINAL' "Internal table name

      'LABST' "CREDIT CONTROL AREA

      '10' "length

      'QUANTITY' "Description

      'L' "Dictionary long text

      ' ' "Database table name

      ' ' "Database tab' field name

      ' ' "Justification R/M/L

      ' ' "To do total

      ' ' "emphasize

      ' ' "emphasize

      ' ' "emphasize

      ' ' "Data type

      ' ' "edit.

      ' '. "round

      PERFORM fieldcat USING: 'I_FINAL' "Internal table name

      'REMARK' "CREDIT CONTROL AREA

      '50' "length

      'REMARK' "Description

      'L' "Dictionary long text

      ' ' "Database table name

      ' ' "Database tab' field name

      ' ' "Justification R/M/L

      ' ' "To do total

      ' ' "emphasize

      ' ' "emphasize

      ' ' "emphasize

      ' ' "Data type

      ' ' "edit.

      ' '. "round

      ENDFORM. "build_fieldcat

      &----


      *& Form fieldcat

      &----


      • text

      ----


      FORM fieldcat CHANGING value(p_tname)

      value(p_fname)

      value(p_length)

      value(p_ltext)

      value(p_typet)

      value(p_rtab)

      value(p_rfield)

      value(p_just)

      value(p_dosum)

      value(p_emphasize)

      value(p_datatype)

      value(p_no_zero)

      value(p_hotspot)

      value(p_edit)

      value(p_round).

      fs_fldcat-tabname = p_tname.

      fs_fldcat-fieldname = p_fname.

      fs_fldcat-outputlen = p_length.

      fs_fldcat-seltext_l = p_ltext.

      fs_fldcat-input = p_typet.

      fs_fldcat-edit = p_rtab.

      fs_fldcat-ref_fieldname = p_rfield.

      fs_fldcat-just = p_just.

      fs_fldcat-do_sum = p_dosum.

      fs_fldcat-emphasize = p_emphasize.

      fs_fldcat-datatype = p_datatype.

      fs_fldcat-lzero = p_no_zero.

      fs_fldcat-hotspot = p_hotspot.

      fs_fldcat-edit = p_edit.

      fs_fldcat-decimals_out = p_round.

      APPEND fs_fldcat TO it_fldcat.

      ENDFORM. "fieldcat

      &----


      *& Form fill_list_header

      &----


      • text

      ----


      • -->FV_I_LISTHEADER text

      ----


      FORM fill_list_header USING fv_i_listheader TYPE slis_t_listheader.

      DATA: lw_line TYPE slis_listheader,

      l_date(10),

      l_time(10).

      DATA : p_date LIKE sy-datum.

      DATA : p_time LIKE sy-uzeit.

      DATA : ztext(17).

      DATA : ztext1(80).

      p_date = sy-datum.

      p_time = sy-uzeit.

      CLEAR fv_i_listheader.

      CONCATENATE p_date6(2) '.' p_date4(2) '.' p_date+0(4) INTO l_date.

      CONCATENATE p_time0(2) ':' p_time2(2) ':' p_time+4(2) INTO l_time.

      IF doc_post = 'X'.

      ztext = 'Execute Mode'.

      ELSE.

      ztext = 'Update Mode'.

      ENDIF.

      CLEAR lw_line.

      lw_line-typ = 'H'.

      lw_line-info = sy-repid.

      APPEND lw_line TO fv_i_listheader.

      CLEAR lw_line.

      lw_line-typ = 'H'.

      lw_line-info = l_date.

      APPEND lw_line TO fv_i_listheader.

      CLEAR lw_line.

      lw_line-typ = 'H'.

      lw_line-info = l_time.

      APPEND lw_line TO fv_i_listheader.

      CLEAR lw_line.

      lw_line-typ = 'H'.

      lw_line-info = sy-uname.

      APPEND lw_line TO fv_i_listheader.

      CLEAR lw_line.

      lw_line-typ = 'H'.

      lw_line-info = ztext.

      APPEND lw_line TO fv_i_listheader.

      endform. "fill_list_header

      &----


      *& Form top_of_page

      &----


      • text

      ----


      FORM top_of_page.

      CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'

      EXPORTING

      it_list_commentary = gi_listheader.

      ENDFORM. "top_of_page

      &----


      *& Form layout_build

      &----


      • text

      ----


      • -->LAYOUT text

      ----


      FORM layout_build USING layout TYPE slis_layout_alv.

      • layout-box_fieldname = 'BOX'.

      layout-zebra = 'X'. " STRIPED PATTERN

      layout-numc_sum = 'X'. " TOTALS FOR NUMC-FIELDS

      layout-no_keyfix = ' '. " DO NOT FIX KEYCOLUMNS

      layout-colwidth_optimize = ' ' .

      layout-flexible_key = ' '. " KEY COLUMNS MOVABLE,...

      layout-detail_popup = ' '. " SHOW DETAIL IN POPUP

      ENDFORM. "layout_build

      &----


      *& Form BAPI_GOODS_MVT

      &----


      • text

      ----


      FORM bapi_goods_mvt.

      DATA: dc_numner TYPE bapi2017_gm_head_ret-mat_doc,

      dc_year TYPE bapi2017_gm_head_ret-doc_year.

      clear: dc_numner, dc_year.

      if doc_post = 'X'.

      gmhead-pstng_date = sy-datum.

      gmhead-doc_date = sy-datum.

      gmhead-pr_uname = sy-uname.

      gmhead-REF_DOC_NO = it_mkpf-xblnr.

      gmcode-gm_code = '04'. "04 - MB1B - Transfer Posting

      LOOP AT it_final.

      itab-move_type = '301'.

      CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'

      EXPORTING

      input = it_final-matnr

      IMPORTING

      output = itab-material.

      itab-plant = it_final-f_werks .

      itab-stge_loc = it_final-f_lgort .

      itab-MOVE_PLANT = it_final-t_werks .

      itab-move_stloc = it_final-t_lgort .

      itab-entry_qnt = it_final-labst .

      APPEND itab.

      ENDLOOP.

      CALL FUNCTION 'BAPI_GOODSMVT_CREATE'

      EXPORTING

      goodsmvt_header = gmhead

      goodsmvt_code = gmcode

      • TESTRUN = ' '

      IMPORTING

      goodsmvt_headret = mthead

      materialdocument = dc_numner

      matdocumentyear = dc_year

      TABLES

      goodsmvt_item = itab

      • GOODSMVT_SERIALNUMBER =

      return = errmsg.

      IF errmsg[] IS INITIAL.

      CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'

      EXPORTING

      wait = 'X'.

      LOOP AT it_final.

      it_final-remark = dc_numner.

      MODIFY it_final.

      ENDLOOP.

      endif.

      ELSE.

      • clear errflag.

      LOOP AT errmsg.

      IF errmsg-type EQ 'E'.

      WRITE:/'Error in function', errmsg-message.

      • errflag = 'X'.

      ELSE.

      WRITE:/ errmsg-message.

      ENDIF.

      ENDLOOP.

      endif.

      ENDFORM. "BAPI_GOODS_MVT

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.