Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

validation problem in select...endselect

aris_hidalgo
Contributor
0 Kudos

Hello experts,

How can I remove the records that has dates that exceeds the value in v_budat? So for example, I check a PO number based on the report output and validate it on ME23 and the delivery date exceeds the date which I typed in the parameter pa_augdt.Please check my code below.Thanks guys and take care.

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

PARAMETERS: pa_bukrs LIKE t001-bukrs OBLIGATORY DEFAULT 'GLOB'.

SELECT-OPTIONS: so_psphi FOR prps-psphi,

so_ebeln FOR ekko-ebeln,

so_lifnr FOR ekko-lifnr,

so_matnr FOR ekpo-matnr.

  • so_augdt FOR bseg-augdt.

PARAMETERS: pa_augdt LIKE bseg-augdt.

SELECTION-SCREEN END OF BLOCK b1.

START-OF-SELECTION.

IF pa_augdt is initial.

  • IF so_augdt[] IS INITIAL.

v_budat = sy-datum.

ELSE.

v_budat = pa_augdt.

ENDIF.

***here is where it gets the data based on the values in ***the selection screen

SELECT apsphi brefbn b~lifnr

FROM prps AS a INNER JOIN cooi AS b

ON aobjnr = bobjnr

INTO CORRESPONDING FIELDS OF it_hdr

WHERE a~psphi IN so_psphi

AND a~pbukr = pa_bukrs

AND a~erdat LE v_budat

  • AND a~erdat in so_augdt

AND b~refbn IN so_ebeln

AND b~lifnr IN so_lifnr

AND b~matnr IN so_matnr

AND b~rfart = 'P'.

SELECT SINGLE name1 FROM lfa1 INTO it_hdr-name1

WHERE lifnr = it_hdr-lifnr.

if not pa_augdt is initial.

  • IF NOT so_augdt[] IS INITIAL.

CLEAR ekko.

SELECT SINGLE * FROM ekko

WHERE ebeln = it_hdr-refbn

  • AND bedat IN so_augdt.

and bedat LE pa_augdt.

IF sy-subrc EQ 0.

APPEND it_hdr.

CLEAR it_hdr.

ENDIF.

ELSE.

APPEND it_hdr.

CLEAR it_hdr.

ENDIF.

ENDSELECT.

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi,

Check this...

SELECT apsphi brefbn b~lifnr

FROM prps AS a INNER JOIN cooi AS b

ON aobjnr = bobjnr

INTO CORRESPONDING FIELDS OF <b>table</b> it_hdr

WHERE a~psphi IN so_psphi

AND a~pbukr = pa_bukrs

AND a~erdat LE v_budat

AND b~refbn IN so_ebeln

AND b~lifnr IN so_lifnr

AND b~matnr IN so_matnr

AND b~rfart = 'P'.

loop at it_hdr.

SELECT SINGLE name1 FROM lfa1 INTO it_hdr-name1

WHERE lifnr = it_hdr-lifnr.

if not pa_augdt is initial.

CLEAR ekko.

SELECT SINGLE * FROM ekko

WHERE ebeln = it_hdr-refbn

and bedat LE pa_augdt.

IF sy-subrc EQ 0.

modify it_hdr transporting name1.

ENDIF.

ELSE.

modify it_hdr transporting name1.

ENDIF.

endloop.

5 REPLIES 5

Former Member
0 Kudos

Hi,

Your code looks good.are you getting data which is more than v_budat??

0 Kudos

Check whether you declaration of v_budat is like this:

DATA v_budat LIKE sy-datum.

and not as character string.

Ps: Reward points if helpful.

Former Member
0 Kudos

First of all instead of using SELECT - ENDSELECT, i suggest to use INTO Table.

Get all data from PRPS and COOI into table IT_HDR.

Loop at IT_HDR.

Get PO No from Ekko using IT_HDR-REFNN.

Do validation for Date with EKKO-BEDAT.

If it fails, delete all entries from IT_HDR where REFBN = IT_HDR-REFBN.

Get LFA1-NAME1 into IT_HDR-NAME1. Modify IT_HDR transporting NAME1.

ENDLOOP.

Check if this helps....

Former Member
0 Kudos

Hi,

Check this...

SELECT apsphi brefbn b~lifnr

FROM prps AS a INNER JOIN cooi AS b

ON aobjnr = bobjnr

INTO CORRESPONDING FIELDS OF <b>table</b> it_hdr

WHERE a~psphi IN so_psphi

AND a~pbukr = pa_bukrs

AND a~erdat LE v_budat

AND b~refbn IN so_ebeln

AND b~lifnr IN so_lifnr

AND b~matnr IN so_matnr

AND b~rfart = 'P'.

loop at it_hdr.

SELECT SINGLE name1 FROM lfa1 INTO it_hdr-name1

WHERE lifnr = it_hdr-lifnr.

if not pa_augdt is initial.

CLEAR ekko.

SELECT SINGLE * FROM ekko

WHERE ebeln = it_hdr-refbn

and bedat LE pa_augdt.

IF sy-subrc EQ 0.

modify it_hdr transporting name1.

ENDIF.

ELSE.

modify it_hdr transporting name1.

ENDIF.

endloop.

former_member186741
Active Contributor
0 Kudos

deliveries are in table EKET - del date is EINDT. You need to refer to this table so maybe use eket instead of EKKO unless you need some header info too. This table is beeath the EKKO so has ebeln ebelp and etenr as the key.