ABAP Select data from SAP table BAPI_NETWORK_COMP_CNG_UPD 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 BAPI_NETWORK_COMP_CNG_UPD 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 BAPI_NETWORK_COMP_CNG_UPD. 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 BAPI_NETWORK_COMP_CNG_UPD 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_BAPI_NETWORK_COMP_CNG_UPD TYPE STANDARD TABLE OF BAPI_NETWORK_COMP_CNG_UPD,
      WA_BAPI_NETWORK_COMP_CNG_UPD TYPE BAPI_NETWORK_COMP_CNG_UPD,
      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: <BAPI_NETWORK_COMP_CNG_UPD> TYPE BAPI_NETWORK_COMP_CNG_UPD.

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

SELECT *
*restrict ABAP select to first 10 rows
 UP TO 10 ROWS      
  FROM BAPI_NETWORK_COMP_CNG_UPD
  INTO TABLE IT_BAPI_NETWORK_COMP_CNG_UPD.

*Select data and declare internal table using in-line method @DATA
*SELECT *
*  FROM BAPI_NETWORK_COMP_CNG_UPD
*  INTO TABLE @DATA(IT_BAPI_NETWORK_COMP_CNG_UPD2).
*--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_BAPI_NETWORK_COMP_CNG_UPD INDEX 1 INTO DATA(WA_BAPI_NETWORK_COMP_CNG_UPD2).


*Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL
LOOP AT IT_BAPI_NETWORK_COMP_CNG_UPD ASSIGNING <BAPI_NETWORK_COMP_CNG_UPD>.
*To update a field value using a field symbol simply change the value via the field symbol pointer
<BAPI_NETWORK_COMP_CNG_UPD>-COMPONENT = 1.
<BAPI_NETWORK_COMP_CNG_UPD>-ACTIVITY = 1.
<BAPI_NETWORK_COMP_CNG_UPD>-ITEM_NUMBER = 1.
<BAPI_NETWORK_COMP_CNG_UPD>-ENTRY_QUANTITY = 1.
<BAPI_NETWORK_COMP_CNG_UPD>-CHANGE_NOMNG = 1.
ENDLOOP.

LOOP AT IT_BAPI_NETWORK_COMP_CNG_UPD INTO WA_BAPI_NETWORK_COMP_CNG_UPD.
*Write horizonal line to screen report.
  WRITE:/ sy-uline.

*Write selected data to screen/report before conversion.
  WRITE:/ sy-vline,   WA_BAPI_NETWORK_COMP_CNG_UPD-BASE_UOM, sy-vline,
WA_BAPI_NETWORK_COMP_CNG_UPD-BASE_UOM_ISO, sy-vline,
WA_BAPI_NETWORK_COMP_CNG_UPD-ITEM_TEXT, sy-vline,
WA_BAPI_NETWORK_COMP_CNG_UPD-MRP_RELEVANT, sy-vline,
WA_BAPI_NETWORK_COMP_CNG_UPD-REQ_DATE, sy-vline,
WA_BAPI_NETWORK_COMP_CNG_UPD-MANUAL_REQUIREMENTS_DATE, sy-vline.
ENDLOOP. *Add any further fields from structure WA_BAPI_NETWORK_COMP_CNG_UPD 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_BAPI_NETWORK_COMP_CNG_UPD 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_BAPI_NETWORK_COMP_CNG_UPD INTO WA_BAPI_NETWORK_COMP_CNG_UPD. *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_BAPI_NETWORK_COMP_CNG_UPD_STR,
COMPONENT TYPE STRING,
ACTIVITY TYPE STRING,
ITEM_NUMBER TYPE STRING,
ENTRY_QUANTITY TYPE STRING,
CHANGE_NOMNG TYPE STRING,
BASE_UOM TYPE STRING,
BASE_UOM_ISO TYPE STRING,
ITEM_TEXT TYPE STRING,
MRP_RELEVANT TYPE STRING,
REQ_DATE TYPE STRING,
MANUAL_REQUIREMENTS_DATE TYPE STRING,
LEAD_TIME_OFFSET_OPR TYPE STRING,
LEAD_TIME_OFFSET_OPR_UNIT TYPE STRING,
LEAD_TIME_OFFSET_OPR_UNIT_ISO TYPE STRING,
MRP_DISTRIBUTION_KEY TYPE STRING,
COST_RELEVANT TYPE STRING,
STGE_LOC TYPE STRING,
BATCH TYPE STRING,
BOMEXPL_NO TYPE STRING,
DELIVERY_DAYS TYPE STRING,
PUR_GROUP TYPE STRING,
PURCH_ORG TYPE STRING,
INFO_REC TYPE STRING,
PRICE TYPE STRING,
PRICE_UNIT TYPE STRING,
CURRENCY TYPE STRING,
CURRENCY_ISO TYPE STRING,
PUR_INFO_RECORD_DATA_FIXED TYPE STRING,
AGREEMENT TYPE STRING,
AGMT_ITEM TYPE STRING,
GL_ACCOUNT TYPE STRING,
VENDOR_NO TYPE STRING,
GR_PR_TIME TYPE STRING,
MATL_GROUP TYPE STRING,
PREQ_NAME TYPE STRING,
GR_RCPT TYPE STRING,
TRACKINGNO TYPE STRING,
UNLOAD_PT TYPE STRING,
SORT_STRING TYPE STRING,
BACKFLUSH TYPE STRING,
WITHDRAWN TYPE STRING,
BULK_MAT TYPE STRING,
VSI_SIZE1 TYPE STRING,
VSI_SIZE2 TYPE STRING,
VSI_SIZE3 TYPE STRING,
VSI_SIZE_UNIT TYPE STRING,
VSI_SIZE_UNIT_ISO TYPE STRING,
VSI_QTY TYPE STRING,
VAR_SIZE_COMP_MEASURE_UNIT TYPE STRING,
VAR_SIZE_COMP_MEASURE_UNIT_ISO TYPE STRING,
VSI_FORMULA TYPE STRING,
VSI_NO TYPE STRING,
ORIGINAL_QUANTITY TYPE STRING,
ADDR_NO TYPE STRING,
ADDR_NO2 TYPE STRING,
SUPP_VENDOR TYPE STRING,
CUSTOMER TYPE STRING,
WBS_ELEMENT TYPE STRING,
S_ORD_ITEM TYPE STRING,END OF T_EKKO_STR. DATA: WA_BAPI_NETWORK_COMP_CNG_UPD_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_BAPI_NETWORK_COMP_CNG_UPD_STR-COMPONENT sy-vline
WA_BAPI_NETWORK_COMP_CNG_UPD_STR-ACTIVITY sy-vline
WA_BAPI_NETWORK_COMP_CNG_UPD_STR-ITEM_NUMBER sy-vline
WA_BAPI_NETWORK_COMP_CNG_UPD_STR-ENTRY_QUANTITY sy-vline
WA_BAPI_NETWORK_COMP_CNG_UPD_STR-CHANGE_NOMNG sy-vline
WA_BAPI_NETWORK_COMP_CNG_UPD_STR-BASE_UOM sy-vline
WA_BAPI_NETWORK_COMP_CNG_UPD_STR-BASE_UOM_ISO sy-vline
WA_BAPI_NETWORK_COMP_CNG_UPD_STR-ITEM_TEXT sy-vline
WA_BAPI_NETWORK_COMP_CNG_UPD_STR-MRP_RELEVANT sy-vline
WA_BAPI_NETWORK_COMP_CNG_UPD_STR-REQ_DATE sy-vline
WA_BAPI_NETWORK_COMP_CNG_UPD_STR-MANUAL_REQUIREMENTS_DATE sy-vline
WA_BAPI_NETWORK_COMP_CNG_UPD_STR-LEAD_TIME_OFFSET_OPR sy-vline
WA_BAPI_NETWORK_COMP_CNG_UPD_STR-LEAD_TIME_OFFSET_OPR_UNIT sy-vline
WA_BAPI_NETWORK_COMP_CNG_UPD_STR-LEAD_TIME_OFFSET_OPR_UNIT_ISO sy-vline
WA_BAPI_NETWORK_COMP_CNG_UPD_STR-MRP_DISTRIBUTION_KEY sy-vline
WA_BAPI_NETWORK_COMP_CNG_UPD_STR-COST_RELEVANT sy-vline
WA_BAPI_NETWORK_COMP_CNG_UPD_STR-STGE_LOC sy-vline
WA_BAPI_NETWORK_COMP_CNG_UPD_STR-BATCH sy-vline
WA_BAPI_NETWORK_COMP_CNG_UPD_STR-BOMEXPL_NO sy-vline
WA_BAPI_NETWORK_COMP_CNG_UPD_STR-DELIVERY_DAYS sy-vline
WA_BAPI_NETWORK_COMP_CNG_UPD_STR-PUR_GROUP sy-vline
WA_BAPI_NETWORK_COMP_CNG_UPD_STR-PURCH_ORG sy-vline
WA_BAPI_NETWORK_COMP_CNG_UPD_STR-INFO_REC sy-vline
WA_BAPI_NETWORK_COMP_CNG_UPD_STR-PRICE sy-vline
WA_BAPI_NETWORK_COMP_CNG_UPD_STR-PRICE_UNIT sy-vline
WA_BAPI_NETWORK_COMP_CNG_UPD_STR-CURRENCY sy-vline
WA_BAPI_NETWORK_COMP_CNG_UPD_STR-CURRENCY_ISO sy-vline
WA_BAPI_NETWORK_COMP_CNG_UPD_STR-PUR_INFO_RECORD_DATA_FIXED sy-vline
WA_BAPI_NETWORK_COMP_CNG_UPD_STR-AGREEMENT sy-vline
WA_BAPI_NETWORK_COMP_CNG_UPD_STR-AGMT_ITEM sy-vline
WA_BAPI_NETWORK_COMP_CNG_UPD_STR-GL_ACCOUNT sy-vline
WA_BAPI_NETWORK_COMP_CNG_UPD_STR-VENDOR_NO sy-vline
WA_BAPI_NETWORK_COMP_CNG_UPD_STR-GR_PR_TIME sy-vline
WA_BAPI_NETWORK_COMP_CNG_UPD_STR-MATL_GROUP sy-vline
WA_BAPI_NETWORK_COMP_CNG_UPD_STR-PREQ_NAME sy-vline
WA_BAPI_NETWORK_COMP_CNG_UPD_STR-GR_RCPT sy-vline
WA_BAPI_NETWORK_COMP_CNG_UPD_STR-TRACKINGNO sy-vline
WA_BAPI_NETWORK_COMP_CNG_UPD_STR-UNLOAD_PT sy-vline
WA_BAPI_NETWORK_COMP_CNG_UPD_STR-SORT_STRING sy-vline
WA_BAPI_NETWORK_COMP_CNG_UPD_STR-BACKFLUSH sy-vline
WA_BAPI_NETWORK_COMP_CNG_UPD_STR-WITHDRAWN sy-vline
WA_BAPI_NETWORK_COMP_CNG_UPD_STR-BULK_MAT sy-vline
WA_BAPI_NETWORK_COMP_CNG_UPD_STR-VSI_SIZE1 sy-vline
WA_BAPI_NETWORK_COMP_CNG_UPD_STR-VSI_SIZE2 sy-vline
WA_BAPI_NETWORK_COMP_CNG_UPD_STR-VSI_SIZE3 sy-vline
WA_BAPI_NETWORK_COMP_CNG_UPD_STR-VSI_SIZE_UNIT sy-vline
WA_BAPI_NETWORK_COMP_CNG_UPD_STR-VSI_SIZE_UNIT_ISO sy-vline
WA_BAPI_NETWORK_COMP_CNG_UPD_STR-VSI_QTY sy-vline
WA_BAPI_NETWORK_COMP_CNG_UPD_STR-VAR_SIZE_COMP_MEASURE_UNIT sy-vline
WA_BAPI_NETWORK_COMP_CNG_UPD_STR-VAR_SIZE_COMP_MEASURE_UNIT_ISO sy-vline
WA_BAPI_NETWORK_COMP_CNG_UPD_STR-VSI_FORMULA sy-vline
WA_BAPI_NETWORK_COMP_CNG_UPD_STR-VSI_NO sy-vline
WA_BAPI_NETWORK_COMP_CNG_UPD_STR-ORIGINAL_QUANTITY sy-vline
WA_BAPI_NETWORK_COMP_CNG_UPD_STR-ADDR_NO sy-vline
WA_BAPI_NETWORK_COMP_CNG_UPD_STR-ADDR_NO2 sy-vline
WA_BAPI_NETWORK_COMP_CNG_UPD_STR-SUPP_VENDOR sy-vline
WA_BAPI_NETWORK_COMP_CNG_UPD_STR-CUSTOMER sy-vline
WA_BAPI_NETWORK_COMP_CNG_UPD_STR-WBS_ELEMENT sy-vline
WA_BAPI_NETWORK_COMP_CNG_UPD_STR-S_ORD_ITEM sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.