'Sap Abap': Data Type Write
'Sap Abap': Data Type Write
'Sap Abap': Data Type Write
* variable
*before 7.4
data: lv_data type char10.
lv_data = 'SAP ABAP'.
write: lv_data.
*after 7.4
data(lv_data) = 'SAP ABAP'.
write: lv_data.
**concatenate before 7.4
data: lv_string1 type char20,
lv_string2 type char20,
lv_string3 type string.
lv_string1 = 'ABAP'.
lv_string2 = 'DDIC'.
CONCATENATE lv_string1 lv_string2 into lv_string3 SEPARATED BY ''.
write: lv_string3.
*after 7.4
data(lv_string1) = 'ABAP'.
data(lv_string2) = 'DDIC'.
data(lv_string3) = | { lv_string1 && lv_String2 }|.
write: lv_String3.
** using inline declaration
* before 7.4
* select stement display material data
types: begin of ty_mara,
matnr type matnr,
mtart type mtart,
matkl type matkl,
end of ty_mara.
data: it_mara type table of ty_mara,
wa_mara type ty_mara.
select matnr mtart matkl from mara into table it_mara up to 10 rows.
LOOP AT it_mara into wa_mara.
write:/ wa_mara-matnr,
wa_mara-mtart,
wa_mara-matkl,
wa_mara-status_material.
ENDLOOP.
* after 7.4
select matnr,mtart,matkl from mara into table @data(it_mara) up to 10 rows .
LOOP AT it_mara into data(wa_mara).
write:/ wa_mara-matnr,
wa_mara-mtart,
wa_mara-matkl.
ENDLOOP.
**** before 7.4 Calculation
TYPES: BEGIN OF ty_mara,
matnr TYPE matnr,
mtart TYPE mtart,
matkl TYPE matkl,
material_status TYPE string,
END OF ty_mara.
DATA: it_mara TYPE TABLE OF ty_mara,
wa_mara TYPE ty_mara.
SELECT matnr mtart matkl FROM mara INTO TABLE it_mara UP TO 10 ROWS.
LOOP AT it_mara INTO wa_mara.
IF wa_mara-mtart = 'FERT'.
wa_mara-material_status = 'Finished Material'.
ELSEIF wa_mara-mtart = 'HALB'.
wa_mara-material_status = 'Semi finished material'.
ELSE.
wa_mara-material_status = 'Raw material'.
ENDIF.
WRITE:/ wa_mara-matnr,
wa_mara-mtart,
wa_mara-matkl,
wa_mara-material_status.
ENDLOOP.
*after 7.4
select matnr,
mtart,
matkl,
case mtart
when 'FERT' then 'Finished materil'
when 'HALB' then 'Semi finished material'
else 'Raw material'
end as status_material
from mara into table @data(it_mara) up to 10 rows.
cl_demo_output=>display_data(
EXPORTING
value = it_mara
* name = " Name
).
**** before 7.4 leading zeros add
TYPES: BEGIN OF ty_mara,
matnr TYPE matnr,
mtart TYPE mtart,
matkl TYPE matkl,
material_status TYPE string,
END OF ty_mara.
DATA: it_mara TYPE TABLE OF ty_mara,
wa_mara TYPE ty_mara.
SELECT matnr mtart matkl FROM mara INTO TABLE it_mara UP TO 10 ROWS.
LOOP AT it_mara INTO wa_mara.
IF wa_mara-mtart = 'FERT'.
wa_mara-material_status = 'Finished Material'.
ELSEIF wa_mara-mtart = 'HALB'.
wa_mara-material_status = 'Semi finished material'.
ELSE.
wa_mara-material_status = 'Raw material'.
ENDIF.
data lv_output type char40.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = wa_mara-matnr
IMPORTING
OUTPUT = lv_output.
.
WRITE:/ lv_output,
wa_mara-mtart,
wa_mara-matkl,
wa_mara-material_status.
ENDLOOP.
* after 7.4
select matnr,
mtart,
matkl,
case mtart
when 'FERT' then 'Finished materil'
when 'HALB' then 'Semi finished material'
else 'Raw material'
end as status_material
from mara into table @data(it_mara) up to 10 rows.
LOOP AT it_mara into data(wa_mara).
DATA(lv_output) = |{ wa_mara-matnr ALPHA = out }|.
write:/ lv_output,
wa_mara-mtart ,
wa_mara-matkl,
wa_mara-status_material.
ENDLOOP.
* new opearator
*before 7.4
class lcl_base DEFINITION.
PUBLIC SECTION.
endclass.
CLASS lcl_base IMPLEMENTATION.
ENDCLASS.
data lo_obj type ref to lcl_base.
create object lo_obj.
*after 7.4
class lcl_base DEFINITION.
PUBLIC SECTION.
endclass.
CLASS lcl_base IMPLEMENTATION.
ENDCLASS.
data(lr_obj) = new class_name( ).
* read statement before 7.4
read table it_mara INTO wa_mara index 1.
*after 7.4
data(wa_mara) = it_mara[ 1 ].
write: wa_mara-matnr.
*read statement with key before 7.4
read TABLE it_mara into lw_mara with key matnr = ''.
* after 7.4
try.
data(lw_mara) = it_mara[ matnr = '000000000000000023' ].
CATCH CX_SY_ITAB_LINE_NOT_FOUND.
endtry.
write: lw_mara-matnr.
*Condition Operator
**** bfefore 7.4 how to use condition
*types: BEGIN OF ty_mara,
* matnr type matnr,
* mtart type mtart,
* matkl type matkl,
*
* end of ty_mara.
* data: lv_status type char50.
* data: lt_mara type table of ty_mara,
* lw_mara type ty_mara.
*START-OF-SELECTION.
*
*select matnr
* mtart
* matkl from mara into table lt_mara
* up to 10 rows.
* LOOP AT lt_mara into lw_mara.
* if lw_mara-mtart = 'FERT'.
* lv_status = 'Finished'.
* elseif lw_mara-mtart = 'ROH'.
* lv_status = 'Raw material'.
* endif.
* write:/ lw_mara-matnr,
* lw_mara-mtart,
* lw_mara-matkl,
* lv_status COLOR 1 INTENSIFIED.
* ENDLOOP.
***** after 7.4
select matnr,
mtart,
matkl from mara into table @data(lt_mara) up to 10 rows.
LOOP AT lt_mara into data(lw_mara).
data(lv_status) = cond #( when
lw_mara-mtart = 'FERT' then 'FINISHED'
when lw_mara-mtart = 'ROH' then 'Raw material'
else 'Semi finshed' ).
write:/ lw_mara-matnr,
lw_mara-mtart,
lw_mara-matkl,
lv_status.
ENDLOOP.
data: lt_emp type TABLE OF ty_emp,
wa_emp type ty_Emp.
lt_emp = VALUE #(
( empid = '01' empname = 'ADI' empsal = '10000' empdesig
= 'SSE' )
( empid = '02' empname = 'Narayana' empsal = '20000' em
pdesig = 'SSE' )
( empid = '03' empname = 'Gauri' empsal = '30000' empde
sig = 'AM' )
( empid = '04' empname = 'Dhiren' empsal = '40000' empd
esig = 'AM' )
( empid = '05' empname = 'Vinitha' empsal = '50000' empdes
ig = 'TL' )
).
data: lr_display type REF TO cl_demo_output.
CALL METHOD cl_demo_output=>display_data
EXPORTING
value = lt_emp
* name =
.
group by looping
select * from mard into table @data(lt_mard).
LOOP AT lt_mard ASSIGNING FIELD-SYMBOL(<lfs_mard>)
GROUP BY ( werks = <lfs_mard>-werks count = group size )
ASSIGNING FIELD-SYMBOL(<lfs_group>).
write:/ 'company code:', <lfs_group>-werks , 'total count:', <
lfs_group>-count.
write:/ 'Material:', 'count:' .
LOOP AT group <lfs_group> ASSIGNING FIELD-SYMBOL(<lfs_mard2>)
group by ( matnr = <lfs_mard2>-matnr count = GROUP SIZE )
ASSIGNING FIELD-SYMBOL(<lfs_group2>).
write:/ <lfs_group2>-matnr,
<lfs_group2>-count.
.
ENDLOOP.
ENDLOOP.
PUBLIC SECTION.
methods: ncasting.
ENDCLASS.
CLASS lcl_base IMPLEMENTATION.
method ncasting.
write: 'Narrow casting'.
ENDMETHOD.
endclass.
class lcl_base1 DEFINITION INHERITING FROM lcl_base.
PUBLIC SECTION.
methods: wcasting.
ENDCLASS.
CLASS lcl_base1 IMPLEMENTATION.
method wcasting.
write: 'wide casting'.
ENDMETHOD.
ENDCLASS.
START-OF-SELECTION.
data(lo_nc) = new lcl_base( ).
data(lo_n2) = new lcl_base1( ).
lo_nc = lo_n2." chidclass to parenet class"up casting
call method lo_nc->ncasting.
lo_n2 ?= lo_nc." parent class to child "downcasting
call method lo_n2->wcasting.
After 7.4
class lcl_base DEFINITION.
PUBLIC SECTION.
methods: ncasting.
ENDCLASS.
CLASS lcl_base IMPLEMENTATION.
method ncasting.
write: 'Narrow casting'.
ENDMETHOD.
endclass.
class lcl_base1 DEFINITION INHERITING FROM lcl_base.
PUBLIC SECTION.
methods: wcasting.
ENDCLASS.
CLASS lcl_base1 IMPLEMENTATION.
method wcasting.
write: 'wide casting'.
ENDMETHOD.
ENDCLASS.
START-OF-SELECTION.
data(lo_nc) = new lcl_base( ).
*data(lo_nc1) = new lcl_base( ).
data(lo_n2) = new lcl_base1( ).
lo_nc = cast #( lo_n2 )." chidclass to parenet class"up casting
call method lo_nc->ncasting.
lo_n2 ?= lo_nc ." parent class to child "downcasting
call method lo_n2->wcasting.