1 Introduce
we use how to fetch string and use CONCATENATE.
Input format
20211006 100000
Output format
2021-10-06 10:00:00
2 code
2.1 CONCATENATE Method
data : ldate type string.
data : ltime type string.
CONCATENATE gw_vbrk-erdat(4) '-' gw_vbrk-erdat+4(2) '-' gw_vbrk-erdat+6(2) into ldate.
CONCATENATE gw_vbrk-erzet(2) ':' gw_vbrk-erzet+2(2)':' gw_vbrk-erzet+4(2) into ltime .
CONCATENATE ldate ltime into gw_send-send_date SEPARATED by space.
2.2 Function Method
DATA :E_TIMESTAMP LIKE TZONREF-TSTAMPS .
CALL FUNCTION 'CIF_GEN4_CONVERT_DATETIME'
EXPORTING
IV_DATE = SY-DATUM
IV_TIME = SY-UZEIT
IV_TIMEZONE = SY-ZONLO
IMPORTING
EV_TIMESTAMP = E_TIMESTAMP
EXCEPTIONS
TIME_CONVERSION_FAILED = 1
OTHERS = 2.
write: / E_TIMESTAMP TIME ZONE sy-zonlo.
3 summary
How to fetch string in the field? you will get 4 front char in the field in the demo.
In the sap , it is very easy. you only need add (4) after field.
data: a type string value '12345678'.
data: b type string.
b = a(4)
4 Scenarios
When you remove data in the sap , We can fetch string for looking for data.
For example.
We don’t fetch data at of head with ‘301’ and ‘123’ and ‘2’ and ‘5’ in following example.
loop at it_eina[] into it_eina .
if it_eina-matnr(12) = '000000000301' or it_eina-matnr(12) = '000000000123'
or it_eina-matnr(10) = '0000000002'or it_eina-matnr(10) = '0000000005'.
delete it_eina .
endif.
clear :it_eina.
ENDLOOP.