https://zbap.net/abap-7-4-new-features-4eb4cde1a622
https://discoveringabap.com/2021/10/15/abap-7-4-and-beyond-9-for-loop-for-internal-tables/
*- type declarations DATA(lv_text) = 'Declaring variables'. DATA(lv_count) = 1000. *- using value to create internal tables DATA lt_matnr TYPE STANDARD TABLE OF matnr. lt_matnr = VALUE #( ( 'a' ) ( 'b' ) ( 'c' ) ( 'd' ) ( 'e' ) ). *- another way of declaring same with type TYPES:t_matnr TYPE STANDARD TABLE OF matnr WITH DEFAULT KEY . DATA(lt_data) = VALUE t_matnr( ( 'a' ) ( 'b' ) ( 'c' ) ( 'd' ) ( 'e' ) ). *- filling data into an internal table with structure DATA:lt_bukrs TYPE RANGE OF bukrs. lt_bukrs = VALUE #( sign = 'I' option = 'EQ' ( low = '0001' ) ( low = '1000' ) ( low = '2000' ) ). *- declaring work area variable for loop LOOP AT lt_matnr INTO DATA(ls_matnr). ENDLOOP. *- declaring field symbol variable for loop LOOP AT lt_bukrs ASSIGNING FIELD-SYMBOL(<ls_bukrs>). ENDLOOP. *- declaring field symbol variable for read table READ TABLE lt_matnr ASSIGNING FIELD-SYMBOL(<ls_matnr>) INDEX 3. IF sy-subrc EQ 0. ENDIF. *- getting same data with using table expression DATA(wa_matnr) = lt_matnr[ 3 ]. *- another examples of table expressions DATA(wa_bukrs) = lt_bukrs[ low = '1000' ]. *- check if line exists IF line_exists( lt_bukrs[ low = '1000'] ). ENDIF. *- iteration with 'FOR' DATA(lt_material) = VALUE t_matnr( FOR ls_material IN lt_matnr ( ls_material ) ). *- another use of 'FOR' TYPES : BEGIN OF t_year , year TYPE numc4, END OF t_year, tt_year TYPE STANDARD TABLE OF t_year WITH EMPTY KEY. DATA(lt_years) = VALUE tt_year( FOR i = 2000 THEN i + 1 UNTIL i > 2020 ( year = i ) ). LOOP AT lt_years ASSIGNING FIELD-SYMBOL(<ls_year>). WRITE / <ls_year>-year. ENDLOOP. *- using 'COND' for declaring new variables DATA(lv_status) = 'S'. DATA(lv_status_text) = COND string( WHEN lv_status = 'A' THEN 'Aborted' WHEN lv_status = 'S' THEN 'Success' WHEN lv_status = 'F' THEN 'Failed' ELSE 'Status not found' ). WRITE / lv_status_text. *- we can use 'SWITCH' for declaring conditional operators DATA(lv_status_text2) = SWITCH string( lv_status WHEN 'A' THEN 'Aborted' WHEN 'S' THEN 'Success' WHEN 'F' THEN 'Failed' ELSE 'Status not found' ). WRITE / lv_status_text2. *- CONCATENATE is easy DATA(lv_time_string) = |Date: { sy-datum } / { sy-uzeit } Status: { lv_status_text } |. WRITE / lv_time_string. *- you can use embedded expressions for many string operations DATA:lv_ebeln TYPE ebeln VALUE '490001'. DATA(lv_purc_no) = |{ lv_ebeln ALPHA = IN } |. WRITE / lv_purc_no. DATA:lv_decimal TYPE p DECIMALS 10 VALUE '123.456789'. DATA(lv_money) = |{ lv_decimal DECIMALS = 2 } |. WRITE:lv_money.*- using case statement in database access SELECT werks, CASE WHEN land1 = 'DE' THEN 'IN' ELSE 'OUT' END AS country FROM t001w INTO TABLE @DATA(lt_werks). LOOP AT lt_werks ASSIGNING FIELD-SYMBOL(<ls_werks>). WRITE: / <ls_werks>-country,<ls_werks>-werks. ENDLOOP.*- fill ranges/tables directly from select with default valuesDATA:lr_range TYPE RANGE OF matnr. SELECT matnr, 'ORHAN' AS yaratan FROM mara INTO TABLE @DATA(lt_data) . SELECT 'I' AS sign ,'EQ' AS option, matnr AS low FROM mara INTO TABLE @lr_range UP TO 10 ROWS.++++++++++++++++++++++++++++++++++++++++++++++++++EXEMPLO FILTRAR DADOS DE TABELA INTERNA SEM LOOP. TYPES: BEGIN OF tp_upl, partner_coop TYPE zsdt_0099-partner_coop,
id_coop TYPE zsdt_0099-id_coop,
partner_prop TYPE zsdt_0099-partner_prop,
barracao TYPE zsdt_0099-barracao,
semana TYPE zsdt_0099-semana,
ano TYPE zsdt_0099-ano,
rodada TYPE zsdt_0099-rodada,
dt_cri_lote TYPE zsdt_0099-dt_cri_lote,
END OF tp_upl.
TYPES: tp_dados_sel TYPE TABLE OF tp_upl WITH DEFAULT KEY.
DATA(lt_upl) = VALUE tp_dados_sel(
FOR ls_dados IN gt_zsdt_0099
WHERE ( partner_prop = zsds_0041-id_propr )
( partner_coop = ls_dados-partner_coop
id_coop = ls_dados-id_coop
partner_prop = ls_dados-partner_prop
barracao = ls_dados-barracao
semana = ls_dados-semana
ano = ls_dados-ano
rodada = ls_dados-rodada
dt_cri_lote = ls_dados-dt_cri_lote ) ).
===============================================
DELETE FROM demo_expressions.
INSERT demo_expressions FROM TABLE @( VALUE #(
( id = 'X'
char1 = ' 0123'
char2 = 'aAaA' ) ) ).
SELECT SINGLE
char1 AS text1,
char2 AS text2,
CONCAT( char1,char2 ) AS concat,
CONCAT_WITH_SPACE( char1,char2, 1 ) AS concat_with_space,
INSTR( char1,'12' ) AS instr,
LEFT( char1,3 ) AS left,
LENGTH( char1 ) AS length,
LOWER( char2 ) AS lower,
LPAD( char1,10,'x' ) AS lpad,
LTRIM( char1,' ' ) AS ltrim,
REPLACE( char1,'12','__' ) AS replace,
RIGHT( char1,3 ) as right,
RPAD( char1,10,'x' ) AS rpad,
RTRIM( char1,'3' ) AS rtrim,
SUBSTRING( char1,3,3 ) AS substring,
UPPER( char2 ) AS upper
FROM demo_expressions
INTO @DATA(result).
cl_demo_output=>display( result ).
========================================================================
SELECT SINGLE concat( concat( rtrim( ort01,' ' ),'-' ), regio ) AS incol2
FROM t001w
WHERE werks EQ @ls_ped_transf-werks_dest
INTO @DATA(l_incol2).
======================================================================
Nenhum comentário:
Postar um comentário