2023 Feb 15 11:43 AM
Hi Experts,
I have below code which I would like to write in one go with new syntax avoiding IF-ELSE or Case Statement.
Can you please suggest the same for below?
IF p_vat IS NOT INITIAL.
gt_final = VALUE #( FOR ls_vat IN gt_vat_bp
( partner = ls_vat-innuar
stceg = ls_vat-stceg
)
).
ELSEIF p_vertex IS NOT INITIAL.
gt_final = VALUE #( FOR ls_vertex IN gt_vertex_bp
( partner = ls_vertex-innuar
country = ls_vertex-country
region = ls_vertex-region
txjcd = ls_vertex-txjcd
)
).
ELSEIF p_gmap IS NOT INITIAL.
gt_final = VALUE #( BASE gt_final
FOR ls_gmap IN gt_gmap_bp
( partner = ls_gmap-innuar
country = ls_gmap-country
pstcd1 = ls_gmap-postcode1
street = ls_gmap-street
housenumber = ls_gmap-housenum
)
).
ENDIF.
*Expecting something like below:
gt_final = do all above processing based on COND/SWITCH maybe?
*This should remove any need to if-else and pick which FOR LOOP to be run based on whats chosen as radiobutton parameter.
2023 Feb 15 12:45 PM
I guess you know the COND constructor operator, right? What did you try? What is your issue?
2023 Feb 15 12:46 PM
gt_final = cond #( when p_vat is not initial
then value #( ..... )
2023 Feb 15 2:46 PM
Thanks Frederic and Sandra.
I was expecting a type to be there in place of hash and I was getting errors.
It is done:
gt_final = COND #(
WHEN p_map IS NOT INITIAL THEN VALUE #(
FOR ls_gmap IN gt_gmap_bp
( partner = ls_gmap-innuar
country = ls_gmap-country
pstcd1 = ls_gmap-postcode1
street = ls_gmap-street
housenumber = ls_gmap-housenum
city = ls_gmap-city
region = ls_gmap-region )
)"GMAP
WHEN p_vat IS NOT INITIAL THEN VALUE #(
FOR ls_vat IN gt_vat_bp
( partner = ls_vat-innuar
stceg = ls_vat-stceg )
) "VAT
WHEN p_ver IS NOT INITIAL THEN VALUE #(
FOR ls_vertex IN gt_vertex_bp
( partner = ls_vertex-innuar
country = ls_vertex-country
region = ls_vertex-region
pstcd1 = ls_vertex-pstcd1
city = ls_vertex-city
county = ls_vertex-county
txjcd = ls_vertex-txjcd )
) "Vertex
). "This is COND Bracket