ABAP Select data from SAP table /SMFND/D_INB_H 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 /SMFND/D_INB_H 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 /SMFND/D_INB_H. 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 /SMFND/D_INB_H 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_/SMFND/D_INB_H TYPE STANDARD TABLE OF /SMFND/D_INB_H,
      WA_/SMFND/D_INB_H TYPE /SMFND/D_INB_H,
      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: </SMFND/D_INB_H> TYPE /SMFND/D_INB_H.

*Process all fields in table header/work area as string values
  PERFORM process_as_string_field_values CHANGING wa_/SMFND/D_INB_H.

SELECT *
*restrict ABAP select to first 10 rows
 UP TO 10 ROWS      
  FROM /SMFND/D_INB_H
  INTO TABLE IT_/SMFND/D_INB_H.

*Select data and declare internal table using in-line method @DATA
*SELECT *
*  FROM /SMFND/D_INB_H
*  INTO TABLE @DATA(IT_/SMFND/D_INB_H2).
*--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_/SMFND/D_INB_H INDEX 1 INTO DATA(WA_/SMFND/D_INB_H2).


*Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL
LOOP AT IT_/SMFND/D_INB_H ASSIGNING </SMFND/D_INB_H>.
*To update a field value using a field symbol simply change the value via the field symbol pointer
</SMFND/D_INB_H>-MANDT = 1.
</SMFND/D_INB_H>-TRANSACTION_GUID = 1.
</SMFND/D_INB_H>-RECORD_ID = 1.
</SMFND/D_INB_H>-OBJECT_TYPE = 1.
</SMFND/D_INB_H>-OBJECT_KEY = 1.
ENDLOOP.

LOOP AT IT_/SMFND/D_INB_H INTO WA_/SMFND/D_INB_H.
*Write horizonal line to screen report.
  WRITE:/ sy-uline.

*Write selected data to screen/report before conversion.
  WRITE:/ sy-vline,   WA_/SMFND/D_INB_H-OBJECT_GROUP, sy-vline,
WA_/SMFND/D_INB_H-OBJECT_GROUP_1, sy-vline,
WA_/SMFND/D_INB_H-OBJECT_ID, sy-vline,
WA_/SMFND/D_INB_H-EXT_TRANS_ID, sy-vline,
WA_/SMFND/D_INB_H-DEP_OBJECT_TYPE, sy-vline,
WA_/SMFND/D_INB_H-DEP_OBJECT_KEY, sy-vline.
ENDLOOP. *Add any further fields from structure WA_/SMFND/D_INB_H 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_/SMFND/D_INB_H 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_/SMFND/D_INB_H INTO WA_/SMFND/D_INB_H. *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.

*Conversion exit ALPHA, internal->external for field LOGSYS CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_/SMFND/D_INB_H-LOGSYS IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_/SMFND/D_INB_H-LOGSYS.
WRITE:/ 'New Value:', ld_input.

*Conversion exit ISOLA, internal->external for field REQ_LANGU CALL FUNCTION 'CONVERSION_EXIT_ISOLA_OUTPUT' EXPORTING input = WA_/SMFND/D_INB_H-REQ_LANGU IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_/SMFND/D_INB_H-REQ_LANGU.
WRITE:/ 'New Value:', ld_input.
ENDFORM. *&---------------------------------------------------------------------* *& Form process_as_string_field_values *&---------------------------------------------------------------------* FORM process_as_string_field_values CHANGING p_EKKO LIKE wa_EKKO. TYPES: BEGIN OF T_/SMFND/D_INB_H_STR,
MANDT TYPE STRING,
TRANSACTION_GUID TYPE STRING,
RECORD_ID TYPE STRING,
OBJECT_TYPE TYPE STRING,
OBJECT_KEY TYPE STRING,
OBJECT_GROUP TYPE STRING,
OBJECT_GROUP_1 TYPE STRING,
OBJECT_ID TYPE STRING,
EXT_TRANS_ID TYPE STRING,
DEP_OBJECT_TYPE TYPE STRING,
DEP_OBJECT_KEY TYPE STRING,
DEP_TRANS_ID TYPE STRING,
DEP_TRANS_GUID TYPE STRING,
DEP_OBJECT_ID TYPE STRING,
FLAG_REQ_KEYMAP TYPE STRING,
FLAG_LOCAL_KEY TYPE STRING,
FLAG_LOCAL_ITEM TYPE STRING,
FLAG_REQ_REVIEW TYPE STRING,
OBJTYP_REF TYPE STRING,
OBJKEY_REF TYPE STRING,
OBJECT_ID_REF TYPE STRING,
REQ_PROC_MODE TYPE STRING,
REQ_USER_ID TYPE STRING,
REQ_USER_GUID TYPE STRING,
TRANSACTION_TIME TYPE STRING,
TIME_ZONE TYPE STRING,
MOBILE_APP TYPE STRING,
LOGSYS TYPE STRING,
REQ_TYPE TYPE STRING,
REQ_OBJECT TYPE STRING,
REQ_OBJECT_MTHD TYPE STRING,
REQ_DO_ID TYPE STRING,
REQ_DO_MTHD_TYPE TYPE STRING,
TRANSACTION_TYPE TYPE STRING,
REF_ATTR_1 TYPE STRING,
REF_ATTR_2 TYPE STRING,
TRANSACTION_GRP TYPE STRING,
SYS_COMP TYPE STRING,
TRANS_MERGE_MODE TYPE STRING,
INSTANCE_GUID TYPE STRING,
ITEM_GUID TYPE STRING,
MESSAGE_GUID TYPE STRING,
ORIG_USER_GUID TYPE STRING,
REQ_LANGU TYPE STRING,
TRANS_STATUS TYPE STRING,
EXPIRATION_TS TYPE STRING,
PROCESS_TS TYPE STRING,
COMPLETE_TS TYPE STRING,
CANCEL_TS TYPE STRING,
CHECK_OUT_TS TYPE STRING,
DATA_EDIT_TS TYPE STRING,
ERROR_TS TYPE STRING,
IBQ_QUEUE_ID TYPE STRING,
CHECK_OUT_USER TYPE STRING,
REASON_CODE TYPE STRING,
CHECK_IN_MESSAGE TYPE STRING,
CREATED_BY TYPE STRING,
CREATED_TS TYPE STRING,
CHANGED_BY TYPE STRING,
CHANGED_TS TYPE STRING,END OF T_EKKO_STR. DATA: WA_/SMFND/D_INB_H_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_/SMFND/D_INB_H_STR-MANDT sy-vline
WA_/SMFND/D_INB_H_STR-TRANSACTION_GUID sy-vline
WA_/SMFND/D_INB_H_STR-RECORD_ID sy-vline
WA_/SMFND/D_INB_H_STR-OBJECT_TYPE sy-vline
WA_/SMFND/D_INB_H_STR-OBJECT_KEY sy-vline
WA_/SMFND/D_INB_H_STR-OBJECT_GROUP sy-vline
WA_/SMFND/D_INB_H_STR-OBJECT_GROUP_1 sy-vline
WA_/SMFND/D_INB_H_STR-OBJECT_ID sy-vline
WA_/SMFND/D_INB_H_STR-EXT_TRANS_ID sy-vline
WA_/SMFND/D_INB_H_STR-DEP_OBJECT_TYPE sy-vline
WA_/SMFND/D_INB_H_STR-DEP_OBJECT_KEY sy-vline
WA_/SMFND/D_INB_H_STR-DEP_TRANS_ID sy-vline
WA_/SMFND/D_INB_H_STR-DEP_TRANS_GUID sy-vline
WA_/SMFND/D_INB_H_STR-DEP_OBJECT_ID sy-vline
WA_/SMFND/D_INB_H_STR-FLAG_REQ_KEYMAP sy-vline
WA_/SMFND/D_INB_H_STR-FLAG_LOCAL_KEY sy-vline
WA_/SMFND/D_INB_H_STR-FLAG_LOCAL_ITEM sy-vline
WA_/SMFND/D_INB_H_STR-FLAG_REQ_REVIEW sy-vline
WA_/SMFND/D_INB_H_STR-OBJTYP_REF sy-vline
WA_/SMFND/D_INB_H_STR-OBJKEY_REF sy-vline
WA_/SMFND/D_INB_H_STR-OBJECT_ID_REF sy-vline
WA_/SMFND/D_INB_H_STR-REQ_PROC_MODE sy-vline
WA_/SMFND/D_INB_H_STR-REQ_USER_ID sy-vline
WA_/SMFND/D_INB_H_STR-REQ_USER_GUID sy-vline
WA_/SMFND/D_INB_H_STR-TRANSACTION_TIME sy-vline
WA_/SMFND/D_INB_H_STR-TIME_ZONE sy-vline
WA_/SMFND/D_INB_H_STR-MOBILE_APP sy-vline
WA_/SMFND/D_INB_H_STR-LOGSYS sy-vline
WA_/SMFND/D_INB_H_STR-REQ_TYPE sy-vline
WA_/SMFND/D_INB_H_STR-REQ_OBJECT sy-vline
WA_/SMFND/D_INB_H_STR-REQ_OBJECT_MTHD sy-vline
WA_/SMFND/D_INB_H_STR-REQ_DO_ID sy-vline
WA_/SMFND/D_INB_H_STR-REQ_DO_MTHD_TYPE sy-vline
WA_/SMFND/D_INB_H_STR-TRANSACTION_TYPE sy-vline
WA_/SMFND/D_INB_H_STR-REF_ATTR_1 sy-vline
WA_/SMFND/D_INB_H_STR-REF_ATTR_2 sy-vline
WA_/SMFND/D_INB_H_STR-TRANSACTION_GRP sy-vline
WA_/SMFND/D_INB_H_STR-SYS_COMP sy-vline
WA_/SMFND/D_INB_H_STR-TRANS_MERGE_MODE sy-vline
WA_/SMFND/D_INB_H_STR-INSTANCE_GUID sy-vline
WA_/SMFND/D_INB_H_STR-ITEM_GUID sy-vline
WA_/SMFND/D_INB_H_STR-MESSAGE_GUID sy-vline
WA_/SMFND/D_INB_H_STR-ORIG_USER_GUID sy-vline
WA_/SMFND/D_INB_H_STR-REQ_LANGU sy-vline
WA_/SMFND/D_INB_H_STR-TRANS_STATUS sy-vline
WA_/SMFND/D_INB_H_STR-EXPIRATION_TS sy-vline
WA_/SMFND/D_INB_H_STR-PROCESS_TS sy-vline
WA_/SMFND/D_INB_H_STR-COMPLETE_TS sy-vline
WA_/SMFND/D_INB_H_STR-CANCEL_TS sy-vline
WA_/SMFND/D_INB_H_STR-CHECK_OUT_TS sy-vline
WA_/SMFND/D_INB_H_STR-DATA_EDIT_TS sy-vline
WA_/SMFND/D_INB_H_STR-ERROR_TS sy-vline
WA_/SMFND/D_INB_H_STR-IBQ_QUEUE_ID sy-vline
WA_/SMFND/D_INB_H_STR-CHECK_OUT_USER sy-vline
WA_/SMFND/D_INB_H_STR-REASON_CODE sy-vline
WA_/SMFND/D_INB_H_STR-CHECK_IN_MESSAGE sy-vline
WA_/SMFND/D_INB_H_STR-CREATED_BY sy-vline
WA_/SMFND/D_INB_H_STR-CREATED_TS sy-vline
WA_/SMFND/D_INB_H_STR-CHANGED_BY sy-vline
WA_/SMFND/D_INB_H_STR-CHANGED_TS sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.