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: 

How to properly filter and transfer local table to local structure?

walkerist
Participant
0 Kudos

Local tables:

  • LT_VBFA and LT_VBFA_TMP which has the same exact content.
  • LT_VBFA_AUX

LT_VBFA and LT_VBFA_TMP content:
I was trying to get the ROW 8 but instead, I was getting the ROW 6. I need to get the MJAHR and VBELN/VBELV of ROW 8.

Local structure:

  • LX_VBFA

Here's my code:

        lt_vbfa_aux[] = VALUE #( FOR lx_vbfa IN lt_vbfa[]
WHERE ( vbtyp_n = lcl_main=>C
OR vbtyp_n = lcl_main=>J )
( VALUE #( BASE CORRESPONDING #( lx_vbfa )
vbelv = lx_vbfa-vbeln
matnr = VALUE #( lt_vbfa[
vbelv = lx_vbfa-vbelv
vbtyp_n = lcl_main=>R ]-matnr OPTIONAL )
mjahr = VALUE #( lt_vbfa[
vbelv = lx_vbfa-vbelv
vbtyp_n = lcl_main=>R ]-mjahr OPTIONAL ) ) ) ).
2 REPLIES 2

Sandra_Rossi
Active Contributor
0 Kudos

It's impossible that if you read the line with VBTYP_N = 'R', you get a line with VBTYP_N = 'J'.

Or you simply have lcl_main=>R = 'J'... Typo!

Either you don't run the right version, or not the right code. The last possibility is a bug in the kernel but I think it's not (past bugs where never "so trivial", they were always "subtle").

If you want us to look at it more in depth, please provide a short reproducible example with test data.

NB: I advise to create an auxiliary variable to not access LT_VBFA twice:

LET <aux_vbfa> = lt_vbfa[ vbelv = lx_vbfa-vbelv vbtyp_n = lcl_main=>R ] IN
( VALUE #( BASE ...
  vbelv = ...
  matnr = COND #( WHEN <aux_vbfa> IS ASSIGNED THEN <aux_vbfa>-matnr )
  mjahr = COND #( WHEN <aux_vbfa> IS ASSIGNED THEN <aux_vbfa>-mjahr ) ...

0 Kudos

If a line with vbtyp_n = 'R' is not found, a shortdump will be produced. The check IS ASSIGNED is always true, if executed.

LET aux_vbfa = VALUE #( lt_vbfa[ vbelv = lx_vbfa-vbelv vbtyp_n = lcl_main=>R ] OPTIONAL ) IN
( VALUE #( BASE ...
  vbelv = ...
  matnr = aux_vbfa-matnr )
  mjahr = aux_vbfa-mjahr ) ...