Skip to Content

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

select- end select

Hello Experts,

cc---company code.

  • if cc is populated in selection screen

SELECT abukrs awerks aaufnr agamng agstrs agltrs arueck aautyp

aauart aobjnr a~gmein

INTO (int_caufv-bukrs, int_caufv-werks,

int_caufv-aufnr, int_caufv-gamng,

int_caufv-gstrs, int_caufv-gltrs,

int_caufv-rueck, int_caufv-autyp,

int_caufv-auart, int_caufv-objnr,

int_caufv-gmein)

FROM caufv AS a INNER JOIN afvv AS b

ON aaufpl = baufpl

WHERE a~auart IN pordtype AND "Prod Order Type

a~bukrs = cc AND "Company

  • a~aufnr IN pordno AND "Prod order

b~sssbd BETWEEN tgtfm and tgtto and "Date filter

A~WERKS in PLANT.

endselect.

if user does not enter company code(cc) in selection screen then i need ot fetch company code based on plant data from t001k table.

i have multiple company code values in internal tabel for a given range of plant data .

DATA: wa_bukrs type RANGE OF t001k-bukrs,

wa_bukrs_line like LINE OF wa_bukrs.

select bukrs from t001k into table it_cust where bwkey in plant.

if sy-subrc = 0.

sort it_cust by bukrs.

endif.

loop at it_cust INTO wa_cust.

wa_bukrs_line-sign = 'I'.

wa_bukrs_line-option = 'BT'.

at FIRST.

wa_bukrs_line-low = wa_cust-bukrs.

ENDAT.

at LAST.

wa_bukrs_line-high = wa_cust-bukrs.

APPEND wa_bukrs_line TO wa_bukrs.

ENDAT.

ENDLOOP.

SELECT abukrs awerks aaufnr agamng agstrs agltrs arueck aautyp

aauart aobjnr a~gmein

INTO (int_caufv-bukrs, int_caufv-werks,

int_caufv-aufnr, int_caufv-gamng,

int_caufv-gstrs, int_caufv-gltrs,

int_caufv-rueck, int_caufv-autyp,

int_caufv-auart, int_caufv-objnr,

int_caufv-gmein)

FROM caufv AS a INNER JOIN afvv AS b

ON aaufpl = baufpl

WHERE a~auart IN pordtype AND "Prod Order Type

a~bukrs in wa_bukrs AND "Company

  • a~aufnr IN pordno AND "Prod order

b~sssbd BETWEEN tgtfm and tgtto and "Date filter

A~WERKS in PLANT. "Plant

ENDSELECT.

but in this case sy-subrc is becoming 4 , any suggestion please......

Former Member
Former Member replied

check your range table wa_bukrs. I suppose it to be full of starts and nothing else.

check your values of wa_cust-bukrs in your AT statements during the loop.

To avoid this, either have a second structure taking those values during the loop, or work with a field symbol and LOOP at XXX assigning <YYY>.

BTW when you are at it, rename it please for better maintainability. Every programmer would expect a workarea (structure) when variable starts with WA_.

0 View this answer in context
Not what you were looking for? View more on this topic or Ask a question