‎2020 Mar 05 5:57 AM
Hi Experts,
Could you pls share ABAP 7.4 new syntax for loop and read?
I've used for in iterations for loop. But how to include read in the loop ?
Thanks in Advance
‎2020 Mar 05 9:31 AM
The error you mention is because your code is completely meaningless. Let me explain what you should indicate.
gt_fin = VALUE tt_fin(
FOR lw_j IN lt_join
( line to be added, must be like line type of tt_fin ) ).Possibly, you want something like that:
TYPES : BEGIN OF ty_fin,
sernr TYPE string,
matnr TYPE string,
END OF ty_fin,
tt_fin TYPE STANDARD TABLE OF ty_fin WITH EMPTY KEY.
DATA(lt_join) = VALUE tt_fin( ( ) ).
DATA(lt_ser) = VALUE tt_fin( ).
DATA(gt_fin) = VALUE tt_fin(
FOR lw_j IN lt_join
( matnr = VALUE #( lt_ser[ sernr = lw_j-sernr ]-matnr OPTIONAL )
sernr = lw_j-sernr
) ).
You must define a standalone type for lines of lt_ser (I presume it's named ty_ser). If lt_ser is declared inline, you can do like that after lt_ser inline declaration:
TYPES ty_ser LIKE LINE OF lt_ser.
‎2020 Mar 05 6:06 AM
Maybe if you post your code it will be easier to understand your objective
‎2020 Mar 05 6:09 AM
Thanks for your quick response. Heres the sample old way of coding.
LOOP AT lt_join INTO DATA(wa_join).
READ TABLE lt_ser INTO DATA(wa_ser) WITH KEY sernr = wa_join-serial.
IF sy-subrc NE 0.
append xxx to yyy.
endif.
endloop.
‎2020 Mar 05 6:22 AM
Tried like this. But its not working.
gt_fin = VALUE tt_fin(
FOR lw_j IN lt_join
LET <ser> = lt_ser[ sernr = lw_j-serial ]
IN (
equnr = lw_j-equnr
) ).
Pls suggest
‎2020 Mar 05 6:46 AM
‎2020 Mar 05 6:50 AM
First of all: the ABAP keyword documentation is available online at https://help.sap.com/doc/abapdocu_740_index_htm/7.40/en-US/index.html. Especially the release specific content is of interest.
To answer your question:
gt_fin = VALUE tt_fin(
FOR lw_j IN lt_join
( lt_ser[ sernr = lw_j-serial ] )
).
This should work. Please note the brackets which state the line creation.
‎2020 Mar 05 6:58 AM
You scratch the internal table result, you need a BASE or to append the result
‎2020 Mar 05 7:07 AM
I need to fill the loop table's values or from both sometimes. Do base keyword needed?
‎2020 Mar 05 7:10 AM
I tried this. But getting ty_fin cannot be converted to lt_ser error.
gt_fin = VALUE tt_fin(
FOR lw_j IN lt_join
( lt_ser[ sernr = lw_j-serial ] )
equnr = lw_j-equnr
matnr = <ser>-matnr
sernr = lw_j-serial
sap = | ESTO - In { p_werks } warehouse |
snacc = | Not available in SNACC Table - ZZSNT_SERTAB |
&& |for given plant { p_werks } |
).
‎2020 Mar 05 7:26 AM
Please explain what error you get, if it's a syntax error or a run time error, etc. Do you mean there's a line in lt_ser which doesn't exist and that fails? (if yes, use matnr = VALUE ty_ser( lt_ser[ ... ] OPTIONAL )-matnr ).
People try random answers because you don't explain well.
‎2020 Mar 05 8:32 AM
Thanks Sandra..It is giving syntax error - ty_fin cannot be converted to lt_ser .
Ty_fin is the type of gt_fin , lt_Ser is an inline table. SHould i need to declare it before? TIA
‎2020 Mar 05 8:39 AM
Also, this is my requirement.
Loop main table.
read sub table with key = main-key.
if sy-subrc NE 0. - I'm doing negative check as i cant have negative case in READ .
Is it possible in new way? If there are no matching keys in sub table i need to fill it in my final itab.
‎2020 Mar 05 9:16 AM
You can try like below to check using the new constructor expressions (FLTER & CORRESPONDING)
TYPES:
BEGIN OF line1,
field1 TYPE i,
field2 TYPE c LENGTH 1,
END OF line1,
tt_line1 TYPE SORTED TABLE OF line1 WITH NON-UNIQUE KEY field1,
BEGIN OF line2,
field1 TYPE i,
field3 TYPE i,
END OF line2,
tt_line2 TYPE SORTED TABLE OF line2 WITH NON-UNIQUE KEY field1,
BEGIN OF line3,
field1 TYPE i,
field2 TYPE c LENGTH 1,
field3 TYPE i,
END OF line3,
tt_line3 TYPE STANDARD TABLE OF line3 with DEFAULT KEY.
DATA(itab1) = VALUE tt_line1(
( field1 = 1 field2 = ' ' )
( field1 = 3 field2 = 'X' )
( field1 = 12 field2 = '4' )
( field1 = 11 field2 = 'X' ) ).
DATA(itab2) = VALUE tt_line2(
( field1 = 1 field3 = 1 )
( field1 = 1 field3 = 3 )
( field1 = 3 field3 = 4 ) ).
DATA(itab3) = CORRESPONDING tt_line3( FILTER tt_line1( itab1 EXCEPT IN itab2
WHERE field1 = field1 ) ).
The internal tables that you are using should be of type sorted tables in FILTER.
-Mahesh
‎2020 Mar 05 9:31 AM
The error you mention is because your code is completely meaningless. Let me explain what you should indicate.
gt_fin = VALUE tt_fin(
FOR lw_j IN lt_join
( line to be added, must be like line type of tt_fin ) ).Possibly, you want something like that:
TYPES : BEGIN OF ty_fin,
sernr TYPE string,
matnr TYPE string,
END OF ty_fin,
tt_fin TYPE STANDARD TABLE OF ty_fin WITH EMPTY KEY.
DATA(lt_join) = VALUE tt_fin( ( ) ).
DATA(lt_ser) = VALUE tt_fin( ).
DATA(gt_fin) = VALUE tt_fin(
FOR lw_j IN lt_join
( matnr = VALUE #( lt_ser[ sernr = lw_j-sernr ]-matnr OPTIONAL )
sernr = lw_j-sernr
) ).
You must define a standalone type for lines of lt_ser (I presume it's named ty_ser). If lt_ser is declared inline, you can do like that after lt_ser inline declaration:
TYPES ty_ser LIKE LINE OF lt_ser.
‎2020 Mar 05 10:33 AM
Thanks Sandra.. But could you pls clarify me on this..
gt_fin =VALUE tt_fin(FOR lw_j IN lt_join
( equnr = lw_j-equnr
matnr =VALUE ty_ser( lt_ser[...]OPTIONAL)-matnr
sernr = lw_j-serial
sap=| ESTO -In{ p_werks } warehouse |
snacc =|Not available in SNACC Table- ZZSNT_SERTAB |&&|for given plant { p_werks }|)).
Is this matnr =VALUE ty_ser( lt_ser[...]OPTIONAL)-matnr like read table lt_Ser with matnr? Im not sure lt_ser[...] what should be filled here :(
‎2020 Mar 05 10:38 AM
Sorry, corrected (same as what you proposed). I guess that lt_ser contains components sernr and matnr.
‎2020 Mar 05 10:56 AM
thanks for your response.
But i got ITAB_LINE_NOT_FOUND run time error for the below code.
TYPES ty_ser LIKE LINE OF lt_ser.
gt_fin = VALUE tt_fin(
FOR lw_j IN lt_join
( equnr = lw_j-equnr
matnr = lw_j-matnr
sernr = VALUE ty_ser( lt_ser[ sernr = lw_j-serial ] ) - lw_j-serial
sap = | ESTO - in { p_werks } warehouse |
snacc = | Not available in SNACC table - ZZSNT_SERTAB |
&& |for given plant { p_werks } | )
).
‎2020 Mar 05 11:04 AM
I have added all the "fixture" so that I can test myself. See my answer corrected.
‎2020 Mar 05 12:09 PM
You should try by yourself. You'll learn quicker.
Now, about:
VALUE#( lt_ser[ sernr = lw_j-sernr ]-matnr OPTIONAL )it's the same as:
lt_ser[ sernr = lw_j-sernr ]-matnrexcept that CX_SY_ITAB_LINE_NOT_FOUND doesn't occur, it's replaced with initial value.
As Michael said, look at the documentation:
https://help.sap.com/doc/abapdocu_740_index_htm/7.40/en-US/index.html.
Especially, table expressions: https://help.sap.com/doc/abapdocu_753_index_htm/7.53/en-US/index.htm?file=abentable_expressions.htm
‎2020 Mar 05 11:44 AM
Thanks a lot , Sandra for your patience in helping me.
Just a doubt.
Here i have defined tt_Fin. But lt_Ser is of a different type as it is inline. Will this work only if both are of same type?
DATA(gt_fin) = VALUE tt_fin(FOR lw_j IN lt_join
( matnr =VALUE#( lt_ser[ sernr = lw_j-sernr ]-matnr OPTIONAL)
sernr = lw_j-sernr )).
‎2020 Mar 05 11:48 AM
Thanks sandra.. Should lt_Ser should be of same type always?
‎2020 Mar 05 11:57 AM
DATA(gt_fin)=VALUE tt_fin(FOR lw_j IN lt_join
( matnr =VALUE#( lt_ser[ sernr = lw_j-sernr ]-matnr OPTIONAL)
sernr = lw_j-sernr )).
As im confused,Would be so helpful if you could just let me know what is this doing. so that i can use it in other cases by my own. Thanks
‎2020 Mar 05 4:36 PM
If your requirement is to make a joined table out of a loop through table1 and joining it with table2, assuming there is one matching row (otherwise values from tabl2 are initial), you can do it this way:
DATA(itab3) = VALUE ty_itab(
FOR wa IN itab1
( key = wa-key
valx = wa-valx
valy = VALUE #( itab2[ key = wa-key ]-valy OPTIONAL ) ) ).<br>