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

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

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

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


*Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL
LOOP AT IT_/SAPDII/INC_BAPISDHD1 ASSIGNING </SAPDII/INC_BAPISDHD1>.
*To update a field value using a field symbol simply change the value via the field symbol pointer
</SAPDII/INC_BAPISDHD1>-REFOBJTYPE = 1.
</SAPDII/INC_BAPISDHD1>-REFOBJKEY = 1.
</SAPDII/INC_BAPISDHD1>-REFDOCTYPE = 1.
</SAPDII/INC_BAPISDHD1>-DOC_TYPE = 1.
</SAPDII/INC_BAPISDHD1>-COLLECT_NO = 1.
ENDLOOP.

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

*Write selected data to screen/report before conversion.
  WRITE:/ sy-vline,   WA_/SAPDII/INC_BAPISDHD1-SALES_ORG, sy-vline,
WA_/SAPDII/INC_BAPISDHD1-DISTR_CHAN, sy-vline,
WA_/SAPDII/INC_BAPISDHD1-DIVISION, sy-vline,
WA_/SAPDII/INC_BAPISDHD1-SALES_GRP, sy-vline,
WA_/SAPDII/INC_BAPISDHD1-SALES_OFF, sy-vline,
WA_/SAPDII/INC_BAPISDHD1-REQ_DATE_H, sy-vline.
ENDLOOP. *Add any further fields from structure WA_/SAPDII/INC_BAPISDHD1 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_/SAPDII/INC_BAPISDHD1 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_/SAPDII/INC_BAPISDHD1 INTO WA_/SAPDII/INC_BAPISDHD1. *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_/SAPDII/INC_BAPISDHD1_STR,
REFOBJTYPE TYPE STRING,
REFOBJKEY TYPE STRING,
REFDOCTYPE TYPE STRING,
DOC_TYPE TYPE STRING,
COLLECT_NO TYPE STRING,
SALES_ORG TYPE STRING,
DISTR_CHAN TYPE STRING,
DIVISION TYPE STRING,
SALES_GRP TYPE STRING,
SALES_OFF TYPE STRING,
REQ_DATE_H TYPE STRING,
DATE_TYPE TYPE STRING,
PURCH_DATE TYPE STRING,
PO_METHOD TYPE STRING,
PO_SUPPLEM TYPE STRING,
REF_1 TYPE STRING,
NAME TYPE STRING,
TELEPHONE TYPE STRING,
PRICE_GRP TYPE STRING,
CUST_GROUP TYPE STRING,
SALES_DIST TYPE STRING,
PRICE_LIST TYPE STRING,
INCOTERMS1 TYPE STRING,
INCOTERMS2 TYPE STRING,
PMNTTRMS TYPE STRING,
DLV_BLOCK TYPE STRING,
BILL_BLOCK TYPE STRING,
ORD_REASON TYPE STRING,
COMPL_DLV TYPE STRING,
PRICE_DATE TYPE STRING,
QT_VALID_F TYPE STRING,
QT_VALID_T TYPE STRING,
CT_VALID_F TYPE STRING,
CT_VALID_T TYPE STRING,
CUST_GRP1 TYPE STRING,
CUST_GRP2 TYPE STRING,
CUST_GRP3 TYPE STRING,
CUST_GRP4 TYPE STRING,
CUST_GRP5 TYPE STRING,
PURCH_NO_C TYPE STRING,
PURCH_NO_S TYPE STRING,
PO_DAT_S TYPE STRING,
PO_METH_S TYPE STRING,
REF_1_S TYPE STRING,
SD_DOC_CAT TYPE STRING,
DOC_DATE TYPE STRING,
WAR_DATE TYPE STRING,
SHIP_COND TYPE STRING,
PP_SEARCH TYPE STRING,
DUN_COUNT TYPE STRING,
DUN_DATE TYPE STRING,
DLVSCHDUSE TYPE STRING,
PLDLVSTYP TYPE STRING,
REF_DOC TYPE STRING,
COMP_CDE_B TYPE STRING,
ALTTAX_CLS TYPE STRING,
TAX_CLASS2 TYPE STRING,
TAX_CLASS3 TYPE STRING,
TAX_CLASS4 TYPE STRING,
TAX_CLASS5 TYPE STRING,
TAX_CLASS6 TYPE STRING,
TAX_CLASS7 TYPE STRING,
TAX_CLASS8 TYPE STRING,
TAX_CLASS9 TYPE STRING,
REF_DOC_L TYPE STRING,
ASS_NUMBER TYPE STRING,
REFDOC_CAT TYPE STRING,
ORDCOMB_IN TYPE STRING,
BILL_SCHED TYPE STRING,
INVO_SCHED TYPE STRING,
MN_INVOICE TYPE STRING,
EXRATE_FI TYPE STRING,
ADD_VAL_DY TYPE STRING,
FIX_VAL_DY TYPE STRING,
PYMT_METH TYPE STRING,
ACCNT_ASGN TYPE STRING,
EXCHG_RATE TYPE STRING,
BILL_DATE TYPE STRING,
SERV_DATE TYPE STRING,
DUNN_KEY TYPE STRING,
DUNN_BLOCK TYPE STRING,
PMTGAR_PRO TYPE STRING,
DEPARTM_NO TYPE STRING,
REC_POINT TYPE STRING,
DOC_NUM_FI TYPE STRING,
CSTCNDGRP1 TYPE STRING,
CSTCNDGRP2 TYPE STRING,
CSTCNDGRP3 TYPE STRING,
CSTCNDGRP4 TYPE STRING,
CSTCNDGRP5 TYPE STRING,
DLV_TIME TYPE STRING,
CURRENCY TYPE STRING,
CURR_ISO TYPE STRING,
CREATED_BY TYPE STRING,
TAXDEP_CTY TYPE STRING,
TAXDST_CTY TYPE STRING,
EUTRI_DEAL TYPE STRING,
MAST_CONTR TYPE STRING,
REF_PROC TYPE STRING,
CHKPRTAUTH TYPE STRING,
CMLQTY_DAT TYPE STRING,
VERSION TYPE STRING,
NOTIF_NO TYPE STRING,
WBS_ELEM TYPE STRING,
EXCH_RATE_FI_V TYPE STRING,
EXCHG_RATE_V TYPE STRING,
FKK_CONACCT TYPE STRING,
CAMPAIGN TYPE STRING,
DOC_CLASS TYPE STRING,
H_CURR TYPE STRING,
H_CURR_ISO TYPE STRING,
SHIP_TYPE TYPE STRING,
S_PROC_IND TYPE STRING,END OF T_EKKO_STR. DATA: WA_/SAPDII/INC_BAPISDHD1_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_/SAPDII/INC_BAPISDHD1_STR-REFOBJTYPE sy-vline
WA_/SAPDII/INC_BAPISDHD1_STR-REFOBJKEY sy-vline
WA_/SAPDII/INC_BAPISDHD1_STR-REFDOCTYPE sy-vline
WA_/SAPDII/INC_BAPISDHD1_STR-DOC_TYPE sy-vline
WA_/SAPDII/INC_BAPISDHD1_STR-COLLECT_NO sy-vline
WA_/SAPDII/INC_BAPISDHD1_STR-SALES_ORG sy-vline
WA_/SAPDII/INC_BAPISDHD1_STR-DISTR_CHAN sy-vline
WA_/SAPDII/INC_BAPISDHD1_STR-DIVISION sy-vline
WA_/SAPDII/INC_BAPISDHD1_STR-SALES_GRP sy-vline
WA_/SAPDII/INC_BAPISDHD1_STR-SALES_OFF sy-vline
WA_/SAPDII/INC_BAPISDHD1_STR-REQ_DATE_H sy-vline
WA_/SAPDII/INC_BAPISDHD1_STR-DATE_TYPE sy-vline
WA_/SAPDII/INC_BAPISDHD1_STR-PURCH_DATE sy-vline
WA_/SAPDII/INC_BAPISDHD1_STR-PO_METHOD sy-vline
WA_/SAPDII/INC_BAPISDHD1_STR-PO_SUPPLEM sy-vline
WA_/SAPDII/INC_BAPISDHD1_STR-REF_1 sy-vline
WA_/SAPDII/INC_BAPISDHD1_STR-NAME sy-vline
WA_/SAPDII/INC_BAPISDHD1_STR-TELEPHONE sy-vline
WA_/SAPDII/INC_BAPISDHD1_STR-PRICE_GRP sy-vline
WA_/SAPDII/INC_BAPISDHD1_STR-CUST_GROUP sy-vline
WA_/SAPDII/INC_BAPISDHD1_STR-SALES_DIST sy-vline
WA_/SAPDII/INC_BAPISDHD1_STR-PRICE_LIST sy-vline
WA_/SAPDII/INC_BAPISDHD1_STR-INCOTERMS1 sy-vline
WA_/SAPDII/INC_BAPISDHD1_STR-INCOTERMS2 sy-vline
WA_/SAPDII/INC_BAPISDHD1_STR-PMNTTRMS sy-vline
WA_/SAPDII/INC_BAPISDHD1_STR-DLV_BLOCK sy-vline
WA_/SAPDII/INC_BAPISDHD1_STR-BILL_BLOCK sy-vline
WA_/SAPDII/INC_BAPISDHD1_STR-ORD_REASON sy-vline
WA_/SAPDII/INC_BAPISDHD1_STR-COMPL_DLV sy-vline
WA_/SAPDII/INC_BAPISDHD1_STR-PRICE_DATE sy-vline
WA_/SAPDII/INC_BAPISDHD1_STR-QT_VALID_F sy-vline
WA_/SAPDII/INC_BAPISDHD1_STR-QT_VALID_T sy-vline
WA_/SAPDII/INC_BAPISDHD1_STR-CT_VALID_F sy-vline
WA_/SAPDII/INC_BAPISDHD1_STR-CT_VALID_T sy-vline
WA_/SAPDII/INC_BAPISDHD1_STR-CUST_GRP1 sy-vline
WA_/SAPDII/INC_BAPISDHD1_STR-CUST_GRP2 sy-vline
WA_/SAPDII/INC_BAPISDHD1_STR-CUST_GRP3 sy-vline
WA_/SAPDII/INC_BAPISDHD1_STR-CUST_GRP4 sy-vline
WA_/SAPDII/INC_BAPISDHD1_STR-CUST_GRP5 sy-vline
WA_/SAPDII/INC_BAPISDHD1_STR-PURCH_NO_C sy-vline
WA_/SAPDII/INC_BAPISDHD1_STR-PURCH_NO_S sy-vline
WA_/SAPDII/INC_BAPISDHD1_STR-PO_DAT_S sy-vline
WA_/SAPDII/INC_BAPISDHD1_STR-PO_METH_S sy-vline
WA_/SAPDII/INC_BAPISDHD1_STR-REF_1_S sy-vline
WA_/SAPDII/INC_BAPISDHD1_STR-SD_DOC_CAT sy-vline
WA_/SAPDII/INC_BAPISDHD1_STR-DOC_DATE sy-vline
WA_/SAPDII/INC_BAPISDHD1_STR-WAR_DATE sy-vline
WA_/SAPDII/INC_BAPISDHD1_STR-SHIP_COND sy-vline
WA_/SAPDII/INC_BAPISDHD1_STR-PP_SEARCH sy-vline
WA_/SAPDII/INC_BAPISDHD1_STR-DUN_COUNT sy-vline
WA_/SAPDII/INC_BAPISDHD1_STR-DUN_DATE sy-vline
WA_/SAPDII/INC_BAPISDHD1_STR-DLVSCHDUSE sy-vline
WA_/SAPDII/INC_BAPISDHD1_STR-PLDLVSTYP sy-vline
WA_/SAPDII/INC_BAPISDHD1_STR-REF_DOC sy-vline
WA_/SAPDII/INC_BAPISDHD1_STR-COMP_CDE_B sy-vline
WA_/SAPDII/INC_BAPISDHD1_STR-ALTTAX_CLS sy-vline
WA_/SAPDII/INC_BAPISDHD1_STR-TAX_CLASS2 sy-vline
WA_/SAPDII/INC_BAPISDHD1_STR-TAX_CLASS3 sy-vline
WA_/SAPDII/INC_BAPISDHD1_STR-TAX_CLASS4 sy-vline
WA_/SAPDII/INC_BAPISDHD1_STR-TAX_CLASS5 sy-vline
WA_/SAPDII/INC_BAPISDHD1_STR-TAX_CLASS6 sy-vline
WA_/SAPDII/INC_BAPISDHD1_STR-TAX_CLASS7 sy-vline
WA_/SAPDII/INC_BAPISDHD1_STR-TAX_CLASS8 sy-vline
WA_/SAPDII/INC_BAPISDHD1_STR-TAX_CLASS9 sy-vline
WA_/SAPDII/INC_BAPISDHD1_STR-REF_DOC_L sy-vline
WA_/SAPDII/INC_BAPISDHD1_STR-ASS_NUMBER sy-vline
WA_/SAPDII/INC_BAPISDHD1_STR-REFDOC_CAT sy-vline
WA_/SAPDII/INC_BAPISDHD1_STR-ORDCOMB_IN sy-vline
WA_/SAPDII/INC_BAPISDHD1_STR-BILL_SCHED sy-vline
WA_/SAPDII/INC_BAPISDHD1_STR-INVO_SCHED sy-vline
WA_/SAPDII/INC_BAPISDHD1_STR-MN_INVOICE sy-vline
WA_/SAPDII/INC_BAPISDHD1_STR-EXRATE_FI sy-vline
WA_/SAPDII/INC_BAPISDHD1_STR-ADD_VAL_DY sy-vline
WA_/SAPDII/INC_BAPISDHD1_STR-FIX_VAL_DY sy-vline
WA_/SAPDII/INC_BAPISDHD1_STR-PYMT_METH sy-vline
WA_/SAPDII/INC_BAPISDHD1_STR-ACCNT_ASGN sy-vline
WA_/SAPDII/INC_BAPISDHD1_STR-EXCHG_RATE sy-vline
WA_/SAPDII/INC_BAPISDHD1_STR-BILL_DATE sy-vline
WA_/SAPDII/INC_BAPISDHD1_STR-SERV_DATE sy-vline
WA_/SAPDII/INC_BAPISDHD1_STR-DUNN_KEY sy-vline
WA_/SAPDII/INC_BAPISDHD1_STR-DUNN_BLOCK sy-vline
WA_/SAPDII/INC_BAPISDHD1_STR-PMTGAR_PRO sy-vline
WA_/SAPDII/INC_BAPISDHD1_STR-DEPARTM_NO sy-vline
WA_/SAPDII/INC_BAPISDHD1_STR-REC_POINT sy-vline
WA_/SAPDII/INC_BAPISDHD1_STR-DOC_NUM_FI sy-vline
WA_/SAPDII/INC_BAPISDHD1_STR-CSTCNDGRP1 sy-vline
WA_/SAPDII/INC_BAPISDHD1_STR-CSTCNDGRP2 sy-vline
WA_/SAPDII/INC_BAPISDHD1_STR-CSTCNDGRP3 sy-vline
WA_/SAPDII/INC_BAPISDHD1_STR-CSTCNDGRP4 sy-vline
WA_/SAPDII/INC_BAPISDHD1_STR-CSTCNDGRP5 sy-vline
WA_/SAPDII/INC_BAPISDHD1_STR-DLV_TIME sy-vline
WA_/SAPDII/INC_BAPISDHD1_STR-CURRENCY sy-vline
WA_/SAPDII/INC_BAPISDHD1_STR-CURR_ISO sy-vline
WA_/SAPDII/INC_BAPISDHD1_STR-CREATED_BY sy-vline
WA_/SAPDII/INC_BAPISDHD1_STR-TAXDEP_CTY sy-vline
WA_/SAPDII/INC_BAPISDHD1_STR-TAXDST_CTY sy-vline
WA_/SAPDII/INC_BAPISDHD1_STR-EUTRI_DEAL sy-vline
WA_/SAPDII/INC_BAPISDHD1_STR-MAST_CONTR sy-vline
WA_/SAPDII/INC_BAPISDHD1_STR-REF_PROC sy-vline
WA_/SAPDII/INC_BAPISDHD1_STR-CHKPRTAUTH sy-vline
WA_/SAPDII/INC_BAPISDHD1_STR-CMLQTY_DAT sy-vline
WA_/SAPDII/INC_BAPISDHD1_STR-VERSION sy-vline
WA_/SAPDII/INC_BAPISDHD1_STR-NOTIF_NO sy-vline
WA_/SAPDII/INC_BAPISDHD1_STR-WBS_ELEM sy-vline
WA_/SAPDII/INC_BAPISDHD1_STR-EXCH_RATE_FI_V sy-vline
WA_/SAPDII/INC_BAPISDHD1_STR-EXCHG_RATE_V sy-vline
WA_/SAPDII/INC_BAPISDHD1_STR-FKK_CONACCT sy-vline
WA_/SAPDII/INC_BAPISDHD1_STR-CAMPAIGN sy-vline
WA_/SAPDII/INC_BAPISDHD1_STR-DOC_CLASS sy-vline
WA_/SAPDII/INC_BAPISDHD1_STR-H_CURR sy-vline
WA_/SAPDII/INC_BAPISDHD1_STR-H_CURR_ISO sy-vline
WA_/SAPDII/INC_BAPISDHD1_STR-SHIP_TYPE sy-vline
WA_/SAPDII/INC_BAPISDHD1_STR-S_PROC_IND sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.