ABAP Select data from SAP table /TMF/S_NFH_UI5 into internal table
Get Example source ABAP code based on a different SAP table
Below is a number of ABAP code snippets to demonstrate how to select data from SAP /TMF/S_NFH_UI5 table and store it within an internal table, including using the newer @DATA inline declaration methods. It also shows you various ways to process this data using ABAP work area, inline declaration or field symbols including executing all the relevant CONVERSION_EXIT routines specific to /TMF/S_NFH_UI5. See here for more generic Select statement tips.
Sometimes data within SAP is stored within the database table in a different format to what it is displayed to the user. These input/output conversation FM routines are what translates the data between the two formats.
There is also a full declaration of the /TMF/S_NFH_UI5 table where each field has a char/string type for you to simply copy and paste. This allows you to use processing that is only available to these field types such as the CONCATENATE statement.
DATA: IT_/TMF/S_NFH_UI5 TYPE STANDARD TABLE OF /TMF/S_NFH_UI5, WA_/TMF/S_NFH_UI5 TYPE /TMF/S_NFH_UI5, GD_STR TYPE STRING. DATA: lo_typedescr type REF TO cl_abap_typedescr. DATA: lv_fieldname type fieldname. FIELD-SYMBOLS: <FIELD> TYPE any. FIELD-SYMBOLS: </TMF/S_NFH_UI5> TYPE /TMF/S_NFH_UI5. *Process all fields in table header/work area as string values PERFORM process_as_string_field_values CHANGING wa_/TMF/S_NFH_UI5. SELECT * *restrict ABAP select to first 10 rows UP TO 10 ROWS FROM /TMF/S_NFH_UI5 INTO TABLE IT_/TMF/S_NFH_UI5. *Select data and declare internal table using in-line method @DATA *SELECT * * FROM /TMF/S_NFH_UI5 * INTO TABLE @DATA(IT_/TMF/S_NFH_UI52). *--Further methods of using ABAP code to select data from SAP database tables *You can also declare the header/work area using the in-line DATA declaration method READ TABLE IT_/TMF/S_NFH_UI5 INDEX 1 INTO DATA(WA_/TMF/S_NFH_UI52). *Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL LOOP AT IT_/TMF/S_NFH_UI5 ASSIGNING </TMF/S_NFH_UI5>.*To update a field value using a field symbol simply change the value via the field symbol pointer
</TMF/S_NFH_UI5>-MANDT = 1.
</TMF/S_NFH_UI5>-NF_ID = 1.
</TMF/S_NFH_UI5>-CHV_NFE = 1.
</TMF/S_NFH_UI5>-NUM_DOC = 1.
</TMF/S_NFH_UI5>-SER = 1.
ENDLOOP. LOOP AT IT_/TMF/S_NFH_UI5 INTO WA_/TMF/S_NFH_UI5. *Write horizonal line to screen report. WRITE:/ sy-uline. *Write selected data to screen/report before conversion. WRITE:/ sy-vline, WA_/TMF/S_NFH_UI5-COD_MOD, sy-vline,
WA_/TMF/S_NFH_UI5-DT_DOC, sy-vline,
WA_/TMF/S_NFH_UI5-DT_E_S, sy-vline,
WA_/TMF/S_NFH_UI5-HR_E_S, sy-vline,
WA_/TMF/S_NFH_UI5-VL_TOTAL_DOCUMENTO, sy-vline,
WA_/TMF/S_NFH_UI5-CNPJ_CPF, sy-vline.
ENDLOOP. *Add any further fields from structure WA_/TMF/S_NFH_UI5 you want to display... WRITE:/ sy-uline. * Aternatively use generic code to Write field values (and NAME) to screen report DO. ASSIGN COMPONENT sy-index OF STRUCTURE wa_/TMF/S_NFH_UI5 TO <field>. IF sy-subrc <> 0. EXIT. ENDIF. WRITE:/ 'Field Value', <field>, sy-vline. gd_str = <field> . lo_typedescr ?= CL_ABAP_DATADESCR=>DESCRIBE_BY_DATA( <field> ). lv_fieldname = lo_typedescr->GET_RELATIVE_NAME( ). WRITE:/ 'Field Name', lv_fieldname. ENDDO. *Redo loop but convert all fields from internal to out value LOOP AT IT_/TMF/S_NFH_UI5 INTO WA_/TMF/S_NFH_UI5. *Write horizonal line to screen report. WRITE:/ sy-uline. *Convert all fields to display/output versions using conversion routines PERFORM convert_all_field_values CHANGING wa_EKKO. ENDLOOP. *&---------------------------------------------------------------------* *& Form convert_all_field_values *&---------------------------------------------------------------------* FORM convert_all_field_values CHANGING p_EKKO LIKE wa_EKKO. DATA: ld_input(1000) TYPE c, ld_output(1000) TYPE C.
ENDFORM. *&---------------------------------------------------------------------* *& Form process_as_string_field_values *&---------------------------------------------------------------------* FORM process_as_string_field_values CHANGING p_EKKO LIKE wa_EKKO. TYPES: BEGIN OF T_/TMF/S_NFH_UI5_STR,
MANDT TYPE STRING,
NF_ID TYPE STRING,
CHV_NFE TYPE STRING,
NUM_DOC TYPE STRING,
SER TYPE STRING,
COD_MOD TYPE STRING,
DT_DOC TYPE STRING,
DT_E_S TYPE STRING,
HR_E_S TYPE STRING,
VL_TOTAL_DOCUMENTO TYPE STRING,
CNPJ_CPF TYPE STRING,
SIT_ATUAL TYPE STRING,
XML_VERS TYPE STRING,
NAT_OPER_TXT TYPE STRING,
COD_SIT TYPE STRING,
COD_SIT_TXT TYPE STRING,
TIPO_EMIT TYPE STRING,
TIPO_EMIT_TXT TYPE STRING,
TIPO_OPER TYPE STRING,
TIPO_OPER_TXT TYPE STRING,
IND_EMIT TYPE STRING,
IND_EMIT_TXT TYPE STRING,
IND_PGTO TYPE STRING,
IND_PGTO_TXT TYPE STRING,
DT_AUTH TYPE STRING,
HR_AUTH TYPE STRING,
IND_FRT TYPE STRING,
MOD_FRETE_TXT TYPE STRING,
ECF_MOD TYPE STRING,
ECF_ORD_SEQ TYPE STRING,
ECF_ORD_OPER TYPE STRING,
VL_BC_ICMS TYPE STRING,
VL_ICMS TYPE STRING,
VL_BC_ICMSST TYPE STRING,
VL_ICMSST TYPE STRING,
VL_ITEM TYPE STRING,
VL_FRT TYPE STRING,
VL_SEG TYPE STRING,
VL_OUT TYPE STRING,
VL_IPI TYPE STRING,
VL_DESC TYPE STRING,
VL_PIS TYPE STRING,
VL_COFINS TYPE STRING,
VL_APROX_TRIB TYPE STRING,
COMPANY_CODE TYPE STRING,
BRANCH TYPE STRING,
NOME_EMPRESA TYPE STRING,
IE_EMPRESA TYPE STRING,
IE_EMPRESA_ST TYPE STRING,
UF_EMPRESA TYPE STRING,
NOME_FANTASIA_EMPRESA TYPE STRING,
CNPJ_EMPRESA TYPE STRING,
ENDERECO_EMPRESA TYPE STRING,
BAIRRO_EMPRESA TYPE STRING,
CEP_EMPRESA TYPE STRING,
COD_MUN_EMPRESA TYPE STRING,
DESC_MUN_EMPRESA TYPE STRING,
FONE_EMPRESA TYPE STRING,
PAIS_EMPRESA TYPE STRING,
IM_EMPRESA TYPE STRING,
CNAE_EMPRESA TYPE STRING,
CRT_BUPLA TYPE STRING,
CRT_BUPLA_EMPRESA TYPE STRING,
NOME_PARCEIRO TYPE STRING,
IE_PARCEIRO TYPE STRING,
UF_PARCEIRO TYPE STRING,
IND_FINAL TYPE STRING,
IND_FINAL_TXT TYPE STRING,
PRE_COMPRADOR TYPE STRING,
PRE_COMPRADOR_TXT TYPE STRING,
CNPJ_PARCEIRO TYPE STRING,
ENDERECO_PARCEIRO TYPE STRING,
BAIRRO_PARCEIRO TYPE STRING,
CEP_PARCEIRO TYPE STRING,
DESC_MUN_PARCEIRO TYPE STRING,
FONE_PARCEIRO TYPE STRING,
PAIS_PARCEIRO TYPE STRING,
SUFRAMA_PARCEIRO TYPE STRING,
EMAIL_PARCEIRO TYPE STRING,
SEARCH TYPE STRING,END OF T_EKKO_STR. DATA: WA_/TMF/S_NFH_UI5_STR type T_EKKO_STR. DATA: ld_text TYPE string. LOOP AT IT_EKKO INTO WA_EKKO. MOVE-CORRESPONDING wa_EKKO TO WA_EKKO_STR. CONCATENATE: sy-vline
WA_/TMF/S_NFH_UI5_STR-MANDT sy-vline
WA_/TMF/S_NFH_UI5_STR-NF_ID sy-vline
WA_/TMF/S_NFH_UI5_STR-CHV_NFE sy-vline
WA_/TMF/S_NFH_UI5_STR-NUM_DOC sy-vline
WA_/TMF/S_NFH_UI5_STR-SER sy-vline
WA_/TMF/S_NFH_UI5_STR-COD_MOD sy-vline
WA_/TMF/S_NFH_UI5_STR-DT_DOC sy-vline
WA_/TMF/S_NFH_UI5_STR-DT_E_S sy-vline
WA_/TMF/S_NFH_UI5_STR-HR_E_S sy-vline
WA_/TMF/S_NFH_UI5_STR-VL_TOTAL_DOCUMENTO sy-vline
WA_/TMF/S_NFH_UI5_STR-CNPJ_CPF sy-vline
WA_/TMF/S_NFH_UI5_STR-SIT_ATUAL sy-vline
WA_/TMF/S_NFH_UI5_STR-XML_VERS sy-vline
WA_/TMF/S_NFH_UI5_STR-NAT_OPER_TXT sy-vline
WA_/TMF/S_NFH_UI5_STR-COD_SIT sy-vline
WA_/TMF/S_NFH_UI5_STR-COD_SIT_TXT sy-vline
WA_/TMF/S_NFH_UI5_STR-TIPO_EMIT sy-vline
WA_/TMF/S_NFH_UI5_STR-TIPO_EMIT_TXT sy-vline
WA_/TMF/S_NFH_UI5_STR-TIPO_OPER sy-vline
WA_/TMF/S_NFH_UI5_STR-TIPO_OPER_TXT sy-vline
WA_/TMF/S_NFH_UI5_STR-IND_EMIT sy-vline
WA_/TMF/S_NFH_UI5_STR-IND_EMIT_TXT sy-vline
WA_/TMF/S_NFH_UI5_STR-IND_PGTO sy-vline
WA_/TMF/S_NFH_UI5_STR-IND_PGTO_TXT sy-vline
WA_/TMF/S_NFH_UI5_STR-DT_AUTH sy-vline
WA_/TMF/S_NFH_UI5_STR-HR_AUTH sy-vline
WA_/TMF/S_NFH_UI5_STR-IND_FRT sy-vline
WA_/TMF/S_NFH_UI5_STR-MOD_FRETE_TXT sy-vline
WA_/TMF/S_NFH_UI5_STR-ECF_MOD sy-vline
WA_/TMF/S_NFH_UI5_STR-ECF_ORD_SEQ sy-vline
WA_/TMF/S_NFH_UI5_STR-ECF_ORD_OPER sy-vline
WA_/TMF/S_NFH_UI5_STR-VL_BC_ICMS sy-vline
WA_/TMF/S_NFH_UI5_STR-VL_ICMS sy-vline
WA_/TMF/S_NFH_UI5_STR-VL_BC_ICMSST sy-vline
WA_/TMF/S_NFH_UI5_STR-VL_ICMSST sy-vline
WA_/TMF/S_NFH_UI5_STR-VL_ITEM sy-vline
WA_/TMF/S_NFH_UI5_STR-VL_FRT sy-vline
WA_/TMF/S_NFH_UI5_STR-VL_SEG sy-vline
WA_/TMF/S_NFH_UI5_STR-VL_OUT sy-vline
WA_/TMF/S_NFH_UI5_STR-VL_IPI sy-vline
WA_/TMF/S_NFH_UI5_STR-VL_DESC sy-vline
WA_/TMF/S_NFH_UI5_STR-VL_PIS sy-vline
WA_/TMF/S_NFH_UI5_STR-VL_COFINS sy-vline
WA_/TMF/S_NFH_UI5_STR-VL_APROX_TRIB sy-vline
WA_/TMF/S_NFH_UI5_STR-COMPANY_CODE sy-vline
WA_/TMF/S_NFH_UI5_STR-BRANCH sy-vline
WA_/TMF/S_NFH_UI5_STR-NOME_EMPRESA sy-vline
WA_/TMF/S_NFH_UI5_STR-IE_EMPRESA sy-vline
WA_/TMF/S_NFH_UI5_STR-IE_EMPRESA_ST sy-vline
WA_/TMF/S_NFH_UI5_STR-UF_EMPRESA sy-vline
WA_/TMF/S_NFH_UI5_STR-NOME_FANTASIA_EMPRESA sy-vline
WA_/TMF/S_NFH_UI5_STR-CNPJ_EMPRESA sy-vline
WA_/TMF/S_NFH_UI5_STR-ENDERECO_EMPRESA sy-vline
WA_/TMF/S_NFH_UI5_STR-BAIRRO_EMPRESA sy-vline
WA_/TMF/S_NFH_UI5_STR-CEP_EMPRESA sy-vline
WA_/TMF/S_NFH_UI5_STR-COD_MUN_EMPRESA sy-vline
WA_/TMF/S_NFH_UI5_STR-DESC_MUN_EMPRESA sy-vline
WA_/TMF/S_NFH_UI5_STR-FONE_EMPRESA sy-vline
WA_/TMF/S_NFH_UI5_STR-PAIS_EMPRESA sy-vline
WA_/TMF/S_NFH_UI5_STR-IM_EMPRESA sy-vline
WA_/TMF/S_NFH_UI5_STR-CNAE_EMPRESA sy-vline
WA_/TMF/S_NFH_UI5_STR-CRT_BUPLA sy-vline
WA_/TMF/S_NFH_UI5_STR-CRT_BUPLA_EMPRESA sy-vline
WA_/TMF/S_NFH_UI5_STR-NOME_PARCEIRO sy-vline
WA_/TMF/S_NFH_UI5_STR-IE_PARCEIRO sy-vline
WA_/TMF/S_NFH_UI5_STR-UF_PARCEIRO sy-vline
WA_/TMF/S_NFH_UI5_STR-IND_FINAL sy-vline
WA_/TMF/S_NFH_UI5_STR-IND_FINAL_TXT sy-vline
WA_/TMF/S_NFH_UI5_STR-PRE_COMPRADOR sy-vline
WA_/TMF/S_NFH_UI5_STR-PRE_COMPRADOR_TXT sy-vline
WA_/TMF/S_NFH_UI5_STR-CNPJ_PARCEIRO sy-vline
WA_/TMF/S_NFH_UI5_STR-ENDERECO_PARCEIRO sy-vline
WA_/TMF/S_NFH_UI5_STR-BAIRRO_PARCEIRO sy-vline
WA_/TMF/S_NFH_UI5_STR-CEP_PARCEIRO sy-vline
WA_/TMF/S_NFH_UI5_STR-DESC_MUN_PARCEIRO sy-vline
WA_/TMF/S_NFH_UI5_STR-FONE_PARCEIRO sy-vline
WA_/TMF/S_NFH_UI5_STR-PAIS_PARCEIRO sy-vline
WA_/TMF/S_NFH_UI5_STR-SUFRAMA_PARCEIRO sy-vline
WA_/TMF/S_NFH_UI5_STR-EMAIL_PARCEIRO sy-vline
WA_/TMF/S_NFH_UI5_STR-SEARCH sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.